From 8b74b160890b9dbdd4a2d660d74d2879df6ceced Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 22 Jul 2017 17:45:51 +1200 Subject: Another GT06 LBS and WiFi message type --- src/org/traccar/protocol/Gt06ProtocolDecoder.java | 122 +++++++++++++--------- 1 file changed, 70 insertions(+), 52 deletions(-) (limited to 'src') diff --git a/src/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/org/traccar/protocol/Gt06ProtocolDecoder.java index aea3a29f4..36358b6e5 100644 --- a/src/org/traccar/protocol/Gt06ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gt06ProtocolDecoder.java @@ -31,6 +31,7 @@ import org.traccar.model.CellTower; import org.traccar.model.Device; import org.traccar.model.Network; import org.traccar.model.Position; +import org.traccar.model.WifiAccessPoint; import java.net.SocketAddress; import java.nio.charset.StandardCharsets; @@ -68,6 +69,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { public static final int MSG_GPS_LBS_STATUS_1 = 0x16; public static final int MSG_GPS_LBS_STATUS_2 = 0x26; public static final int MSG_GPS_LBS_STATUS_3 = 0x27; + public static final int MSG_LBS_WIFI = 0x2C; public static final int MSG_LBS_PHONE = 0x17; public static final int MSG_LBS_EXTEND = 0x18; public static final int MSG_LBS_STATUS = 0x19; @@ -390,82 +392,98 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { } else { - Position position = new Position(); - position.setDeviceId(deviceSession.getDeviceId()); - position.setProtocol(getProtocolName()); + return decodeBasicOther(channel, buf, deviceSession, type, dataLength); - if (type == MSG_LBS_EXTEND) { + } - DateBuilder dateBuilder = new DateBuilder(timeZone) - .setDate(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()) - .setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()); + return null; + } - getLastLocation(position, dateBuilder.getDate()); + private Object decodeBasicOther(Channel channel, ChannelBuffer buf, + DeviceSession deviceSession, int type, int dataLength) throws Exception { - int mcc = buf.readUnsignedShort(); - int mnc = buf.readUnsignedByte(); - Network network = new Network(); - for (int i = 0; i < 7; i++) { - network.addCellTower(CellTower.from( - mcc, mnc, buf.readUnsignedShort(), buf.readUnsignedMedium(), -buf.readUnsignedByte())); - } - position.setNetwork(network); + Position position = new Position(); + position.setDeviceId(deviceSession.getDeviceId()); + position.setProtocol(getProtocolName()); - } else if (type == MSG_STRING) { + if (type == MSG_LBS_EXTEND || type == MSG_LBS_WIFI) { - getLastLocation(position, null); + DateBuilder dateBuilder = new DateBuilder(timeZone) + .setDate(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()) + .setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()); - int commandLength = buf.readUnsignedByte(); + getLastLocation(position, dateBuilder.getDate()); - if (commandLength > 0) { - buf.readUnsignedByte(); // server flag (reserved) - position.set(Position.KEY_RESULT, - buf.readBytes(commandLength - 1).toString(StandardCharsets.US_ASCII)); - } + int mcc = buf.readUnsignedShort(); + int mnc = buf.readUnsignedByte(); + Network network = new Network(); + for (int i = 0; i < 7; i++) { + network.addCellTower(CellTower.from( + mcc, mnc, buf.readUnsignedShort(), buf.readUnsignedMedium(), -buf.readUnsignedByte())); + } - } else if (isSupported(type)) { + buf.readUnsignedByte(); // time leads - if (hasGps(type)) { - decodeGps(position, buf, false); - } else { - getLastLocation(position, null); - } + int wifiCount = buf.readUnsignedByte(); + for (int i = 0; i < wifiCount; i++) { + String mac = ChannelBuffers.hexDump(buf.readBytes(6)).replaceAll("(..)", "$1:"); + network.addWifiAccessPoint(WifiAccessPoint.from( + mac.substring(0, mac.length() - 1), buf.readUnsignedByte())); + } - if (hasLbs(type)) { - decodeLbs(position, buf, hasStatus(type)); - } + position.setNetwork(network); - if (hasStatus(type)) { - decodeStatus(position, buf); - } + } else if (type == MSG_STRING) { - if (type == MSG_GPS_LBS_1 && buf.readableBytes() >= 4 + 6) { - position.set(Position.KEY_ODOMETER, buf.readUnsignedInt()); - } + getLastLocation(position, null); - if (type == MSG_GPS_LBS_2 && buf.readableBytes() >= 3 + 6) { - position.set(Position.KEY_IGNITION, buf.readUnsignedByte() > 0); - position.set(Position.KEY_EVENT, buf.readUnsignedByte()); // reason - position.set(Position.KEY_ARCHIVE, buf.readUnsignedByte() > 0); - } + int commandLength = buf.readUnsignedByte(); + if (commandLength > 0) { + buf.readUnsignedByte(); // server flag (reserved) + position.set(Position.KEY_RESULT, + buf.readBytes(commandLength - 1).toString(StandardCharsets.US_ASCII)); + } + + } else if (isSupported(type)) { + + if (hasGps(type)) { + decodeGps(position, buf, false); } else { + getLastLocation(position, null); + } - buf.skipBytes(dataLength); - if (type != MSG_COMMAND_0 && type != MSG_COMMAND_1 && type != MSG_COMMAND_2) { - sendResponse(channel, false, type); - } - return null; + if (hasLbs(type)) { + decodeLbs(position, buf, hasStatus(type)); + } + if (hasStatus(type)) { + decodeStatus(position, buf); } - sendResponse(channel, false, type); + if (type == MSG_GPS_LBS_1 && buf.readableBytes() >= 4 + 6) { + position.set(Position.KEY_ODOMETER, buf.readUnsignedInt()); + } - return position; + if (type == MSG_GPS_LBS_2 && buf.readableBytes() >= 3 + 6) { + position.set(Position.KEY_IGNITION, buf.readUnsignedByte() > 0); + position.set(Position.KEY_EVENT, buf.readUnsignedByte()); // reason + position.set(Position.KEY_ARCHIVE, buf.readUnsignedByte() > 0); + } + + } else { + + buf.skipBytes(dataLength); + if (type != MSG_COMMAND_0 && type != MSG_COMMAND_1 && type != MSG_COMMAND_2) { + sendResponse(channel, false, type); + } + return null; } - return null; + sendResponse(channel, false, type); + + return position; } private Object decodeExtended(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) throws Exception { -- cgit v1.2.3