|
|
@@ -12,6 +12,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.io.File;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
|
@@ -24,11 +25,14 @@ public class DeJuRFIDService implements IService {
|
|
|
|
|
|
private static final ISendService sendService = SpringUtils.getBean("sendService");
|
|
|
|
|
|
- private static final Map<String, GClient> clientMap = new ConcurrentHashMap<>();
|
|
|
+ private static final Map<String, GClient> CLIENT_MAP = new ConcurrentHashMap<>();
|
|
|
|
|
|
static AtomicBoolean isAlarm = new AtomicBoolean();
|
|
|
|
|
|
- public static final Integer PORT=8160;
|
|
|
+ public static final Integer PORT = 8160;
|
|
|
+
|
|
|
+ private static final String HTTP_SEPARATOR = ":";
|
|
|
+ private static final Integer TIME_OUT = 2000;
|
|
|
|
|
|
private static final ScheduledExecutorService scheduledExecutorService = SpringUtils.getBean("scheduledExecutorService");
|
|
|
|
|
|
@@ -40,15 +44,15 @@ public class DeJuRFIDService implements IService {
|
|
|
private static void open(RemoteLabHardware hardware) {
|
|
|
GClient client;
|
|
|
String ipAddress = hardware.getIpAddress();
|
|
|
- if (clientMap.containsKey(ipAddress)) {
|
|
|
- client = clientMap.get(ipAddress);
|
|
|
+ if (CLIENT_MAP.containsKey(ipAddress)) {
|
|
|
+ client = CLIENT_MAP.get(ipAddress);
|
|
|
} else {
|
|
|
client = new GClient();
|
|
|
- clientMap.put(ipAddress, client);
|
|
|
+ CLIENT_MAP.put(ipAddress, client);
|
|
|
}
|
|
|
- if (client.openTcp(ipAddress + ":"+PORT, 2000)) {
|
|
|
+ if (client.openTcp(ipAddress + HTTP_SEPARATOR+ PORT, TIME_OUT)) {
|
|
|
// 订阅标签上报事件
|
|
|
- subscribeHandler(client,hardware);
|
|
|
+ subscribeHandler(client, hardware);
|
|
|
// 功率配置, 将4个天线功率都设置为30dBm.
|
|
|
MsgBaseSetPower msgBaseSetPower = setPower(hardware, client);
|
|
|
if (0 != msgBaseSetPower.getRtCode()) {
|
|
|
@@ -123,13 +127,24 @@ public class DeJuRFIDService implements IService {
|
|
|
return msgBaseSetPower;
|
|
|
}
|
|
|
|
|
|
- public static MsgBaseSetBaseband setSession(RemoteLabHardware hardware, GClient client){
|
|
|
- MsgBaseGetBaseband msgBaseGetBaseband=new MsgBaseGetBaseband();
|
|
|
- MsgBaseSetBaseband msgBaseSetBaseband=new MsgBaseSetBaseband();
|
|
|
+ public static MsgBaseSetBaseband setSession(RemoteLabHardware hardware, GClient client) {
|
|
|
+ MsgBaseGetBaseband msgBaseGetBaseband = new MsgBaseGetBaseband();
|
|
|
+ MsgBaseSetBaseband msgBaseSetBaseband = new MsgBaseSetBaseband();
|
|
|
client.sendSynMsg(msgBaseGetBaseband);
|
|
|
- if (0==msgBaseGetBaseband.getRtCode()){
|
|
|
- msgBaseSetBaseband.setSession(hardware.getSessionIndex());
|
|
|
- client.sendSynMsg(msgBaseSetBaseband);
|
|
|
+ if (0 == msgBaseGetBaseband.getRtCode()) {
|
|
|
+ int session = msgBaseGetBaseband.getSession();
|
|
|
+ log.info("Session index is:==============》{}", session);
|
|
|
+ if (session != hardware.getSessionIndex()) {
|
|
|
+ msgBaseSetBaseband.setSession(hardware.getSessionIndex());
|
|
|
+ client.sendSynMsg(msgBaseSetBaseband);
|
|
|
+ if (0 != msgBaseSetBaseband.getRtCode()) {
|
|
|
+ log.info("Session epc error.");
|
|
|
+ } else {
|
|
|
+ log.info("Session epc success.");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ msgBaseSetBaseband.setRtCode((byte) 0);
|
|
|
+ }
|
|
|
}
|
|
|
return msgBaseSetBaseband;
|
|
|
}
|
|
|
@@ -151,9 +166,9 @@ public class DeJuRFIDService implements IService {
|
|
|
public void alarm(RemoteLabHardware hardware) {
|
|
|
//灯带设置
|
|
|
String ipAddress = hardware.getIpAddress();
|
|
|
- if (clientMap.containsKey(ipAddress)){
|
|
|
- GClient client = clientMap.get(ipAddress);
|
|
|
- log.info("报警状态:==============》{}",isAlarm.get());
|
|
|
+ if (CLIENT_MAP.containsKey(ipAddress)) {
|
|
|
+ GClient client = CLIENT_MAP.get(ipAddress);
|
|
|
+ log.info("报警状态:==============》{}", isAlarm.get());
|
|
|
if (!isAlarm.get()) {
|
|
|
scheduledExecutorService.execute(() -> {
|
|
|
isAlarm.set(true);
|
|
|
@@ -165,8 +180,8 @@ public class DeJuRFIDService implements IService {
|
|
|
|
|
|
public static void close(RemoteLabHardware hardware) {
|
|
|
String ipAddress = hardware.getIpAddress();
|
|
|
- if (clientMap.containsKey(ipAddress)) {
|
|
|
- GClient client = clientMap.get(ipAddress);
|
|
|
+ if (CLIENT_MAP.containsKey(ipAddress)) {
|
|
|
+ GClient client = CLIENT_MAP.get(ipAddress);
|
|
|
changeGpo(0, client, 0);
|
|
|
MsgBaseStop msg = new MsgBaseStop();
|
|
|
// 停止读卡,空闲态
|
|
|
@@ -174,7 +189,7 @@ public class DeJuRFIDService implements IService {
|
|
|
String result = msg.getRtCode() == 0 ? "成功" : "失败";
|
|
|
log.info("客户端停止读卡{}", result);
|
|
|
client.close();
|
|
|
- clientMap.remove(ipAddress);
|
|
|
+ CLIENT_MAP.remove(ipAddress);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -185,7 +200,7 @@ public class DeJuRFIDService implements IService {
|
|
|
client.sendSynMsg(msgAppSetGpo);
|
|
|
String status = state == 1 ? "start" : "stop";
|
|
|
if (0 == msgAppSetGpo.getRtCode()) {
|
|
|
- log.info("============》灯带{}成功.",status);
|
|
|
+ log.info("============》灯带{}成功.", status);
|
|
|
if (state == 1) {
|
|
|
stopGpo(client, delayTime);
|
|
|
} else {
|
|
|
@@ -211,14 +226,12 @@ public class DeJuRFIDService implements IService {
|
|
|
/**
|
|
|
* 订阅6c标签信息上报
|
|
|
*
|
|
|
- * @param client 客户端
|
|
|
+ * @param client 客户端
|
|
|
* @param hardware 设备数据
|
|
|
*/
|
|
|
public static void subscribeHandler(GClient client, RemoteLabHardware hardware) {
|
|
|
String ipAddress = hardware.getIpAddress();
|
|
|
- if (!clientMap.containsKey(ipAddress)){
|
|
|
- clientMap.put(ipAddress,client);
|
|
|
- }
|
|
|
+ CLIENT_MAP.computeIfAbsent(ipAddress, f -> client);
|
|
|
client.onTagEpcLog = (s, logBaseEpcInfo) -> {
|
|
|
if (logBaseEpcInfo.getResult() == 0) {
|
|
|
log.info("===========》{}", logBaseEpcInfo.getEpc());
|