|
|
|
@ -38,6 +38,7 @@ import java.io.ByteArrayInputStream; |
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.Iterator; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.concurrent.*; |
|
|
|
|
|
|
|
@ -67,7 +68,7 @@ public class NettyServer { |
|
|
|
@Resource |
|
|
|
DeviceServerProperties deviceServerProperties; |
|
|
|
|
|
|
|
@Resource |
|
|
|
@Resource(name = "stringRedisTemplate") |
|
|
|
private RedisTemplate<String, String> redisTemplate; |
|
|
|
|
|
|
|
@Resource |
|
|
|
@ -162,7 +163,32 @@ public class NettyServer { |
|
|
|
nettyServerHandler.sendMsg(uuid, clientKey, tcpClientMap.get(clientKey), allBuf); |
|
|
|
sendIndex++; |
|
|
|
} else { |
|
|
|
logger.warn(Color.RED + "######## 会话: {}, 设备端机器人: [{}] 离线!!! ########" + Color.END, uuid, tcpClientMap.get(clientKey)); |
|
|
|
logger.warn(Color.RED + "######## 会话: {}, 客户: [{}/{}] 离线!!! ########" + Color.END, uuid, tcpClientMap.get(clientKey), clientKey); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void flushMsgToDeviceBroadcast(String uuid, String clientKey, boolean request, String xml) { |
|
|
|
for (Map.Entry<String, String> entry : tcpClientMap.entrySet()) { |
|
|
|
logger.info("######## flushMsgToDeviceBroadcast key: {}, value: {} ########", entry.getKey(), entry.getValue()); |
|
|
|
ByteBuf byteBuf = Unpooled.copiedBuffer(xml, CharsetUtil.UTF_8); |
|
|
|
int length = byteBuf.readableBytes(); |
|
|
|
ByteBuf allBuf = Unpooled.buffer(length + ConfigType.dataLength); |
|
|
|
allBuf.writeByte(0xEB); |
|
|
|
allBuf.writeByte(0x90); |
|
|
|
allBuf.writeLongLE(sendIndex); |
|
|
|
allBuf.writeLongLE(receiveIndex); |
|
|
|
allBuf.writeByte(request ? 0x00 : 0x01); |
|
|
|
allBuf.writeIntLE(length); |
|
|
|
allBuf.writeBytes(byteBuf); |
|
|
|
allBuf.writeByte(0xEB); |
|
|
|
allBuf.writeByte(0x90); |
|
|
|
redisTemplate.opsForValue().set(String.valueOf(sendIndex), allBuf.toString(CharsetUtil.US_ASCII), 60L, TimeUnit.SECONDS); |
|
|
|
logger.info(Color.MAGENTA + "######## => 会话:{}, 客户:{}, 向设备回送序列:{}, 接收端序列:{}, 消息########\n{}" + Color.END, uuid, tcpClientMap.get(clientKey), sendIndex, receiveIndex, xml); |
|
|
|
nettyServerHandler.sendMsg(uuid, entry.getKey(), tcpClientMap.get(entry.getKey()), allBuf); |
|
|
|
sendIndex++; |
|
|
|
try { |
|
|
|
Thread.sleep(1); |
|
|
|
} catch (InterruptedException e) {} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -195,6 +221,7 @@ public class NettyServer { |
|
|
|
Document document = saxReader.read(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8))); |
|
|
|
Element root = document.getRootElement(); |
|
|
|
String sendCode = root.element("SendCode").getText(); |
|
|
|
String receiveCode = root.element("ReceiveCode").getText(); |
|
|
|
tcpClientMap.put(sendCode, binaryModel.id); |
|
|
|
int type = 0; |
|
|
|
if (null != root.element("Type") && !StringUtil.isNullOrEmpty(root.element("Type").getText())) { |
|
|
|
@ -205,7 +232,7 @@ public class NettyServer { |
|
|
|
command = Integer.parseInt(root.element("Command").getText()); |
|
|
|
} |
|
|
|
|
|
|
|
// logger.info(Color.MAGENTA + "######## <= 会话: {}, 客户: {}, 消息类型: {}, 命令:{}, 消息体: ########\n{}" + Color.END, binaryModel.uuid, binaryModel.id, type, command, xml); |
|
|
|
logger.info(Color.MAGENTA + "######## <= 会话: {}, 客户: [{}/{}], 消息类型: {}, 命令:{}, 消息体: ########\n{}" + Color.END, binaryModel.uuid, sendCode, binaryModel.id, type, command, xml); |
|
|
|
//判断是否重发 |
|
|
|
if (type == SystemType.system) { |
|
|
|
if (command == SystemType.has_response || command == SystemType.no_response) { |
|
|
|
@ -279,7 +306,7 @@ public class NettyServer { |
|
|
|
break; |
|
|
|
case PushType.patrolDeviceRunning:// insert into basedata_mont_patdevrundata |
|
|
|
// json = downXml2Json.PatrolDeviceRunningControlXml2Json(xml); |
|
|
|
json = downXml2Json.DownStreamJson2Xml(binaryModel.uuid, binaryModel.id, xml, PatrolDeviceRuningControl.class); |
|
|
|
json = downXml2Json.DownStreamJson2Xml(binaryModel.uuid, binaryModel.id, xml, PatrolDeviceRunningControl.class); |
|
|
|
logger.info("######## 会话: {}, 客户: {}, 客户端设备运行数据 ########", binaryModel.uuid, binaryModel.id); |
|
|
|
break; |
|
|
|
case PushType.nestState:// insert into basedata_mont_neststadata |
|
|
|
@ -289,7 +316,7 @@ public class NettyServer { |
|
|
|
break; |
|
|
|
case PushType.nestRunning:// insert into basedata_mont_nestrundata |
|
|
|
// json = downXml2Json.NestRunningControlXml2Json(xml); |
|
|
|
json = downXml2Json.DownStreamJson2Xml(binaryModel.uuid, binaryModel.id, xml, NestRuningControl.class); |
|
|
|
json = downXml2Json.DownStreamJson2Xml(binaryModel.uuid, binaryModel.id, xml, NestRunningControl.class); |
|
|
|
logger.info("######## 会话: {}, 客户: {}, 客户端机巢运行数据 ########", binaryModel.uuid, binaryModel.id); |
|
|
|
break; |
|
|
|
case PushType.location:// insert into basedata_mont_patdevcoord |
|
|
|
@ -324,20 +351,33 @@ public class NettyServer { |
|
|
|
break; |
|
|
|
default: |
|
|
|
// server-handle-接收到的type:{},不在处理范围内,不予处理 |
|
|
|
logger.info("######## 会话: {}, 客户: {}, 非法的消息不予处理, 类型{}, 消息体 {} ########", binaryModel.uuid, binaryModel.id, type, xml); |
|
|
|
logger.info("######## 会话: {}, 客户: {}, 非法的消息不予处理, 类型{}, 消息体 ########\n{}", binaryModel.uuid, binaryModel.id, type, xml); |
|
|
|
} |
|
|
|
if (type != SystemType.system && !StringUtil.isNullOrEmpty(json)) { |
|
|
|
//rabbitmq推送到消息队列中基于springboot_xggd |
|
|
|
JSONObject jsonObject = JSONObject.parseObject(json); |
|
|
|
jsonObject.put("uuid", binaryModel.uuid); |
|
|
|
json = jsonObject.toJSONString(); |
|
|
|
// send to BasedataMontDataMqAcceptHandle |
|
|
|
rabbitTemplate.convertAndSend(Constant.EX_CHANGE_NAME, Constant.ROUTING_KEY_NAME, json); |
|
|
|
String receiveCode = root.element("ReceiveCode").getText(); |
|
|
|
boolean isHost = json.contains(aliasHost); |
|
|
|
logger.info("######## 会话: {}, 客户: {}, isHost: {}", binaryModel.uuid, binaryModel.id, isHost); |
|
|
|
sendResponseToDevice(binaryModel.uuid, receiveCode, sendCode, isHost); |
|
|
|
if ((type == NestCtlType.courseReversal && command == 3)) { // 处理用SSCOM模拟的数据, 向无人机发送控制指令 |
|
|
|
logger.info("######## 会话: {}, 客户: {}, 向设备透传200001控制指令", binaryModel.uuid, binaryModel.id); |
|
|
|
flushMsgToDeviceBroadcast(binaryModel.uuid, receiveCode, false, xml); |
|
|
|
} else { |
|
|
|
//rabbitmq推送到消息队列中基于springboot_xggd |
|
|
|
JSONObject jsonObject = JSONObject.parseObject(json); |
|
|
|
jsonObject.put("uuid", binaryModel.uuid); |
|
|
|
json = jsonObject.toJSONString(); |
|
|
|
// send to BasedataMontDataMqAcceptHandle |
|
|
|
rabbitTemplate.convertAndSend(Constant.EX_CHANGE_NAME, Constant.ROUTING_KEY_NAME, json); |
|
|
|
boolean isHost = json.contains(aliasHost); |
|
|
|
logger.info("######## 会话: {}, 客户: {}, isHost: {}", binaryModel.uuid, binaryModel.id, isHost); |
|
|
|
sendResponseToDevice(binaryModel.uuid, receiveCode, sendCode, isHost); |
|
|
|
} |
|
|
|
} else { |
|
|
|
if ((type == NestCtlType.suddenStop && command == 7) |
|
|
|
|| (type == NestCtlType.ptzPitch && command == 6) |
|
|
|
|| (type == NestCtlType.picModelSet && command == 1) |
|
|
|
|| (type == NestCtlType.nestSuddenStop && command == 2)) {// 处理用SSCOM模拟的数据, 向无人机发送控制指令 |
|
|
|
logger.info("######## 会话: {}, 客户: {}, 向设备透传200002~20005控制指令", binaryModel.uuid, binaryModel.id); |
|
|
|
flushMsgToDeviceBroadcast(binaryModel.uuid, receiveCode, false, xml); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public void sendResponseToDevice(String uuid, String sendCode, String receiveCode, boolean isHost) { |
|
|
|
|