| | |
| | | private UavTelemetryManager uavTelemetryManager; |
| | | @Resource |
| | | private UavSignalManager uavSignalManager; |
| | | |
| | | @Resource |
| | | private UavControlManager uavControlManager; |
| | | @Resource |
| | | private UavAllManager uavAllManager; |
| | | @Override |
| | | public void handleTextMessage(WebSocketSession session, TextMessage message) { |
| | | String userIdStr = (String) session.getAttributes().get("userId"); |
| | |
| | | break; |
| | | case "signal": |
| | | handleSignalMessage(payload, userId); |
| | | break; |
| | | case "controller": |
| | | handleControlMessage(payload, userId); |
| | | break; |
| | | case "all": |
| | | handleAllMessage(payload, userId); |
| | | break; |
| | | } |
| | | } |
| | |
| | | Boolean subscribe = uavStateMessage.getSubscribe(); |
| | | if (subscribe) { |
| | | // 执行订阅操作 |
| | | uavStateManager.subscribe(boxSn, userId); |
| | | uavStateManager.subscribe(boxSn, userId, 2); |
| | | } else { |
| | | // 执行退订操作 |
| | | uavStateManager.unsubscribe(boxSn, userId); |
| | |
| | | Boolean subscribe = uavTelemetryMessage.getSubscribe(); |
| | | if (subscribe) { |
| | | // 执行订阅操作 |
| | | uavTelemetryManager.subscribe(boxSn, userId); |
| | | uavTelemetryManager.subscribe(boxSn, userId, 2); |
| | | } else { |
| | | // 执行退订操作 |
| | | uavTelemetryManager.unsubscribe(boxSn, userId); |
| | |
| | | Boolean subscribe = uavSignalMessage.getSubscribe(); |
| | | if (subscribe) { |
| | | // 执行订阅操作 |
| | | uavSignalManager.subscribe(boxSn, userId); |
| | | uavSignalManager.subscribe(boxSn, userId, 2); |
| | | } else { |
| | | // 执行退订操作 |
| | | uavSignalManager.unsubscribe(boxSn, userId); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 处理无人机控制 |
| | | * 根据接收到的消息内容,决定无人机控制信息的订阅或退订 |
| | | * |
| | | * @param payload 消息负载,包含控制信息 |
| | | * @param userId 用户ID,用于标识用户 |
| | | */ |
| | | private void handleControlMessage(String payload, Long userId) { |
| | | // 解析接收到的JSON消息,将其转换为BaseMessage对象 |
| | | BaseMessage<UavControlMessage> controlMessage = JSON.parseObject(payload, |
| | | new TypeReference<BaseMessage<UavControlMessage>>() { |
| | | }); |
| | | // 获取消息的有效载荷部分 |
| | | UavControlMessage uavControlMessage = controlMessage.getPayload(); |
| | | |
| | | // 检查有效载荷是否存在 |
| | | if (uavControlMessage != null) { |
| | | // 获取无人机盒子的序列号 |
| | | String boxSn = uavControlMessage.getBoxSn(); |
| | | // 根据消息中的订阅标志,决定是订阅还是退订无人机状态 |
| | | Boolean subscribe = uavControlMessage.getSubscribe(); |
| | | if (subscribe) { |
| | | // 执行订阅操作 |
| | | uavControlManager.subscribe(boxSn, userId, 2); |
| | | } else { |
| | | // 执行退订操作 |
| | | uavControlManager.unsubscribe(boxSn, userId); |
| | | } |
| | | } |
| | | } |
| | | private void handleAllMessage(String payload, Long userId) { |
| | | // 解析接收到的JSON消息,将其转换为BaseMessage对象 |
| | | BaseMessage<UavControlMessage> controlMessage = JSON.parseObject(payload, |
| | | new TypeReference<BaseMessage<UavControlMessage>>() { |
| | | }); |
| | | // 获取消息的有效载荷部分 |
| | | UavControlMessage uavControlMessage = controlMessage.getPayload(); |
| | | |
| | | // 检查有效载荷是否存在 |
| | | if (uavControlMessage != null) { |
| | | // 获取无人机盒子的序列号 |
| | | String boxSn = uavControlMessage.getBoxSn(); |
| | | // 根据消息中的订阅标志,决定是订阅还是退订无人机状态 |
| | | Boolean subscribe = uavControlMessage.getSubscribe(); |
| | | if (subscribe) { |
| | | // 执行订阅操作 |
| | | uavAllManager.subscribe(boxSn, userId, 2); |
| | | } else { |
| | | // 执行退订操作 |
| | | uavAllManager.unsubscribe(boxSn, userId); |
| | | } |
| | | } |
| | | } |
| | |
| | | uavStateManager.removeSubscribe(userId); |
| | | uavTelemetryManager.removeSubscribe(userId); |
| | | uavSignalManager.removeSubscribe(userId); |
| | | uavControlManager.removeSubscribe(userId); |
| | | } |
| | | } |