diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2019-04-27 10:33:15 -0700 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2019-04-27 10:33:15 -0700 |
commit | c2c1e429865e84a09ce95dc9f9c8e707fa9c50eb (patch) | |
tree | 845058da18bda5cb55ea7bd0f1a8da1638f4c1ee /src/main | |
parent | 4abbb070fa13c480f2bc23aff0cfd026d186af80 (diff) | |
download | traccar-server-c2c1e429865e84a09ce95dc9f9c8e707fa9c50eb.tar.gz traccar-server-c2c1e429865e84a09ce95dc9f9c8e707fa9c50eb.tar.bz2 traccar-server-c2c1e429865e84a09ce95dc9f9c8e707fa9c50eb.zip |
Store received photo file
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/org/traccar/protocol/FifotrackProtocolDecoder.java | 16 |
1 files changed, 15 insertions, 1 deletions
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); |