aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/BaseProtocolDecoder.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/BaseProtocolDecoder.java')
-rw-r--r--src/org/traccar/BaseProtocolDecoder.java29
1 files changed, 22 insertions, 7 deletions
diff --git a/src/org/traccar/BaseProtocolDecoder.java b/src/org/traccar/BaseProtocolDecoder.java
index 54d2bf28f..2d6286bf8 100644
--- a/src/org/traccar/BaseProtocolDecoder.java
+++ b/src/org/traccar/BaseProtocolDecoder.java
@@ -17,7 +17,9 @@ package org.traccar;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.socket.DatagramChannel;
+import org.jboss.netty.handler.codec.http.HttpRequestDecoder;
import org.traccar.helper.Log;
+import org.traccar.helper.UnitsConverter;
import org.traccar.model.Device;
import org.traccar.model.Position;
@@ -45,15 +47,13 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder {
}
try {
- Context.getDeviceManager().addDevice(device);
+ Context.getDeviceManager().addItem(device);
Log.info("Automatically registered device " + uniqueId);
if (defaultGroupId != 0) {
- Context.getPermissionsManager().refreshPermissions();
- if (Context.getGeofenceManager() != null) {
- Context.getGeofenceManager().refresh();
- }
+ Context.getPermissionsManager().refreshDeviceAndGroupPermissions();
+ Context.getPermissionsManager().refreshAllExtendedPermissions();
}
return device.getId();
@@ -67,6 +67,20 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder {
return protocol.getName();
}
+ protected double convertSpeed(double value, String defaultUnits) {
+ switch (Context.getConfig().getString(getProtocolName() + ".speed", defaultUnits)) {
+ case "kmh":
+ return UnitsConverter.knotsFromKph(value);
+ case "mps":
+ return UnitsConverter.knotsFromMps(value);
+ case "mph":
+ return UnitsConverter.knotsFromMph(value);
+ case "kn":
+ default:
+ return value;
+ }
+ }
+
private DeviceSession channelDeviceSession; // connection-based protocols
private Map<SocketAddress, DeviceSession> addressDeviceSessions = new HashMap<>(); // connectionless protocols
@@ -76,7 +90,7 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder {
try {
for (String uniqueId : uniqueIds) {
if (uniqueId != null) {
- Device device = Context.getIdentityManager().getDeviceByUniqueId(uniqueId);
+ Device device = Context.getIdentityManager().getByUniqueId(uniqueId);
if (device != null) {
deviceId = device.getId();
break;
@@ -105,7 +119,8 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder {
}
public DeviceSession getDeviceSession(Channel channel, SocketAddress remoteAddress, String... uniqueIds) {
- if (Context.getConfig().getBoolean("decoder.ignoreSessionCache")) {
+ if (channel != null && channel.getPipeline().get(HttpRequestDecoder.class) != null
+ || Context.getConfig().getBoolean("decoder.ignoreSessionCache")) {
long deviceId = findDeviceId(remoteAddress, uniqueIds);
if (deviceId != 0) {
if (Context.getConnectionManager() != null) {