aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwilliamchitto <williamchitto@gmail.com>2012-07-31 08:08:53 -0300
committerwilliamchitto <williamchitto@gmail.com>2012-07-31 08:08:53 -0300
commitf5e305c4ea89210a2e4daffa4e947acdc440fbe7 (patch)
treeebc542944483e95c9b7374217690fc7bba38ff33
parentd9c99fafa2e4d581f473029144aec495cb94bb62 (diff)
downloadtraccar-server-f5e305c4ea89210a2e4daffa4e947acdc440fbe7.tar.gz
traccar-server-f5e305c4ea89210a2e4daffa4e947acdc440fbe7.tar.bz2
traccar-server-f5e305c4ea89210a2e4daffa4e947acdc440fbe7.zip
adicionando classes de testes
-rw-r--r--setup/windows/windows.cfg12
-rw-r--r--src/Main.java10
-rw-r--r--src/org/traccar/GenericPipelineFactory.java2
-rw-r--r--src/org/traccar/Server.java914
-rw-r--r--src/org/traccar/TrackerServer.java125
-rw-r--r--src/org/traccar/model/DatabaseDataManager.java2
-rw-r--r--src/org/traccar/model/Position.java12
-rw-r--r--src/org/traccar/protocol/ST210ProtocolDecoder.java3
-rw-r--r--test/org/traccar/protocol/ST210ProtocolDecoderTest.java47
9 files changed, 667 insertions, 460 deletions
diff --git a/setup/windows/windows.cfg b/setup/windows/windows.cfg
index 273b0700b..3487189f6 100644
--- a/setup/windows/windows.cfg
+++ b/setup/windows/windows.cfg
@@ -16,7 +16,7 @@
<!-- Create database schema -->
<entry key="database.initialize">
CREATE TABLE IF NOT EXISTS devices (id INT IDENTITY, imei VARCHAR(16));
- CREATE TABLE IF NOT EXISTS positions (device_id INT, time TIMESTAMP, valid BOOLEAN, latitude DOUBLE, longitude DOUBLE, speed DOUBLE, course DOUBLE, power DOUBLE);
+ CREATE TABLE IF NOT EXISTS positions (device_id INT, time TIMESTAMP, valid BOOLEAN, latitude DOUBLE, longitude DOUBLE, speed DOUBLE, course DOUBLE, power DOUBLE, mode INT);
</entry>
<!-->
@@ -72,11 +72,12 @@
speed - Double
course - Double
power - Double (NULL for some protocols)
+ mode - Integer
extended_info - String (XML)
<-->
<entry key="database.insertPosition">
INSERT INTO positions (device_id, time, valid, latitude, longitude, speed, course, power)
- VALUES (:device_id, :time, :valid, :latitude, :longitude, :speed, :course, :power)
+ VALUES (:device_id, :time, :valid, :latitude, :longitude, :speed, :course, :power, :mode)
</entry>
<!-- Web interface port -->
@@ -84,7 +85,7 @@
<entry key="http.port">8082</entry>
<!-- Logging options -->
- <entry key="logger.enable">false</entry>
+ <entry key="logger.enable">true</entry>
<entry key="logger.file">[LOG]</entry>
<!-- Xexun server configuration -->
@@ -136,5 +137,10 @@
<entry key="meiligao.enable">true</entry>
<entry key="meiligao.port">5009</entry>
<entry key="meiligao.resetDelay">0</entry>
+
+ <!-- ST210 server configuration -->
+ <entry key="st210.enable">true</entry>
+ <entry key="st210.port">5010</entry>
+ <entry key="st210.resetDelay">0</entry>
</properties>
diff --git a/src/Main.java b/src/Main.java
index 8b6f2002e..783ebe0f6 100644
--- a/src/Main.java
+++ b/src/Main.java
@@ -6,10 +6,18 @@ public class Main {
public static void main(String[] args) throws Exception {
final Server service = new Server();
- service.init(args);
+ String[] argss = new String[1];
+ argss[0] = "setup\\windows\\windows.cfg";
+ service.init(argss);
Log.info("starting server...");
+
+
service.start();
+
+
+
+
// Shutdown server properly
Runtime.getRuntime().addShutdownHook(new Thread() {
diff --git a/src/org/traccar/GenericPipelineFactory.java b/src/org/traccar/GenericPipelineFactory.java
index c5e2cc812..db3c378ba 100644
--- a/src/org/traccar/GenericPipelineFactory.java
+++ b/src/org/traccar/GenericPipelineFactory.java
@@ -59,6 +59,7 @@ public abstract class GenericPipelineFactory implements ChannelPipelineFactory {
@Override
public void log(ChannelEvent e) {
+ server.mandaMSG();
if (e instanceof MessageEvent) {
MessageEvent event = (MessageEvent) e;
String msg = "[" + ((InetSocketAddress) e.getChannel().getLocalAddress()).getPort() + " - ";
@@ -110,6 +111,7 @@ public abstract class GenericPipelineFactory implements ChannelPipelineFactory {
pipeline.addLast("geocoder", new ReverseGeocoderHandler(geocoder));
}
pipeline.addLast("handler", new TrackerEventHandler(dataManager));
+
return pipeline;
}
} \ No newline at end of file
diff --git a/src/org/traccar/Server.java b/src/org/traccar/Server.java
index 5a6b298c7..e6eabdb71 100644
--- a/src/org/traccar/Server.java
+++ b/src/org/traccar/Server.java
@@ -21,6 +21,7 @@ import java.sql.SQLException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;
@@ -29,6 +30,7 @@ import java.util.logging.Formatter;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import org.jboss.netty.buffer.ChannelBuffers;
+import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.handler.codec.frame.DelimiterBasedFrameDecoder;
import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder;
@@ -47,407 +49,519 @@ import org.traccar.protocol.*;
*/
public class Server {
- /**
- * Server list
- */
- private List<TrackerServer> serverList;
-
- private boolean loggerEnabled;
-
- public Server() {
- serverList = new LinkedList<TrackerServer>();
- loggerEnabled = false;
- }
-
- public boolean isLoggerEnabled() {
- return loggerEnabled;
- }
-
- private DataManager dataManager;
-
- private WebServer webServer;
-
- private ReverseGeocoder geocoder;
-
- /**
- * Initialize
- */
- public void init(String[] arguments)
- throws IOException, ClassNotFoundException, SQLException {
-
- // Load properties
- Properties properties = new Properties();
- if (arguments.length > 0) {
- properties.loadFromXML(new FileInputStream(arguments[0]));
- }
-
- dataManager = new DatabaseDataManager(properties);
-
- initLogger(properties);
- initGeocoder(properties);
-
- initXexunServer(properties);
- initGps103Server(properties);
- initTk103Server(properties);
- initGl100Server(properties);
- initGl200Server(properties);
- initT55Server(properties);
- initXexun2Server(properties);
- initAvl08Server(properties);
- initEnforaServer(properties);
- initMeiligaoServer(properties);
-
- // Initialize web server
- if (Boolean.valueOf(properties.getProperty("http.enable"))) {
- Integer port = Integer.valueOf(properties.getProperty("http.port", "8082"));
- webServer = new WebServer(port, dataManager);
- }
- }
-
- /**
- * Start
- */
- public void start() {
- if (webServer != null) {
- webServer.start();
- }
- for (Object server: serverList) {
- ((TrackerServer) server).start();
- }
+ /**
+ * Server list
+ */
+ private List<TrackerServer> serverList;
+
+ private boolean loggerEnabled;
+
+ public Server() {
+ serverList = new LinkedList<TrackerServer>();
+ loggerEnabled = false;
+ }
+
+ public boolean isLoggerEnabled() {
+ return loggerEnabled;
+ }
+
+ private DataManager dataManager;
+
+ private WebServer webServer;
+
+ private ReverseGeocoder geocoder;
+
+ public void mandaMSG()
+ {
+
+ for (Iterator iterator = serverList.iterator(); iterator.hasNext();) {
+ TrackerServer type = (TrackerServer) iterator.next();
+ if(type.getPort().equals(5010)){
+
+ for (Iterator it = type.getChannelGroup().iterator(); it.hasNext();) {
+ Channel chanel = (Channel) it.next();
+ System.out.println(chanel.getRemoteAddress());
+
+ }
+ }
+ // System.out.println(type.getPort());
+
+ }
}
- /**
- * Stop
- */
- public void stop() {
- for (Object server: serverList) {
- ((TrackerServer) server).stop();
- }
- if (webServer != null) {
- webServer.stop();
- }
- }
-
- /**
- * Destroy
- */
- public void destroy() {
- serverList.clear();
- }
-
- /**
- * Initialize logger
- */
- private void initLogger(Properties properties) throws IOException {
-
- loggerEnabled = Boolean.valueOf(properties.getProperty("logger.enable"));
-
- if (loggerEnabled) {
-
- String fileName = properties.getProperty("logger.file");
- if (fileName != null) {
-
- FileHandler file = new FileHandler(fileName, true);
-
- // Simple formatter
- file.setFormatter(new Formatter() {
- private final String LINE_SEPARATOR =
- System.getProperty("line.separator", "\n");
-
- private final DateFormat dateFormat =
- new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
-
- public String format(LogRecord record) {
- String line = dateFormat.format(new Date(record.getMillis()));
- line += " " + record.getLevel().getName() + ": ";
- line += formatMessage(record);
- line += LINE_SEPARATOR;
- return line;
- }
- });
-
- // NOTE: Console logger level will remain INFO
- Log.getLogger().setLevel(Level.ALL);
- Log.getLogger().addHandler(file);
- }
- }
- }
-
- private void initGeocoder(Properties properties) throws IOException {
- if (Boolean.parseBoolean("geocoder.enable")) {
- geocoder = new GoogleReverseGeocoder();
- }
- }
-
- private boolean isProtocolEnabled(Properties properties, String protocol) {
- String enabled = properties.getProperty(protocol + ".enable");
- if (enabled != null) {
- return Boolean.valueOf(enabled);
- }
- return false;
- }
-
- private Integer getProtocolPort(Properties properties, String protocol) {
- String port = properties.getProperty(protocol + ".port");
- if (port != null) {
- return Integer.valueOf(port);
- }
- return 5000; // Magic number
- }
-
- private Integer getProtocolResetDelay(Properties properties, String protocol) {
- String resetDelay = properties.getProperty(protocol + ".resetDelay");
- if (resetDelay != null) {
- return Integer.valueOf(resetDelay);
- }
- return 0;
- }
-
- /**
- * Init Xexun server
- */
- private void initXexunServer(Properties properties) throws SQLException {
-
- String protocol = "xexun";
- if (isProtocolEnabled(properties, protocol)) {
-
- TrackerServer server = new TrackerServer(getProtocolPort(properties, protocol));
- final Integer resetDelay = getProtocolResetDelay(properties, protocol);
-
- server.setPipelineFactory(new GenericPipelineFactory(server, dataManager, isLoggerEnabled(), geocoder) {
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new XexunFrameDecoder());
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new XexunProtocolDecoder(getDataManager(), resetDelay));
- }
- });
-
- serverList.add(server);
- }
- }
-
- /**
- * Init Gps103 server
- */
- private void initGps103Server(Properties properties) throws SQLException {
-
- String protocol = "gps103";
- if (isProtocolEnabled(properties, protocol)) {
-
- TrackerServer server = new TrackerServer(getProtocolPort(properties, protocol));
- final Integer resetDelay = getProtocolResetDelay(properties, protocol);
-
- server.setPipelineFactory(new GenericPipelineFactory(server, dataManager, isLoggerEnabled(), geocoder) {
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- byte delimiter[] = { (byte) ';' };
- pipeline.addLast("frameDecoder",
- new DelimiterBasedFrameDecoder(1024, ChannelBuffers.wrappedBuffer(delimiter)));
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new Gps103ProtocolDecoder(getDataManager(), resetDelay));
- }
- });
-
- serverList.add(server);
- }
- }
-
- /**
- * Init Tk103 server
- */
- private void initTk103Server(Properties properties) throws SQLException {
-
- String protocol = "tk103";
- if (isProtocolEnabled(properties, protocol)) {
-
- TrackerServer server = new TrackerServer(getProtocolPort(properties, protocol));
- final Integer resetDelay = getProtocolResetDelay(properties, protocol);
-
- server.setPipelineFactory(new GenericPipelineFactory(server, dataManager, isLoggerEnabled(), geocoder) {
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- byte delimiter[] = { (byte) ')' };
- pipeline.addLast("frameDecoder",
- new DelimiterBasedFrameDecoder(1024, ChannelBuffers.wrappedBuffer(delimiter)));
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new Tk103ProtocolDecoder(getDataManager(), resetDelay));
- }
- });
-
- serverList.add(server);
- }
- }
-
- /**
- * Init Gl100 server
- */
- private void initGl100Server(Properties properties) throws SQLException {
-
- String protocol = "gl100";
- if (isProtocolEnabled(properties, protocol)) {
-
- TrackerServer server = new TrackerServer(getProtocolPort(properties, protocol));
- final Integer resetDelay = getProtocolResetDelay(properties, protocol);
-
- server.setPipelineFactory(new GenericPipelineFactory(server, dataManager, isLoggerEnabled(), geocoder) {
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- byte delimiter[] = { (byte) 0x0 };
- pipeline.addLast("frameDecoder",
- new DelimiterBasedFrameDecoder(1024, ChannelBuffers.wrappedBuffer(delimiter)));
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new Gl100ProtocolDecoder(getDataManager(), resetDelay));
- }
- });
-
- serverList.add(server);
- }
- }
-
- /**
- * Init Gl200 server
- */
- private void initGl200Server(Properties properties) throws SQLException {
-
- String protocol = "gl200";
- if (isProtocolEnabled(properties, protocol)) {
-
- TrackerServer server = new TrackerServer(getProtocolPort(properties, protocol));
- final Integer resetDelay = getProtocolResetDelay(properties, protocol);
-
- server.setPipelineFactory(new GenericPipelineFactory(server, dataManager, isLoggerEnabled(), geocoder) {
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- byte delimiter[] = { (byte) '$' };
- pipeline.addLast("frameDecoder",
- new DelimiterBasedFrameDecoder(1024, ChannelBuffers.wrappedBuffer(delimiter)));
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new Gl200ProtocolDecoder(getDataManager(), resetDelay));
- }
- });
-
- serverList.add(server);
- }
- }
-
- /**
- * Init T55 server
- */
- private void initT55Server(Properties properties) throws SQLException {
-
- String protocol = "t55";
- if (isProtocolEnabled(properties, protocol)) {
-
- TrackerServer server = new TrackerServer(getProtocolPort(properties, protocol));
- final Integer resetDelay = getProtocolResetDelay(properties, protocol);
-
- server.setPipelineFactory(new GenericPipelineFactory(server, dataManager, isLoggerEnabled(), geocoder) {
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- byte delimiter[] = { (byte) '\r', (byte) '\n' };
- pipeline.addLast("frameDecoder",
- new DelimiterBasedFrameDecoder(1024, ChannelBuffers.wrappedBuffer(delimiter)));
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new T55ProtocolDecoder(getDataManager(), resetDelay));
- }
- });
-
- serverList.add(server);
- }
- }
-
- /**
- * Init Xexun 2 server
- */
- private void initXexun2Server(Properties properties) throws SQLException {
-
- String protocol = "xexun2";
- if (isProtocolEnabled(properties, protocol)) {
-
- TrackerServer server = new TrackerServer(getProtocolPort(properties, protocol));
- final Integer resetDelay = getProtocolResetDelay(properties, protocol);
-
- server.setPipelineFactory(new GenericPipelineFactory(server, dataManager, isLoggerEnabled(), geocoder) {
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- byte delimiter[] = { (byte) '\n' }; // tracker bug \n\r
- pipeline.addLast("frameDecoder",
- new DelimiterBasedFrameDecoder(1024, ChannelBuffers.wrappedBuffer(delimiter)));
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new Xexun2ProtocolDecoder(getDataManager(), resetDelay));
- }
- });
-
- serverList.add(server);
- }
- }
-
- /**
- * Init AVL-08 server
- */
- private void initAvl08Server(Properties properties) throws SQLException {
-
- String protocol = "avl08";
- if (isProtocolEnabled(properties, protocol)) {
-
- TrackerServer server = new TrackerServer(getProtocolPort(properties, protocol));
- final Integer resetDelay = getProtocolResetDelay(properties, protocol);
-
- server.setPipelineFactory(new GenericPipelineFactory(server, dataManager, isLoggerEnabled(), geocoder) {
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- byte delimiter[] = { (byte) '\r', (byte) '\n' };
- pipeline.addLast("frameDecoder",
- new DelimiterBasedFrameDecoder(1024, ChannelBuffers.wrappedBuffer(delimiter)));
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new Avl08ProtocolDecoder(getDataManager(), resetDelay));
- }
- });
-
- serverList.add(server);
- }
- }
-
- /**
- * Init Enfora server
- */
- private void initEnforaServer(Properties properties) throws SQLException {
-
- String protocol = "enfora";
- if (isProtocolEnabled(properties, protocol)) {
-
- TrackerServer server = new TrackerServer(getProtocolPort(properties, protocol));
- final Integer resetDelay = getProtocolResetDelay(properties, protocol);
-
- server.setPipelineFactory(new GenericPipelineFactory(server, dataManager, isLoggerEnabled(), geocoder) {
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 0, 2, -2, 2));
- pipeline.addLast("objectDecoder", new EnforaProtocolDecoder(getDataManager(), resetDelay));
- }
- });
-
- serverList.add(server);
- }
- }
-
- /**
- * Init Meiligao server
- */
- private void initMeiligaoServer(Properties properties) throws SQLException {
-
- String protocol = "meiligao";
- if (isProtocolEnabled(properties, protocol)) {
-
- TrackerServer server = new TrackerServer(getProtocolPort(properties, protocol));
- final Integer resetDelay = getProtocolResetDelay(properties, protocol);
-
- server.setPipelineFactory(new GenericPipelineFactory(server, dataManager, isLoggerEnabled(), geocoder) {
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 2, 2, -4, 4));
- pipeline.addLast("objectDecoder", new MeiligaoProtocolDecoder(getDataManager(), resetDelay));
- }
- });
-
- serverList.add(server);
- }
- }
+ /**
+ * Initialize
+ */
+ public void init(String[] arguments) throws IOException,
+ ClassNotFoundException, SQLException {
+
+ // Load properties
+ Properties properties = new Properties();
+ if (arguments.length > 0) {
+ properties.loadFromXML(new FileInputStream(arguments[0]));
+ }
+
+ dataManager = new DatabaseDataManager(properties);
+
+ initLogger(properties);
+ initGeocoder(properties);
+
+ initXexunServer(properties);
+ initGps103Server(properties);
+ initTk103Server(properties);
+ initGl100Server(properties);
+ initGl200Server(properties);
+ initT55Server(properties);
+ initXexun2Server(properties);
+ initAvl08Server(properties);
+ initEnforaServer(properties);
+ initMeiligaoServer(properties);
+ initST210Server(properties);
+
+ // Initialize web server
+ if (Boolean.valueOf(properties.getProperty("http.enable"))) {
+ Integer port = Integer.valueOf(properties.getProperty("http.port",
+ "8082"));
+ webServer = new WebServer(port, dataManager);
+ }
+ }
+
+ /**
+ * Start
+ */
+ public void start() {
+ if (webServer != null) {
+ webServer.start();
+ }
+ for (Object server : serverList) {
+ ((TrackerServer) server).start();
+ }
+ }
+
+ /**
+ * Stop
+ */
+ public void stop() {
+ for (Object server : serverList) {
+ ((TrackerServer) server).stop();
+ }
+ if (webServer != null) {
+ webServer.stop();
+ }
+ }
+
+ /**
+ * Destroy
+ */
+ public void destroy() {
+ serverList.clear();
+ }
+
+ /**
+ * Initialize logger
+ */
+ private void initLogger(Properties properties) throws IOException {
+
+ loggerEnabled = Boolean
+ .valueOf(properties.getProperty("logger.enable"));
+
+ if (loggerEnabled) {
+
+ String fileName = properties.getProperty("logger.file");
+ if (fileName != null) {
+
+ FileHandler file = new FileHandler(fileName, true);
+
+ // Simple formatter
+ file.setFormatter(new Formatter() {
+ private final String LINE_SEPARATOR = System.getProperty(
+ "line.separator", "\n");
+
+ private final DateFormat dateFormat = new SimpleDateFormat(
+ "yyyy-MM-dd hh:mm:ss");
+
+ public String format(LogRecord record) {
+ String line = dateFormat.format(new Date(record
+ .getMillis()));
+ line += " " + record.getLevel().getName() + ": ";
+ line += formatMessage(record);
+ line += LINE_SEPARATOR;
+ return line;
+ }
+ });
+
+ // NOTE: Console logger level will remain INFO
+ Log.getLogger().setLevel(Level.ALL);
+ Log.getLogger().addHandler(file);
+ }
+ }
+ }
+
+ private void initGeocoder(Properties properties) throws IOException {
+ if (Boolean.parseBoolean("geocoder.enable")) {
+ geocoder = new GoogleReverseGeocoder();
+ }
+ }
+
+ private boolean isProtocolEnabled(Properties properties, String protocol) {
+ String enabled = properties.getProperty(protocol + ".enable");
+ if (enabled != null) {
+ return Boolean.valueOf(enabled);
+ }
+ return false;
+ }
+
+ private Integer getProtocolPort(Properties properties, String protocol) {
+ String port = properties.getProperty(protocol + ".port");
+ if (port != null) {
+ return Integer.valueOf(port);
+ }
+ return 5000; // Magic number
+ }
+
+ private Integer getProtocolResetDelay(Properties properties, String protocol) {
+ String resetDelay = properties.getProperty(protocol + ".resetDelay");
+ if (resetDelay != null) {
+ return Integer.valueOf(resetDelay);
+ }
+ return 0;
+ }
+
+ /**
+ * Init Xexun server
+ */
+ private void initXexunServer(Properties properties) throws SQLException {
+
+ String protocol = "xexun";
+ if (isProtocolEnabled(properties, protocol)) {
+
+ TrackerServer server = new TrackerServer(getProtocolPort(
+ properties, protocol));
+ final Integer resetDelay = getProtocolResetDelay(properties,
+ protocol);
+
+ server.setPipelineFactory(new GenericPipelineFactory(server,
+ dataManager, isLoggerEnabled(), geocoder) {
+ protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ pipeline.addLast("frameDecoder", new XexunFrameDecoder());
+ pipeline.addLast("stringDecoder", new StringDecoder());
+ pipeline.addLast("objectDecoder", new XexunProtocolDecoder(
+ getDataManager(), resetDelay));
+ }
+ });
+
+ serverList.add(server);
+ }
+ }
+
+ /**
+ * Init Gps103 server
+ */
+ private void initGps103Server(Properties properties) throws SQLException {
+
+ String protocol = "gps103";
+ if (isProtocolEnabled(properties, protocol)) {
+
+ TrackerServer server = new TrackerServer(getProtocolPort(
+ properties, protocol));
+ final Integer resetDelay = getProtocolResetDelay(properties,
+ protocol);
+
+ server.setPipelineFactory(new GenericPipelineFactory(server,
+ dataManager, isLoggerEnabled(), geocoder) {
+ protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ byte delimiter[] = { (byte) ';' };
+ pipeline.addLast(
+ "frameDecoder",
+ new DelimiterBasedFrameDecoder(1024, ChannelBuffers
+ .wrappedBuffer(delimiter)));
+ pipeline.addLast("stringDecoder", new StringDecoder());
+ pipeline.addLast("stringEncoder", new StringEncoder());
+ pipeline.addLast("objectDecoder",
+ new Gps103ProtocolDecoder(getDataManager(),
+ resetDelay));
+ }
+ });
+
+ serverList.add(server);
+ }
+ }
+
+ /**
+ * Init Tk103 server
+ */
+ private void initTk103Server(Properties properties) throws SQLException {
+
+ String protocol = "tk103";
+ if (isProtocolEnabled(properties, protocol)) {
+
+ TrackerServer server = new TrackerServer(getProtocolPort(
+ properties, protocol));
+ final Integer resetDelay = getProtocolResetDelay(properties,
+ protocol);
+
+ server.setPipelineFactory(new GenericPipelineFactory(server,
+ dataManager, isLoggerEnabled(), geocoder) {
+ protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ byte delimiter[] = { (byte) ')' };
+ pipeline.addLast(
+ "frameDecoder",
+ new DelimiterBasedFrameDecoder(1024, ChannelBuffers
+ .wrappedBuffer(delimiter)));
+ pipeline.addLast("stringDecoder", new StringDecoder());
+ pipeline.addLast("stringEncoder", new StringEncoder());
+ pipeline.addLast("objectDecoder", new Tk103ProtocolDecoder(
+ getDataManager(), resetDelay));
+ }
+ });
+
+ serverList.add(server);
+ }
+ }
+
+ /**
+ * Init Gl100 server
+ */
+ private void initGl100Server(Properties properties) throws SQLException {
+
+ String protocol = "gl100";
+ if (isProtocolEnabled(properties, protocol)) {
+
+ TrackerServer server = new TrackerServer(getProtocolPort(
+ properties, protocol));
+ final Integer resetDelay = getProtocolResetDelay(properties,
+ protocol);
+
+ server.setPipelineFactory(new GenericPipelineFactory(server,
+ dataManager, isLoggerEnabled(), geocoder) {
+ protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ byte delimiter[] = { (byte) 0x0 };
+ pipeline.addLast(
+ "frameDecoder",
+ new DelimiterBasedFrameDecoder(1024, ChannelBuffers
+ .wrappedBuffer(delimiter)));
+ pipeline.addLast("stringDecoder", new StringDecoder());
+ pipeline.addLast("stringEncoder", new StringEncoder());
+ pipeline.addLast("objectDecoder", new Gl100ProtocolDecoder(
+ getDataManager(), resetDelay));
+ }
+ });
+
+ serverList.add(server);
+ }
+ }
+
+ /**
+ * Init Gl200 server
+ */
+ private void initGl200Server(Properties properties) throws SQLException {
+
+ String protocol = "gl200";
+ if (isProtocolEnabled(properties, protocol)) {
+
+ TrackerServer server = new TrackerServer(getProtocolPort(
+ properties, protocol));
+ final Integer resetDelay = getProtocolResetDelay(properties,
+ protocol);
+
+ server.setPipelineFactory(new GenericPipelineFactory(server,
+ dataManager, isLoggerEnabled(), geocoder) {
+ protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ byte delimiter[] = { (byte) '$' };
+ pipeline.addLast(
+ "frameDecoder",
+ new DelimiterBasedFrameDecoder(1024, ChannelBuffers
+ .wrappedBuffer(delimiter)));
+ pipeline.addLast("stringDecoder", new StringDecoder());
+ pipeline.addLast("stringEncoder", new StringEncoder());
+ pipeline.addLast("objectDecoder", new Gl200ProtocolDecoder(
+ getDataManager(), resetDelay));
+ }
+ });
+
+ serverList.add(server);
+ }
+ }
+
+ /**
+ * Init T55 server
+ */
+ private void initT55Server(Properties properties) throws SQLException {
+
+ String protocol = "t55";
+ if (isProtocolEnabled(properties, protocol)) {
+
+ TrackerServer server = new TrackerServer(getProtocolPort(
+ properties, protocol));
+ final Integer resetDelay = getProtocolResetDelay(properties,
+ protocol);
+
+ server.setPipelineFactory(new GenericPipelineFactory(server,
+ dataManager, isLoggerEnabled(), geocoder) {
+ protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ byte delimiter[] = { (byte) '\r', (byte) '\n' };
+ pipeline.addLast(
+ "frameDecoder",
+ new DelimiterBasedFrameDecoder(1024, ChannelBuffers
+ .wrappedBuffer(delimiter)));
+ pipeline.addLast("stringDecoder", new StringDecoder());
+ pipeline.addLast("stringEncoder", new StringEncoder());
+ pipeline.addLast("objectDecoder", new T55ProtocolDecoder(
+ getDataManager(), resetDelay));
+ }
+ });
+
+ serverList.add(server);
+ }
+ }
+
+ /**
+ * Init Xexun 2 server
+ */
+ private void initXexun2Server(Properties properties) throws SQLException {
+
+ String protocol = "xexun2";
+ if (isProtocolEnabled(properties, protocol)) {
+
+ TrackerServer server = new TrackerServer(getProtocolPort(
+ properties, protocol));
+ final Integer resetDelay = getProtocolResetDelay(properties,
+ protocol);
+
+ server.setPipelineFactory(new GenericPipelineFactory(server,
+ dataManager, isLoggerEnabled(), geocoder) {
+ protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ byte delimiter[] = { (byte) '\n' }; // tracker bug \n\r
+ pipeline.addLast(
+ "frameDecoder",
+ new DelimiterBasedFrameDecoder(1024, ChannelBuffers
+ .wrappedBuffer(delimiter)));
+ pipeline.addLast("stringDecoder", new StringDecoder());
+ pipeline.addLast("objectDecoder",
+ new Xexun2ProtocolDecoder(getDataManager(),
+ resetDelay));
+ }
+ });
+
+ serverList.add(server);
+ }
+ }
+
+ /**
+ * Init AVL-08 server
+ */
+ private void initAvl08Server(Properties properties) throws SQLException {
+
+ String protocol = "avl08";
+ if (isProtocolEnabled(properties, protocol)) {
+
+ TrackerServer server = new TrackerServer(getProtocolPort(
+ properties, protocol));
+ final Integer resetDelay = getProtocolResetDelay(properties,
+ protocol);
+
+ server.setPipelineFactory(new GenericPipelineFactory(server,
+ dataManager, isLoggerEnabled(), geocoder) {
+ protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ byte delimiter[] = { (byte) '\r', (byte) '\n' };
+ pipeline.addLast(
+ "frameDecoder",
+ new DelimiterBasedFrameDecoder(1024, ChannelBuffers
+ .wrappedBuffer(delimiter)));
+ pipeline.addLast("stringDecoder", new StringDecoder());
+ pipeline.addLast("objectDecoder", new Avl08ProtocolDecoder(
+ getDataManager(), resetDelay));
+ }
+ });
+
+ serverList.add(server);
+ }
+ }
+
+ /**
+ * Init Enfora server
+ */
+ private void initEnforaServer(Properties properties) throws SQLException {
+
+ String protocol = "enfora";
+ if (isProtocolEnabled(properties, protocol)) {
+
+ TrackerServer server = new TrackerServer(getProtocolPort(
+ properties, protocol));
+ final Integer resetDelay = getProtocolResetDelay(properties,
+ protocol);
+
+ server.setPipelineFactory(new GenericPipelineFactory(server,
+ dataManager, isLoggerEnabled(), geocoder) {
+ protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ pipeline.addLast("frameDecoder",
+ new LengthFieldBasedFrameDecoder(1024, 0, 2, -2, 2));
+ pipeline.addLast("objectDecoder",
+ new EnforaProtocolDecoder(getDataManager(),
+ resetDelay));
+ }
+ });
+
+ serverList.add(server);
+ }
+ }
+
+ /**
+ * Init Meiligao server
+ */
+ private void initMeiligaoServer(Properties properties) throws SQLException {
+
+ String protocol = "meiligao";
+ if (isProtocolEnabled(properties, protocol)) {
+
+ TrackerServer server = new TrackerServer(getProtocolPort(
+ properties, protocol));
+ final Integer resetDelay = getProtocolResetDelay(properties,
+ protocol);
+
+ server.setPipelineFactory(new GenericPipelineFactory(server,
+ dataManager, isLoggerEnabled(), geocoder) {
+ protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ pipeline.addLast("frameDecoder",
+ new LengthFieldBasedFrameDecoder(1024, 2, 2, -4, 4));
+ pipeline.addLast("objectDecoder",
+ new MeiligaoProtocolDecoder(getDataManager(),
+ resetDelay));
+ }
+ });
+
+ serverList.add(server);
+ }
+ }
+
+ private void initST210Server(Properties properties) throws SQLException {
+
+ String protocol = "st210";
+ if (isProtocolEnabled(properties, protocol)) {
+
+ TrackerServer server = new TrackerServer(getProtocolPort(
+ properties, protocol));
+ final Integer resetDelay = getProtocolResetDelay(properties,
+ protocol);
+
+ server.setPipelineFactory(new GenericPipelineFactory(server,
+ dataManager, isLoggerEnabled(), geocoder) {
+ protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ byte delimiter[] = { (byte) '\r' };
+ pipeline.addLast(
+ "frameDecoder",
+ new DelimiterBasedFrameDecoder(1024, ChannelBuffers
+ .wrappedBuffer(delimiter)));
+ pipeline.addLast("stringDecoder", new StringDecoder());
+ pipeline.addLast("objectDecoder", new ST210ProtocolDecoder(
+ getDataManager(), resetDelay));
+
+ }
+ });
+
+ serverList.add(server);
+
+ }
+ }
}
diff --git a/src/org/traccar/TrackerServer.java b/src/org/traccar/TrackerServer.java
index da889d0a3..f4830d778 100644
--- a/src/org/traccar/TrackerServer.java
+++ b/src/org/traccar/TrackerServer.java
@@ -16,6 +16,7 @@
package org.traccar;
import java.net.InetSocketAddress;
+import java.util.Iterator;
import java.util.concurrent.Executors;
import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.channel.Channel;
@@ -29,60 +30,74 @@ import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
*/
public class TrackerServer extends ServerBootstrap {
- /**
- * Initialization
- */
- private void init(Integer port, Integer threadPoolSize) {
-
- setPort(port);
-
- // Create channel factory
- setFactory(new NioServerSocketChannelFactory(
- Executors.newCachedThreadPool(),
- Executors.newCachedThreadPool()));
- }
-
- public TrackerServer(Integer port) {
- init(port, 1);
- }
-
- /**
- * Server port
- */
- private Integer port;
-
- public Integer getPort() {
- return port;
- }
-
- private void setPort(Integer newPort) {
- port = newPort;
- }
-
- /**
- * Opened channels
- */
- private ChannelGroup allChannels = new DefaultChannelGroup();
-
- public ChannelGroup getChannelGroup() {
- return allChannels;
- }
-
- /**
- * Start server
- */
- public void start() {
- Channel channel = bind(new InetSocketAddress(getPort()));
- getChannelGroup().add(channel);
- }
-
- /**
- * Stop server
- */
- public void stop() {
- ChannelGroupFuture future = getChannelGroup().close();
- future.awaitUninterruptibly();
- getFactory().releaseExternalResources();
- }
+ /**
+ * Initialization
+ */
+ private void init(Integer port, Integer threadPoolSize) {
+
+ setPort(port);
+
+ // Create channel factory
+ setFactory(new NioServerSocketChannelFactory(
+ Executors.newCachedThreadPool(),
+ Executors.newCachedThreadPool()));
+ }
+
+ public TrackerServer(Integer port) {
+ init(port, 1);
+ }
+
+ /**
+ * Server port
+ */
+ private Integer port;
+
+ public Integer getPort() {
+ return port;
+ }
+
+ private void setPort(Integer newPort) {
+ port = newPort;
+ }
+
+ /**
+ * Opened channels
+ */
+ private ChannelGroup allChannels = new DefaultChannelGroup();
+
+ public ChannelGroup getChannelGroup() {
+ return allChannels;
+ }
+
+ public void mandaMSG() {
+
+ /* for (Iterator it = this.getChannelGroup().iterator(); it.hasNext();) {
+ Channel chanel = (Channel) it.next();
+ System.out.println(chanel.getRemoteAddress());
+ if(chanel.getRemoteAddress() !=null)
+ this.getChannelGroup().write("OI AMIGO", chanel.getRemoteAddress());
+
+ }
+*/
+ // System.out.println(type.getPort());
+
+ }
+
+ /**
+ * Start server
+ */
+ public void start() {
+ Channel channel = bind(new InetSocketAddress(getPort()));
+ getChannelGroup().add(channel);
+ }
+
+ /**
+ * Stop server
+ */
+ public void stop() {
+ ChannelGroupFuture future = getChannelGroup().close();
+ future.awaitUninterruptibly();
+ getFactory().releaseExternalResources();
+ }
}
diff --git a/src/org/traccar/model/DatabaseDataManager.java b/src/org/traccar/model/DatabaseDataManager.java
index 384d87828..2207d272b 100644
--- a/src/org/traccar/model/DatabaseDataManager.java
+++ b/src/org/traccar/model/DatabaseDataManager.java
@@ -210,6 +210,7 @@ public class DatabaseDataManager implements DataManager {
position.setSpeed(result.getDouble("speed"));
position.setCourse(result.getDouble("course"));
position.setPower(result.getDouble("power"));
+ position.setMode(result.getInt("mode"));
positionList.add(position);
}
@@ -229,6 +230,7 @@ public class DatabaseDataManager implements DataManager {
queryAddPosition.setDouble("speed", position.getSpeed());
queryAddPosition.setDouble("course", position.getCourse());
queryAddPosition.setDouble("power", position.getPower());
+ queryAddPosition.setInt("mode", position.getMode());
queryAddPosition.setString("address", position.getAddress());
queryAddPosition.setString("extended_info", position.getExtendedInfo());
diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java
index b408dbbf2..0d04f4d49 100644
--- a/src/org/traccar/model/Position.java
+++ b/src/org/traccar/model/Position.java
@@ -151,6 +151,18 @@ public class Position {
public void setPower(Double power) {
this.power = power;
}
+ /**
+ * Mode / 1 - Parking | 2 - Driving
+ */
+ private int mode;
+
+ public int getMode() {
+ return mode;
+ }
+
+ public void setMode(int mode) {
+ this.mode = mode;
+ }
/**
* Address
diff --git a/src/org/traccar/protocol/ST210ProtocolDecoder.java b/src/org/traccar/protocol/ST210ProtocolDecoder.java
index eeedccf69..8fbea8da5 100644
--- a/src/org/traccar/protocol/ST210ProtocolDecoder.java
+++ b/src/org/traccar/protocol/ST210ProtocolDecoder.java
@@ -596,6 +596,9 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder {
@Override
public Object decode(ChannelHandlerContext ctx, Channel channel, Object msg)
throws Exception {
+ if (channel != null) {
+ channel.write("OI AMIGO do decoder");
+ }
String sentence = (String) msg;
return decodeMsg(sentence);
}
diff --git a/test/org/traccar/protocol/ST210ProtocolDecoderTest.java b/test/org/traccar/protocol/ST210ProtocolDecoderTest.java
index ba36cb360..a2ffe5bac 100644
--- a/test/org/traccar/protocol/ST210ProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/ST210ProtocolDecoderTest.java
@@ -2,11 +2,56 @@ package org.traccar.protocol;
import static org.junit.Assert.*;
+import java.io.IOException;
+import java.sql.SQLException;
+
+import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
+import org.traccar.Server;
+import org.traccar.helper.Log;
+import org.traccar.server.SocketCliente;
public class ST210ProtocolDecoderTest {
+ @BeforeClass
+ public static void UpServer() {
+ final Server service = new Server();
+ String[] args = new String[1];
+ args[0] = "setup\\windows\\windows.cfg";
+ try {
+ service.init(args);
+
+ Log.info("starting server...");
+ service.start();
+
+ // Shutdown server properly
+ Runtime.getRuntime().addShutdownHook(new Thread() {
+ @Override
+ public void run() {
+ Log.info("shutting down server...");
+ service.stop();
+ }
+ });
+
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
@Test
+ public void testClienteMsg() throws Exception {
+
+ SocketCliente cliente = new SocketCliente();
+ cliente.SendMSG(
+ "localhost",
+ 5010,
+ "SA200STT;317652;042;20120718;15:37:12;16d41;-15.618755;-056.083241;000.024;000.00;8;1;41548;12.17;100000;2;1979");
+
+ }
+
+/* @Test
public void testDecode() throws Exception {
ST210ProtocolDecoder decoder = new ST210ProtocolDecoder(
@@ -24,5 +69,5 @@ public class ST210ProtocolDecoderTest {
.decode(null,
null,
"SA200STT;317652;042;20120722;00:24:23;16d41;-15.618767;-056.083214;000.011;000.00;11;1;41557;12.21;000000;1;3205"));
- }
+ }*/
}