diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2010-07-27 20:26:26 +0000 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2010-07-27 20:26:26 +0000 |
commit | f60fe194659614fcb65339fc1772308f7ced5126 (patch) | |
tree | a7af5561b806a18a44ad80acf5d7fef290bd3bd1 | |
parent | 8c958b95a3b01c1b1b392723e2b35c7575e3a45e (diff) | |
download | trackermap-server-f60fe194659614fcb65339fc1772308f7ced5126.tar.gz trackermap-server-f60fe194659614fcb65339fc1772308f7ced5126.tar.bz2 trackermap-server-f60fe194659614fcb65339fc1772308f7ced5126.zip |
fix gps103 protocol
-rw-r--r-- | nbproject/project.properties | 9 | ||||
-rw-r--r-- | src/net/sourceforge/opentracking/Server.java | 2 | ||||
-rw-r--r-- | src/net/sourceforge/opentracking/protocol/gps103/Gps103ProtocolDecoder.java | 46 | ||||
-rwxr-xr-x | tracker-server.log | 75 | ||||
-rwxr-xr-x | tracker-server.log.lck | 0 |
5 files changed, 126 insertions, 6 deletions
diff --git a/nbproject/project.properties b/nbproject/project.properties index 0fa69139c..a32e47f3b 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -22,13 +22,14 @@ dist.jar=${dist.dir}/tracker-server.jar dist.javadoc.dir=${dist.dir}/javadoc endorsed.classpath= excludes= -file.reference.netty-3.1.5.GA.jar=C:\\WorkJava\\netty-3.1.5.GA\\jar\\netty-3.1.5.GA.jar +file.reference.derbyclient.jar=/usr/lib/jvm/java-6-sun-1.6.0.20/db/lib/derbyclient.jar +file.reference.netty-3.2.1.Final.jar=/home/user/NetBeansProjects/netty-3.2.1.Final/jar/netty-3.2.1.Final.jar includes=** jar.compress=false javac.classpath=\ - ${file.reference.netty-3.1.5.GA.jar}:\ - ${libs.JAVADB_DRIVER_LABEL.classpath}:\ - ${libs.PostgreSQLDriver.classpath} + ${libs.PostgreSQLDriver.classpath}:\ + ${file.reference.netty-3.2.1.Final.jar}:\ + ${file.reference.derbyclient.jar} # Space-separated list of extra javac options javac.compilerargs= javac.deprecation=false diff --git a/src/net/sourceforge/opentracking/Server.java b/src/net/sourceforge/opentracking/Server.java index acee30037..278a4589a 100644 --- a/src/net/sourceforge/opentracking/Server.java +++ b/src/net/sourceforge/opentracking/Server.java @@ -33,6 +33,7 @@ import java.util.logging.Level; import java.util.logging.LogRecord; import net.sourceforge.opentracking.helper.NamedParameterStatement; import org.jboss.netty.handler.codec.string.StringDecoder; +import org.jboss.netty.handler.codec.string.StringEncoder; import org.jboss.netty.handler.codec.frame.DelimiterBasedFrameDecoder; import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.handler.logging.LoggingHandler; @@ -241,6 +242,7 @@ public class Server implements DataManager { server.getPipeline().addLast("frameDecoder", new DelimiterBasedFrameDecoder(1024, ChannelBuffers.wrappedBuffer(delimiter))); server.getPipeline().addLast("stringDecoder", new StringDecoder()); + server.getPipeline().addLast("stringEncoder", new StringEncoder()); server.getPipeline().addLast("objectDecoder", new Gps103ProtocolDecoder(this)); server.getPipeline().addLast("handler", new TrackerEventHandler(this)); diff --git a/src/net/sourceforge/opentracking/protocol/gps103/Gps103ProtocolDecoder.java b/src/net/sourceforge/opentracking/protocol/gps103/Gps103ProtocolDecoder.java index 0b9b1c5bf..26637f3f1 100644 --- a/src/net/sourceforge/opentracking/protocol/gps103/Gps103ProtocolDecoder.java +++ b/src/net/sourceforge/opentracking/protocol/gps103/Gps103ProtocolDecoder.java @@ -18,6 +18,8 @@ package net.sourceforge.opentracking.protocol.gps103; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.TimeZone; +import java.util.Timer; +import java.util.TimerTask; import java.util.regex.Pattern; import java.util.regex.Matcher; import org.jboss.netty.channel.Channel; @@ -26,6 +28,9 @@ import org.jboss.netty.handler.codec.oneone.OneToOneDecoder; import org.jboss.netty.channel.ChannelPipelineCoverage; import net.sourceforge.opentracking.Position; import net.sourceforge.opentracking.DataManager; +import org.jboss.netty.channel.ChannelEvent; +import org.jboss.netty.channel.ChannelState; +import org.jboss.netty.channel.ChannelStateEvent; /** * Gps 103 tracker protocol decoder @@ -69,9 +74,14 @@ public class Gps103ProtocolDecoder extends OneToOneDecoder { ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { - // Parse message - String sentence = (String) msg; + + // Send response + if (sentence.contains("##")) { + channel.write("LOAD"); + } + + // Parse message Matcher parser = pattern.matcher(sentence); if (!parser.matches()) { return null; @@ -116,4 +126,36 @@ public class Gps103ProtocolDecoder extends OneToOneDecoder { return position; } + /** + * Disconnect channel + */ + class DisconnectTask extends TimerTask { + private Channel channel; + + public DisconnectTask(Channel channel) { + this.channel = channel; + } + + public void run() { + channel.disconnect(); + } + } + + /** + * Handle connect event + */ + @Override + public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent evt) throws Exception { + super.handleUpstream(ctx, evt); + + if (evt instanceof ChannelStateEvent) { + ChannelStateEvent event = (ChannelStateEvent) evt; + + if (event.getState() == ChannelState.CONNECTED && event.getValue() != null) { + new Timer().schedule(new DisconnectTask(evt.getChannel()) , 5 * 60 * 1000); + } + } + + } + } diff --git a/tracker-server.log b/tracker-server.log new file mode 100755 index 000000000..e77fde97c --- /dev/null +++ b/tracker-server.log @@ -0,0 +1,75 @@ +May 2, 2010 9:51:59 PM net.sourceforge.opentracking.Server init +WARNING: test +May 2, 2010 9:51:59 PM net.sourceforge.opentracking.Server init +WARNING: test2 +May 2, 2010 9:54:20 PM net.sourceforge.opentracking.Server init +WARNING: test +May 2, 2010 9:54:20 PM net.sourceforge.opentracking.Server init +WARNING: test2 +May 2, 2010 10:14:26 PM net.sourceforge.opentracking.Server init +FINE: test fine +May 2, 2010 10:14:47 PM net.sourceforge.opentracking +FINE: [id: 0x01148603, /0:0:0:0:0:0:0:1:49581 => /0:0:0:0:0:0:0:1:5000] BOUND: /0:0:0:0:0:0:0:1:5000 +May 2, 2010 10:14:47 PM net.sourceforge.opentracking +FINE: [id: 0x01148603, /0:0:0:0:0:0:0:1:49581 => /0:0:0:0:0:0:0:1:5000] CONNECTED: /0:0:0:0:0:0:0:1:49581 +May 2, 2010 10:14:49 PM net.sourceforge.opentracking +FINE: [id: 0x01148603, /0:0:0:0:0:0:0:1:49581 => /0:0:0:0:0:0:0:1:5000] RECEIVED: BigEndianHeapChannelBuffer(ridx=0, widx=3, cap=1024) - (HEXDUMP: 730d0a) +May 2, 2010 10:14:49 PM net.sourceforge.opentracking +FINE: [id: 0x01148603, /0:0:0:0:0:0:0:1:49581 => /0:0:0:0:0:0:0:1:5000] RECEIVED: BigEndianHeapChannelBuffer(ridx=0, widx=3, cap=1024) - (HEXDUMP: 610d0a) +May 2, 2010 10:14:50 PM net.sourceforge.opentracking +FINE: [id: 0x01148603, /0:0:0:0:0:0:0:1:49581 => /0:0:0:0:0:0:0:1:5000] RECEIVED: BigEndianHeapChannelBuffer(ridx=0, widx=3, cap=960) - (HEXDUMP: 620d0a) +May 2, 2010 10:14:51 PM net.sourceforge.opentracking +FINE: [id: 0x01148603, /0:0:0:0:0:0:0:1:49581 => /0:0:0:0:0:0:0:1:5000] RECEIVED: BigEndianHeapChannelBuffer(ridx=0, widx=6, cap=960) - (HEXDUMP: 313131310d0a) +May 2, 2010 10:14:57 PM net.sourceforge.opentracking +FINE: [id: 0x01148603, /0:0:0:0:0:0:0:1:49581 => /0:0:0:0:0:0:0:1:5000] DISCONNECTED +May 2, 2010 10:14:57 PM net.sourceforge.opentracking +FINE: [id: 0x01148603, /0:0:0:0:0:0:0:1:49581 => /0:0:0:0:0:0:0:1:5000] UNBOUND +May 2, 2010 10:14:58 PM net.sourceforge.opentracking +FINE: [id: 0x01148603, /0:0:0:0:0:0:0:1:49581 => /0:0:0:0:0:0:0:1:5000] CLOSED +May 2, 2010 10:18:07 PM net.sourceforge.opentracking.Server init +FINE: test fine +May 2, 2010 10:18:14 PM net.sourceforge.opentracking +FINE: [id: 0x012b3349, /0:0:0:0:0:0:0:1:55726 => /0:0:0:0:0:0:0:1:5000] BOUND: /0:0:0:0:0:0:0:1:5000 +May 2, 2010 10:18:15 PM net.sourceforge.opentracking +FINE: [id: 0x012b3349, /0:0:0:0:0:0:0:1:55726 => /0:0:0:0:0:0:0:1:5000] CONNECTED: /0:0:0:0:0:0:0:1:55726 +May 2, 2010 10:18:16 PM net.sourceforge.opentracking +FINE: [id: 0x012b3349, /0:0:0:0:0:0:0:1:55726 => /0:0:0:0:0:0:0:1:5000] RECEIVED: BigEndianHeapChannelBuffer(ridx=0, widx=6, cap=1024) - (HEXDUMP: 68656c6c0d0a) +May 2, 2010 10:18:18 PM net.sourceforge.opentracking +FINE: [id: 0x012b3349, /0:0:0:0:0:0:0:1:55726 => /0:0:0:0:0:0:0:1:5000] RECEIVED: BigEndianHeapChannelBuffer(ridx=0, widx=3, cap=1024) - (HEXDUMP: 6f0d0a) +May 2, 2010 10:18:21 PM net.sourceforge.opentracking +FINE: [id: 0x012b3349, /0:0:0:0:0:0:0:1:55726 => /0:0:0:0:0:0:0:1:5000] RECEIVED: BigEndianHeapChannelBuffer(ridx=0, widx=7, cap=960) - (HEXDUMP: 31323334350d0a) +May 2, 2010 10:18:26 PM net.sourceforge.opentracking +FINE: [id: 0x012b3349, /0:0:0:0:0:0:0:1:55726 => /0:0:0:0:0:0:0:1:5000] DISCONNECTED +May 2, 2010 10:18:27 PM net.sourceforge.opentracking +FINE: [id: 0x012b3349, /0:0:0:0:0:0:0:1:55726 => /0:0:0:0:0:0:0:1:5000] UNBOUND +May 2, 2010 10:18:27 PM net.sourceforge.opentracking +FINE: [id: 0x012b3349, /0:0:0:0:0:0:0:1:55726 => /0:0:0:0:0:0:0:1:5000] CLOSED +May 2, 2010 10:42:28 PM net.sourceforge.opentracking +FINE: [id: 0x006db33c, /127.0.0.1:45082 => /127.0.0.1:5000] BOUND: /127.0.0.1:5000 +May 2, 2010 10:42:28 PM net.sourceforge.opentracking +FINE: [id: 0x006db33c, /127.0.0.1:45082 => /127.0.0.1:5000] CONNECTED: /127.0.0.1:45082 +May 2, 2010 10:42:30 PM net.sourceforge.opentracking +FINE: [id: 0x006db33c, /127.0.0.1:45082 => /127.0.0.1:5000] RECEIVED: BigEndianHeapChannelBuffer(ridx=0, widx=3, cap=1024) - (HEXDUMP: 610d0a) +May 2, 2010 10:42:31 PM net.sourceforge.opentracking +FINE: [id: 0x006db33c, /127.0.0.1:45082 => /127.0.0.1:5000] RECEIVED: BigEndianHeapChannelBuffer(ridx=0, widx=3, cap=1024) - (HEXDUMP: 620d0a) +May 2, 2010 10:42:34 PM net.sourceforge.opentracking +FINE: [id: 0x006db33c, /127.0.0.1:45082 => /127.0.0.1:5000] RECEIVED: BigEndianHeapChannelBuffer(ridx=0, widx=3, cap=960) - (HEXDUMP: 1b0d0a) +May 2, 2010 10:42:39 PM net.sourceforge.opentracking +FINE: [id: 0x006db33c, /127.0.0.1:45082 => /127.0.0.1:5000] DISCONNECTED +May 2, 2010 10:42:39 PM net.sourceforge.opentracking +FINE: [id: 0x006db33c, /127.0.0.1:45082 => /127.0.0.1:5000] UNBOUND +May 2, 2010 10:42:39 PM net.sourceforge.opentracking +FINE: [id: 0x006db33c, /127.0.0.1:45082 => /127.0.0.1:5000] CLOSED +[id: 0x0158689a, /0:0:0:0:0:0:0:1:45776 => /0:0:0:0:0:0:0:1:5000] BOUND: /0:0:0:0:0:0:0:1:5000[id: 0x0158689a, /0:0:0:0:0:0:0:1:45776 => /0:0:0:0:0:0:0:1:5000] CONNECTED: /0:0:0:0:0:0:0:1:45776[id: 0x0158689a, /0:0:0:0:0:0:0:1:45776 => /0:0:0:0:0:0:0:1:5000] RECEIVED: BigEndianHeapChannelBuffer(ridx=0, widx=8, cap=1024) - (HEXDUMP: 7177657274790d0a)[id: 0x0158689a, /0:0:0:0:0:0:0:1:45776 => /0:0:0:0:0:0:0:1:5000] DISCONNECTED[id: 0x0158689a, /0:0:0:0:0:0:0:1:45776 => /0:0:0:0:0:0:0:1:5000] UNBOUND[id: 0x0158689a, /0:0:0:0:0:0:0:1:45776 => /0:0:0:0:0:0:0:1:5000] CLOSED[id: 0x0158689a, /127.0.0.1:33077 => /127.0.0.1:5000] BOUND: /127.0.0.1:5000 +[id: 0x0158689a, /127.0.0.1:33077 => /127.0.0.1:5000] CONNECTED: /127.0.0.1:33077 +[id: 0x0158689a, /127.0.0.1:33077 => /127.0.0.1:5000] RECEIVED: BigEndianHeapChannelBuffer(ridx=0, widx=3, cap=1024) - (HEXDUMP: 310d0a) +[id: 0x0158689a, /127.0.0.1:33077 => /127.0.0.1:5000] RECEIVED: BigEndianHeapChannelBuffer(ridx=0, widx=5, cap=1024) - (HEXDUMP: 3233340d0a) +[id: 0x0158689a, /127.0.0.1:33077 => /127.0.0.1:5000] DISCONNECTED +[id: 0x0158689a, /127.0.0.1:33077 => /127.0.0.1:5000] UNBOUND +[id: 0x0158689a, /127.0.0.1:33077 => /127.0.0.1:5000] CLOSED +[id: 0x0158689a, /127.0.0.1:35718 => /127.0.0.1:5000] BOUND: /127.0.0.1:5000 +[id: 0x0158689a, /127.0.0.1:35718 => /127.0.0.1:5000] CONNECTED: /127.0.0.1:35718 +[id: 0x0158689a, /127.0.0.1:35718 => /127.0.0.1:5000] RECEIVED: BigEndianHeapChannelBuffer(ridx=0, widx=59, cap=1024) - (HEXDUMP: 6161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161610d0a) +[id: 0x0158689a, /127.0.0.1:35718 => /127.0.0.1:5000] DISCONNECTED +[id: 0x0158689a, /127.0.0.1:35718 => /127.0.0.1:5000] UNBOUND +[id: 0x0158689a, /127.0.0.1:35718 => /127.0.0.1:5000] CLOSED diff --git a/tracker-server.log.lck b/tracker-server.log.lck new file mode 100755 index 000000000..e69de29bb --- /dev/null +++ b/tracker-server.log.lck |