aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2019-04-10 19:19:18 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2019-04-10 19:19:18 -0700
commita21526cfa9e204715cfc41966dc95584d6e30168 (patch)
treed16427e5feeea9680b5b565b0288827b064bc346 /src
parentd701e4cd549e99c594a7ddf41359b59f34ad2cff (diff)
downloadtraccar-server-a21526cfa9e204715cfc41966dc95584d6e30168.tar.gz
traccar-server-a21526cfa9e204715cfc41966dc95584d6e30168.tar.bz2
traccar-server-a21526cfa9e204715cfc41966dc95584d6e30168.zip
Support command response
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/traccar/protocol/T800xProtocolDecoder.java160
-rw-r--r--src/main/java/org/traccar/protocol/T800xProtocolEncoder.java4
-rw-r--r--src/test/java/org/traccar/protocol/T800xProtocolDecoderTest.java5
-rw-r--r--src/test/java/org/traccar/protocol/T800xProtocolEncoderTest.java2
4 files changed, 99 insertions, 72 deletions
diff --git a/src/main/java/org/traccar/protocol/T800xProtocolDecoder.java b/src/main/java/org/traccar/protocol/T800xProtocolDecoder.java
index fc7b88b08..28fd7937d 100644
--- a/src/main/java/org/traccar/protocol/T800xProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/T800xProtocolDecoder.java
@@ -32,6 +32,7 @@ import org.traccar.model.Network;
import org.traccar.model.Position;
import java.net.SocketAddress;
+import java.nio.charset.StandardCharsets;
public class T800xProtocolDecoder extends BaseProtocolDecoder {
@@ -101,7 +102,6 @@ public class T800xProtocolDecoder extends BaseProtocolDecoder {
buf.readUnsignedShort(); // length
int index = buf.readUnsignedShort();
ByteBuf imei = buf.readSlice(8);
- int alarm = 0;
DeviceSession deviceSession = getDeviceSession(
channel, remoteAddress, ByteBufUtil.hexDump(imei).substring(1));
@@ -111,96 +111,118 @@ public class T800xProtocolDecoder extends BaseProtocolDecoder {
if (type == MSG_GPS || type == MSG_ALARM) {
+ return decodePosition(channel, deviceSession, buf, header, type, index, imei);
+
+ } else if (type == MSG_COMMAND) {
+
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
- position.set(Position.KEY_INDEX, index);
+ getLastLocation(position, null);
+
+ buf.readUnsignedByte(); // protocol number
- buf.readUnsignedShort(); // acc on interval
- buf.readUnsignedShort(); // acc off interval
- buf.readUnsignedByte(); // angle compensation
- buf.readUnsignedShort(); // distance compensation
+ position.set(Position.KEY_RESULT, buf.toString(StandardCharsets.UTF_16LE));
- position.set(Position.KEY_RSSI, BitUtil.to(buf.readUnsignedShort(), 7));
+ sendResponse(channel, header, type, index, imei, 0);
- int status = buf.readUnsignedByte();
- position.set(Position.KEY_SATELLITES, BitUtil.to(status, 5));
+ return position;
- buf.readUnsignedByte(); // gsensor manager status
- buf.readUnsignedByte(); // other flags
- buf.readUnsignedByte(); // heartbeat
- buf.readUnsignedByte(); // relay status
- buf.readUnsignedShort(); // drag alarm setting
+ }
- int io = buf.readUnsignedShort();
- position.set(Position.KEY_IGNITION, BitUtil.check(io, 14));
- position.set("ac", BitUtil.check(io, 13));
+ sendResponse(channel, header, type, index, imei, 0);
- position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort());
- position.set(Position.PREFIX_ADC + 2, buf.readUnsignedShort());
+ return null;
+ }
- alarm = buf.readUnsignedByte();
- position.set(Position.KEY_ALARM, decodeAlarm(alarm));
+ private Position decodePosition(
+ Channel channel, DeviceSession deviceSession,
+ ByteBuf buf, short header, int type, int index, ByteBuf imei) {
- buf.readUnsignedByte(); // reserved
+ Position position = new Position(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
+ position.set(Position.KEY_INDEX, index);
- int battery = BcdUtil.readInteger(buf, 2);
- if (battery == 0) {
- battery = 100;
- }
- position.set(Position.KEY_BATTERY, battery);
-
- DateBuilder dateBuilder = new DateBuilder()
- .setYear(BcdUtil.readInteger(buf, 2))
- .setMonth(BcdUtil.readInteger(buf, 2))
- .setDay(BcdUtil.readInteger(buf, 2))
- .setHour(BcdUtil.readInteger(buf, 2))
- .setMinute(BcdUtil.readInteger(buf, 2))
- .setSecond(BcdUtil.readInteger(buf, 2));
-
- if (BitUtil.check(status, 6)) {
-
- position.setValid(!BitUtil.check(status, 7));
- position.setTime(dateBuilder.getDate());
- position.setAltitude(buf.readFloatLE());
- position.setLongitude(buf.readFloatLE());
- position.setLatitude(buf.readFloatLE());
- position.setSpeed(UnitsConverter.knotsFromKph(BcdUtil.readInteger(buf, 4) * 0.1));
- position.setCourse(buf.readUnsignedShort());
-
- } else {
-
- getLastLocation(position, dateBuilder.getDate());
-
- int mcc = buf.readUnsignedShortLE();
- int mnc = buf.readUnsignedShortLE();
-
- if (mcc != 0xffff && mnc != 0xffff) {
- Network network = new Network();
- for (int i = 0; i < 3; i++) {
- network.addCellTower(CellTower.from(
- mcc, mnc, buf.readUnsignedShortLE(), buf.readUnsignedShortLE()));
- }
- position.setNetwork(network);
- }
+ buf.readUnsignedShort(); // acc on interval
+ buf.readUnsignedShort(); // acc off interval
+ buf.readUnsignedByte(); // angle compensation
+ buf.readUnsignedShort(); // distance compensation
- }
+ position.set(Position.KEY_RSSI, BitUtil.to(buf.readUnsignedShort(), 7));
- if (buf.readableBytes() >= 2) {
- position.set(Position.KEY_POWER, BcdUtil.readInteger(buf, 4) * 0.01);
- }
+ int status = buf.readUnsignedByte();
+ position.set(Position.KEY_SATELLITES, BitUtil.to(status, 5));
- sendResponse(channel, header, type, index, imei, alarm);
+ buf.readUnsignedByte(); // gsensor manager status
+ buf.readUnsignedByte(); // other flags
+ buf.readUnsignedByte(); // heartbeat
+ buf.readUnsignedByte(); // relay status
+ buf.readUnsignedShort(); // drag alarm setting
- return position;
+ int io = buf.readUnsignedShort();
+ position.set(Position.KEY_IGNITION, BitUtil.check(io, 14));
+ position.set("ac", BitUtil.check(io, 13));
+ position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort());
+ position.set(Position.PREFIX_ADC + 2, buf.readUnsignedShort());
+
+ int alarm = buf.readUnsignedByte();
+ position.set(Position.KEY_ALARM, decodeAlarm(alarm));
+
+ buf.readUnsignedByte(); // reserved
+
+ position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
+
+ int battery = BcdUtil.readInteger(buf, 2);
+ if (battery == 0) {
+ battery = 100;
+ }
+ position.set(Position.KEY_BATTERY, battery);
+
+ DateBuilder dateBuilder = new DateBuilder()
+ .setYear(BcdUtil.readInteger(buf, 2))
+ .setMonth(BcdUtil.readInteger(buf, 2))
+ .setDay(BcdUtil.readInteger(buf, 2))
+ .setHour(BcdUtil.readInteger(buf, 2))
+ .setMinute(BcdUtil.readInteger(buf, 2))
+ .setSecond(BcdUtil.readInteger(buf, 2));
+
+ if (BitUtil.check(status, 6)) {
+
+ position.setValid(!BitUtil.check(status, 7));
+ position.setTime(dateBuilder.getDate());
+ position.setAltitude(buf.readFloatLE());
+ position.setLongitude(buf.readFloatLE());
+ position.setLatitude(buf.readFloatLE());
+ position.setSpeed(UnitsConverter.knotsFromKph(BcdUtil.readInteger(buf, 4) * 0.1));
+ position.setCourse(buf.readUnsignedShort());
+
+ } else {
+
+ getLastLocation(position, dateBuilder.getDate());
+
+ int mcc = buf.readUnsignedShortLE();
+ int mnc = buf.readUnsignedShortLE();
+
+ if (mcc != 0xffff && mnc != 0xffff) {
+ Network network = new Network();
+ for (int i = 0; i < 3; i++) {
+ network.addCellTower(CellTower.from(
+ mcc, mnc, buf.readUnsignedShortLE(), buf.readUnsignedShortLE()));
+ }
+ position.setNetwork(network);
+ }
+
+ }
+
+ if (buf.readableBytes() >= 2) {
+ position.set(Position.KEY_POWER, BcdUtil.readInteger(buf, 4) * 0.01);
}
sendResponse(channel, header, type, index, imei, alarm);
- return null;
+ return position;
}
}
diff --git a/src/main/java/org/traccar/protocol/T800xProtocolEncoder.java b/src/main/java/org/traccar/protocol/T800xProtocolEncoder.java
index 1d0f3dabe..34f30b147 100644
--- a/src/main/java/org/traccar/protocol/T800xProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/T800xProtocolEncoder.java
@@ -33,8 +33,8 @@ public class T800xProtocolEncoder extends BaseProtocolEncoder {
ByteBuf buf = Unpooled.buffer();
- buf.writeByte('#');
- buf.writeByte('#');
+ buf.writeByte('%');
+ buf.writeByte('%');
buf.writeByte(T800xProtocolDecoder.MSG_COMMAND);
buf.writeShort(7 + 8 + 1 + content.length());
buf.writeShort(1); // serial number
diff --git a/src/test/java/org/traccar/protocol/T800xProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/T800xProtocolDecoderTest.java
index fe77d91b7..bfe06b5cd 100644
--- a/src/test/java/org/traccar/protocol/T800xProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/T800xProtocolDecoderTest.java
@@ -2,6 +2,7 @@ package org.traccar.protocol;
import org.junit.Test;
import org.traccar.ProtocolTest;
+import org.traccar.model.Position;
public class T800xProtocolDecoderTest extends ProtocolTest {
@@ -13,6 +14,10 @@ public class T800xProtocolDecoderTest extends ProtocolTest {
verifyNull(decoder, binary(
"252501001504050880061689888888111111250350"));
+ verifyAttribute(decoder, binary(
+ "2525810128000108664250328959160149004d00450049003a003800360036003400320035003000330032003800390035003900310036002c005300450054002000560045005200530049004f004e0020004f004b002c00560065007200730069006f006e003a00420061007300690063003a00560031002e0030002e0030002c004100500050003a00560034002e0032002e0033002c004200550049004c0044003a0032003000310039002d00300033002d00330030002c00300038003a00300035002c0050004c0054003a0032003500300033004100560045002c00480057003a00560032002e0031002c004d004f00440045004c003a002c004d004f00440045004d003a0042003900470036004d0041005200300032004100300037004d00310047002300"),
+ Position.KEY_RESULT, "IMEI:866425032895916,SET VERSION OK,Version:Basic:V1.0.0,APP:V4.2.3,BUILD:2019-03-30,08:05,PLT:2503AVE,HW:V2.1,MODEL:,MODEM:B9G6MAR02A07M1G#");
+
verifyPosition(decoder, binary(
"2525020044a66d0862522030401350001403841409c40064edc000051100960000071701370000003ea7ee0019032010581300000000aad3e1bda6f24d42000000001281"));
diff --git a/src/test/java/org/traccar/protocol/T800xProtocolEncoderTest.java b/src/test/java/org/traccar/protocol/T800xProtocolEncoderTest.java
index af3700225..e41b91281 100644
--- a/src/test/java/org/traccar/protocol/T800xProtocolEncoderTest.java
+++ b/src/test/java/org/traccar/protocol/T800xProtocolEncoderTest.java
@@ -16,7 +16,7 @@ public class T800xProtocolEncoderTest extends ProtocolTest {
command.setType(Command.TYPE_CUSTOM);
command.set(Command.KEY_DATA, "RELAY,0000,On#");
- verifyCommand(encoder, command, binary("232381001e000101234567890123450152454c41592c303030302c4f6e23"));
+ verifyCommand(encoder, command, binary("252581001e000101234567890123450152454c41592c303030302c4f6e23"));
}