rev:ndc线程处理
This commit is contained in:
@@ -33,10 +33,15 @@ import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import static org.nl.acs.agv.server.impl.NDCAgvServiceImpl.Bytes2HexString;
|
||||
|
||||
@@ -64,6 +69,10 @@ public class TwoNDCSocketConnectionAutoRun extends AbstractAutoRunnable {
|
||||
boolean requireSucessTake = false;
|
||||
boolean requireSucessPut = false;
|
||||
|
||||
private final ConcurrentHashMap<String, ExecutorService> carExecutors = new ConcurrentHashMap<>();
|
||||
|
||||
private final ConcurrentHashMap<String, AtomicBoolean> CAR_PHASE = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
@Autowired
|
||||
ISysParamService paramService;
|
||||
@@ -119,7 +128,7 @@ public class TwoNDCSocketConnectionAutoRun extends AbstractAutoRunnable {
|
||||
dis = new DataInputStream(socket.getInputStream());
|
||||
|
||||
while (socket.isConnected()) {
|
||||
System.out.println("当前socket状态:"+socket.isConnected());
|
||||
System.out.println("当前socket状态:" + socket.isConnected());
|
||||
int count = dis.read(b);
|
||||
// System.out.println("当前count值:"+count);
|
||||
if (count == -1) {
|
||||
@@ -198,8 +207,6 @@ public class TwoNDCSocketConnectionAutoRun extends AbstractAutoRunnable {
|
||||
device = deviceAppService.findDeviceByCode(device_code);
|
||||
}
|
||||
|
||||
AgvNdcTwoDeviceDriver agvNdcTwoDeviceDriver;
|
||||
AgvNdcOneDeviceDriver agvNdcOneDeviceDriver;
|
||||
//开始任务
|
||||
if (phase == 0x01) {
|
||||
if (!ObjectUtil.isEmpty(inst)) {
|
||||
@@ -221,10 +228,10 @@ public class TwoNDCSocketConnectionAutoRun extends AbstractAutoRunnable {
|
||||
Device agvDevice = deviceAppService.findDeviceByCode(agvcar);
|
||||
if (agvDevice != null) {
|
||||
if (agvDevice.getDeviceDriver() instanceof AgvNdcTwoDeviceDriver) {
|
||||
agvNdcTwoDeviceDriver = (AgvNdcTwoDeviceDriver) agvDevice.getDeviceDriver();
|
||||
AgvNdcTwoDeviceDriver agvNdcTwoDeviceDriver = (AgvNdcTwoDeviceDriver) agvDevice.getDeviceDriver();
|
||||
agvNdcTwoDeviceDriver.setInstruction(null);
|
||||
} else if (device.getDeviceDriver() instanceof AgvNdcOneDeviceDriver) {
|
||||
agvNdcOneDeviceDriver = (AgvNdcOneDeviceDriver) device.getDeviceDriver();
|
||||
AgvNdcOneDeviceDriver agvNdcOneDeviceDriver = (AgvNdcOneDeviceDriver) device.getDeviceDriver();
|
||||
agvNdcOneDeviceDriver.setInstruction(null);
|
||||
}
|
||||
}
|
||||
@@ -273,8 +280,7 @@ public class TwoNDCSocketConnectionAutoRun extends AbstractAutoRunnable {
|
||||
} else {
|
||||
log.info("未下发NDC信号原因: 下发开门信号值为:{},读取开门信号值为:{}", standardAutodoorDeviceDriver.getToOpen(), standardAutodoorDeviceDriver.getOpen());
|
||||
}
|
||||
}
|
||||
else if (device.getDeviceDriver() instanceof RasterDeviceDriver){
|
||||
} else if (device.getDeviceDriver() instanceof RasterDeviceDriver) {
|
||||
rasterDeviceDriver = (RasterDeviceDriver) device.getDeviceDriver();
|
||||
try {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
@@ -316,8 +322,7 @@ public class TwoNDCSocketConnectionAutoRun extends AbstractAutoRunnable {
|
||||
} else {
|
||||
log.info("未下发NDC信号原因: 读取自动门信号值为:{}", standardAutodoorDeviceDriver.getClose());
|
||||
}
|
||||
}
|
||||
else if (device.getDeviceDriver() instanceof RasterDeviceDriver) {
|
||||
} else if (device.getDeviceDriver() instanceof RasterDeviceDriver) {
|
||||
rasterDeviceDriver = (RasterDeviceDriver) device.getDeviceDriver();
|
||||
try {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
@@ -336,64 +341,83 @@ public class TwoNDCSocketConnectionAutoRun extends AbstractAutoRunnable {
|
||||
} else {
|
||||
log.info(device_code + "对应设备号为空!");
|
||||
}
|
||||
} else if (phase == 0x64){
|
||||
log.info("AGV车号{}反馈充电任务下发成功,锁定充电桩{}",agvaddr,station);
|
||||
Dict dict = dictService.getDictByName3("station",String.valueOf(agvaddr),null);
|
||||
if (ObjectUtil.isNotEmpty(dict)){
|
||||
} else if (phase == 0x64) {
|
||||
log.info("AGV车号{}反馈充电任务下发成功,锁定充电桩{}", agvaddr, station);
|
||||
Dict dict = dictService.getDictByName3("station", String.valueOf(agvaddr), null);
|
||||
if (ObjectUtil.isNotEmpty(dict)) {
|
||||
dict.setValue("1");
|
||||
dict.setPara2(String.valueOf(agvaddr));
|
||||
dict.setPara3("下发成功");
|
||||
dictService.updateDetail(dict);
|
||||
}
|
||||
//充电成功
|
||||
}else if (phase == 0x65){
|
||||
log.info("AGV车号{}反馈充电中,充电桩{}",agvaddr,station);
|
||||
} else if (phase == 0x65) {
|
||||
log.info("AGV车号{}反馈充电中,充电桩{}", agvaddr, station);
|
||||
//充电取消上报
|
||||
}else if (phase == 0x66){
|
||||
log.info("AGV车号{}反馈充电任务已取消,释放充电桩{}",agvaddr,station);
|
||||
Dict dict = dictService.getDictByName3("station",String.valueOf(agvaddr),null);
|
||||
if (ObjectUtil.isNotEmpty(dict)){
|
||||
} else if (phase == 0x66) {
|
||||
log.info("AGV车号{}反馈充电任务已取消,释放充电桩{}", agvaddr, station);
|
||||
Dict dict = dictService.getDictByName3("station", String.valueOf(agvaddr), null);
|
||||
if (ObjectUtil.isNotEmpty(dict)) {
|
||||
dict.setValue("0");
|
||||
dict.setPara2("");
|
||||
dict.setPara3("充电桩空闲");
|
||||
dictService.updateDetail(dict);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
//上报异常信息
|
||||
//(不需要WCS反馈)
|
||||
if (phase == 0x67 || phase == 0x70 || phase == 0x71 || phase == 0x72 || phase == 0x73 || phase == 0x74) {
|
||||
device = deviceAppService.findDeviceByCode(Integer.toString(arr[18] * 256 + arr[19]));
|
||||
} else {
|
||||
device = deviceAppService.findDeviceByCode(Integer.toString(arr[20]));
|
||||
|
||||
String carnoKey = String.valueOf(arr[20]);
|
||||
int phaseForCarno = arr[16] * 256 + arr[17];
|
||||
if (phaseForCarno == 0x67 || phaseForCarno == 0x70 || phaseForCarno == 0x71 || phaseForCarno == 0x72 || phaseForCarno == 0x73 || phaseForCarno == 0x74) {
|
||||
carnoKey = String.valueOf(arr[18] * 256 + arr[19]);
|
||||
}
|
||||
try {
|
||||
if (ObjectUtil.isNotEmpty(device)) {
|
||||
if (device.getDeviceDriver() instanceof AgvNdcTwoDeviceDriver) {
|
||||
agvNdcTwoDeviceDriver = (AgvNdcTwoDeviceDriver) device.getDeviceDriver();
|
||||
CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
agvNdcTwoDeviceDriver.processSocket(arr);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("agv运行逻辑报错:{}", e.getMessage());
|
||||
LuceneLogDto logDto = LuceneLogDto.builder()
|
||||
.content("agv运行报错" + "报错原因:" + e.getMessage())
|
||||
.build();
|
||||
logDto.setLog_level(4);
|
||||
luceneExecuteLogService.deviceExecuteLog(logDto);
|
||||
final int[] arrCopy = new int[count];
|
||||
System.arraycopy(arr, 0, arrCopy, 0, count);
|
||||
final String bsCopy = bs.toString();
|
||||
final String finalCarnoKey = carnoKey;
|
||||
ExecutorService executor = carExecutors.computeIfAbsent(finalCarnoKey, k -> {
|
||||
ExecutorService es = Executors.newSingleThreadExecutor(r -> {
|
||||
Thread t = new Thread(r, "NDC2-Car-" + k);
|
||||
t.setDaemon(true);
|
||||
return t;
|
||||
});
|
||||
return es;
|
||||
});
|
||||
Device agvDevice = deviceAppService.findDeviceByCode(carnoKey);
|
||||
|
||||
// if (phase == 0x67 || phase == 0x70 || phase == 0x71 || phase == 0x72 || phase == 0x73 || phase == 0x74) {
|
||||
// device = deviceAppService.findDeviceByCode(Integer.toString(arr[18] * 256 + arr[19]));
|
||||
// } else {
|
||||
// device = deviceAppService.findDeviceByCode(Integer.toString(arr[20]));
|
||||
// }
|
||||
if (ObjectUtil.isNotEmpty(agvDevice)) {
|
||||
String car_phase = carnoKey + "_" + phaseForCarno;
|
||||
AtomicBoolean atomicBoolean = CAR_PHASE.computeIfAbsent(car_phase, k -> new AtomicBoolean(false));
|
||||
if (atomicBoolean.compareAndSet(false, true)) {
|
||||
executor.submit((Runnable) () -> {
|
||||
try {
|
||||
if (agvDevice.getDeviceDriver() instanceof AgvNdcTwoDeviceDriver) {
|
||||
AgvNdcTwoDeviceDriver agvNdcTwoDeviceDriver = (AgvNdcTwoDeviceDriver) agvDevice.getDeviceDriver();
|
||||
agvNdcTwoDeviceDriver.processSocket(arrCopy);
|
||||
} else if (agvDevice.getDeviceDriver() instanceof AgvNdcOneDeviceDriver) {
|
||||
AgvNdcOneDeviceDriver agvNdcOneDeviceDriver = (AgvNdcOneDeviceDriver) agvDevice.getDeviceDriver();
|
||||
agvNdcOneDeviceDriver.processSocket(arrCopy);
|
||||
}
|
||||
});
|
||||
} else if (device.getDeviceDriver() instanceof AgvNdcOneDeviceDriver) {
|
||||
agvNdcOneDeviceDriver = (AgvNdcOneDeviceDriver) device.getDeviceDriver();
|
||||
agvNdcOneDeviceDriver.processSocket(arr);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.info("processSocket出错:{},{},{}", e, e.getMessage(), Arrays.toString(e.getStackTrace()));
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
atomicBoolean.set(false);
|
||||
if (CAR_PHASE.get(car_phase) == atomicBoolean) {
|
||||
CAR_PHASE.remove(car_phase, atomicBoolean);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
log.info("当前phase:" + phase + "未找到对应设备");
|
||||
logServer.deviceExecuteLog("NDC2", "", "","当前车号:" + carnoKey + "当前PHASE值:" + phaseForCarno + "正在执行中,后续不进行处理");
|
||||
log.info("当前车号:" + carnoKey + "当前PHASE值:" + phaseForCarno + "正在执行中,后续不进行处理");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.info("processSocket出错:{},{}", e, e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (!ObjectUtil.isEmpty(data)) {
|
||||
|
||||
@@ -102,7 +102,7 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
|
||||
|
||||
int mode = 2;
|
||||
|
||||
public synchronized void processSocket(int[] arr) throws Exception {
|
||||
public synchronized void processSocket(int[] arr) {
|
||||
device_code = this.getDeviceCode();
|
||||
byte[] data = null;
|
||||
phase = arr[16] * 256 + arr[17];
|
||||
|
||||
@@ -106,7 +106,7 @@ public class AgvNdcTwoDeviceDriver extends AbstractDeviceDriver implements Devic
|
||||
this.error_message = error_message;
|
||||
}
|
||||
|
||||
public synchronized void processSocket(int[] arr) throws Exception {
|
||||
public synchronized void processSocket(int[] arr) {
|
||||
device_code = this.getDeviceCode();
|
||||
byte[] data = null;
|
||||
phase = arr[16] * 256 + arr[17];
|
||||
|
||||
@@ -286,19 +286,19 @@ public class PlugPullDeviceSiteDeviceDriver extends AbstractOpcDeviceDriver impl
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
if (!requireSucess) {
|
||||
if (!requireSucess && StrUtil.isNotEmpty(this.barcode)) {
|
||||
//拔轴完成
|
||||
pullShaftSucess(mode);
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
if (!requireSucess) {
|
||||
if (!requireSucess && StrUtil.isNotEmpty(this.barcode)) {
|
||||
//申请拔轴
|
||||
applyPullShaft(mode);
|
||||
}
|
||||
break;
|
||||
case 8:
|
||||
if (!requireSucess) {
|
||||
if (!requireSucess && this.size > 0) {
|
||||
//缓存线已满,申请行架任务
|
||||
applyTask(mode);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user