diff options
author | Valerii Vyshniak <valeravi@vi-soft.com.ua> | 2017-11-16 00:31:27 +0100 |
---|---|---|
committer | Valerii Vyshniak <valeravi@vi-soft.com.ua> | 2017-11-18 18:52:11 +0100 |
commit | f26eb9c61bc1270707af0a7589ae6ee56531e905 (patch) | |
tree | 3f5600eea3e3875024ee42a1e6a899bef33d82bc | |
parent | 2f98dd6c9f151f48d31ecd09ee06ccbcd4430b97 (diff) | |
download | trackermap-server-f26eb9c61bc1270707af0a7589ae6ee56531e905.tar.gz trackermap-server-f26eb9c61bc1270707af0a7589ae6ee56531e905.tar.bz2 trackermap-server-f26eb9c61bc1270707af0a7589ae6ee56531e905.zip |
T580W: parse battery level
-rw-r--r-- | src/org/traccar/protocol/Tk103ProtocolDecoder.java | 24 | ||||
-rw-r--r-- | test/org/traccar/protocol/Tk103ProtocolDecoderTest.java | 3 |
2 files changed, 26 insertions, 1 deletions
diff --git a/src/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java index 1a5ada81b..b62ee12ec 100644 --- a/src/org/traccar/protocol/Tk103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tk103ProtocolDecoder.java @@ -75,7 +75,7 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { .text("ZC20,") .number("(dd)(dd)(dd),") // date (ddmmyy) .number("(dd)(dd)(dd),") // time (hhmmss) - .number("d+,") // battery level + .number("(d+),") // battery level .number("(d+),") // battery voltage .number("(d+),") // power voltage .number("d+") // installed @@ -147,6 +147,23 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { } } + private Integer decodeBattery(int value) { + switch (value) { + case 6: + return 100; + case 5: + return 80; + case 4: + return 60; + case 3: + return 20; + case 2: + return 10; + default: + return null; + } + } + private Position decodeBattery(Channel channel, SocketAddress remoteAddress, String sentence) { Parser parser = new Parser(PATTERN_BATTERY, sentence); if (!parser.matches()) { @@ -164,6 +181,11 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { getLastLocation(position, parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS)); + int batterylevel = parser.nextInt(0); + if (batterylevel != 255) { + position.set(Position.KEY_BATTERY_LEVEL, decodeBattery(batterylevel)); + } + int battery = parser.nextInt(0); if (battery != 65535) { position.set(Position.KEY_BATTERY, battery * 0.01); diff --git a/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java b/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java index 3c17d2d11..4f8ee2858 100644 --- a/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java @@ -169,6 +169,9 @@ public class Tk103ProtocolDecoderTest extends ProtocolTest { verifyPosition(decoder, text( "(013632651491,ZC07,040613,A,2234.0297N,11405.9101E,000.0,040137,178.48)")); + verifyAttributes(decoder, text( + "(013632651491,ZC20,040613,040137,6,42,112,0")); + } } |