aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar
diff options
context:
space:
mode:
authorDaniel Bastos <dbastos@toledo.com>2016-09-21 08:59:28 -0300
committerDaniel Bastos <dbastos@toledo.com>2016-09-22 09:07:54 -0300
commitad070aa889b0f8727f0b8389f19d3ed4bfb09806 (patch)
treef03b376eab6d6a19ab4caf42fa772359fbe54334 /src/org/traccar
parent411edf2fecc6f5d2cceba20f06958f729ebcca54 (diff)
downloadtrackermap-server-ad070aa889b0f8727f0b8389f19d3ed4bfb09806.tar.gz
trackermap-server-ad070aa889b0f8727f0b8389f19d3ed4bfb09806.tar.bz2
trackermap-server-ad070aa889b0f8727f0b8389f19d3ed4bfb09806.zip
Adds unknown devices automatically.
Diffstat (limited to 'src/org/traccar')
-rw-r--r--src/org/traccar/BaseProtocolDecoder.java20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/org/traccar/BaseProtocolDecoder.java b/src/org/traccar/BaseProtocolDecoder.java
index 46832a4ca..00f45727f 100644
--- a/src/org/traccar/BaseProtocolDecoder.java
+++ b/src/org/traccar/BaseProtocolDecoder.java
@@ -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);