aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/protocol/T800xProtocolEncoder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2019-08-11 10:59:06 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2019-08-11 10:59:06 -0700
commit34588a82377708f8664427cae0bd4dea8a582764 (patch)
tree16b97e587c28d091d7ac3de1c084b1d15ebb4d8d /src/main/java/org/traccar/protocol/T800xProtocolEncoder.java
parentb1d7e4d00072e8293051d502311a5f826eb95287 (diff)
downloadtrackermap-server-34588a82377708f8664427cae0bd4dea8a582764.tar.gz
trackermap-server-34588a82377708f8664427cae0bd4dea8a582764.tar.bz2
trackermap-server-34588a82377708f8664427cae0bd4dea8a582764.zip
Use correct header
Diffstat (limited to 'src/main/java/org/traccar/protocol/T800xProtocolEncoder.java')
-rw-r--r--src/main/java/org/traccar/protocol/T800xProtocolEncoder.java15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/main/java/org/traccar/protocol/T800xProtocolEncoder.java b/src/main/java/org/traccar/protocol/T800xProtocolEncoder.java
index 439bedb57..74587c8b1 100644
--- a/src/main/java/org/traccar/protocol/T800xProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/T800xProtocolEncoder.java
@@ -17,6 +17,7 @@ package org.traccar.protocol;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
+import io.netty.channel.Channel;
import org.traccar.BaseProtocolEncoder;
import org.traccar.helper.DataConverter;
import org.traccar.model.Command;
@@ -34,12 +35,11 @@ public class T800xProtocolEncoder extends BaseProtocolEncoder {
super(protocol);
}
- private ByteBuf encodeContent(Command command, String content) {
+ private ByteBuf encodeContent(Command command, short header, String content) {
ByteBuf buf = Unpooled.buffer();
- buf.writeByte('%');
- buf.writeByte('%');
+ buf.writeShort(header);
buf.writeByte(T800xProtocolDecoder.MSG_COMMAND);
buf.writeShort(7 + 8 + 1 + content.length());
buf.writeShort(1); // serial number
@@ -51,11 +51,16 @@ public class T800xProtocolEncoder extends BaseProtocolEncoder {
}
@Override
- protected Object encodeCommand(Command command) {
+ protected Object encodeCommand(Channel channel, Command command) {
+
+ short header = T800xProtocolDecoder.DEFAULT_HEADER;
+ if (channel != null) {
+ header = channel.pipeline().get(T800xProtocolDecoder.class).getHeader();
+ }
switch (command.getType()) {
case Command.TYPE_CUSTOM:
- return encodeContent(command, command.getString(Command.KEY_DATA));
+ return encodeContent(command, header, command.getString(Command.KEY_DATA));
default:
return null;
}