aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-01-12 17:06:52 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2016-01-12 17:06:52 +1300
commit8d973ed63075acfcf4b1c4809de41cb9d4a2c9db (patch)
treec43f2cb1573e76eda1816c98d55de4b4684677fa
parent751569af4d09b693ec01442ae2241ee5ec6432d7 (diff)
downloadtrackermap-server-8d973ed63075acfcf4b1c4809de41cb9d4a2c9db.tar.gz
trackermap-server-8d973ed63075acfcf4b1c4809de41cb9d4a2c9db.tar.bz2
trackermap-server-8d973ed63075acfcf4b1c4809de41cb9d4a2c9db.zip
Handle new format for Watch protocol
-rw-r--r--src/org/traccar/protocol/WatchProtocolDecoder.java19
-rw-r--r--test/org/traccar/protocol/WatchProtocolDecoderTest.java6
2 files changed, 17 insertions, 8 deletions
diff --git a/src/org/traccar/protocol/WatchProtocolDecoder.java b/src/org/traccar/protocol/WatchProtocolDecoder.java
index 00f49deb5..6b5d47023 100644
--- a/src/org/traccar/protocol/WatchProtocolDecoder.java
+++ b/src/org/traccar/protocol/WatchProtocolDecoder.java
@@ -50,9 +50,9 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
.number("-?(d+.d+),") // latitude
.expression("([NS]),")
.number("-?(d+.d+),") // longitude
- .expression("([EW]),")
+ .expression("([EW])?,")
.number("(d+.d+),") // speed
- .number("(d+.d+),") // course
+ .number("(d+.?d*),") // course
.number("(d+.?d*),") // altitude
.number("(d+),") // satellites
.number("(d+),") // gsm
@@ -92,15 +92,18 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
sendResponse(channel, manufacturer, id, "LK");
if (!content.isEmpty()) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(getDeviceId());
+ String[] values = content.split(",");
+ if (values.length >= 4) {
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
+ position.setDeviceId(getDeviceId());
- getLastLocation(position, null);
+ getLastLocation(position, null);
- position.set(Event.KEY_BATTERY, content.split(",")[3]);
+ position.set(Event.KEY_BATTERY, values[3]);
- return position;
+ return position;
+ }
}
} else if (type.equals("UD") || type.equals("UD2") || type.equals("AL")) {
diff --git a/test/org/traccar/protocol/WatchProtocolDecoderTest.java b/test/org/traccar/protocol/WatchProtocolDecoderTest.java
index 5b09f48ff..b7320098f 100644
--- a/test/org/traccar/protocol/WatchProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/WatchProtocolDecoderTest.java
@@ -10,6 +10,12 @@ public class WatchProtocolDecoderTest extends ProtocolTest {
WatchProtocolDecoder decoder = new WatchProtocolDecoder(new WatchProtocol());
+ verifyNothing(decoder, text(
+ "[SG*9081000548*0009*LK,0,100"));
+
+ verifyPosition(decoder, text(
+ "[SG*9081000548*00A9*UD,110116,113639,V,16.479064,S,68.119072,,0.7593,000,99,00,80,80,0,50,00000000,5,1,736,2,10103,10732,153,10103,11061,152,10103,11012,152,10103,10151,150,10103,10731,143,,00"));
+
verifyPosition(decoder, text(
"[3G*2256002206*0079*UD2,100116,153723,A,38.000000,N,-9.000000,W,0.44,299.3,0.0,7,100,86,0,0,00000008,2,0,268,3,3010,51042,146,3010,51043,132]"));