diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-11-15 10:09:54 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-11-15 10:09:54 +1300 |
commit | a79893a68065f4fd1eb684c9df1c346cd7841a83 (patch) | |
tree | b453918cc63d0586d3e3f8f1e4f4a42ed4189e6d /src/org/traccar/protocol | |
parent | 132e70273ec3ad4b193f759dda8e3a7420bbbeab (diff) | |
download | traccar-server-a79893a68065f4fd1eb684c9df1c346cd7841a83.tar.gz traccar-server-a79893a68065f4fd1eb684c9df1c346cd7841a83.tar.bz2 traccar-server-a79893a68065f4fd1eb684c9df1c346cd7841a83.zip |
Support for GT02 heartbeat messages
Diffstat (limited to 'src/org/traccar/protocol')
-rw-r--r-- | src/org/traccar/protocol/Gt02ProtocolDecoder.java | 46 |
1 files changed, 19 insertions, 27 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; } } |