diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2017-06-26 20:04:05 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2017-06-26 20:04:05 +1200 |
commit | 8d31a6b136c792b181822d84cbb854c15e15f482 (patch) | |
tree | 884174b4302dccea03a653802b5ac2dca6acdc6d | |
parent | 71a9d9f6df3bc0ef17bcb834487838b94d989a74 (diff) | |
download | trackermap-server-8d31a6b136c792b181822d84cbb854c15e15f482.tar.gz trackermap-server-8d31a6b136c792b181822d84cbb854c15e15f482.tar.bz2 trackermap-server-8d31a6b136c792b181822d84cbb854c15e15f482.zip |
Support X1 GT06 variant
-rw-r--r-- | src/org/traccar/protocol/Gt06ProtocolDecoder.java | 41 | ||||
-rw-r--r-- | test/org/traccar/protocol/Gt06ProtocolDecoderTest.java | 12 |
2 files changed, 50 insertions, 3 deletions
diff --git a/src/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/org/traccar/protocol/Gt06ProtocolDecoder.java index 261278539..64365aee0 100644 --- a/src/org/traccar/protocol/Gt06ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gt06ProtocolDecoder.java @@ -66,6 +66,9 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { public static final int MSG_LBS_STATUS = 0x19; public static final int MSG_GPS_PHONE = 0x1A; public static final int MSG_GPS_LBS_EXTEND = 0x1E; + public static final int MSG_X1_GPS = 0x34; + public static final int MSG_X1_PHOTO_INFO = 0x35; + public static final int MSG_X1_PHOTO_DATA = 0x36; public static final int MSG_COMMAND_0 = 0x80; public static final int MSG_COMMAND_1 = 0x81; public static final int MSG_COMMAND_2 = 0x82; @@ -138,7 +141,9 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_IGNITION, BitUtil.check(flags, 15)); } - buf.skipBytes(length - 12); // skip reserved + if (length > 0) { + buf.skipBytes(length - 12); // skip reserved + } } private void decodeLbs(Position position, ChannelBuffer buf, boolean hasLength) { @@ -266,7 +271,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { return position; } - protected Object decodeBasic(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) throws Exception { + private Object decodeBasic(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) throws Exception { int length = buf.readUnsignedByte(); int dataLength = length - 5; @@ -296,6 +301,36 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { sendResponse(channel, type, buf.readUnsignedShort()); } + } else if (type == MSG_X1_GPS) { + + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress); + if (deviceSession == null) { + return null; + } + + Position position = new Position(); + position.setDeviceId(deviceSession.getDeviceId()); + position.setProtocol(getProtocolName()); + + buf.readUnsignedInt(); // data and alarm + + decodeGps(position, buf); + + buf.readUnsignedShort(); // terminal info + + position.set(Position.KEY_ODOMETER, buf.readUnsignedInt()); + + position.setNetwork(new Network(CellTower.from( + buf.readUnsignedShort(), buf.readUnsignedByte(), + buf.readUnsignedShort(), buf.readUnsignedInt()))); + + if (buf.readableBytes() > 6) { + buf.skipBytes(buf.readableBytes() - 6); + } + sendResponse(channel, type, buf.readUnsignedShort()); + + return position; + } else { DeviceSession deviceSession = getDeviceSession(channel, remoteAddress); @@ -379,7 +414,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { return null; } - protected Object decodeExtended(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) throws Exception { + private Object decodeExtended(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) throws Exception { DeviceSession deviceSession = getDeviceSession(channel, remoteAddress); if (deviceSession == null) { diff --git a/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java b/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java index 188282bd6..77214557e 100644 --- a/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java @@ -16,6 +16,18 @@ public class Gt06ProtocolDecoderTest extends ProtocolTest { verifyNull(decoder, binary( "78780D01086471700328358100093F040D0A")); + verifyNull(decoder, binary( + "787811010863586038760942a0010000010aa4000d0a")); + + verifyPosition(decoder, binary( + "78783c340000000011061809130c0903107d2408488a5800144c00000000000001940b00b1000047ff000000000500018f42210000000100050003010b69450d0a")); + + verifyPosition(decoder, binary( + "78783c34000000001106190336070903107d51084889b900152e0000000043b101940b00b10000480100000000050001a3422100000001000300011bdc7b5f0d0a")); + + verifyAttributes(decoder, binary( + "78780a13c40604000201298f5b0d0a")); + verifyNotNull(decoder, binary( "78781f12110616091835d0024bb93007d3fb783dd4c501940500f2006c8504a6e0370d0a")); |