aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/protocol
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
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')
-rw-r--r--src/main/java/org/traccar/protocol/T800xProtocolDecoder.java14
-rw-r--r--src/main/java/org/traccar/protocol/T800xProtocolEncoder.java15
2 files changed, 21 insertions, 8 deletions
diff --git a/src/main/java/org/traccar/protocol/T800xProtocolDecoder.java b/src/main/java/org/traccar/protocol/T800xProtocolDecoder.java
index 5c2c26da7..4351a14bf 100644
--- a/src/main/java/org/traccar/protocol/T800xProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/T800xProtocolDecoder.java
@@ -37,10 +37,18 @@ import java.util.Date;
public class T800xProtocolDecoder extends BaseProtocolDecoder {
+ private short header = DEFAULT_HEADER;
+
+ public short getHeader() {
+ return header;
+ }
+
public T800xProtocolDecoder(Protocol protocol) {
super(protocol);
}
+ public static final short DEFAULT_HEADER = 0x2323;
+
public static final int MSG_LOGIN = 0x01;
public static final int MSG_GPS = 0x02;
public static final int MSG_HEARTBEAT = 0x03;
@@ -110,7 +118,7 @@ public class T800xProtocolDecoder extends BaseProtocolDecoder {
ByteBuf buf = (ByteBuf) msg;
- short header = buf.readShort();
+ header = buf.readShort();
int type = buf.readUnsignedByte();
buf.readUnsignedShort(); // length
int index = buf.readUnsignedShort();
@@ -128,7 +136,7 @@ public class T800xProtocolDecoder extends BaseProtocolDecoder {
if (type == MSG_GPS || type == MSG_ALARM) {
- return decodePosition(channel, deviceSession, buf, header, type, index, imei);
+ return decodePosition(channel, deviceSession, buf, type, index, imei);
} else if (type == MSG_NETWORK) {
@@ -169,7 +177,7 @@ public class T800xProtocolDecoder extends BaseProtocolDecoder {
private Position decodePosition(
Channel channel, DeviceSession deviceSession,
- ByteBuf buf, short header, int type, int index, ByteBuf imei) {
+ ByteBuf buf, int type, int index, ByteBuf imei) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
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;
}