RFID流程

merge-requests/7/head
qiushui 4 years ago
parent f3b5cfa730
commit 307f3994a7

@ -8,6 +8,7 @@ import com.zhehekeji.web.entity.*;
import com.zhehekeji.web.lib.*; import com.zhehekeji.web.lib.*;
import com.zhehekeji.web.mapper.*; import com.zhehekeji.web.mapper.*;
import com.zhehekeji.web.pojo.OrderVO; import com.zhehekeji.web.pojo.OrderVO;
import com.zhehekeji.web.service.RFID.RFIDMap;
import com.zhehekeji.web.service.RFID.RFIDSocket; import com.zhehekeji.web.service.RFID.RFIDSocket;
import com.zhehekeji.web.service.hikLightSource.HikControlSocket; import com.zhehekeji.web.service.hikLightSource.HikControlSocket;
import com.zhehekeji.web.service.ksec.KsecNettyClient; import com.zhehekeji.web.service.ksec.KsecNettyClient;
@ -20,7 +21,9 @@ import org.springframework.util.StringUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.Duration; import java.time.Duration;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingDeque; import java.util.concurrent.BlockingDeque;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
@ -653,6 +656,9 @@ public class PlcService {
}else if(configProperties.getScanCodeMode().getTray() == 3){ }else if(configProperties.getScanCodeMode().getTray() == 3){
//RFID //RFID
RFID rfid = rfidService.getRFIDByPlc(street.getId()); RFID rfid = rfidService.getRFIDByPlc(street.getId());
} }
OrderInfo orderInfo = new OrderInfo(street,plcCmdInfo,1,cmdCode); OrderInfo orderInfo = new OrderInfo(street,plcCmdInfo,1,cmdCode);
Stock stock = stockMapper.getByShelveIdAndRowColumn(orderInfo.getShelveId(),orderInfo.getRow(),orderInfo.getColumn()); Stock stock = stockMapper.getByShelveIdAndRowColumn(orderInfo.getShelveId(),orderInfo.getRow(),orderInfo.getColumn());
@ -738,6 +744,36 @@ public class PlcService {
stockMapper.truncate(); stockMapper.truncate();
} }
public void RFIDCheck(PlcCmdInfo plcCmdInfo){
Street street = streetService.getStreetByPlcId(plcCmdInfo.getPlcId());
if(street != null){
RFID rfid = rfidService.getRFIDByPlc(street.getId());
if(rfid != null){
RFIDStart(rfid.getIp(),rfid.getPort(),street.getId());
}
}
}
public void RFIDStart(String ip,Integer port,Integer streetId){
RFIDSocket rfidSocket = new RFIDSocket(ip,port);
rfidSocket.startCheck();
rfidSocket.readData();
RFIDMap.put(streetId,rfidSocket);
}
public Set<String> RFIDStop(PlcCmdInfo plcCmdInfo){
Street street = streetService.getStreetByPlcId(plcCmdInfo.getPlcId());
RFIDSocket rfidSocket = RFIDMap.get(street.getId());
Set<String> tags = null;
if(rfidSocket != null){
tags = rfidSocket.getTags();
log.info("tags:{}",tags);
rfidSocket.close();
RFIDMap.remove(street.getId());
}
return tags;
}
public ConfigProperties getConfigProperties(){ public ConfigProperties getConfigProperties(){
return configProperties; return configProperties;
} }

@ -0,0 +1,22 @@
package com.zhehekeji.web.service.RFID;
import java.util.HashMap;
import java.util.Map;
public class RFIDMap {
private static Map<Integer,RFIDSocket> socketMap = new HashMap<>();
public static void put(Integer streetId,RFIDSocket rfidSocket){
socketMap.put(streetId,rfidSocket);
}
public static void remove(Integer streetId){
socketMap.remove(streetId);
}
public static RFIDSocket get(Integer streetId){
return socketMap.get(streetId);
}
}

