diff options
177 files changed, 1081 insertions, 1428 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")); diff --git a/test/org/traccar/DetectorHandlerTest.java b/test/org/traccar/DetectorHandlerTest.java index f506856af..109747748 100644 --- a/test/org/traccar/DetectorHandlerTest.java +++ b/test/org/traccar/DetectorHandlerTest.java @@ -30,7 +30,7 @@ public class DetectorHandlerTest { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, "\r\n", "\n", ";")); pipeline.addLast("stringDecoder", new StringDecoder()); pipeline.addLast("stringEncoder", new StringEncoder()); - pipeline.addLast("objectDecoder", new Gps103ProtocolDecoder(new TestDataManager(), null, null)); + pipeline.addLast("objectDecoder", new Gps103ProtocolDecoder(null)); DetectorHandler.checkPipeline("gps103", pipeline, ChannelBuffers.copiedBuffer( "imei:869039001186913,tracker,1308282156,0,F,215630.000,A,5602.11015,N,9246.30767,E,1.4,,175.9,;", Charset.defaultCharset()));*/ diff --git a/test/org/traccar/helper/TestDataManager.java b/test/org/traccar/helper/TestDataManager.java index a54c1f7a3..a74669add 100644 --- a/test/org/traccar/helper/TestDataManager.java +++ b/test/org/traccar/helper/TestDataManager.java @@ -12,7 +12,7 @@ public class TestDataManager extends DataManager { } @Override - public Device getDeviceByImei(String imei) { + public Device getDeviceByUniqueId(String imei) { Device device = new Device(); device.setId(new Long(1)); device.setImei("123456789012345"); diff --git a/test/org/traccar/protocol/ApelProtocolDecoderTest.java b/test/org/traccar/protocol/ApelProtocolDecoderTest.java index 3d96563f6..f6899a6ad 100644 --- a/test/org/traccar/protocol/ApelProtocolDecoderTest.java +++ b/test/org/traccar/protocol/ApelProtocolDecoderTest.java @@ -7,12 +7,12 @@ import static org.traccar.helper.DecoderVerifier.verify; import static org.junit.Assert.assertNull; import org.junit.Test; -public class ApelProtocolDecoderTest { +public class ApelProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - ApelProtocolDecoder decoder = new ApelProtocolDecoder(new TestDataManager(), null, null); + ApelProtocolDecoder decoder = new ApelProtocolDecoder(null); /*byte[] buf1 = {0x40,0x4E,0x54,0x43,0x01,0x00,0x00,0x00,0x7B,0x00,0x00,0x00,0x13,0x00,0x44,0x34,0x2A,0x3E,0x53,0x3A,0x38,0x36,0x31,0x37,0x38,0x35,0x30,0x30,0x35,0x32,0x30,0x35,0x30,0x37,0x39}; assertNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, buf1)));*/ diff --git a/test/org/traccar/protocol/AplicomProtocolDecoderTest.java b/test/org/traccar/protocol/AplicomProtocolDecoderTest.java index cdbc4dab9..af41e8c03 100644 --- a/test/org/traccar/protocol/AplicomProtocolDecoderTest.java +++ b/test/org/traccar/protocol/AplicomProtocolDecoderTest.java @@ -6,12 +6,12 @@ import static org.traccar.helper.DecoderVerifier.verify; import org.junit.Test;
import org.traccar.helper.ChannelBufferTools;
-public class AplicomProtocolDecoderTest {
+public class AplicomProtocolDecoderTest extends ProtocolDecoderTest {
@Test
public void testDecode() throws Exception {
- AplicomProtocolDecoder decoder = new AplicomProtocolDecoder(new TestDataManager(), null, null);
+ AplicomProtocolDecoder decoder = new AplicomProtocolDecoder(null);
verify(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString(
"44C20143720729D6840043031fff7191C0450ef906450ef90603b20b8003b20b80066465b3870ce30f010ce30ce3003200001520000000030aa200003b13000000320300000bcb17acff0099000186a002"))));
diff --git a/test/org/traccar/protocol/Ardi01ProtocolDecoderTest.java b/test/org/traccar/protocol/Ardi01ProtocolDecoderTest.java index 7e4a2eb95..90993475e 100644 --- a/test/org/traccar/protocol/Ardi01ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Ardi01ProtocolDecoderTest.java @@ -6,12 +6,12 @@ import org.traccar.helper.TestDataManager; import static org.junit.Assert.assertNull; import static org.traccar.helper.DecoderVerifier.verify; -public class Ardi01ProtocolDecoderTest { +public class Ardi01ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Ardi01ProtocolDecoder decoder = new Ardi01ProtocolDecoder(new TestDataManager(), null, null); + Ardi01ProtocolDecoder decoder = new Ardi01ProtocolDecoder(null); verify(decoder.decode(null, null, "013227003054776,20141010052719,24.4736042,56.8445807,110,289,40,7,5,78,-1")); diff --git a/test/org/traccar/protocol/AtrackProtocolDecoderTest.java b/test/org/traccar/protocol/AtrackProtocolDecoderTest.java index 043c843c0..34f34c957 100644 --- a/test/org/traccar/protocol/AtrackProtocolDecoderTest.java +++ b/test/org/traccar/protocol/AtrackProtocolDecoderTest.java @@ -7,12 +7,12 @@ import static org.junit.Assert.assertNull; import org.junit.Test; import org.traccar.helper.ChannelBufferTools; -public class AtrackProtocolDecoderTest { +public class AtrackProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - AtrackProtocolDecoder decoder = new AtrackProtocolDecoder(new TestDataManager(), null, null); + AtrackProtocolDecoder decoder = new AtrackProtocolDecoder(null); assertNull(decoder.decode(null, null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString( "fe0200014104d8f196820001")))); diff --git a/test/org/traccar/protocol/AutoFon45ProtocolDecoderTest.java b/test/org/traccar/protocol/AutoFon45ProtocolDecoderTest.java index 2665c7cab..26c25833b 100644 --- a/test/org/traccar/protocol/AutoFon45ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/AutoFon45ProtocolDecoderTest.java @@ -8,10 +8,10 @@ import org.traccar.helper.TestDataManager; import static org.junit.Assert.assertNull; import static org.traccar.helper.DecoderVerifier.verify; -public class AutoFon45ProtocolDecoderTest { +public class AutoFon45ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - AutoFon45ProtocolDecoder decoder = new AutoFon45ProtocolDecoder(new TestDataManager(), null, null); + AutoFon45ProtocolDecoder decoder = new AutoFon45ProtocolDecoder(null); assertNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString( "41032125656985547543619173484002123481")))); diff --git a/test/org/traccar/protocol/AutoFonProtocolDecoderTest.java b/test/org/traccar/protocol/AutoFonProtocolDecoderTest.java index 7e0e13541..ded0aca6f 100644 --- a/test/org/traccar/protocol/AutoFonProtocolDecoderTest.java +++ b/test/org/traccar/protocol/AutoFonProtocolDecoderTest.java @@ -8,12 +8,12 @@ import org.traccar.helper.TestDataManager; import static org.junit.Assert.assertNull;
import static org.traccar.helper.DecoderVerifier.verify;
-public class AutoFonProtocolDecoderTest {
+public class AutoFonProtocolDecoderTest extends ProtocolDecoderTest {
@Test
public void testDecode() throws Exception {
- AutoFonProtocolDecoder decoder = new AutoFonProtocolDecoder(new TestDataManager(), null, null);
+ AutoFonProtocolDecoder decoder = new AutoFonProtocolDecoder(null);
assertNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString(
"10556103592310314825728F"))));
diff --git a/test/org/traccar/protocol/BceProtocolDecoderTest.java b/test/org/traccar/protocol/BceProtocolDecoderTest.java index ded4ec291..356a6fba1 100644 --- a/test/org/traccar/protocol/BceProtocolDecoderTest.java +++ b/test/org/traccar/protocol/BceProtocolDecoderTest.java @@ -9,12 +9,12 @@ import org.traccar.helper.ChannelBufferTools; import static org.traccar.helper.DecoderVerifier.verify; import org.traccar.helper.TestDataManager; -public class BceProtocolDecoderTest { +public class BceProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - BceProtocolDecoder decoder = new BceProtocolDecoder(new TestDataManager(), null, null); + BceProtocolDecoder decoder = new BceProtocolDecoder(null); verify(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, ChannelBufferTools.convertHexString( "be76619c834601004200a0003fd769c568ffc3db0079161d420683a9414918b1150000000000d102660167040000000000009f06357f0000a401042ea415e10232000000000000000000000051")))); diff --git a/test/org/traccar/protocol/BoxProtocolDecoderTest.java b/test/org/traccar/protocol/BoxProtocolDecoderTest.java index 94404d4bc..a864d62dd 100644 --- a/test/org/traccar/protocol/BoxProtocolDecoderTest.java +++ b/test/org/traccar/protocol/BoxProtocolDecoderTest.java @@ -5,12 +5,12 @@ import org.traccar.helper.TestDataManager; import static org.traccar.helper.DecoderVerifier.verify; import org.junit.Test; -public class BoxProtocolDecoderTest { +public class BoxProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - BoxProtocolDecoder decoder = new BoxProtocolDecoder(new TestDataManager(), null, null); + BoxProtocolDecoder decoder = new BoxProtocolDecoder(null); assertNull(decoder.decode(null, null, "H,BT,358281002435893,081028142432,F5813D19,6D6E6DC2")); diff --git a/test/org/traccar/protocol/CalAmpProtocolDecoderTest.java b/test/org/traccar/protocol/CalAmpProtocolDecoderTest.java index 5e72fdf26..5f2e5bfce 100644 --- a/test/org/traccar/protocol/CalAmpProtocolDecoderTest.java +++ b/test/org/traccar/protocol/CalAmpProtocolDecoderTest.java @@ -8,12 +8,12 @@ import org.traccar.helper.TestDataManager; import static org.junit.Assert.assertNull; import static org.traccar.helper.DecoderVerifier.verify; -public class CalAmpProtocolDecoderTest { +public class CalAmpProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - CalAmpProtocolDecoder decoder = new CalAmpProtocolDecoder(new TestDataManager(), null, null); + CalAmpProtocolDecoder decoder = new CalAmpProtocolDecoder(null); assertNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString( "830545321041830101010300010000333862000023c301000000004532104183ffffff353816051610691f420040163953294fffffffffffffffff8996604211639032949f4f54413a317c303b302c317c343b302c34004f5441535441543a302c302c302c302c302c222200564255533a342c322e302e302c343533323130343138332c5630312e30332e30312e34302c5630312e30332e30312e33312c2c0056494e2d494e464f3a56494e3d31464d5a5537324539355a4137303032362c4445562d5245474e3d55532c535256522d5245474e3d555300")), null)); diff --git a/test/org/traccar/protocol/CarTrackProtocolDecoderTest.java b/test/org/traccar/protocol/CarTrackProtocolDecoderTest.java index fa19f485f..05e2402a6 100644 --- a/test/org/traccar/protocol/CarTrackProtocolDecoderTest.java +++ b/test/org/traccar/protocol/CarTrackProtocolDecoderTest.java @@ -4,12 +4,12 @@ import org.traccar.helper.TestDataManager; import static org.traccar.helper.DecoderVerifier.verify; import org.junit.Test; -public class CarTrackProtocolDecoderTest { +public class CarTrackProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - CarTrackProtocolDecoder decoder = new CarTrackProtocolDecoder(new TestDataManager(), null, null); + CarTrackProtocolDecoder decoder = new CarTrackProtocolDecoder(null); verify(decoder.decode(null, null, "$$2222234???????&A9955&B102904.000,A,2233.0655,N,11404.9440,E,0.00,,030109,,*17|6.3|&C0100000100&D000024?>&E10000000&Y00100020")); diff --git a/test/org/traccar/protocol/CarscopProtocolDecoderTest.java b/test/org/traccar/protocol/CarscopProtocolDecoderTest.java index 8c75c2437..04217dcd6 100644 --- a/test/org/traccar/protocol/CarscopProtocolDecoderTest.java +++ b/test/org/traccar/protocol/CarscopProtocolDecoderTest.java @@ -5,12 +5,12 @@ import static org.traccar.helper.DecoderVerifier.verify; import static org.junit.Assert.assertNull; import org.junit.Test; -public class CarscopProtocolDecoderTest { +public class CarscopProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - CarscopProtocolDecoder decoder = new CarscopProtocolDecoder(new TestDataManager(), null, null); + CarscopProtocolDecoder decoder = new CarscopProtocolDecoder(null); verify(decoder.decode(null, null, "*040331141830UB05123456789012345061825A2934.0133N10627.2544E000.0040331309.6200000000L000000")); diff --git a/test/org/traccar/protocol/CellocatorProtocolDecoderTest.java b/test/org/traccar/protocol/CellocatorProtocolDecoderTest.java index 3825430e3..74b7e305e 100644 --- a/test/org/traccar/protocol/CellocatorProtocolDecoderTest.java +++ b/test/org/traccar/protocol/CellocatorProtocolDecoderTest.java @@ -7,12 +7,12 @@ import static org.traccar.helper.DecoderVerifier.verify; import org.junit.Test; import org.traccar.helper.ChannelBufferTools; -public class CellocatorProtocolDecoderTest { +public class CellocatorProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - CellocatorProtocolDecoder decoder = new CellocatorProtocolDecoder(new TestDataManager(), null, null); + CellocatorProtocolDecoder decoder = new CellocatorProtocolDecoder(null); verify(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, ChannelBufferTools.convertHexString( "4D4347500006000000081A02021204000000210062300000006B00E100000000000000000000E5A100040206614EA303181A57034E1200000000000000001525071403D60749")))); diff --git a/test/org/traccar/protocol/EasyTrackProtocolDecoderTest.java b/test/org/traccar/protocol/EasyTrackProtocolDecoderTest.java index 8a62e0f14..de746751a 100644 --- a/test/org/traccar/protocol/EasyTrackProtocolDecoderTest.java +++ b/test/org/traccar/protocol/EasyTrackProtocolDecoderTest.java @@ -5,12 +5,12 @@ import static org.traccar.helper.DecoderVerifier.verify; import static org.junit.Assert.assertNull; import org.junit.Test; -public class EasyTrackProtocolDecoderTest { +public class EasyTrackProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - EasyTrackProtocolDecoder decoder = new EasyTrackProtocolDecoder(new TestDataManager(), null, null); + EasyTrackProtocolDecoder decoder = new EasyTrackProtocolDecoder(null); assertNull(decoder.decode(null, null, "*ET,135790246811221,GZ,0001,0005")); diff --git a/test/org/traccar/protocol/EelinkProtocolDecoderTest.java b/test/org/traccar/protocol/EelinkProtocolDecoderTest.java index 58f8d71ad..6bf7d7143 100644 --- a/test/org/traccar/protocol/EelinkProtocolDecoderTest.java +++ b/test/org/traccar/protocol/EelinkProtocolDecoderTest.java @@ -7,12 +7,12 @@ import static org.junit.Assert.assertNull; import org.junit.Test; import org.traccar.helper.ChannelBufferTools; -public class EelinkProtocolDecoderTest { +public class EelinkProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - EelinkProtocolDecoder decoder = new EelinkProtocolDecoder(new TestDataManager(), null, null); + EelinkProtocolDecoder decoder = new EelinkProtocolDecoder(null); assertNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString( "676701000b001b035418804661834901")))); diff --git a/test/org/traccar/protocol/EnforaProtocolDecoderTest.java b/test/org/traccar/protocol/EnforaProtocolDecoderTest.java index 5c1a015be..7e67a300f 100644 --- a/test/org/traccar/protocol/EnforaProtocolDecoderTest.java +++ b/test/org/traccar/protocol/EnforaProtocolDecoderTest.java @@ -9,12 +9,12 @@ import org.junit.Test; import org.traccar.helper.ChannelBufferTools; import static org.traccar.helper.DecoderVerifier.verify; -public class EnforaProtocolDecoderTest { +public class EnforaProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - EnforaProtocolDecoder decoder = new EnforaProtocolDecoder(new TestDataManager(), null, null); + EnforaProtocolDecoder decoder = new EnforaProtocolDecoder(null); assertNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString( "000A08002020202020303131303730303030353730323637")))); diff --git a/test/org/traccar/protocol/Ev603ProtocolDecoderTest.java b/test/org/traccar/protocol/Ev603ProtocolDecoderTest.java index 0fd062e97..b56a92c16 100644 --- a/test/org/traccar/protocol/Ev603ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Ev603ProtocolDecoderTest.java @@ -5,12 +5,12 @@ import static org.traccar.helper.DecoderVerifier.verify; import static org.junit.Assert.assertNull; import org.junit.Test; -public class Ev603ProtocolDecoderTest { +public class Ev603ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Ev603ProtocolDecoder decoder = new Ev603ProtocolDecoder(new TestDataManager(), null, null); + Ev603ProtocolDecoder decoder = new Ev603ProtocolDecoder(null); assertNull(decoder.decode(null, null, "!1,123456789012345")); diff --git a/test/org/traccar/protocol/FreedomProtocolDecoderTest.java b/test/org/traccar/protocol/FreedomProtocolDecoderTest.java index e58de3bb1..b39b7a0cd 100644 --- a/test/org/traccar/protocol/FreedomProtocolDecoderTest.java +++ b/test/org/traccar/protocol/FreedomProtocolDecoderTest.java @@ -5,12 +5,12 @@ import static org.traccar.helper.DecoderVerifier.verify; import static org.junit.Assert.assertNull; import org.junit.Test; -public class FreedomProtocolDecoderTest { +public class FreedomProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - FreedomProtocolDecoder decoder = new FreedomProtocolDecoder(new TestDataManager(), null, null); + FreedomProtocolDecoder decoder = new FreedomProtocolDecoder(null); verify(decoder.decode(null, null, "IMEI,353358011714362,2014/05/22, 20:49:32, N, Lat:4725.9624, E, Lon:01912.5483, Spd:5.05")); diff --git a/test/org/traccar/protocol/GalileoProtocolDecoderTest.java b/test/org/traccar/protocol/GalileoProtocolDecoderTest.java index abe41b839..b79de9fbf 100644 --- a/test/org/traccar/protocol/GalileoProtocolDecoderTest.java +++ b/test/org/traccar/protocol/GalileoProtocolDecoderTest.java @@ -8,12 +8,12 @@ import org.junit.Test; import org.traccar.helper.ChannelBufferTools; import static org.traccar.helper.DecoderVerifier.verify; -public class GalileoProtocolDecoderTest { +public class GalileoProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - GalileoProtocolDecoder decoder = new GalileoProtocolDecoder(new TestDataManager(), null, null); + GalileoProtocolDecoder decoder = new GalileoProtocolDecoder(null); assertNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, ChannelBufferTools.convertHexString( "011380033836383230343030313534393038370432008590")))); diff --git a/test/org/traccar/protocol/GatorProtocolDecoderTest.java b/test/org/traccar/protocol/GatorProtocolDecoderTest.java index 24cf1ed1f..6bcd829e3 100644 --- a/test/org/traccar/protocol/GatorProtocolDecoderTest.java +++ b/test/org/traccar/protocol/GatorProtocolDecoderTest.java @@ -6,12 +6,12 @@ import static org.traccar.helper.DecoderVerifier.verify; import org.junit.Test; import org.traccar.helper.ChannelBufferTools; -public class GatorProtocolDecoderTest { +public class GatorProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - GatorProtocolDecoder decoder = new GatorProtocolDecoder(new TestDataManager(), null, null); + GatorProtocolDecoder decoder = new GatorProtocolDecoder(null); verify(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString( "24248000260009632d141121072702059226180104367500000000c04700079c0c34000ad80b00ff000a0d")))); diff --git a/test/org/traccar/protocol/Gl100ProtocolDecoderTest.java b/test/org/traccar/protocol/Gl100ProtocolDecoderTest.java index 0d5a5bc24..08003e155 100644 --- a/test/org/traccar/protocol/Gl100ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Gl100ProtocolDecoderTest.java @@ -5,12 +5,12 @@ import org.traccar.helper.TestDataManager; import static org.traccar.helper.DecoderVerifier.verify; import org.junit.Test; -public class Gl100ProtocolDecoderTest { +public class Gl100ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Gl100ProtocolDecoder decoder = new Gl100ProtocolDecoder(new TestDataManager(), null, null); + Gl100ProtocolDecoder decoder = new Gl100ProtocolDecoder(null); assertNull(decoder.decode(null, null, "AT+GTHBD=HeartBeat,359231030000010,20090101000000,11F0,0102120204")); diff --git a/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java b/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java index f30f08a63..10f3100f5 100644 --- a/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java @@ -5,12 +5,12 @@ import static org.traccar.helper.DecoderVerifier.verify; import static org.junit.Assert.assertNull; import org.junit.Test; -public class Gl200ProtocolDecoderTest { +public class Gl200ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Gl200ProtocolDecoder decoder = new Gl200ProtocolDecoder(new TestDataManager(), null, null); + Gl200ProtocolDecoder decoder = new Gl200ProtocolDecoder(null); verify(decoder.decode(null, null, "+RESP:GTFRI,1A0200,860599000165464,CRI001,0,0,1,2,,41,,-71.153137,42.301634,20150328020301,,,,,280.3,55,20150327220351,320C")); diff --git a/test/org/traccar/protocol/GlobalSatProtocolDecoderTest.java b/test/org/traccar/protocol/GlobalSatProtocolDecoderTest.java index 9f9173c28..67e0f965f 100644 --- a/test/org/traccar/protocol/GlobalSatProtocolDecoderTest.java +++ b/test/org/traccar/protocol/GlobalSatProtocolDecoderTest.java @@ -5,12 +5,12 @@ import static org.traccar.helper.DecoderVerifier.verify; import static org.junit.Assert.assertNull; import org.junit.Test; -public class GlobalSatProtocolDecoderTest { +public class GlobalSatProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - GlobalSatProtocolDecoder decoder = new GlobalSatProtocolDecoder(new TestDataManager(), null, null); + GlobalSatProtocolDecoder decoder = new GlobalSatProtocolDecoder(null); assertNull(decoder.decode(null, null, "GSh,131826789036289,3,M,ea04*3d")); diff --git a/test/org/traccar/protocol/GoSafeProtocolDecoderTest.java b/test/org/traccar/protocol/GoSafeProtocolDecoderTest.java index 08f4a4fb6..75d5b0121 100644 --- a/test/org/traccar/protocol/GoSafeProtocolDecoderTest.java +++ b/test/org/traccar/protocol/GoSafeProtocolDecoderTest.java @@ -5,12 +5,12 @@ import static org.traccar.helper.DecoderVerifier.verify; import static org.junit.Assert.assertNull; import org.junit.Test; -public class GoSafeProtocolDecoderTest { +public class GoSafeProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - GoSafeProtocolDecoder decoder = new GoSafeProtocolDecoder(new TestDataManager(), null, null); + GoSafeProtocolDecoder decoder = new GoSafeProtocolDecoder(null); assertNull(decoder.decode(null, null, null, "*GS16,351535058709775")); diff --git a/test/org/traccar/protocol/GotopProtocolDecoderTest.java b/test/org/traccar/protocol/GotopProtocolDecoderTest.java index b30ac5534..bfeaf9e2e 100644 --- a/test/org/traccar/protocol/GotopProtocolDecoderTest.java +++ b/test/org/traccar/protocol/GotopProtocolDecoderTest.java @@ -5,12 +5,12 @@ import static org.traccar.helper.DecoderVerifier.verify; import static org.junit.Assert.assertNull; import org.junit.Test; -public class GotopProtocolDecoderTest { +public class GotopProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - GotopProtocolDecoder decoder = new GotopProtocolDecoder(new TestDataManager(), null, null); + GotopProtocolDecoder decoder = new GotopProtocolDecoder(null); assertNull(decoder.decode(null, null, "")); diff --git a/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java b/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java index 53a092598..71e2194bd 100644 --- a/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java @@ -5,12 +5,12 @@ import static org.traccar.helper.DecoderVerifier.verify; import static org.junit.Assert.assertNull; import org.junit.Test; -public class Gps103ProtocolDecoderTest { +public class Gps103ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Gps103ProtocolDecoder decoder = new Gps103ProtocolDecoder(new TestDataManager(), null, null); + Gps103ProtocolDecoder decoder = new Gps103ProtocolDecoder(null); // Log on request assertNull(decoder.decode(null, null, null, "##,imei:359586015829802,A")); diff --git a/test/org/traccar/protocol/GpsGateProtocolDecoderTest.java b/test/org/traccar/protocol/GpsGateProtocolDecoderTest.java index 812f63873..d50f03d39 100644 --- a/test/org/traccar/protocol/GpsGateProtocolDecoderTest.java +++ b/test/org/traccar/protocol/GpsGateProtocolDecoderTest.java @@ -5,12 +5,12 @@ import static org.traccar.helper.DecoderVerifier.verify; import static org.junit.Assert.assertNull; import org.junit.Test; -public class GpsGateProtocolDecoderTest { +public class GpsGateProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - GpsGateProtocolDecoder decoder = new GpsGateProtocolDecoder(new TestDataManager(), null, null); + GpsGateProtocolDecoder decoder = new GpsGateProtocolDecoder(null); assertNull(decoder.decode(null, null, "$FRLIN,,user1,8IVHF*7A")); diff --git a/test/org/traccar/protocol/Gt02ProtocolDecoderTest.java b/test/org/traccar/protocol/Gt02ProtocolDecoderTest.java index 11fc4ff97..539fe2612 100644 --- a/test/org/traccar/protocol/Gt02ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Gt02ProtocolDecoderTest.java @@ -7,12 +7,12 @@ import org.traccar.helper.ChannelBufferTools; import static org.traccar.helper.DecoderVerifier.verify; import org.traccar.helper.TestDataManager; -public class Gt02ProtocolDecoderTest { +public class Gt02ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Gt02ProtocolDecoder decoder = new Gt02ProtocolDecoder(new TestDataManager(), null, null); + Gt02ProtocolDecoder decoder = new Gt02ProtocolDecoder(null); verify(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString( "68682500000123456789012345000110010101010101026B3F3E026B3F3E000000000000000000010D0A")))); diff --git a/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java b/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java index c0af74538..aee675b2e 100644 --- a/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java @@ -7,12 +7,12 @@ import org.junit.Test; import org.traccar.helper.ChannelBufferTools; import static org.traccar.helper.DecoderVerifier.verify; -public class Gt06ProtocolDecoderTest { +public class Gt06ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Gt06ProtocolDecoder decoder = new Gt06ProtocolDecoder(new TestDataManager(), null, null); + Gt06ProtocolDecoder decoder = new Gt06ProtocolDecoder(null); assertNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString( "787811010123456789012345100B3201000171930D0A")))); diff --git a/test/org/traccar/protocol/H02ProtocolDecoderTest.java b/test/org/traccar/protocol/H02ProtocolDecoderTest.java index cb8e55517..443462a57 100644 --- a/test/org/traccar/protocol/H02ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/H02ProtocolDecoderTest.java @@ -8,12 +8,12 @@ import static org.junit.Assert.assertNull; import org.junit.Test; import org.traccar.helper.ChannelBufferTools; -public class H02ProtocolDecoderTest { +public class H02ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - H02ProtocolDecoder decoder = new H02ProtocolDecoder(new TestDataManager(), null, null); + H02ProtocolDecoder decoder = new H02ProtocolDecoder(null); verify(decoder.decode(null, null, ChannelBuffers.copiedBuffer( "*HQ,1451316409,V1,030149,A,-23-29.0095,S,-46-51.5852,W,2.4,065,070315,FFFFFFFF#", Charset.defaultCharset()))); diff --git a/test/org/traccar/protocol/HaicomProtocolDecoderTest.java b/test/org/traccar/protocol/HaicomProtocolDecoderTest.java index f35bf78e3..13659d040 100644 --- a/test/org/traccar/protocol/HaicomProtocolDecoderTest.java +++ b/test/org/traccar/protocol/HaicomProtocolDecoderTest.java @@ -4,12 +4,12 @@ import org.traccar.helper.TestDataManager; import static org.traccar.helper.DecoderVerifier.verify; import org.junit.Test; -public class HaicomProtocolDecoderTest { +public class HaicomProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - HaicomProtocolDecoder decoder = new HaicomProtocolDecoder(new TestDataManager(), null, null); + HaicomProtocolDecoder decoder = new HaicomProtocolDecoder(null); verify(decoder.decode(null, null, "$GPRS123456789012345,602S19A,100915,063515,7240649312041079,0019,3156,111000,10004,0000,11111,00LH#V037")); diff --git a/test/org/traccar/protocol/IntellitracProtocolDecoderTest.java b/test/org/traccar/protocol/IntellitracProtocolDecoderTest.java index 33c3fd3cd..28e5a3ae7 100644 --- a/test/org/traccar/protocol/IntellitracProtocolDecoderTest.java +++ b/test/org/traccar/protocol/IntellitracProtocolDecoderTest.java @@ -5,12 +5,12 @@ import static org.traccar.helper.DecoderVerifier.verify; import static org.junit.Assert.assertNull; import org.junit.Test; -public class IntellitracProtocolDecoderTest { +public class IntellitracProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - IntellitracProtocolDecoder decoder = new IntellitracProtocolDecoder(new TestDataManager(), null, null); + IntellitracProtocolDecoder decoder = new IntellitracProtocolDecoder(null); assertNull(decoder.decode(null, null, "$OK:TRACKING")); diff --git a/test/org/traccar/protocol/Jt600ProtocolDecoderTest.java b/test/org/traccar/protocol/Jt600ProtocolDecoderTest.java index 7cbab2836..8f5f4db55 100644 --- a/test/org/traccar/protocol/Jt600ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Jt600ProtocolDecoderTest.java @@ -7,12 +7,12 @@ import org.jboss.netty.buffer.ChannelBuffers; import static org.traccar.helper.DecoderVerifier.verify; import org.junit.Test; -public class Jt600ProtocolDecoderTest { +public class Jt600ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Jt600ProtocolDecoder decoder = new Jt600ProtocolDecoder(new TestDataManager(), null, null); + Jt600ProtocolDecoder decoder = new Jt600ProtocolDecoder(null); verify(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString( "24311021600111001B16021105591022329862114046227B0598095080012327951435161F")))); diff --git a/test/org/traccar/protocol/KhdProtocolDecoderTest.java b/test/org/traccar/protocol/KhdProtocolDecoderTest.java index 9593bf6d1..5d9e4ef2c 100644 --- a/test/org/traccar/protocol/KhdProtocolDecoderTest.java +++ b/test/org/traccar/protocol/KhdProtocolDecoderTest.java @@ -7,12 +7,12 @@ import static org.junit.Assert.assertNull; import org.junit.Test; import org.traccar.helper.ChannelBufferTools; -public class KhdProtocolDecoderTest { +public class KhdProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - KhdProtocolDecoder decoder = new KhdProtocolDecoder(new TestDataManager(), null, null); + KhdProtocolDecoder decoder = new KhdProtocolDecoder(null); assertNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString( "2929b1000605162935b80d")))); diff --git a/test/org/traccar/protocol/LaipacProtocolDecoderTest.java b/test/org/traccar/protocol/LaipacProtocolDecoderTest.java index fcfa4e98e..e74c2d411 100644 --- a/test/org/traccar/protocol/LaipacProtocolDecoderTest.java +++ b/test/org/traccar/protocol/LaipacProtocolDecoderTest.java @@ -5,12 +5,12 @@ import static org.traccar.helper.DecoderVerifier.verify; import static org.junit.Assert.assertNull; import org.junit.Test; -public class LaipacProtocolDecoderTest { +public class LaipacProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - LaipacProtocolDecoder decoder = new LaipacProtocolDecoder(new TestDataManager(), null, null); + LaipacProtocolDecoder decoder = new LaipacProtocolDecoder(null); assertNull(decoder.decode(null, null, "$AVSYS,99999999,V1.50,SN0000103,32768*15")); diff --git a/test/org/traccar/protocol/M2mProtocolDecoderTest.java b/test/org/traccar/protocol/M2mProtocolDecoderTest.java index 346cdbedb..ceb248fb5 100644 --- a/test/org/traccar/protocol/M2mProtocolDecoderTest.java +++ b/test/org/traccar/protocol/M2mProtocolDecoderTest.java @@ -7,12 +7,12 @@ import static org.junit.Assert.assertNull; import org.junit.Test; import org.traccar.helper.ChannelBufferTools; -public class M2mProtocolDecoderTest { +public class M2mProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - M2mProtocolDecoder decoder = new M2mProtocolDecoder(new TestDataManager(), null, null); + M2mProtocolDecoder decoder = new M2mProtocolDecoder(null); assertNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString( "235A3C2A2624215C287D70212A21254C7C6421220B0B0B")))); diff --git a/test/org/traccar/protocol/ManPowerProtocolDecoderTest.java b/test/org/traccar/protocol/ManPowerProtocolDecoderTest.java index 235778dd2..d5a722019 100644 --- a/test/org/traccar/protocol/ManPowerProtocolDecoderTest.java +++ b/test/org/traccar/protocol/ManPowerProtocolDecoderTest.java @@ -4,12 +4,12 @@ import org.traccar.helper.TestDataManager; import static org.traccar.helper.DecoderVerifier.verify; import org.junit.Test; -public class ManPowerProtocolDecoderTest { +public class ManPowerProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - ManPowerProtocolDecoder decoder = new ManPowerProtocolDecoder(new TestDataManager(), null, null); + ManPowerProtocolDecoder decoder = new ManPowerProtocolDecoder(null); verify(decoder.decode(null, null, "simei:352581250259539,,,tracker,51,24,1.73,130426023608,A,3201.5462,N,03452.2975,E,0.01,28B9,1DED,425,01,1x0x0*0x1*60x+2,en-us,")); diff --git a/test/org/traccar/protocol/MegastekProtocolDecoderTest.java b/test/org/traccar/protocol/MegastekProtocolDecoderTest.java index 7a25ff340..dd044990f 100644 --- a/test/org/traccar/protocol/MegastekProtocolDecoderTest.java +++ b/test/org/traccar/protocol/MegastekProtocolDecoderTest.java @@ -4,12 +4,12 @@ import org.traccar.helper.TestDataManager; import static org.traccar.helper.DecoderVerifier.verify; import org.junit.Test; -public class MegastekProtocolDecoderTest { +public class MegastekProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - MegastekProtocolDecoder decoder = new MegastekProtocolDecoder(new TestDataManager(), null, null); + MegastekProtocolDecoder decoder = new MegastekProtocolDecoder(null); verify(decoder.decode(null, null, "STX,GerAL22,$GPRMC,174752.000,A,3637.060059,S,6416.2354,W,0.00,0.00,030812,,,A*55,F,,imei:861785000249353,05,180.6,Battery=100%,,1,722,310,0FA6,39D0;8F")); diff --git a/test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java b/test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java index 212e2301a..7d3353016 100644 --- a/test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java +++ b/test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java @@ -7,12 +7,12 @@ import static org.junit.Assert.assertNull; import org.junit.Test; import org.traccar.helper.ChannelBufferTools; -public class MeiligaoProtocolDecoderTest { +public class MeiligaoProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - MeiligaoProtocolDecoder decoder = new MeiligaoProtocolDecoder(new TestDataManager(), null, null); + MeiligaoProtocolDecoder decoder = new MeiligaoProtocolDecoder(null); assertNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString( "24240000123456FFFFFFFF50008B9B0D0A")))); diff --git a/test/org/traccar/protocol/MeitrackProtocolDecoderTest.java b/test/org/traccar/protocol/MeitrackProtocolDecoderTest.java index f031a5f15..339cddde5 100644 --- a/test/org/traccar/protocol/MeitrackProtocolDecoderTest.java +++ b/test/org/traccar/protocol/MeitrackProtocolDecoderTest.java @@ -8,12 +8,12 @@ import org.junit.Test; import org.traccar.helper.ChannelBufferTools; import static org.traccar.helper.DecoderVerifier.verify; -public class MeitrackProtocolDecoderTest { +public class MeitrackProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - MeitrackProtocolDecoder decoder = new MeitrackProtocolDecoder(new TestDataManager(), null, null); + MeitrackProtocolDecoder decoder = new MeitrackProtocolDecoder(null); verify(decoder.decode(null, null, ChannelBuffers.copiedBuffer( "$$I152,013949004569813,AAA,37,54.739468,25.273648,150208173414,A,5,24,0,73,1.5,165,74,3381,246|1|0065|118A,0000,0003|0003|0000|08D4|0002,006380DF,,1,0008*7C", Charset.defaultCharset()))); diff --git a/test/org/traccar/protocol/MiniFinderProtocolDecoderTest.java b/test/org/traccar/protocol/MiniFinderProtocolDecoderTest.java index c377a11c8..27c88216f 100644 --- a/test/org/traccar/protocol/MiniFinderProtocolDecoderTest.java +++ b/test/org/traccar/protocol/MiniFinderProtocolDecoderTest.java @@ -5,12 +5,12 @@ import static org.traccar.helper.DecoderVerifier.verify; import static org.junit.Assert.assertNull; import org.junit.Test; -public class MiniFinderProtocolDecoderTest { +public class MiniFinderProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - MiniFinderProtocolDecoder decoder = new MiniFinderProtocolDecoder(new TestDataManager(), null, null); + MiniFinderProtocolDecoder decoder = new MiniFinderProtocolDecoder(null); assertNull(decoder.decode(null, null, "!1,860719020212696")); diff --git a/test/org/traccar/protocol/MtxProtocolDecoderTest.java b/test/org/traccar/protocol/MtxProtocolDecoderTest.java index f003780cd..2d027cbf8 100644 --- a/test/org/traccar/protocol/MtxProtocolDecoderTest.java +++ b/test/org/traccar/protocol/MtxProtocolDecoderTest.java @@ -5,12 +5,12 @@ import static org.traccar.helper.DecoderVerifier.verify; import static org.junit.Assert.assertNull; import org.junit.Test; -public class MtxProtocolDecoderTest { +public class MtxProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - MtxProtocolDecoder decoder = new MtxProtocolDecoder(new TestDataManager(), null, null); + MtxProtocolDecoder decoder = new MtxProtocolDecoder(null); verify(decoder.decode(null, null, "#MTX,353815011138124,20101226,195550,41.6296399,002.3611174,000,035,000000.00,X,X,1111,000,0,0")); diff --git a/test/org/traccar/protocol/NavigilProtocolDecoderTest.java b/test/org/traccar/protocol/NavigilProtocolDecoderTest.java index 6f58f83d1..ab72d887f 100644 --- a/test/org/traccar/protocol/NavigilProtocolDecoderTest.java +++ b/test/org/traccar/protocol/NavigilProtocolDecoderTest.java @@ -8,12 +8,12 @@ import org.junit.Test; import org.traccar.helper.ChannelBufferTools; import static org.traccar.helper.DecoderVerifier.verify; -public class NavigilProtocolDecoderTest { +public class NavigilProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - NavigilProtocolDecoder decoder = new NavigilProtocolDecoder(new TestDataManager(), null, null); + NavigilProtocolDecoder decoder = new NavigilProtocolDecoder(null); assertNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, ChannelBufferTools.convertHexString( "01004300040020000000f60203080200e7cd0f510c0000003b00000000000000")))); diff --git a/test/org/traccar/protocol/NavisProtocolDecoderTest.java b/test/org/traccar/protocol/NavisProtocolDecoderTest.java index 82dcc0ba1..bdc656b10 100644 --- a/test/org/traccar/protocol/NavisProtocolDecoderTest.java +++ b/test/org/traccar/protocol/NavisProtocolDecoderTest.java @@ -8,12 +8,12 @@ import static org.traccar.helper.DecoderVerifier.verify; import static org.junit.Assert.assertNull; import org.junit.Test; -public class NavisProtocolDecoderTest { +public class NavisProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - NavisProtocolDecoder decoder = new NavisProtocolDecoder(new TestDataManager(), null, null); + NavisProtocolDecoder decoder = new NavisProtocolDecoder(null); assertNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, ChannelBufferTools.convertHexString( "404E5443010000007B000000130044342A3E533A383631373835303035323035303739")))); diff --git a/test/org/traccar/protocol/NoranProtocolDecoderTest.java b/test/org/traccar/protocol/NoranProtocolDecoderTest.java index 1c80bb399..b7c05a62e 100644 --- a/test/org/traccar/protocol/NoranProtocolDecoderTest.java +++ b/test/org/traccar/protocol/NoranProtocolDecoderTest.java @@ -8,12 +8,12 @@ import static org.traccar.helper.DecoderVerifier.verify; import org.junit.Test; import org.traccar.helper.ChannelBufferTools; -public class NoranProtocolDecoderTest { +public class NoranProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - NoranProtocolDecoder decoder = new NoranProtocolDecoder(new TestDataManager(), null, null); + NoranProtocolDecoder decoder = new NoranProtocolDecoder(null); assertNull(decoder.decode(null, null, null, ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, ChannelBufferTools.convertHexString( "0f0000004e52303946303431353500")))); diff --git a/test/org/traccar/protocol/OrionProtocolDecoderTest.java b/test/org/traccar/protocol/OrionProtocolDecoderTest.java index d41ea5b91..66243ecf3 100644 --- a/test/org/traccar/protocol/OrionProtocolDecoderTest.java +++ b/test/org/traccar/protocol/OrionProtocolDecoderTest.java @@ -8,12 +8,12 @@ import org.junit.Test; import org.traccar.helper.ChannelBufferTools; import static org.traccar.helper.DecoderVerifier.verify; -public class OrionProtocolDecoderTest { +public class OrionProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - OrionProtocolDecoder decoder = new OrionProtocolDecoder(new TestDataManager(), null, null); + OrionProtocolDecoder decoder = new OrionProtocolDecoder(null); verify(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, ChannelBufferTools.convertHexString( "5057000137bf6236235a0331b5c6e402a3b5ecff5102980003000e0c1d172936080e0c1d172936b03b01000882050000008e080000000000008c0300940500000084030085030003067600900113150000000000000000000000000000000000000004a4c8")))); diff --git a/test/org/traccar/protocol/OsmAndProtocolDecoderTest.java b/test/org/traccar/protocol/OsmAndProtocolDecoderTest.java index 94b0eb91b..0d20dc959 100644 --- a/test/org/traccar/protocol/OsmAndProtocolDecoderTest.java +++ b/test/org/traccar/protocol/OsmAndProtocolDecoderTest.java @@ -7,12 +7,12 @@ import org.jboss.netty.handler.codec.http.HttpVersion; import static org.traccar.helper.DecoderVerifier.verify; import org.junit.Test; -public class OsmAndProtocolDecoderTest { +public class OsmAndProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - OsmAndProtocolDecoder decoder = new OsmAndProtocolDecoder(new TestDataManager(), null, null); + OsmAndProtocolDecoder decoder = new OsmAndProtocolDecoder(null); verify(decoder.decode(null, null, new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/?lat=49.60688&lon=6.15788×tamp=2014-06-04+09%3A10%3A11&altitude=384.7&speed=0.0&id=353861053849681"))); diff --git a/test/org/traccar/protocol/PiligrimProtocolDecoderTest.java b/test/org/traccar/protocol/PiligrimProtocolDecoderTest.java index 62e19ad85..354606817 100644 --- a/test/org/traccar/protocol/PiligrimProtocolDecoderTest.java +++ b/test/org/traccar/protocol/PiligrimProtocolDecoderTest.java @@ -11,12 +11,12 @@ import static org.traccar.helper.DecoderVerifier.verify; import org.junit.Test; import org.traccar.helper.ChannelBufferTools; -public class PiligrimProtocolDecoderTest { +public class PiligrimProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - PiligrimProtocolDecoder decoder = new PiligrimProtocolDecoder(new TestDataManager(), null, null); + PiligrimProtocolDecoder decoder = new PiligrimProtocolDecoder(null); HttpRequest msg1 = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/bingps?imei=868204005544720&csq=18&vout=00&vin=4050&dataid=00000000"); msg1.setContent(ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString( diff --git a/test/org/traccar/protocol/ProgressProtocolDecoderTest.java b/test/org/traccar/protocol/ProgressProtocolDecoderTest.java index dd4203609..e12f96279 100644 --- a/test/org/traccar/protocol/ProgressProtocolDecoderTest.java +++ b/test/org/traccar/protocol/ProgressProtocolDecoderTest.java @@ -10,12 +10,12 @@ import java.nio.ByteOrder; import static org.junit.Assert.assertNull; import static org.traccar.helper.DecoderVerifier.verify; -public class ProgressProtocolDecoderTest { +public class ProgressProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - ProgressProtocolDecoder decoder = new ProgressProtocolDecoder(new TestDataManager(), null, null); + ProgressProtocolDecoder decoder = new ProgressProtocolDecoder(null); assertNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, ChannelBufferTools.convertHexString( "020037000100000003003131310f003335343836383035313339303036320f00323530303136333832383531353535010000000100000000000000e6bb97b6")))); diff --git a/test/org/traccar/protocol/ProtocolDecoderTest.java b/test/org/traccar/protocol/ProtocolDecoderTest.java new file mode 100644 index 000000000..766a30284 --- /dev/null +++ b/test/org/traccar/protocol/ProtocolDecoderTest.java @@ -0,0 +1,15 @@ +package org.traccar.protocol; + +import org.traccar.Context; +import org.traccar.helper.TestDataManager; + +public class ProtocolDecoderTest { + + static { + try { + Context.init(new TestDataManager()); + } catch(Exception error) { + } + } + +} diff --git a/test/org/traccar/protocol/Pt3000ProtocolDecoderTest.java b/test/org/traccar/protocol/Pt3000ProtocolDecoderTest.java index 3aba53b69..22c1d5069 100644 --- a/test/org/traccar/protocol/Pt3000ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Pt3000ProtocolDecoderTest.java @@ -4,12 +4,12 @@ import org.traccar.helper.TestDataManager; import static org.traccar.helper.DecoderVerifier.verify; import org.junit.Test; -public class Pt3000ProtocolDecoderTest { +public class Pt3000ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Pt3000ProtocolDecoder decoder = new Pt3000ProtocolDecoder(new TestDataManager(), null, null); + Pt3000ProtocolDecoder decoder = new Pt3000ProtocolDecoder(null); verify(decoder.decode(null, null, "%356939010012099,$GPRMC,124945.752,A,4436.6245,N,01054.4634,E,0.11,358.52,060408,,,A,+393334347445,N028d")); diff --git a/test/org/traccar/protocol/Pt502ProtocolDecoderTest.java b/test/org/traccar/protocol/Pt502ProtocolDecoderTest.java index eb99e9d37..0f63c6fd7 100644 --- a/test/org/traccar/protocol/Pt502ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Pt502ProtocolDecoderTest.java @@ -4,12 +4,12 @@ import org.traccar.helper.TestDataManager; import static org.traccar.helper.DecoderVerifier.verify; import org.junit.Test; -public class Pt502ProtocolDecoderTest { +public class Pt502ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Pt502ProtocolDecoder decoder = new Pt502ProtocolDecoder(new TestDataManager(), null, null); + Pt502ProtocolDecoder decoder = new Pt502ProtocolDecoder(null); verify(decoder.decode(null, null, "$POS,6094,205523.000,A,1013.6223,N,06728.4248,W,0.0,99.3,011112,,,A/00000,00000/0/23895000//")); diff --git a/test/org/traccar/protocol/RitiProtocolDecoderTest.java b/test/org/traccar/protocol/RitiProtocolDecoderTest.java index b949e1376..d94772cd8 100644 --- a/test/org/traccar/protocol/RitiProtocolDecoderTest.java +++ b/test/org/traccar/protocol/RitiProtocolDecoderTest.java @@ -8,12 +8,12 @@ import org.traccar.helper.ChannelBufferTools; import static org.traccar.helper.DecoderVerifier.verify; import org.traccar.helper.TestDataManager; -public class RitiProtocolDecoderTest { +public class RitiProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - RitiProtocolDecoder decoder = new RitiProtocolDecoder(new TestDataManager(), null, null); + RitiProtocolDecoder decoder = new RitiProtocolDecoder(null); verify(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, ChannelBufferTools.convertHexString( "3b2864a3056300006d40000003000000000000000000000000244750524d432c3231313734332e3030302c412c313335372e333637352c4e2c31303033362e363939322c452c302e30302c2c3031303931342c2c2c412a37380d0a00000000000000000000000000000000040404")))); diff --git a/test/org/traccar/protocol/RuptelaProtocolDecoderTest.java b/test/org/traccar/protocol/RuptelaProtocolDecoderTest.java index 84949b534..22c0b6c87 100644 --- a/test/org/traccar/protocol/RuptelaProtocolDecoderTest.java +++ b/test/org/traccar/protocol/RuptelaProtocolDecoderTest.java @@ -6,12 +6,12 @@ import static org.traccar.helper.DecoderVerifier.verify; import org.junit.Test; import org.traccar.helper.ChannelBufferTools; -public class RuptelaProtocolDecoderTest { +public class RuptelaProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - RuptelaProtocolDecoder decoder = new RuptelaProtocolDecoder(new TestDataManager(), null, null); + RuptelaProtocolDecoder decoder = new RuptelaProtocolDecoder(null); verify(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString( "007900000b1a2a5585c30100024e9c036900000f101733208ff45e07b31b570a001009090605011b1a020003001c01ad01021d338e16000002960000601a41014bc16d004e9c038400000f104fdf20900d20075103b00a001308090605011b1a020003001c01ad01021d33b116000002960000601a41014bc1ea0028f9")))); diff --git a/test/org/traccar/protocol/SanavProtocolDecoderTest.java b/test/org/traccar/protocol/SanavProtocolDecoderTest.java index 6405ee281..c7b1335a1 100644 --- a/test/org/traccar/protocol/SanavProtocolDecoderTest.java +++ b/test/org/traccar/protocol/SanavProtocolDecoderTest.java @@ -4,12 +4,12 @@ import org.traccar.helper.TestDataManager; import static org.traccar.helper.DecoderVerifier.verify; import org.junit.Test; -public class SanavProtocolDecoderTest { +public class SanavProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - SanavProtocolDecoder decoder = new SanavProtocolDecoder(new TestDataManager(), null, null); + SanavProtocolDecoder decoder = new SanavProtocolDecoder(null); verify(decoder.decode(null, null, "imei=352024028982787&rmc=$GPRMC,103048.000,A,4735.0399,N,01905.2895,E,0.00,0.00,171013,,*05,AUTO-4095mv")); diff --git a/test/org/traccar/protocol/SkypatrolProtocolDecoderTest.java b/test/org/traccar/protocol/SkypatrolProtocolDecoderTest.java index 5873a78d9..942ada8b4 100644 --- a/test/org/traccar/protocol/SkypatrolProtocolDecoderTest.java +++ b/test/org/traccar/protocol/SkypatrolProtocolDecoderTest.java @@ -6,12 +6,12 @@ import static org.traccar.helper.DecoderVerifier.verify; import org.junit.Test; import org.traccar.helper.ChannelBufferTools; -public class SkypatrolProtocolDecoderTest { +public class SkypatrolProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - SkypatrolProtocolDecoder decoder = new SkypatrolProtocolDecoder(new TestDataManager(), null, null); + SkypatrolProtocolDecoder decoder = new SkypatrolProtocolDecoder(null); verify(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString( "0005021004FFFFFFFF0000000D313134373735383300CB000000000E11070C010184D032FB3841370000000016072B000017050032000000000000024E0C071116072C105900050000000000050000000000050000000003100260B7363B6306C11A00B73637F206BF19B73637F106B50EB73638B106BB0BB7363B6106B80AB73637F306B709000000000000000000C")))); diff --git a/test/org/traccar/protocol/Stl060ProtocolDecoderTest.java b/test/org/traccar/protocol/Stl060ProtocolDecoderTest.java index c1f499e4b..a4f953198 100644 --- a/test/org/traccar/protocol/Stl060ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Stl060ProtocolDecoderTest.java @@ -4,12 +4,12 @@ import org.traccar.helper.TestDataManager; import static org.traccar.helper.DecoderVerifier.verify; import org.junit.Test; -public class Stl060ProtocolDecoderTest { +public class Stl060ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Stl060ProtocolDecoder decoder = new Stl060ProtocolDecoder(new TestDataManager(), null, null); + Stl060ProtocolDecoder decoder = new Stl060ProtocolDecoder(null); verify(decoder.decode(null, null, "$1,357804048043099,D001,AP29AW0963,23/02/14,14:06:54,17248488N,078342226E,0.08,193.12,1,1,1,1,1,A")); diff --git a/test/org/traccar/protocol/SuntechProtocolDecoderTest.java b/test/org/traccar/protocol/SuntechProtocolDecoderTest.java index f3a18f70a..96bf1ea95 100644 --- a/test/org/traccar/protocol/SuntechProtocolDecoderTest.java +++ b/test/org/traccar/protocol/SuntechProtocolDecoderTest.java @@ -5,12 +5,12 @@ import static org.traccar.helper.DecoderVerifier.verify; import static org.junit.Assert.assertNull; import org.junit.Test; -public class SuntechProtocolDecoderTest { +public class SuntechProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - SuntechProtocolDecoder decoder = new SuntechProtocolDecoder(new TestDataManager(), null, null); + SuntechProtocolDecoder decoder = new SuntechProtocolDecoder(null); assertNull(decoder.decode(null, null, "SA200ALV;317652")); diff --git a/test/org/traccar/protocol/SyrusProtocolDecoderTest.java b/test/org/traccar/protocol/SyrusProtocolDecoderTest.java index 9b2457c99..4482d30cb 100644 --- a/test/org/traccar/protocol/SyrusProtocolDecoderTest.java +++ b/test/org/traccar/protocol/SyrusProtocolDecoderTest.java @@ -5,12 +5,12 @@ import org.traccar.helper.TestDataManager; import static org.traccar.helper.DecoderVerifier.verify; import org.junit.Test; -public class SyrusProtocolDecoderTest { +public class SyrusProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - SyrusProtocolDecoder decoder = new SyrusProtocolDecoder(new TestDataManager(), null, null, false); + SyrusProtocolDecoder decoder = new SyrusProtocolDecoder(null, false); assertNotNull(decoder.decode(null, null, ">RPV00000+3739438-1220384601512612;ID=1234;*7F")); diff --git a/test/org/traccar/protocol/T55ProtocolDecoderTest.java b/test/org/traccar/protocol/T55ProtocolDecoderTest.java index 48f462775..4a61fa6fa 100644 --- a/test/org/traccar/protocol/T55ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/T55ProtocolDecoderTest.java @@ -5,12 +5,12 @@ import static org.traccar.helper.DecoderVerifier.verify; import static org.junit.Assert.assertNull; import org.junit.Test; -public class T55ProtocolDecoderTest { +public class T55ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - T55ProtocolDecoder decoder = new T55ProtocolDecoder(new TestDataManager(), null, null); + T55ProtocolDecoder decoder = new T55ProtocolDecoder(null); assertNull(decoder.decode(null, null, "$GPFID,ID123456ABC")); diff --git a/test/org/traccar/protocol/TelikProtocolDecoderTest.java b/test/org/traccar/protocol/TelikProtocolDecoderTest.java index 55e00a472..dff2f9489 100644 --- a/test/org/traccar/protocol/TelikProtocolDecoderTest.java +++ b/test/org/traccar/protocol/TelikProtocolDecoderTest.java @@ -5,12 +5,12 @@ import static org.traccar.helper.DecoderVerifier.verify; import static org.junit.Assert.assertNull; import org.junit.Test; -public class TelikProtocolDecoderTest { +public class TelikProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - TelikProtocolDecoder decoder = new TelikProtocolDecoder(new TestDataManager(), null, null); + TelikProtocolDecoder decoder = new TelikProtocolDecoder(null); assertNull(decoder.decode(null, null, "0026436729|232|01|003002030")); diff --git a/test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java b/test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java index 32fa7df87..db151e65c 100644 --- a/test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java +++ b/test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java @@ -7,12 +7,12 @@ import static org.junit.Assert.assertNull; import org.junit.Test; import org.traccar.helper.ChannelBufferTools; -public class TeltonikaProtocolDecoderTest { +public class TeltonikaProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - TeltonikaProtocolDecoder decoder = new TeltonikaProtocolDecoder(new TestDataManager(), null, null); + TeltonikaProtocolDecoder decoder = new TeltonikaProtocolDecoder(null); assertNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString( "000F313233343536373839303132333435")))); diff --git a/test/org/traccar/protocol/Tk102ProtocolDecoderTest.java b/test/org/traccar/protocol/Tk102ProtocolDecoderTest.java index 998365648..21a6e3010 100644 --- a/test/org/traccar/protocol/Tk102ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Tk102ProtocolDecoderTest.java @@ -5,12 +5,12 @@ import static org.traccar.helper.DecoderVerifier.verify; import static org.junit.Assert.assertNull; import org.junit.Test; -public class Tk102ProtocolDecoderTest { +public class Tk102ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Tk102ProtocolDecoder decoder = new Tk102ProtocolDecoder(new TestDataManager(), null, null); + Tk102ProtocolDecoder decoder = new Tk102ProtocolDecoder(null); assertNull(decoder.decode(null, null, "")); diff --git a/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java b/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java index be1c8929b..f8df401fe 100644 --- a/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java @@ -5,12 +5,12 @@ import static org.traccar.helper.DecoderVerifier.verify; import static org.junit.Assert.assertNull; import org.junit.Test; -public class Tk103ProtocolDecoderTest { +public class Tk103ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Tk103ProtocolDecoder decoder = new Tk103ProtocolDecoder(new TestDataManager(), null, null); + Tk103ProtocolDecoder decoder = new Tk103ProtocolDecoder(null); assertNull(decoder.decode(null, null, "(090411121854BP0000001234567890HSO")); diff --git a/test/org/traccar/protocol/Tlt2hProtocolDecoderTest.java b/test/org/traccar/protocol/Tlt2hProtocolDecoderTest.java index de1ce2aa3..5473f6774 100644 --- a/test/org/traccar/protocol/Tlt2hProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Tlt2hProtocolDecoderTest.java @@ -4,12 +4,12 @@ import org.traccar.helper.TestDataManager; import static org.traccar.helper.DecoderVerifier.verify; import org.junit.Test; -public class Tlt2hProtocolDecoderTest { +public class Tlt2hProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Tlt2hProtocolDecoder decoder = new Tlt2hProtocolDecoder(new TestDataManager(), null, null); + Tlt2hProtocolDecoder decoder = new Tlt2hProtocolDecoder(null); verify(decoder.decode(null, null, "#357671030946351#V500#0000#AUTO#1\r\n" + diff --git a/test/org/traccar/protocol/TopflytechProtocolDecoderTest.java b/test/org/traccar/protocol/TopflytechProtocolDecoderTest.java index 2e5d1b0af..1804b335c 100644 --- a/test/org/traccar/protocol/TopflytechProtocolDecoderTest.java +++ b/test/org/traccar/protocol/TopflytechProtocolDecoderTest.java @@ -5,12 +5,12 @@ import static org.traccar.helper.DecoderVerifier.verify; import static org.junit.Assert.assertNull; import org.junit.Test; -public class TopflytechProtocolDecoderTest { +public class TopflytechProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - TopflytechProtocolDecoder decoder = new TopflytechProtocolDecoder(new TestDataManager(), null, null); + TopflytechProtocolDecoder decoder = new TopflytechProtocolDecoder(null); verify(decoder.decode(null, null, "(880316890094910BP00XG00b600000000L00074b54S00000000R0C0F0014000100f0130531152205A0706.1395S11024.0965E000.0251.25")); diff --git a/test/org/traccar/protocol/TotemProtocolDecoderTest.java b/test/org/traccar/protocol/TotemProtocolDecoderTest.java index 35d30d9ae..bd66c7677 100644 --- a/test/org/traccar/protocol/TotemProtocolDecoderTest.java +++ b/test/org/traccar/protocol/TotemProtocolDecoderTest.java @@ -5,12 +5,12 @@ import static org.traccar.helper.DecoderVerifier.verify; import static org.junit.Assert.assertNull; import org.junit.Test; -public class TotemProtocolDecoderTest { +public class TotemProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - TotemProtocolDecoder decoder = new TotemProtocolDecoder(new TestDataManager(), null, null); + TotemProtocolDecoder decoder = new TotemProtocolDecoder(null); verify(decoder.decode(null, null, "$$AE860990002922822|AA$GPRMC,051002.00,A,0439.26245,N,10108.94448,E,0.023,,140315,,,A*71|02.98|01.95|02.26|000000000000|20150314051003|13841157|105A3B1C|0000|0.0000|0005|5324")); diff --git a/test/org/traccar/protocol/Tr20ProtocolDecoderTest.java b/test/org/traccar/protocol/Tr20ProtocolDecoderTest.java index b2d2d9a7d..669e84f53 100644 --- a/test/org/traccar/protocol/Tr20ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Tr20ProtocolDecoderTest.java @@ -5,12 +5,12 @@ import static org.traccar.helper.DecoderVerifier.verify; import static org.junit.Assert.assertNull; import org.junit.Test; -public class Tr20ProtocolDecoderTest { +public class Tr20ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Tr20ProtocolDecoder decoder = new Tr20ProtocolDecoder(new TestDataManager(), null, null); + Tr20ProtocolDecoder decoder = new Tr20ProtocolDecoder(null); assertNull(decoder.decode(null, null, "%%TRACKPRO01,1")); diff --git a/test/org/traccar/protocol/Tr900ProtocolDecoderTest.java b/test/org/traccar/protocol/Tr900ProtocolDecoderTest.java index 0549478d9..a5ce90b15 100644 --- a/test/org/traccar/protocol/Tr900ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Tr900ProtocolDecoderTest.java @@ -6,12 +6,12 @@ import org.traccar.helper.TestDataManager; import static org.junit.Assert.assertNull; import static org.traccar.helper.DecoderVerifier.verify; -public class Tr900ProtocolDecoderTest { +public class Tr900ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Tr900ProtocolDecoder decoder = new Tr900ProtocolDecoder(new TestDataManager(), null, null); + Tr900ProtocolDecoder decoder = new Tr900ProtocolDecoder(null); verify(decoder.decode(null, null, ">12345678,1,1,070201,144111,W05829.2613,S3435.2313,,00,034,25,00,126-000,0,3,11111111*2d!")); diff --git a/test/org/traccar/protocol/TrackboxProtocolDecoderTest.java b/test/org/traccar/protocol/TrackboxProtocolDecoderTest.java index eb26532b0..4319a1eed 100644 --- a/test/org/traccar/protocol/TrackboxProtocolDecoderTest.java +++ b/test/org/traccar/protocol/TrackboxProtocolDecoderTest.java @@ -5,12 +5,12 @@ import static org.traccar.helper.DecoderVerifier.verify; import static org.junit.Assert.assertNull; import org.junit.Test; -public class TrackboxProtocolDecoderTest { +public class TrackboxProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - TrackboxProtocolDecoder decoder = new TrackboxProtocolDecoder(new TestDataManager(), null, null); + TrackboxProtocolDecoder decoder = new TrackboxProtocolDecoder(null); assertNull(decoder.decode(null, null, "a=connect&v=11&i=111111111111111")); diff --git a/test/org/traccar/protocol/TramigoProtocolDecoderTest.java b/test/org/traccar/protocol/TramigoProtocolDecoderTest.java index 2009c8072..f2cdf3332 100644 --- a/test/org/traccar/protocol/TramigoProtocolDecoderTest.java +++ b/test/org/traccar/protocol/TramigoProtocolDecoderTest.java @@ -10,12 +10,12 @@ import java.nio.ByteOrder; import static org.junit.Assert.assertNull; import static org.traccar.helper.DecoderVerifier.verify; -public class TramigoProtocolDecoderTest { +public class TramigoProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - TramigoProtocolDecoder decoder = new TramigoProtocolDecoder(new TestDataManager(), null, null); + TramigoProtocolDecoder decoder = new TramigoProtocolDecoder(null); verify(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, ChannelBufferTools.convertHexString( "8000011bb0009e0001015b93032ef6f35994a9545472616d69676f3a204d6f76696e672c20302e3930206b6d205345206f66204372616e6562726f6f6b20466972652053746174696f6e2c2050656e726974682c205379646e65792c2041552c202d33332e37303732322c203135302e37313735392c2053452077697468207370656564203337206b6d2f682c2031393a3438204a616e20342020454f46")))); diff --git a/test/org/traccar/protocol/TytanProtocolDecoderTest.java b/test/org/traccar/protocol/TytanProtocolDecoderTest.java index 2139cbcb5..5fdb847b1 100644 --- a/test/org/traccar/protocol/TytanProtocolDecoderTest.java +++ b/test/org/traccar/protocol/TytanProtocolDecoderTest.java @@ -7,12 +7,12 @@ import org.traccar.helper.ChannelBufferTools; import static org.traccar.helper.DecoderVerifier.verify; import org.traccar.helper.TestDataManager; -public class TytanProtocolDecoderTest { +public class TytanProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - TytanProtocolDecoder decoder = new TytanProtocolDecoder(new TestDataManager(), null, null); + TytanProtocolDecoder decoder = new TytanProtocolDecoder(null); verify(decoder.decode(null, null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString( "D56000000AF20E4FA7C77AFF3282C68D2F890800")))); diff --git a/test/org/traccar/protocol/UlbotechProtocolDecoderTest.java b/test/org/traccar/protocol/UlbotechProtocolDecoderTest.java index f71b746f3..e680ec6af 100644 --- a/test/org/traccar/protocol/UlbotechProtocolDecoderTest.java +++ b/test/org/traccar/protocol/UlbotechProtocolDecoderTest.java @@ -8,12 +8,12 @@ import org.traccar.helper.TestDataManager; import static org.junit.Assert.assertNull; import static org.traccar.helper.DecoderVerifier.verify; -public class UlbotechProtocolDecoderTest { +public class UlbotechProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - UlbotechProtocolDecoder decoder = new UlbotechProtocolDecoder(new TestDataManager(), null, null); + UlbotechProtocolDecoder decoder = new UlbotechProtocolDecoder(null); verify(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString( "F80101035785203457289495D60235010E016175A506C2C838000000000064")))); diff --git a/test/org/traccar/protocol/V680ProtocolDecoderTest.java b/test/org/traccar/protocol/V680ProtocolDecoderTest.java index f481bfda4..07359f890 100644 --- a/test/org/traccar/protocol/V680ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/V680ProtocolDecoderTest.java @@ -5,12 +5,12 @@ import static org.traccar.helper.DecoderVerifier.verify; import static org.junit.Assert.assertNull; import org.junit.Test; -public class V680ProtocolDecoderTest { +public class V680ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - V680ProtocolDecoder decoder = new V680ProtocolDecoder(new TestDataManager(), null, null); + V680ProtocolDecoder decoder = new V680ProtocolDecoder(null); assertNull(decoder.decode(null, null, "#353588102019155")); diff --git a/test/org/traccar/protocol/VisiontekProtocolDecoderTest.java b/test/org/traccar/protocol/VisiontekProtocolDecoderTest.java index 45f8d892a..3eb1045a7 100644 --- a/test/org/traccar/protocol/VisiontekProtocolDecoderTest.java +++ b/test/org/traccar/protocol/VisiontekProtocolDecoderTest.java @@ -5,12 +5,12 @@ import static org.traccar.helper.DecoderVerifier.verify; import static org.junit.Assert.assertNull; import org.junit.Test; -public class VisiontekProtocolDecoderTest { +public class VisiontekProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - VisiontekProtocolDecoder decoder = new VisiontekProtocolDecoder(new TestDataManager(), null, null); + VisiontekProtocolDecoder decoder = new VisiontekProtocolDecoder(null); verify(decoder.decode(null, null, "$1,AP09BU9397,861785006462448,20,06,14,15,03,28,17267339N,078279407E,060.0,073,0550,11,0,1,0,0,1,1,26,A,0000000000")); diff --git a/test/org/traccar/protocol/WialonProtocolDecoderTest.java b/test/org/traccar/protocol/WialonProtocolDecoderTest.java index 0f5035650..25d61b363 100644 --- a/test/org/traccar/protocol/WialonProtocolDecoderTest.java +++ b/test/org/traccar/protocol/WialonProtocolDecoderTest.java @@ -5,12 +5,12 @@ import static org.traccar.helper.DecoderVerifier.verify; import static org.junit.Assert.assertNull; import org.junit.Test; -public class WialonProtocolDecoderTest { +public class WialonProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - WialonProtocolDecoder decoder = new WialonProtocolDecoder(new TestDataManager(), null, null); + WialonProtocolDecoder decoder = new WialonProtocolDecoder(null); assertNull(decoder.decode(null, null, "#L#123456789012345;test")); diff --git a/test/org/traccar/protocol/WondexProtocolDecoderTest.java b/test/org/traccar/protocol/WondexProtocolDecoderTest.java index 096273a66..45f72dd8a 100644 --- a/test/org/traccar/protocol/WondexProtocolDecoderTest.java +++ b/test/org/traccar/protocol/WondexProtocolDecoderTest.java @@ -4,12 +4,12 @@ import org.traccar.helper.TestDataManager; import static org.traccar.helper.DecoderVerifier.verify; import org.junit.Test; -public class WondexProtocolDecoderTest { +public class WondexProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - WondexProtocolDecoder decoder = new WondexProtocolDecoder(new TestDataManager(), null, null); + WondexProtocolDecoder decoder = new WondexProtocolDecoder(null); verify(decoder.decode(null, null, "1044989601,20130323074605,0.000000,90.000000,0,000,0,0,2")); diff --git a/test/org/traccar/protocol/Xexun2ProtocolDecoderTest.java b/test/org/traccar/protocol/Xexun2ProtocolDecoderTest.java index 9703d3ca3..a4dcdc9f4 100644 --- a/test/org/traccar/protocol/Xexun2ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Xexun2ProtocolDecoderTest.java @@ -5,12 +5,12 @@ import org.traccar.helper.TestDataManager; import static org.traccar.helper.DecoderVerifier.verify; import org.junit.Test; -public class Xexun2ProtocolDecoderTest { +public class Xexun2ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Xexun2ProtocolDecoder decoder = new Xexun2ProtocolDecoder(new TestDataManager(), null, null); + Xexun2ProtocolDecoder decoder = new Xexun2ProtocolDecoder(null); assertNull(decoder.decode(null, null, ",+48606717068,,L,, imei:012207005047292,,,F:4.28V,1,52,11565,247,01,000E,1FC5")); diff --git a/test/org/traccar/protocol/XexunProtocolDecoderTest.java b/test/org/traccar/protocol/XexunProtocolDecoderTest.java index 9b19d3822..cf134d1a5 100644 --- a/test/org/traccar/protocol/XexunProtocolDecoderTest.java +++ b/test/org/traccar/protocol/XexunProtocolDecoderTest.java @@ -4,12 +4,12 @@ import org.traccar.helper.TestDataManager; import static org.traccar.helper.DecoderVerifier.verify; import org.junit.Test; -public class XexunProtocolDecoderTest { +public class XexunProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - XexunProtocolDecoder decoder = new XexunProtocolDecoder(new TestDataManager(), null, null); + XexunProtocolDecoder decoder = new XexunProtocolDecoder(null); verify(decoder.decode(null, null, "GPRMC,043435.000,A,811.299200,S,11339.9500,E,0.93,29.52,160313,00,0000.0,A*65,F,,imei:359585014597923,")); diff --git a/test/org/traccar/protocol/XirgoProtocolDecoderTest.java b/test/org/traccar/protocol/XirgoProtocolDecoderTest.java index 81133104c..99e5f95ec 100644 --- a/test/org/traccar/protocol/XirgoProtocolDecoderTest.java +++ b/test/org/traccar/protocol/XirgoProtocolDecoderTest.java @@ -4,12 +4,12 @@ import org.traccar.helper.TestDataManager; import static org.traccar.helper.DecoderVerifier.verify; import org.junit.Test; -public class XirgoProtocolDecoderTest { +public class XirgoProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - XirgoProtocolDecoder decoder = new XirgoProtocolDecoder(new TestDataManager(), null, null); + XirgoProtocolDecoder decoder = new XirgoProtocolDecoder(null); verify(decoder.decode(null, null, null, "$$354898045650537,6031,2015/02/26,15:47:26,33.42552,-112.30308,287.8,0,0,0,0,0.0,7,1.2,2,0.0,12.2,22,1,0,82.3")); diff --git a/test/org/traccar/protocol/Xt013ProtocolDecoderTest.java b/test/org/traccar/protocol/Xt013ProtocolDecoderTest.java index 45d86b902..c7ef44607 100644 --- a/test/org/traccar/protocol/Xt013ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Xt013ProtocolDecoderTest.java @@ -5,12 +5,12 @@ import org.traccar.helper.TestDataManager; import static org.traccar.helper.DecoderVerifier.verify; -public class Xt013ProtocolDecoderTest { +public class Xt013ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Xt013ProtocolDecoder decoder = new Xt013ProtocolDecoder(new TestDataManager(), null, null); + Xt013ProtocolDecoder decoder = new Xt013ProtocolDecoder(null); verify(decoder.decode(null, null, "TK,862950021650364,150131090859,+53.267863,+5.767363,0,38,12,0,F,204,08,C94,336C,24,,4.09,1,,,,,,,,")); diff --git a/test/org/traccar/protocol/Xt7ProtocolDecoderTest.java b/test/org/traccar/protocol/Xt7ProtocolDecoderTest.java index e786cd4da..b2be6fa48 100644 --- a/test/org/traccar/protocol/Xt7ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Xt7ProtocolDecoderTest.java @@ -8,12 +8,12 @@ import org.jboss.netty.buffer.HeapChannelBufferFactory; import static org.traccar.helper.DecoderVerifier.verify; import org.junit.Test; -public class Xt7ProtocolDecoderTest { +public class Xt7ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Xt7ProtocolDecoder decoder = new Xt7ProtocolDecoder(new TestDataManager(), null, null); + Xt7ProtocolDecoder decoder = new Xt7ProtocolDecoder(null); verify(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString( "53545832303130313031383031202020202020026A244750524D432C3130313035332E3030302C412C323233322E373630372C4E2C31313430342E373636392C452C302E30302C2C3233313131302C2C2C412A37462C3436302C30302C323739352C304536412C31342C39342C313030302C303030302C39312C54696D65723B31440D0A")))); diff --git a/test/org/traccar/protocol/YwtProtocolDecoderTest.java b/test/org/traccar/protocol/YwtProtocolDecoderTest.java index 5d98530e3..30d8091a8 100644 --- a/test/org/traccar/protocol/YwtProtocolDecoderTest.java +++ b/test/org/traccar/protocol/YwtProtocolDecoderTest.java @@ -5,12 +5,12 @@ import static org.traccar.helper.DecoderVerifier.verify; import static org.junit.Assert.assertNull; import org.junit.Test; -public class YwtProtocolDecoderTest { +public class YwtProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - YwtProtocolDecoder decoder = new YwtProtocolDecoder(new TestDataManager(), null, null); + YwtProtocolDecoder decoder = new YwtProtocolDecoder(null); assertNull(decoder.decode(null, null, "%SN,0417061042:0,0,140117041203,404")); |