liusuyi
2024-10-25 91f6e60919b92b7f99a41f2ddeb42df17cd0c487
优化
14 files modified
1 files renamed
70 ■■■■■ changed files
ard-work/src/main/java/com/ard/tianyu/controller/UavController.java 2 ●●●●● patch | view | raw | blame | history
ard-work/src/main/java/com/ard/tianyu/netty/command/BaseCommand.java 1 ●●●●● patch | view | raw | blame | history
ard-work/src/main/java/com/ard/tianyu/netty/command/ControlAngleCommand.java 4 ●●●●● patch | view | raw | blame | history
ard-work/src/main/java/com/ard/tianyu/netty/command/HeartbeatCommand.java 3 ●●●●● patch | view | raw | blame | history
ard-work/src/main/java/com/ard/tianyu/netty/command/HeartbeatReplyCommand.java 3 ●●●●● patch | view | raw | blame | history
ard-work/src/main/java/com/ard/tianyu/netty/command/PointFlyCommand.java 4 ●●●●● patch | view | raw | blame | history
ard-work/src/main/java/com/ard/tianyu/netty/command/RegisterCommand.java 3 ●●●●● patch | view | raw | blame | history
ard-work/src/main/java/com/ard/tianyu/netty/command/RegisterReplyCommand.java 3 ●●●●● patch | view | raw | blame | history
ard-work/src/main/java/com/ard/tianyu/netty/command/UavInitInfoCommand.java 12 ●●●●● patch | view | raw | blame | history
ard-work/src/main/java/com/ard/tianyu/netty/command/UavReadyNotificationCommand.java 4 ●●●●● patch | view | raw | blame | history
ard-work/src/main/java/com/ard/tianyu/netty/handler/ClientHandler.java 1 ●●●●● patch | view | raw | blame | history
ard-work/src/main/java/com/ard/tianyu/netty/handler/MessageProtocolDecoder.java 4 ●●●●● patch | view | raw | blame | history
ard-work/src/main/java/com/ard/tianyu/netty/handler/MessageProtocolEncoder.java 8 ●●●●● patch | view | raw | blame | history
ard-work/src/main/java/com/ard/tianyu/service/ITyService.java 5 ●●●●● patch | view | raw | blame | history
ard-work/src/main/java/com/ard/tianyu/service/impl/TyServiceImpl.java 13 ●●●●● patch | view | raw | blame | history
ard-work/src/main/java/com/ard/tianyu/controller/UavController.java
@@ -77,7 +77,7 @@
    @ApiOperation("云台转动(基于角度)")
    @GetMapping("/controlAngle")
    public AjaxResult controlAngle(String boxSn,Integer actionId,Integer rotationAngle) {
        tyService.controlAngle(boxSn,actionId,rotationAngle);
        tyService.angleControl(boxSn,actionId,rotationAngle);
        return AjaxResult.success();
    }
