liusuyi
2024-10-25 75902fb9d5b27a440d14308ccca3c3cff32167bb
ard-work/src/main/java/com/ard/tianyu/service/impl/TyServiceImpl.java
@@ -127,13 +127,6 @@
        this.sendMessage(tyConfiguration.getIpPort(), registerMessage);
    }
    /**
     * 无人机控制订阅
     */
    public void uavControlSubscribe(String boxSn) {
        SubscribeCommand subscribeCommand = new SubscribeCommand(boxSn);
        this.sendMessage(tyConfiguration.getIpPort(), subscribeCommand);
    }
    /**
     * 发送消息
@@ -146,10 +139,7 @@
                InetSocketAddress ipSocket = (InetSocketAddress) channel.remoteAddress();
                String host = ipSocket.getHostString();
                int port = ipSocket.getPort();
                // 创建 ByteBuf 并编码消息
                ByteBuf buffer = Unpooled.buffer();
                msg.encode(buffer); // 确保对消息进行编码
                channel.writeAndFlush(buffer); // 发送编码后的数据
                channel.writeAndFlush(msg); // 发送编码后的数据
                log.debug("向天宇服务器【{}:{}】发送数据,命令码:{}", host, port, String.format("0x%02X", msg.getCmdCode() & 0xFF));
            } else {
                log.error("与天宇服务器链接断开,无法发送数据!");
@@ -164,7 +154,7 @@
     */
    @Override
    public void controlAngle(String boxSn, Integer actionId, Integer rotationAngle) {
        ControlAngleCommand controlAngleCommand = new ControlAngleCommand(boxSn.getBytes(), (byte) 0x00, actionId.byteValue(), rotationAngle.byteValue());
        ControlAngleCommand controlAngleCommand = new ControlAngleCommand(boxSn, actionId.byteValue(), rotationAngle.byteValue());
        this.sendMessage(tyConfiguration.getIpPort(), controlAngleCommand);
    }
@@ -213,13 +203,9 @@
                break;
            case 0x03:
                // 处理订阅消息
                SubscribeCommand subscribeCommand = (SubscribeCommand) tyCommand;
                log.info("收到订阅消息-->处理订阅消息{}", subscribeCommand.getBoxSn());
                break;
            case 0x04:
                // 处理取消订阅消息
                subscribeCommand = (SubscribeCommand) tyCommand;
                log.info("收到取消订阅消息-->处理取消订阅消息{}", subscribeCommand.getBoxSn());
                break;
            case (byte) 0xA8:
                // 处理无人机状态消息
@@ -246,7 +232,7 @@
                // 处理无人机
                DroneReadyNotificationCommand droneReadyNotificationCommand = (DroneReadyNotificationCommand) tyCommand;
                if (droneReadyNotificationCommand.getActionCode() == (byte) 0x42) {
                    UavInitInfoCommand uavInitCommand = new UavInitInfoCommand((byte) 0x00, (byte) 0x42, (byte) 0x01);
                    UavInitInfoCommand uavInitCommand = new UavInitInfoCommand(new String(droneReadyNotificationCommand.getBoxSn()), (byte) 0x42);
                    this.sendMessage(tyConfiguration.getIpPort(), uavInitCommand);
                    log.info("收到无人机初始化详情-回复防止再次发送");
                }