aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2020-10-29 23:27:33 -0700
committerGitHub <noreply@github.com>2020-10-29 23:27:33 -0700
commit2f6d252cca600f1a9cf326b13c614d46ee2197b5 (patch)
tree45e7dfac1d35916f752e11eac1b6838dcc12a51e
parent36d5da225b4c9e986a8cae1af4133204b148c885 (diff)
parent11c243661e8c81b7244393277dc257952ff9c4a2 (diff)
downloadtrackermap-server-2f6d252cca600f1a9cf326b13c614d46ee2197b5.tar.gz
trackermap-server-2f6d252cca600f1a9cf326b13c614d46ee2197b5.tar.bz2
trackermap-server-2f6d252cca600f1a9cf326b13c614d46ee2197b5.zip
Merge pull request #4595 from elderstudios/feat/jc400-device-alerts
Added support for JC400 alarm messages
-rw-r--r--src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java40
-rw-r--r--src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java15
2 files changed, 39 insertions, 16 deletions
diff --git a/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java
index 7b510639a..e003db51a 100644
--- a/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java
@@ -213,6 +213,11 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
}
public static boolean decodeGps(Position position, ByteBuf buf, boolean hasLength, TimeZone timezone) {
+ return decodeGps(position, buf, hasLength, true, true, timezone);
+ }
+
+ public static boolean decodeGps(Position position, ByteBuf buf, boolean hasLength, boolean hasSatellites,
+ boolean hasSpeed, TimeZone timezone) {
DateBuilder dateBuilder = new DateBuilder(timezone)
.setDate(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte())
@@ -223,11 +228,16 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
return false;
}
- position.set(Position.KEY_SATELLITES, BitUtil.to(buf.readUnsignedByte(), 4));
+ if (hasSatellites) {
+ position.set(Position.KEY_SATELLITES, BitUtil.to(buf.readUnsignedByte(), 4));
+ }
double latitude = buf.readUnsignedInt() / 60.0 / 30000.0;
double longitude = buf.readUnsignedInt() / 60.0 / 30000.0;
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
+
+ if (hasSpeed) {
+ position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
+ }
int flags = buf.readUnsignedShort();
position.setCourse(BitUtil.to(flags, 10));
@@ -732,16 +742,20 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
decodeBasicUniversal(buf, deviceSession, type, position);
} 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());
-
+ boolean extendedAlarm = dataLength > 7;
+ if (extendedAlarm) {
+ decodeGps(position, buf, false, false, false, deviceSession.getTimeZone());
+ } else {
+ DateBuilder dateBuilder = new DateBuilder(deviceSession.getTimeZone())
+ .setDate(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte())
+ .setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
+ getLastLocation(position, dateBuilder.getDate());
+ }
short alarmType = buf.readUnsignedByte();
-
switch (alarmType) {
+ case 0x01:
+ position.set(Position.KEY_ALARM, extendedAlarm ? Position.ALARM_SOS : Position.ALARM_GENERAL);
+ break;
case 0x80:
position.set(Position.KEY_ALARM, Position.ALARM_VIBRATION);
break;
@@ -757,13 +771,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) {
diff --git a/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java
index 776a984dc..e6b7b7ce3 100644
--- a/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java
@@ -341,12 +341,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);
+
}
}