aboutsummaryrefslogtreecommitdiff
path: root/src/org
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-04-23 15:49:56 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2015-04-23 15:49:56 +1200
commit2a3fad9496decd83f06ae5abf067f8d4337ec741 (patch)
tree69837f0bf89cf6ff78915d70380118575cc5c47a /src/org
parenta8d2a0170b7ac891ffe784320ac2d1389f11bf68 (diff)
downloadtraccar-server-2a3fad9496decd83f06ae5abf067f8d4337ec741.tar.gz
traccar-server-2a3fad9496decd83f06ae5abf067f8d4337ec741.tar.bz2
traccar-server-2a3fad9496decd83f06ae5abf067f8d4337ec741.zip
Major code refacroting
Diffstat (limited to 'src/org')
-rw-r--r--src/org/traccar/BasePipelineFactory.java34
-rw-r--r--src/org/traccar/BaseProtocolDecoder.java51
-rw-r--r--src/org/traccar/Context.java109
-rw-r--r--src/org/traccar/FilterHandler.java3
-rw-r--r--src/org/traccar/GlobalChannelFactory.java1
-rw-r--r--src/org/traccar/Main.java14
-rw-r--r--src/org/traccar/ServerManager.java633
-rw-r--r--src/org/traccar/TrackerEventHandler.java14
-rw-r--r--src/org/traccar/TrackerServer.java10
-rw-r--r--src/org/traccar/database/DataManager.java7
-rw-r--r--src/org/traccar/protocol/ApelProtocolDecoder.java18
-rw-r--r--src/org/traccar/protocol/AplicomProtocolDecoder.java12
-rw-r--r--src/org/traccar/protocol/Ardi01ProtocolDecoder.java13
-rw-r--r--src/org/traccar/protocol/AtrackProtocolDecoder.java19
-rw-r--r--src/org/traccar/protocol/AutoFon45ProtocolDecoder.java12
-rw-r--r--src/org/traccar/protocol/AutoFonProtocolDecoder.java13
-rw-r--r--src/org/traccar/protocol/BceProtocolDecoder.java12
-rw-r--r--src/org/traccar/protocol/BoxProtocolDecoder.java15
-rw-r--r--src/org/traccar/protocol/CalAmpProtocolDecoder.java22
-rw-r--r--src/org/traccar/protocol/CarTrackProtocolDecoder.java11
-rw-r--r--src/org/traccar/protocol/CarscopProtocolDecoder.java17
-rw-r--r--src/org/traccar/protocol/CellocatorProtocolDecoder.java16
-rw-r--r--src/org/traccar/protocol/EasyTrackProtocolDecoder.java14
-rw-r--r--src/org/traccar/protocol/EelinkProtocolDecoder.java19
-rw-r--r--src/org/traccar/protocol/EnforaProtocolDecoder.java10
-rw-r--r--src/org/traccar/protocol/Ev603ProtocolDecoder.java18
-rw-r--r--src/org/traccar/protocol/FreedomProtocolDecoder.java13
-rw-r--r--src/org/traccar/protocol/GalileoProtocolDecoder.java18
-rw-r--r--src/org/traccar/protocol/GatorProtocolDecoder.java13
-rw-r--r--src/org/traccar/protocol/Gl100ProtocolDecoder.java11
-rw-r--r--src/org/traccar/protocol/Gl200ProtocolDecoder.java11
-rw-r--r--src/org/traccar/protocol/GlobalSatProtocolDecoder.java19
-rw-r--r--src/org/traccar/protocol/GoSafeProtocolDecoder.java13
-rw-r--r--src/org/traccar/protocol/GotopProtocolDecoder.java11
-rw-r--r--src/org/traccar/protocol/Gps103ProtocolDecoder.java11
-rw-r--r--src/org/traccar/protocol/GpsGateProtocolDecoder.java23
-rw-r--r--src/org/traccar/protocol/Gt02ProtocolDecoder.java10
-rw-r--r--src/org/traccar/protocol/Gt06ProtocolDecoder.java31
-rw-r--r--src/org/traccar/protocol/H02ProtocolDecoder.java20
-rw-r--r--src/org/traccar/protocol/HaicomProtocolDecoder.java11
-rw-r--r--src/org/traccar/protocol/IntellitracProtocolDecoder.java11
-rw-r--r--src/org/traccar/protocol/Jt600ProtocolDecoder.java19
-rw-r--r--src/org/traccar/protocol/KhdProtocolDecoder.java14
-rw-r--r--src/org/traccar/protocol/LaipacProtocolDecoder.java12
-rw-r--r--src/org/traccar/protocol/M2mProtocolDecoder.java17
-rw-r--r--src/org/traccar/protocol/ManPowerProtocolDecoder.java13
-rw-r--r--src/org/traccar/protocol/MaxonProtocolDecoder.java28
-rw-r--r--src/org/traccar/protocol/MegastekProtocolDecoder.java24
-rw-r--r--src/org/traccar/protocol/MeiligaoProtocolDecoder.java14
-rw-r--r--src/org/traccar/protocol/MeitrackProtocolDecoder.java21
-rw-r--r--src/org/traccar/protocol/MiniFinderProtocolDecoder.java17
-rw-r--r--src/org/traccar/protocol/Mta6ProtocolDecoder.java22
-rw-r--r--src/org/traccar/protocol/MtxProtocolDecoder.java11
-rw-r--r--src/org/traccar/protocol/NavigilProtocolDecoder.java47
-rw-r--r--src/org/traccar/protocol/NavisProtocolDecoder.java21
-rw-r--r--src/org/traccar/protocol/NoranProtocolDecoder.java12
-rw-r--r--src/org/traccar/protocol/OrionProtocolDecoder.java17
-rw-r--r--src/org/traccar/protocol/OsmAndProtocolDecoder.java10
-rw-r--r--src/org/traccar/protocol/PiligrimProtocolDecoder.java15
-rw-r--r--src/org/traccar/protocol/ProgressProtocolDecoder.java23
-rw-r--r--src/org/traccar/protocol/Pt3000ProtocolDecoder.java16
-rw-r--r--src/org/traccar/protocol/Pt502ProtocolDecoder.java11
-rw-r--r--src/org/traccar/protocol/RitiProtocolDecoder.java14
-rw-r--r--src/org/traccar/protocol/RuptelaProtocolDecoder.java14
-rw-r--r--src/org/traccar/protocol/SanavProtocolDecoder.java11
-rw-r--r--src/org/traccar/protocol/SkypatrolProtocolDecoder.java10
-rw-r--r--src/org/traccar/protocol/Stl060ProtocolDecoder.java11
-rw-r--r--src/org/traccar/protocol/SuntechProtocolDecoder.java11
-rw-r--r--src/org/traccar/protocol/SyrusProtocolDecoder.java15
-rw-r--r--src/org/traccar/protocol/T55ProtocolDecoder.java32
-rw-r--r--src/org/traccar/protocol/TelikProtocolDecoder.java11
-rw-r--r--src/org/traccar/protocol/TeltonikaProtocolDecoder.java13
-rw-r--r--src/org/traccar/protocol/Tk102ProtocolDecoder.java18
-rw-r--r--src/org/traccar/protocol/Tk103ProtocolDecoder.java18
-rw-r--r--src/org/traccar/protocol/Tlt2hProtocolDecoder.java15
-rw-r--r--src/org/traccar/protocol/TopflytechProtocolDecoder.java13
-rw-r--r--src/org/traccar/protocol/TotemProtocolDecoder.java13
-rw-r--r--src/org/traccar/protocol/Tr20ProtocolDecoder.java13
-rw-r--r--src/org/traccar/protocol/Tr900ProtocolDecoder.java11
-rw-r--r--src/org/traccar/protocol/TrackboxProtocolDecoder.java13
-rw-r--r--src/org/traccar/protocol/TramigoProtocolDecoder.java11
-rw-r--r--src/org/traccar/protocol/TytanProtocolDecoder.java17
-rw-r--r--src/org/traccar/protocol/UlbotechProtocolDecoder.java14
-rw-r--r--src/org/traccar/protocol/V680ProtocolDecoder.java23
-rw-r--r--src/org/traccar/protocol/VisiontekProtocolDecoder.java23
-rw-r--r--src/org/traccar/protocol/WialonProtocolDecoder.java15
-rw-r--r--src/org/traccar/protocol/WondexProtocolDecoder.java11
-rw-r--r--src/org/traccar/protocol/Xexun2ProtocolDecoder.java13
-rw-r--r--src/org/traccar/protocol/XexunProtocolDecoder.java11
-rw-r--r--src/org/traccar/protocol/XirgoProtocolDecoder.java11
-rw-r--r--src/org/traccar/protocol/Xt013ProtocolDecoder.java11
-rw-r--r--src/org/traccar/protocol/Xt7ProtocolDecoder.java12
-rw-r--r--src/org/traccar/protocol/YwtProtocolDecoder.java11
93 files changed, 902 insertions, 1264 deletions
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java
index 469bbc49f..fcb6266ef 100644
--- a/src/org/traccar/BasePipelineFactory.java
+++ b/src/org/traccar/BasePipelineFactory.java
@@ -26,13 +26,11 @@ import org.traccar.database.DataManager;
import org.traccar.geocode.ReverseGeocoder;
import org.traccar.helper.Log;
+import javax.crypto.Cipher;
+
public abstract class BasePipelineFactory implements ChannelPipelineFactory {
private final TrackerServer server;
- private final DataManager dataManager;
- private final DataCache dataCache;
- private final Boolean loggerEnabled;
- private final ReverseGeocoder reverseGeocoder;
private FilterHandler filterHandler;
private Integer resetDelay;
private Boolean processInvalidPositions;
@@ -83,34 +81,26 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory {
}
- public BasePipelineFactory(ServerManager serverManager, TrackerServer server, String protocol) {
+ public BasePipelineFactory(TrackerServer server, String protocol) {
this.server = server;
- dataManager = serverManager.getDataManager();
- dataCache = serverManager.getDataCache();
- loggerEnabled = serverManager.isLoggerEnabled();
- reverseGeocoder = serverManager.getReverseGeocoder();
- String resetDelayProperty = serverManager.getProperties().getProperty(protocol + ".resetDelay");
+ String resetDelayProperty = Context.getProps().getProperty(protocol + ".resetDelay");
if (resetDelayProperty != null) {
resetDelay = Integer.valueOf(resetDelayProperty);
}
- String enableFilter = serverManager.getProperties().getProperty("filter.enable");
+ String enableFilter = Context.getProps().getProperty("filter.enable");
if (enableFilter != null && Boolean.valueOf(enableFilter)) {
- filterHandler = new FilterHandler(serverManager.getProperties());
+ filterHandler = new FilterHandler();
}
- if (reverseGeocoder != null) {
+ if (Context.getReverseGeocoder() != null) {
// Default behavior is to process invalid positions (i.e., the "null" case)
- String invalidPositions = serverManager.getProperties().getProperty("geocode.processInvalidPositions");
+ String invalidPositions = Context.getProps().getProperty("geocode.processInvalidPositions");
processInvalidPositions = (invalidPositions == null || Boolean.valueOf(invalidPositions));
}
}
- protected DataManager getDataManager() {
- return dataManager;
- }
-
protected abstract void addSpecificHandlers(ChannelPipeline pipeline);
@Override
@@ -120,17 +110,17 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory {
pipeline.addLast("idleHandler", new IdleStateHandler(GlobalTimer.getTimer(), resetDelay, 0, 0));
}
pipeline.addLast("openHandler", new OpenChannelHandler(server));
- if (loggerEnabled) {
+ if (Context.isLoggerEnabled()) {
pipeline.addLast("logger", new StandardLoggingHandler());
}
addSpecificHandlers(pipeline);
if (filterHandler != null) {
pipeline.addLast("filter", filterHandler);
}
- if (reverseGeocoder != null) {
- pipeline.addLast("geocoder", new ReverseGeocoderHandler(reverseGeocoder, processInvalidPositions));
+ if (Context.getReverseGeocoder() != null) {
+ pipeline.addLast("geocoder", new ReverseGeocoderHandler(Context.getReverseGeocoder(), processInvalidPositions));
}
- pipeline.addLast("handler", new TrackerEventHandler(dataManager, dataCache));
+ pipeline.addLast("handler", new TrackerEventHandler());
return pipeline;
}
diff --git a/src/org/traccar/BaseProtocolDecoder.java b/src/org/traccar/BaseProtocolDecoder.java
index 04b1a1eec..bcd441268 100644
--- a/src/org/traccar/BaseProtocolDecoder.java
+++ b/src/org/traccar/BaseProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2013 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2015 Anton Tananaev (anton.tananaev@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,33 +26,54 @@ import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.handler.codec.oneone.OneToOneDecoder;
import org.traccar.database.DataManager;
+import org.traccar.helper.Log;
+import org.traccar.model.Device;
/**
* Base class for protocol decoders
*/
public abstract class BaseProtocolDecoder extends OneToOneDecoder {
- private final DataManager dataManager;
private final String protocol;
- private final Properties properties;
- public final DataManager getDataManager() {
- return dataManager;
+ public String getProtocol() {
+ return protocol;
}
- public final String getProtocol() {
- return protocol;
+ private long deviceId;
+
+ public boolean hasDeviceId() {
+ return (deviceId != 0);
}
-
- public final Properties getProperties() {
- return properties;
+
+ public long getDeviceId() {
+ return deviceId;
}
-
- public BaseProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- this.dataManager = dataManager;
+ public boolean identify(String uniqueId, boolean logWarning) {
+ try {
+ Device device = Context.getDataManager().getDeviceByUniqueId(uniqueId);
+ if (device != null) {
+ deviceId = device.getId();
+ return true;
+ } else {
+ if (logWarning) {
+ Log.warning("Unknown device - " + uniqueId);
+ }
+ return false;
+ }
+ } catch (Exception error) {
+ Log.warning(error);
+ return false;
+ }
+ }
+
+ public boolean identify(String uniqueId) {
+ return identify(uniqueId, true);
+ }
+
+ public BaseProtocolDecoder(String protocol) {
this.protocol = protocol;
- this.properties = properties;
}
@Override
@@ -77,7 +98,6 @@ public abstract class BaseProtocolDecoder extends OneToOneDecoder {
ChannelHandlerContext ctx, Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
return decode(ctx, channel, msg);
-
}
@Override
@@ -85,7 +105,6 @@ public abstract class BaseProtocolDecoder extends OneToOneDecoder {
ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
return null; // default implementation
-
}
}
diff --git a/src/org/traccar/Context.java b/src/org/traccar/Context.java
new file mode 100644
index 000000000..f05a191aa
--- /dev/null
+++ b/src/org/traccar/Context.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ *
+ * 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;
+
+import org.traccar.database.DataCache;
+import org.traccar.database.DataManager;
+import org.traccar.geocode.GoogleReverseGeocoder;
+import org.traccar.geocode.NominatimReverseGeocoder;
+import org.traccar.geocode.ReverseGeocoder;
+import org.traccar.helper.Log;
+import org.traccar.http.WebServer;
+
+import java.io.FileInputStream;
+import java.util.Properties;
+
+public class Context {
+
+ private static Properties properties;
+
+ public static Properties getProps() {
+ return properties;
+ }
+
+ private static boolean loggerEnabled;
+
+ public static boolean isLoggerEnabled() {
+ return loggerEnabled;
+ }
+
+ private static DataManager dataManager;
+
+ public static DataManager getDataManager() {
+ return dataManager;
+ }
+
+ private static DataCache dataCache;
+
+ public static DataCache getDataCache() {
+ return dataCache;
+ }
+
+ private static ReverseGeocoder reverseGeocoder;
+
+ public static ReverseGeocoder getReverseGeocoder() {
+ return reverseGeocoder;
+ }
+
+ private static WebServer webServer;
+
+ public static WebServer getWebServer() {
+ return webServer;
+ }
+
+ private static ServerManager serverManager;
+
+ public static ServerManager getServerManager() {
+ return serverManager;
+ }
+
+ public static void init(String[] arguments) throws Exception {
+
+ properties = new Properties();
+ if (arguments.length > 0) {
+ properties.loadFromXML(new FileInputStream(arguments[0]));
+ }
+
+ loggerEnabled = Boolean.valueOf(properties.getProperty("logger.enable"));
+ if (loggerEnabled) {
+ Log.setupLogger(properties);
+ }
+
+ dataManager = new DataManager(properties);
+ dataCache = new DataCache(dataManager);
+
+ if (Boolean.parseBoolean(properties.getProperty("geocoder.enable"))) {
+ String type = properties.getProperty("geocoder.type");
+ if (type != null && type.equals("nominatim")) {
+ reverseGeocoder = new NominatimReverseGeocoder(properties.getProperty("geocoder.url"));
+ } else {
+ reverseGeocoder = new GoogleReverseGeocoder();
+ }
+ }
+
+ if (Boolean.valueOf(properties.getProperty("http.enable"))) {
+ webServer = new WebServer(properties, dataManager);
+ }
+
+ serverManager = new ServerManager();
+ serverManager.init();
+ }
+
+ public static void init(DataManager dataManager) {
+ Context.dataManager = dataManager;
+ }
+
+}
diff --git a/src/org/traccar/FilterHandler.java b/src/org/traccar/FilterHandler.java
index 5e1910210..88eeb7080 100644
--- a/src/org/traccar/FilterHandler.java
+++ b/src/org/traccar/FilterHandler.java
@@ -51,7 +51,8 @@ public class FilterHandler extends OneToOneDecoder {
this.filterLimit = filterLimit;
}
- public FilterHandler(Properties properties) {
+ public FilterHandler() {
+ Properties properties = Context.getProps();
String value = properties.getProperty("filter.invalid");
if (value != null) filterInvalid = Boolean.valueOf(value);
diff --git a/src/org/traccar/GlobalChannelFactory.java b/src/org/traccar/GlobalChannelFactory.java
index 7d2f3cbb6..af0ce89b0 100644
--- a/src/org/traccar/GlobalChannelFactory.java
+++ b/src/org/traccar/GlobalChannelFactory.java
@@ -15,7 +15,6 @@
*/
package org.traccar;
-import java.util.concurrent.Executors;
import org.jboss.netty.channel.ChannelFactory;
import org.jboss.netty.channel.socket.DatagramChannelFactory;
import org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory;
diff --git a/src/org/traccar/Main.java b/src/org/traccar/Main.java
index 53abb37e4..834b37eff 100644
--- a/src/org/traccar/Main.java
+++ b/src/org/traccar/Main.java
@@ -23,22 +23,26 @@ public class Main {
public static void main(String[] args) throws Exception {
Locale.setDefault(Locale.ENGLISH);
- final ServerManager service = new ServerManager();
- service.init(args);
+ Context.init(args);
Log.info("Starting server...");
Log.logSystemInfo();
-
Log.info("Version: " + Main.class.getPackage().getImplementationVersion());
- service.start();
+ Context.getServerManager().start();
+ if (Context.getWebServer() != null) {
+ Context.getWebServer().start();
+ }
// Shutdown server properly
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
Log.info("Shutting down server...");
- service.stop();
+ if (Context.getWebServer() != null) {
+ Context.getWebServer().stop();
+ }
+ Context.getServerManager().stop();
}
});
}
diff --git a/src/org/traccar/ServerManager.java b/src/org/traccar/ServerManager.java
index bef90052f..4c9645e41 100644
--- a/src/org/traccar/ServerManager.java
+++ b/src/org/traccar/ServerManager.java
@@ -15,14 +15,11 @@
*/
package org.traccar;
-import java.io.FileInputStream;
-import java.io.IOException;
import java.nio.ByteOrder;
import java.sql.SQLException;
-import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
-import java.util.Properties;
+
import org.jboss.netty.bootstrap.ConnectionlessBootstrap;
import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.channel.ChannelPipeline;
@@ -34,82 +31,14 @@ import org.jboss.netty.handler.codec.http.HttpRequestDecoder;
import org.jboss.netty.handler.codec.http.HttpResponseEncoder;
import org.jboss.netty.handler.codec.string.StringDecoder;
import org.jboss.netty.handler.codec.string.StringEncoder;
-import org.traccar.database.DataCache;
-import org.traccar.database.DataManager;
-import org.traccar.geocode.GoogleReverseGeocoder;
-import org.traccar.geocode.NominatimReverseGeocoder;
-import org.traccar.geocode.ReverseGeocoder;
-import org.traccar.helper.Log;
-import org.traccar.http.WebServer;
-import org.traccar.model.Position;
import org.traccar.protocol.*;
-/**
- * Server Manager
- */
public class ServerManager {
private final List<TrackerServer> serverList = new LinkedList<TrackerServer>();
- public void addTrackerServer(TrackerServer trackerServer) {
- serverList.add(trackerServer);
- }
-
- private boolean loggerEnabled;
-
- public boolean isLoggerEnabled() {
- return loggerEnabled;
- }
-
- private DataManager dataManager;
-
- public DataManager getDataManager() {
- return dataManager;
- }
-
- private DataCache dataCache;
-
- public DataCache getDataCache() {
- return dataCache;
- }
-
- private ReverseGeocoder reverseGeocoder;
-
- public ReverseGeocoder getReverseGeocoder() {
- return reverseGeocoder;
- }
-
- private WebServer webServer;
-
- public WebServer getWebServer() {
- return webServer;
- }
-
- private Properties properties;
-
- public Properties getProperties() {
- return properties;
- }
-
- public void init(String[] arguments) throws Exception {
-
- // Load properties
- properties = new Properties();
- if (arguments.length > 0) {
- properties.loadFromXML(new FileInputStream(arguments[0]));
- }
-
- // Init logger
- loggerEnabled = Boolean.valueOf(properties.getProperty("logger.enable"));
- if (loggerEnabled) {
- Log.setupLogger(properties);
- }
-
- dataManager = new DataManager(properties);
- dataCache = new DataCache(dataManager);
-
- initGeocoder(properties);
+ public void init() throws Exception {
initGps103Server("gps103");
initTk103Server("tk103");
@@ -197,17 +126,9 @@ public class ServerManager {
initTytanServer("tytan");
initProtocolDetector();
-
- // Initialize web server
- if (Boolean.valueOf(properties.getProperty("http.enable"))) {
- webServer = new WebServer(properties, dataManager);
- }
}
public void start() {
- if (webServer != null) {
- webServer.start();
- }
for (Object server: serverList) {
((TrackerServer) server).start();
}
@@ -221,30 +142,10 @@ public class ServerManager {
// Release resources
GlobalChannelFactory.release();
GlobalTimer.release();
-
- if (webServer != null) {
- webServer.stop();
- }
- }
-
- public void destroy() {
- serverList.clear();
- }
-
- private void initGeocoder(Properties properties) throws IOException {
- if (Boolean.parseBoolean(properties.getProperty("geocoder.enable"))) {
- String type = properties.getProperty("geocoder.type");
- if (type != null && type.equals("nominatim")) {
- reverseGeocoder = new NominatimReverseGeocoder(
- getProperties().getProperty("geocoder.url"));
- } else {
- reverseGeocoder = new GoogleReverseGeocoder();
- }
- }
}
- private boolean isProtocolEnabled(Properties properties, String protocol) {
- String enabled = properties.getProperty(protocol + ".enable");
+ private boolean isProtocolEnabled(String protocol) {
+ String enabled = Context.getProps().getProperty(protocol + ".enable");
if (enabled != null) {
return Boolean.valueOf(enabled);
}
@@ -253,14 +154,14 @@ public class ServerManager {
private void initProtocolDetector() throws SQLException {
String protocol = "detector";
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("detectorHandler", new DetectorHandler(serverList));
}
});
- serverList.add(new TrackerServer(this, new ConnectionlessBootstrap(), protocol) {
+ serverList.add(new TrackerServer(new ConnectionlessBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("detectorHandler", new DetectorHandler(serverList));
@@ -269,104 +170,104 @@ public class ServerManager {
}
}
private void initGps103Server(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, "\r\n", "\n", ";"));
pipeline.addLast("stringDecoder", new StringDecoder());
pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new Gps103ProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new Gps103ProtocolDecoder(protocol));
}
});
- serverList.add(new TrackerServer(this, new ConnectionlessBootstrap(), protocol) {
+ serverList.add(new TrackerServer(new ConnectionlessBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("stringDecoder", new StringDecoder());
pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new Gps103ProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new Gps103ProtocolDecoder(protocol));
}
});
}
}
private void initTk103Server(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, ')'));
pipeline.addLast("stringDecoder", new StringDecoder());
pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new Tk103ProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new Tk103ProtocolDecoder(protocol));
}
});
- serverList.add(new TrackerServer(this, new ConnectionlessBootstrap(), protocol) {
+ serverList.add(new TrackerServer(new ConnectionlessBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("stringDecoder", new StringDecoder());
pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new Tk103ProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new Tk103ProtocolDecoder(protocol));
}
});
}
}
private void initGl100Server(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '\0'));
pipeline.addLast("stringDecoder", new StringDecoder());
pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new Gl100ProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new Gl100ProtocolDecoder(protocol));
}
});
}
}
private void initGl200Server(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, "$", "\0"));
pipeline.addLast("stringDecoder", new StringDecoder());
pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new Gl200ProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new Gl200ProtocolDecoder(protocol));
}
});
}
}
private void initT55Server(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024));
pipeline.addLast("stringDecoder", new StringDecoder());
pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new T55ProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new T55ProtocolDecoder(protocol));
}
});
}
}
private void initXexunServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
- if (Boolean.valueOf(properties.getProperty(protocol + ".extended"))) {
+ if (Boolean.valueOf(Context.getProps().getProperty(protocol + ".extended"))) {
pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024)); // tracker bug \n\r
pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new Xexun2ProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new Xexun2ProtocolDecoder(protocol));
} else {
pipeline.addLast("frameDecoder", new XexunFrameDecoder());
pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new XexunProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new XexunProtocolDecoder(protocol));
}
}
});
@@ -374,76 +275,76 @@ public class ServerManager {
}
private void initTotemServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new TotemFrameDecoder());
pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new TotemProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new TotemProtocolDecoder(protocol));
}
});
}
}
private void initEnforaServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 0, 2, -2, 2));
- pipeline.addLast("objectDecoder", new EnforaProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new EnforaProtocolDecoder(protocol));
}
});
}
}
private void initMeiligaoServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new MeiligaoFrameDecoder());
- pipeline.addLast("objectDecoder", new MeiligaoProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new MeiligaoProtocolDecoder(protocol));
}
});
}
}
private void initMaxonServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024));
pipeline.addLast("stringDecoder", new StringDecoder());
pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new MaxonProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new MaxonProtocolDecoder(protocol));
}
});
}
}
private void initSuntechServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '\r'));
pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new SuntechProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new SuntechProtocolDecoder(protocol));
}
});
}
}
private void initProgressServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- TrackerServer server = new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ TrackerServer server = new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 2, 2, 4, 0));
- pipeline.addLast("objectDecoder", new ProgressProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new ProgressProtocolDecoder(protocol));
}
};
server.setEndianness(ByteOrder.LITTLE_ENDIAN);
@@ -452,63 +353,63 @@ public class ServerManager {
}
private void initH02Server(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new H02FrameDecoder());
- pipeline.addLast("objectDecoder", new H02ProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new H02ProtocolDecoder(protocol));
}
});
}
}
private void initJt600Server(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new Jt600FrameDecoder());
- pipeline.addLast("objectDecoder", new Jt600ProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new Jt600ProtocolDecoder(protocol));
}
});
}
}
private void initEv603Server(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, ';'));
pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new Ev603ProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new Ev603ProtocolDecoder(protocol));
}
});
}
}
private void initV680Server(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, "##"));
pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new V680ProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new V680ProtocolDecoder(protocol));
}
});
}
}
private void initPt502Server(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- TrackerServer server = new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ TrackerServer server = new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new Pt502FrameDecoder());
pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new Pt502ProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new Pt502ProtocolDecoder(protocol));
}
};
server.setEndianness(ByteOrder.LITTLE_ENDIAN);
@@ -517,26 +418,26 @@ public class ServerManager {
}
private void initTr20Server(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024));
pipeline.addLast("stringDecoder", new StringDecoder());
pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new Tr20ProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new Tr20ProtocolDecoder(protocol));
}
});
}
}
private void initNavisServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- TrackerServer server = new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ TrackerServer server = new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(4 * 1024, 12, 2, 2, 0));
- pipeline.addLast("objectDecoder", new NavisProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new NavisProtocolDecoder(protocol));
}
};
server.setEndianness(ByteOrder.LITTLE_ENDIAN);
@@ -545,13 +446,13 @@ public class ServerManager {
}
private void initMeitrackServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- TrackerServer server = new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ TrackerServer server = new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new MeitrackFrameDecoder());
pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new MeitrackProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new MeitrackProtocolDecoder(protocol));
}
};
server.setEndianness(ByteOrder.LITTLE_ENDIAN);
@@ -560,61 +461,61 @@ public class ServerManager {
}
private void initSkypatrolServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ConnectionlessBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ConnectionlessBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("objectDecoder", new SkypatrolProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new SkypatrolProtocolDecoder(protocol));
}
});
}
}
private void initGt02Server(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(256, 2, 1, 2, 0));
- pipeline.addLast("objectDecoder", new Gt02ProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new Gt02ProtocolDecoder(protocol));
}
});
}
}
private void initGt06Server(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new Gt06FrameDecoder());
- pipeline.addLast("objectDecoder", new Gt06ProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new Gt06ProtocolDecoder(protocol));
}
});
}
}
private void initMegastekServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024));
pipeline.addLast("stringDecoder", new StringDecoder());
pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new MegastekProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new MegastekProtocolDecoder(protocol));
}
});
}
}
private void initNavigilServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- TrackerServer server = new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ TrackerServer server = new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new NavigilFrameDecoder());
- pipeline.addLast("objectDecoder", new NavigilProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new NavigilProtocolDecoder(protocol));
}
};
server.setEndianness(ByteOrder.LITTLE_ENDIAN);
@@ -623,105 +524,105 @@ public class ServerManager {
}
private void initGpsGateServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024));
pipeline.addLast("stringDecoder", new StringDecoder());
pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new GpsGateProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new GpsGateProtocolDecoder(protocol));
}
});
}
}
private void initTeltonikaServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new TeltonikaFrameDecoder());
- pipeline.addLast("objectDecoder", new TeltonikaProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new TeltonikaProtocolDecoder(protocol));
}
});
}
}
private void initMta6Server(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("httpDecoder", new HttpRequestDecoder());
pipeline.addLast("httpEncoder", new HttpResponseEncoder());
- pipeline.addLast("objectDecoder", new Mta6ProtocolDecoder(dataManager, protocol, properties, false));
+ pipeline.addLast("objectDecoder", new Mta6ProtocolDecoder(protocol, false));
}
});
}
}
private void initMta6CanServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("httpDecoder", new HttpRequestDecoder());
pipeline.addLast("httpEncoder", new HttpResponseEncoder());
- pipeline.addLast("objectDecoder", new Mta6ProtocolDecoder(dataManager, protocol, properties, true));
+ pipeline.addLast("objectDecoder", new Mta6ProtocolDecoder(protocol, true));
}
});
}
}
private void initTlt2hServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(32 * 1024, "##"));
pipeline.addLast("stringDecoder", new StringDecoder());
pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new Tlt2hProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new Tlt2hProtocolDecoder(protocol));
}
});
}
}
private void initSyrusServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '<'));
pipeline.addLast("stringDecoder", new StringDecoder());
pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new SyrusProtocolDecoder(dataManager, protocol, properties, true));
+ pipeline.addLast("objectDecoder", new SyrusProtocolDecoder(protocol, true));
}
});
}
}
private void initWondexServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new WondexFrameDecoder());
pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new WondexProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new WondexProtocolDecoder(protocol));
}
});
}
}
private void initCellocatorServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- TrackerServer server = new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ TrackerServer server = new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new CellocatorFrameDecoder());
- pipeline.addLast("objectDecoder", new CellocatorProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new CellocatorProtocolDecoder(protocol));
}
};
server.setEndianness(ByteOrder.LITTLE_ENDIAN);
@@ -730,12 +631,12 @@ public class ServerManager {
}
private void initGalileoServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- TrackerServer server = new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ TrackerServer server = new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new GalileoFrameDecoder());
- pipeline.addLast("objectDecoder", new GalileoProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new GalileoProtocolDecoder(protocol));
}
};
server.setEndianness(ByteOrder.LITTLE_ENDIAN);
@@ -744,94 +645,94 @@ public class ServerManager {
}
private void initYwtServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024));
pipeline.addLast("stringDecoder", new StringDecoder());
pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new YwtProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new YwtProtocolDecoder(protocol));
}
});
}
}
private void initTk102Server(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, ']'));
pipeline.addLast("stringDecoder", new StringDecoder());
pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new Tk102ProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new Tk102ProtocolDecoder(protocol));
}
});
}
}
private void initIntellitracServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new IntellitracFrameDecoder(1024));
pipeline.addLast("stringDecoder", new StringDecoder());
pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new IntellitracProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new IntellitracProtocolDecoder(protocol));
}
});
}
}
private void initXt7Server(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(256, 20, 1, 5, 0));
- pipeline.addLast("objectDecoder", new Xt7ProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new Xt7ProtocolDecoder(protocol));
}
});
}
}
private void initWialonServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(4 * 1024));
pipeline.addLast("stringDecoder", new StringDecoder());
pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new WialonProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new WialonProtocolDecoder(protocol));
}
});
}
}
private void initCarscopServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '^'));
pipeline.addLast("stringDecoder", new StringDecoder());
pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new CarscopProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new CarscopProtocolDecoder(protocol));
}
});
}
}
private void initApelServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- TrackerServer server = new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ TrackerServer server = new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 2, 2, 4, 0));
- pipeline.addLast("objectDecoder", new ApelProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new ApelProtocolDecoder(protocol));
}
};
server.setEndianness(ByteOrder.LITTLE_ENDIAN);
@@ -840,46 +741,46 @@ public class ServerManager {
}
private void initManPowerServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, ';'));
pipeline.addLast("stringDecoder", new StringDecoder());
pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new ManPowerProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new ManPowerProtocolDecoder(protocol));
}
});
}
}
private void initGlobalSatServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '!'));
pipeline.addLast("stringDecoder", new StringDecoder());
pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new GlobalSatProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new GlobalSatProtocolDecoder(protocol));
}
});
}
}
private void initAtrackServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new AtrackFrameDecoder());
- pipeline.addLast("objectDecoder", new AtrackProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new AtrackProtocolDecoder(protocol));
}
});
- serverList.add(new TrackerServer(this, new ConnectionlessBootstrap(), protocol) {
+ serverList.add(new TrackerServer(new ConnectionlessBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("objectDecoder", new AtrackProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new AtrackProtocolDecoder(protocol));
}
});
@@ -887,113 +788,113 @@ public class ServerManager {
}
private void initPt3000Server(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, 'd')); // probably wrong
pipeline.addLast("stringDecoder", new StringDecoder());
pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new Pt3000ProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new Pt3000ProtocolDecoder(protocol));
}
});
}
}
private void initRuptelaServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 0, 2, 2, 0));
- pipeline.addLast("objectDecoder", new RuptelaProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new RuptelaProtocolDecoder(protocol));
}
});
}
}
private void initTopflytechServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, ')'));
pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new TopflytechProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new TopflytechProtocolDecoder(protocol));
}
});
}
}
private void initLaipacServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024));
pipeline.addLast("stringDecoder", new StringDecoder());
pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new LaipacProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new LaipacProtocolDecoder(protocol));
}
});
}
}
private void initAplicomServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new AplicomFrameDecoder());
- pipeline.addLast("objectDecoder", new AplicomProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new AplicomProtocolDecoder(protocol));
}
});
}
}
private void initGotopServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '#'));
pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new GotopProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new GotopProtocolDecoder(protocol));
}
});
}
}
private void initSanavServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '*'));
pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new SanavProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new SanavProtocolDecoder(protocol));
}
});
}
}
private void initGatorServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ConnectionlessBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ConnectionlessBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("objectDecoder", new GatorProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new GatorProtocolDecoder(protocol));
}
});
}
}
private void initNoranServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- TrackerServer server = new TrackerServer(this, new ConnectionlessBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ TrackerServer server = new TrackerServer(new ConnectionlessBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("objectDecoder", new NoranProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new NoranProtocolDecoder(protocol));
}
};
server.setEndianness(ByteOrder.LITTLE_ENDIAN);
@@ -1002,218 +903,218 @@ public class ServerManager {
}
private void initM2mServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new FixedLengthFrameDecoder(23));
- pipeline.addLast("objectDecoder", new M2mProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new M2mProtocolDecoder(protocol));
}
});
}
}
private void initOsmAndServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("httpDecoder", new HttpRequestDecoder());
pipeline.addLast("httpEncoder", new HttpResponseEncoder());
- pipeline.addLast("objectDecoder", new OsmAndProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new OsmAndProtocolDecoder(protocol));
}
});
}
}
private void initEasyTrackServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '#'));
pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new EasyTrackProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new EasyTrackProtocolDecoder(protocol));
}
});
}
}
private void initTaipServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ConnectionlessBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ConnectionlessBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new SyrusProtocolDecoder(dataManager, protocol, properties, false));
+ pipeline.addLast("objectDecoder", new SyrusProtocolDecoder(protocol, false));
}
});
}
}
private void initKhdServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(256, 3, 2));
- pipeline.addLast("objectDecoder", new KhdProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new KhdProtocolDecoder(protocol));
}
});
}
}
private void initPiligrimServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("httpDecoder", new HttpRequestDecoder());
pipeline.addLast("httpAggregator", new HttpChunkAggregator(16384));
pipeline.addLast("httpEncoder", new HttpResponseEncoder());
- pipeline.addLast("objectDecoder", new PiligrimProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new PiligrimProtocolDecoder(protocol));
}
});
}
}
private void initStl060Server(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new Stl060FrameDecoder(1024));
pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new Stl060ProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new Stl060ProtocolDecoder(protocol));
}
});
}
}
private void initCarTrackServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, "##"));
pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new CarTrackProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new CarTrackProtocolDecoder(protocol));
}
});
}
}
private void initMiniFinderServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, ';'));
pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new MiniFinderProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new MiniFinderProtocolDecoder(protocol));
}
});
}
}
private void initHaicomServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '*'));
pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new HaicomProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new HaicomProtocolDecoder(protocol));
}
});
}
}
private void initEelinkServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 3, 2));
- pipeline.addLast("objectDecoder", new EelinkProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new EelinkProtocolDecoder(protocol));
}
});
}
}
private void initBoxServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '\r'));
pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new BoxProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new BoxProtocolDecoder(protocol));
}
});
}
}
private void initFreedomServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024));
pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new FreedomProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new FreedomProtocolDecoder(protocol));
}
});
}
}
private void initTelikServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '\0'));
pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new TelikProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new TelikProtocolDecoder(protocol));
}
});
}
}
private void initTrackboxServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024));
pipeline.addLast("stringDecoder", new StringDecoder());
pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new TrackboxProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new TrackboxProtocolDecoder(protocol));
}
});
}
}
private void initVisiontekServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '#'));
pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new VisiontekProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new VisiontekProtocolDecoder(protocol));
}
});
}
}
private void initOrionServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- TrackerServer server = new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ TrackerServer server = new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new OrionFrameDecoder());
- pipeline.addLast("objectDecoder", new OrionProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new OrionProtocolDecoder(protocol));
}
};
server.setEndianness(ByteOrder.LITTLE_ENDIAN);
@@ -1222,12 +1123,12 @@ public class ServerManager {
}
private void initRitiServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- TrackerServer server = new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ TrackerServer server = new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 105, 2, 3, 0));
- pipeline.addLast("objectDecoder", new RitiProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new RitiProtocolDecoder(protocol));
}
};
server.setEndianness(ByteOrder.LITTLE_ENDIAN);
@@ -1236,24 +1137,24 @@ public class ServerManager {
}
private void initUlbotechServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new UlbotechFrameDecoder());
- pipeline.addLast("objectDecoder", new UlbotechProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new UlbotechProtocolDecoder(protocol));
}
});
}
}
private void initTramigoServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- TrackerServer server = new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ TrackerServer server = new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new TramigoFrameDecoder());
- pipeline.addLast("objectDecoder", new TramigoProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new TramigoProtocolDecoder(protocol));
}
};
server.setEndianness(ByteOrder.LITTLE_ENDIAN);
@@ -1262,89 +1163,89 @@ public class ServerManager {
}
private void initTr900Server(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '!'));
pipeline.addLast("stringDecoder", new StringDecoder());
pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new Tr900ProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new Tr900ProtocolDecoder(protocol));
}
});
}
}
private void initArdi01Server(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024));
pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new Ardi01ProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new Ardi01ProtocolDecoder(protocol));
}
});
}
}
private void initXt013Server(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024));
pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new Xt013ProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new Xt013ProtocolDecoder(protocol));
}
});
}
}
private void initAutoFonServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new AutoFonFrameDecoder());
- pipeline.addLast("objectDecoder", new AutoFonProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new AutoFonProtocolDecoder(protocol));
}
});
}
}
private void initGoSafeServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '#'));
pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new GoSafeProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new GoSafeProtocolDecoder(protocol));
}
});
}
}
private void initAutoFon45Server(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new AutoFon45FrameDecoder());
- pipeline.addLast("objectDecoder", new AutoFon45ProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new AutoFon45ProtocolDecoder(protocol));
}
});
}
}
private void initBceServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- TrackerServer server = new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ TrackerServer server = new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new BceFrameDecoder());
- pipeline.addLast("objectDecoder", new BceProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new BceProtocolDecoder(protocol));
}
};
server.setEndianness(ByteOrder.LITTLE_ENDIAN);
@@ -1353,50 +1254,50 @@ public class ServerManager {
}
private void initXirgoServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, "##"));
pipeline.addLast("stringDecoder", new StringDecoder());
pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new XirgoProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new XirgoProtocolDecoder(protocol));
}
});
}
}
private void initCalAmpServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ConnectionlessBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ConnectionlessBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("objectDecoder", new CalAmpProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new CalAmpProtocolDecoder(protocol));
}
});
}
}
private void initMtxServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ServerBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024));
pipeline.addLast("stringDecoder", new StringDecoder());
pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new MtxProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new MtxProtocolDecoder(protocol));
}
});
}
}
private void initTytanServer(final String protocol) throws SQLException {
- if (isProtocolEnabled(properties, protocol)) {
- serverList.add(new TrackerServer(this, new ConnectionlessBootstrap(), protocol) {
+ if (isProtocolEnabled(protocol)) {
+ serverList.add(new TrackerServer(new ConnectionlessBootstrap(), protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("objectDecoder", new TytanProtocolDecoder(dataManager, protocol, properties));
+ pipeline.addLast("objectDecoder", new TytanProtocolDecoder(protocol));
}
});
}
diff --git a/src/org/traccar/TrackerEventHandler.java b/src/org/traccar/TrackerEventHandler.java
index ecce97fa4..bc3ff0e16 100644
--- a/src/org/traccar/TrackerEventHandler.java
+++ b/src/org/traccar/TrackerEventHandler.java
@@ -27,14 +27,6 @@ import org.traccar.model.Position;
@ChannelHandler.Sharable
public class TrackerEventHandler extends IdleStateAwareChannelHandler {
- private final DataManager dataManager;
- private final DataCache dataCache;
-
- TrackerEventHandler(DataManager dataManager, DataCache dataCache) {
- this.dataManager = dataManager;
- this.dataCache = dataCache;
- }
-
private Long processSinglePosition(Position position) {
if (position == null) {
Log.info("processSinglePosition null message");
@@ -50,7 +42,7 @@ public class TrackerEventHandler extends IdleStateAwareChannelHandler {
// Write position to database
Long id = null;
try {
- id = dataManager.addPosition(position);
+ id = Context.getDataManager().addPosition(position);
} catch (Exception error) {
Log.warning(error);
}
@@ -73,8 +65,8 @@ public class TrackerEventHandler extends IdleStateAwareChannelHandler {
}
if (lastPostition != null) {
try {
- dataManager.updateLatestPosition(lastPostition, id);
- dataCache.update(lastPostition);
+ Context.getDataManager().updateLatestPosition(lastPostition, id);
+ Context.getDataCache().update(lastPostition);
} catch (Exception error) {
Log.warning(error);
}
diff --git a/src/org/traccar/TrackerServer.java b/src/org/traccar/TrackerServer.java
index 7ae1c8498..c65583584 100644
--- a/src/org/traccar/TrackerServer.java
+++ b/src/org/traccar/TrackerServer.java
@@ -33,7 +33,6 @@ import org.jboss.netty.channel.group.DefaultChannelGroup;
*/
public abstract class TrackerServer {
- private final ServerManager serverManager;
private final Bootstrap bootstrap;
private final String protocol;
@@ -41,8 +40,7 @@ public abstract class TrackerServer {
return protocol;
}
- public TrackerServer(ServerManager serverManager, Bootstrap bootstrap, String protocol) {
- this.serverManager = serverManager;
+ public TrackerServer(Bootstrap bootstrap, String protocol) {
this.bootstrap = bootstrap;
this.protocol = protocol;
@@ -53,11 +51,11 @@ public abstract class TrackerServer {
bootstrap.setFactory(GlobalChannelFactory.getDatagramFactory());
}
- address = serverManager.getProperties().getProperty(protocol + ".address");
- String portProperty = serverManager.getProperties().getProperty(protocol + ".port");
+ address = Context.getProps().getProperty(protocol + ".address");
+ String portProperty = Context.getProps().getProperty(protocol + ".port");
port = Integer.valueOf(portProperty);
- bootstrap.setPipelineFactory(new BasePipelineFactory(serverManager, this, protocol) {
+ bootstrap.setPipelineFactory(new BasePipelineFactory(this, protocol) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
TrackerServer.this.addSpecificHandlers(pipeline);
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java
index 9bc8ea805..1c6579bf4 100644
--- a/src/org/traccar/database/DataManager.java
+++ b/src/org/traccar/database/DataManager.java
@@ -138,10 +138,11 @@ public class DataManager {
private long devicesRefreshDelay;
private static final long DEFAULT_REFRESH_DELAY = 300;
- public Device getDeviceByImei(String imei) throws SQLException {
+ public Device getDeviceByUniqueId(String uniqueId) throws SQLException {
- if (devices == null || !devices.containsKey(imei) ||
+ if (devices == null || !devices.containsKey(uniqueId) ||
(Calendar.getInstance().getTimeInMillis() - devicesLastUpdate.getTimeInMillis() > devicesRefreshDelay)) {
+
devices = new HashMap<String, Device>();
for (Device device : getDevices()) {
devices.put(device.getImei(), device);
@@ -149,7 +150,7 @@ public class DataManager {
devicesLastUpdate = Calendar.getInstance();
}
- return devices.get(imei);
+ return devices.get(uniqueId);
}
private NamedParameterStatement.ResultSetProcessor<Long> generatedKeysResultSetProcessor = new NamedParameterStatement.ResultSetProcessor<Long>() {
diff --git a/src/org/traccar/protocol/ApelProtocolDecoder.java b/src/org/traccar/protocol/ApelProtocolDecoder.java
index c772ce6f7..619831f0f 100644
--- a/src/org/traccar/protocol/ApelProtocolDecoder.java
+++ b/src/org/traccar/protocol/ApelProtocolDecoder.java
@@ -29,6 +29,7 @@ import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.traccar.BaseProtocolDecoder;
+import org.traccar.Context;
import org.traccar.database.DataManager;
import org.traccar.helper.Crc;
import org.traccar.helper.Log;
@@ -37,12 +38,11 @@ import org.traccar.model.Position;
public class ApelProtocolDecoder extends BaseProtocolDecoder {
- private long deviceId;
private long lastIndex;
private long newIndex;
- public ApelProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public ApelProtocolDecoder(String protocol) {
+ super(protocol);
}
/*
@@ -140,13 +140,7 @@ public class ApelProtocolDecoder extends BaseProtocolDecoder {
int length = buf.readUnsignedShort();
buf.skipBytes(length);
length = buf.readUnsignedShort();
- String imei = buf.readBytes(length).toString(Charset.defaultCharset());
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
- loadLastIndex();
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei + " (id - " + id + ")");
- }
+ identify(buf.readBytes(length).toString(Charset.defaultCharset()));
}
else if (type == MSG_TYPE_LAST_LOG_INDEX) {
@@ -158,7 +152,7 @@ public class ApelProtocolDecoder extends BaseProtocolDecoder {
}
// Position
- else if (deviceId != 0 && (type == MSG_TYPE_CURRENT_GPS_DATA || type == MSG_TYPE_STATE_FULL_INFO_T104 || type == MSG_TYPE_LOG_RECORDS)) {
+ else if (hasDeviceId() && (type == MSG_TYPE_CURRENT_GPS_DATA || type == MSG_TYPE_STATE_FULL_INFO_T104 || type == MSG_TYPE_LOG_RECORDS)) {
List<Position> positions = new LinkedList<Position>();
int recordCount = 1;
@@ -169,7 +163,7 @@ public class ApelProtocolDecoder extends BaseProtocolDecoder {
for (int j = 0; j < recordCount; j++) {
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
// Message index
int subtype = type;
diff --git a/src/org/traccar/protocol/AplicomProtocolDecoder.java b/src/org/traccar/protocol/AplicomProtocolDecoder.java
index c47731759..aee1517e4 100644
--- a/src/org/traccar/protocol/AplicomProtocolDecoder.java
+++ b/src/org/traccar/protocol/AplicomProtocolDecoder.java
@@ -23,6 +23,7 @@ import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.traccar.BaseProtocolDecoder;
+import org.traccar.Context;
import org.traccar.database.DataManager;
import org.traccar.helper.Log;
import org.traccar.model.ExtendedInfoFormatter;
@@ -30,8 +31,8 @@ import org.traccar.model.Position;
public class AplicomProtocolDecoder extends BaseProtocolDecoder {
- public AplicomProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public AplicomProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final long IMEI_BASE_TC65_V20 = 0x1437207000000L;
@@ -128,13 +129,12 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder {
// Create new position
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(imei)) {
return null;
}
+ position.setDeviceId(getDeviceId());
+
// Event
extendedInfo.set("event", buf.readUnsignedByte());
buf.readUnsignedByte();
diff --git a/src/org/traccar/protocol/Ardi01ProtocolDecoder.java b/src/org/traccar/protocol/Ardi01ProtocolDecoder.java
index e25ff1c57..4e90134ae 100644
--- a/src/org/traccar/protocol/Ardi01ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Ardi01ProtocolDecoder.java
@@ -31,8 +31,8 @@ import java.util.regex.Pattern;
public class Ardi01ProtocolDecoder extends BaseProtocolDecoder {
- public Ardi01ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public Ardi01ProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -68,14 +68,11 @@ public class Ardi01ProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Detect device
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
-
+ position.setDeviceId(getDeviceId());
+
// Date and time
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
time.clear();
diff --git a/src/org/traccar/protocol/AtrackProtocolDecoder.java b/src/org/traccar/protocol/AtrackProtocolDecoder.java
index 607b3e558..e2f3e924f 100644
--- a/src/org/traccar/protocol/AtrackProtocolDecoder.java
+++ b/src/org/traccar/protocol/AtrackProtocolDecoder.java
@@ -35,8 +35,8 @@ import org.traccar.model.Position;
public class AtrackProtocolDecoder extends BaseProtocolDecoder {
- public AtrackProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public AtrackProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final int MSG_HEARTBEAT = 0x1A;
@@ -91,18 +91,13 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder {
int index = buf.readUnsignedShort();
// Get device id
- long deviceId;
- long rawId = buf.readLong();
- String id = String.valueOf(rawId);
- try {
- deviceId = getDataManager().getDeviceByImei(id).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ long id = buf.readLong();
+ if (!identify(String.valueOf(id))) {
return null;
}
-
+
// Send acknowledgement
- sendResponse(channel, remoteAddress, rawId, index);
+ sendResponse(channel, remoteAddress, id, index);
List<Position> positions = new LinkedList<Position>();
@@ -110,7 +105,7 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder {
// Create new position
Position position = new Position();
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
// Date and time
diff --git a/src/org/traccar/protocol/AutoFon45ProtocolDecoder.java b/src/org/traccar/protocol/AutoFon45ProtocolDecoder.java
index df98fa93b..c72139c50 100644
--- a/src/org/traccar/protocol/AutoFon45ProtocolDecoder.java
+++ b/src/org/traccar/protocol/AutoFon45ProtocolDecoder.java
@@ -32,15 +32,14 @@ import org.traccar.model.Position;
import java.util.*;
public class AutoFon45ProtocolDecoder extends BaseProtocolDecoder {
- private long deviceId;
private static double convertCoordinate(short degrees, int raw) {
double seconds = (raw >> 4 & 0xffffff) / 600000.0;
return (degrees + seconds) * ((raw & 0x0f) == 0 ? -1 : 1);
}
- public AutoFon45ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public AutoFon45ProtocolDecoder(String protocol) {
+ super(protocol);
}
@Override
@@ -54,10 +53,7 @@ public class AutoFon45ProtocolDecoder extends BaseProtocolDecoder {
buf.readBytes(bytes);
String imei = ChannelBufferTools.readHexString(ChannelBuffers.wrappedBuffer(bytes, 1, 16), 16).substring(1);
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(imei)) {
return null;
}
@@ -74,7 +70,7 @@ public class AutoFon45ProtocolDecoder extends BaseProtocolDecoder {
// Create new position
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
short status = buf.readUnsignedByte();
extendedInfo.set("alarm", (status & 0x80) != 0);
diff --git a/src/org/traccar/protocol/AutoFonProtocolDecoder.java b/src/org/traccar/protocol/AutoFonProtocolDecoder.java
index fbc142846..2c563d6d2 100644
--- a/src/org/traccar/protocol/AutoFonProtocolDecoder.java
+++ b/src/org/traccar/protocol/AutoFonProtocolDecoder.java
@@ -30,16 +30,14 @@ import java.util.*;
public class AutoFonProtocolDecoder extends BaseProtocolDecoder {
- public AutoFonProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public AutoFonProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final int MSG_LOGIN = 0x10;
private static final int MSG_LOCATION = 0x11;
private static final int MSG_HISTORY = 0x12;
- private long deviceId;
-
private static double convertCoordinate(int raw) {
double result = raw / 1000000;
result += (raw % 1000000) / 600000.0;
@@ -51,7 +49,7 @@ public class AutoFonProtocolDecoder extends BaseProtocolDecoder {
// Create new position
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
if (!history) {
buf.readUnsignedByte(); // interval
@@ -127,10 +125,7 @@ public class AutoFonProtocolDecoder extends BaseProtocolDecoder {
buf.readUnsignedByte(); // software version
String imei = ChannelBufferTools.readHexString(buf, 16).substring(1);
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(imei)) {
return null;
}
diff --git a/src/org/traccar/protocol/BceProtocolDecoder.java b/src/org/traccar/protocol/BceProtocolDecoder.java
index a1c45758c..2f96ab317 100644
--- a/src/org/traccar/protocol/BceProtocolDecoder.java
+++ b/src/org/traccar/protocol/BceProtocolDecoder.java
@@ -33,8 +33,8 @@ import org.traccar.model.Position;
public class BceProtocolDecoder extends BaseProtocolDecoder {
- public BceProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public BceProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final int DATA_TYPE = 7;
@@ -57,11 +57,7 @@ public class BceProtocolDecoder extends BaseProtocolDecoder {
ChannelBuffer buf = (ChannelBuffer) msg;
String imei = String.format("%015d", buf.readLong());
- long deviceId;
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
- } catch (Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(imei)) {
return null;
}
@@ -77,7 +73,7 @@ public class BceProtocolDecoder extends BaseProtocolDecoder {
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
int structEnd = buf.readUnsignedByte() + buf.readerIndex();
diff --git a/src/org/traccar/protocol/BoxProtocolDecoder.java b/src/org/traccar/protocol/BoxProtocolDecoder.java
index cdbd3932e..d2de48489 100644
--- a/src/org/traccar/protocol/BoxProtocolDecoder.java
+++ b/src/org/traccar/protocol/BoxProtocolDecoder.java
@@ -31,11 +31,9 @@ import org.traccar.model.ExtendedInfoFormatter;
import org.traccar.model.Position;
public class BoxProtocolDecoder extends BaseProtocolDecoder {
-
- private Long deviceId;
- public BoxProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public BoxProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -63,12 +61,7 @@ public class BoxProtocolDecoder extends BaseProtocolDecoder {
int index = sentence.indexOf(',', 2) + 1;
String id = sentence.substring(index, sentence.indexOf(',', index));
-
- try {
- deviceId = getDataManager().getDeviceByImei(id).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
- }
+ identify(id);
}
else if (sentence.startsWith("L,")) {
@@ -81,7 +74,7 @@ public class BoxProtocolDecoder extends BaseProtocolDecoder {
// Create new position
Position position = new Position();
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
Integer index = 1;
diff --git a/src/org/traccar/protocol/CalAmpProtocolDecoder.java b/src/org/traccar/protocol/CalAmpProtocolDecoder.java
index 8fe75bf93..04ac8f165 100644
--- a/src/org/traccar/protocol/CalAmpProtocolDecoder.java
+++ b/src/org/traccar/protocol/CalAmpProtocolDecoder.java
@@ -33,8 +33,8 @@ import org.traccar.model.Position;
public class CalAmpProtocolDecoder extends BaseProtocolDecoder {
- public CalAmpProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public CalAmpProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final int MSG_NULL = 0;
@@ -91,8 +91,6 @@ public class CalAmpProtocolDecoder extends BaseProtocolDecoder {
ChannelBuffer buf = (ChannelBuffer) msg;
- Long deviceId = null;
-
// Check options header
if ((buf.getByte(buf.readerIndex()) & 0x80) != 0) {
@@ -112,14 +110,7 @@ public class CalAmpProtocolDecoder extends BaseProtocolDecoder {
}
}
- // Find device in database
- String stringId = String.valueOf(id);
- try {
- deviceId = getDataManager().getDeviceByImei(stringId).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + stringId);
- }
-
+ identify(String.valueOf(id));
}
// Identifier type
@@ -150,8 +141,7 @@ public class CalAmpProtocolDecoder extends BaseProtocolDecoder {
}
// Unidentified device
- if (deviceId == null) {
- Log.warning("Unknown device");
+ if (!hasDeviceId()) {
return null;
}
@@ -170,8 +160,8 @@ public class CalAmpProtocolDecoder extends BaseProtocolDecoder {
// Create new position
Position position = new Position();
- position.setDeviceId(deviceId);
- ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("calamp");
+ position.setDeviceId(getDeviceId());
+ ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
// Location data
position.setTime(new Date(buf.readUnsignedInt() * 1000));
diff --git a/src/org/traccar/protocol/CarTrackProtocolDecoder.java b/src/org/traccar/protocol/CarTrackProtocolDecoder.java
index 170db3130..425115fe9 100644
--- a/src/org/traccar/protocol/CarTrackProtocolDecoder.java
+++ b/src/org/traccar/protocol/CarTrackProtocolDecoder.java
@@ -33,8 +33,8 @@ import org.traccar.model.Position;
public class CarTrackProtocolDecoder extends BaseProtocolDecoder {
- public CarTrackProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public CarTrackProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -77,13 +77,10 @@ public class CarTrackProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Get device by unique identifier
- String id = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Command
extendedInfo.set("command", parser.group(index++));
diff --git a/src/org/traccar/protocol/CarscopProtocolDecoder.java b/src/org/traccar/protocol/CarscopProtocolDecoder.java
index e56036d0b..e7c4d6192 100644
--- a/src/org/traccar/protocol/CarscopProtocolDecoder.java
+++ b/src/org/traccar/protocol/CarscopProtocolDecoder.java
@@ -32,13 +32,10 @@ import org.traccar.model.Position;
public class CarscopProtocolDecoder extends BaseProtocolDecoder {
- private Long deviceId;
-
- public CarscopProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public CarscopProtocolDecoder(String protocol) {
+ super(protocol);
}
- // Very similar to TK103 protocol
static private Pattern pattern = Pattern.compile(
"\\*.*" +
"(\\d{2})(\\d{2})(\\d{2})" + // Time (HHMMSS)
@@ -64,13 +61,9 @@ public class CarscopProtocolDecoder extends BaseProtocolDecoder {
int index = sentence.indexOf("UB05");
if (index != -1) {
String imei = sentence.substring(index + 4, index + 4 + 15);
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
- }
+ identify(imei);
}
- if (deviceId == null) {
+ if (!hasDeviceId()) {
return null;
}
@@ -82,7 +75,7 @@ public class CarscopProtocolDecoder extends BaseProtocolDecoder {
// Create new position
Position position = new Position();
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
index = 1;
diff --git a/src/org/traccar/protocol/CellocatorProtocolDecoder.java b/src/org/traccar/protocol/CellocatorProtocolDecoder.java
index 178e17530..a61c5b79f 100644
--- a/src/org/traccar/protocol/CellocatorProtocolDecoder.java
+++ b/src/org/traccar/protocol/CellocatorProtocolDecoder.java
@@ -33,8 +33,8 @@ import org.traccar.model.Position;
public class CellocatorProtocolDecoder extends BaseProtocolDecoder {
- public CellocatorProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public CellocatorProtocolDecoder(String protocol) {
+ super(protocol);
}
private String readImei(ChannelBuffer buf) {
@@ -93,7 +93,7 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder {
buf.skipBytes(4); // system code
int type = buf.readUnsignedByte();
- long deviceId = buf.readUnsignedInt();
+ long deviceUniqueId = buf.readUnsignedInt();
if (type != MSG_CLIENT_SERIAL) {
buf.readUnsignedShort(); // communication control
@@ -101,7 +101,7 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder {
byte packetNumber = buf.readByte();
// Send reply
- sendReply(channel, deviceId, packetNumber);
+ sendReply(channel, deviceUniqueId, packetNumber);
// Parse location
if (type == MSG_CLIENT_STATUS) {
@@ -109,13 +109,11 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder {
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
// Device identifier
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(String.valueOf(deviceId)).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + deviceId);
+ if (!identify(String.valueOf(deviceUniqueId))) {
return null;
}
-
+ position.setDeviceId(getDeviceId());
+
buf.readUnsignedByte(); // hardware version
buf.readUnsignedByte(); // software version
buf.readUnsignedByte(); // protocol version
diff --git a/src/org/traccar/protocol/EasyTrackProtocolDecoder.java b/src/org/traccar/protocol/EasyTrackProtocolDecoder.java
index bbf1ce817..c32ac2228 100644
--- a/src/org/traccar/protocol/EasyTrackProtocolDecoder.java
+++ b/src/org/traccar/protocol/EasyTrackProtocolDecoder.java
@@ -32,11 +32,10 @@ import org.traccar.model.Position;
public class EasyTrackProtocolDecoder extends BaseProtocolDecoder {
- public EasyTrackProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public EasyTrackProtocolDecoder(String protocol) {
+ super(protocol);
}
- //ET,358155100003016,HB,A,0d081e,07381e,8038ee09,03d2e9be,004f,0000,40c00000,0f,100,0000,00037c,29
static private Pattern pattern = Pattern.compile(
"\\*..," + // Manufacturer
"(\\d+)," + // IMEI
@@ -82,19 +81,16 @@ public class EasyTrackProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Get device by IMEI
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Command
extendedInfo.set("command", parser.group(index++));
// Validity
- position.setValid(parser.group(index++).compareTo("A") == 0 ? true : false);
+ position.setValid(parser.group(index++).compareTo("A") == 0);
// Date
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
diff --git a/src/org/traccar/protocol/EelinkProtocolDecoder.java b/src/org/traccar/protocol/EelinkProtocolDecoder.java
index e63189dae..929153033 100644
--- a/src/org/traccar/protocol/EelinkProtocolDecoder.java
+++ b/src/org/traccar/protocol/EelinkProtocolDecoder.java
@@ -35,8 +35,8 @@ import org.traccar.model.Position;
public class EelinkProtocolDecoder extends BaseProtocolDecoder {
- public EelinkProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public EelinkProtocolDecoder(String protocol) {
+ super(protocol);
}
private String readImei(ChannelBuffer buf) {
@@ -60,9 +60,7 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder {
private static final int MSG_OBD = 0x07;
private static final int MSG_INTERACTIVE = 0x80;
private static final int MSG_DATA = 0x81;
-
- private Long deviceId;
-
+
private void sendResponse(Channel channel, int type, int index) {
if (channel != null) {
ChannelBuffer response = ChannelBuffers.buffer(7);
@@ -91,15 +89,10 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder {
}
if (type == MSG_LOGIN) {
- String imei = ChannelBufferTools.readHexString(buf, 16).substring(1);
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
- }
+ identify(ChannelBufferTools.readHexString(buf, 16).substring(1));
}
- else if (deviceId != null &&
+ else if (hasDeviceId() &&
(type == MSG_GPS ||
type == MSG_ALARM ||
type == MSG_STATE ||
@@ -107,7 +100,7 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder {
// Create new position
Position position = new Position();
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
extendedInfo.set("index", index);
diff --git a/src/org/traccar/protocol/EnforaProtocolDecoder.java b/src/org/traccar/protocol/EnforaProtocolDecoder.java
index 8f5391fd6..430693189 100644
--- a/src/org/traccar/protocol/EnforaProtocolDecoder.java
+++ b/src/org/traccar/protocol/EnforaProtocolDecoder.java
@@ -35,8 +35,8 @@ import org.traccar.model.Position;
public class EnforaProtocolDecoder extends BaseProtocolDecoder {
- public EnforaProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public EnforaProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -101,12 +101,10 @@ public class EnforaProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Get device by IMEI
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(imei)) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Time
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
diff --git a/src/org/traccar/protocol/Ev603ProtocolDecoder.java b/src/org/traccar/protocol/Ev603ProtocolDecoder.java
index 7c596d479..acf359daf 100644
--- a/src/org/traccar/protocol/Ev603ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Ev603ProtocolDecoder.java
@@ -33,10 +33,8 @@ import org.traccar.model.Position;
public class Ev603ProtocolDecoder extends BaseProtocolDecoder{
- private Long deviceId;
-
- public Ev603ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public Ev603ProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -58,25 +56,19 @@ public class Ev603ProtocolDecoder extends BaseProtocolDecoder{
// Detect device ID
if (sentence.startsWith("!1,")) {
- String imei = sentence.substring(3);
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
- return null;
- }
+ identify(sentence.substring(3));
}
else if (sentence.startsWith("!A,")) {
// Parse message
Matcher parser = pattern.matcher(sentence);
- if (deviceId == null || !parser.matches()) {
+ if (!hasDeviceId() || !parser.matches()) {
return null;
}
// Create new position
Position position = new Position();
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
Integer index = 1;
diff --git a/src/org/traccar/protocol/FreedomProtocolDecoder.java b/src/org/traccar/protocol/FreedomProtocolDecoder.java
index 21e6f9abc..f8ab610b1 100644
--- a/src/org/traccar/protocol/FreedomProtocolDecoder.java
+++ b/src/org/traccar/protocol/FreedomProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class FreedomProtocolDecoder extends BaseProtocolDecoder {
- public FreedomProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public FreedomProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -63,14 +63,11 @@ public class FreedomProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Identification
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
-
+ position.setDeviceId(getDeviceId());
+
// Validity
position.setValid(true);
diff --git a/src/org/traccar/protocol/GalileoProtocolDecoder.java b/src/org/traccar/protocol/GalileoProtocolDecoder.java
index 0fa881949..99b745175 100644
--- a/src/org/traccar/protocol/GalileoProtocolDecoder.java
+++ b/src/org/traccar/protocol/GalileoProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class GalileoProtocolDecoder extends BaseProtocolDecoder {
- public GalileoProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public GalileoProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final int TAG_IMEI = 0x03;
@@ -77,9 +77,7 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder {
channel.write(reply);
}
}
-
- private Long deviceId;
-
+
@Override
protected Object decode(
ChannelHandlerContext ctx, Channel channel, Object msg)
@@ -113,11 +111,7 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder {
case TAG_IMEI:
String imei = buf.toString(buf.readerIndex(), 15, Charset.defaultCharset());
buf.skipBytes(imei.length());
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
- }
+ identify(imei);
break;
case TAG_DATE:
@@ -165,7 +159,7 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder {
position.setExtendedInfo(extendedInfo.toString());
positions.add(position);
- if (deviceId == null) {
+ if (!hasDeviceId()) {
Log.warning("Unknown device");
return null;
}
@@ -175,7 +169,7 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder {
for (Iterator<Position> i = positions.iterator(); i.hasNext(); ) {
Position p = i.next();
- p.setDeviceId(deviceId);
+ p.setDeviceId(getDeviceId());
if (p.getAltitude() == null) {
p.setAltitude(0.0);
diff --git a/src/org/traccar/protocol/GatorProtocolDecoder.java b/src/org/traccar/protocol/GatorProtocolDecoder.java
index 5bc205214..33b8c501c 100644
--- a/src/org/traccar/protocol/GatorProtocolDecoder.java
+++ b/src/org/traccar/protocol/GatorProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class GatorProtocolDecoder extends BaseProtocolDecoder {
- public GatorProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public GatorProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final int PACKET_HEARTBEAT = 0x21;
@@ -75,12 +75,11 @@ public class GatorProtocolDecoder extends BaseProtocolDecoder {
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
// Identification
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ if (!identify(id)) {
+ return null;
}
-
+ position.setDeviceId(getDeviceId());
+
// Date and time
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
time.clear();
diff --git a/src/org/traccar/protocol/Gl100ProtocolDecoder.java b/src/org/traccar/protocol/Gl100ProtocolDecoder.java
index fb1e42cce..fb64d8dda 100644
--- a/src/org/traccar/protocol/Gl100ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gl100ProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class Gl100ProtocolDecoder extends BaseProtocolDecoder {
- public Gl100ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public Gl100ProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -82,13 +82,10 @@ public class Gl100ProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Get device by IMEI
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Validity
position.setValid(Integer.valueOf(parser.group(index++)) == 0);
diff --git a/src/org/traccar/protocol/Gl200ProtocolDecoder.java b/src/org/traccar/protocol/Gl200ProtocolDecoder.java
index 1c20c5cc1..969be7611 100644
--- a/src/org/traccar/protocol/Gl200ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gl200ProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
- public Gl200ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public Gl200ProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -78,13 +78,10 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Get device by IMEI
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Validity
position.setValid(Integer.valueOf(parser.group(index++)) < 20);
diff --git a/src/org/traccar/protocol/GlobalSatProtocolDecoder.java b/src/org/traccar/protocol/GlobalSatProtocolDecoder.java
index fd0c04bb4..1a0132c4a 100644
--- a/src/org/traccar/protocol/GlobalSatProtocolDecoder.java
+++ b/src/org/traccar/protocol/GlobalSatProtocolDecoder.java
@@ -25,6 +25,7 @@ import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.traccar.BaseProtocolDecoder;
+import org.traccar.Context;
import org.traccar.database.DataManager;
import org.traccar.helper.Log;
import org.traccar.model.ExtendedInfoFormatter;
@@ -36,9 +37,10 @@ public class GlobalSatProtocolDecoder extends BaseProtocolDecoder {
private String format0 = "TSPRXAB27GHKLMnaicz*U!";
private String format1 = "SARY*U!";
- public GlobalSatProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public GlobalSatProtocolDecoder(String protocol) {
+ super(protocol);
+ Properties properties = Context.getProps();
if (properties != null) {
if (properties.containsKey(protocol + ".format0")) {
format0 = properties.getProperty(protocol + ".format0");
@@ -97,12 +99,10 @@ public class GlobalSatProtocolDecoder extends BaseProtocolDecoder {
switch(format.charAt(formatIndex)) {
case 'S':
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(value).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + value);
+ if (!identify(value)) {
return null;
}
+ position.setDeviceId(getDeviceId());
break;
case 'A':
if (value.isEmpty()) {
@@ -215,13 +215,10 @@ public class GlobalSatProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Identification
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Validity
position.setValid(parser.group(index++).compareTo("1") != 0);
diff --git a/src/org/traccar/protocol/GoSafeProtocolDecoder.java b/src/org/traccar/protocol/GoSafeProtocolDecoder.java
index 65f058bb6..3d981bb60 100644
--- a/src/org/traccar/protocol/GoSafeProtocolDecoder.java
+++ b/src/org/traccar/protocol/GoSafeProtocolDecoder.java
@@ -33,8 +33,8 @@ import org.traccar.model.Position;
public class GoSafeProtocolDecoder extends BaseProtocolDecoder {
- public GoSafeProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public GoSafeProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -73,14 +73,11 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Get device by IMEI
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
-
+ position.setDeviceId(getDeviceId());
+
// Date
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
time.clear();
diff --git a/src/org/traccar/protocol/GotopProtocolDecoder.java b/src/org/traccar/protocol/GotopProtocolDecoder.java
index 2e49a5dd0..80196c04a 100644
--- a/src/org/traccar/protocol/GotopProtocolDecoder.java
+++ b/src/org/traccar/protocol/GotopProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class GotopProtocolDecoder extends BaseProtocolDecoder {
- public GotopProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public GotopProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -67,13 +67,10 @@ public class GotopProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Get device by IMEI
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Validity
position.setValid(parser.group(index++).compareTo("A") == 0);
diff --git a/src/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/org/traccar/protocol/Gps103ProtocolDecoder.java
index 0d8257e55..b99507ffb 100644
--- a/src/org/traccar/protocol/Gps103ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gps103ProtocolDecoder.java
@@ -33,8 +33,8 @@ import org.traccar.model.Position;
public class Gps103ProtocolDecoder extends BaseProtocolDecoder {
- public Gps103ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public Gps103ProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -99,13 +99,10 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Get device by IMEI
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Alarm message
extendedInfo.set("alarm", parser.group(index++));
diff --git a/src/org/traccar/protocol/GpsGateProtocolDecoder.java b/src/org/traccar/protocol/GpsGateProtocolDecoder.java
index 80e06c911..cb26d3a61 100644
--- a/src/org/traccar/protocol/GpsGateProtocolDecoder.java
+++ b/src/org/traccar/protocol/GpsGateProtocolDecoder.java
@@ -33,15 +33,10 @@ import org.traccar.model.Position;
public class GpsGateProtocolDecoder extends BaseProtocolDecoder {
- private Long deviceId;
-
- public GpsGateProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public GpsGateProtocolDecoder(String protocol) {
+ super(protocol);
}
- /**
- * Regular expressions pattern
- */
private static final Pattern pattern = Pattern.compile(
"\\$GPRMC," +
"(\\d{2})(\\d{2})(\\d{2})\\.?(\\d+)?," + // Time (HHMMSS.SSS)
@@ -76,11 +71,11 @@ public class GpsGateProtocolDecoder extends BaseProtocolDecoder {
int endIndex = sentence.indexOf(',', beginIndex);
if (endIndex != -1) {
String imei = sentence.substring(beginIndex, endIndex);
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
- send(channel, "$FRSES," + channel.getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (identify(imei)) {
+ if (channel != null) {
+ send(channel, "$FRSES," + channel.getId());
+ }
+ } else {
send(channel, "$FRERR,AuthError,Unknown device");
}
} else {
@@ -97,7 +92,7 @@ public class GpsGateProtocolDecoder extends BaseProtocolDecoder {
}
// Process data
- else if (sentence.startsWith("$GPRMC,") && deviceId != null) {
+ else if (sentence.startsWith("$GPRMC,") && hasDeviceId()) {
// Parse message
Matcher parser = pattern.matcher(sentence);
@@ -108,7 +103,7 @@ public class GpsGateProtocolDecoder extends BaseProtocolDecoder {
// Create new position
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
Integer index = 1;
diff --git a/src/org/traccar/protocol/Gt02ProtocolDecoder.java b/src/org/traccar/protocol/Gt02ProtocolDecoder.java
index 3857766c7..bab03d13f 100644
--- a/src/org/traccar/protocol/Gt02ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gt02ProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class Gt02ProtocolDecoder extends BaseProtocolDecoder {
- public Gt02ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public Gt02ProtocolDecoder(String protocol) {
+ super(protocol);
}
private String readImei(ChannelBuffer buf) {
@@ -84,12 +84,10 @@ public class Gt02ProtocolDecoder extends BaseProtocolDecoder {
extendedInfo.set("index", index);
// Get device id
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(imei)) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Date and time
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
diff --git a/src/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/org/traccar/protocol/Gt06ProtocolDecoder.java
index 1d81bb351..e94a7238b 100644
--- a/src/org/traccar/protocol/Gt06ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gt06ProtocolDecoder.java
@@ -20,6 +20,7 @@ import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.traccar.BaseProtocolDecoder;
+import org.traccar.Context;
import org.traccar.database.DataManager;
import org.traccar.helper.Crc;
import org.traccar.helper.Log;
@@ -32,19 +33,16 @@ import java.util.TimeZone;
public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
- private Long deviceId;
private boolean forceTimeZone = false;
private final TimeZone timeZone = TimeZone.getTimeZone("UTC");
- public Gt06ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
-
- if (properties != null) {
- if (properties.containsKey(protocol + ".timezone")) {
- forceTimeZone = true;
- timeZone.setRawOffset(
- Integer.valueOf(properties.getProperty(protocol + ".timezone")) * 1000);
- }
+ public Gt06ProtocolDecoder(String protocol) {
+ super(protocol);
+
+ Properties properties = Context.getProps();
+ if (properties != null && properties.containsKey(protocol + ".timezone")) {
+ forceTimeZone = true;
+ timeZone.setRawOffset(Integer.valueOf(properties.getProperty(protocol + ".timezone")) * 1000);
}
}
@@ -126,16 +124,13 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
timeZone.setRawOffset(offset);
}
}
-
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
+
+ if (identify(imei)) {
buf.skipBytes(buf.readableBytes() - 6);
sendResponse(channel, type, buf.readUnsignedShort());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
}
-
- } else if (deviceId != null && (
+
+ } else if (hasDeviceId() && (
type == MSG_GPS ||
type == MSG_GPS_LBS_1 ||
type == MSG_GPS_LBS_2 ||
@@ -147,7 +142,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
// Create new position
Position position = new Position();
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
// Date and time
diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java
index 84ddaf895..51d1ed8d0 100644
--- a/src/org/traccar/protocol/H02ProtocolDecoder.java
+++ b/src/org/traccar/protocol/H02ProtocolDecoder.java
@@ -35,8 +35,8 @@ import org.traccar.model.Position;
public class H02ProtocolDecoder extends BaseProtocolDecoder {
- public H02ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public H02ProtocolDecoder(String protocol) {
+ super(protocol);
}
private static double readCoordinate(ChannelBuffer buf, boolean lon) {
@@ -67,14 +67,11 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
buf.readByte(); // marker
// Identification
- String id = ChannelBufferTools.readHexString(buf, 10);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ if (!identify(ChannelBufferTools.readHexString(buf, 10))) {
return null;
}
-
+ position.setDeviceId(getDeviceId());
+
// Time
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
time.clear();
@@ -141,13 +138,10 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Get device by IMEI
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Time
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
diff --git a/src/org/traccar/protocol/HaicomProtocolDecoder.java b/src/org/traccar/protocol/HaicomProtocolDecoder.java
index 078ee9ae6..ae070fd84 100644
--- a/src/org/traccar/protocol/HaicomProtocolDecoder.java
+++ b/src/org/traccar/protocol/HaicomProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class HaicomProtocolDecoder extends BaseProtocolDecoder {
- public HaicomProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public HaicomProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -75,13 +75,10 @@ public class HaicomProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Get device by IMEI
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Firmware version
extendedInfo.set("version", parser.group(index++));
diff --git a/src/org/traccar/protocol/IntellitracProtocolDecoder.java b/src/org/traccar/protocol/IntellitracProtocolDecoder.java
index fa1837e50..3b03a6b2d 100644
--- a/src/org/traccar/protocol/IntellitracProtocolDecoder.java
+++ b/src/org/traccar/protocol/IntellitracProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class IntellitracProtocolDecoder extends BaseProtocolDecoder {
- public IntellitracProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public IntellitracProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -83,13 +83,10 @@ public class IntellitracProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Detect device
- String id = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Date and time
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
diff --git a/src/org/traccar/protocol/Jt600ProtocolDecoder.java b/src/org/traccar/protocol/Jt600ProtocolDecoder.java
index 197b4103a..80c584d21 100644
--- a/src/org/traccar/protocol/Jt600ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Jt600ProtocolDecoder.java
@@ -35,8 +35,8 @@ import org.traccar.model.Position;
public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
- public Jt600ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public Jt600ProtocolDecoder(String protocol) {
+ super(protocol);
}
private Position decodeNormalMessage(ChannelBuffer buf) throws Exception {
@@ -48,12 +48,10 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
// Get device by identifier
String id = Long.valueOf(ChannelBufferTools.readHexString(buf, 10)).toString();
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
- //return null;
+ if (!identify(id)) {
+ return null;
}
+ position.setDeviceId(getDeviceId());
// Protocol and type
int version = ChannelBufferTools.readHexInteger(buf, 1);
@@ -166,13 +164,10 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Get device by identifier
- String id = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Longitude
Double longitude = Double.valueOf(parser.group(index++));
diff --git a/src/org/traccar/protocol/KhdProtocolDecoder.java b/src/org/traccar/protocol/KhdProtocolDecoder.java
index 022def9eb..ed974d8ca 100644
--- a/src/org/traccar/protocol/KhdProtocolDecoder.java
+++ b/src/org/traccar/protocol/KhdProtocolDecoder.java
@@ -34,8 +34,8 @@ import org.traccar.model.Position;
public class KhdProtocolDecoder extends BaseProtocolDecoder {
- public KhdProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public KhdProtocolDecoder(String protocol) {
+ super(protocol);
}
private String readSerialNumber(ChannelBuffer buf) {
@@ -79,13 +79,11 @@ public class KhdProtocolDecoder extends BaseProtocolDecoder {
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
// Device identification
- String id = readSerialNumber(buf);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ if (!identify(readSerialNumber(buf))) {
+ return null;
}
-
+ position.setDeviceId(getDeviceId());
+
// Date and time
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
time.clear();
diff --git a/src/org/traccar/protocol/LaipacProtocolDecoder.java b/src/org/traccar/protocol/LaipacProtocolDecoder.java
index f95109b80..b868887ec 100644
--- a/src/org/traccar/protocol/LaipacProtocolDecoder.java
+++ b/src/org/traccar/protocol/LaipacProtocolDecoder.java
@@ -33,8 +33,8 @@ import org.traccar.model.Position;
public class LaipacProtocolDecoder extends BaseProtocolDecoder {
- public LaipacProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public LaipacProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -78,12 +78,10 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Identification
- String id = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ if (!identify(parser.group(index++))) {
+ return null;
}
+ position.setDeviceId(getDeviceId());
// Time
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
diff --git a/src/org/traccar/protocol/M2mProtocolDecoder.java b/src/org/traccar/protocol/M2mProtocolDecoder.java
index 46442fb4f..0daa07422 100644
--- a/src/org/traccar/protocol/M2mProtocolDecoder.java
+++ b/src/org/traccar/protocol/M2mProtocolDecoder.java
@@ -31,12 +31,11 @@ import org.traccar.model.Position;
public class M2mProtocolDecoder extends BaseProtocolDecoder {
- public M2mProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public M2mProtocolDecoder(String protocol) {
+ super(protocol);
}
private boolean firstPacket = true;
- private Long deviceId;
@Override
protected Object decode(
@@ -68,18 +67,14 @@ public class M2mProtocolDecoder extends BaseProtocolDecoder {
}
// Identification
- try {
- deviceId = getDataManager().getDeviceByImei(imei.toString()).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
- }
-
- } else if (deviceId != null) {
+ identify(imei.toString());
+
+ } else if (hasDeviceId()) {
// Create new position
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
// Date and time
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
diff --git a/src/org/traccar/protocol/ManPowerProtocolDecoder.java b/src/org/traccar/protocol/ManPowerProtocolDecoder.java
index 449a1b532..dea190715 100644
--- a/src/org/traccar/protocol/ManPowerProtocolDecoder.java
+++ b/src/org/traccar/protocol/ManPowerProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class ManPowerProtocolDecoder extends BaseProtocolDecoder {
- public ManPowerProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public ManPowerProtocolDecoder(String protocol) {
+ super(protocol);
}
static private Pattern pattern = Pattern.compile(
@@ -72,13 +72,10 @@ public class ManPowerProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Get device by IMEI
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Alarm message
extendedInfo.set("status", parser.group(index++));
@@ -95,7 +92,7 @@ public class ManPowerProtocolDecoder extends BaseProtocolDecoder {
position.setTime(time.getTime());
// Validity
- position.setValid(parser.group(index++).compareTo("A") == 0 ? true : false);
+ position.setValid(parser.group(index++).compareTo("A") == 0);
// Latitude
Double latitude = Double.valueOf(parser.group(index++));
diff --git a/src/org/traccar/protocol/MaxonProtocolDecoder.java b/src/org/traccar/protocol/MaxonProtocolDecoder.java
index eb1e43885..cd86e5e65 100644
--- a/src/org/traccar/protocol/MaxonProtocolDecoder.java
+++ b/src/org/traccar/protocol/MaxonProtocolDecoder.java
@@ -38,21 +38,12 @@ import org.traccar.model.Position;
*/
public class MaxonProtocolDecoder extends BaseProtocolDecoder {
- /**
- * Device ID
- */
private Position position = null;
- /**
- * Initialize
- */
- public MaxonProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public MaxonProtocolDecoder(String protocol) {
+ super(protocol);
}
- /**
- * Regular expressions pattern
- */
static private Pattern pattern = Pattern.compile(
"\\$GPRMC," +
"(\\d{2})(\\d{2})(\\d{2})\\.(\\d{2})," + // Time (HHMMSS.SSS)
@@ -66,12 +57,8 @@ public class MaxonProtocolDecoder extends BaseProtocolDecoder {
"(\\d{2})(\\d{2})(\\d{2})" + // Date (DDMMYY)
".+"); // Other (Checksumm)
- static private Pattern gpfidPattern = Pattern.compile(
- "\\$GPFID,(\\d+)$");
+ static private Pattern gpfidPattern = Pattern.compile("\\$GPFID,(\\d+)$");
- /**
- * Decode message"
- */
protected Object decode(
ChannelHandlerContext ctx, Channel channel, Object msg)
throws Exception {
@@ -102,7 +89,7 @@ public class MaxonProtocolDecoder extends BaseProtocolDecoder {
index += 1; // Skip milliseconds
// Validity
- position.setValid(parser.group(index++).compareTo("A") == 0 ? true : false);
+ position.setValid(parser.group(index++).compareTo("A") == 0);
// Latitude
Double latitude = Double.valueOf(parser.group(index++));
@@ -145,13 +132,10 @@ public class MaxonProtocolDecoder extends BaseProtocolDecoder {
Matcher parser = gpfidPattern.matcher(sentence);
if (parser.matches()) {
- String imei = parser.group(1);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(1))) {
return null;
}
+ position.setDeviceId(getDeviceId());
return position;
}
}
diff --git a/src/org/traccar/protocol/MegastekProtocolDecoder.java b/src/org/traccar/protocol/MegastekProtocolDecoder.java
index 2eed12fce..4a621245a 100644
--- a/src/org/traccar/protocol/MegastekProtocolDecoder.java
+++ b/src/org/traccar/protocol/MegastekProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class MegastekProtocolDecoder extends BaseProtocolDecoder {
- public MegastekProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public MegastekProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern patternGPRMC = Pattern.compile(
@@ -49,7 +49,6 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder {
"(\\d{2})(\\d{2})(\\d{2})" + // Date (DDMMYY)
"[^\\*]+\\*[0-9a-fA-F]{2}"); // Checksum
- //F,,imei:123456789012345,0/6,,Battery=100%,,0,,,5856,78A3;24
private static final Pattern patternSimple = Pattern.compile(
"[FL]," + // Flag
"([^,]*)," + // Alarm
@@ -200,17 +199,12 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder {
extendedInfo.set("alarm", parser.group(index++));
// IMEI
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception firstError) {
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception secondError) {
- Log.warning("Unknown device - " + imei + " (id - " + id + ")");
+ if (!identify(parser.group(index++), false)) {
+ if (!identify(id)) {
return null;
}
}
+ position.setDeviceId(getDeviceId());
// Satellites
extendedInfo.set("satellites", parser.group(index++));
@@ -248,13 +242,11 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder {
// Altitude
position.setAltitude(0.0);
-
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+
+ if (!identify(id)) {
return null;
}
+ position.setDeviceId(getDeviceId());
extendedInfo.set("mcc", parser.group(index++));
extendedInfo.set("mnc", parser.group(index++));
diff --git a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java
index 9c1f5bee9..547821c69 100644
--- a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java
+++ b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java
@@ -29,6 +29,7 @@ import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.traccar.BaseProtocolDecoder;
+import org.traccar.Context;
import org.traccar.database.DataManager;
import org.traccar.helper.Crc;
import org.traccar.helper.Log;
@@ -37,8 +38,8 @@ import org.traccar.model.Position;
public class MeiligaoProtocolDecoder extends BaseProtocolDecoder {
- public MeiligaoProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public MeiligaoProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -117,7 +118,7 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder {
}
private String getMeiligaoServer(Channel channel) {
- Properties p = getProperties();
+ Properties p = Context.getProps();
if (p != null && p.containsKey(getProtocol() + ".server")) {
return p.getProperty(getProtocol() + ".server");
@@ -179,13 +180,10 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder {
}
// Get device by id
- String imei = getImei(id);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(getImei(id))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Parse message
String sentence = buf.toString(
diff --git a/src/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/org/traccar/protocol/MeitrackProtocolDecoder.java
index cdeef155b..e213b7ddb 100644
--- a/src/org/traccar/protocol/MeitrackProtocolDecoder.java
+++ b/src/org/traccar/protocol/MeitrackProtocolDecoder.java
@@ -38,8 +38,8 @@ import org.traccar.model.Position;
public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
- public MeitrackProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public MeitrackProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -91,13 +91,10 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Identification
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Event
int event = Integer.valueOf(parser.group(index++));
@@ -191,22 +188,18 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
int index = ChannelBufferTools.find(buf, 0, buf.readableBytes(), ",");
// Identification
- long deviceId;
String imei = buf.toString(index + 1, 15, Charset.defaultCharset());
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(imei)) {
return null;
}
-
+
buf.skipBytes(index + 1 + 15 + 1 + 3 + 1 + 2 + 2 + 4);
while (buf.readableBytes() >= 0x34) {
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
// Event
extendedInfo.set("event", buf.readUnsignedByte());
diff --git a/src/org/traccar/protocol/MiniFinderProtocolDecoder.java b/src/org/traccar/protocol/MiniFinderProtocolDecoder.java
index 9a6c7396c..c37e44659 100644
--- a/src/org/traccar/protocol/MiniFinderProtocolDecoder.java
+++ b/src/org/traccar/protocol/MiniFinderProtocolDecoder.java
@@ -32,10 +32,8 @@ import org.traccar.model.Position;
public class MiniFinderProtocolDecoder extends BaseProtocolDecoder {
- private Long deviceId;
-
- public MiniFinderProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public MiniFinderProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -62,16 +60,11 @@ public class MiniFinderProtocolDecoder extends BaseProtocolDecoder {
// Identification
if (sentence.startsWith("!1")) {
- String imei = sentence.substring(3, sentence.length());
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
- }
+ identify(sentence.substring(3, sentence.length()));
}
// Location
- else if (sentence.startsWith("!D") && deviceId != null) {
+ else if (sentence.startsWith("!D") && hasDeviceId()) {
// Parse message
Matcher parser = pattern.matcher(sentence);
@@ -82,7 +75,7 @@ public class MiniFinderProtocolDecoder extends BaseProtocolDecoder {
// Create new position
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
Integer index = 1;
diff --git a/src/org/traccar/protocol/Mta6ProtocolDecoder.java b/src/org/traccar/protocol/Mta6ProtocolDecoder.java
index d8d1b9f98..f09cf32f1 100644
--- a/src/org/traccar/protocol/Mta6ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Mta6ProtocolDecoder.java
@@ -44,8 +44,8 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder {
private boolean simple;
- public Mta6ProtocolDecoder(DataManager dataManager, String protocol, Properties properties, boolean simple) {
- super(dataManager, protocol, properties);
+ public Mta6ProtocolDecoder(String protocol, boolean simple) {
+ super(protocol);
this.simple = simple;
}
@@ -121,7 +121,7 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder {
}
- private List<Position> parseFormatA(ChannelBuffer buf, long deviceId) {
+ private List<Position> parseFormatA(ChannelBuffer buf) {
List<Position> positions = new LinkedList<Position>();
FloatReader latitudeReader = new FloatReader();
@@ -131,7 +131,7 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder {
try {
while (buf.readable()) {
Position position = new Position();
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
short flags = buf.readUnsignedByte();
@@ -211,9 +211,9 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder {
return positions;
}
- private Position parseFormatA1(ChannelBuffer buf, long deviceId) {
+ private Position parseFormatA1(ChannelBuffer buf) {
Position position = new Position();
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
short flags = buf.readUnsignedByte();
@@ -303,11 +303,7 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder {
buf.skipBytes("id=".length());
int index = ChannelBufferTools.find(buf, buf.readerIndex(), length, "&");
String uniqueId = buf.toString(buf.readerIndex(), index - buf.readerIndex(), Charset.defaultCharset());
- long deviceId;
- try {
- deviceId = getDataManager().getDeviceByImei(uniqueId).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + uniqueId);
+ if (!identify(uniqueId)) {
return null;
}
buf.skipBytes(uniqueId.length());
@@ -330,9 +326,9 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder {
// Parse data
if (packetId == 0x31 || packetId == 0x32 || packetId == 0x36) {
if (simple) {
- return parseFormatA1(buf, deviceId);
+ return parseFormatA1(buf);
} else {
- return parseFormatA(buf, deviceId);
+ return parseFormatA(buf);
}
} //else if (0x34 0x38 0x4F 0x59)
diff --git a/src/org/traccar/protocol/MtxProtocolDecoder.java b/src/org/traccar/protocol/MtxProtocolDecoder.java
index c552e3831..150e95e3b 100644
--- a/src/org/traccar/protocol/MtxProtocolDecoder.java
+++ b/src/org/traccar/protocol/MtxProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class MtxProtocolDecoder extends BaseProtocolDecoder {
- public MtxProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public MtxProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -79,13 +79,10 @@ public class MtxProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Get device by IMEI
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Date
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
diff --git a/src/org/traccar/protocol/NavigilProtocolDecoder.java b/src/org/traccar/protocol/NavigilProtocolDecoder.java
index eb9ad96d3..f12e15fb6 100644
--- a/src/org/traccar/protocol/NavigilProtocolDecoder.java
+++ b/src/org/traccar/protocol/NavigilProtocolDecoder.java
@@ -33,8 +33,8 @@ import org.traccar.model.Position;
public class NavigilProtocolDecoder extends BaseProtocolDecoder {
- public NavigilProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public NavigilProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final int LEAP_SECONDS_DELTA = 25;
@@ -81,13 +81,13 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder {
}
}
- private Position parseUnitReport(ChannelBuffer buf, long deviceId, int sequenceNumber) {
+ private Position parseUnitReport(ChannelBuffer buf, int sequenceNumber) {
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
position.setValid(true);
extendedInfo.set("index", sequenceNumber);
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
buf.readUnsignedShort(); // report trigger
buf.readUnsignedShort(); // flags
@@ -118,13 +118,13 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder {
return position;
}
- private Position parseTg2Report(ChannelBuffer buf, long deviceId, int sequenceNumber) {
+ private Position parseTg2Report(ChannelBuffer buf, int sequenceNumber) {
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
position.setValid(true);
extendedInfo.set("index", sequenceNumber);
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
buf.readUnsignedShort(); // report trigger
buf.readUnsignedByte(); // reserved
@@ -157,12 +157,12 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder {
return position;
}
- private Position parsePositionReport(ChannelBuffer buf, long deviceId, int sequenceNumber, long timestamp) {
+ private Position parsePositionReport(ChannelBuffer buf, int sequenceNumber, long timestamp) {
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
extendedInfo.set("index", sequenceNumber);
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
position.setTime(convertTimestamp(timestamp));
position.setLatitude(buf.readMedium() * 0.00002);
@@ -181,12 +181,12 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder {
return position;
}
- private Position parsePositionReport2(ChannelBuffer buf, long deviceId, int sequenceNumber, long timestamp) {
+ private Position parsePositionReport2(ChannelBuffer buf, int sequenceNumber, long timestamp) {
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
extendedInfo.set("index", sequenceNumber);
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
position.setTime(convertTimestamp(timestamp));
position.setLatitude(buf.readInt() * 0.0000001);
@@ -208,12 +208,12 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder {
return position;
}
- private Position parseSnapshot4(ChannelBuffer buf, long deviceId, int sequenceNumber) {
+ private Position parseSnapshot4(ChannelBuffer buf, int sequenceNumber) {
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
extendedInfo.set("index", sequenceNumber);
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
buf.readUnsignedByte(); // report trigger
buf.readUnsignedByte(); // position fix source
@@ -249,12 +249,12 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder {
return position;
}
- private Position parseTrackingData(ChannelBuffer buf, long deviceId, int sequenceNumber, long timestamp) {
+ private Position parseTrackingData(ChannelBuffer buf, int sequenceNumber, long timestamp) {
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
extendedInfo.set("index", sequenceNumber);
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
position.setTime(convertTimestamp(timestamp));
buf.readUnsignedByte(); // tracking mode
@@ -296,12 +296,7 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder {
buf.readUnsignedShort(); // checksum
// Get device identifier
- long deviceId;
- String navigilDeviceId = String.valueOf(buf.readUnsignedInt());
- try {
- deviceId = getDataManager().getDeviceByImei(navigilDeviceId).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + navigilDeviceId);
+ if (!identify(String.valueOf(buf.readUnsignedInt()))) {
return null;
}
@@ -315,17 +310,17 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder {
// Parse messages
switch (messageId) {
case MESSAGE_UNIT_REPORT:
- return parseUnitReport(buf, deviceId, sequenceNumber);
+ return parseUnitReport(buf, sequenceNumber);
case MESSAGE_TG2_REPORT:
- return parseTg2Report(buf, deviceId, sequenceNumber);
+ return parseTg2Report(buf, sequenceNumber);
case MESSAGE_POSITION_REPORT:
- return parsePositionReport(buf, deviceId, sequenceNumber, timestamp);
+ return parsePositionReport(buf, sequenceNumber, timestamp);
case MESSAGE_POSITION_REPORT_2:
- return parsePositionReport2(buf, deviceId, sequenceNumber, timestamp);
+ return parsePositionReport2(buf, sequenceNumber, timestamp);
case MESSAGE_SNAPSHOT4:
- return parseSnapshot4(buf, deviceId, sequenceNumber);
+ return parseSnapshot4(buf, sequenceNumber);
case MESSAGE_TRACKING_DATA:
- return parseTrackingData(buf, deviceId, sequenceNumber, timestamp);
+ return parseTrackingData(buf, sequenceNumber, timestamp);
}
return null;
diff --git a/src/org/traccar/protocol/NavisProtocolDecoder.java b/src/org/traccar/protocol/NavisProtocolDecoder.java
index 4646d215f..8a5afc17f 100644
--- a/src/org/traccar/protocol/NavisProtocolDecoder.java
+++ b/src/org/traccar/protocol/NavisProtocolDecoder.java
@@ -37,15 +37,12 @@ import org.traccar.model.Position;
public class NavisProtocolDecoder extends BaseProtocolDecoder {
private String prefix;
- private long deviceId, serverId;
+ private long deviceUniqueId, serverId;
private static final Charset charset = Charset.defaultCharset();
- private String imei;
- private Long databaseDeviceId;
-
- public NavisProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public NavisProtocolDecoder(String protocol) {
+ super(protocol);
}
// Format types
@@ -88,7 +85,7 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder {
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- position.setDeviceId(databaseDeviceId);
+ position.setDeviceId(getDeviceId());
position.setAltitude(0.0);
// Format type
@@ -262,12 +259,8 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder {
private Object processHandshake(Channel channel, ChannelBuffer buf) {
buf.readByte(); // semicolon symbol
- imei = buf.toString(Charset.defaultCharset());
- try {
- databaseDeviceId = getDataManager().getDeviceByImei(imei).getId();
+ if (identify(buf.toString(Charset.defaultCharset()))) {
sendReply(channel, ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "*<S", charset));
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
}
return null;
}
@@ -283,7 +276,7 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder {
private void sendReply(Channel channel, ChannelBuffer data) {
ChannelBuffer header = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 16);
header.writeBytes(ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, prefix, charset));
- header.writeInt((int) deviceId);
+ header.writeInt((int) deviceUniqueId);
header.writeInt((int) serverId);
header.writeShort(data.readableBytes());
header.writeByte(checksum(data));
@@ -305,7 +298,7 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder {
prefix = buf.toString(buf.readerIndex(), 4, charset);
buf.skipBytes(prefix.length()); // prefix @NTC by default
serverId = buf.readUnsignedInt();
- deviceId = buf.readUnsignedInt();
+ deviceUniqueId = buf.readUnsignedInt();
int length = buf.readUnsignedShort();
buf.skipBytes(2); // header and data XOR checksum
diff --git a/src/org/traccar/protocol/NoranProtocolDecoder.java b/src/org/traccar/protocol/NoranProtocolDecoder.java
index b6fa93607..bc807711d 100644
--- a/src/org/traccar/protocol/NoranProtocolDecoder.java
+++ b/src/org/traccar/protocol/NoranProtocolDecoder.java
@@ -35,8 +35,8 @@ import org.traccar.model.Position;
public class NoranProtocolDecoder extends BaseProtocolDecoder {
- public NoranProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public NoranProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final int MSG_UPLOAD_POSITION = 0x0008;
@@ -111,13 +111,11 @@ public class NoranProtocolDecoder extends BaseProtocolDecoder {
// Identification
String id = buf.readBytes(11).toString(Charset.defaultCharset()).replaceAll("[^\\p{Print}]", "");
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ if (!identify(id)) {
return null;
}
-
+ position.setDeviceId(getDeviceId());
+
// IO status
extendedInfo.set("io", buf.readUnsignedByte());
diff --git a/src/org/traccar/protocol/OrionProtocolDecoder.java b/src/org/traccar/protocol/OrionProtocolDecoder.java
index f20bb6d72..3b4b598b1 100644
--- a/src/org/traccar/protocol/OrionProtocolDecoder.java
+++ b/src/org/traccar/protocol/OrionProtocolDecoder.java
@@ -34,8 +34,8 @@ import org.traccar.model.Position;
public class OrionProtocolDecoder extends BaseProtocolDecoder {
- public OrionProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public OrionProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final int TYPE_USERLOG = 0;
@@ -74,23 +74,18 @@ public class OrionProtocolDecoder extends BaseProtocolDecoder {
if ((header & 0x40) != 0) {
sendResponse(channel, buf);
}
-
- String id = String.valueOf(buf.readUnsignedInt());
- long deviceId;
- try {
- deviceId = getDataManager().getDeviceByImei(id).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+
+ if (!identify(String.valueOf(buf.readUnsignedInt()))) {
return null;
}
-
+
List<Position> positions = new LinkedList<Position>();
for (int i = 0; i < (header & 0x0f); i++) {
// Create new position
Position position = new Position();
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
extendedInfo.set("event", buf.readUnsignedByte());
diff --git a/src/org/traccar/protocol/OsmAndProtocolDecoder.java b/src/org/traccar/protocol/OsmAndProtocolDecoder.java
index f773a4633..85cf1219c 100644
--- a/src/org/traccar/protocol/OsmAndProtocolDecoder.java
+++ b/src/org/traccar/protocol/OsmAndProtocolDecoder.java
@@ -41,8 +41,8 @@ import org.traccar.model.Position;
public class OsmAndProtocolDecoder extends BaseProtocolDecoder {
- public OsmAndProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public OsmAndProtocolDecoder(String protocol) {
+ super(protocol);
}
@Override
@@ -65,12 +65,10 @@ public class OsmAndProtocolDecoder extends BaseProtocolDecoder {
// Identification
String id = params.get(params.containsKey("id") ? "id" : "deviceid").get(0);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ if (!identify(id)) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Decode position
position.setValid(true);
diff --git a/src/org/traccar/protocol/PiligrimProtocolDecoder.java b/src/org/traccar/protocol/PiligrimProtocolDecoder.java
index 02c86152d..1c0faef37 100644
--- a/src/org/traccar/protocol/PiligrimProtocolDecoder.java
+++ b/src/org/traccar/protocol/PiligrimProtocolDecoder.java
@@ -42,8 +42,8 @@ import org.traccar.model.Position;
public class PiligrimProtocolDecoder extends BaseProtocolDecoder {
- public PiligrimProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public PiligrimProtocolDecoder(String protocol) {
+ super(protocol);
}
private void sendResponse(Channel channel, String message) {
@@ -85,13 +85,8 @@ public class PiligrimProtocolDecoder extends BaseProtocolDecoder {
sendResponse(channel, "BINGPS: OK");
// Identification
- long deviceId;
QueryStringDecoder decoder = new QueryStringDecoder(request.getUri());
- String imei = decoder.getParameters().get("imei").get(0);
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(decoder.getParameters().get("imei").get(0))) {
return null;
}
@@ -108,7 +103,7 @@ public class PiligrimProtocolDecoder extends BaseProtocolDecoder {
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
// Time
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
@@ -178,9 +173,7 @@ public class PiligrimProtocolDecoder extends BaseProtocolDecoder {
} else if (type == MSG_EVENTS) {
buf.skipBytes(13);
-
}
-
}
return positions;
diff --git a/src/org/traccar/protocol/ProgressProtocolDecoder.java b/src/org/traccar/protocol/ProgressProtocolDecoder.java
index 3f120445c..04584b884 100644
--- a/src/org/traccar/protocol/ProgressProtocolDecoder.java
+++ b/src/org/traccar/protocol/ProgressProtocolDecoder.java
@@ -34,22 +34,15 @@ import org.traccar.helper.Log;
import org.traccar.model.ExtendedInfoFormatter;
import org.traccar.model.Position;
-/**
- * Progress tracker protocol decoder
- */
public class ProgressProtocolDecoder extends BaseProtocolDecoder {
- private long deviceId;
private long lastIndex;
private long newIndex;
- public ProgressProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public ProgressProtocolDecoder(String protocol) {
+ super(protocol);
}
- /*
- * Message types
- */
private static final int MSG_NULL = 0;
private static final int MSG_IDENT = 1;
private static final int MSG_IDENT_FULL = 2;
@@ -80,9 +73,6 @@ public class ProgressProtocolDecoder extends BaseProtocolDecoder {
}*/
}
- /**
- * Request archive messages
- */
private void requestArchive(Channel channel) {
if (lastIndex == 0) {
lastIndex = newIndex;
@@ -112,16 +102,13 @@ public class ProgressProtocolDecoder extends BaseProtocolDecoder {
buf.skipBytes(length);
length = buf.readUnsignedShort();
String imei = buf.readBytes(length).toString(Charset.defaultCharset());
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
+ if (identify(imei)) {
loadLastIndex();
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei + " (id - " + id + ")");
}
}
// Position
- else if (deviceId != 0 && (type == MSG_POINT || type == MSG_ALARM || type == MSG_LOGMSG)) {
+ else if (hasDeviceId() && (type == MSG_POINT || type == MSG_ALARM || type == MSG_LOGMSG)) {
List<Position> positions = new LinkedList<Position>();
int recordCount = 1;
@@ -132,7 +119,7 @@ public class ProgressProtocolDecoder extends BaseProtocolDecoder {
for (int j = 0; j < recordCount; j++) {
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
// Message index
if (type == MSG_LOGMSG) {
diff --git a/src/org/traccar/protocol/Pt3000ProtocolDecoder.java b/src/org/traccar/protocol/Pt3000ProtocolDecoder.java
index 86c438f6c..513fdbb4b 100644
--- a/src/org/traccar/protocol/Pt3000ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Pt3000ProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class Pt3000ProtocolDecoder extends BaseProtocolDecoder {
- public Pt3000ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public Pt3000ProtocolDecoder(String protocol) {
+ super(protocol);
}
static private Pattern pattern = Pattern.compile(
@@ -70,12 +70,10 @@ public class Pt3000ProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Identifier
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
- }
+ if (!identify(parser.group(index++))) {
+ return null;
+ }
+ position.setDeviceId(getDeviceId());
// Time
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
@@ -85,7 +83,7 @@ public class Pt3000ProtocolDecoder extends BaseProtocolDecoder {
time.set(Calendar.SECOND, Integer.valueOf(parser.group(index++)));
// Validity
- position.setValid(parser.group(index++).compareTo("A") == 0 ? true : false);
+ position.setValid(parser.group(index++).compareTo("A") == 0);
// Latitude
Double latitude = Double.valueOf(parser.group(index++));
diff --git a/src/org/traccar/protocol/Pt502ProtocolDecoder.java b/src/org/traccar/protocol/Pt502ProtocolDecoder.java
index 72f95a0f6..2cf5ad3d6 100644
--- a/src/org/traccar/protocol/Pt502ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Pt502ProtocolDecoder.java
@@ -33,8 +33,8 @@ import org.traccar.model.Position;
public class Pt502ProtocolDecoder extends BaseProtocolDecoder {
- public Pt502ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public Pt502ProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -71,13 +71,10 @@ public class Pt502ProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Get device by IMEI
- String id = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Time
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
diff --git a/src/org/traccar/protocol/RitiProtocolDecoder.java b/src/org/traccar/protocol/RitiProtocolDecoder.java
index 4bc04501c..58e744f1a 100644
--- a/src/org/traccar/protocol/RitiProtocolDecoder.java
+++ b/src/org/traccar/protocol/RitiProtocolDecoder.java
@@ -35,8 +35,8 @@ import org.traccar.model.Position;
public class RitiProtocolDecoder extends BaseProtocolDecoder {
- public RitiProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public RitiProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -66,13 +66,11 @@ public class RitiProtocolDecoder extends BaseProtocolDecoder {
buf.skipBytes(2); // header
// Get device id
- String id = String.valueOf(buf.readUnsignedShort());
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ if (!identify(String.valueOf(buf.readUnsignedShort()))) {
+ return null;
}
-
+ position.setDeviceId(getDeviceId());
+
extendedInfo.set("mode", buf.readUnsignedByte());
extendedInfo.set("command", buf.readUnsignedByte());
extendedInfo.set("power", buf.readUnsignedShort());
diff --git a/src/org/traccar/protocol/RuptelaProtocolDecoder.java b/src/org/traccar/protocol/RuptelaProtocolDecoder.java
index 0574aa2d8..b83d9f721 100644
--- a/src/org/traccar/protocol/RuptelaProtocolDecoder.java
+++ b/src/org/traccar/protocol/RuptelaProtocolDecoder.java
@@ -33,8 +33,8 @@ import org.traccar.model.Position;
public class RuptelaProtocolDecoder extends BaseProtocolDecoder {
- public RuptelaProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public RuptelaProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final int COMMAND_RECORDS = 0x01;
@@ -49,14 +49,10 @@ public class RuptelaProtocolDecoder extends BaseProtocolDecoder {
// Identify device
String imei = String.format("%015d", buf.readLong());
- long deviceId;
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(imei)) {
return null;
}
-
+
int type = buf.readUnsignedByte();
if (type == COMMAND_RECORDS) {
@@ -68,7 +64,7 @@ public class RuptelaProtocolDecoder extends BaseProtocolDecoder {
for (int i = 0; i < count; i++) {
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
// Time
position.setTime(new Date(buf.readUnsignedInt() * 1000));
diff --git a/src/org/traccar/protocol/SanavProtocolDecoder.java b/src/org/traccar/protocol/SanavProtocolDecoder.java
index 343dc87c8..abdb25d2c 100644
--- a/src/org/traccar/protocol/SanavProtocolDecoder.java
+++ b/src/org/traccar/protocol/SanavProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class SanavProtocolDecoder extends BaseProtocolDecoder {
- public SanavProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public SanavProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -69,13 +69,10 @@ public class SanavProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Identification
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Time
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
diff --git a/src/org/traccar/protocol/SkypatrolProtocolDecoder.java b/src/org/traccar/protocol/SkypatrolProtocolDecoder.java
index aa47e42fb..51150a8e9 100644
--- a/src/org/traccar/protocol/SkypatrolProtocolDecoder.java
+++ b/src/org/traccar/protocol/SkypatrolProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class SkypatrolProtocolDecoder extends BaseProtocolDecoder {
- public SkypatrolProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public SkypatrolProtocolDecoder(String protocol) {
+ super(protocol);
}
private static boolean checkBit(long mask, int bit) {
@@ -98,12 +98,10 @@ public class SkypatrolProtocolDecoder extends BaseProtocolDecoder {
Log.warning("No device id field");
return null;
}
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ if (!identify(id)) {
return null;
}
+ position.setDeviceId(getDeviceId());
// IO data
if (checkBit(mask, 3)) {
diff --git a/src/org/traccar/protocol/Stl060ProtocolDecoder.java b/src/org/traccar/protocol/Stl060ProtocolDecoder.java
index 51af0941e..44cf20118 100644
--- a/src/org/traccar/protocol/Stl060ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Stl060ProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class Stl060ProtocolDecoder extends BaseProtocolDecoder {
- public Stl060ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public Stl060ProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -75,13 +75,10 @@ public class Stl060ProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Device identification
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Date
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
diff --git a/src/org/traccar/protocol/SuntechProtocolDecoder.java b/src/org/traccar/protocol/SuntechProtocolDecoder.java
index cdfca7905..b2bbcf573 100644
--- a/src/org/traccar/protocol/SuntechProtocolDecoder.java
+++ b/src/org/traccar/protocol/SuntechProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class SuntechProtocolDecoder extends BaseProtocolDecoder {
- public SuntechProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public SuntechProtocolDecoder(String protocol) {
+ super(protocol);
}
static private Pattern pattern = Pattern.compile(
@@ -70,13 +70,10 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder {
int index = 1;
// Identifier
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Version
extendedInfo.set("version", parser.group(index++));
diff --git a/src/org/traccar/protocol/SyrusProtocolDecoder.java b/src/org/traccar/protocol/SyrusProtocolDecoder.java
index ee11b35ef..5b7440bf9 100644
--- a/src/org/traccar/protocol/SyrusProtocolDecoder.java
+++ b/src/org/traccar/protocol/SyrusProtocolDecoder.java
@@ -35,9 +35,8 @@ public class SyrusProtocolDecoder extends BaseProtocolDecoder {
boolean sendResponse;
-
- public SyrusProtocolDecoder(DataManager dataManager, String protocol, Properties properties, boolean sendResponse) {
- super(dataManager, protocol, properties);
+ public SyrusProtocolDecoder(String protocol, boolean sendResponse) {
+ super(protocol);
this.sendResponse = sendResponse;
}
@@ -102,7 +101,6 @@ public class SyrusProtocolDecoder extends BaseProtocolDecoder {
}
// Find device ID
- Long deviceId = null;
beginIndex = sentence.indexOf(";ID=");
if (beginIndex != -1) {
beginIndex += 4;
@@ -113,13 +111,10 @@ public class SyrusProtocolDecoder extends BaseProtocolDecoder {
// Find device in database
String id = sentence.substring(beginIndex, endIndex);
- try {
- deviceId = getDataManager().getDeviceByImei(id).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ if (!identify(id)) {
return null;
}
-
+
// Send response
if (sendResponse && channel != null) {
channel.write(id);
@@ -137,7 +132,7 @@ public class SyrusProtocolDecoder extends BaseProtocolDecoder {
// Create new position
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
Integer index = 1;
diff --git a/src/org/traccar/protocol/T55ProtocolDecoder.java b/src/org/traccar/protocol/T55ProtocolDecoder.java
index 25b7f367f..ccf56ea41 100644
--- a/src/org/traccar/protocol/T55ProtocolDecoder.java
+++ b/src/org/traccar/protocol/T55ProtocolDecoder.java
@@ -32,10 +32,8 @@ import org.traccar.model.Position;
public class T55ProtocolDecoder extends BaseProtocolDecoder {
- private Long deviceId;
-
- public T55ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public T55ProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern patternGPRMC = Pattern.compile(
@@ -83,15 +81,7 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder {
"(-?\\d+\\.\\d+)," + // Altitude
"(\\d+\\.?\\d*)," + // Battery
".+");
-
- private void identify(String id) {
- try {
- deviceId = getDataManager().getDeviceByImei(id).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
- }
- }
-
+
@Override
protected Object decode(
ChannelHandlerContext ctx, Channel channel, Object msg)
@@ -135,7 +125,7 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder {
}
// Location
- else if (sentence.startsWith("$GPRMC") && deviceId != null) {
+ else if (sentence.startsWith("$GPRMC") && hasDeviceId()) {
// Send response
if (channel != null) {
@@ -151,7 +141,7 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder {
// Create new position
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
Integer index = 1;
@@ -207,7 +197,7 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder {
}
// Location
- else if (sentence.startsWith("$GPGGA") && deviceId != null) {
+ else if (sentence.startsWith("$GPGGA") && hasDeviceId()) {
// Parse message
Matcher parser = patternGPGGA.matcher(sentence);
@@ -218,7 +208,7 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder {
// Create new position
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
Integer index = 1;
@@ -259,7 +249,7 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder {
}
// Location
- else if (sentence.startsWith("$GPRMA") && deviceId != null) {
+ else if (sentence.startsWith("$GPRMA") && hasDeviceId()) {
// Parse message
Matcher parser = patternGPRMA.matcher(sentence);
@@ -270,7 +260,7 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder {
// Create new position
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
Integer index = 1;
@@ -316,7 +306,7 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder {
}
// Location
- else if (sentence.startsWith("$TRCCR") && deviceId != null) {
+ else if (sentence.startsWith("$TRCCR") && hasDeviceId()) {
// Parse message
Matcher parser = patternTRCCR.matcher(sentence);
@@ -327,7 +317,7 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder {
// Create new position
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
Integer index = 1;
diff --git a/src/org/traccar/protocol/TelikProtocolDecoder.java b/src/org/traccar/protocol/TelikProtocolDecoder.java
index 84dd6fb0b..15ad77e6b 100644
--- a/src/org/traccar/protocol/TelikProtocolDecoder.java
+++ b/src/org/traccar/protocol/TelikProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class TelikProtocolDecoder extends BaseProtocolDecoder {
- public TelikProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public TelikProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -70,13 +70,10 @@ public class TelikProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Get device by IMEI
- String id = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Message type
extendedInfo.set("type", parser.group(index++));
diff --git a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
index 961d4e73b..f39a81fbc 100644
--- a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
+++ b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
@@ -36,8 +36,8 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
private long deviceId;
- public TeltonikaProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public TeltonikaProtocolDecoder(String protocol) {
+ super(protocol);
}
private void parseIdentification(Channel channel, ChannelBuffer buf) {
@@ -45,13 +45,8 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
int length = buf.readUnsignedShort();
String imei = buf.toString(buf.readerIndex(), length, Charset.defaultCharset());
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
- result = true;
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
- }
-
+ result = identify(imei);
+
if (channel != null) {
ChannelBuffer response = ChannelBuffers.directBuffer(1);
response.writeByte(result ? 1 : 0);
diff --git a/src/org/traccar/protocol/Tk102ProtocolDecoder.java b/src/org/traccar/protocol/Tk102ProtocolDecoder.java
index bb9a5fbd2..b32b020d1 100644
--- a/src/org/traccar/protocol/Tk102ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Tk102ProtocolDecoder.java
@@ -32,10 +32,8 @@ import org.traccar.model.Position;
public class Tk102ProtocolDecoder extends BaseProtocolDecoder {
- private Long deviceId;
-
- public Tk102ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public Tk102ProtocolDecoder(String protocol) {
+ super(protocol);
}
static private Pattern pattern = Pattern.compile(
@@ -59,11 +57,7 @@ public class Tk102ProtocolDecoder extends BaseProtocolDecoder {
// Login
if (sentence.startsWith("[!")) {
- String imei = sentence.substring(14, 14 + 15);
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(sentence.substring(14, 14 + 15))) {
return null;
}
@@ -78,7 +72,7 @@ public class Tk102ProtocolDecoder extends BaseProtocolDecoder {
}
// Parse message
- else if (deviceId != null) {
+ else if (hasDeviceId()) {
// Parse message
Matcher parser = pattern.matcher(sentence);
@@ -89,7 +83,7 @@ public class Tk102ProtocolDecoder extends BaseProtocolDecoder {
// Create new position
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
Integer index = 1;
@@ -101,7 +95,7 @@ public class Tk102ProtocolDecoder extends BaseProtocolDecoder {
time.set(Calendar.SECOND, Integer.valueOf(parser.group(index++)));
// Validity
- position.setValid(parser.group(index++).compareTo("A") == 0 ? true : false);
+ position.setValid(parser.group(index++).compareTo("A") == 0);
// Latitude
Double latitude = Double.valueOf(parser.group(index++));
diff --git a/src/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java
index f8955b1df..fa589956a 100644
--- a/src/org/traccar/protocol/Tk103ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Tk103ProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class Tk103ProtocolDecoder extends BaseProtocolDecoder {
- public Tk103ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public Tk103ProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -89,18 +89,10 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Get device by IMEI
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- // Compatibility mode (remove in future)
- try {
- position.setDeviceId(getDataManager().getDeviceByImei("000" + imei).getId());
- } catch(Exception error2) {
- Log.warning("Unknown device - " + imei);
- return null;
- }
+ if (!identify(parser.group(index++))) {
+ return null;
}
+ position.setDeviceId(getDeviceId());
// Date
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
diff --git a/src/org/traccar/protocol/Tlt2hProtocolDecoder.java b/src/org/traccar/protocol/Tlt2hProtocolDecoder.java
index 0e17fc70c..01c1ac2aa 100644
--- a/src/org/traccar/protocol/Tlt2hProtocolDecoder.java
+++ b/src/org/traccar/protocol/Tlt2hProtocolDecoder.java
@@ -34,8 +34,8 @@ import org.traccar.model.Position;
public class Tlt2hProtocolDecoder extends BaseProtocolDecoder {
- public Tlt2hProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public Tlt2hProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern patternHeader = Pattern.compile(
@@ -75,15 +75,10 @@ public class Tlt2hProtocolDecoder extends BaseProtocolDecoder {
}
// Get device identifier
- String imei = parser.group(1);
- long deviceId;
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(1))) {
return null;
}
-
+
// Get status
String status = parser.group(2);
@@ -95,7 +90,7 @@ public class Tlt2hProtocolDecoder extends BaseProtocolDecoder {
if (parser.matches()) {
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
Integer index = 1;
diff --git a/src/org/traccar/protocol/TopflytechProtocolDecoder.java b/src/org/traccar/protocol/TopflytechProtocolDecoder.java
index 9e9a7e3e3..20c4e54ad 100644
--- a/src/org/traccar/protocol/TopflytechProtocolDecoder.java
+++ b/src/org/traccar/protocol/TopflytechProtocolDecoder.java
@@ -34,8 +34,8 @@ public class TopflytechProtocolDecoder extends BaseProtocolDecoder {
private Long deviceId;
- public TopflytechProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public TopflytechProtocolDecoder(String protocol) {
+ super(protocol);
}
static private Pattern pattern = Pattern.compile(
@@ -71,13 +71,10 @@ public class TopflytechProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Identifier
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Time
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
@@ -91,7 +88,7 @@ public class TopflytechProtocolDecoder extends BaseProtocolDecoder {
position.setTime(time.getTime());
// Validity
- position.setValid(parser.group(index++).compareTo("A") == 0 ? true : false);
+ position.setValid(parser.group(index++).compareTo("A") == 0);
// Latitude
Double latitude = Double.valueOf(parser.group(index++));
diff --git a/src/org/traccar/protocol/TotemProtocolDecoder.java b/src/org/traccar/protocol/TotemProtocolDecoder.java
index 5c0cc9bec..ae8335b78 100644
--- a/src/org/traccar/protocol/TotemProtocolDecoder.java
+++ b/src/org/traccar/protocol/TotemProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class TotemProtocolDecoder extends BaseProtocolDecoder {
- public TotemProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public TotemProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern patternFirst = Pattern.compile(
@@ -156,7 +156,7 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder {
} else if (format == MessageFormat.third) {
parser = patternThird.matcher(sentence);
}
- if (parser == null || !parser.matches()) {
+ if (!parser.matches()) {
return null;
}
@@ -167,13 +167,10 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Get device by IMEI
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Alarm type
extendedInfo.set("alarm", parser.group(index++));
diff --git a/src/org/traccar/protocol/Tr20ProtocolDecoder.java b/src/org/traccar/protocol/Tr20ProtocolDecoder.java
index fb6f319d5..9bd1ccaaf 100644
--- a/src/org/traccar/protocol/Tr20ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Tr20ProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class Tr20ProtocolDecoder extends BaseProtocolDecoder {
- public Tr20ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public Tr20ProtocolDecoder(String protocol) {
+ super(protocol);
}
static private Pattern patternPing = Pattern.compile(
@@ -85,16 +85,13 @@ public class Tr20ProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Get device by id
- String id = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Validity
- position.setValid(parser.group(index++).compareTo("A") == 0 ? true : false);
+ position.setValid(parser.group(index++).compareTo("A") == 0);
// Time
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
diff --git a/src/org/traccar/protocol/Tr900ProtocolDecoder.java b/src/org/traccar/protocol/Tr900ProtocolDecoder.java
index da307efc9..f8890f954 100644
--- a/src/org/traccar/protocol/Tr900ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Tr900ProtocolDecoder.java
@@ -31,8 +31,8 @@ import java.util.regex.Pattern;
public class Tr900ProtocolDecoder extends BaseProtocolDecoder {
- public Tr900ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public Tr900ProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -76,13 +76,10 @@ public class Tr900ProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Identification
- String id = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Validity
position.setValid(parser.group(index++).compareTo("1") == 0);
diff --git a/src/org/traccar/protocol/TrackboxProtocolDecoder.java b/src/org/traccar/protocol/TrackboxProtocolDecoder.java
index 186bc24cd..5be74b15d 100644
--- a/src/org/traccar/protocol/TrackboxProtocolDecoder.java
+++ b/src/org/traccar/protocol/TrackboxProtocolDecoder.java
@@ -32,10 +32,8 @@ import org.traccar.model.Position;
public class TrackboxProtocolDecoder extends BaseProtocolDecoder {
- private Long deviceId;
-
- public TrackboxProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public TrackboxProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -66,11 +64,8 @@ public class TrackboxProtocolDecoder extends BaseProtocolDecoder {
if (sentence.startsWith("a=connect")) {
String id = sentence.substring(sentence.indexOf("i=") + 2);
- try {
- deviceId = getDataManager().getDeviceByImei(id).getId();
+ if (identify(id)) {
sendResponse(channel);
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
}
}
@@ -84,7 +79,7 @@ public class TrackboxProtocolDecoder extends BaseProtocolDecoder {
// Create new position
Position position = new Position();
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
Integer index = 1;
diff --git a/src/org/traccar/protocol/TramigoProtocolDecoder.java b/src/org/traccar/protocol/TramigoProtocolDecoder.java
index a31f3294b..e0bab0483 100644
--- a/src/org/traccar/protocol/TramigoProtocolDecoder.java
+++ b/src/org/traccar/protocol/TramigoProtocolDecoder.java
@@ -37,8 +37,8 @@ import java.util.regex.Pattern;
public class TramigoProtocolDecoder extends BaseProtocolDecoder {
- public TramigoProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public TramigoProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final int MSG_COMPACT = 0x0100;
@@ -68,12 +68,10 @@ public class TramigoProtocolDecoder extends BaseProtocolDecoder {
position.setValid(true);
// Get device id
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(String.valueOf(id)).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ if (!identify(String.valueOf(id))) {
return null;
}
+ position.setDeviceId(getDeviceId());
if (protocol == 0x01 && (type == MSG_COMPACT || type == MSG_FULL)) {
@@ -147,7 +145,6 @@ public class TramigoProtocolDecoder extends BaseProtocolDecoder {
position.setExtendedInfo(extendedInfo.toString());
return position;
-
}
return null;
diff --git a/src/org/traccar/protocol/TytanProtocolDecoder.java b/src/org/traccar/protocol/TytanProtocolDecoder.java
index 5b3772d31..e0dc7f68e 100644
--- a/src/org/traccar/protocol/TytanProtocolDecoder.java
+++ b/src/org/traccar/protocol/TytanProtocolDecoder.java
@@ -34,13 +34,10 @@ import org.traccar.model.Position;
public class TytanProtocolDecoder extends BaseProtocolDecoder {
- public TytanProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public TytanProtocolDecoder(String protocol) {
+ super(protocol);
}
- private static final int MSG_HEARTBEAT = 0x1A;
- private static final int MSG_DATA = 0x10;
-
@Override
protected Object decode(
ChannelHandlerContext ctx, Channel channel, SocketAddress remoteAddress, Object msg)
@@ -58,21 +55,17 @@ public class TytanProtocolDecoder extends BaseProtocolDecoder {
}
String id = String.valueOf(buf.readUnsignedInt());
- long deviceId;
- try {
- deviceId = getDataManager().getDeviceByImei(id).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ if (!identify(id)) {
return null;
}
-
+
List<Position> positions = new LinkedList<Position>();
while (buf.readable()) {
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
int end = buf.readerIndex() + buf.readUnsignedByte();
diff --git a/src/org/traccar/protocol/UlbotechProtocolDecoder.java b/src/org/traccar/protocol/UlbotechProtocolDecoder.java
index c5f63812e..48122a8f3 100644
--- a/src/org/traccar/protocol/UlbotechProtocolDecoder.java
+++ b/src/org/traccar/protocol/UlbotechProtocolDecoder.java
@@ -30,8 +30,8 @@ import java.util.Properties;
public class UlbotechProtocolDecoder extends BaseProtocolDecoder {
- public UlbotechProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public UlbotechProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final short DATA_GPS = 0x01;
@@ -63,11 +63,10 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder {
// Get device id
String imei = ChannelBufferTools.readHexString(buf, 16).substring(1);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(imei)) {
+ return null;
}
+ position.setDeviceId(getDeviceId());
// Time
long seconds = buf.readUnsignedInt() & 0x7fffffffl;
@@ -82,7 +81,6 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder {
switch (type) {
case DATA_GPS:
-
position.setValid(true);
position.setLatitude(buf.readInt() / 1000000.0);
position.setLongitude(buf.readInt() / 1000000.0);
@@ -90,10 +88,8 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder {
position.setSpeed(buf.readUnsignedShort() * 0.539957);
position.setCourse((double) buf.readUnsignedShort());
extendedInfo.set("hdop", buf.readUnsignedShort());
-
break;
-
default:
buf.skipBytes(length);
break;
diff --git a/src/org/traccar/protocol/V680ProtocolDecoder.java b/src/org/traccar/protocol/V680ProtocolDecoder.java
index 95f4e101c..6e85640c0 100644
--- a/src/org/traccar/protocol/V680ProtocolDecoder.java
+++ b/src/org/traccar/protocol/V680ProtocolDecoder.java
@@ -32,10 +32,8 @@ import org.traccar.model.Position;
public class V680ProtocolDecoder extends BaseProtocolDecoder {
- private Long deviceId;
-
- public V680ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public V680ProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -68,11 +66,7 @@ public class V680ProtocolDecoder extends BaseProtocolDecoder {
// Detect device ID
if (sentence.length() == 16) {
String imei = sentence.substring(1, sentence.length());
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
- }
+ identify(imei);
} else {
// Parse message
@@ -89,17 +83,12 @@ public class V680ProtocolDecoder extends BaseProtocolDecoder {
// Get device by IMEI
String imei = parser.group(index++);
if (imei != null) {
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
- return null;
- }
+ identify(imei);
}
- if (deviceId == null) {
+ if (!hasDeviceId()) {
return null;
}
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
// User
extendedInfo.set("user", parser.group(index++));
diff --git a/src/org/traccar/protocol/VisiontekProtocolDecoder.java b/src/org/traccar/protocol/VisiontekProtocolDecoder.java
index 242ac1083..b61500bd9 100644
--- a/src/org/traccar/protocol/VisiontekProtocolDecoder.java
+++ b/src/org/traccar/protocol/VisiontekProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class VisiontekProtocolDecoder extends BaseProtocolDecoder {
- public VisiontekProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public VisiontekProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -81,22 +81,11 @@ public class VisiontekProtocolDecoder extends BaseProtocolDecoder {
// Device identification
String id = parser.group(index++);
String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception error) {
- if (imei != null) {
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error2) {
- Log.warning("Unknown device - " + id);
- return null;
- }
- } else {
- Log.warning("Unknown device - " + id);
- return null;
- }
+ if (!identify(id, false) && !identify(imei)) {
+ return null;
}
-
+ position.setDeviceId(getDeviceId());
+
// Date
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
time.clear();
diff --git a/src/org/traccar/protocol/WialonProtocolDecoder.java b/src/org/traccar/protocol/WialonProtocolDecoder.java
index 6c4c0e8db..76cf9b924 100644
--- a/src/org/traccar/protocol/WialonProtocolDecoder.java
+++ b/src/org/traccar/protocol/WialonProtocolDecoder.java
@@ -34,10 +34,8 @@ import org.traccar.model.Position;
public class WialonProtocolDecoder extends BaseProtocolDecoder {
- private Long deviceId;
-
- public WialonProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public WialonProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -75,14 +73,14 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder {
// Parse message
Matcher parser = pattern.matcher(substring);
- if (deviceId == null || !parser.matches()) {
+ if (!hasDeviceId() || !parser.matches()) {
return null;
}
// Create new position
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
Integer index = 1;
@@ -187,11 +185,8 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder {
// Detect device ID
if (sentence.startsWith("#L#")) {
String imei = sentence.substring(3, sentence.indexOf(';'));
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
+ if (identify(imei)) {
sendResponse(channel, "#AL#", 1);
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
}
}
diff --git a/src/org/traccar/protocol/WondexProtocolDecoder.java b/src/org/traccar/protocol/WondexProtocolDecoder.java
index a9068e7be..98b75b0d2 100644
--- a/src/org/traccar/protocol/WondexProtocolDecoder.java
+++ b/src/org/traccar/protocol/WondexProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class WondexProtocolDecoder extends BaseProtocolDecoder {
- public WondexProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public WondexProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -72,13 +72,10 @@ public class WondexProtocolDecoder extends BaseProtocolDecoder {
int index = 1;
// Device identifier
- String id = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Time
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
diff --git a/src/org/traccar/protocol/Xexun2ProtocolDecoder.java b/src/org/traccar/protocol/Xexun2ProtocolDecoder.java
index d60e48750..bfd20c64b 100644
--- a/src/org/traccar/protocol/Xexun2ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Xexun2ProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class Xexun2ProtocolDecoder extends BaseProtocolDecoder {
- public Xexun2ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public Xexun2ProtocolDecoder(String protocol) {
+ super(protocol);
}
static private Pattern pattern = Pattern.compile(
@@ -94,7 +94,7 @@ public class Xexun2ProtocolDecoder extends BaseProtocolDecoder {
time.set(Calendar.MILLISECOND, Integer.valueOf(parser.group(index++)));
// Validity
- position.setValid(parser.group(index++).compareTo("A") == 0 ? true : false);
+ position.setValid(parser.group(index++).compareTo("A") == 0);
// Latitude
Double latitude = Double.valueOf(parser.group(index++));
@@ -132,13 +132,10 @@ public class Xexun2ProtocolDecoder extends BaseProtocolDecoder {
extendedInfo.set("alarm", parser.group(index++));
// Get device by IMEI
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Satellites
extendedInfo.set("satellites", parser.group(index++).replaceFirst ("^0*(?![\\.$])", ""));
diff --git a/src/org/traccar/protocol/XexunProtocolDecoder.java b/src/org/traccar/protocol/XexunProtocolDecoder.java
index dd9ed0528..bf119808d 100644
--- a/src/org/traccar/protocol/XexunProtocolDecoder.java
+++ b/src/org/traccar/protocol/XexunProtocolDecoder.java
@@ -33,8 +33,8 @@ import org.traccar.model.Position;
public class XexunProtocolDecoder extends BaseProtocolDecoder {
- public XexunProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public XexunProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -116,13 +116,10 @@ public class XexunProtocolDecoder extends BaseProtocolDecoder {
position.setTime(time.getTime());
// Get device by IMEI
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
position.setExtendedInfo(extendedInfo.toString());
return position;
diff --git a/src/org/traccar/protocol/XirgoProtocolDecoder.java b/src/org/traccar/protocol/XirgoProtocolDecoder.java
index e6a7bd10b..cec36c866 100644
--- a/src/org/traccar/protocol/XirgoProtocolDecoder.java
+++ b/src/org/traccar/protocol/XirgoProtocolDecoder.java
@@ -33,8 +33,8 @@ import org.traccar.model.Position;
public class XirgoProtocolDecoder extends BaseProtocolDecoder {
- public XirgoProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public XirgoProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -76,13 +76,10 @@ public class XirgoProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Get device by IMEI
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
extendedInfo.set("event", parser.group(index++));
diff --git a/src/org/traccar/protocol/Xt013ProtocolDecoder.java b/src/org/traccar/protocol/Xt013ProtocolDecoder.java
index 389ed3b59..e471ea349 100644
--- a/src/org/traccar/protocol/Xt013ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Xt013ProtocolDecoder.java
@@ -32,8 +32,8 @@ import java.util.regex.Pattern;
public class Xt013ProtocolDecoder extends BaseProtocolDecoder {
- public Xt013ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public Xt013ProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -78,13 +78,10 @@ public class Xt013ProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Identify device
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Time
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
diff --git a/src/org/traccar/protocol/Xt7ProtocolDecoder.java b/src/org/traccar/protocol/Xt7ProtocolDecoder.java
index bd46cee37..1e5396f22 100644
--- a/src/org/traccar/protocol/Xt7ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Xt7ProtocolDecoder.java
@@ -34,8 +34,8 @@ import org.traccar.model.Position;
public class Xt7ProtocolDecoder extends BaseProtocolDecoder {
- public Xt7ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public Xt7ProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -74,13 +74,11 @@ public class Xt7ProtocolDecoder extends BaseProtocolDecoder {
// Get device by id
String id = buf.readBytes(16).toString(Charset.defaultCharset()).trim();
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ if (!identify(id)) {
return null;
}
-
+ position.setDeviceId(getDeviceId());
+
buf.readUnsignedByte(); // command
int length = buf.readUnsignedByte();
diff --git a/src/org/traccar/protocol/YwtProtocolDecoder.java b/src/org/traccar/protocol/YwtProtocolDecoder.java
index 5392a4ccf..fa17d6f43 100644
--- a/src/org/traccar/protocol/YwtProtocolDecoder.java
+++ b/src/org/traccar/protocol/YwtProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class YwtProtocolDecoder extends BaseProtocolDecoder {
- public YwtProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public YwtProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -89,13 +89,10 @@ public class YwtProtocolDecoder extends BaseProtocolDecoder {
String type = parser.group(index++);
// Device
- String id = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Time
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));