超威fix

This commit is contained in:
psh
2024-07-17 16:17:25 +08:00
parent 73bc4a3c45
commit 67c68ae05b
2 changed files with 145 additions and 126 deletions

View File

@@ -28,6 +28,7 @@ import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.net.Socket; import java.net.Socket;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@@ -100,154 +101,155 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable {
break; break;
} }
int[] arr = new int[count]; int[] arrAll = new int[count];
StringBuffer bs = new StringBuffer(); StringBuffer bs = new StringBuffer();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
int temp = b[i]; int temp = b[i];
if (temp < 0) if (temp < 0)
temp += 256; temp += 256;
arr[i] = temp; arrAll[i] = temp;
StringBuffer bs1 = new StringBuffer("0"); StringBuffer bs1 = new StringBuffer("0");
bs.append(temp < 16 ? bs1.append(Integer.toHexString(temp)) : Integer.toHexString(temp)); bs.append(temp < 16 ? bs1.append(Integer.toHexString(temp)) : Integer.toHexString(temp));
} }
//System.out.println("收到请求参数:" + bs); int chunkSize = 28;
boolean flag = false; List<int[]> chunks = this.splitArray(arrAll, chunkSize);
log.info("接收agv上报信息" + bs); for (int i = 0; i < chunks.size(); i++) {
if (arr[8] * 256 + arr[9] == 0x73) { int[] arr = chunks.get(i);
byte[] data = null; if (arr[8] * 256 + arr[9] == 0x73) {
//执行阶段 byte[] data = null;
int phase = arr[16] * 256 + arr[17]; //执行阶段
// agv任务号 int phase = arr[16] * 256 + arr[17];
int index = arr[12] * 256 + arr[13]; // agv任务号
//任务号 int index = arr[12] * 256 + arr[13];
int ikey = arr[26] * 256 + arr[27]; //任务号
//站点号 int ikey = arr[26] * 256 + arr[27];
int agvaddr = arr[18] * 256 + arr[19]; //站点号
//车号 int agvaddr = arr[18] * 256 + arr[19];
int carno = arr[20]; //车号
Instruction link_inst = null; int carno = arr[20];
Instruction inst = null; Instruction link_inst = null;
List<Instruction> insts = null; Instruction inst = null;
boolean link_flag = false; List<Instruction> insts = null;
Device agv_device = null; boolean link_flag = false;
if (carno != 0) { Device agv_device = null;
agv_device = deviceAppService.findDeviceByCode(String.valueOf(carno)); if (carno != 0) {
} agv_device = deviceAppService.findDeviceByCode(String.valueOf(carno));
if (ikey != 0) {
inst = instructionService.findByCodeFromCache(String.valueOf(ikey));
if (ObjectUtil.isEmpty(inst)) {
inst = instructionService.findByCode(String.valueOf(ikey));
} }
} if (ikey != 0) {
if (!ObjectUtil.isEmpty(link_inst)) { inst = instructionService.findByCodeFromCache(String.valueOf(ikey));
link_flag = true; if (ObjectUtil.isEmpty(inst)) {
} inst = instructionService.findByCode(String.valueOf(ikey));
log.info("接收agv上报信息" + bs);
log.info("接收agv上报信息" + "phase--" + phase + " index--" + index + " ikey--" + ikey + " agvaddr--" + agvaddr + " Car--" + carno);
Device device = null;
String device_code = null;
String old_device_code = null;
if (agvaddr != 0) {
old_device_code = deviceService.queryDeviceCodeByAddress(agvaddr);
if (StrUtil.contains(old_device_code, "-")) {
String[] point = old_device_code.split("-");
device_code = point[0];
} else if (StrUtil.contains(old_device_code, ".")) {
String[] point = old_device_code.split("\\.");
device_code = point[0];
} else {
device_code = old_device_code;
}
device = deviceAppService.findDeviceByCode(device_code);
}
//
AgvNdcOneDeviceDriver agvNdcOneDeviceDriver;
StandardAutodoorDeviceDriver standardAutodoorDeviceDriver;
//开始任务/上报订单号
if (phase == 0x01) {
if (!ObjectUtil.isEmpty(inst)) {
inst.setInstruction_status("1");
inst.setAgv_jobno(String.valueOf(index));
inst.setSend_status("1");
instructionService.update(inst);
}
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0, 0, 0, 0, 0);
}
//任务完毕
//无车id及状态
else if (phase == 0x0A) {
if (!ObjectUtil.isEmpty(inst)) {
instructionService.finish(inst.getInstruction_id());
} else {
log.warn("指令号:{},未反馈wms任务完成因为agv上报指令号查询指令为空!");
}
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0, 0, 0, 0, 0);
log.info("指令号:{},已反馈agv任务完成!");
}
//请求删除任务
//(需要WCS反馈)
else if (phase == 0x30) {
data = NDCAgvService.sendAgvOneModeInst(0x8F, index, 0, 0, 0, 0, 0);
} //进入区域
else if (phase == 0x50) {
//开门
if (device!=null&&device.getDeviceDriver() instanceof StandardAutodoorDeviceDriver) {
standardAutodoorDeviceDriver = (StandardAutodoorDeviceDriver) device.getDeviceDriver();
standardAutodoorDeviceDriver.OpenOrClose("1");
if (standardAutodoorDeviceDriver.getAction() == 1) {
standardAutodoorDeviceDriver.OpenOrClose("1");
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0, 0, 0, 0, 0);
} }
} }
} if (!ObjectUtil.isEmpty(link_inst)) {
//离开区域 link_flag = true;
else if (phase == 0x51) { }
//关门 log.info("接收agv上报信息" + bs);
if (device!=null&&device.getDeviceDriver() instanceof StandardAutodoorDeviceDriver) { log.info("接收agv上报信息" + "phase--" + phase + " index--" + index + " ikey--" + ikey + " agvaddr--" + agvaddr + " Car--" + carno);
standardAutodoorDeviceDriver = (StandardAutodoorDeviceDriver) device.getDeviceDriver(); Device device = null;
standardAutodoorDeviceDriver.OpenOrClose("2"); String device_code = null;
if (standardAutodoorDeviceDriver.getAction() == 2) { String old_device_code = null;
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0, 0, 0, 0, 0); if (agvaddr != 0) {
} old_device_code = deviceService.queryDeviceCodeByAddress(agvaddr);
if (StrUtil.contains(old_device_code, "-")) {
String[] point = old_device_code.split("-");
device_code = point[0];
} else if (StrUtil.contains(old_device_code, ".")) {
String[] point = old_device_code.split("\\.");
device_code = point[0];
} else {
device_code = old_device_code;
}
device = deviceAppService.findDeviceByCode(device_code);
} }
//任务删除确认
//(需要WCS反馈)
}else if (phase == 0xFF) {
if (!ObjectUtil.isEmpty(inst)) { //
AgvNdcOneDeviceDriver agvNdcOneDeviceDriver;
StandardAutodoorDeviceDriver standardAutodoorDeviceDriver;
//开始任务/上报订单号
if (phase == 0x01) {
if (!ObjectUtil.isEmpty(inst)) { if (!ObjectUtil.isEmpty(inst)) {
instructionService.cancelNOSendAgv(inst.getInstruction_id()); inst.setInstruction_status("1");
taskService.cancel(inst.getTask_id()); inst.setAgv_jobno(String.valueOf(index));
inst.setSend_status("1");
instructionService.update(inst);
}
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0, 0, 0, 0, 0);
}
//任务完毕
//无车id及状态
else if (phase == 0x0A) {
if (!ObjectUtil.isEmpty(inst)) {
instructionService.finish(inst.getInstruction_id());
} else {
log.warn("指令号:{},未反馈wms任务完成因为agv上报指令号查询指令为空!");
}
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0, 0, 0, 0, 0);
log.info("指令号:{},已反馈agv任务完成!");
}
//请求删除任务
//(需要WCS反馈)
else if (phase == 0x30) {
data = NDCAgvService.sendAgvOneModeInst(0x8F, index, 0, 0, 0, 0, 0);
} //进入区域
else if (phase == 0x50) {
//开门
if (device != null && device.getDeviceDriver() instanceof StandardAutodoorDeviceDriver) {
standardAutodoorDeviceDriver = (StandardAutodoorDeviceDriver) device.getDeviceDriver();
standardAutodoorDeviceDriver.OpenOrClose("1");
if (standardAutodoorDeviceDriver.getAction() == 1) {
standardAutodoorDeviceDriver.OpenOrClose("1");
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0, 0, 0, 0, 0);
}
} }
} }
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0, 0, 0, 0, 0); //离开区域
else if (phase == 0x51) {
//关门
if (device != null && device.getDeviceDriver() instanceof StandardAutodoorDeviceDriver) {
standardAutodoorDeviceDriver = (StandardAutodoorDeviceDriver) device.getDeviceDriver();
standardAutodoorDeviceDriver.OpenOrClose("2");
if (standardAutodoorDeviceDriver.getAction() == 2) {
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0, 0, 0, 0, 0);
}
}
//任务删除确认
//(需要WCS反馈)
} else if (phase == 0xFF) {
if (!ObjectUtil.isEmpty(inst)) {
if (!ObjectUtil.isEmpty(inst)) {
instructionService.cancelNOSendAgv(inst.getInstruction_id());
taskService.cancel(inst.getTask_id());
}
}
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0, 0, 0, 0, 0);
} else {
//上报异常信息
//不需要WCS反馈
if (phase == 0x67) {
device = deviceAppService.findDeviceByCode(Integer.toString(arr[27]));
} else { } else {
device = deviceAppService.findDeviceByCode(Integer.toString(arr[20])); //上报异常信息
} //不需要WCS反馈
if (ObjectUtil.isNotEmpty(device)) { if (phase == 0x67) {
if (device.getDeviceDriver() instanceof AgvNdcOneDeviceDriver) { device = deviceAppService.findDeviceByCode(Integer.toString(arr[27]));
agvNdcOneDeviceDriver = (AgvNdcOneDeviceDriver) device.getDeviceDriver(); } else {
agvNdcOneDeviceDriver.processSocket(arr); device = deviceAppService.findDeviceByCode(Integer.toString(arr[20]));
} }
if (ObjectUtil.isNotEmpty(device)) {
if (device.getDeviceDriver() instanceof AgvNdcOneDeviceDriver) {
agvNdcOneDeviceDriver = (AgvNdcOneDeviceDriver) device.getDeviceDriver();
agvNdcOneDeviceDriver.processSocket(arr);
}
}
} }
if (!ObjectUtil.isEmpty(data)) {
write(data);
}
} else {
log.info("agv上报不是0073类型动作不处理");
} }
if (!ObjectUtil.isEmpty(data)) {
write(data);
}
} else {
log.info("agv上报不是0073类型动作不处理");
} }
} }
@@ -301,5 +303,22 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable {
} }
} }
public static List<int[]> splitArray(int[] array, int chunkSize) {
List<int[]> 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;
}
} }

View File

@@ -163,7 +163,7 @@ public abstract class AbstractTask {
* @param param * @param param
* @throws BadRequestException * @throws BadRequestException
*/ */
public void apply(JSONObject param) throws BadRequestException { public synchronized void apply(JSONObject param) throws BadRequestException {
// 申请任务 // 申请任务
SchBaseTask task = new SchBaseTask(); // 任务实体 SchBaseTask task = new SchBaseTask(); // 任务实体
String apply_point_code = param.getString("device_code"); // 请求点 String apply_point_code = param.getString("device_code"); // 请求点