From f26eb9c61bc1270707af0a7589ae6ee56531e905 Mon Sep 17 00:00:00 2001 From: Valerii Vyshniak Date: Thu, 16 Nov 2017 00:31:27 +0100 Subject: T580W: parse battery level --- src/org/traccar/protocol/Tk103ProtocolDecoder.java | 24 +++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src/org') 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); -- cgit v1.2.3