Files
BQP/srcs/RobotNet10/RobotApp/RobotNet10.RobotApp/Hubs/RfHandleHub.cs
2026-07-13 09:25:40 +07:00

62 lines
1.8 KiB
C#

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
};
}
}