更新
This commit is contained in:
@@ -31,8 +31,6 @@ import org.nl.acs.opc.DeviceAppService;
|
||||
import org.nl.acs.opc.DeviceAppServiceImpl;
|
||||
import org.nl.acs.task.service.TaskService;
|
||||
import org.nl.exception.BadRequestException;
|
||||
import org.nl.start.auto.run.NDCSocketConnectionAutoRun;
|
||||
import org.nl.start.auto.run.OneNDCSocketConnectionAutoRun;
|
||||
import org.nl.utils.SpringContextHolder;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -485,7 +483,7 @@ public class AgvServiceImpl implements AgvService {
|
||||
};
|
||||
log.info("下发AGV作业指令--{}", str1);
|
||||
|
||||
OneNDCSocketConnectionAutoRun.write(b);
|
||||
// OneNDCSocketConnectionAutoRun.write(b);
|
||||
System.out.println("下发agv指令数据:" + Bytes2HexString(b));
|
||||
}
|
||||
}
|
||||
@@ -578,7 +576,7 @@ public class AgvServiceImpl implements AgvService {
|
||||
};
|
||||
log.info("下发AGV作业指令--{}", str1);
|
||||
|
||||
NDCSocketConnectionAutoRun.write(b);
|
||||
// NDCSocketConnectionAutoRun.write(b);
|
||||
System.out.println("下发agv指令数据:" + Bytes2HexString(b));
|
||||
}
|
||||
|
||||
@@ -843,7 +841,7 @@ public class AgvServiceImpl implements AgvService {
|
||||
};
|
||||
log.info("下发删除AGV指令--{}", Bytes2HexString(b));
|
||||
if (ObjectUtil.isNotEmpty(b)) {
|
||||
NDCSocketConnectionAutoRun.write(b);
|
||||
// NDCSocketConnectionAutoRun.write(b);
|
||||
System.out.println("下发删除agv指令数据:" + Bytes2HexString(b));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ import org.nl.acs.log.service.LogServer;
|
||||
import org.nl.acs.opc.DeviceAppService;
|
||||
import org.nl.acs.route.service.RouteLineService;
|
||||
import org.nl.acs.task.service.TaskService;
|
||||
import org.nl.start.auto.run.OneNDCSocketConnectionAutoRun;
|
||||
import org.nl.utils.SpringContextHolder;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@@ -125,7 +124,7 @@ public class StandardOrdinarySiteDeviceDriver extends AbstractDeviceDriver imple
|
||||
inst.setExecute_status("1");
|
||||
instructionService.update(inst);
|
||||
byte[] data = agvService.sendAgvOneModeInst(agvphase, index, 0);
|
||||
OneNDCSocketConnectionAutoRun.write(data);
|
||||
// OneNDCSocketConnectionAutoRun.write(data);
|
||||
agvphase = 0;
|
||||
index = 0;
|
||||
inst = null;
|
||||
@@ -141,7 +140,7 @@ public class StandardOrdinarySiteDeviceDriver extends AbstractDeviceDriver imple
|
||||
inst.setExecute_status("2");
|
||||
instructionService.update(inst);
|
||||
byte[] data = agvService.sendAgvOneModeInst(agvphase, index, 0);
|
||||
OneNDCSocketConnectionAutoRun.write(data);
|
||||
// OneNDCSocketConnectionAutoRun.write(data);
|
||||
agvphase = 0;
|
||||
index = 0;
|
||||
inst = null;
|
||||
@@ -157,7 +156,7 @@ public class StandardOrdinarySiteDeviceDriver extends AbstractDeviceDriver imple
|
||||
inst.setExecute_status("5");
|
||||
instructionService.update(inst);
|
||||
byte[] data = agvService.sendAgvOneModeInst(agvphase, index, 0);
|
||||
OneNDCSocketConnectionAutoRun.write(data);
|
||||
// OneNDCSocketConnectionAutoRun.write(data);
|
||||
agvphase = 0;
|
||||
index = 0;
|
||||
inst = null;
|
||||
@@ -172,7 +171,7 @@ public class StandardOrdinarySiteDeviceDriver extends AbstractDeviceDriver imple
|
||||
inst.setExecute_status("6");
|
||||
instructionService.update(inst);
|
||||
byte[] data = agvService.sendAgvOneModeInst(agvphase, index, 0);
|
||||
OneNDCSocketConnectionAutoRun.write(data);
|
||||
// OneNDCSocketConnectionAutoRun.write(data);
|
||||
agvphase = 0;
|
||||
index = 0;
|
||||
inst = null;
|
||||
|
||||
@@ -6,7 +6,6 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.acs.test.service.TestService;
|
||||
import org.nl.start.auto.run.LetteringSocketConnectionAutoRun;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -20,92 +19,36 @@ import java.util.Map;
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class TestServiceImpl implements TestService {
|
||||
public class TestServiceImpl implements TestService
|
||||
{
|
||||
|
||||
@Override
|
||||
public void test1() throws IOException {
|
||||
|
||||
try {
|
||||
//返回编译完成信号
|
||||
LetteringSocketConnectionAutoRun.write("SETMSG 26 1" + "\r\n");
|
||||
//返回打印开始信号
|
||||
LetteringSocketConnectionAutoRun.write("SETMSG 2 1" + "\r\n");
|
||||
//返回打印完成信号
|
||||
LetteringSocketConnectionAutoRun.write("SETMSG 3 1" + "\r\n");
|
||||
//返回每次打印的内容
|
||||
LetteringSocketConnectionAutoRun.write("SETMSG 24 1" + "\r\n");
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void test2() throws IOException {
|
||||
try {
|
||||
LetteringSocketConnectionAutoRun.write("BUFFERCLEAR" + "\r\n");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void test3() throws IOException {
|
||||
// LOADPROJECT "ZY.lbm"
|
||||
//此处为模板名称 D310激光机,加载CS.lbm模版
|
||||
String str = "CS.lbm";
|
||||
try {
|
||||
LetteringSocketConnectionAutoRun.write("LOADPROJECT" + " \"" + str + "\"" + "\r\n");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void test4(Map map) throws IOException {
|
||||
String name = map.get("name").toString();
|
||||
String name2 = map.get("name2").toString();
|
||||
String name3 = map.get("name3").toString();
|
||||
String name4 = map.get("name4").toString();
|
||||
String yh = "\"";
|
||||
try {
|
||||
//先清空缓存
|
||||
LetteringSocketConnectionAutoRun.write("BUFFERCLEAR" + "\r\n");
|
||||
// test5();
|
||||
// LetteringSocketConnectionAutoRun.write("BUFFERDATA -1 "+ yh + name + yh +" " + yh + name2 + yh +" "
|
||||
// +yh +name3 +yh + " " + yh + name4 + yh + "\r\n");
|
||||
|
||||
//两行
|
||||
// LetteringSocketConnectionAutoRun.write("BUFFERDATA -1 "+ yh + name + yh +" " + yh + name2 + yh +" "
|
||||
// + "\r\n");
|
||||
|
||||
LetteringSocketConnectionAutoRun.write("BUFFERDATA -1 " + yh + name + yh + " " + "\r\n");
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void test5() throws IOException {
|
||||
try {
|
||||
LetteringSocketConnectionAutoRun.write("BUFFERCLEAR" + "\r\n");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void test6(Map map) throws IOException {
|
||||
String yh = "\"";
|
||||
String inst = map.get("inst").toString();
|
||||
String inst2 = map.get("inst2").toString();
|
||||
String strInst = "SETTEXT " + "S1" + " " + yh + inst + yh + "\r\n"; //2个变量
|
||||
String strInst2 = "SETTEXT " + "S2" + " " + yh + inst2 + yh + "\r\n"; //2个变量
|
||||
|
||||
LetteringSocketConnectionAutoRun.write(strInst);
|
||||
LetteringSocketConnectionAutoRun.write(strInst2);
|
||||
|
||||
}
|
||||
|
||||
@@ -116,9 +59,6 @@ public class TestServiceImpl implements TestService {
|
||||
|
||||
@Override
|
||||
public JSONObject print() throws IOException {
|
||||
JSONObject jo = new JSONObject();
|
||||
jo.put("cpbh", "A1111111111");
|
||||
jo.put("cpmc", "产品名称:A1111111111");
|
||||
return jo;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,141 +0,0 @@
|
||||
package org.nl.start.auto.run;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.acs.config.AcsConfig;
|
||||
import org.nl.acs.config.server.AcsConfigService;
|
||||
import org.nl.acs.config.server.impl.AcsConfigServiceImpl;
|
||||
import org.nl.utils.SpringContextHolder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.Socket;
|
||||
import java.util.Date;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class LetteringSocketConnectionAutoRun extends AbstractAutoRunnable {
|
||||
|
||||
Socket s;
|
||||
String ip = "192.168.46.225";
|
||||
int port = 1234;
|
||||
static DataOutputStream dos;
|
||||
static DataInputStream dis;
|
||||
private int recordTimeOut = 10000;
|
||||
private Date recordTime;
|
||||
boolean bConnected = true;
|
||||
|
||||
public LetteringSocketConnectionAutoRun() {
|
||||
this.recordTime = new Date((new Date()).getTime() - (long) this.recordTimeOut);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCode() {
|
||||
return LetteringSocketConnectionAutoRun.class.getSimpleName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "海亮激光刻字在线连接";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void autoRun() throws IOException {
|
||||
AcsConfigService acsConfigService = SpringContextHolder.getBean(AcsConfigServiceImpl.class);
|
||||
|
||||
ip = acsConfigService.findConfigFromCache().get(AcsConfig.LETTERINGURL);
|
||||
port = Integer.parseInt(acsConfigService.findConfigFromCache().get(AcsConfig.LETTERINGPORT));
|
||||
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;
|
||||
bs.append(asciiToString(String.valueOf(temp)));
|
||||
}
|
||||
System.out.println("收到请求参数:" + bs);
|
||||
//打印完成
|
||||
if (StrUtil.equals(bs.toString(), "MSG 3")) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void write(String str) throws IOException {
|
||||
System.out.println(str);
|
||||
dos.write(hexStringToByte(bytesToHexString(stringToByte(str))));
|
||||
}
|
||||
|
||||
public static byte[] stringToByte(String str) {
|
||||
byte[] bytes = str.getBytes();
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public static String bytesToHexString(byte[] src) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < src.length; i++) {
|
||||
int v = src[i] & 0xff;
|
||||
String hv = Integer.toHexString(v);
|
||||
if (hv.length() < 2) {
|
||||
builder.append(0);
|
||||
}
|
||||
builder.append(hv);
|
||||
}
|
||||
return builder.toString().toUpperCase();
|
||||
}
|
||||
|
||||
|
||||
public static byte[] hexStringToByte(String hex) {
|
||||
byte[] b = new byte[hex.length() / 2];
|
||||
int j = 0;
|
||||
for (int i = 0; i < b.length; i++) {
|
||||
char c0 = hex.charAt(j++);
|
||||
char c1 = hex.charAt(j++);
|
||||
b[i] = (byte) ((parse(c0) << 4) | parse(c1));
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
private static int parse(char c) {
|
||||
if (c >= 'a')
|
||||
return (c - 'a' + 10) & 0x0f;
|
||||
if (c >= 'A')
|
||||
return (c - 'A' + 10) & 0x0f;
|
||||
return (c - '0') & 0x0f;
|
||||
}
|
||||
|
||||
/*
|
||||
* Ascii转换为字符串
|
||||
*
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public static String asciiToString(String value) {
|
||||
StringBuffer sbu = new StringBuffer();
|
||||
String[] chars = value.split(",");
|
||||
for (int i = 0; i < chars.length; i++) {
|
||||
sbu.append((char) Integer.parseInt(chars[i]));
|
||||
}
|
||||
return sbu.toString();
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) throws UnsupportedEncodingException {
|
||||
byte[] bytes = "你".getBytes("utf-8");
|
||||
}
|
||||
}
|
||||
@@ -1,226 +0,0 @@
|
||||
package org.nl.start.auto.run;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.acs.agv.server.AgvService;
|
||||
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.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;
|
||||
import java.util.List;
|
||||
|
||||
import static org.nl.acs.agv.server.impl.AgvServiceImpl.Bytes2HexString;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class NDCSocketConnectionAutoRun extends AbstractAutoRunnable {
|
||||
|
||||
Socket s;
|
||||
String ip = "192.168.46.225";
|
||||
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);
|
||||
AgvService AgvService = SpringContextHolder.getBean(AgvService.class);
|
||||
DeviceAppService deviceAppService = SpringContextHolder.getBean(DeviceAppService.class);
|
||||
DeviceService deviceService = SpringContextHolder.getBean(DeviceService.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 link_inst = null;
|
||||
List<Instruction> insts = null;
|
||||
boolean link_flag = false;
|
||||
Device agv_device = null;
|
||||
if (carno != 0) {
|
||||
agv_device = deviceAppService.findDeviceByCode(String.valueOf(carno));
|
||||
}
|
||||
if (ikey != 0) {
|
||||
insts = instructionService.findByLinkNum(String.valueOf(ikey));
|
||||
}
|
||||
if (!ObjectUtil.isEmpty(link_inst)) {
|
||||
link_flag = true;
|
||||
}
|
||||
log.info("接收agv上报信息:" + bs);
|
||||
log.info("接收agv上报信息:" + "phase--" + phase + " index--" + index + " ikey--" + ikey + " agvaddr--" + agvaddr + " Car--" + carno);
|
||||
Device device = null;
|
||||
String device_code = null;
|
||||
|
||||
|
||||
//开始任务/上报订单号
|
||||
if (phase == 0x01) {
|
||||
for (Instruction inst : insts) {
|
||||
inst.setInstruction_status("1");
|
||||
inst.setAgv_jobno(String.valueOf(index));
|
||||
inst.setSend_status("1");
|
||||
instructionService.update(inst);
|
||||
}
|
||||
data = AgvService.sendAgvTwoModeInst(phase, index, 0);
|
||||
|
||||
|
||||
} else if (phase == 0x1A) {
|
||||
|
||||
for (Instruction inst : insts) {
|
||||
if (!ObjectUtil.isEmpty(inst)) {
|
||||
instructionService.finish(inst.getInstruction_id());
|
||||
}
|
||||
}
|
||||
data = AgvService.sendAgvTwoModeInst(phase, index, 0);
|
||||
|
||||
} else if (phase == 0x30) {
|
||||
data = AgvService.sendAgvTwoModeInst(143, index, 0);
|
||||
|
||||
} else if (phase == 0xFF) {
|
||||
|
||||
for (Instruction inst : insts) {
|
||||
if (!ObjectUtil.isEmpty(inst)) {
|
||||
instructionService.cancelNOSendAgv(inst.getInstruction_id());
|
||||
}
|
||||
}
|
||||
data = AgvService.sendAgvTwoModeInst(phase, index, 0);
|
||||
|
||||
} else {
|
||||
|
||||
if (phase == 0x67) {
|
||||
device = deviceAppService.findDeviceByCode(Integer.toString(arr[27]));
|
||||
} else {
|
||||
device = deviceAppService.findDeviceByCode(Integer.toString(arr[20]));
|
||||
}
|
||||
|
||||
if (ObjectUtil.isEmpty(device)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,238 +0,0 @@
|
||||
package org.nl.start.auto.run;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.acs.agv.server.AgvService;
|
||||
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.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;
|
||||
import java.util.List;
|
||||
|
||||
import static org.nl.acs.agv.server.impl.AgvServiceImpl.Bytes2HexString;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable {
|
||||
|
||||
Socket s;
|
||||
String ip = "192.168.46.225";
|
||||
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 OneNDCSocketConnectionAutoRun() {
|
||||
this.recordTime = new Date((new Date()).getTime() - (long) this.recordTimeOut);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCode() {
|
||||
return OneNDCSocketConnectionAutoRun.class.getSimpleName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "单工NDC在线连接";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void autoRun() throws IOException {
|
||||
System.out.println("OneAgv链接开始");
|
||||
AcsConfigService acsConfigService = SpringContextHolder.getBean(AcsConfigServiceImpl.class);
|
||||
InstructionService instructionService = SpringContextHolder.getBean(InstructionServiceImpl.class);
|
||||
AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class);
|
||||
AgvService AgvService = SpringContextHolder.getBean(AgvService.class);
|
||||
DeviceAppService deviceAppService = SpringContextHolder.getBean(DeviceAppService.class);
|
||||
DeviceService deviceService = SpringContextHolder.getBean(DeviceService.class);
|
||||
ip = acsConfigService.findConfigFromCache().get(AcsConfig.ONEAGVURL);
|
||||
port = Integer.parseInt(acsConfigService.findConfigFromCache().get(AcsConfig.ONEAGVPORT));
|
||||
|
||||
|
||||
try {
|
||||
|
||||
byte[] b = new byte[1028];
|
||||
s = new Socket(ip, port);
|
||||
dos = new DataOutputStream(s.getOutputStream());
|
||||
dis = new DataInputStream(s.getInputStream());
|
||||
System.out.println("OneAgv链接成功");
|
||||
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 link_inst = null;
|
||||
List<Instruction> insts = null;
|
||||
boolean link_flag = false;
|
||||
Device agv_device = null;
|
||||
if (carno != 0) {
|
||||
agv_device = deviceAppService.findDeviceByCode(String.valueOf(carno));
|
||||
}
|
||||
if (ikey != 0) {
|
||||
insts = instructionService.findByLinkNum(String.valueOf(ikey));
|
||||
}
|
||||
if (!ObjectUtil.isEmpty(link_inst)) {
|
||||
link_flag = true;
|
||||
}
|
||||
log.info("接收agv上报信息:" + bs);
|
||||
log.info("接收agv上报信息:" + "phase--" + phase + " index--" + index + " ikey--" + ikey + " agvaddr--" + agvaddr + " Car--" + carno);
|
||||
Device device = null;
|
||||
String device_code = null;
|
||||
|
||||
|
||||
//开始任务/上报订单号
|
||||
if (phase == 0x01) {
|
||||
for (Instruction inst : insts) {
|
||||
inst.setInstruction_status("1");
|
||||
inst.setAgv_jobno(String.valueOf(index));
|
||||
inst.setSend_status("1");
|
||||
instructionService.update(inst);
|
||||
}
|
||||
data = AgvService.sendAgvOneModeInst(phase, index, 0);
|
||||
|
||||
|
||||
} else if (phase == 0x0A) {
|
||||
|
||||
for (Instruction inst : insts) {
|
||||
if (!ObjectUtil.isEmpty(inst)) {
|
||||
instructionService.finish(inst.getInstruction_id());
|
||||
}
|
||||
}
|
||||
data = AgvService.sendAgvOneModeInst(phase, index, 0);
|
||||
|
||||
} else if (phase == 0x30) {
|
||||
data = AgvService.sendAgvOneModeInst(143, index, 0);
|
||||
|
||||
} else if (phase == 0xFF) {
|
||||
|
||||
for (Instruction inst : insts) {
|
||||
if (!ObjectUtil.isEmpty(inst)) {
|
||||
instructionService.cancelNOSendAgv(inst.getInstruction_id());
|
||||
}
|
||||
}
|
||||
data = AgvService.sendAgvOneModeInst(phase, index, 0);
|
||||
|
||||
} else if (phase == 0x50) {//离开区域
|
||||
data = AgvService.sendAgvOneModeInst(phase, index, 0);
|
||||
|
||||
} else if (phase == 0x51) {//离开区域
|
||||
|
||||
data = AgvService.sendAgvOneModeInst(phase, index, 0);
|
||||
|
||||
} else {
|
||||
|
||||
if (phase == 0x67) {
|
||||
device = deviceAppService.findDeviceByCode(Integer.toString(arr[27]));
|
||||
} else {
|
||||
device = deviceAppService.findDeviceByCode(Integer.toString(arr[20]));
|
||||
}
|
||||
}
|
||||
if (!ObjectUtil.isEmpty(data)) {
|
||||
write(data);
|
||||
}
|
||||
|
||||
} else {
|
||||
// System.out.println("agv上报不是0073类型动作,不处理");
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
System.out.println("OneAgv链接异常");
|
||||
if (ObjectUtil.isNotEmpty(s)) {
|
||||
s.close();
|
||||
}
|
||||
System.out.println(e.getMessage());
|
||||
e.printStackTrace();
|
||||
|
||||
} 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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user