104 lines
3.3 KiB
C#
104 lines
3.3 KiB
C#
using YD_YiLu.Api.WebSockets;
|
||
|
||
namespace YD_YiLu.Api.Services
|
||
{
|
||
public class DeviceCommandService
|
||
{
|
||
private readonly ICameraDeviceSocketRegistry _registry;
|
||
|
||
public DeviceCommandService(ICameraDeviceSocketRegistry registry)
|
||
{
|
||
_registry = registry;
|
||
}
|
||
|
||
#region 通用发送
|
||
|
||
private async Task<bool> Send(string sn, string request, object data, CancellationToken ct)
|
||
{
|
||
if (!_registry.TryGet(sn, out var socket))
|
||
return false;
|
||
|
||
await DeviceWebSocketSender.SendAsync(socket, request, data, ct);
|
||
return true;
|
||
}
|
||
|
||
#endregion
|
||
|
||
// ================================
|
||
// 1️⃣ 信息提醒
|
||
// ================================
|
||
public Task<bool> Remind(string sn, int type, string msg, CancellationToken ct)
|
||
{
|
||
return Send(sn, "station:remind", new
|
||
{
|
||
remindType = type,
|
||
remindMessage = msg,
|
||
time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
|
||
}, ct);
|
||
}
|
||
|
||
// ================================
|
||
// 2️⃣ 控制设备(重启/关机)
|
||
// ================================
|
||
public Task<bool> Control(string sn, int code, string type, CancellationToken ct)
|
||
{
|
||
return Send(sn, "station:control", new
|
||
{
|
||
controlCode = code,
|
||
controlType = type,
|
||
time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
|
||
}, ct);
|
||
}
|
||
|
||
// ================================
|
||
// 3️⃣ 推送APK更新
|
||
// ================================
|
||
public Task<bool> PushApk(string sn, string version, int force, string url, string hardware, CancellationToken ct)
|
||
{
|
||
return Send(sn, "apk:version:download", new
|
||
{
|
||
versionNumber = version,
|
||
needForcedUpdating = force,
|
||
updateUrl = url,
|
||
hardwareType = hardware,
|
||
time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
|
||
}, ct);
|
||
}
|
||
|
||
// ================================
|
||
// 4️⃣ 获取现场截图
|
||
// ================================
|
||
public Task<bool> GetPicture(string sn, int courseId, CancellationToken ct)
|
||
{
|
||
return Send(sn, "station:intercept:picture", new
|
||
{
|
||
remindType = 1,
|
||
courseId = courseId
|
||
}, ct);
|
||
}
|
||
|
||
// ================================
|
||
// 5️⃣ 获取默认标定
|
||
// ================================
|
||
public Task<bool> GetDefaultCalibration(string sn, int courseId, CancellationToken ct)
|
||
{
|
||
return Send(sn, "station:default:calibration", new
|
||
{
|
||
remindType = 1,
|
||
courseId = courseId
|
||
}, ct);
|
||
}
|
||
|
||
// ================================
|
||
// 6️⃣ 推送最新标定
|
||
// ================================
|
||
public Task<bool> UpdateCalibration(string sn, string calibrationJson, int courseId, CancellationToken ct)
|
||
{
|
||
return Send(sn, "station:update:calibration", new
|
||
{
|
||
calibrationJson = calibrationJson,
|
||
courseId = courseId
|
||
}, ct);
|
||
}
|
||
}
|
||
} |