@ -51,16 +51,14 @@ public class RFIDSocket {
is = socket.getInputStream(); is = socket.getInputStream();
} catch (IOException e) { } catch (IOException e) {
log.error("RFIDSocket time out,ip:{},info:{}",ip,e); log.error("RFIDSocket time out,ip:{},info:{}",ip,e);
try {
close(); close();
} catch (IOException ex) {
ex.printStackTrace();
}
} }
} }
public void readData() throws IOException { public void readData(){
running = true; running = true;
buffer = new LinkedList(); buffer = new LinkedList();
@ -167,14 +165,20 @@ public class RFIDSocket {
index = 0; index = 0;
} }
public void close() throws IOException { public void close() {
running = false; running = false;
try {
is.close(); is.close();
socket.close(); socket.close();
os.close(); os.close();
} catch (IOException e) {
e.printStackTrace();
log.error("warn rfid close:{}",e);
}
} }
public void startCheck() throws IOException { public void startCheck(){
Thread thread = new Thread(new Runnable() { Thread thread = new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -186,16 +190,16 @@ public class RFIDSocket {
byte []antChanges = new byte[6]; byte []antChanges = new byte[6];
antChanges[0] = (byte)0xa0; antChanges[0] = (byte)0xa0;
antChanges[1] = (byte)0x04; antChanges[1] = (byte)0x04;
antChanges[2] = (byte)0x22; antChanges[2] = (byte)0x01;
antChanges[3] = (byte)0x74; antChanges[3] = (byte)0x74;
if(i % 2 == 0){ if(i % 2 == 0){
//切换天线 使用天线0 //切换天线 使用天线0
antChanges[4] = (byte)0x00; antChanges[4] = (byte)0x00;
antChanges[5] = (byte)0xc6; antChanges[5] = (byte)0xe7;
}else { }else {
//切换天线 使用天线1 //切换天线 使用天线1
antChanges[4] = (byte)0x01; antChanges[4] = (byte)0x01;
antChanges[5] = (byte)0xc5; antChanges[5] = (byte)0xe6;
} }
i++; i++;
try { try {
@ -207,14 +211,14 @@ public class RFIDSocket {
byte[]bytes = new byte[5]; byte[]bytes = new byte[5];
bytes[0] = (byte)0xa0; bytes[0] = (byte)0xa0;
bytes[1] = (byte)0x03; bytes[1] = (byte)0x03;
bytes[2] = (byte)0x22; bytes[2] = (byte)0x01;
bytes[3] = (byte)0xb0; bytes[3] = (byte)0xb0;
bytes[4] = (byte)0x8b; bytes[4] = (byte)0xac;
try { try {
os.write(bytes); os.write(bytes);
Thread.sleep(70); Thread.sleep(70);
} catch (InterruptedException | IOException e) { } catch (InterruptedException | IOException e) {
log.error("send cmd error:{}",e); log.warn("send rfid cmd error:{}",e);
} }
} }
} }

@ -184,21 +184,29 @@ public class KsecDecoder extends DelimiterBasedFrameDecoder {
//盘点 //盘点
//转球机到盘点位 然后拍照 //转球机到盘点位 然后拍照
if(!StringUtils.isEmpty(lotnum) && !lotnum.equals(lastLotnum)){ // if(!StringUtils.isEmpty(lotnum) && !lotnum.equals(lastLotnum)){
//需要把stock表truncate // //需要把stock表truncate
FileUtil.save(lotnum,"lastLotnum"); // FileUtil.save(lotnum,"lastLotnum");
tcpLogger.info("truncate table ,last lotnum:{},new lotnum:{}",lastLotnum,lotnum); // tcpLogger.info("truncate table ,last lotnum:{},new lotnum:{}",lastLotnum,lotnum);
plcService.truncateStock(); // plcService.truncateStock();
lastLotnum = lotnum; // lastLotnum = lotnum;
} // }
plcCmdInfo.setTimes(1); // plcCmdInfo.setTimes(1);
Boolean ok = plcService.check(plcCmdInfo,ksecInfo.getData().getCmdName(), dataInfo.getCode(), dataInfo.getTrayCode()); // Boolean ok = plcService.check(plcCmdInfo,ksecInfo.getData().getCmdName(), dataInfo.getCode(), dataInfo.getTrayCode());
if(ok){ // if(ok){
ksecInfo.getData().setAckStatus(1); // ksecInfo.getData().setAckStatus(1);
// }else {
// ksecInfo.getData().setAckStatus(0);
// }
// ctx.channel().writeAndFlush(ksecInfo);
//rfid的逻辑
String code = dataInfo.getCmdName();
if("E1".equals(code)){
plcService.RFIDCheck(plcCmdInfo);
}else { }else {
ksecInfo.getData().setAckStatus(0); plcService.RFIDStop(plcCmdInfo);
} }
ctx.channel().writeAndFlush(ksecInfo);
} }
//找到该货位的最后一张照片与现在的照片比照 //找到该货位的最后一张照片与现在的照片比照
//plcService.recordStock(plcCmdInfo, dataInfo.getCode(), 0, 0); //plcService.recordStock(plcCmdInfo, dataInfo.getCode(), 0, 0);

@ -34,10 +34,25 @@ cameraConfig:
videoServer: 127.0.0.1:8083 videoServer: 127.0.0.1:8083
#相机抓图延迟 毫秒,这个延迟是等待球机球机转动到位,然后拍照的 #相机抓图延迟 毫秒,这个延迟是等待球机球机转动到位,然后拍照的
delayCaptureTime: 3500 delayCaptureTime: 3500
#随行模式下的相机抓图延迟 毫秒,这个延迟是等待球机球机转动到位,然后拍照的
# 发了C1之后多久拍照
C1DelayCaptureTime: 1500
# 内侧货架 发了C2 之后多久拍照
C2DelayCaptureTime: 1500
# 外侧货架 发了C2 之后多久拍照
C2OutDelayCaptureTime: 2500
# 发了C3之后多久拍照
C3DelayCaptureTime: 1500
C4DelayCaptureTime: 1500
C4OutDelayCaptureTime: 1500
# 发了B2之后多久转原点位
B2DelayTime: 2000
# 外侧货架发了B2多久转原点位
B2OutDelayTime: 2000
# 下载mp4延迟 海康的下载mp4需要2分钟 # 下载mp4延迟 海康的下载mp4需要2分钟
# 利珀延迟10s就可 # 利珀延迟10s就可
# 单位毫秒 # 单位毫秒
delayDownloadMp4: 120000 delayDownloadMp4: 10000
# ------------ # ------------
# -----图片 mp4下载地址 # -----图片 mp4下载地址
savePath: savePath:
@ -46,12 +61,12 @@ savePath:
# ------------服务端类型 0TCP(罗伯泰克) 1:KSEC(JSON)(昆船) # ------------服务端类型 0TCP(罗伯泰克) 1:KSEC(JSON)(昆船)
serverMode: 1 serverMode: 1
ksec: ksec:
ip: 127.0.0.1 ip: 172.18.96.1
port: 3000 port: 3000
# ------------ 实时视频流 全部页面的格式 行列数量 # ------------ 实时视频流 全部页面的格式 行列数量
videoStyleConfig: videoStyleConfig:
videoStyleRow: 2 videoStyleRow: 4
videoStyleColumn: 2 videoStyleColumn: 4
# ------------光源--- # ------------光源---
# -------------type 0:没有光源 1利珀光源控制器JYDam 2利珀视觉控制器 # -------------type 0:没有光源 1利珀光源控制器JYDam 2利珀视觉控制器
# ----------- num:总共多少个光源端口 index:需要控制的是哪个 # ----------- num:总共多少个光源端口 index:需要控制的是哪个
@ -64,7 +79,7 @@ lightSource:
# -----goods 货物 # -----goods 货物
# 扫码模式 0:此处不盘点 1球机扫码 2sick扫码枪 3:南北达RFID # 扫码模式 0:此处不盘点 1球机扫码 2sick扫码枪 3:南北达RFID
scanCodeMode: scanCodeMode:
tray: 2 tray: 1
goods: 0 goods: 0
goodsCodeTypes: goodsCodeTypes:
- 14 - 14

Loading…
Cancel
Save