Socket推送客户端数据

This commit is contained in:
cbs 2025-07-14 17:36:05 +08:00
parent 20e0a18dd3
commit d5d0f5bdcb
6 changed files with 107 additions and 6 deletions

View File

@ -18,6 +18,7 @@ import java.io.IOException;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@ -146,7 +147,35 @@ public class RemoteControllerProcessor {
msg = msg + " " + crcOne + " " + crcTwo;
remoteControllerSocket.setMsg(msg);
remoteControllerSocket.setMsg(hexStringToByteArray(msg));
}
public String hexStringToByteArray(String hexString) {
// 移除所有空格包括中间和两端的空格
String cleaned = hexString.replaceAll("\\s", "");
// 验证字符串长度是否为偶数
if (cleaned.length() % 2 != 0) {
throw new IllegalArgumentException("无效的十六进制字符串长度: " + cleaned.length());
}
// 创建结果字节数组
byte[] byteArray = new byte[cleaned.length() / 2];
for (int i = 0; i < cleaned.length(); i += 2) {
// 提取两个连续的十六进制字符
String hexPair = cleaned.substring(i, i + 2);
try {
// 将十六进制字符串转换为字节
byteArray[i / 2] = (byte) Integer.parseInt(hexPair, 16);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("无效的十六进制字符: " + hexPair);
}
}
String str = Arrays.toString(byteArray);
return str.substring(1, str.length() - 1);
}
public void remoteCache(RemoteRobotTransferDTO dto, String ip) {
@ -223,7 +252,10 @@ public class RemoteControllerProcessor {
try {
os = socket.getOutputStream();
String str = remoteControllerSocketDTO.getMsg();
os.write(remoteControllerSocketDTO.getMsg().getBytes());
String[] split = str.split(",");
for (String meg : split) {
os.write(Integer.parseInt(meg.trim()));
}
log.info("socket推送的数据 :{}", str);
} catch (IOException e) {
log.error("socket发送异常 :{}", e);

View File

@ -0,0 +1,58 @@
package cn.iocoder.yudao.module.remote.util;
import java.util.Arrays;
public class HexConverter {
public static byte[] hexStringToByteArray(String hexString) {
// 移除所有空格包括中间和两端的空格
String cleaned = hexString.replaceAll("\\s", "");
// 验证字符串长度是否为偶数
if (cleaned.length() % 2 != 0) {
throw new IllegalArgumentException("无效的十六进制字符串长度: " + cleaned.length());
}
// 创建结果字节数组
byte[] byteArray = new byte[cleaned.length() / 2];
for (int i = 0; i < cleaned.length(); i += 2) {
// 提取两个连续的十六进制字符
String hexPair = cleaned.substring(i, i + 2);
try {
// 将十六进制字符串转换为字节
byteArray[i / 2] = (byte) Integer.parseInt(hexPair, 16);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("无效的十六进制字符: " + hexPair);
}
}
return byteArray;
}
public static void main(String[] args) {
String input = "AA 55 13 04 01 88 88 02 C0 A8 09 09 0f 27 01 78 01 78 01 78 EE 27"; // 可以测试 "ab c5 ef" "A B C 5 E F"
try {
byte[] result = hexStringToByteArray(input);
// 格式化输出为 {0xAB, 0xC5, 0xEF} 形式
StringBuilder sb = new StringBuilder("{");
for (int i = 0; i < result.length; i++) {
// 使用 & 0xFF 将字节转换为无符号整数
sb.append(String.format("0x%02X", result[i] & 0xFF));
if (i < result.length - 1) sb.append(", ");
}
sb.append("}");
System.out.println("输入: \"" + input + "\"");
System.out.println("十六进制数组: " + sb.toString());
System.out.println("字节数组内容: " + Arrays.toString(result));
} catch (IllegalArgumentException e) {
System.err.println("错误: " + e.getMessage());
}
}
}

View File

@ -55,8 +55,11 @@ logging:
remote:
cockpit: # 远遥控制车辆IP和端口
- controllerPort: 9000
controllerIp: 127.0.0.1
ipcIp: 10.10.7.132
controllerIp: 10.10.100.19
ipcIp: 10.10.100.19
- controllerPort: 9000
controllerIp: 10.10.100.19
ipcIp: 10.10.5.26
msg: AA 55 13 04 01 88 88 # 驾舱socket头信息
cockpit-time-out: 120 # 驾舱超时报警时间
industrial-control-time-out: 120 # 工控通信超时报警时间

View File

@ -77,6 +77,10 @@ public class TaskDistributionConsumer {
} else if (RobotTaskEventTypeEnum.DONE.getType().equals(message.getEventType())) {
String orderId = message.getMessage();
String endTime = DateUtils.getYearMonthDayHourMinuteSecon();
try {
Thread.sleep(5000);
} catch (Exception e) {
}
RobotTaskDetailDO taskDetail = robotTaskDetailService.getTaskDetail(Long.valueOf(orderId));
if (RobotTaskTypeEnum.TAKE_RELEASE.getType().equals(taskDetail.getTaskType())) {
takeRelease(taskDetail, endTime, orderId);

View File

@ -10,6 +10,7 @@ import cn.iocoder.yudao.module.system.controller.admin.log.vo.RobotTaskLineTimeC
import cn.iocoder.yudao.module.system.dal.dataobject.log.RobotTaskLineTimeConsumingDO;
import cn.iocoder.yudao.module.system.dal.dataobject.robot.RobotTaskDetailDO;
import cn.iocoder.yudao.module.system.dal.mysql.log.RobotTaskLineTimeConsumingMapper;
import cn.iocoder.yudao.module.system.enums.common.ZeroOneEnum;
import cn.iocoder.yudao.module.system.service.robot.RobotTaskDetailService;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
@ -97,6 +98,9 @@ public class RobotTaskLineTimeConsumingServiceImpl extends ServiceImpl<RobotTask
RobotTaskDetailDO taskDetail = robotTaskDetailService.getTaskDetail(orderId);
List<RobotTaskLineTimeConsumingDO> addList = new ArrayList<>();
for (RobotTaskLineTimeConsumingDetailDTO v : list) {
if ((ZeroOneEnum.ZERO.getType()+"").equals(v.getTimeConsuming())) {
continue;
}
RobotTaskLineTimeConsumingDO line = BeanUtils.toBean(v, RobotTaskLineTimeConsumingDO.class);
line.setTaskNo(taskNo);
line.setTaskDetailId(orderId);

View File

@ -555,7 +555,7 @@ public class RobotPathPlanningServiceImpl implements RobotPathPlanningService {
}
WareHouseLocationDO nextLocation = locationMapper.selectOne(new LambdaQueryWrapperX<WareHouseLocationDO>()
.eq(WareHouseLocationDO::getId, fromLocation.getMapItemId())
.eq(WareHouseLocationDO::getMapItemId, fromLocation.getMapItemId())
.eq(WareHouseLocationDO::getLocationStorey, fromLocation.getLocationStorey() - 1)
.last("limit 1"));
if (ObjectUtil.isNotEmpty(nextLocation) && ObjectUtil.isNotEmpty(nextLocation.getLocationTotalHeight())) {
@ -590,7 +590,7 @@ public class RobotPathPlanningServiceImpl implements RobotPathPlanningService {
}
WareHouseLocationDO nextLocation = locationMapper.selectOne(new LambdaQueryWrapperX<WareHouseLocationDO>()
.eq(WareHouseLocationDO::getId, toLocation.getMapItemId())
.eq(WareHouseLocationDO::getMapItemId, toLocation.getMapItemId())
.eq(WareHouseLocationDO::getLocationStorey, toLocation.getLocationStorey() - 1)
.last("limit 1"));
if (ObjectUtil.isNotEmpty(nextLocation) && ObjectUtil.isNotEmpty(nextLocation.getLocationTotalHeight())) {