aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2017-07-15 12:05:36 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2017-07-15 12:05:36 +1200
commit7a17135f9b0b1ae127b9cb5ea4f29e0af98a813b (patch)
tree3e3f25b7076480baf988e0bd6159570786ac628a
parent1b4bcb2cef3f4e3907ed0820478f2f3cae245c7f (diff)
downloadtrackermap-server-7a17135f9b0b1ae127b9cb5ea4f29e0af98a813b.tar.gz
trackermap-server-7a17135f9b0b1ae127b9cb5ea4f29e0af98a813b.tar.bz2
trackermap-server-7a17135f9b0b1ae127b9cb5ea4f29e0af98a813b.zip
Extend eelink protocol decoder
-rw-r--r--src/org/traccar/protocol/EelinkProtocolDecoder.java41
-rw-r--r--test/org/traccar/protocol/EelinkProtocolDecoderTest.java14
2 files changed, 45 insertions, 10 deletions
diff --git a/src/org/traccar/protocol/EelinkProtocolDecoder.java b/src/org/traccar/protocol/EelinkProtocolDecoder.java
index 0f6551cc3..e16866977 100644
--- a/src/org/traccar/protocol/EelinkProtocolDecoder.java
+++ b/src/org/traccar/protocol/EelinkProtocolDecoder.java
@@ -96,6 +96,22 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder {
}
}
+ private void decodeStatus(Position position, int status) {
+ if (BitUtil.check(status, 1)) {
+ position.set(Position.KEY_IGNITION, BitUtil.check(status, 2));
+ }
+ if (BitUtil.check(status, 3)) {
+ position.set(Position.KEY_ARMED, BitUtil.check(status, 4));
+ }
+ if (BitUtil.check(status, 5)) {
+ position.set(Position.KEY_BLOCKED, !BitUtil.check(status, 6));
+ }
+ if (BitUtil.check(status, 7)) {
+ position.set(Position.KEY_CHARGE, BitUtil.check(status, 8));
+ }
+ position.set(Position.KEY_STATUS, status);
+ }
+
private Position decodeOld(DeviceSession deviceSession, ChannelBuffer buf, int type, int index) {
Position position = new Position();
@@ -119,16 +135,11 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_ALARM, decodeAlarm(buf.readUnsignedByte()));
}
- if (buf.readableBytes() >= 2 * 5) {
+ if (buf.readableBytes() >= 2) {
+ decodeStatus(position, buf.readUnsignedShort());
+ }
- int status = buf.readUnsignedShort();
- if (BitUtil.check(status, 1)) {
- position.set(Position.KEY_IGNITION, BitUtil.check(status, 2));
- }
- if (BitUtil.check(status, 7)) {
- position.set(Position.KEY_CHARGE, BitUtil.check(status, 8));
- }
- position.set(Position.KEY_STATUS, status);
+ if (buf.readableBytes() >= 2 * 4) {
position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.001);
@@ -221,6 +232,18 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder {
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();
+ position.setDeviceId(deviceSession.getDeviceId());
+ position.setProtocol(getProtocolName());
+
+ getLastLocation(position, null);
+
+ decodeStatus(position, buf.readUnsignedShort());
+
+ return position;
+
}
}
diff --git a/test/org/traccar/protocol/EelinkProtocolDecoderTest.java b/test/org/traccar/protocol/EelinkProtocolDecoderTest.java
index 8aabf8375..46c85d89a 100644
--- a/test/org/traccar/protocol/EelinkProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/EelinkProtocolDecoderTest.java
@@ -14,6 +14,18 @@ public class EelinkProtocolDecoderTest extends ProtocolTest {
"676701000c007b03525440717505180104"));
verifyPosition(decoder, binary(
+ "6767050022001F59643640000000000000000000000001CC0000249500142000015964A6C0006E"));
+
+ verifyAttributes(decoder, binary(
+ "67670300040021006E"));
+
+ verifyPosition(decoder, binary(
+ "676705002200255964369D000000000000000000000001CC0000249500142000025964A71D006A"));
+
+ verifyAttributes(decoder, binary(
+ "67670300040028006A"));
+
+ verifyPosition(decoder, binary(
"676712002d066c592cca6803002631a60b22127700240046005c08020d000301af000da0fd12007f11ce05820000001899c0"));
verifyPosition(decoder, binary(
@@ -46,7 +58,7 @@ public class EelinkProtocolDecoderTest extends ProtocolTest {
verifyNull(decoder, binary(
"676701000b001b035418804661834901"));
- verifyNull(decoder, binary(
+ verifyAttributes(decoder, binary(
"6767030004001A0001"));
verifyNull(decoder, binary(