Initial commit
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using RobotNet10.RobotApp.Client.Shared.Devices;
|
||||
using RobotNet10.RobotApp.Devices;
|
||||
|
||||
namespace RobotNet10.RobotApp.Hubs;
|
||||
|
||||
[Authorize]
|
||||
public class RfHandleHub(IDeviceProvider _deviceProvider) : Hub
|
||||
{
|
||||
// Snapshot / RPC calls
|
||||
public Task<DeviceInfoDto?> GetDeviceInfo(string deviceId)
|
||||
{
|
||||
var device = _deviceProvider.GetDevice(deviceId);
|
||||
if (device is not IRfHandle)
|
||||
return Task.FromResult<DeviceInfoDto?>(null);
|
||||
|
||||
return Task.FromResult<DeviceInfoDto?>(new DeviceInfoDto
|
||||
{
|
||||
DeviceId = deviceId,
|
||||
DeviceName = device.DeviceName
|
||||
});
|
||||
}
|
||||
|
||||
public Task<RfHandleDataDto?> GetRfHandleData(string deviceId)
|
||||
{
|
||||
var device = _deviceProvider.GetDevice(deviceId);
|
||||
if (device is not IRfHandle rf)
|
||||
return Task.FromResult<RfHandleDataDto?>(null);
|
||||
|
||||
var dto = MapToDto(rf, deviceId);
|
||||
return Task.FromResult<RfHandleDataDto?>(dto);
|
||||
}
|
||||
|
||||
// ====== Helper & DTO mapper ======
|
||||
private static RfHandleDataDto MapToDto(IRfHandle rf, string deviceId)
|
||||
{
|
||||
return new RfHandleDataDto
|
||||
{
|
||||
DeviceId = deviceId,
|
||||
Heartbeat = rf.Heartbeat,
|
||||
RemoteReady = rf.RemoteReady,
|
||||
EStop = rf.EStop,
|
||||
|
||||
LiftUp = rf.LiftUp,
|
||||
LiftDown = rf.LiftDown,
|
||||
RotateLeft = rf.RotateLeft,
|
||||
RotateRight = rf.RotateRight,
|
||||
|
||||
ModeSelect = rf.ModeSelect,
|
||||
Enable = rf.Enable,
|
||||
|
||||
Speed = rf.Speed,
|
||||
Linear = rf.Linear,
|
||||
Angular = rf.Angular,
|
||||
Mode = rf.Mode.ToString(),
|
||||
|
||||
LastUpdateTime = rf.LastUpdateTime
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user