diff options
-rw-r--r-- | src/org/traccar/protocol/WatchProtocolDecoder.java | 19 | ||||
-rw-r--r-- | test/org/traccar/protocol/WatchProtocolDecoderTest.java | 6 |
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]")); |