|
|
|
|
@ -15,6 +15,9 @@ import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
|
|
import java.nio.charset.Charset;
|
|
|
|
|
import java.util.concurrent.ArrayBlockingQueue;
|
|
|
|
|
import java.util.concurrent.ThreadPoolExecutor;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 昆船通讯协议(TCP 传输JSON)
|
|
|
|
|
@ -30,6 +33,8 @@ public class KsecDecoder extends DelimiterBasedFrameDecoder {
|
|
|
|
|
|
|
|
|
|
private static String lastLotnum;
|
|
|
|
|
|
|
|
|
|
private static ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(7,21,30, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<>(20000));
|
|
|
|
|
|
|
|
|
|
private PlcService plcService;
|
|
|
|
|
|
|
|
|
|
public KsecDecoder(int maxFrameLength, ByteBuf delimiter, PlcService plcService) {
|
|
|
|
|
@ -44,86 +49,120 @@ public class KsecDecoder extends DelimiterBasedFrameDecoder {
|
|
|
|
|
log.debug("no data");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
String body = in.toString(Charset.forName("UTF-8"));
|
|
|
|
|
if (body.startsWith("<")){
|
|
|
|
|
// 去掉首尾标识符
|
|
|
|
|
body = body.substring(1, body.length());
|
|
|
|
|
KsecInfo ksecInfo = JSONObject.parseObject(body, KsecInfo.class);
|
|
|
|
|
if (Cmd.A.name().equals(ksecInfo.getType())) {
|
|
|
|
|
in.release();
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
KsecDataInfo dataInfo = ksecInfo.getData();
|
|
|
|
|
String lotnum = dataInfo.getLotnum();
|
|
|
|
|
PlcCmdInfo plcCmdInfo = null;
|
|
|
|
|
String srmNumber = null;
|
|
|
|
|
String cmdName = null;
|
|
|
|
|
if(dataInfo != null){
|
|
|
|
|
//左右换过来
|
|
|
|
|
if(dataInfo.getFromDirection() == 1){
|
|
|
|
|
dataInfo.setFromDirection(2);
|
|
|
|
|
}else {
|
|
|
|
|
dataInfo.setFromDirection(1);
|
|
|
|
|
}
|
|
|
|
|
if(dataInfo.getToDirection() != null && dataInfo.getToDirection() == 1){
|
|
|
|
|
dataInfo.setToDirection(2);
|
|
|
|
|
}else {
|
|
|
|
|
dataInfo.setToDirection(1);
|
|
|
|
|
}
|
|
|
|
|
plcCmdInfo = new PlcCmdInfo(dataInfo.getSRMNumber(), dataInfo.getTaskId(), dataInfo.getFromSide(), dataInfo.getFromDirection(), dataInfo.getFromColumn(), dataInfo.getFromRow(), dataInfo.getFromSeparation(),dataInfo.getToSide(), dataInfo.getToDirection(), dataInfo.getToColumn(), dataInfo.getToRow(),dataInfo.getToSeparation(),lotnum);
|
|
|
|
|
KescRunnable kescRunnable = new KescRunnable(in,ctx,plcService);
|
|
|
|
|
threadPoolExecutor.execute(kescRunnable);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
srmNumber = dataInfo.getSRMNumber();
|
|
|
|
|
cmdName = dataInfo.getCmdName();
|
|
|
|
|
}
|
|
|
|
|
if (Cmd.A.name().equals(ksecInfo.getType())) {
|
|
|
|
|
//心跳
|
|
|
|
|
log.debug("receieve heart ");
|
|
|
|
|
} else if (Cmd.B.name().equals(ksecInfo.getType())) {
|
|
|
|
|
tcpLogger.info("info:{}",body);
|
|
|
|
|
//任务
|
|
|
|
|
if (Cmd.B1.name().equals(cmdName)) {
|
|
|
|
|
//昆船盘点模式下也会发B1 ,但是不会发送B2
|
|
|
|
|
//这里判断下,是否存在盘点批次号 若存在,既是盘点的B1,无需处理;若不存在lotnum,则是随行的B1
|
|
|
|
|
if(StringUtils.isEmpty(dataInfo.getLotnum())){
|
|
|
|
|
//任务开始 旋转到原点位
|
|
|
|
|
plcService.gyrateCamera(plcCmdInfo,Cmd.C5.name());
|
|
|
|
|
plcService.orderStart(plcCmdInfo);
|
|
|
|
|
}else {
|
|
|
|
|
log.info("check move");
|
|
|
|
|
}
|
|
|
|
|
public static class KescRunnable implements Runnable{
|
|
|
|
|
|
|
|
|
|
private ByteBuf in;
|
|
|
|
|
|
|
|
|
|
} else if (Cmd.B2.name().equals(cmdName)) {
|
|
|
|
|
//B2 C4 一起发的,需要停止等B2
|
|
|
|
|
private ChannelHandlerContext ctx;
|
|
|
|
|
|
|
|
|
|
//这里判断是不是双伸
|
|
|
|
|
if(plcCmdInfo.getSeparation2() == 2){
|
|
|
|
|
//深测货架延迟
|
|
|
|
|
Thread.sleep(plcService.getConfigProperties().getCameraConfig().getB2OutDelayTime());
|
|
|
|
|
private PlcService plcService;
|
|
|
|
|
|
|
|
|
|
public KescRunnable(ByteBuf body,ChannelHandlerContext ctx,PlcService plcService){
|
|
|
|
|
this.in = body;
|
|
|
|
|
this.ctx = ctx;
|
|
|
|
|
this.plcService = plcService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
String body = in.toString(Charset.forName("UTF-8"));
|
|
|
|
|
tcpLogger.info(body);
|
|
|
|
|
if (body.startsWith("<")){
|
|
|
|
|
// 去掉首尾标识符
|
|
|
|
|
body = body.substring(1, body.length());
|
|
|
|
|
KsecInfo ksecInfo = JSONObject.parseObject(body, KsecInfo.class);
|
|
|
|
|
if (Cmd.A.name().equals(ksecInfo.getType())) {
|
|
|
|
|
in.release();
|
|
|
|
|
return ;
|
|
|
|
|
}
|
|
|
|
|
KsecDataInfo dataInfo = ksecInfo.getData();
|
|
|
|
|
String lotnum = dataInfo.getLotnum();
|
|
|
|
|
PlcCmdInfo plcCmdInfo = null;
|
|
|
|
|
String srmNumber = null;
|
|
|
|
|
String cmdName = null;
|
|
|
|
|
if(dataInfo != null){
|
|
|
|
|
//左右换过来
|
|
|
|
|
if(dataInfo.getFromDirection() == 1){
|
|
|
|
|
dataInfo.setFromDirection(2);
|
|
|
|
|
}else {
|
|
|
|
|
//浅侧延迟
|
|
|
|
|
Thread.sleep(plcService.getConfigProperties().getCameraConfig().getB2DelayTime());
|
|
|
|
|
dataInfo.setFromDirection(1);
|
|
|
|
|
}
|
|
|
|
|
plcService.gyrateCamera(plcCmdInfo,Cmd.C5.name());
|
|
|
|
|
plcService.orderStop(plcCmdInfo);
|
|
|
|
|
}
|
|
|
|
|
} else if (Cmd.C.name().equals(ksecInfo.getType())) {
|
|
|
|
|
tcpLogger.info("info:{}",body);
|
|
|
|
|
//动作
|
|
|
|
|
String code = dataInfo.getCmdName();
|
|
|
|
|
log.info("action code,{},orderInfo:{}", code, plcCmdInfo.toString());
|
|
|
|
|
if (Cmd.isBaseAction(code)) {
|
|
|
|
|
//执行动作,需要保存执行到第几步了
|
|
|
|
|
Integer times = GoodsActionTimes.put(plcCmdInfo.getOrderNum());
|
|
|
|
|
plcCmdInfo.setTimes(times);
|
|
|
|
|
code = code + "-" + plcCmdInfo.getLeftRightStr(times) + plcCmdInfo.getInOutStr(times);
|
|
|
|
|
//执行动作
|
|
|
|
|
plcService.action(plcCmdInfo, times, code);
|
|
|
|
|
}else {
|
|
|
|
|
log.info("other C code :{}",code);
|
|
|
|
|
if(dataInfo.getToDirection() != null && dataInfo.getToDirection() == 1){
|
|
|
|
|
dataInfo.setToDirection(2);
|
|
|
|
|
}else {
|
|
|
|
|
dataInfo.setToDirection(1);
|
|
|
|
|
}
|
|
|
|
|
plcCmdInfo = new PlcCmdInfo(dataInfo.getSRMNumber(), dataInfo.getTaskId(), dataInfo.getFromSide(), dataInfo.getFromDirection(), dataInfo.getFromColumn(), dataInfo.getFromRow(), dataInfo.getFromSeparation(),dataInfo.getToSide(), dataInfo.getToDirection(), dataInfo.getToColumn(), dataInfo.getToRow(),dataInfo.getToSeparation(),lotnum);
|
|
|
|
|
|
|
|
|
|
srmNumber = dataInfo.getSRMNumber();
|
|
|
|
|
cmdName = dataInfo.getCmdName();
|
|
|
|
|
}
|
|
|
|
|
} else if (Cmd.D.name().equals(ksecInfo.getType())) {
|
|
|
|
|
tcpLogger.info("info:{}",body);
|
|
|
|
|
//柳州去掉告警
|
|
|
|
|
if (Cmd.A.name().equals(ksecInfo.getType())) {
|
|
|
|
|
//心跳
|
|
|
|
|
log.debug("receieve heart ");
|
|
|
|
|
} else if (Cmd.B.name().equals(ksecInfo.getType())) {
|
|
|
|
|
|
|
|
|
|
//任务
|
|
|
|
|
if (Cmd.B1.name().equals(cmdName)) {
|
|
|
|
|
//昆船盘点模式下也会发B1 ,但是不会发送B2
|
|
|
|
|
//这里判断下,是否存在盘点批次号 若存在,既是盘点的B1,无需处理;若不存在lotnum,则是随行的B1
|
|
|
|
|
if(StringUtils.isEmpty(dataInfo.getLotnum())){
|
|
|
|
|
//任务开始 旋转到原点位
|
|
|
|
|
plcService.gyrateCamera(plcCmdInfo,Cmd.C5.name());
|
|
|
|
|
plcService.orderStart(plcCmdInfo);
|
|
|
|
|
}else {
|
|
|
|
|
log.info("check move");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else if (Cmd.B2.name().equals(cmdName)) {
|
|
|
|
|
//B2 C4 一起发的,需要停止等B2
|
|
|
|
|
|
|
|
|
|
//这里判断是不是双伸
|
|
|
|
|
if(plcCmdInfo.getSeparation2() == 2){
|
|
|
|
|
//深测货架延迟
|
|
|
|
|
try {
|
|
|
|
|
Thread.sleep(plcService.getConfigProperties().getCameraConfig().getB2OutDelayTime());
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}else {
|
|
|
|
|
//浅侧延迟
|
|
|
|
|
try {
|
|
|
|
|
Thread.sleep(plcService.getConfigProperties().getCameraConfig().getB2DelayTime());
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
plcService.gyrateCamera(plcCmdInfo,Cmd.C5.name());
|
|
|
|
|
plcService.orderStop(plcCmdInfo);
|
|
|
|
|
}
|
|
|
|
|
} else if (Cmd.C.name().equals(ksecInfo.getType())) {
|
|
|
|
|
|
|
|
|
|
//动作
|
|
|
|
|
String code = dataInfo.getCmdName();
|
|
|
|
|
log.info("action code,{},orderInfo:{}", code, plcCmdInfo.toString());
|
|
|
|
|
if (Cmd.isBaseAction(code)) {
|
|
|
|
|
//执行动作,需要保存执行到第几步了
|
|
|
|
|
Integer times = GoodsActionTimes.put(plcCmdInfo.getOrderNum());
|
|
|
|
|
plcCmdInfo.setTimes(times);
|
|
|
|
|
code = code + "-" + plcCmdInfo.getLeftRightStr(times) + plcCmdInfo.getInOutStr(times);
|
|
|
|
|
//执行动作
|
|
|
|
|
try {
|
|
|
|
|
plcService.action(plcCmdInfo, times, code);
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}else {
|
|
|
|
|
log.info("other C code :{}",code);
|
|
|
|
|
}
|
|
|
|
|
} else if (Cmd.D.name().equals(ksecInfo.getType())) {
|
|
|
|
|
|
|
|
|
|
//柳州去掉告警
|
|
|
|
|
// String code = dataInfo.getCmdName();
|
|
|
|
|
// if(code.equals(Cmd.D1.name())){
|
|
|
|
|
// log.info("plcId:{},warn start",plcCmdInfo.getPlcId());
|
|
|
|
|
@ -140,44 +179,31 @@ public class KsecDecoder extends DelimiterBasedFrameDecoder {
|
|
|
|
|
// }else {
|
|
|
|
|
// log.info("other D code :{}",code);
|
|
|
|
|
// }
|
|
|
|
|
} else if (Cmd.E.name().equals(ksecInfo.getType())) {
|
|
|
|
|
tcpLogger.info("info:{}",body);
|
|
|
|
|
//盘点
|
|
|
|
|
//转球机到盘点位 然后拍照
|
|
|
|
|
|
|
|
|
|
if(!StringUtils.isEmpty(lotnum) && !lotnum.equals(lastLotnum)){
|
|
|
|
|
//需要把stock表truncate
|
|
|
|
|
FileUtil.save(lotnum,"lastLotnum");
|
|
|
|
|
tcpLogger.info("truncate table ,last lotnum:{},new lotnum:{}",lastLotnum,lotnum);
|
|
|
|
|
plcService.truncateStock();
|
|
|
|
|
lastLotnum = lotnum;
|
|
|
|
|
}
|
|
|
|
|
plcCmdInfo.setTimes(1);
|
|
|
|
|
Boolean ok = plcService.check(plcCmdInfo,ksecInfo.getData().getCmdName(), dataInfo.getCode(), dataInfo.getTrayCode());
|
|
|
|
|
if(ok){
|
|
|
|
|
ksecInfo.getData().setAckStatus(1);
|
|
|
|
|
}else {
|
|
|
|
|
ksecInfo.getData().setAckStatus(0);
|
|
|
|
|
} else if (Cmd.E.name().equals(ksecInfo.getType())) {
|
|
|
|
|
|
|
|
|
|
//盘点
|
|
|
|
|
//转球机到盘点位 然后拍照
|
|
|
|
|
|
|
|
|
|
if(!StringUtils.isEmpty(lotnum) && !lotnum.equals(lastLotnum)){
|
|
|
|
|
//需要把stock表truncate
|
|
|
|
|
FileUtil.save(lotnum,"lastLotnum");
|
|
|
|
|
tcpLogger.info("truncate table ,last lotnum:{},new lotnum:{}",lastLotnum,lotnum);
|
|
|
|
|
plcService.truncateStock();
|
|
|
|
|
lastLotnum = lotnum;
|
|
|
|
|
}
|
|
|
|
|
plcCmdInfo.setTimes(1);
|
|
|
|
|
Boolean ok = plcService.check(plcCmdInfo,ksecInfo.getData().getCmdName(), dataInfo.getCode(), dataInfo.getTrayCode());
|
|
|
|
|
if(ok){
|
|
|
|
|
ksecInfo.getData().setAckStatus(1);
|
|
|
|
|
}else {
|
|
|
|
|
ksecInfo.getData().setAckStatus(0);
|
|
|
|
|
}
|
|
|
|
|
ctx.channel().writeAndFlush(ksecInfo);
|
|
|
|
|
}
|
|
|
|
|
ctx.channel().writeAndFlush(ksecInfo);
|
|
|
|
|
}
|
|
|
|
|
//找到该货位的最后一张照片与现在的照片比照
|
|
|
|
|
//plcService.recordStock(plcCmdInfo, dataInfo.getCode(), 0, 0);
|
|
|
|
|
}
|
|
|
|
|
in.release();
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class StopThread extends Thread {
|
|
|
|
|
|
|
|
|
|
private PlcCmdInfo plcCmdInfo;
|
|
|
|
|
|
|
|
|
|
public StopThread(PlcCmdInfo plcCmdInfo){
|
|
|
|
|
this.plcCmdInfo = plcCmdInfo;
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
plcService.orderStop(plcCmdInfo);
|
|
|
|
|
}
|
|
|
|
|
in.release();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|