|
@@ -1,10 +1,13 @@
|
|
|
package com.tidecloud.dataacceptance.service.impl;
|
|
|
|
|
|
+import java.nio.charset.Charset;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
+import javax.xml.bind.DatatypeConverter;
|
|
|
+
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.context.annotation.Scope;
|
|
@@ -19,6 +22,7 @@ import io.netty.buffer.ByteBuf;
|
|
|
import io.netty.buffer.Unpooled;
|
|
|
import io.netty.channel.Channel;
|
|
|
import io.netty.channel.ChannelFuture;
|
|
|
+import io.netty.channel.ChannelHandlerContext;
|
|
|
import io.netty.channel.ChannelHandler.Sharable;
|
|
|
import io.netty.util.concurrent.Future;
|
|
|
import io.netty.util.concurrent.GenericFutureListener;
|
|
@@ -38,7 +42,6 @@ public class WatchServerHandler extends HexBinaryAcceptanceHandlerAdapter {
|
|
|
protected void handle(ByteBuf in, Channel channel) throws Exception {
|
|
|
ByteBuf byteBuf = (ByteBuf) in;
|
|
|
String msg = byteBufferToString(byteBuf.nioBuffer());
|
|
|
- logger.info("接入数据:{}", msg);
|
|
|
Advice advice = getAdevice(msg);
|
|
|
String deviceId = advice.getDeviceId();
|
|
|
String adviceType = advice.getAdviceType();
|
|
@@ -51,7 +54,7 @@ public class WatchServerHandler extends HexBinaryAcceptanceHandlerAdapter {
|
|
|
byte[] dataByteArray = new byte[in.readableBytes()];
|
|
|
in.readBytes(dataByteArray);
|
|
|
receiveMsg(dataByteArray, deviceId, channel);
|
|
|
- //logger.info("正常存储设备信息:" + getDevice(msg).toString());
|
|
|
+ // logger.info("正常存储设备信息:" + getDevice(msg).toString());
|
|
|
break;
|
|
|
case "LK":
|
|
|
normalReply(advice, channel);
|
|
@@ -65,7 +68,6 @@ public class WatchServerHandler extends HexBinaryAcceptanceHandlerAdapter {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
private void normalReply(Advice advice, Channel channel) {
|
|
|
String facotry = advice.getFacotry();
|
|
|
String adviceType = advice.getAdviceType();
|
|
@@ -114,29 +116,13 @@ public class WatchServerHandler extends HexBinaryAcceptanceHandlerAdapter {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- /* 数据[手表具体数据] [对应位数] [数据内容]
|
|
|
- * 3G*3918197044*0107*UD [0] [厂商*设备 ID*内容长度*内容类型]
|
|
|
- 200917 [1] 日期
|
|
|
- 054140 [2] 时间
|
|
|
- V [3] gps定位是否有效[A]有效,[V]无效
|
|
|
- 31.171093 [4] 纬度
|
|
|
- N [5] 纬度表示
|
|
|
- 121.4215967 [6] 经度
|
|
|
- E [7] 经度表示
|
|
|
- 0.00 [8] 速度
|
|
|
- 0.0 [9] 方向
|
|
|
- 0.0 [10] 海拔
|
|
|
- 0 [11] 卫星个数
|
|
|
- 42,50 [12] gsm信号强度
|
|
|
- 14420 [13] 电量
|
|
|
- 0 [14] 计步数
|
|
|
- 00000010 [15] 终端状态
|
|
|
- 7,255 [16]
|
|
|
- 460 [17]
|
|
|
- 0 [18]
|
|
|
- ... ...
|
|
|
- */
|
|
|
+ /*
|
|
|
+ * 数据[手表具体数据] [对应位数] [数据内容] 3G*3918197044*0107*UD [0] [厂商*设备 ID*内容长度*内容类型]
|
|
|
+ * 200917 [1] 日期 054140 [2] 时间 V [3] gps定位是否有效[A]有效,[V]无效 31.171093 [4] 纬度 N [5]
|
|
|
+ * 纬度表示 121.4215967 [6] 经度 E [7] 经度表示 0.00 [8] 速度 0.0 [9] 方向 0.0 [10] 海拔 0 [11]
|
|
|
+ * 卫星个数 42,50 [12] gsm信号强度 14420 [13] 电量 0 [14] 计步数 00000010 [15] 终端状态 7,255
|
|
|
+ * [16] 460 [17] 0 [18] ... ...
|
|
|
+ */
|
|
|
public Device getDevice(String msg) throws Exception {
|
|
|
int startIndex = msg.indexOf("[");
|
|
|
int endIndex = msg.indexOf("]");
|
|
@@ -175,16 +161,16 @@ public class WatchServerHandler extends HexBinaryAcceptanceHandlerAdapter {
|
|
|
String[] headersBodys = headers.split("\\*");
|
|
|
String gpsState = bodys[3];
|
|
|
logger.info("正在解析device,gpsState:" + gpsState);
|
|
|
-
|
|
|
- String imei = "3588"+headersBodys[1]+"8";
|
|
|
+
|
|
|
+ String imei = "3588" + headersBodys[1] + "8";
|
|
|
String type = headersBodys[3];
|
|
|
- if (("UD".equals(type) || "UD2".equals(type))&&!"A".equals(gpsState)) {
|
|
|
+ if (("UD".equals(type) || "UD2".equals(type)) && !"A".equals(gpsState)) {
|
|
|
int length = Integer.valueOf(bodys[17]);
|
|
|
-
|
|
|
+
|
|
|
String mcc = bodys[19];
|
|
|
String mnc = bodys[20];
|
|
|
- int start = 21;
|
|
|
-
|
|
|
+ int start = 21;
|
|
|
+
|
|
|
for (int i = 0; i < length; i++) {
|
|
|
LbsInfo lbsInfo = new LbsInfo();
|
|
|
lbsInfo.setImei(imei);
|
|
@@ -195,17 +181,37 @@ public class WatchServerHandler extends HexBinaryAcceptanceHandlerAdapter {
|
|
|
lbsInfo.setCellid(bodys[start]);
|
|
|
start++;
|
|
|
int signal = Integer.valueOf(bodys[start]);
|
|
|
-// if (signal>0) {
|
|
|
-// signal = signal*2 - 113;
|
|
|
-// }
|
|
|
+ // if (signal>0) {
|
|
|
+ // signal = signal*2 - 113;
|
|
|
+ // }
|
|
|
lbsInfo.setSignal(signal);
|
|
|
start++;
|
|
|
lbsList.add(lbsInfo);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return lbsList;
|
|
|
}
|
|
|
|
|
|
+ /*
|
|
|
+ * (non-Javadoc)
|
|
|
+ *
|
|
|
+ * @see
|
|
|
+ * com.tidecloud.dataacceptance.service.AcceptanceInboundHandlerAdapter#getMsg(
|
|
|
+ * byte[])
|
|
|
+ */
|
|
|
+ protected String getMsg(byte[] dataByteArray) {
|
|
|
+ Charset charset = Charset.forName("UTF-8");
|
|
|
+ String msg = new String(dataByteArray, charset);
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
|
|
|
+ protected void printAcceptanceData(ByteBuf dataByteBuf,ChannelHandlerContext ctx) {
|
|
|
+ ByteBuf dataByteBufCopy = dataByteBuf.copy();
|
|
|
+ byte[] dataByteArray = new byte[dataByteBufCopy.readableBytes()];
|
|
|
+ dataByteBufCopy.readBytes(dataByteArray);
|
|
|
+ String msg = getMsg(dataByteArray);
|
|
|
+ logger.info("设备: [{}] 传入数据为 : {}", channelDeviceMap.get(ctx.channel()), msg);
|
|
|
+ dataByteBufCopy.release();
|
|
|
+ }
|
|
|
}
|