From 2d1398d8018deb7d8a1edf752bcc81f3bcb701e8 Mon Sep 17 00:00:00 2001 From: psh Date: Thu, 18 Jul 2024 13:48:21 +0800 Subject: [PATCH] =?UTF-8?q?1.ndc=E4=BA=A4=E4=BA=92=E7=B2=98=E5=8C=85?= =?UTF-8?q?=E9=9C=80=E8=A6=81=E5=88=86=E5=89=B2=E5=88=A4=E6=96=AD=202.?= =?UTF-8?q?=E7=A9=BA=E6=9E=B6=E5=85=A5=E5=BA=93=E4=BC=9A=E5=87=BA=E7=8E=B0?= =?UTF-8?q?=E6=9C=80=E5=90=8E=E5=90=8C=E6=97=B6=E6=BB=A1=E6=96=99=EF=BC=8C?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=BD=AF=E9=94=81=E6=8E=A7=E5=88=B6=EF=BC=8C?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E4=BB=BB=E5=8A=A1=E6=97=B6=E8=BF=87=E6=BB=A4?= =?UTF-8?q?=EF=BC=8C=E4=BA=8C=E6=AC=A1=E5=88=86=E9=85=8D=E6=97=B6=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E6=94=BE=EF=BC=8C=E4=BB=BB=E5=8A=A1=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E6=88=96=E5=8F=96=E6=B6=88=E5=90=8E=E8=A7=A3=E9=94=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../run/OneNDCSocketConnectionAutoRun.java | 34 +++---- .../main/java/org/nl/acs/utils/ByteUtil.java | 90 +++++++++++++++++++ .../sch/point/service/dao/SchBasePoint.java | 3 + .../task_manage/task/tasks/KGHJRKTask.java | 20 +++-- 4 files changed, 117 insertions(+), 30 deletions(-) create mode 100644 acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/utils/ByteUtil.java diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/auto/run/OneNDCSocketConnectionAutoRun.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/auto/run/OneNDCSocketConnectionAutoRun.java index f37781f..64e1a62 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/auto/run/OneNDCSocketConnectionAutoRun.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/auto/run/OneNDCSocketConnectionAutoRun.java @@ -17,6 +17,7 @@ import org.nl.acs.instruction.service.impl.InstructionServiceImpl; import org.nl.acs.log.service.DeviceExecuteLogService; import org.nl.acs.opc.DeviceAppService; import org.nl.acs.task.service.TaskService; +import org.nl.acs.utils.ByteUtil; import org.nl.system.service.lucene.LuceneExecuteLogService; import org.nl.system.service.param.ISysParamService; import org.nl.config.SpringContextHolder; @@ -28,7 +29,7 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import java.net.Socket; -import java.util.ArrayList; +import java.util.Arrays; import java.util.Date; import java.util.List; @@ -112,12 +113,13 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable { StringBuffer bs1 = new StringBuffer("0"); bs.append(temp < 16 ? bs1.append(Integer.toHexString(temp)) : Integer.toHexString(temp)); } - - int chunkSize = 28; - List chunks = this.splitArray(arrAll, chunkSize); - for (int i = 0; i < chunks.size(); i++) { - int[] arr = chunks.get(i); - if (arr[8] * 256 + arr[9] == 0x73) { + List packets = ByteUtil.splitAndConvertPackets(bs.toString()); + log.info("接收agv上报信息:" + bs); + // 打印分割后的报文 + for (int i = 0; i < packets.size(); i++) { + int[] arr = packets.get(i); + log.info("处理当前分割部分{}", Arrays.toString(arr)); + if (arr.length>10&&arr[8] * 256 + arr[9] == 0x73) { byte[] data = null; //执行阶段 int phase = arr[16] * 256 + arr[17]; @@ -247,6 +249,7 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable { if (!ObjectUtil.isEmpty(data)) { write(data); } + } else { log.info("agv上报不是0073类型动作,不处理"); } @@ -303,22 +306,5 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable { } } - - public static List splitArray(int[] array, int chunkSize) { - List resultList = new ArrayList<>(); - int length = array.length; - - for (int i = 0; i < length; i += chunkSize) { - // 计算当前子数组的大小 - int currentChunkSize = Math.min(chunkSize, length - i); - - // 创建并填充新的子数组 - int[] chunk = new int[currentChunkSize]; - System.arraycopy(array, i, chunk, 0, currentChunkSize); - resultList.add(chunk); - } - - return resultList; - } } diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/utils/ByteUtil.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/utils/ByteUtil.java new file mode 100644 index 0000000..deff7ec --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/utils/ByteUtil.java @@ -0,0 +1,90 @@ +package org.nl.acs.utils; + +import java.util.ArrayList; +import java.util.List; + +public class ByteUtil{ + + public static List splitAndConvertPackets(String data) { + // 将输入的十六进制字符串转换为字节数组 + byte[] dataBytes = hexStringToByteArray(data); + + // 87CD的字节表示 + byte[] startMarker = {(byte) 0x87, (byte) 0xCD}; + + // 存储结果的列表 + List packets = new ArrayList<>(); + + // 当前分割点 + int start = 0; + + // 遍历整个字节数组 + while (start < dataBytes.length) { + // 找到下一个87CD的起始位置 + int nextStart = findStartMarker(dataBytes, startMarker, start + 2); + + if (nextStart == -1) { + // 没有找到下一个87CD,说明到了最后一个包 + packets.add(byteArrayToIntArray(dataBytes, start, dataBytes.length - start)); + break; + } else { + // 找到一个新的87CD,将前面的部分作为一个完整的包 + packets.add(byteArrayToIntArray(dataBytes, start, nextStart - start)); + start = nextStart; + } + } + + return packets; + } + + private static int findStartMarker(byte[] data, byte[] marker, int start) { + for (int i = start; i <= data.length - marker.length; i++) { + boolean match = true; + for (int j = 0; j < marker.length; j++) { + if (data[i + j] != marker[j]) { + match = false; + break; + } + } + if (match) { + return i; + } + } + return -1; + } + + private static byte[] hexStringToByteArray(String s) { + int len = s.length(); + byte[] data = new byte[len / 2]; + for (int i = 0; i < len; i += 2) { + data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + + Character.digit(s.charAt(i + 1), 16)); + } + return data; + } + + private static int[] byteArrayToIntArray(byte[] bytes, int offset, int length) { + int[] intArray = new int[length]; + for (int i = 0; i < length; i++) { + intArray[i] = bytes[offset + i] & 0xFF; + } + return intArray; + } + + public static void main(String[] args) { + String data = "87cd0008001400010073001000796e030003023e0300000000003f2c87cd00080014000100730010007b6e03000309370200000000003f2d87cd00080014000100730010007f6e03000309310600000000003f3087cd00080014000100730010001f6e030009085c06000001085c3eec87cd00080036000100450032002f00020000000000000000000300000085669788c40000708000000000000000000000000200000a59000000000000000087cd00080036000100450032002f00020000000000000000000300000085669788c40000708000000000000000000000000200000a59000000000000000087cd00080036000100450032002f0006000000000000000000030000012e669788c40000708000000000000000000000000400000000000000000000000087cd00080036000100450032002f00020000000000000000000300000085669788c40000708000000000000000000000000200000a59000000000000000087cd00080036000100450032002f00020000000000000000000300000085669788c50000708000000000000000000000000200000a590000000000000000"; + + // 处理数据 + List packets = splitAndConvertPackets(data); + + // 打印分割后的报文 + for (int i = 0; i < packets.size(); i++) { + System.out.print("Packet " + (i + 1) + ": "); + for (int value : packets.get(i)) { + System.out.print(String.format("%02x", value) + " "); + } + System.out.println(); + } + } +} + diff --git a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/point/service/dao/SchBasePoint.java b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/point/service/dao/SchBasePoint.java index b2073d0..61b0e37 100644 --- a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/point/service/dao/SchBasePoint.java +++ b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/point/service/dao/SchBasePoint.java @@ -137,6 +137,9 @@ public class SchBasePoint implements Serializable { @TableField(exist = false) private String point_status_name; + @ApiModelProperty(value = "是否锁定") + private Boolean is_lock; + // 组盘标识 @TableField(exist = false) private String group_id; diff --git a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/tasks/KGHJRKTask.java b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/tasks/KGHJRKTask.java index 6f7fd02..6c8bafc 100644 --- a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/tasks/KGHJRKTask.java +++ b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/tasks/KGHJRKTask.java @@ -76,7 +76,8 @@ public class KGHJRKTask extends AbstractTask { // 找终点 SchBasePoint startPoint = pointService.getOne(new LambdaQueryWrapper() .eq(SchBasePoint::getPoint_code, task.getPoint_code1())); - SchBasePoint point = findNextPoint(startPoint, task.getVehicle_type()); + //创建任务时判断软锁,已锁则不能创建,下发任务时不考虑 + SchBasePoint point = findNextPoint(startPoint, task.getVehicle_type(),0); if (ObjectUtil.isEmpty(point)) { task.setRemark("未找到所需点位!"); taskService.update(task); @@ -97,9 +98,9 @@ public class KGHJRKTask extends AbstractTask { task.setRemark(""); taskService.update(task); -// //发起任务时先把点位占用,防止发起重复任务 -// point.setIng_task_code(task.getTask_code()); -// pointService.update(point); + //发起任务时先把点位占用,防止发起重复任务 + point.setIs_lock(true); + pointService.update(point); //下发 this.renotifyAcs(task); @@ -112,7 +113,7 @@ public class KGHJRKTask extends AbstractTask { * 2.倒叙查找,找到满足当前位置数量不足3的即可 * 3.负极板优先放到HCQ7,放满了再放到HCQ1 */ - private SchBasePoint findNextPoint(SchBasePoint startPoint, String vehicleType) { + private SchBasePoint findNextPoint(SchBasePoint startPoint, String vehicleType,int type) { String regionCode = null; String regionCode2 = null; if ("A1".equals(startPoint.getWorkshop_code())) { @@ -139,6 +140,9 @@ public class KGHJRKTask extends AbstractTask { if (!temp.getPoint_code().endsWith("01")) { continue; } + if(type==0&&temp.getIs_lock()){ + log.info("当前点位{}已被软锁,寻找终点时默认跳过",temp.getPoint_code()); + } //如果当列已放满,跳过到下一列最后一个点位0501开始判断 if (flag && !temp.getPoint_code().endsWith("0501")) { continue; @@ -235,14 +239,17 @@ public class KGHJRKTask extends AbstractTask { // 终点解锁,库存增加 endPointObj.setIng_task_code(""); endPointObj.setVehicle_qty(1); + endPointObj.setIs_lock(false); pointService.update(endPointObj); endPointObj = pointService.getById(endPoint.substring(0, endPoint.length() - 1) + "2"); endPointObj.setIng_task_code(""); endPointObj.setVehicle_qty(1); + endPointObj.setIs_lock(false); pointService.update(endPointObj); endPointObj = pointService.getById(endPoint.substring(0, endPoint.length() - 1) + "3"); endPointObj.setIng_task_code(""); endPointObj.setVehicle_qty(1); + endPointObj.setIs_lock(false); pointService.update(endPointObj); @@ -254,6 +261,7 @@ public class KGHJRKTask extends AbstractTask { // 终点解锁 if (ObjectUtil.isNotEmpty(endPointObj)) { endPointObj.setIng_task_code(""); + endPointObj.setIs_lock(false); pointService.update(endPointObj); } taskObj.setRemark("任务取消"); @@ -282,7 +290,7 @@ public class KGHJRKTask extends AbstractTask { } SchBasePoint startPoint = pointService.getOne(new LambdaQueryWrapper() .eq(SchBasePoint::getPoint_code, schBaseTask.getPoint_code1())); - SchBasePoint point = findNextPoint(startPoint, schBaseTask.getVehicle_type()); + SchBasePoint point = findNextPoint(startPoint, schBaseTask.getVehicle_type(),1); if ("ZJBKGHJDJW".equals(point.getRegion_code())) { schBaseTask.setPoint_code2(point.getPoint_code() + "0" + (point.getVehicle_qty() + 1)); } else {