diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2017-08-15 07:39:46 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2017-08-15 07:39:46 +1200 |
commit | 8012240ac5662d8b0a2ec7907ad3f04e86b17627 (patch) | |
tree | 6855a975eb8c8940ebaceb2900606b33d3e02bd4 | |
parent | 52d19ba205d76d18d62789fbb013a43fef024e91 (diff) | |
download | trackermap-server-8012240ac5662d8b0a2ec7907ad3f04e86b17627.tar.gz trackermap-server-8012240ac5662d8b0a2ec7907ad3f04e86b17627.tar.bz2 trackermap-server-8012240ac5662d8b0a2ec7907ad3f04e86b17627.zip |
Add VT200 trip message support
-rw-r--r-- | src/org/traccar/protocol/Vt200ProtocolDecoder.java | 58 | ||||
-rw-r--r-- | test/org/traccar/protocol/Vt200ProtocolDecoderTest.java | 7 |
2 files changed, 57 insertions, 8 deletions
diff --git a/src/org/traccar/protocol/Vt200ProtocolDecoder.java b/src/org/traccar/protocol/Vt200ProtocolDecoder.java index 111c29313..6be70c3c1 100644 --- a/src/org/traccar/protocol/Vt200ProtocolDecoder.java +++ b/src/org/traccar/protocol/Vt200ProtocolDecoder.java @@ -27,6 +27,8 @@ import org.traccar.helper.UnitsConverter; import org.traccar.model.Position; import java.net.SocketAddress; +import java.util.Arrays; +import java.util.Date; public class Vt200ProtocolDecoder extends BaseProtocolDecoder { @@ -40,6 +42,13 @@ public class Vt200ProtocolDecoder extends BaseProtocolDecoder { return degrees + minutes * 0.0001 / 60; } + protected Date decodeDate(ChannelBuffer buf) { + DateBuilder dateBuilder = new DateBuilder() + .setDateReverse(BcdUtil.readInteger(buf, 2), BcdUtil.readInteger(buf, 2), BcdUtil.readInteger(buf, 2)) + .setTime(BcdUtil.readInteger(buf, 2), BcdUtil.readInteger(buf, 2), BcdUtil.readInteger(buf, 2)); + return dateBuilder.getDate(); + } + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -66,12 +75,7 @@ public class Vt200ProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedByte(); // data type buf.readUnsignedShort(); // trip id - DateBuilder dateBuilder = new DateBuilder(); - dateBuilder.setDateReverse( - BcdUtil.readInteger(buf, 2), BcdUtil.readInteger(buf, 2), BcdUtil.readInteger(buf, 2)); - dateBuilder.setTime( - BcdUtil.readInteger(buf, 2), BcdUtil.readInteger(buf, 2), BcdUtil.readInteger(buf, 2)); - position.setTime(dateBuilder.getDate()); + position.setTime(decodeDate(buf)); position.setLatitude(decodeCoordinate(BcdUtil.readInteger(buf, 8))); position.setLongitude(decodeCoordinate(BcdUtil.readInteger(buf, 9))); @@ -97,6 +101,48 @@ public class Vt200ProtocolDecoder extends BaseProtocolDecoder { return position; + } else if (type == 0x3088) { + + Position position = new Position(); + position.setProtocol(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + getLastLocation(position, null); + + buf.readUnsignedShort(); // trip id + buf.skipBytes(8); // imei + buf.skipBytes(8); // imsi + + position.set("tripStart", decodeDate(buf).getTime()); + position.set("tripEnd", decodeDate(buf).getTime()); + position.set("drivingTime", buf.readUnsignedShort()); + + position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedInt()); + position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedInt()); + + position.set("maxSpeed", UnitsConverter.knotsFromKph(buf.readUnsignedByte())); + position.set("maxRpm", buf.readUnsignedShort()); + position.set("maxTemp", buf.readUnsignedByte() - 40); + position.set("hardAccelerationCount", buf.readUnsignedByte()); + position.set("hardBreakingCount", buf.readUnsignedByte()); + + for (String speedType : Arrays.asList("over", "high", "normal", "low")) { + position.set(speedType + "SpeedTime", buf.readUnsignedShort()); + position.set(speedType + "SpeedDistance", buf.readUnsignedInt()); + position.set(speedType + "SpeedFuel", buf.readUnsignedInt()); + } + + position.set("idleTime", buf.readUnsignedShort()); + position.set("idleFuel", buf.readUnsignedInt()); + + position.set("hardCorneringCount", buf.readUnsignedByte()); + position.set("overspeedCount", buf.readUnsignedByte()); + position.set("overheatCount", buf.readUnsignedShort()); + position.set("laneChangeCount", buf.readUnsignedByte()); + position.set("emergencyRefueling", buf.readUnsignedByte()); + + return position; + } return null; diff --git a/test/org/traccar/protocol/Vt200ProtocolDecoderTest.java b/test/org/traccar/protocol/Vt200ProtocolDecoderTest.java index 37d9c46d9..42ed4a652 100644 --- a/test/org/traccar/protocol/Vt200ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Vt200ProtocolDecoderTest.java @@ -13,6 +13,9 @@ public class Vt200ProtocolDecoderTest extends ProtocolTest { verifyNull(decoder, binary( "286310373094563082002701033d010817143327c68a14841e00c27f550e9a000000000c000000084700200120007d01af260b29")); + verifyAttributes(decoder, binary( + "2863103730945630880062033d862631037309456f222014604362936f010817140954010817144135076b00002a3800003b7d6127cc91040000000000000000000000005a0000088e000001ce02630000263b000009b401ff00000cb40000069c02af000018190200000102019729")); + verifyPosition(decoder, binary( "286310373094562086002101033d010817143328441790420114817637207d090a00000847002001207f00d6f229")); @@ -25,7 +28,7 @@ public class Vt200ProtocolDecoderTest extends ProtocolTest { verifyNull(decoder, binary( "28631037309456108800002e29")); - verifyNull(decoder, binary( + verifyAttributes(decoder, binary( "2863103730945630880062033c862631037309456f222014604362936f01081713365601081713571904c800001b2c000034f66827f0840000000000000000000000000047000006e7000001b9022a000023ff000007f2018a00000a10000003f300cd00000d8d0300000302002729")); verifyNull(decoder, binary( @@ -40,7 +43,7 @@ public class Vt200ProtocolDecoderTest extends ProtocolTest { verifyNull(decoder, binary( "286310373094563089001200032f2107171740144417075001147188872c29")); - verifyNull(decoder, binary( + verifyAttributes(decoder, binary( "2863103730945630880062032f862631037309456f222014604362936f21071717373221071717401400a100000cd700000004020d3c8e0000000000000000000000000000000000000000000000000000000000000000000a000000040000000e009700000cc9000000000000e929")); verifyPosition(decoder, binary( |