aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/protocol/EelinkProtocolDecoder.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar/protocol/EelinkProtocolDecoder.java')
-rw-r--r--src/main/java/org/traccar/protocol/EelinkProtocolDecoder.java26
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) {