aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/org/traccar/protocol/Gt02ProtocolDecoder.java46
-rw-r--r--test/org/traccar/protocol/Gt02ProtocolDecoderTest.java5
2 files changed, 23 insertions, 28 deletions
diff --git a/src/org/traccar/protocol/Gt02ProtocolDecoder.java b/src/org/traccar/protocol/Gt02ProtocolDecoder.java
index 81a04be0a..d15d999cf 100644
--- a/src/org/traccar/protocol/Gt02ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gt02ProtocolDecoder.java
@@ -32,18 +32,6 @@ public class Gt02ProtocolDecoder extends BaseProtocolDecoder {
super(protocol);
}
- private String readImei(ChannelBuffer buf) {
- int b = buf.readUnsignedByte();
- StringBuilder imei = new StringBuilder();
- imei.append(b & 0x0F);
- for (int i = 0; i < 7; i++) {
- b = buf.readUnsignedByte();
- imei.append((b & 0xF0) >> 4);
- imei.append(b & 0x0F);
- }
- return imei.toString();
- }
-
public static final int MSG_HEARTBEAT = 0x1A;
public static final int MSG_DATA = 0x10;
@@ -56,16 +44,30 @@ public class Gt02ProtocolDecoder extends BaseProtocolDecoder {
buf.skipBytes(2); // header
buf.readByte(); // size
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
+
// Zero for location messages
- buf.readByte(); // voltage
- buf.readByte(); // gsm signal
+ int power = buf.readUnsignedByte();
+ int gsm = buf.readUnsignedByte();
+
+ String imei = ChannelBuffers.hexDump(buf.readBytes(8)).substring(1);
+ if (!identify(imei, channel)) {
+ return null;
+ }
+ position.setDeviceId(getDeviceId());
+
+ position.set(Event.KEY_INDEX, buf.readUnsignedShort());
- String imei = readImei(buf);
- long index = buf.readUnsignedShort();
int type = buf.readUnsignedByte();
if (type == MSG_HEARTBEAT) {
+ getLastLocation(position, null);
+
+ position.set(Event.KEY_POWER, power);
+ position.set(Event.KEY_GSM, gsm);
+
if (channel != null) {
byte[] response = {0x54, 0x68, 0x1A, 0x0D, 0x0A};
channel.write(ChannelBuffers.wrappedBuffer(response));
@@ -73,15 +75,6 @@ public class Gt02ProtocolDecoder extends BaseProtocolDecoder {
} else if (type == MSG_DATA) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.set(Event.KEY_INDEX, index);
-
- if (!identify(imei, channel)) {
- return null;
- }
- position.setDeviceId(getDeviceId());
-
DateBuilder dateBuilder = new DateBuilder()
.setDate(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte())
.setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
@@ -107,10 +100,9 @@ public class Gt02ProtocolDecoder extends BaseProtocolDecoder {
position.setLatitude(latitude);
position.setLongitude(longitude);
- return position;
}
- return null;
+ return position;
}
}
diff --git a/test/org/traccar/protocol/Gt02ProtocolDecoderTest.java b/test/org/traccar/protocol/Gt02ProtocolDecoderTest.java
index 4f086d4f3..052187c1d 100644
--- a/test/org/traccar/protocol/Gt02ProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/Gt02ProtocolDecoderTest.java
@@ -10,11 +10,14 @@ public class Gt02ProtocolDecoderTest extends ProtocolDecoderTest {
Gt02ProtocolDecoder decoder = new Gt02ProtocolDecoder(new Gt02Protocol());
+ verifyAttributes(decoder, binary(
+ "68681a060303588990500037252de91a010a171a191b171915191e10000d0a"));
+
verifyPosition(decoder, binary(
"68682500000123456789012345000110010101010101026B3F3E026B3F3E000000000000000000010D0A"),
position("2001-01-01 01:01:01.000", true, -22.54610, -22.54610));
- verifyNothing(decoder, binary(
+ verifyAttributes(decoder, binary(
"6868110603035889905101276600001a0402292d0d0a"));
verifyPosition(decoder, binary(