| | |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup; |
| | | using Serilog; |
| | | using System.Net; |
| | | using WIDESEAWCS_Common.TaskEnum; |
| | | using WIDESEAWCS_Core.LogHelper; |
| | | using WIDESEAWCS_Model.Models; |
| | |
| | | private readonly ILogger _logger; |
| | | |
| | | /// <summary> |
| | | /// 机械手状态管理器 |
| | | /// </summary> |
| | | /// <remarks> |
| | | /// 用于读取和更新机器人的状态。 |
| | | /// </remarks> |
| | | private readonly RobotStateManager _stateManager; |
| | | |
| | | /// <summary> |
| | | /// 构造函数 |
| | | /// </summary> |
| | | /// <param name="taskProcessor">任务处理器实例</param> |
| | | /// <param name="logger">日志记录器</param> |
| | | public RobotSimpleCommandHandler(RobotTaskProcessor taskProcessor, ISocketClientGateway socketClientGateway, ILogger logger) |
| | | public RobotSimpleCommandHandler(RobotTaskProcessor taskProcessor, ISocketClientGateway socketClientGateway, ILogger logger, RobotStateManager stateManager) |
| | | { |
| | | _taskProcessor = taskProcessor; |
| | | _socketClientGateway = socketClientGateway; |
| | | _logger = logger; |
| | | _stateManager = stateManager; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | // 机器人已完成回零 |
| | | case "homed": |
| | | state.Homed = "Homed"; |
| | | |
| | | await _socketClientGateway.SendToClientAsync(state.IPAddress, "Homed"); |
| | | return true; |
| | | |
| | | // 机器人正在运行 |
| | |
| | | // 是否电芯到位 |
| | | case "batteryarrivedno": |
| | | state.BatteryArrived = false; |
| | | |
| | | await _socketClientGateway.SendToClientAsync(state.IPAddress, "batteryarrivedno"); |
| | | return true; |
| | | // ==================== 接收任务反馈 ==================== |
| | | |
| | | // 取货接收 |
| | | case "pickbatteryover": |
| | | var isResult = UpdateStatus(state, true); |
| | | if (!isResult) |
| | | return false; |
| | | return true; |
| | | |
| | | // 放货接收 |
| | | case "putbatteryover": |
| | | isResult = UpdateStatus(state, false); |
| | | if (!isResult) |
| | | return false; |
| | | return true; |
| | | |
| | | // ==================== 全部完成命令 ==================== |
| | |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | public bool UpdateStatus(RobotSocketState state, bool isPick) |
| | | { |
| | | var task = _taskProcessor.GetTask(state?.RobotCrane); |
| | | if (task == null) |
| | | { |
| | | QuartzLogHelper.LogError(_logger, $"取货接收失败: 未找到【{state?.RobotCrane}】的任务", state.RobotCrane?.DeviceName ?? "Unknown"); |
| | | } |
| | | task.RobotTaskState = (int)TaskRobotStatusEnum.RobotExecuting; |
| | | _taskProcessor.UpdateRobotTask(task); |
| | | return true; |
| | | } |
| | | } |
| | | } |