|
|
|
@ -140,7 +140,7 @@ public class NettyServer { |
|
|
|
} |
|
|
|
|
|
|
|
//发送消息 |
|
|
|
public void sendMsg(String uuid, String clientKey, boolean request, String xml) { |
|
|
|
public void flushMsgToDevice(String uuid, String clientKey, boolean request, String xml) { |
|
|
|
if (tcpClientMap.containsKey(clientKey) && !StringUtil.isNullOrEmpty(xml)) { |
|
|
|
ByteBuf byteBuf = Unpooled.copiedBuffer(xml, CharsetUtil.UTF_8); |
|
|
|
int length = byteBuf.readableBytes(); |
|
|
|
@ -155,11 +155,11 @@ public class NettyServer { |
|
|
|
allBuf.writeByte(0xEB); |
|
|
|
allBuf.writeByte(0x90); |
|
|
|
redisTemplate.opsForValue().set(String.valueOf(sendIndex), allBuf.toString(CharsetUtil.US_ASCII), 60L, TimeUnit.SECONDS); |
|
|
|
logger.info("######## 会话:{}, 客户:{}, 向设备回送序列:{}, 接收端序列:{}, 消息########\n{}", uuid, clientKey, sendIndex, receiveIndex, xml); |
|
|
|
logger.info(Color.MAGENTA + "######## => 会话:{}, 客户:{}, 向设备回送序列:{}, 接收端序列:{}, 消息########\n{}" + Color.END, uuid, tcpClientMap.get(clientKey), sendIndex, receiveIndex, xml); |
|
|
|
nettyServerHandler.sendMsg(uuid, clientKey, tcpClientMap.get(clientKey), allBuf); |
|
|
|
sendIndex++; |
|
|
|
} else { |
|
|
|
logger.warn("######## 会话: {}, 设备端机器人: [{}] 离线!!! ########", uuid, clientKey); |
|
|
|
logger.warn(Color.RED + "######## 会话: {}, 设备端机器人: [{}] 离线!!! ########" + Color.END, uuid, tcpClientMap.get(clientKey)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -180,7 +180,7 @@ public class NettyServer { |
|
|
|
String msg = redisTemplate.opsForValue().get(String.valueOf(sendIndex)); |
|
|
|
if (!StringUtil.isNullOrEmpty(msg)) { |
|
|
|
ByteBuf allBuf = Unpooled.copiedBuffer(msg, CharsetUtil.US_ASCII); |
|
|
|
sendMsg("", sendCode, true, msg); |
|
|
|
flushMsgToDevice("", sendCode, true, msg); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -202,7 +202,7 @@ public class NettyServer { |
|
|
|
command = Integer.parseInt(root.element("Command").getText()); |
|
|
|
} |
|
|
|
|
|
|
|
logger.info(Color.RED + "######## 会话: {}, 客户: {}, 消息类型: {}, 命令:{}, 消息体: ########\n{}" + Color.END, binaryModel.uuid, binaryModel.id, type, command, xml); |
|
|
|
logger.info(Color.MAGENTA + "######## <= 会话: {}, 客户: {}, 消息类型: {}, 命令:{}, 消息体: ########\n{}" + Color.END, binaryModel.uuid, binaryModel.id, type, command, xml); |
|
|
|
//判断是否重发 |
|
|
|
if (type == SystemType.system) { |
|
|
|
if (command == SystemType.has_response || command == SystemType.no_response) { |
|
|
|
@ -323,13 +323,15 @@ public class NettyServer { |
|
|
|
// send to BasedataMontDataMqAcceptHandle |
|
|
|
rabbitTemplate.convertAndSend(Constant.EX_CHANGE_NAME, Constant.ROUTING_KEY_NAME, json); |
|
|
|
String receiveCode = root.element("ReceiveCode").getText(); |
|
|
|
feedbackToDevice(binaryModel.uuid, receiveCode, sendCode); |
|
|
|
boolean isHost = json.contains(aliasHost); |
|
|
|
logger.info("######## 会话: {}, 客户: {}, isHost: {}", binaryModel.uuid, binaryModel.id, isHost); |
|
|
|
sendResponseToDevice(binaryModel.uuid, receiveCode, sendCode, isHost); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void feedbackToDevice(String uuid, String sendCode, String receiveCode) { |
|
|
|
public void sendResponseToDevice(String uuid, String sendCode, String receiveCode, boolean isHost) { |
|
|
|
XStream xStream = new XStream(new Xpp3Driver(new NoNameCoder())); |
|
|
|
xStream.alias(aliasHost, ResponseControl.class); |
|
|
|
xStream.alias(isHost ? aliasHost : aliasDevice, ResponseControl.class); |
|
|
|
xStream.autodetectAnnotations(true); |
|
|
|
ResponseControl responseControl = new ResponseControl(); |
|
|
|
responseControl.SendCode = sendCode; |
|
|
|
@ -340,7 +342,7 @@ public class NettyServer { |
|
|
|
responseControl.Time = CommonUtils.GetNowDateString(); |
|
|
|
responseControl.Items = ""; |
|
|
|
String xml = xStream.toXML(responseControl); |
|
|
|
sendMsg(uuid, receiveCode, false, xml); |
|
|
|
flushMsgToDevice(uuid, receiveCode, false, xml); |
|
|
|
} |
|
|
|
|
|
|
|
//处理注册应答 |
|
|
|
@ -457,11 +459,12 @@ public class NettyServer { |
|
|
|
logger.error("################ DOWN REGISTER 解析失败[PatrolDevice] {} ################", e2.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
sendMsg(uuid, sendCode, false, xml); |
|
|
|
flushMsgToDevice(uuid, sendCode, false, xml); |
|
|
|
} |
|
|
|
|
|
|
|
public void sendHeartBeat(final String uuid, String xml) { |
|
|
|
//logger.info("################ 设备端机器人系统心跳消息 ################\n{}", xml); |
|
|
|
boolean isHost = true; |
|
|
|
BaseControl obj = new BaseControl(); |
|
|
|
try { |
|
|
|
XStream xStream = new XStream(new Xpp3Driver(new NoNameCoder())); |
|
|
|
@ -479,12 +482,13 @@ public class NettyServer { |
|
|
|
xStream.ignoreUnknownElements(); |
|
|
|
xStream.addPermission(AnyTypePermission.ANY); |
|
|
|
obj = (BaseControl) xStream.fromXML(xml); |
|
|
|
isHost = false; |
|
|
|
} catch (com.thoughtworks.xstream.XStreamException e2) { |
|
|
|
logger.error("######## HEARTBEAT TO MQ 解析失败[PatrolDevice] {} ########", e2.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
feedbackToDevice(uuid, obj.ReceiveCode, obj.SendCode); |
|
|
|
sendResponseToDevice(uuid, obj.ReceiveCode, obj.SendCode, isHost); |
|
|
|
|
|
|
|
// 推送消息到mq |
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
|
@ -554,7 +558,7 @@ public class NettyServer { |
|
|
|
} |
|
|
|
if (!StringUtils.isEmpty(xml)) { |
|
|
|
//logger.info("################ 向设备端下发命令 ################\n{}", xml); |
|
|
|
sendMsg("", receiveCode, true, xml); |
|
|
|
flushMsgToDevice("", receiveCode, true, xml); |
|
|
|
} |
|
|
|
} |
|
|
|
} |