diff options
author | Radek Svanda <radek.svanda@elder.cz> | 2020-10-23 18:07:28 +0200 |
---|---|---|
committer | Radek Svanda <radek.svanda@elder.cz> | 2020-10-26 12:15:32 +0100 |
commit | e67e83731f80d12b86aac91337c9aab94bb6d4e6 (patch) | |
tree | c579695891d55cf747c405e17cb5d46b6a57537f /src | |
parent | 9188d67c08f309697fed0f4e452b06ea738a67bf (diff) | |
download | traccar-server-e67e83731f80d12b86aac91337c9aab94bb6d4e6.tar.gz traccar-server-e67e83731f80d12b86aac91337c9aab94bb6d4e6.tar.bz2 traccar-server-e67e83731f80d12b86aac91337c9aab94bb6d4e6.zip |
Added support for JC400 alarm messages
Also a bit of code reuse included.
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java | 52 | ||||
-rw-r--r-- | src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java | 15 |
2 files changed, 36 insertions, 31 deletions
diff --git a/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java index c0e9541a4..0fc94d15f 100644 --- a/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java @@ -222,9 +222,19 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_SATELLITES, BitUtil.to(buf.readUnsignedByte(), 4)); + decodeLocation(position, buf, true); + + return true; + } + + private static void decodeLocation(Position position, ByteBuf buf, boolean withSpeed) { + double latitude = buf.readUnsignedInt() / 60.0 / 30000.0; double longitude = buf.readUnsignedInt() / 60.0 / 30000.0; - position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte())); + + if (withSpeed) { + position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte())); + } int flags = buf.readUnsignedShort(); position.setCourse(BitUtil.to(flags, 10)); @@ -244,7 +254,6 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_IGNITION, BitUtil.check(flags, 15)); } - return true; } private boolean decodeLbs(Position position, ByteBuf buf, boolean hasLength) { @@ -779,16 +788,20 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { } } else if (type == MSG_ALARM) { - DateBuilder dateBuilder = new DateBuilder(deviceSession.getTimeZone()) .setDate(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()) .setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()); - - getLastLocation(position, dateBuilder.getDate()); - + if (dataLength == 7) { + getLastLocation(position, dateBuilder.getDate()); + } else { + position.setTime(dateBuilder.getDate()); + decodeLocation(position, buf, false); + } short alarmType = buf.readUnsignedByte(); - switch (alarmType) { + case 0x01: + position.set(Position.KEY_ALARM, dataLength == 7 ? Position.ALARM_GENERAL : Position.ALARM_SOS); + break; case 0x80: position.set(Position.KEY_ALARM, Position.ALARM_VIBRATION); break; @@ -804,13 +817,13 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { case 0x92: position.set(Position.KEY_ALARM, Position.ALARM_CORNERING); break; + case 0x93: + position.set(Position.KEY_ALARM, Position.ALARM_ACCIDENT); + break; default: position.set(Position.KEY_ALARM, Position.ALARM_GENERAL); break; } - - position.set("alarmValue", buf.readShort()); - } else { if (dataLength > 0) { @@ -1108,24 +1121,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { position.setTime(new Date(buf.readUnsignedInt() * 1000)); position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); position.setAltitude(buf.readShort()); - - double latitude = buf.readUnsignedInt() / 60.0 / 30000.0; - double longitude = buf.readUnsignedInt() / 60.0 / 30000.0; - position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte())); - - int flags = buf.readUnsignedShort(); - position.setCourse(BitUtil.to(flags, 10)); - position.setValid(BitUtil.check(flags, 12)); - - if (!BitUtil.check(flags, 10)) { - latitude = -latitude; - } - if (BitUtil.check(flags, 11)) { - longitude = -longitude; - } - - position.setLatitude(latitude); - position.setLongitude(longitude); + decodeLocation(position, buf, true); break; case 0x34: position.set(Position.KEY_EVENT, buf.readUnsignedByte()); diff --git a/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java index 46d6a6dab..25d6870bc 100644 --- a/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java @@ -334,12 +334,21 @@ public class Gt06ProtocolDecoderTest extends ProtocolTest { Position.KEY_ALARM, Position.ALARM_ACCELERATION); verifyAttribute(decoder, binary( - "78780c95130a0209321c90000112800d0a"), - "alarmValue", 1); + "78780c95130a0209321c91000112800d0a"), + Position.KEY_ALARM, Position.ALARM_BRAKING); verifyAttribute(decoder, binary( - "78780c95130a0209321c91000112800d0a"), + "78788b95140a060e2208055D4A800209D9C014c59100004556454e545f3335333337363131303032333139365f30303030303030305f323032305f31305f30365f31365f33345f30385f33322e6d70342c4556454e545f3335333337363131303032333139365f30303030303030305f323032305f31305f30365f31365f33345f30385f33312e6d70340000da360d0a"), Position.KEY_ALARM, Position.ALARM_BRAKING); + + verifyAttribute(decoder, binary( + "78788b95140a070c1434055D4A800209D9C014280100004556454e545f3335333337363131303032333139365f30303030303030305f323032305f31305f30375f31345f32305f35325f32342e6d70342c4556454e545f3335333337363131303032333139365f30303030303030305f323032305f31305f30375f31345f32305f35325f32332e6d7034003f6b260d0a"), + Position.KEY_ALARM, Position.ALARM_SOS); + + verifyAttribute(decoder, binary( + "78785195140a020c2914055D4A800209D9C014009300004556454e545f3335333337363131303032333139365f30303030303030305f323032305f31305f30325f31345f34315f32305f30352e6d70340004e3a60d0a"), + Position.KEY_ALARM, Position.ALARM_ACCIDENT); + } } |