diff options
author | Radek Svanda <radek.svanda@elder.cz> | 2020-10-29 09:54:42 +0100 |
---|---|---|
committer | Radek Svanda <radek.svanda@elder.cz> | 2020-10-30 06:59:16 +0100 |
commit | 11c243661e8c81b7244393277dc257952ff9c4a2 (patch) | |
tree | 9425f95d9f2d30dd4dc184da1486d0caa0bf3132 | |
parent | e67e83731f80d12b86aac91337c9aab94bb6d4e6 (diff) | |
download | trackermap-server-11c243661e8c81b7244393277dc257952ff9c4a2.tar.gz trackermap-server-11c243661e8c81b7244393277dc257952ff9c4a2.tar.bz2 trackermap-server-11c243661e8c81b7244393277dc257952ff9c4a2.zip |
Use boolean switches rather then method extraction
-rw-r--r-- | src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java | 54 |
1 files changed, 36 insertions, 18 deletions
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()); |