From d0de5245574e223384d9e89421850af16fb7a848 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 22 Mar 2012 04:54:46 +0000 Subject: --- .../traccar/protocol/t55/T55ProtocolDecoder.java | 57 ++-------------------- 1 file changed, 5 insertions(+), 52 deletions(-) (limited to 'src/org/traccar/protocol/t55') diff --git a/src/org/traccar/protocol/t55/T55ProtocolDecoder.java b/src/org/traccar/protocol/t55/T55ProtocolDecoder.java index ad674d4a8..5b1558c00 100644 --- a/src/org/traccar/protocol/t55/T55ProtocolDecoder.java +++ b/src/org/traccar/protocol/t55/T55ProtocolDecoder.java @@ -18,45 +18,29 @@ package org.traccar.protocol.t55; 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; 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; /** * T55 tracker protocol decoder */ -public class T55ProtocolDecoder extends OneToOneDecoder { +public class T55ProtocolDecoder extends GenericProtocolDecoder { - /** - * Data manager - */ - private DataManager dataManager; - - /** - * Reset connection delay - */ - private Integer resetDelay; - /** * Device ID */ private Long deviceId; /** - * Init device table + * Initialize */ public T55ProtocolDecoder(DataManager dataManager, Integer resetDelay) { - this.dataManager = dataManager; - this.resetDelay = resetDelay; + super(dataManager, resetDelay); } /** @@ -89,7 +73,7 @@ public class T55ProtocolDecoder extends OneToOneDecoder { // Detect device ID if (sentence.contains("$PGID")) { String imei = sentence.substring(6, 6 + 15); - deviceId = dataManager.getDeviceByImei(imei).getId(); + deviceId = getDataManager().getDeviceByImei(imei).getId(); } // Parse message @@ -166,35 +150,4 @@ public class T55ProtocolDecoder extends OneToOneDecoder { return null; } - /** - * 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); - } - } - } - } -- cgit v1.2.3