|
|
@@ -2,42 +2,22 @@ package com.zd.netty.sdk;
|
|
|
|
|
|
import com.gg.reader.api.dal.GClient;
|
|
|
import com.gg.reader.api.dal.GServer;
|
|
|
-import com.gg.reader.api.protocol.gx.*;
|
|
|
-import com.zd.common.core.utils.SpringUtils;
|
|
|
-import com.zd.netty.service.ISendService;
|
|
|
+import com.gg.reader.api.protocol.gx.MsgBaseStop;
|
|
|
import com.zd.netty.service.IService;
|
|
|
-import com.zd.system.api.domain.InventoryTag;
|
|
|
import com.zd.system.api.laboratory.domain.RemoteLabHardware;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import javax.annotation.Resource;
|
|
|
-import java.util.Hashtable;
|
|
|
import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
-import java.util.TimerTask;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
-import java.util.concurrent.ScheduledExecutorService;
|
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
-import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
public class DeJuRFIDListenerService implements IService {
|
|
|
|
|
|
- @Resource
|
|
|
- private ISendService sendService;
|
|
|
-
|
|
|
private final Map<String, GServer> serverMap = new ConcurrentHashMap<>();
|
|
|
|
|
|
- AtomicBoolean isAlarm = new AtomicBoolean();
|
|
|
-
|
|
|
- GClient client;
|
|
|
-
|
|
|
- private final ScheduledExecutorService scheduledExecutorService = SpringUtils.getBean("scheduledExecutorService");
|
|
|
-
|
|
|
@Override
|
|
|
public void start(RemoteLabHardware hardware) {
|
|
|
String ipAddress = hardware.getIpAddress();
|
|
|
@@ -47,7 +27,7 @@ public class DeJuRFIDListenerService implements IService {
|
|
|
} else {
|
|
|
server = new GServer();
|
|
|
}
|
|
|
- if (server.open(9190)) {
|
|
|
+ if (server.open(DeJuRFIDService.PORT)) {
|
|
|
subscribeServerHandler(server, hardware);
|
|
|
log.info("开始监听");
|
|
|
} else {
|
|
|
@@ -67,28 +47,26 @@ public class DeJuRFIDListenerService implements IService {
|
|
|
|
|
|
//订阅监听上报
|
|
|
private void subscribeServerHandler(GServer server, RemoteLabHardware hardware) {
|
|
|
- server.onGClientConnected = (gClient, serialNumber) -> {
|
|
|
- log.info(gClient.getName() + "---监听成功");
|
|
|
- client = gClient;//切换连接对象
|
|
|
+ server.onGClientConnected = (client, serialNumber) -> {
|
|
|
+ log.info(client.getName() + "---监听成功");
|
|
|
client.setSendHeartBeat(true);//开启心跳检测Tcp连接状态
|
|
|
client.setPrint(true);
|
|
|
- subscribeTcpHandler();//订阅Tcp断连上报
|
|
|
+ subscribeTcpHandler(client);//订阅Tcp断连上报
|
|
|
DeJuRFIDService.setPower(hardware, client);
|
|
|
DeJuRFIDService.setInventory(hardware, client);
|
|
|
DeJuRFIDService.subscribeHandler(client);
|
|
|
-// stop();//测试监听成功的连接是否通信正常
|
|
|
};
|
|
|
}
|
|
|
|
|
|
//订阅TCP断开连接上报
|
|
|
- private void subscribeTcpHandler() {
|
|
|
+ private void subscribeTcpHandler(GClient client) {
|
|
|
client.onDisconnected = s -> {
|
|
|
log.info("连接" + s + "已断开");
|
|
|
client.close();//释放当前连接资源
|
|
|
};
|
|
|
}
|
|
|
|
|
|
- private void stop() {
|
|
|
+ private void stop(GClient client) {
|
|
|
MsgBaseStop msg = new MsgBaseStop();
|
|
|
client.sendSynMsg(msg);
|
|
|
if (0x00 == msg.getRtCode()) {
|