|
@@ -2,11 +2,13 @@ package com.zd.netty.sdk;
|
|
|
|
|
|
|
|
import com.gg.reader.api.dal.GClient;
|
|
import com.gg.reader.api.dal.GClient;
|
|
|
import com.gg.reader.api.protocol.gx.*;
|
|
import com.gg.reader.api.protocol.gx.*;
|
|
|
|
|
+import com.zd.common.core.enums.HardwareOperate;
|
|
|
import com.zd.common.core.exception.ServiceException;
|
|
import com.zd.common.core.exception.ServiceException;
|
|
|
import com.zd.common.core.utils.SpringUtils;
|
|
import com.zd.common.core.utils.SpringUtils;
|
|
|
import com.zd.netty.service.ISendService;
|
|
import com.zd.netty.service.ISendService;
|
|
|
import com.zd.netty.service.IService;
|
|
import com.zd.netty.service.IService;
|
|
|
import com.zd.system.api.domain.InventoryTag;
|
|
import com.zd.system.api.domain.InventoryTag;
|
|
|
|
|
+import com.zd.system.api.laboratory.RemoteLaboratoryService;
|
|
|
import com.zd.system.api.laboratory.domain.RemoteLabHardware;
|
|
import com.zd.system.api.laboratory.domain.RemoteLabHardware;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
@@ -44,6 +46,9 @@ public class DeJuRFIDServerImpl implements IService {
|
|
|
@Resource
|
|
@Resource
|
|
|
private RedisTemplate<String, RemoteLabHardware> redisTemplate;
|
|
private RedisTemplate<String, RemoteLabHardware> redisTemplate;
|
|
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private RemoteLaboratoryService remoteLaboratoryService;
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public void start(RemoteLabHardware hardware) {
|
|
public void start(RemoteLabHardware hardware) {
|
|
|
open(hardware);
|
|
open(hardware);
|
|
@@ -77,6 +82,8 @@ public class DeJuRFIDServerImpl implements IService {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 订阅标签上报事件
|
|
|
|
|
+ subscribeHandler(client, hardware);
|
|
|
MsgBaseSetBaseband msgBaseSetBaseband = setSession(hardware, client);
|
|
MsgBaseSetBaseband msgBaseSetBaseband = setSession(hardware, client);
|
|
|
if (0 != msgBaseSetBaseband.getRtCode()) {
|
|
if (0 != msgBaseSetBaseband.getRtCode()) {
|
|
|
log.info("Session epc error.");
|
|
log.info("Session epc error.");
|
|
@@ -84,14 +91,30 @@ public class DeJuRFIDServerImpl implements IService {
|
|
|
open(hardware);
|
|
open(hardware);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- // 订阅标签上报事件
|
|
|
|
|
- subscribeHandler(client, hardware);
|
|
|
|
|
redisTemplate.opsForValue().set(client.getSerialNumber(), hardware);
|
|
redisTemplate.opsForValue().set(client.getSerialNumber(), hardware);
|
|
|
} else {
|
|
} else {
|
|
|
throw new ServiceException("Connect failure.");
|
|
throw new ServiceException("Connect failure.");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 订阅TCP断开连接上报
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param client 客户端对象
|
|
|
|
|
+ */
|
|
|
|
|
+ public void subscribeTcpHandler(GClient client) {
|
|
|
|
|
+ RemoteLabHardware labHardware = redisTemplate.opsForValue().get(client.getSerialNumber());
|
|
|
|
|
+ client.onDisconnected = s -> {
|
|
|
|
|
+ log.info("连接" + s + "已断开");
|
|
|
|
|
+ if (labHardware!=null){
|
|
|
|
|
+ client.close();
|
|
|
|
|
+ remoteLaboratoryService.update(HardwareOperate.CLOSE, labHardware.getIpAddress());
|
|
|
|
|
+ log.info("连接" + s + "重连中。。。");
|
|
|
|
|
+ start(labHardware);
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public static MsgBaseInventoryEpc setInventory(RemoteLabHardware hardware, GClient client) {
|
|
public static MsgBaseInventoryEpc setInventory(RemoteLabHardware hardware, GClient client) {
|
|
|
MsgBaseInventoryEpc msgBaseInventoryEpc = new MsgBaseInventoryEpc();
|
|
MsgBaseInventoryEpc msgBaseInventoryEpc = new MsgBaseInventoryEpc();
|
|
|
switch (hardware.getChannels()) {
|
|
switch (hardware.getChannels()) {
|
|
@@ -214,6 +237,7 @@ public class DeJuRFIDServerImpl implements IService {
|
|
|
GClient client = clientMap.get(ipAddress);
|
|
GClient client = clientMap.get(ipAddress);
|
|
|
changeGpo(ipAddress, 0, client, 0);
|
|
changeGpo(ipAddress, 0, client, 0);
|
|
|
stopMsg(client);
|
|
stopMsg(client);
|
|
|
|
|
+ log.error("client.close()");
|
|
|
client.close();
|
|
client.close();
|
|
|
clientMap.remove(ipAddress);
|
|
clientMap.remove(ipAddress);
|
|
|
}
|
|
}
|