diff options
Diffstat (limited to 'src/org/traccar')
-rw-r--r-- | src/org/traccar/protocol/Jt600ProtocolDecoder.java | 63 |
1 files changed, 40 insertions, 23 deletions
diff --git a/src/org/traccar/protocol/Jt600ProtocolDecoder.java b/src/org/traccar/protocol/Jt600ProtocolDecoder.java index 86711a644..f7eccbfb5 100644 --- a/src/org/traccar/protocol/Jt600ProtocolDecoder.java +++ b/src/org/traccar/protocol/Jt600ProtocolDecoder.java @@ -27,6 +27,7 @@ import org.traccar.BaseProtocolDecoder; import org.traccar.ServerManager; import org.traccar.helper.ChannelBufferTools; import org.traccar.helper.Log; +import org.traccar.model.ExtendedInfoFormatter; import org.traccar.model.Position; public class Jt600ProtocolDecoder extends BaseProtocolDecoder { @@ -38,6 +39,7 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { private Position decodeNormalMessage(ChannelBuffer buf) throws Exception { Position position = new Position(); + ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("jt600"); buf.readByte(); // header @@ -50,19 +52,21 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { //return null; } - buf.readByte(); // protocol version + data type + // Protocol and type + int version = ChannelBufferTools.readHexInteger(buf, 1); + int type = buf.readUnsignedByte() & 0xf; buf.readBytes(2); // length // Time Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); time.clear(); - time.set(Calendar.DAY_OF_MONTH, ChannelBufferTools.readHexInteger(buf, 2)); - time.set(Calendar.MONTH, ChannelBufferTools.readHexInteger(buf, 2) - 1); - time.set(Calendar.YEAR, 2000 + ChannelBufferTools.readHexInteger(buf, 2)); - time.set(Calendar.HOUR, ChannelBufferTools.readHexInteger(buf, 2)); - time.set(Calendar.MINUTE, ChannelBufferTools.readHexInteger(buf, 2)); - time.set(Calendar.SECOND, ChannelBufferTools.readHexInteger(buf, 2)); + time.set(Calendar.DAY_OF_MONTH, buf.readUnsignedByte()); + time.set(Calendar.MONTH, buf.readUnsignedByte() - 1); + time.set(Calendar.YEAR, 2000 + buf.readUnsignedByte()); + time.set(Calendar.HOUR, buf.readUnsignedByte()); + time.set(Calendar.MINUTE, buf.readUnsignedByte()); + time.set(Calendar.SECOND, buf.readUnsignedByte()); position.setTime(time.getTime()); // Coordinates @@ -84,32 +88,42 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { position.setLongitude(longitude); // Speed - double speed = ChannelBufferTools.readHexInteger(buf, 2); - position.setSpeed(speed); + position.setSpeed((double) buf.readUnsignedByte()); // Course - double course = buf.readUnsignedByte() * 2; - position.setCourse(course); + position.setCourse(buf.readUnsignedByte() * 2.0); + + if (version == 1) { + + extendedInfo.set("satellites", buf.readUnsignedByte()); - buf.readByte(); // number of satellites + // Power + position.setPower((double) buf.readUnsignedByte()); - // Course - double power = buf.readUnsignedByte(); - position.setPower(power); + buf.readByte(); // other flags and sensors + + // Altitude + position.setAltitude((double) buf.readUnsignedShort()); - buf.readByte(); // other flags and sensors + extendedInfo.set("cell", buf.readUnsignedShort()); + extendedInfo.set("lac", buf.readUnsignedShort()); + extendedInfo.set("gsm", buf.readUnsignedByte()); - // Altitude - double altitude = buf.readUnsignedShort(); - position.setAltitude(altitude); + } else if (version == 2) { - buf.readUnsignedShort(); // cell id - buf.readUnsignedShort(); // lac + position.setAltitude(0.0); - buf.readUnsignedByte(); // gsm signal + int fuel = buf.readUnsignedByte() << 8; - buf.readUnsignedByte(); // message number + extendedInfo.set("status", buf.readUnsignedInt()); + extendedInfo.set("milage", buf.readUnsignedInt()); + fuel += buf.readUnsignedByte(); + extendedInfo.set("fuel", fuel); + + } + + position.setExtendedInfo(extendedInfo.toString()); return position; } @@ -144,6 +158,8 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); + ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("jt600"); + extendedInfo.set("alert", "true"); Integer index = 1; // Get device by identifier @@ -190,6 +206,7 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { // Power position.setPower(Double.valueOf(parser.group(index++))); + position.setExtendedInfo(extendedInfo.toString()); return position; } |