aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2019-05-12 19:23:04 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2019-05-12 19:23:04 -0700
commitb607711e6471cc6018c5bbb20a1df7c399bfb878 (patch)
tree035143f805fbc3b9944572dfaafcb7a019c04a20 /src/main/java
parentad6fef91db91140a59cce596a429c0ae7b95eb2d (diff)
downloadtrackermap-server-b607711e6471cc6018c5bbb20a1df7c399bfb878.tar.gz
trackermap-server-b607711e6471cc6018c5bbb20a1df7c399bfb878.tar.bz2
trackermap-server-b607711e6471cc6018c5bbb20a1df7c399bfb878.zip
Support binary custom command
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/traccar/protocol/TeltonikaProtocolEncoder.java25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/main/java/org/traccar/protocol/TeltonikaProtocolEncoder.java b/src/main/java/org/traccar/protocol/TeltonikaProtocolEncoder.java
index 944cec024..705d01d07 100644
--- a/src/main/java/org/traccar/protocol/TeltonikaProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/TeltonikaProtocolEncoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 - 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2019 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.
@@ -17,6 +17,7 @@ package org.traccar.protocol;
import org.traccar.BaseProtocolEncoder;
import org.traccar.helper.Checksum;
+import org.traccar.helper.DataConverter;
import org.traccar.model.Command;
import io.netty.buffer.ByteBuf;
@@ -26,17 +27,17 @@ import java.nio.charset.StandardCharsets;
public class TeltonikaProtocolEncoder extends BaseProtocolEncoder {
- private ByteBuf encodeContent(String content) {
+ private ByteBuf encodeContent(byte[] content) {
ByteBuf buf = Unpooled.buffer();
buf.writeInt(0);
- buf.writeInt(content.length() + 10);
+ buf.writeInt(content.length + 10);
buf.writeByte(TeltonikaProtocolDecoder.CODEC_12);
buf.writeByte(1); // quantity
buf.writeByte(5); // type
- buf.writeInt(content.length() + 2);
- buf.writeBytes(content.getBytes(StandardCharsets.US_ASCII));
+ buf.writeInt(content.length + 2);
+ buf.writeBytes(content);
buf.writeByte('\r');
buf.writeByte('\n');
buf.writeByte(1); // quantity
@@ -48,11 +49,15 @@ public class TeltonikaProtocolEncoder extends BaseProtocolEncoder {
@Override
protected Object encodeCommand(Command command) {
- switch (command.getType()) {
- case Command.TYPE_CUSTOM:
- return encodeContent(command.getString(Command.KEY_DATA));
- default:
- return null;
+ if (command.getType().equals(Command.TYPE_CUSTOM)) {
+ String data = command.getString(Command.KEY_DATA);
+ if (data.matches("(\\p{XDigit}{2})+")) {
+ return encodeContent(DataConverter.parseHex(data));
+ } else {
+ return encodeContent(data.getBytes(StandardCharsets.US_ASCII));
+ }
+ } else {
+ return null;
}
}