diff options
Diffstat (limited to 'src/org/traccar/protocol/At2000ProtocolDecoder.java')
-rw-r--r-- | src/org/traccar/protocol/At2000ProtocolDecoder.java | 63 |
1 files changed, 33 insertions, 30 deletions
diff --git a/src/org/traccar/protocol/At2000ProtocolDecoder.java b/src/org/traccar/protocol/At2000ProtocolDecoder.java index 4c2967158..4457854e3 100644 --- a/src/org/traccar/protocol/At2000ProtocolDecoder.java +++ b/src/org/traccar/protocol/At2000ProtocolDecoder.java @@ -106,51 +106,54 @@ public class At2000ProtocolDecoder extends BaseProtocolDecoder { return null; // empty message } + List<Position> positions = new LinkedList<>(); + byte[] data = new byte[buf.capacity() - BLOCK_LENGTH]; buf.readBytes(data); buf = Unpooled.wrappedBuffer(cipher.update(data)); + try { + while (buf.readableBytes() >= 63) { - List<Position> positions = new LinkedList<>(); - - while (buf.readableBytes() >= 63) { - - Position position = new Position(getProtocolName()); - position.setDeviceId(deviceSession.getDeviceId()); + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); - buf.readUnsignedShortLE(); // index - buf.readUnsignedShortLE(); // reserved + buf.readUnsignedShortLE(); // index + buf.readUnsignedShortLE(); // reserved - position.setValid(true); + position.setValid(true); - position.setTime(new Date(buf.readLongLE() * 1000)); + position.setTime(new Date(buf.readLongLE() * 1000)); - position.setLatitude(buf.readFloatLE()); - position.setLongitude(buf.readFloatLE()); - position.setAltitude(buf.readFloatLE()); - position.setSpeed(UnitsConverter.knotsFromKph(buf.readFloatLE())); - position.setCourse(buf.readFloatLE()); + position.setLatitude(buf.readFloatLE()); + position.setLongitude(buf.readFloatLE()); + position.setAltitude(buf.readFloatLE()); + position.setSpeed(UnitsConverter.knotsFromKph(buf.readFloatLE())); + position.setCourse(buf.readFloatLE()); - buf.readUnsignedIntLE(); // geozone event - buf.readUnsignedIntLE(); // io events - buf.readUnsignedIntLE(); // geozone value - buf.readUnsignedIntLE(); // io values - buf.readUnsignedShortLE(); // operator + buf.readUnsignedIntLE(); // geozone event + buf.readUnsignedIntLE(); // io events + buf.readUnsignedIntLE(); // geozone value + buf.readUnsignedIntLE(); // io values + buf.readUnsignedShortLE(); // operator - position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShortLE()); - position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShortLE()); + position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShortLE()); + position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShortLE()); - position.set(Position.KEY_POWER, buf.readUnsignedShortLE() * 0.001); + position.set(Position.KEY_POWER, buf.readUnsignedShortLE() * 0.001); - buf.readUnsignedShortLE(); // cid - position.set(Position.KEY_RSSI, buf.readUnsignedByte()); - buf.readUnsignedByte(); // current profile + buf.readUnsignedShortLE(); // cid + position.set(Position.KEY_RSSI, buf.readUnsignedByte()); + buf.readUnsignedByte(); // current profile - position.set(Position.KEY_BATTERY, buf.readUnsignedByte()); - position.set(Position.PREFIX_TEMP + 1, buf.readUnsignedByte()); - position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); + position.set(Position.KEY_BATTERY, buf.readUnsignedByte()); + position.set(Position.PREFIX_TEMP + 1, buf.readUnsignedByte()); + position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); - positions.add(position); + positions.add(position); + } + } finally { + buf.release(); } return positions; |