代码重构

This commit is contained in:
ldj_willow
2022-08-18 15:00:19 +08:00
parent fe95314152
commit f1cad6b34d
2 changed files with 0 additions and 203 deletions

View File

@@ -24,7 +24,6 @@ import org.nl.acs.opc.DeviceAppServiceImpl;
import org.nl.acs.opc.DeviceType;
import org.nl.acs.task.service.TaskService;
import org.nl.exception.BadRequestException;
import org.nl.start.auto.run.NDCSocketConnectionAutoRun;
import org.nl.utils.SpringContextHolder;
import org.slf4j.MDC;
import org.springframework.stereotype.Service;

View File

@@ -1,202 +0,0 @@
package org.nl.start.auto.run;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import org.nl.acs.agv.server.NDCAgvService;
import org.nl.acs.agv.server.impl.NDCAgvServiceImpl;
import org.nl.acs.config.AcsConfig;
import org.nl.acs.config.server.AcsConfigService;
import org.nl.acs.config.server.impl.AcsConfigServiceImpl;
import org.nl.acs.device.service.DeviceService;
import org.nl.acs.ext.wms.service.AcsToWmsService;
import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl;
import org.nl.acs.ext.xr_lk.service.AcsToXrlkService;
import org.nl.acs.instruction.service.InstructionService;
import org.nl.acs.instruction.service.dto.Instruction;
import org.nl.acs.instruction.service.impl.InstructionServiceImpl;
import org.nl.acs.opc.Device;
import org.nl.acs.opc.DeviceAppService;
import org.nl.utils.SpringContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.util.Date;
@Slf4j
@Component
public class NDCSocketConnectionAutoRun extends AbstractAutoRunnable {
Socket s;
String ip = "127.0.0.1";
int port = 1234;
static DataOutputStream dos;
static DataInputStream dis;
private int recordTimeOut = 10000;
private Date recordTime;
String[] ERROR = new String[]{
"货叉尖部传感器触发", "S300传感器触发", "载货状态改变", "急停按钮触发", "触边开关出发", "需要复位",
"停在充电位", "取货失败", "放货失败", "轮子打滑", "没有动作码不能进入站点", "取货时有货", "丢失定位",
"抬叉停止"};
boolean bConnected = true;
boolean isReConnect = false;
@Autowired
AcsConfigService acsConfigService;
@Autowired
AutoRunService autoRunService;
public NDCSocketConnectionAutoRun() {
this.recordTime = new Date((new Date()).getTime() - (long) this.recordTimeOut);
}
@Override
public String getCode() {
return NDCSocketConnectionAutoRun.class.getSimpleName();
}
@Override
public String getName() {
return "NDC在线连接";
}
@Override
public void autoRun() {
try {
AcsConfigService acsConfigService = SpringContextHolder.getBean(AcsConfigServiceImpl.class);
InstructionService instructionService = SpringContextHolder.getBean(InstructionServiceImpl.class);
AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class);
NDCAgvService ndcAgvService = SpringContextHolder.getBean(NDCAgvServiceImpl.class);
DeviceAppService deviceAppService = SpringContextHolder.getBean(DeviceAppService.class);
DeviceService deviceService = SpringContextHolder.getBean(DeviceService.class);
AcsToXrlkService acsToXrlkService = SpringContextHolder.getBean(AcsToXrlkService.class);
ip = acsConfigService.findConfigFromCache().get(AcsConfig.AGVURL);
port = Integer.parseInt(acsConfigService.findConfigFromCache().get(AcsConfig.AGVPORT));
byte[] b = new byte[1028];
s = new Socket(ip, port);
dos = new DataOutputStream(s.getOutputStream());
dis = new DataInputStream(s.getInputStream());
while (bConnected) {
int count = dis.read(b);
if (count == -1) {
break;
}
int[] arr = new int[count];
StringBuffer bs = new StringBuffer();
for (int i = 0; i < count; i++) {
int temp = b[i];
if (temp < 0)
temp += 256;
arr[i] = temp;
StringBuffer bs1 = new StringBuffer("0");
bs.append(temp < 16 ? bs1.append(Integer.toHexString(temp)) : Integer.toHexString(temp));
}
System.out.println("收到请求参数:" + bs);
boolean flag = false;
if (arr[8] * 256 + arr[9] == 0x73) {
byte[] data = null;
System.out.println("接收agv上报信息" + bs);
//执行阶段
int phase = arr[16] * 256 + arr[17];
// agv任务号
int index = arr[12] * 256 + arr[13];
//任务号
int ikey = arr[26] * 256 + arr[27];
//站点号
int agvaddr = arr[18] * 256 + arr[19];
//车号
int carno = arr[20];
Instruction inst = null;
if (ikey != 0) {
inst = instructionService.findByCodeFromCache(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;
String emptyNum = 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];
emptyNum = point[1];
} else {
device_code = old_device_code;
}
device = deviceAppService.findDeviceByCode(device_code);
}
if (!ObjectUtil.isEmpty(data)) {
write(data);
}
} else {
System.out.println("agv上报不是0073类型动作不处理");
}
}
} catch (Exception e) {
} finally {
}
}
@Override
public void stop() {
super.after();
try {
s.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void write(byte[] b) {
try {
log.info("下发agv数据:" + Bytes2HexString(b));
System.out.println("下发agv数据:" + Bytes2HexString(b));
dos.write(b);
dos.flush();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static String Bytes2HexString(byte[] b) {
String ret = "";
for (int i = 0; i < b.length; i++) {
String hex = Integer.toHexString(b[i] & 0xFF);
if (hex.length() == 1) {
hex = '0' + hex;
}
ret += hex.toUpperCase();
}
return ret;
}
}