diff options
-rw-r--r-- | src/org/traccar/protocol/WatchProtocolDecoder.java | 30 | ||||
-rw-r--r-- | test/org/traccar/protocol/WatchProtocolDecoderTest.java | 9 |
2 files changed, 31 insertions, 8 deletions
diff --git a/src/org/traccar/protocol/WatchProtocolDecoder.java b/src/org/traccar/protocol/WatchProtocolDecoder.java index fe62874b5..6adcb34f2 100644 --- a/src/org/traccar/protocol/WatchProtocolDecoder.java +++ b/src/org/traccar/protocol/WatchProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 - 2017 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -60,10 +60,15 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { .expression("(.*)") // cell and wifi .compile(); - private void sendResponse(Channel channel, String manufacturer, String id, String content) { + private void sendResponse(Channel channel, String manufacturer, String id, String index, String content) { if (channel != null) { - channel.write(String.format( - "[%s*%s*%04x*%s]", manufacturer, id, content.length(), content)); + if (index != null) { + channel.write(String.format( + "[%s*%s*%s*%04x*%s]", manufacturer, id, index, content.length(), content)); + } else { + channel.write(String.format( + "[%s*%s*%04x*%s]", manufacturer, id, content.length(), content)); + } } } @@ -134,13 +139,22 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { String manufacturer = buf.readBytes(2).toString(StandardCharsets.US_ASCII); buf.skipBytes(1); // delimiter - String id = buf.readBytes(10).toString(StandardCharsets.US_ASCII); + int idLength = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '*'); + String id = buf.readBytes(idLength).toString(StandardCharsets.US_ASCII); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id); if (deviceSession == null) { return null; } buf.skipBytes(1); // delimiter + + String index = null; + if (idLength > 10) { + int indexLength = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '*'); + index = buf.readBytes(indexLength).toString(StandardCharsets.US_ASCII); + buf.skipBytes(1); // delimiter + } + buf.skipBytes(4); // length buf.skipBytes(1); // delimiter @@ -159,7 +173,7 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { if (type.equals("LK")) { - sendResponse(channel, manufacturer, id, "LK"); + sendResponse(channel, manufacturer, id, index, "LK"); if (buf.readable()) { String[] values = buf.toString(StandardCharsets.US_ASCII).split(","); @@ -179,7 +193,7 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { || type.equals("AL") || type.equals("WT")) { if (type.equals("AL")) { - sendResponse(channel, manufacturer, id, "AL"); + sendResponse(channel, manufacturer, id, index, "AL"); } Parser parser = new Parser(PATTERN_POSITION, buf.toString(StandardCharsets.US_ASCII)); @@ -217,7 +231,7 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { } else if (type.equals("TKQ")) { - sendResponse(channel, manufacturer, id, "TKQ"); + sendResponse(channel, manufacturer, id, index, "TKQ"); } else if (type.equals("PULSE") || type.equals("heart")) { diff --git a/test/org/traccar/protocol/WatchProtocolDecoderTest.java b/test/org/traccar/protocol/WatchProtocolDecoderTest.java index c960ccc25..46b4c1cd0 100644 --- a/test/org/traccar/protocol/WatchProtocolDecoderTest.java +++ b/test/org/traccar/protocol/WatchProtocolDecoderTest.java @@ -11,6 +11,15 @@ public class WatchProtocolDecoderTest extends ProtocolTest { WatchProtocolDecoder decoder = new WatchProtocolDecoder(new WatchProtocol()); verifyPosition(decoder, buffer( + "[ZJ*014111001350304*0033*0064*UD,070318,020827,V,00.000000,N,000.000000,E,0,0,0,0,100,19,1000,50,00000000,1,255,460,0,9346,5223,42]")); + + verifyPosition(decoder, buffer( + "[ZJ*014111001350304*0035*0097*UD,070318,020857,V,00.000000,N,000.000000,E,0,0,0,0,100,19,1000,50,00000000,5,255,460,0,9346,5223,42,9346,5214,21,9784,4083,13,9346,5222,11,9346,5221,8]")); + + verifyPosition(decoder, buffer( + "[ZJ*014111001350304*0038*008a*UD,070318,021027,V,00.000000,N,000.000000,E,0,0,0,0,100,18,1000,50,00000000,4,255,460,0,9346,5223,42,9346,5214,20,9784,4083,11,9346,5221,5]")); + + verifyPosition(decoder, buffer( "[3G*8308373902*0080*AL,230817,095346,A,47.083950,N,15.4821850,E,7.60,273.8,0.0,4,15,44,0,0,00200010,2,255,232,1,7605,42530,118,7605,58036,119,0,65.8]")); verifyPosition(decoder, buffer( |