aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/protocol/DingtekProtocolDecoder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2020-05-29 23:11:19 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2020-05-29 23:11:19 -0700
commitc524d170f3324ccf10944887faa3d9f35e99e31a (patch)
tree15ddad1449f81cbad53f266665eddbc7615599f6 /src/main/java/org/traccar/protocol/DingtekProtocolDecoder.java
parentab1022d0c571af09b2036f8694db71537fa430cd (diff)
downloadtrackermap-server-c524d170f3324ccf10944887faa3d9f35e99e31a.tar.gz
trackermap-server-c524d170f3324ccf10944887faa3d9f35e99e31a.tar.bz2
trackermap-server-c524d170f3324ccf10944887faa3d9f35e99e31a.zip
Fix protocol decoding
Diffstat (limited to 'src/main/java/org/traccar/protocol/DingtekProtocolDecoder.java')
-rw-r--r--src/main/java/org/traccar/protocol/DingtekProtocolDecoder.java33
1 files changed, 21 insertions, 12 deletions
diff --git a/src/main/java/org/traccar/protocol/DingtekProtocolDecoder.java b/src/main/java/org/traccar/protocol/DingtekProtocolDecoder.java
index 1488c2cd6..98fe4b7b3 100644
--- a/src/main/java/org/traccar/protocol/DingtekProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/DingtekProtocolDecoder.java
@@ -17,13 +17,16 @@ package org.traccar.protocol;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
+import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
import org.traccar.Protocol;
+import org.traccar.helper.DataConverter;
import org.traccar.model.Position;
import java.net.SocketAddress;
+import java.util.Date;
public class DingtekProtocolDecoder extends BaseProtocolDecoder {
@@ -35,23 +38,29 @@ public class DingtekProtocolDecoder extends BaseProtocolDecoder {
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
- ByteBuf buf = (ByteBuf) msg;
+ String sentence = (String) msg;
- buf.readUnsignedByte(); // header
- buf.readUnsignedByte(); // forced
- buf.readUnsignedByte(); // device type
- int type = buf.readUnsignedByte();
- buf.readUnsignedByte(); // length
-
- String imei = ByteBufUtil.hexDump(buf.slice(buf.writerIndex() - 9, 8)).substring(1);
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
- if (deviceSession == null) {
- return null;
- }
+ int type = Integer.parseInt(sentence.substring(6, 8), 16);
if (type == 0x01 || type == 0x02 || type == 0x04) {
+
+ ByteBuf buf = Unpooled.wrappedBuffer(DataConverter.parseHex(sentence));
+
+ buf.readUnsignedByte(); // header
+ buf.readUnsignedByte(); // forced
+ buf.readUnsignedByte(); // device type
+ buf.readUnsignedByte(); // type
+ buf.readUnsignedByte(); // length
+
+ String imei = ByteBufUtil.hexDump(buf.slice(buf.writerIndex() - 9, 8)).substring(1);
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
+ if (deviceSession == null) {
+ return null;
+ }
+
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
+ position.setTime(new Date());
position.set("height", buf.readUnsignedShort());