aboutsummaryrefslogtreecommitdiff
path: root/src/net/sourceforge/opentracking/protocol/gps103
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2010-07-27 20:26:26 +0000
committerAnton Tananaev <anton.tananaev@gmail.com>2010-07-27 20:26:26 +0000
commitf60fe194659614fcb65339fc1772308f7ced5126 (patch)
treea7af5561b806a18a44ad80acf5d7fef290bd3bd1 /src/net/sourceforge/opentracking/protocol/gps103
parent8c958b95a3b01c1b1b392723e2b35c7575e3a45e (diff)
downloadtrackermap-server-f60fe194659614fcb65339fc1772308f7ced5126.tar.gz
trackermap-server-f60fe194659614fcb65339fc1772308f7ced5126.tar.bz2
trackermap-server-f60fe194659614fcb65339fc1772308f7ced5126.zip
fix gps103 protocol
Diffstat (limited to 'src/net/sourceforge/opentracking/protocol/gps103')
-rw-r--r--src/net/sourceforge/opentracking/protocol/gps103/Gps103ProtocolDecoder.java46
1 files changed, 44 insertions, 2 deletions
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);
+ }
+ }
+
+ }
+
}