#实时消息和参数

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; package com.maibu.core.business;
import java.time.LocalDate;
import java.util.List;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.maibu.annotation.Excel; import com.maibu.annotation.Excel;
import com.maibu.constant.CommandConstant;
import com.maibu.core.domain.BaseDO; import com.maibu.core.domain.BaseDO;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import java.util.List;
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@Data @Data
@TableName(value = "iot_device_run_param", autoResultMap = true) @TableName(value = "iot_device_run_param", autoResultMap = true)
@@ -64,327 +61,401 @@ public class DeviceRunParam extends BaseDO {
@TableField(exist = false) @TableField(exist = false)
private String capabilities; 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) @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;
@TableField(exist = false) // public byte chipUidSign;// 芯片UID固化标志位
public byte header1; // public String chipUid;// 芯片UID
@TableField(exist = false)
public byte header2;
@TableField(exist = false)
public byte cmd;
// public byte[] remoteConfig;// 遥控器通道配置
// public int knifeMotorMode;// 割刀电机模式
// public int walkMotorMode;// 行走电机模式
// public int leftMotorReverse;// 左轮电机方向极性
// public int rightMotorReverse;// 右轮电机方向极性
// public int swapChannel;// 左右轮通道互换标志位
// public int use4G;// 联网标志位
public byte chipUidSign;//芯片UID固化标志位 // public short forwardSpeedLimit;// 前进速度限制
public String chipUid;//芯片UID // public short turnSpeedLimit;// 转向速度限制
public byte[] remoteConfig;//遥控器通道配置 // public int knifePolarity;// 割刀通道极性
public int knifeMotorMode;//割刀电机模式 // public int fanPolarity;// 风门通道极性
public int walkMotorMode;//行走电机模式 // public int throttlePolarity;// 油门通道极性
public int leftMotorReverse;//左轮电机方向极性 // public int liftProtectTime;// 底盘升降电机保护时间
public int rightMotorReverse;//右轮电机方向极性 // public int dualRtk;// RTK配置
public int swapChannel;//左右轮通道互换标志位
public int use4G;//联网标志位
public short forwardSpeedLimit;//前进速度限制 // public int knifeChannel;// 割刀通道配置
public short turnSpeedLimit;//转向速度限制 // public int fanChannel;// 风门通道配置
public int knifePolarity;//割刀通道极性 // public int throttleChannel;// 油门通道配置
public int fanPolarity;//风门通道极性 // public int remoteType;// 遥控器类型
public int throttlePolarity;//油门通道极性 // public boolean relayBoard;// 是否搭载继电器板
public int liftProtectTime;//底盘升降电机保护时间
public int dualRtk;//RTK配置
// public int liftChannel;// 底盘升通道配置
// public int chassisChannel;// 底盘降通道配置
public int knifeChannel;//割刀通道配置 // public int armChannel;// 抱闸通道配置
public int fanChannel;//风门通道配置 // public int fuelPumpChannel;// 燃油励磁通道配置
public int throttleChannel;//油门通道配置 // public String wifiName;// wifi名称
public int remoteType;//遥控器类型 // public String wifiPassword;// wifi密码
public boolean relayBoard;//是否搭载继电器板
public int liftChannel;//底盘升通道配置 // public int batteryType;// 电池类型
public int chassisChannel;//底盘降通道配置 // public int driveType;// 行走驱动配置
public int armChannel;//抱闸通道配置 // public float gearRatio;// 转速比
public int fuelPumpChannel;//燃油励磁通道配置 // 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 wifiName;//wifi名称 // public String firmwareVersion;// 固件版本
public String wifiPassword;//wifi密码 // @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 int batteryType;//电池类型 // public static byte[] toReadBytes() {
public int driveType;//行走驱动配置 // ByteBuffer buffer = ByteBuffer.allocate(7); // 修改为27字节
// buffer.order(ByteOrder.LITTLE_ENDIAN);
public float gearRatio;//转速比 // buffer.put((byte) 0xAB);
public float robotLength;//机器人长度 // buffer.put((byte) 0xAA);
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;//固件版本 // buffer.put(CommandConstant.readConfig);
@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() { // buffer.putShort((short) 0);
ByteBuffer buffer = ByteBuffer.allocate(7); // 修改为27字节
buffer.order(ByteOrder.LITTLE_ENDIAN);
buffer.put((byte) 0xAB); // buffer.put((byte) 0xAA);
buffer.put((byte) 0xAA); // buffer.put((byte) 0xAB);
buffer.put(CommandConstant.readConfig); // return buffer.array();
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);
// // public byte[] toWriteBytes() {
// byte[] wifiPwdBytes = new byte[20]; // // 如果没有原始数据,使用静态方法重新构建
// if (getWifiPassword() != null) { // if (originalData == null || originalData.length < 178) {
// byte[] src = getWifiPassword().getBytes(StandardCharsets.UTF_8); // return null;
// System.arraycopy(src, 0, wifiPwdBytes, 0, Math.min(src.length, 20));
// } // }
// System.arraycopy(wifiPwdBytes, 0, result, 98, 20);
// // 修改字节118:电池和驱动配置 // // 克隆原始数据,避免修改原始数据
// byte b118 = 0; // byte[] result = originalData.clone();
// b118 |= (getBatteryType() & 0x03); // ByteBuffer buffer = ByteBuffer.wrap(result);
// b118 |= (getDriveType() & 0x03) << 2; // buffer.order(ByteOrder.LITTLE_ENDIAN);
// buffer.put(118, b118);
// 修改字节119-158:float参数 // // 修改指令为写配置(字节2)
buffer.putFloat(119, getGearRatio()); // buffer.put(2, CommandConstant.writeConfig);
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:固件版本 // // 修改字节68:遥控器配置
// byte[] fwBytes = new byte[15]; // byte remote = 0;
// if (getFirmwareVersion() != null) { // remote |= (getKnifeMotorMode() & 0x03);
// byte[] src = getFirmwareVersion().getBytes(StandardCharsets.UTF_8); // remote |= (getWalkMotorMode() & 0x03) << 2;
// System.arraycopy(src, 0, fwBytes, 0, Math.min(src.length, 15)); // 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;
// } // }
// System.arraycopy(fwBytes, 0, result, 159, 15);
// 保留原始的 CRC 和尾部,不强制修改 // public static void putFixedString(ByteBuffer buffer, String value, int len) {
// 移除以下强制修改:
// buffer.putShort(174, (short) 0);
// buffer.put(176, (byte) 0xAA);
// buffer.put(177, (byte) 0xAB);
return result; // byte[] bytes = new byte[len];
}
public static void putFixedString(ByteBuffer buffer, String value, int len) { // if (value != null) {
// byte[] src = value.getBytes(StandardCharsets.UTF_8);
byte[] bytes = new byte[len]; // System.arraycopy(src, 0, bytes, 0, Math.min(src.length, len));
// }
if (value != null) { // buffer.put(bytes);
byte[] src = value.getBytes(StandardCharsets.UTF_8); // }
System.arraycopy(src, 0, bytes, 0, Math.min(src.length, len)); // public static DeviceRunParam fromBytes(byte[] data) {
} // // 183
// if (data == null || data.length < 178) {
// throw new IllegalArgumentException("数据长度不足");
// }
buffer.put(bytes); // ByteBuffer buffer = ByteBuffer.wrap(data);
} // buffer.order(ByteOrder.LITTLE_ENDIAN);
// DeviceRunParam p = new DeviceRunParam();
public static DeviceRunParam fromBytes(byte[] data) { // p.setOriginalData(data);
// 183
if (data == null || data.length < 178) {
throw new IllegalArgumentException("数据长度不足");
}
ByteBuffer buffer = ByteBuffer.wrap(data); // p.setHeader1(buffer.get());
buffer.order(ByteOrder.LITTLE_ENDIAN); // p.setHeader2(buffer.get());
DeviceRunParam p = new DeviceRunParam(); // p.setCmd(buffer.get());
p.setOriginalData(data); // p.setChipUidSign(buffer.get());
p.setHeader1(buffer.get()); // p.setChipUid(readString(buffer, 45));
p.setHeader2(buffer.get());
p.setCmd(buffer.get()); // // 跳过字节49-67(共19字节,预留不用)
// buffer.position(buffer.position() + 19);
p.setChipUidSign(buffer.get()); // byte remote = buffer.get();
p.setChipUid(readString(buffer, 45)); // // p.setRemoteConfig(remote);
// 跳过字节49-67(共19字节,预留不用) // p.setKnifeMotorMode(remote & 0x03);
buffer.position(buffer.position() + 19); // 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 remote = buffer.get(); // p.setForwardSpeedLimit(buffer.getShort());
// p.setTurnSpeedLimit(buffer.getShort());
// p.setRemoteConfig(remote); // byte b73 = buffer.get();
p.setKnifeMotorMode(remote & 0x03); // p.setKnifePolarity(b73 & 1);
p.setWalkMotorMode((remote >> 2) & 0x03); // p.setFanPolarity((b73 >> 1) & 1);
p.setLeftMotorReverse((remote >> 4) & 0x01); // p.setThrottlePolarity((b73 >> 2) & 1);
p.setRightMotorReverse((remote >> 5) & 0x01); // p.setLiftProtectTime((b73 >> 3) & 0x0F);
p.setSwapChannel((remote >> 6) & 0x01); // p.setDualRtk((b73 >> 7) & 1);
p.setUse4G((remote >> 7) & 0x01);
p.setForwardSpeedLimit(buffer.getShort()); // byte b74 = buffer.get();
p.setTurnSpeedLimit(buffer.getShort());
byte b73 = buffer.get(); // p.setKnifeChannel(b74 & 0x0F);
// p.setFanChannel((b74 >> 4) & 0x0F);
p.setKnifePolarity(b73 & 1); // byte b75 = buffer.get();
p.setFanPolarity((b73 >> 1) & 1);
p.setThrottlePolarity((b73 >> 2) & 1);
p.setLiftProtectTime((b73 >> 3) & 0x0F);
p.setDualRtk((b73 >> 7) & 1);
byte b74 = buffer.get(); // p.setThrottleChannel(b75 & 0x0F);
// p.setRemoteType((b75 >> 4) & 0x07);
// p.setRelayBoard(((b75 >> 7) & 1) == 1);
p.setKnifeChannel(b74 & 0x0F); // byte b76 = buffer.get();
p.setFanChannel((b74 >> 4) & 0x0F);
byte b75 = buffer.get(); // p.setLiftChannel(b76 & 0x0F);
// p.setChassisChannel((b76 >> 4) & 0x0F);
p.setThrottleChannel(b75 & 0x0F); // byte b77 = buffer.get();
p.setRemoteType((b75 >> 4) & 0x07);
p.setRelayBoard(((b75 >> 7) & 1) == 1);
byte b76 = buffer.get(); // p.setArmChannel(b77 & 0x0F);
// p.setFuelPumpChannel((b77 >> 4) & 0x0F);
p.setLiftChannel(b76 & 0x0F); // p.setWifiName(readString(buffer, 20));
p.setChassisChannel((b76 >> 4) & 0x0F); // p.setWifiPassword(readString(buffer, 20));
byte b77 = buffer.get(); // byte b118 = buffer.get();
p.setArmChannel(b77 & 0x0F); // p.setBatteryType(b118 & 0x03);
p.setFuelPumpChannel((b77 >> 4) & 0x0F); // p.setDriveType((b118 >> 2) & 0x03);
p.setWifiName(readString(buffer, 20)); // // float
p.setWifiPassword(readString(buffer, 20)); // 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());
byte b118 = buffer.get(); // p.setFirmwareVersion(readString(buffer, 15));
p.setBatteryType(b118 & 0x03); // p.setCrc16(Short.toUnsignedInt(buffer.getShort()));
p.setDriveType((b118 >> 2) & 0x03);
// float // p.setTail1(buffer.get());
p.setGearRatio(buffer.getFloat()); // p.setTail2(buffer.get());
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.setFirmwareVersion(readString(buffer, 15)); // return p;
// }
p.setCrc16(Short.toUnsignedInt(buffer.getShort())); // public static String readString(ByteBuffer buffer, int len) {
// byte[] bytes = new byte[len];
// buffer.get(bytes);
p.setTail1(buffer.get()); // int end = 0;
p.setTail2(buffer.get()); // while (end < bytes.length && bytes[end] != 0) {
// end++;
// }
return p; // return new String(bytes, 0, end, StandardCharsets.UTF_8);
} // }
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);
}
} }

