aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-09-27 13:01:40 +1300
committerGitHub <noreply@github.com>2016-09-27 13:01:40 +1300
commit73d63c16505d869a82df1038cf876f1413d38bd5 (patch)
tree41bd458abf2d3c8b0194acedc1387e23a5070ad8
parent18499577b16a198762609075ff1846f354d3d712 (diff)
parentad070aa889b0f8727f0b8389f19d3ed4bfb09806 (diff)
downloadtrackermap-server-73d63c16505d869a82df1038cf876f1413d38bd5.tar.gz
trackermap-server-73d63c16505d869a82df1038cf876f1413d38bd5.tar.bz2
trackermap-server-73d63c16505d869a82df1038cf876f1413d38bd5.zip
Merge pull request #2349 from dcbastos/master
Adds unknown devices automatically.
-rw-r--r--debug.xml3
-rw-r--r--src/org/traccar/BaseProtocolDecoder.java20
2 files changed, 23 insertions, 0 deletions
diff --git a/debug.xml b/debug.xml
index 2314735ca..39a52fe96 100644
--- a/debug.xml
+++ b/debug.xml
@@ -82,6 +82,9 @@
<entry key='database.password'></entry>
<entry key='database.ignoreUnknown'>true</entry>
+
+ <!-- Automatically registers unknown devices. -->
+ <entry key='database.registerUnknown'>false</entry>
<entry key='database.xml'>false</entry>
<entry key='database.saveOriginal'>true</entry>
diff --git a/src/org/traccar/BaseProtocolDecoder.java b/src/org/traccar/BaseProtocolDecoder.java
index 72b9a7a74..15f5471e9 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);