aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/protocol
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2023-10-25 20:42:52 -0700
committerAnton Tananaev <anton@traccar.org>2023-10-25 20:42:52 -0700
commit74ead779cd0b275620ffd399bac7b57f4bc02deb (patch)
tree9e65b6a34d7612dc6c1d953db1264fbe9ad982d7 /src/main/java/org/traccar/protocol
parentb7145ea2e9d7efabb0d9806e76e7ac2995e56b27 (diff)
downloadtrackermap-server-74ead779cd0b275620ffd399bac7b57f4bc02deb.tar.gz
trackermap-server-74ead779cd0b275620ffd399bac7b57f4bc02deb.tar.bz2
trackermap-server-74ead779cd0b275620ffd399bac7b57f4bc02deb.zip
Support Teltonika DSM camera
Diffstat (limited to 'src/main/java/org/traccar/protocol')
-rw-r--r--src/main/java/org/traccar/protocol/DualcamProtocolDecoder.java30
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: