#实时消息和参数

This commit is contained in:
2026-10-23 09:12:53 +08:00
parent e57699dbdf
commit 372b1a2d11
13 changed files with 711 additions and 519 deletions

View File

@@ -1,22 +1,19 @@
package com.maibu.core.business;
import java.time.LocalDate;
import java.util.List;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.maibu.annotation.Excel;
import com.maibu.constant.CommandConstant;
import com.maibu.core.domain.BaseDO;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import java.util.List;
@EqualsAndHashCode(callSuper = true)
@Data
@TableName(value = "iot_device_run_param", autoResultMap = true)
@@ -25,366 +22,440 @@ public class DeviceRunParam extends BaseDO {
@TableId(type = IdType.AUTO)
private Long id;
// private String deviceId;
// private String deviceId;
private Long siteId;
private Long orgId;
private Integer runSpeed; //不下发到设备自己用
private Integer runSpeed; // 不下发到设备自己用
@Excel(name = "设备序列号", cellType = Excel.ColumnType.STRING, prompt = "设备序列号")
private String deviceId;//设备序列号
private String deviceId;// 设备序列号
@Excel(name = "产品型号", cellType = Excel.ColumnType.STRING, prompt = "产品型号")
private String productModel;//产品型号
private String productModel;// 产品型号
@Excel(name = "设备类型", cellType = Excel.ColumnType.STRING, prompt = "设备类型")
private String deviceType;//设备类型:mower-割草机器人
private String deviceType;// 设备类型:mower-割草机器人
@Excel(name = "RTK模式", cellType = Excel.ColumnType.STRING, prompt = "RTK模式")
private String rtkMode;//RTK模式:network-4G网络差分
private String rtkMode;// RTK模式:network-4G网络差分
@Excel(name = "摄像头数量", cellType = Excel.ColumnType.STRING, prompt = "摄像头数量")
private Integer cameraNum;//摄像头数量
private Integer cameraNum;// 摄像头数量
@Excel(name = "动力类型", cellType = Excel.ColumnType.STRING, prompt = "动力类型")
private String powerType;//动力类型:hybrid-混动
private String powerType;// 动力类型:hybrid-混动
@Excel(name = "车轮类型", cellType = Excel.ColumnType.STRING, prompt = "车轮类型")
private String wheelType;//车轮类型:track-履带式
private String wheelType;// 车轮类型:track-履带式
@Excel(name = "发动机类型", cellType = Excel.ColumnType.STRING, prompt = "发动机类型")
private String engineType;//发动机类型:honda-本田发动机
private String engineType;// 发动机类型:honda-本田发动机
@Excel(name = "是否搭载上位机",cellType = Excel.ColumnType.NUMERIC)
private Integer hasHost = 1;//是否搭载上位机
@Excel(name = "是否搭载上位机", cellType = Excel.ColumnType.NUMERIC)
private Integer hasHost = 1;// 是否搭载上位机
@Excel(name = "设备能力列表")
@TableField(exist = false)
private String capabilities;
private String factoryCode; // 工厂码
private String lineNum;// 产线号
private LocalDate productionDate;// 生产日期
private String serialNumber;// 流水号
@Excel(name = "电池类型", cellType = Excel.ColumnType.STRING, prompt = "电池类型")
private String batteryType;// 电池类型
@Excel(name = "行走驱动类型", cellType = Excel.ColumnType.STRING, prompt = "行走驱动类型")
private String walkingDriveType;// 行走驱动类型
@Excel(name = "割刀驱动类型", cellType = Excel.ColumnType.STRING, prompt = "割刀驱动类型")
private String cutterDriveType;// 割刀驱动类型
@Excel(name = "RTK天线数", cellType = Excel.ColumnType.STRING, prompt = "RTK天线数")
private String rtkAntennasNum;// RTK天线数
@Excel(name = "手柄类型", cellType = Excel.ColumnType.STRING, prompt = "手柄类型")
private String handleType;// 手柄类型
@Excel(name = "PCB硬件版本", cellType = Excel.ColumnType.STRING, prompt = "PCB硬件版本")
private String pcbVersion;// PCB硬件版本
@Excel(name = "长宽高", cellType = Excel.ColumnType.STRING, prompt = "长宽高")
private String dimensions;// 长宽高
@Excel(name = "割刀宽度", cellType = Excel.ColumnType.STRING, prompt = "割刀宽度")
private String bladeWidth;// 割刀宽度
@Excel(name = "轮胎尺寸", cellType = Excel.ColumnType.STRING, prompt = "轮胎尺寸")
private String tyreSize;// 轮胎尺寸
@Excel(name = "转速比", cellType = Excel.ColumnType.STRING, prompt = "转速比")
private String speedRatio;// 转速比
@Excel(name = "蜂窝网络通信信息", cellType = Excel.ColumnType.STRING, prompt = "蜂窝网络通信信息")
private String cellularInfo;// 蜂窝网络通信信息
@Excel(name = "wifi名称", cellType = Excel.ColumnType.STRING, prompt = "wifi名称")
private String wifiName;// wifi名称
@Excel(name = "蓝牙广播名", cellType = Excel.ColumnType.STRING, prompt = "蓝牙广播名")
private String bluetoothName;// 蓝牙广播名
@Excel(name = "硬件标识信息", cellType = Excel.ColumnType.STRING, prompt = "硬件标识信息")
private String hardwareIdentifiers;// 硬件标识信息
@Excel(name = "IMU型号", cellType = Excel.ColumnType.STRING, prompt = "IMU型号")
private String imuModel;// IMU型号
@Excel(name = "温湿度传感器", cellType = Excel.ColumnType.STRING, prompt = "温湿度传感器")
private String tempHumiditySensor;// 温湿度传感器
@Excel(name = "气压计在位", cellType = Excel.ColumnType.STRING, prompt = "气压计在位")
private String barometerPresent;// 气压计在位
@Excel(name = "超声波在位", cellType = Excel.ColumnType.STRING, prompt = "超声波在位")
private String ultrasonicPresent;// 超声波在位
@Excel(name = "DAC在位", cellType = Excel.ColumnType.STRING, prompt = "DAC在位")
private String dacPresent;// DAC在位
@Excel(name = "质检员", cellType = Excel.ColumnType.STRING, prompt = "质检员")
private String operator;// 质检员
@Excel(name = "检测报告号", cellType = Excel.ColumnType.STRING, prompt = "检测报告号")
private String inspectionNo;// 检测报告号
@Excel(name = "固件版本", cellType = Excel.ColumnType.STRING, prompt = "固件版本")
private String firmwareVersion;// 固件版本
@Excel(name = "经销商", cellType = Excel.ColumnType.STRING, prompt = "经销商")
private String dealer;// DAC在位
@TableField(typeHandler = JacksonTypeHandler.class)
private List<String> capabilityList;//设备能力列表:heartbeat-上报心跳/location-上报位置/vehicle_status-上报整机状态/task_control-任务控制/single_point-单点作业/coverage-全覆盖割草作业/path_upload-作业路径上传
private List<String> capabilityList;// 设备能力列表:heartbeat-上报心跳/location-上报位置/vehicle_status-上报整机状态/task_control-任务控制/single_point-单点作业/coverage-全覆盖割草作业/path_upload-作业路径上传
// @TableField(exist = false)
// public byte header1;
// @TableField(exist = false)
// public byte header2;
// @TableField(exist = false)
// public byte cmd;
// public byte chipUidSign;// 芯片UID固化标志位
// public String chipUid;// 芯片UID
// public byte[] remoteConfig;// 遥控器通道配置
// public int knifeMotorMode;// 割刀电机模式
// public int walkMotorMode;// 行走电机模式
// public int leftMotorReverse;// 左轮电机方向极性
// public int rightMotorReverse;// 右轮电机方向极性
// public int swapChannel;// 左右轮通道互换标志位
// public int use4G;// 联网标志位
// public short forwardSpeedLimit;// 前进速度限制
// public short turnSpeedLimit;// 转向速度限制
// public int knifePolarity;// 割刀通道极性
// public int fanPolarity;// 风门通道极性
// public int throttlePolarity;// 油门通道极性
// public int liftProtectTime;// 底盘升降电机保护时间
// public int dualRtk;// RTK配置
// public int knifeChannel;// 割刀通道配置
// public int fanChannel;// 风门通道配置
// public int throttleChannel;// 油门通道配置
// public int remoteType;// 遥控器类型
// public boolean relayBoard;// 是否搭载继电器板
// public int liftChannel;// 底盘升通道配置
// public int chassisChannel;// 底盘降通道配置
// public int armChannel;// 抱闸通道配置
// public int fuelPumpChannel;// 燃油励磁通道配置
// public String wifiName;// wifi名称
// public String wifiPassword;// wifi密码
// public int batteryType;// 电池类型
// public int driveType;// 行走驱动配置
// public float gearRatio;// 转速比
// public float robotLength;// 机器人长度
// public float robotWidth;// 机器人宽度
// public float robotHeight;// 机器人高度
// public float knifeWidth;// 割刀宽度
// public float tyreSize;// 轮胎尺寸
// public float leftForwardGain;// 左轮前进增益
// public float leftBackwardGain;// 左轮后退增益
// public float rightForwardGain;// 右轮前进增益
// public float rightBackwardGain;// 右轮后退增益
// public String firmwareVersion;// 固件版本
// @TableField(exist = false)
// public int crc16;
// @TableField(exist = false)
// public byte tail1;
// @TableField(exist = false)
// public byte tail2;
// @TableField(exist = false)
// private byte[] originalData;
// public static byte[] toReadBytes() {
// ByteBuffer buffer = ByteBuffer.allocate(7); // 修改为27字节
// buffer.order(ByteOrder.LITTLE_ENDIAN);
// buffer.put((byte) 0xAB);
// buffer.put((byte) 0xAA);
// buffer.put(CommandConstant.readConfig);
// buffer.putShort((short) 0);
// buffer.put((byte) 0xAA);
// buffer.put((byte) 0xAB);
// return buffer.array();
// }
// public byte[] toWriteBytes() {
// // 如果没有原始数据,使用静态方法重新构建
// if (originalData == null || originalData.length < 178) {
// return null;
// }
// // 克隆原始数据,避免修改原始数据
// byte[] result = originalData.clone();
// ByteBuffer buffer = ByteBuffer.wrap(result);
// buffer.order(ByteOrder.LITTLE_ENDIAN);
// // 修改指令为写配置(字节2)
// buffer.put(2, CommandConstant.writeConfig);
// // 修改字节68:遥控器配置
// byte remote = 0;
// remote |= (getKnifeMotorMode() & 0x03);
// remote |= (getWalkMotorMode() & 0x03) << 2;
// remote |= (getLeftMotorReverse() & 0x01) << 4;
// remote |= (getRightMotorReverse() & 0x01) << 5;
// remote |= (getSwapChannel() & 0x01) << 6;
// remote |= (getUse4G() & 0x01) << 7;
// buffer.put(68, remote);
// // 修改字节69-72:速度限制
// buffer.putShort(69, getForwardSpeedLimit());
// buffer.putShort(71, getTurnSpeedLimit());
// // 修改字节73:通道极性
// byte b73 = 0;
// b73 |= (getKnifePolarity() & 1);
// b73 |= (getFanPolarity() & 1) << 1;
// b73 |= (getThrottlePolarity() & 1) << 2;
// b73 |= (getLiftProtectTime() & 0x0F) << 3;
// b73 |= (getDualRtk() & 1) << 7;
// buffer.put(73, b73);
// // 修改字节74-77:通道配置
// byte b74 = 0;
// b74 |= (getKnifeChannel() & 0x0F);
// b74 |= (getFanChannel() & 0x0F) << 4;
// buffer.put(74, b74);
// byte b75 = 0;
// b75 |= (getThrottleChannel() & 0x0F);
// b75 |= (getRemoteType() & 0x07) << 4;
// if (isRelayBoard())
// b75 |= 1 << 7;
// buffer.put(75, b75);
// byte b76 = 0;
// b76 |= (getLiftChannel() & 0x0F);
// b76 |= (getChassisChannel() & 0x0F) << 4;
// buffer.put(76, b76);
// byte b77 = 0;
// b77 |= (getArmChannel() & 0x0F);
// b77 |= (getFuelPumpChannel() & 0x0F) << 4;
// buffer.put(77, b77);
// // // 修改字节78-117:WiFi信息
// // byte[] wifiNameBytes = new byte[20];
// // if (getWifiName() != null) {
// // byte[] src = getWifiName().getBytes(StandardCharsets.UTF_8);
// // System.arraycopy(src, 0, wifiNameBytes, 0, Math.min(src.length, 20));
// // }
// // System.arraycopy(wifiNameBytes, 0, result, 78, 20);
// //
// // byte[] wifiPwdBytes = new byte[20];
// // if (getWifiPassword() != null) {
// // byte[] src = getWifiPassword().getBytes(StandardCharsets.UTF_8);
// // System.arraycopy(src, 0, wifiPwdBytes, 0, Math.min(src.length, 20));
// // }
// // System.arraycopy(wifiPwdBytes, 0, result, 98, 20);
// // // 修改字节118:电池和驱动配置
// // byte b118 = 0;
// // b118 |= (getBatteryType() & 0x03);
// // b118 |= (getDriveType() & 0x03) << 2;
// // buffer.put(118, b118);
// // 修改字节119-158:float参数
// buffer.putFloat(119, getGearRatio());
// buffer.putFloat(123, getRobotLength());
// buffer.putFloat(127, getRobotWidth());
// buffer.putFloat(131, getRobotHeight());
// buffer.putFloat(135, getKnifeWidth());
// buffer.putFloat(139, getTyreSize());
// buffer.putFloat(143, getLeftForwardGain());
// buffer.putFloat(147, getLeftBackwardGain());
// buffer.putFloat(151, getRightForwardGain());
// buffer.putFloat(155, getRightBackwardGain());
// // 修改字节159-173:固件版本
// // byte[] fwBytes = new byte[15];
// // if (getFirmwareVersion() != null) {
// // byte[] src = getFirmwareVersion().getBytes(StandardCharsets.UTF_8);
// // System.arraycopy(src, 0, fwBytes, 0, Math.min(src.length, 15));
// // }
// // System.arraycopy(fwBytes, 0, result, 159, 15);
// // 保留原始的 CRC 和尾部,不强制修改
// // 移除以下强制修改:
// // buffer.putShort(174, (short) 0);
// // buffer.put(176, (byte) 0xAA);
// // buffer.put(177, (byte) 0xAB);
// return result;
// }
// public static void putFixedString(ByteBuffer buffer, String value, int len) {
// byte[] bytes = new byte[len];
// if (value != null) {
// byte[] src = value.getBytes(StandardCharsets.UTF_8);
// System.arraycopy(src, 0, bytes, 0, Math.min(src.length, len));
// }
// buffer.put(bytes);
// }
// public static DeviceRunParam fromBytes(byte[] data) {
// // 183
// if (data == null || data.length < 178) {
// throw new IllegalArgumentException("数据长度不足");
// }
// ByteBuffer buffer = ByteBuffer.wrap(data);
// buffer.order(ByteOrder.LITTLE_ENDIAN);
// DeviceRunParam p = new DeviceRunParam();
// p.setOriginalData(data);
@TableField(exist = false)
public byte header1;
@TableField(exist = false)
public byte header2;
@TableField(exist = false)
public byte cmd;
public byte chipUidSign;//芯片UID固化标志位
public String chipUid;//芯片UID
public byte[] remoteConfig;//遥控器通道配置
public int knifeMotorMode;//割刀电机模式
public int walkMotorMode;//行走电机模式
public int leftMotorReverse;//左轮电机方向极性
public int rightMotorReverse;//右轮电机方向极性
public int swapChannel;//左右轮通道互换标志位
public int use4G;//联网标志位
public short forwardSpeedLimit;//前进速度限制
public short turnSpeedLimit;//转向速度限制
public int knifePolarity;//割刀通道极性
public int fanPolarity;//风门通道极性
public int throttlePolarity;//油门通道极性
public int liftProtectTime;//底盘升降电机保护时间
public int dualRtk;//RTK配置
public int knifeChannel;//割刀通道配置
public int fanChannel;//风门通道配置
public int throttleChannel;//油门通道配置
public int remoteType;//遥控器类型
public boolean relayBoard;//是否搭载继电器板
public int liftChannel;//底盘升通道配置
public int chassisChannel;//底盘降通道配置
public int armChannel;//抱闸通道配置
public int fuelPumpChannel;//燃油励磁通道配置
public String wifiName;//wifi名称
public String wifiPassword;//wifi密码
public int batteryType;//电池类型
public int driveType;//行走驱动配置
public float gearRatio;//转速比
public float robotLength;//机器人长度
public float robotWidth;//机器人宽度
public float robotHeight;//机器人高度
public float knifeWidth;//割刀宽度
public float tyreSize;//轮胎尺寸
public float leftForwardGain;//左轮前进增益
public float leftBackwardGain;//左轮后退增益
public float rightForwardGain;//右轮前进增益
public float rightBackwardGain;//右轮后退增益
public String firmwareVersion;//固件版本
@TableField(exist = false)
public int crc16;
@TableField(exist = false)
public byte tail1;
@TableField(exist = false)
public byte tail2;
@TableField(exist = false)
private byte[] originalData;
public static byte[] toReadBytes() {
ByteBuffer buffer = ByteBuffer.allocate(7); // 修改为27字节
buffer.order(ByteOrder.LITTLE_ENDIAN);
buffer.put((byte) 0xAB);
buffer.put((byte) 0xAA);
buffer.put(CommandConstant.readConfig);
buffer.putShort((short) 0);
buffer.put((byte) 0xAA);
buffer.put((byte) 0xAB);
return buffer.array();
}
public byte[] toWriteBytes() {
// 如果没有原始数据,使用静态方法重新构建
if (originalData == null || originalData.length < 178) {
return null;
}
// 克隆原始数据,避免修改原始数据
byte[] result = originalData.clone();
ByteBuffer buffer = ByteBuffer.wrap(result);
buffer.order(ByteOrder.LITTLE_ENDIAN);
// 修改指令为写配置(字节2)
buffer.put(2, CommandConstant.writeConfig);
// 修改字节68:遥控器配置
byte remote = 0;
remote |= (getKnifeMotorMode() & 0x03);
remote |= (getWalkMotorMode() & 0x03) << 2;
remote |= (getLeftMotorReverse() & 0x01) << 4;
remote |= (getRightMotorReverse() & 0x01) << 5;
remote |= (getSwapChannel() & 0x01) << 6;
remote |= (getUse4G() & 0x01) << 7;
buffer.put(68, remote);
// 修改字节69-72:速度限制
buffer.putShort(69, getForwardSpeedLimit());
buffer.putShort(71, getTurnSpeedLimit());
// 修改字节73:通道极性
byte b73 = 0;
b73 |= (getKnifePolarity() & 1);
b73 |= (getFanPolarity() & 1) << 1;
b73 |= (getThrottlePolarity() & 1) << 2;
b73 |= (getLiftProtectTime() & 0x0F) << 3;
b73 |= (getDualRtk() & 1) << 7;
buffer.put(73, b73);
// 修改字节74-77:通道配置
byte b74 = 0;
b74 |= (getKnifeChannel() & 0x0F);
b74 |= (getFanChannel() & 0x0F) << 4;
buffer.put(74, b74);
byte b75 = 0;
b75 |= (getThrottleChannel() & 0x0F);
b75 |= (getRemoteType() & 0x07) << 4;
if (isRelayBoard()) b75 |= 1 << 7;
buffer.put(75, b75);
byte b76 = 0;
b76 |= (getLiftChannel() & 0x0F);
b76 |= (getChassisChannel() & 0x0F) << 4;
buffer.put(76, b76);
byte b77 = 0;
b77 |= (getArmChannel() & 0x0F);
b77 |= (getFuelPumpChannel() & 0x0F) << 4;
buffer.put(77, b77);
// // 修改字节78-117:WiFi信息
// byte[] wifiNameBytes = new byte[20];
// if (getWifiName() != null) {
// byte[] src = getWifiName().getBytes(StandardCharsets.UTF_8);
// System.arraycopy(src, 0, wifiNameBytes, 0, Math.min(src.length, 20));
// }
// System.arraycopy(wifiNameBytes, 0, result, 78, 20);
//
// byte[] wifiPwdBytes = new byte[20];
// if (getWifiPassword() != null) {
// byte[] src = getWifiPassword().getBytes(StandardCharsets.UTF_8);
// System.arraycopy(src, 0, wifiPwdBytes, 0, Math.min(src.length, 20));
// }
// System.arraycopy(wifiPwdBytes, 0, result, 98, 20);
// // 修改字节118:电池和驱动配置
// byte b118 = 0;
// b118 |= (getBatteryType() & 0x03);
// b118 |= (getDriveType() & 0x03) << 2;
// buffer.put(118, b118);
// 修改字节119-158:float参数
buffer.putFloat(119, getGearRatio());
buffer.putFloat(123, getRobotLength());
buffer.putFloat(127, getRobotWidth());
buffer.putFloat(131, getRobotHeight());
buffer.putFloat(135, getKnifeWidth());
buffer.putFloat(139, getTyreSize());
buffer.putFloat(143, getLeftForwardGain());
buffer.putFloat(147, getLeftBackwardGain());
buffer.putFloat(151, getRightForwardGain());
buffer.putFloat(155, getRightBackwardGain());
// 修改字节159-173:固件版本
// byte[] fwBytes = new byte[15];
// if (getFirmwareVersion() != null) {
// byte[] src = getFirmwareVersion().getBytes(StandardCharsets.UTF_8);
// System.arraycopy(src, 0, fwBytes, 0, Math.min(src.length, 15));
// }
// System.arraycopy(fwBytes, 0, result, 159, 15);
// 保留原始的 CRC 和尾部,不强制修改
// 移除以下强制修改:
// buffer.putShort(174, (short) 0);
// buffer.put(176, (byte) 0xAA);
// buffer.put(177, (byte) 0xAB);
return result;
}
public static void putFixedString(ByteBuffer buffer, String value, int len) {
byte[] bytes = new byte[len];
if (value != null) {
byte[] src = value.getBytes(StandardCharsets.UTF_8);
System.arraycopy(src, 0, bytes, 0, Math.min(src.length, len));
}
buffer.put(bytes);
}
public static DeviceRunParam fromBytes(byte[] data) {
// 183
if (data == null || data.length < 178) {
throw new IllegalArgumentException("数据长度不足");
}
ByteBuffer buffer = ByteBuffer.wrap(data);
buffer.order(ByteOrder.LITTLE_ENDIAN);
DeviceRunParam p = new DeviceRunParam();
// p.setHeader1(buffer.get());
// p.setHeader2(buffer.get());
p.setOriginalData(data);
// p.setCmd(buffer.get());
p.setHeader1(buffer.get());
p.setHeader2(buffer.get());
// p.setChipUidSign(buffer.get());
p.setCmd(buffer.get());
// p.setChipUid(readString(buffer, 45));
p.setChipUidSign(buffer.get());
// // 跳过字节49-67(共19字节,预留不用)
// buffer.position(buffer.position() + 19);
p.setChipUid(readString(buffer, 45));
// byte remote = buffer.get();
// 跳过字节49-67(共19字节,预留不用)
buffer.position(buffer.position() + 19);
// // p.setRemoteConfig(remote);
byte remote = buffer.get();
// p.setKnifeMotorMode(remote & 0x03);
// p.setWalkMotorMode((remote >> 2) & 0x03);
// p.setLeftMotorReverse((remote >> 4) & 0x01);
// p.setRightMotorReverse((remote >> 5) & 0x01);
// p.setSwapChannel((remote >> 6) & 0x01);
// p.setUse4G((remote >> 7) & 0x01);
// p.setRemoteConfig(remote);
// p.setForwardSpeedLimit(buffer.getShort());
// p.setTurnSpeedLimit(buffer.getShort());
p.setKnifeMotorMode(remote & 0x03);
p.setWalkMotorMode((remote >> 2) & 0x03);
p.setLeftMotorReverse((remote >> 4) & 0x01);
p.setRightMotorReverse((remote >> 5) & 0x01);
p.setSwapChannel((remote >> 6) & 0x01);
p.setUse4G((remote >> 7) & 0x01);
// byte b73 = buffer.get();
p.setForwardSpeedLimit(buffer.getShort());
p.setTurnSpeedLimit(buffer.getShort());
// p.setKnifePolarity(b73 & 1);
// p.setFanPolarity((b73 >> 1) & 1);
// p.setThrottlePolarity((b73 >> 2) & 1);
// p.setLiftProtectTime((b73 >> 3) & 0x0F);
// p.setDualRtk((b73 >> 7) & 1);
byte b73 = buffer.get();
// byte b74 = buffer.get();
p.setKnifePolarity(b73 & 1);
p.setFanPolarity((b73 >> 1) & 1);
p.setThrottlePolarity((b73 >> 2) & 1);
p.setLiftProtectTime((b73 >> 3) & 0x0F);
p.setDualRtk((b73 >> 7) & 1);
// p.setKnifeChannel(b74 & 0x0F);
// p.setFanChannel((b74 >> 4) & 0x0F);
byte b74 = buffer.get();
// byte b75 = buffer.get();
p.setKnifeChannel(b74 & 0x0F);
p.setFanChannel((b74 >> 4) & 0x0F);
// p.setThrottleChannel(b75 & 0x0F);
// p.setRemoteType((b75 >> 4) & 0x07);
// p.setRelayBoard(((b75 >> 7) & 1) == 1);
byte b75 = buffer.get();
// byte b76 = buffer.get();
p.setThrottleChannel(b75 & 0x0F);
p.setRemoteType((b75 >> 4) & 0x07);
p.setRelayBoard(((b75 >> 7) & 1) == 1);
// p.setLiftChannel(b76 & 0x0F);
// p.setChassisChannel((b76 >> 4) & 0x0F);
byte b76 = buffer.get();
// byte b77 = buffer.get();
p.setLiftChannel(b76 & 0x0F);
p.setChassisChannel((b76 >> 4) & 0x0F);
// p.setArmChannel(b77 & 0x0F);
// p.setFuelPumpChannel((b77 >> 4) & 0x0F);
byte b77 = buffer.get();
// p.setWifiName(readString(buffer, 20));
// p.setWifiPassword(readString(buffer, 20));
p.setArmChannel(b77 & 0x0F);
p.setFuelPumpChannel((b77 >> 4) & 0x0F);
// byte b118 = buffer.get();
p.setWifiName(readString(buffer, 20));
p.setWifiPassword(readString(buffer, 20));
// p.setBatteryType(b118 & 0x03);
// p.setDriveType((b118 >> 2) & 0x03);
byte b118 = buffer.get();
// // float
// p.setGearRatio(buffer.getFloat());
// p.setRobotLength(buffer.getFloat());
// p.setRobotWidth(buffer.getFloat());
// p.setRobotHeight(buffer.getFloat());
// p.setKnifeWidth(buffer.getFloat());
// p.setTyreSize(buffer.getFloat());
// p.setLeftForwardGain(buffer.getFloat());
// p.setLeftBackwardGain(buffer.getFloat());
// p.setRightForwardGain(buffer.getFloat());
// p.setRightBackwardGain(buffer.getFloat());
p.setBatteryType(b118 & 0x03);
p.setDriveType((b118 >> 2) & 0x03);
// p.setFirmwareVersion(readString(buffer, 15));
// float
p.setGearRatio(buffer.getFloat());
p.setRobotLength(buffer.getFloat());
p.setRobotWidth(buffer.getFloat());
p.setRobotHeight(buffer.getFloat());
p.setKnifeWidth(buffer.getFloat());
p.setTyreSize(buffer.getFloat());
p.setLeftForwardGain(buffer.getFloat());
p.setLeftBackwardGain(buffer.getFloat());
p.setRightForwardGain(buffer.getFloat());
p.setRightBackwardGain(buffer.getFloat());
// p.setCrc16(Short.toUnsignedInt(buffer.getShort()));
p.setFirmwareVersion(readString(buffer, 15));
// p.setTail1(buffer.get());
// p.setTail2(buffer.get());
p.setCrc16(Short.toUnsignedInt(buffer.getShort()));
// return p;
// }
p.setTail1(buffer.get());
p.setTail2(buffer.get());
// public static String readString(ByteBuffer buffer, int len) {
// byte[] bytes = new byte[len];
// buffer.get(bytes);
return p;
}
// int end = 0;
// while (end < bytes.length && bytes[end] != 0) {
// end++;
// }
public static String readString(ByteBuffer buffer, int len) {
byte[] bytes = new byte[len];
buffer.get(bytes);
int end = 0;
while (end < bytes.length && bytes[end] != 0) {
end++;
}
return new String(bytes, 0, end, StandardCharsets.UTF_8);
}
// return new String(bytes, 0, end, StandardCharsets.UTF_8);
// }
}

