From 7a17135f9b0b1ae127b9cb5ea4f29e0af98a813b Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 15 Jul 2017 12:05:36 +1200 Subject: Extend eelink protocol decoder --- .../traccar/protocol/EelinkProtocolDecoder.java | 41 +++++++++++++++++----- 1 file changed, 32 insertions(+), 9 deletions(-) (limited to 'src/org/traccar/protocol/EelinkProtocolDecoder.java') 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; + } } -- cgit v1.2.3 From ff949b7ee233cd343f1fb5bb5ef7db7f24991df0 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 29 Aug 2017 05:16:55 +1200 Subject: Fix eeLink status decoding --- .../traccar/protocol/EelinkProtocolDecoder.java | 37 +++++++++++++++------- 1 file changed, 26 insertions(+), 11 deletions(-) (limited to 'src/org/traccar/protocol/EelinkProtocolDecoder.java') diff --git a/src/org/traccar/protocol/EelinkProtocolDecoder.java b/src/org/traccar/protocol/EelinkProtocolDecoder.java index e16866977..11d111e54 100644 --- a/src/org/traccar/protocol/EelinkProtocolDecoder.java +++ b/src/org/traccar/protocol/EelinkProtocolDecoder.java @@ -131,22 +131,37 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder { position.setValid((buf.readUnsignedByte() & 0x01) != 0); - if (type == MSG_ALARM) { - position.set(Position.KEY_ALARM, decodeAlarm(buf.readUnsignedByte())); - } + if (type == MSG_GPS) { - if (buf.readableBytes() >= 2) { - decodeStatus(position, buf.readUnsignedShort()); - } + if (buf.readableBytes() >= 2) { + decodeStatus(position, buf.readUnsignedShort()); + } + + if (buf.readableBytes() >= 2 * 4) { + + position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.001); + + position.set(Position.KEY_RSSI, buf.readUnsignedShort()); - if (buf.readableBytes() >= 2 * 4) { + position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort()); + position.set(Position.PREFIX_ADC + 2, buf.readUnsignedShort()); - position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.001); + } + + } else if (type == MSG_ALARM) { + + position.set(Position.KEY_ALARM, decodeAlarm(buf.readUnsignedByte())); - position.set(Position.KEY_RSSI, buf.readUnsignedShort()); + } else if (type == MSG_STATE) { - position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort()); - position.set(Position.PREFIX_ADC + 2, buf.readUnsignedShort()); + int statusType = buf.readUnsignedByte(); + + position.set(Position.KEY_EVENT, statusType); + + if (statusType == 0x01 || statusType == 0x02 || statusType == 0x03) { + buf.readUnsignedInt(); // device time + decodeStatus(position, buf.readUnsignedShort()); + } } -- cgit v1.2.3 From 3aebd92cc3781b417ded6260d1300434b1418e7e Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 8 Sep 2017 04:45:40 +1200 Subject: Handle GOOME status message --- src/org/traccar/protocol/EelinkProtocolDecoder.java | 4 +++- test/org/traccar/protocol/EelinkProtocolDecoderTest.java | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'src/org/traccar/protocol/EelinkProtocolDecoder.java') diff --git a/src/org/traccar/protocol/EelinkProtocolDecoder.java b/src/org/traccar/protocol/EelinkProtocolDecoder.java index 11d111e54..2526282b1 100644 --- a/src/org/traccar/protocol/EelinkProtocolDecoder.java +++ b/src/org/traccar/protocol/EelinkProtocolDecoder.java @@ -160,7 +160,9 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder { if (statusType == 0x01 || statusType == 0x02 || statusType == 0x03) { buf.readUnsignedInt(); // device time - decodeStatus(position, buf.readUnsignedShort()); + if (buf.readableBytes() >= 2) { + decodeStatus(position, buf.readUnsignedShort()); + } } } diff --git a/test/org/traccar/protocol/EelinkProtocolDecoderTest.java b/test/org/traccar/protocol/EelinkProtocolDecoderTest.java index 46c85d89a..d62357fe3 100644 --- a/test/org/traccar/protocol/EelinkProtocolDecoderTest.java +++ b/test/org/traccar/protocol/EelinkProtocolDecoderTest.java @@ -13,6 +13,12 @@ public class EelinkProtocolDecoderTest extends ProtocolTest { verifyNull(decoder, binary( "676701000c007b03525440717505180104")); + verifyPosition(decoder, binary( + "676705002102b459ae7388fcd360d7034332b1000000028f000a4f64002eb101010159ae7388")); + + verifyPosition(decoder, binary( + "676702001c02b259ae7387fcd360d6034332b2000000028f000a4f64002eb10101")); + verifyPosition(decoder, binary( "6767050022001F59643640000000000000000000000001CC0000249500142000015964A6C0006E")); -- cgit v1.2.3 From 62e2696c2d8e619d90cb978fa60f714312649866 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 24 Sep 2017 14:45:14 +1300 Subject: Support additional eeLink parameters --- src/org/traccar/model/Position.java | 1 + .../traccar/protocol/EelinkProtocolDecoder.java | 41 ++++++++++++++++++++++ src/org/traccar/protocol/H02ProtocolDecoder.java | 2 +- src/org/traccar/protocol/WatchProtocolDecoder.java | 2 +- .../protocol/EelinkProtocolDecoderTest.java | 3 ++ 5 files changed, 47 insertions(+), 2 deletions(-) (limited to 'src/org/traccar/protocol/EelinkProtocolDecoder.java') diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java index c188124af..31af3d38a 100644 --- a/src/org/traccar/model/Position.java +++ b/src/org/traccar/model/Position.java @@ -37,6 +37,7 @@ public class Position extends Message { public static final String KEY_ODOMETER_SERVICE = "serviceOdometer"; // meters public static final String KEY_ODOMETER_TRIP = "tripOdometer"; // meters public static final String KEY_HOURS = "hours"; + public static final String KEY_STEPS = "steps"; public static final String KEY_INPUT = "input"; public static final String KEY_OUTPUT = "output"; public static final String KEY_IMAGE = "image"; diff --git a/src/org/traccar/protocol/EelinkProtocolDecoder.java b/src/org/traccar/protocol/EelinkProtocolDecoder.java index 2526282b1..8d0f8016a 100644 --- a/src/org/traccar/protocol/EelinkProtocolDecoder.java +++ b/src/org/traccar/protocol/EelinkProtocolDecoder.java @@ -217,6 +217,45 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder { buf.skipBytes(7); // bss2 } + if (buf.readableBytes() >= 2) { + int status = buf.readUnsignedShort(); + position.setValid(BitUtil.check(status, 0)); + if (BitUtil.check(status, 1)) { + position.set(Position.KEY_IGNITION, BitUtil.check(status, 2)); + } + position.set(Position.KEY_STATUS, status); + } + + if (buf.readableBytes() >= 2) { + position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.001); + } + + if (buf.readableBytes() >= 4) { + position.set(Position.PREFIX_ADC + 0, buf.readUnsignedShort()); + position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort()); + } + + if (buf.readableBytes() >= 4) { + position.set(Position.KEY_ODOMETER, buf.readUnsignedInt()); + } + + if (buf.readableBytes() >= 4) { + buf.readUnsignedShort(); // gsm counter + buf.readUnsignedShort(); // gps counter + } + + if (buf.readableBytes() >= 4) { + position.set(Position.KEY_STEPS, buf.readUnsignedShort()); + buf.readUnsignedShort(); // walking time + } + + if (buf.readableBytes() >= 12) { + position.set(Position.PREFIX_TEMP + 1, buf.readUnsignedShort() / 256.0); + position.set("humidity", buf.readUnsignedShort() * 0.1); + position.set("illuminance", buf.readUnsignedInt() / 256.0); + position.set("co2", buf.readUnsignedInt()); + } + return position; } @@ -240,6 +279,7 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder { getDeviceSession(channel, remoteAddress, ChannelBuffers.hexDump(buf.readBytes(8)).substring(1)); } else { + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress); if (deviceSession == null) { return null; @@ -262,6 +302,7 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder { return position; } + } return null; diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java index aea8f0b3b..e4b18e277 100644 --- a/src/org/traccar/protocol/H02ProtocolDecoder.java +++ b/src/org/traccar/protocol/H02ProtocolDecoder.java @@ -392,7 +392,7 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_RSSI, parser.nextInt()); position.set(Position.KEY_SATELLITES, parser.nextInt()); position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt()); - position.set("steps", parser.nextInt()); + position.set(Position.KEY_STEPS, parser.nextInt()); position.set("turnovers", parser.nextInt()); dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0)); diff --git a/src/org/traccar/protocol/WatchProtocolDecoder.java b/src/org/traccar/protocol/WatchProtocolDecoder.java index adab65245..86dc9456d 100644 --- a/src/org/traccar/protocol/WatchProtocolDecoder.java +++ b/src/org/traccar/protocol/WatchProtocolDecoder.java @@ -205,7 +205,7 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_RSSI, parser.nextInt(0)); position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt(0)); - position.set("steps", parser.nextInt(0)); + position.set(Position.KEY_STEPS, parser.nextInt(0)); int status = parser.nextHexInt(0); position.set(Position.KEY_ALARM, decodeAlarm(status)); diff --git a/test/org/traccar/protocol/EelinkProtocolDecoderTest.java b/test/org/traccar/protocol/EelinkProtocolDecoderTest.java index ca2bb463e..115eef1a3 100644 --- a/test/org/traccar/protocol/EelinkProtocolDecoderTest.java +++ b/test/org/traccar/protocol/EelinkProtocolDecoderTest.java @@ -13,6 +13,9 @@ public class EelinkProtocolDecoderTest extends ProtocolTest { verifyNull(decoder, binary( "676701000c007b03525440717505180104")); + verifyPosition(decoder, binary( + "6767120048000559c1829213059a7400008e277d000c000000000800cc00080d2a000034df3cf0b429dd82cad3048910320000000000007b7320d005ba0000000019a000000000000000000000")); + verifyPosition(decoder, binary( "6767050020213b59c6aecdff41dce70b8b977d00000001fe000a36e30078fe010159c6aecd")); -- cgit v1.2.3