From d7adccdfe7f355f8ab62805663df68a706f15d0c Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 19 Jan 2013 13:24:54 +1300 Subject: Add GT07 support --- src/org/traccar/protocol/Gt06ProtocolDecoder.java | 83 ++++++++++++++++------- 1 file changed, 60 insertions(+), 23 deletions(-) (limited to 'src/org') diff --git a/src/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/org/traccar/protocol/Gt06ProtocolDecoder.java index a3306dc97..93f2eee42 100644 --- a/src/org/traccar/protocol/Gt06ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gt06ProtocolDecoder.java @@ -15,6 +15,7 @@ */ package org.traccar.protocol; +import java.nio.charset.Charset; import java.util.Calendar; import java.util.TimeZone; import org.jboss.netty.buffer.ChannelBuffer; @@ -54,10 +55,12 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { } private static final int MSG_LOGIN = 0x01; - private static final int MSG_DATA = 0x12; - private static final int MSG_HEARTBEAT = 0x13; + private static final int MSG_GPS = 0x10; + private static final int MSG_LBS = 0x11; + private static final int MSG_GPS_LBS = 0x12; + private static final int MSG_STATUS = 0x13; private static final int MSG_STRING = 0x15; - private static final int MSG_ALARM = 0x16; + private static final int MSG_GPS_LBS_STATUS = 0x16; private static void sendResponse(Channel channel, int type, int index) { if (channel != null) { @@ -83,7 +86,8 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { ChannelBuffer buf = (ChannelBuffer) msg; buf.skipBytes(2); // header - buf.readByte(); // size + int length = buf.readByte(); // size + int dataLength = length - 5; int type = buf.readUnsignedByte(); @@ -91,18 +95,19 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { String imei = readImei(buf); try { deviceId = getDataManager().getDeviceByImei(imei).getId(); + buf.skipBytes(dataLength - 8); sendResponse(channel, type, buf.readUnsignedShort()); } catch(Exception error) { Log.warning("Unknown device - " + imei); } } - else if (type == MSG_HEARTBEAT) { - buf.skipBytes(5); + else if (type == MSG_STATUS) { + buf.skipBytes(dataLength); sendResponse(channel, type, buf.readUnsignedShort()); } - else if (type == MSG_DATA) { + else if (type == MSG_GPS || type == MSG_GPS_LBS || type == MSG_GPS_LBS_STATUS) { // Create new position Position position = new Position(); position.setDeviceId(deviceId); @@ -119,10 +124,12 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { time.set(Calendar.SECOND, buf.readUnsignedByte()); position.setTime(time.getTime()); - // Satellites count + // GPS length and Satellites count + int gpsLength = buf.readUnsignedByte(); extendedInfo.append(""); - extendedInfo.append(buf.readUnsignedByte()); + extendedInfo.append(gpsLength & 0xf); extendedInfo.append(""); + gpsLength >>= 4; // Latitude double latitude = buf.readUnsignedInt() / (60.0 * 30000.0); @@ -144,22 +151,52 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { position.setLongitude(longitude); position.setAltitude(0.0); - // Cell information - extendedInfo.append(""); - extendedInfo.append(buf.readUnsignedShort()); - extendedInfo.append(""); - extendedInfo.append(""); - extendedInfo.append(buf.readUnsignedByte()); - extendedInfo.append(""); - extendedInfo.append(""); - extendedInfo.append(buf.readUnsignedShort()); - extendedInfo.append(""); - extendedInfo.append(""); - extendedInfo.append(buf.readUnsignedShort() << 8 + buf.readUnsignedByte()); - extendedInfo.append(""); + buf.skipBytes(gpsLength - 12); // skip reserved + + if (type == MSG_GPS_LBS || type == MSG_GPS_LBS_STATUS) { + + int lbsLength = 0; + if (type == MSG_GPS_LBS_STATUS) { + lbsLength = buf.readUnsignedByte(); + } + + // Cell information + extendedInfo.append(""); + extendedInfo.append(buf.readUnsignedShort()); + extendedInfo.append(""); + extendedInfo.append(""); + extendedInfo.append(buf.readUnsignedByte()); + extendedInfo.append(""); + extendedInfo.append(""); + extendedInfo.append(buf.readUnsignedShort()); + extendedInfo.append(""); + extendedInfo.append(""); + extendedInfo.append(buf.readUnsignedShort() << 8 + buf.readUnsignedByte()); + extendedInfo.append(""); + buf.skipBytes(lbsLength - 9); + + // Status + if (type == MSG_GPS_LBS_STATUS) { + int flags = buf.readUnsignedByte(); // TODO parse flags + extendedInfo.append("true"); + + // Voltage + position.setPower((double) buf.readUnsignedByte()); + + // GSM signal + extendedInfo.append(""); + extendedInfo.append(buf.readUnsignedByte()); + extendedInfo.append(""); + } + } // Index - position.setId((long) buf.readUnsignedShort()); + if (buf.readableBytes() > 6) { + buf.skipBytes(buf.readableBytes() - 6); + } + int index = buf.readUnsignedShort(); + position.setId((long) index); + sendResponse(channel, type, index); position.setExtendedInfo(extendedInfo.toString()); return position; -- cgit v1.2.3