From c2c1e429865e84a09ce95dc9f9c8e707fa9c50eb Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 27 Apr 2019 10:33:15 -0700 Subject: Store received photo file --- .../org/traccar/protocol/FifotrackProtocolDecoder.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/main/java/org/traccar') diff --git a/src/main/java/org/traccar/protocol/FifotrackProtocolDecoder.java b/src/main/java/org/traccar/protocol/FifotrackProtocolDecoder.java index 2719464c9..a9cf025af 100644 --- a/src/main/java/org/traccar/protocol/FifotrackProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/FifotrackProtocolDecoder.java @@ -19,6 +19,7 @@ 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; @@ -181,6 +182,9 @@ public class FifotrackProtocolDecoder extends BaseProtocolDecoder { requestPhoto(channel, remoteAddress, imei, photoId); } } else if (type.equals("D06")) { + if (photo == null) { + return null; + } int dataIndex = buf.indexOf(typeIndex + 4, buf.writerIndex(), (byte) ',') + 1; dataIndex = buf.indexOf(dataIndex, buf.writerIndex(), (byte) ',') + 1; dataIndex = buf.indexOf(dataIndex, buf.writerIndex(), (byte) ',') + 1; @@ -193,7 +197,17 @@ public class FifotrackProtocolDecoder extends BaseProtocolDecoder { parser.nextInt(); // size buf.readerIndex(dataIndex); photo.writeBytes(buf.readBytes(buf.readableBytes() - 3)); // ignore checksum - requestPhoto(channel, remoteAddress, imei, photoId); + if (photo.isWritable()) { + requestPhoto(channel, remoteAddress, imei, photoId); + } else { + Position position = new Position(getProtocolName()); + position.setDeviceId(getDeviceSession(channel, remoteAddress, imei).getDeviceId()); + getLastLocation(position, null); + position.set(Position.KEY_IMAGE, Context.getMediaManager().writeFile(imei, photo, "jpg")); + photo.release(); + photo = null; + return position; + } } } else { String sentence = buf.toString(StandardCharsets.US_ASCII); -- cgit v1.2.3