From 13d7ef6c133329c8a70ad123ac445ed3b45d756f Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 24 Jul 2012 17:43:51 -0400 Subject: Improve Maven to make jar, included README_MAVEN and removed unecessary files --- README_MAVEN.txt | 42 ++ build.xml | 74 --- nbproject/build-impl.xml | 1053 ----------------------------------------- nbproject/genfiles.properties | 8 - nbproject/project.properties | 101 ---- nbproject/project.xml | 15 - pom.xml | 22 +- 7 files changed, 58 insertions(+), 1257 deletions(-) create mode 100644 README_MAVEN.txt delete mode 100644 build.xml delete mode 100644 nbproject/build-impl.xml delete mode 100644 nbproject/genfiles.properties delete mode 100644 nbproject/project.properties delete mode 100644 nbproject/project.xml diff --git a/README_MAVEN.txt b/README_MAVEN.txt new file mode 100644 index 000000000..c12762bf0 --- /dev/null +++ b/README_MAVEN.txt @@ -0,0 +1,42 @@ +----------------ECLIPSE------------------------- +If you use Eclipse for Jave EE, you can simply import the generated +project into Eclipse. We've tested against Eclipse 3.6. Later versions +will likely also work, earlier versions may not. + +Eclipse users will need to install the following plugin components: +- Google Plugin for Eclipse (instructions at http://code.google.com/eclipse/) +- m2eclipse Core +- Maven Integration for WTP (in m2eclipse extras) + Instructions for installing the maven plugins can be found here: + http://m2eclipse.sonatype.org/installing-m2eclipse.html + +Ensure Eclipse is configured to use Java 1.6 as this sample uses +AppEngine. + +In Eclipse, go to the File menu and choose: + + File -> Import... -> Existing Maven Projects into Workspace + + Select the directory containing this file. + + Click Finish. + +You can now browse the project in Eclipse. + +To compile your project for deployment, just type 'mvn package'. + +--------------NETBEANS----------------- + +From the NetBeans IDE, install the Maven plugin. To do this, select Tools->Plugins, select Maven, click Install, and follow the prompts. + +Configure Maven in NetBeans IDE. To do this, select Tools->Options, select Miscellaneous from the top panel, then select the Maven tab. + +For the External Maven Home field, browse to your Maven installation. + +If the option is available, check Always use external Maven for building projects. Close the dialog. + +From the NetBeans IDE, select File->Open Project, and then browse to the location of the project you'd like to open. + +Check Open as Main Project, then click Open Project. + +Right-click the project and select Run. diff --git a/build.xml b/build.xml deleted file mode 100644 index 03869cab6..000000000 --- a/build.xml +++ /dev/null @@ -1,74 +0,0 @@ - - - - - - - - - - - Builds, tests, and runs the project tracker-server. - - - diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml deleted file mode 100644 index 37432878f..000000000 --- a/nbproject/build-impl.xml +++ /dev/null @@ -1,1053 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set src.dir - Must set test.src.dir - Must set build.dir - Must set dist.dir - Must set build.classes.dir - Must set dist.javadoc.dir - Must set build.test.classes.dir - Must set build.test.results.dir - Must set build.classes.excludes - Must set dist.jar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set javac.includes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set JVM to use for profiling in profiler.info.jvm - Must set profiler agent JVM arguments in profiler.info.jvmargs.agent - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select some files in the IDE or set javac.includes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - To run this application from the command line without Ant, try: - - - - - - - java -cp "${run.classpath.with.dist.jar}" ${main.class} - - - - - - - - - - - - - - - - - - - - - - - - - To run this application from the command line without Ant, try: - - java -jar "${dist.jar.resolved}" - - - - - - - - - - - - - - - - - - - - - - - - - Must select one file in the IDE or set run.class - - - - Must select one file in the IDE or set run.class - - - - - - - - - - - - - - - - - - - - - - - Must select one file in the IDE or set debug.class - - - - - Must select one file in the IDE or set debug.class - - - - - Must set fix.includes - - - - - - - - - - - - - - - - - Must select one file in the IDE or set profile.class - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select some files in the IDE or set javac.includes - - - - - - - - - - - - - - - - - - - - Some tests failed; see details above. - - - - - - - - - Must select some files in the IDE or set test.includes - - - - Some tests failed; see details above. - - - - - Must select one file in the IDE or set test.class - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select one file in the IDE or set applet.url - - - - - - - - - Must select one file in the IDE or set applet.url - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties deleted file mode 100644 index 3a5d43391..000000000 --- a/nbproject/genfiles.properties +++ /dev/null @@ -1,8 +0,0 @@ -build.xml.data.CRC32=06177666 -build.xml.script.CRC32=c43836c6 -build.xml.stylesheet.CRC32=28e38971@1.38.2.45 -# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. -# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=06177666 -nbproject/build-impl.xml.script.CRC32=d2f1c940 -nbproject/build-impl.xml.stylesheet.CRC32=fcddb364@1.50.2.46 diff --git a/nbproject/project.properties b/nbproject/project.properties deleted file mode 100644 index 6a702265f..000000000 --- a/nbproject/project.properties +++ /dev/null @@ -1,101 +0,0 @@ -annotation.processing.enabled=true -annotation.processing.enabled.in.editor=false -annotation.processing.processors.list= -annotation.processing.run.all.processors=true -application.title=tracker-server -application.vendor=user -build.classes.dir=${build.dir}/classes -build.classes.excludes=**/*.java,**/*.form -# This directory is removed when the project is cleaned: -build.dir=build -build.generated.dir=${build.dir}/generated -build.generated.sources.dir=${build.dir}/generated-sources -# Only compile against the classpath explicitly listed here: -build.sysclasspath=ignore -build.test.classes.dir=${build.dir}/test/classes -build.test.results.dir=${build.dir}/test/results -# Uncomment to specify the preferred debugger connection transport: -#debug.transport=dt_socket -debug.classpath=\ - ${run.classpath} -debug.test.classpath=\ - ${run.test.classpath} -# This directory is removed when the project is cleaned: -dist.dir=dist -dist.jar=${dist.dir}/tracker-server.jar -dist.javadoc.dir=${dist.dir}/javadoc -endorsed.classpath= -excludes= -file.reference.h2-1.3.167.jar=/home/user/Documents/lib/h2-1.3.167.jar -file.reference.jetty-continuation-8.1.4.v20120524.jar=/home/user/Documents/lib/jetty/jetty-continuation-8.1.4.v20120524.jar -file.reference.jetty-http-8.1.4.v20120524.jar=/home/user/Documents/lib/jetty/jetty-http-8.1.4.v20120524.jar -file.reference.jetty-io-8.1.4.v20120524.jar=/home/user/Documents/lib/jetty/jetty-io-8.1.4.v20120524.jar -file.reference.jetty-server-8.1.4.v20120524.jar=/home/user/Documents/lib/jetty/jetty-server-8.1.4.v20120524.jar -file.reference.jetty-util-8.1.4.v20120524.jar=/home/user/Documents/lib/jetty/jetty-util-8.1.4.v20120524.jar -file.reference.junit-4.10.jar=/home/user/Documents/lib/junit-4.10.jar -file.reference.mysql-connector-java-5.1.21-bin.jar=/home/user/Documents/lib/mysql-connector-java-5.1.21-bin.jar -file.reference.netty-3.5.2.Final.jar=/home/user/Documents/lib/netty-3.5.2.Final.jar -file.reference.servlet-api-3.0.jar=/home/user/Documents/lib/jetty/servlet-api-3.0.jar -includes=** -jar.archive.disabled=${jnlp.enabled} -jar.compress=false -jar.index=${jnlp.enabled} -javac.classpath=\ - ${file.reference.h2-1.3.167.jar}:\ - ${file.reference.netty-3.5.2.Final.jar}:\ - ${file.reference.jetty-continuation-8.1.4.v20120524.jar}:\ - ${file.reference.jetty-http-8.1.4.v20120524.jar}:\ - ${file.reference.jetty-io-8.1.4.v20120524.jar}:\ - ${file.reference.jetty-server-8.1.4.v20120524.jar}:\ - ${file.reference.jetty-util-8.1.4.v20120524.jar}:\ - ${file.reference.servlet-api-3.0.jar}:\ - ${file.reference.mysql-connector-java-5.1.21-bin.jar} -# Space-separated list of extra javac options -javac.compilerargs= -javac.deprecation=true -javac.processorpath=\ - ${javac.classpath} -javac.source=1.5 -javac.target=1.5 -javac.test.classpath=\ - ${javac.classpath}:\ - ${build.classes.dir}:\ - ${file.reference.junit-4.10.jar} -javadoc.additionalparam= -javadoc.author=false -javadoc.encoding=${source.encoding} -javadoc.noindex=false -javadoc.nonavbar=false -javadoc.notree=false -javadoc.private=false -javadoc.splitindex=true -javadoc.use=true -javadoc.version=false -javadoc.windowtitle= -jnlp.codebase.type=no.codebase -jnlp.descriptor=application -jnlp.enabled=false -jnlp.mixed.code=default -jnlp.offline-allowed=false -jnlp.signed=false -jnlp.signing= -jnlp.signing.alias= -jnlp.signing.keystore= -main.class=Main -manifest.file=manifest.mf -meta.inf.dir=${src.dir}/META-INF -mkdist.disabled=false -platform.active=default_platform -run.classpath=\ - ${javac.classpath}:\ - ${build.classes.dir} -# Space-separated list of JVM arguments used when running the project -# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value -# or test-sys-prop.name=value to set system properties for unit tests): -run.jvmargs= -run.test.classpath=\ - ${javac.test.classpath}:\ - ${build.test.classes.dir} -source.encoding=UTF-8 -src.dir=src -test.src.dir=test diff --git a/nbproject/project.xml b/nbproject/project.xml deleted file mode 100644 index ab723c074..000000000 --- a/nbproject/project.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - org.netbeans.modules.java.j2seproject - - - tracker-server - - - - - - - - - diff --git a/pom.xml b/pom.xml index b6d4a5a6d..9e11580f3 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.traccar traccar - 0.0.1-SNAPSHOT + 1.1.0-SNAPSHOT @@ -21,15 +21,25 @@ netty 3.5.2.Final - - javax.servlet - javax.servlet-api - 3.0.1 - junit junit 4.10 + + + tracker-server + target\classes + src + test + + + src + + **/*.java + + + + \ No newline at end of file -- cgit v1.2.3 From 7db70d18647246a838572a6246fa8ee4ef7a69b2 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 24 Jul 2012 17:43:51 -0400 Subject: Improve Maven to make jar, included README_MAVEN and removed unecessary files --- README_MAVEN.txt | 41 ++ build.xml | 74 --- nbproject/build-impl.xml | 1053 ----------------------------------------- nbproject/genfiles.properties | 8 - nbproject/project.properties | 101 ---- nbproject/project.xml | 15 - pom.xml | 22 +- 7 files changed, 57 insertions(+), 1257 deletions(-) create mode 100644 README_MAVEN.txt delete mode 100644 build.xml delete mode 100644 nbproject/build-impl.xml delete mode 100644 nbproject/genfiles.properties delete mode 100644 nbproject/project.properties delete mode 100644 nbproject/project.xml diff --git a/README_MAVEN.txt b/README_MAVEN.txt new file mode 100644 index 000000000..ffefa78c9 --- /dev/null +++ b/README_MAVEN.txt @@ -0,0 +1,41 @@ +----------------ECLIPSE------------------------- +If you use Eclipse for Jave EE, you can simply import the generated +project into Eclipse. We've tested against Eclipse 3.6. Later versions +will likely also work, earlier versions may not. + +Eclipse users will need to install the following plugin components: +- m2eclipse Core +- Maven Integration for WTP (in m2eclipse extras) + Instructions for installing the maven plugins can be found here: + http://m2eclipse.sonatype.org/installing-m2eclipse.html + +Ensure Eclipse is configured to use Java 1.6 as this sample uses +AppEngine. + +In Eclipse, go to the File menu and choose: + + File -> Import... -> Existing Maven Projects into Workspace + + Select the directory containing this file. + + Click Finish. + +You can now browse the project in Eclipse. + +To compile your project for deployment, just type 'mvn package'. + +--------------NETBEANS----------------- + +From the NetBeans IDE, install the Maven plugin. To do this, select Tools->Plugins, select Maven, click Install, and follow the prompts. + +Configure Maven in NetBeans IDE. To do this, select Tools->Options, select Miscellaneous from the top panel, then select the Maven tab. + +For the External Maven Home field, browse to your Maven installation. + +If the option is available, check Always use external Maven for building projects. Close the dialog. + +From the NetBeans IDE, select File->Open Project, and then browse to the location of the project you'd like to open. + +Check Open as Main Project, then click Open Project. + +Right-click the project and select Run. diff --git a/build.xml b/build.xml deleted file mode 100644 index 03869cab6..000000000 --- a/build.xml +++ /dev/null @@ -1,74 +0,0 @@ - - - - - - - - - - - Builds, tests, and runs the project tracker-server. - - - diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml deleted file mode 100644 index 37432878f..000000000 --- a/nbproject/build-impl.xml +++ /dev/null @@ -1,1053 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set src.dir - Must set test.src.dir - Must set build.dir - Must set dist.dir - Must set build.classes.dir - Must set dist.javadoc.dir - Must set build.test.classes.dir - Must set build.test.results.dir - Must set build.classes.excludes - Must set dist.jar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set javac.includes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set JVM to use for profiling in profiler.info.jvm - Must set profiler agent JVM arguments in profiler.info.jvmargs.agent - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select some files in the IDE or set javac.includes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - To run this application from the command line without Ant, try: - - - - - - - java -cp "${run.classpath.with.dist.jar}" ${main.class} - - - - - - - - - - - - - - - - - - - - - - - - - To run this application from the command line without Ant, try: - - java -jar "${dist.jar.resolved}" - - - - - - - - - - - - - - - - - - - - - - - - - Must select one file in the IDE or set run.class - - - - Must select one file in the IDE or set run.class - - - - - - - - - - - - - - - - - - - - - - - Must select one file in the IDE or set debug.class - - - - - Must select one file in the IDE or set debug.class - - - - - Must set fix.includes - - - - - - - - - - - - - - - - - Must select one file in the IDE or set profile.class - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select some files in the IDE or set javac.includes - - - - - - - - - - - - - - - - - - - - Some tests failed; see details above. - - - - - - - - - Must select some files in the IDE or set test.includes - - - - Some tests failed; see details above. - - - - - Must select one file in the IDE or set test.class - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select one file in the IDE or set applet.url - - - - - - - - - Must select one file in the IDE or set applet.url - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties deleted file mode 100644 index 3a5d43391..000000000 --- a/nbproject/genfiles.properties +++ /dev/null @@ -1,8 +0,0 @@ -build.xml.data.CRC32=06177666 -build.xml.script.CRC32=c43836c6 -build.xml.stylesheet.CRC32=28e38971@1.38.2.45 -# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. -# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=06177666 -nbproject/build-impl.xml.script.CRC32=d2f1c940 -nbproject/build-impl.xml.stylesheet.CRC32=fcddb364@1.50.2.46 diff --git a/nbproject/project.properties b/nbproject/project.properties deleted file mode 100644 index 6a702265f..000000000 --- a/nbproject/project.properties +++ /dev/null @@ -1,101 +0,0 @@ -annotation.processing.enabled=true -annotation.processing.enabled.in.editor=false -annotation.processing.processors.list= -annotation.processing.run.all.processors=true -application.title=tracker-server -application.vendor=user -build.classes.dir=${build.dir}/classes -build.classes.excludes=**/*.java,**/*.form -# This directory is removed when the project is cleaned: -build.dir=build -build.generated.dir=${build.dir}/generated -build.generated.sources.dir=${build.dir}/generated-sources -# Only compile against the classpath explicitly listed here: -build.sysclasspath=ignore -build.test.classes.dir=${build.dir}/test/classes -build.test.results.dir=${build.dir}/test/results -# Uncomment to specify the preferred debugger connection transport: -#debug.transport=dt_socket -debug.classpath=\ - ${run.classpath} -debug.test.classpath=\ - ${run.test.classpath} -# This directory is removed when the project is cleaned: -dist.dir=dist -dist.jar=${dist.dir}/tracker-server.jar -dist.javadoc.dir=${dist.dir}/javadoc -endorsed.classpath= -excludes= -file.reference.h2-1.3.167.jar=/home/user/Documents/lib/h2-1.3.167.jar -file.reference.jetty-continuation-8.1.4.v20120524.jar=/home/user/Documents/lib/jetty/jetty-continuation-8.1.4.v20120524.jar -file.reference.jetty-http-8.1.4.v20120524.jar=/home/user/Documents/lib/jetty/jetty-http-8.1.4.v20120524.jar -file.reference.jetty-io-8.1.4.v20120524.jar=/home/user/Documents/lib/jetty/jetty-io-8.1.4.v20120524.jar -file.reference.jetty-server-8.1.4.v20120524.jar=/home/user/Documents/lib/jetty/jetty-server-8.1.4.v20120524.jar -file.reference.jetty-util-8.1.4.v20120524.jar=/home/user/Documents/lib/jetty/jetty-util-8.1.4.v20120524.jar -file.reference.junit-4.10.jar=/home/user/Documents/lib/junit-4.10.jar -file.reference.mysql-connector-java-5.1.21-bin.jar=/home/user/Documents/lib/mysql-connector-java-5.1.21-bin.jar -file.reference.netty-3.5.2.Final.jar=/home/user/Documents/lib/netty-3.5.2.Final.jar -file.reference.servlet-api-3.0.jar=/home/user/Documents/lib/jetty/servlet-api-3.0.jar -includes=** -jar.archive.disabled=${jnlp.enabled} -jar.compress=false -jar.index=${jnlp.enabled} -javac.classpath=\ - ${file.reference.h2-1.3.167.jar}:\ - ${file.reference.netty-3.5.2.Final.jar}:\ - ${file.reference.jetty-continuation-8.1.4.v20120524.jar}:\ - ${file.reference.jetty-http-8.1.4.v20120524.jar}:\ - ${file.reference.jetty-io-8.1.4.v20120524.jar}:\ - ${file.reference.jetty-server-8.1.4.v20120524.jar}:\ - ${file.reference.jetty-util-8.1.4.v20120524.jar}:\ - ${file.reference.servlet-api-3.0.jar}:\ - ${file.reference.mysql-connector-java-5.1.21-bin.jar} -# Space-separated list of extra javac options -javac.compilerargs= -javac.deprecation=true -javac.processorpath=\ - ${javac.classpath} -javac.source=1.5 -javac.target=1.5 -javac.test.classpath=\ - ${javac.classpath}:\ - ${build.classes.dir}:\ - ${file.reference.junit-4.10.jar} -javadoc.additionalparam= -javadoc.author=false -javadoc.encoding=${source.encoding} -javadoc.noindex=false -javadoc.nonavbar=false -javadoc.notree=false -javadoc.private=false -javadoc.splitindex=true -javadoc.use=true -javadoc.version=false -javadoc.windowtitle= -jnlp.codebase.type=no.codebase -jnlp.descriptor=application -jnlp.enabled=false -jnlp.mixed.code=default -jnlp.offline-allowed=false -jnlp.signed=false -jnlp.signing= -jnlp.signing.alias= -jnlp.signing.keystore= -main.class=Main -manifest.file=manifest.mf -meta.inf.dir=${src.dir}/META-INF -mkdist.disabled=false -platform.active=default_platform -run.classpath=\ - ${javac.classpath}:\ - ${build.classes.dir} -# Space-separated list of JVM arguments used when running the project -# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value -# or test-sys-prop.name=value to set system properties for unit tests): -run.jvmargs= -run.test.classpath=\ - ${javac.test.classpath}:\ - ${build.test.classes.dir} -source.encoding=UTF-8 -src.dir=src -test.src.dir=test diff --git a/nbproject/project.xml b/nbproject/project.xml deleted file mode 100644 index ab723c074..000000000 --- a/nbproject/project.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - org.netbeans.modules.java.j2seproject - - - tracker-server - - - - - - - - - diff --git a/pom.xml b/pom.xml index b6d4a5a6d..9e11580f3 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.traccar traccar - 0.0.1-SNAPSHOT + 1.1.0-SNAPSHOT @@ -21,15 +21,25 @@ netty 3.5.2.Final - - javax.servlet - javax.servlet-api - 3.0.1 - junit junit 4.10 + + + tracker-server + target\classes + src + test + + + src + + **/*.java + + + + \ No newline at end of file -- cgit v1.2.3 From d9c99fafa2e4d581f473029144aec495cb94bb62 Mon Sep 17 00:00:00 2001 From: williamchitto Date: Wed, 25 Jul 2012 12:40:09 -0300 Subject: added protocol ST210ProtocolDecoder --- src/org/traccar/protocol/ST210ProtocolDecoder.java | 637 +++++++++++++++++++++ .../traccar/protocol/ST210ProtocolDecoderTest.java | 28 + 2 files changed, 665 insertions(+) create mode 100644 src/org/traccar/protocol/ST210ProtocolDecoder.java create mode 100644 test/org/traccar/protocol/ST210ProtocolDecoderTest.java diff --git a/src/org/traccar/protocol/ST210ProtocolDecoder.java b/src/org/traccar/protocol/ST210ProtocolDecoder.java new file mode 100644 index 000000000..eeedccf69 --- /dev/null +++ b/src/org/traccar/protocol/ST210ProtocolDecoder.java @@ -0,0 +1,637 @@ +package org.traccar.protocol; + +import java.util.Calendar; +import java.util.LinkedList; +import java.util.List; +import java.util.TimeZone; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.jboss.netty.channel.Channel; +import org.jboss.netty.channel.ChannelHandlerContext; +import org.traccar.GenericProtocolDecoder; +import org.traccar.helper.Log; +import org.traccar.model.DataManager; +import org.traccar.model.Position; + +public class ST210ProtocolDecoder extends GenericProtocolDecoder { + + /** + * Initialize + */ + public ST210ProtocolDecoder(DataManager dataManager, Integer resetDelay) { + super(dataManager, resetDelay); + } + + private enum ST210FIELDS { + HDR_STATUS("SA200STT;", "Status Report"), HDR_EMERGENCY("SA200EMG;", + "Emergency Report"), HDR_EVENT("SA200EVT;", "Event Report"), HDR_ALERT( + "SA200ALT;", "Alert Report"), HDR_ALIVE("SA200ALV;", + "Alive Report"), DEV_ID("(\\d+);", "Device ID"), SW_VER( + "(\\d{3});", "Software Release Version"), DATE("(\\d+);", + "GPS date (yyyymmdd) Year + Month + Day"), TIME( + "(\\d{2}:\\d{2}:\\d{2});", + "GPS time (hh:mm:ss) Hour : Minute : Second"), CELL( + "(\\d{2}\\w\\d{2});", + "Location Code ID (3 digits hex) + Serving Cell BSIC(2 digits decimal)"), LAT( + "(-\\d{2}.\\d+);", "Latitude (+/-xx.xxxxxx)"), LON( + "(-\\d{3}.\\d+);", "Longitude (+/-xxx.xxxxxx)"), SPD( + "(\\d{3}.\\d{3});", + "Speed in km/h - This value returns to 0 when it is over than 200,000Km"), CRS( + "(\\d{3}.\\d{2});", "Course over ground in degree"), SATT( + "(\\d+);", "Number of satellites"), FIX("(\\d);", + "GPS is fixed(1)\n" + "GPS is not fixed(0)"), DIST("(\\d+);", + "Traveled ddistance in meter"), PWR_VOLT("(\\d{2}.\\d{2});", + "Voltage value of main power"), IO("(\\d+);", + "Current I/O status of inputs and outputs."), MODE("(\\d);", + "1 = Idle mode (Parking)\n" + "2 = Active Mode (Driving)"), MSG_NUM( + "(\\d{4})", + "Message number - After 9999 is reported, message number returns to 0000"), EMG_ID( + "(\\d);", "Emergency type"), EVT_ID("(\\d);", "Event type"), ALERT_ID( + "(\\d);", "Alert type"); + + private String pattern; + + private String desc; + + private ST210FIELDS(String pattern, String desc) { + this.pattern = pattern; + this.desc = desc; + } + + public String getPattern() { + return pattern; + } + + public String getDesc() { + return desc; + } + + public void populatePosition(Position position, String groupValue, + DataManager dataManager) throws Exception { + + switch (this) { + + case DEV_ID: + position.setDeviceId(dataManager.getDeviceByImei(groupValue) + .getId()); + break; + + case LAT: + position.setLatitude(Double.valueOf(groupValue)); + break; + + case LON: + position.setLongitude(Double.valueOf(groupValue)); + break; + + case CRS: + position.setCourse(Double.valueOf(groupValue)); + break; + + case PWR_VOLT: + position.setPower(Double.valueOf(groupValue)); + break; + + case SPD: + position.setSpeed(Double.valueOf(groupValue)); + break; + + case DATE: { + // Date + Calendar time = Calendar.getInstance(TimeZone + .getTimeZone("UTC")); + time.clear(); + time.set(Calendar.YEAR, Integer.valueOf(Integer + .valueOf(groupValue.substring(0, 4)))); + time.set(Calendar.MONTH, Integer.valueOf(Integer + .valueOf(groupValue.substring(4, 6)))); + time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(Integer + .valueOf(groupValue.substring(6, 8)))); + position.setTime(time.getTime()); + break; + } + + case TIME: { + + Calendar time = Calendar.getInstance(TimeZone + .getTimeZone("UTC")); + time.clear(); + time.setTime(position.getTime()); + + time.set(Calendar.HOUR, Integer.valueOf(Integer + .valueOf(groupValue.substring(0, 2)))); + time.set(Calendar.MINUTE, Integer.valueOf(Integer + .valueOf(groupValue.substring(3, 5)))); + time.set(Calendar.SECOND, Integer.valueOf(Integer + .valueOf(groupValue.substring(6, 8)))); + + position.setTime(time.getTime()); + break; + } + + default: + break; + } + + } + } + + private enum FIELD_FIX_VALUE { + FIXED(1, "GPS is fixed"), NOT_FIXED(0, "GPS is not fixed"); + + private int value; + + private String desc; + + private FIELD_FIX_VALUE(int value, String desc) { + this.value = value; + this.desc = desc; + } + + public int getValue() { + return value; + } + + public String getDesc() { + return desc; + } + + public FIELD_FIX_VALUE getValueOf(String indiceStr) { + int indice = Integer.valueOf(indiceStr); + return getValueOf(indice); + } + + public FIELD_FIX_VALUE getValueOf(int indice) { + switch (indice) { + case 1: + return FIXED; + case 0: + return NOT_FIXED; + default: + throw new IllegalArgumentException("Índice não definido"); + } + } + } + + private enum FIELD_MODE_VALUE { + PARKING(1, "Idle mode (Parking)"), DRIVING(2, "Active Mode (Driving)"); + + private int value; + + private String desc; + + private FIELD_MODE_VALUE(int value, String desc) { + this.value = value; + this.desc = desc; + } + + public int getValue() { + return value; + } + + public String getDesc() { + return desc; + } + + public FIELD_MODE_VALUE getValueOf(String indiceStr) { + int indice = Integer.valueOf(indiceStr); + return getValueOf(indice); + } + + public FIELD_MODE_VALUE getValueOf(int indice) { + switch (indice) { + case 1: + return PARKING; + case 2: + return DRIVING; + default: + throw new IllegalArgumentException("Índice não definido"); + } + } + } + + private enum FIELD_EMG_ID_VALUE { + PANIC(1, "Emergency by panic button"), PARKING(2, + "Emergency by parking lock"), MAIN_POWER(3, + "Emergency by removing main power"), ANTI_THEFT(5, + "Emergency by anti-theft"); + + private int value; + + private String desc; + + private FIELD_EMG_ID_VALUE(int value, String desc) { + this.value = value; + this.desc = desc; + } + + public int getValue() { + return value; + } + + public String getDesc() { + return desc; + } + + public FIELD_EMG_ID_VALUE getValueOf(String indiceStr) { + int indice = Integer.valueOf(indiceStr); + return getValueOf(indice); + } + + public FIELD_EMG_ID_VALUE getValueOf(int indice) { + switch (indice) { + case 1: + return PANIC; + case 2: + return PARKING; + case 3: + return MAIN_POWER; + case 5: + return ANTI_THEFT; + default: + throw new IllegalArgumentException("Índice não definido"); + } + } + } + + private enum FIELD_EVT_ID_VALUE { + INPUT1_GROUND(1, "Input1 goes to ground state"), INPUT1_OPEN(2, + "Input1 goes to open state"), INPUT2_GROUND(3, + "Input2 goes to ground state"), INPUT2_OPEN(4, + "Input2 goes to open state"), INPUT3_GROUND(5, + "Input3 goes to ground state"), INPUT3_OPEN(6, + "Input3 goes to open state"); + + private int value; + + private String desc; + + private FIELD_EVT_ID_VALUE(int value, String desc) { + this.value = value; + this.desc = desc; + } + + public int getValue() { + return value; + } + + public String getDesc() { + return desc; + } + + public FIELD_EVT_ID_VALUE getValueOf(String indiceStr) { + int indice = Integer.valueOf(indiceStr); + return getValueOf(indice); + } + + public FIELD_EVT_ID_VALUE getValueOf(int indice) { + switch (indice) { + case 1: + return INPUT1_GROUND; + case 2: + return INPUT1_OPEN; + case 3: + return INPUT2_GROUND; + case 4: + return INPUT2_OPEN; + case 5: + return INPUT3_GROUND; + case 6: + return INPUT3_OPEN; + default: + throw new IllegalArgumentException("Índice não definido"); + } + } + } + + private enum FIELD_ALERT_ID_VALUE { + DRIVING_FASTER(1, "Start driving faster than SPEED_LIMIT"), OVER_SPPED( + 2, "Ended over speed condition"), DISCON_GPS(3, + "Disconnected GPS antenna"), RECON_GPS(4, + "Reconnected GPS antenna after disconnected"), OUT_GEO_FENCE(5, + "The vehicle went out from the geo-fence that has following ID"), INTO_GEO_FENCE( + 6, + "The vehicle entered into the geo-fence that has following ID"), SHORTED_GPS( + 8, "Shorted GPS antenna"), DEEP_SLEEP_ON(9, + "Enter to deep sleep mode"), DEEP_SLEEP_OFF(10, + "Exite from deep sleep mode"), BKP_BATTERY(13, + "Backup battery error"), BATTERY_DOWN(14, + "Vehicle battery goes down to so low level"), SHOCKED(15, + "Shocked"), COLLISION(16, "Occurred some collision"), DEVIATE_ROUT( + 18, "Deviate from predefined rout"), ENTER_ROUT(19, + "Enter into predefined rout"); + + private int value; + + private String desc; + + private FIELD_ALERT_ID_VALUE(int value, String desc) { + this.value = value; + this.desc = desc; + } + + public int getValue() { + return value; + } + + public String getDesc() { + return desc; + } + + public FIELD_ALERT_ID_VALUE getValueOf(String indiceStr) { + int indice = Integer.valueOf(indiceStr); + return getValueOf(indice); + } + + public FIELD_ALERT_ID_VALUE getValueOf(int indice) { + switch (indice) { + case 1: + return DRIVING_FASTER; + case 2: + return OVER_SPPED; + case 3: + return DISCON_GPS; + case 4: + return RECON_GPS; + case 5: + return OUT_GEO_FENCE; + case 6: + return INTO_GEO_FENCE; + case 8: + return SHORTED_GPS; + case 9: + return DEEP_SLEEP_ON; + case 10: + return DEEP_SLEEP_OFF; + case 13: + return BKP_BATTERY; + case 14: + return BATTERY_DOWN; + case 15: + return SHOCKED; + case 16: + return COLLISION; + case 18: + return DEVIATE_ROUT; + case 19: + return ENTER_ROUT; + default: + throw new IllegalArgumentException("Índice não definido"); + } + } + } + + private enum ST210REPORTS { + + STATUS("SA200STT"), EMERGENCY("SA200EMG"), EVENT("SA200EVT"), ALERT( + "SA200ALT"), ALIVE("SA200ALV"); + + private String header; + + private ST210REPORTS(String header) { + this.header = header; + } + + public String getHeader() { + return this.header; + } + + public List getProtocol() { + + if (this.equals(STATUS)) { + return StatusProtocol; + } + + if (this.equals(EMERGENCY)) { + return EmergencyProtocol; + } + + if (this.equals(EVENT)) { + return EventProtocol; + } + + if (this.equals(ALERT)) { + return AlertProtocol; + } + + if (this.equals(ALIVE)) { + return AliveProtocol; + } + + return null; + } + + public Pattern getProtocolPattern() { + + if (this.equals(STATUS)) { + return getPattern(StatusProtocol); + } + + if (this.equals(EMERGENCY)) { + return getPattern(EmergencyProtocol); + } + + if (this.equals(EVENT)) { + return getPattern(EventProtocol); + } + + if (this.equals(ALERT)) { + return getPattern(AlertProtocol); + } + + if (this.equals(ALIVE)) { + return getPattern(AliveProtocol); + } + + return null; + } + + } + + private static ST210REPORTS getReportType(String msg) { + + if (msg.startsWith(ST210REPORTS.STATUS.getHeader())) { + return ST210REPORTS.STATUS; + } + + if (msg.startsWith(ST210REPORTS.EMERGENCY.getHeader())) { + return ST210REPORTS.EMERGENCY; + } + + if (msg.startsWith(ST210REPORTS.EVENT.getHeader())) { + return ST210REPORTS.EVENT; + } + + if (msg.startsWith(ST210REPORTS.ALERT.getHeader())) { + return ST210REPORTS.ALERT; + } + + if (msg.startsWith(ST210REPORTS.ALIVE.getHeader())) { + return ST210REPORTS.ALIVE; + } + + return null; + } + + public static Pattern getPattern(List protocol) { + + String patternStr = ""; + + for (ST210FIELDS field : protocol) { + patternStr += field.getPattern(); + } + + return Pattern.compile(patternStr); + + } + + @SuppressWarnings("serial") + static private List StatusProtocol = new LinkedList() { + + { + add(ST210FIELDS.HDR_STATUS); + add(ST210FIELDS.DEV_ID); + add(ST210FIELDS.SW_VER); + add(ST210FIELDS.DATE); + add(ST210FIELDS.TIME); + add(ST210FIELDS.CELL); + add(ST210FIELDS.LAT); + add(ST210FIELDS.LON); + add(ST210FIELDS.SPD); + add(ST210FIELDS.CRS); + add(ST210FIELDS.SATT); + add(ST210FIELDS.FIX); + add(ST210FIELDS.DIST); + add(ST210FIELDS.PWR_VOLT); + add(ST210FIELDS.IO); + add(ST210FIELDS.MODE); + add(ST210FIELDS.MSG_NUM); + } + + }; + + @SuppressWarnings("serial") + static private List EmergencyProtocol = new LinkedList() { + + { + add(ST210FIELDS.HDR_EMERGENCY); + add(ST210FIELDS.DEV_ID); + add(ST210FIELDS.SW_VER); + add(ST210FIELDS.DATE); + add(ST210FIELDS.TIME); + add(ST210FIELDS.CELL); + add(ST210FIELDS.LAT); + add(ST210FIELDS.LON); + add(ST210FIELDS.SPD); + add(ST210FIELDS.CRS); + add(ST210FIELDS.SATT); + add(ST210FIELDS.FIX); + add(ST210FIELDS.DIST); + add(ST210FIELDS.PWR_VOLT); + add(ST210FIELDS.IO); + add(ST210FIELDS.EMG_ID); + } + + }; + + @SuppressWarnings("serial") + static private List EventProtocol = new LinkedList() { + + { + add(ST210FIELDS.HDR_EVENT); + add(ST210FIELDS.DEV_ID); + add(ST210FIELDS.SW_VER); + add(ST210FIELDS.DATE); + add(ST210FIELDS.TIME); + add(ST210FIELDS.CELL); + add(ST210FIELDS.LAT); + add(ST210FIELDS.LON); + add(ST210FIELDS.SPD); + add(ST210FIELDS.CRS); + add(ST210FIELDS.SATT); + add(ST210FIELDS.FIX); + add(ST210FIELDS.DIST); + add(ST210FIELDS.PWR_VOLT); + add(ST210FIELDS.IO); + add(ST210FIELDS.EVT_ID); + } + + }; + + @SuppressWarnings("serial") + static private List AlertProtocol = new LinkedList() { + + { + add(ST210FIELDS.HDR_ALERT); + add(ST210FIELDS.DEV_ID); + add(ST210FIELDS.SW_VER); + add(ST210FIELDS.DATE); + add(ST210FIELDS.TIME); + add(ST210FIELDS.CELL); + add(ST210FIELDS.LAT); + add(ST210FIELDS.LON); + add(ST210FIELDS.SPD); + add(ST210FIELDS.CRS); + add(ST210FIELDS.SATT); + add(ST210FIELDS.FIX); + add(ST210FIELDS.DIST); + add(ST210FIELDS.PWR_VOLT); + add(ST210FIELDS.IO); + add(ST210FIELDS.ALERT_ID); + } + + }; + + @SuppressWarnings("serial") + static private List AliveProtocol = new LinkedList() { + + { + add(ST210FIELDS.HDR_ALIVE); + add(ST210FIELDS.DEV_ID); + } + + }; + + @Override + public Object decode(ChannelHandlerContext ctx, Channel channel, Object msg) + throws Exception { + String sentence = (String) msg; + return decodeMsg(sentence); + } + + public Position decodeMsg(String msg) throws Exception { + + ST210REPORTS report = getReportType(msg); + + List protocol = report.getProtocol(); + + Pattern protocolPattern = report.getProtocolPattern(); + + Log.info("Protocol Pattern: " + protocolPattern.toString()); + Log.info("Msg: " + msg); + + // Parse message + Matcher parser = protocolPattern.matcher(msg); + if (!parser.matches()) { + return null; + } + + // Create new position + Position position = new Position(); + + position.setAltitude(0D); + position.setExtendedInfo(""); + position.setValid(true); + + Integer index = 0; + for (ST210FIELDS field : protocol) { + + String groupValue = parser.group(index++); + + field.populatePosition(position, groupValue, getDataManager()); + } + + return position; + } +} diff --git a/test/org/traccar/protocol/ST210ProtocolDecoderTest.java b/test/org/traccar/protocol/ST210ProtocolDecoderTest.java new file mode 100644 index 000000000..ba36cb360 --- /dev/null +++ b/test/org/traccar/protocol/ST210ProtocolDecoderTest.java @@ -0,0 +1,28 @@ +package org.traccar.protocol; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class ST210ProtocolDecoderTest { + + @Test + public void testDecode() throws Exception { + + ST210ProtocolDecoder decoder = new ST210ProtocolDecoder( + new TestDataManager(), 0); + + assertNotNull(decoder + .decode(null, + null, + "SA200STT;317652;042;20120718;15:37:12;16d41;-15.618755;-056.083241;000.024;000.00;8;1;41548;12.17;100000;2;1979")); + assertNotNull(decoder + .decode(null, + null, + "SA200STT;317652;042;20120721;19:04:30;16d41;-15.618743;-056.083221;000.001;000.00;12;1;41557;12.21;000000;1;3125")); + 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")); + } +} -- cgit v1.2.3 From f5e305c4ea89210a2e4daffa4e947acdc440fbe7 Mon Sep 17 00:00:00 2001 From: williamchitto Date: Tue, 31 Jul 2012 08:08:53 -0300 Subject: adicionando classes de testes --- setup/windows/windows.cfg | 12 +- src/Main.java | 10 +- src/org/traccar/GenericPipelineFactory.java | 2 + src/org/traccar/Server.java | 914 ++++++++++++--------- src/org/traccar/TrackerServer.java | 125 +-- src/org/traccar/model/DatabaseDataManager.java | 2 + src/org/traccar/model/Position.java | 12 + src/org/traccar/protocol/ST210ProtocolDecoder.java | 3 + .../traccar/protocol/ST210ProtocolDecoderTest.java | 47 +- 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 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); @@ -72,11 +72,12 @@ speed - Double course - Double power - Double (NULL for some protocols) + mode - Integer extended_info - String (XML) <--> 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) @@ -84,7 +85,7 @@ 8082 - false + true [LOG] @@ -136,5 +137,10 @@ true 5009 0 + + + true + 5010 + 0 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 serverList; - - private boolean loggerEnabled; - - public Server() { - serverList = new LinkedList(); - 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 serverList; + + private boolean loggerEnabled; + + public Server() { + serverList = new LinkedList(); + 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")); - } + }*/ } -- cgit v1.2.3 From b11ff82a003b828dbaecc564c54d447440249701 Mon Sep 17 00:00:00 2001 From: williamchitto Date: Tue, 31 Jul 2012 12:00:03 -0300 Subject: Added socket client --- test/org/traccar/server/SocketCliente.java | 44 ++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 test/org/traccar/server/SocketCliente.java diff --git a/test/org/traccar/server/SocketCliente.java b/test/org/traccar/server/SocketCliente.java new file mode 100644 index 000000000..c26c02e49 --- /dev/null +++ b/test/org/traccar/server/SocketCliente.java @@ -0,0 +1,44 @@ +package org.traccar.server; + +import java.io.IOException; +import java.io.PrintStream; +import java.net.Socket; + +public class SocketCliente { + + /** + * @param args + */ + public void SendMSG(String url, int port, String msg) { + + Socket s = null; + + PrintStream ps = null; + + try { + + s = new Socket(url, port); + + ps = new PrintStream(s.getOutputStream()); + + ps.println(msg); + + System.out.println("send"); + + } catch (IOException e) { + + System.out + .println("Some problem happened on send data to socket."); + + } finally { + + try { + s.close(); + } catch (IOException e) { + } + + } + + } + +} -- cgit v1.2.3 From 1dcac709aecfeaf19d616316bd2f23b96ef86390 Mon Sep 17 00:00:00 2001 From: leandro Date: Fri, 3 Aug 2012 13:11:52 -0400 Subject: Atualização de parametros e dependencia do postgre MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 5 +++++ src/Main.java | 26 ++++++++++++++------------ src/org/traccar/Server.java | 11 +++++++++++ 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index 9e11580f3..a880e58ee 100644 --- a/pom.xml +++ b/pom.xml @@ -26,6 +26,11 @@ junit 4.10 + + postgresql + postgresql + 8.1-407.jdbc3 + diff --git a/src/Main.java b/src/Main.java index 783ebe0f6..69c029c61 100644 --- a/src/Main.java +++ b/src/Main.java @@ -4,21 +4,23 @@ import org.traccar.helper.Log; public class Main { public static void main(String[] args) throws Exception { - - final Server service = new Server(); - String[] argss = new String[1]; - argss[0] = "setup\\windows\\windows.cfg"; - service.init(argss); - - Log.info("starting server..."); - + + final Server service = new Server(); + + if(args.length > 0){ + Log.info("Using parameterized config: " + args[0]); + service.init(args); + } + else{ + String[] argsDefault = new String[]{"setup\\windows\\windows.cfg"}; + Log.info("Using default config: " + argsDefault[0]); + service.init(argsDefault); + } + Log.info("starting server..."); + service.start(); - - - - // Shutdown server properly Runtime.getRuntime().addShutdownHook(new Thread() { @Override diff --git a/src/org/traccar/Server.java b/src/org/traccar/Server.java index e6eabdb71..f01b5af2a 100644 --- a/src/org/traccar/Server.java +++ b/src/org/traccar/Server.java @@ -251,6 +251,7 @@ public class Server { }); serverList.add(server); + Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } @@ -284,6 +285,7 @@ public class Server { }); serverList.add(server); + Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } @@ -316,6 +318,7 @@ public class Server { }); serverList.add(server); + Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } @@ -348,6 +351,7 @@ public class Server { }); serverList.add(server); + Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } @@ -380,6 +384,7 @@ public class Server { }); serverList.add(server); + Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } @@ -412,6 +417,7 @@ public class Server { }); serverList.add(server); + Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } @@ -444,6 +450,7 @@ public class Server { }); serverList.add(server); + Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } @@ -475,6 +482,7 @@ public class Server { }); serverList.add(server); + Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } @@ -503,6 +511,7 @@ public class Server { }); serverList.add(server); + Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } @@ -531,6 +540,7 @@ public class Server { }); serverList.add(server); + Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } @@ -560,6 +570,7 @@ public class Server { }); serverList.add(server); + Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } -- cgit v1.2.3 From f1eb1b7c77219b09fcfe3ce1bea918d8807388d1 Mon Sep 17 00:00:00 2001 From: Leandro Silva Ferreira Date: Sat, 4 Aug 2012 16:45:08 -0400 Subject: Adicionado gitignore para desconsiderar configuracoes do eclipse e targ do maven --- .gitignore | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..b8abee9f2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +# Compiled source # +################### +*.class + +# Eclipse Files # +################### +.classpath +.project +.settings/ +target/ + -- cgit v1.2.3 From 1205bd5f9b708ff2633551e6e38f4e90b1efd35b Mon Sep 17 00:00:00 2001 From: Leandro Silva Ferreira Date: Sat, 4 Aug 2012 17:13:21 -0400 Subject: Correção de identações MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/org/traccar/Server.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/org/traccar/Server.java b/src/org/traccar/Server.java index f01b5af2a..df035fc21 100644 --- a/src/org/traccar/Server.java +++ b/src/org/traccar/Server.java @@ -120,8 +120,7 @@ public class Server { // Initialize web server if (Boolean.valueOf(properties.getProperty("http.enable"))) { - Integer port = Integer.valueOf(properties.getProperty("http.port", - "8082")); + Integer port = Integer.valueOf(properties.getProperty("http.port","8082")); webServer = new WebServer(port, dataManager); } } @@ -162,8 +161,7 @@ public class Server { */ private void initLogger(Properties properties) throws IOException { - loggerEnabled = Boolean - .valueOf(properties.getProperty("logger.enable")); + loggerEnabled = Boolean.valueOf(properties.getProperty("logger.enable")); if (loggerEnabled) { -- cgit v1.2.3 From 5a80591e29ee7b05ed50737e3d5d6bb98c1f59a3 Mon Sep 17 00:00:00 2001 From: Leandro Silva Ferreira Date: Sat, 4 Aug 2012 17:26:40 -0400 Subject: Mais correções de identações para testes com github MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/org/traccar/Server.java | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/org/traccar/Server.java b/src/org/traccar/Server.java index df035fc21..612eeb32a 100644 --- a/src/org/traccar/Server.java +++ b/src/org/traccar/Server.java @@ -172,15 +172,12 @@ public class Server { // Simple formatter file.setFormatter(new Formatter() { - private final String LINE_SEPARATOR = System.getProperty( - "line.separator", "\n"); + private final String LINE_SEPARATOR = System.getProperty("line.separator", "\n"); - private final DateFormat dateFormat = new SimpleDateFormat( - "yyyy-MM-dd hh:mm:ss"); + 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())); + String line = dateFormat.format(new Date(record.getMillis())); line += " " + record.getLevel().getName() + ": "; line += formatMessage(record); line += LINE_SEPARATOR; @@ -233,18 +230,14 @@ public class Server { String protocol = "xexun"; if (isProtocolEnabled(properties, protocol)) { - TrackerServer server = new TrackerServer(getProtocolPort( - properties, protocol)); - final Integer resetDelay = getProtocolResetDelay(properties, - protocol); + TrackerServer server = new TrackerServer(getProtocolPort(properties, protocol)); + final Integer resetDelay = getProtocolResetDelay(properties,protocol); - server.setPipelineFactory(new GenericPipelineFactory(server, - dataManager, isLoggerEnabled(), geocoder) { + 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)); + pipeline.addLast("objectDecoder", new XexunProtocolDecoder(getDataManager(), resetDelay)); } }); -- cgit v1.2.3 From df9f126e59cf70b7b0d9d7e8a9b7808fe51952bf Mon Sep 17 00:00:00 2001 From: Leandro Ferreira Date: Mon, 6 Aug 2012 12:19:56 -0400 Subject: corrections in wrong words --- src/org/traccar/Server.java | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/org/traccar/Server.java b/src/org/traccar/Server.java index 612eeb32a..917bf7bbb 100644 --- a/src/org/traccar/Server.java +++ b/src/org/traccar/Server.java @@ -242,7 +242,7 @@ public class Server { }); serverList.add(server); - Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); + Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } @@ -276,7 +276,7 @@ public class Server { }); serverList.add(server); - Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); + Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } @@ -309,7 +309,7 @@ public class Server { }); serverList.add(server); - Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); + Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } @@ -342,7 +342,7 @@ public class Server { }); serverList.add(server); - Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); + Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } @@ -375,7 +375,7 @@ public class Server { }); serverList.add(server); - Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); + Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } @@ -408,7 +408,7 @@ public class Server { }); serverList.add(server); - Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); + Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } @@ -441,7 +441,7 @@ public class Server { }); serverList.add(server); - Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); + Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } @@ -473,7 +473,7 @@ public class Server { }); serverList.add(server); - Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); + Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } @@ -502,7 +502,7 @@ public class Server { }); serverList.add(server); - Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); + Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } @@ -531,7 +531,7 @@ public class Server { }); serverList.add(server); - Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); + Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } @@ -561,7 +561,7 @@ public class Server { }); serverList.add(server); - Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); + Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } -- cgit v1.2.3 From 21a5374f98234135a825aef89f29b3a2a69c85f2 Mon Sep 17 00:00:00 2001 From: Leandro Silva Ferreira Date: Tue, 7 Aug 2012 12:26:01 -0400 Subject: Added st210 test. --- test.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test.sh b/test.sh index cbb7851e2..b4a525182 100755 --- a/test.sh +++ b/test.sh @@ -38,3 +38,9 @@ echo "8. enfora" 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 + + + + -- cgit v1.2.3 From be061beae7ee71d6ed8666ff733600b2b2f7d354 Mon Sep 17 00:00:00 2001 From: Leandro Silva Ferreira Date: Tue, 7 Aug 2012 12:26:17 -0400 Subject: Added postgre dependencies. --- pom.xml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ed2c431a2..844183d49 100644 --- a/pom.xml +++ b/pom.xml @@ -19,6 +19,11 @@ mysql-connector-java 5.1.21 + + postgresql + postgresql + 8.1-407.jdbc3 + io.netty netty @@ -84,9 +89,11 @@ install + copy-dependencies - + + ${project.build.directory}/lib junit -- cgit v1.2.3 From 356ad74b9a5f803ea7c22eb15e32cf21d2c85e2e Mon Sep 17 00:00:00 2001 From: Leandro Silva Ferreira Date: Tue, 7 Aug 2012 12:27:01 -0400 Subject: Corrected time zones bugs. --- src/org/traccar/protocol/ST210ProtocolDecoder.java | 48 +++++++++++++--------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/src/org/traccar/protocol/ST210ProtocolDecoder.java b/src/org/traccar/protocol/ST210ProtocolDecoder.java index 8745941cb..8348f5a14 100644 --- a/src/org/traccar/protocol/ST210ProtocolDecoder.java +++ b/src/org/traccar/protocol/ST210ProtocolDecoder.java @@ -1,6 +1,7 @@ package org.traccar.protocol; import java.util.Calendar; +import java.util.GregorianCalendar; import java.util.LinkedList; import java.util.List; import java.util.TimeZone; @@ -97,34 +98,41 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { case DATE: { // Date - Calendar time = Calendar.getInstance(TimeZone - .getTimeZone("UTC")); + Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); time.clear(); - time.set(Calendar.YEAR, Integer.valueOf(Integer - .valueOf(groupValue.substring(0, 4)))); - time.set(Calendar.MONTH, Integer.valueOf(Integer - .valueOf(groupValue.substring(4, 6)))); - time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(Integer - .valueOf(groupValue.substring(6, 8)))); - position.setTime(time.getTime()); + time.set(Calendar.YEAR, Integer.valueOf(Integer.valueOf(groupValue.substring(0, 4)))); + time.set(Calendar.MONTH, Integer.valueOf(Integer.valueOf(groupValue.substring(4, 6))-1)); + time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(Integer.valueOf(groupValue.substring(6, 8)))); + + Calendar ret = new GregorianCalendar(TimeZone.getTimeZone("UTC")); + + ret.setTimeInMillis(time.getTimeInMillis() + + TimeZone.getTimeZone("UTC").getOffset(time.getTimeInMillis()) - + TimeZone.getDefault().getOffset(time.getTimeInMillis())); + + position.setTime(ret.getTime()); + break; } case TIME: { - Calendar time = Calendar.getInstance(TimeZone - .getTimeZone("UTC")); + Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); time.clear(); time.setTime(position.getTime()); - - time.set(Calendar.HOUR, Integer.valueOf(Integer - .valueOf(groupValue.substring(0, 2)))); - time.set(Calendar.MINUTE, Integer.valueOf(Integer - .valueOf(groupValue.substring(3, 5)))); - time.set(Calendar.SECOND, Integer.valueOf(Integer - .valueOf(groupValue.substring(6, 8)))); - - position.setTime(time.getTime()); + + time.set(Calendar.HOUR_OF_DAY, Integer.valueOf(Integer.valueOf(groupValue.substring(0, 2)))); + time.set(Calendar.MINUTE, Integer.valueOf(Integer.valueOf(groupValue.substring(3, 5)))); + time.set(Calendar.SECOND, Integer.valueOf(Integer.valueOf(groupValue.substring(6, 8)))); + + Calendar ret = new GregorianCalendar(TimeZone.getTimeZone("UTC")); + + ret.setTimeInMillis(time.getTimeInMillis() + + TimeZone.getTimeZone("UTC").getOffset(time.getTimeInMillis()) - + TimeZone.getDefault().getOffset(time.getTimeInMillis())); + + position.setTime(ret.getTime()); + break; } -- cgit v1.2.3 From ba8779f8230c5adf4fa0a83be3272db9927b709f Mon Sep 17 00:00:00 2001 From: Leandro Silva Ferreira Date: Tue, 7 Aug 2012 12:32:35 -0400 Subject: Added windows config for PostGree SQL 9.1 and Mode Parameter (Idle mode,Parking,Active Mode (Driving)) in Position. --- setup/windows/windowsPG.cfg | 150 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 setup/windows/windowsPG.cfg diff --git a/setup/windows/windowsPG.cfg b/setup/windows/windowsPG.cfg new file mode 100644 index 000000000..5a23d1e40 --- /dev/null +++ b/setup/windows/windowsPG.cfg @@ -0,0 +1,150 @@ + + + + + + + + org.postgresql.Driver + jdbc:postgresql:traccar + postgres + postgres + + + 300 + + + + 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; + + + + id - Long + imei - String + <--> + + SELECT id, imei + FROM devices + + + + imei - String + <--> + + INSERT INTO devices (id,imei) + VALUES (nextval('devicesSQ'),:imei) + + + + id - Long + imei - String + <--> + + UPDATE devices + SET imei = :imei + WHERE id = :id + + + + id - Long + <--> + + DELETE FROM devices + WHERE id = :id + + + + device_id - Long + <--> + + SELECT * + FROM positions + WHERE device_id = :device_id + + + + 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) + <--> + + INSERT INTO positions (id, device_id, time, valid, latitude, longitude, speed, course, power, mode) + VALUES (nextval('positionsSQ'),:device_id, :time, :valid, :latitude, :longitude, :speed, :course, :power, :mode) + + + + true + 8082 + + + false + jornadaLOG + + + false + 5000 + 0 + + + false + 5001 + 0 + + + false + 5002 + 0 + + + false + 5003 + 0 + + + false + 5004 + 0 + + + false + 5005 + 0 + + + false + 5006 + 0 + + + false + 5007 + 0 + + + false + 5008 + 0 + + + false + 5009 + 0 + + + true + 8801 + 0 + + -- cgit v1.2.3 From 96bc0ffa914d89e3b58e6e8642d201bb016c31ee Mon Sep 17 00:00:00 2001 From: Leandro Silva Ferreira Date: Wed, 8 Aug 2012 12:03:26 -0400 Subject: Corrections of correct version of plugins and phase of execution chaged from install to package. --- pom.xml | 217 ++++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 109 insertions(+), 108 deletions(-) diff --git a/pom.xml b/pom.xml index 844183d49..2ddd1491d 100644 --- a/pom.xml +++ b/pom.xml @@ -1,121 +1,122 @@ - 4.0.0 - org.traccar - traccar - 1.1-SNAPSHOT + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + org.traccar + traccar + 1.1-SNAPSHOT - traccar - http://www.traccar.org + traccar + http://www.traccar.org - - - com.h2database - h2 - 1.3.168 - - - mysql - mysql-connector-java - 5.1.21 - - + + + com.h2database + h2 + 1.3.168 + + + mysql + mysql-connector-java + 5.1.21 + + postgresql postgresql 8.1-407.jdbc3 - - io.netty - netty - 3.5.2.Final - + + io.netty + netty + 3.5.2.Final + - - junit - junit - 4.10 - + + junit + junit + 4.10 + - - - org.eclipse.jetty.orbit - javax.servlet - 3.0.0.v201112011016 - - - org.eclipse.jetty - jetty-continuation - 8.1.5.v20120716 - - - org.eclipse.jetty - jetty-http - 8.1.5.v20120716 - - - org.eclipse.jetty - jetty-io - 8.1.5.v20120716 - - - org.eclipse.jetty - jetty-util - 8.1.5.v20120716 - - - org.eclipse.jetty - jetty-server - 8.1.5.v20120716 - - + + + org.eclipse.jetty.orbit + javax.servlet + 3.0.0.v201112011016 + + + org.eclipse.jetty + jetty-continuation + 8.1.5.v20120716 + + + org.eclipse.jetty + jetty-http + 8.1.5.v20120716 + + + org.eclipse.jetty + jetty-io + 8.1.5.v20120716 + + + org.eclipse.jetty + jetty-util + 8.1.5.v20120716 + + + org.eclipse.jetty + jetty-server + 8.1.5.v20120716 + + - - tracker-server - target/classes - src - test - - - src - - **/*.java - - - + + tracker-server + target/classes + src + test + + + src + + **/*.java + + + - - - maven-dependency-plugin - - - install - - - copy-dependencies - - - - ${project.build.directory}/lib - junit - true - - - - - - org.apache.maven.plugins - maven-jar-plugin - - - - org.traccar.Main - true - lib/ - - - - - + + + maven-dependency-plugin + 2.5 + + + copy-dependencies + package + + copy-dependencies + + + ${project.build.directory}/lib + junit + true + + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + + org.traccar.Main + true + lib/ + + + + + - + \ No newline at end of file -- cgit v1.2.3 From bb72110f2ff0ed8f64e61eb578d60040c914a99a Mon Sep 17 00:00:00 2001 From: Leandro Silva Ferreira Date: Wed, 8 Aug 2012 12:04:23 -0400 Subject: Removed wrong code that was generating errors on connections. --- src/org/traccar/GenericPipelineFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/org/traccar/GenericPipelineFactory.java b/src/org/traccar/GenericPipelineFactory.java index db3c378ba..521b8bc74 100644 --- a/src/org/traccar/GenericPipelineFactory.java +++ b/src/org/traccar/GenericPipelineFactory.java @@ -59,7 +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() + " - "; -- cgit v1.2.3 From bb9d9ad68735b5eb3f8c0e66751f979d8e07684c Mon Sep 17 00:00:00 2001 From: Leandro Silva Ferreira Date: Thu, 9 Aug 2012 08:57:08 -0400 Subject: Changed to test only the decoder and not decoder and server. --- test/org/traccar/protocol/ST210ProtocolDecoderTest.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/org/traccar/protocol/ST210ProtocolDecoderTest.java b/test/org/traccar/protocol/ST210ProtocolDecoderTest.java index bd1e60ee1..c300c056b 100644 --- a/test/org/traccar/protocol/ST210ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/ST210ProtocolDecoderTest.java @@ -14,6 +14,7 @@ import org.traccar.server.SocketCliente; public class ST210ProtocolDecoderTest { + /* @BeforeClass public static void UpServer() { final Server service = new Server(); @@ -50,7 +51,9 @@ public class ST210ProtocolDecoderTest { "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 +*/ + + @Test public void testDecode() throws Exception { ST210ProtocolDecoder decoder = new ST210ProtocolDecoder( @@ -68,6 +71,6 @@ 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")); - }*/ + } } -- cgit v1.2.3 From 208547fae3d20c77309c98c44595dd07ab77ee39 Mon Sep 17 00:00:00 2001 From: Leandro Silva Ferreira Date: Thu, 9 Aug 2012 08:59:52 -0400 Subject: Log. --- src/org/traccar/protocol/ST210ProtocolDecoder.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/org/traccar/protocol/ST210ProtocolDecoder.java b/src/org/traccar/protocol/ST210ProtocolDecoder.java index 8348f5a14..8d2200f57 100644 --- a/src/org/traccar/protocol/ST210ProtocolDecoder.java +++ b/src/org/traccar/protocol/ST210ProtocolDecoder.java @@ -608,6 +608,8 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { public Position decodeMsg(String msg) throws Exception { + Log.info("Msg: " + msg); + ST210REPORTS report = getReportType(msg); List protocol = report.getProtocol(); @@ -615,7 +617,6 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { Pattern protocolPattern = report.getProtocolPattern(); Log.info("Protocol Pattern: " + protocolPattern.toString()); - Log.info("Msg: " + msg); // Parse message Matcher parser = protocolPattern.matcher(msg); -- cgit v1.2.3 From 14b10b15c268983c1ce3f0a74fdaaf79b5ce7785 Mon Sep 17 00:00:00 2001 From: Leandro Silva Ferreira Date: Thu, 9 Aug 2012 09:22:46 -0400 Subject: Changed to correct port. --- src/org/traccar/Server.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/org/traccar/Server.java b/src/org/traccar/Server.java index 917bf7bbb..32a2888cc 100644 --- a/src/org/traccar/Server.java +++ b/src/org/traccar/Server.java @@ -76,7 +76,7 @@ public class Server { for (Iterator iterator = serverList.iterator(); iterator.hasNext();) { TrackerServer type = (TrackerServer) iterator.next(); - if(type.getPort().equals(5010)){ + if(type.getPort().equals(8801)){ for (Iterator it = type.getChannelGroup().iterator(); it.hasNext();) { Channel chanel = (Channel) it.next(); -- cgit v1.2.3 From e3a427afad7810726cf77cdc741b50c71e11223b Mon Sep 17 00:00:00 2001 From: Leandro Silva Ferreira Date: Thu, 9 Aug 2012 09:23:43 -0400 Subject: Log true. --- setup/windows/windowsPG.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/windows/windowsPG.cfg b/setup/windows/windowsPG.cfg index 5a23d1e40..28e29dbad 100644 --- a/setup/windows/windowsPG.cfg +++ b/setup/windows/windowsPG.cfg @@ -89,7 +89,7 @@ 8082 - false + true jornadaLOG -- cgit v1.2.3 From 7c3649250d4905b1c7024d2e85faebf9467f865a Mon Sep 17 00:00:00 2001 From: Leandro Silva Ferreira Date: Thu, 9 Aug 2012 11:04:36 -0400 Subject: Corrected the PWR_VOLT regex pattern and some encoding errors. --- src/org/traccar/protocol/ST210ProtocolDecoder.java | 59 +++++++++++----------- 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/src/org/traccar/protocol/ST210ProtocolDecoder.java b/src/org/traccar/protocol/ST210ProtocolDecoder.java index 8d2200f57..226f171bf 100644 --- a/src/org/traccar/protocol/ST210ProtocolDecoder.java +++ b/src/org/traccar/protocol/ST210ProtocolDecoder.java @@ -23,31 +23,30 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { } private enum ST210FIELDS { - HDR_STATUS("SA200STT;", "Status Report"), HDR_EMERGENCY("SA200EMG;", - "Emergency Report"), HDR_EVENT("SA200EVT;", "Event Report"), HDR_ALERT( - "SA200ALT;", "Alert Report"), HDR_ALIVE("SA200ALV;", - "Alive Report"), DEV_ID("(\\d+);", "Device ID"), SW_VER( - "(\\d{3});", "Software Release Version"), DATE("(\\d+);", - "GPS date (yyyymmdd) Year + Month + Day"), TIME( - "(\\d{2}:\\d{2}:\\d{2});", - "GPS time (hh:mm:ss) Hour : Minute : Second"), CELL( - "(\\d{2}\\w\\d{2});", - "Location Code ID (3 digits hex) + Serving Cell BSIC(2 digits decimal)"), LAT( - "(-\\d{2}.\\d+);", "Latitude (+/-xx.xxxxxx)"), LON( - "(-\\d{3}.\\d+);", "Longitude (+/-xxx.xxxxxx)"), SPD( - "(\\d{3}.\\d{3});", - "Speed in km/h - This value returns to 0 when it is over than 200,000Km"), CRS( - "(\\d{3}.\\d{2});", "Course over ground in degree"), SATT( - "(\\d+);", "Number of satellites"), FIX("(\\d);", - "GPS is fixed(1)\n" + "GPS is not fixed(0)"), DIST("(\\d+);", - "Traveled ddistance in meter"), PWR_VOLT("(\\d{2}.\\d{2});", - "Voltage value of main power"), IO("(\\d+);", - "Current I/O status of inputs and outputs."), MODE("(\\d);", - "1 = Idle mode (Parking)\n" + "2 = Active Mode (Driving)"), MSG_NUM( - "(\\d{4})", - "Message number - After 9999 is reported, message number returns to 0000"), EMG_ID( - "(\\d);", "Emergency type"), EVT_ID("(\\d);", "Event type"), ALERT_ID( - "(\\d);", "Alert type"); + HDR_STATUS("SA200STT;", + "Status Report"), + HDR_EMERGENCY("SA200EMG;","Emergency Report"), + HDR_EVENT("SA200EVT;", "Event Report"), + HDR_ALERT("SA200ALT;","Alert Report"), + HDR_ALIVE("SA200ALV;","Alive Report"), + DEV_ID("(\\d+);", "Device ID"), + SW_VER("(\\d{3});", "Software Release Version"), + DATE("(\\d+);","GPS date (yyyymmdd) Year + Month + Day"), + TIME("(\\d{2}:\\d{2}:\\d{2});","GPS time (hh:mm:ss) Hour : Minute : Second"), + CELL("(\\d{2}\\w\\d{2});","Location Code ID (3 digits hex) + Serving Cell BSIC(2 digits decimal)"), + LAT("(-\\d{2}.\\d+);", "Latitude (+/-xx.xxxxxx)"), + LON("(-\\d{3}.\\d+);", "Longitude (+/-xxx.xxxxxx)"), + SPD("(\\d{3}.\\d{3});","Speed in km/h - This value returns to 0 when it is over than 200,000Km"), + CRS("(\\d{3}.\\d{2});", "Course over ground in degree"), + SATT("(\\d+);", "Number of satellites"), + FIX("(\\d);","GPS is fixed(1)\n" + "GPS is not fixed(0)"), + DIST("(\\d+);","Traveled ddistance in meter"), + PWR_VOLT("(\\d+.\\d{2});","Voltage value of main power"), + IO("(\\d+);","Current I/O status of inputs and outputs."), + MODE("(\\d);","1 = Idle mode (Parking)\n" + "2 = Active Mode (Driving)"), + MSG_NUM("(\\d{4})","Message number - After 9999 is reported, message number returns to 0000"), + EMG_ID("(\\d);", "Emergency type"), EVT_ID("(\\d);", "Event type"), + ALERT_ID("(\\d);", "Alert type"); private String pattern; @@ -175,7 +174,7 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { case 0: return NOT_FIXED; default: - throw new IllegalArgumentException("�ndice n�o definido"); + throw new IllegalArgumentException("Index not defined"); } } } @@ -212,7 +211,7 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { case 2: return DRIVING; default: - throw new IllegalArgumentException("�ndice n�o definido"); + throw new IllegalArgumentException("Index not defined"); } } } @@ -256,7 +255,7 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { case 5: return ANTI_THEFT; default: - throw new IllegalArgumentException("�ndice n�o definido"); + throw new IllegalArgumentException("Index not defined"); } } } @@ -306,7 +305,7 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { case 6: return INPUT3_OPEN; default: - throw new IllegalArgumentException("�ndice n�o definido"); + throw new IllegalArgumentException("Index not defined"); } } } @@ -383,7 +382,7 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { case 19: return ENTER_ROUT; default: - throw new IllegalArgumentException("�ndice n�o definido"); + throw new IllegalArgumentException("Index not defined"); } } } -- cgit v1.2.3 From 4709481ccb413fe04e21abb8be3165ec78ee18ef Mon Sep 17 00:00:00 2001 From: Leandro Silva Ferreira Date: Thu, 9 Aug 2012 11:05:58 -0400 Subject: Added new tests for PWR_VOLT field with different values. --- test/org/traccar/protocol/ST210ProtocolDecoderTest.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/org/traccar/protocol/ST210ProtocolDecoderTest.java b/test/org/traccar/protocol/ST210ProtocolDecoderTest.java index c300c056b..d14f60201 100644 --- a/test/org/traccar/protocol/ST210ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/ST210ProtocolDecoderTest.java @@ -71,6 +71,14 @@ 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")); + 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")); + 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")); } } -- cgit v1.2.3 From 485d9e45883b4f028f76a6d05c5a72de08736e4c Mon Sep 17 00:00:00 2001 From: Leandro Silva Ferreira Date: Sat, 11 Aug 2012 18:27:37 -0400 Subject: Added more position fields on log --- src/org/traccar/TrackerEventHandler.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/org/traccar/TrackerEventHandler.java b/src/org/traccar/TrackerEventHandler.java index e4e45a174..2a66a084f 100644 --- a/src/org/traccar/TrackerEventHandler.java +++ b/src/org/traccar/TrackerEventHandler.java @@ -55,7 +55,9 @@ public class TrackerEventHandler extends SimpleChannelHandler { ", longitude: " + position.getLongitude() + ", altitude: " + position.getAltitude() + ", speed: " + position.getSpeed() + - ", course: " + position.getCourse()); + ", course: " + position.getCourse() + + ", power: " + position.getPower() + + ", mode: " + position.getMode()); } // Write position to database -- cgit v1.2.3 From 85229eebab501ee0b36a2b84c1a2df2124f31571 Mon Sep 17 00:00:00 2001 From: Leandro Silva Ferreira Date: Sat, 11 Aug 2012 19:38:33 -0400 Subject: New test for Emergency messages of st210 --- test.sh | 3 +++ test/org/traccar/protocol/ST210ProtocolDecoderTest.java | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/test.sh b/test.sh index b4a525182..611979342 100755 --- a/test.sh +++ b/test.sh @@ -41,6 +41,9 @@ echo "9. meiligao" 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 "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 + diff --git a/test/org/traccar/protocol/ST210ProtocolDecoderTest.java b/test/org/traccar/protocol/ST210ProtocolDecoderTest.java index d14f60201..88ad9f306 100644 --- a/test/org/traccar/protocol/ST210ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/ST210ProtocolDecoderTest.java @@ -79,6 +79,10 @@ public class ST210ProtocolDecoderTest { .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")); + 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")); } } -- cgit v1.2.3 From 65433706d8c321c1e29844de41576e1b38af8638 Mon Sep 17 00:00:00 2001 From: Leandro Silva Ferreira Date: Sat, 11 Aug 2012 20:03:05 -0400 Subject: Translate the user interface to portuguese Corrected the date column Added Mode column --- src/org/traccar/http/WebServer.java | 13 ++++---- src/org/traccar/model/Position.java | 7 +++++ src/web/index.html | 60 ++++++++++++++++++++----------------- 3 files changed, 46 insertions(+), 34 deletions(-) diff --git a/src/org/traccar/http/WebServer.java b/src/org/traccar/http/WebServer.java index 6c79e6421..e379a0a9a 100644 --- a/src/org/traccar/http/WebServer.java +++ b/src/org/traccar/http/WebServer.java @@ -146,14 +146,15 @@ public class WebServer { Iterator 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}", 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()); if (i.hasNext()) out.print(","); } } diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java index 0d04f4d49..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; diff --git a/src/web/index.html b/src/web/index.html index cde73f47b..dcc4771db 100644 --- a/src/web/index.html +++ b/src/web/index.html @@ -1,7 +1,9 @@ - - + + -Traccar Manager +Jornada Beta + + @@ -758,6 +760,7 @@ Ext.onReady(function() { ] }); + Ext.define('Position', { extend: 'Ext.data.Model', fields: [ @@ -768,7 +771,8 @@ 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'} ] }); @@ -806,7 +810,8 @@ Ext.onReady(function() { 'longitude', 'speed', 'course', - 'power' + 'power', + 'mode' ], proxy: { type: 'ajax', @@ -824,7 +829,7 @@ Ext.onReady(function() { }); var devicesPanel = Ext.create('Ext.grid.Panel', { - title: 'Devices', + title: 'Dispositivos', region: 'west', split: true, width: 300, @@ -837,16 +842,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 +860,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 +872,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 +893,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 +910,7 @@ Ext.onReady(function() { }); var positionsPanel = Ext.create('Ext.grid.Panel', { - title: 'Positions', + title: 'Posicionamentos', region: 'south', split: true, height: 300, @@ -918,7 +923,7 @@ Ext.onReady(function() { tbar: [ { id: 'position_update', - text: 'Update', + text: 'Atualizar', disabled: true, handler : function() { positions.load(); @@ -926,19 +931,18 @@ Ext.onReady(function() { } ], columns: [ - {header: 'Device Id', dataIndex: 'device_id'}, - { - header: 'Time', - dataIndex: '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') + renderer: Ext.util.Format.dateRenderer('d/m/Y H:i:s') }, - {header: 'Valid', dataIndex: 'valid'}, + {header: 'Válido', dataIndex: 'valid'}, {header: 'Latitude', dataIndex: 'latitude'}, {header: 'Longitude', dataIndex: 'longitude'}, - {header: 'Speed', dataIndex: 'speed'}, - {header: 'Course', dataIndex: 'course'}, - {header: 'Power', dataIndex: 'power'} + {header: 'Velocidade', dataIndex: 'speed'}, + {header: 'Curso', dataIndex: 'course'}, + {header: 'Voltagem', dataIndex: 'power'}, + {header: 'Modo', dataIndex: 'mode'} ], listeners: { selectionchange: function(sender, selected, eOpts) { @@ -955,7 +959,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}, -- cgit v1.2.3 From 4aaf5dd3cf3d1b089bb168ffdb2ed8f75e2899c6 Mon Sep 17 00:00:00 2001 From: Leandro Silva Ferreira Date: Sat, 11 Aug 2012 20:04:19 -0400 Subject: Corrected error on regex pattern of EMG_ID field --- src/org/traccar/protocol/ST210ProtocolDecoder.java | 78 ++++++++++++---------- 1 file changed, 43 insertions(+), 35 deletions(-) diff --git a/src/org/traccar/protocol/ST210ProtocolDecoder.java b/src/org/traccar/protocol/ST210ProtocolDecoder.java index 226f171bf..f503fead6 100644 --- a/src/org/traccar/protocol/ST210ProtocolDecoder.java +++ b/src/org/traccar/protocol/ST210ProtocolDecoder.java @@ -45,7 +45,8 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { IO("(\\d+);","Current I/O status of inputs and outputs."), MODE("(\\d);","1 = Idle mode (Parking)\n" + "2 = Active Mode (Driving)"), MSG_NUM("(\\d{4})","Message number - After 9999 is reported, message number returns to 0000"), - EMG_ID("(\\d);", "Emergency type"), EVT_ID("(\\d);", "Event type"), + EMG_ID("(\\d)", "Emergency type"), + EVT_ID("(\\d);", "Event type"), ALERT_ID("(\\d);", "Alert type"); private String pattern; @@ -217,10 +218,10 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { } private enum FIELD_EMG_ID_VALUE { - PANIC(1, "Emergency by panic button"), PARKING(2, - "Emergency by parking lock"), MAIN_POWER(3, - "Emergency by removing main power"), ANTI_THEFT(5, - "Emergency by anti-theft"); + PANIC(1, "Emergency by panic button"), + PARKING(2,"Emergency by parking lock"), + MAIN_POWER(3,"Emergency by removing main power"), + ANTI_THEFT(5,"Emergency by anti-theft"); private int value; @@ -261,12 +262,12 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { } private enum FIELD_EVT_ID_VALUE { - INPUT1_GROUND(1, "Input1 goes to ground state"), INPUT1_OPEN(2, - "Input1 goes to open state"), INPUT2_GROUND(3, - "Input2 goes to ground state"), INPUT2_OPEN(4, - "Input2 goes to open state"), INPUT3_GROUND(5, - "Input3 goes to ground state"), INPUT3_OPEN(6, - "Input3 goes to open state"); + INPUT1_GROUND(1, "Input1 goes to ground state"), + INPUT1_OPEN(2,"Input1 goes to open state"), + INPUT2_GROUND(3,"Input2 goes to ground state"), + INPUT2_OPEN(4,"Input2 goes to open state"), + INPUT3_GROUND(5,"Input3 goes to ground state"), + INPUT3_OPEN(6,"Input3 goes to open state"); private int value; @@ -288,7 +289,7 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { public FIELD_EVT_ID_VALUE getValueOf(String indiceStr) { int indice = Integer.valueOf(indiceStr); return getValueOf(indice); - } + } public FIELD_EVT_ID_VALUE getValueOf(int indice) { switch (indice) { @@ -311,21 +312,21 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { } private enum FIELD_ALERT_ID_VALUE { - DRIVING_FASTER(1, "Start driving faster than SPEED_LIMIT"), OVER_SPPED( - 2, "Ended over speed condition"), DISCON_GPS(3, - "Disconnected GPS antenna"), RECON_GPS(4, - "Reconnected GPS antenna after disconnected"), OUT_GEO_FENCE(5, - "The vehicle went out from the geo-fence that has following ID"), INTO_GEO_FENCE( - 6, - "The vehicle entered into the geo-fence that has following ID"), SHORTED_GPS( - 8, "Shorted GPS antenna"), DEEP_SLEEP_ON(9, - "Enter to deep sleep mode"), DEEP_SLEEP_OFF(10, - "Exite from deep sleep mode"), BKP_BATTERY(13, - "Backup battery error"), BATTERY_DOWN(14, - "Vehicle battery goes down to so low level"), SHOCKED(15, - "Shocked"), COLLISION(16, "Occurred some collision"), DEVIATE_ROUT( - 18, "Deviate from predefined rout"), ENTER_ROUT(19, - "Enter into predefined rout"); + DRIVING_FASTER(1, "Start driving faster than SPEED_LIMIT"), + OVER_SPPED(2, "Ended over speed condition"), + DISCON_GPS(3,"Disconnected GPS antenna"), + RECON_GPS(4,"Reconnected GPS antenna after disconnected"), + OUT_GEO_FENCE(5,"The vehicle went out from the geo-fence that has following ID"), + INTO_GEO_FENCE(6,"The vehicle entered into the geo-fence that has following ID"), + SHORTED_GPS(8, "Shorted GPS antenna"), + DEEP_SLEEP_ON(9,"Enter to deep sleep mode"), + DEEP_SLEEP_OFF(10,"Exite from deep sleep mode"), + BKP_BATTERY(13,"Backup battery error"), + BATTERY_DOWN(14,"Vehicle battery goes down to so low level"), + SHOCKED(15,"Shocked"), + COLLISION(16, "Occurred some collision"), + DEVIATE_ROUT(18, "Deviate from predefined rout"), + ENTER_ROUT(19,"Enter into predefined rout"); private int value; @@ -599,28 +600,35 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { }; @Override - public Object decode(ChannelHandlerContext ctx, Channel channel, Object msg) - throws Exception { + public Object decode(ChannelHandlerContext ctx, Channel channel, Object msg) { String sentence = (String) msg; - return decodeMsg(sentence); + Log.info("Msg: " + msg); + + Position position = null; + + try{ + position = decodeMsg(sentence); + Log.info("MESSAGE DECODED WITH SUCCESS!"); + } + catch(Exception e){ + Log.info("ERROR WHILE DECODING MESSAGE: " + e.getMessage()); + } + + return position; } public Position decodeMsg(String msg) throws Exception { - Log.info("Msg: " + msg); - ST210REPORTS report = getReportType(msg); List protocol = report.getProtocol(); Pattern protocolPattern = report.getProtocolPattern(); - Log.info("Protocol Pattern: " + protocolPattern.toString()); - // Parse message Matcher parser = protocolPattern.matcher(msg); if (!parser.matches()) { - return null; + throw new Exception("Pattern no match: " + protocolPattern.toString()); } // Create new position -- cgit v1.2.3