aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2020-06-28 16:58:20 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2020-06-28 16:58:20 -0700
commit2d876de908a24261310cb51071ff7644d84cb40e (patch)
tree4dcd1410a614ea10034ceb35048ebf60e496a008 /src/main
parent6c1ba89c82c0a07e6a33e4ea437953fbfc4dc1bd (diff)
downloadtrackermap-server-2d876de908a24261310cb51071ff7644d84cb40e.tar.gz
trackermap-server-2d876de908a24261310cb51071ff7644d84cb40e.tar.bz2
trackermap-server-2d876de908a24261310cb51071ff7644d84cb40e.zip
Support binary data
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/traccar/protocol/TeltonikaProtocolDecoder.java32
1 files changed, 20 insertions, 12 deletions
diff --git a/src/main/java/org/traccar/protocol/TeltonikaProtocolDecoder.java b/src/main/java/org/traccar/protocol/TeltonikaProtocolDecoder.java
index be7a01ee0..10cf1bee3 100644
--- a/src/main/java/org/traccar/protocol/TeltonikaProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/TeltonikaProtocolDecoder.java
@@ -103,6 +103,18 @@ 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, Position position, ByteBuf buf) {
getLastLocation(position, null);
@@ -148,16 +160,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_TYPE, type);
int length = buf.readInt();
- boolean readable = true;
- for (int i = 0; i < length; i++) {
- byte b = buf.getByte(buf.readerIndex() + i);
- if (b < 32 && b != '\r' && b != '\n') {
- readable = false;
- break;
- }
- }
-
- if (readable) {
+ if (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(";");
@@ -603,8 +606,13 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
buf.readUnsignedByte(); // type
int length = buf.readInt() - 4;
getLastLocation(position, new Date(buf.readUnsignedInt() * 1000));
- position.set(Position.KEY_RESULT,
- buf.readCharSequence(length, StandardCharsets.US_ASCII).toString().trim());
+ if (isPrintable(buf, length)) {
+ position.set(Position.KEY_RESULT,
+ buf.readCharSequence(length, StandardCharsets.US_ASCII).toString().trim());
+ } else {
+ position.set(Position.KEY_RESULT,
+ ByteBufUtil.hexDump(buf.readSlice(length)));
+ }
} else if (codec == CODEC_12) {
decodeSerial(channel, remoteAddress, position, buf);
} else {