|
@@ -28,17 +28,20 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
@Service
|
|
@Service
|
|
|
public class DeJuRFIDService implements IService {
|
|
public class DeJuRFIDService implements IService {
|
|
|
|
|
|
|
|
- @Resource
|
|
|
|
|
- private ISendService sendService;
|
|
|
|
|
|
|
+ private static final ISendService sendService = SpringUtils.getBean("sendService");
|
|
|
|
|
|
|
|
- private final Map<String, GClient> clientMap = new ConcurrentHashMap<>();
|
|
|
|
|
|
|
+ private static final Map<String, GClient> clientMap = new ConcurrentHashMap<>();
|
|
|
|
|
|
|
|
- AtomicBoolean isAlarm = new AtomicBoolean();
|
|
|
|
|
|
|
+ static AtomicBoolean isAlarm = new AtomicBoolean();
|
|
|
|
|
|
|
|
- private final ScheduledExecutorService scheduledExecutorService = SpringUtils.getBean("scheduledExecutorService");
|
|
|
|
|
|
|
+ private static final ScheduledExecutorService scheduledExecutorService = SpringUtils.getBean("scheduledExecutorService");
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void start(RemoteLabHardware hardware) {
|
|
public void start(RemoteLabHardware hardware) {
|
|
|
|
|
+ open(hardware);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static void open(RemoteLabHardware hardware) {
|
|
|
GClient client;
|
|
GClient client;
|
|
|
String ipAddress = hardware.getIpAddress();
|
|
String ipAddress = hardware.getIpAddress();
|
|
|
if (clientMap.containsKey(ipAddress)) {
|
|
if (clientMap.containsKey(ipAddress)) {
|
|
@@ -51,67 +54,72 @@ public class DeJuRFIDService implements IService {
|
|
|
// 订阅标签上报事件
|
|
// 订阅标签上报事件
|
|
|
subscribeHandler(client);
|
|
subscribeHandler(client);
|
|
|
// 功率配置, 将4个天线功率都设置为30dBm.
|
|
// 功率配置, 将4个天线功率都设置为30dBm.
|
|
|
- Integer uniformPower = hardware.getUniformPower();
|
|
|
|
|
- MsgBaseGetPower msgBaseGetPower = new MsgBaseGetPower();
|
|
|
|
|
- client.sendSynMsg(msgBaseGetPower);
|
|
|
|
|
- if (0 == msgBaseGetPower.getRtCode()) {
|
|
|
|
|
- Hashtable<Integer, Integer> dicPower = msgBaseGetPower.getDicPower();
|
|
|
|
|
- Integer integer = dicPower.get(0);
|
|
|
|
|
- if (!Objects.equals(integer, uniformPower)) {
|
|
|
|
|
- MsgBaseSetPower msgBaseSetPower = new MsgBaseSetPower();
|
|
|
|
|
- Hashtable<Integer, Integer> hashtable = new Hashtable<>();
|
|
|
|
|
-
|
|
|
|
|
- Integer channels = hardware.getChannels();
|
|
|
|
|
- for (int i = 1; i <= channels; i++) {
|
|
|
|
|
- hashtable.put(i, uniformPower);
|
|
|
|
|
- }
|
|
|
|
|
- msgBaseSetPower.setDicPower(hashtable);
|
|
|
|
|
- client.sendSynMsg(msgBaseSetPower);
|
|
|
|
|
- if (0 != msgBaseSetPower.getRtCode()) {
|
|
|
|
|
- log.error("Power configuration error.");
|
|
|
|
|
- reset(client);
|
|
|
|
|
- disconnect(hardware);
|
|
|
|
|
- start(hardware);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
|
|
+ MsgBaseSetPower msgBaseSetPower = setPower(hardware, client);
|
|
|
|
|
+ if (0 != msgBaseSetPower.getRtCode()) {
|
|
|
log.error("Power configuration error.");
|
|
log.error("Power configuration error.");
|
|
|
reset(client);
|
|
reset(client);
|
|
|
- disconnect(hardware);
|
|
|
|
|
- start(hardware);
|
|
|
|
|
|
|
+ close(hardware);
|
|
|
|
|
+ open(hardware);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
//天线读卡, 读取EPC数据区以及TID数据区
|
|
//天线读卡, 读取EPC数据区以及TID数据区
|
|
|
- MsgBaseInventoryEpc msgBaseInventoryEpc = new MsgBaseInventoryEpc();
|
|
|
|
|
- switch (hardware.getChannels()) {
|
|
|
|
|
- case 4:
|
|
|
|
|
- msgBaseInventoryEpc.setAntennaEnable(EnumG.AntennaNo_1 | EnumG.AntennaNo_2 | EnumG.AntennaNo_3 | EnumG.AntennaNo_4);
|
|
|
|
|
- break;
|
|
|
|
|
- case 8:
|
|
|
|
|
- msgBaseInventoryEpc.setAntennaEnable(EnumG.AntennaNo_1 | EnumG.AntennaNo_2 | EnumG.AntennaNo_3 | EnumG.AntennaNo_4 | EnumG.AntennaNo_5 | EnumG.AntennaNo_6 | EnumG.AntennaNo_7 | EnumG.AntennaNo_8);
|
|
|
|
|
- break;
|
|
|
|
|
- case 16:
|
|
|
|
|
- msgBaseInventoryEpc.setAntennaEnable(EnumG.AntennaNo_1 | EnumG.AntennaNo_2 | EnumG.AntennaNo_3 | EnumG.AntennaNo_4 | EnumG.AntennaNo_5 | EnumG.AntennaNo_6 | EnumG.AntennaNo_7 | EnumG.AntennaNo_8 | EnumG.AntennaNo_9 | EnumG.AntennaNo_10 | EnumG.AntennaNo_11 | EnumG.AntennaNo_12 | EnumG.AntennaNo_13 | EnumG.AntennaNo_14 | EnumG.AntennaNo_15 | EnumG.AntennaNo_16);
|
|
|
|
|
- break;
|
|
|
|
|
- case 1:
|
|
|
|
|
- default:
|
|
|
|
|
- msgBaseInventoryEpc.setAntennaEnable(EnumG.AntennaNo_1);
|
|
|
|
|
- }
|
|
|
|
|
- msgBaseInventoryEpc.setInventoryMode(EnumG.InventoryMode_Inventory);
|
|
|
|
|
-
|
|
|
|
|
- client.sendSynMsg(msgBaseInventoryEpc);
|
|
|
|
|
|
|
+ MsgBaseInventoryEpc msgBaseInventoryEpc = setInventory(hardware, client);
|
|
|
if (0 != msgBaseInventoryEpc.getRtCode()) {
|
|
if (0 != msgBaseInventoryEpc.getRtCode()) {
|
|
|
log.error("Inventory epc error.");
|
|
log.error("Inventory epc error.");
|
|
|
reset(client);
|
|
reset(client);
|
|
|
- disconnect(hardware);
|
|
|
|
|
- start(hardware);
|
|
|
|
|
|
|
+ close(hardware);
|
|
|
|
|
+ open(hardware);
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
throw new ServiceException("Connect failure.");
|
|
throw new ServiceException("Connect failure.");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void reset(GClient client) {
|
|
|
|
|
|
|
+ public static MsgBaseInventoryEpc setInventory(RemoteLabHardware hardware, GClient client) {
|
|
|
|
|
+ MsgBaseInventoryEpc msgBaseInventoryEpc = new MsgBaseInventoryEpc();
|
|
|
|
|
+ switch (hardware.getChannels()) {
|
|
|
|
|
+ case 4:
|
|
|
|
|
+ msgBaseInventoryEpc.setAntennaEnable(EnumG.AntennaNo_1 | EnumG.AntennaNo_2 | EnumG.AntennaNo_3 | EnumG.AntennaNo_4);
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 8:
|
|
|
|
|
+ msgBaseInventoryEpc.setAntennaEnable(EnumG.AntennaNo_1 | EnumG.AntennaNo_2 | EnumG.AntennaNo_3 | EnumG.AntennaNo_4 | EnumG.AntennaNo_5 | EnumG.AntennaNo_6 | EnumG.AntennaNo_7 | EnumG.AntennaNo_8);
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 16:
|
|
|
|
|
+ msgBaseInventoryEpc.setAntennaEnable(EnumG.AntennaNo_1 | EnumG.AntennaNo_2 | EnumG.AntennaNo_3 | EnumG.AntennaNo_4 | EnumG.AntennaNo_5 | EnumG.AntennaNo_6 | EnumG.AntennaNo_7 | EnumG.AntennaNo_8 | EnumG.AntennaNo_9 | EnumG.AntennaNo_10 | EnumG.AntennaNo_11 | EnumG.AntennaNo_12 | EnumG.AntennaNo_13 | EnumG.AntennaNo_14 | EnumG.AntennaNo_15 | EnumG.AntennaNo_16);
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 1:
|
|
|
|
|
+ default:
|
|
|
|
|
+ msgBaseInventoryEpc.setAntennaEnable(EnumG.AntennaNo_1);
|
|
|
|
|
+ }
|
|
|
|
|
+ msgBaseInventoryEpc.setInventoryMode(EnumG.InventoryMode_Inventory);
|
|
|
|
|
+
|
|
|
|
|
+ client.sendSynMsg(msgBaseInventoryEpc);
|
|
|
|
|
+ return msgBaseInventoryEpc;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static MsgBaseSetPower setPower(RemoteLabHardware hardware, GClient client) {
|
|
|
|
|
+ Integer uniformPower = hardware.getUniformPower();
|
|
|
|
|
+ MsgBaseGetPower msgBaseGetPower = new MsgBaseGetPower();
|
|
|
|
|
+ client.sendSynMsg(msgBaseGetPower);
|
|
|
|
|
+ MsgBaseSetPower msgBaseSetPower = new MsgBaseSetPower();
|
|
|
|
|
+ if (0 == msgBaseGetPower.getRtCode()) {
|
|
|
|
|
+ Hashtable<Integer, Integer> dicPower = msgBaseGetPower.getDicPower();
|
|
|
|
|
+ Integer integer = dicPower.get(0);
|
|
|
|
|
+ if (!Objects.equals(integer, uniformPower)) {
|
|
|
|
|
+ Hashtable<Integer, Integer> hashtable = new Hashtable<>();
|
|
|
|
|
+ Integer channels = hardware.getChannels();
|
|
|
|
|
+ for (int i = 1; i <= channels; i++) {
|
|
|
|
|
+ hashtable.put(i, uniformPower);
|
|
|
|
|
+ }
|
|
|
|
|
+ msgBaseSetPower.setDicPower(hashtable);
|
|
|
|
|
+ client.sendSynMsg(msgBaseSetPower);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ msgBaseSetPower.setRtCode((byte) 0);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return msgBaseSetPower;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static void reset(GClient client) {
|
|
|
MsgAppReset msgAppReset = new MsgAppReset();
|
|
MsgAppReset msgAppReset = new MsgAppReset();
|
|
|
client.sendSynMsg(msgAppReset);
|
|
client.sendSynMsg(msgAppReset);
|
|
|
if (0 != msgAppReset.getRtCode()) {
|
|
if (0 != msgAppReset.getRtCode()) {
|
|
@@ -121,6 +129,10 @@ public class DeJuRFIDService implements IService {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void disconnect(RemoteLabHardware hardware) {
|
|
public void disconnect(RemoteLabHardware hardware) {
|
|
|
|
|
+ close(hardware);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static void close(RemoteLabHardware hardware) {
|
|
|
String ipAddress = hardware.getIpAddress();
|
|
String ipAddress = hardware.getIpAddress();
|
|
|
if (clientMap.containsKey(ipAddress)) {
|
|
if (clientMap.containsKey(ipAddress)) {
|
|
|
GClient client = clientMap.get(ipAddress);
|
|
GClient client = clientMap.get(ipAddress);
|
|
@@ -133,7 +145,7 @@ public class DeJuRFIDService implements IService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private void changeGpo(int state, GClient client, int delayTime) {
|
|
|
|
|
|
|
+ private static void changeGpo(int state, GClient client, int delayTime) {
|
|
|
MsgAppSetGpo msgAppSetGpo = new MsgAppSetGpo();
|
|
MsgAppSetGpo msgAppSetGpo = new MsgAppSetGpo();
|
|
|
msgAppSetGpo.setGpo1(state);
|
|
msgAppSetGpo.setGpo1(state);
|
|
|
msgAppSetGpo.setGpo2(state);
|
|
msgAppSetGpo.setGpo2(state);
|
|
@@ -154,7 +166,7 @@ public class DeJuRFIDService implements IService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void stopGpo(GClient client, int delayTime) {
|
|
|
|
|
|
|
+ public static void stopGpo(GClient client, int delayTime) {
|
|
|
scheduledExecutorService.schedule(new TimerTask() {
|
|
scheduledExecutorService.schedule(new TimerTask() {
|
|
|
@Override
|
|
@Override
|
|
|
public void run() {
|
|
public void run() {
|
|
@@ -168,7 +180,7 @@ public class DeJuRFIDService implements IService {
|
|
|
*
|
|
*
|
|
|
* @param client 客户端
|
|
* @param client 客户端
|
|
|
*/
|
|
*/
|
|
|
- private void subscribeHandler(GClient client) {
|
|
|
|
|
|
|
+ public static void subscribeHandler(GClient client) {
|
|
|
client.onTagEpcLog = (s, logBaseEpcInfo) -> {
|
|
client.onTagEpcLog = (s, logBaseEpcInfo) -> {
|
|
|
if (logBaseEpcInfo.getResult() == 0) {
|
|
if (logBaseEpcInfo.getResult() == 0) {
|
|
|
log.info("===========》{}", logBaseEpcInfo.getbEpc());
|
|
log.info("===========》{}", logBaseEpcInfo.getbEpc());
|