aboutsummaryrefslogtreecommitdiff
path: root/src/net/sourceforge/opentracking/protocol/xexun
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2011-05-05 06:28:25 +0000
committerAnton Tananaev <anton.tananaev@gmail.com>2011-05-05 06:28:25 +0000
commitd673fa357b64ffa34209465a535d00983cba5576 (patch)
treebff99c61fdf368a915adb336f1d1b173d99b6197 /src/net/sourceforge/opentracking/protocol/xexun
parentdd6db81db43f5c23e5349c0b06d4a0ce6830d127 (diff)
downloadtraccar-server-d673fa357b64ffa34209465a535d00983cba5576.tar.gz
traccar-server-d673fa357b64ffa34209465a535d00983cba5576.tar.bz2
traccar-server-d673fa357b64ffa34209465a535d00983cba5576.zip
Diffstat (limited to 'src/net/sourceforge/opentracking/protocol/xexun')
-rw-r--r--src/net/sourceforge/opentracking/protocol/xexun/XexunFrameDecoder.java20
-rw-r--r--src/net/sourceforge/opentracking/protocol/xexun/XexunProtocolDecoder.java47
2 files changed, 57 insertions, 10 deletions
diff --git a/src/net/sourceforge/opentracking/protocol/xexun/XexunFrameDecoder.java b/src/net/sourceforge/opentracking/protocol/xexun/XexunFrameDecoder.java
index 8c4c4eb70..839e5b3ec 100644
--- a/src/net/sourceforge/opentracking/protocol/xexun/XexunFrameDecoder.java
+++ b/src/net/sourceforge/opentracking/protocol/xexun/XexunFrameDecoder.java
@@ -1,9 +1,18 @@
/*
- * Минимум - 100
- * Начало - (10 цифр) + ','
- * Длина 16 x ','
+ * Copyright 2010 Anton Tananaev (anton@tananaev.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
-
package net.sourceforge.opentracking.protocol.xexun;
import org.jboss.netty.handler.codec.frame.FrameDecoder;
@@ -11,9 +20,6 @@ import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.buffer.ChannelBuffer;
-/**
- *
- */
public class XexunFrameDecoder extends FrameDecoder {
/**
diff --git a/src/net/sourceforge/opentracking/protocol/xexun/XexunProtocolDecoder.java b/src/net/sourceforge/opentracking/protocol/xexun/XexunProtocolDecoder.java
index 7b21a1a72..94b1cb31b 100644
--- a/src/net/sourceforge/opentracking/protocol/xexun/XexunProtocolDecoder.java
+++ b/src/net/sourceforge/opentracking/protocol/xexun/XexunProtocolDecoder.java
@@ -20,13 +20,17 @@ import java.util.GregorianCalendar;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.text.ParseException;
+import java.util.Timer;
+import java.util.TimerTask;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
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 java.sql.SQLException;
+import org.jboss.netty.channel.ChannelEvent;
+import org.jboss.netty.channel.ChannelState;
+import org.jboss.netty.channel.ChannelStateEvent;
/**
* Xexun tracker protocol decoder
@@ -40,10 +44,16 @@ public class XexunProtocolDecoder extends OneToOneDecoder {
private DataManager dataManager;
/**
+ * Reset connection delay
+ */
+ private Integer resetDelay;
+
+ /**
* Init device table
*/
- public XexunProtocolDecoder(DataManager newDataManager) {
- dataManager = newDataManager;
+ public XexunProtocolDecoder(DataManager dataManager, Integer resetDelay) {
+ this.dataManager = dataManager;
+ this.resetDelay = resetDelay;
}
/**
@@ -129,4 +139,35 @@ public class XexunProtocolDecoder 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 && resetDelay != 0) {
+ new Timer().schedule(new DisconnectTask(evt.getChannel()), resetDelay);
+ }
+ }
+ }
+
}