From 38f4c7ea61c58397ba42e527621bdece88fa472b Mon Sep 17 00:00:00 2001 From: RafaelMiquelino Date: Tue, 30 Mar 2021 21:44:50 -0300 Subject: Modify Vt200ProtocolDecoder.java Implements ignition status decoding on VT200 protocol. --- .../org/traccar/protocol/Vt200ProtocolDecoder.java | 26 ++++++++++++++++++++++ .../traccar/protocol/Vt200ProtocolDecoderTest.java | 20 ++++++++++++++--- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/traccar/protocol/Vt200ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Vt200ProtocolDecoder.java index b1564abd9..f60f6213d 100644 --- a/src/main/java/org/traccar/protocol/Vt200ProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/Vt200ProtocolDecoder.java @@ -142,6 +142,32 @@ public class Vt200ProtocolDecoder extends BaseProtocolDecoder { return position; + } else if (type == 0x3089) { + + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + position.set(Position.KEY_IGNITION, buf.readUnsignedByte() == 1); + buf.readUnsignedShort(); // trip id + + position.setTime(decodeDate(buf)); + + if (buf.readableBytes() >= 9) { + position.setLatitude(decodeCoordinate(BcdUtil.readInteger(buf, 8))); + position.setLongitude(decodeCoordinate(BcdUtil.readInteger(buf, 9))); + + int flags = buf.readUnsignedByte(); + position.setValid(BitUtil.check(flags, 0)); + if (!BitUtil.check(flags, 1)) { + position.setLatitude(-position.getLatitude()); + } + if (!BitUtil.check(flags, 2)) { + position.setLongitude(-position.getLongitude()); + } + } + + return position; + } return null; diff --git a/src/test/java/org/traccar/protocol/Vt200ProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/Vt200ProtocolDecoderTest.java index 9c224bc8e..47e5cb331 100644 --- a/src/test/java/org/traccar/protocol/Vt200ProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/Vt200ProtocolDecoderTest.java @@ -2,6 +2,7 @@ package org.traccar.protocol; import org.junit.Test; import org.traccar.ProtocolTest; +import org.traccar.model.Position; public class Vt200ProtocolDecoderTest extends ProtocolTest { @@ -43,9 +44,6 @@ public class Vt200ProtocolDecoderTest extends ProtocolTest { verifyPosition(decoder, binary( "28631037309456208200210103302307171805444417097301147188170198090f0000073a002000007e00074429")); - verifyNull(decoder, binary( - "286310373094563089001200032f2107171740144417075001147188872c29")); - verifyAttributes(decoder, binary( "2863103730945630880062032f862631037309456f222014604362936f21071717373221071717401400a100000cd700000004020d3c8e0000000000000000000000000000000000000000000000000000000000000000000a000000040000000e009700000cc9000000000000e929")); @@ -55,6 +53,22 @@ public class Vt200ProtocolDecoderTest extends ProtocolTest { verifyPosition(decoder, binary( "28631037309456208400340102dc090617161654441577230114439597368c0a0c0000030500200100417c1baa349d3290510000006a00007000003d15004c11c629")); + verifyPosition(decoder, binary( + "2830140414000130890009010003280414090004df29"), + position("2014-04-28 09:00:04.000", false, 0.0, 0.0)); + + verifyPosition(decoder, binary( + "2830140414000130890012000003280414090004224388161134912397df29"), + position("2014-04-28 09:00:04.000", true, 22.73136, 113.81873166666666)); + + verifyAttribute(decoder, binary( + "2830140414000130890012000003280414090004224388161134912397df29"), + Position.KEY_IGNITION, false); + + verifyAttribute(decoder, binary( + "2830140414000130890012010003280414090004224388161134912397df29"), + Position.KEY_IGNITION, true); + } } -- cgit v1.2.3 From 9d2df94145fa68c17d1bc13297590a401f1917c9 Mon Sep 17 00:00:00 2001 From: RafaelMiquelino Date: Wed, 31 Mar 2021 19:55:55 -0300 Subject: Modify Vt200ProtocolDecoder Add back removed test on previous commit. Remove duplication on common gps messages decoding. --- .../org/traccar/protocol/Vt200ProtocolDecoder.java | 71 ++++++++-------------- .../traccar/protocol/Vt200ProtocolDecoderTest.java | 3 + 2 files changed, 30 insertions(+), 44 deletions(-) diff --git a/src/main/java/org/traccar/protocol/Vt200ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Vt200ProtocolDecoder.java index f60f6213d..22fc2cf18 100644 --- a/src/main/java/org/traccar/protocol/Vt200ProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/Vt200ProtocolDecoder.java @@ -67,37 +67,46 @@ public class Vt200ProtocolDecoder extends BaseProtocolDecoder { int type = buf.readUnsignedShort(); buf.readUnsignedShort(); // length - if (type == 0x2086 || type == 0x2084 || type == 0x2082) { + if (type == 0x2086 || type == 0x2084 || type == 0x2082 || type == 0x3089) { Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); - buf.readUnsignedByte(); // data type + if (type == 0x3089) { + position.set(Position.KEY_IGNITION, buf.readUnsignedByte() == 1); + } else { + buf.readUnsignedByte(); // data type + } + buf.readUnsignedShort(); // trip id position.setTime(decodeDate(buf)); - position.setLatitude(decodeCoordinate(BcdUtil.readInteger(buf, 8))); - position.setLongitude(decodeCoordinate(BcdUtil.readInteger(buf, 9))); + if (buf.readableBytes() >= 9) { + position.setLatitude(decodeCoordinate(BcdUtil.readInteger(buf, 8))); + position.setLongitude(decodeCoordinate(BcdUtil.readInteger(buf, 9))); - int flags = buf.readUnsignedByte(); - position.setValid(BitUtil.check(flags, 0)); - if (!BitUtil.check(flags, 1)) { - position.setLatitude(-position.getLatitude()); - } - if (!BitUtil.check(flags, 2)) { - position.setLongitude(-position.getLongitude()); + int flags = buf.readUnsignedByte(); + position.setValid(BitUtil.check(flags, 0)); + if (!BitUtil.check(flags, 1)) { + position.setLatitude(-position.getLatitude()); + } + if (!BitUtil.check(flags, 2)) { + position.setLongitude(-position.getLongitude()); + } } - position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte())); - position.setCourse(buf.readUnsignedByte() * 2); + if (type != 0x3089) { + position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte())); + position.setCourse(buf.readUnsignedByte() * 2); - position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); - position.set(Position.KEY_RSSI, buf.readUnsignedByte()); - position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 1000); - position.set(Position.KEY_STATUS, buf.readUnsignedInt()); + position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); + position.set(Position.KEY_RSSI, buf.readUnsignedByte()); + position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 1000); + position.set(Position.KEY_STATUS, buf.readUnsignedInt()); - // additional data + // additional data + } return position; @@ -142,32 +151,6 @@ public class Vt200ProtocolDecoder extends BaseProtocolDecoder { return position; - } else if (type == 0x3089) { - - Position position = new Position(getProtocolName()); - position.setDeviceId(deviceSession.getDeviceId()); - - position.set(Position.KEY_IGNITION, buf.readUnsignedByte() == 1); - buf.readUnsignedShort(); // trip id - - position.setTime(decodeDate(buf)); - - if (buf.readableBytes() >= 9) { - position.setLatitude(decodeCoordinate(BcdUtil.readInteger(buf, 8))); - position.setLongitude(decodeCoordinate(BcdUtil.readInteger(buf, 9))); - - int flags = buf.readUnsignedByte(); - position.setValid(BitUtil.check(flags, 0)); - if (!BitUtil.check(flags, 1)) { - position.setLatitude(-position.getLatitude()); - } - if (!BitUtil.check(flags, 2)) { - position.setLongitude(-position.getLongitude()); - } - } - - return position; - } return null; diff --git a/src/test/java/org/traccar/protocol/Vt200ProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/Vt200ProtocolDecoderTest.java index 47e5cb331..1b492b40a 100644 --- a/src/test/java/org/traccar/protocol/Vt200ProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/Vt200ProtocolDecoderTest.java @@ -44,6 +44,9 @@ public class Vt200ProtocolDecoderTest extends ProtocolTest { verifyPosition(decoder, binary( "28631037309456208200210103302307171805444417097301147188170198090f0000073a002000007e00074429")); + verifyPosition(decoder, binary( + "286310373094563089001200032f2107171740144417075001147188872c29")); + verifyAttributes(decoder, binary( "2863103730945630880062032f862631037309456f222014604362936f21071717373221071717401400a100000cd700000004020d3c8e0000000000000000000000000000000000000000000000000000000000000000000a000000040000000e009700000cc9000000000000e929")); -- cgit v1.2.3 From 1ede0fefed4fb220cd5510b5d75ddd92455f90fa Mon Sep 17 00:00:00 2001 From: RafaelMiquelino Date: Sat, 5 Jun 2021 14:14:27 -0300 Subject: Modify Vt200ProtocolDecoder Change condition to read position to buf.readableBytes() > 2 --- src/main/java/org/traccar/protocol/Vt200ProtocolDecoder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/traccar/protocol/Vt200ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Vt200ProtocolDecoder.java index 22fc2cf18..84ad09caa 100644 --- a/src/main/java/org/traccar/protocol/Vt200ProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/Vt200ProtocolDecoder.java @@ -82,7 +82,7 @@ public class Vt200ProtocolDecoder extends BaseProtocolDecoder { position.setTime(decodeDate(buf)); - if (buf.readableBytes() >= 9) { + if (buf.readableBytes() > 2) { position.setLatitude(decodeCoordinate(BcdUtil.readInteger(buf, 8))); position.setLongitude(decodeCoordinate(BcdUtil.readInteger(buf, 9))); -- cgit v1.2.3