diff options
-rw-r--r-- | src/org/traccar/protocol/Gps103ProtocolDecoder.java | 47 | ||||
-rw-r--r-- | test/org/traccar/protocol/Gps103ProtocolDecoderTest.java | 6 |
2 files changed, 52 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); diff --git a/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java b/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java index 00e85f5e3..b44eb26f9 100644 --- a/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java @@ -12,6 +12,12 @@ public class Gps103ProtocolDecoderTest extends ProtocolTest { Gps103ProtocolDecoder decoder = new Gps103ProtocolDecoder(null); verifyPosition(decoder, text( + "imei:864180034124375,vt14,190116192753,,F,172750.000,A,3649.2186,N,00235.8411,W,0.00,0,,0,0,51.93%,,+22;")); + + verifyNull(decoder, text( + "imei:864180034124375,vr,0c00fa011ea05a03d726977103ad0034c98ef49e6d303fffd1c8361303f2dbb0fa530d8ca3930be3e94f4110145c7029a507a0a00028f4a70514c05c500503170334b400531971cad002ab7634f001a4027949c8e541ea47f853bca2f961ba427ab1e290089197711c485e4f6e82ad0d1ee8f25573eed4af60284f6935bb7ef2307f1dc3f4355bbf3f90a607ffd2e5fcc6c60310be80f152dbca54ed53147fed3ae7fa1fe54809e45330fdedc993d073b7f2a6340a00d8cabeb9a4980c68900e5cb1f6e29aab9e00fc334012a5a5c32e5227c7b21a9a2d35dc02cdb49edb189fe545ec058fec7565e667cfa08b1fccd34686e4f12003dd7ffaf4b980957440bd595beb53269bb082a517dd570693604cb6299cb1663f5a9d608e3e42807d71cd002d206028011e50aa49381513494011349cd2092803ffd3d031f154ef11bc86d870781f8679a90302540adc545c55a00e28c8a602e47ad2e46680133cd19e6800cd1cf4a0063293ce695188e0d20265e58559305c3ffcb2948eca10d20278adb50518890c40f5ed9a5fece941ccb29cfd19ff00c2a6e860d6471c7da1cffb3b507eb9aaafa3dc4a4909b7fdf6c9fd28b88fffd4ca5d06e7b94152af87a53f7a7403d949a8e60265f0eaff0014ee7e8807f5a99340857abcadf881fd2973013a6936f1f48d4ffbc01fe95652dd63fba00fa521926d1de8e07a51600dc3d01d00;")); + + verifyPosition(decoder, text( "imei:868683026321020,T:+11,181217080050,,F,080047.000,A,3227.3057,N,11649.4754,W,0.00,0,,0,0,0.00%,,+11;")); verifyAttribute(decoder, text( |