aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/traccar/MainModule.java2
-rw-r--r--src/main/java/org/traccar/config/Keys.java8
-rw-r--r--src/main/java/org/traccar/protocol/CastelProtocolDecoder.java1
-rw-r--r--src/main/java/org/traccar/protocol/NtoProtocol.java42
-rw-r--r--src/main/java/org/traccar/protocol/NtoProtocolDecoder.java82
-rw-r--r--src/main/java/org/traccar/protocol/RamacProtocol.java42
-rw-r--r--src/main/java/org/traccar/protocol/RamacProtocolDecoder.java112
-rw-r--r--src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java2
-rw-r--r--src/main/java/org/traccar/speedlimit/OverpassSpeedLimitProvider.java9
-rw-r--r--src/test/java/org/traccar/protocol/NtoProtocolDecoderTest.java19
-rw-r--r--src/test/java/org/traccar/protocol/RamacProtocolDecoderTest.java26
-rw-r--r--src/test/java/org/traccar/speedlimit/OverpassSpeedLimitProviderTest.java4
12 files changed, 343 insertions, 6 deletions
diff --git a/src/main/java/org/traccar/MainModule.java b/src/main/java/org/traccar/MainModule.java
index 6ed240d2c..9559b3a90 100644
--- a/src/main/java/org/traccar/MainModule.java
+++ b/src/main/java/org/traccar/MainModule.java
@@ -303,7 +303,7 @@ public class MainModule extends AbstractModule {
switch (type) {
case "overpass":
default:
- return new OverpassSpeedLimitProvider(client, url);
+ return new OverpassSpeedLimitProvider(config, client, url);
}
}
return null;
diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java
index 27f5f0921..23a983e7b 100644
--- a/src/main/java/org/traccar/config/Keys.java
+++ b/src/main/java/org/traccar/config/Keys.java
@@ -1678,6 +1678,14 @@ public final class Keys {
List.of(KeyType.CONFIG));
/**
+ * Search radius for speed limit. Value is in meters. Default value is 100.
+ */
+ public static final ConfigKey<Integer> SPEED_LIMIT_ACCURACY = new IntegerConfigKey(
+ "speedLimit.accuracy",
+ List.of(KeyType.CONFIG),
+ 100);
+
+ /**
* Override latitude sign / hemisphere. Useful in cases where value is incorrect because of device bug. Value can be
* N for North or S for South.
*/
diff --git a/src/main/java/org/traccar/protocol/CastelProtocolDecoder.java b/src/main/java/org/traccar/protocol/CastelProtocolDecoder.java
index 566d856bb..b076b9f66 100644
--- a/src/main/java/org/traccar/protocol/CastelProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/CastelProtocolDecoder.java
@@ -449,6 +449,7 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
} else {
codes.append(ObdDecoder.decodeCode(buf.readUnsignedShortLE()));
}
+ codes.append(' ');
}
position.set(Position.KEY_DTCS, codes.toString().trim());
diff --git a/src/main/java/org/traccar/protocol/NtoProtocol.java b/src/main/java/org/traccar/protocol/NtoProtocol.java
new file mode 100644
index 000000000..d3596e287
--- /dev/null
+++ b/src/main/java/org/traccar/protocol/NtoProtocol.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2023 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.traccar.protocol;
+
+import io.netty.handler.codec.string.StringDecoder;
+import io.netty.handler.codec.string.StringEncoder;
+import jakarta.inject.Inject;
+import org.traccar.BaseProtocol;
+import org.traccar.CharacterDelimiterFrameDecoder;
+import org.traccar.PipelineBuilder;
+import org.traccar.TrackerServer;
+import org.traccar.config.Config;
+
+public class NtoProtocol extends BaseProtocol {
+
+ @Inject
+ public NtoProtocol(Config config) {
+ addServer(new TrackerServer(config, getName(), false) {
+ @Override
+ protected void addProtocolHandlers(PipelineBuilder pipeline, Config config) {
+ pipeline.addLast(new CharacterDelimiterFrameDecoder(1024, '&'));
+ pipeline.addLast(new StringEncoder());
+ pipeline.addLast(new StringDecoder());
+ pipeline.addLast(new NtoProtocolDecoder(NtoProtocol.this));
+ }
+ });
+ }
+
+}
diff --git a/src/main/java/org/traccar/protocol/NtoProtocolDecoder.java b/src/main/java/org/traccar/protocol/NtoProtocolDecoder.java
new file mode 100644
index 000000000..bbdae485e
--- /dev/null
+++ b/src/main/java/org/traccar/protocol/NtoProtocolDecoder.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2023 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.traccar.protocol;
+
+import io.netty.channel.Channel;
+import org.traccar.BaseProtocolDecoder;
+import org.traccar.Protocol;
+import org.traccar.helper.Parser;
+import org.traccar.helper.PatternBuilder;
+import org.traccar.model.Position;
+import org.traccar.session.DeviceSession;
+
+import java.net.SocketAddress;
+import java.util.regex.Pattern;
+
+public class NtoProtocolDecoder extends BaseProtocolDecoder {
+
+ public NtoProtocolDecoder(Protocol protocol) {
+ super(protocol);
+ }
+
+ private static final Pattern PATTERN = new PatternBuilder()
+ .text("^NB,") // manufacturer
+ .number("(d+),") // imei
+ .expression("(...),") // type
+ .number("(dd)(dd)(dd),") // date (ddmmyy)
+ .number("(dd)(dd)(dd),") // time (hhmmss)
+ .expression("([AVM]),") // validity
+ .number("([NS]),(dd)(dd.d+),") // latitude
+ .number("([EW]),(ddd)(dd.d+),") // longitude
+ .number("(d+.?d*),") // speed
+ .number("(d+),") // course
+ .number("(x+),") // status
+ .any()
+ .compile();
+
+ @Override
+ protected Object decode(
+ Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+
+ Parser parser = new Parser(PATTERN, (String) msg);
+ if (!parser.matches()) {
+ return null;
+ }
+
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
+ if (deviceSession == null) {
+ return null;
+ }
+
+ Position position = new Position(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ position.set(Position.KEY_TYPE, parser.next());
+
+ position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
+
+ position.setValid(parser.next().equals("A"));
+ position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
+ position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
+ position.setSpeed(parser.nextDouble());
+ position.setCourse(parser.nextInt());
+
+ position.set(Position.KEY_STATUS, parser.next());
+
+ return position;
+ }
+
+}
diff --git a/src/main/java/org/traccar/protocol/RamacProtocol.java b/src/main/java/org/traccar/protocol/RamacProtocol.java
new file mode 100644
index 000000000..42ce16fe8
--- /dev/null
+++ b/src/main/java/org/traccar/protocol/RamacProtocol.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2023 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.traccar.protocol;
+
+import io.netty.handler.codec.http.HttpObjectAggregator;
+import io.netty.handler.codec.http.HttpRequestDecoder;
+import io.netty.handler.codec.http.HttpResponseEncoder;
+import jakarta.inject.Inject;
+import org.traccar.BaseProtocol;
+import org.traccar.PipelineBuilder;
+import org.traccar.TrackerServer;
+import org.traccar.config.Config;
+
+public class RamacProtocol extends BaseProtocol {
+
+ @Inject
+ public RamacProtocol(Config config) {
+ addServer(new TrackerServer(config, getName(), false) {
+ @Override
+ protected void addProtocolHandlers(PipelineBuilder pipeline, Config config) {
+ pipeline.addLast(new HttpResponseEncoder());
+ pipeline.addLast(new HttpRequestDecoder());
+ pipeline.addLast(new HttpObjectAggregator(65535));
+ pipeline.addLast(new RamacProtocolDecoder(RamacProtocol.this));
+ }
+ });
+ }
+
+}
diff --git a/src/main/java/org/traccar/protocol/RamacProtocolDecoder.java b/src/main/java/org/traccar/protocol/RamacProtocolDecoder.java
new file mode 100644
index 000000000..ffdc68474
--- /dev/null
+++ b/src/main/java/org/traccar/protocol/RamacProtocolDecoder.java
@@ -0,0 +1,112 @@
+/*
+ * Copyright 2023 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.traccar.protocol;
+
+import io.netty.buffer.Unpooled;
+import io.netty.channel.Channel;
+import io.netty.handler.codec.http.FullHttpRequest;
+import io.netty.handler.codec.http.HttpResponseStatus;
+import jakarta.json.Json;
+import jakarta.json.JsonObject;
+import org.traccar.BaseHttpProtocolDecoder;
+import org.traccar.Protocol;
+import org.traccar.model.Position;
+import org.traccar.session.DeviceSession;
+
+import java.io.StringReader;
+import java.net.SocketAddress;
+import java.nio.charset.StandardCharsets;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+
+public class RamacProtocolDecoder extends BaseHttpProtocolDecoder {
+
+ private final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
+ public RamacProtocolDecoder(Protocol protocol) {
+ super(protocol);
+ }
+
+ @Override
+ protected Object decode(
+ Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+
+ FullHttpRequest request = (FullHttpRequest) msg;
+ String content = request.content().toString(StandardCharsets.UTF_8);
+ JsonObject json = Json.createReader(new StringReader(content)).readObject();
+
+ String deviceId = json.getString("DeviceId");
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, deviceId);
+ if (deviceSession == null) {
+ sendResponse(channel, HttpResponseStatus.BAD_REQUEST);
+ return null;
+ }
+
+ Position position = new Position(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ position.set(Position.KEY_TYPE, json.getInt("PacketType"));
+ position.set(Position.KEY_INDEX, json.getInt("SeqNumber"));
+ position.setDeviceTime(dateFormat.parse(json.getString("UpdateDate")));
+
+ int alert = json.getInt("Alert");
+ if (alert > 0) {
+ position.set("alert", alert);
+ String alertMessage = json.getString("AlertMessage");
+ if (!alertMessage.isEmpty()) {
+ position.set("alertMessage", alertMessage);
+ }
+ }
+
+ if (json.containsKey("GpsEvent")) {
+ position.set("gpsEvent", json.getInt("GpsEvent"));
+ if (json.containsKey("GpsEventText")) {
+ position.set("gpsEventText", json.getString("GpsEventText"));
+ }
+ }
+
+ if (json.containsKey("Event")) {
+ position.set(Position.KEY_EVENT, json.getInt("Event"));
+ }
+ if (json.containsKey("BatteryPercentage")) {
+ position.set(Position.KEY_BATTERY_LEVEL, json.getInt("BatteryPercentage"));
+ }
+ if (json.containsKey("Battery")) {
+ position.set(Position.KEY_BATTERY, json.getJsonNumber("Battery").doubleValue());
+ }
+
+ position.set("deviceType", json.getString("DeviceTypeText"));
+
+ if (json.containsKey("Latitude") && json.containsKey("Longitude")) {
+ position.setValid(true);
+ if (json.containsKey("LocationDateTime")) {
+ position.setFixTime(dateFormat.parse(json.getString("LocationDateTime")));
+ } else {
+ position.setFixTime(position.getDeviceTime());
+ }
+ position.setLatitude(json.getJsonNumber("Latitude").doubleValue());
+ position.setLongitude(json.getJsonNumber("Longitude").doubleValue());
+ } else {
+ getLastLocation(position, position.getDeviceTime());
+ }
+
+ sendResponse(
+ channel, HttpResponseStatus.OK,
+ Unpooled.copiedBuffer("{\"CaseID\":1,\"EventID\":1}", StandardCharsets.UTF_8));
+ return position;
+ }
+
+}
diff --git a/src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java b/src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java
index 1298112d1..6f739a1a4 100644
--- a/src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java
@@ -105,7 +105,7 @@ public class SigfoxProtocolDecoder extends BaseHttpProtocolDecoder {
FullHttpRequest request = (FullHttpRequest) msg;
String content = request.content().toString(StandardCharsets.UTF_8);
if (!content.startsWith("{")) {
- content = URLDecoder.decode(content.split("=")[0], "UTF-8");
+ content = URLDecoder.decode(content.split("=")[0], StandardCharsets.UTF_8);
}
JsonObject json = Json.createReader(new StringReader(content)).readObject();
diff --git a/src/main/java/org/traccar/speedlimit/OverpassSpeedLimitProvider.java b/src/main/java/org/traccar/speedlimit/OverpassSpeedLimitProvider.java
index 60ad65f9e..a25eedb2c 100644
--- a/src/main/java/org/traccar/speedlimit/OverpassSpeedLimitProvider.java
+++ b/src/main/java/org/traccar/speedlimit/OverpassSpeedLimitProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2020 - 2022 Anton Tananaev (anton@traccar.org)
+ * Copyright 2020 - 2023 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.
@@ -15,6 +15,8 @@
*/
package org.traccar.speedlimit;
+import org.traccar.config.Config;
+import org.traccar.config.Keys;
import org.traccar.helper.UnitsConverter;
import jakarta.json.JsonArray;
@@ -28,9 +30,10 @@ public class OverpassSpeedLimitProvider implements SpeedLimitProvider {
private final Client client;
private final String url;
- public OverpassSpeedLimitProvider(Client client, String url) {
+ public OverpassSpeedLimitProvider(Config config, Client client, String url) {
+ int accuracy = config.getInteger(Keys.SPEED_LIMIT_ACCURACY);
this.client = client;
- this.url = url + "?data=[out:json];way[maxspeed](around:100.0,%f,%f);out%%20tags;";
+ this.url = url + "?data=[out:json];way[maxspeed](around:" + accuracy + ",%f,%f);out%%20tags;";
}
private Double parseSpeed(String value) {
diff --git a/src/test/java/org/traccar/protocol/NtoProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/NtoProtocolDecoderTest.java
new file mode 100644
index 000000000..424eaadde
--- /dev/null
+++ b/src/test/java/org/traccar/protocol/NtoProtocolDecoderTest.java
@@ -0,0 +1,19 @@
+package org.traccar.protocol;
+
+import org.junit.jupiter.api.Test;
+import org.traccar.ProtocolTest;
+
+public class NtoProtocolDecoderTest extends ProtocolTest {
+
+ @Test
+ public void testDecode() throws Exception {
+
+ var decoder = inject(new NtoProtocolDecoder(null));
+
+ verifyPosition(decoder, text(
+ "^NB,880002023090601,N00,050923,233519,V,N,2236.1994,E,11315.4645,5,0,000000000000,460:00:0:75217090,-04:00,,1693971319,31,2DA5"),
+ position("2023-09-05 23:35:19.000", false, 22.60332, 113.25774));
+
+ }
+
+}
diff --git a/src/test/java/org/traccar/protocol/RamacProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/RamacProtocolDecoderTest.java
new file mode 100644
index 000000000..86734a259
--- /dev/null
+++ b/src/test/java/org/traccar/protocol/RamacProtocolDecoderTest.java
@@ -0,0 +1,26 @@
+package org.traccar.protocol;
+
+import io.netty.handler.codec.http.HttpMethod;
+import org.junit.jupiter.api.Test;
+import org.traccar.ProtocolTest;
+import org.traccar.model.Position;
+
+public class RamacProtocolDecoderTest extends ProtocolTest {
+
+ @Test
+ public void testDecode() throws Exception {
+
+ var decoder = inject(new RamacProtocolDecoder(null));
+
+ verifyAttributes(decoder, request(HttpMethod.POST, "/",
+ buffer("{\"PacketType\": 0,\"SeqNumber\": 4,\"UpdateDate\": \"2022-05-06 12:25:35\",\"Alert\": 42,\"AlertMessage\": \"Low Battery\",\"Mode\": 1,\"ModeText\": \"Help Me\",\"SigfoxTXInterval\": 2,\"GpsFixInterval\": 3,\"SigfoxTXIntervalText\": \"2 Seconds\",\"GpsFixIntervalText\": \"3 Seconds\",\"BatteryPercentage\": 4,\"Battery\": 0.1,\"Temperature\": -22,\"HwVersion\": 7,\"FirmwareVersion\": 8,\"DeviceId\": \"A10001\",\"DeviceType\": \"12\",\"DeviceTypeText\": \"RAMAC P1\"}")));
+
+ verifyPosition(decoder, request(HttpMethod.POST, "/",
+ buffer("{\"PacketType\": 1,\"SeqNumber\": 4,\"UpdateDate\": \"2022-05-06 12:25:35\",\"Alert\": 0,\"AlertMessage\": \"\",\"Latitude\": -25.87586735939189,\"Longitude\": 28.179579268668846,\"Speed\": 1,\"COG\": 3,\"EstimatedAccuracy\": 3,\"LastLocation\": 0,\"LastLocationText\": \"NEW LOCATION\",\"IsMoving\": 0,\"IsMovingText\": \"STATIONARY\",\"GpsEvent\": 5,\"GpsEventText\": \"Heartbeat\",\"DeviceId\": \"A10001\",\"DeviceType\": \"12\",\"DeviceTypeText\": \"RAMAC P1\"}")));
+
+ verifyPosition(decoder, request(HttpMethod.POST, "/",
+ buffer("{\"PacketType\": 2,\"SeqNumber\": 4,\"UpdateDate\": \"2022-05-06 12:25:35\",\"Alert\": 19,\"AlertMessage\": \"P1 Panic\",\"Event\": 16,\"DeviceId\": \"A10001\",\"DeviceType\": \"12\",\"DeviceTypeText\": \"RAMAC P1\",\"Latitude\": -25.875867359392,\"Longitude\": 28.179579268669,\"LocationDateTime\": \"2022-05-05 08:48:11\"}")));
+
+ }
+
+}
diff --git a/src/test/java/org/traccar/speedlimit/OverpassSpeedLimitProviderTest.java b/src/test/java/org/traccar/speedlimit/OverpassSpeedLimitProviderTest.java
index a59d1ce91..dbdf85420 100644
--- a/src/test/java/org/traccar/speedlimit/OverpassSpeedLimitProviderTest.java
+++ b/src/test/java/org/traccar/speedlimit/OverpassSpeedLimitProviderTest.java
@@ -5,6 +5,7 @@ import org.junit.jupiter.api.Test;
import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.client.ClientBuilder;
+import org.traccar.config.Config;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
@@ -16,7 +17,8 @@ public class OverpassSpeedLimitProviderTest {
@Disabled
@Test
public void testOverpass() throws Exception {
- SpeedLimitProvider provider = new OverpassSpeedLimitProvider(client, "http://8.8.8.8/api/interpreter");
+ var config = new Config();
+ SpeedLimitProvider provider = new OverpassSpeedLimitProvider(config, client, "http://8.8.8.8/api/interpreter");
provider.getSpeedLimit(34.74767, -82.48098, new SpeedLimitProvider.SpeedLimitProviderCallback() {
@Override