diff options
Diffstat (limited to 'src/main/java/org/traccar/protocol')
3 files changed, 39 insertions, 3 deletions
diff --git a/src/main/java/org/traccar/protocol/KhdProtocolDecoder.java b/src/main/java/org/traccar/protocol/KhdProtocolDecoder.java index 251351a74..371b0f71c 100644 --- a/src/main/java/org/traccar/protocol/KhdProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/KhdProtocolDecoder.java @@ -162,7 +162,13 @@ public class KhdProtocolDecoder extends BaseProtocolDecoder { if (type != MSG_ALARM) { - position.set(Position.KEY_ODOMETER, buf.readUnsignedMedium()); + int odometer = buf.readUnsignedMedium(); + if (BitUtil.to(odometer, 16) > 0) { + position.set(Position.KEY_ODOMETER, odometer); + } else if (odometer > 0) { + position.set(Position.KEY_FUEL_LEVEL, BitUtil.from(odometer, 16)); + } + position.set(Position.KEY_STATUS, buf.readUnsignedInt()); buf.readUnsignedShort(); diff --git a/src/main/java/org/traccar/protocol/StartekProtocolDecoder.java b/src/main/java/org/traccar/protocol/StartekProtocolDecoder.java index 68fc511aa..aae764993 100644 --- a/src/main/java/org/traccar/protocol/StartekProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/StartekProtocolDecoder.java @@ -41,6 +41,11 @@ public class StartekProtocolDecoder extends BaseProtocolDecoder { .expression(".") // index .number("d+,") // length .number("(d+),") // imei + .expression("(.+)") // content + .number("xx") // checksum + .compile(); + + private static final Pattern PATTERN_POSITION = new PatternBuilder() .number("xxx,") // command .number("(d+),") // event .expression("([^,]+)?,") // event data @@ -75,7 +80,6 @@ public class StartekProtocolDecoder extends BaseProtocolDecoder { .expression("([^,]+)?") // temperature .groupEnd("?") .groupEnd("?") - .number("xx") // checksum .compile(); private String decodeAlarm(int value) { @@ -108,6 +112,32 @@ public class StartekProtocolDecoder extends BaseProtocolDecoder { return null; } + String content = parser.next(); + if (content.length() < 100) { + + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + getLastLocation(position, null); + + position.set(Position.KEY_RESULT, content); + + return position; + + } else { + + return decodePosition(deviceSession, content); + + } + } + + protected Object decodePosition(DeviceSession deviceSession, String content) throws Exception { + + Parser parser = new Parser(PATTERN_POSITION, content); + if (!parser.matches()) { + return null; + } + Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); diff --git a/src/main/java/org/traccar/protocol/WatchProtocolDecoder.java b/src/main/java/org/traccar/protocol/WatchProtocolDecoder.java index 5ff0bbb6c..564acd7b4 100644 --- a/src/main/java/org/traccar/protocol/WatchProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/WatchProtocolDecoder.java @@ -101,7 +101,7 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { return Position.ALARM_GEOFENCE_ENTER; } else if (BitUtil.check(status, 20)) { return Position.ALARM_REMOVING; - } else if (BitUtil.check(status, 21)) { + } else if (BitUtil.check(status, 21) || BitUtil.check(status, 22)) { return Position.ALARM_FALL_DOWN; } return null; |