aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-05-28 06:31:55 -0700
committerAnton Tananaev <anton@traccar.org>2022-05-28 06:31:55 -0700
commit56af285413c2337079332f303f7d091d65f09c4e (patch)
tree800c4b6c3f7a54b98a63451aea3183832c64947c /src/main
parentbb50a4178d171d40734b94fccf52b72733f1f04c (diff)
downloadtrackermap-server-56af285413c2337079332f303f7d091d65f09c4e.tar.gz
trackermap-server-56af285413c2337079332f303f7d091d65f09c4e.tar.bz2
trackermap-server-56af285413c2337079332f303f7d091d65f09c4e.zip
Decode G6W audio format
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/traccar/helper/BufferUtil.java12
-rw-r--r--src/main/java/org/traccar/protocol/WatchProtocolDecoder.java39
2 files changed, 43 insertions, 8 deletions
diff --git a/src/main/java/org/traccar/helper/BufferUtil.java b/src/main/java/org/traccar/helper/BufferUtil.java
index 9485c17c6..1e1a687fa 100644
--- a/src/main/java/org/traccar/helper/BufferUtil.java
+++ b/src/main/java/org/traccar/helper/BufferUtil.java
@@ -27,6 +27,18 @@ public final class BufferUtil {
private BufferUtil() {
}
+ public static int indexOf(ByteBuf buffer, int fromIndex, int toIndex, byte value, int count) {
+ int startIndex = fromIndex;
+ for (int i = 0; i < count; i++) {
+ int result = buffer.indexOf(startIndex, toIndex, value);
+ if (result < 0 || i == count - 1) {
+ return result;
+ }
+ startIndex = result + 1;
+ }
+ return -1;
+ }
+
public static int indexOf(String needle, ByteBuf haystack) {
return indexOf(needle, haystack, haystack.readerIndex(), haystack.writerIndex());
}
diff --git a/src/main/java/org/traccar/protocol/WatchProtocolDecoder.java b/src/main/java/org/traccar/protocol/WatchProtocolDecoder.java
index b25a15f93..420866578 100644
--- a/src/main/java/org/traccar/protocol/WatchProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/WatchProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2021 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2022 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,14 +18,13 @@ package org.traccar.protocol;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.traccar.BaseProtocolDecoder;
import org.traccar.Context;
import org.traccar.DeviceSession;
import org.traccar.NetworkMessage;
import org.traccar.Protocol;
import org.traccar.helper.BitUtil;
+import org.traccar.helper.BufferUtil;
import org.traccar.helper.Parser;
import org.traccar.helper.PatternBuilder;
import org.traccar.helper.UnitsConverter;
@@ -41,7 +40,7 @@ import java.util.regex.Pattern;
public class WatchProtocolDecoder extends BaseProtocolDecoder {
- private static final Logger LOGGER = LoggerFactory.getLogger(WatchProtocolDecoder.class);
+ private ByteBuf audio;
public WatchProtocolDecoder(Protocol protocol) {
super(protocol);
@@ -318,13 +317,37 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
return position;
+ } else if (type.equals("JXTK")) {
+
+ int dataIndex = BufferUtil.indexOf(buf, buf.readerIndex(), buf.writerIndex(), (byte) ',', 4) + 1;
+ String[] values = buf.readCharSequence(
+ dataIndex - buf.readerIndex(), StandardCharsets.US_ASCII).toString().split(",");
+
+ int current = Integer.parseInt(values[2]);
+ int total = Integer.parseInt(values[3]);
+
+ if (audio == null) {
+ audio = Unpooled.buffer();
+ }
+ audio.writeBytes(buf);
+
+ sendResponse(channel, id, index, "JXTKR,1");
+
+ if (current < total) {
+ return null;
+ } else {
+ Position position = new Position(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+ getLastLocation(position, null);
+ position.set(Position.KEY_AUDIO, Context.getMediaManager().writeFile(id, audio, "amr"));
+ audio.release();
+ audio = null;
+ return position;
+ }
+
} else if (type.equals("TK")) {
if (buf.readableBytes() == 1) {
- byte result = buf.readByte();
- if (result != '1') {
- LOGGER.warn(type + "," + result);
- }
return null;
}