aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2020-11-02 22:03:03 -0800
committerAnton Tananaev <anton.tananaev@gmail.com>2020-11-02 22:03:03 -0800
commit1afe1e818d77d2e6df520071aa7e6b0c9f335454 (patch)
treecb37f680d1f6f2f2f384c9ea96ae2e71ea5565ae /src
parentc2f3554886b62690b2dc705e037517b34da99340 (diff)
downloadtraccar-server-1afe1e818d77d2e6df520071aa7e6b0c9f335454.tar.gz
traccar-server-1afe1e818d77d2e6df520071aa7e6b0c9f335454.tar.bz2
traccar-server-1afe1e818d77d2e6df520071aa7e6b0c9f335454.zip
Decode CalAmp user data
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/traccar/protocol/CalAmpProtocolDecoder.java42
-rw-r--r--src/test/java/org/traccar/protocol/CalAmpProtocolDecoderTest.java3
2 files changed, 31 insertions, 14 deletions
diff --git a/src/main/java/org/traccar/protocol/CalAmpProtocolDecoder.java b/src/main/java/org/traccar/protocol/CalAmpProtocolDecoder.java
index dad0ae774..59b1fdf21 100644
--- a/src/main/java/org/traccar/protocol/CalAmpProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/CalAmpProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2019 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2020 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.
@@ -28,6 +28,7 @@ import org.traccar.helper.UnitsConverter;
import org.traccar.model.Position;
import java.net.SocketAddress;
+import java.nio.charset.StandardCharsets;
import java.util.Date;
public class CalAmpProtocolDecoder extends BaseProtocolDecoder {
@@ -121,22 +122,34 @@ public class CalAmpProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_EVENT, buf.readUnsignedByte());
}
- int accType = BitUtil.from(buf.getUnsignedByte(buf.readerIndex()), 6);
- int accCount = BitUtil.to(buf.readUnsignedByte(), 6);
+ if (type == MSG_EVENT_REPORT || type == MSG_LOCATE_REPORT || type == MSG_MINI_EVENT_REPORT) {
- if (type != MSG_MINI_EVENT_REPORT) {
- position.set("append", buf.readUnsignedByte());
- }
+ int accType = BitUtil.from(buf.getUnsignedByte(buf.readerIndex()), 6);
+ int accCount = BitUtil.to(buf.readUnsignedByte(), 6);
- if (accType == 1) {
- buf.readUnsignedInt(); // threshold
- buf.readUnsignedInt(); // mask
- }
+ if (type != MSG_MINI_EVENT_REPORT) {
+ position.set("append", buf.readUnsignedByte());
+ }
- for (int i = 0; i < accCount; i++) {
- if (buf.readableBytes() >= 4) {
- position.set("acc" + i, buf.readUnsignedInt());
+ if (accType == 1) {
+ buf.readUnsignedInt(); // threshold
+ buf.readUnsignedInt(); // mask
}
+
+ for (int i = 0; i < accCount; i++) {
+ if (buf.readableBytes() >= 4) {
+ position.set("acc" + i, buf.readUnsignedInt());
+ }
+ }
+
+ } else if (type == MSG_USER_DATA) {
+
+ buf.readUnsignedByte(); // message route
+ buf.readUnsignedByte(); // message id
+ position.set(
+ Position.KEY_RESULT,
+ buf.readCharSequence(buf.readUnsignedShort(), StandardCharsets.US_ASCII).toString().trim());
+
}
return position;
@@ -192,7 +205,8 @@ public class CalAmpProtocolDecoder extends BaseProtocolDecoder {
sendResponse(channel, remoteAddress, type, index, 0);
}
- if (type == MSG_EVENT_REPORT || type == MSG_LOCATE_REPORT || type == MSG_MINI_EVENT_REPORT) {
+ if (type == MSG_EVENT_REPORT || type == MSG_LOCATE_REPORT
+ || type == MSG_MINI_EVENT_REPORT || type == MSG_USER_DATA) {
return decodePosition(deviceSession, type, buf);
}
diff --git a/src/test/java/org/traccar/protocol/CalAmpProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/CalAmpProtocolDecoderTest.java
index 7640484d4..8be693ee6 100644
--- a/src/test/java/org/traccar/protocol/CalAmpProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/CalAmpProtocolDecoderTest.java
@@ -11,6 +11,9 @@ public class CalAmpProtocolDecoderTest extends ProtocolTest {
CalAmpProtocolDecoder decoder = new CalAmpProtocolDecoder(null);
verifyPosition(decoder, binary(
+ "830547643586340101010400105f9c39ba5f9c302eeb36d5bddf39df700000000000000000003400040321ff9f4f0087080200001c30783330304544383946333335303139303030303030343637450d0a"));
+
+ verifyPosition(decoder, binary(
"8308352648068863398f01070102039c5cfc4dcd5cfc4dcd19913f5dcce1291e000033fa0000005801110800019aff9d6f0e13003e0b02000000000000000000"));
verifyPosition(decoder, binary(