aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-06-15 22:53:56 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2016-06-15 22:53:56 +1200
commitd003da04e27f81959308ac80de8bf597b53bd537 (patch)
tree812921c6234cdc89bf54dd6f62c1fbaa5342b3a5
parent5ef8e9c97ca8adb42f8aedc99550de98e76bf6cf (diff)
downloadtraccar-server-d003da04e27f81959308ac80de8bf597b53bd537.tar.gz
traccar-server-d003da04e27f81959308ac80de8bf597b53bd537.tar.bz2
traccar-server-d003da04e27f81959308ac80de8bf597b53bd537.zip
Support new GT06 protocol message
-rw-r--r--src/org/traccar/protocol/Gt06ProtocolDecoder.java165
-rw-r--r--test/org/traccar/protocol/Gt06ProtocolDecoderTest.java3
2 files changed, 101 insertions, 67 deletions
diff --git a/src/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/org/traccar/protocol/Gt06ProtocolDecoder.java
index e9799c1b0..00444b61b 100644
--- a/src/org/traccar/protocol/Gt06ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gt06ProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -63,6 +63,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
public static final int MSG_COMMAND_0 = 0x80;
public static final int MSG_COMMAND_1 = 0x81;
public static final int MSG_COMMAND_2 = 0x82;
+ public static final int MSG_INFO = 0x94;
private static boolean isSupported(int type) {
return hasGps(type) || hasLbs(type) || hasStatus(type);
@@ -168,102 +169,132 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
ChannelBuffer buf = (ChannelBuffer) msg;
- if (buf.readByte() != 0x78 || buf.readByte() != 0x78) {
- return null;
- }
+ int header = buf.readShort();
+
+ if (header == 0x7878) {
- int length = buf.readUnsignedByte(); // size
- int dataLength = length - 5;
+ int length = buf.readUnsignedByte();
+ int dataLength = length - 5;
- int type = buf.readUnsignedByte();
+ int type = buf.readUnsignedByte();
- if (type == MSG_LOGIN) {
+ if (type == MSG_LOGIN) {
- String imei = ChannelBuffers.hexDump(buf.readBytes(8)).substring(1);
- buf.readUnsignedShort(); // type
+ String imei = ChannelBuffers.hexDump(buf.readBytes(8)).substring(1);
+ buf.readUnsignedShort(); // type
- // Timezone offset
- if (dataLength > 10) {
- int extensionBits = buf.readUnsignedShort();
- int hours = (extensionBits >> 4) / 100;
- int minutes = (extensionBits >> 4) % 100;
- int offset = (hours * 60 + minutes) * 60;
- if ((extensionBits & 0x8) != 0) {
- offset = -offset;
+ // Timezone offset
+ if (dataLength > 10) {
+ int extensionBits = buf.readUnsignedShort();
+ int hours = (extensionBits >> 4) / 100;
+ int minutes = (extensionBits >> 4) % 100;
+ int offset = (hours * 60 + minutes) * 60;
+ if ((extensionBits & 0x8) != 0) {
+ offset = -offset;
+ }
+ if (!forceTimeZone) {
+ timeZone.setRawOffset(offset * 1000);
+ }
}
- if (!forceTimeZone) {
- timeZone.setRawOffset(offset * 1000);
+
+ if (identify(imei, channel, remoteAddress)) {
+ buf.skipBytes(buf.readableBytes() - 6);
+ sendResponse(channel, type, buf.readUnsignedShort());
}
- }
- if (identify(imei, channel, remoteAddress)) {
- buf.skipBytes(buf.readableBytes() - 6);
- sendResponse(channel, type, buf.readUnsignedShort());
- }
+ } else if (hasDeviceId()) {
+
+ if (type == MSG_STRING) {
- } else if (hasDeviceId()) {
+ Position position = new Position();
+ position.setDeviceId(getDeviceId());
+ position.setProtocol(getProtocolName());
- if (type == MSG_STRING) {
+ getLastLocation(position, null);
- Position position = new Position();
- position.setDeviceId(getDeviceId());
- position.setProtocol(getProtocolName());
+ int commandLength = buf.readUnsignedByte();
- getLastLocation(position, null);
+ if (commandLength > 0) {
+ buf.readUnsignedByte(); // server flag (reserved)
+ position.set("command", buf.readBytes(commandLength - 1).toString(StandardCharsets.US_ASCII));
+ }
- int commandLength = buf.readUnsignedByte();
+ buf.readUnsignedShort(); // language
- if (commandLength > 0) {
- buf.readUnsignedByte(); // server flag (reserved)
- position.set("command", buf.readBytes(commandLength - 1).toString(StandardCharsets.US_ASCII));
- }
+ sendResponse(channel, type, buf.readUnsignedShort());
+
+ return position;
- buf.readUnsignedShort(); // language
+ } else if (isSupported(type)) {
- sendResponse(channel, type, buf.readUnsignedShort());
+ Position position = new Position();
+ position.setDeviceId(getDeviceId());
+ position.setProtocol(getProtocolName());
- return position;
+ if (hasGps(type)) {
+ decodeGps(position, buf);
+ } else {
+ getLastLocation(position, null);
+ }
- } else if (isSupported(type)) {
+ if (hasLbs(type)) {
+ decodeLbs(position, buf, hasStatus(type));
+ }
- Position position = new Position();
- position.setDeviceId(getDeviceId());
- position.setProtocol(getProtocolName());
+ if (hasStatus(type)) {
+ decodeStatus(position, buf);
+ }
+
+ if (type == MSG_GPS_LBS_1 && buf.readableBytes() == 4 + 6) {
+ position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
+ }
+
+ if (buf.readableBytes() > 6) {
+ buf.skipBytes(buf.readableBytes() - 6);
+ }
+ int index = buf.readUnsignedShort();
+ position.set(Position.KEY_INDEX, index);
+ sendResponse(channel, type, index);
+
+ return position;
- if (hasGps(type)) {
- decodeGps(position, buf);
} else {
- getLastLocation(position, null);
- }
- if (hasLbs(type)) {
- decodeLbs(position, buf, hasStatus(type));
- }
+ buf.skipBytes(dataLength);
+ if (type != MSG_COMMAND_0 && type != MSG_COMMAND_1 && type != MSG_COMMAND_2) {
+ sendResponse(channel, type, buf.readUnsignedShort());
+ }
- if (hasStatus(type)) {
- decodeStatus(position, buf);
}
- if (type == MSG_GPS_LBS_1 && buf.readableBytes() == 4 + 6) {
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
- }
+ }
- if (buf.readableBytes() > 6) {
- buf.skipBytes(buf.readableBytes() - 6);
- }
- int index = buf.readUnsignedShort();
- position.set(Position.KEY_INDEX, index);
- sendResponse(channel, type, index);
+ } else if (header == 0x7979) {
- return position;
+ int length = buf.readUnsignedShort();
+ int dataLength = length - 6;
- } else {
+ int type = buf.readUnsignedByte();
- buf.skipBytes(dataLength);
- if (type != MSG_COMMAND_0 && type != MSG_COMMAND_1 && type != MSG_COMMAND_2) {
- sendResponse(channel, type, buf.readUnsignedShort());
- }
+ if (type == MSG_INFO) {
+ int subType = buf.readUnsignedByte();
+ if (subType == 0x05) {
+
+ Position position = new Position();
+ position.setDeviceId(getDeviceId());
+ position.setProtocol(getProtocolName());
+
+ getLastLocation(position, null);
+
+ int flags = buf.readUnsignedByte();
+
+ position.set("door", BitUtil.check(flags, 0));
+ position.set(Position.PREFIX_IO + 1, BitUtil.check(flags, 2));
+
+ return position;
+
+ }
}
}
diff --git a/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java b/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java
index 46ee223ad..81f9f81c3 100644
--- a/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java
@@ -16,6 +16,9 @@ public class Gt06ProtocolDecoderTest extends ProtocolTest {
verifyNothing(decoder, binary(
"78780D01086471700328358100093F040D0A"));
+ verifyAttributes(decoder, binary(
+ "7979000794050000c9b63e0d0a"));
+
verifyNotNull(decoder, binary(
"787866150000000000416c726561647920696e20746865207374617465206f66206675656c20737570706c7920746f20726573756d652c74686520636f6d6d616e64206973206e6f742072756e6e696e672100000000000000000000000000000000000001001981e50d0a"));