diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2013-01-15 00:19:39 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2013-01-15 00:19:39 +1300 |
commit | b5bd3e35f563825c9d40eaa04c02bc6397029219 (patch) | |
tree | 05684875856d3908fdec3c582ecbf2153a5bdfb8 | |
parent | 38fbc3e872717a1179abd00a48b600b489f9fead (diff) | |
download | traccar-server-b5bd3e35f563825c9d40eaa04c02bc6397029219.tar.gz traccar-server-b5bd3e35f563825c9d40eaa04c02bc6397029219.tar.bz2 traccar-server-b5bd3e35f563825c9d40eaa04c02bc6397029219.zip |
Pass ServerManager to every protocol decoder
50 files changed, 444 insertions, 429 deletions
diff --git a/src/org/traccar/GenericPipelineFactory.java b/src/org/traccar/BasePipelineFactory.java index 4537ac4f7..139f5e526 100644 --- a/src/org/traccar/GenericPipelineFactory.java +++ b/src/org/traccar/BasePipelineFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2012 - 2013 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,9 +26,9 @@ import org.traccar.helper.Log; import org.traccar.model.DataManager; /** - * Generic pipeline factory + * Base pipeline factory */ -public abstract class GenericPipelineFactory implements ChannelPipelineFactory { +public abstract class BasePipelineFactory implements ChannelPipelineFactory { private TrackerServer server; private DataManager dataManager; @@ -85,7 +85,7 @@ public abstract class GenericPipelineFactory implements ChannelPipelineFactory { } } - public GenericPipelineFactory(ServerManager serverManager, TrackerServer server, String protocol) { + public BasePipelineFactory(ServerManager serverManager, TrackerServer server, String protocol) { this.server = server; dataManager = serverManager.getDataManager(); loggerEnabled = serverManager.isLoggerEnabled(); @@ -120,4 +120,5 @@ public abstract class GenericPipelineFactory implements ChannelPipelineFactory { pipeline.addLast("handler", new TrackerEventHandler(dataManager)); return pipeline; } -}
\ No newline at end of file + +} diff --git a/src/org/traccar/GenericProtocolDecoder.java b/src/org/traccar/BaseProtocolDecoder.java index 440b37dcb..9b8dbb362 100644 --- a/src/org/traccar/GenericProtocolDecoder.java +++ b/src/org/traccar/BaseProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2012 - 2013 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,47 +15,38 @@ */ package org.traccar; -import java.util.Timer; -import java.util.TimerTask; -import org.jboss.netty.channel.*; import org.jboss.netty.handler.codec.oneone.OneToOneDecoder; import org.traccar.model.DataManager; /** * Base class for protocol decoders */ -public abstract class GenericProtocolDecoder extends OneToOneDecoder { +public abstract class BaseProtocolDecoder extends OneToOneDecoder { - /** - * Data manager - */ + private ServerManager serverManager; private DataManager dataManager; - /** - * Set data manager - */ public final void setDataManager(DataManager dataManager) { this.dataManager = dataManager; } - /** - * Return data manager - */ public final DataManager getDataManager() { return dataManager; } - /** - * Default constructor - */ - public GenericProtocolDecoder() { + public final void setServerManager(ServerManager serverManager) { + this.serverManager = serverManager; } - /** - * Initialize - */ - public GenericProtocolDecoder(DataManager dataManager) { - setDataManager(dataManager); + public final ServerManager getServerManager() { + return serverManager; + } + + public BaseProtocolDecoder() { + } + + public BaseProtocolDecoder(ServerManager serverManager) { + this.serverManager = serverManager; } } diff --git a/src/org/traccar/ServerManager.java b/src/org/traccar/ServerManager.java index 68c537cba..b1cd51040 100644 --- a/src/org/traccar/ServerManager.java +++ b/src/org/traccar/ServerManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2012 - 2013 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -234,7 +234,7 @@ public class ServerManager { protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new XexunFrameDecoder()); pipeline.addLast("stringDecoder", new StringDecoder()); - pipeline.addLast("objectDecoder", new XexunProtocolDecoder(getDataManager())); + pipeline.addLast("objectDecoder", new XexunProtocolDecoder(ServerManager.this)); } }); } @@ -250,7 +250,7 @@ public class ServerManager { new DelimiterBasedFrameDecoder(1024, ChannelBuffers.wrappedBuffer(delimiter))); pipeline.addLast("stringDecoder", new StringDecoder()); pipeline.addLast("stringEncoder", new StringEncoder()); - pipeline.addLast("objectDecoder", new Gps103ProtocolDecoder(getDataManager())); + pipeline.addLast("objectDecoder", new Gps103ProtocolDecoder(ServerManager.this)); } }); } @@ -266,7 +266,7 @@ public class ServerManager { new DelimiterBasedFrameDecoder(1024, ChannelBuffers.wrappedBuffer(delimiter))); pipeline.addLast("stringDecoder", new StringDecoder()); pipeline.addLast("stringEncoder", new StringEncoder()); - pipeline.addLast("objectDecoder", new Tk103ProtocolDecoder(getDataManager())); + pipeline.addLast("objectDecoder", new Tk103ProtocolDecoder(ServerManager.this)); } }); } @@ -282,7 +282,7 @@ public class ServerManager { new DelimiterBasedFrameDecoder(1024, ChannelBuffers.wrappedBuffer(delimiter))); pipeline.addLast("stringDecoder", new StringDecoder()); pipeline.addLast("stringEncoder", new StringEncoder()); - pipeline.addLast("objectDecoder", new Gl100ProtocolDecoder(getDataManager())); + pipeline.addLast("objectDecoder", new Gl100ProtocolDecoder(ServerManager.this)); } }); } @@ -298,7 +298,7 @@ public class ServerManager { new DelimiterBasedFrameDecoder(1024, ChannelBuffers.wrappedBuffer(delimiter))); pipeline.addLast("stringDecoder", new StringDecoder()); pipeline.addLast("stringEncoder", new StringEncoder()); - pipeline.addLast("objectDecoder", new Gl200ProtocolDecoder(getDataManager())); + pipeline.addLast("objectDecoder", new Gl200ProtocolDecoder(ServerManager.this)); } }); } @@ -314,7 +314,7 @@ public class ServerManager { new DelimiterBasedFrameDecoder(1024, ChannelBuffers.wrappedBuffer(delimiter))); pipeline.addLast("stringDecoder", new StringDecoder()); pipeline.addLast("stringEncoder", new StringEncoder()); - pipeline.addLast("objectDecoder", new T55ProtocolDecoder(getDataManager())); + pipeline.addLast("objectDecoder", new T55ProtocolDecoder(ServerManager.this)); } }); } @@ -329,7 +329,7 @@ public class ServerManager { pipeline.addLast("frameDecoder", new DelimiterBasedFrameDecoder(1024, ChannelBuffers.wrappedBuffer(delimiter))); pipeline.addLast("stringDecoder", new StringDecoder()); - pipeline.addLast("objectDecoder", new Xexun2ProtocolDecoder(getDataManager())); + pipeline.addLast("objectDecoder", new Xexun2ProtocolDecoder(ServerManager.this)); } }); } @@ -344,7 +344,7 @@ public class ServerManager { pipeline.addLast("frameDecoder", new DelimiterBasedFrameDecoder(1024, ChannelBuffers.wrappedBuffer(delimiter))); pipeline.addLast("stringDecoder", new StringDecoder()); - pipeline.addLast("objectDecoder", new Avl08ProtocolDecoder(getDataManager())); + pipeline.addLast("objectDecoder", new Avl08ProtocolDecoder(ServerManager.this)); } }); } @@ -356,7 +356,7 @@ public class ServerManager { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 0, 2, -2, 2)); - pipeline.addLast("objectDecoder", new EnforaProtocolDecoder(getDataManager())); + pipeline.addLast("objectDecoder", new EnforaProtocolDecoder(ServerManager.this)); } }); } @@ -368,7 +368,7 @@ public class ServerManager { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 2, 2, -4, 4)); - pipeline.addLast("objectDecoder", new MeiligaoProtocolDecoder(getDataManager())); + pipeline.addLast("objectDecoder", new MeiligaoProtocolDecoder(ServerManager.this)); } }); } @@ -384,7 +384,7 @@ public class ServerManager { new DelimiterBasedFrameDecoder(1024, ChannelBuffers.wrappedBuffer(delimiter))); pipeline.addLast("stringDecoder", new StringDecoder()); pipeline.addLast("stringEncoder", new StringEncoder()); - pipeline.addLast("objectDecoder", new MaxonProtocolDecoder(getDataManager())); + pipeline.addLast("objectDecoder", new MaxonProtocolDecoder(ServerManager.this)); } }); } @@ -399,7 +399,7 @@ public class ServerManager { pipeline.addLast("frameDecoder", new DelimiterBasedFrameDecoder(1024, ChannelBuffers.wrappedBuffer(delimiter))); pipeline.addLast("stringDecoder", new StringDecoder()); - pipeline.addLast("objectDecoder", new ST210ProtocolDecoder(getDataManager())); + pipeline.addLast("objectDecoder", new ST210ProtocolDecoder(ServerManager.this)); } }); } @@ -411,7 +411,7 @@ public class ServerManager { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 2, 2, 0, 0)); - pipeline.addLast("objectDecoder", new ProgressProtocolDecoder(getDataManager())); + pipeline.addLast("objectDecoder", new ProgressProtocolDecoder(ServerManager.this)); } }); } @@ -426,7 +426,7 @@ public class ServerManager { pipeline.addLast("frameDecoder", new DelimiterBasedFrameDecoder(1024, ChannelBuffers.wrappedBuffer(delimiter))); pipeline.addLast("stringDecoder", new StringDecoder()); - pipeline.addLast("objectDecoder", new H02ProtocolDecoder(getDataManager())); + pipeline.addLast("objectDecoder", new H02ProtocolDecoder(ServerManager.this)); } }); } @@ -438,7 +438,7 @@ public class ServerManager { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new Jt600FrameDecoder()); - pipeline.addLast("objectDecoder", new Jt600ProtocolDecoder(getDataManager())); + pipeline.addLast("objectDecoder", new Jt600ProtocolDecoder(ServerManager.this)); } }); } @@ -453,7 +453,7 @@ public class ServerManager { pipeline.addLast("frameDecoder", new DelimiterBasedFrameDecoder(1024, ChannelBuffers.wrappedBuffer(delimiter))); pipeline.addLast("stringDecoder", new StringDecoder()); - pipeline.addLast("objectDecoder", new Ev603ProtocolDecoder(getDataManager())); + pipeline.addLast("objectDecoder", new Ev603ProtocolDecoder(ServerManager.this)); } }); } @@ -468,7 +468,7 @@ public class ServerManager { pipeline.addLast("frameDecoder", new DelimiterBasedFrameDecoder(1024, ChannelBuffers.wrappedBuffer(delimiter))); pipeline.addLast("stringDecoder", new StringDecoder()); - pipeline.addLast("objectDecoder", new V680ProtocolDecoder(getDataManager())); + pipeline.addLast("objectDecoder", new V680ProtocolDecoder(ServerManager.this)); } }); } @@ -484,7 +484,7 @@ public class ServerManager { new DelimiterBasedFrameDecoder(1024, ChannelBuffers.wrappedBuffer(delimiter))); pipeline.addLast("stringDecoder", new StringDecoder()); pipeline.addLast("stringEncoder", new StringEncoder()); - pipeline.addLast("objectDecoder", new Pt502ProtocolDecoder(getDataManager())); + pipeline.addLast("objectDecoder", new Pt502ProtocolDecoder(ServerManager.this)); } }); } @@ -500,7 +500,7 @@ public class ServerManager { new DelimiterBasedFrameDecoder(1024, ChannelBuffers.wrappedBuffer(delimiter))); pipeline.addLast("stringDecoder", new StringDecoder()); pipeline.addLast("stringEncoder", new StringEncoder()); - pipeline.addLast("objectDecoder", new Tr20ProtocolDecoder(getDataManager())); + pipeline.addLast("objectDecoder", new Tr20ProtocolDecoder(ServerManager.this)); } }); } @@ -512,7 +512,7 @@ public class ServerManager { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(4 * 1024, 12, 2, 2, 0)); - pipeline.addLast("objectDecoder", new NavisProtocolDecoder(getDataManager())); + pipeline.addLast("objectDecoder", new NavisProtocolDecoder(ServerManager.this)); } }); } @@ -528,7 +528,7 @@ public class ServerManager { new DelimiterBasedFrameDecoder(1024, ChannelBuffers.wrappedBuffer(delimiter))); pipeline.addLast("stringDecoder", new StringDecoder()); pipeline.addLast("stringEncoder", new StringEncoder()); - pipeline.addLast("objectDecoder", new MeitrackProtocolDecoder(getDataManager())); + pipeline.addLast("objectDecoder", new MeitrackProtocolDecoder(ServerManager.this)); } }); } @@ -539,7 +539,7 @@ public class ServerManager { serverList.add(new TrackerServer(this, new ConnectionlessBootstrap(), protocol) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { - pipeline.addLast("objectDecoder", new SkypatrolProtocolDecoder(getDataManager())); + pipeline.addLast("objectDecoder", new SkypatrolProtocolDecoder(ServerManager.this)); } }); } @@ -551,7 +551,7 @@ public class ServerManager { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(256, 2, 1, 2, 0)); - pipeline.addLast("objectDecoder", new Gt02ProtocolDecoder(getDataManager())); + pipeline.addLast("objectDecoder", new Gt02ProtocolDecoder(ServerManager.this)); } }); } @@ -563,7 +563,7 @@ public class ServerManager { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(256, 2, 1, 2, 0)); - pipeline.addLast("objectDecoder", new Gt06ProtocolDecoder(getDataManager())); + pipeline.addLast("objectDecoder", new Gt06ProtocolDecoder(ServerManager.this)); } }); } diff --git a/src/org/traccar/TrackerServer.java b/src/org/traccar/TrackerServer.java index 36c0ce70e..1d7185fe6 100644 --- a/src/org/traccar/TrackerServer.java +++ b/src/org/traccar/TrackerServer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2012 - 2013 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -52,7 +52,7 @@ public abstract class TrackerServer { String portProperty = serverManager.getProperties().getProperty(protocol + ".port"); port = (portProperty != null) ? Integer.valueOf(portProperty) : 5000; - bootstrap.setPipelineFactory(new GenericPipelineFactory(serverManager, this, protocol) { + bootstrap.setPipelineFactory(new BasePipelineFactory(serverManager, this, protocol) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { TrackerServer.this.addSpecificHandlers(pipeline); diff --git a/src/org/traccar/protocol/Avl08ProtocolDecoder.java b/src/org/traccar/protocol/Avl08ProtocolDecoder.java index a01771c35..488008be4 100644 --- a/src/org/traccar/protocol/Avl08ProtocolDecoder.java +++ b/src/org/traccar/protocol/Avl08ProtocolDecoder.java @@ -21,21 +21,21 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; -import org.traccar.GenericProtocolDecoder; +import org.traccar.BaseProtocolDecoder; +import org.traccar.ServerManager; import org.traccar.helper.Log; -import org.traccar.model.DataManager; import org.traccar.model.Position; /** * AVL-08 tracker protocol decoder */ -public class Avl08ProtocolDecoder extends GenericProtocolDecoder { +public class Avl08ProtocolDecoder extends BaseProtocolDecoder { /** * Initialize */ - public Avl08ProtocolDecoder(DataManager dataManager) { - super(dataManager); + public Avl08ProtocolDecoder(ServerManager serverManager) { + super(serverManager); } /** diff --git a/src/org/traccar/protocol/EnforaProtocolDecoder.java b/src/org/traccar/protocol/EnforaProtocolDecoder.java index aa6dbaf13..e389e0fdd 100644 --- a/src/org/traccar/protocol/EnforaProtocolDecoder.java +++ b/src/org/traccar/protocol/EnforaProtocolDecoder.java @@ -23,22 +23,22 @@ import java.util.regex.Pattern; import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; -import org.traccar.GenericProtocolDecoder; +import org.traccar.BaseProtocolDecoder; +import org.traccar.ServerManager; import org.traccar.helper.ChannelBufferTools; import org.traccar.helper.Log; -import org.traccar.model.DataManager; import org.traccar.model.Position; /** * Enfora protocol decoder */ -public class EnforaProtocolDecoder extends GenericProtocolDecoder { +public class EnforaProtocolDecoder extends BaseProtocolDecoder { /** * Initialize */ - public EnforaProtocolDecoder(DataManager dataManager) { - super(dataManager); + public EnforaProtocolDecoder(ServerManager serverManager) { + super(serverManager); } /** diff --git a/src/org/traccar/protocol/Ev603ProtocolDecoder.java b/src/org/traccar/protocol/Ev603ProtocolDecoder.java index 6d89120a8..e80717cdf 100644 --- a/src/org/traccar/protocol/Ev603ProtocolDecoder.java +++ b/src/org/traccar/protocol/Ev603ProtocolDecoder.java @@ -1,7 +1,7 @@ /*
* Copyright 2012 Anton Tananaev (anton.tananaev@gmail.com)
* Luis Parada (luis.parada@gmail.com)
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -22,28 +22,28 @@ import java.util.regex.Matcher; import java.util.regex.Pattern;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
-import org.traccar.GenericProtocolDecoder;
+import org.traccar.BaseProtocolDecoder;
+import org.traccar.ServerManager;
import org.traccar.helper.Log;
-import org.traccar.model.DataManager;
import org.traccar.model.Position;
/**
* Ev603 Protocol Decoder
*/
-public class Ev603ProtocolDecoder extends GenericProtocolDecoder{
+public class Ev603ProtocolDecoder extends BaseProtocolDecoder{
/**
* Device ID
*/
private Long deviceId;
-
+
/**
* Initialize
*/
- public Ev603ProtocolDecoder(DataManager dataManager) {
- super(dataManager);
+ public Ev603ProtocolDecoder(ServerManager serverManager) {
+ super(serverManager);
}
-
+
/**
* Regular expressions pattern
*/
@@ -76,20 +76,20 @@ public class Ev603ProtocolDecoder extends GenericProtocolDecoder{ return null;
}
}
-
+
else if (sentence.startsWith("!A,")) {
// Parse message
Matcher parser = pattern.matcher(sentence);
if (!parser.matches()) {
return null;
}
-
+
// Create new position
Position position = new Position();
position.setDeviceId(deviceId);
StringBuilder extendedInfo = new StringBuilder("<protocol>ev603</protocol>");
Integer index = 1;
-
+
// Date
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
time.clear();
@@ -102,7 +102,7 @@ public class Ev603ProtocolDecoder extends GenericProtocolDecoder{ time.set(Calendar.MINUTE, Integer.valueOf(parser.group(index++)));
time.set(Calendar.SECOND, Integer.valueOf(parser.group(index++)));
position.setTime(time.getTime());
-
+
// Validity
position.setValid(true);
@@ -115,13 +115,13 @@ public class Ev603ProtocolDecoder extends GenericProtocolDecoder{ // Speed
position.setSpeed(Double.valueOf(parser.group(index++)));
-
+
// Course
position.setCourse(Double.valueOf(parser.group(index++)));
-
+
// Extended info
position.setExtendedInfo(extendedInfo.toString());
-
+
return position;
}
diff --git a/src/org/traccar/protocol/Gl100ProtocolDecoder.java b/src/org/traccar/protocol/Gl100ProtocolDecoder.java index 760e91f68..d99953f24 100644 --- a/src/org/traccar/protocol/Gl100ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gl100ProtocolDecoder.java @@ -21,21 +21,21 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; -import org.traccar.GenericProtocolDecoder; +import org.traccar.BaseProtocolDecoder; +import org.traccar.ServerManager; import org.traccar.helper.Log; -import org.traccar.model.DataManager; import org.traccar.model.Position; /** * GL200 tracker protocol decoder */ -public class Gl100ProtocolDecoder extends GenericProtocolDecoder { +public class Gl100ProtocolDecoder extends BaseProtocolDecoder { /** * Initialize */ - public Gl100ProtocolDecoder(DataManager dataManager) { - super(dataManager); + public Gl100ProtocolDecoder(ServerManager serverManager) { + super(serverManager); } /** diff --git a/src/org/traccar/protocol/Gl200ProtocolDecoder.java b/src/org/traccar/protocol/Gl200ProtocolDecoder.java index 019c839cd..639c9439a 100644 --- a/src/org/traccar/protocol/Gl200ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gl200ProtocolDecoder.java @@ -21,21 +21,21 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; -import org.traccar.GenericProtocolDecoder; +import org.traccar.BaseProtocolDecoder; +import org.traccar.ServerManager; import org.traccar.helper.Log; -import org.traccar.model.DataManager; import org.traccar.model.Position; /** * GL200 tracker protocol decoder */ -public class Gl200ProtocolDecoder extends GenericProtocolDecoder { +public class Gl200ProtocolDecoder extends BaseProtocolDecoder { /** * Initialize */ - public Gl200ProtocolDecoder(DataManager dataManager) { - super(dataManager); + public Gl200ProtocolDecoder(ServerManager serverManager) { + super(serverManager); } /** diff --git a/src/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/org/traccar/protocol/Gps103ProtocolDecoder.java index 935697c51..e79ae109f 100644 --- a/src/org/traccar/protocol/Gps103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gps103ProtocolDecoder.java @@ -21,21 +21,21 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; -import org.traccar.GenericProtocolDecoder; +import org.traccar.BaseProtocolDecoder; +import org.traccar.ServerManager; import org.traccar.helper.Log; -import org.traccar.model.DataManager; import org.traccar.model.Position; /** * Gps 103 tracker protocol decoder */ -public class Gps103ProtocolDecoder extends GenericProtocolDecoder { +public class Gps103ProtocolDecoder extends BaseProtocolDecoder { /** * Initialize */ - public Gps103ProtocolDecoder(DataManager dataManager) { - super(dataManager); + public Gps103ProtocolDecoder(ServerManager serverManager) { + super(serverManager); } /** diff --git a/src/org/traccar/protocol/Gt02ProtocolDecoder.java b/src/org/traccar/protocol/Gt02ProtocolDecoder.java index 69d54cb5b..16b2955d5 100644 --- a/src/org/traccar/protocol/Gt02ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gt02ProtocolDecoder.java @@ -21,23 +21,23 @@ import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; -import org.traccar.GenericProtocolDecoder; +import org.traccar.BaseProtocolDecoder; +import org.traccar.ServerManager; import org.traccar.helper.Log; -import org.traccar.model.DataManager; import org.traccar.model.Position; /** * T55 tracker protocol decoder */ -public class Gt02ProtocolDecoder extends GenericProtocolDecoder { +public class Gt02ProtocolDecoder extends BaseProtocolDecoder { /** * Initialize */ - public Gt02ProtocolDecoder(DataManager dataManager) { - super(dataManager); + public Gt02ProtocolDecoder(ServerManager serverManager) { + super(serverManager); } - + private String readImei(ChannelBuffer buf) { int b = buf.readUnsignedByte(); StringBuilder imei = new StringBuilder(); @@ -52,7 +52,7 @@ public class Gt02ProtocolDecoder extends GenericProtocolDecoder { private static final int MSG_HEARTBEAT = 0x1A; private static final int MSG_DATA = 0x10; - + /** * Decode message */ @@ -62,38 +62,38 @@ public class Gt02ProtocolDecoder extends GenericProtocolDecoder { throws Exception { ChannelBuffer buf = (ChannelBuffer) msg; - + buf.skipBytes(2); // header buf.readByte(); // size - + // Zero for location messages buf.readByte(); // voltage buf.readByte(); // gsm signal - + String imei = readImei(buf); long index = buf.readUnsignedShort(); int type = buf.readUnsignedByte(); - + if (type == MSG_HEARTBEAT) { if (channel != null) { byte[] response = {0x54, 0x68, 0x1A, 0x0D, 0x0A}; channel.write(ChannelBuffers.wrappedBuffer(response)); } } - + else if (type == MSG_DATA) { - + // Create new position Position position = new Position(); position.setId(index); - + // Get device id try { position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); } catch(Exception error) { Log.warning("Unknown device - " + imei); } - + // Date and time Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); time.clear(); @@ -104,27 +104,27 @@ public class Gt02ProtocolDecoder extends GenericProtocolDecoder { time.set(Calendar.MINUTE, buf.readUnsignedByte()); time.set(Calendar.SECOND, buf.readUnsignedByte()); position.setTime(time.getTime()); - + // Latitude double latitude = buf.readUnsignedInt() / (60.0 * 30000.0); - + // Longitude double longitude = buf.readUnsignedInt() / (60.0 * 30000.0); - + // Speed position.setSpeed((double) buf.readUnsignedByte()); - + // Course position.setCourse((double) buf.readUnsignedShort()); - + buf.skipBytes(3); // reserved - + // Flags long flags = buf.readUnsignedInt(); position.setValid((flags & 0x1) == 0x1); if ((flags & 0x2) == 0) latitude = -latitude; if ((flags & 0x4) == 0) longitude = -longitude; - + position.setLatitude(latitude); position.setLongitude(longitude); position.setAltitude(0.0); diff --git a/src/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/org/traccar/protocol/Gt06ProtocolDecoder.java index 0005df19b..a3306dc97 100644 --- a/src/org/traccar/protocol/Gt06ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gt06ProtocolDecoder.java @@ -21,24 +21,24 @@ import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; -import org.traccar.GenericProtocolDecoder; +import org.traccar.BaseProtocolDecoder; +import org.traccar.ServerManager; import org.traccar.helper.Crc; import org.traccar.helper.Log; -import org.traccar.model.DataManager; import org.traccar.model.Position; /** * T55 tracker protocol decoder */ -public class Gt06ProtocolDecoder extends GenericProtocolDecoder { +public class Gt06ProtocolDecoder extends BaseProtocolDecoder { private Long deviceId; /** * Initialize */ - public Gt06ProtocolDecoder(DataManager dataManager) { - super(dataManager); + public Gt06ProtocolDecoder(ServerManager serverManager) { + super(serverManager); } private String readImei(ChannelBuffer buf) { diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java index 2d4fb9a21..d09343bcd 100644 --- a/src/org/traccar/protocol/H02ProtocolDecoder.java +++ b/src/org/traccar/protocol/H02ProtocolDecoder.java @@ -21,21 +21,21 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; -import org.traccar.GenericProtocolDecoder; +import org.traccar.BaseProtocolDecoder; +import org.traccar.ServerManager; import org.traccar.helper.Log; -import org.traccar.model.DataManager; import org.traccar.model.Position; /** * H02 tracker protocol decoder */ -public class H02ProtocolDecoder extends GenericProtocolDecoder { +public class H02ProtocolDecoder extends BaseProtocolDecoder { /** * Initialize */ - public H02ProtocolDecoder(DataManager dataManager) { - super(dataManager); + public H02ProtocolDecoder(ServerManager serverManager) { + super(serverManager); } /** diff --git a/src/org/traccar/protocol/Jt600ProtocolDecoder.java b/src/org/traccar/protocol/Jt600ProtocolDecoder.java index d765c1b42..6a8f9da52 100644 --- a/src/org/traccar/protocol/Jt600ProtocolDecoder.java +++ b/src/org/traccar/protocol/Jt600ProtocolDecoder.java @@ -23,33 +23,33 @@ import java.util.regex.Pattern; import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; -import org.traccar.GenericProtocolDecoder; +import org.traccar.BaseProtocolDecoder; +import org.traccar.ServerManager; import org.traccar.helper.ChannelBufferTools; import org.traccar.helper.Log; -import org.traccar.model.DataManager; import org.traccar.model.Position; /** * JT600 protocol decoder */ -public class Jt600ProtocolDecoder extends GenericProtocolDecoder { +public class Jt600ProtocolDecoder extends BaseProtocolDecoder { /** * Initialize */ - public Jt600ProtocolDecoder(DataManager dataManager) { - super(dataManager); + public Jt600ProtocolDecoder(ServerManager serverManager) { + super(serverManager); } /** * Decode regular message */ private Position decodeNormalMessage(ChannelBuffer buf) throws Exception { - + Position position = new Position(); - + buf.readByte(); // header - + // Get device by identifier String id = Long.valueOf(ChannelBufferTools.readHexString(buf, 10)).toString(); try { @@ -58,11 +58,11 @@ public class Jt600ProtocolDecoder extends GenericProtocolDecoder { Log.warning("Unknown device - " + id); return null; } - + buf.readByte(); // protocol version + data type - + buf.readBytes(2); // length - + // Time Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); time.clear(); @@ -73,7 +73,7 @@ public class Jt600ProtocolDecoder extends GenericProtocolDecoder { time.set(Calendar.MINUTE, ChannelBufferTools.readHexInteger(buf, 2)); time.set(Calendar.SECOND, ChannelBufferTools.readHexInteger(buf, 2)); position.setTime(time.getTime()); - + // Coordinates int temp = ChannelBufferTools.readHexInteger(buf, 8); double latitude = temp % 1000000; @@ -83,7 +83,7 @@ public class Jt600ProtocolDecoder extends GenericProtocolDecoder { double longitude = temp % 1000000; longitude /= 60 * 10000; longitude += temp / 1000000; - + // Flags byte flags = buf.readByte(); position.setValid((flags & 0x1) == 0x1); @@ -91,7 +91,7 @@ public class Jt600ProtocolDecoder extends GenericProtocolDecoder { position.setLatitude(latitude); if ((flags & 0x4) == 0) longitude = -longitude; position.setLongitude(longitude); - + // Speed double speed = ChannelBufferTools.readHexInteger(buf, 2); position.setSpeed(speed); @@ -99,26 +99,26 @@ public class Jt600ProtocolDecoder extends GenericProtocolDecoder { // Course double course = buf.readUnsignedByte() * 2; position.setCourse(course); - + buf.readByte(); // number of satellites - + // Course double power = buf.readUnsignedByte(); position.setPower(power); - + buf.readByte(); // other flags and sensors - + // Altitude double altitude = buf.readUnsignedShort(); position.setAltitude(altitude); - + buf.readUnsignedShort(); // cell id buf.readUnsignedShort(); // lac - + buf.readUnsignedByte(); // gsm signal - + buf.readUnsignedByte(); // message number - + return position; } @@ -150,7 +150,7 @@ public class Jt600ProtocolDecoder extends GenericProtocolDecoder { private Position decodeAlertMessage(ChannelBuffer buf) throws Exception { String message = buf.toString(Charset.defaultCharset()); - + // Parse message Matcher parser = pattern.matcher(message); if (!parser.matches()) { @@ -175,7 +175,7 @@ public class Jt600ProtocolDecoder extends GenericProtocolDecoder { lonlitude += Double.valueOf(parser.group(index++)) / 60; if (parser.group(index++).compareTo("W") == 0) lonlitude = -lonlitude; position.setLongitude(lonlitude); - + // Latitude Double latitude = Double.valueOf(parser.group(index++)); latitude += Double.valueOf(parser.group(index++)) / 60; @@ -184,7 +184,7 @@ public class Jt600ProtocolDecoder extends GenericProtocolDecoder { // Validity position.setValid(parser.group(index++).compareTo("A") == 0 ? true : false); - + // Time Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); time.clear(); @@ -204,7 +204,7 @@ public class Jt600ProtocolDecoder extends GenericProtocolDecoder { // Power position.setPower(Double.valueOf(parser.group(index++))); - + return position; } diff --git a/src/org/traccar/protocol/MaxonProtocolDecoder.java b/src/org/traccar/protocol/MaxonProtocolDecoder.java index 9bad2c965..c5b53bab0 100644 --- a/src/org/traccar/protocol/MaxonProtocolDecoder.java +++ b/src/org/traccar/protocol/MaxonProtocolDecoder.java @@ -21,9 +21,9 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; -import org.traccar.GenericProtocolDecoder; +import org.traccar.BaseProtocolDecoder; +import org.traccar.ServerManager; import org.traccar.helper.Log; -import org.traccar.model.DataManager; import org.traccar.model.Position; /** @@ -33,7 +33,7 @@ import org.traccar.model.Position; * It sends its identity after the GPRMC sentence, and with the type * GPFID. */ -public class MaxonProtocolDecoder extends GenericProtocolDecoder { +public class MaxonProtocolDecoder extends BaseProtocolDecoder { /** * Device ID @@ -43,8 +43,8 @@ public class MaxonProtocolDecoder extends GenericProtocolDecoder { /** * Initialize */ - public MaxonProtocolDecoder(DataManager dataManager) { - super(dataManager); + public MaxonProtocolDecoder(ServerManager serverManager) { + super(serverManager); } /** diff --git a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java index 0ba9568ba..e5c2a9845 100644 --- a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java +++ b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java @@ -25,22 +25,22 @@ import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.buffer.HeapChannelBufferFactory; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; -import org.traccar.GenericProtocolDecoder; +import org.traccar.BaseProtocolDecoder; +import org.traccar.ServerManager; import org.traccar.helper.Crc; import org.traccar.helper.Log; -import org.traccar.model.DataManager; import org.traccar.model.Position; /** * Meiligao protocol decoder */ -public class MeiligaoProtocolDecoder extends GenericProtocolDecoder { +public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { /** * Initialize */ - public MeiligaoProtocolDecoder(DataManager dataManager) { - super(dataManager); + public MeiligaoProtocolDecoder(ServerManager serverManager) { + super(serverManager); } /** diff --git a/src/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/org/traccar/protocol/MeitrackProtocolDecoder.java index 6bb9a915f..87d222c37 100644 --- a/src/org/traccar/protocol/MeitrackProtocolDecoder.java +++ b/src/org/traccar/protocol/MeitrackProtocolDecoder.java @@ -21,21 +21,21 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; -import org.traccar.GenericProtocolDecoder; +import org.traccar.BaseProtocolDecoder; +import org.traccar.ServerManager; import org.traccar.helper.Log; -import org.traccar.model.DataManager; import org.traccar.model.Position; /** * Meitrack protocol decoder */ -public class MeitrackProtocolDecoder extends GenericProtocolDecoder { +public class MeitrackProtocolDecoder extends BaseProtocolDecoder { /** * Initialize */ - public MeitrackProtocolDecoder(DataManager dataManager) { - super(dataManager); + public MeitrackProtocolDecoder(ServerManager serverManager) { + super(serverManager); } /** @@ -94,11 +94,11 @@ public class MeitrackProtocolDecoder extends GenericProtocolDecoder { extendedInfo.append("<event>"); extendedInfo.append(parser.group(index++)); extendedInfo.append("</event>"); - + // Coordinates position.setLatitude(Double.valueOf(parser.group(index++))); position.setLongitude(Double.valueOf(parser.group(index++))); - + // Time Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); time.clear(); @@ -109,10 +109,10 @@ public class MeitrackProtocolDecoder extends GenericProtocolDecoder { time.set(Calendar.MINUTE, Integer.valueOf(parser.group(index++))); time.set(Calendar.SECOND, Integer.valueOf(parser.group(index++))); position.setTime(time.getTime()); - + // Validity position.setValid(parser.group(index++).compareTo("A") == 0 ? true : false); - + // Satellites extendedInfo.append("<satellites>"); extendedInfo.append(parser.group(index++)); @@ -136,7 +136,7 @@ public class MeitrackProtocolDecoder extends GenericProtocolDecoder { // Altitude position.setAltitude(Double.valueOf(parser.group(index++))); - + // Milage extendedInfo.append("<milage>"); extendedInfo.append(parser.group(index++)); diff --git a/src/org/traccar/protocol/NavisProtocolDecoder.java b/src/org/traccar/protocol/NavisProtocolDecoder.java index 291d2b87c..1c384969d 100644 --- a/src/org/traccar/protocol/NavisProtocolDecoder.java +++ b/src/org/traccar/protocol/NavisProtocolDecoder.java @@ -25,19 +25,19 @@ import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; -import org.traccar.GenericProtocolDecoder; +import org.traccar.BaseProtocolDecoder; +import org.traccar.ServerManager; import org.traccar.helper.Log; -import org.traccar.model.DataManager; import org.traccar.model.Position; /** * Navis protocol decoder */ -public class NavisProtocolDecoder extends GenericProtocolDecoder { +public class NavisProtocolDecoder extends BaseProtocolDecoder { private String prefix; private long deviceId, serverId; - + private static final Charset charset = Charset.defaultCharset(); private String imei; @@ -46,8 +46,8 @@ public class NavisProtocolDecoder extends GenericProtocolDecoder { /** * Initialize */ - public NavisProtocolDecoder(DataManager dataManager) { - super(dataManager); + public NavisProtocolDecoder(ServerManager serverManager) { + super(serverManager); } // Format types @@ -58,7 +58,7 @@ public class NavisProtocolDecoder extends GenericProtocolDecoder { public static final int F50 = 0x05; public static final int F51 = 0x15; public static final int F52 = 0x25; - + private static boolean isFormat(int type, int... types) { for (int i : types) { if (type == i) { @@ -71,7 +71,7 @@ public class NavisProtocolDecoder extends GenericProtocolDecoder { private Position parsePosition(ChannelBuffer buf) { Position position = new Position(); StringBuilder extendedInfo = new StringBuilder("<protocol>navis</protocol>"); - + position.setDeviceId(databaseDeviceId); position.setAltitude(0.0); @@ -85,14 +85,14 @@ public class NavisProtocolDecoder extends GenericProtocolDecoder { extendedInfo.append("<format>"); extendedInfo.append(format); extendedInfo.append("</format>"); - + position.setId(buf.readUnsignedInt()); // sequence number // Event type extendedInfo.append("<event>"); extendedInfo.append(buf.readUnsignedShort()); extendedInfo.append("</event>"); - + // Event time Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); time.clear(); @@ -105,22 +105,22 @@ public class NavisProtocolDecoder extends GenericProtocolDecoder { extendedInfo.append("<time>"); extendedInfo.append(time.getTimeInMillis()); extendedInfo.append("</time>"); - + // Alarm status extendedInfo.append("<alarm>"); extendedInfo.append(buf.readUnsignedByte()); extendedInfo.append("</alarm>"); - + // Modules status extendedInfo.append("<status>"); extendedInfo.append(buf.readUnsignedByte()); extendedInfo.append("</status>"); - + // GSM signal extendedInfo.append("<gsm>"); extendedInfo.append(buf.readUnsignedByte()); extendedInfo.append("</gsm>"); - + // Output extendedInfo.append("<output>"); if (isFormat(format, F10, F20, F30)) { @@ -129,7 +129,7 @@ public class NavisProtocolDecoder extends GenericProtocolDecoder { extendedInfo.append(buf.readUnsignedByte()); } extendedInfo.append("</output>"); - + // Input extendedInfo.append("<input>"); if (isFormat(format, F10, F20, F30, F40)) { @@ -138,7 +138,7 @@ public class NavisProtocolDecoder extends GenericProtocolDecoder { extendedInfo.append(buf.readUnsignedByte()); } extendedInfo.append("</input>"); - + position.setPower(buf.readUnsignedShort() / 1000.0); // power // Battery power @@ -164,13 +164,13 @@ public class NavisProtocolDecoder extends GenericProtocolDecoder { extendedInfo.append(buf.readUnsignedShort()); extendedInfo.append("</adc2>"); } - + if (isFormat(format, F20, F50, F51, F52)) { // Impulse counters buf.readUnsignedInt(); buf.readUnsignedInt(); } - + if (isFormat(format, F20, F50, F51, F52)) { // Validity int locationStatus = buf.readUnsignedByte(); @@ -185,28 +185,28 @@ public class NavisProtocolDecoder extends GenericProtocolDecoder { time.set(Calendar.MONTH, buf.readUnsignedByte()); time.set(Calendar.YEAR, 2000 + buf.readUnsignedByte()); position.setTime(time.getTime()); - + // Location data position.setLatitude(buf.readFloat() / Math.PI * 180); position.setLongitude(buf.readFloat() / Math.PI * 180); position.setSpeed((double) buf.readFloat()); position.setCourse((double) buf.readUnsignedShort()); - + // Milage extendedInfo.append("<milage>"); extendedInfo.append(buf.readFloat()); extendedInfo.append("</milage>"); - + // Last segment extendedInfo.append("<segment>"); extendedInfo.append(buf.readFloat()); extendedInfo.append("</segment>"); - + // Segment times buf.readUnsignedShort(); buf.readUnsignedShort(); } - + if (isFormat(format, F51, F52)) { // Other stuff buf.readUnsignedShort(); @@ -219,7 +219,7 @@ public class NavisProtocolDecoder extends GenericProtocolDecoder { buf.readByte(); buf.readUnsignedShort(); } - + if (isFormat(format, F40, F52)) { // Four temperature sensors buf.readByte(); @@ -233,10 +233,10 @@ public class NavisProtocolDecoder extends GenericProtocolDecoder { return position; } - + private Object processSingle(Channel channel, ChannelBuffer buf) { Position position = parsePosition(buf); - + ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 8); response.writeBytes(ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "*<T", charset)); response.writeInt(position.getId().intValue()); @@ -246,10 +246,10 @@ public class NavisProtocolDecoder extends GenericProtocolDecoder { if (position.getValid() == null) { return null; } - + return position; } - + private Object processArray(Channel channel, ChannelBuffer buf) { List<Position> positions = new LinkedList<Position>(); int count = buf.readUnsignedByte(); @@ -260,7 +260,7 @@ public class NavisProtocolDecoder extends GenericProtocolDecoder { positions.add(position); } } - + ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 8); response.writeBytes(ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "*<A", charset)); response.writeByte(count); @@ -270,10 +270,10 @@ public class NavisProtocolDecoder extends GenericProtocolDecoder { if (positions.isEmpty()) { return null; } - + return positions; } - + private Object processHandshake(Channel channel, ChannelBuffer buf) { buf.readByte(); // semicolon symbol imei = buf.toString(Charset.defaultCharset()); @@ -285,7 +285,7 @@ public class NavisProtocolDecoder extends GenericProtocolDecoder { } return null; } - + private static short checksum(ChannelBuffer buf) { short sum = 0; for (int i = 0; i < buf.readableBytes(); i++) { @@ -293,7 +293,7 @@ public class NavisProtocolDecoder extends GenericProtocolDecoder { } return sum; } - + private void sendReply(Channel channel, ChannelBuffer data) { ChannelBuffer header = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 16); header.writeBytes(ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, prefix, charset)); @@ -302,19 +302,19 @@ public class NavisProtocolDecoder extends GenericProtocolDecoder { header.writeShort(data.readableBytes()); header.writeByte(checksum(data)); header.writeByte(checksum(header)); - + if (channel != null) { channel.write(ChannelBuffers.copiedBuffer(header, data)); } } - + /** * Decode message */ protected Object decode( ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { - + ChannelBuffer buf = (ChannelBuffer) msg; // Read header @@ -324,15 +324,15 @@ public class NavisProtocolDecoder extends GenericProtocolDecoder { deviceId = buf.readUnsignedInt(); int length = buf.readUnsignedShort(); buf.skipBytes(2); // header and data XOR checksum - + if (length == 0) { return null; // keep alive message } - + // Read message type String type = buf.toString(buf.readerIndex(), 3, charset); buf.skipBytes(type.length()); - + if (type.equals("*>T")) { return processSingle(channel, buf); } else if (type.equals("*>A")) { diff --git a/src/org/traccar/protocol/ProgressProtocolDecoder.java b/src/org/traccar/protocol/ProgressProtocolDecoder.java index 35db6e113..06904711e 100644 --- a/src/org/traccar/protocol/ProgressProtocolDecoder.java +++ b/src/org/traccar/protocol/ProgressProtocolDecoder.java @@ -22,15 +22,15 @@ import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; -import org.traccar.GenericProtocolDecoder; +import org.traccar.BaseProtocolDecoder; +import org.traccar.ServerManager; import org.traccar.helper.Log; -import org.traccar.model.DataManager; import org.traccar.model.Position; /** * Progress tracker protocol decoder */ -public class ProgressProtocolDecoder extends GenericProtocolDecoder { +public class ProgressProtocolDecoder extends BaseProtocolDecoder { /** * Device ID @@ -40,8 +40,8 @@ public class ProgressProtocolDecoder extends GenericProtocolDecoder { /** * Initialize */ - public ProgressProtocolDecoder(DataManager dataManager) { - super(dataManager); + public ProgressProtocolDecoder(ServerManager serverManager) { + super(serverManager); } /* @@ -56,7 +56,7 @@ public class ProgressProtocolDecoder extends GenericProtocolDecoder { private static final int MSG_TEXT = 102; private static final int MSG_ALARM = 200; private static final int MSG_ALARM_RECIEVED = 201; - + private static final String HEX_CHARS = "0123456789ABCDEF"; /** @@ -135,7 +135,7 @@ public class ProgressProtocolDecoder extends GenericProtocolDecoder { extendedInfo.append("<milage>"); extendedInfo.append(buf.readUnsignedInt()); extendedInfo.append("</milage>"); - + long extraFlags = buf.readLong(); // Analog inputs @@ -146,7 +146,7 @@ public class ProgressProtocolDecoder extends GenericProtocolDecoder { extendedInfo.append(buf.readUnsignedShort()); extendedInfo.append("</adc").append(i).append(">"); } - + } // CAN adapter @@ -157,11 +157,11 @@ public class ProgressProtocolDecoder extends GenericProtocolDecoder { extendedInfo.append("</can>"); buf.skipBytes(size); } - + // Passenger sensor if ((extraFlags & 0x4) == 0x4) { int size = buf.readUnsignedShort(); - + // Convert binary data to hex StringBuilder hex = new StringBuilder(); for (int i = buf.readerIndex(); i < buf.readerIndex() + size; i++) { @@ -173,7 +173,7 @@ public class ProgressProtocolDecoder extends GenericProtocolDecoder { extendedInfo.append("<passenger>"); extendedInfo.append(hex); extendedInfo.append("</passenger>"); - + buf.skipBytes(size); } diff --git a/src/org/traccar/protocol/Pt502ProtocolDecoder.java b/src/org/traccar/protocol/Pt502ProtocolDecoder.java index e5f2e9224..a00913ae4 100644 --- a/src/org/traccar/protocol/Pt502ProtocolDecoder.java +++ b/src/org/traccar/protocol/Pt502ProtocolDecoder.java @@ -22,22 +22,23 @@ import java.util.regex.Matcher; import java.util.regex.Pattern;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
-import org.traccar.GenericProtocolDecoder;
+import org.traccar.BaseProtocolDecoder;
+import org.traccar.ServerManager;
import org.traccar.helper.Log;
-import org.traccar.model.DataManager;
import org.traccar.model.Position;
/**
* PT502 tracker protocol decoder
*/
-public class Pt502ProtocolDecoder extends GenericProtocolDecoder {
+public class Pt502ProtocolDecoder extends BaseProtocolDecoder {
/**
* Initialize
*/
- public Pt502ProtocolDecoder(DataManager dataManager) {
- super(dataManager);
+ public Pt502ProtocolDecoder(ServerManager serverManager) {
+ super(serverManager);
}
+
/**
* Regular expressions pattern
*/
@@ -124,7 +125,7 @@ public class Pt502ProtocolDecoder extends GenericProtocolDecoder { } else {
position.setSpeed(0.0);
}
-
+
// Course
String course = parser.group(index++);
if (course != null) {
diff --git a/src/org/traccar/protocol/ST210ProtocolDecoder.java b/src/org/traccar/protocol/ST210ProtocolDecoder.java index 642079361..d8d42eed6 100644 --- a/src/org/traccar/protocol/ST210ProtocolDecoder.java +++ b/src/org/traccar/protocol/ST210ProtocolDecoder.java @@ -8,42 +8,43 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; -import org.traccar.GenericProtocolDecoder; +import org.traccar.BaseProtocolDecoder; +import org.traccar.ServerManager; import org.traccar.helper.Log; import org.traccar.model.DataManager; import org.traccar.model.Position; -public class ST210ProtocolDecoder extends GenericProtocolDecoder { - +public class ST210ProtocolDecoder extends BaseProtocolDecoder { - public ST210ProtocolDecoder(DataManager dataManager) { - super(dataManager); + + public ST210ProtocolDecoder(ServerManager serverManager) { + super(serverManager); } private enum ST210FIELDS { - HDR_STATUS("SA200STT;","Status Report"), - HDR_EMERGENCY("SA200EMG;","Emergency Report"), - HDR_EVENT("SA200EVT;", "Event Report"), - HDR_ALERT("SA200ALT;","Alert Report"), - HDR_ALIVE("SA200ALV;","Alive Report"), - DEV_ID("(\\d+);", "Device ID"), - SW_VER("(\\d{3});", "Software Release Version"), - DATE("(\\d+);","GPS date (yyyymmdd) Year + Month + Day"), - TIME("(\\d{2}:\\d{2}:\\d{2});","GPS time (hh:mm:ss) Hour : Minute : Second"), - CELL("(\\w+);","Location Code ID (3 digits hex) + Serving Cell BSIC(2 digits decimal)"), - LAT("(-\\d{2}.\\d+);", "Latitude (+/-xx.xxxxxx)"), - LON("(-\\d{3}.\\d+);", "Longitude (+/-xxx.xxxxxx)"), - SPD("(\\d{3}.\\d{3});","Speed in km/h - This value returns to 0 when it is over than 200,000Km"), + HDR_STATUS("SA200STT;","Status Report"), + HDR_EMERGENCY("SA200EMG;","Emergency Report"), + HDR_EVENT("SA200EVT;", "Event Report"), + HDR_ALERT("SA200ALT;","Alert Report"), + HDR_ALIVE("SA200ALV;","Alive Report"), + DEV_ID("(\\d+);", "Device ID"), + SW_VER("(\\d{3});", "Software Release Version"), + DATE("(\\d+);","GPS date (yyyymmdd) Year + Month + Day"), + TIME("(\\d{2}:\\d{2}:\\d{2});","GPS time (hh:mm:ss) Hour : Minute : Second"), + CELL("(\\w+);","Location Code ID (3 digits hex) + Serving Cell BSIC(2 digits decimal)"), + LAT("(-\\d{2}.\\d+);", "Latitude (+/-xx.xxxxxx)"), + LON("(-\\d{3}.\\d+);", "Longitude (+/-xxx.xxxxxx)"), + SPD("(\\d{3}.\\d{3});","Speed in km/h - This value returns to 0 when it is over than 200,000Km"), CRS("(\\d{3}.\\d{2});", "Course over ground in degree"), SATT("(\\d+);", "Number of satellites"), - FIX("(\\d);","GPS is fixed(1)\n" + "GPS is not fixed(0)"), - DIST("(\\d+);","Traveled ddistance in meter"), - PWR_VOLT("(\\d+.\\d{2});","Voltage value of main power"), - IO("(\\d+);","Current I/O status of inputs and outputs."), + FIX("(\\d);","GPS is fixed(1)\n" + "GPS is not fixed(0)"), + DIST("(\\d+);","Traveled ddistance in meter"), + PWR_VOLT("(\\d+.\\d{2});","Voltage value of main power"), + IO("(\\d+);","Current I/O status of inputs and outputs."), MODE("(\\d);","1 = Idle mode (Parking)\n" + "2 = Active Mode (Driving)"), - MSG_NUM("(\\d{4});","Message number - After 9999 is reported, message number returns to 0000"), - EMG_ID("(\\d);", "Emergency type"), - EVT_ID("(\\d);", "Event type"), + MSG_NUM("(\\d{4});","Message number - After 9999 is reported, message number returns to 0000"), + EMG_ID("(\\d);", "Emergency type"), + EVT_ID("(\\d);", "Event type"), ALERT_ID("(\\d+);", "Alert type"); private String pattern; @@ -92,7 +93,7 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { case SPD: position.setSpeed(Double.valueOf(groupValue)); break; - + case MODE: //position.setMode(Integer.parseInt(groupValue)); break; @@ -104,15 +105,15 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { time.set(Calendar.YEAR, Integer.valueOf(Integer.valueOf(groupValue.substring(0, 4)))); time.set(Calendar.MONTH, Integer.valueOf(Integer.valueOf(groupValue.substring(4, 6))-1)); time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(Integer.valueOf(groupValue.substring(6, 8)))); - + /*Calendar ret = new GregorianCalendar(TimeZone.getTimeZone("UTC")); - - ret.setTimeInMillis(time.getTimeInMillis() + + + ret.setTimeInMillis(time.getTimeInMillis() + TimeZone.getTimeZone("UTC").getOffset(time.getTimeInMillis()) - TimeZone.getDefault().getOffset(time.getTimeInMillis()));*/ position.setTime(time.getTime()); - + break; } @@ -121,19 +122,19 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); time.clear(); time.setTime(position.getTime()); - + time.set(Calendar.HOUR_OF_DAY, Integer.valueOf(Integer.valueOf(groupValue.substring(0, 2)))); time.set(Calendar.MINUTE, Integer.valueOf(Integer.valueOf(groupValue.substring(3, 5)))); time.set(Calendar.SECOND, Integer.valueOf(Integer.valueOf(groupValue.substring(6, 8)))); /*Calendar ret = new GregorianCalendar(TimeZone.getTimeZone("UTC")); - - ret.setTimeInMillis(time.getTimeInMillis() + + + ret.setTimeInMillis(time.getTimeInMillis() + TimeZone.getTimeZone("UTC").getOffset(time.getTimeInMillis()) - TimeZone.getDefault().getOffset(time.getTimeInMillis()));*/ position.setTime(time.getTime()); - + break; } @@ -219,9 +220,9 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { } private enum FIELD_EMG_ID_VALUE { - PANIC(1, "Emergency by panic button"), - PARKING(2,"Emergency by parking lock"), - MAIN_POWER(3,"Emergency by removing main power"), + PANIC(1, "Emergency by panic button"), + PARKING(2,"Emergency by parking lock"), + MAIN_POWER(3,"Emergency by removing main power"), ANTI_THEFT(5,"Emergency by anti-theft"); private int value; @@ -263,11 +264,11 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { } private enum FIELD_EVT_ID_VALUE { - INPUT1_GROUND(1, "Input1 goes to ground state"), - INPUT1_OPEN(2,"Input1 goes to open state"), - INPUT2_GROUND(3,"Input2 goes to ground state"), - INPUT2_OPEN(4,"Input2 goes to open state"), - INPUT3_GROUND(5,"Input3 goes to ground state"), + INPUT1_GROUND(1, "Input1 goes to ground state"), + INPUT1_OPEN(2,"Input1 goes to open state"), + INPUT2_GROUND(3,"Input2 goes to ground state"), + INPUT2_OPEN(4,"Input2 goes to open state"), + INPUT3_GROUND(5,"Input3 goes to ground state"), INPUT3_OPEN(6,"Input3 goes to open state"); private int value; @@ -290,7 +291,7 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { public FIELD_EVT_ID_VALUE getValueOf(String indiceStr) { int indice = Integer.valueOf(indiceStr); return getValueOf(indice); - } + } public FIELD_EVT_ID_VALUE getValueOf(int indice) { switch (indice) { @@ -313,19 +314,19 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { } private enum FIELD_ALERT_ID_VALUE { - DRIVING_FASTER(1, "Start driving faster than SPEED_LIMIT"), - OVER_SPPED(2, "Ended over speed condition"), - DISCON_GPS(3,"Disconnected GPS antenna"), - RECON_GPS(4,"Reconnected GPS antenna after disconnected"), - OUT_GEO_FENCE(5,"The vehicle went out from the geo-fence that has following ID"), - INTO_GEO_FENCE(6,"The vehicle entered into the geo-fence that has following ID"), - SHORTED_GPS(8, "Shorted GPS antenna"), - DEEP_SLEEP_ON(9,"Enter to deep sleep mode"), - DEEP_SLEEP_OFF(10,"Exite from deep sleep mode"), - BKP_BATTERY(13,"Backup battery error"), - BATTERY_DOWN(14,"Vehicle battery goes down to so low level"), - SHOCKED(15,"Shocked"), - COLLISION(16, "Occurred some collision"), + DRIVING_FASTER(1, "Start driving faster than SPEED_LIMIT"), + OVER_SPPED(2, "Ended over speed condition"), + DISCON_GPS(3,"Disconnected GPS antenna"), + RECON_GPS(4,"Reconnected GPS antenna after disconnected"), + OUT_GEO_FENCE(5,"The vehicle went out from the geo-fence that has following ID"), + INTO_GEO_FENCE(6,"The vehicle entered into the geo-fence that has following ID"), + SHORTED_GPS(8, "Shorted GPS antenna"), + DEEP_SLEEP_ON(9,"Enter to deep sleep mode"), + DEEP_SLEEP_OFF(10,"Exite from deep sleep mode"), + BKP_BATTERY(13,"Backup battery error"), + BATTERY_DOWN(14,"Vehicle battery goes down to so low level"), + SHOCKED(15,"Shocked"), + COLLISION(16, "Occurred some collision"), DEVIATE_ROUT(18, "Deviate from predefined rout"), ENTER_ROUT(19,"Enter into predefined rout"); @@ -492,7 +493,7 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { if(patternStr.endsWith(";")){ patternStr = patternStr.substring(0, patternStr.length()-1); } - + return Pattern.compile(patternStr); } @@ -608,9 +609,9 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { public Object decode(ChannelHandlerContext ctx, Channel channel, Object msg) { String sentence = (String) msg; Log.info("Msg: " + msg); - + Position position = null; - + try{ position = decodeMsg(sentence); Log.info("MESSAGE DECODED WITH SUCCESS!"); @@ -618,7 +619,7 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { catch(Exception e){ Log.severe("ERROR WHILE DECODING MESSAGE: " + e.getMessage()); } - + return position; } @@ -639,7 +640,7 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { if(report.equals(ST210REPORTS.ALIVE)){ return null; } - + // Create new position Position position = new Position(); diff --git a/src/org/traccar/protocol/SkypatrolProtocolDecoder.java b/src/org/traccar/protocol/SkypatrolProtocolDecoder.java index 3f54fd0bf..11f9424aa 100644 --- a/src/org/traccar/protocol/SkypatrolProtocolDecoder.java +++ b/src/org/traccar/protocol/SkypatrolProtocolDecoder.java @@ -21,41 +21,41 @@ import java.util.TimeZone; import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; -import org.traccar.GenericProtocolDecoder; +import org.traccar.BaseProtocolDecoder; +import org.traccar.ServerManager; import org.traccar.helper.Log; -import org.traccar.model.DataManager; import org.traccar.model.Position; /** * T55 tracker protocol decoder */ -public class SkypatrolProtocolDecoder extends GenericProtocolDecoder { +public class SkypatrolProtocolDecoder extends BaseProtocolDecoder { /** * Initialize */ - public SkypatrolProtocolDecoder(DataManager dataManager) { - super(dataManager); + public SkypatrolProtocolDecoder(ServerManager serverManager) { + super(serverManager); } private static boolean checkBit(long mask, int bit) { long checkMask = 1 << bit; return (mask & checkMask) == checkMask; } - + private static double convertCoordinate(long coordinate) { int sign = 1; if (coordinate > 0x7fffffffl) { sign = -1; coordinate = 0xffffffffl - coordinate; } - + double degrees = coordinate / 1000000; degrees += (coordinate % 1000000) / 600000.0; - + return sign * degrees; } - + /** * Decode message */ @@ -81,18 +81,18 @@ public class SkypatrolProtocolDecoder extends GenericProtocolDecoder { commandType == 2 && messageType == 1 && checkBit(mask, 0)) { - + // Create new position Position position = new Position(); StringBuilder extendedInfo = new StringBuilder("<protocol>skypatrol</protocol>"); - + // Status code if (checkBit(mask, 1)) { extendedInfo.append("<status>"); extendedInfo.append(buf.readUnsignedInt()); extendedInfo.append("</status>"); } - + // Device id String id = null; if (checkBit(mask, 23)) { @@ -111,12 +111,12 @@ public class SkypatrolProtocolDecoder extends GenericProtocolDecoder { Log.warning("Unknown device - " + id); return null; } - + // IO data if (checkBit(mask, 3)) { buf.readUnsignedShort(); } - + // ADC 1 if (checkBit(mask, 4)) { buf.readUnsignedShort(); @@ -131,7 +131,7 @@ public class SkypatrolProtocolDecoder extends GenericProtocolDecoder { if (checkBit(mask, 7)) { buf.readUnsignedByte(); } - + Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); time.clear(); @@ -156,7 +156,7 @@ public class SkypatrolProtocolDecoder extends GenericProtocolDecoder { if (checkBit(mask, 11)) { position.setLongitude(convertCoordinate(buf.readUnsignedInt())); } - + // Speed if (checkBit(mask, 12)) { position.setSpeed(buf.readUnsignedShort() / 10.0); @@ -173,60 +173,60 @@ public class SkypatrolProtocolDecoder extends GenericProtocolDecoder { time.set(Calendar.MINUTE, buf.readUnsignedByte()); time.set(Calendar.SECOND, buf.readUnsignedByte()); } - + position.setTime(time.getTime()); - + // Altitude if (checkBit(mask, 15)) { buf.skipBytes(3); } - + // Satellites if (checkBit(mask, 16)) { extendedInfo.append("<satellites>"); extendedInfo.append(buf.readUnsignedByte()); extendedInfo.append("</satellites>"); } - + // Battery percentage if (checkBit(mask, 17)) { buf.readUnsignedShort(); } - + // Trip milage if (checkBit(mask, 20)) { extendedInfo.append("<trip>"); extendedInfo.append(buf.readUnsignedInt()); extendedInfo.append("</trip>"); } - + // Milage if (checkBit(mask, 21)) { extendedInfo.append("<milage>"); extendedInfo.append(buf.readUnsignedInt()); extendedInfo.append("</milage>"); } - + // Time of message generation if (checkBit(mask, 22)) { buf.skipBytes(6); } - + // Battery level if (checkBit(mask, 24)) { position.setPower(buf.readUnsignedShort() / 1000.0); } - + // GPS overspeed if (checkBit(mask, 25)) { buf.skipBytes(18); } - + // Cell information if (checkBit(mask, 26)) { buf.skipBytes(54); } - + // Sequence number if (checkBit(mask, 28)) { position.setId((long) buf.readUnsignedShort()); diff --git a/src/org/traccar/protocol/T55ProtocolDecoder.java b/src/org/traccar/protocol/T55ProtocolDecoder.java index 184f5e40b..8903bf3e1 100644 --- a/src/org/traccar/protocol/T55ProtocolDecoder.java +++ b/src/org/traccar/protocol/T55ProtocolDecoder.java @@ -21,15 +21,15 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; -import org.traccar.GenericProtocolDecoder; +import org.traccar.BaseProtocolDecoder; +import org.traccar.ServerManager; import org.traccar.helper.Log; -import org.traccar.model.DataManager; import org.traccar.model.Position; /** * T55 tracker protocol decoder */ -public class T55ProtocolDecoder extends GenericProtocolDecoder { +public class T55ProtocolDecoder extends BaseProtocolDecoder { /** * Device ID @@ -39,8 +39,8 @@ public class T55ProtocolDecoder extends GenericProtocolDecoder { /** * Initialize */ - public T55ProtocolDecoder(DataManager dataManager) { - super(dataManager); + public T55ProtocolDecoder(ServerManager serverManager) { + super(serverManager); } /** diff --git a/src/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java index 7145cf893..65cf6fcd0 100644 --- a/src/org/traccar/protocol/Tk103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tk103ProtocolDecoder.java @@ -21,21 +21,21 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; -import org.traccar.GenericProtocolDecoder; +import org.traccar.BaseProtocolDecoder; +import org.traccar.ServerManager; import org.traccar.helper.Log; -import org.traccar.model.DataManager; import org.traccar.model.Position; /** * Gps 103 tracker protocol decoder */ -public class Tk103ProtocolDecoder extends GenericProtocolDecoder { +public class Tk103ProtocolDecoder extends BaseProtocolDecoder { /** * Initialize */ - public Tk103ProtocolDecoder(DataManager dataManager) { - super(dataManager); + public Tk103ProtocolDecoder(ServerManager serverManager) { + super(serverManager); } /** @@ -66,7 +66,7 @@ public class Tk103ProtocolDecoder extends GenericProtocolDecoder { throws Exception { String sentence = (String) msg; - + // TODO: Send answer //(090411121854AP05) diff --git a/src/org/traccar/protocol/Tr20ProtocolDecoder.java b/src/org/traccar/protocol/Tr20ProtocolDecoder.java index 0424b70b0..95935cd29 100644 --- a/src/org/traccar/protocol/Tr20ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tr20ProtocolDecoder.java @@ -21,21 +21,21 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; -import org.traccar.GenericProtocolDecoder; +import org.traccar.BaseProtocolDecoder; +import org.traccar.ServerManager; import org.traccar.helper.Log; -import org.traccar.model.DataManager; import org.traccar.model.Position; /** * TR20 tracker protocol decoder */ -public class Tr20ProtocolDecoder extends GenericProtocolDecoder { +public class Tr20ProtocolDecoder extends BaseProtocolDecoder { /** * Initialize */ - public Tr20ProtocolDecoder(DataManager dataManager) { - super(dataManager); + public Tr20ProtocolDecoder(ServerManager serverManager) { + super(serverManager); } static private Pattern patternPing = Pattern.compile( @@ -69,16 +69,16 @@ public class Tr20ProtocolDecoder extends GenericProtocolDecoder { // Keep alive message Matcher parser = patternPing.matcher(sentence); if (parser.matches()) { - + // Send response if (channel != null) { channel.write("&&" + parser.group(1) + "\r\n"); } } else { - + // Data message parse parser = patternData.matcher(sentence); - + // Unknown message if (!parser.matches()) { return null; @@ -89,7 +89,7 @@ public class Tr20ProtocolDecoder extends GenericProtocolDecoder { StringBuilder extendedInfo = new StringBuilder("<protocol>tr20</protocol>"); Integer index = 1; - + // Get device by id String id = parser.group(index++); try { @@ -98,10 +98,10 @@ public class Tr20ProtocolDecoder extends GenericProtocolDecoder { Log.warning("Unknown device - " + id); return null; } - + // Validity position.setValid(parser.group(index++).compareTo("A") == 0 ? true : false); - + // Time Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); time.clear(); @@ -112,7 +112,7 @@ public class Tr20ProtocolDecoder extends GenericProtocolDecoder { time.set(Calendar.MINUTE, Integer.parseInt(parser.group(index++))); time.set(Calendar.SECOND, Integer.parseInt(parser.group(index++))); position.setTime(time.getTime()); - + // Latitude int hemisphere = 1; if (parser.group(index++).compareTo("S") == 0) hemisphere = -1; @@ -135,10 +135,10 @@ public class Tr20ProtocolDecoder extends GenericProtocolDecoder { // Altitude position.setAltitude(0.0); - + // Extended info position.setExtendedInfo(extendedInfo.toString()); - + return position; } diff --git a/src/org/traccar/protocol/V680ProtocolDecoder.java b/src/org/traccar/protocol/V680ProtocolDecoder.java index 57e5982dc..c8a16c377 100644 --- a/src/org/traccar/protocol/V680ProtocolDecoder.java +++ b/src/org/traccar/protocol/V680ProtocolDecoder.java @@ -21,21 +21,21 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; -import org.traccar.GenericProtocolDecoder; +import org.traccar.BaseProtocolDecoder; +import org.traccar.ServerManager; import org.traccar.helper.Log; -import org.traccar.model.DataManager; import org.traccar.model.Position; /** * V680 tracker protocol decoder */ -public class V680ProtocolDecoder extends GenericProtocolDecoder { +public class V680ProtocolDecoder extends BaseProtocolDecoder { /** * Initialize */ - public V680ProtocolDecoder(DataManager dataManager) { - super(dataManager); + public V680ProtocolDecoder(ServerManager serverManager) { + super(serverManager); } /** @@ -95,41 +95,41 @@ public class V680ProtocolDecoder extends GenericProtocolDecoder { // Validity position.setValid(parser.group(index++).compareTo("1") == 0 ? true : false); - + // Password extendedInfo.append("<password>"); extendedInfo.append(parser.group(index++)); extendedInfo.append("</password>"); - + // Packet number extendedInfo.append("<packet>"); extendedInfo.append(parser.group(index++)); extendedInfo.append("</packet>"); - + // GSM base station extendedInfo.append("<gsm>"); extendedInfo.append(parser.group(index++)); extendedInfo.append("</gsm>"); - + // Longitude Double lonlitude = Double.valueOf(parser.group(index++)); lonlitude += Double.valueOf(parser.group(index++)) / 60; if (parser.group(index++).compareTo("W") == 0) lonlitude = -lonlitude; position.setLongitude(lonlitude); - + // Latitude Double latitude = Double.valueOf(parser.group(index++)); latitude += Double.valueOf(parser.group(index++)) / 60; if (parser.group(index++).compareTo("S") == 0) latitude = -latitude; position.setLatitude(latitude); - + // Altitude position.setAltitude(0.0); // Speed and Course position.setSpeed(Double.valueOf(parser.group(index++))); position.setCourse(Double.valueOf(parser.group(index++))); - + // Date Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); time.clear(); diff --git a/src/org/traccar/protocol/Xexun2ProtocolDecoder.java b/src/org/traccar/protocol/Xexun2ProtocolDecoder.java index 54f502667..2e84ef47f 100644 --- a/src/org/traccar/protocol/Xexun2ProtocolDecoder.java +++ b/src/org/traccar/protocol/Xexun2ProtocolDecoder.java @@ -21,21 +21,21 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; -import org.traccar.GenericProtocolDecoder; +import org.traccar.BaseProtocolDecoder; +import org.traccar.ServerManager; import org.traccar.helper.Log; -import org.traccar.model.DataManager; import org.traccar.model.Position; /** * Xexun tracker protocol decoder */ -public class Xexun2ProtocolDecoder extends GenericProtocolDecoder { +public class Xexun2ProtocolDecoder extends BaseProtocolDecoder { /** * Initialize */ - public Xexun2ProtocolDecoder(DataManager dataManager) { - super(dataManager); + public Xexun2ProtocolDecoder(ServerManager serverManager) { + super(serverManager); } /** diff --git a/src/org/traccar/protocol/XexunProtocolDecoder.java b/src/org/traccar/protocol/XexunProtocolDecoder.java index 6610730e9..1fd572896 100644 --- a/src/org/traccar/protocol/XexunProtocolDecoder.java +++ b/src/org/traccar/protocol/XexunProtocolDecoder.java @@ -22,21 +22,21 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; -import org.traccar.GenericProtocolDecoder; +import org.traccar.BaseProtocolDecoder; +import org.traccar.ServerManager; import org.traccar.helper.Log; -import org.traccar.model.DataManager; import org.traccar.model.Position; /** * Xexun tracker protocol decoder */ -public class XexunProtocolDecoder extends GenericProtocolDecoder { +public class XexunProtocolDecoder extends BaseProtocolDecoder { /** * Initialize */ - public XexunProtocolDecoder(DataManager dataManager) { - super(dataManager); + public XexunProtocolDecoder(ServerManager serverManager) { + super(serverManager); } /** diff --git a/test/org/traccar/protocol/Avl08ProtocolDecoderTest.java b/test/org/traccar/protocol/Avl08ProtocolDecoderTest.java index 5e0004444..19a54b6e3 100644 --- a/test/org/traccar/protocol/Avl08ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Avl08ProtocolDecoderTest.java @@ -8,8 +8,9 @@ public class Avl08ProtocolDecoderTest { @Test public void testDecode() throws Exception { - - Avl08ProtocolDecoder decoder = new Avl08ProtocolDecoder(new TestDataManager()); + + Avl08ProtocolDecoder decoder = new Avl08ProtocolDecoder(null); + decoder.setDataManager(new TestDataManager()); assertNull(decoder.decode(null, null, "$$AE359772033395899|AA000000000000000000000000000000000000000000000000000000000000|00.0|00.0|00.0|000000000000|20090215000153|13601435|00000000|00000000|0000|0.0000|0007|2DAA")); @@ -25,7 +26,7 @@ public class Avl08ProtocolDecoderTest { assertNotNull(decoder.decode(null, null, "$$B3359772032399074|09$GPRMC,094905.000,A,3648.2229,N,01008.0976,E,0.00,,221211,,,A*71|02.1|01.3|01.7|000000000000|20111222094905|03210533|00000000|00000000|0000|0.0000|0002||FA58")); - + assertNotNull(decoder.decode(null, null, "$$B3359772032399074|AA$GPRMC,093911.000,A,3648.2146,N,01008.0977,E,0.00,,140312,,,A*7E|02.1|01.1|01.8|000000000000|20120314093910|04100057|00000000|0012D887|0000|0.0000|1128||C50E")); diff --git a/test/org/traccar/protocol/EnforaProtocolDecoderTest.java b/test/org/traccar/protocol/EnforaProtocolDecoderTest.java index bf7f22290..a0a2e1b6f 100644 --- a/test/org/traccar/protocol/EnforaProtocolDecoderTest.java +++ b/test/org/traccar/protocol/EnforaProtocolDecoderTest.java @@ -11,7 +11,8 @@ public class EnforaProtocolDecoderTest { @Test public void testDecode() throws Exception { - EnforaProtocolDecoder decoder = new EnforaProtocolDecoder(new TestDataManager()); + EnforaProtocolDecoder decoder = new EnforaProtocolDecoder(null); + decoder.setDataManager(new TestDataManager()); ChannelBufferFactory factory = new HeapChannelBufferFactory(); byte[] buf1 = {0x00,0x0A,0x08,0x00,0x20,0x20,0x20,0x20,0x20,0x30,0x31,0x31,0x30,0x37,0x30,0x30,0x30,0x30,0x35,0x37,0x30,0x32,0x36,0x37}; diff --git a/test/org/traccar/protocol/Ev603ProtocolDecoderTest.java b/test/org/traccar/protocol/Ev603ProtocolDecoderTest.java index c25c06798..c4ecc5c7b 100644 --- a/test/org/traccar/protocol/Ev603ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Ev603ProtocolDecoderTest.java @@ -8,9 +8,10 @@ public class Ev603ProtocolDecoderTest { @Test public void testDecode() throws Exception { - - Ev603ProtocolDecoder decoder = new Ev603ProtocolDecoder(new TestDataManager()); - + + Ev603ProtocolDecoder decoder = new Ev603ProtocolDecoder(null); + decoder.setDataManager(new TestDataManager()); + assertNull(decoder.decode(null, null, "!5,17,V")); assertNotNull(decoder.decode(null, null, diff --git a/test/org/traccar/protocol/Gl100ProtocolDecoderTest.java b/test/org/traccar/protocol/Gl100ProtocolDecoderTest.java index e066d9af8..b705e446e 100644 --- a/test/org/traccar/protocol/Gl100ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Gl100ProtocolDecoderTest.java @@ -7,9 +7,10 @@ public class Gl100ProtocolDecoderTest { @Test public void testDecode() throws Exception { - - Gl100ProtocolDecoder decoder = new Gl100ProtocolDecoder(new TestDataManager()); - + + Gl100ProtocolDecoder decoder = new Gl100ProtocolDecoder(null); + decoder.setDataManager(new TestDataManager()); + assertNotNull(decoder.decode(null, null, "+RESP:GTSOS,359231030000010,0,0,0,1,4.3,92,70.0,1,121.354335,31.222073,20090101000000,0460,0000,18d8,6141,00,11F0,0102120204")); diff --git a/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java b/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java index 3be9bdc35..460d0dfec 100644 --- a/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java @@ -8,7 +8,8 @@ public class Gl200ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Gl200ProtocolDecoder decoder = new Gl200ProtocolDecoder(new TestDataManager()); + Gl200ProtocolDecoder decoder = new Gl200ProtocolDecoder(null); + decoder.setDataManager(new TestDataManager()); assertNotNull(decoder.decode(null, null, "+RESP:GTFRI,020102,000035988863964,,0,0,1,1,4.3,92,70.0,121.354335,31.222073,20090214013254,0460,0000,18d8,6141,00,,20090214093254,11F0")); diff --git a/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java b/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java index 0433e2e34..823b4fca2 100644 --- a/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java @@ -9,7 +9,8 @@ public class Gps103ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Gps103ProtocolDecoder decoder = new Gps103ProtocolDecoder(new TestDataManager()); + Gps103ProtocolDecoder decoder = new Gps103ProtocolDecoder(null); + decoder.setDataManager(new TestDataManager()); // Log on request //assertNull(decoder.decode(null, null, "##,imei:359586015829802,A")); diff --git a/test/org/traccar/protocol/Gt02ProtocolDecoderTest.java b/test/org/traccar/protocol/Gt02ProtocolDecoderTest.java index 585a2cea3..19d7f3812 100644 --- a/test/org/traccar/protocol/Gt02ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Gt02ProtocolDecoderTest.java @@ -8,9 +8,10 @@ public class Gt02ProtocolDecoderTest { @Test public void testDecode() throws Exception { - - Gt02ProtocolDecoder decoder = new Gt02ProtocolDecoder(new TestDataManager()); - + + Gt02ProtocolDecoder decoder = new Gt02ProtocolDecoder(null); + decoder.setDataManager(new TestDataManager()); + byte[] buf1 = {0x68,0x68,0x25,0x00,0x00,0x01,0x23,0x45,0x67,(byte)0x89,0x01,0x23,0x45,0x00,0x01,0x10,0x01,0x01,0x01,0x01,0x01,0x01,0x02,0x6B,0x3F,0x3E,0x02,0x6B,0x3F,0x3E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x0D,0x0A}; assertNotNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(buf1))); diff --git a/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java b/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java index ae4416435..c738cd79d 100644 --- a/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java @@ -10,7 +10,8 @@ public class Gt06ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Gt06ProtocolDecoder decoder = new Gt06ProtocolDecoder(new TestDataManager()); + Gt06ProtocolDecoder decoder = new Gt06ProtocolDecoder(null); + decoder.setDataManager(new TestDataManager()); byte[] buf1 = {0x78,0x78,0x0d,0x01,0x03,0x53,0x41,(byte)0x90,0x36,0x06,0x60,0x61,0x00,0x03,(byte)0xc3,(byte)0xdf,0x0d,0x0a}; assertNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(buf1))); diff --git a/test/org/traccar/protocol/H02ProtocolDecoderTest.java b/test/org/traccar/protocol/H02ProtocolDecoderTest.java index cd200705b..235ef279e 100644 --- a/test/org/traccar/protocol/H02ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/H02ProtocolDecoderTest.java @@ -8,9 +8,10 @@ public class H02ProtocolDecoderTest { @Test public void testDecode() throws Exception { - - H02ProtocolDecoder decoder = new H02ProtocolDecoder(new TestDataManager()); - + + H02ProtocolDecoder decoder = new H02ProtocolDecoder(null); + decoder.setDataManager(new TestDataManager()); + assertNotNull(decoder.decode(null, null, "*HQ,123456789012345,V1,155850,A,5214.5346,N,2117.4683,E,0.00,270.90,131012,ffffffff,000000,000000,000000,000000")); diff --git a/test/org/traccar/protocol/Jt600ProtocolDecoderTest.java b/test/org/traccar/protocol/Jt600ProtocolDecoderTest.java index 3e214832e..0419c024c 100644 --- a/test/org/traccar/protocol/Jt600ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Jt600ProtocolDecoderTest.java @@ -9,18 +9,19 @@ public class Jt600ProtocolDecoderTest { @Test public void testDecode() throws Exception { - - Jt600ProtocolDecoder decoder = new Jt600ProtocolDecoder(new TestDataManager()); - + + Jt600ProtocolDecoder decoder = new Jt600ProtocolDecoder(null); + decoder.setDataManager(new TestDataManager()); + byte[] buf1 = {0x24,0x31,0x10,0x21,0x60,0x01,0x11,0x00,0x1B,0x16,0x02,0x11,0x05,0x59,0x10,0x22,0x32,(byte)0x98,0x62,0x11,0x40,0x46,0x22,0x7B,0x05,(byte)0x98,0x09,0x50,(byte)0x80,0x01,0x23,0x27,(byte)0x95,0x14,0x35,0x16,0x1F}; assertNotNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(buf1))); - + byte[] buf2 = {0x24,0x31,0x20,(byte)0x82,0x00,0x29,0x11,0x00,0x1B,0x17,0x10,0x12,0x05,0x28,0x31,0x24,0x38,0x10,0x12,0x02,0x55,0x33,0x64,0x25,0x00,0x19,0x07,0x19,0x00,0x03,(byte)0xFD,0x2B,(byte)0x91,0x04,0x4D,0x1F,(byte)0xA0}; assertNotNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(buf2))); byte[] buf3 = {0x24,0x31,0x20,(byte)0x82,0x00,0x29,0x11,0x00,0x1B,0x17,0x10,0x12,0x05,0x33,0x05,0x24,0x38,0x09,(byte)0x97,0x02,0x55,0x33,0x58,0x45,0x00,0x04,0x06,0x1E,0x00,0x03,(byte)0xEE,0x00,0x00,0x00,0x00,0x0C,0x00}; assertNotNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(buf2))); - + assertNotNull(decoder.decode(null, null, ChannelBuffers.copiedBuffer("(3110312099,W01,11404.6204,E,2232.9961,N,A,040511,063736,4,7,100,4,17,1,1,company)", Charset.defaultCharset()))); diff --git a/test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java b/test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java index 11ca13aef..94950fc9c 100644 --- a/test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java +++ b/test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java @@ -11,27 +11,28 @@ public class MeiligaoProtocolDecoderTest { @Test public void testDecode() throws Exception { - MeiligaoProtocolDecoder decoder = new MeiligaoProtocolDecoder(new TestDataManager()); + MeiligaoProtocolDecoder decoder = new MeiligaoProtocolDecoder(null); + decoder.setDataManager(new TestDataManager()); ChannelBufferFactory factory = new HeapChannelBufferFactory(); - + byte[] buf1 = {0x12,0x34,0x56,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,0x50,0x00,(byte)0x8B,(byte)0x9B,0x0D,0x0A}; assertNull(decoder.decode(null, null, factory.getBuffer(buf1, 0, buf1.length))); byte[] buf2 = {0x12,0x34,0x56,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0x99,0x55,0x30,0x33,0x35,0x36,0x34,0x34,0x2E,0x30,0x30,0x30,0x2C,0x41,0x2C,0x32,0x32,0x33,0x32,0x2E,0x36,0x30,0x38,0x33,0x2C,0x4E,0x2C,0x31,0x31,0x34,0x30,0x34,0x2E,0x38,0x31,0x33,0x37,0x2C,0x45,0x2C,0x30,0x2E,0x30,0x30,0x2C,0x2C,0x30,0x31,0x30,0x38,0x30,0x39,0x2C,0x2C,0x2A,0x31,0x43,0x7C,0x31,0x31,0x2E,0x35,0x7C,0x31,0x39,0x34,0x7C,0x30,0x30,0x30,0x30,0x7C,0x30,0x30,0x30,0x30,0x2C,0x30,0x30,0x30,0x30,0x69,0x62,0x0D,0x0A}; assertNotNull(decoder.decode(null, null, factory.getBuffer(buf2, 0, buf2.length))); - + byte[] buf3 = {0x33,0x58,0x01,(byte)0x97,0x03,0x58,0x1F,(byte)0x99,0x55,0x31,0x33,0x34,0x33,0x35,0x31,0x2E,0x30,0x30,0x30,0x2C,0x41,0x2C,0x30,0x39,0x32,0x35,0x2E,0x35,0x30,0x32,0x35,0x2C,0x4E,0x2C,0x30,0x36,0x39,0x31,0x34,0x2E,0x38,0x31,0x30,0x37,0x2C,0x57,0x2C,0x30,0x2E,0x30,0x30,0x2C,0x32,0x33,0x2C,0x33,0x30,0x31,0x30,0x31,0x32,0x2C,0x2C,0x2A,0x32,0x43,0x7C,0x30,0x2E,0x38,0x7C,0x31,0x38,0x36,0x7C,0x32,0x30,0x30,0x30,0x7C,0x30,0x31,0x32,0x36,0x2C,0x30,0x30,0x46,0x46,0x7C,0x30,0x32,0x44,0x45,0x30,0x30,0x30,0x32,0x44,0x38,0x43,0x44,0x42,0x34,0x31,0x35,0x7C,0x30,0x36,0x7C,0x30,0x30,0x46,0x44,0x36,0x42,0x37,0x39,(byte)0x95,(byte)0x82,0x0D,0x0A}; assertNotNull(decoder.decode(null, null, factory.getBuffer(buf3, 0, buf3.length))); byte[] buf4 = {0x16,(byte)0x91,0x00,0x04,(byte)0x84,0x12,0x4F,(byte)0x99,0x55,0x31,0x34,0x30,0x36,0x30,0x33,0x2E,0x30,0x30,0x30,0x2C,0x41,0x2C,0x30,0x39,0x33,0x34,0x2E,0x32,0x35,0x35,0x34,0x2C,0x4E,0x2C,0x30,0x36,0x39,0x31,0x33,0x2E,0x30,0x39,0x36,0x36,0x2C,0x57,0x2C,0x30,0x2E,0x30,0x30,0x2C,0x2C,0x33,0x30,0x31,0x30,0x31,0x32,0x2C,0x2C,0x2A,0x30,0x32,0x7C,0x30,0x2E,0x38,0x7C,0x32,0x30,0x37,0x7C,0x30,0x30,0x30,0x30,(byte)0xFA,0x42,0x0D,0x0A}; assertNotNull(decoder.decode(null, null, factory.getBuffer(buf4, 0, buf4.length))); - + byte[] buf5 = {0x45,0x12,0x42,0x20,0x30,0x6F,(byte)0xFF,(byte)0x99,(byte)0x99,0x14,0x31,0x35,0x35,0x34,0x32,0x32,0x2E,0x30,0x30,0x30,0x2C,0x56,0x2C,0x32,0x32,0x33,0x30,0x2E,0x37,0x36,0x32,0x33,0x2C,0x4E,0x2C,0x31,0x31,0x34,0x30,0x33,0x2E,0x34,0x32,0x31,0x38,0x2C,0x45,0x2C,0x30,0x2E,0x30,0x30,0x2C,0x30,0x2C,0x30,0x36,0x30,0x32,0x31,0x31,0x2C,0x2C,0x2A,0x31,0x41,0x7C,0x30,0x2E,0x30,0x7C,0x32,0x36,0x7C,0x30,0x30,0x30,0x30,0x7C,0x30,0x30,0x30,0x30,0x2C,0x30,0x30,0x30,0x30,0x7C,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x7C,0x36,0x33,0x7C,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,(byte)0xBA,(byte)0xC1,0x0D,0x0A}; assertNotNull(decoder.decode(null, null, factory.getBuffer(buf5, 0, buf5.length))); - + byte[] buf6 = {(byte)0x86,0x21,0x70,0x01,0x42,0x45,(byte)0x8F,(byte)0x99,(byte)0x99,0x50,0x31,0x39,0x32,0x39,0x35,0x38,0x2E,0x30,0x30,0x30,0x2C,0x41,0x2C,0x33,0x36,0x32,0x37,0x2E,0x31,0x36,0x39,0x39,0x2C,0x4E,0x2C,0x30,0x31,0x30,0x34,0x33,0x2E,0x35,0x36,0x32,0x37,0x2C,0x45,0x2C,0x30,0x2E,0x30,0x30,0x2C,0x32,0x33,0x39,0x2C,0x30,0x39,0x31,0x32,0x31,0x32,0x2C,0x2C,0x2A,0x30,0x46,0x7C,0x31,0x2E,0x30,0x7C,0x37,0x7C,0x30,0x30,0x30,0x30,0x7C,0x30,0x31,0x41,0x39,0x2C,0x30,0x31,0x39,0x37,0x7C,0x30,0x32,0x35,0x44,0x30,0x30,0x30,0x32,0x30,0x30,0x35,0x41,0x38,0x36,0x39,0x46,0x7C,0x31,0x32,0x7C,0x30,0x30,0x30,0x33,0x33,0x42,0x42,0x33,(byte)0xE2,0x48,0x0D,0x0A}; assertNotNull(decoder.decode(null, null, factory.getBuffer(buf6, 0, buf6.length))); - + byte[] buf7 = {0x12,0x34,0x56,0x78,(byte)0x9F,(byte)0xFF,(byte)0xFF,(byte)0x99,0x55,0x30,0x32,0x30,0x36,0x30,0x30,0x2E,0x39,0x33,0x30,0x2C,0x41,0x2C,0x32,0x33,0x30,0x39,0x2E,0x32,0x30,0x35,0x31,0x2C,0x4E,0x2C,0x31,0x31,0x33,0x31,0x38,0x2E,0x38,0x34,0x34,0x39,0x2C,0x45,0x2C,0x30,0x2E,0x30,0x30,0x2C,0x30,0x2E,0x30,0x30,0x2C,0x30,0x39,0x30,0x37,0x31,0x30,0x2C,0x2C,0x2C,0x41,0x2A,0x36,0x41,0x7C,0x32,0x2E,0x36,0x7C,0x39,0x36,0x2E,0x37,0x7C,0x30,0x30,0x30,0x30,0x7C,0x30,0x30,0x30,0x30,0x2C,0x33,0x46,0x46,0x46,0x7C,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,(byte)0xC4,0x52,0x0D,0x0A}; assertNotNull(decoder.decode(null, null, factory.getBuffer(buf7, 0, buf7.length))); diff --git a/test/org/traccar/protocol/MeitrackProtocolDecoderTest.java b/test/org/traccar/protocol/MeitrackProtocolDecoderTest.java index c67fc2e31..e2f30b752 100644 --- a/test/org/traccar/protocol/MeitrackProtocolDecoderTest.java +++ b/test/org/traccar/protocol/MeitrackProtocolDecoderTest.java @@ -8,7 +8,8 @@ public class MeitrackProtocolDecoderTest { @Test public void testDecode() throws Exception { - MeitrackProtocolDecoder decoder = new MeitrackProtocolDecoder(new TestDataManager()); + MeitrackProtocolDecoder decoder = new MeitrackProtocolDecoder(null); + decoder.setDataManager(new TestDataManager()); assertNotNull(decoder.decode(null, null, "$$]138,012896000475498,AAA,35,-6.138255,106.910545,121205074600,A,5,18,0,0,0,49,3800,24826,510|10|0081|4F4F,0000,0011|0012|0010|0963|0000,,*94")); @@ -18,13 +19,13 @@ public class MeitrackProtocolDecoderTest { assertNotNull(decoder.decode(null, null, "$$j138,012896000475498,AAA,35,-6.138306,106.910655,121205103708,A,3,11,0,0,1,36,4182,35025,510|10|0081|4F4F,0000,000A|000C|000A|0915|0000,,*BF")); - + assertNotNull(decoder.decode(null, null, "$$m139,012896005334567,AAA,35,-33.866423,151.190060,121208020649,A,7,27,0,32,4,13,6150,49517,505|2|0B67|5A6C,0000,0000|0000|0000|0977|0000,,*F1")); - + assertNotNull(decoder.decode(null, null, "$$A141,012896005334567,AAA,35,-33.866543,151.190148,121209081758,A,6,27,0,16,1,48,65551,152784,505|2|0B5F|D9D3,0000,0000|0000|0000|0A39|0000,,*5B")); - + } } diff --git a/test/org/traccar/protocol/NavisProtocolDecoderTest.java b/test/org/traccar/protocol/NavisProtocolDecoderTest.java index cf9a47992..2d568765a 100644 --- a/test/org/traccar/protocol/NavisProtocolDecoderTest.java +++ b/test/org/traccar/protocol/NavisProtocolDecoderTest.java @@ -10,18 +10,19 @@ public class NavisProtocolDecoderTest { @Test public void testDecode() throws Exception { - - NavisProtocolDecoder decoder = new NavisProtocolDecoder(new TestDataManager()); - + + NavisProtocolDecoder decoder = new NavisProtocolDecoder(null); + decoder.setDataManager(new TestDataManager()); + 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))); byte[] buf2 = {0x40,0x4E,0x54,0x43,0x01,0x00,0x00,0x00,0x7B,0x00,0x00,0x00,0x5A,0x00,0x50,0x69,0x2A,0x3E,0x41,0x01,0x25,(byte)0xDB,0x0E,0x00,0x00,0x00,0x15,0x11,0x07,0x07,0x11,0x0A,0x0C,0x08,(byte)0x80,0x63,0x00,0x00,(byte)0xAA,0x39,(byte)0xA2,0x38,0x16,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x11,0x07,0x08,0x11,0x0A,0x0C,(byte)0xB3,(byte)0x89,(byte)0x79,0x3F,0x1A,(byte)0xEF,0x26,0x3F,0x00,0x00,0x00,0x00,0x12,0x00,0x34,(byte)0xF5,0x16,0x44,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,(byte)0xFA,(byte)0xFF,0x00,0x00,0x00,(byte)0xFA,(byte)0xFF,0x00,0x00,0x00,(byte)0xFA,(byte)0xFF,(byte)0x80,(byte)0x80,(byte)0x80,(byte)0x80}; assertNotNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, buf2))); - + byte[] buf3 = {0x40,0x4E,0x54,0x43,0x01,0x00,0x00,0x00,0x7B,0x00,0x00,0x00,0x13,0x00,0x47,0x37,0x2A,0x3E,0x53,0x3A,0x38,0x36,0x31,0x37,0x38,0x35,0x30,0x30,0x35,0x31,0x32,0x36,0x30,0x36,0x39}; assertNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, buf3))); - + } } diff --git a/test/org/traccar/protocol/Pt502ProtocolDecoderTest.java b/test/org/traccar/protocol/Pt502ProtocolDecoderTest.java index f8c4c43d2..c8a33037c 100644 --- a/test/org/traccar/protocol/Pt502ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Pt502ProtocolDecoderTest.java @@ -7,21 +7,22 @@ public class Pt502ProtocolDecoderTest { @Test public void testDecode() throws Exception { - - Pt502ProtocolDecoder decoder = new Pt502ProtocolDecoder(new TestDataManager()); + + Pt502ProtocolDecoder decoder = new Pt502ProtocolDecoder(null); + decoder.setDataManager(new TestDataManager()); assertNotNull(decoder.decode(null, null, "$POS,6094,205523.000,A,1013.6223,N,06728.4248,W,0.0,99.3,011112,,,A/00000,00000/0/23895000//")); assertNotNull(decoder.decode(null, null, "$POS,6120,233326.000,V,0935.1201,N,06914.6933,W,0.00,,151112,,,A/00000,00000/0/0/")); - + assertNotNull(decoder.decode(null, null, "$POS,6002,233257.000,A,0931.0430,N,06912.8707,W,0.05,146.98,141112,,,A/00010,00000/0/5360872")); - + assertNotNull(decoder.decode(null, null, "$POS,6095,233344.000,V,0933.0451,N,06912.3360,W,,,151112,,,N/00000,00000/0/1677600/")); - + /*assertNotNull(decoder.decode(null, null, "$PHO0,6091,233606.000,A,0902.9855,N,06944.3654,W,0.0,43.8,141112,,,A/00010,00000/0/224000//"));*/ diff --git a/test/org/traccar/protocol/ST210ProtocolDecoderTest.java b/test/org/traccar/protocol/ST210ProtocolDecoderTest.java index 7956c3dd4..d84993b95 100644 --- a/test/org/traccar/protocol/ST210ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/ST210ProtocolDecoderTest.java @@ -10,8 +10,8 @@ public class ST210ProtocolDecoderTest { @Test public void testDecode() throws Exception { - ST210ProtocolDecoder decoder = new ST210ProtocolDecoder( - new TestDataManager()); + ST210ProtocolDecoder decoder = new ST210ProtocolDecoder(null); + decoder.setDataManager(new TestDataManager()); //Status assertNotNull(decoder @@ -48,7 +48,7 @@ public class ST210ProtocolDecoderTest { assertNotNull(decoder .decode(null, null, - "SA200ALT;317652;042;20120829;14:25:58;16d41;-15.618770;-056.083242;000.029;000.00;0;0;2404240;0.00;000000;10")); + "SA200ALT;317652;042;20120829;14:25:58;16d41;-15.618770;-056.083242;000.029;000.00;0;0;2404240;0.00;000000;10")); } } diff --git a/test/org/traccar/protocol/SkypatrolProtocolDecoderTest.java b/test/org/traccar/protocol/SkypatrolProtocolDecoderTest.java index 3024094d4..e3b1a0dc1 100644 --- a/test/org/traccar/protocol/SkypatrolProtocolDecoderTest.java +++ b/test/org/traccar/protocol/SkypatrolProtocolDecoderTest.java @@ -6,13 +6,14 @@ import static org.junit.Assert.assertNotNull; import org.junit.Test; public class SkypatrolProtocolDecoderTest { - + @Test public void testDecode() throws Exception { - - SkypatrolProtocolDecoder decoder = new SkypatrolProtocolDecoder(new TestDataManager()); + + SkypatrolProtocolDecoder decoder = new SkypatrolProtocolDecoder(null); + decoder.setDataManager(new TestDataManager()); ChannelBufferFactory factory = new HeapChannelBufferFactory(); - + byte[] buf1 = {0x00,0x05,0x02,0x10,0x04,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,0x00,0x00,0x00,0x0D,0x31,0x31,0x34,0x37,0x37,0x35,0x38,0x33,0x00,(byte)0xCB,0x00,0x00,0x00,0x00,0x0E,0x11,0x07,0x0C,0x01,0x01,(byte)0x84,(byte)0xD0,0x32,(byte)0xFB,0x38,0x41,0x37,0x00,0x00,0x00,0x00,0x16,0x07,0x2B,0x00,0x00,0x17,0x05,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x4E,0x0C,0x07,0x11,0x16,0x07,0x2C,0x10,0x59,0x00,0x05,0x00,0x00,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x00,0x03,0x10,0x02,0x60,(byte)0xB7,0x36,0x3B,0x63,0x06,(byte)0xC1,0x1A,0x00,(byte)0xB7,0x36,0x37,(byte)0xF2,0x06,(byte)0xBF,0x19,(byte)0xB7,0x36,0x37,(byte)0xF1,0x06,(byte)0xB5,0x0E,(byte)0xB7,0x36,0x38,(byte)0xB1,0x06,(byte)0xBB,0x0B,(byte)0xB7,0x36,0x3B,0x61,0x06,(byte)0xB8,0x0A,(byte)0xB7,0x36,0x37,(byte)0xF3,0x06,(byte)0xB7,0x09,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C}; assertNotNull(decoder.decode(null, null, factory.getBuffer(buf1, 0, buf1.length))); diff --git a/test/org/traccar/protocol/T55ProtocolDecoderTest.java b/test/org/traccar/protocol/T55ProtocolDecoderTest.java index 5d9ae4e3a..6d639ee8c 100644 --- a/test/org/traccar/protocol/T55ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/T55ProtocolDecoderTest.java @@ -8,9 +8,10 @@ public class T55ProtocolDecoderTest { @Test public void testDecode() throws Exception { - - T55ProtocolDecoder decoder = new T55ProtocolDecoder(new TestDataManager()); - + + T55ProtocolDecoder decoder = new T55ProtocolDecoder(null); + decoder.setDataManager(new TestDataManager()); + assertNull(decoder.decode(null, null, "$PGID,359853000144328*0F")); assertNotNull(decoder.decode(null, null, diff --git a/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java b/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java index d7e9b2444..b7e4ab849 100644 --- a/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java @@ -9,7 +9,8 @@ public class Tk103ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Tk103ProtocolDecoder decoder = new Tk103ProtocolDecoder(new TestDataManager()); + Tk103ProtocolDecoder decoder = new Tk103ProtocolDecoder(null); + decoder.setDataManager(new TestDataManager()); assertNull(decoder.decode(null, null, "(090411121854BP0000001234567890HSO")); diff --git a/test/org/traccar/protocol/Tr20ProtocolDecoderTest.java b/test/org/traccar/protocol/Tr20ProtocolDecoderTest.java index aa978655b..ecb814708 100644 --- a/test/org/traccar/protocol/Tr20ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Tr20ProtocolDecoderTest.java @@ -8,9 +8,10 @@ public class Tr20ProtocolDecoderTest { @Test public void testDecode() throws Exception { - - Tr20ProtocolDecoder decoder = new Tr20ProtocolDecoder(new TestDataManager()); - + + Tr20ProtocolDecoder decoder = new Tr20ProtocolDecoder(null); + decoder.setDataManager(new TestDataManager()); + assertNull(decoder.decode(null, null, "%%TRACKPRO01,1")); assertNotNull(decoder.decode(null, null, diff --git a/test/org/traccar/protocol/V680ProtocolDecoderTest.java b/test/org/traccar/protocol/V680ProtocolDecoderTest.java index 15b25b9d9..e185ab9fd 100644 --- a/test/org/traccar/protocol/V680ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/V680ProtocolDecoderTest.java @@ -7,9 +7,10 @@ public class V680ProtocolDecoderTest { @Test public void testDecode() throws Exception { - - V680ProtocolDecoder decoder = new V680ProtocolDecoder(new TestDataManager()); - + + V680ProtocolDecoder decoder = new V680ProtocolDecoder(null); + decoder.setDataManager(new TestDataManager()); + assertNotNull(decoder.decode(null, null, "#356823033219838#1000#0#1478#AUT#1#66830FFB#03855.6628,E,4716.6821,N,001.41,259#130812#143905")); diff --git a/test/org/traccar/protocol/Xexun2ProtocolDecoderTest.java b/test/org/traccar/protocol/Xexun2ProtocolDecoderTest.java index 8d585337a..9a4b6e28d 100644 --- a/test/org/traccar/protocol/Xexun2ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Xexun2ProtocolDecoderTest.java @@ -8,7 +8,8 @@ public class Xexun2ProtocolDecoderTest { @Test public void testDecode() throws Exception { - Xexun2ProtocolDecoder decoder = new Xexun2ProtocolDecoder(new TestDataManager()); + Xexun2ProtocolDecoder decoder = new Xexun2ProtocolDecoder(null); + decoder.setDataManager(new TestDataManager()); assertNotNull(decoder.decode(null, null, "111111120009,+436763737552,GPRMC,120009.590,A,4639.6774,N,01418.5737,E,0.00,0.00,111111,,,A*68,F,, imei:359853000144328,04,481.2,F:4.15V,0,139,2689,232,03,2725,0576")); diff --git a/test/org/traccar/protocol/XexunProtocolDecoderTest.java b/test/org/traccar/protocol/XexunProtocolDecoderTest.java index 832f4ee63..fa32ed966 100644 --- a/test/org/traccar/protocol/XexunProtocolDecoderTest.java +++ b/test/org/traccar/protocol/XexunProtocolDecoderTest.java @@ -7,8 +7,9 @@ public class XexunProtocolDecoderTest { @Test public void testDecode() throws Exception { - - XexunProtocolDecoder decoder = new XexunProtocolDecoder(new TestDataManager()); + + XexunProtocolDecoder decoder = new XexunProtocolDecoder(null); + decoder.setDataManager(new TestDataManager()); assertNotNull(decoder.decode(null, null, "GPRMC,150120.000,A,3346.4463,S,15057.3083,E,0.0,117.4,010911,,,A*76,F,imei:351525010943661,")); @@ -21,7 +22,7 @@ public class XexunProtocolDecoderTest { assertNotNull(decoder.decode(null, null, "GPRMC,080303.000,A,5546.7313,N,03738.6005,E,0.56,160.13,100311,,,A*6A,L,imei:354778030461167,")); - + assertNotNull(decoder.decode(null, null, "GPRMC,014623.000,A,4710.8260,N,1948.1220,E,0.11,105.40,111212,00,0000.0,A*49,F,,imei:357713002048962,")); |