aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/BaseProtocolDecoder.java
diff options
context:
space:
mode:
authorPhilipp Prangenberg <philipp.prangenberg@derkurier.de>2016-12-05 12:03:08 +0100
committerPhilipp Prangenberg <philipp.prangenberg@derkurier.de>2016-12-05 12:03:08 +0100
commita21f436a58133f7da0cae06366d729665f3b8f9c (patch)
tree72ff1743d96f79e4a9d85b0d48715e5f9aa67cf9 /src/org/traccar/BaseProtocolDecoder.java
parent960bf899414d89221e92138fdb98777c3f4f73ec (diff)
parent40607036c5aa6385a7ae3f3a283bf107238a5944 (diff)
downloadtrackermap-server-a21f436a58133f7da0cae06366d729665f3b8f9c.tar.gz
trackermap-server-a21f436a58133f7da0cae06366d729665f3b8f9c.tar.bz2
trackermap-server-a21f436a58133f7da0cae06366d729665f3b8f9c.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'src/org/traccar/BaseProtocolDecoder.java')
-rw-r--r--src/org/traccar/BaseProtocolDecoder.java36
1 files changed, 35 insertions, 1 deletions
diff --git a/src/org/traccar/BaseProtocolDecoder.java b/src/org/traccar/BaseProtocolDecoder.java
index 46832a4ca..d8130c79e 100644
--- a/src/org/traccar/BaseProtocolDecoder.java
+++ b/src/org/traccar/BaseProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2016 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.
@@ -26,11 +26,27 @@ import java.net.SocketAddress;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
+import java.sql.SQLException;
public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder {
private final Protocol protocol;
+ public long addUnknownDevice(String uniqueId) {
+ Device device = new Device();
+ device.setName(uniqueId);
+ device.setUniqueId(uniqueId);
+
+ try {
+ Context.getDeviceManager().addDevice(device);
+ Log.info("Automatically registered device " + uniqueId);
+ return device.getId();
+ } catch (SQLException e) {
+ Log.warning(e);
+ return 0;
+ }
+ }
+
public String getProtocolName() {
return protocol.getName();
}
@@ -55,6 +71,10 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder {
Log.warning(e);
}
if (deviceId == 0) {
+ if (Context.getConfig().getBoolean("database.registerUnknown")) {
+ return addUnknownDevice(uniqueIds[0]);
+ }
+
StringBuilder message = new StringBuilder("Unknown device -");
for (String uniqueId : uniqueIds) {
message.append(" ").append(uniqueId);
@@ -69,6 +89,17 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder {
}
public DeviceSession getDeviceSession(Channel channel, SocketAddress remoteAddress, String... uniqueIds) {
+ if (Context.getConfig().getBoolean("decoder.ignoreSessionCache")) {
+ long deviceId = findDeviceId(remoteAddress, uniqueIds);
+ if (deviceId != 0) {
+ if (Context.getConnectionManager() != null) {
+ Context.getConnectionManager().addActiveDevice(deviceId, protocol, channel, remoteAddress);
+ }
+ return new DeviceSession(deviceId);
+ } else {
+ return null;
+ }
+ }
if (channel instanceof DatagramChannel) {
long deviceId = findDeviceId(remoteAddress, uniqueIds);
DeviceSession deviceSession = addressDeviceSessions.get(remoteAddress);
@@ -129,6 +160,9 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder {
@Override
protected void onMessageEvent(Channel channel, SocketAddress remoteAddress, Object msg) {
+ if (Context.getStatisticsManager() != null) {
+ Context.getStatisticsManager().registerMessageReceived();
+ }
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
if (deviceSession != null) {
Context.getConnectionManager().updateDevice(deviceSession.getDeviceId(), Device.STATUS_ONLINE, new Date());