14 files modified
1 files renamed
| | |
| | | @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(); |
| | | } |
| | | |
| | |
| | | |
| | | // 编码方法,子类需要实现 |
| | | public abstract void encode(ByteBuf out); |
| | | |
| | | } |
| | |
| | | } |
| | | |
| | | 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); // 写入转动角度 |
| | |
| | | this.timestamp = timestamp; |
| | | } |
| | | public void encode(ByteBuf out) { |
| | | out.writeShort(getDataHeader()); // 写入数据头 |
| | | out.writeShort(getDataLength()); // 写入数据长度 |
| | | out.writeByte(getCmdCode()); // 写入命令码 |
| | | out.writeLong(timestamp); // 写入时间戳 |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | public void encode(ByteBuf out) { |
| | | out.writeShort(getDataHeader()); // 写入数据头 |
| | | out.writeShort(getDataLength()); // 写入数据长度 |
| | | out.writeByte(getCmdCode()); // 写入命令码 |
| | | out.writeLong(timestamp); // 写入时间戳 |
| | | } |
| | | } |
| | |
| | | |
| | | @Override |
| | | public void encode(ByteBuf out) { |
| | | |
| | | out.writeShort(getDataHeader()); // 写入数据头 |
| | | out.writeShort(getDataLength()); // 写入数据长度 |
| | | out.writeByte(getCmdCode()); // 写入命令码 |
| | | out.writeDouble(longitude); // 写入经度 |
| | | out.writeDouble(latitude); // 写入纬度 |
| | | out.writeFloat(height); // 写入高度 |
| | |
| | | |
| | | @Override |
| | | public void encode(ByteBuf out) { |
| | | out.writeShort(getDataHeader()); // 写入数据头 |
| | | out.writeShort(getDataLength()); // 写入数据长度 |
| | | out.writeByte(getCmdCode()); // 写入命令码 |
| | | out.writeInt(userId); // 写入用户编号 |
| | | out.writeBytes(accessToken); // 写入访问令牌 |
| | | } |
| | |
| | | |
| | | @Override |
| | | public void encode(ByteBuf out) { |
| | | out.writeShort(getDataHeader()); // 写入数据头 |
| | | out.writeShort(getDataLength()); // 写入数据长度 |
| | | out.writeByte(getCmdCode()); // 写入命令码 |
| | | out.writeByte(success); // 写入用户编号 |
| | | } |
| | | } |
| | |
| | | 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()); // 写入云盒编号 |
| | | } |
| | | } |
| File was renamed from ard-work/src/main/java/com/ard/tianyu/netty/command/DroneReadyNotificationCommand.java |
| | |
| | | * @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()); |
| | |
| | | |
| | | 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; |
| | |
| | | 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)); |
| | |
| | | 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) |
| | | { |
| | | // 打印编码后的字节数组 |
| | |
| | | /** |
| | | * 云台转动(基于角度) |
| | | */ |
| | | 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); |
| | | |
| | | /** |
| | | * 获取无人机状态 |
| | |
| | | * 获取信道质量遥测 |
| | | */ |
| | | SignalInfo getSignalInfo(String boxSn); |
| | | |
| | | /** |
| | | * 解析天宇服务端发来的消息 |
| | | */ |
| | |
| | | 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; |
| | |
| | | * 云台控制基于角度 |
| | | */ |
| | | @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) { |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | 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("收到无人机初始化详情-回复防止再次发送"); |
| | | } |