diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2018-02-27 08:01:46 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2018-02-27 17:02:25 +1300 |
commit | ed2798625b993c9ac42d83fec291c2bdd68750d4 (patch) | |
tree | f66c76114fc97e8d335489ab1cf407cb58f198ce /src/org/traccar/protocol/MeitrackProtocolDecoder.java | |
parent | 8ce5b13f0c088f88ce39e6f5fa155fbfc1533085 (diff) | |
download | trackermap-server-ed2798625b993c9ac42d83fec291c2bdd68750d4.tar.gz trackermap-server-ed2798625b993c9ac42d83fec291c2bdd68750d4.tar.bz2 trackermap-server-ed2798625b993c9ac42d83fec291c2bdd68750d4.zip |
Improve Meitrack photo decoding
Diffstat (limited to 'src/org/traccar/protocol/MeitrackProtocolDecoder.java')
-rw-r--r-- | src/org/traccar/protocol/MeitrackProtocolDecoder.java | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/org/traccar/protocol/MeitrackProtocolDecoder.java index 11e38194f..513a024ed 100644 --- a/src/org/traccar/protocol/MeitrackProtocolDecoder.java +++ b/src/org/traccar/protocol/MeitrackProtocolDecoder.java @@ -434,9 +434,9 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { return positions; } - private void requestPhotoPacket(Channel channel, String imei, int index) { + private void requestPhotoPacket(Channel channel, String imei, String file, int index) { if (channel != null) { - String content = "D00,camera_picture.jpg," + index; + String content = "D00," + file + "," + index; int length = 1 + imei.length() + 1 + content.length() + 5; String response = String.format("@@O%02d,%s,%s*", length, imei, content); response += Checksum.sum(response) + "\r\n"; @@ -458,11 +458,14 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { switch (type) { case "D00": if (photo == null) { - return null; + photo = ChannelBuffers.dynamicBuffer(); } - index = buf.indexOf(index + 1 + type.length() + 1, buf.writerIndex(), (byte) ',') + 1; + index = index + 1 + type.length() + 1; int endIndex = buf.indexOf(index, buf.writerIndex(), (byte) ','); + String file = buf.toString(index, endIndex - index, StandardCharsets.US_ASCII); + index = endIndex + 1; + endIndex = buf.indexOf(index, buf.writerIndex(), (byte) ','); int total = Integer.parseInt(buf.toString(index, endIndex - index, StandardCharsets.US_ASCII)); index = endIndex + 1; endIndex = buf.indexOf(index, buf.writerIndex(), (byte) ','); @@ -483,13 +486,13 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { return position; } else { if ((current + 1) % 8 == 0) { - requestPhotoPacket(channel, imei, current + 1); + requestPhotoPacket(channel, imei, file, current + 1); } return null; } case "D03": photo = ChannelBuffers.dynamicBuffer(); - requestPhotoPacket(channel, imei, 0); + requestPhotoPacket(channel, imei, "camera_picture.jpg", 0); return null; case "CCC": return decodeBinaryC(channel, remoteAddress, buf); |