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 /src/org/traccar/protocol/Tk103ProtocolDecoder.java | |
parent | 2f98dd6c9f151f48d31ecd09ee06ccbcd4430b97 (diff) | |
download | trackermap-server-f26eb9c61bc1270707af0a7589ae6ee56531e905.tar.gz trackermap-server-f26eb9c61bc1270707af0a7589ae6ee56531e905.tar.bz2 trackermap-server-f26eb9c61bc1270707af0a7589ae6ee56531e905.zip |
T580W: parse battery level
Diffstat (limited to 'src/org/traccar/protocol/Tk103ProtocolDecoder.java')
-rw-r--r-- | src/org/traccar/protocol/Tk103ProtocolDecoder.java | 24 |
1 files changed, 23 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); |