|
@@ -7,6 +7,7 @@ import javax.xml.bind.DatatypeConverter;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
+import org.slf4j.MDC;
|
|
|
import org.springframework.context.annotation.Scope;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
@@ -102,24 +103,25 @@ public class YiTongGpsServerHandler extends HexBinaryAcceptanceHandlerAdapter {
|
|
|
private void handle(ByteBuf in, int length, Channel channel) throws Exception {
|
|
|
if (in.isReadable()) {
|
|
|
String deviceId = channelDeviceMap.get(channel);
|
|
|
-
|
|
|
+ if (deviceId!=null) {
|
|
|
+ MDC.put(MDC_DEVICEID, deviceId);
|
|
|
+ }
|
|
|
byte msgType = in.readByte();
|
|
|
if (LOGIN_MSG == msgType) {
|
|
|
-
|
|
|
resolveLoginMSG(in, channel);
|
|
|
} else if (LOCATION_MSG == msgType) {
|
|
|
logger.info("GPS 定位包");
|
|
|
sendMsg2Kafka(getOriginalData(in, deviceId), deviceId, channel);
|
|
|
// resolveLocationMSG(in, deviceId);
|
|
|
} else if (STATUS_MSG == msgType) {
|
|
|
- logger.info("心跳包");
|
|
|
+
|
|
|
reply(channel, STATUS_MSG);
|
|
|
} else if (WARNING_MSG == msgType) {
|
|
|
logger.info("报警数据(UTC)");
|
|
|
reply(channel, WARNING_MSG);
|
|
|
sendMsg2Kafka(getOriginalData(in, deviceId), deviceId, channel);
|
|
|
} else if (CORRECT_TIME_MSG == msgType) {
|
|
|
- logger.info("校时包");
|
|
|
+
|
|
|
reply(channel, CORRECT_TIME_MSG);
|
|
|
} else if (VOLTAGE_MSG == msgType) {
|
|
|
logger.info("信息传输通用包");
|
|
@@ -211,6 +213,7 @@ public class YiTongGpsServerHandler extends HexBinaryAcceptanceHandlerAdapter {
|
|
|
byte[] deviceIdBytes = new byte[8];
|
|
|
in.readBytes(deviceIdBytes);
|
|
|
String deviceId = DatatypeConverter.printHexBinary(deviceIdBytes);
|
|
|
+ MDC.put(MDC_DEVICEID, deviceId);
|
|
|
// 回复和链接管理
|
|
|
String deviceIdInMap = channelDeviceMap.get(channel);
|
|
|
if (!deviceId.equals(deviceIdInMap)) {
|
|
@@ -264,6 +267,7 @@ public class YiTongGpsServerHandler extends HexBinaryAcceptanceHandlerAdapter {
|
|
|
}
|
|
|
|
|
|
private void reply(Channel channel, byte msgType) {
|
|
|
+
|
|
|
ByteBuf buffer = Unpooled.buffer();
|
|
|
byte[] crcBytes = new byte[] { 0x05, msgType, 0x00, 0x05 };
|
|
|
int doCrc = CRCUtil.do_crc(65535, crcBytes);
|
|
@@ -275,7 +279,25 @@ public class YiTongGpsServerHandler extends HexBinaryAcceptanceHandlerAdapter {
|
|
|
@Override
|
|
|
public void operationComplete(Future<? super Void> future) throws Exception {
|
|
|
String deviceId = channelDeviceMap.get(channel);
|
|
|
- logger.info("server reply to client device [{}] success:[{}] ",deviceId, DatatypeConverter.printHexBinary(bytes));
|
|
|
+ String type = "";
|
|
|
+ switch (msgType) {
|
|
|
+ case STATUS_MSG:
|
|
|
+ type = "心跳包";
|
|
|
+ break;
|
|
|
+ case WARNING_MSG:
|
|
|
+ type = "报警数据(UTC)";
|
|
|
+ break;
|
|
|
+ case CORRECT_TIME_MSG:
|
|
|
+ type = "校时包";
|
|
|
+ break;
|
|
|
+ case LOGIN_MSG:
|
|
|
+ type = "登录包";
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ logger.info("server reply [{}] to client device [{}] success:[{}] ",type,deviceId, DatatypeConverter.printHexBinary(bytes));
|
|
|
}
|
|
|
});
|
|
|
}
|