aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/traccar/protocol/TrvProtocolDecoder.java93
-rw-r--r--src/test/java/org/traccar/protocol/TrvProtocolDecoderTest.java27
2 files changed, 114 insertions, 6 deletions
diff --git a/src/main/java/org/traccar/protocol/TrvProtocolDecoder.java b/src/main/java/org/traccar/protocol/TrvProtocolDecoder.java
index 02744f8ab..8b2e755b2 100644
--- a/src/main/java/org/traccar/protocol/TrvProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/TrvProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2019 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2024 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -64,6 +64,7 @@ public class TrvProtocolDecoder extends BaseProtocolDecoder {
.number("(d+),") // mnc
.number("(d+),") // lac
.number("(d+)") // cell
+ .number(",(dd)").optional() // alarm
.groupBegin()
.text(",")
.expression("(")
@@ -77,7 +78,7 @@ public class TrvProtocolDecoder extends BaseProtocolDecoder {
.any()
.compile();
- private static final Pattern PATTERN_HEARTBEAT = new PatternBuilder()
+ private static final Pattern PATTERN_CP01 = new PatternBuilder()
.expression("[A-Z]{2,3}")
.text("CP01,")
.number("(ddd)") // gsm
@@ -99,7 +100,7 @@ public class TrvProtocolDecoder extends BaseProtocolDecoder {
.any()
.compile();
- private static final Pattern PATTERN_LBS = new PatternBuilder()
+ private static final Pattern PATTERN_AP02 = new PatternBuilder()
.expression("[A-Z]{2,3}")
.text("AP02,")
.expression("[^,]+,") // language
@@ -118,6 +119,19 @@ public class TrvProtocolDecoder extends BaseProtocolDecoder {
.expression("(.*)") // wifi
.compile();
+ private static final Pattern PATTERN_AP03 = new PatternBuilder()
+ .expression("[A-Z]{2,3}")
+ .text("AP03,")
+ .number("(ddd)") // rssi
+ .number("(ddd)") // satellites
+ .number("(ddd)") // battery level
+ .number("d") // space
+ .number("xx") // fortification state
+ .number("dd,") // working mode
+ .number("(d+),") // steps
+ .number("d+") // rolls frequency
+ .compile();
+
private Boolean decodeOptionalValue(Parser parser, int activeValue) {
int value = parser.nextInt();
if (value != 0) {
@@ -183,7 +197,7 @@ public class TrvProtocolDecoder extends BaseProtocolDecoder {
if (type.equals("CP01")) {
- Parser parser = new Parser(PATTERN_HEARTBEAT, sentence);
+ Parser parser = new Parser(PATTERN_CP01, sentence);
if (!parser.matches()) {
return null;
}
@@ -234,6 +248,20 @@ public class TrvProtocolDecoder extends BaseProtocolDecoder {
parser.nextInt(), parser.nextInt(), parser.nextInt(), parser.nextInt()));
if (parser.hasNext()) {
+ switch (parser.nextInt()) {
+ case 1:
+ position.set(Position.KEY_ALARM, Position.ALARM_SOS);
+ break;
+ case 5:
+ case 6:
+ position.set(Position.KEY_ALARM, Position.ALARM_FALL_DOWN);
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (parser.hasNext()) {
decodeWifi(network, parser.next());
}
@@ -243,7 +271,7 @@ public class TrvProtocolDecoder extends BaseProtocolDecoder {
} else if (type.equals("AP02")) {
- Parser parser = new Parser(PATTERN_LBS, sentence);
+ Parser parser = new Parser(PATTERN_AP02, sentence);
if (!parser.matches()) {
return null;
}
@@ -275,6 +303,61 @@ public class TrvProtocolDecoder extends BaseProtocolDecoder {
return position;
+ } else if (type.equals("AP03")) {
+
+ Parser parser = new Parser(PATTERN_AP03, sentence);
+ if (!parser.matches()) {
+ return null;
+ }
+
+ Position position = new Position(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ getLastLocation(position, null);
+
+ position.set(Position.KEY_RSSI, parser.nextInt());
+ position.set(Position.KEY_SATELLITES, parser.nextInt());
+ position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt());
+ position.set(Position.KEY_STEPS, parser.nextInt());
+
+ return position;
+
+ } else if (type.equals("AP49") || type.equals("APHT") || type.equals("APHP") || type.equals("AP50")) {
+
+ Position position = new Position(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ getLastLocation(position, null);
+
+ String[] values = sentence.split(",");
+
+ switch (type) {
+ case "AP49":
+ position.set(Position.KEY_HEART_RATE, Integer.parseInt(values[1]));
+ break;
+ case "APHT":
+ position.set(Position.KEY_HEART_RATE, Integer.parseInt(values[1]));
+ position.set("pressureSystolic", Integer.parseInt(values[2]));
+ position.set("pressureDiastolic", Integer.parseInt(values[3]));
+ break;
+ case "APHP":
+ position.set(Position.KEY_HEART_RATE, Integer.parseInt(values[1]));
+ position.set("pressureSystolic", Integer.parseInt(values[2]));
+ position.set("pressureDiastolic", Integer.parseInt(values[3]));
+ position.set("spo2", Integer.parseInt(values[4]));
+ position.set("bloodSugar", Integer.parseInt(values[5]));
+ position.set("temperature", Double.parseDouble(values[6]));
+ break;
+ case "AP50":
+ position.set("temperature", Double.parseDouble(values[1]));
+ position.set(Position.KEY_BATTERY_LEVEL, Integer.parseInt(values[2]));
+ break;
+ default:
+ break;
+ }
+
+ return position;
+
}
return null;
diff --git a/src/test/java/org/traccar/protocol/TrvProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/TrvProtocolDecoderTest.java
index 370775735..a17fc341f 100644
--- a/src/test/java/org/traccar/protocol/TrvProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/TrvProtocolDecoderTest.java
@@ -2,6 +2,7 @@ package org.traccar.protocol;
import org.junit.jupiter.api.Test;
import org.traccar.ProtocolTest;
+import org.traccar.model.Position;
public class TrvProtocolDecoderTest extends ProtocolTest {
@@ -13,6 +14,30 @@ public class TrvProtocolDecoderTest extends ProtocolTest {
verifyNull(decoder, text(
"TRVAP00352121088015548"));
+ verifyAttribute(decoder, text(
+ "IWAP10080524A2232.9806N11404.9355E000.1061830323.8706000908000502,460,0,9520,3671,01,zhcn,00,HOME|74-DE-2B-44-88-8C|97&HOME1|74-DE-2B-44-88-8C|97&HOME2|74-DE-2B-44-88-8C|97&HOME3|74-DE-2B-44-88-8C|97"),
+ Position.KEY_ALARM, Position.ALARM_SOS);
+
+ verifyAttribute(decoder, text(
+ "IWAP49,68"),
+ Position.KEY_HEART_RATE, 68);
+
+ verifyAttribute(decoder, text(
+ "IWAPHT,60,130,85"),
+ "pressureDiastolic", 85);
+
+ verifyAttribute(decoder, text(
+ "IWAPHP,60,130,85,95,90,36.5,,,,,,,"),
+ "temperature", 36.5);
+
+ verifyAttribute(decoder, text(
+ "IWAP50,36.7,90"),
+ Position.KEY_BATTERY_LEVEL, 90);
+
+ verifyAttribute(decoder, text(
+ "IWAP03,06000908000102,5555,30"),
+ Position.KEY_STEPS, 5555);
+
verifyPosition(decoder, text(
"TRVYP14080524A2232.9806N11404.9355E000.1061830323.870600090800010200011,460,0,9520,3671,Home|74-DE-2B-44-88-8C|97&Home1|74-DE-2B-44-88-8C|97&Home2|74-DE-2B-44-88-8C|97& Home3|74-DE-2B-44-88-8C|97"));
@@ -40,7 +65,7 @@ public class TrvProtocolDecoderTest extends ProtocolTest {
verifyPosition(decoder, text(
"IWAP10080524A2232.9806N11404.9355E000.1061830323.8706000908000502,460,0,9520,3671,00,zh-cn,00,HOME|74-DE-2B-44-88-8C|97&HOME1|74-DE-2B-44-88-8C|97&HOME2|74-DE-2B-44-88-8C|97&HOME3|74-DE-2B-44-88-8C|97"));
- verifyNull(decoder, text(
+ verifyAttributes(decoder, text(
"IWAP03,06000908000102,5555,30"));
verifyNull(decoder, text(