diff options
author | Anton Tananaev <anton@traccar.org> | 2022-10-16 12:54:28 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2022-10-16 12:54:28 -0700 |
commit | db97378f2210818d0600420bc9c69103ddea248b (patch) | |
tree | 88a66baf0e06b3ce10a95b9b95bfc8337732a050 /src/main | |
parent | 3f01f92125851e325b8e3e4ef679d832fe3dee21 (diff) | |
download | trackermap-server-db97378f2210818d0600420bc9c69103ddea248b.tar.gz trackermap-server-db97378f2210818d0600420bc9c69103ddea248b.tar.bz2 trackermap-server-db97378f2210818d0600420bc9c69103ddea248b.zip |
Improve Suntech support
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/org/traccar/protocol/SuntechProtocolDecoder.java | 18 | ||||
-rw-r--r-- | src/main/java/org/traccar/protocol/SuntechProtocolEncoder.java | 10 |
2 files changed, 21 insertions, 7 deletions
diff --git a/src/main/java/org/traccar/protocol/SuntechProtocolDecoder.java b/src/main/java/org/traccar/protocol/SuntechProtocolDecoder.java index f1097abac..e67bd7a71 100644 --- a/src/main/java/org/traccar/protocol/SuntechProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/SuntechProtocolDecoder.java @@ -43,6 +43,7 @@ import java.util.Date; import java.util.LinkedList; import java.util.List; import java.util.TimeZone; +import java.util.stream.Collectors; public class SuntechProtocolDecoder extends BaseProtocolDecoder { @@ -203,12 +204,16 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder { return Position.ALARM_POWER_RESTORED; case 41: return Position.ALARM_POWER_CUT; + case 42: + return Position.ALARM_SOS; case 46: return Position.ALARM_ACCELERATION; case 47: return Position.ALARM_BRAKING; case 50: return Position.ALARM_JAMMING; + case 132: + return Position.ALARM_DOOR; default: return null; } @@ -468,7 +473,7 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder { String type = values[index++]; - if (!type.equals("STT") && !type.equals("ALT") && !type.equals("BLE")) { + if (!type.equals("STT") && !type.equals("ALT") && !type.equals("BLE") && !type.equals("RES")) { return null; } @@ -481,6 +486,14 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder { position.setDeviceId(deviceSession.getDeviceId()); position.set(Position.KEY_TYPE, type); + if (type.equals("RES")) { + getLastLocation(position, null); + position.set( + Position.KEY_RESULT, + Arrays.stream(values, index, values.length).collect(Collectors.joining(";"))); + return position; + } + int mask; if (type.equals("BLE")) { mask = 0b1100000110110; @@ -581,7 +594,8 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder { if (type.equals("ALT")) { if (BitUtil.check(mask, 19)) { - position.set("alertId", values[index++]); + int alertId = Integer.parseInt(values[index++]); + position.set(Position.KEY_ALARM, decodeAlert(alertId)); } if (BitUtil.check(mask, 20)) { position.set("alertModifier", values[index++]); diff --git a/src/main/java/org/traccar/protocol/SuntechProtocolEncoder.java b/src/main/java/org/traccar/protocol/SuntechProtocolEncoder.java index 597acaae8..53308f968 100644 --- a/src/main/java/org/traccar/protocol/SuntechProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/SuntechProtocolEncoder.java @@ -45,13 +45,13 @@ public class SuntechProtocolEncoder extends StringProtocolEncoder { } if (universal) { - return encodeUniversalCommand(channel, command); + return encodeUniversalCommand(command); } else { - return encodeLegacyCommand(channel, prefix, command); + return encodeLegacyCommand(prefix, command); } } - protected Object encodeUniversalCommand(Channel channel, Command command) { + protected Object encodeUniversalCommand(Command command) { switch (command.getType()) { case Command.TYPE_REBOOT_DEVICE: return formatCommand(command, "CMD;%s;03;03\r", Command.KEY_UNIQUE_ID); @@ -84,7 +84,7 @@ public class SuntechProtocolEncoder extends StringProtocolEncoder { case Command.TYPE_ENGINE_STOP: return formatCommand(command, "CMD;%s;04;01\r", Command.KEY_UNIQUE_ID); case Command.TYPE_ENGINE_RESUME: - return formatCommand(command, "CMD;%s;02;02\r", Command.KEY_UNIQUE_ID); + return formatCommand(command, "CMD;%s;04;02\r", Command.KEY_UNIQUE_ID); case Command.TYPE_ALARM_ARM: return formatCommand(command, "CMD;%s;04;03\r", Command.KEY_UNIQUE_ID); case Command.TYPE_ALARM_DISARM: @@ -94,7 +94,7 @@ public class SuntechProtocolEncoder extends StringProtocolEncoder { } } - protected Object encodeLegacyCommand(Channel channel, String prefix, Command command) { + protected Object encodeLegacyCommand(String prefix, Command command) { switch (command.getType()) { case Command.TYPE_REBOOT_DEVICE: return formatCommand(command, prefix + "CMD;%s;02;Reboot\r", Command.KEY_UNIQUE_ID); |