aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2024-05-23 16:41:52 -0700
committerAnton Tananaev <anton@traccar.org>2024-05-23 16:41:52 -0700
commit7df59714609a62d76ca2f34f2a9d9aed9feb956b (patch)
tree9ecb9dddc55cf38c3c651627e1fb7baaf56afa32
parentc466a8d2baea1913e5623b4dff13e8256220e648 (diff)
downloadtrackermap-server-7df59714609a62d76ca2f34f2a9d9aed9feb956b.tar.gz
trackermap-server-7df59714609a62d76ca2f34f2a9d9aed9feb956b.tar.bz2
trackermap-server-7df59714609a62d76ca2f34f2a9d9aed9feb956b.zip
Model-based Globalstar Atlas decoding
-rw-r--r--src/main/java/org/traccar/protocol/GlobalstarProtocolDecoder.java19
-rw-r--r--src/test/java/org/traccar/protocol/GlobalstarProtocolDecoderTest.java4
2 files changed, 6 insertions, 17 deletions
diff --git a/src/main/java/org/traccar/protocol/GlobalstarProtocolDecoder.java b/src/main/java/org/traccar/protocol/GlobalstarProtocolDecoder.java
index b75e612b8..654071d22 100644
--- a/src/main/java/org/traccar/protocol/GlobalstarProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/GlobalstarProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2019 - 2023 Anton Tananaev (anton@traccar.org)
+ * Copyright 2019 - 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.
@@ -27,7 +27,6 @@ import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.HttpVersion;
import org.traccar.BaseHttpProtocolDecoder;
-import org.traccar.config.Keys;
import org.traccar.session.DeviceSession;
import org.traccar.NetworkMessage;
import org.traccar.Protocol;
@@ -65,12 +64,6 @@ public class GlobalstarProtocolDecoder extends BaseHttpProtocolDecoder {
private final XPath xPath;
private final XPathExpression messageExpression;
- private boolean alternative;
-
- public void setAlternative(boolean alternative) {
- this.alternative = alternative;
- }
-
public GlobalstarProtocolDecoder(Protocol protocol) {
super(protocol);
try {
@@ -89,11 +82,6 @@ public class GlobalstarProtocolDecoder extends BaseHttpProtocolDecoder {
}
}
- @Override
- protected void init() {
- this.alternative = getConfig().getBoolean(Keys.PROTOCOL_ALTERNATIVE.withPrefix(getProtocolName()));
- }
-
private void sendResponse(Channel channel, String messageId) throws TransformerException {
Document document = documentBuilder.newDocument();
@@ -144,6 +132,7 @@ public class GlobalstarProtocolDecoder extends BaseHttpProtocolDecoder {
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, xPath.evaluate("esn", node));
if (deviceSession != null) {
+ boolean atlas = "AtlasTrax".equalsIgnoreCase(getDeviceModel(deviceSession));
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
@@ -154,7 +143,7 @@ public class GlobalstarProtocolDecoder extends BaseHttpProtocolDecoder {
int flags = buf.readUnsignedByte();
int type;
- if (alternative) {
+ if (atlas) {
type = BitUtil.to(flags, 1);
position.setValid(true);
position.set(Position.PREFIX_IN + 1, !BitUtil.check(flags, 1));
@@ -179,7 +168,7 @@ public class GlobalstarProtocolDecoder extends BaseHttpProtocolDecoder {
position.setLongitude(longitude > 180 ? longitude - 360 : longitude);
int speed = 0;
- if (alternative) {
+ if (atlas) {
speed = buf.readUnsignedByte();
position.setSpeed(UnitsConverter.knotsFromKph(speed));
position.set("batteryReplace", BitUtil.check(buf.readUnsignedByte(), 7));
diff --git a/src/test/java/org/traccar/protocol/GlobalstarProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/GlobalstarProtocolDecoderTest.java
index 995fffad0..e78c6c7e7 100644
--- a/src/test/java/org/traccar/protocol/GlobalstarProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/GlobalstarProtocolDecoderTest.java
@@ -11,7 +11,7 @@ public class GlobalstarProtocolDecoderTest extends ProtocolTest {
var decoder = inject(new GlobalstarProtocolDecoder(null));
- decoder.setAlternative(true);
+ decoder.setModelOverride("AtlasTrax");
verifyNull(decoder, request(HttpMethod.POST, "/", buffer(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n",
@@ -24,7 +24,7 @@ public class GlobalstarProtocolDecoderTest extends ProtocolTest {
"</stuMessage>\n",
"</stuMessages>")));
- decoder.setAlternative(false);
+ decoder.setModelOverride(null);
verifyPositions(decoder, request(HttpMethod.POST, "/", buffer(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>",