ard-work/src/main/java/com/ard/tianyu/netty/command/BaseCommand.java
@@ -12,4 +12,5 @@
    // 编码方法,子类需要实现
    public abstract void encode(ByteBuf out);
}
ard-work/src/main/java/com/ard/tianyu/netty/command/ControlAngleCommand.java
@@ -28,6 +28,10 @@
    }
    public void encode(ByteBuf out) {
        out.writeShort(getDataHeader());    // 写入数据头
        out.writeShort(getDataLength());    // 写入数据长度
        out.writeBytes(getBoxSn());         // 写入盒子SN
        out.writeByte(getCmdCode());        // 写入命令码
        out.writeByte(encryptFlag);         // 写入加密标志
        out.writeByte(actionCode);          // 写入动作编号
        out.writeByte(rotationAngle);       // 写入转动角度
ard-work/src/main/java/com/ard/tianyu/netty/command/HeartbeatCommand.java
@@ -19,6 +19,9 @@
        this.timestamp = timestamp;
    }
    public void encode(ByteBuf out) {
        out.writeShort(getDataHeader());    // 写入数据头
        out.writeShort(getDataLength());    // 写入数据长度
        out.writeByte(getCmdCode());        // 写入命令码
        out.writeLong(timestamp); // 写入时间戳
    }
}
ard-work/src/main/java/com/ard/tianyu/netty/command/HeartbeatReplyCommand.java
@@ -24,6 +24,9 @@
    }
    public void encode(ByteBuf out) {
        out.writeShort(getDataHeader());    // 写入数据头
        out.writeShort(getDataLength());    // 写入数据长度
        out.writeByte(getCmdCode());        // 写入命令码
        out.writeLong(timestamp); // 写入时间戳
    }
}
ard-work/src/main/java/com/ard/tianyu/netty/command/PointFlyCommand.java
@@ -19,7 +19,9 @@
    @Override
    public void encode(ByteBuf out) {
        out.writeShort(getDataHeader());    // 写入数据头
        out.writeShort(getDataLength());    // 写入数据长度
        out.writeByte(getCmdCode());        // 写入命令码
        out.writeDouble(longitude);         // 写入经度
        out.writeDouble(latitude);          // 写入纬度
        out.writeFloat(height);             // 写入高度
ard-work/src/main/java/com/ard/tianyu/netty/command/RegisterCommand.java
@@ -22,6 +22,9 @@
    @Override
    public void encode(ByteBuf out) {
        out.writeShort(getDataHeader());    // 写入数据头
        out.writeShort(getDataLength());    // 写入数据长度
        out.writeByte(getCmdCode());        // 写入命令码
        out.writeInt(userId);               // 写入用户编号
        out.writeBytes(accessToken);        // 写入访问令牌
    }
ard-work/src/main/java/com/ard/tianyu/netty/command/RegisterReplyCommand.java
@@ -22,6 +22,9 @@
    @Override
    public void encode(ByteBuf out) {
        out.writeShort(getDataHeader());    // 写入数据头
        out.writeShort(getDataLength());    // 写入数据长度
        out.writeByte(getCmdCode());        // 写入命令码
        out.writeByte(success);             // 写入用户编号
    }
}
ard-work/src/main/java/com/ard/tianyu/netty/command/UavInitInfoCommand.java
@@ -17,19 +17,23 @@
    private final byte actionCode; // 动作编号
    private final byte result; // 执行结果
    public UavInitInfoCommand(String boxSn, byte actionCode) {
    public UavInitInfoCommand(byte[] boxSn) {
        setDataHeader((short)0x7479);
        setDataLength((short) 18);
        setBoxSn(boxSn.getBytes());
        setDataLength((short) 19);
        setCmdCode((byte)0xD1);
        this.encryptFlag = 0x00;
        this.actionCode = actionCode;
        this.actionCode = 0x42;
        this.result = 0x01;
        setBoxSn(boxSn);
    }
    public void encode(ByteBuf out) {
        out.writeShort(getDataHeader());    // 写入数据头
        out.writeShort(getDataLength());    // 写入数据长度
        out.writeByte(getCmdCode());        // 写入命令码
        out.writeByte(encryptFlag);         // 写入加密标志
        out.writeByte(actionCode);          // 写入动作编号
        out.writeByte(result);              // 写入执行结果
        out.writeBytes(getBoxSn());         // 写入云盒编号
    }
}
ard-work/src/main/java/com/ard/tianyu/netty/command/UavReadyNotificationCommand.java
File was renamed from ard-work/src/main/java/com/ard/tianyu/netty/command/DroneReadyNotificationCommand.java
@@ -11,12 +11,12 @@
 * @date 2024/10/24 17:18
 */
