diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2020-08-19 21:57:17 -0700 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2020-08-19 21:57:17 -0700 |
commit | 5a62b28e205186358bf45349d31f53c95b5f8a1e (patch) | |
tree | bd4b673102e28348cfec82b25ce647f6d001ce85 /src/main/java/org/traccar/protocol | |
parent | 8ac3babace6125aa430b39581e347d42996a7ce3 (diff) | |
download | trackermap-server-5a62b28e205186358bf45349d31f53c95b5f8a1e.tar.gz trackermap-server-5a62b28e205186358bf45349d31f53c95b5f8a1e.tar.bz2 trackermap-server-5a62b28e205186358bf45349d31f53c95b5f8a1e.zip |
Improve eeLink decoder
Diffstat (limited to 'src/main/java/org/traccar/protocol')
-rw-r--r-- | src/main/java/org/traccar/protocol/EelinkProtocolDecoder.java | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/main/java/org/traccar/protocol/EelinkProtocolDecoder.java b/src/main/java/org/traccar/protocol/EelinkProtocolDecoder.java index c3fe7121e..9778cd4e5 100644 --- a/src/main/java/org/traccar/protocol/EelinkProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/EelinkProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 - 2018 Anton Tananaev (anton@traccar.org) + * Copyright 2014 - 2020 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. @@ -35,6 +35,8 @@ import org.traccar.model.Position; import java.net.SocketAddress; import java.nio.charset.StandardCharsets; import java.util.Date; +import java.util.LinkedList; +import java.util.List; import java.util.regex.Pattern; public class EelinkProtocolDecoder extends BaseProtocolDecoder { @@ -388,9 +390,29 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder { deviceSession = getDeviceSession(channel, remoteAddress); } + List<Position> positions = new LinkedList<>(); + + while (buf.isReadable()) { + Position position = decodePackage(channel, remoteAddress, buf, uniqueId, deviceSession); + if (position != null) { + positions.add(position); + } + } + + if (!positions.isEmpty()) { + return positions.size() > 1 ? positions : positions.iterator().next(); + } else { + return null; + } + } + + protected Position decodePackage( + Channel channel, SocketAddress remoteAddress, ByteBuf buf, + String uniqueId, DeviceSession deviceSession) throws Exception { + buf.skipBytes(2); // header int type = buf.readUnsignedByte(); - buf.readShort(); // length + buf = buf.readSlice(buf.readUnsignedShort()); int index = buf.readUnsignedShort(); if (type != MSG_GPS && type != MSG_DATA) { |