aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/xexun2
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/protocol/xexun2')
-rw-r--r--src/org/traccar/protocol/xexun2/Xexun2ProtocolDecoder.java58
1 files changed, 5 insertions, 53 deletions
diff --git a/src/org/traccar/protocol/xexun2/Xexun2ProtocolDecoder.java b/src/org/traccar/protocol/xexun2/Xexun2ProtocolDecoder.java
index b8ed8a54f..62ec432ee 100644
--- a/src/org/traccar/protocol/xexun2/Xexun2ProtocolDecoder.java
+++ b/src/org/traccar/protocol/xexun2/Xexun2ProtocolDecoder.java
@@ -19,40 +19,23 @@ import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
-import java.text.ParseException;
import java.util.TimeZone;
-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.traccar.Position;
import org.traccar.DataManager;
-import org.jboss.netty.channel.ChannelEvent;
-import org.jboss.netty.channel.ChannelState;
-import org.jboss.netty.channel.ChannelStateEvent;
+import org.traccar.GenericProtocolDecoder;
/**
* Xexun tracker protocol decoder
*/
-public class Xexun2ProtocolDecoder extends OneToOneDecoder {
+public class Xexun2ProtocolDecoder extends GenericProtocolDecoder {
/**
- * Data manager
- */
- private DataManager dataManager;
-
- /**
- * Reset connection delay
- */
- private Integer resetDelay;
-
- /**
- * Init device table
+ * Initialize
*/
public Xexun2ProtocolDecoder(DataManager dataManager, Integer resetDelay) {
- this.dataManager = dataManager;
- this.resetDelay = resetDelay;
+ super(dataManager, resetDelay);
}
/**
@@ -145,7 +128,7 @@ public class Xexun2ProtocolDecoder extends OneToOneDecoder {
// Get device by IMEI
String imei = parser.group(index++);
- position.setDeviceId(dataManager.getDeviceByImei(imei).getId());
+ position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
// Power
position.setPower(Double.valueOf(parser.group(index++)));
@@ -153,35 +136,4 @@ public class Xexun2ProtocolDecoder 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);
- }
- }
- }
-
}