|
|
|
@ -139,7 +139,7 @@ public class NettyServer { |
|
|
|
} |
|
|
|
|
|
|
|
//发送消息 |
|
|
|
public void sendMsg(String client, boolean request, String xml) { |
|
|
|
public void sendMsg(String uuid, String client, boolean request, String xml) { |
|
|
|
if (tcpClientMap.containsKey(client) && !StringUtil.isNullOrEmpty(xml)) { |
|
|
|
ByteBuf byteBuf = Unpooled.copiedBuffer(xml, CharsetUtil.UTF_8); |
|
|
|
int length = byteBuf.readableBytes(); |
|
|
|
@ -154,11 +154,11 @@ public class NettyServer { |
|
|
|
allBuf.writeByte(0xEB); |
|
|
|
allBuf.writeByte(0x90); |
|
|
|
redisTemplate.opsForValue().set(String.valueOf(sendIndex), allBuf.toString(CharsetUtil.US_ASCII), 60L, TimeUnit.SECONDS); |
|
|
|
nettyServerHandler.sendMsg(tcpClientMap.get(client), allBuf); |
|
|
|
logger.info("################ 客户: {}, 向设备端机器人发送消息会话序列号: {}, 接收端序列号: {}, 消息体: ################\n{}", client, sendIndex, receiveIndex, xml); |
|
|
|
logger.info("################ 会话: {}, 客户: {}, 向设备端机器人回送消息序列号: {}, 接收端序列号: {}, 消息体: ################\n{}", uuid, client, sendIndex, receiveIndex, xml); |
|
|
|
nettyServerHandler.sendMsg(uuid, tcpClientMap.get(client), allBuf); |
|
|
|
sendIndex++; |
|
|
|
} else { |
|
|
|
logger.warn("################ 设备端机器人: [{}] 离线!!! ################", client); |
|
|
|
logger.warn("################ 会话: {}, 设备端机器人: [{}] 离线!!! ################", uuid, client); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -179,7 +179,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); |
|
|
|
sendMsg("", sendCode, true, msg); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -201,7 +201,7 @@ public class NettyServer { |
|
|
|
command = Integer.parseInt(root.element("Command").getText()); |
|
|
|
} |
|
|
|
|
|
|
|
logger.info("################ 客户: {}, 消息类型: {}, 消息体: ################ \n{}", binaryModel.id, type, xml); |
|
|
|
logger.info("################ 会话: {}, 客户: {}, 消息类型: {}, 命令:{}, 消息体: ################ \n{}", binaryModel.uuid, binaryModel.id, type, command, xml); |
|
|
|
//判断是否重发 |
|
|
|
if (type == SystemType.system) { |
|
|
|
if (command == SystemType.has_response || command == SystemType.no_response) { |
|
|
|
@ -218,13 +218,13 @@ public class NettyServer { |
|
|
|
switch (command) { |
|
|
|
case SystemType.register_request: |
|
|
|
// 收到接入侧注册信息 |
|
|
|
logger.info("################ 客户: {}, 客户端注册信息 ################ \n {} ", binaryModel.id, xml); |
|
|
|
dealRegister(xml); |
|
|
|
logger.info("################ 会话: {}, 客户: {}, 客户端注册信息 ################", binaryModel.uuid, binaryModel.id); |
|
|
|
dealRegister(binaryModel.uuid, xml); |
|
|
|
break; |
|
|
|
case SystemType.heart_request: |
|
|
|
// 处理心跳请求响应 |
|
|
|
logger.info("################ 客户: {}, 客户端心跳 ################ \n {} ", binaryModel.id, xml); |
|
|
|
sendHeartBeat(xml); |
|
|
|
logger.info("################ 会话: {}, 客户: {}, 客户端心跳 ################", binaryModel.uuid, binaryModel.id); |
|
|
|
sendHeartBeat(binaryModel.uuid, xml); |
|
|
|
break; |
|
|
|
case SystemType.has_response: |
|
|
|
// 处理有返回值的消息响应 |
|
|
|
@ -232,7 +232,7 @@ public class NettyServer { |
|
|
|
// 处理设备上报的模型同步响应 |
|
|
|
if (null != root.element("Items").element("Item").attribute("device_file_path")) { |
|
|
|
// 收到接入侧模型同步数据 |
|
|
|
logger.info("################ 客户: {}, 客户端模型同步数据 ################ \n{}", binaryModel.id, xml); |
|
|
|
logger.info("################ 会话: {}, 客户: {}, 客户端模型同步数据 ################", binaryModel.uuid, binaryModel.id); |
|
|
|
// json = downXml2Json.ModelControlXml2Json(xml); |
|
|
|
json = downXml2Json.DownStreamJson2Xml(binaryModel.id, xml, ModelControl.class); |
|
|
|
JSONObject jsonObject = JSONObject.parseObject(json); |
|
|
|
@ -242,7 +242,7 @@ public class NettyServer { |
|
|
|
// 任务控制响应任务执行ID |
|
|
|
if (null != root.element("Items").element("Item").attribute("task_patrolled_id")) { |
|
|
|
// 收到接入侧任务下发或控制回复数据 |
|
|
|
logger.info("################ 客户: {}, 设备端任务下发或控制回复数据 ################\n{}", binaryModel.id, xml); |
|
|
|
logger.info("################ 会话: {}, 客户: {}, 设备端任务下发或控制回复数据 ################", binaryModel.uuid, binaryModel.id); |
|
|
|
// json = downXml2Json.ModelControlXml2Json(xml); |
|
|
|
json = downXml2Json.DownStreamJson2Xml(binaryModel.id, xml, ModelControl.class); |
|
|
|
JSONObject jsonObject = JSONObject.parseObject(json); |
|
|
|
@ -262,66 +262,66 @@ public class NettyServer { |
|
|
|
case PushType.patrolDeviceState: |
|
|
|
// json = downXml2Json.PatrolDeviceStateControlXml2Json(xml); |
|
|
|
json = downXml2Json.DownStreamJson2Xml(binaryModel.id, xml, PatrolDeviceStateControl.class); |
|
|
|
logger.info("################ 客户: {}, 客户端设备状态数据 ################ \n{}", binaryModel.id, json); |
|
|
|
logger.info("################ 会话: {}, 客户: {}, 客户端设备状态数据 ################", binaryModel.uuid, binaryModel.id); |
|
|
|
break; |
|
|
|
case PushType.patrolDeviceRunning: |
|
|
|
// json = downXml2Json.PatrolDeviceRunningControlXml2Json(xml); |
|
|
|
json = downXml2Json.DownStreamJson2Xml(binaryModel.id, xml, PatrolDeviceRuningControl.class); |
|
|
|
logger.info("################ 客户: {}, 客户端设备运行数据 ################ \n{}", binaryModel.id, json); |
|
|
|
logger.info("################ 会话: {}, 客户: {}, 客户端设备运行数据 ################", binaryModel.uuid, binaryModel.id); |
|
|
|
break; |
|
|
|
case PushType.nestState: |
|
|
|
// json = downXml2Json.NestStateControlXml2Json(xml); |
|
|
|
json = downXml2Json.DownStreamJson2Xml(binaryModel.id, xml, NestStateControl.class); |
|
|
|
logger.info("################ 客户: {}, 客户端机巢状态数据 ################ \n{}", binaryModel.id, json); |
|
|
|
logger.info("################ 会话: {}, 客户: {}, 客户端机巢状态数据 ################", binaryModel.uuid, binaryModel.id); |
|
|
|
break; |
|
|
|
case PushType.nestRunning: |
|
|
|
// json = downXml2Json.NestRunningControlXml2Json(xml); |
|
|
|
json = downXml2Json.DownStreamJson2Xml(binaryModel.id, xml, NestRuningControl.class); |
|
|
|
logger.info("################ 客户: {}, 客户端机巢运行数据 ################ \n{}", binaryModel.id, json); |
|
|
|
logger.info("################ 会话: {}, 客户: {}, 客户端机巢运行数据 ################", binaryModel.uuid, binaryModel.id); |
|
|
|
break; |
|
|
|
case PushType.location: |
|
|
|
// json = downXml2Json.LocationControlXml2Json(xml); |
|
|
|
json = downXml2Json.DownStreamJson2Xml(binaryModel.id, xml, LocationControl.class); |
|
|
|
logger.info("################ 客户: {}, 客户端设备坐标 ################ \n{}", binaryModel.id, json); |
|
|
|
logger.info("################ 会话: {}, 客户: {}, 客户端设备坐标 ################", binaryModel.uuid, binaryModel.id); |
|
|
|
break; |
|
|
|
case PushType.route: |
|
|
|
// json = downXml2Json.RouteControlXml2Json(xml); |
|
|
|
json = downXml2Json.DownStreamJson2Xml(binaryModel.id, xml, RouteControl.class); |
|
|
|
logger.info("################ 客户: {}, 客户端设备路线 ################ \n{}", binaryModel.id, json); |
|
|
|
logger.info("################ 会话: {}, 客户: {}, 客户端设备路线 ################", binaryModel.uuid, binaryModel.id); |
|
|
|
break; |
|
|
|
case PushType.alarm: |
|
|
|
// json = down.AlarmControlXml2Json(xml); |
|
|
|
json = downXml2Json.DownStreamJson2Xml(binaryModel.id, xml, AlarmControl.class); |
|
|
|
logger.info("################ 客户: {}, 客户端设备异常告警 ################ \n{}", binaryModel.id, json); |
|
|
|
logger.info("################ 会话: {}, 客户: {}, 客户端设备异常告警 ################", binaryModel.uuid, binaryModel.id); |
|
|
|
break; |
|
|
|
case PushType.environment: |
|
|
|
// json = downXml2Json.EnvironmentControlXml2Json(xml); |
|
|
|
json = downXml2Json.DownStreamJson2Xml(binaryModel.id, xml, EnvironmentControl.class); |
|
|
|
logger.info("################ 客户: {}, 客户端设备上报环境数据 ################ \n{}", binaryModel.id, json); |
|
|
|
logger.info("################ 会话: {}, 客户: {}, 客户端设备上报环境数据 ################", binaryModel.uuid, binaryModel.id); |
|
|
|
break; |
|
|
|
case PushType.taskState: |
|
|
|
// json = downXml2Json.TaskStateControlXml2Json(xml); |
|
|
|
json = downXml2Json.DownStreamJson2Xml(binaryModel.id, xml, TaskStateControl.class); |
|
|
|
logger.info("################ 客户: {}, 客户端设备任务状态 ################ \n{}", binaryModel.id, json); |
|
|
|
logger.info("################ 会话: {}, 客户: {}, 客户端设备任务状态 ################", binaryModel.uuid, binaryModel.id); |
|
|
|
break; |
|
|
|
case PushType.result: |
|
|
|
// json = downXml2Json.TaskResultControlXml2Json(xml); |
|
|
|
json = downXml2Json.DownStreamJson2Xml(binaryModel.id, xml, TaskResultControl.class); |
|
|
|
logger.info("################ 客户: {}, 客户端巡视结果 ################ \n{}", binaryModel.id, json); |
|
|
|
logger.info("################ 会话: {}, 客户: {}, 客户端巡视结果 ################", binaryModel.uuid, binaryModel.id); |
|
|
|
break; |
|
|
|
default: |
|
|
|
// server-handle-接收到的type:{},不在处理范围内,不予处理 |
|
|
|
logger.info("################ 客户: {}, 非法的消息不予处理, 类型{}, 消息体 ################ \n {}", binaryModel.id, type, xml); |
|
|
|
logger.info("################ 会话: {}, 客户: {}, 非法的消息不予处理, 类型{}, 消息体 ################", binaryModel.id, type, xml); |
|
|
|
} |
|
|
|
if (type != SystemType.system && !StringUtil.isNullOrEmpty(json)) { |
|
|
|
//rabbitmq推送到消息队列中基于springboot_xggd |
|
|
|
rabbitTemplate.convertAndSend(Constant.EX_CHANGE_NAME, Constant.ROUTING_KEY_NAME, json); |
|
|
|
String receiveCode = root.element("ReceiveCode").getText(); |
|
|
|
responseMsg(receiveCode, sendCode); |
|
|
|
feedbackToDevice(binaryModel.uuid, receiveCode, sendCode); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void responseMsg(String sendCode, String receiveCode) { |
|
|
|
public void feedbackToDevice(String uuid, String sendCode, String receiveCode) { |
|
|
|
XStream xStream = new XStream(new Xpp3Driver(new NoNameCoder())); |
|
|
|
xStream.alias(aliasHost, ResponseControl.class); |
|
|
|
xStream.autodetectAnnotations(true); |
|
|
|
@ -334,11 +334,11 @@ public class NettyServer { |
|
|
|
responseControl.Time = CommonUtils.GetNowDateString(); |
|
|
|
responseControl.Items = ""; |
|
|
|
String xml = xStream.toXML(responseControl); |
|
|
|
sendMsg(receiveCode, false, xml); |
|
|
|
sendMsg(uuid, receiveCode, false, xml); |
|
|
|
} |
|
|
|
|
|
|
|
//处理注册应答 |
|
|
|
public void dealRegister(String xml) { |
|
|
|
public void dealRegister(String uuid, String xml) { |
|
|
|
BaseControl obj = new BaseControl(); |
|
|
|
try { |
|
|
|
XStream xStream = getXmlStreamInstance(); |
|
|
|
@ -348,8 +348,7 @@ public class NettyServer { |
|
|
|
xStream.addPermission(AnyTypePermission.ANY); |
|
|
|
obj = (BaseControl) xStream.fromXML(xml); |
|
|
|
} catch (com.thoughtworks.xstream.XStreamException e) { |
|
|
|
logger.error("################ 解析失败[PatrolHost] ################"); |
|
|
|
logger.error("################ 异常堆栈 ################\n{}", ExceptionUtils.getStackTrace(e)); |
|
|
|
logger.error("################ 注册解析失败, 异常堆栈[PatrolHost] {} ################", e.getMessage()); |
|
|
|
try { |
|
|
|
XStream xStreamEx = getXmlStreamInstance(); |
|
|
|
xStreamEx.alias(aliasDevice, BaseControl.class); |
|
|
|
@ -387,9 +386,9 @@ public class NettyServer { |
|
|
|
} |
|
|
|
responseControl.Items.add(model); |
|
|
|
|
|
|
|
|
|
|
|
// 推送消息到mq |
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
|
jsonObject.put("uuid", uuid); |
|
|
|
jsonObject.put("patroldevice_code", obj.SendCode); |
|
|
|
jsonObject.put("Type", "heartbeat"); |
|
|
|
jsonObject.put("eventType", "connect"); |
|
|
|
@ -400,7 +399,7 @@ public class NettyServer { |
|
|
|
// 鉴权不通过 |
|
|
|
responseControl.Code = ResponseType.fault; |
|
|
|
} |
|
|
|
sendRegisterResponse(responseControl, obj.SendCode); |
|
|
|
sendRegisterResponse(uuid, responseControl, obj.SendCode); |
|
|
|
} |
|
|
|
|
|
|
|
private XStream getXmlStreamInstance() { |
|
|
|
@ -434,26 +433,58 @@ public class NettyServer { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void sendRegisterResponse(RegisterResponseControl responseControl, String sendCode) { |
|
|
|
XStream xStream = new XStream(new Xpp3Driver(new NoNameCoder())); |
|
|
|
xStream.alias(aliasHost, RegisterResponseControl.class); |
|
|
|
xStream.autodetectAnnotations(true); |
|
|
|
String xml = xStream.toXML(responseControl); |
|
|
|
sendMsg(sendCode, false, xml); |
|
|
|
public void sendRegisterResponse(String uuid, RegisterResponseControl responseControl, String sendCode) { |
|
|
|
String xml = ""; |
|
|
|
try { |
|
|
|
XStream xStream = new XStream(new Xpp3Driver(new NoNameCoder())); |
|
|
|
xStream.alias(aliasHost, RegisterResponseControl.class); |
|
|
|
xStream.autodetectAnnotations(true); |
|
|
|
xml = xStream.toXML(responseControl); |
|
|
|
} catch (com.thoughtworks.xstream.XStreamException e) { |
|
|
|
logger.error("################ DOWN REGISTER 解析失败, 异常堆栈 [PatrolHost]: {} ################", ExceptionUtils.getMessage(e)); |
|
|
|
try { |
|
|
|
XStream xStream = new XStream(new Xpp3Driver(new NoNameCoder())); |
|
|
|
xStream.alias(aliasDevice, RegisterResponseControl.class); |
|
|
|
xStream.autodetectAnnotations(true); |
|
|
|
xml = xStream.toXML(responseControl); |
|
|
|
} catch (com.thoughtworks.xstream.XStreamException e2) { |
|
|
|
logger.error("################ DOWN REGISTER 解析失败[PatrolDevice] ################"); |
|
|
|
logger.error("################ DOWN REGISTER 异常堆栈[PatrolDevice] ################\n{}", ExceptionUtils.getStackTrace(e2)); |
|
|
|
} |
|
|
|
} |
|
|
|
sendMsg(uuid, sendCode, false, xml); |
|
|
|
} |
|
|
|
|
|
|
|
public void sendHeartBeat(String xml) { |
|
|
|
logger.info("[NETTY] 设备端机器人系统心跳消息: {}", xml); |
|
|
|
XStream xStream = new XStream(new Xpp3Driver(new NoNameCoder())); |
|
|
|
xStream.alias(aliasHost, BaseControl.class); |
|
|
|
xStream.autodetectAnnotations(true); |
|
|
|
xStream.ignoreUnknownElements(); |
|
|
|
xStream.addPermission(AnyTypePermission.ANY); |
|
|
|
BaseControl obj = (BaseControl) xStream.fromXML(xml); |
|
|
|
responseMsg(obj.ReceiveCode, obj.SendCode); |
|
|
|
public void sendHeartBeat(final String uuid, String xml) { |
|
|
|
//logger.info("################ 设备端机器人系统心跳消息 ################\n{}", xml); |
|
|
|
BaseControl obj = new BaseControl(); |
|
|
|
try { |
|
|
|
XStream xStream = new XStream(new Xpp3Driver(new NoNameCoder())); |
|
|
|
xStream.alias(aliasHost, BaseControl.class); |
|
|
|
xStream.autodetectAnnotations(true); |
|
|
|
xStream.ignoreUnknownElements(); |
|
|
|
xStream.addPermission(AnyTypePermission.ANY); |
|
|
|
obj = (BaseControl) xStream.fromXML(xml); |
|
|
|
} catch (com.thoughtworks.xstream.XStreamException e) { |
|
|
|
logger.error("################ HEARTBEAT TO MQ 解析失败, 异常堆栈[PatrolHost]: {} ################", e.getMessage()); |
|
|
|
try { |
|
|
|
XStream xStream = new XStream(new Xpp3Driver(new NoNameCoder())); |
|
|
|
xStream.alias(aliasDevice, BaseControl.class); |
|
|
|
xStream.autodetectAnnotations(true); |
|
|
|
xStream.ignoreUnknownElements(); |
|
|
|
xStream.addPermission(AnyTypePermission.ANY); |
|
|
|
obj = (BaseControl) xStream.fromXML(xml); |
|
|
|
} catch (com.thoughtworks.xstream.XStreamException e2) { |
|
|
|
logger.error("################ HEARTBEAT TO MQ 解析失败[PatrolDevice] ################"); |
|
|
|
logger.error("################ HEARTBEAT TO MQ 异常堆栈[PatrolDevice] ################\n{}", ExceptionUtils.getStackTrace(e2)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
feedbackToDevice(uuid, obj.ReceiveCode, obj.SendCode); |
|
|
|
|
|
|
|
// 推送消息到mq |
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
|
jsonObject.put("uuid", uuid); |
|
|
|
jsonObject.put("SendCode", obj.SendCode); |
|
|
|
jsonObject.put("Type", "heartbeat"); |
|
|
|
jsonObject.put("eventType", "heart"); |
|
|
|
@ -519,7 +550,7 @@ public class NettyServer { |
|
|
|
} |
|
|
|
if (!StringUtils.isEmpty(xml)) { |
|
|
|
logger.info("################ 向设备端下发命令 ################\n{}", xml); |
|
|
|
sendMsg(receiveCode, true, xml); |
|
|
|
sendMsg("", receiveCode, true, xml); |
|
|
|
} |
|
|
|
} |
|
|
|
} |