aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar')
-rw-r--r--src/main/java/org/traccar/BasePipelineFactory.java2
-rw-r--r--src/main/java/org/traccar/MainModule.java27
-rw-r--r--src/main/java/org/traccar/config/Keys.java18
-rw-r--r--src/main/java/org/traccar/handler/SpeedLimitHandler.java60
-rw-r--r--src/main/java/org/traccar/model/Position.java1
5 files changed, 108 insertions, 0 deletions
diff --git a/src/main/java/org/traccar/BasePipelineFactory.java b/src/main/java/org/traccar/BasePipelineFactory.java
index 5a5850a86..c038c1f92 100644
--- a/src/main/java/org/traccar/BasePipelineFactory.java
+++ b/src/main/java/org/traccar/BasePipelineFactory.java
@@ -26,6 +26,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.traccar.config.Keys;
import org.traccar.handler.DefaultDataHandler;
+import org.traccar.handler.SpeedLimitHandler;
import org.traccar.handler.TimeHandler;
import org.traccar.handler.events.AlertEventHandler;
import org.traccar.handler.events.CommandResultEventHandler;
@@ -133,6 +134,7 @@ public abstract class BasePipelineFactory extends ChannelInitializer<Channel> {
pipeline,
FilterHandler.class,
GeocoderHandler.class,
+ SpeedLimitHandler.class,
MotionHandler.class,
CopyAttributesHandler.class,
EngineHoursHandler.class,
diff --git a/src/main/java/org/traccar/MainModule.java b/src/main/java/org/traccar/MainModule.java
index de6ec5b87..e751cb453 100644
--- a/src/main/java/org/traccar/MainModule.java
+++ b/src/main/java/org/traccar/MainModule.java
@@ -61,6 +61,7 @@ import org.traccar.handler.GeolocationHandler;
import org.traccar.handler.HemisphereHandler;
import org.traccar.handler.MotionHandler;
import org.traccar.handler.RemoteAddressHandler;
+import org.traccar.handler.SpeedLimitHandler;
import org.traccar.handler.TimeHandler;
import org.traccar.handler.events.AlertEventHandler;
import org.traccar.handler.events.CommandResultEventHandler;
@@ -76,6 +77,8 @@ import org.traccar.reports.model.TripsConfig;
import javax.annotation.Nullable;
import javax.ws.rs.client.Client;
import io.netty.util.Timer;
+import org.traccar.speedlimit.OverpassSpeedLimitProvider;
+import org.traccar.speedlimit.SpeedLimitProvider;
public class MainModule extends AbstractModule {
@@ -211,6 +214,21 @@ public class MainModule extends AbstractModule {
@Singleton
@Provides
+ public static SpeedLimitProvider provideSpeedLimitProvider(Config config) {
+ if (config.getBoolean(Keys.SPEED_LIMIT_ENABLE)) {
+ String type = config.getString(Keys.SPEED_LIMIT_TYPE, "overpass");
+ String url = config.getString(Keys.SPEED_LIMIT_URL);
+ switch (type) {
+ case "overpass":
+ default:
+ return new OverpassSpeedLimitProvider(url);
+ }
+ }
+ return null;
+ }
+
+ @Singleton
+ @Provides
public static DistanceHandler provideDistanceHandler(Config config, IdentityManager identityManager) {
return new DistanceHandler(config, identityManager);
}
@@ -275,6 +293,15 @@ public class MainModule extends AbstractModule {
@Singleton
@Provides
+ public static SpeedLimitHandler provideSpeedLimitHandler(@Nullable SpeedLimitProvider speedLimitProvider) {
+ if (speedLimitProvider != null) {
+ return new SpeedLimitHandler(speedLimitProvider);
+ }
+ return null;
+ }
+
+ @Singleton
+ @Provides
public static MotionHandler provideMotionHandler(TripsConfig tripsConfig) {
return new MotionHandler(tripsConfig.getSpeedThreshold());
}
diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java
index cd80e68c4..d9e03517c 100644
--- a/src/main/java/org/traccar/config/Keys.java
+++ b/src/main/java/org/traccar/config/Keys.java
@@ -389,6 +389,24 @@ public final class Keys {
"geolocation.processInvalidPositions", Boolean.class);
/**
+ * Boolean flag to enable speed limit API to get speed limit values depending on location. Default value is false.
+ */
+ public static final ConfigKey SPEED_LIMIT_ENABLE = new ConfigKey(
+ "speedLimit.enable", Boolean.class);
+
+ /**
+ * Provider to use for speed limit. Available options: overpass. By default overpass is used.
+ */
+ public static final ConfigKey SPEED_LIMIT_TYPE = new ConfigKey(
+ "speedLimit.type", String.class);
+
+ /**
+ * Speed limit provider API URL address.
+ */
+ public static final ConfigKey SPEED_LIMIT_URL = new ConfigKey(
+ "speedLimit.url", String.class);
+
+ /**
* 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/handler/SpeedLimitHandler.java b/src/main/java/org/traccar/handler/SpeedLimitHandler.java
new file mode 100644
index 000000000..65f2c9cfe
--- /dev/null
+++ b/src/main/java/org/traccar/handler/SpeedLimitHandler.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 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.
+ * 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.handler;
+
+import io.netty.channel.ChannelHandler;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInboundHandlerAdapter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.traccar.model.Position;
+import org.traccar.speedlimit.SpeedLimitProvider;
+
+@ChannelHandler.Sharable
+public class SpeedLimitHandler extends ChannelInboundHandlerAdapter {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(SpeedLimitHandler.class);
+
+ private final SpeedLimitProvider speedLimitProvider;
+
+ public SpeedLimitHandler(SpeedLimitProvider speedLimitProvider) {
+ this.speedLimitProvider = speedLimitProvider;
+ }
+
+ @Override
+ public void channelRead(final ChannelHandlerContext ctx, Object message) {
+ if (message instanceof Position) {
+ final Position position = (Position) message;
+ speedLimitProvider.getSpeedLimit(position.getLatitude(), position.getLongitude(),
+ new SpeedLimitProvider.SpeedLimitProviderCallback() {
+ @Override
+ public void onSuccess(double speedLimit) {
+ position.set(Position.KEY_SPEED_LIMIT, speedLimit);
+ ctx.fireChannelRead(position);
+ }
+
+ @Override
+ public void onFailure(Throwable e) {
+ LOGGER.warn("Speed limit provider failed", e);
+ ctx.fireChannelRead(position);
+ }
+ });
+ } else {
+ ctx.fireChannelRead(message);
+ }
+ }
+
+}
diff --git a/src/main/java/org/traccar/model/Position.java b/src/main/java/org/traccar/model/Position.java
index 2c0e22c9e..6f70c8e21 100644
--- a/src/main/java/org/traccar/model/Position.java
+++ b/src/main/java/org/traccar/model/Position.java
@@ -85,6 +85,7 @@ public class Position extends Message {
public static final String KEY_G_SENSOR = "gSensor";
public static final String KEY_ICCID = "iccid";
public static final String KEY_PHONE = "phone";
+ public static final String KEY_SPEED_LIMIT = "speedLimit";
public static final String KEY_DTCS = "dtcs";
public static final String KEY_OBD_SPEED = "obdSpeed"; // knots