diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2018-04-18 01:46:14 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2018-04-18 01:46:14 +1200 |
commit | b8d998875277a59a7d18f71fc725ba32ac61eda3 (patch) | |
tree | 9d5e926939debbfff367fe9fc7dde3635b002af5 | |
parent | 2850cd63c6f89304e4c038c82e5b320067c1a2c9 (diff) | |
download | trackermap-server-b8d998875277a59a7d18f71fc725ba32ac61eda3.tar.gz trackermap-server-b8d998875277a59a7d18f71fc725ba32ac61eda3.tar.bz2 trackermap-server-b8d998875277a59a7d18f71fc725ba32ac61eda3.zip |
Decode eeLink new format alarms
-rw-r--r-- | src/org/traccar/protocol/EelinkProtocolDecoder.java | 70 | ||||
-rw-r--r-- | test/org/traccar/protocol/EelinkProtocolDecoderTest.java | 6 |
2 files changed, 49 insertions, 27 deletions
diff --git a/src/org/traccar/protocol/EelinkProtocolDecoder.java b/src/org/traccar/protocol/EelinkProtocolDecoder.java index 0ed81c925..0fda6fb74 100644 --- a/src/org/traccar/protocol/EelinkProtocolDecoder.java +++ b/src/org/traccar/protocol/EelinkProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 - 2017 Anton Tananaev (anton@traccar.org) + * Copyright 2014 - 2018 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. @@ -170,7 +170,7 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder { return position; } - private Position decodeNew(DeviceSession deviceSession, ChannelBuffer buf, int index) { + private Position decodeNew(DeviceSession deviceSession, ChannelBuffer buf, int type, int index) { Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); @@ -218,43 +218,59 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder { buf.skipBytes(7); // bss2 } - if (buf.readableBytes() >= 2) { + if (type == MSG_WARNING) { + + position.set(Position.KEY_ALARM, decodeAlarm(buf.readUnsignedByte())); + + } else if (type == MSG_REPORT) { + + buf.readUnsignedByte(); // report type + + } + + if (type == MSG_NORMAL || type == MSG_WARNING || type == MSG_REPORT) { + 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 (type == MSG_NORMAL) { - if (buf.readableBytes() >= 4) { - position.set(Position.KEY_ODOMETER, buf.readUnsignedInt()); - } + if (buf.readableBytes() >= 2) { + position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.001); + } - if (buf.readableBytes() >= 4) { - buf.readUnsignedShort(); // gsm counter - buf.readUnsignedShort(); // gps counter - } + 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_STEPS, buf.readUnsignedShort()); - buf.readUnsignedShort(); // walking time - } + 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()); + } - 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; @@ -355,7 +371,7 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder { } else if (type >= MSG_NORMAL && type <= MSG_OBD_CODE) { - return decodeNew(deviceSession, buf, index); + return decodeNew(deviceSession, buf, type, index); } else if (type == MSG_HEARTBEAT && buf.readableBytes() >= 2) { diff --git a/test/org/traccar/protocol/EelinkProtocolDecoderTest.java b/test/org/traccar/protocol/EelinkProtocolDecoderTest.java index aaf58b438..b6145c183 100644 --- a/test/org/traccar/protocol/EelinkProtocolDecoderTest.java +++ b/test/org/traccar/protocol/EelinkProtocolDecoderTest.java @@ -14,6 +14,12 @@ public class EelinkProtocolDecoderTest extends ProtocolTest { "454C0027E753035254407167747167670100180002035254407167747100200205020500010432000086BD")); verifyPosition(decoder, binary( + "676714002414B05AD43A7D03026B92B10C395499FFD7000000000701CC00002495000014203604067B")); + + verifyNotNull(decoder, binary( + "676714004F14B0E68CAFE58AA8E68AA5E8ADA621E5B9BFE4B89CE79C81E6B7B1E59CB3E5B882E58D97E5B1B1E58CBAE696B0E8A5BFE8B7AF3138EFBC88E8B79DE5AE87E998B3E5A4A7E58EA63230E7B1B3EFBC89")); + + verifyPosition(decoder, binary( "676780005a000001000000004c61743a4e33312e38333935352c4c6f6e3a5738322e36313334362c436f757273653a302e30302c53706565643a302e30306b6d2f682c4461746554696d653a323031372d31322d30322031313a32393a3433")); verifyPosition(decoder, binary( |