aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/EelinkProtocolDecoder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2017-11-28 20:01:45 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2017-11-28 20:01:58 +1300
commit818fff6daf87a9e90a225122d04dc8b93694a8c6 (patch)
tree8f24ab85903d404023a27c35566efe6320da5dee /src/org/traccar/protocol/EelinkProtocolDecoder.java
parent97360131f2f5f53c79e4d41a3e5b3bfebe49d960 (diff)
downloadtrackermap-server-818fff6daf87a9e90a225122d04dc8b93694a8c6.tar.gz
trackermap-server-818fff6daf87a9e90a225122d04dc8b93694a8c6.tar.bz2
trackermap-server-818fff6daf87a9e90a225122d04dc8b93694a8c6.zip
Fix eelink checksum and decode result
Diffstat (limited to 'src/org/traccar/protocol/EelinkProtocolDecoder.java')
-rw-r--r--src/org/traccar/protocol/EelinkProtocolDecoder.java74
1 files changed, 73 insertions, 1 deletions
diff --git a/src/org/traccar/protocol/EelinkProtocolDecoder.java b/src/org/traccar/protocol/EelinkProtocolDecoder.java
index 91ae16289..f2b4f0765 100644
--- a/src/org/traccar/protocol/EelinkProtocolDecoder.java
+++ b/src/org/traccar/protocol/EelinkProtocolDecoder.java
@@ -21,13 +21,17 @@ import org.jboss.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
import org.traccar.helper.BitUtil;
+import org.traccar.helper.Parser;
+import org.traccar.helper.PatternBuilder;
import org.traccar.helper.UnitsConverter;
import org.traccar.model.CellTower;
import org.traccar.model.Network;
import org.traccar.model.Position;
import java.net.SocketAddress;
+import java.nio.charset.StandardCharsets;
import java.util.Date;
+import java.util.regex.Pattern;
public class EelinkProtocolDecoder extends BaseProtocolDecoder {
@@ -259,13 +263,73 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder {
return position;
}
+ /*
+ gg€^WˆLuLuLat:N23.111743
+Lon:E114.409238
+Course:0.00
+Speed:0.17KM/H
+Date Time:2015-09-13 20:21:20
+ */
+
+ private static final Pattern PATTERN = new PatternBuilder()
+ .text("Lat:")
+ .number("([NS])(d+.d+)") // latitude
+ .any()
+ .text("Lon:")
+ .number("([EW])(d+.d+)") // longitude
+ .any()
+ .text("Course:")
+ .number("(d+.d+)") // course
+ .any()
+ .text("Speed:")
+ .number("(d+.d+)KM/H") // speed
+ .any()
+ .text("Date Time:")
+ .number("(dddd)-(dd)-(dd) ") // date
+ .number("(dd):(dd):(dd)") // time
+ .compile();
+
+ private Position decodeResult(DeviceSession deviceSession, ChannelBuffer buf, int index) {
+
+ Position position = new Position();
+ position.setDeviceId(deviceSession.getDeviceId());
+ position.setProtocol(getProtocolName());
+
+ position.set(Position.KEY_INDEX, index);
+
+ buf.readUnsignedByte(); // type
+ buf.readUnsignedInt(); // uid
+
+ String sentence = buf.toString(StandardCharsets.UTF_8);
+
+ Parser parser = new Parser(PATTERN, sentence);
+ if (parser.matches()) {
+
+ position.setValid(true);
+ position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG));
+ position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG));
+ position.setCourse(parser.nextDouble());
+ position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble()));
+ position.setTime(parser.nextDateTime());
+
+ } else {
+
+ getLastLocation(position, null);
+
+ position.set(Position.KEY_RESULT, sentence);
+
+ }
+
+ return position;
+ }
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ChannelBuffer buf = (ChannelBuffer) msg;
- DeviceSession deviceSession = null;
+ DeviceSession deviceSession;
if (buf.getByte(0) == 'E' && buf.getByte(1) == 'L') {
buf.skipBytes(2 + 2 + 2); // udp header
@@ -297,9 +361,13 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder {
}
if (type == MSG_GPS || type == MSG_ALARM || type == MSG_STATE || type == MSG_SMS) {
+
return decodeOld(deviceSession, buf, type, index);
+
} else if (type >= MSG_NORMAL && type <= MSG_OBD_CODE) {
+
return decodeNew(deviceSession, buf, index);
+
} else if (type == MSG_HEARTBEAT && buf.readableBytes() >= 2) {
Position position = new Position();
@@ -312,6 +380,10 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder {
return position;
+ } else if (type == MSG_DOWNLINK) {
+
+ return decodeResult(deviceSession, buf, index);
+
}
}