aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-11-01 14:42:22 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2015-11-01 14:43:13 +1300
commit35ba8d35cacbe3e94ffef12416bd034441950d75 (patch)
tree0fe32e796554a50ede10f0e50ed9e4e7803fc97c
parentceda2502b2311389b4d5605079d30eb35df9b78a (diff)
downloadtraccar-server-35ba8d35cacbe3e94ffef12416bd034441950d75.tar.gz
traccar-server-35ba8d35cacbe3e94ffef12416bd034441950d75.tar.bz2
traccar-server-35ba8d35cacbe3e94ffef12416bd034441950d75.zip
Support TK103 battery info (fix #1097)
-rw-r--r--src/org/traccar/protocol/Tk103ProtocolDecoder.java44
-rw-r--r--test/org/traccar/protocol/Tk103ProtocolDecoderTest.java6
2 files changed, 48 insertions, 2 deletions
diff --git a/src/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java
index 73ab08b59..95728c447 100644
--- a/src/org/traccar/protocol/Tk103ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Tk103ProtocolDecoder.java
@@ -38,7 +38,7 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder {
.number("(d+)(,)?") // device id
.expression(".{4},?") // command
.number("d*") // imei?
- .number("(dd)(dd)(dd),?") // date (yymmdd)
+ .number("(dd)(dd)(dd),?") // date
.expression("([AV]),?") // validity
.number("(dd)(dd.d+)") // latitude
.expression("([NS]),?")
@@ -53,6 +53,17 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder {
.text(")").optional()
.compile();
+ private static final Pattern PATTERN_BATTERY = new PatternBuilder()
+ .number("(d+),") // device id
+ .text("ZC20,")
+ .number("(dd)(dd)(dd),") // date (ddmmyy)
+ .number("(dd)(dd)(dd),") // time
+ .number("d+,") // battery level
+ .number("(d+),") // battery voltage
+ .number("(d+),") // power voltage
+ .number("d+") // installed
+ .compile();
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -77,7 +88,36 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder {
}
}
- Parser parser = new Parser(PATTERN, sentence);
+ Parser parser = new Parser(PATTERN_BATTERY, sentence);
+ if (parser.matches()) {
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
+
+ if (!identify(parser.next(), channel)) {
+ return null;
+ }
+ position.setDeviceId(getDeviceId());
+
+ DateBuilder dateBuilder = new DateBuilder()
+ .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt())
+ .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt());
+
+ getLastLocation(position, dateBuilder.getDate());
+
+ int battery = parser.nextInt();
+ if (battery != 65535) {
+ position.set(Event.KEY_BATTERY, battery);
+ }
+
+ int power = parser.nextInt();
+ if (power != 65535) {
+ position.set(Event.KEY_POWER, battery);
+ }
+
+ return position;
+ }
+
+ parser = new Parser(PATTERN, sentence);
if (!parser.matches()) {
return null;
}
diff --git a/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java b/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java
index 8f2cea217..d9152ecf0 100644
--- a/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java
@@ -10,6 +10,12 @@ public class Tk103ProtocolDecoderTest extends ProtocolDecoderTest {
Tk103ProtocolDecoder decoder = new Tk103ProtocolDecoder(new Tk103Protocol());
+ verifyAttributes(decoder, text(
+ "(013632651491,ZC20,040613,040137,6,42,112,0"));
+
+ verifyAttributes(decoder, text(
+ "(864768010159785,ZC20,291015,030413,3,362,65535,255"));
+
verifyPosition(decoder, text(
"(088047365460BR00151024A2555.3531S02855.3329E004.7055148276.1701000000L00009AA3)"),
position("2015-10-24 05:51:48.000", true, -25.92255, 28.92222));