View File

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

View File

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

View File

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

View File

@@ -399,6 +399,18 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
control_mode.setUnit(""); control_mode.setUnit("");
transferData.add(control_mode); 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.setData(transferData);
webStatusMessageDTO.setType(MesType.deviceInfo); webStatusMessageDTO.setType(MesType.deviceInfo);
return webStatusMessageDTO; return webStatusMessageDTO;

View File

@@ -83,7 +83,7 @@ public class CommandForwardHandler extends SimpleChannelInboundHandler<String> {
} }
for (Connector target : connectedDevices) { for (Connector target : connectedDevices) {
if (!target.canReceive()) { if (target == null || !target.canReceive()) {
logger.debug("发送拒绝master:{},消息到达的slave设备:{},处于禁止接收状态", senderDeviceId, target.getConnectorId()); logger.debug("发送拒绝master:{},消息到达的slave设备:{},处于禁止接收状态", senderDeviceId, target.getConnectorId());
continue; continue;
} }
@@ -110,8 +110,8 @@ public class CommandForwardHandler extends SimpleChannelInboundHandler<String> {
.setScale(2, RoundingMode.HALF_UP) .setScale(2, RoundingMode.HALF_UP)
.doubleValue(); .doubleValue();
data.setLinear_speed(linearSpeed); data.setLinear_x(linearSpeed);
data.setAngular_speed(angularSpeed); data.setAngular_z(angularSpeed);
data.setChassis_lift(pEntity.getChassisLiftFlag()); data.setChassis_lift(pEntity.getChassisLiftFlag());
data.setCutter(pEntity.getMowerSpeedFlag()); data.setCutter(pEntity.getMowerSpeedFlag());

View File

@@ -140,13 +140,13 @@ public class DataToDataBaseHandler extends SimpleChannelInboundHandler<String> {
nettyDevice.setLatestStatus(latestStatus); nettyDevice.setLatestStatus(latestStatus);
} }
} else if (bytes[2] == CommandConstant.readConfig) { } else if (bytes[2] == CommandConstant.readConfig) {
DeviceRunParam runParam = DeviceRunParam.fromBytes(bytes); // DeviceRunParam runParam = DeviceRunParam.fromBytes(bytes);
logger.debug("收到返回的设备运行参数: {}", JsonUtils.toJsonString(runParam)); // logger.debug("收到返回的设备运行参数: {}", JsonUtils.toJsonString(runParam));
CompletableFuture<DeviceRunParam> future = ctx.channel().attr(Constant.READ_CONFIG_KEY).get(); // CompletableFuture<DeviceRunParam> future = ctx.channel().attr(Constant.READ_CONFIG_KEY).get();
if (future != null) { // if (future != null) {
future.complete(runParam); // future.complete(runParam);
ctx.channel().attr(Constant.READ_CONFIG_KEY).set(null); // ctx.channel().attr(Constant.READ_CONFIG_KEY).set(null);
} // }
} }
ctx.fireChannelRead(msg); ctx.fireChannelRead(msg);
} catch (Exception e) { } catch (Exception e) {

View File

@@ -75,20 +75,20 @@ public class ScheduledTask {
System.out.println("0点定时刷新状态执行完成"); System.out.println("0点定时刷新状态执行完成");
} }
public static void main(String[] args) throws DecoderException { // public static void main(String[] args) throws DecoderException {
String hex = "AB AA 05 88 4D 43 37 30 30 50 4C 55 53 2D 43 4E 2D 4A 53 2D 31 37 38 34 38 37 31 39 37 39 31 39 30 2D 30 30 30 30 30 30 30 41 2D 36 30 00 B1 FB 7F FE FE FE 00 00 00 00 00 00 00 00 00 00 00 00 00 12 01 48 95 E8 03 E8 03 28 32 91 53 24 4D 43 37 30 30 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 31 32 33 34 35 36 37 38 00 00 00 00 00 00 00 00 00 00 00 00 00 08 00 00 00 CD CC A4 41 00 00 80 3F 33 33 33 3F B8 1E 05 3F 33 33 33 3F 9A 99 19 3E 00 00 80 3F 00 00 80 3F 00 00 80 3F 32 36 2D 34 2D 32 37 00 2D 32 37 00 50 B1 BF 00 00 AA AB"; // String hex = "AB AA 05 88 4D 43 37 30 30 50 4C 55 53 2D 43 4E 2D 4A 53 2D 31 37 38 34 38 37 31 39 37 39 31 39 30 2D 30 30 30 30 30 30 30 41 2D 36 30 00 B1 FB 7F FE FE FE 00 00 00 00 00 00 00 00 00 00 00 00 00 12 01 48 95 E8 03 E8 03 28 32 91 53 24 4D 43 37 30 30 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 31 32 33 34 35 36 37 38 00 00 00 00 00 00 00 00 00 00 00 00 00 08 00 00 00 CD CC A4 41 00 00 80 3F 33 33 33 3F B8 1E 05 3F 33 33 33 3F 9A 99 19 3E 00 00 80 3F 00 00 80 3F 00 00 80 3F 32 36 2D 34 2D 32 37 00 2D 32 37 00 50 B1 BF 00 00 AA AB";
String cleanHex = hex.replaceAll("\\s+", ""); // 移除所有空白字符 // String cleanHex = hex.replaceAll("\\s+", ""); // 移除所有空白字符
byte[] bytes = Hex.decodeHex(cleanHex); // byte[] bytes = Hex.decodeHex(cleanHex);
DeviceRunParam runParam = DeviceRunParam.fromBytes(bytes); // DeviceRunParam runParam = DeviceRunParam.fromBytes(bytes);
System.out.println(JsonUtils.toJsonString(runParam)); // System.out.println(JsonUtils.toJsonString(runParam));
runParam.setLeftBackwardGain(0.2f); // runParam.setLeftBackwardGain(0.2f);
runParam.setLeftForwardGain(0.2f); // runParam.setLeftForwardGain(0.2f);
runParam.setRightForwardGain(0.2f); // runParam.setRightForwardGain(0.2f);
runParam.setRightBackwardGain(0.2f); // runParam.setRightBackwardGain(0.2f);
byte[] newB = runParam.toWriteBytes(); // byte[] newB = runParam.toWriteBytes();
System.out.println(Hex.encodeHexString(newB)); // System.out.println(Hex.encodeHexString(newB));
} // }
} }

