aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2012-08-19 22:16:12 +0400
committerAnton Tananaev <anton.tananaev@gmail.com>2012-08-19 22:16:12 +0400
commite7660ab714ee237ce080eaf14f5ab7f1997bea3f (patch)
tree1adbaee8db27325f3bfd99962484cc203c7743b4
parentb0b93983f5411ceffc649d44d55093b04ddf802a (diff)
parentdf91992080ee4db293e6f81882e95e72600d9bd8 (diff)
downloadtrackermap-server-e7660ab714ee237ce080eaf14f5ab7f1997bea3f.tar.gz
trackermap-server-e7660ab714ee237ce080eaf14f5ab7f1997bea3f.tar.bz2
trackermap-server-e7660ab714ee237ce080eaf14f5ab7f1997bea3f.zip
Merge branch 'master' of https://github.com/williamchitto/traccar into williamchitto-master
Conflicts: pom.xml src/org/traccar/Server.java
-rw-r--r--.gitignore6
-rw-r--r--pom.xml190
-rw-r--r--setup/windows/windows.cfg12
-rw-r--r--setup/windows/windowsPG.cfg154
-rw-r--r--src/org/traccar/Server.java852
-rw-r--r--src/org/traccar/TrackerEventHandler.java4
-rw-r--r--src/org/traccar/geocode/GoogleReverseGeocoder.java8
-rw-r--r--src/org/traccar/http/WebServer.java14
-rw-r--r--src/org/traccar/model/DatabaseDataManager.java3
-rw-r--r--src/org/traccar/model/Position.java19
-rw-r--r--src/org/traccar/protocol/ST210ProtocolDecoder.java19
-rw-r--r--src/web/index.html92
-rwxr-xr-xtest.sh8
-rw-r--r--test/org/traccar/protocol/ST210ProtocolDecoderTest.java60
14 files changed, 921 insertions, 520 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 000000000..6f3ccb7fa
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,6 @@
+*.class
+*.*~
+.classpath
+.project
+.settings/
+target/
diff --git a/pom.xml b/pom.xml
index b7e3b1a16..5f67b7189 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,83 +1,89 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <groupId>org.traccar</groupId>
- <artifactId>traccar</artifactId>
- <version>1.1-SNAPSHOT</version>
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.traccar</groupId>
+ <artifactId>traccar</artifactId>
+ <version>1.1-SNAPSHOT</version>
- <name>traccar</name>
- <url>http://www.traccar.org</url>
+ <name>traccar</name>
+ <url>http://www.traccar.org</url>
- <dependencies>
- <dependency>
- <groupId>com.h2database</groupId>
- <artifactId>h2</artifactId>
- <version>1.3.168</version>
- </dependency>
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- <version>5.1.21</version>
- </dependency>
- <dependency>
- <groupId>io.netty</groupId>
- <artifactId>netty</artifactId>
- <version>3.5.2.Final</version>
- </dependency>
+ <dependencies>
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ <version>1.3.168</version>
+ </dependency>
+ <dependency>
+ <groupId>mysql</groupId>
+ <artifactId>mysql-connector-java</artifactId>
+ <version>5.1.21</version>
+ </dependency>
+ <dependency>
+ <groupId>postgresql</groupId>
+ <artifactId>postgresql</artifactId>
+ <version>9.1-901.jdbc4</version>
+ </dependency>
+ <dependency>
+ <groupId>io.netty</groupId>
+ <artifactId>netty</artifactId>
+ <version>3.5.2.Final</version>
+ </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.10</version>
- </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.10</version>
+ </dependency>
- <!-- Jetty -->
- <dependency>
- <groupId>org.eclipse.jetty.orbit</groupId>
- <artifactId>javax.servlet</artifactId>
- <version>3.0.0.v201112011016</version>
- </dependency>
- <dependency>
- <groupId>org.eclipse.jetty</groupId>
- <artifactId>jetty-continuation</artifactId>
- <version>8.1.5.v20120716</version>
- </dependency>
- <dependency>
- <groupId>org.eclipse.jetty</groupId>
- <artifactId>jetty-http</artifactId>
- <version>8.1.5.v20120716</version>
- </dependency>
- <dependency>
- <groupId>org.eclipse.jetty</groupId>
- <artifactId>jetty-io</artifactId>
- <version>8.1.5.v20120716</version>
- </dependency>
- <dependency>
- <groupId>org.eclipse.jetty</groupId>
- <artifactId>jetty-util</artifactId>
- <version>8.1.5.v20120716</version>
- </dependency>
- <dependency>
- <groupId>org.eclipse.jetty</groupId>
- <artifactId>jetty-server</artifactId>
- <version>8.1.5.v20120716</version>
- </dependency>
- </dependencies>
+ <!-- Jetty -->
+ <dependency>
+ <groupId>org.eclipse.jetty.orbit</groupId>
+ <artifactId>javax.servlet</artifactId>
+ <version>3.0.0.v201112011016</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-continuation</artifactId>
+ <version>8.1.5.v20120716</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-http</artifactId>
+ <version>8.1.5.v20120716</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-io</artifactId>
+ <version>8.1.5.v20120716</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-util</artifactId>
+ <version>8.1.5.v20120716</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-server</artifactId>
+ <version>8.1.5.v20120716</version>
+ </dependency>
+ </dependencies>
- <build>
- <finalName>tracker-server</finalName>
- <outputDirectory>target/classes</outputDirectory>
- <sourceDirectory>src</sourceDirectory>
- <testSourceDirectory>test</testSourceDirectory>
- <resources>
- <resource>
- <directory>src</directory>
- <excludes>
- <exclude>**/*.java</exclude>
- </excludes>
- </resource>
- </resources>
+ <build>
+ <finalName>tracker-server</finalName>
+ <outputDirectory>target/classes</outputDirectory>
+ <sourceDirectory>src</sourceDirectory>
+ <testSourceDirectory>test</testSourceDirectory>
+ <resources>
+ <resource>
+ <directory>src</directory>
+ <excludes>
+ <exclude>**/*.java</exclude>
+ </excludes>
+ </resource>
+ </resources>
+<<<<<<< HEAD
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
@@ -111,6 +117,42 @@
</configuration>
</plugin>
</plugins>
+=======
+ <plugins>
+ <plugin>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <version>2.5</version>
+ <executions>
+ <execution>
+ <id>copy-dependencies</id>
+ <phase>package</phase>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ <configuration>
+ <outputDirectory>${project.build.directory}/lib</outputDirectory>
+ <excludeArtifactIds>junit</excludeArtifactIds>
+ <excludeTransitive>true</excludeTransitive>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>2.4</version>
+ <configuration>
+ <archive>
+ <manifest>
+ <mainClass>org.traccar.Main</mainClass>
+ <addClasspath>true</addClasspath>
+ <classpathPrefix>lib/</classpathPrefix>
+ </manifest>
+ </archive>
+ </configuration>
+ </plugin>
+ </plugins>
+>>>>>>> df91992080ee4db293e6f81882e95e72600d9bd8
- </build>
+ </build>
</project>
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/setup/windows/windowsPG.cfg b/setup/windows/windowsPG.cfg
new file mode 100644
index 000000000..aaefc4b21
--- /dev/null
+++ b/setup/windows/windowsPG.cfg
@@ -0,0 +1,154 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
+
+<properties>
+
+ <!-- Global confiduration -->
+ <entry key="database.driver">org.postgresql.Driver</entry>
+ <entry key="database.url">jdbc:postgresql:traccar</entry>
+ <entry key="database.user">postgres</entry>
+ <entry key="database.password">postgres</entry>
+
+ <!-- Database refresh delay in seconds -->
+ <entry key="database.refreshDelay">300</entry>
+
+ <!-- Create database schema -->
+ <!--
+ <entry key="database.initialize">
+ CREATE SEQUENCE devicesSQ START 1 INCREMENT 1;
+ CREATE SEQUENCE positionsSQ START 1 INCREMENT 1;
+ CREATE TABLE devices (id int8 NOT NULL,imei varchar(16) NOT NULL,phonenumber varchar(255),uniqueid varchar(255),CONSTRAINT devices_pkey PRIMARY KEY (id)) WITH (OIDS=FALSE);
+ ALTER TABLE devices OWNER TO postgres;
+ CREATE TABLE positions (id int8 NOT NULL,address varchar(255),altitude float8,course float8,extendedinfo varchar(255),latitude float8 NOT NULL,longitude float8 NOT NULL,power float8 NOT NULL,speed float8,"time" timestamp NOT NULL,"valid" bool,device_id int8 NOT NULL,"mode" int4,CONSTRAINT positions_pkey PRIMARY KEY (id),CONSTRAINT fk_device FOREIGN KEY (device_id) REFERENCES devices (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION) WITH (OIDS=FALSE);
+ ALTER TABLE positions OWNER TO postgres;
+ </entry>
+ -->
+
+ <!-->
+ id - Long
+ imei - String
+ <-->
+ <entry key="database.selectDevice">
+ SELECT id, imei
+ FROM devices
+ </entry>
+
+ <!-->
+ imei - String
+ <-->
+ <entry key="database.insertDevice">
+ INSERT INTO devices (id,imei)
+ VALUES (nextval('devicesSQ'),:imei)
+ </entry>
+
+ <!-->
+ id - Long
+ imei - String
+ <-->
+ <entry key="database.updateDevice">
+ UPDATE devices
+ SET imei = :imei
+ WHERE id = :id
+ </entry>
+
+ <!-->
+ id - Long
+ <-->
+ <entry key="database.deleteDevice">
+ DELETE FROM devices
+ WHERE id = :id
+ </entry>
+
+ <!-->
+ device_id - Long
+ <-->
+ <entry key="database.selectPosition">
+ SELECT *
+ FROM positions
+ WHERE device_id = :device_id
+ </entry>
+
+ <!-->
+ device_id - Long
+ time - Date
+ valid - Boolean
+ latitude - Double
+ longitude - Double
+ speed - Double
+ course - Double
+ power - Double (NULL for some protocols)
+ mode - Integer
+ extended_info - String (XML)
+ <-->
+ <entry key="database.insertPosition">
+ INSERT INTO positions (id, device_id, time, valid, latitude, longitude, speed, course, power, mode, address)
+ VALUES (nextval('positionsSQ'),:device_id, :time, :valid, :latitude, :longitude, :speed, :course, :power, :mode, :address)
+ </entry>
+
+ <!-- Web interface port -->
+ <entry key="http.enable">true</entry>
+ <entry key="http.port">8082</entry>
+
+ <entry key="geocoder.enable">true</entry>
+
+ <!-- Logging options -->
+ <entry key="logger.enable">true</entry>
+ <entry key="logger.file">jornadaLOG</entry>
+
+ <!-- Xexun server configuration -->
+ <entry key="xexun.enable">false</entry>
+ <entry key="xexun.port">5000</entry>
+ <entry key="xexun.resetDelay">0</entry>
+
+ <!-- Gps103 server configuration -->
+ <entry key="gps103.enable">false</entry>
+ <entry key="gps103.port">5001</entry>
+ <entry key="gps103.resetDelay">0</entry>
+
+ <!-- Tk103 server configuration -->
+ <entry key="tk103.enable">false</entry>
+ <entry key="tk103.port">5002</entry>
+ <entry key="tk103.resetDelay">0</entry>
+
+ <!-- Gl100 server configuration -->
+ <entry key="gl100.enable">false</entry>
+ <entry key="gl100.port">5003</entry>
+ <entry key="gl100.resetDelay">0</entry>
+
+ <!-- Gl200 server configuration -->
+ <entry key="gl200.enable">false</entry>
+ <entry key="gl200.port">5004</entry>
+ <entry key="gl200.resetDelay">0</entry>
+
+ <!-- T55 server configuration -->
+ <entry key="t55.enable">false</entry>
+ <entry key="t55.port">5005</entry>
+ <entry key="t55.resetDelay">0</entry>
+
+ <!-- Xexun 2 server configuration -->
+ <entry key="xexun2.enable">false</entry>
+ <entry key="xexun2.port">5006</entry>
+ <entry key="xexun2.resetDelay">0</entry>
+
+ <!-- AVL-08 server configuration -->
+ <entry key="avl08.enable">false</entry>
+ <entry key="avl08.port">5007</entry>
+ <entry key="avl08.resetDelay">0</entry>
+
+ <!-- Enfora server configuration -->
+ <entry key="enfora.enable">false</entry>
+ <entry key="enfora.port">5008</entry>
+ <entry key="enfora.resetDelay">0</entry>
+
+ <!-- Meiligao server configuration -->
+ <entry key="meiligao.enable">false</entry>
+ <entry key="meiligao.port">5009</entry>
+ <entry key="meiligao.resetDelay">0</entry>
+
+ <!-- ST-210 server configuration -->
+ <entry key="st210.enable">true</entry>
+ <entry key="st210.port">8801</entry>
+ <entry key="st210.resetDelay">0</entry>
+
+</properties>
diff --git a/src/org/traccar/Server.java b/src/org/traccar/Server.java
index 36d7720b6..a36da81e4 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,6 +49,7 @@ import org.traccar.protocol.*;
*/
public class Server {
+<<<<<<< HEAD
/**
* Server list
*/
@@ -120,341 +123,524 @@ public class Server {
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(8801)){
+
+ for (Iterator it = type.getChannelGroup().iterator(); it.hasNext();) {
+ Channel chanel = (Channel) it.next();
+ System.out.println(chanel.getRemoteAddress());
+
+ }
+ }
+ // System.out.println(type.getPort());
+
+ }
+>>>>>>> df91992080ee4db293e6f81882e95e72600d9bd8
}
- /**
- * 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(properties.getProperty("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(properties.getProperty("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);
+ Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol));
+ }
+ }
+
+ /**
+ * 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);
+ Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol));
+ }
+ }
+
+ /**
+ * 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);
+ Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol));
+ }
+ }
+
+ /**
+ * 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);
+ Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol));
+ }
+ }
+
+ /**
+ * 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);
+ Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol));
+ }
+ }
+
+ /**
+ * 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);
+ Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol));
+ }
+ }
+
+ /**
+ * 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);
+ Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol));
+ }
+ }
+
+ /**
+ * 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);
+ Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol));
+ }
+ }
+
+ /**
+ * 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);
+ Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol));
+ }
+ }
+
+ /**
+ * 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);
+ Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol));
+ }
+ }
+
+ 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);
+ Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol));
+
+ }
+ }
private void initMaxonServer(Properties properties) throws SQLException {
String protocol = "maxon";
diff --git a/src/org/traccar/TrackerEventHandler.java b/src/org/traccar/TrackerEventHandler.java
index 9e46372ca..07ecf71de 100644
--- a/src/org/traccar/TrackerEventHandler.java
+++ b/src/org/traccar/TrackerEventHandler.java
@@ -56,7 +56,9 @@ public class TrackerEventHandler extends SimpleChannelHandler {
", altitude: " + position.getAltitude() +
", speed: " + position.getSpeed() +
", course: " + position.getCourse() +
- ", power: " + position.getPower());
+ ", power: " + position.getPower() +
+ ", mode: " + position.getMode() +
+ ", address: " + position.getAddress());
}
// Write position to database
diff --git a/src/org/traccar/geocode/GoogleReverseGeocoder.java b/src/org/traccar/geocode/GoogleReverseGeocoder.java
index 724c60e50..a25f60d66 100644
--- a/src/org/traccar/geocode/GoogleReverseGeocoder.java
+++ b/src/org/traccar/geocode/GoogleReverseGeocoder.java
@@ -19,6 +19,8 @@ import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
+import java.nio.charset.Charset;
+
import org.traccar.helper.Log;
/**
@@ -36,8 +38,10 @@ public class GoogleReverseGeocoder implements ReverseGeocoder {
try {
URL url = new URL("http://maps.googleapis.com/maps/api/geocode/json?latlng=" + latitude + "," + longitude + "&sensor=false");
URLConnection connection = url.openConnection();
- BufferedReader reader = new BufferedReader(
- new InputStreamReader(connection.getInputStream()));
+
+ connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
+
+ BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(),Charset.forName("UTF-8")));
// Find address line
String line;
diff --git a/src/org/traccar/http/WebServer.java b/src/org/traccar/http/WebServer.java
index 5dfeabed2..853bff3de 100644
--- a/src/org/traccar/http/WebServer.java
+++ b/src/org/traccar/http/WebServer.java
@@ -147,14 +147,16 @@ public class WebServer {
Iterator<Position> i = dataManager.getPositions(Long.valueOf(deviceId)).iterator();
while (i.hasNext()) {
Position position = i.next();
- out.format("{'device_id':%d,'time':'%tF %tT','valid':%b,'latitude':%f,'longitude':%f,'speed':%f,'course':%f}",
+ out.format("{'device_id':%d,'time':'%s','valid':%b,'latitude':%s,'longitude':%s,'speed':%s,'course':%s,'mode':%d,'address':'%s'}",
position.getDeviceId(),
- position.getTime(), position.getTime(),
+ position.getTimeFormated(),
position.getValid(),
- position.getLatitude(),
- position.getLongitude(),
- position.getSpeed(),
- position.getCourse());
+ position.getLatitude().toString(),
+ position.getLongitude().toString(),
+ position.getSpeed().toString(),
+ position.getCourse().toString(),
+ position.getMode(),
+ position.getAddress());
if (i.hasNext()) out.print(",");
}
}
diff --git a/src/org/traccar/model/DatabaseDataManager.java b/src/org/traccar/model/DatabaseDataManager.java
index 384d87828..3092744c0 100644
--- a/src/org/traccar/model/DatabaseDataManager.java
+++ b/src/org/traccar/model/DatabaseDataManager.java
@@ -210,6 +210,8 @@ 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"));
+ position.setAddress(result.getString("address"));
positionList.add(position);
}
@@ -229,6 +231,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..e6ac46de1 100644
--- a/src/org/traccar/model/Position.java
+++ b/src/org/traccar/model/Position.java
@@ -15,6 +15,7 @@
*/
package org.traccar.model;
+import java.text.SimpleDateFormat;
import java.util.Date;
/**
@@ -56,6 +57,12 @@ public class Position {
public Date getTime() {
return time;
}
+
+ public String getTimeFormated(){
+ SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
+ df.setLenient(false);
+ return df.format(time);
+ }
public void setTime(Date time) {
this.time = time;
@@ -151,6 +158,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 f503fead6..d41a78da5 100644
--- a/src/org/traccar/protocol/ST210ProtocolDecoder.java
+++ b/src/org/traccar/protocol/ST210ProtocolDecoder.java
@@ -23,8 +23,7 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder {
}
private enum ST210FIELDS {
- HDR_STATUS("SA200STT;",
- "Status Report"),
+ HDR_STATUS("SA200STT;","Status Report"),
HDR_EMERGENCY("SA200EMG;","Emergency Report"),
HDR_EVENT("SA200EVT;", "Event Report"),
HDR_ALERT("SA200ALT;","Alert Report"),
@@ -33,7 +32,7 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder {
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("(\\d{2}\\w\\d{2});","Location Code ID (3 digits hex) + Serving Cell BSIC(2 digits decimal)"),
+ 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"),
@@ -44,8 +43,8 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder {
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"),
+ 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");
@@ -488,6 +487,10 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder {
patternStr += field.getPattern();
}
+ if(patternStr.endsWith(";")){
+ patternStr = patternStr.substring(0, patternStr.length()-1);
+ }
+
return Pattern.compile(patternStr);
}
@@ -611,7 +614,7 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder {
Log.info("MESSAGE DECODED WITH SUCCESS!");
}
catch(Exception e){
- Log.info("ERROR WHILE DECODING MESSAGE: " + e.getMessage());
+ Log.severe("ERROR WHILE DECODING MESSAGE: " + e.getMessage());
}
return position;
@@ -631,6 +634,10 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder {
throw new Exception("Pattern no match: " + protocolPattern.toString());
}
+ if(report.equals(ST210REPORTS.ALIVE)){
+ return null;
+ }
+
// Create new position
Position position = new Position();
diff --git a/src/web/index.html b/src/web/index.html
index cde73f47b..6be205300 100644
--- a/src/web/index.html
+++ b/src/web/index.html
@@ -1,7 +1,9 @@
-<!doctype html>
-<html>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
<head>
-<title>Traccar Manager</title>
+<title>Jornada Beta</title>
+<meta http-equiv="content-type" content="text/html;charset=utf-8" />
+
<link rel="stylesheet" type="text/css" href="http://cdn.sencha.io/ext-4.1.0-gpl/resources/css/ext-all.css" />
<script type="text/javascript" src="http://cdn.sencha.io/ext-4.1.0-gpl/ext-all.js"></script>
@@ -164,11 +166,12 @@ setCenter: {
},
// or just specify lat/long
+*/
setCenter: {
- lat: 42.345573,
- lng: -71.098326
-}
- * </code></pre>
+ lat: '-15.618767',
+ lng: '-56.083214'
+},
+ /* * </code></pre>listeners
*/
/**
* @cfg {Number} zoomLevel
@@ -176,7 +179,7 @@ setCenter: {
* Also used as the zoom level for panoramas, zero specifies no zoom at all.
* Defaults to <tt>3</tt>.
*/
- zoomLevel: 3,
+ zoomLevel: 10,
/**
* @cfg {Number} yaw
* The Yaw, or rotational direction of the users perspective in degrees. Only applies to panoramas.
@@ -289,7 +292,7 @@ markers: [{
Ext.defer(function(){
if (this.gmapType === 'map'){
- this.gmap = new google.maps.Map(this.getEl().dom, {zoom:this.zoomLevel,mapTypeId: google.maps.MapTypeId.ROADMAP});
+ this.gmap = new google.maps.Map(this.getEl().dom, {zoom:this.zoomLevel,mapTypeId: google.maps.MapTypeId.HYBRID});
this.mapDefined = true;
this.mapDefinedGMap = true;
}
@@ -300,7 +303,7 @@ markers: [{
}
if (!this.mapDefined && this.gmapType){
- this.gmap = new google.maps.Map(this.getEl().dom, {zoom:this.zoomLevel,mapTypeId: google.maps.MapTypeId.ROADMAP});
+ this.gmap = new google.maps.Map(this.getEl().dom, {zoom:this.zoomLevel,mapTypeId: google.maps.MapTypeId.HYBRID});
this.gmap.setMapTypeId(this.gmapType);
this.mapDefined = true;
this.mapDefinedGMap = true;
@@ -315,7 +318,7 @@ markers: [{
this.geoCodeLookup(this.setCenter.geoCodeAddr, this.setCenter.marker, false, true, this.setCenter.listeners);
}else{
if (this.gmapType === 'map'){
- var point = new google.maps.LatLng(this.setCenter.lat,this.setCenter.lng);
+ var point = new google.maps.LatLng(-15.618767,-56.083214);
this.getMap().setCenter(point, this.zoomLevel);
this.lastCenter = point;
}
@@ -471,9 +474,7 @@ markers: [{
this.lastCenter = point;
}
- var mark = new google.maps.Marker(Ext.apply(marker, {
- position: point
- }));
+ var mark = new google.maps.Marker(Ext.apply(marker, {position: point}));
if (marker.infoWindow){
this.createInfoWindow(marker.infoWindow, point, mark);
@@ -758,6 +759,7 @@ Ext.onReady(function() {
]
});
+
Ext.define('Position', {
extend: 'Ext.data.Model',
fields: [
@@ -768,7 +770,9 @@ Ext.onReady(function() {
{name: 'longitude', type: 'float'},
{name: 'speed', type: 'float'},
{name: 'course', type: 'float'},
- {name: 'power', type: 'float'}
+ {name: 'power', type: 'float'},
+ {name: 'mode', type: 'int'},
+ {name: 'address', type: 'string'}
]
});
@@ -806,7 +810,9 @@ Ext.onReady(function() {
'longitude',
'speed',
'course',
- 'power'
+ 'power',
+ 'mode',
+ 'address'
],
proxy: {
type: 'ajax',
@@ -824,7 +830,7 @@ Ext.onReady(function() {
});
var devicesPanel = Ext.create('Ext.grid.Panel', {
- title: 'Devices',
+ title: 'Dispositivos',
region: 'west',
split: true,
width: 300,
@@ -837,16 +843,16 @@ Ext.onReady(function() {
tbar: [
{
id: 'device_update',
- text: 'Update',
+ text: 'Atualizar',
handler : function() {
devices.load();
}
},
{
id: 'device_add',
- text: 'Add',
+ text: 'Incluir',
handler : function() {
- Ext.Msg.prompt('Add', 'Device IMEI:', function(btn, text) {
+ Ext.Msg.prompt('Incluir', 'IMEI do Dispositivo:', function(btn, text) {
if (btn == 'ok') {
devices.add({imei: text});
}
@@ -855,10 +861,10 @@ Ext.onReady(function() {
},
{
id: 'device_remove',
- text: 'Remove',
+ text: 'Remover',
disabled: true,
handler : function() {
- Ext.Msg.confirm('Remove', 'Are you sure to remove item?', function(btn) {
+ Ext.Msg.confirm('Remover', 'Confirma remoção do item?', function(btn) {
if (btn == 'yes') {
devices.remove(devicesPanel.getSelectionModel().getLastSelected());
}
@@ -867,10 +873,10 @@ Ext.onReady(function() {
},
{
id: 'device_edit',
- text: 'Edit',
+ text: 'Alterar',
disabled: true,
handler : function() {
- Ext.Msg.prompt('Edit', 'Device IMEI:', function(btn, text) {
+ Ext.Msg.prompt('Alterar', 'IMEI do Dispositivo:', function(btn, text) {
if (btn == 'ok') {
devicesPanel.getSelectionModel().getLastSelected().set('imei', text);
}
@@ -888,11 +894,11 @@ Ext.onReady(function() {
Ext.getCmp('device_remove').enable();
Ext.getCmp('device_edit').enable();
- positions.getProxy().url = positionsUrl + '?deviceId=' +
- devicesPanel.getSelectionModel().getLastSelected().get('id');
+ positions.getProxy().url = positionsUrl + '?deviceId=' + devicesPanel.getSelectionModel().getLastSelected().get('id');
positions.load();
Ext.getCmp('position_update').enable();
- } else {
+ }
+ else {
Ext.getCmp('position_update').disable();
positions.getProxy().url = positionsUrl;
positions.load();
@@ -905,7 +911,7 @@ Ext.onReady(function() {
});
var positionsPanel = Ext.create('Ext.grid.Panel', {
- title: 'Positions',
+ title: 'Posicionamentos',
region: 'south',
split: true,
height: 300,
@@ -918,7 +924,7 @@ Ext.onReady(function() {
tbar: [
{
id: 'position_update',
- text: 'Update',
+ text: 'Atualizar',
disabled: true,
handler : function() {
positions.load();
@@ -926,27 +932,31 @@ Ext.onReady(function() {
}
],
columns: [
- {header: 'Device Id', dataIndex: 'device_id'},
- {
- header: 'Time',
+ {header: 'Id Dispositivo', dataIndex: 'device_id'},
+ {header: 'Data/Hora',
dataIndex: 'time',
flex: 1,
- renderer: Ext.util.Format.dateRenderer('Y-m-d H:i:s')
+ sortable: true,
+ renderer: Ext.util.Format.dateRenderer('d/m/Y H:i:s'),
+ width: 100
},
- {header: 'Valid', dataIndex: 'valid'},
- {header: 'Latitude', dataIndex: 'latitude'},
- {header: 'Longitude', dataIndex: 'longitude'},
- {header: 'Speed', dataIndex: 'speed'},
- {header: 'Course', dataIndex: 'course'},
- {header: 'Power', dataIndex: 'power'}
+ {header: 'Endereço', dataIndex: 'address', width: 480},
+ {header: 'Latitude', dataIndex: 'latitude', width: 70},
+ {header: 'Longitude', dataIndex: 'longitude', width: 70},
+ {header: 'Velocidade', dataIndex: 'speed', width: 70},
+ {header: 'Curso', dataIndex: 'course', width: 70},
+ {header: 'Voltagem', dataIndex: 'power', width: 70},
+ {header: 'Modo', dataIndex: 'mode', width: 70},
+ {header: 'Válido', dataIndex: 'valid', width: 70}
],
listeners: {
selectionchange: function(sender, selected, eOpts) {
if (selected.length != 0) {
var lat = positionsPanel.getSelectionModel().getLastSelected().get('latitude');
var lng = positionsPanel.getSelectionModel().getLastSelected().get('longitude');
+ var title = positionsPanel.getSelectionModel().getLastSelected().get('address');
var point = new google.maps.LatLng(lat, lng);
- map.addMarker(point, {lat: lat, lng: lng}, true, true);
+ map.addMarker(point, {lat: lat, lng: lng, title: title}, true, true);
} else {
map.clearMarkers(); // private?
}
@@ -955,7 +965,7 @@ Ext.onReady(function() {
});
var mapPanel = Ext.create('Ext.panel.Panel', {
- title: 'Map',
+ title: 'Mapa',
region: 'center',
margins: {top: 5, bottom: 0, right: 5, left: 0},
diff --git a/test.sh b/test.sh
index b4a525182..66d4535eb 100755
--- a/test.sh
+++ b/test.sh
@@ -39,8 +39,10 @@ echo "9. meiligao"
(echo -n -e "\x24\x24\x00\x11\x12\x34\x56\xFF\xFF\xFF\xFF\x50\x00\x8B\x9B\x0D\x0A";) | nc -v localhost 5009
echo "10. st210"
-(echo -n -e "SA200STT;317652;042;20120807;10:43:23;16d41;-15.618767;-056.083214;000.011;000.00;11;1;41557;12.21;000000;1;3205\r";) | nc -v localhost 8801
-
-
+(echo -n -e "SA200STT;317652;042;20120807;10:43:23;4f310;-15.618767;-056.083214;000.011;000.00;11;1;41557;12.21;000000;1;3205\r";) | nc -v localhost 8801
+echo "11. st210emg"
+(echo -n -e "SA200EMG;317652;042;20120718;15:35:41;16d41;-15.618740;-056.083252;000.034;000.00;8;1;41548;12.17;110000;1\r";) | nc -v localhost 8801
+echo "12. st210alv"
+(echo -n -e "SA200ALV;317652\r";) | nc -v localhost 8801
diff --git a/test/org/traccar/protocol/ST210ProtocolDecoderTest.java b/test/org/traccar/protocol/ST210ProtocolDecoderTest.java
index 63234efd0..403b5621a 100644
--- a/test/org/traccar/protocol/ST210ProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/ST210ProtocolDecoderTest.java
@@ -1,58 +1,12 @@
package org.traccar.protocol;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
-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 {
@@ -70,19 +24,23 @@ public class ST210ProtocolDecoderTest {
assertNotNull(decoder
.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"));
+ "SA200STT;317652;042;20120722;00:24:23;4f310;-15.618767;-056.083214;000.011;000.00;11;1;41557;12.21;000000;1;3205"));
assertNotNull(decoder
.decode(null,
null,
- "SA200STT;315198;042;20120808;20:37:34;42948;-15.618731;-056.083216;000.007;000.00;12;1;48;0.00;000000;1;0127"));
+ "SA200STT;315198;042;20120808;20:37:34;3fac25;-15.618731;-056.083216;000.007;000.00;12;1;48;0.00;000000;1;0127"));
assertNotNull(decoder
.decode(null,
null,
- "SA200STT;315198;042;20120809;13:43:34;16d41;-15.618709;-056.083223;000.025;000.00;8;1;49;12.10;100000;2;0231"));
+ "SA200STT;315198;042;20120809;13:43:34;4f310;-15.618709;-056.083223;000.025;000.00;8;1;49;12.10;100000;2;0231"));
assertNotNull(decoder
.decode(null,
null,
"SA200EMG;317652;042;20120718;15:35:41;16d41;-15.618740;-056.083252;000.034;000.00;8;1;41548;12.17;110000;1"));
+ assertNull(decoder
+ .decode(null,
+ null,
+ "SA200ALV;317652"));
}
}