From e67e83731f80d12b86aac91337c9aab94bb6d4e6 Mon Sep 17 00:00:00 2001 From: Radek Svanda Date: Fri, 23 Oct 2020 18:07:28 +0200 Subject: Added support for JC400 alarm messages Also a bit of code reuse included. --- .../org/traccar/protocol/Gt06ProtocolDecoder.java | 52 ++++++++++------------ 1 file changed, 24 insertions(+), 28 deletions(-) (limited to 'src/main') 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()); -- cgit v1.2.3 From 11c243661e8c81b7244393277dc257952ff9c4a2 Mon Sep 17 00:00:00 2001 From: Radek Svanda Date: Thu, 29 Oct 2020 09:54:42 +0100 Subject: Use boolean switches rather then method extraction --- .../org/traccar/protocol/Gt06ProtocolDecoder.java | 54 ++++++++++++++-------- 1 file changed, 36 insertions(+), 18 deletions(-) (limited to 'src/main') diff --git a/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java index 0fc94d15f..2c2ca7365 100644 --- a/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java @@ -210,6 +210,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()) @@ -220,19 +225,14 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { return false; } - 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) { + 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; - if (withSpeed) { + if (hasSpeed) { position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte())); } @@ -254,6 +254,7 @@ 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) { @@ -788,19 +789,19 @@ 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()); - if (dataLength == 7) { - getLastLocation(position, dateBuilder.getDate()); + boolean extendedAlarm = dataLength > 7; + if (extendedAlarm) { + decodeGps(position, buf, false, false, false, deviceSession.getTimeZone()); } else { - position.setTime(dateBuilder.getDate()); - decodeLocation(position, buf, false); + 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, dataLength == 7 ? Position.ALARM_GENERAL : Position.ALARM_SOS); + position.set(Position.KEY_ALARM, extendedAlarm ? Position.ALARM_SOS : Position.ALARM_GENERAL); break; case 0x80: position.set(Position.KEY_ALARM, Position.ALARM_VIBRATION); @@ -1121,7 +1122,24 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { position.setTime(new Date(buf.readUnsignedInt() * 1000)); position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); position.setAltitude(buf.readShort()); - decodeLocation(position, buf, true); + + 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); break; case 0x34: position.set(Position.KEY_EVENT, buf.readUnsignedByte()); -- cgit v1.2.3