diff options
-rw-r--r-- | src/main/java/org/traccar/protocol/DualcamProtocolDecoder.java | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/src/main/java/org/traccar/protocol/DualcamProtocolDecoder.java b/src/main/java/org/traccar/protocol/DualcamProtocolDecoder.java index f6712d7f2..b0e793a43 100644 --- a/src/main/java/org/traccar/protocol/DualcamProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/DualcamProtocolDecoder.java @@ -46,11 +46,15 @@ public class DualcamProtocolDecoder extends BaseProtocolDecoder { public static final int MSG_PATH_RESPONSE = 0x000D; private String uniqueId; - private int packetCount; - private int currentPacket; + private int dataSize; + private int dataCurrent; private boolean video; private ByteBuf media; + private boolean isPacketData() { + return dataSize < 100; + } + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -97,21 +101,29 @@ public class DualcamProtocolDecoder extends BaseProtocolDecoder { break; case MSG_START: buf.readUnsignedShort(); // length - packetCount = buf.readInt(); - currentPacket = 1; + dataSize = buf.readInt(); + dataCurrent = isPacketData() ? 1 : 0; media = Unpooled.buffer(); if (channel != null) { ByteBuf response = Unpooled.buffer(); response.writeShort(MSG_RESUME); response.writeShort(4); - response.writeInt(currentPacket); + response.writeInt(dataCurrent); channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); } break; case MSG_DATA: - buf.readUnsignedShort(); // length - media.writeBytes(buf, buf.readableBytes() - 2); - if (currentPacket == packetCount) { + int length = buf.readUnsignedShort(); + media.writeBytes(buf, length); + boolean finished; + if (isPacketData()) { + finished = dataCurrent == dataSize; + dataCurrent += 1; + } else { + finished = dataCurrent + length == dataSize; + dataCurrent += length; + } + if (finished) { deviceSession = getDeviceSession(channel, remoteAddress); Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); @@ -132,8 +144,6 @@ public class DualcamProtocolDecoder extends BaseProtocolDecoder { channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); } return position; - } else { - currentPacket += 1; } break; case MSG_PATH_RESPONSE: |