aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2019-11-05 23:21:24 -0800
committerAnton Tananaev <anton.tananaev@gmail.com>2019-11-05 23:21:24 -0800
commita41841ac8ce200aa0c3836f4c35ce4524eef077c (patch)
tree12877213fc9f53f8eeec14c8320e899fe25d39c9
parentcce68c7e6c116dc23a66dde7ca5476ad7ea575b2 (diff)
downloadtrackermap-server-a41841ac8ce200aa0c3836f4c35ce4524eef077c.tar.gz
trackermap-server-a41841ac8ce200aa0c3836f4c35ce4524eef077c.tar.bz2
trackermap-server-a41841ac8ce200aa0c3836f4c35ce4524eef077c.zip
Decode temperature and humidity
-rw-r--r--src/main/java/org/traccar/protocol/UproProtocolDecoder.java23
-rw-r--r--src/test/java/org/traccar/protocol/UproProtocolDecoderTest.java3
2 files changed, 24 insertions, 2 deletions
diff --git a/src/main/java/org/traccar/protocol/UproProtocolDecoder.java b/src/main/java/org/traccar/protocol/UproProtocolDecoder.java
index 873b22006..a17003fc8 100644
--- a/src/main/java/org/traccar/protocol/UproProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/UproProtocolDecoder.java
@@ -171,12 +171,31 @@ public class UproProtocolDecoder extends BaseProtocolDecoder {
position.setAltitude(
Integer.parseInt(data.readSlice(6).toString(StandardCharsets.US_ASCII)) * 0.1);
break;
+ case 'J':
+ if (data.readableBytes() == 6) {
+ char index = (char) data.readUnsignedByte();
+ int status = data.readUnsignedByte();
+ double value = Integer.parseInt(data.readSlice(4).toString(StandardCharsets.US_ASCII)) * 0.1;
+ if (BitUtil.check(status, 0)) {
+ value = -value;
+ }
+ position.set(Position.PREFIX_TEMP + index, value);
+ }
+ break;
case 'K':
position.set("statusExtended", data.toString(StandardCharsets.US_ASCII));
break;
case 'M':
- position.set(Position.KEY_BATTERY_LEVEL,
- Integer.parseInt(data.readSlice(3).toString(StandardCharsets.US_ASCII)) * 0.1);
+ if (data.readableBytes() == 3) {
+ position.set(Position.KEY_BATTERY_LEVEL,
+ Integer.parseInt(data.readSlice(3).toString(StandardCharsets.US_ASCII)) * 0.1);
+ } else if (data.readableBytes() == 4) {
+ char index = (char) data.readUnsignedByte();
+ data.readUnsignedByte(); // status
+ position.set(
+ "humidity" + index,
+ Integer.parseInt(data.readSlice(2).toString(StandardCharsets.US_ASCII)));
+ }
break;
case 'N':
position.set(Position.KEY_RSSI,
diff --git a/src/test/java/org/traccar/protocol/UproProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/UproProtocolDecoderTest.java
index e43ff322e..e758725f2 100644
--- a/src/test/java/org/traccar/protocol/UproProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/UproProtocolDecoderTest.java
@@ -11,6 +11,9 @@ public class UproProtocolDecoderTest extends ProtocolTest {
UproProtocolDecoder decoder = new UproProtocolDecoder(null);
+ verifyPosition(decoder, buffer(
+ "*HQ201861909268000132,BA&A1820223307024309650492530000311019&B0100000000&F0000&V0036&R0500&J000182&M0052&W00000091&I231026027BD39090827BD5ACA04&X(501E0)(B0000)(E0136)(J01E0)(L3)(k8937204016201240376F)&K00200&T85&N01#"));
+
verifyAttribute(decoder, buffer(
"*VK200867282036729446,BA&A1759265051877702037465660022210819&B0000000000&W00&G000030&M830&N26&O1706&o11&T0783#"),
Position.KEY_BATTERY_LEVEL, 83.0);