aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar')
-rw-r--r--src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java54
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());