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.mapper.*;
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.hikLightSource.HikControlSocket;
import com.zhehekeji.web.service.ksec.KsecNettyClient;
@ -20,7 +21,9 @@ import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
@ -653,6 +656,9 @@ public class PlcService {
}else if(configProperties.getScanCodeMode().getTray() == 3){
//RFID
RFID rfid = rfidService.getRFIDByPlc(street.getId());
}
OrderInfo orderInfo = new OrderInfo(street,plcCmdInfo,1,cmdCode);
Stock stock = stockMapper.getByShelveIdAndRowColumn(orderInfo.getShelveId(),orderInfo.getRow(),orderInfo.getColumn());
@ -738,6 +744,36 @@ public class PlcService {
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(){
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();
} catch (IOException e) {
log.error("RFIDSocket time out,ip:{},info:{}",ip,e);
try {
close();
} catch (IOException ex) {
ex.printStackTrace();
}
close();
}
}
public void readData() throws IOException {
public void readData(){
running = true;
buffer = new LinkedList();
@ -167,14 +165,20 @@ public class RFIDSocket {
index = 0;
}
public void close() throws IOException {
public void close() {
running = false;
is.close();
socket.close();
os.close();
try {
is.close();
socket.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() {
@Override
public void run() {
@ -186,16 +190,16 @@ public class RFIDSocket {
byte []antChanges = new byte[6];
antChanges[0] = (byte)0xa0;
antChanges[1] = (byte)0x04;
antChanges[2] = (byte)0x22;
antChanges[2] = (byte)0x01;
antChanges[3] = (byte)0x74;
if(i % 2 == 0){
//切换天线 使用天线0
antChanges[4] = (byte)0x00;
antChanges[5] = (byte)0xc6;
antChanges[5] = (byte)0xe7;
}else {
//切换天线 使用天线1
antChanges[4] = (byte)0x01;
antChanges[5] = (byte)0xc5;
antChanges[5] = (byte)0xe6;
}
i++;
try {
@ -207,14 +211,14 @@ public class RFIDSocket {
byte[]bytes = new byte[5];
bytes[0] = (byte)0xa0;
bytes[1] = (byte)0x03;
bytes[2] = (byte)0x22;
bytes[2] = (byte)0x01;
bytes[3] = (byte)0xb0;
bytes[4] = (byte)0x8b;
bytes[4] = (byte)0xac;
try {
os.write(bytes);
Thread.sleep(70);
} 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)){
//需要把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);
// 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);
//rfid的逻辑
String code = dataInfo.getCmdName();
if("E1".equals(code)){
plcService.RFIDCheck(plcCmdInfo);
}else {
ksecInfo.getData().setAckStatus(0);
plcService.RFIDStop(plcCmdInfo);
}
ctx.channel().writeAndFlush(ksecInfo);
}
//找到该货位的最后一张照片与现在的照片比照
//plcService.recordStock(plcCmdInfo, dataInfo.getCode(), 0, 0);

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

Loading…
Cancel
Save