@Data
public class DroneReadyNotificationCommand extends BaseCommand {
public class UavReadyNotificationCommand extends BaseCommand {
    private byte actionCode;
    private TelemetryDataPB.UavInitInfo uavInitInfo;
    public DroneReadyNotificationCommand(String boxSn,TelemetryDataPB.UavInitInfo uavInitInfo, byte actionCode) {
    public UavReadyNotificationCommand(String boxSn, TelemetryDataPB.UavInitInfo uavInitInfo, byte actionCode) {
        setDataHeader((short) 0x6A77); // 设置帧头
        // setDataLength((short) (1 + uavState.toByteArray().length)); // 数据长度
        setBoxSn(boxSn.getBytes());
ard-work/src/main/java/com/ard/tianyu/netty/handler/ClientHandler.java
@@ -2,7 +2,6 @@
import com.ard.tianyu.netty.TyNettyTcpClient;
import com.ard.tianyu.netty.command.BaseCommand;
import com.ard.tianyu.netty.command.HeartbeatCommand;
import com.ard.tianyu.service.ITyService;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
ard-work/src/main/java/com/ard/tianyu/netty/handler/MessageProtocolDecoder.java
@@ -81,8 +81,8 @@
                        in.readBytes(uavData2);
                        String boxSn = new String(uavData2);
                        TelemetryDataPB.UavInitInfo uavInitInfo = TelemetryDataPB.UavInitInfo.parseFrom(uavData1);
                        baseCommand = new DroneReadyNotificationCommand(boxSn, uavInitInfo, actionCode);
                        log.info("无人机初始化数据: {}", uavInitInfo.getUavModel());
                        baseCommand = new UavReadyNotificationCommand(boxSn, uavInitInfo, actionCode);
                        log.debug("无人机初始化数据: {}", boxSn);
                        break;
                    default:
                        log.warn("无法识别的命令码动作编号:{}", String.format("0x%02X", actionCode & 0xFF));
ard-work/src/main/java/com/ard/tianyu/netty/handler/MessageProtocolEncoder.java
@@ -12,18 +12,14 @@
public class MessageProtocolEncoder extends MessageToByteEncoder<BaseCommand> {
    @Override
    protected void encode(ChannelHandlerContext ctx, BaseCommand command, ByteBuf out) throws Exception {
        out.writeShort(command.getDataHeader()); // 写入帧头
        out.writeShort(command.getDataLength()); // 写入数据长度
        if(command.getBoxSn() != null) {
            out.writeBytes(command.getBoxSn());
        }// 写入指令编号
        out.writeByte(command.getCmdCode()); // 写入指令编号
        command.encode(out); // 编码具体负载
        // 打印
        if(command.getCmdCode()!=0x02) {
            printHex(out);
        }
    }
    // 打印编码后的字节数组
    private void printHex(ByteBuf out)
    {
        // 打印编码后的字节数组
ard-work/src/main/java/com/ard/tianyu/service/ITyService.java
@@ -65,7 +65,9 @@
    /**
     * 云台转动(基于角度)
     */
    void controlAngle(String boxSn,Integer actionId,Integer rotationAngle) ;
    void angleControl(String boxSn, Integer actionId, Integer rotationAngle);
    void absAngleControl(String boxSn, Integer actionId, float pitch, float yaw, float roll);
    /**
     * 获取无人机状态
@@ -81,6 +83,7 @@
     * 获取信道质量遥测
     */
    SignalInfo getSignalInfo(String boxSn);
    /**
     * 解析天宇服务端发来的消息
     */
ard-work/src/main/java/com/ard/tianyu/service/impl/TyServiceImpl.java
@@ -18,8 +18,6 @@
import com.ard.tianyu.netty.command.*;
import com.ard.tianyu.netty.TyNettyTcpClient;
import com.ard.tianyu.service.ITyService;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import lombok.extern.slf4j.Slf4j;
@@ -153,9 +151,14 @@
     * 云台控制基于角度
     */
    @Override
    public void controlAngle(String boxSn, Integer actionId, Integer rotationAngle) {
    public void angleControl(String boxSn, Integer actionId, Integer rotationAngle) {
        ControlAngleCommand controlAngleCommand = new ControlAngleCommand(boxSn, actionId.byteValue(), rotationAngle.byteValue());
        this.sendMessage(tyConfiguration.getIpPort(), controlAngleCommand);
    }
    @Override
    public void absAngleControl(String boxSn, Integer actionId, float pitch, float yaw, float roll) {
    }
    /**
@@ -230,9 +233,9 @@
                break;
            case (byte) 0xD1:
                // 处理无人机
                DroneReadyNotificationCommand droneReadyNotificationCommand = (DroneReadyNotificationCommand) tyCommand;
                UavReadyNotificationCommand droneReadyNotificationCommand = (UavReadyNotificationCommand) tyCommand;
                if (droneReadyNotificationCommand.getActionCode() == (byte) 0x42) {
                    UavInitInfoCommand uavInitCommand = new UavInitInfoCommand(new String(droneReadyNotificationCommand.getBoxSn()), (byte) 0x42);
                    UavInitInfoCommand uavInitCommand = new UavInitInfoCommand(droneReadyNotificationCommand.getBoxSn());
                    this.sendMessage(tyConfiguration.getIpPort(), uavInitCommand);
                    log.info("收到无人机初始化详情-回复防止再次发送");
                }