diff options
Diffstat (limited to 'src/main/java/org/traccar/protocol/EgtsProtocolDecoder.java')
-rw-r--r-- | src/main/java/org/traccar/protocol/EgtsProtocolDecoder.java | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/src/main/java/org/traccar/protocol/EgtsProtocolDecoder.java b/src/main/java/org/traccar/protocol/EgtsProtocolDecoder.java index b9fcb2f44..9f0baf6b2 100644 --- a/src/main/java/org/traccar/protocol/EgtsProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/EgtsProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2018 Anton Tananaev (anton@traccar.org) + * Copyright 2018 - 2019 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,6 +39,8 @@ public class EgtsProtocolDecoder extends BaseProtocolDecoder { super(protocol); } + private boolean useObjectIdAsDeviceId = true; + public static final int PT_RESPONSE = 0; public static final int PT_APPDATA = 1; public static final int PT_SIGNED_APPDATA = 2; @@ -68,7 +70,7 @@ public class EgtsProtocolDecoder extends BaseProtocolDecoder { public static final int MSG_ABS_CNTR_DATA = 25; public static final int MSG_ABS_LOOPIN_DATA = 26; public static final int MSG_LIQUID_LEVEL_SENSOR = 27; - public static final int MSG_PASSENGERS_COUNTERS = 28; + public static final int MSG_PASSENGERS_COUNTERS = 28; private int packetId; @@ -121,11 +123,18 @@ public class EgtsProtocolDecoder extends BaseProtocolDecoder { ByteBuf buf = (ByteBuf) msg; + List<Position> positions = new LinkedList<>(); + + short headerLength = buf.getUnsignedByte(buf.readerIndex() + 3); int index = buf.getUnsignedShort(buf.readerIndex() + 5 + 2); - buf.skipBytes(buf.getUnsignedByte(buf.readerIndex() + 3)); + short packetType = buf.getUnsignedByte(buf.readerIndex() + 5 + 2 + 2); + buf.skipBytes(headerLength); - List<Position> positions = new LinkedList<>(); + if (packetType == PT_RESPONSE) { + return null; + } + long objectId = 0L; while (buf.readableBytes() > 2) { int length = buf.readUnsignedShortLE(); @@ -133,7 +142,7 @@ public class EgtsProtocolDecoder extends BaseProtocolDecoder { int recordFlags = buf.readUnsignedByte(); if (BitUtil.check(recordFlags, 0)) { - buf.readUnsignedIntLE(); // object id + objectId = buf.readUnsignedIntLE(); } if (BitUtil.check(recordFlags, 1)) { @@ -164,6 +173,7 @@ public class EgtsProtocolDecoder extends BaseProtocolDecoder { int end = buf.readUnsignedShortLE() + buf.readerIndex(); if (type == MSG_TERM_IDENTITY) { + useObjectIdAsDeviceId = false; buf.readUnsignedIntLE(); // object id int flags = buf.readUnsignedByte(); @@ -254,8 +264,16 @@ public class EgtsProtocolDecoder extends BaseProtocolDecoder { buf.readerIndex(end); } - if (serviceType == SERVICE_TELEDATA && deviceSession != null) { - positions.add(position); + if (serviceType == SERVICE_TELEDATA && position.getValid()) { + if (useObjectIdAsDeviceId && objectId != 0L) { + deviceSession = getDeviceSession(channel, remoteAddress, true, String.valueOf(objectId)); + if (deviceSession != null) { + position.setDeviceId(deviceSession.getDeviceId()); + } + } + if (deviceSession != null) { + positions.add(position); + } } } |