aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-10-16 12:54:28 -0700
committerAnton Tananaev <anton@traccar.org>2022-10-16 12:54:28 -0700
commitdb97378f2210818d0600420bc9c69103ddea248b (patch)
tree88a66baf0e06b3ce10a95b9b95bfc8337732a050 /src
parent3f01f92125851e325b8e3e4ef679d832fe3dee21 (diff)
downloadtrackermap-server-db97378f2210818d0600420bc9c69103ddea248b.tar.gz
trackermap-server-db97378f2210818d0600420bc9c69103ddea248b.tar.bz2
trackermap-server-db97378f2210818d0600420bc9c69103ddea248b.zip
Improve Suntech support
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/traccar/protocol/SuntechProtocolDecoder.java18
-rw-r--r--src/main/java/org/traccar/protocol/SuntechProtocolEncoder.java10
-rw-r--r--src/test/java/org/traccar/protocol/SuntechProtocolDecoderTest.java4
3 files changed, 25 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);
diff --git a/src/test/java/org/traccar/protocol/SuntechProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/SuntechProtocolDecoderTest.java
index 30959c8b9..ebd48c5c7 100644
--- a/src/test/java/org/traccar/protocol/SuntechProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/SuntechProtocolDecoderTest.java
@@ -83,6 +83,10 @@ public class SuntechProtocolDecoderTest extends ProtocolTest {
var decoder = inject(new SuntechProtocolDecoder(null));
+ verifyAttribute(decoder, buffer(
+ "RES;4309999001;04;02;TEST"),
+ Position.KEY_RESULT, "04;02;TEST");
+
verifyPosition(decoder, buffer(
"BLE;1140000053;114;1.0.1;20211001;17:27:09;+28.433465;-82.565891;1;-43;-46;-41;ACB89523EF68;247;0;0"));