View File

@@ -43,7 +43,6 @@ public class TransferDeviceService {
@Autowired @Autowired
private DeviceMapper deviceMapper; private DeviceMapper deviceMapper;
public AjaxResult bind(DeviceBindDTO bindDTO, LoginUser user) { public AjaxResult bind(DeviceBindDTO bindDTO, LoginUser user) {
try { try {
String deviceId = bindDTO.getDeviceId(); String deviceId = bindDTO.getDeviceId();
@@ -109,11 +108,14 @@ public class TransferDeviceService {
if (deviceMaster != null) { if (deviceMaster != null) {
String oldSlave = userClient.getDeviceName(); String oldSlave = userClient.getDeviceName();
// 删除主的连接关系 // 删除主的连接关系
deviceMaster.getConnectedConnectors().removeIf(x -> x.getConnectorId().equals(oldSlave)); deviceMaster.getConnectedConnectors()
.removeIf(x -> x.getConnectorId().equals(oldSlave));
// 删除从的连接关系 // 删除从的连接关系
NettyDevice oldSlaveDevice = sessionManager.getDevice(oldSlave); NettyDevice oldSlaveDevice = sessionManager.getDevice(oldSlave);
if (oldSlaveDevice != null && !CollectionUtils.isEmpty(oldSlaveDevice.getConnectedConnectors())) { if (oldSlaveDevice != null
Set<com.maibu.core.business.device.Connector> connectedDevices = oldSlaveDevice.getConnectedConnectors(); && !CollectionUtils.isEmpty(oldSlaveDevice.getConnectedConnectors())) {
Set<com.maibu.core.business.device.Connector> connectedDevices = oldSlaveDevice
.getConnectedConnectors();
connectedDevices.removeIf(x -> x.getConnectorId().equals(masterId)); connectedDevices.removeIf(x -> x.getConnectorId().equals(masterId));
} }
} }
@@ -130,7 +132,6 @@ public class TransferDeviceService {
} }
} }
public AjaxResult updateDeviceAlias(DeviceBindDTO bindDTO, LoginUser user) { public AjaxResult updateDeviceAlias(DeviceBindDTO bindDTO, LoginUser user) {
try { try {
String deviceId = bindDTO.getDeviceId(); String deviceId = bindDTO.getDeviceId();
@@ -158,7 +159,8 @@ public class TransferDeviceService {
} }
} }
// public synchronized boolean switchDevice(DeviceBindDTO bindDTO, LoginUser user) { // public synchronized boolean switchDevice(DeviceBindDTO bindDTO, LoginUser
// user) {
// try { // try {
// String slaveId = bindDTO.getDeviceId(); // String slaveId = bindDTO.getDeviceId();
// String platform = bindDTO.getPlatform(); // String platform = bindDTO.getPlatform();
@@ -228,7 +230,6 @@ public class TransferDeviceService {
// String masterId = userName + ":" + platform; // String masterId = userName + ":" + platform;
String token = bindDTO.getToken(); String token = bindDTO.getToken();
log.info("switchDevice slaveId:{},token:{}", slaveId, token); log.info("switchDevice slaveId:{},token:{}", slaveId, token);
@@ -247,7 +248,8 @@ public class TransferDeviceService {
sessionManager.lock(slaveId, token); sessionManager.lock(slaveId, token);
log.info("switchDevice bindConnector slaveId:{},token:{}", slaveId, token); log.info("switchDevice bindConnector slaveId:{},token:{}", slaveId, token);
} else { } else {
List<String> connectorIds = controls.stream().map(NettyDevice::getConnectorId).collect(Collectors.toList()); List<String> connectorIds = controls.stream().map(NettyDevice::getConnectorId)
.collect(Collectors.toList());
if (!connectorIds.contains(token)) { if (!connectorIds.contains(token)) {
// 当前的设备有控制 的主机 // 当前的设备有控制 的主机
deviceMaster.getConnectedConnectors().clear(); deviceMaster.getConnectedConnectors().clear();
@@ -264,12 +266,11 @@ public class TransferDeviceService {
} }
return true; return true;
} catch (Exception e) { } catch (Exception e) {
log.error("切换设备失败: {}", e.getMessage(), e); log.error("切换设备失败", e);
} }
return false; return false;
} }
public DeviceControlDTO remoteControl(DeviceBindDTO bindDTO) { public DeviceControlDTO remoteControl(DeviceBindDTO bindDTO) {
try { try {
String token = bindDTO.getToken(); String token = bindDTO.getToken();
@@ -290,7 +291,6 @@ public class TransferDeviceService {
return null; return null;
} }
public DeviceSwitchControlDTO switchControl(DeviceBindDTO bindDTO, LoginUser user) { public DeviceSwitchControlDTO switchControl(DeviceBindDTO bindDTO, LoginUser user) {
try { try {
String slaveId = bindDTO.getDeviceId(); String slaveId = bindDTO.getDeviceId();
@@ -333,7 +333,8 @@ public class TransferDeviceService {
} }
masterDevice.setCurrentSlaveId(slaveId); masterDevice.setCurrentSlaveId(slaveId);
masterDevice.setConnectorStatus(ConnectorStatus.ACTIVE); masterDevice.setConnectorStatus(ConnectorStatus.ACTIVE);
// sysUserClientService.updateAliveStatus(masterDevice.getConnectorId(), slaveId, 1); // sysUserClientService.updateAliveStatus(masterDevice.getConnectorId(),
// slaveId, 1);
dto.setSwitchControl(true); dto.setSwitchControl(true);
dto.setHolder(platform); dto.setHolder(platform);

View File

@@ -8,13 +8,20 @@ import com.maibu.dto.BaseQueryDTO;
import com.maibu.service.impl.DeviceRunParamService; import com.maibu.service.impl.DeviceRunParamService;
import com.maibu.utils.poi.ExcelUtil; import com.maibu.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;
import java.util.List; import java.util.List;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
@RestController @RestController
@RequestMapping("/iot/deviceRunParam") @RequestMapping("/iot/deviceRunParam")
public class DeviceRunParamController extends BaseController { public class DeviceRunParamController extends BaseController {
@@ -23,7 +30,7 @@ public class DeviceRunParamController extends BaseController {
private DeviceRunParamService service; private DeviceRunParamService service;
@PostMapping("/save") @PostMapping("/save")
public AjaxResult save(@RequestBody DeviceRunParam deviceRunParam) throws ExecutionException, InterruptedException, TimeoutException { public AjaxResult save(@RequestBody DeviceRunParam deviceRunParam) {
return AjaxResult.success(service.save(deviceRunParam)); return AjaxResult.success(service.save(deviceRunParam));
} }
@@ -35,7 +42,8 @@ public class DeviceRunParamController extends BaseController {
} }
@GetMapping("/selectByDeviceId") @GetMapping("/selectByDeviceId")
public AjaxResult selectByDeviceId(@RequestParam String deviceId) throws ExecutionException, InterruptedException, TimeoutException { public AjaxResult selectByDeviceId(@RequestParam String deviceId)
throws ExecutionException, InterruptedException, TimeoutException {
return AjaxResult.success(service.selectByDeviceId(deviceId)); return AjaxResult.success(service.selectByDeviceId(deviceId));
} }
@@ -51,4 +59,31 @@ public class DeviceRunParamController extends BaseController {
boolean message = service.importParam(paramList); boolean message = service.importParam(paramList);
return success(message); return success(message);
} }
/**
* 下载机器属性导入模板
*/
@GetMapping("/downloadTemplate")
public void downloadTemplate(HttpServletResponse response) throws IOException {
String fileName = "机器属性导入模板.xlsx";
try (InputStream inputStream = new ClassPathResource("机器属性导入模板.xlsx").getInputStream()) {
response.setContentType(
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("UTF-8");
response.setHeader(
"Content-Disposition",
"attachment; filename*=UTF-8''" +
URLEncoder.encode(fileName, "UTF-8").replace("+", "%20"));
ServletOutputStream outputStream = response.getOutputStream();
byte[] buffer = new byte[8192];
int len;
while ((len = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, len);
}
outputStream.flush();
}
}
} }

View File

@@ -3,14 +3,11 @@ package com.maibu.controller;
import java.util.List; import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.maibu.core.business.DeviceRunParam;
import com.maibu.core.business.OrderModel; import com.maibu.core.business.OrderModel;
import com.maibu.core.controller.BaseController; import com.maibu.core.controller.BaseController;
import com.maibu.core.domain.AjaxResult; import com.maibu.core.domain.AjaxResult;

View File

@@ -1,7 +1,10 @@
package com.maibu.service.impl; package com.maibu.service.impl;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@@ -39,47 +42,55 @@ public class DeviceRunParamService {
@Autowired @Autowired
private DeviceSessionManager sessionManager; private DeviceSessionManager sessionManager;
public boolean save(DeviceRunParam deviceRunParam) // public boolean save(DeviceRunParam deviceRunParam)
throws ExecutionException, InterruptedException, TimeoutException { // throws ExecutionException, InterruptedException, TimeoutException {
NettyDevice nettyDevice = sessionManager.getDevice(deviceRunParam.getDeviceId()); // NettyDevice nettyDevice =
if (nettyDevice == null || !nettyDevice.getChannel().isActive()) { // sessionManager.getDevice(deviceRunParam.getDeviceId());
throw new ServiceException("设备不在线,无法操作!"); // if (nettyDevice == null || !nettyDevice.getChannel().isActive()) {
} // throw new ServiceException("设备不在线,无法操作!");
// }
CompletableFuture<DeviceRunParam> future = new CompletableFuture<>(); // CompletableFuture<DeviceRunParam> future = new CompletableFuture<>();
nettyDevice.getChannel().attr(Constant.READ_CONFIG_KEY).set(future); // nettyDevice.getChannel().attr(Constant.READ_CONFIG_KEY).set(future);
try { // try {
nettyDevice.readConfigCommand(); // nettyDevice.readConfigCommand();
DeviceRunParam param = future.get(5, TimeUnit.SECONDS); // DeviceRunParam param = future.get(5, TimeUnit.SECONDS);
if (param == null) { // if (param == null) {
throw new ServiceException("获取设备当前属性失败!"); // throw new ServiceException("获取设备当前属性失败!");
} // }
param.setLeftForwardGain(deviceRunParam.getLeftForwardGain()); // param.setLeftForwardGain(deviceRunParam.getLeftForwardGain());
param.setLeftBackwardGain(deviceRunParam.getLeftBackwardGain()); // param.setLeftBackwardGain(deviceRunParam.getLeftBackwardGain());
param.setRightForwardGain(deviceRunParam.getRightForwardGain()); // param.setRightForwardGain(deviceRunParam.getRightForwardGain());
param.setRightBackwardGain(deviceRunParam.getRightBackwardGain()); // param.setRightBackwardGain(deviceRunParam.getRightBackwardGain());
nettyDevice.writeConfigCommand(param); // nettyDevice.writeConfigCommand(param);
param.setRunSpeed(deviceRunParam.getRunSpeed()); // param.setRunSpeed(deviceRunParam.getRunSpeed());
param.setDeviceId(deviceRunParam.getDeviceId()); // param.setDeviceId(deviceRunParam.getDeviceId());
param.setSiteId(deviceRunParam.getSiteId()); // param.setSiteId(deviceRunParam.getSiteId());
param.setOrgId(deviceRunParam.getOrgId()); // param.setOrgId(deviceRunParam.getOrgId());
param.setId(deviceRunParam.getId()); // param.setId(deviceRunParam.getId());
// SiteMemory siteMemory = GlobalMemory.getSiteMemory(deviceRunParam.getOrgId(),
// deviceRunParam.getSiteId());
// if (siteMemory != null) {
// siteMemory.saveDeviceRunParam(param);
// }
// return deviceRunParamMapper.saveOrUpdate(param);
// } finally {
// nettyDevice.getChannel().attr(Constant.READ_CONFIG_KEY).set(null);
// }
// }
public boolean save(DeviceRunParam deviceRunParam) {
return deviceRunParamMapper.saveOrUpdate(deviceRunParam);
SiteMemory siteMemory = GlobalMemory.getSiteMemory(deviceRunParam.getOrgId(), deviceRunParam.getSiteId());
if (siteMemory != null) {
siteMemory.saveDeviceRunParam(param);
}
return deviceRunParamMapper.saveOrUpdate(param);
} finally {
nettyDevice.getChannel().attr(Constant.READ_CONFIG_KEY).set(null);
}
} }
public List<DeviceRunParam> list(BaseQueryDTO dto) { public List<DeviceRunParam> list(BaseQueryDTO dto) {
@@ -127,6 +138,49 @@ public class DeviceRunParamService {
// return null; // return null;
// } // }
// public DeviceRunParam selectByDeviceId(String deviceId)
// throws ExecutionException, InterruptedException, TimeoutException {
// LambdaQueryWrapper<DeviceRunParam> queryWrapper = new LambdaQueryWrapper<>();
// if (!StringUtils.isEmpty(deviceId)) {
// queryWrapper.eq(DeviceRunParam::getDeviceId, deviceId);
// }
// DeviceRunParam result = deviceRunParamMapper.selectOne(queryWrapper);
// if (result != null && result.getHasHost() != null && result.getHasHost() ==
// 1) {
// return result;
// } else {
// NettyDevice nettyDevice = sessionManager.getDevice(deviceId);
// CompletableFuture<DeviceRunParam> future = new CompletableFuture<>();
// if (nettyDevice != null && nettyDevice.getChannel() != null &&
// nettyDevice.getChannel().isActive()) {
// nettyDevice.getChannel().attr(Constant.READ_CONFIG_KEY).set(future);
// try {
// nettyDevice.readConfigCommand();
// DeviceRunParam param = future.get(5, TimeUnit.SECONDS);
// // LambdaQueryWrapper<DeviceRunParam> queryWrapper = new
// LambdaQueryWrapper<>();
// // if (!StringUtils.isEmpty(deviceId)) {
// // queryWrapper.eq(DeviceRunParam::getDeviceId, deviceId);
// // }
// // DeviceRunParam result = deviceRunParamMapper.selectOne(queryWrapper);
// if (result != null) {
// param.setId(result.getId());
// param.setDeviceId(result.getDeviceId());
// param.setRunSpeed(result.getRunSpeed());
// param.setOrgId(nettyDevice.getDevice().getOrgId());
// param.setSiteId(nettyDevice.getDevice().getSiteId());
// }
// return param;
// } finally {
// nettyDevice.getChannel().attr(Constant.READ_CONFIG_KEY).set(null);
// }
// }
// }
// return null;
// }
public DeviceRunParam selectByDeviceId(String deviceId) public DeviceRunParam selectByDeviceId(String deviceId)
throws ExecutionException, InterruptedException, TimeoutException { throws ExecutionException, InterruptedException, TimeoutException {
@@ -135,36 +189,7 @@ public class DeviceRunParamService {
queryWrapper.eq(DeviceRunParam::getDeviceId, deviceId); queryWrapper.eq(DeviceRunParam::getDeviceId, deviceId);
} }
DeviceRunParam result = deviceRunParamMapper.selectOne(queryWrapper); DeviceRunParam result = deviceRunParamMapper.selectOne(queryWrapper);
if (result != null && result.getHasHost() != null && result.getHasHost() == 1) {
return result; return result;
} else {
NettyDevice nettyDevice = sessionManager.getDevice(deviceId);
CompletableFuture<DeviceRunParam> future = new CompletableFuture<>();
if (nettyDevice != null && nettyDevice.getChannel() != null && nettyDevice.getChannel().isActive()) {
nettyDevice.getChannel().attr(Constant.READ_CONFIG_KEY).set(future);
try {
nettyDevice.readConfigCommand();
DeviceRunParam param = future.get(5, TimeUnit.SECONDS);
// LambdaQueryWrapper<DeviceRunParam> queryWrapper = new LambdaQueryWrapper<>();
// if (!StringUtils.isEmpty(deviceId)) {
// queryWrapper.eq(DeviceRunParam::getDeviceId, deviceId);
// }
// DeviceRunParam result = deviceRunParamMapper.selectOne(queryWrapper);
if (result != null) {
param.setId(result.getId());
param.setDeviceId(result.getDeviceId());
param.setRunSpeed(result.getRunSpeed());
param.setOrgId(nettyDevice.getDevice().getOrgId());
param.setSiteId(nettyDevice.getDevice().getSiteId());
}
return param;
} finally {
nettyDevice.getChannel().attr(Constant.READ_CONFIG_KEY).set(null);
}
}
}
return null;
} }
public int delete(List<Long> ids) { public int delete(List<Long> ids) {
@@ -211,16 +236,47 @@ public class DeviceRunParamService {
} }
if (deviceRunParam != null) { if (deviceRunParam != null) {
deviceRunParam.setCapabilityList(x.getCapabilityList()); deviceRunParam.setCapabilityList(x.getCapabilityList());
deviceRunParam.setDeviceId(x.getDeviceId());
parseSn(x.getDeviceId(), deviceRunParam);
deviceRunParam.setProductModel(x.getProductModel()); deviceRunParam.setProductModel(x.getProductModel());
deviceRunParam.setRtkMode(x.getRtkMode());
deviceRunParam.setDeviceType(x.getDeviceType()); deviceRunParam.setDeviceType(x.getDeviceType());
deviceRunParam.setPowerType(x.getPowerType()); deviceRunParam.setRtkMode(x.getRtkMode());
deviceRunParam.setCameraNum(x.getCameraNum()); deviceRunParam.setCameraNum(x.getCameraNum());
deviceRunParam.setPowerType(x.getPowerType());
deviceRunParam.setWheelType(x.getWheelType()); deviceRunParam.setWheelType(x.getWheelType());
deviceRunParam.setEngineType(x.getEngineType()); deviceRunParam.setEngineType(x.getEngineType());
deviceRunParam.setHasHost(x.getHasHost()); deviceRunParam.setHasHost(x.getHasHost());
deviceRunParam.setBatteryType(x.getBatteryType());
deviceRunParam.setWalkingDriveType(x.getWalkingDriveType());
deviceRunParam.setCutterDriveType(x.getCutterDriveType());
deviceRunParam.setRtkAntennasNum(x.getRtkAntennasNum());
deviceRunParam.setHandleType(x.getHandleType());
deviceRunParam.setPcbVersion(x.getPcbVersion());
deviceRunParam.setDimensions(x.getDimensions());
deviceRunParam.setBladeWidth(x.getBladeWidth());
deviceRunParam.setTyreSize(x.getTyreSize());
deviceRunParam.setSpeedRatio(x.getSpeedRatio());
deviceRunParam.setCellularInfo(x.getCellularInfo());
deviceRunParam.setWifiName(x.getWifiName());
deviceRunParam.setBluetoothName(x.getBluetoothName());
deviceRunParam.setHardwareIdentifiers(x.getHardwareIdentifiers());
deviceRunParam.setImuModel(x.getImuModel());
deviceRunParam.setTempHumiditySensor(x.getTempHumiditySensor());
deviceRunParam.setBarometerPresent(x.getBarometerPresent());
deviceRunParam.setUltrasonicPresent(x.getUltrasonicPresent());
deviceRunParam.setDacPresent(x.getDacPresent());
deviceRunParam.setOperator(x.getOperator());
deviceRunParam.setInspectionNo(x.getInspectionNo());
deviceRunParam.setFirmwareVersion(x.getFirmwareVersion());
deviceRunParam.setDealer(x.getDealer());
saveList.add(deviceRunParam); saveList.add(deviceRunParam);
} else { } else {
parseSn(x.getDeviceId(), x);
saveList.add(x); saveList.add(x);
} }
}); });
@@ -234,4 +290,21 @@ public class DeviceRunParamService {
} }
} }
public static void parseSn(String sn, DeviceRunParam deviceRunParam) {
if (sn == null || sn.length() != 21) {
throw new IllegalArgumentException("SN 必须是 21 位字符串");
}
deviceRunParam.setProductModel(sn.substring(0, 2));
deviceRunParam.setFactoryCode(sn.substring(2, 4));
deviceRunParam.setLineNum(sn.substring(4, 6));
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyMMdd");
LocalDate date = LocalDate.parse(sn.substring(6, 12), formatter);
deviceRunParam.setProductionDate(date);
deviceRunParam.setSerialNumber(sn.substring(12, 17));
}
} }