From 5a62b28e205186358bf45349d31f53c95b5f8a1e Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 19 Aug 2020 21:57:17 -0700 Subject: Improve eeLink decoder --- .../traccar/protocol/EelinkProtocolDecoder.java | 26 ++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'src/main/java/org/traccar') 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 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) { -- cgit v1.2.3