aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2019-01-16 21:40:38 -0800
committerAnton Tananaev <anton.tananaev@gmail.com>2019-01-16 21:40:38 -0800
commitca2cca9355c3b36b2e7ed9ad808db797fa94cb78 (patch)
tree8cb06ad4ac1a47f9ae626b89b972982f4d11d3a0 /src/org/traccar/protocol
parent29147f2731bdb235f90174d1a8cc4fd5fb3f27cd (diff)
downloadtrackermap-server-ca2cca9355c3b36b2e7ed9ad808db797fa94cb78.tar.gz
trackermap-server-ca2cca9355c3b36b2e7ed9ad808db797fa94cb78.tar.bz2
trackermap-server-ca2cca9355c3b36b2e7ed9ad808db797fa94cb78.zip
Support 105B and 103B photos
Diffstat (limited to 'src/org/traccar/protocol')
-rw-r--r--src/org/traccar/protocol/Gps103ProtocolDecoder.java47
1 files changed, 46 insertions, 1 deletions
diff --git a/src/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/org/traccar/protocol/Gps103ProtocolDecoder.java
index 1fbae15ce..27b94739b 100644
--- a/src/org/traccar/protocol/Gps103ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gps103ProtocolDecoder.java
@@ -15,11 +15,15 @@
*/
package org.traccar.protocol;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
+import org.traccar.Context;
import org.traccar.DeviceSession;
import org.traccar.NetworkMessage;
import org.traccar.Protocol;
+import org.traccar.helper.DataConverter;
import org.traccar.helper.DateBuilder;
import org.traccar.helper.Parser;
import org.traccar.helper.PatternBuilder;
@@ -34,6 +38,9 @@ import java.util.regex.Pattern;
public class Gps103ProtocolDecoder extends BaseProtocolDecoder {
+ private int photoPackets = 0;
+ private ByteBuf photo;
+
public Gps103ProtocolDecoder(Protocol protocol) {
super(protocol);
}
@@ -190,6 +197,9 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder {
if (channel != null) {
channel.writeAndFlush(new NetworkMessage("**,imei:" + imei + ",E;", remoteAddress));
}
+ } else if (alarm.startsWith("vt")) {
+ photoPackets = Integer.parseInt(alarm.substring(2));
+ photo = Unpooled.buffer();
} else if (alarm.equals("acc on")) {
position.set(Position.KEY_IGNITION, true);
} else if (alarm.equals("acc off")) {
@@ -336,6 +346,39 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder {
return position;
}
+ private Position decodePhoto(Channel channel, SocketAddress remoteAddress, String sentence) {
+
+ String imei = sentence.substring(5, 5 + 15);
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
+ if (deviceSession == null) {
+ return null;
+ }
+
+ ByteBuf buf = Unpooled.wrappedBuffer(DataConverter.parseHex(
+ sentence.substring(24, sentence.endsWith(";") ? sentence.length() - 1 : sentence.length())));
+ int index = buf.readUnsignedShortLE();
+ photo.writeBytes(buf, buf.readerIndex() + 2, buf.readableBytes() - 4);
+
+ if (index + 1 >= photoPackets) {
+ Position position = new Position(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ getLastLocation(position, null);
+
+ try {
+ position.set(Position.KEY_IMAGE, Context.getMediaManager().writeFile(imei, photo, "jpg"));
+ } finally {
+ photoPackets = 0;
+ photo.release();
+ photo = null;
+ }
+
+ return position;
+ } else {
+ return null;
+ }
+ }
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -365,7 +408,9 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder {
}
}
- if (sentence.contains("OBD")) {
+ if (sentence.substring(21, 21 + 2).equals("vr")) {
+ return decodePhoto(channel, remoteAddress, sentence);
+ } else if (sentence.substring(21, 21 + 3).contains("OBD")) {
return decodeObd(channel, remoteAddress, sentence);
} else if (sentence.endsWith("*")) {
return decodeAlternative(channel, remoteAddress, sentence);