aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2018-08-28 17:32:08 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2018-08-28 17:32:08 +1200
commitb3e485ae96a7d8af1c339c2c960383a247752417 (patch)
treea675e3f998501ebe3414a5c398513d6a161cd85c /src/org/traccar
parent5de2f5a094469e87ff04e8605665ca8b9f33aa7a (diff)
downloadtrackermap-server-b3e485ae96a7d8af1c339c2c960383a247752417.tar.gz
trackermap-server-b3e485ae96a7d8af1c339c2c960383a247752417.tar.bz2
trackermap-server-b3e485ae96a7d8af1c339c2c960383a247752417.zip
Support photos for Galileo
Diffstat (limited to 'src/org/traccar')
-rw-r--r--src/org/traccar/protocol/GalileoProtocolDecoder.java60
1 files changed, 56 insertions, 4 deletions
diff --git a/src/org/traccar/protocol/GalileoProtocolDecoder.java b/src/org/traccar/protocol/GalileoProtocolDecoder.java
index 7e17ebd93..8ed4840a5 100644
--- a/src/org/traccar/protocol/GalileoProtocolDecoder.java
+++ b/src/org/traccar/protocol/GalileoProtocolDecoder.java
@@ -20,6 +20,7 @@ import io.netty.buffer.ByteBufUtil;
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.helper.UnitsConverter;
@@ -41,6 +42,8 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder {
super(protocol);
}
+ private ByteBuf photo;
+
private static final Map<Integer, Integer> TAG_LENGTH_MAP = new HashMap<>();
static {
@@ -92,10 +95,10 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder {
return length;
}
- private void sendReply(Channel channel, int checksum) {
+ private void sendReply(Channel channel, int header, int checksum) {
if (channel != null) {
ByteBuf reply = Unpooled.buffer(3);
- reply.writeByte(0x02);
+ reply.writeByte(header);
reply.writeShortLE((short) checksum);
channel.writeAndFlush(new NetworkMessage(reply, channel.remoteAddress()));
}
@@ -243,7 +246,19 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder {
ByteBuf buf = (ByteBuf) msg;
- buf.readUnsignedByte(); // header
+ int header = buf.readUnsignedByte();
+ if (header == 0x01) {
+ return decodePositions(channel, remoteAddress, buf);
+ } else if (header == 0x07) {
+ return decodePhoto(channel, remoteAddress, buf);
+ }
+
+ return null;
+ }
+
+ private Object decodePositions(
+ Channel channel, SocketAddress remoteAddress, ByteBuf buf) throws Exception {
+
int length = (buf.readUnsignedShortLE() & 0x7fff) + 3;
List<Position> positions = new LinkedList<>();
@@ -295,7 +310,7 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder {
positions.add(position);
}
- sendReply(channel, buf.readUnsignedShortLE());
+ sendReply(channel, 0x02, buf.readUnsignedShortLE());
for (Position p : positions) {
p.setDeviceId(deviceSession.getDeviceId());
@@ -304,4 +319,41 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder {
return positions.isEmpty() ? null : positions;
}
+ private Object decodePhoto(
+ Channel channel, SocketAddress remoteAddress, ByteBuf buf) throws Exception {
+
+ int length = buf.readUnsignedShortLE();
+
+ Position position = null;
+
+ if (length > 1) {
+
+ if (photo == null) {
+ photo = Unpooled.buffer();
+ }
+
+ buf.readUnsignedByte(); // part number
+ photo.writeBytes(buf, length - 1);
+
+ } else {
+
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
+ String uniqueId = Context.getIdentityManager().getById(deviceSession.getDeviceId()).getUniqueId();
+
+ position = new Position(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ getLastLocation(position, null);
+
+ position.set(Position.KEY_IMAGE, Context.getMediaManager().writeFile(uniqueId, photo, "jpg"));
+ photo.release();
+ photo = null;
+
+ }
+
+ sendReply(channel, 0x07, buf.readUnsignedShortLE());
+
+ return position;
+ }
+
}