View File

@@ -246,24 +246,24 @@ public class NettyDevice extends Connector {
}
}
public void readConfigCommand() {
byte[] bytes = DeviceRunParam.toReadBytes();
log.debug("下发读取配置的报文:{}", toHexString(bytes));
if (this.getChannel() != null && this.getChannel().isActive()) {
this.getChannel().writeAndFlush(Unpooled.wrappedBuffer(bytes));
}
log.debug("下发读取配置的报文完成:{}", toHexString(bytes));
}
// public void readConfigCommand() {
// byte[] bytes = DeviceRunParam.toReadBytes();
// log.debug("下发读取配置的报文:{}", toHexString(bytes));
// if (this.getChannel() != null && this.getChannel().isActive()) {
// this.getChannel().writeAndFlush(Unpooled.wrappedBuffer(bytes));
// }
// log.debug("下发读取配置的报文完成:{}", toHexString(bytes));
// }
public void writeConfigCommand(DeviceRunParam deviceRunParam) {
log.debug("下发修改配置的属性:{}", JsonUtils.toJsonString(deviceRunParam));
byte[] bytes = deviceRunParam.toWriteBytes();
log.debug("下发修改配置的报文:{}", toHexString(bytes));
if (this.getChannel() != null && this.getChannel().isActive()) {
this.getChannel().writeAndFlush(Unpooled.wrappedBuffer(bytes));
}
log.debug("下发修改配置的报文完成:{}", toHexString(bytes));
}
// public void writeConfigCommand(DeviceRunParam deviceRunParam) {
// log.debug("下发修改配置的属性:{}", JsonUtils.toJsonString(deviceRunParam));
// byte[] bytes = deviceRunParam.toWriteBytes();
// log.debug("下发修改配置的报文:{}", toHexString(bytes));
// if (this.getChannel() != null && this.getChannel().isActive()) {
// this.getChannel().writeAndFlush(Unpooled.wrappedBuffer(bytes));
// }
// log.debug("下发修改配置的报文完成:{}", toHexString(bytes));
// }
// todo 优化
public synchronized boolean pauseTask() {

View File

@@ -4,11 +4,11 @@ import lombok.Data;
@Data
public class ParamDetail {
private short left_wheel_rpm; // 左轮转速
private short right_wheel_rpm; // 右轮转速
// private short left_wheel_rpm; // 左轮转速
// private short right_wheel_rpm; // 右轮转速
private double linear_speed; // 线速度
private double angular_speed; // 角速度
private double linear_x; // 线速度
private double angular_z; // 角速度
private int chassis_lift; // 底盘升降 0:停止 1:升 2:降
private int cutter; // 割刀加减速 0:停止 1:加速 2:减速

View File

@@ -31,4 +31,7 @@ public class VehicleMessage {
private double roll;// 实时翻滚角度
private String control_mode;// 遥控器拨杆对应的当前控制模式
private double linear_speed; // 实时线速度
private double angular_speed; // 实时角速度
}

View File

@@ -154,7 +154,7 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
String.format(MqttTopic.DEVICE_LOCATION_MESSAGE_TOPIC, deviceId),
JsonUtils.toJsonString(locationRelTimeDTO));
} catch (MqttException e) {
log.error("位置实时数据推送失败: deviceId={}, error={}", deviceId, e.getMessage(), e);
log.error("位置实时数据推送失败: deviceId={}, error={}", deviceId, e.getMessage(), e);
}
}
@@ -399,6 +399,18 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
control_mode.setUnit("");
transferData.add(control_mode);
DeviceStatusDetail linear_speed = new DeviceStatusDetail();
linear_speed.setName("linear_speed");
linear_speed.setValue(String.valueOf(vehicleRelTimeDTO.getData().getLinear_speed()));
linear_speed.setUnit("");
transferData.add(linear_speed);
DeviceStatusDetail angular_speed = new DeviceStatusDetail();
angular_speed.setName("angular_speed");
angular_speed.setValue(String.valueOf(vehicleRelTimeDTO.getData().getAngular_speed()));
angular_speed.setUnit("");
transferData.add(angular_speed);
webStatusMessageDTO.setData(transferData);
webStatusMessageDTO.setType(MesType.deviceInfo);
return webStatusMessageDTO;
@@ -447,13 +459,13 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
}
}
}
// todo 推送实时位置和状态消息到外部
// todo 推送实时位置和状态消息到外部
try {
GlobalMemory.customMqttDeviceMonitor.publish(mqttClientId,
String.format(MqttTopic.DEVICE_VEHICLE_MESSAGE_TOPIC, deviceId),
JsonUtils.toJsonString(vehicleRelTimeDTO));
} catch (MqttException e) {
log.error("位置实时数据推送失败: deviceId={}, error={}", deviceId, e.getMessage(), e);
log.error("位置实时数据推送失败: deviceId={}, error={}", deviceId, e.getMessage(), e);
}
}
} catch (Exception e) {