aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2023-07-12 07:27:40 -0700
committerAnton Tananaev <anton@traccar.org>2023-07-12 07:27:48 -0700
commit7325030436e5fc42b6998240a0c5696a1d4fed5a (patch)
tree70bcbe4fb90b3c19857b606fae23310e20aead52 /src
parentb3c6e22fc19ceeceb0f318131538b5e1d260450c (diff)
downloadtrackermap-server-7325030436e5fc42b6998240a0c5696a1d4fed5a.tar.gz
trackermap-server-7325030436e5fc42b6998240a0c5696a1d4fed5a.tar.bz2
trackermap-server-7325030436e5fc42b6998240a0c5696a1d4fed5a.zip
Fix GT06 transparent data
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/traccar/helper/BufferUtil.java12
-rw-r--r--src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java17
-rw-r--r--src/main/java/org/traccar/protocol/TeltonikaProtocolDecoder.java17
-rw-r--r--src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java13
4 files changed, 30 insertions, 29 deletions
diff --git a/src/main/java/org/traccar/helper/BufferUtil.java b/src/main/java/org/traccar/helper/BufferUtil.java
index d1025f548..12c31ba9d 100644
--- a/src/main/java/org/traccar/helper/BufferUtil.java
+++ b/src/main/java/org/traccar/helper/BufferUtil.java
@@ -71,4 +71,16 @@ public final class BufferUtil {
}
}
+ public static boolean isPrintable(ByteBuf buf, int length) {
+ boolean printable = true;
+ for (int i = 0; i < length; i++) {
+ byte b = buf.getByte(buf.readerIndex() + i);
+ if (b < 32 && b != '\r' && b != '\n') {
+ printable = false;
+ break;
+ }
+ }
+ return printable;
+ }
+
}
diff --git a/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java
index 383d4cb3a..e1bc2b5ad 100644
--- a/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java
@@ -20,6 +20,7 @@ import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
+import org.traccar.helper.BufferUtil;
import org.traccar.session.DeviceSession;
import org.traccar.NetworkMessage;
import org.traccar.Protocol;
@@ -1382,19 +1383,13 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
getLastLocation(position, null);
buf.readUnsignedByte(); // external device type code
- int length = buf.readableBytes() - 9; // line break + checksum + index + checksum + footer
- if (length <= 0) {
- return null;
- } else if (length < 8) {
- position.set(
- Position.PREFIX_TEMP + 1,
- Double.parseDouble(buf.readCharSequence(length - 1, StandardCharsets.US_ASCII).toString()));
+ ByteBuf data = buf.readSlice(buf.readableBytes() - 6); // index + checksum + footer
+ if (BufferUtil.isPrintable(data, data.readableBytes())) {
+ String value = data.readCharSequence(data.readableBytes(), StandardCharsets.US_ASCII).toString();
+ position.set(Position.KEY_RESULT, value.trim());
} else {
- buf.readUnsignedByte(); // card type
- position.set(
- Position.KEY_DRIVER_UNIQUE_ID,
- buf.readCharSequence(length - 1, StandardCharsets.US_ASCII).toString());
+ position.set(Position.KEY_RESULT, ByteBufUtil.hexDump(data));
}
return position;
diff --git a/src/main/java/org/traccar/protocol/TeltonikaProtocolDecoder.java b/src/main/java/org/traccar/protocol/TeltonikaProtocolDecoder.java
index c8e0005f9..e888642b4 100644
--- a/src/main/java/org/traccar/protocol/TeltonikaProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/TeltonikaProtocolDecoder.java
@@ -20,6 +20,7 @@ import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
+import org.traccar.helper.BufferUtil;
import org.traccar.model.Device;
import org.traccar.session.DeviceSession;
import org.traccar.NetworkMessage;
@@ -112,18 +113,6 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
}
}
- private boolean isPrintable(ByteBuf buf, int length) {
- boolean printable = true;
- for (int i = 0; i < length; i++) {
- byte b = buf.getByte(buf.readerIndex() + i);
- if (b < 32 && b != '\r' && b != '\n') {
- printable = false;
- break;
- }
- }
- return printable;
- }
-
private void decodeSerial(
Channel channel, SocketAddress remoteAddress, DeviceSession deviceSession, Position position, ByteBuf buf) {
@@ -169,7 +158,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_TYPE, type);
int length = buf.readInt();
- if (isPrintable(buf, length)) {
+ if (BufferUtil.isPrintable(buf, length)) {
String data = buf.readSlice(length).toString(StandardCharsets.US_ASCII).trim();
if (data.startsWith("UUUUww") && data.endsWith("SSS")) {
String[] values = data.substring(6, data.length() - 4).split(";");
@@ -636,7 +625,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
buf.readUnsignedByte(); // type
int length = buf.readInt() - 4;
getLastLocation(position, new Date(buf.readUnsignedInt() * 1000));
- if (isPrintable(buf, length)) {
+ if (BufferUtil.isPrintable(buf, length)) {
String data = buf.readCharSequence(length, StandardCharsets.US_ASCII).toString().trim();
if (data.startsWith("GTSL")) {
position.set(Position.KEY_DRIVER_UNIQUE_ID, data.split("\\|")[4]);
diff --git a/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java
index fac92d70f..26f300554 100644
--- a/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java
@@ -17,6 +17,10 @@ public class Gt06ProtocolDecoderTest extends ProtocolTest {
verifyNull(decoder, binary(
"78780D01086471700328358100093F040D0A"));
+ /*verifyAttribute(decoder, binary(
+ "797900109b0344373532304136320d0a000f87f00d0a"),
+ Position.KEY_DRIVER_UNIQUE_ID, "44373532304136320d0a");*/
+
verifyAttribute(decoder, binary(
"7878241617070a150e24ca01fba0040780e177005c0001720253360027db6204e40400004bf1e90d0a"),
Position.KEY_ALARM, Position.ALARM_SOS);
@@ -111,8 +115,9 @@ public class Gt06ProtocolDecoderTest extends ProtocolTest {
"7878281520000000003c49434349443a38393838323339303030303039373330323635303e00020d446f260d0a"),
Position.KEY_ICCID, "89882390000097302650");
- verifyNull(decoder, binary(
- "797900099b0380d600046f91e90d0a"));
+ verifyAttribute(decoder, binary(
+ "797900099b0380d600046f91e90d0a"),
+ Position.KEY_RESULT, "80d600");
verifyNull(decoder, binary(
"797900a56615010d081f3b012c323131303d30303033643238342c323130353d30303030316332302c323130623d30303030326537632c323130633d30303033643238342c323130663d30303030306331632c323130643d30303030323166632c323161363d30303030303030302c323130343d30303030306531302c323132663d30303030303030302c323134353d30303030303030302ccb03851f5f03c020525514a7003e216a0d0a"));
@@ -125,7 +130,7 @@ public class Gt06ProtocolDecoderTest extends ProtocolTest {
verifyAttribute(decoder, binary(
"7979000E9B0332382E33A1E60D0A0289BE490D0A"),
- Position.PREFIX_TEMP + 1, 28.3);
+ Position.KEY_RESULT, "32382e33a1e60d0a");
verifyPosition(decoder, binary(
"7878353714080d05000ac500a886eb0b7522f000100001fe0a05ea004f1b000001002e0400002328003b0217c0003c0401020001002c468a0d0a"));
@@ -168,7 +173,7 @@ public class Gt06ProtocolDecoderTest extends ProtocolTest {
verifyAttribute(decoder, binary(
"797900149b03023539303042343843454238410300139ba40d0a"),
- Position.KEY_DRIVER_UNIQUE_ID, "5900B48CEB");
+ Position.KEY_RESULT, "0235393030423438434542384103");
verifyPosition(decoder, binary(
"787821121303120b2524c70138e363085b549003d43301940057d200cd52c000006aa1ca0d0a"));