diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2018-03-09 15:18:22 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2018-03-09 15:18:22 +1300 |
commit | 7831801c2d3d4d425659f985a53dbc1eaef6b5fb (patch) | |
tree | 6f82f5f717bdeb3c227eca997bdce53e2136f8b8 /src/org/traccar | |
parent | 7bf00894ad47ef47ce4c9ccc84b560956f3b41f8 (diff) | |
download | traccar-server-7831801c2d3d4d425659f985a53dbc1eaef6b5fb.tar.gz traccar-server-7831801c2d3d4d425659f985a53dbc1eaef6b5fb.tar.bz2 traccar-server-7831801c2d3d4d425659f985a53dbc1eaef6b5fb.zip |
Extend Watch response format
Diffstat (limited to 'src/org/traccar')
-rw-r--r-- | src/org/traccar/protocol/WatchProtocolDecoder.java | 30 |
1 files changed, 22 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")) { |