diff options
277 files changed, 4398 insertions, 1707 deletions
diff --git a/src/org/traccar/BaseProtocol.java b/src/org/traccar/BaseProtocol.java new file mode 100644 index 000000000..f8bf7ef30 --- /dev/null +++ b/src/org/traccar/BaseProtocol.java @@ -0,0 +1,40 @@ +package org.traccar; + +import org.traccar.database.ActiveDevice; +import org.traccar.http.commands.CommandType; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.GpsCommand; + +import java.util.HashMap; +import java.util.Map; + +public abstract class BaseProtocol implements Protocol { + + private final String name; + private Map<CommandType, CommandTemplate> commandTemplates = new HashMap<CommandType, CommandTemplate>(); + + public BaseProtocol(String name) { + this.name = name; + this.loadCommandsTemplates(commandTemplates); + } + + public String getName() { + return name; + } + + @Override + public void sendCommand(ActiveDevice activeDevice, GpsCommand command) { + CommandTemplate commandMessage = commandTemplates.get(command.getType()); + + if (commandMessage == null) { + throw new RuntimeException("The command " + command + " is not yet supported in protocol " + this.getName()); + } + + Object response = commandMessage.applyTo(activeDevice, command); + + activeDevice.write(response); + } + + protected abstract void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates); + +} diff --git a/src/org/traccar/BaseProtocolDecoder.java b/src/org/traccar/BaseProtocolDecoder.java index b10f4d355..6e9efd830 100644 --- a/src/org/traccar/BaseProtocolDecoder.java +++ b/src/org/traccar/BaseProtocolDecoder.java @@ -16,7 +16,6 @@ package org.traccar; import java.net.SocketAddress; -import java.util.Properties; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelEvent; @@ -25,7 +24,6 @@ import static org.jboss.netty.channel.Channels.fireMessageReceived; 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; @@ -34,10 +32,10 @@ import org.traccar.model.Device; */ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder { - private final String protocol; + private final Protocol protocol; - public String getProtocol() { - return protocol; + public String getProtocolName() { + return protocol.getName(); } private long deviceId; @@ -50,11 +48,12 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder { return deviceId; } - public boolean identify(String uniqueId, boolean logWarning) { + public boolean identify(String uniqueId, Channel channel, SocketAddress remoteAddress, boolean logWarning) { try { Device device = Context.getDataManager().getDeviceByUniqueId(uniqueId); if (device != null) { deviceId = device.getId(); + Context.getDataManager().setActiveDevice(device.getUniqueId(), protocol, channel, remoteAddress); return true; } else { deviceId = 0; @@ -70,11 +69,15 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder { } } - public boolean identify(String uniqueId) { - return identify(uniqueId, true); + public boolean identify(String uniqueId, Channel channel, SocketAddress remoteAddress) { + return identify(uniqueId, channel, remoteAddress, true); } - public BaseProtocolDecoder(String protocol) { + public boolean identify(String uniqueId, Channel channel) { + return identify(uniqueId, channel, null, true); + } + + public BaseProtocolDecoder(Protocol protocol) { this.protocol = protocol; } diff --git a/src/org/traccar/Protocol.java b/src/org/traccar/Protocol.java new file mode 100644 index 000000000..bcb591aaf --- /dev/null +++ b/src/org/traccar/Protocol.java @@ -0,0 +1,15 @@ +package org.traccar; + +import org.traccar.database.ActiveDevice; +import org.traccar.http.commands.GpsCommand; + +import java.util.List; + +public interface Protocol { + + public String getName(); + + void sendCommand(ActiveDevice activeDevice, GpsCommand command); + + void addTrackerServersTo(List<TrackerServer> serverList); +} diff --git a/src/org/traccar/ServerManager.java b/src/org/traccar/ServerManager.java index 3ad7cb474..bf6e87e17 100644 --- a/src/org/traccar/ServerManager.java +++ b/src/org/traccar/ServerManager.java @@ -32,100 +32,99 @@ import org.jboss.netty.handler.codec.string.StringDecoder; import org.jboss.netty.handler.codec.string.StringEncoder; import org.traccar.protocol.*; - public class ServerManager { private final List<TrackerServer> serverList = new LinkedList<TrackerServer>(); public void init() throws Exception { - initGps103Server("gps103"); - initTk103Server("tk103"); - initGl100Server("gl100"); - initGl200Server("gl200"); - initT55Server("t55"); - initXexunServer("xexun"); - initTotemServer("totem"); - initEnforaServer("enfora"); - initMeiligaoServer("meiligao"); - initMaxonServer("maxon"); - initSuntechServer("suntech"); - initProgressServer("progress"); - initH02Server("h02"); - initJt600Server("jt600"); - initEv603Server("ev603"); - initV680Server("v680"); - initPt502Server("pt502"); - initTr20Server("tr20"); - initNavisServer("navis"); - initMeitrackServer("meitrack"); - initSkypatrolServer("skypatrol"); - initGt02Server("gt02"); - initGt06Server("gt06"); - initMegastekServer("megastek"); - initNavigilServer("navigil"); - initGpsGateServer("gpsgate"); - initTeltonikaServer("teltonika"); - initMta6Server("mta6"); - initMta6CanServer("mta6can"); - initTlt2hServer("tlt2h"); - initSyrusServer("syrus"); - initWondexServer("wondex"); - initCellocatorServer("cellocator"); - initGalileoServer("galileo"); - initYwtServer("ywt"); - initTk102Server("tk102"); - initIntellitracServer("intellitrac"); - initXt7Server("xt7"); - initWialonServer("wialon"); - initCarscopServer("carscop"); - initApelServer("apel"); - initManPowerServer("manpower"); - initGlobalSatServer("globalsat"); - initAtrackServer("atrack"); - initPt3000Server("pt3000"); - initRuptelaServer("ruptela"); - initTopflytechServer("topflytech"); - initLaipacServer("laipac"); - initAplicomServer("aplicom"); - initGotopServer("gotop"); - initSanavServer("sanav"); - initGatorServer("gator"); - initNoranServer("noran"); - initM2mServer("m2m"); - initOsmAndServer("osmand"); - initEasyTrackServer("easytrack"); - initTaipServer("taip"); - initKhdServer("khd"); - initPiligrimServer("piligrim"); - initStl060Server("stl060"); - initCarTrackServer("cartrack"); - initMiniFinderServer("minifinder"); - initHaicomServer("haicom"); - initEelinkServer("eelink"); - initBoxServer("box"); - initFreedomServer("freedom"); - initTelikServer("telik"); - initTrackboxServer("trackbox"); - initVisiontekServer("visiontek"); - initOrionServer("orion"); - initRitiServer("riti"); - initUlbotechServer("ulbotech"); - initTramigoServer("tramigo"); - initTr900Server("tr900"); - initArdi01Server("ardi01"); - initXt013Server("xt013"); - initAutoFonServer("autofon"); - initGoSafeServer("gosafe"); - initAutoFon45Server("autofon45"); - initBceServer("bce"); - initXirgoServer("xirgo"); - initCalAmpServer("calamp"); - initMtxServer("mtx"); - initTytanServer("tytan"); - initAvl301Server("avl301"); - initCastelServer("castel"); - initMxtServer("mxt"); + initProtocolServer(new Gps103Protocol()); + initProtocolServer(new Tk103Protocol()); + initProtocolServer(new Gl100Protocol()); + initProtocolServer(new Gl200Protocol()); + initProtocolServer(new T55Protocol()); + initProtocolServer(new XexunProtocol()); + initProtocolServer(new TotemProtocol()); + initProtocolServer(new EnforaProtocol()); + initProtocolServer(new MeiligaoProtocol()); + initProtocolServer(new MaxonProtocol()); + initProtocolServer(new SuntechProtocol()); + initProtocolServer(new ProgressProtocol()); + initProtocolServer(new H02Protocol()); + initProtocolServer(new Jt600Protocol()); + initProtocolServer(new Ev603Protocol()); + initProtocolServer(new V680Protocol()); + initProtocolServer(new Pt502Protocol()); + initProtocolServer(new Tr20Protocol()); + initProtocolServer(new NavisProtocol()); + initProtocolServer(new MeitrackProtocol()); + initProtocolServer(new SkypatrolProtocol()); + initProtocolServer(new Gt02Protocol()); + initProtocolServer(new Gt06Protocol()); + initProtocolServer(new MegastekProtocol()); + initProtocolServer(new NavigilProtocol()); + initProtocolServer(new GpsGateProtocol()); + initProtocolServer(new TeltonikaProtocol()); + initProtocolServer(new Mta6Protocol()); + initProtocolServer(new Mta6canProtocol()); + initProtocolServer(new Tlt2hProtocol()); + initProtocolServer(new SyrusProtocol()); + initProtocolServer(new WondexProtocol()); + initProtocolServer(new CellocatorProtocol()); + initProtocolServer(new GalileoProtocol()); + initProtocolServer(new YwtProtocol()); + initProtocolServer(new Tk102Protocol()); + initProtocolServer(new IntellitracProtocol()); + initProtocolServer(new Xt7Protocol()); + initProtocolServer(new WialonProtocol()); + initProtocolServer(new CarscopProtocol()); + initProtocolServer(new ApelProtocol()); + initProtocolServer(new ManPowerProtocol()); + initProtocolServer(new GlobalSatProtocol()); + initProtocolServer(new AtrackProtocol()); + initProtocolServer(new Pt3000Protocol()); + initProtocolServer(new RuptelaProtocol()); + initProtocolServer(new TopflytechProtocol()); + initProtocolServer(new LaipacProtocol()); + initProtocolServer(new AplicomProtocol()); + initProtocolServer(new GotopProtocol()); + initProtocolServer(new SanavProtocol()); + initProtocolServer(new GatorProtocol()); + initProtocolServer(new NoranProtocol()); + initProtocolServer(new M2mProtocol()); + initProtocolServer(new OsmAndProtocol()); + initProtocolServer(new EasyTrackProtocol()); + initProtocolServer(new TaipProtocol()); + initProtocolServer(new KhdProtocol()); + initProtocolServer(new PiligrimProtocol()); + initProtocolServer(new Stl060Protocol()); + initProtocolServer(new CarTrackProtocol()); + initProtocolServer(new MiniFinderProtocol()); + initProtocolServer(new HaicomProtocol()); + initProtocolServer(new EelinkProtocol()); + initProtocolServer(new BoxProtocol()); + initProtocolServer(new FreedomProtocol()); + initProtocolServer(new TelikProtocol()); + initProtocolServer(new TrackboxProtocol()); + initProtocolServer(new VisiontekProtocol()); + initProtocolServer(new OrionProtocol()); + initProtocolServer(new RitiProtocol()); + initProtocolServer(new UlbotechProtocol()); + initProtocolServer(new TramigoProtocol()); + initProtocolServer(new Tr900Protocol()); + initProtocolServer(new Ardi01Protocol()); + initProtocolServer(new Xt013Protocol()); + initProtocolServer(new AutoFonProtocol()); + initProtocolServer(new GoSafeProtocol()); + initProtocolServer(new AutoFon45Protocol()); + initProtocolServer(new BceProtocol()); + initProtocolServer(new XirgoProtocol()); + initProtocolServer(new CalAmpProtocol()); + initProtocolServer(new MtxProtocol()); + initProtocolServer(new TytanProtocol()); + initProtocolServer(new Avl301Protocol()); + initProtocolServer(new CastelProtocol()); + initProtocolServer(new MxtProtocol()); initProtocolDetector(); } @@ -168,1204 +167,9 @@ public class ServerManager { } } - private void initGps103Server(final String protocol) throws SQLException { - 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(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(protocol)); - } - }); - } - } - - private void initTk103Server(final String protocol) throws SQLException { - 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(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(protocol)); - } - }); - } - } - - private void initGl100Server(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initGl200Server(final String protocol) throws SQLException { - 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(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 Gl200ProtocolDecoder(protocol)); - } - }); - } - } - - private void initT55Server(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initXexunServer(final String protocol) throws SQLException { - if (isProtocolEnabled(protocol)) { - serverList.add(new TrackerServer(new ServerBootstrap(), protocol) { - @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { - 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(protocol)); - } else { - pipeline.addLast("frameDecoder", new XexunFrameDecoder()); - pipeline.addLast("stringDecoder", new StringDecoder()); - pipeline.addLast("objectDecoder", new XexunProtocolDecoder(protocol)); - } - } - }); - } - } - - private void initTotemServer(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initEnforaServer(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initMeiligaoServer(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initMaxonServer(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initSuntechServer(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initProgressServer(final String protocol) throws SQLException { - 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(protocol)); - } - }; - server.setEndianness(ByteOrder.LITTLE_ENDIAN); - serverList.add(server); - } - } - - private void initH02Server(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initJt600Server(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initEv603Server(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initV680Server(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initPt502Server(final String protocol) throws SQLException { - 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(protocol)); - } - }; - server.setEndianness(ByteOrder.LITTLE_ENDIAN); - serverList.add(server); - } - } - - private void initTr20Server(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initNavisServer(final String protocol) throws SQLException { - 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(protocol)); - } - }; - server.setEndianness(ByteOrder.LITTLE_ENDIAN); - serverList.add(server); - } - } - - private void initMeitrackServer(final String protocol) throws SQLException { - 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(protocol)); - } - }; - server.setEndianness(ByteOrder.LITTLE_ENDIAN); - serverList.add(server); - } - } - - private void initSkypatrolServer(final String protocol) throws SQLException { - if (isProtocolEnabled(protocol)) { - serverList.add(new TrackerServer(new ConnectionlessBootstrap(), protocol) { - @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { - pipeline.addLast("objectDecoder", new SkypatrolProtocolDecoder(protocol)); - } - }); - } - } - - private void initGt02Server(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initGt06Server(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initMegastekServer(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initNavigilServer(final String protocol) throws SQLException { - 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(protocol)); - } - }; - server.setEndianness(ByteOrder.LITTLE_ENDIAN); - serverList.add(server); - } - } - - private void initGpsGateServer(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initTeltonikaServer(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initMta6Server(final String protocol) throws SQLException { - 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(protocol, false)); - } - }); - } - } - - private void initMta6CanServer(final String protocol) throws SQLException { - 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(protocol, true)); - } - }); - } - } - - private void initTlt2hServer(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initSyrusServer(final String protocol) throws SQLException { - 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(protocol, true)); - } - }); - } - } - - private void initWondexServer(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initCellocatorServer(final String protocol) throws SQLException { - 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(protocol)); - } - }; - server.setEndianness(ByteOrder.LITTLE_ENDIAN); - serverList.add(server); - } - } - - private void initGalileoServer(final String protocol) throws SQLException { - 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(protocol)); - } - }; - server.setEndianness(ByteOrder.LITTLE_ENDIAN); - serverList.add(server); - } - } - - private void initYwtServer(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initTk102Server(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initIntellitracServer(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initXt7Server(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initWialonServer(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initCarscopServer(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initApelServer(final String protocol) throws SQLException { - 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(protocol)); - } - }; - server.setEndianness(ByteOrder.LITTLE_ENDIAN); - serverList.add(server); - } - } - - private void initManPowerServer(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initGlobalSatServer(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initAtrackServer(final String protocol) throws SQLException { - 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(protocol)); - } - }); - serverList.add(new TrackerServer(new ConnectionlessBootstrap(), protocol) { - @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { - pipeline.addLast("objectDecoder", new AtrackProtocolDecoder(protocol)); - } - }); - - } - } - - private void initPt3000Server(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initRuptelaServer(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initTopflytechServer(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initLaipacServer(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initAplicomServer(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initGotopServer(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initSanavServer(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initGatorServer(final String protocol) throws SQLException { - if (isProtocolEnabled(protocol)) { - serverList.add(new TrackerServer(new ConnectionlessBootstrap(), protocol) { - @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { - pipeline.addLast("objectDecoder", new GatorProtocolDecoder(protocol)); - } - }); - } - } - - private void initNoranServer(final String protocol) throws SQLException { - if (isProtocolEnabled(protocol)) { - TrackerServer server = new TrackerServer(new ConnectionlessBootstrap(), protocol) { - @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { - pipeline.addLast("objectDecoder", new NoranProtocolDecoder(protocol)); - } - }; - server.setEndianness(ByteOrder.LITTLE_ENDIAN); - serverList.add(server); - } - } - - private void initM2mServer(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initOsmAndServer(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initEasyTrackServer(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initTaipServer(final String protocol) throws SQLException { - 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(protocol, false)); - } - }); - } - } - - private void initKhdServer(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initPiligrimServer(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initStl060Server(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initCarTrackServer(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initMiniFinderServer(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initHaicomServer(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initEelinkServer(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initBoxServer(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initFreedomServer(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initTelikServer(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initTrackboxServer(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initVisiontekServer(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initOrionServer(final String protocol) throws SQLException { - 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(protocol)); - } - }; - server.setEndianness(ByteOrder.LITTLE_ENDIAN); - serverList.add(server); - } - } - - private void initRitiServer(final String protocol) throws SQLException { - 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(protocol)); - } - }; - server.setEndianness(ByteOrder.LITTLE_ENDIAN); - serverList.add(server); - } - } - - private void initUlbotechServer(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initTramigoServer(final String protocol) throws SQLException { - 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(protocol)); - } - }; - server.setEndianness(ByteOrder.LITTLE_ENDIAN); - serverList.add(server); - } - } - - private void initTr900Server(final String protocol) throws SQLException { - 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 Tr900ProtocolDecoder(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 Tr900ProtocolDecoder(protocol)); - } - }); - } - } - - private void initArdi01Server(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initXt013Server(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initAutoFonServer(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initGoSafeServer(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initAutoFon45Server(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initBceServer(final String protocol) throws SQLException { - 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(protocol)); - } - }; - server.setEndianness(ByteOrder.LITTLE_ENDIAN); - serverList.add(server); - } - } - - private void initXirgoServer(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initCalAmpServer(final String protocol) throws SQLException { - if (isProtocolEnabled(protocol)) { - serverList.add(new TrackerServer(new ConnectionlessBootstrap(), protocol) { - @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { - pipeline.addLast("objectDecoder", new CalAmpProtocolDecoder(protocol)); - } - }); - } - } - - private void initMtxServer(final String protocol) throws SQLException { - 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(protocol)); - } - }); - } - } - - private void initTytanServer(final String protocol) throws SQLException { - if (isProtocolEnabled(protocol)) { - serverList.add(new TrackerServer(new ConnectionlessBootstrap(), protocol) { - @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { - pipeline.addLast("objectDecoder", new TytanProtocolDecoder(protocol)); - } - }); - } - } - - private void initAvl301Server(final String protocol) throws SQLException { - if (isProtocolEnabled(protocol)) { - serverList.add(new TrackerServer(new ServerBootstrap(), protocol) { - @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { - pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(256, 2, 1, -3, 0)); - pipeline.addLast("objectDecoder", new Avl301ProtocolDecoder(protocol)); - } - }); - } - } - - private void initCastelServer(final String protocol) throws SQLException { - 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 CastelProtocolDecoder(protocol)); - } - }; - server.setEndianness(ByteOrder.LITTLE_ENDIAN); - serverList.add(server); - - server = new TrackerServer(new ConnectionlessBootstrap(), protocol) { - @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { - pipeline.addLast("objectDecoder", new CastelProtocolDecoder(protocol)); - } - }; - server.setEndianness(ByteOrder.LITTLE_ENDIAN); - serverList.add(server); - } - } - - private void initMxtServer(final String protocol) throws SQLException { - if (isProtocolEnabled(protocol)) { - TrackerServer server = new TrackerServer(new ServerBootstrap(), protocol) { - @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { - pipeline.addLast("frameDecoder", new MxtFrameDecoder()); - pipeline.addLast("objectDecoder", new MxtProtocolDecoder(protocol)); - } - }; - server.setEndianness(ByteOrder.LITTLE_ENDIAN); - serverList.add(server); + private void initProtocolServer(final Protocol protocol) throws SQLException { + if (isProtocolEnabled(protocol.getName())) { + protocol.addTrackerServersTo(serverList); } } diff --git a/src/org/traccar/TrackerServer.java b/src/org/traccar/TrackerServer.java index c65583584..6796f2064 100644 --- a/src/org/traccar/TrackerServer.java +++ b/src/org/traccar/TrackerServer.java @@ -94,7 +94,7 @@ public abstract class TrackerServer { /** * Set endianness */ - void setEndianness(ByteOrder byteOrder) { + public void setEndianness(ByteOrder byteOrder) { bootstrap.setOption("bufferFactory", new HeapChannelBufferFactory(byteOrder)); bootstrap.setOption("child.bufferFactory", new HeapChannelBufferFactory(byteOrder)); } diff --git a/src/org/traccar/database/ActiveDevice.java b/src/org/traccar/database/ActiveDevice.java new file mode 100644 index 000000000..29f2b47d2 --- /dev/null +++ b/src/org/traccar/database/ActiveDevice.java @@ -0,0 +1,37 @@ +package org.traccar.database; + +import org.jboss.netty.channel.Channel; +import org.traccar.Protocol; +import org.traccar.http.commands.GpsCommand; + +import java.net.SocketAddress; + +public class ActiveDevice { + private String uniqueId; + private Protocol protocol; + private Channel channel; + private SocketAddress remoteAddress; + + public ActiveDevice(String uniqueId, Protocol protocol, Channel channel, SocketAddress remoteAddress) { + this.uniqueId = uniqueId; + this.protocol = protocol; + this.channel = channel; + this.remoteAddress = remoteAddress; + } + + public Channel getChannel() { + return channel; + } + + public String getUniqueId() { + return uniqueId; + } + + public void sendCommand(GpsCommand command) { + protocol.sendCommand(this, command); + } + + public void write(Object message) { + getChannel().write(message, remoteAddress); + } +} diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java index 496a5a1b6..62275af3c 100644 --- a/src/org/traccar/database/DataManager.java +++ b/src/org/traccar/database/DataManager.java @@ -17,6 +17,7 @@ package org.traccar.database; import com.mchange.v2.c3p0.ComboPooledDataSource; import java.io.File; +import java.net.SocketAddress; import java.net.URL; import java.net.URLClassLoader; import java.sql.Connection; @@ -32,7 +33,10 @@ import java.util.Map; import java.util.Properties; import javax.naming.InitialContext; import javax.sql.DataSource; + +import org.jboss.netty.channel.Channel; import org.traccar.Context; +import org.traccar.Protocol; import org.traccar.helper.DriverDelegate; import org.traccar.helper.Log; import org.traccar.http.AsyncServlet; @@ -52,6 +56,7 @@ public class DataManager { private DataSource dataSource; private final Map<String, Device> devices = new HashMap<String, Device>(); + private Map<String, ActiveDevice> activeDevices = new HashMap<String, ActiveDevice>(); private long devicesLastUpdate; private long devicesRefreshDelay; @@ -74,6 +79,14 @@ public class DataManager { return dataSource; } + public void setActiveDevice(String uniqueId, Protocol protocol, Channel channel, SocketAddress remoteAddress) { + this.activeDevices.put(uniqueId, new ActiveDevice(uniqueId, protocol, channel, remoteAddress)); + } + + public ActiveDevice getActiveDevice(String uniqueId) { + return this.activeDevices.get(uniqueId); + } + private void initDatabase(Properties properties) throws Exception { String jndiName = properties.getProperty("database.jndi"); diff --git a/src/org/traccar/http/CommandsServlet.java b/src/org/traccar/http/CommandsServlet.java new file mode 100644 index 000000000..3e3ab9086 --- /dev/null +++ b/src/org/traccar/http/CommandsServlet.java @@ -0,0 +1,58 @@ +package org.traccar.http; + +import org.traccar.Context; +import org.traccar.database.ActiveDevice; +import org.traccar.http.commands.CommandType; +import org.traccar.http.commands.GpsCommand; + +import javax.json.Json; +import javax.json.JsonObject; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class CommandsServlet extends BaseServlet { + + @Override + protected boolean handle(String command, HttpServletRequest req, HttpServletResponse resp) throws Exception { + if (command.equals("/send")) { + send(req, resp); + } + else if (command.equals("/raw")) { + sendRawCommand(req, resp); + } + else { + return false; + } + return true; + } + + private void send(HttpServletRequest req, HttpServletResponse resp) throws Exception { + GpsCommand command = JsonConverter.<GpsCommand>enumObjectFromJson(req.getReader(), new EnumFactory(CommandType.class, "type")); + + String uniqueId = command.getUniqueId(); + + ActiveDevice activeDevice = Context.getDataManager().getActiveDevice(uniqueId); + if(activeDevice == null) { + throw new RuntimeException("The device has not yet registered to the server"); + } + + activeDevice.sendCommand(command); + + sendResponse(resp.getWriter(), JsonConverter.objectToJson(new Object())); + } + + private void sendRawCommand(HttpServletRequest req, HttpServletResponse resp) throws Exception { + JsonObject json = Json.createReader(req.getReader()).readObject(); + String uniqueId = json.getString("uniqueId"); + + ActiveDevice activeDevice = Context.getDataManager().getActiveDevice(uniqueId); + if(activeDevice == null) { + throw new RuntimeException("The device has not yet registered to the server"); + } + + String command = json.getString("command"); + activeDevice.write(command); + + sendResponse(resp.getWriter(), JsonConverter.objectToJson(new Object())); + } +} diff --git a/src/org/traccar/http/EnumFactory.java b/src/org/traccar/http/EnumFactory.java new file mode 100644 index 000000000..6e9971f71 --- /dev/null +++ b/src/org/traccar/http/EnumFactory.java @@ -0,0 +1,20 @@ +package org.traccar.http; + +import org.traccar.model.Factory; + +import javax.json.JsonObject; + +public class EnumFactory<T extends Enum<T> & Factory> { + private Class<T> commandTypeClass; + private String jsonKey; + + public EnumFactory(Class<T> commandTypeClass, String type) { + this.commandTypeClass = commandTypeClass; + jsonKey = type; + } + + public <K> K create(JsonObject json) { + Factory factory = Enum.valueOf(commandTypeClass, json.getString(jsonKey)); + return (K) factory.create(); + } +} diff --git a/src/org/traccar/http/JsonConverter.java b/src/org/traccar/http/JsonConverter.java index f18470d9d..eb672da8d 100644 --- a/src/org/traccar/http/JsonConverter.java +++ b/src/org/traccar/http/JsonConverter.java @@ -35,7 +35,7 @@ import org.traccar.helper.IgnoreOnSerialization; import org.traccar.model.Factory; public class JsonConverter { - + private static final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); public static Date parseDate(String value) throws ParseException { @@ -45,19 +45,29 @@ public class JsonConverter { public static <T extends Factory> T objectFromJson(Reader reader, T prototype) throws ParseException { return objectFromJson(Json.createReader(reader).readObject(), prototype); } - - public static <T extends Factory> T objectFromJson(JsonObject json, T prototype) throws ParseException { + public static <T> T enumObjectFromJson(Reader reader, EnumFactory<? extends Enum<?>> factory) throws ParseException { + JsonObject json = Json.createReader(reader).readObject(); + T object = factory.<T>create(json); + populateObject(json, object); + return object; + } + + public static <T extends Factory> T objectFromJson(JsonObject json, T prototype) throws ParseException { T object = (T) prototype.create(); - - Method[] methods = prototype.getClass().getMethods(); - + populateObject(json, object); + return object; + } + + private static void populateObject(JsonObject json, Object object) throws ParseException { + Method[] methods = object.getClass().getMethods(); + for (final Method method : methods) { if (method.getName().startsWith("set") && method.getParameterTypes().length == 1) { final String name = Introspector.decapitalize(method.getName().substring(3)); Class<?> parameterType = method.getParameterTypes()[0]; - + if (json.containsKey(name)) try { if (parameterType.equals(boolean.class)) { method.invoke(object, json.getBoolean(name)); @@ -73,22 +83,28 @@ public class JsonConverter { method.invoke(object, json.getString(name)); } else if (parameterType.equals(Date.class)) { method.invoke(object, dateFormat.parse(json.getString(name))); + } else if (parameterType.isEnum()) { + method.invoke(object, Enum.valueOf((Class<? extends Enum>) parameterType, json.getString(name))); + } else { + Object nestedObject = parameterType.newInstance(); + populateObject(json.getJsonObject(name), nestedObject); + method.invoke(object, nestedObject); } } catch (IllegalAccessException error) { } catch (InvocationTargetException error) { + } catch (InstantiationException e) { } } } - - return object; + } - + public static <T> JsonObject objectToJson(T object) { - + JsonObjectBuilder json = Json.createObjectBuilder(); - + Method[] methods = object.getClass().getMethods(); - + for (Method method : methods) { if(method.isAnnotationPresent(IgnoreOnSerialization.class)) { continue; @@ -127,7 +143,7 @@ public class JsonConverter { public static JsonArray arrayToJson(Collection<?> array) { JsonArrayBuilder json = Json.createArrayBuilder(); - + for (Object object : array) { json.add(objectToJson(object)); } diff --git a/src/org/traccar/http/WebServer.java b/src/org/traccar/http/WebServer.java index 21e43b3d3..9030e992b 100644 --- a/src/org/traccar/http/WebServer.java +++ b/src/org/traccar/http/WebServer.java @@ -55,6 +55,7 @@ public class WebServer { servletHandler.addServlet(new ServletHolder(new UserServlet()), "/user/*"); servletHandler.addServlet(new ServletHolder(new DeviceServlet()), "/device/*"); servletHandler.addServlet(new ServletHolder(new PositionServlet()), "/position/*"); + servletHandler.addServlet(new ServletHolder(new CommandsServlet()), "/commands/*"); servletHandler.addServlet(new ServletHolder(new MainServlet()), "/*"); /*ResourceHandler mobileResourceHandler = new ResourceHandler(); diff --git a/src/org/traccar/http/commands/CommandType.java b/src/org/traccar/http/commands/CommandType.java new file mode 100644 index 000000000..12610dbcc --- /dev/null +++ b/src/org/traccar/http/commands/CommandType.java @@ -0,0 +1,28 @@ +package org.traccar.http.commands; + +import org.traccar.model.Factory; + +public enum CommandType implements Factory { + STOP_POSITIONING(NoParameterCommand.class), + FIX_POSITIONING(FixPositioningCommand.class), + STOP_ENGINE(NoParameterCommand.class), + RESUME_ENGINE(NoParameterCommand.class); + + + private Class<? extends GpsCommand> commandClass; + + CommandType(Class<? extends GpsCommand> commandClass) { + this.commandClass = commandClass; + } + + @Override + public Object create() { + try { + return commandClass.newInstance(); + } catch (InstantiationException e) { + throw new RuntimeException(e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } +} diff --git a/src/org/traccar/http/commands/Duration.java b/src/org/traccar/http/commands/Duration.java new file mode 100644 index 000000000..e50f0c23e --- /dev/null +++ b/src/org/traccar/http/commands/Duration.java @@ -0,0 +1,38 @@ +package org.traccar.http.commands; + +public class Duration { + + public enum TimeUnit { + SECOND("s"), MINUTE("m"), HOUR("h"); + + private final String commandFormat; + + TimeUnit(String commandFormat) { + this.commandFormat = commandFormat; + } + + public String getCommandFormat() { + return commandFormat; + } + } + + + private TimeUnit unit; + private int value; + + public TimeUnit getUnit() { + return unit; + } + + public void setUnit(TimeUnit unit) { + this.unit = unit; + } + + public int getValue() { + return value; + } + + public void setValue(int value) { + this.value = value; + } +} diff --git a/src/org/traccar/http/commands/FixPositioningCommand.java b/src/org/traccar/http/commands/FixPositioningCommand.java new file mode 100644 index 000000000..f3b25acbc --- /dev/null +++ b/src/org/traccar/http/commands/FixPositioningCommand.java @@ -0,0 +1,25 @@ +package org.traccar.http.commands; + +import java.util.HashMap; +import java.util.Map; + +public class FixPositioningCommand extends GpsCommand { + public static final String FREQUENCY = "frequency"; + + private Duration data; + + @Override + public Map<String, Object> getReplacements() { + Map<String, Object> replacements = new HashMap<String, Object>(); + replacements.put(FREQUENCY, data); + return replacements; + } + + public Duration getData() { + return data; + } + + public void setData(Duration data) { + this.data = data; + } +} diff --git a/src/org/traccar/http/commands/GpsCommand.java b/src/org/traccar/http/commands/GpsCommand.java new file mode 100644 index 000000000..604bf832f --- /dev/null +++ b/src/org/traccar/http/commands/GpsCommand.java @@ -0,0 +1,27 @@ +package org.traccar.http.commands; + +import java.util.Map; + +public abstract class GpsCommand { + public static final String UNIQUE_ID = "uniqueId"; + private String uniqueId; + private CommandType type; + + public String getUniqueId() { + return uniqueId; + } + + public void setUniqueId(String uniqueId) { + this.uniqueId = uniqueId; + } + + public CommandType getType() { + return type; + } + + public void setType(CommandType type) { + this.type = type; + } + + public abstract Map<String, Object> getReplacements(); +} diff --git a/src/org/traccar/http/commands/NoParameterCommand.java b/src/org/traccar/http/commands/NoParameterCommand.java new file mode 100644 index 000000000..fee3c8097 --- /dev/null +++ b/src/org/traccar/http/commands/NoParameterCommand.java @@ -0,0 +1,11 @@ +package org.traccar.http.commands; + +import java.util.HashMap; +import java.util.Map; + +public class NoParameterCommand extends GpsCommand { + @Override + public Map<String, Object> getReplacements() { + return new HashMap<String, Object>(); + } +} diff --git a/src/org/traccar/protocol/ApelProtocol.java b/src/org/traccar/protocol/ApelProtocol.java new file mode 100644 index 000000000..fd6174d31 --- /dev/null +++ b/src/org/traccar/protocol/ApelProtocol.java @@ -0,0 +1,38 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.nio.ByteOrder; +import java.util.List; +import java.util.Map; + +public class ApelProtocol extends BaseProtocol { + + public ApelProtocol() { + super("apel"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + TrackerServer server = new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 2, 2, 4, 0)); + pipeline.addLast("objectDecoder", new ApelProtocolDecoder(ApelProtocol.this)); + } + }; + server.setEndianness(ByteOrder.LITTLE_ENDIAN); + serverList.add(server); + } +} diff --git a/src/org/traccar/protocol/ApelProtocolDecoder.java b/src/org/traccar/protocol/ApelProtocolDecoder.java index 4b05f3004..85a4e771a 100644 --- a/src/org/traccar/protocol/ApelProtocolDecoder.java +++ b/src/org/traccar/protocol/ApelProtocolDecoder.java @@ -39,7 +39,7 @@ public class ApelProtocolDecoder extends BaseProtocolDecoder { private long lastIndex; private long newIndex; - public ApelProtocolDecoder(String protocol) { + public ApelProtocolDecoder(ApelProtocol protocol) { super(protocol); } @@ -120,7 +120,7 @@ public class ApelProtocolDecoder extends BaseProtocolDecoder { int length = buf.readUnsignedShort(); buf.skipBytes(length); length = buf.readUnsignedShort(); - identify(buf.readBytes(length).toString(Charset.defaultCharset())); + identify(buf.readBytes(length).toString(Charset.defaultCharset()), channel); } else if (type == MSG_TYPE_LAST_LOG_INDEX) { @@ -142,7 +142,7 @@ public class ApelProtocolDecoder extends BaseProtocolDecoder { for (int j = 0; j < recordCount; j++) { Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); position.setDeviceId(getDeviceId()); // Message index diff --git a/src/org/traccar/protocol/AplicomProtocol.java b/src/org/traccar/protocol/AplicomProtocol.java new file mode 100644 index 000000000..bd4cfbd9f --- /dev/null +++ b/src/org/traccar/protocol/AplicomProtocol.java @@ -0,0 +1,34 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class AplicomProtocol extends BaseProtocol { + + public AplicomProtocol() { + super("aplicom"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new AplicomFrameDecoder()); + pipeline.addLast("objectDecoder", new AplicomProtocolDecoder(AplicomProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/AplicomProtocolDecoder.java b/src/org/traccar/protocol/AplicomProtocolDecoder.java index 81f760654..045eb2adc 100644 --- a/src/org/traccar/protocol/AplicomProtocolDecoder.java +++ b/src/org/traccar/protocol/AplicomProtocolDecoder.java @@ -32,7 +32,7 @@ import org.traccar.model.Position; public class AplicomProtocolDecoder extends BaseProtocolDecoder { - public AplicomProtocolDecoder(String protocol) { + public AplicomProtocolDecoder(AplicomProtocol protocol) { super(protocol); } @@ -131,8 +131,8 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); - if (!identify(imei)) { + position.setProtocol(getProtocolName()); + if (!identify(imei, channel)) { return null; } diff --git a/src/org/traccar/protocol/Ardi01Protocol.java b/src/org/traccar/protocol/Ardi01Protocol.java new file mode 100644 index 000000000..a30560d4f --- /dev/null +++ b/src/org/traccar/protocol/Ardi01Protocol.java @@ -0,0 +1,37 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.frame.LineBasedFrameDecoder; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class Ardi01Protocol extends BaseProtocol { + + public Ardi01Protocol() { + super("ardi01"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024)); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("objectDecoder", new Ardi01ProtocolDecoder(Ardi01Protocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/Ardi01ProtocolDecoder.java b/src/org/traccar/protocol/Ardi01ProtocolDecoder.java index 3a254cf41..dcc342b97 100644 --- a/src/org/traccar/protocol/Ardi01ProtocolDecoder.java +++ b/src/org/traccar/protocol/Ardi01ProtocolDecoder.java @@ -29,7 +29,7 @@ import java.util.regex.Pattern; public class Ardi01ProtocolDecoder extends BaseProtocolDecoder { - public Ardi01ProtocolDecoder(String protocol) { + public Ardi01ProtocolDecoder(Ardi01Protocol protocol) { super(protocol); } @@ -62,11 +62,11 @@ public class Ardi01ProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); Integer index = 1; // Detect device - if (!identify(parser.group(index++))) { + if (!identify(parser.group(index++), channel)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/AtrackProtocol.java b/src/org/traccar/protocol/AtrackProtocol.java new file mode 100644 index 000000000..7940e4208 --- /dev/null +++ b/src/org/traccar/protocol/AtrackProtocol.java @@ -0,0 +1,41 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ConnectionlessBootstrap; +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class AtrackProtocol extends BaseProtocol { + + public AtrackProtocol() { + super("atrack"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new AtrackFrameDecoder()); + pipeline.addLast("objectDecoder", new AtrackProtocolDecoder(AtrackProtocol.this)); + } + }); + serverList.add(new TrackerServer(new ConnectionlessBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("objectDecoder", new AtrackProtocolDecoder(AtrackProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/AtrackProtocolDecoder.java b/src/org/traccar/protocol/AtrackProtocolDecoder.java index b0b7ef1fc..6a346f946 100644 --- a/src/org/traccar/protocol/AtrackProtocolDecoder.java +++ b/src/org/traccar/protocol/AtrackProtocolDecoder.java @@ -33,7 +33,7 @@ import org.traccar.model.Position; public class AtrackProtocolDecoder extends BaseProtocolDecoder { - public AtrackProtocolDecoder(String protocol) { + public AtrackProtocolDecoder(AtrackProtocol protocol) { super(protocol); } @@ -87,7 +87,7 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder { // Get device id long id = buf.readLong(); - if (!identify(String.valueOf(id))) { + if (!identify(String.valueOf(id), channel, remoteAddress)) { return null; } @@ -101,7 +101,7 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); position.setDeviceId(getDeviceId()); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); // Date and time position.setTime(new Date(buf.readUnsignedInt() * 1000)); // gps time diff --git a/src/org/traccar/protocol/AutoFon45Protocol.java b/src/org/traccar/protocol/AutoFon45Protocol.java new file mode 100644 index 000000000..0af206ea3 --- /dev/null +++ b/src/org/traccar/protocol/AutoFon45Protocol.java @@ -0,0 +1,34 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class AutoFon45Protocol extends BaseProtocol { + + public AutoFon45Protocol() { + super("autofon45"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new AutoFon45FrameDecoder()); + pipeline.addLast("objectDecoder", new AutoFon45ProtocolDecoder(AutoFon45Protocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/AutoFon45ProtocolDecoder.java b/src/org/traccar/protocol/AutoFon45ProtocolDecoder.java index 55b4ad9dc..4fbf05c94 100644 --- a/src/org/traccar/protocol/AutoFon45ProtocolDecoder.java +++ b/src/org/traccar/protocol/AutoFon45ProtocolDecoder.java @@ -36,7 +36,7 @@ public class AutoFon45ProtocolDecoder extends BaseProtocolDecoder { return (degrees + seconds) * ((raw & 0x0f) == 0 ? -1 : 1); } - public AutoFon45ProtocolDecoder(String protocol) { + public AutoFon45ProtocolDecoder(AutoFon45Protocol protocol) { super(protocol); } @@ -51,7 +51,7 @@ public class AutoFon45ProtocolDecoder extends BaseProtocolDecoder { buf.readBytes(bytes); String imei = ChannelBufferTools.readHexString(ChannelBuffers.wrappedBuffer(bytes, 1, 16), 16).substring(1); - if (!identify(imei)) { + if (!identify(imei, channel)) { return null; } @@ -67,7 +67,7 @@ public class AutoFon45ProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); position.setDeviceId(getDeviceId()); short status = buf.readUnsignedByte(); diff --git a/src/org/traccar/protocol/AutoFonProtocol.java b/src/org/traccar/protocol/AutoFonProtocol.java new file mode 100644 index 000000000..5dc3b583d --- /dev/null +++ b/src/org/traccar/protocol/AutoFonProtocol.java @@ -0,0 +1,34 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class AutoFonProtocol extends BaseProtocol { + + public AutoFonProtocol() { + super("autofon"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new AutoFonFrameDecoder()); + pipeline.addLast("objectDecoder", new AutoFonProtocolDecoder(AutoFonProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/AutoFonProtocolDecoder.java b/src/org/traccar/protocol/AutoFonProtocolDecoder.java index 04cd4da72..b23f7a562 100644 --- a/src/org/traccar/protocol/AutoFonProtocolDecoder.java +++ b/src/org/traccar/protocol/AutoFonProtocolDecoder.java @@ -28,7 +28,7 @@ import java.util.*; public class AutoFonProtocolDecoder extends BaseProtocolDecoder { - public AutoFonProtocolDecoder(String protocol) { + public AutoFonProtocolDecoder(AutoFonProtocol protocol) { super(protocol); } @@ -46,7 +46,7 @@ public class AutoFonProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); position.setDeviceId(getDeviceId()); if (!history) { @@ -121,7 +121,7 @@ public class AutoFonProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedByte(); // software version String imei = ChannelBufferTools.readHexString(buf, 16).substring(1); - if (!identify(imei)) { + if (!identify(imei, channel)) { return null; } diff --git a/src/org/traccar/protocol/Avl301Protocol.java b/src/org/traccar/protocol/Avl301Protocol.java new file mode 100644 index 000000000..a20919d99 --- /dev/null +++ b/src/org/traccar/protocol/Avl301Protocol.java @@ -0,0 +1,35 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class Avl301Protocol extends BaseProtocol { + + public Avl301Protocol() { + super("avl301"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(256, 2, 1, -3, 0)); + pipeline.addLast("objectDecoder", new Avl301ProtocolDecoder(Avl301Protocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/Avl301ProtocolDecoder.java b/src/org/traccar/protocol/Avl301ProtocolDecoder.java index 7a53c3d3f..c4ce150c2 100644 --- a/src/org/traccar/protocol/Avl301ProtocolDecoder.java +++ b/src/org/traccar/protocol/Avl301ProtocolDecoder.java @@ -28,7 +28,7 @@ import java.util.TimeZone; public class Avl301ProtocolDecoder extends BaseProtocolDecoder { - public Avl301ProtocolDecoder(String protocol) { + public Avl301ProtocolDecoder(Avl301Protocol protocol) { super(protocol); } @@ -72,7 +72,7 @@ public class Avl301ProtocolDecoder extends BaseProtocolDecoder { if (type == MSG_LOGIN) { - if (identify(readImei(buf))) { + if (identify(readImei(buf), channel)) { sendResponse(channel, type); } @@ -85,7 +85,7 @@ public class Avl301ProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); position.setDeviceId(getDeviceId()); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); // Date and time(6) Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); diff --git a/src/org/traccar/protocol/BceProtocol.java b/src/org/traccar/protocol/BceProtocol.java new file mode 100644 index 000000000..6bd1e70e3 --- /dev/null +++ b/src/org/traccar/protocol/BceProtocol.java @@ -0,0 +1,37 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.nio.ByteOrder; +import java.util.List; +import java.util.Map; + +public class BceProtocol extends BaseProtocol { + + public BceProtocol() { + super("bce"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + TrackerServer server = new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new BceFrameDecoder()); + pipeline.addLast("objectDecoder", new BceProtocolDecoder(BceProtocol.this)); + } + }; + server.setEndianness(ByteOrder.LITTLE_ENDIAN); + serverList.add(server); + } +} diff --git a/src/org/traccar/protocol/BceProtocolDecoder.java b/src/org/traccar/protocol/BceProtocolDecoder.java index 189cad754..763f35d0c 100644 --- a/src/org/traccar/protocol/BceProtocolDecoder.java +++ b/src/org/traccar/protocol/BceProtocolDecoder.java @@ -30,7 +30,7 @@ import org.traccar.model.Position; public class BceProtocolDecoder extends BaseProtocolDecoder { - public BceProtocolDecoder(String protocol) { + public BceProtocolDecoder(BceProtocol protocol) { super(protocol); } @@ -50,7 +50,7 @@ public class BceProtocolDecoder extends BaseProtocolDecoder { ChannelBuffer buf = (ChannelBuffer) msg; String imei = String.format("%015d", buf.readLong()); - if (!identify(imei)) { + if (!identify(imei, channel)) { return null; } @@ -65,7 +65,7 @@ public class BceProtocolDecoder extends BaseProtocolDecoder { while (buf.readerIndex() < dataEnd) { Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); position.setDeviceId(getDeviceId()); int structEnd = buf.readUnsignedByte() + buf.readerIndex(); diff --git a/src/org/traccar/protocol/BoxProtocol.java b/src/org/traccar/protocol/BoxProtocol.java new file mode 100644 index 000000000..803c8c9c2 --- /dev/null +++ b/src/org/traccar/protocol/BoxProtocol.java @@ -0,0 +1,37 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.traccar.BaseProtocol; +import org.traccar.CharacterDelimiterFrameDecoder; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class BoxProtocol extends BaseProtocol { + + public BoxProtocol() { + super("box"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '\r')); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("objectDecoder", new BoxProtocolDecoder(BoxProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/BoxProtocolDecoder.java b/src/org/traccar/protocol/BoxProtocolDecoder.java index b7e30733c..77e546cda 100644 --- a/src/org/traccar/protocol/BoxProtocolDecoder.java +++ b/src/org/traccar/protocol/BoxProtocolDecoder.java @@ -29,7 +29,7 @@ import org.traccar.model.Position; public class BoxProtocolDecoder extends BaseProtocolDecoder { - public BoxProtocolDecoder(String protocol) { + public BoxProtocolDecoder(BoxProtocol protocol) { super(protocol); } @@ -58,7 +58,7 @@ public class BoxProtocolDecoder extends BaseProtocolDecoder { int index = sentence.indexOf(',', 2) + 1; String id = sentence.substring(index, sentence.indexOf(',', index)); - identify(id); + identify(id, channel); } else if (sentence.startsWith("L,")) { @@ -72,7 +72,7 @@ public class BoxProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); position.setDeviceId(getDeviceId()); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); Integer index = 1; diff --git a/src/org/traccar/protocol/CalAmpProtocol.java b/src/org/traccar/protocol/CalAmpProtocol.java new file mode 100644 index 000000000..a60812324 --- /dev/null +++ b/src/org/traccar/protocol/CalAmpProtocol.java @@ -0,0 +1,33 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ConnectionlessBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class CalAmpProtocol extends BaseProtocol { + + public CalAmpProtocol() { + super("calamp"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ConnectionlessBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("objectDecoder", new CalAmpProtocolDecoder(CalAmpProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/CalAmpProtocolDecoder.java b/src/org/traccar/protocol/CalAmpProtocolDecoder.java index f6b06ebe7..99d8651de 100644 --- a/src/org/traccar/protocol/CalAmpProtocolDecoder.java +++ b/src/org/traccar/protocol/CalAmpProtocolDecoder.java @@ -32,7 +32,7 @@ import org.traccar.model.Position; public class CalAmpProtocolDecoder extends BaseProtocolDecoder { - public CalAmpProtocolDecoder(String protocol) { + public CalAmpProtocolDecoder(CalAmpProtocol protocol) { super(protocol); } @@ -109,7 +109,7 @@ public class CalAmpProtocolDecoder extends BaseProtocolDecoder { } } - identify(String.valueOf(id)); + identify(String.valueOf(id), channel, remoteAddress); } // Identifier type @@ -160,7 +160,7 @@ public class CalAmpProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); position.setDeviceId(getDeviceId()); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); // Location data position.setTime(new Date(buf.readUnsignedInt() * 1000)); diff --git a/src/org/traccar/protocol/CarTrackProtocol.java b/src/org/traccar/protocol/CarTrackProtocol.java new file mode 100644 index 000000000..bab6562b6 --- /dev/null +++ b/src/org/traccar/protocol/CarTrackProtocol.java @@ -0,0 +1,37 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.traccar.BaseProtocol; +import org.traccar.CharacterDelimiterFrameDecoder; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class CarTrackProtocol extends BaseProtocol { + + public CarTrackProtocol() { + super("cartrack"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, "##")); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("objectDecoder", new CarTrackProtocolDecoder(CarTrackProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/CarTrackProtocolDecoder.java b/src/org/traccar/protocol/CarTrackProtocolDecoder.java index 223023a31..fea4f6a5e 100644 --- a/src/org/traccar/protocol/CarTrackProtocolDecoder.java +++ b/src/org/traccar/protocol/CarTrackProtocolDecoder.java @@ -30,7 +30,7 @@ import org.traccar.model.Position; public class CarTrackProtocolDecoder extends BaseProtocolDecoder { - public CarTrackProtocolDecoder(String protocol) { + public CarTrackProtocolDecoder(CarTrackProtocol protocol) { super(protocol); } @@ -70,11 +70,11 @@ public class CarTrackProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); Integer index = 1; // Get device by unique identifier - if (!identify(parser.group(index++))) { + if (!identify(parser.group(index++), channel)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/CarscopProtocol.java b/src/org/traccar/protocol/CarscopProtocol.java new file mode 100644 index 000000000..9f4abb11c --- /dev/null +++ b/src/org/traccar/protocol/CarscopProtocol.java @@ -0,0 +1,39 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.jboss.netty.handler.codec.string.StringEncoder; +import org.traccar.BaseProtocol; +import org.traccar.CharacterDelimiterFrameDecoder; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class CarscopProtocol extends BaseProtocol { + + public CarscopProtocol() { + super("carscop"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @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(CarscopProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/CarscopProtocolDecoder.java b/src/org/traccar/protocol/CarscopProtocolDecoder.java index 5f7ba6374..d9c18d0b5 100644 --- a/src/org/traccar/protocol/CarscopProtocolDecoder.java +++ b/src/org/traccar/protocol/CarscopProtocolDecoder.java @@ -29,7 +29,7 @@ import org.traccar.model.Position; public class CarscopProtocolDecoder extends BaseProtocolDecoder { - public CarscopProtocolDecoder(String protocol) { + public CarscopProtocolDecoder(CarscopProtocol protocol) { super(protocol); } @@ -58,7 +58,7 @@ public class CarscopProtocolDecoder extends BaseProtocolDecoder { int index = sentence.indexOf("UB05"); if (index != -1) { String imei = sentence.substring(index + 4, index + 4 + 15); - identify(imei); + identify(imei, channel); } if (!hasDeviceId()) { return null; @@ -73,7 +73,7 @@ public class CarscopProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); position.setDeviceId(getDeviceId()); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); index = 1; // Time diff --git a/src/org/traccar/protocol/CastelProtocol.java b/src/org/traccar/protocol/CastelProtocol.java new file mode 100644 index 000000000..bfcf0cb1b --- /dev/null +++ b/src/org/traccar/protocol/CastelProtocol.java @@ -0,0 +1,48 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ConnectionlessBootstrap; +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.nio.ByteOrder; +import java.util.List; +import java.util.Map; + +public class CastelProtocol extends BaseProtocol { + + public CastelProtocol() { + super("castel"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + TrackerServer server = new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 2, 2, -4, 0)); + pipeline.addLast("objectDecoder", new CastelProtocolDecoder(CastelProtocol.this)); + } + }; + server.setEndianness(ByteOrder.LITTLE_ENDIAN); + serverList.add(server); + + server = new TrackerServer(new ConnectionlessBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("objectDecoder", new CastelProtocolDecoder(CastelProtocol.this)); + } + }; + server.setEndianness(ByteOrder.LITTLE_ENDIAN); + serverList.add(server); + } +} diff --git a/src/org/traccar/protocol/CastelProtocolDecoder.java b/src/org/traccar/protocol/CastelProtocolDecoder.java index e82f837a7..8c2efb114 100644 --- a/src/org/traccar/protocol/CastelProtocolDecoder.java +++ b/src/org/traccar/protocol/CastelProtocolDecoder.java @@ -33,7 +33,7 @@ import org.traccar.model.Position; public class CastelProtocolDecoder extends BaseProtocolDecoder { - public CastelProtocolDecoder(String protocol) { + public CastelProtocolDecoder(CastelProtocol protocol) { super(protocol); } @@ -73,9 +73,9 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { } else if (type == MSG_LOGIN || type == MSG_GPS) { Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); - if (!identify(id.toString(Charset.defaultCharset()).trim())) { + if (!identify(id.toString(Charset.defaultCharset()).trim(), channel, remoteAddress)) { return null; } else if (type == MSG_LOGIN) { diff --git a/src/org/traccar/protocol/CellocatorProtocol.java b/src/org/traccar/protocol/CellocatorProtocol.java new file mode 100644 index 000000000..eedeadebc --- /dev/null +++ b/src/org/traccar/protocol/CellocatorProtocol.java @@ -0,0 +1,37 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.nio.ByteOrder; +import java.util.List; +import java.util.Map; + +public class CellocatorProtocol extends BaseProtocol { + + public CellocatorProtocol() { + super("cellocator"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + TrackerServer server = new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new CellocatorFrameDecoder()); + pipeline.addLast("objectDecoder", new CellocatorProtocolDecoder(CellocatorProtocol.this)); + } + }; + server.setEndianness(ByteOrder.LITTLE_ENDIAN); + serverList.add(server); + } +} diff --git a/src/org/traccar/protocol/CellocatorProtocolDecoder.java b/src/org/traccar/protocol/CellocatorProtocolDecoder.java index adb01b234..6c3343224 100644 --- a/src/org/traccar/protocol/CellocatorProtocolDecoder.java +++ b/src/org/traccar/protocol/CellocatorProtocolDecoder.java @@ -31,7 +31,7 @@ import org.traccar.model.Position; public class CellocatorProtocolDecoder extends BaseProtocolDecoder { - public CellocatorProtocolDecoder(String protocol) { + public CellocatorProtocolDecoder(CellocatorProtocol protocol) { super(protocol); } @@ -104,10 +104,10 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder { // Parse location if (type == MSG_CLIENT_STATUS) { Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); // Device identifier - if (!identify(String.valueOf(deviceUniqueId))) { + if (!identify(String.valueOf(deviceUniqueId), channel)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/EasyTrackProtocol.java b/src/org/traccar/protocol/EasyTrackProtocol.java new file mode 100644 index 000000000..d6c422943 --- /dev/null +++ b/src/org/traccar/protocol/EasyTrackProtocol.java @@ -0,0 +1,37 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.traccar.BaseProtocol; +import org.traccar.CharacterDelimiterFrameDecoder; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class EasyTrackProtocol extends BaseProtocol { + + public EasyTrackProtocol() { + super("easytrack"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '#')); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("objectDecoder", new EasyTrackProtocolDecoder(EasyTrackProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/EasyTrackProtocolDecoder.java b/src/org/traccar/protocol/EasyTrackProtocolDecoder.java index a3f75973e..0a08d6394 100644 --- a/src/org/traccar/protocol/EasyTrackProtocolDecoder.java +++ b/src/org/traccar/protocol/EasyTrackProtocolDecoder.java @@ -29,7 +29,7 @@ import org.traccar.model.Position; public class EasyTrackProtocolDecoder extends BaseProtocolDecoder { - public EasyTrackProtocolDecoder(String protocol) { + public EasyTrackProtocolDecoder(EasyTrackProtocol protocol) { super(protocol); } @@ -73,12 +73,12 @@ public class EasyTrackProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); Integer index = 1; // Get device by IMEI - if (!identify(parser.group(index++))) { + if (!identify(parser.group(index++), channel)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/EelinkProtocol.java b/src/org/traccar/protocol/EelinkProtocol.java new file mode 100644 index 000000000..9975133a8 --- /dev/null +++ b/src/org/traccar/protocol/EelinkProtocol.java @@ -0,0 +1,35 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class EelinkProtocol extends BaseProtocol { + + public EelinkProtocol() { + super("eelink"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 3, 2)); + pipeline.addLast("objectDecoder", new EelinkProtocolDecoder(EelinkProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/EelinkProtocolDecoder.java b/src/org/traccar/protocol/EelinkProtocolDecoder.java index 6628b9c37..3cdf3977e 100644 --- a/src/org/traccar/protocol/EelinkProtocolDecoder.java +++ b/src/org/traccar/protocol/EelinkProtocolDecoder.java @@ -30,7 +30,7 @@ import org.traccar.model.Position; public class EelinkProtocolDecoder extends BaseProtocolDecoder { - public EelinkProtocolDecoder(String protocol) { + public EelinkProtocolDecoder(EelinkProtocol protocol) { super(protocol); } @@ -84,7 +84,7 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder { } if (type == MSG_LOGIN) { - identify(ChannelBufferTools.readHexString(buf, 16).substring(1)); + identify(ChannelBufferTools.readHexString(buf, 16).substring(1), channel); } else if (hasDeviceId() && @@ -97,7 +97,7 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder { Position position = new Position(); position.setDeviceId(getDeviceId()); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); position.set(Event.KEY_INDEX, index); // Location diff --git a/src/org/traccar/protocol/EnforaProtocol.java b/src/org/traccar/protocol/EnforaProtocol.java new file mode 100644 index 000000000..671081ef3 --- /dev/null +++ b/src/org/traccar/protocol/EnforaProtocol.java @@ -0,0 +1,35 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class EnforaProtocol extends BaseProtocol { + + public EnforaProtocol() { + super("enfora"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 0, 2, -2, 2)); + pipeline.addLast("objectDecoder", new EnforaProtocolDecoder(EnforaProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/EnforaProtocolDecoder.java b/src/org/traccar/protocol/EnforaProtocolDecoder.java index 1185c28ad..13148641a 100644 --- a/src/org/traccar/protocol/EnforaProtocolDecoder.java +++ b/src/org/traccar/protocol/EnforaProtocolDecoder.java @@ -28,12 +28,11 @@ import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.BaseProtocolDecoder; import org.traccar.helper.ChannelBufferTools; import org.traccar.helper.Log; -import org.traccar.model.Event; import org.traccar.model.Position; public class EnforaProtocolDecoder extends BaseProtocolDecoder { - public EnforaProtocolDecoder(String protocol) { + public EnforaProtocolDecoder(EnforaProtocol protocol) { super(protocol); } @@ -95,11 +94,11 @@ public class EnforaProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); Integer index = 1; // Get device by IMEI - if (!identify(imei)) { + if (!identify(imei, channel)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/Ev603Protocol.java b/src/org/traccar/protocol/Ev603Protocol.java new file mode 100644 index 000000000..d67e6f15b --- /dev/null +++ b/src/org/traccar/protocol/Ev603Protocol.java @@ -0,0 +1,37 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.traccar.BaseProtocol; +import org.traccar.CharacterDelimiterFrameDecoder; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class Ev603Protocol extends BaseProtocol { + + public Ev603Protocol() { + super("ev603"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, ';')); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("objectDecoder", new Ev603ProtocolDecoder(Ev603Protocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/Ev603ProtocolDecoder.java b/src/org/traccar/protocol/Ev603ProtocolDecoder.java index 5024ddcd1..36a08f394 100644 --- a/src/org/traccar/protocol/Ev603ProtocolDecoder.java +++ b/src/org/traccar/protocol/Ev603ProtocolDecoder.java @@ -25,12 +25,11 @@ import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext;
import org.traccar.BaseProtocolDecoder;
-import org.traccar.model.Event;
import org.traccar.model.Position;
public class Ev603ProtocolDecoder extends BaseProtocolDecoder{
- public Ev603ProtocolDecoder(String protocol) {
+ public Ev603ProtocolDecoder(Ev603Protocol protocol) {
super(protocol);
}
@@ -53,7 +52,7 @@ public class Ev603ProtocolDecoder extends BaseProtocolDecoder{ // Detect device ID
if (sentence.startsWith("!1,")) {
- identify(sentence.substring(3));
+ identify(sentence.substring(3), channel);
}
else if (sentence.startsWith("!A,")) {
@@ -66,7 +65,7 @@ public class Ev603ProtocolDecoder extends BaseProtocolDecoder{ // Create new position
Position position = new Position();
position.setDeviceId(getDeviceId());
- position.setProtocol(getProtocol());
+ position.setProtocol(getProtocolName());
Integer index = 1;
// Date
diff --git a/src/org/traccar/protocol/FreedomProtocol.java b/src/org/traccar/protocol/FreedomProtocol.java new file mode 100644 index 000000000..8e0d20ee9 --- /dev/null +++ b/src/org/traccar/protocol/FreedomProtocol.java @@ -0,0 +1,37 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.frame.LineBasedFrameDecoder; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class FreedomProtocol extends BaseProtocol { + + public FreedomProtocol() { + super("freedom"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024)); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("objectDecoder", new FreedomProtocolDecoder(FreedomProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/FreedomProtocolDecoder.java b/src/org/traccar/protocol/FreedomProtocolDecoder.java index e4cfe99af..d6e641bb1 100644 --- a/src/org/traccar/protocol/FreedomProtocolDecoder.java +++ b/src/org/traccar/protocol/FreedomProtocolDecoder.java @@ -24,12 +24,11 @@ import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.BaseProtocolDecoder; -import org.traccar.model.Event; import org.traccar.model.Position; public class FreedomProtocolDecoder extends BaseProtocolDecoder { - public FreedomProtocolDecoder(String protocol) { + public FreedomProtocolDecoder(FreedomProtocol protocol) { super(protocol); } @@ -56,11 +55,11 @@ public class FreedomProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); Integer index = 1; // Identification - if (!identify(parser.group(index++))) { + if (!identify(parser.group(index++), channel)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/GalileoProtocol.java b/src/org/traccar/protocol/GalileoProtocol.java new file mode 100644 index 000000000..71594e0e2 --- /dev/null +++ b/src/org/traccar/protocol/GalileoProtocol.java @@ -0,0 +1,37 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.nio.ByteOrder; +import java.util.List; +import java.util.Map; + +public class GalileoProtocol extends BaseProtocol { + + public GalileoProtocol() { + super("galileo"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + TrackerServer server = new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new GalileoFrameDecoder()); + pipeline.addLast("objectDecoder", new GalileoProtocolDecoder(GalileoProtocol.this)); + } + }; + server.setEndianness(ByteOrder.LITTLE_ENDIAN); + serverList.add(server); + } +} diff --git a/src/org/traccar/protocol/GalileoProtocolDecoder.java b/src/org/traccar/protocol/GalileoProtocolDecoder.java index c2c8864e9..acf95a552 100644 --- a/src/org/traccar/protocol/GalileoProtocolDecoder.java +++ b/src/org/traccar/protocol/GalileoProtocolDecoder.java @@ -31,7 +31,7 @@ import org.traccar.model.Position; public class GalileoProtocolDecoder extends BaseProtocolDecoder { - public GalileoProtocolDecoder(String protocol) { + public GalileoProtocolDecoder(GalileoProtocol protocol) { super(protocol); } @@ -91,7 +91,7 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { Set<Integer> tags = new HashSet<Integer>(); boolean hasLocation = false; Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); while (buf.readerIndex() < length) { @@ -112,7 +112,7 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { case TAG_IMEI: String imei = buf.toString(buf.readerIndex(), 15, Charset.defaultCharset()); buf.skipBytes(imei.length()); - identify(imei); + identify(imei, channel); break; case TAG_DATE: diff --git a/src/org/traccar/protocol/GatorProtocol.java b/src/org/traccar/protocol/GatorProtocol.java new file mode 100644 index 000000000..8518eaa28 --- /dev/null +++ b/src/org/traccar/protocol/GatorProtocol.java @@ -0,0 +1,33 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ConnectionlessBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class GatorProtocol extends BaseProtocol { + + public GatorProtocol() { + super("gator"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ConnectionlessBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("objectDecoder", new GatorProtocolDecoder(GatorProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/GatorProtocolDecoder.java b/src/org/traccar/protocol/GatorProtocolDecoder.java index bebba144d..6a3434c8a 100644 --- a/src/org/traccar/protocol/GatorProtocolDecoder.java +++ b/src/org/traccar/protocol/GatorProtocolDecoder.java @@ -30,7 +30,7 @@ import org.traccar.model.Position; public class GatorProtocolDecoder extends BaseProtocolDecoder { - public GatorProtocolDecoder(String protocol) { + public GatorProtocolDecoder(GatorProtocol protocol) { super(protocol); } @@ -70,10 +70,10 @@ public class GatorProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); // Identification - if (!identify(id)) { + if (!identify(id, channel)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/Gl100Protocol.java b/src/org/traccar/protocol/Gl100Protocol.java new file mode 100644 index 000000000..e240c6909 --- /dev/null +++ b/src/org/traccar/protocol/Gl100Protocol.java @@ -0,0 +1,39 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.jboss.netty.handler.codec.string.StringEncoder; +import org.traccar.BaseProtocol; +import org.traccar.CharacterDelimiterFrameDecoder; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class Gl100Protocol extends BaseProtocol { + + public Gl100Protocol() { + super("gl100"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @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(Gl100Protocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/Gl100ProtocolDecoder.java b/src/org/traccar/protocol/Gl100ProtocolDecoder.java index a4545583b..7746395a1 100644 --- a/src/org/traccar/protocol/Gl100ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gl100ProtocolDecoder.java @@ -24,12 +24,11 @@ import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.BaseProtocolDecoder; -import org.traccar.model.Event; import org.traccar.model.Position; public class Gl100ProtocolDecoder extends BaseProtocolDecoder { - public Gl100ProtocolDecoder(String protocol) { + public Gl100ProtocolDecoder(Gl100Protocol protocol) { super(protocol); } @@ -74,12 +73,12 @@ public class Gl100ProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); Integer index = 1; // Get device by IMEI - if (!identify(parser.group(index++))) { + if (!identify(parser.group(index++), channel)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/Gl200Protocol.java b/src/org/traccar/protocol/Gl200Protocol.java new file mode 100644 index 000000000..363a1b716 --- /dev/null +++ b/src/org/traccar/protocol/Gl200Protocol.java @@ -0,0 +1,50 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ConnectionlessBootstrap; +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.jboss.netty.handler.codec.string.StringEncoder; +import org.traccar.BaseProtocol; +import org.traccar.CharacterDelimiterFrameDecoder; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class Gl200Protocol extends BaseProtocol { + + public Gl200Protocol() { + super("gl200"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @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(Gl200Protocol.this)); + } + }); + + serverList.add(new TrackerServer(new ConnectionlessBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("stringEncoder", new StringEncoder()); + pipeline.addLast("objectDecoder", new Gl200ProtocolDecoder(Gl200Protocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/Gl200ProtocolDecoder.java b/src/org/traccar/protocol/Gl200ProtocolDecoder.java index 59d09ae6a..a3fb8ee4b 100644 --- a/src/org/traccar/protocol/Gl200ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gl200ProtocolDecoder.java @@ -32,7 +32,7 @@ import org.traccar.model.Position; public class Gl200ProtocolDecoder extends BaseProtocolDecoder { - public Gl200ProtocolDecoder(String protocol) { + public Gl200ProtocolDecoder(Gl200Protocol protocol) { super(protocol); } @@ -89,12 +89,12 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); Integer index = 1; // Get device by IMEI - if (!identify(parser.group(index++))) { + if (!identify(parser.group(index++), channel, remoteAddress)) { return null; } position.setDeviceId(getDeviceId()); @@ -150,7 +150,7 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { } position.set(Event.KEY_BATTERY, parser.group(index++)); - if (Boolean.valueOf(Context.getProps().getProperty(getProtocol() + ".ack")) && channel != null) { + if (Boolean.valueOf(Context.getProps().getProperty(getProtocolName() + ".ack")) && channel != null) { channel.write("+SACK:" + parser.group(index++) + "$", remoteAddress); } diff --git a/src/org/traccar/protocol/GlobalSatProtocol.java b/src/org/traccar/protocol/GlobalSatProtocol.java new file mode 100644 index 000000000..3f9e7af04 --- /dev/null +++ b/src/org/traccar/protocol/GlobalSatProtocol.java @@ -0,0 +1,39 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.jboss.netty.handler.codec.string.StringEncoder; +import org.traccar.BaseProtocol; +import org.traccar.CharacterDelimiterFrameDecoder; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class GlobalSatProtocol extends BaseProtocol { + + public GlobalSatProtocol() { + super("globalsat"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @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(GlobalSatProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/GlobalSatProtocolDecoder.java b/src/org/traccar/protocol/GlobalSatProtocolDecoder.java index 17cfacbb5..e427def3a 100644 --- a/src/org/traccar/protocol/GlobalSatProtocolDecoder.java +++ b/src/org/traccar/protocol/GlobalSatProtocolDecoder.java @@ -36,7 +36,7 @@ public class GlobalSatProtocolDecoder extends BaseProtocolDecoder { private String format0 = "TSPRXAB27GHKLMnaicz*U!"; private String format1 = "SARY*U!"; - public GlobalSatProtocolDecoder(String protocol) { + public GlobalSatProtocolDecoder(GlobalSatProtocol protocol) { super(protocol); Properties properties = Context.getProps(); @@ -91,14 +91,14 @@ public class GlobalSatProtocolDecoder extends BaseProtocolDecoder { // Parse data Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); for (int formatIndex = 0, valueIndex = 1; formatIndex < format.length() && valueIndex < values.length; formatIndex++) { String value = values[valueIndex]; switch(format.charAt(formatIndex)) { case 'S': - if (!identify(value)) { + if (!identify(value, channel)) { return null; } position.setDeviceId(getDeviceId()); @@ -208,11 +208,11 @@ public class GlobalSatProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); Integer index = 1; // Identification - if (!identify(parser.group(index++))) { + if (!identify(parser.group(index++), channel)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/GoSafeProtocol.java b/src/org/traccar/protocol/GoSafeProtocol.java new file mode 100644 index 000000000..5d0e67c26 --- /dev/null +++ b/src/org/traccar/protocol/GoSafeProtocol.java @@ -0,0 +1,37 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.traccar.BaseProtocol; +import org.traccar.CharacterDelimiterFrameDecoder; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class GoSafeProtocol extends BaseProtocol { + + public GoSafeProtocol() { + super("gosafe"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '#')); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("objectDecoder", new GoSafeProtocolDecoder(GoSafeProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/GoSafeProtocolDecoder.java b/src/org/traccar/protocol/GoSafeProtocolDecoder.java index a768ac589..0a24e7029 100644 --- a/src/org/traccar/protocol/GoSafeProtocolDecoder.java +++ b/src/org/traccar/protocol/GoSafeProtocolDecoder.java @@ -30,7 +30,7 @@ import org.traccar.model.Position; public class GoSafeProtocolDecoder extends BaseProtocolDecoder { - public GoSafeProtocolDecoder(String protocol) { + public GoSafeProtocolDecoder(GoSafeProtocol protocol) { super(protocol); } @@ -65,12 +65,12 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); Integer index = 1; // Get device by IMEI - if (!identify(parser.group(index++))) { + if (!identify(parser.group(index++), channel, remoteAddress)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/GotopProtocol.java b/src/org/traccar/protocol/GotopProtocol.java new file mode 100644 index 000000000..ce7a18bae --- /dev/null +++ b/src/org/traccar/protocol/GotopProtocol.java @@ -0,0 +1,37 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.traccar.BaseProtocol; +import org.traccar.CharacterDelimiterFrameDecoder; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class GotopProtocol extends BaseProtocol { + + public GotopProtocol() { + super("gotop"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '#')); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("objectDecoder", new GotopProtocolDecoder(GotopProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/GotopProtocolDecoder.java b/src/org/traccar/protocol/GotopProtocolDecoder.java index eed0b4703..81b17b29f 100644 --- a/src/org/traccar/protocol/GotopProtocolDecoder.java +++ b/src/org/traccar/protocol/GotopProtocolDecoder.java @@ -30,7 +30,7 @@ import org.traccar.model.Position; public class GotopProtocolDecoder extends BaseProtocolDecoder { - public GotopProtocolDecoder(String protocol) { + public GotopProtocolDecoder(GotopProtocol protocol) { super(protocol); } @@ -61,11 +61,11 @@ public class GotopProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); Integer index = 1; // Get device by IMEI - if (!identify(parser.group(index++))) { + if (!identify(parser.group(index++), channel)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/Gps103Protocol.java b/src/org/traccar/protocol/Gps103Protocol.java new file mode 100644 index 000000000..8b0322f4e --- /dev/null +++ b/src/org/traccar/protocol/Gps103Protocol.java @@ -0,0 +1,62 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ConnectionlessBootstrap; +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.jboss.netty.handler.codec.string.StringEncoder; +import org.traccar.BaseProtocol; +import org.traccar.CharacterDelimiterFrameDecoder; +import org.traccar.TrackerServer; +import org.traccar.http.commands.CommandType; +import org.traccar.http.commands.Duration; +import org.traccar.http.commands.FixPositioningCommand; +import org.traccar.http.commands.GpsCommand; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.protocol.commands.CommandValueConversion; +import org.traccar.protocol.commands.StringCommandTemplate; + +import java.util.List; +import java.util.Map; + +public class Gps103Protocol extends BaseProtocol { + + public Gps103Protocol() { + super("gps103"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + templates.put(CommandType.STOP_POSITIONING, new StringCommandTemplate("**,imei:[%s],A", GpsCommand.UNIQUE_ID)); + templates.put(CommandType.FIX_POSITIONING, new StringCommandTemplate("**,imei:[%s],C,[%s]", GpsCommand.UNIQUE_ID, FixPositioningCommand.FREQUENCY) + .addConverter(Duration.class, new CommandValueConversion<Duration>() { + @Override + public String convert(Duration value) { + return String.format("%02d%s", value.getValue(), value.getUnit().getCommandFormat()); + } + })); + templates.put(CommandType.RESUME_ENGINE, new StringCommandTemplate("**,imei:[%s],J", GpsCommand.UNIQUE_ID)); + templates.put(CommandType.STOP_ENGINE, new StringCommandTemplate("**,imei:[%s],K", GpsCommand.UNIQUE_ID)); + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @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(Gps103Protocol.this)); + } + }); + serverList.add(new TrackerServer(new ConnectionlessBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("stringEncoder", new StringEncoder()); + pipeline.addLast("objectDecoder", new Gps103ProtocolDecoder(Gps103Protocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/org/traccar/protocol/Gps103ProtocolDecoder.java index 60714fbcf..5dadd10e4 100644 --- a/src/org/traccar/protocol/Gps103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gps103ProtocolDecoder.java @@ -28,7 +28,7 @@ import org.traccar.model.Position; public class Gps103ProtocolDecoder extends BaseProtocolDecoder { - public Gps103ProtocolDecoder(String protocol) { + public Gps103ProtocolDecoder(Gps103Protocol protocol) { super(protocol); } @@ -90,13 +90,13 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); Integer index = 1; // Get device by IMEI String imei = parser.group(index++); - if (!identify(imei)) { + if (!identify(imei, channel, remoteAddress)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/GpsGateProtocol.java b/src/org/traccar/protocol/GpsGateProtocol.java new file mode 100644 index 000000000..00780de17 --- /dev/null +++ b/src/org/traccar/protocol/GpsGateProtocol.java @@ -0,0 +1,39 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.frame.LineBasedFrameDecoder; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.jboss.netty.handler.codec.string.StringEncoder; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class GpsGateProtocol extends BaseProtocol { + + public GpsGateProtocol() { + super("gpsgate"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @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(GpsGateProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/GpsGateProtocolDecoder.java b/src/org/traccar/protocol/GpsGateProtocolDecoder.java index dbc1ac5a9..011ec1219 100644 --- a/src/org/traccar/protocol/GpsGateProtocolDecoder.java +++ b/src/org/traccar/protocol/GpsGateProtocolDecoder.java @@ -25,12 +25,11 @@ import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.BaseProtocolDecoder; import org.traccar.helper.Crc; -import org.traccar.model.Event; import org.traccar.model.Position; public class GpsGateProtocolDecoder extends BaseProtocolDecoder { - public GpsGateProtocolDecoder(String protocol) { + public GpsGateProtocolDecoder(GpsGateProtocol protocol) { super(protocol); } @@ -68,7 +67,7 @@ public class GpsGateProtocolDecoder extends BaseProtocolDecoder { int endIndex = sentence.indexOf(',', beginIndex); if (endIndex != -1) { String imei = sentence.substring(beginIndex, endIndex); - if (identify(imei)) { + if (identify(imei, channel)) { if (channel != null) { send(channel, "$FRSES," + channel.getId()); } @@ -99,7 +98,7 @@ public class GpsGateProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); position.setDeviceId(getDeviceId()); Integer index = 1; diff --git a/src/org/traccar/protocol/Gt02Protocol.java b/src/org/traccar/protocol/Gt02Protocol.java new file mode 100644 index 000000000..51f78cb68 --- /dev/null +++ b/src/org/traccar/protocol/Gt02Protocol.java @@ -0,0 +1,35 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class Gt02Protocol extends BaseProtocol { + + public Gt02Protocol() { + super("gt02"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(256, 2, 1, 2, 0)); + pipeline.addLast("objectDecoder", new Gt02ProtocolDecoder(Gt02Protocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/Gt02ProtocolDecoder.java b/src/org/traccar/protocol/Gt02ProtocolDecoder.java index 3280be207..8d775a2bb 100644 --- a/src/org/traccar/protocol/Gt02ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gt02ProtocolDecoder.java @@ -29,7 +29,7 @@ import org.traccar.model.Position; public class Gt02ProtocolDecoder extends BaseProtocolDecoder { - public Gt02ProtocolDecoder(String protocol) { + public Gt02ProtocolDecoder(Gt02Protocol protocol) { super(protocol); } @@ -77,11 +77,11 @@ public class Gt02ProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); position.set(Event.KEY_INDEX, index); // Get device id - if (!identify(imei)) { + if (!identify(imei, channel)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/Gt06Protocol.java b/src/org/traccar/protocol/Gt06Protocol.java new file mode 100644 index 000000000..f3fc6a7b3 --- /dev/null +++ b/src/org/traccar/protocol/Gt06Protocol.java @@ -0,0 +1,79 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.buffer.ChannelBuffer; +import org.jboss.netty.buffer.ChannelBuffers; +import org.jboss.netty.channel.ChannelPipeline; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.database.ActiveDevice; +import org.traccar.helper.Crc; +import org.traccar.http.commands.CommandType; +import org.traccar.http.commands.NoParameterCommand; +import org.traccar.protocol.commands.CommandTemplate; + +import java.util.List; +import java.util.Map; + +public class Gt06Protocol extends BaseProtocol { + + public Gt06Protocol() { + super("gt06"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + templates.put(CommandType.STOP_ENGINE, new Gt06CommandTemplate("DYD#")); + templates.put(CommandType.RESUME_ENGINE, new Gt06CommandTemplate("HFYD#")); + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new Gt06FrameDecoder()); + pipeline.addLast("objectDecoder", new Gt06ProtocolDecoder(Gt06Protocol.this)); + } + }); + } + + class Gt06CommandTemplate implements CommandTemplate<NoParameterCommand> { + + private String commandContent; + + public Gt06CommandTemplate(String commandContent) { + this.commandContent = commandContent; + } + + @Override + public Object applyTo(ActiveDevice activeDevice, NoParameterCommand command) { + int serverFlagBit = 0x0; + int commandLength = serverFlagBit + commandContent.length(); + int packetLength = 0x80 /*Protocol Number */ + commandContent.length() /* Information Content */ + 2 /*Information Serial Number */+ 2 /*Error Check */; + + int informationSerialNumber = 1; + + + ChannelBuffer response = ChannelBuffers.directBuffer(10); + response.writeBytes(new byte[]{0x78, 0x78}); // Start Bit + response.writeByte(packetLength); // Packet Length + response.writeByte(0x80); // Protocol Number + + // Information Content + response.writeByte(commandLength); // Length of command + response.writeByte(serverFlagBit); // Server Flag Bit + response.writeBytes(commandContent.getBytes()); // Command Content + response.writeBytes(new byte[]{0x00, 0x02}); // Language + + response.writeShort(informationSerialNumber); // Information Serial Number + + int crc = Crc.crc16Ccitt(response.toByteBuffer(2, response.writerIndex())); + response.writeShort(crc); // Error Check + + response.writeBytes(new byte[] {0x0D, 0x0A}); // Stop Bit + + return response; + } + } +} diff --git a/src/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/org/traccar/protocol/Gt06ProtocolDecoder.java index 01ffe5490..f5a8dc307 100644 --- a/src/org/traccar/protocol/Gt06ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gt06ProtocolDecoder.java @@ -35,7 +35,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { private boolean forceTimeZone = false; private final TimeZone timeZone = TimeZone.getTimeZone("UTC"); - public Gt06ProtocolDecoder(String protocol) { + public Gt06ProtocolDecoder(Gt06Protocol protocol) { super(protocol); Properties properties = Context.getProps(); @@ -126,7 +126,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { } } - if (identify(imei)) { + if (identify(imei, channel)) { buf.skipBytes(buf.readableBytes() - 6); sendResponse(channel, type, buf.readUnsignedShort()); } @@ -144,7 +144,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); position.setDeviceId(getDeviceId()); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); // Date and time Calendar time = Calendar.getInstance(timeZone); diff --git a/src/org/traccar/protocol/H02Protocol.java b/src/org/traccar/protocol/H02Protocol.java new file mode 100644 index 000000000..91ddda772 --- /dev/null +++ b/src/org/traccar/protocol/H02Protocol.java @@ -0,0 +1,34 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class H02Protocol extends BaseProtocol { + + public H02Protocol() { + super("h02"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new H02FrameDecoder()); + pipeline.addLast("objectDecoder", new H02ProtocolDecoder(H02Protocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java index 30c0aaa60..95d80edb5 100644 --- a/src/org/traccar/protocol/H02ProtocolDecoder.java +++ b/src/org/traccar/protocol/H02ProtocolDecoder.java @@ -32,7 +32,7 @@ import org.traccar.model.Position; public class H02ProtocolDecoder extends BaseProtocolDecoder { - public H02ProtocolDecoder(String protocol) { + public H02ProtocolDecoder(H02Protocol protocol) { super(protocol); } @@ -55,16 +55,16 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { return result; } - private Position decodeBinary(ChannelBuffer buf) { + private Position decodeBinary(ChannelBuffer buf, Channel channel) { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); buf.readByte(); // marker // Identification - if (!identify(ChannelBufferTools.readHexString(buf, 10))) { + if (!identify(ChannelBufferTools.readHexString(buf, 10), channel)) { return null; } position.setDeviceId(getDeviceId()); @@ -117,7 +117,7 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { "(\\p{XDigit}{8})" + // Status ".*"); - private Position decodeText(String sentence) { + private Position decodeText(String sentence, Channel channel) { // Parse message Matcher parser = pattern.matcher(sentence); @@ -127,12 +127,12 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); Integer index = 1; // Get device by IMEI - if (!identify(parser.group(index++))) { + if (!identify(parser.group(index++), channel)) { return null; } position.setDeviceId(getDeviceId()); @@ -190,9 +190,9 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { // TODO X mode? if (marker.equals("*")) { - return decodeText(buf.toString(Charset.defaultCharset())); + return decodeText(buf.toString(Charset.defaultCharset()), channel); } else if (marker.equals("$")) { - return decodeBinary(buf); + return decodeBinary(buf, channel); } return null; diff --git a/src/org/traccar/protocol/HaicomProtocol.java b/src/org/traccar/protocol/HaicomProtocol.java new file mode 100644 index 000000000..79f7ac1ff --- /dev/null +++ b/src/org/traccar/protocol/HaicomProtocol.java @@ -0,0 +1,37 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.traccar.BaseProtocol; +import org.traccar.CharacterDelimiterFrameDecoder; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class HaicomProtocol extends BaseProtocol { + + public HaicomProtocol() { + super("haicom"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '*')); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("objectDecoder", new HaicomProtocolDecoder(HaicomProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/HaicomProtocolDecoder.java b/src/org/traccar/protocol/HaicomProtocolDecoder.java index 5955ac905..27fb05d34 100644 --- a/src/org/traccar/protocol/HaicomProtocolDecoder.java +++ b/src/org/traccar/protocol/HaicomProtocolDecoder.java @@ -29,7 +29,7 @@ import org.traccar.model.Position; public class HaicomProtocolDecoder extends BaseProtocolDecoder { - public HaicomProtocolDecoder(String protocol) { + public HaicomProtocolDecoder(HaicomProtocol protocol) { super(protocol); } @@ -67,12 +67,12 @@ public class HaicomProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); Integer index = 1; // Get device by IMEI - if (!identify(parser.group(index++))) { + if (!identify(parser.group(index++), channel)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/IntellitracProtocol.java b/src/org/traccar/protocol/IntellitracProtocol.java new file mode 100644 index 000000000..977635a67 --- /dev/null +++ b/src/org/traccar/protocol/IntellitracProtocol.java @@ -0,0 +1,38 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.jboss.netty.handler.codec.string.StringEncoder; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class IntellitracProtocol extends BaseProtocol { + + public IntellitracProtocol() { + super("intellitrac"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @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(IntellitracProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/IntellitracProtocolDecoder.java b/src/org/traccar/protocol/IntellitracProtocolDecoder.java index 39d851cf9..9b99fc408 100644 --- a/src/org/traccar/protocol/IntellitracProtocolDecoder.java +++ b/src/org/traccar/protocol/IntellitracProtocolDecoder.java @@ -29,7 +29,7 @@ import org.traccar.model.Position; public class IntellitracProtocolDecoder extends BaseProtocolDecoder { - public IntellitracProtocolDecoder(String protocol) { + public IntellitracProtocolDecoder(IntellitracProtocol protocol) { super(protocol); } @@ -76,11 +76,11 @@ public class IntellitracProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); Integer index = 1; // Detect device - if (!identify(parser.group(index++))) { + if (!identify(parser.group(index++), channel)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/Jt600Protocol.java b/src/org/traccar/protocol/Jt600Protocol.java new file mode 100644 index 000000000..c650aed7e --- /dev/null +++ b/src/org/traccar/protocol/Jt600Protocol.java @@ -0,0 +1,34 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class Jt600Protocol extends BaseProtocol { + + public Jt600Protocol() { + super("jt600"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new Jt600FrameDecoder()); + pipeline.addLast("objectDecoder", new Jt600ProtocolDecoder(Jt600Protocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/Jt600ProtocolDecoder.java b/src/org/traccar/protocol/Jt600ProtocolDecoder.java index 5c3dcef46..eaf9ff9c6 100644 --- a/src/org/traccar/protocol/Jt600ProtocolDecoder.java +++ b/src/org/traccar/protocol/Jt600ProtocolDecoder.java @@ -32,20 +32,20 @@ import org.traccar.model.Position; public class Jt600ProtocolDecoder extends BaseProtocolDecoder { - public Jt600ProtocolDecoder(String protocol) { + public Jt600ProtocolDecoder(Jt600Protocol protocol) { super(protocol); } - private Position decodeNormalMessage(ChannelBuffer buf) throws Exception { + private Position decodeNormalMessage(ChannelBuffer buf, Channel channel) throws Exception { Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); buf.readByte(); // header // Get device by identifier String id = Long.valueOf(ChannelBufferTools.readHexString(buf, 10)).toString(); - if (!identify(id)) { + if (!identify(id, channel)) { return null; } position.setDeviceId(getDeviceId()); @@ -140,7 +140,7 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { "(\\d+)," + // Alert Type ".*\\)"); - private Position decodeAlertMessage(ChannelBuffer buf) throws Exception { + private Position decodeAlertMessage(ChannelBuffer buf, Channel channel) throws Exception { String message = buf.toString(Charset.defaultCharset()); @@ -152,12 +152,12 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); position.set(Event.KEY_ALARM, true); Integer index = 1; // Get device by identifier - if (!identify(parser.group(index++))) { + if (!identify(parser.group(index++), channel)) { return null; } position.setDeviceId(getDeviceId()); @@ -209,9 +209,9 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { // Check message type if (first == '$') { - return decodeNormalMessage(buf); + return decodeNormalMessage(buf, channel); } else if (first == '(') { - return decodeAlertMessage(buf); + return decodeAlertMessage(buf, channel); } return null; diff --git a/src/org/traccar/protocol/KhdProtocol.java b/src/org/traccar/protocol/KhdProtocol.java new file mode 100644 index 000000000..313f10a7d --- /dev/null +++ b/src/org/traccar/protocol/KhdProtocol.java @@ -0,0 +1,35 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class KhdProtocol extends BaseProtocol { + + public KhdProtocol() { + super("khd"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(256, 3, 2)); + pipeline.addLast("objectDecoder", new KhdProtocolDecoder(KhdProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/KhdProtocolDecoder.java b/src/org/traccar/protocol/KhdProtocolDecoder.java index e9d43798c..335e84697 100644 --- a/src/org/traccar/protocol/KhdProtocolDecoder.java +++ b/src/org/traccar/protocol/KhdProtocolDecoder.java @@ -32,7 +32,7 @@ import org.traccar.model.Position; public class KhdProtocolDecoder extends BaseProtocolDecoder { - public KhdProtocolDecoder(String protocol) { + public KhdProtocolDecoder(KhdProtocol protocol) { super(protocol); } @@ -74,10 +74,10 @@ public class KhdProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); // Device identification - if (!identify(readSerialNumber(buf))) { + if (!identify(readSerialNumber(buf), channel)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/LaipacProtocol.java b/src/org/traccar/protocol/LaipacProtocol.java new file mode 100644 index 000000000..96b84a6f4 --- /dev/null +++ b/src/org/traccar/protocol/LaipacProtocol.java @@ -0,0 +1,39 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.frame.LineBasedFrameDecoder; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.jboss.netty.handler.codec.string.StringEncoder; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class LaipacProtocol extends BaseProtocol { + + public LaipacProtocol() { + super("laipac"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @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(LaipacProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/LaipacProtocolDecoder.java b/src/org/traccar/protocol/LaipacProtocolDecoder.java index af43df511..e5838387a 100644 --- a/src/org/traccar/protocol/LaipacProtocolDecoder.java +++ b/src/org/traccar/protocol/LaipacProtocolDecoder.java @@ -25,12 +25,11 @@ import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.BaseProtocolDecoder; import org.traccar.helper.Crc; -import org.traccar.model.Event; import org.traccar.model.Position; public class LaipacProtocolDecoder extends BaseProtocolDecoder { - public LaipacProtocolDecoder(String protocol) { + public LaipacProtocolDecoder(LaipacProtocol protocol) { super(protocol); } @@ -71,11 +70,11 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); Integer index = 1; // Identification - if (!identify(parser.group(index++))) { + if (!identify(parser.group(index++), channel)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/M2mProtocol.java b/src/org/traccar/protocol/M2mProtocol.java new file mode 100644 index 000000000..53948b93a --- /dev/null +++ b/src/org/traccar/protocol/M2mProtocol.java @@ -0,0 +1,35 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.frame.FixedLengthFrameDecoder; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class M2mProtocol extends BaseProtocol { + + public M2mProtocol() { + super("m2m"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new FixedLengthFrameDecoder(23)); + pipeline.addLast("objectDecoder", new M2mProtocolDecoder(M2mProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/M2mProtocolDecoder.java b/src/org/traccar/protocol/M2mProtocolDecoder.java index c335a2d41..10df475b3 100644 --- a/src/org/traccar/protocol/M2mProtocolDecoder.java +++ b/src/org/traccar/protocol/M2mProtocolDecoder.java @@ -28,7 +28,7 @@ import org.traccar.model.Position; public class M2mProtocolDecoder extends BaseProtocolDecoder { - public M2mProtocolDecoder(String protocol) { + public M2mProtocolDecoder(M2mProtocol protocol) { super(protocol); } @@ -64,13 +64,13 @@ public class M2mProtocolDecoder extends BaseProtocolDecoder { } // Identification - identify(imei.toString()); + identify(imei.toString(), channel); } else if (hasDeviceId()) { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); position.setDeviceId(getDeviceId()); // Date and time diff --git a/src/org/traccar/protocol/ManPowerProtocol.java b/src/org/traccar/protocol/ManPowerProtocol.java new file mode 100644 index 000000000..f2745bd0d --- /dev/null +++ b/src/org/traccar/protocol/ManPowerProtocol.java @@ -0,0 +1,39 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.jboss.netty.handler.codec.string.StringEncoder; +import org.traccar.BaseProtocol; +import org.traccar.CharacterDelimiterFrameDecoder; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class ManPowerProtocol extends BaseProtocol { + + public ManPowerProtocol() { + super("manpower"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @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(ManPowerProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/ManPowerProtocolDecoder.java b/src/org/traccar/protocol/ManPowerProtocolDecoder.java index 773e2d782..7070e8e39 100644 --- a/src/org/traccar/protocol/ManPowerProtocolDecoder.java +++ b/src/org/traccar/protocol/ManPowerProtocolDecoder.java @@ -29,7 +29,7 @@ import org.traccar.model.Position; public class ManPowerProtocolDecoder extends BaseProtocolDecoder { - public ManPowerProtocolDecoder(String protocol) { + public ManPowerProtocolDecoder(ManPowerProtocol protocol) { super(protocol); } @@ -64,12 +64,12 @@ public class ManPowerProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); Integer index = 1; // Get device by IMEI - if (!identify(parser.group(index++))) { + if (!identify(parser.group(index++), channel)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/MaxonProtocol.java b/src/org/traccar/protocol/MaxonProtocol.java new file mode 100644 index 000000000..c8b79f876 --- /dev/null +++ b/src/org/traccar/protocol/MaxonProtocol.java @@ -0,0 +1,39 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.frame.LineBasedFrameDecoder; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.jboss.netty.handler.codec.string.StringEncoder; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class MaxonProtocol extends BaseProtocol { + + public MaxonProtocol() { + super("maxon"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @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(MaxonProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/MaxonProtocolDecoder.java b/src/org/traccar/protocol/MaxonProtocolDecoder.java index c25a190f1..c65476590 100644 --- a/src/org/traccar/protocol/MaxonProtocolDecoder.java +++ b/src/org/traccar/protocol/MaxonProtocolDecoder.java @@ -16,7 +16,6 @@ package org.traccar.protocol; import java.util.Calendar; -import java.util.Properties; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -25,9 +24,6 @@ import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.BaseProtocolDecoder; -import org.traccar.database.DataManager; -import org.traccar.helper.Log; -import org.traccar.model.Event; import org.traccar.model.Position; /** @@ -41,7 +37,7 @@ public class MaxonProtocolDecoder extends BaseProtocolDecoder { private Position position = null; - public MaxonProtocolDecoder(String protocol) { + public MaxonProtocolDecoder(MaxonProtocol protocol) { super(protocol); } @@ -126,7 +122,7 @@ public class MaxonProtocolDecoder extends BaseProtocolDecoder { Matcher parser = gpfidPattern.matcher(sentence); if (parser.matches()) { - if (!identify(parser.group(1))) { + if (!identify(parser.group(1), channel)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/MegastekProtocol.java b/src/org/traccar/protocol/MegastekProtocol.java new file mode 100644 index 000000000..ec747a6d1 --- /dev/null +++ b/src/org/traccar/protocol/MegastekProtocol.java @@ -0,0 +1,39 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.frame.LineBasedFrameDecoder; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.jboss.netty.handler.codec.string.StringEncoder; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class MegastekProtocol extends BaseProtocol { + + public MegastekProtocol() { + super("megastek"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @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(MegastekProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/MegastekProtocolDecoder.java b/src/org/traccar/protocol/MegastekProtocolDecoder.java index 3f29d8470..5b9f0408c 100644 --- a/src/org/traccar/protocol/MegastekProtocolDecoder.java +++ b/src/org/traccar/protocol/MegastekProtocolDecoder.java @@ -29,7 +29,7 @@ import org.traccar.model.Position; public class MegastekProtocolDecoder extends BaseProtocolDecoder { - public MegastekProtocolDecoder(String protocol) { + public MegastekProtocolDecoder(MegastekProtocol protocol) { super(protocol); } @@ -171,7 +171,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); // Parse location data if (!parseGPRMC(gprmc, position)) { @@ -192,8 +192,8 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { position.set(Event.KEY_ALARM, parser.group(index++)); // IMEI - if (!identify(parser.group(index++), false)) { - if (!identify(id)) { + if (!identify(parser.group(index++), channel, null, false)) { + if (!identify(id, channel)) { return null; } } @@ -231,7 +231,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { int index = 1; - if (!identify(id)) { + if (!identify(id, channel)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/MeiligaoProtocol.java b/src/org/traccar/protocol/MeiligaoProtocol.java new file mode 100644 index 000000000..37aa35df2 --- /dev/null +++ b/src/org/traccar/protocol/MeiligaoProtocol.java @@ -0,0 +1,34 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class MeiligaoProtocol extends BaseProtocol { + + public MeiligaoProtocol() { + super("meiligao"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new MeiligaoFrameDecoder()); + pipeline.addLast("objectDecoder", new MeiligaoProtocolDecoder(MeiligaoProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java index 2b1ea9434..f17d2e168 100644 --- a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java +++ b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java @@ -34,7 +34,7 @@ import org.traccar.model.Position; public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { - public MeiligaoProtocolDecoder(String protocol) { + public MeiligaoProtocolDecoder(MeiligaoProtocol protocol) { super(protocol); } @@ -118,8 +118,8 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { private String getMeiligaoServer(Channel channel) { Properties p = Context.getProps(); - if (p != null && p.containsKey(getProtocol() + ".server")) { - return p.getProperty(getProtocol() + ".server"); + if (p != null && p.containsKey(getProtocolName() + ".server")) { + return p.getProperty(getProtocolName() + ".server"); } else { InetSocketAddress address = (InetSocketAddress) channel.getLocalAddress(); return address.getAddress().getHostAddress() + ":" + address.getPort(); @@ -168,7 +168,7 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); // Custom data if (command == MSG_ALARM) { @@ -178,7 +178,7 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { } // Get device by id - if (!identify(getImei(id))) { + if (!identify(getImei(id), channel)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/MeitrackProtocol.java b/src/org/traccar/protocol/MeitrackProtocol.java new file mode 100644 index 000000000..c0261153b --- /dev/null +++ b/src/org/traccar/protocol/MeitrackProtocol.java @@ -0,0 +1,39 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.string.StringEncoder; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.nio.ByteOrder; +import java.util.List; +import java.util.Map; + +public class MeitrackProtocol extends BaseProtocol { + + public MeitrackProtocol() { + super("meitrack"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + TrackerServer server = new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new MeitrackFrameDecoder()); + pipeline.addLast("stringEncoder", new StringEncoder()); + pipeline.addLast("objectDecoder", new MeitrackProtocolDecoder(MeitrackProtocol.this)); + } + }; + server.setEndianness(ByteOrder.LITTLE_ENDIAN); + serverList.add(server); + } +} diff --git a/src/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/org/traccar/protocol/MeitrackProtocolDecoder.java index 3d6eb2a78..4e6927e56 100644 --- a/src/org/traccar/protocol/MeitrackProtocolDecoder.java +++ b/src/org/traccar/protocol/MeitrackProtocolDecoder.java @@ -36,7 +36,7 @@ import org.traccar.model.Position; public class MeitrackProtocolDecoder extends BaseProtocolDecoder { - public MeitrackProtocolDecoder(String protocol) { + public MeitrackProtocolDecoder(MeitrackProtocol protocol) { super(protocol); } @@ -84,12 +84,12 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); Integer index = 1; // Identification - if (!identify(parser.group(index++))) { + if (!identify(parser.group(index++), channel)) { return null; } position.setDeviceId(getDeviceId()); @@ -184,7 +184,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { // Identification String imei = buf.toString(index + 1, 15, Charset.defaultCharset()); - if (!identify(imei)) { + if (!identify(imei, channel)) { return null; } @@ -193,7 +193,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { while (buf.readableBytes() >= 0x34) { Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); position.setDeviceId(getDeviceId()); // Event diff --git a/src/org/traccar/protocol/MiniFinderProtocol.java b/src/org/traccar/protocol/MiniFinderProtocol.java new file mode 100644 index 000000000..88dfdd147 --- /dev/null +++ b/src/org/traccar/protocol/MiniFinderProtocol.java @@ -0,0 +1,37 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.traccar.BaseProtocol; +import org.traccar.CharacterDelimiterFrameDecoder; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class MiniFinderProtocol extends BaseProtocol { + + public MiniFinderProtocol() { + super("minifinder"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, ';')); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("objectDecoder", new MiniFinderProtocolDecoder(MiniFinderProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/MiniFinderProtocolDecoder.java b/src/org/traccar/protocol/MiniFinderProtocolDecoder.java index 27442875a..cd1cc4eec 100644 --- a/src/org/traccar/protocol/MiniFinderProtocolDecoder.java +++ b/src/org/traccar/protocol/MiniFinderProtocolDecoder.java @@ -29,7 +29,7 @@ import org.traccar.model.Position; public class MiniFinderProtocolDecoder extends BaseProtocolDecoder { - public MiniFinderProtocolDecoder(String protocol) { + public MiniFinderProtocolDecoder(MiniFinderProtocol protocol) { super(protocol); } @@ -57,7 +57,7 @@ public class MiniFinderProtocolDecoder extends BaseProtocolDecoder { // Identification if (sentence.startsWith("!1")) { - identify(sentence.substring(3, sentence.length())); + identify(sentence.substring(3, sentence.length()), channel); } // Location @@ -71,7 +71,7 @@ public class MiniFinderProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); position.setDeviceId(getDeviceId()); Integer index = 1; diff --git a/src/org/traccar/protocol/Mta6Protocol.java b/src/org/traccar/protocol/Mta6Protocol.java new file mode 100644 index 000000000..af6c35e1a --- /dev/null +++ b/src/org/traccar/protocol/Mta6Protocol.java @@ -0,0 +1,37 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.http.HttpRequestDecoder; +import org.jboss.netty.handler.codec.http.HttpResponseEncoder; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class Mta6Protocol extends BaseProtocol { + + public Mta6Protocol() { + super("mta6"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("httpDecoder", new HttpRequestDecoder()); + pipeline.addLast("httpEncoder", new HttpResponseEncoder()); + pipeline.addLast("objectDecoder", new Mta6ProtocolDecoder(Mta6Protocol.this, false)); + } + }); + } +} diff --git a/src/org/traccar/protocol/Mta6ProtocolDecoder.java b/src/org/traccar/protocol/Mta6ProtocolDecoder.java index 459b8bcb8..8872ba76a 100644 --- a/src/org/traccar/protocol/Mta6ProtocolDecoder.java +++ b/src/org/traccar/protocol/Mta6ProtocolDecoder.java @@ -32,6 +32,7 @@ import org.jboss.netty.handler.codec.http.HttpResponseStatus; import org.jboss.netty.handler.codec.http.HttpVersion; import org.traccar.BaseProtocolDecoder; import org.traccar.helper.BitUtil; +import org.traccar.Protocol; import org.traccar.helper.ChannelBufferTools; import org.traccar.model.Event; import org.traccar.model.Position; @@ -40,7 +41,7 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder { private boolean simple; - public Mta6ProtocolDecoder(String protocol, boolean simple) { + public Mta6ProtocolDecoder(Protocol protocol, boolean simple) { super(protocol); this.simple = simple; } @@ -123,7 +124,7 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder { while (buf.readable()) { Position position = new Position(); position.setDeviceId(getDeviceId()); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); short flags = buf.readUnsignedByte(); @@ -202,7 +203,7 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder { private Position parseFormatA1(ChannelBuffer buf) { Position position = new Position(); position.setDeviceId(getDeviceId()); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); short flags = buf.readUnsignedByte(); @@ -289,7 +290,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()); - if (!identify(uniqueId)) { + if (!identify(uniqueId, channel)) { return null; } buf.skipBytes(uniqueId.length()); diff --git a/src/org/traccar/protocol/Mta6canProtocol.java b/src/org/traccar/protocol/Mta6canProtocol.java new file mode 100644 index 000000000..ed4003575 --- /dev/null +++ b/src/org/traccar/protocol/Mta6canProtocol.java @@ -0,0 +1,37 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.http.HttpRequestDecoder; +import org.jboss.netty.handler.codec.http.HttpResponseEncoder; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class Mta6canProtocol extends BaseProtocol { + + public Mta6canProtocol() { + super("mta6can"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("httpDecoder", new HttpRequestDecoder()); + pipeline.addLast("httpEncoder", new HttpResponseEncoder()); + pipeline.addLast("objectDecoder", new Mta6ProtocolDecoder(Mta6canProtocol.this, true)); + } + }); + } +} diff --git a/src/org/traccar/protocol/MtxProtocol.java b/src/org/traccar/protocol/MtxProtocol.java new file mode 100644 index 000000000..8dc5c43fb --- /dev/null +++ b/src/org/traccar/protocol/MtxProtocol.java @@ -0,0 +1,39 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.frame.LineBasedFrameDecoder; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.jboss.netty.handler.codec.string.StringEncoder; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class MtxProtocol extends BaseProtocol { + + public MtxProtocol() { + super("mtx"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @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(MtxProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/MtxProtocolDecoder.java b/src/org/traccar/protocol/MtxProtocolDecoder.java index 0151e9a8c..860f3a5a0 100644 --- a/src/org/traccar/protocol/MtxProtocolDecoder.java +++ b/src/org/traccar/protocol/MtxProtocolDecoder.java @@ -29,7 +29,7 @@ import org.traccar.model.Position; public class MtxProtocolDecoder extends BaseProtocolDecoder { - public MtxProtocolDecoder(String protocol) { + public MtxProtocolDecoder(MtxProtocol protocol) { super(protocol); } @@ -71,12 +71,12 @@ public class MtxProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); Integer index = 1; // Get device by IMEI - if (!identify(parser.group(index++))) { + if (!identify(parser.group(index++), channel)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/MxtProtocol.java b/src/org/traccar/protocol/MxtProtocol.java new file mode 100644 index 000000000..5e6d4374e --- /dev/null +++ b/src/org/traccar/protocol/MxtProtocol.java @@ -0,0 +1,37 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.http.commands.CommandType; +import org.traccar.protocol.commands.CommandTemplate; + +import java.nio.ByteOrder; +import java.util.List; +import java.util.Map; + +public class MxtProtocol extends BaseProtocol { + + public MxtProtocol() { + super("mxt"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + TrackerServer server = new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new MxtFrameDecoder()); + pipeline.addLast("objectDecoder", new MxtProtocolDecoder(MxtProtocol.this)); + } + }; + server.setEndianness(ByteOrder.LITTLE_ENDIAN); + serverList.add(server); + } +} diff --git a/src/org/traccar/protocol/MxtProtocolDecoder.java b/src/org/traccar/protocol/MxtProtocolDecoder.java index 32aa5a4ba..b6d9a2f9e 100644 --- a/src/org/traccar/protocol/MxtProtocolDecoder.java +++ b/src/org/traccar/protocol/MxtProtocolDecoder.java @@ -29,7 +29,7 @@ import org.traccar.model.Position; public class MxtProtocolDecoder extends BaseProtocolDecoder { - public MxtProtocolDecoder(String protocol) { + public MxtProtocolDecoder(MxtProtocol protocol) { super(protocol); } @@ -49,14 +49,14 @@ public class MxtProtocolDecoder extends BaseProtocolDecoder { int type = buf.readUnsignedByte(); String id = String.valueOf(buf.readUnsignedInt()); - if (!identify(id)) { + if (!identify(id, channel)) { return null; } if (type == MSG_POSITION) { Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); position.setDeviceId(getDeviceId()); buf.readUnsignedByte(); // protocol diff --git a/src/org/traccar/protocol/NavigilProtocol.java b/src/org/traccar/protocol/NavigilProtocol.java new file mode 100644 index 000000000..f41575e02 --- /dev/null +++ b/src/org/traccar/protocol/NavigilProtocol.java @@ -0,0 +1,37 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.nio.ByteOrder; +import java.util.List; +import java.util.Map; + +public class NavigilProtocol extends BaseProtocol { + + public NavigilProtocol() { + super("navigil"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + TrackerServer server = new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new NavigilFrameDecoder()); + pipeline.addLast("objectDecoder", new NavigilProtocolDecoder(NavigilProtocol.this)); + } + }; + server.setEndianness(ByteOrder.LITTLE_ENDIAN); + serverList.add(server); + } +} diff --git a/src/org/traccar/protocol/NavigilProtocolDecoder.java b/src/org/traccar/protocol/NavigilProtocolDecoder.java index 0a2e8ce44..711a51047 100644 --- a/src/org/traccar/protocol/NavigilProtocolDecoder.java +++ b/src/org/traccar/protocol/NavigilProtocolDecoder.java @@ -31,7 +31,7 @@ import org.traccar.model.Position; public class NavigilProtocolDecoder extends BaseProtocolDecoder { - public NavigilProtocolDecoder(String protocol) { + public NavigilProtocolDecoder(NavigilProtocol protocol) { super(protocol); } @@ -81,7 +81,7 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder { private Position parseUnitReport(ChannelBuffer buf, int sequenceNumber) { Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); position.setValid(true); position.set(Event.KEY_INDEX, sequenceNumber); @@ -116,7 +116,7 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder { private Position parseTg2Report(ChannelBuffer buf, int sequenceNumber) { Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); position.setValid(true); position.set(Event.KEY_INDEX, sequenceNumber); @@ -153,7 +153,7 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder { private Position parsePositionReport(ChannelBuffer buf, int sequenceNumber, long timestamp) { Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); position.set(Event.KEY_INDEX, sequenceNumber); position.setDeviceId(getDeviceId()); @@ -174,7 +174,7 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder { private Position parsePositionReport2(ChannelBuffer buf, int sequenceNumber, long timestamp) { Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); position.set(Event.KEY_INDEX, sequenceNumber); position.setDeviceId(getDeviceId()); @@ -197,7 +197,7 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder { private Position parseSnapshot4(ChannelBuffer buf, int sequenceNumber) { Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); position.set(Event.KEY_INDEX, sequenceNumber); position.setDeviceId(getDeviceId()); @@ -236,7 +236,7 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder { private Position parseTrackingData(ChannelBuffer buf, int sequenceNumber, long timestamp) { Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); position.set(Event.KEY_INDEX, sequenceNumber); position.setDeviceId(getDeviceId()); @@ -278,7 +278,7 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedShort(); // checksum // Get device identifier - if (!identify(String.valueOf(buf.readUnsignedInt()))) { + if (!identify(String.valueOf(buf.readUnsignedInt()), channel)) { return null; } diff --git a/src/org/traccar/protocol/NavisProtocol.java b/src/org/traccar/protocol/NavisProtocol.java new file mode 100644 index 000000000..726a28c03 --- /dev/null +++ b/src/org/traccar/protocol/NavisProtocol.java @@ -0,0 +1,38 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.nio.ByteOrder; +import java.util.List; +import java.util.Map; + +public class NavisProtocol extends BaseProtocol { + + public NavisProtocol() { + super("navis"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + TrackerServer server = new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(4 * 1024, 12, 2, 2, 0)); + pipeline.addLast("objectDecoder", new NavisProtocolDecoder(NavisProtocol.this)); + } + }; + server.setEndianness(ByteOrder.LITTLE_ENDIAN); + serverList.add(server); + } +} diff --git a/src/org/traccar/protocol/NavisProtocolDecoder.java b/src/org/traccar/protocol/NavisProtocolDecoder.java index 125559aab..94dcec1a4 100644 --- a/src/org/traccar/protocol/NavisProtocolDecoder.java +++ b/src/org/traccar/protocol/NavisProtocolDecoder.java @@ -38,7 +38,7 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder { private static final Charset charset = Charset.defaultCharset(); - public NavisProtocolDecoder(String protocol) { + public NavisProtocolDecoder(NavisProtocol protocol) { super(protocol); } @@ -80,7 +80,7 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder { private ParseResult parsePosition(ChannelBuffer buf) { Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); position.setDeviceId(getDeviceId()); @@ -252,7 +252,7 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder { private Object processHandshake(Channel channel, ChannelBuffer buf) { buf.readByte(); // semicolon symbol - if (identify(buf.toString(Charset.defaultCharset()))) { + if (identify(buf.toString(Charset.defaultCharset()), channel)) { sendReply(channel, ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "*<S", charset)); } return null; diff --git a/src/org/traccar/protocol/NoranProtocol.java b/src/org/traccar/protocol/NoranProtocol.java new file mode 100644 index 000000000..bf06b6ea0 --- /dev/null +++ b/src/org/traccar/protocol/NoranProtocol.java @@ -0,0 +1,36 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ConnectionlessBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.nio.ByteOrder; +import java.util.List; +import java.util.Map; + +public class NoranProtocol extends BaseProtocol { + + public NoranProtocol() { + super("noran"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + TrackerServer server = new TrackerServer(new ConnectionlessBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("objectDecoder", new NoranProtocolDecoder(NoranProtocol.this)); + } + }; + server.setEndianness(ByteOrder.LITTLE_ENDIAN); + serverList.add(server); + } +} diff --git a/src/org/traccar/protocol/NoranProtocolDecoder.java b/src/org/traccar/protocol/NoranProtocolDecoder.java index 69ed623d8..f7eb26e97 100644 --- a/src/org/traccar/protocol/NoranProtocolDecoder.java +++ b/src/org/traccar/protocol/NoranProtocolDecoder.java @@ -21,7 +21,6 @@ import java.nio.charset.Charset; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; -import java.util.Date; import java.util.TimeZone; import org.jboss.netty.buffer.ChannelBuffer; @@ -35,7 +34,7 @@ import org.traccar.model.Position; public class NoranProtocolDecoder extends BaseProtocolDecoder { - public NoranProtocolDecoder(String protocol) { + public NoranProtocolDecoder(NoranProtocol protocol) { super(protocol); } @@ -88,7 +87,7 @@ public class NoranProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); if (type == MSG_CONTROL_RESPONSE) { buf.readUnsignedInt(); // GIS ip @@ -129,7 +128,7 @@ public class NoranProtocolDecoder extends BaseProtocolDecoder { // Identification String id = buf.readBytes(newFormat ? 12 : 11).toString(Charset.defaultCharset()).replaceAll("[^\\p{Print}]", ""); - if (!identify(id)) { + if (!identify(id, channel, remoteAddress)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/OrionProtocol.java b/src/org/traccar/protocol/OrionProtocol.java new file mode 100644 index 000000000..e074d3ea5 --- /dev/null +++ b/src/org/traccar/protocol/OrionProtocol.java @@ -0,0 +1,37 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.nio.ByteOrder; +import java.util.List; +import java.util.Map; + +public class OrionProtocol extends BaseProtocol { + + public OrionProtocol() { + super("orion"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + TrackerServer server = new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new OrionFrameDecoder()); + pipeline.addLast("objectDecoder", new OrionProtocolDecoder(OrionProtocol.this)); + } + }; + server.setEndianness(ByteOrder.LITTLE_ENDIAN); + serverList.add(server); + } +} diff --git a/src/org/traccar/protocol/OrionProtocolDecoder.java b/src/org/traccar/protocol/OrionProtocolDecoder.java index 7265a9762..e43ced8a5 100644 --- a/src/org/traccar/protocol/OrionProtocolDecoder.java +++ b/src/org/traccar/protocol/OrionProtocolDecoder.java @@ -31,7 +31,7 @@ import org.traccar.model.Position; public class OrionProtocolDecoder extends BaseProtocolDecoder { - public OrionProtocolDecoder(String protocol) { + public OrionProtocolDecoder(OrionProtocol protocol) { super(protocol); } @@ -72,7 +72,7 @@ public class OrionProtocolDecoder extends BaseProtocolDecoder { sendResponse(channel, buf); } - if (!identify(String.valueOf(buf.readUnsignedInt()))) { + if (!identify(String.valueOf(buf.readUnsignedInt()), channel)) { return null; } @@ -83,7 +83,7 @@ public class OrionProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); position.setDeviceId(getDeviceId()); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); position.set(Event.KEY_EVENT, buf.readUnsignedByte()); buf.readUnsignedByte(); // length diff --git a/src/org/traccar/protocol/OsmAndProtocol.java b/src/org/traccar/protocol/OsmAndProtocol.java new file mode 100644 index 000000000..58702cf45 --- /dev/null +++ b/src/org/traccar/protocol/OsmAndProtocol.java @@ -0,0 +1,37 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.http.HttpRequestDecoder; +import org.jboss.netty.handler.codec.http.HttpResponseEncoder; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class OsmAndProtocol extends BaseProtocol { + + public OsmAndProtocol() { + super("osmand"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("httpDecoder", new HttpRequestDecoder()); + pipeline.addLast("httpEncoder", new HttpResponseEncoder()); + pipeline.addLast("objectDecoder", new OsmAndProtocolDecoder(OsmAndProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/OsmAndProtocolDecoder.java b/src/org/traccar/protocol/OsmAndProtocolDecoder.java index 6fb858d70..91f15e098 100644 --- a/src/org/traccar/protocol/OsmAndProtocolDecoder.java +++ b/src/org/traccar/protocol/OsmAndProtocolDecoder.java @@ -38,7 +38,7 @@ import org.traccar.model.Position; public class OsmAndProtocolDecoder extends BaseProtocolDecoder { - public OsmAndProtocolDecoder(String protocol) { + public OsmAndProtocolDecoder(OsmAndProtocol protocol) { super(protocol); } @@ -58,11 +58,11 @@ public class OsmAndProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); // Identification String id = params.get(params.containsKey("id") ? "id" : "deviceid").get(0); - if (!identify(id)) { + if (!identify(id, channel)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/PiligrimProtocol.java b/src/org/traccar/protocol/PiligrimProtocol.java new file mode 100644 index 000000000..438908b30 --- /dev/null +++ b/src/org/traccar/protocol/PiligrimProtocol.java @@ -0,0 +1,39 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.http.HttpChunkAggregator; +import org.jboss.netty.handler.codec.http.HttpRequestDecoder; +import org.jboss.netty.handler.codec.http.HttpResponseEncoder; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class PiligrimProtocol extends BaseProtocol { + + public PiligrimProtocol() { + super("piligrim"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @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(PiligrimProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/PiligrimProtocolDecoder.java b/src/org/traccar/protocol/PiligrimProtocolDecoder.java index 30b81f5fb..f3c9056af 100644 --- a/src/org/traccar/protocol/PiligrimProtocolDecoder.java +++ b/src/org/traccar/protocol/PiligrimProtocolDecoder.java @@ -39,7 +39,7 @@ import org.traccar.model.Position; public class PiligrimProtocolDecoder extends BaseProtocolDecoder { - public PiligrimProtocolDecoder(String protocol) { + public PiligrimProtocolDecoder(PiligrimProtocol protocol) { super(protocol); } @@ -83,7 +83,7 @@ public class PiligrimProtocolDecoder extends BaseProtocolDecoder { // Identification QueryStringDecoder decoder = new QueryStringDecoder(request.getUri()); - if (!identify(decoder.getParameters().get("imei").get(0))) { + if (!identify(decoder.getParameters().get("imei").get(0), channel)) { return null; } @@ -99,7 +99,7 @@ public class PiligrimProtocolDecoder extends BaseProtocolDecoder { if (type == MSG_GPS || type == MSG_GPS_SENSORS) { Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); position.setDeviceId(getDeviceId()); // Time diff --git a/src/org/traccar/protocol/ProgressProtocol.java b/src/org/traccar/protocol/ProgressProtocol.java new file mode 100644 index 000000000..8a84c8990 --- /dev/null +++ b/src/org/traccar/protocol/ProgressProtocol.java @@ -0,0 +1,38 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.nio.ByteOrder; +import java.util.List; +import java.util.Map; + +public class ProgressProtocol extends BaseProtocol { + + public ProgressProtocol() { + super("progress"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + TrackerServer server = new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 2, 2, 4, 0)); + pipeline.addLast("objectDecoder", new ProgressProtocolDecoder(ProgressProtocol.this)); + } + }; + server.setEndianness(ByteOrder.LITTLE_ENDIAN); + serverList.add(server); + } +} diff --git a/src/org/traccar/protocol/ProgressProtocolDecoder.java b/src/org/traccar/protocol/ProgressProtocolDecoder.java index 9ec0e08eb..4c3e58ddc 100644 --- a/src/org/traccar/protocol/ProgressProtocolDecoder.java +++ b/src/org/traccar/protocol/ProgressProtocolDecoder.java @@ -36,7 +36,7 @@ public class ProgressProtocolDecoder extends BaseProtocolDecoder { private long lastIndex; private long newIndex; - public ProgressProtocolDecoder(String protocol) { + public ProgressProtocolDecoder(ProgressProtocol protocol) { super(protocol); } @@ -81,7 +81,7 @@ public class ProgressProtocolDecoder extends BaseProtocolDecoder { buf.skipBytes(length); length = buf.readUnsignedShort(); String imei = buf.readBytes(length).toString(Charset.defaultCharset()); - identify(imei); + identify(imei, channel); } // Position @@ -95,7 +95,7 @@ public class ProgressProtocolDecoder extends BaseProtocolDecoder { for (int j = 0; j < recordCount; j++) { Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); position.setDeviceId(getDeviceId()); // Message index diff --git a/src/org/traccar/protocol/Pt3000Protocol.java b/src/org/traccar/protocol/Pt3000Protocol.java new file mode 100644 index 000000000..4d22418c0 --- /dev/null +++ b/src/org/traccar/protocol/Pt3000Protocol.java @@ -0,0 +1,39 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.jboss.netty.handler.codec.string.StringEncoder; +import org.traccar.BaseProtocol; +import org.traccar.CharacterDelimiterFrameDecoder; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class Pt3000Protocol extends BaseProtocol { + + public Pt3000Protocol() { + super("pt3000"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @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(Pt3000Protocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/Pt3000ProtocolDecoder.java b/src/org/traccar/protocol/Pt3000ProtocolDecoder.java index 01b7b284c..ebfded3d5 100644 --- a/src/org/traccar/protocol/Pt3000ProtocolDecoder.java +++ b/src/org/traccar/protocol/Pt3000ProtocolDecoder.java @@ -24,12 +24,11 @@ import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.BaseProtocolDecoder; -import org.traccar.model.Event; import org.traccar.model.Position; public class Pt3000ProtocolDecoder extends BaseProtocolDecoder { - public Pt3000ProtocolDecoder(String protocol) { + public Pt3000ProtocolDecoder(Pt3000Protocol protocol) { super(protocol); } @@ -62,12 +61,12 @@ public class Pt3000ProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); Integer index = 1; // Identifier - if (!identify(parser.group(index++))) { + if (!identify(parser.group(index++), channel)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/Pt502Protocol.java b/src/org/traccar/protocol/Pt502Protocol.java new file mode 100644 index 000000000..53e2a8665 --- /dev/null +++ b/src/org/traccar/protocol/Pt502Protocol.java @@ -0,0 +1,39 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.nio.ByteOrder; +import java.util.List; +import java.util.Map; + +public class Pt502Protocol extends BaseProtocol { + + public Pt502Protocol() { + super("pt502"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + TrackerServer server = new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new Pt502FrameDecoder()); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("objectDecoder", new Pt502ProtocolDecoder(Pt502Protocol.this)); + } + }; + server.setEndianness(ByteOrder.LITTLE_ENDIAN); + serverList.add(server); + } +} diff --git a/src/org/traccar/protocol/Pt502ProtocolDecoder.java b/src/org/traccar/protocol/Pt502ProtocolDecoder.java index fe22b0fdc..145d3d42d 100644 --- a/src/org/traccar/protocol/Pt502ProtocolDecoder.java +++ b/src/org/traccar/protocol/Pt502ProtocolDecoder.java @@ -30,7 +30,7 @@ import org.traccar.model.Position; public class Pt502ProtocolDecoder extends BaseProtocolDecoder {
- public Pt502ProtocolDecoder(String protocol) {
+ public Pt502ProtocolDecoder(Pt502Protocol protocol) {
super(protocol);
}
@@ -71,12 +71,12 @@ public class Pt502ProtocolDecoder extends BaseProtocolDecoder { // Create new position
Position position = new Position();
- position.setProtocol(getProtocol());
+ position.setProtocol(getProtocolName());
Integer index = 1;
// Get device by IMEI
- if (!identify(parser.group(index++))) {
+ if (!identify(parser.group(index++), channel)) {
return null;
}
position.setDeviceId(getDeviceId());
diff --git a/src/org/traccar/protocol/RitiProtocol.java b/src/org/traccar/protocol/RitiProtocol.java new file mode 100644 index 000000000..360f1ab7e --- /dev/null +++ b/src/org/traccar/protocol/RitiProtocol.java @@ -0,0 +1,38 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.nio.ByteOrder; +import java.util.List; +import java.util.Map; + +public class RitiProtocol extends BaseProtocol { + + public RitiProtocol() { + super("riti"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + TrackerServer server = new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 105, 2, 3, 0)); + pipeline.addLast("objectDecoder", new RitiProtocolDecoder(RitiProtocol.this)); + } + }; + server.setEndianness(ByteOrder.LITTLE_ENDIAN); + serverList.add(server); + } +} diff --git a/src/org/traccar/protocol/RitiProtocolDecoder.java b/src/org/traccar/protocol/RitiProtocolDecoder.java index 7c53ec37f..b684ad2e7 100644 --- a/src/org/traccar/protocol/RitiProtocolDecoder.java +++ b/src/org/traccar/protocol/RitiProtocolDecoder.java @@ -32,7 +32,7 @@ import org.traccar.model.Position; public class RitiProtocolDecoder extends BaseProtocolDecoder { - public RitiProtocolDecoder(String protocol) { + public RitiProtocolDecoder(RitiProtocol protocol) { super(protocol); } @@ -58,12 +58,12 @@ public class RitiProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); buf.skipBytes(2); // header // Get device id - if (!identify(String.valueOf(buf.readUnsignedShort()))) { + if (!identify(String.valueOf(buf.readUnsignedShort()), channel)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/RuptelaProtocol.java b/src/org/traccar/protocol/RuptelaProtocol.java new file mode 100644 index 000000000..79df3587d --- /dev/null +++ b/src/org/traccar/protocol/RuptelaProtocol.java @@ -0,0 +1,35 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class RuptelaProtocol extends BaseProtocol { + + public RuptelaProtocol() { + super("ruptela"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 0, 2, 2, 0)); + pipeline.addLast("objectDecoder", new RuptelaProtocolDecoder(RuptelaProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/RuptelaProtocolDecoder.java b/src/org/traccar/protocol/RuptelaProtocolDecoder.java index 833285ca3..7938026e8 100644 --- a/src/org/traccar/protocol/RuptelaProtocolDecoder.java +++ b/src/org/traccar/protocol/RuptelaProtocolDecoder.java @@ -31,7 +31,7 @@ import org.traccar.model.Position; public class RuptelaProtocolDecoder extends BaseProtocolDecoder { - public RuptelaProtocolDecoder(String protocol) { + public RuptelaProtocolDecoder(RuptelaProtocol protocol) { super(protocol); } @@ -47,7 +47,7 @@ public class RuptelaProtocolDecoder extends BaseProtocolDecoder { // Identify device String imei = String.format("%015d", buf.readLong()); - if (!identify(imei)) { + if (!identify(imei, channel)) { return null; } @@ -61,7 +61,7 @@ public class RuptelaProtocolDecoder extends BaseProtocolDecoder { for (int i = 0; i < count; i++) { Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); position.setDeviceId(getDeviceId()); // Time diff --git a/src/org/traccar/protocol/SanavProtocol.java b/src/org/traccar/protocol/SanavProtocol.java new file mode 100644 index 000000000..6af6e90c5 --- /dev/null +++ b/src/org/traccar/protocol/SanavProtocol.java @@ -0,0 +1,37 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.traccar.BaseProtocol; +import org.traccar.CharacterDelimiterFrameDecoder; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class SanavProtocol extends BaseProtocol { + + public SanavProtocol() { + super("sanav"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '*')); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("objectDecoder", new SanavProtocolDecoder(SanavProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/SanavProtocolDecoder.java b/src/org/traccar/protocol/SanavProtocolDecoder.java index 91bba54c7..d8c3bd65b 100644 --- a/src/org/traccar/protocol/SanavProtocolDecoder.java +++ b/src/org/traccar/protocol/SanavProtocolDecoder.java @@ -24,12 +24,11 @@ import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.BaseProtocolDecoder; -import org.traccar.model.Event; import org.traccar.model.Position; public class SanavProtocolDecoder extends BaseProtocolDecoder { - public SanavProtocolDecoder(String protocol) { + public SanavProtocolDecoder(SanavProtocol protocol) { super(protocol); } @@ -62,11 +61,11 @@ public class SanavProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); Integer index = 1; // Identification - if (!identify(parser.group(index++))) { + if (!identify(parser.group(index++), channel)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/SkypatrolProtocol.java b/src/org/traccar/protocol/SkypatrolProtocol.java new file mode 100644 index 000000000..60bc86fdd --- /dev/null +++ b/src/org/traccar/protocol/SkypatrolProtocol.java @@ -0,0 +1,33 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ConnectionlessBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class SkypatrolProtocol extends BaseProtocol { + + public SkypatrolProtocol() { + super("skypatrol"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ConnectionlessBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("objectDecoder", new SkypatrolProtocolDecoder(SkypatrolProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/SkypatrolProtocolDecoder.java b/src/org/traccar/protocol/SkypatrolProtocolDecoder.java index 5521502f6..a23ebc1e6 100644 --- a/src/org/traccar/protocol/SkypatrolProtocolDecoder.java +++ b/src/org/traccar/protocol/SkypatrolProtocolDecoder.java @@ -29,7 +29,7 @@ import org.traccar.model.Position; public class SkypatrolProtocolDecoder extends BaseProtocolDecoder { - public SkypatrolProtocolDecoder(String protocol) { + public SkypatrolProtocolDecoder(SkypatrolProtocol protocol) { super(protocol); } @@ -71,7 +71,7 @@ public class SkypatrolProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); // Status code if (BitUtil.check(mask, 1)) { @@ -90,7 +90,7 @@ public class SkypatrolProtocolDecoder extends BaseProtocolDecoder { Log.warning("No device id field"); return null; } - if (!identify(id)) { + if (!identify(id, channel)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/Stl060Protocol.java b/src/org/traccar/protocol/Stl060Protocol.java new file mode 100644 index 000000000..b8cd70664 --- /dev/null +++ b/src/org/traccar/protocol/Stl060Protocol.java @@ -0,0 +1,36 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class Stl060Protocol extends BaseProtocol { + + public Stl060Protocol() { + super("stl060"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new Stl060FrameDecoder(1024)); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("objectDecoder", new Stl060ProtocolDecoder(Stl060Protocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/Stl060ProtocolDecoder.java b/src/org/traccar/protocol/Stl060ProtocolDecoder.java index 30dc4ab5c..d9c21b441 100644 --- a/src/org/traccar/protocol/Stl060ProtocolDecoder.java +++ b/src/org/traccar/protocol/Stl060ProtocolDecoder.java @@ -27,7 +27,7 @@ import org.traccar.model.Position; public class Stl060ProtocolDecoder extends BaseProtocolDecoder { - public Stl060ProtocolDecoder(String protocol) { + public Stl060ProtocolDecoder(Stl060Protocol protocol) { super(protocol); } @@ -82,12 +82,12 @@ public class Stl060ProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); Integer index = 1; // Device identification - if (!identify(parser.group(index++))) { + if (!identify(parser.group(index++), channel)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/SuntechProtocol.java b/src/org/traccar/protocol/SuntechProtocol.java new file mode 100644 index 000000000..a7a72ef42 --- /dev/null +++ b/src/org/traccar/protocol/SuntechProtocol.java @@ -0,0 +1,37 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.traccar.BaseProtocol; +import org.traccar.CharacterDelimiterFrameDecoder; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class SuntechProtocol extends BaseProtocol { + + public SuntechProtocol() { + super("suntech"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '\r')); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("objectDecoder", new SuntechProtocolDecoder(SuntechProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/SuntechProtocolDecoder.java b/src/org/traccar/protocol/SuntechProtocolDecoder.java index f21f6e0a0..f7b109cb0 100644 --- a/src/org/traccar/protocol/SuntechProtocolDecoder.java +++ b/src/org/traccar/protocol/SuntechProtocolDecoder.java @@ -30,7 +30,7 @@ import org.traccar.model.Position; public class SuntechProtocolDecoder extends BaseProtocolDecoder { - public SuntechProtocolDecoder(String protocol) { + public SuntechProtocolDecoder(SuntechProtocol protocol) { super(protocol); } @@ -64,11 +64,11 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); int index = 1; // Identifier - if (!identify(parser.group(index++))) { + if (!identify(parser.group(index++), channel)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/SyrusProtocol.java b/src/org/traccar/protocol/SyrusProtocol.java new file mode 100644 index 000000000..0fb321c8e --- /dev/null +++ b/src/org/traccar/protocol/SyrusProtocol.java @@ -0,0 +1,39 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.jboss.netty.handler.codec.string.StringEncoder; +import org.traccar.BaseProtocol; +import org.traccar.CharacterDelimiterFrameDecoder; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class SyrusProtocol extends BaseProtocol { + + public SyrusProtocol() { + super("syrus"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @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(SyrusProtocol.this, true)); + } + }); + } +} diff --git a/src/org/traccar/protocol/SyrusProtocolDecoder.java b/src/org/traccar/protocol/SyrusProtocolDecoder.java index b182b8b37..236ded2dc 100644 --- a/src/org/traccar/protocol/SyrusProtocolDecoder.java +++ b/src/org/traccar/protocol/SyrusProtocolDecoder.java @@ -25,15 +25,15 @@ import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.BaseProtocolDecoder; +import org.traccar.Protocol; import org.traccar.helper.UnitsConverter; -import org.traccar.model.Event; import org.traccar.model.Position; public class SyrusProtocolDecoder extends BaseProtocolDecoder { boolean sendResponse; - public SyrusProtocolDecoder(String protocol, boolean sendResponse) { + public SyrusProtocolDecoder(Protocol protocol, boolean sendResponse) { super(protocol); this.sendResponse = sendResponse; } @@ -111,7 +111,7 @@ public class SyrusProtocolDecoder extends BaseProtocolDecoder { // Find device in database String id = sentence.substring(beginIndex, endIndex); - if (!identify(id)) { + if (!identify(id, channel)) { return null; } @@ -131,7 +131,7 @@ public class SyrusProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); position.setDeviceId(getDeviceId()); Integer index = 1; diff --git a/src/org/traccar/protocol/T55Protocol.java b/src/org/traccar/protocol/T55Protocol.java new file mode 100644 index 000000000..b547fd70d --- /dev/null +++ b/src/org/traccar/protocol/T55Protocol.java @@ -0,0 +1,39 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.frame.LineBasedFrameDecoder; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.jboss.netty.handler.codec.string.StringEncoder; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class T55Protocol extends BaseProtocol { + + public T55Protocol() { + super("t55"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @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(T55Protocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/T55ProtocolDecoder.java b/src/org/traccar/protocol/T55ProtocolDecoder.java index f20eb1bf7..ce9f98f2d 100644 --- a/src/org/traccar/protocol/T55ProtocolDecoder.java +++ b/src/org/traccar/protocol/T55ProtocolDecoder.java @@ -29,7 +29,7 @@ import org.traccar.model.Position; public class T55ProtocolDecoder extends BaseProtocolDecoder { - public T55ProtocolDecoder(String protocol) { + public T55ProtocolDecoder(T55Protocol protocol) { super(protocol); } @@ -92,33 +92,33 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder { if (id.endsWith(",")) { id = id.substring(0, id.length() - 1); } - identify(id); + identify(id, channel); sentence = sentence.substring(index); } // Identification if (sentence.startsWith("$PGID")) { - identify(sentence.substring(6, sentence.length() - 3)); + identify(sentence.substring(6, sentence.length() - 3), channel); } // Identification else if (sentence.startsWith("$PCPTI")) { - identify(sentence.substring(7, sentence.indexOf(",", 7))); + identify(sentence.substring(7, sentence.indexOf(",", 7)), channel); } // Identification else if (sentence.startsWith("IMEI")) { - identify(sentence.substring(5, sentence.length())); + identify(sentence.substring(5, sentence.length()), channel); } // Identification else if (sentence.startsWith("$GPFID")) { - identify(sentence.substring(6, sentence.length())); + identify(sentence.substring(6, sentence.length()), channel); } // Identification else if (Character.isDigit(sentence.charAt(0)) & sentence.length() == 15) { - identify(sentence); + identify(sentence, channel); } // Location @@ -137,7 +137,7 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); position.setDeviceId(getDeviceId()); Integer index = 1; @@ -195,7 +195,7 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); position.setDeviceId(getDeviceId()); Integer index = 1; @@ -236,7 +236,7 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); position.setDeviceId(getDeviceId()); Integer index = 1; @@ -284,7 +284,7 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); position.setDeviceId(getDeviceId()); Integer index = 1; diff --git a/src/org/traccar/protocol/TaipProtocol.java b/src/org/traccar/protocol/TaipProtocol.java new file mode 100644 index 000000000..fc66d23e8 --- /dev/null +++ b/src/org/traccar/protocol/TaipProtocol.java @@ -0,0 +1,35 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ConnectionlessBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class TaipProtocol extends BaseProtocol { + + public TaipProtocol() { + super("taip"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ConnectionlessBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("objectDecoder", new SyrusProtocolDecoder(TaipProtocol.this, false)); + } + }); + } +} diff --git a/src/org/traccar/protocol/TelikProtocol.java b/src/org/traccar/protocol/TelikProtocol.java new file mode 100644 index 000000000..02d3b0875 --- /dev/null +++ b/src/org/traccar/protocol/TelikProtocol.java @@ -0,0 +1,37 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.traccar.BaseProtocol; +import org.traccar.CharacterDelimiterFrameDecoder; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class TelikProtocol extends BaseProtocol { + + public TelikProtocol() { + super("telik"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '\0')); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("objectDecoder", new TelikProtocolDecoder(TelikProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/TelikProtocolDecoder.java b/src/org/traccar/protocol/TelikProtocolDecoder.java index c1e5c9370..ece134c83 100644 --- a/src/org/traccar/protocol/TelikProtocolDecoder.java +++ b/src/org/traccar/protocol/TelikProtocolDecoder.java @@ -29,7 +29,7 @@ import org.traccar.model.Position; public class TelikProtocolDecoder extends BaseProtocolDecoder { - public TelikProtocolDecoder(String protocol) { + public TelikProtocolDecoder(TelikProtocol protocol) { super(protocol); } @@ -62,12 +62,12 @@ public class TelikProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); Integer index = 1; // Get device by IMEI - if (!identify(parser.group(index++))) { + if (!identify(parser.group(index++), channel)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/TeltonikaProtocol.java b/src/org/traccar/protocol/TeltonikaProtocol.java new file mode 100644 index 000000000..8c4495dfb --- /dev/null +++ b/src/org/traccar/protocol/TeltonikaProtocol.java @@ -0,0 +1,34 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class TeltonikaProtocol extends BaseProtocol { + + public TeltonikaProtocol() { + super("teltonika"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new TeltonikaFrameDecoder()); + pipeline.addLast("objectDecoder", new TeltonikaProtocolDecoder(TeltonikaProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java index 792a64b79..37168ce22 100644 --- a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java +++ b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java @@ -31,7 +31,7 @@ import org.traccar.model.Position; public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { - public TeltonikaProtocolDecoder(String protocol) { + public TeltonikaProtocolDecoder(TeltonikaProtocol protocol) { super(protocol); } @@ -39,7 +39,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { int length = buf.readUnsignedShort(); String imei = buf.toString(buf.readerIndex(), length, Charset.defaultCharset()); - boolean result = identify(imei); + boolean result = identify(imei, channel); if (channel != null) { ChannelBuffer response = ChannelBuffers.directBuffer(1); @@ -68,7 +68,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { for (int i = 0; i < count; i++) { Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/Tk102Protocol.java b/src/org/traccar/protocol/Tk102Protocol.java new file mode 100644 index 000000000..dc27eb283 --- /dev/null +++ b/src/org/traccar/protocol/Tk102Protocol.java @@ -0,0 +1,39 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.jboss.netty.handler.codec.string.StringEncoder; +import org.traccar.BaseProtocol; +import org.traccar.CharacterDelimiterFrameDecoder; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class Tk102Protocol extends BaseProtocol { + + public Tk102Protocol() { + super("tk102"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @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(Tk102Protocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/Tk102ProtocolDecoder.java b/src/org/traccar/protocol/Tk102ProtocolDecoder.java index 020fb8013..2a752f16f 100644 --- a/src/org/traccar/protocol/Tk102ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tk102ProtocolDecoder.java @@ -24,12 +24,11 @@ import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.BaseProtocolDecoder; -import org.traccar.model.Event; import org.traccar.model.Position; public class Tk102ProtocolDecoder extends BaseProtocolDecoder { - public Tk102ProtocolDecoder(String protocol) { + public Tk102ProtocolDecoder(Tk102Protocol protocol) { super(protocol); } @@ -54,7 +53,7 @@ public class Tk102ProtocolDecoder extends BaseProtocolDecoder { // Login if (sentence.startsWith("[!")) { - if (!identify(sentence.substring(14, 14 + 15))) { + if (!identify(sentence.substring(14, 14 + 15), channel)) { return null; } @@ -79,7 +78,7 @@ public class Tk102ProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); position.setDeviceId(getDeviceId()); Integer index = 1; diff --git a/src/org/traccar/protocol/Tk103Protocol.java b/src/org/traccar/protocol/Tk103Protocol.java new file mode 100644 index 000000000..f7208861a --- /dev/null +++ b/src/org/traccar/protocol/Tk103Protocol.java @@ -0,0 +1,48 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ConnectionlessBootstrap; +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.jboss.netty.handler.codec.string.StringEncoder; +import org.traccar.BaseProtocol; +import org.traccar.CharacterDelimiterFrameDecoder; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class Tk103Protocol extends BaseProtocol { + + public Tk103Protocol() { + super("tk103"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @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(Tk103Protocol.this)); + } + }); + serverList.add(new TrackerServer(new ConnectionlessBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("stringEncoder", new StringEncoder()); + pipeline.addLast("objectDecoder", new Tk103ProtocolDecoder(Tk103Protocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java index e51f8dea5..ded23da26 100644 --- a/src/org/traccar/protocol/Tk103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tk103ProtocolDecoder.java @@ -30,7 +30,7 @@ import org.traccar.model.Position; public class Tk103ProtocolDecoder extends BaseProtocolDecoder { - public Tk103ProtocolDecoder(String protocol) { + public Tk103ProtocolDecoder(Tk103Protocol protocol) { super(protocol); } @@ -83,11 +83,11 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); Integer index = 1; // Get device by IMEI - if (!identify(parser.group(index++))) { + if (!identify(parser.group(index++), channel)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/Tlt2hProtocol.java b/src/org/traccar/protocol/Tlt2hProtocol.java new file mode 100644 index 000000000..2313f8c59 --- /dev/null +++ b/src/org/traccar/protocol/Tlt2hProtocol.java @@ -0,0 +1,39 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.jboss.netty.handler.codec.string.StringEncoder; +import org.traccar.BaseProtocol; +import org.traccar.CharacterDelimiterFrameDecoder; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class Tlt2hProtocol extends BaseProtocol { + + public Tlt2hProtocol() { + super("tlt2h"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @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(Tlt2hProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/Tlt2hProtocolDecoder.java b/src/org/traccar/protocol/Tlt2hProtocolDecoder.java index ecc61d740..fed224937 100644 --- a/src/org/traccar/protocol/Tlt2hProtocolDecoder.java +++ b/src/org/traccar/protocol/Tlt2hProtocolDecoder.java @@ -31,7 +31,7 @@ import org.traccar.model.Position; public class Tlt2hProtocolDecoder extends BaseProtocolDecoder { - public Tlt2hProtocolDecoder(String protocol) { + public Tlt2hProtocolDecoder(Tlt2hProtocol protocol) { super(protocol); } @@ -72,7 +72,7 @@ public class Tlt2hProtocolDecoder extends BaseProtocolDecoder { } // Get device identifier - if (!identify(parser.group(1))) { + if (!identify(parser.group(1), channel)) { return null; } @@ -86,7 +86,7 @@ public class Tlt2hProtocolDecoder extends BaseProtocolDecoder { parser = patternPosition.matcher(message); if (parser.matches()) { Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); position.setDeviceId(getDeviceId()); Integer index = 1; diff --git a/src/org/traccar/protocol/TopflytechProtocol.java b/src/org/traccar/protocol/TopflytechProtocol.java new file mode 100644 index 000000000..805a63d5b --- /dev/null +++ b/src/org/traccar/protocol/TopflytechProtocol.java @@ -0,0 +1,37 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.traccar.BaseProtocol; +import org.traccar.CharacterDelimiterFrameDecoder; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class TopflytechProtocol extends BaseProtocol { + + public TopflytechProtocol() { + super("topflytech"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, ')')); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("objectDecoder", new TopflytechProtocolDecoder(TopflytechProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/TopflytechProtocolDecoder.java b/src/org/traccar/protocol/TopflytechProtocolDecoder.java index e62f77c20..c2aafdea3 100644 --- a/src/org/traccar/protocol/TopflytechProtocolDecoder.java +++ b/src/org/traccar/protocol/TopflytechProtocolDecoder.java @@ -24,12 +24,11 @@ import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.BaseProtocolDecoder; -import org.traccar.model.Event; import org.traccar.model.Position; public class TopflytechProtocolDecoder extends BaseProtocolDecoder { - public TopflytechProtocolDecoder(String protocol) { + public TopflytechProtocolDecoder(TopflytechProtocol protocol) { super(protocol); } @@ -62,11 +61,11 @@ public class TopflytechProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); Integer index = 1; // Identifier - if (!identify(parser.group(index++))) { + if (!identify(parser.group(index++), channel)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/TotemProtocol.java b/src/org/traccar/protocol/TotemProtocol.java new file mode 100644 index 000000000..004a29173 --- /dev/null +++ b/src/org/traccar/protocol/TotemProtocol.java @@ -0,0 +1,36 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class TotemProtocol extends BaseProtocol { + + public TotemProtocol() { + super("totem"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new TotemFrameDecoder()); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("objectDecoder", new TotemProtocolDecoder(TotemProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/TotemProtocolDecoder.java b/src/org/traccar/protocol/TotemProtocolDecoder.java index cf4eaf9af..b348089ff 100644 --- a/src/org/traccar/protocol/TotemProtocolDecoder.java +++ b/src/org/traccar/protocol/TotemProtocolDecoder.java @@ -29,7 +29,7 @@ import org.traccar.model.Position; public class TotemProtocolDecoder extends BaseProtocolDecoder { - public TotemProtocolDecoder(String protocol) { + public TotemProtocolDecoder(TotemProtocol protocol) { super(protocol); } @@ -159,12 +159,12 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); Integer index = 1; // Get device by IMEI - if (!identify(parser.group(index++))) { + if (!identify(parser.group(index++), channel)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/Tr20Protocol.java b/src/org/traccar/protocol/Tr20Protocol.java new file mode 100644 index 000000000..0f8b6656e --- /dev/null +++ b/src/org/traccar/protocol/Tr20Protocol.java @@ -0,0 +1,39 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.frame.LineBasedFrameDecoder; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.jboss.netty.handler.codec.string.StringEncoder; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class Tr20Protocol extends BaseProtocol { + + public Tr20Protocol() { + super("tr20"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @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(Tr20Protocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/Tr20ProtocolDecoder.java b/src/org/traccar/protocol/Tr20ProtocolDecoder.java index 048f510b4..c278fef73 100644 --- a/src/org/traccar/protocol/Tr20ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tr20ProtocolDecoder.java @@ -25,12 +25,11 @@ import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.BaseProtocolDecoder; import org.traccar.helper.UnitsConverter; -import org.traccar.model.Event; import org.traccar.model.Position; public class Tr20ProtocolDecoder extends BaseProtocolDecoder { - public Tr20ProtocolDecoder(String protocol) { + public Tr20ProtocolDecoder(Tr20Protocol protocol) { super(protocol); } @@ -78,12 +77,12 @@ public class Tr20ProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); Integer index = 1; // Get device by id - if (!identify(parser.group(index++))) { + if (!identify(parser.group(index++), channel)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/Tr900Protocol.java b/src/org/traccar/protocol/Tr900Protocol.java new file mode 100644 index 000000000..b26652312 --- /dev/null +++ b/src/org/traccar/protocol/Tr900Protocol.java @@ -0,0 +1,49 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ConnectionlessBootstrap; +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.frame.LineBasedFrameDecoder; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.jboss.netty.handler.codec.string.StringEncoder; +import org.traccar.BaseProtocol; +import org.traccar.CharacterDelimiterFrameDecoder; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class Tr900Protocol extends BaseProtocol { + + public Tr900Protocol() { + super("tr900"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { + @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 Tr900ProtocolDecoder(Tr900Protocol.this)); + } + }); + serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("stringEncoder", new StringEncoder()); + pipeline.addLast("objectDecoder", new Tr900ProtocolDecoder(Tr900Protocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/Tr900ProtocolDecoder.java b/src/org/traccar/protocol/Tr900ProtocolDecoder.java index fadca5fc6..ff99a8e8a 100644 --- a/src/org/traccar/protocol/Tr900ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tr900ProtocolDecoder.java @@ -28,7 +28,7 @@ import org.traccar.model.Position; public class Tr900ProtocolDecoder extends BaseProtocolDecoder { - public Tr900ProtocolDecoder(String protocol) { + public Tr900ProtocolDecoder(Tr900Protocol protocol) { super(protocol); } @@ -69,11 +69,11 @@ public class Tr900ProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); Integer index = 1; // Identification - if (!identify(parser.group(index++))) { + if (!identify(parser.group(index++), channel, remoteAddress)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/TrackboxProtocol.java b/src/org/traccar/protocol/TrackboxProtocol.java new file mode 100644 index 000000000..447376f78 --- /dev/null +++ b/src/org/traccar/protocol/TrackboxProtocol.java @@ -0,0 +1,39 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.frame.LineBasedFrameDecoder; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.jboss.netty.handler.codec.string.StringEncoder; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class TrackboxProtocol extends BaseProtocol { + + public TrackboxProtocol() { + super("trackbox"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @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(TrackboxProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/TrackboxProtocolDecoder.java b/src/org/traccar/protocol/TrackboxProtocolDecoder.java index 3404486aa..800fa16bd 100644 --- a/src/org/traccar/protocol/TrackboxProtocolDecoder.java +++ b/src/org/traccar/protocol/TrackboxProtocolDecoder.java @@ -29,7 +29,7 @@ import org.traccar.model.Position; public class TrackboxProtocolDecoder extends BaseProtocolDecoder { - public TrackboxProtocolDecoder(String protocol) { + public TrackboxProtocolDecoder(TrackboxProtocol protocol) { super(protocol); } @@ -61,7 +61,7 @@ public class TrackboxProtocolDecoder extends BaseProtocolDecoder { if (sentence.startsWith("a=connect")) { String id = sentence.substring(sentence.indexOf("i=") + 2); - if (identify(id)) { + if (identify(id, channel)) { sendResponse(channel); } } @@ -77,7 +77,7 @@ public class TrackboxProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); position.setDeviceId(getDeviceId()); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); Integer index = 1; diff --git a/src/org/traccar/protocol/TramigoProtocol.java b/src/org/traccar/protocol/TramigoProtocol.java new file mode 100644 index 000000000..305107fc1 --- /dev/null +++ b/src/org/traccar/protocol/TramigoProtocol.java @@ -0,0 +1,37 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.nio.ByteOrder; +import java.util.List; +import java.util.Map; + +public class TramigoProtocol extends BaseProtocol { + + public TramigoProtocol() { + super("tramigo"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + TrackerServer server = new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new TramigoFrameDecoder()); + pipeline.addLast("objectDecoder", new TramigoProtocolDecoder(TramigoProtocol.this)); + } + }; + server.setEndianness(ByteOrder.LITTLE_ENDIAN); + serverList.add(server); + } +} diff --git a/src/org/traccar/protocol/TramigoProtocolDecoder.java b/src/org/traccar/protocol/TramigoProtocolDecoder.java index 38b343ad9..7694d1dcb 100644 --- a/src/org/traccar/protocol/TramigoProtocolDecoder.java +++ b/src/org/traccar/protocol/TramigoProtocolDecoder.java @@ -35,7 +35,7 @@ import java.util.regex.Pattern; public class TramigoProtocolDecoder extends BaseProtocolDecoder { - public TramigoProtocolDecoder(String protocol) { + public TramigoProtocolDecoder(TramigoProtocol protocol) { super(protocol); } @@ -61,12 +61,12 @@ public class TramigoProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); position.set(Event.KEY_INDEX, index); position.setValid(true); // Get device id - if (!identify(String.valueOf(id))) { + if (!identify(String.valueOf(id), channel)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/TytanProtocol.java b/src/org/traccar/protocol/TytanProtocol.java new file mode 100644 index 000000000..11acae175 --- /dev/null +++ b/src/org/traccar/protocol/TytanProtocol.java @@ -0,0 +1,33 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ConnectionlessBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class TytanProtocol extends BaseProtocol { + + public TytanProtocol() { + super("tytan"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ConnectionlessBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("objectDecoder", new TytanProtocolDecoder(TytanProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/TytanProtocolDecoder.java b/src/org/traccar/protocol/TytanProtocolDecoder.java index 3ef0e11b7..5296d23a0 100644 --- a/src/org/traccar/protocol/TytanProtocolDecoder.java +++ b/src/org/traccar/protocol/TytanProtocolDecoder.java @@ -31,7 +31,7 @@ import org.traccar.model.Position; public class TytanProtocolDecoder extends BaseProtocolDecoder { - public TytanProtocolDecoder(String protocol) { + public TytanProtocolDecoder(TytanProtocol protocol) { super(protocol); } @@ -52,7 +52,7 @@ public class TytanProtocolDecoder extends BaseProtocolDecoder { } String id = String.valueOf(buf.readUnsignedInt()); - if (!identify(id)) { + if (!identify(id, channel, remoteAddress)) { return null; } @@ -61,7 +61,7 @@ public class TytanProtocolDecoder extends BaseProtocolDecoder { while (buf.readable()) { Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); position.setDeviceId(getDeviceId()); int end = buf.readerIndex() + buf.readUnsignedByte(); diff --git a/src/org/traccar/protocol/UlbotechProtocol.java b/src/org/traccar/protocol/UlbotechProtocol.java new file mode 100644 index 000000000..f60df7f30 --- /dev/null +++ b/src/org/traccar/protocol/UlbotechProtocol.java @@ -0,0 +1,34 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class UlbotechProtocol extends BaseProtocol { + + public UlbotechProtocol() { + super("ulbotech"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new UlbotechFrameDecoder()); + pipeline.addLast("objectDecoder", new UlbotechProtocolDecoder(UlbotechProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/UlbotechProtocolDecoder.java b/src/org/traccar/protocol/UlbotechProtocolDecoder.java index 3ec50b3fc..e6ccfe2c5 100644 --- a/src/org/traccar/protocol/UlbotechProtocolDecoder.java +++ b/src/org/traccar/protocol/UlbotechProtocolDecoder.java @@ -28,7 +28,7 @@ import java.util.Date; public class UlbotechProtocolDecoder extends BaseProtocolDecoder { - public UlbotechProtocolDecoder(String protocol) { + public UlbotechProtocolDecoder(UlbotechProtocol protocol) { super(protocol); } @@ -57,11 +57,11 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); // Get device id String imei = ChannelBufferTools.readHexString(buf, 16).substring(1); - if (!identify(imei)) { + if (!identify(imei, channel)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/V680Protocol.java b/src/org/traccar/protocol/V680Protocol.java new file mode 100644 index 000000000..bb5b537d6 --- /dev/null +++ b/src/org/traccar/protocol/V680Protocol.java @@ -0,0 +1,37 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.traccar.BaseProtocol; +import org.traccar.CharacterDelimiterFrameDecoder; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class V680Protocol extends BaseProtocol { + + public V680Protocol() { + super("v680"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, "##")); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("objectDecoder", new V680ProtocolDecoder(V680Protocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/V680ProtocolDecoder.java b/src/org/traccar/protocol/V680ProtocolDecoder.java index 1558c7d8e..7fbbe400b 100644 --- a/src/org/traccar/protocol/V680ProtocolDecoder.java +++ b/src/org/traccar/protocol/V680ProtocolDecoder.java @@ -29,7 +29,7 @@ import org.traccar.model.Position; public class V680ProtocolDecoder extends BaseProtocolDecoder { - public V680ProtocolDecoder(String protocol) { + public V680ProtocolDecoder(V680Protocol protocol) { super(protocol); } @@ -63,7 +63,7 @@ public class V680ProtocolDecoder extends BaseProtocolDecoder { // Detect device ID if (sentence.length() == 16) { String imei = sentence.substring(1, sentence.length()); - identify(imei); + identify(imei, channel); } else { // Parse message @@ -74,13 +74,13 @@ public class V680ProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); Integer index = 1; // Get device by IMEI String imei = parser.group(index++); if (imei != null) { - identify(imei); + identify(imei, channel); } if (!hasDeviceId()) { return null; diff --git a/src/org/traccar/protocol/VisiontekProtocol.java b/src/org/traccar/protocol/VisiontekProtocol.java new file mode 100644 index 000000000..acce3fc35 --- /dev/null +++ b/src/org/traccar/protocol/VisiontekProtocol.java @@ -0,0 +1,37 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.traccar.BaseProtocol; +import org.traccar.CharacterDelimiterFrameDecoder; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class VisiontekProtocol extends BaseProtocol { + + public VisiontekProtocol() { + super("visiontek"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '#')); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("objectDecoder", new VisiontekProtocolDecoder(VisiontekProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/VisiontekProtocolDecoder.java b/src/org/traccar/protocol/VisiontekProtocolDecoder.java index 236f417e3..abb94ea3a 100644 --- a/src/org/traccar/protocol/VisiontekProtocolDecoder.java +++ b/src/org/traccar/protocol/VisiontekProtocolDecoder.java @@ -28,7 +28,7 @@ import org.traccar.model.Position; public class VisiontekProtocolDecoder extends BaseProtocolDecoder { - public VisiontekProtocolDecoder(String protocol) { + public VisiontekProtocolDecoder(VisiontekProtocol protocol) { super(protocol); } @@ -70,14 +70,14 @@ public class VisiontekProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); Integer index = 1; // Device identification String id = parser.group(index++); String imei = parser.group(index++); - if (!identify(id, false) && !identify(imei)) { + if (!identify(id, channel, null, false) && !identify(imei, channel)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/WialonProtocol.java b/src/org/traccar/protocol/WialonProtocol.java new file mode 100644 index 000000000..80854d1e6 --- /dev/null +++ b/src/org/traccar/protocol/WialonProtocol.java @@ -0,0 +1,39 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.frame.LineBasedFrameDecoder; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.jboss.netty.handler.codec.string.StringEncoder; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class WialonProtocol extends BaseProtocol { + + public WialonProtocol() { + super("wialon"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @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(WialonProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/WialonProtocolDecoder.java b/src/org/traccar/protocol/WialonProtocolDecoder.java index 423f614bc..d85a64d31 100644 --- a/src/org/traccar/protocol/WialonProtocolDecoder.java +++ b/src/org/traccar/protocol/WialonProtocolDecoder.java @@ -32,7 +32,7 @@ import org.traccar.model.Position; public class WialonProtocolDecoder extends BaseProtocolDecoder { - public WialonProtocolDecoder(String protocol) { + public WialonProtocolDecoder(WialonProtocol protocol) { super(protocol); } @@ -77,7 +77,7 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); position.setDeviceId(getDeviceId()); Integer index = 1; @@ -174,7 +174,7 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder { // Detect device ID if (sentence.startsWith("#L#")) { String imei = sentence.substring(3, sentence.indexOf(';')); - if (identify(imei)) { + if (identify(imei, channel)) { sendResponse(channel, "#AL#", 1); } } diff --git a/src/org/traccar/protocol/WondexProtocol.java b/src/org/traccar/protocol/WondexProtocol.java new file mode 100644 index 000000000..a16c6b57d --- /dev/null +++ b/src/org/traccar/protocol/WondexProtocol.java @@ -0,0 +1,36 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class WondexProtocol extends BaseProtocol { + + public WondexProtocol() { + super("wondex"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new WondexFrameDecoder()); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("objectDecoder", new WondexProtocolDecoder(WondexProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/WondexProtocolDecoder.java b/src/org/traccar/protocol/WondexProtocolDecoder.java index 0c627b07c..25d58d17b 100644 --- a/src/org/traccar/protocol/WondexProtocolDecoder.java +++ b/src/org/traccar/protocol/WondexProtocolDecoder.java @@ -30,7 +30,7 @@ import org.traccar.model.Position; public class WondexProtocolDecoder extends BaseProtocolDecoder { - public WondexProtocolDecoder(String protocol) { + public WondexProtocolDecoder(WondexProtocol protocol) { super(protocol); } @@ -66,11 +66,11 @@ public class WondexProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); int index = 1; // Device identifier - if (!identify(parser.group(index++))) { + if (!identify(parser.group(index++), channel)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/Xexun2ProtocolDecoder.java b/src/org/traccar/protocol/Xexun2ProtocolDecoder.java index 8b654bef3..aba913ed3 100644 --- a/src/org/traccar/protocol/Xexun2ProtocolDecoder.java +++ b/src/org/traccar/protocol/Xexun2ProtocolDecoder.java @@ -29,7 +29,7 @@ import org.traccar.model.Position; public class Xexun2ProtocolDecoder extends BaseProtocolDecoder { - public Xexun2ProtocolDecoder(String protocol) { + public Xexun2ProtocolDecoder(XexunProtocol protocol) { super(protocol); } @@ -72,7 +72,7 @@ public class Xexun2ProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); Integer index = 1; @@ -127,7 +127,7 @@ public class Xexun2ProtocolDecoder extends BaseProtocolDecoder { position.set(Event.KEY_ALARM, parser.group(index++)); // Get device by IMEI - if (!identify(parser.group(index++))) { + if (!identify(parser.group(index++), channel)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/XexunProtocol.java b/src/org/traccar/protocol/XexunProtocol.java new file mode 100644 index 000000000..24e0d3279 --- /dev/null +++ b/src/org/traccar/protocol/XexunProtocol.java @@ -0,0 +1,44 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.frame.LineBasedFrameDecoder; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.traccar.BaseProtocol; +import org.traccar.Context; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class XexunProtocol extends BaseProtocol { + + public XexunProtocol() { + super("xexun"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + if (Boolean.valueOf(Context.getProps().getProperty(XexunProtocol.this.getName() + ".extended"))) { + pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024)); // tracker bug \n\r + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("objectDecoder", new Xexun2ProtocolDecoder(XexunProtocol.this)); + } else { + pipeline.addLast("frameDecoder", new XexunFrameDecoder()); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("objectDecoder", new XexunProtocolDecoder(XexunProtocol.this)); + } + } + }); + } +} diff --git a/src/org/traccar/protocol/XexunProtocolDecoder.java b/src/org/traccar/protocol/XexunProtocolDecoder.java index 231d7a969..4f01faa0c 100644 --- a/src/org/traccar/protocol/XexunProtocolDecoder.java +++ b/src/org/traccar/protocol/XexunProtocolDecoder.java @@ -25,12 +25,11 @@ import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.BaseProtocolDecoder; -import org.traccar.model.Event; import org.traccar.model.Position; public class XexunProtocolDecoder extends BaseProtocolDecoder { - public XexunProtocolDecoder(String protocol) { + public XexunProtocolDecoder(XexunProtocol protocol) { super(protocol); } @@ -62,7 +61,7 @@ public class XexunProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); Integer index = 1; @@ -108,7 +107,7 @@ public class XexunProtocolDecoder extends BaseProtocolDecoder { position.setTime(time.getTime()); // Get device by IMEI - if (!identify(parser.group(index++))) { + if (!identify(parser.group(index++), channel)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/XirgoProtocol.java b/src/org/traccar/protocol/XirgoProtocol.java new file mode 100644 index 000000000..81026a676 --- /dev/null +++ b/src/org/traccar/protocol/XirgoProtocol.java @@ -0,0 +1,39 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.jboss.netty.handler.codec.string.StringEncoder; +import org.traccar.BaseProtocol; +import org.traccar.CharacterDelimiterFrameDecoder; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class XirgoProtocol extends BaseProtocol { + + public XirgoProtocol() { + super("xirgo"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @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(XirgoProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/XirgoProtocolDecoder.java b/src/org/traccar/protocol/XirgoProtocolDecoder.java index 397924791..a08986f71 100644 --- a/src/org/traccar/protocol/XirgoProtocolDecoder.java +++ b/src/org/traccar/protocol/XirgoProtocolDecoder.java @@ -31,7 +31,7 @@ import org.traccar.model.Position; public class XirgoProtocolDecoder extends BaseProtocolDecoder { - public XirgoProtocolDecoder(String protocol) { + public XirgoProtocolDecoder(XirgoProtocol protocol) { super(protocol); } @@ -69,12 +69,12 @@ public class XirgoProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); Integer index = 1; // Get device by IMEI - if (!identify(parser.group(index++))) { + if (!identify(parser.group(index++), channel, remoteAddress)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/Xt013Protocol.java b/src/org/traccar/protocol/Xt013Protocol.java new file mode 100644 index 000000000..b9b118081 --- /dev/null +++ b/src/org/traccar/protocol/Xt013Protocol.java @@ -0,0 +1,37 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.frame.LineBasedFrameDecoder; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class Xt013Protocol extends BaseProtocol { + + public Xt013Protocol() { + super("xt013"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024)); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("objectDecoder", new Xt013ProtocolDecoder(Xt013Protocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/Xt013ProtocolDecoder.java b/src/org/traccar/protocol/Xt013ProtocolDecoder.java index 9e2f1fe40..c64869aa1 100644 --- a/src/org/traccar/protocol/Xt013ProtocolDecoder.java +++ b/src/org/traccar/protocol/Xt013ProtocolDecoder.java @@ -30,7 +30,7 @@ import java.util.regex.Pattern; public class Xt013ProtocolDecoder extends BaseProtocolDecoder { - public Xt013ProtocolDecoder(String protocol) { + public Xt013ProtocolDecoder(Xt013Protocol protocol) { super(protocol); } @@ -71,12 +71,12 @@ public class Xt013ProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); Integer index = 1; // Identify device - if (!identify(parser.group(index++))) { + if (!identify(parser.group(index++), channel)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/Xt7Protocol.java b/src/org/traccar/protocol/Xt7Protocol.java new file mode 100644 index 000000000..59e387ee4 --- /dev/null +++ b/src/org/traccar/protocol/Xt7Protocol.java @@ -0,0 +1,35 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class Xt7Protocol extends BaseProtocol { + + public Xt7Protocol() { + super("xt7"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(256, 20, 1, 5, 0)); + pipeline.addLast("objectDecoder", new Xt7ProtocolDecoder(Xt7Protocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/Xt7ProtocolDecoder.java b/src/org/traccar/protocol/Xt7ProtocolDecoder.java index 69e72aa70..d6f82e453 100644 --- a/src/org/traccar/protocol/Xt7ProtocolDecoder.java +++ b/src/org/traccar/protocol/Xt7ProtocolDecoder.java @@ -31,7 +31,7 @@ import org.traccar.model.Position; public class Xt7ProtocolDecoder extends BaseProtocolDecoder { - public Xt7ProtocolDecoder(String protocol) { + public Xt7ProtocolDecoder(Xt7Protocol protocol) { super(protocol); } @@ -67,11 +67,11 @@ public class Xt7ProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); // Get device by id String id = buf.readBytes(16).toString(Charset.defaultCharset()).trim(); - if (!identify(id)) { + if (!identify(id, channel)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/YwtProtocol.java b/src/org/traccar/protocol/YwtProtocol.java new file mode 100644 index 000000000..52cc98b92 --- /dev/null +++ b/src/org/traccar/protocol/YwtProtocol.java @@ -0,0 +1,39 @@ +package org.traccar.protocol; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.handler.codec.frame.LineBasedFrameDecoder; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.jboss.netty.handler.codec.string.StringEncoder; +import org.traccar.BaseProtocol; +import org.traccar.TrackerServer; +import org.traccar.protocol.commands.CommandTemplate; +import org.traccar.http.commands.CommandType; + +import java.util.List; +import java.util.Map; + +public class YwtProtocol extends BaseProtocol { + + public YwtProtocol() { + super("ywt"); + } + + @Override + protected void loadCommandsTemplates(Map<CommandType, CommandTemplate> templates) { + + } + + @Override + public void addTrackerServersTo(List<TrackerServer> serverList) { + serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) { + @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(YwtProtocol.this)); + } + }); + } +} diff --git a/src/org/traccar/protocol/YwtProtocolDecoder.java b/src/org/traccar/protocol/YwtProtocolDecoder.java index e216d61fc..c0b814349 100644 --- a/src/org/traccar/protocol/YwtProtocolDecoder.java +++ b/src/org/traccar/protocol/YwtProtocolDecoder.java @@ -29,7 +29,7 @@ import org.traccar.model.Position; public class YwtProtocolDecoder extends BaseProtocolDecoder { - public YwtProtocolDecoder(String protocol) { + public YwtProtocolDecoder(YwtProtocol protocol) { super(protocol); } @@ -81,12 +81,12 @@ public class YwtProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); - position.setProtocol(getProtocol()); + position.setProtocol(getProtocolName()); Integer index = 1; String type = parser.group(index++); // Device - if (!identify(parser.group(index++))) { + if (!identify(parser.group(index++), channel)) { return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/commands/CommandTemplate.java b/src/org/traccar/protocol/commands/CommandTemplate.java new file mode 100644 index 000000000..5d461b276 --- /dev/null +++ b/src/org/traccar/protocol/commands/CommandTemplate.java @@ -0,0 +1,8 @@ +package org.traccar.protocol.commands; + +import org.traccar.database.ActiveDevice; +import org.traccar.http.commands.GpsCommand; + +public interface CommandTemplate<T extends GpsCommand> { + Object applyTo(ActiveDevice activeDevice, T command); +} diff --git a/src/org/traccar/protocol/commands/CommandValueConversion.java b/src/org/traccar/protocol/commands/CommandValueConversion.java new file mode 100644 index 000000000..cfbf3ce5a --- /dev/null +++ b/src/org/traccar/protocol/commands/CommandValueConversion.java @@ -0,0 +1,5 @@ +package org.traccar.protocol.commands; + +public interface CommandValueConversion<T> { + public String convert(T value); +} diff --git a/src/org/traccar/protocol/commands/StringCommandTemplate.java b/src/org/traccar/protocol/commands/StringCommandTemplate.java new file mode 100644 index 000000000..2ac0ce9a8 --- /dev/null +++ b/src/org/traccar/protocol/commands/StringCommandTemplate.java @@ -0,0 +1,56 @@ +package org.traccar.protocol.commands; + +import org.traccar.database.ActiveDevice; +import org.traccar.http.commands.GpsCommand; +import org.traccar.protocol.commands.CommandValueConversion; + +import java.util.HashMap; +import java.util.Map; + +public class StringCommandTemplate<T extends GpsCommand> implements CommandTemplate<T> { + + private String messageTemplate; + private Map<Class<?>, CommandValueConversion> converters = new HashMap<Class<?>, CommandValueConversion>(); + + public StringCommandTemplate(String template, Object... replacements) { + this.messageTemplate = String.format(template, replacements); + } + + @Override + public Object applyTo(ActiveDevice activeDevice, T command) { + String currentMessage = messageTemplate; + currentMessage = this.replace(currentMessage, GpsCommand.UNIQUE_ID, activeDevice.getUniqueId()); + + Map<String, Object> replacements = command.getReplacements(); + + for (Map.Entry<String, Object> entry : replacements.entrySet()) { + currentMessage = this.replace(currentMessage, entry.getKey(), entry.getValue()); + } + + return currentMessage; + } + + public CommandTemplate addConverter(Class<?> type, CommandValueConversion converter) { + converters.put(type, converter); + return this; + } + + protected CommandValueConversion getConverter(Class<?> type) { + return converters.containsKey(type) ? converters.get(type) : idConverter(); + } + + private CommandValueConversion idConverter() { + return new CommandValueConversion() { + @Override + public String convert(Object value) { + return value.toString(); + } + }; + } + + private String replace(String currentMessage, String key, Object value) { + String replacementValue = getConverter(value.getClass()).convert(value); + return currentMessage.replace("[" + key + "]", replacementValue); + } + +} diff --git a/test/org/traccar/http/json/JsonConverterTestCase.java b/test/org/traccar/http/json/JsonConverterTestCase.java new file mode 100644 index 000000000..d81ca3bc9 --- /dev/null +++ b/test/org/traccar/http/json/JsonConverterTestCase.java @@ -0,0 +1,171 @@ +package org.traccar.http.json; + +import org.junit.Test; +import org.traccar.http.JsonConverter; +import org.traccar.model.Factory; + +import java.io.Reader; +import java.io.StringReader; +import java.text.ParseException; +import java.util.Calendar; +import java.util.Date; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class JsonConverterTestCase { + + private <T extends Factory> T convert(String jsonString, T prototype) throws ParseException { + Reader r = new StringReader( + jsonString); + + return JsonConverter.objectFromJson(r, prototype); + } + + @Test + public void primitiveConversion() throws ParseException { + + AllPrimitives o = convert("{" + + "\"aBoolean\": true, " + + "\"anInt\": 42, " + + "\"aDouble\": 41.99, " + + "\"aString\": \"discworld\", " + + "\"aDate\":\"2015-07-09T19:02:17\"" + + "}", + new AllPrimitives()); + + assertEquals(true, o.getaBoolean()); + assertEquals(42, o.getAnInt()); + assertEquals(41.99, o.getaDouble(), 0.001); + assertEquals("discworld", o.getaString()); + + Calendar c = Calendar.getInstance(); + c.setTime(o.getaDate()); + assertEquals(2015, c.get(Calendar.YEAR)); + assertEquals(Calendar.JULY, c.get(Calendar.MONTH)); + assertEquals(9, c.get(Calendar.DAY_OF_MONTH)); + assertEquals(19, c.get(Calendar.HOUR_OF_DAY)); + assertEquals(2, c.get(Calendar.MINUTE)); + assertEquals(17, c.get(Calendar.SECOND)); + } + + public static class AllPrimitives implements Factory { + + private boolean aBoolean; + private int anInt; + private double aDouble; + private String aString; + private Date aDate; + + + @Override + public Object create() { + return new AllPrimitives(); + } + + public boolean getaBoolean() { + return aBoolean; + } + + public void setaBoolean(boolean aBoolean) { + this.aBoolean = aBoolean; + } + + public int getAnInt() { + return anInt; + } + + public void setAnInt(int anInt) { + this.anInt = anInt; + } + + public double getaDouble() { + return aDouble; + } + + public void setaDouble(double aDouble) { + this.aDouble = aDouble; + } + + public String getaString() { + return aString; + } + + public void setaString(String aString) { + this.aString = aString; + } + + public Date getaDate() { + return aDate; + } + + public void setaDate(Date aDate) { + this.aDate = aDate; + } + } + + + @Test + public void enumConversion() throws ParseException { + ObjectWithEnum o = convert("{\"anEnum\": \"VALUE2\"}", new ObjectWithEnum()); + assertEquals(TestEnum.VALUE2, o.getAnEnum()); + } + + + public enum TestEnum { + VALUE1, VALUE2 + } + + public static class ObjectWithEnum implements Factory { + private TestEnum anEnum; + + public TestEnum getAnEnum() { + return anEnum; + } + + public void setAnEnum(TestEnum anEnum) { + this.anEnum = anEnum; + } + + @Override + public Object create() { + return new ObjectWithEnum(); + } + } + + + @Test + public void nestedObjectsConversion() throws ParseException { + NestedObjects o = convert("{\"name\": \"Rincewind\", \"nestedObject\": {\"anEnum\":\"VALUE1\"}}", new NestedObjects()); + assertEquals("Rincewind", o.getName()); + assertNotNull("The nested object should be populated", o.getNestedObject()); + assertEquals(TestEnum.VALUE1, o.getNestedObject().getAnEnum()); + } + + public static class NestedObjects implements Factory { + + private String name; + private ObjectWithEnum nestedObject; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public ObjectWithEnum getNestedObject() { + return nestedObject; + } + + public void setNestedObject(ObjectWithEnum nestedObject) { + this.nestedObject = nestedObject; + } + + @Override + public Object create() { + return new NestedObjects(); + } + } +} diff --git a/test/org/traccar/protocol/ApelProtocolDecoderTest.java b/test/org/traccar/protocol/ApelProtocolDecoderTest.java index f6899a6ad..1eb02b3b8 100644 --- a/test/org/traccar/protocol/ApelProtocolDecoderTest.java +++ b/test/org/traccar/protocol/ApelProtocolDecoderTest.java @@ -12,7 +12,7 @@ public class ApelProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - ApelProtocolDecoder decoder = new ApelProtocolDecoder(null); + ApelProtocolDecoder decoder = new ApelProtocolDecoder(new ApelProtocol()); /*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 e163b8e35..6f1c204eb 100644 --- a/test/org/traccar/protocol/AplicomProtocolDecoderTest.java +++ b/test/org/traccar/protocol/AplicomProtocolDecoderTest.java @@ -10,8 +10,8 @@ public class AplicomProtocolDecoderTest extends ProtocolDecoderTest { @Test
public void testDecode() throws Exception {
- AplicomProtocolDecoder decoder = new AplicomProtocolDecoder(null);
-
+ AplicomProtocolDecoder decoder = new AplicomProtocolDecoder(new AplicomProtocol());
+
verify(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString(
"44C20146B710C158DA002100B09F0700C054CA0EA254CA0E9C03BE0BF6015D7069070000142A600000000000000001"))));
diff --git a/test/org/traccar/protocol/Ardi01ProtocolDecoderTest.java b/test/org/traccar/protocol/Ardi01ProtocolDecoderTest.java index 90993475e..d27e455ab 100644 --- a/test/org/traccar/protocol/Ardi01ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Ardi01ProtocolDecoderTest.java @@ -11,7 +11,7 @@ public class Ardi01ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Ardi01ProtocolDecoder decoder = new Ardi01ProtocolDecoder(null); + Ardi01ProtocolDecoder decoder = new Ardi01ProtocolDecoder(new Ardi01Protocol()); 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 34f34c957..4433afb91 100644 --- a/test/org/traccar/protocol/AtrackProtocolDecoderTest.java +++ b/test/org/traccar/protocol/AtrackProtocolDecoderTest.java @@ -12,7 +12,7 @@ public class AtrackProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - AtrackProtocolDecoder decoder = new AtrackProtocolDecoder(null); + AtrackProtocolDecoder decoder = new AtrackProtocolDecoder(new AtrackProtocol()); 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 26c25833b..e76a75e97 100644 --- a/test/org/traccar/protocol/AutoFon45ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/AutoFon45ProtocolDecoderTest.java @@ -11,7 +11,7 @@ import static org.traccar.helper.DecoderVerifier.verify; public class AutoFon45ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - AutoFon45ProtocolDecoder decoder = new AutoFon45ProtocolDecoder(null); + AutoFon45ProtocolDecoder decoder = new AutoFon45ProtocolDecoder(new AutoFon45Protocol()); 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 ded0aca6f..8fa323531 100644 --- a/test/org/traccar/protocol/AutoFonProtocolDecoderTest.java +++ b/test/org/traccar/protocol/AutoFonProtocolDecoderTest.java @@ -13,7 +13,7 @@ public class AutoFonProtocolDecoderTest extends ProtocolDecoderTest { @Test
public void testDecode() throws Exception {
- AutoFonProtocolDecoder decoder = new AutoFonProtocolDecoder(null);
+ AutoFonProtocolDecoder decoder = new AutoFonProtocolDecoder(new AutoFonProtocol());
assertNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString(
"10556103592310314825728F"))));
diff --git a/test/org/traccar/protocol/Avl301ProtocolDecoderTest.java b/test/org/traccar/protocol/Avl301ProtocolDecoderTest.java index 666bb0b43..b431fa868 100644 --- a/test/org/traccar/protocol/Avl301ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Avl301ProtocolDecoderTest.java @@ -12,7 +12,7 @@ public class Avl301ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Avl301ProtocolDecoder decoder = new Avl301ProtocolDecoder(null); + Avl301ProtocolDecoder decoder = new Avl301ProtocolDecoder(new Avl301Protocol()); assertNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString( "244c0f086058500087335500010d0a")))); diff --git a/test/org/traccar/protocol/BceProtocolDecoderTest.java b/test/org/traccar/protocol/BceProtocolDecoderTest.java index 356a6fba1..69567556d 100644 --- a/test/org/traccar/protocol/BceProtocolDecoderTest.java +++ b/test/org/traccar/protocol/BceProtocolDecoderTest.java @@ -14,7 +14,7 @@ public class BceProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - BceProtocolDecoder decoder = new BceProtocolDecoder(null); + BceProtocolDecoder decoder = new BceProtocolDecoder(new BceProtocol()); 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 a864d62dd..7cbb1aa4c 100644 --- a/test/org/traccar/protocol/BoxProtocolDecoderTest.java +++ b/test/org/traccar/protocol/BoxProtocolDecoderTest.java @@ -10,7 +10,7 @@ public class BoxProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - BoxProtocolDecoder decoder = new BoxProtocolDecoder(null); + BoxProtocolDecoder decoder = new BoxProtocolDecoder(new BoxProtocol()); 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 5f2e5bfce..ab96dab07 100644 --- a/test/org/traccar/protocol/CalAmpProtocolDecoderTest.java +++ b/test/org/traccar/protocol/CalAmpProtocolDecoderTest.java @@ -13,7 +13,7 @@ public class CalAmpProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - CalAmpProtocolDecoder decoder = new CalAmpProtocolDecoder(null); + CalAmpProtocolDecoder decoder = new CalAmpProtocolDecoder(new CalAmpProtocol()); 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 05e2402a6..f70fe43f5 100644 --- a/test/org/traccar/protocol/CarTrackProtocolDecoderTest.java +++ b/test/org/traccar/protocol/CarTrackProtocolDecoderTest.java @@ -9,7 +9,7 @@ public class CarTrackProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - CarTrackProtocolDecoder decoder = new CarTrackProtocolDecoder(null); + CarTrackProtocolDecoder decoder = new CarTrackProtocolDecoder(new CarTrackProtocol()); 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 04217dcd6..08f40c085 100644 --- a/test/org/traccar/protocol/CarscopProtocolDecoderTest.java +++ b/test/org/traccar/protocol/CarscopProtocolDecoderTest.java @@ -10,7 +10,7 @@ public class CarscopProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - CarscopProtocolDecoder decoder = new CarscopProtocolDecoder(null); + CarscopProtocolDecoder decoder = new CarscopProtocolDecoder(new CarscopProtocol()); verify(decoder.decode(null, null, "*040331141830UB05123456789012345061825A2934.0133N10627.2544E000.0040331309.6200000000L000000")); diff --git a/test/org/traccar/protocol/CastelProtocolDecoderTest.java b/test/org/traccar/protocol/CastelProtocolDecoderTest.java index 1671e4d12..e814beb74 100644 --- a/test/org/traccar/protocol/CastelProtocolDecoderTest.java +++ b/test/org/traccar/protocol/CastelProtocolDecoderTest.java @@ -12,7 +12,7 @@ public class CastelProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - CastelProtocolDecoder decoder = new CastelProtocolDecoder(null); + CastelProtocolDecoder decoder = new CastelProtocolDecoder(new CastelProtocol()); assertNull(decoder.decode(null, null, null, ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, ChannelBufferTools.convertHexString( "40401F00043130303131313235323939383700000000000000100303320D0A")))); diff --git a/test/org/traccar/protocol/CellocatorProtocolDecoderTest.java b/test/org/traccar/protocol/CellocatorProtocolDecoderTest.java index 74b7e305e..b980a9820 100644 --- a/test/org/traccar/protocol/CellocatorProtocolDecoderTest.java +++ b/test/org/traccar/protocol/CellocatorProtocolDecoderTest.java @@ -12,7 +12,7 @@ public class CellocatorProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - CellocatorProtocolDecoder decoder = new CellocatorProtocolDecoder(null); + CellocatorProtocolDecoder decoder = new CellocatorProtocolDecoder(new CellocatorProtocol()); 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 4edd2d052..71f5c2c46 100644 --- a/test/org/traccar/protocol/EasyTrackProtocolDecoderTest.java +++ b/test/org/traccar/protocol/EasyTrackProtocolDecoderTest.java @@ -10,7 +10,7 @@ public class EasyTrackProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - EasyTrackProtocolDecoder decoder = new EasyTrackProtocolDecoder(null); + EasyTrackProtocolDecoder decoder = new EasyTrackProtocolDecoder(new EasyTrackProtocol()); 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 6bf7d7143..e731fbbdd 100644 --- a/test/org/traccar/protocol/EelinkProtocolDecoderTest.java +++ b/test/org/traccar/protocol/EelinkProtocolDecoderTest.java @@ -12,7 +12,7 @@ public class EelinkProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - EelinkProtocolDecoder decoder = new EelinkProtocolDecoder(null); + EelinkProtocolDecoder decoder = new EelinkProtocolDecoder(new EelinkProtocol()); 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 7e67a300f..26499a365 100644 --- a/test/org/traccar/protocol/EnforaProtocolDecoderTest.java +++ b/test/org/traccar/protocol/EnforaProtocolDecoderTest.java @@ -14,7 +14,7 @@ public class EnforaProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - EnforaProtocolDecoder decoder = new EnforaProtocolDecoder(null); + EnforaProtocolDecoder decoder = new EnforaProtocolDecoder(new EnforaProtocol()); 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 b56a92c16..32cf7ebb8 100644 --- a/test/org/traccar/protocol/Ev603ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Ev603ProtocolDecoderTest.java @@ -10,7 +10,7 @@ public class Ev603ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Ev603ProtocolDecoder decoder = new Ev603ProtocolDecoder(null); + Ev603ProtocolDecoder decoder = new Ev603ProtocolDecoder(new Ev603Protocol()); assertNull(decoder.decode(null, null, "!1,123456789012345")); diff --git a/test/org/traccar/protocol/FreedomProtocolDecoderTest.java b/test/org/traccar/protocol/FreedomProtocolDecoderTest.java index b39b7a0cd..2a86a0fec 100644 --- a/test/org/traccar/protocol/FreedomProtocolDecoderTest.java +++ b/test/org/traccar/protocol/FreedomProtocolDecoderTest.java @@ -10,7 +10,7 @@ public class FreedomProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - FreedomProtocolDecoder decoder = new FreedomProtocolDecoder(null); + FreedomProtocolDecoder decoder = new FreedomProtocolDecoder(new FreedomProtocol()); 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 b79de9fbf..9a312ac7a 100644 --- a/test/org/traccar/protocol/GalileoProtocolDecoderTest.java +++ b/test/org/traccar/protocol/GalileoProtocolDecoderTest.java @@ -13,7 +13,7 @@ public class GalileoProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - GalileoProtocolDecoder decoder = new GalileoProtocolDecoder(null); + GalileoProtocolDecoder decoder = new GalileoProtocolDecoder(new GalileoProtocol()); 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 6bcd829e3..38f9b4a1f 100644 --- a/test/org/traccar/protocol/GatorProtocolDecoderTest.java +++ b/test/org/traccar/protocol/GatorProtocolDecoderTest.java @@ -11,7 +11,7 @@ public class GatorProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - GatorProtocolDecoder decoder = new GatorProtocolDecoder(null); + GatorProtocolDecoder decoder = new GatorProtocolDecoder(new GatorProtocol()); 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 08003e155..8d2e3dd53 100644 --- a/test/org/traccar/protocol/Gl100ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Gl100ProtocolDecoderTest.java @@ -10,7 +10,7 @@ public class Gl100ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Gl100ProtocolDecoder decoder = new Gl100ProtocolDecoder(null); + Gl100ProtocolDecoder decoder = new Gl100ProtocolDecoder(new Gl100Protocol()); 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 96be1c5a2..638e9e9dc 100644 --- a/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java @@ -9,14 +9,14 @@ public class Gl200ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Gl200ProtocolDecoder decoder = new Gl200ProtocolDecoder(null); + Gl200ProtocolDecoder decoder = new Gl200ProtocolDecoder(new Gl200Protocol()); verify(decoder.decode(null, null, null, "+RESP:GTSTT,1A0401,860599000508846,,41,0,0.0,84,107.5,-76.657998,39.497203,20150623160622,0310,0260,B435,3B81,,20150623160622,0F54$")); verify(decoder.decode(null, null, null, "+RESP:GTFRI,1A0401,860599000508846,,0,0,1,1,134.8,154,278.7,-76.671089,39.778885,20150623154301,0310,0260,043F,7761,,99,20150623154314,0F24$")); - + verify(decoder.decode(null, 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 c1885bb90..08e4cd77d 100644 --- a/test/org/traccar/protocol/GlobalSatProtocolDecoderTest.java +++ b/test/org/traccar/protocol/GlobalSatProtocolDecoderTest.java @@ -9,7 +9,7 @@ public class GlobalSatProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - GlobalSatProtocolDecoder decoder = new GlobalSatProtocolDecoder(null); + GlobalSatProtocolDecoder decoder = new GlobalSatProtocolDecoder(new GlobalSatProtocol()); 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 75d5b0121..938630655 100644 --- a/test/org/traccar/protocol/GoSafeProtocolDecoderTest.java +++ b/test/org/traccar/protocol/GoSafeProtocolDecoderTest.java @@ -10,7 +10,7 @@ public class GoSafeProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - GoSafeProtocolDecoder decoder = new GoSafeProtocolDecoder(null); + GoSafeProtocolDecoder decoder = new GoSafeProtocolDecoder(new GoSafeProtocol()); 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 bfeaf9e2e..9c544470b 100644 --- a/test/org/traccar/protocol/GotopProtocolDecoderTest.java +++ b/test/org/traccar/protocol/GotopProtocolDecoderTest.java @@ -10,7 +10,7 @@ public class GotopProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - GotopProtocolDecoder decoder = new GotopProtocolDecoder(null); + GotopProtocolDecoder decoder = new GotopProtocolDecoder(new GotopProtocol()); assertNull(decoder.decode(null, null, "")); diff --git a/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java b/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java index 3e63d4b34..9a10d9932 100644 --- a/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java @@ -9,7 +9,7 @@ public class Gps103ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Gps103ProtocolDecoder decoder = new Gps103ProtocolDecoder(null); + Gps103ProtocolDecoder decoder = new Gps103ProtocolDecoder(new Gps103Protocol()); // 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 d50f03d39..876beb59c 100644 --- a/test/org/traccar/protocol/GpsGateProtocolDecoderTest.java +++ b/test/org/traccar/protocol/GpsGateProtocolDecoderTest.java @@ -10,7 +10,7 @@ public class GpsGateProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - GpsGateProtocolDecoder decoder = new GpsGateProtocolDecoder(null); + GpsGateProtocolDecoder decoder = new GpsGateProtocolDecoder(new GpsGateProtocol()); 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 539fe2612..148a668b4 100644 --- a/test/org/traccar/protocol/Gt02ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Gt02ProtocolDecoderTest.java @@ -12,7 +12,7 @@ public class Gt02ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Gt02ProtocolDecoder decoder = new Gt02ProtocolDecoder(null); + Gt02ProtocolDecoder decoder = new Gt02ProtocolDecoder(new Gt02Protocol()); 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 aee675b2e..3fcab6900 100644 --- a/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java @@ -12,7 +12,7 @@ public class Gt06ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Gt06ProtocolDecoder decoder = new Gt06ProtocolDecoder(null); + Gt06ProtocolDecoder decoder = new Gt06ProtocolDecoder(new Gt06Protocol()); 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 443462a57..3f89e2213 100644 --- a/test/org/traccar/protocol/H02ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/H02ProtocolDecoderTest.java @@ -13,7 +13,7 @@ public class H02ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - H02ProtocolDecoder decoder = new H02ProtocolDecoder(null); + H02ProtocolDecoder decoder = new H02ProtocolDecoder(new H02Protocol()); 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 4ccd0fbd4..49a060472 100644 --- a/test/org/traccar/protocol/HaicomProtocolDecoderTest.java +++ b/test/org/traccar/protocol/HaicomProtocolDecoderTest.java @@ -9,7 +9,7 @@ public class HaicomProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - HaicomProtocolDecoder decoder = new HaicomProtocolDecoder(null); + HaicomProtocolDecoder decoder = new HaicomProtocolDecoder(new HaicomProtocol()); verify(decoder.decode(null, null, "$GPRS012497007097169,T100001,150618,230031,5402267400332464,0004,2014,000001,,,1,00#V040*")); diff --git a/test/org/traccar/protocol/IntellitracProtocolDecoderTest.java b/test/org/traccar/protocol/IntellitracProtocolDecoderTest.java index 28e5a3ae7..8028e0f35 100644 --- a/test/org/traccar/protocol/IntellitracProtocolDecoderTest.java +++ b/test/org/traccar/protocol/IntellitracProtocolDecoderTest.java @@ -10,7 +10,7 @@ public class IntellitracProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - IntellitracProtocolDecoder decoder = new IntellitracProtocolDecoder(null); + IntellitracProtocolDecoder decoder = new IntellitracProtocolDecoder(new IntellitracProtocol()); assertNull(decoder.decode(null, null, "$OK:TRACKING")); diff --git a/test/org/traccar/protocol/Jt600ProtocolDecoderTest.java b/test/org/traccar/protocol/Jt600ProtocolDecoderTest.java index 8f5f4db55..11b4ef1e4 100644 --- a/test/org/traccar/protocol/Jt600ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Jt600ProtocolDecoderTest.java @@ -12,7 +12,7 @@ public class Jt600ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Jt600ProtocolDecoder decoder = new Jt600ProtocolDecoder(null); + Jt600ProtocolDecoder decoder = new Jt600ProtocolDecoder(new Jt600Protocol()); 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 5d9e4ef2c..7926cf9c6 100644 --- a/test/org/traccar/protocol/KhdProtocolDecoderTest.java +++ b/test/org/traccar/protocol/KhdProtocolDecoderTest.java @@ -12,7 +12,7 @@ public class KhdProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - KhdProtocolDecoder decoder = new KhdProtocolDecoder(null); + KhdProtocolDecoder decoder = new KhdProtocolDecoder(new KhdProtocol()); 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 e74c2d411..42d474023 100644 --- a/test/org/traccar/protocol/LaipacProtocolDecoderTest.java +++ b/test/org/traccar/protocol/LaipacProtocolDecoderTest.java @@ -10,7 +10,7 @@ public class LaipacProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - LaipacProtocolDecoder decoder = new LaipacProtocolDecoder(null); + LaipacProtocolDecoder decoder = new LaipacProtocolDecoder(new LaipacProtocol()); 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 ceb248fb5..8c0ff3b8c 100644 --- a/test/org/traccar/protocol/M2mProtocolDecoderTest.java +++ b/test/org/traccar/protocol/M2mProtocolDecoderTest.java @@ -12,7 +12,7 @@ public class M2mProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - M2mProtocolDecoder decoder = new M2mProtocolDecoder(null); + M2mProtocolDecoder decoder = new M2mProtocolDecoder(new M2mProtocol()); 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 d5a722019..0d7a9ee5b 100644 --- a/test/org/traccar/protocol/ManPowerProtocolDecoderTest.java +++ b/test/org/traccar/protocol/ManPowerProtocolDecoderTest.java @@ -9,7 +9,7 @@ public class ManPowerProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - ManPowerProtocolDecoder decoder = new ManPowerProtocolDecoder(null); + ManPowerProtocolDecoder decoder = new ManPowerProtocolDecoder(new ManPowerProtocol()); 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 dd044990f..cb112914b 100644 --- a/test/org/traccar/protocol/MegastekProtocolDecoderTest.java +++ b/test/org/traccar/protocol/MegastekProtocolDecoderTest.java @@ -9,7 +9,7 @@ public class MegastekProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - MegastekProtocolDecoder decoder = new MegastekProtocolDecoder(null); + MegastekProtocolDecoder decoder = new MegastekProtocolDecoder(new MegastekProtocol()); 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 620c43115..d0fdebc03 100644 --- a/test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java +++ b/test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java @@ -11,7 +11,7 @@ public class MeiligaoProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - MeiligaoProtocolDecoder decoder = new MeiligaoProtocolDecoder(null); + MeiligaoProtocolDecoder decoder = new MeiligaoProtocolDecoder(new MeiligaoProtocol()); 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 6c3aa1b46..1bbf5e0dc 100644 --- a/test/org/traccar/protocol/MeitrackProtocolDecoderTest.java +++ b/test/org/traccar/protocol/MeitrackProtocolDecoderTest.java @@ -12,7 +12,7 @@ public class MeitrackProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - MeitrackProtocolDecoder decoder = new MeitrackProtocolDecoder(null); + MeitrackProtocolDecoder decoder = new MeitrackProtocolDecoder(new MeitrackProtocol()); verify(decoder.decode(null, null, ChannelBuffers.copiedBuffer( "$$G145,862106024274815,AAA,35,-1.287125,36.906061,150530054639,A,10,13,12,67,0.8,1621,38359791,42330881,639|2|FB2|2F3,0000,3|0|0|A58|432,,,1,0009,*26", Charset.defaultCharset()))); diff --git a/test/org/traccar/protocol/MiniFinderProtocolDecoderTest.java b/test/org/traccar/protocol/MiniFinderProtocolDecoderTest.java index 32bcfe30c..b9f62a8dd 100644 --- a/test/org/traccar/protocol/MiniFinderProtocolDecoderTest.java +++ b/test/org/traccar/protocol/MiniFinderProtocolDecoderTest.java @@ -10,7 +10,7 @@ public class MiniFinderProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - MiniFinderProtocolDecoder decoder = new MiniFinderProtocolDecoder(null); + MiniFinderProtocolDecoder decoder = new MiniFinderProtocolDecoder(new MiniFinderProtocol()); assertNull(decoder.decode(null, null, "!1,860719020212696")); diff --git a/test/org/traccar/protocol/MtxProtocolDecoderTest.java b/test/org/traccar/protocol/MtxProtocolDecoderTest.java index 2d027cbf8..d0e50295d 100644 --- a/test/org/traccar/protocol/MtxProtocolDecoderTest.java +++ b/test/org/traccar/protocol/MtxProtocolDecoderTest.java @@ -10,7 +10,7 @@ public class MtxProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - MtxProtocolDecoder decoder = new MtxProtocolDecoder(null); + MtxProtocolDecoder decoder = new MtxProtocolDecoder(new MtxProtocol()); 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/MxtProtocolDecoderTest.java b/test/org/traccar/protocol/MxtProtocolDecoderTest.java index b667957da..07e27927e 100644 --- a/test/org/traccar/protocol/MxtProtocolDecoderTest.java +++ b/test/org/traccar/protocol/MxtProtocolDecoderTest.java @@ -11,7 +11,7 @@ public class MxtProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - MxtProtocolDecoder decoder = new MxtProtocolDecoder(null); + MxtProtocolDecoder decoder = new MxtProtocolDecoder(new MxtProtocol()); verify(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, ChannelBufferTools.convertHexString( "01a631361e7a00082471418b052a2c46b587ffc01ae3fd000008800000000000003345422203000000f000f00000000000ea1e04")))); diff --git a/test/org/traccar/protocol/NavigilProtocolDecoderTest.java b/test/org/traccar/protocol/NavigilProtocolDecoderTest.java index ab72d887f..4b8b7ef33 100644 --- a/test/org/traccar/protocol/NavigilProtocolDecoderTest.java +++ b/test/org/traccar/protocol/NavigilProtocolDecoderTest.java @@ -13,7 +13,7 @@ public class NavigilProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - NavigilProtocolDecoder decoder = new NavigilProtocolDecoder(null); + NavigilProtocolDecoder decoder = new NavigilProtocolDecoder(new NavigilProtocol()); 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 bdc656b10..8cd4d951b 100644 --- a/test/org/traccar/protocol/NavisProtocolDecoderTest.java +++ b/test/org/traccar/protocol/NavisProtocolDecoderTest.java @@ -13,7 +13,7 @@ public class NavisProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - NavisProtocolDecoder decoder = new NavisProtocolDecoder(null); + NavisProtocolDecoder decoder = new NavisProtocolDecoder(new NavisProtocol()); 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 e51741835..8b1e5d2b2 100644 --- a/test/org/traccar/protocol/NoranProtocolDecoderTest.java +++ b/test/org/traccar/protocol/NoranProtocolDecoderTest.java @@ -12,7 +12,7 @@ public class NoranProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - NoranProtocolDecoder decoder = new NoranProtocolDecoder(null); + NoranProtocolDecoder decoder = new NoranProtocolDecoder(new NoranProtocol()); verify(decoder.decode(null, null, null, ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, ChannelBufferTools.convertHexString( "3400080001090000000000001D43A29BE842E62520424E523039423036363932000031322D30332D30352031313A34373A343300")))); diff --git a/test/org/traccar/protocol/OrionProtocolDecoderTest.java b/test/org/traccar/protocol/OrionProtocolDecoderTest.java index 66243ecf3..cd38ff815 100644 --- a/test/org/traccar/protocol/OrionProtocolDecoderTest.java +++ b/test/org/traccar/protocol/OrionProtocolDecoderTest.java @@ -13,7 +13,7 @@ public class OrionProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - OrionProtocolDecoder decoder = new OrionProtocolDecoder(null); + OrionProtocolDecoder decoder = new OrionProtocolDecoder(new OrionProtocol()); 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 0d20dc959..c7935b90f 100644 --- a/test/org/traccar/protocol/OsmAndProtocolDecoderTest.java +++ b/test/org/traccar/protocol/OsmAndProtocolDecoderTest.java @@ -12,7 +12,7 @@ public class OsmAndProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - OsmAndProtocolDecoder decoder = new OsmAndProtocolDecoder(null); + OsmAndProtocolDecoder decoder = new OsmAndProtocolDecoder(new OsmAndProtocol()); 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 354606817..e6bc75713 100644 --- a/test/org/traccar/protocol/PiligrimProtocolDecoderTest.java +++ b/test/org/traccar/protocol/PiligrimProtocolDecoderTest.java @@ -16,7 +16,7 @@ public class PiligrimProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - PiligrimProtocolDecoder decoder = new PiligrimProtocolDecoder(null); + PiligrimProtocolDecoder decoder = new PiligrimProtocolDecoder(new PiligrimProtocol()); 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 e12f96279..336f64257 100644 --- a/test/org/traccar/protocol/ProgressProtocolDecoderTest.java +++ b/test/org/traccar/protocol/ProgressProtocolDecoderTest.java @@ -15,7 +15,7 @@ public class ProgressProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - ProgressProtocolDecoder decoder = new ProgressProtocolDecoder(null); + ProgressProtocolDecoder decoder = new ProgressProtocolDecoder(new ProgressProtocol()); assertNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, ChannelBufferTools.convertHexString( "020037000100000003003131310f003335343836383035313339303036320f00323530303136333832383531353535010000000100000000000000e6bb97b6")))); diff --git a/test/org/traccar/protocol/Pt3000ProtocolDecoderTest.java b/test/org/traccar/protocol/Pt3000ProtocolDecoderTest.java index 22c1d5069..02046bd8d 100644 --- a/test/org/traccar/protocol/Pt3000ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Pt3000ProtocolDecoderTest.java @@ -9,7 +9,7 @@ public class Pt3000ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Pt3000ProtocolDecoder decoder = new Pt3000ProtocolDecoder(null); + Pt3000ProtocolDecoder decoder = new Pt3000ProtocolDecoder(new Pt3000Protocol()); 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 83ddef991..1987a3180 100644 --- a/test/org/traccar/protocol/Pt502ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Pt502ProtocolDecoderTest.java @@ -9,7 +9,7 @@ public class Pt502ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Pt502ProtocolDecoder decoder = new Pt502ProtocolDecoder(null); + Pt502ProtocolDecoder decoder = new Pt502ProtocolDecoder(new Pt502Protocol()); verify(decoder.decode(null, null, "$POS,11023456,033731.000,A,0335.2617,N,09841.1587,E,0.00,88.12,210615,,,A/0000,0/1f8/388900//f33//")); diff --git a/test/org/traccar/protocol/RitiProtocolDecoderTest.java b/test/org/traccar/protocol/RitiProtocolDecoderTest.java index d94772cd8..053169ae3 100644 --- a/test/org/traccar/protocol/RitiProtocolDecoderTest.java +++ b/test/org/traccar/protocol/RitiProtocolDecoderTest.java @@ -13,7 +13,7 @@ public class RitiProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - RitiProtocolDecoder decoder = new RitiProtocolDecoder(null); + RitiProtocolDecoder decoder = new RitiProtocolDecoder(new RitiProtocol()); 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 76c738251..2012edc76 100644 --- a/test/org/traccar/protocol/RuptelaProtocolDecoderTest.java +++ b/test/org/traccar/protocol/RuptelaProtocolDecoderTest.java @@ -10,7 +10,7 @@ public class RuptelaProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - RuptelaProtocolDecoder decoder = new RuptelaProtocolDecoder(null); + RuptelaProtocolDecoder decoder = new RuptelaProtocolDecoder(new RuptelaProtocol()); verify(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString( "00560003116e7438a7a50100015565cbb9000020fd21300f113f4600005f000600090d090805011b13cf00020003001c012029ad00041d31dd1e0ebd160000c50000047200000000d0000000004100016a2a960000a5a300c9ee")))); diff --git a/test/org/traccar/protocol/SanavProtocolDecoderTest.java b/test/org/traccar/protocol/SanavProtocolDecoderTest.java index c7b1335a1..f7f33843e 100644 --- a/test/org/traccar/protocol/SanavProtocolDecoderTest.java +++ b/test/org/traccar/protocol/SanavProtocolDecoderTest.java @@ -9,7 +9,7 @@ public class SanavProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - SanavProtocolDecoder decoder = new SanavProtocolDecoder(null); + SanavProtocolDecoder decoder = new SanavProtocolDecoder(new SanavProtocol()); 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 942ada8b4..0612d1243 100644 --- a/test/org/traccar/protocol/SkypatrolProtocolDecoderTest.java +++ b/test/org/traccar/protocol/SkypatrolProtocolDecoderTest.java @@ -11,7 +11,7 @@ public class SkypatrolProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - SkypatrolProtocolDecoder decoder = new SkypatrolProtocolDecoder(null); + SkypatrolProtocolDecoder decoder = new SkypatrolProtocolDecoder(new SkypatrolProtocol()); 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 4b3ec36fb..75241c903 100644 --- a/test/org/traccar/protocol/Stl060ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Stl060ProtocolDecoderTest.java @@ -8,7 +8,7 @@ public class Stl060ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Stl060ProtocolDecoder decoder = new Stl060ProtocolDecoder(null); + Stl060ProtocolDecoder decoder = new Stl060ProtocolDecoder(new Stl060Protocol()); 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 96bf1ea95..3912f4887 100644 --- a/test/org/traccar/protocol/SuntechProtocolDecoderTest.java +++ b/test/org/traccar/protocol/SuntechProtocolDecoderTest.java @@ -10,7 +10,7 @@ public class SuntechProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - SuntechProtocolDecoder decoder = new SuntechProtocolDecoder(null); + SuntechProtocolDecoder decoder = new SuntechProtocolDecoder(new SuntechProtocol()); assertNull(decoder.decode(null, null, "SA200ALV;317652")); diff --git a/test/org/traccar/protocol/SyrusProtocolDecoderTest.java b/test/org/traccar/protocol/SyrusProtocolDecoderTest.java index 1aef656e0..e7ede632b 100644 --- a/test/org/traccar/protocol/SyrusProtocolDecoderTest.java +++ b/test/org/traccar/protocol/SyrusProtocolDecoderTest.java @@ -10,7 +10,7 @@ public class SyrusProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - SyrusProtocolDecoder decoder = new SyrusProtocolDecoder(null, false); + SyrusProtocolDecoder decoder = new SyrusProtocolDecoder(new SyrusProtocol(), false); verify(decoder.decode(null, null, ">RGP230615010248-2682523-065236820000003007F4101;ID=0005;#0002;*2A<")); diff --git a/test/org/traccar/protocol/T55ProtocolDecoderTest.java b/test/org/traccar/protocol/T55ProtocolDecoderTest.java index 4a61fa6fa..9de54bbd4 100644 --- a/test/org/traccar/protocol/T55ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/T55ProtocolDecoderTest.java @@ -10,7 +10,7 @@ public class T55ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - T55ProtocolDecoder decoder = new T55ProtocolDecoder(null); + T55ProtocolDecoder decoder = new T55ProtocolDecoder(new T55Protocol()); assertNull(decoder.decode(null, null, "$GPFID,ID123456ABC")); diff --git a/test/org/traccar/protocol/TelikProtocolDecoderTest.java b/test/org/traccar/protocol/TelikProtocolDecoderTest.java index dff2f9489..07b48a2b7 100644 --- a/test/org/traccar/protocol/TelikProtocolDecoderTest.java +++ b/test/org/traccar/protocol/TelikProtocolDecoderTest.java @@ -10,7 +10,7 @@ public class TelikProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - TelikProtocolDecoder decoder = new TelikProtocolDecoder(null); + TelikProtocolDecoder decoder = new TelikProtocolDecoder(new TelikProtocol()); 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 db151e65c..14031527e 100644 --- a/test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java +++ b/test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java @@ -12,7 +12,7 @@ public class TeltonikaProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - TeltonikaProtocolDecoder decoder = new TeltonikaProtocolDecoder(null); + TeltonikaProtocolDecoder decoder = new TeltonikaProtocolDecoder(new TeltonikaProtocol()); 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 7cdb48a9b..a7df4d5e1 100644 --- a/test/org/traccar/protocol/Tk102ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Tk102ProtocolDecoderTest.java @@ -10,7 +10,7 @@ public class Tk102ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Tk102ProtocolDecoder decoder = new Tk102ProtocolDecoder(null); + Tk102ProtocolDecoder decoder = new Tk102ProtocolDecoder(new Tk102Protocol()); assertNull(decoder.decode(null, null, "")); diff --git a/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java b/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java index 18e6142ad..223df8b56 100644 --- a/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java @@ -10,7 +10,7 @@ public class Tk103ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Tk103ProtocolDecoder decoder = new Tk103ProtocolDecoder(null); + Tk103ProtocolDecoder decoder = new Tk103ProtocolDecoder(new Tk103Protocol()); assertNull(decoder.decode(null, null, "(090411121854BP0000001234567890HSO")); diff --git a/test/org/traccar/protocol/Tlt2hProtocolDecoderTest.java b/test/org/traccar/protocol/Tlt2hProtocolDecoderTest.java index 5473f6774..ccc1ce603 100644 --- a/test/org/traccar/protocol/Tlt2hProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Tlt2hProtocolDecoderTest.java @@ -9,7 +9,7 @@ public class Tlt2hProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Tlt2hProtocolDecoder decoder = new Tlt2hProtocolDecoder(null); + Tlt2hProtocolDecoder decoder = new Tlt2hProtocolDecoder(new Tlt2hProtocol()); 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 1804b335c..d0cf08f8a 100644 --- a/test/org/traccar/protocol/TopflytechProtocolDecoderTest.java +++ b/test/org/traccar/protocol/TopflytechProtocolDecoderTest.java @@ -10,7 +10,7 @@ public class TopflytechProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - TopflytechProtocolDecoder decoder = new TopflytechProtocolDecoder(null); + TopflytechProtocolDecoder decoder = new TopflytechProtocolDecoder(new TopflytechProtocol()); 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 bd66c7677..97f78d901 100644 --- a/test/org/traccar/protocol/TotemProtocolDecoderTest.java +++ b/test/org/traccar/protocol/TotemProtocolDecoderTest.java @@ -10,7 +10,7 @@ public class TotemProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - TotemProtocolDecoder decoder = new TotemProtocolDecoder(null); + TotemProtocolDecoder decoder = new TotemProtocolDecoder(new TotemProtocol()); 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 669e84f53..6826b2f32 100644 --- a/test/org/traccar/protocol/Tr20ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Tr20ProtocolDecoderTest.java @@ -10,7 +10,7 @@ public class Tr20ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Tr20ProtocolDecoder decoder = new Tr20ProtocolDecoder(null); + Tr20ProtocolDecoder decoder = new Tr20ProtocolDecoder(new Tr20Protocol()); assertNull(decoder.decode(null, null, "%%TRACKPRO01,1")); diff --git a/test/org/traccar/protocol/Tr900ProtocolDecoderTest.java b/test/org/traccar/protocol/Tr900ProtocolDecoderTest.java index c8cd8d99c..57044a778 100644 --- a/test/org/traccar/protocol/Tr900ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Tr900ProtocolDecoderTest.java @@ -8,7 +8,7 @@ public class Tr900ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Tr900ProtocolDecoder decoder = new Tr900ProtocolDecoder(null); + Tr900ProtocolDecoder decoder = new Tr900ProtocolDecoder(new Tr900Protocol()); verify(decoder.decode(null, null, null, ">00001001,4,1,150626,131252,W05830.2978,S3137.2783,,00,348,18,00,003-000,0,3,11111011*3b!")); diff --git a/test/org/traccar/protocol/TrackboxProtocolDecoderTest.java b/test/org/traccar/protocol/TrackboxProtocolDecoderTest.java index 4319a1eed..6728fe787 100644 --- a/test/org/traccar/protocol/TrackboxProtocolDecoderTest.java +++ b/test/org/traccar/protocol/TrackboxProtocolDecoderTest.java @@ -10,7 +10,7 @@ public class TrackboxProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - TrackboxProtocolDecoder decoder = new TrackboxProtocolDecoder(null); + TrackboxProtocolDecoder decoder = new TrackboxProtocolDecoder(new TrackboxProtocol()); 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 f2cdf3332..c24b85590 100644 --- a/test/org/traccar/protocol/TramigoProtocolDecoderTest.java +++ b/test/org/traccar/protocol/TramigoProtocolDecoderTest.java @@ -15,7 +15,7 @@ public class TramigoProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - TramigoProtocolDecoder decoder = new TramigoProtocolDecoder(null); + TramigoProtocolDecoder decoder = new TramigoProtocolDecoder(new TramigoProtocol()); 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 e32838adc..b99f2a6eb 100644 --- a/test/org/traccar/protocol/TytanProtocolDecoderTest.java +++ b/test/org/traccar/protocol/TytanProtocolDecoderTest.java @@ -10,7 +10,7 @@ public class TytanProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - TytanProtocolDecoder decoder = new TytanProtocolDecoder(null); + TytanProtocolDecoder decoder = new TytanProtocolDecoder(new TytanProtocol()); verify(decoder.decode(null, null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString( "d5300000689d65556877fbd437a09d8ea89360005a23124e410201213704000907000009ffffffffffffffff0affffffffffffffff18ff63ff7f7fff65ff66ff67ff68ff69ff6b00ff6cffffffff6dff7fffffffff81ffffffff82ffff83ffffffffffffffff88ffff9600")))); diff --git a/test/org/traccar/protocol/UlbotechProtocolDecoderTest.java b/test/org/traccar/protocol/UlbotechProtocolDecoderTest.java index fca2e4bd6..e703e078a 100644 --- a/test/org/traccar/protocol/UlbotechProtocolDecoderTest.java +++ b/test/org/traccar/protocol/UlbotechProtocolDecoderTest.java @@ -13,7 +13,7 @@ public class UlbotechProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - UlbotechProtocolDecoder decoder = new UlbotechProtocolDecoder(null); + UlbotechProtocolDecoder decoder = new UlbotechProtocolDecoder(new UlbotechProtocol()); verify(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString( "f8010103545500500179009ccb4b62010e00144db906310d3f0000000000cb0304000000000404000a8123050603211860221006080000000100000000ef97f8")))); diff --git a/test/org/traccar/protocol/V680ProtocolDecoderTest.java b/test/org/traccar/protocol/V680ProtocolDecoderTest.java index 07359f890..7cba4e965 100644 --- a/test/org/traccar/protocol/V680ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/V680ProtocolDecoderTest.java @@ -10,7 +10,7 @@ public class V680ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - V680ProtocolDecoder decoder = new V680ProtocolDecoder(null); + V680ProtocolDecoder decoder = new V680ProtocolDecoder(new V680Protocol()); assertNull(decoder.decode(null, null, "#353588102019155")); diff --git a/test/org/traccar/protocol/VisiontekProtocolDecoderTest.java b/test/org/traccar/protocol/VisiontekProtocolDecoderTest.java index 19e9b3287..5d1879193 100644 --- a/test/org/traccar/protocol/VisiontekProtocolDecoderTest.java +++ b/test/org/traccar/protocol/VisiontekProtocolDecoderTest.java @@ -9,7 +9,7 @@ public class VisiontekProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - VisiontekProtocolDecoder decoder = new VisiontekProtocolDecoder(null); + VisiontekProtocolDecoder decoder = new VisiontekProtocolDecoder(new VisiontekProtocol()); //verify(decoder.decode(null, null, // "$1,AP116,05,06,15,11,48,32,1725.0460N,07824.5289E,0617,07,0,030,2091,0,0,0,1,1,1,1,20,00.0000,00.3820,00.0000,VAJRA V1.00,A#")); diff --git a/test/org/traccar/protocol/WialonProtocolDecoderTest.java b/test/org/traccar/protocol/WialonProtocolDecoderTest.java index 25d61b363..3dd1f24f7 100644 --- a/test/org/traccar/protocol/WialonProtocolDecoderTest.java +++ b/test/org/traccar/protocol/WialonProtocolDecoderTest.java @@ -10,7 +10,7 @@ public class WialonProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - WialonProtocolDecoder decoder = new WialonProtocolDecoder(null); + WialonProtocolDecoder decoder = new WialonProtocolDecoder(new WialonProtocol()); 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 45f72dd8a..dc90a0b71 100644 --- a/test/org/traccar/protocol/WondexProtocolDecoderTest.java +++ b/test/org/traccar/protocol/WondexProtocolDecoderTest.java @@ -9,7 +9,7 @@ public class WondexProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - WondexProtocolDecoder decoder = new WondexProtocolDecoder(null); + WondexProtocolDecoder decoder = new WondexProtocolDecoder(new WondexProtocol()); 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 d5c5328d4..6fa23943f 100644 --- a/test/org/traccar/protocol/Xexun2ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Xexun2ProtocolDecoderTest.java @@ -10,7 +10,7 @@ public class Xexun2ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Xexun2ProtocolDecoder decoder = new Xexun2ProtocolDecoder(null); + Xexun2ProtocolDecoder decoder = new Xexun2ProtocolDecoder(new XexunProtocol()); 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 cf66928da..879771126 100644 --- a/test/org/traccar/protocol/XexunProtocolDecoderTest.java +++ b/test/org/traccar/protocol/XexunProtocolDecoderTest.java @@ -9,7 +9,7 @@ public class XexunProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - XexunProtocolDecoder decoder = new XexunProtocolDecoder(null); + XexunProtocolDecoder decoder = new XexunProtocolDecoder(new XexunProtocol()); 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 4e6670837..cddd29f8c 100644 --- a/test/org/traccar/protocol/XirgoProtocolDecoderTest.java +++ b/test/org/traccar/protocol/XirgoProtocolDecoderTest.java @@ -9,7 +9,7 @@ public class XirgoProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - XirgoProtocolDecoder decoder = new XirgoProtocolDecoder(null); + XirgoProtocolDecoder decoder = new XirgoProtocolDecoder(new XirgoProtocol()); verify(decoder.decode(null, null, null, "$$357207059646786,4003,2015/05/19,15:54:56,-20.21422,-70.14927,37.5,1.8,0.0,11,0.8,12.9,31,297,1,0,0.0,0.0,0,1,1,1##")); diff --git a/test/org/traccar/protocol/Xt013ProtocolDecoderTest.java b/test/org/traccar/protocol/Xt013ProtocolDecoderTest.java index c7ef44607..bf93b895f 100644 --- a/test/org/traccar/protocol/Xt013ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Xt013ProtocolDecoderTest.java @@ -10,7 +10,7 @@ public class Xt013ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Xt013ProtocolDecoder decoder = new Xt013ProtocolDecoder(null); + Xt013ProtocolDecoder decoder = new Xt013ProtocolDecoder(new Xt013Protocol()); 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 b2be6fa48..253579783 100644 --- a/test/org/traccar/protocol/Xt7ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Xt7ProtocolDecoderTest.java @@ -13,7 +13,7 @@ public class Xt7ProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Xt7ProtocolDecoder decoder = new Xt7ProtocolDecoder(null); + Xt7ProtocolDecoder decoder = new Xt7ProtocolDecoder(new Xt7Protocol()); 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 30d8091a8..678a46041 100644 --- a/test/org/traccar/protocol/YwtProtocolDecoderTest.java +++ b/test/org/traccar/protocol/YwtProtocolDecoderTest.java @@ -10,7 +10,7 @@ public class YwtProtocolDecoderTest extends ProtocolDecoderTest { @Test public void testDecode() throws Exception { - YwtProtocolDecoder decoder = new YwtProtocolDecoder(null); + YwtProtocolDecoder decoder = new YwtProtocolDecoder(new YwtProtocol()); assertNull(decoder.decode(null, null, "%SN,0417061042:0,0,140117041203,404")); |