From 2a3fad9496decd83f06ae5abf067f8d4337ec741 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 23 Apr 2015 15:49:56 +1200 Subject: Major code refacroting --- .../traccar/protocol/GlobalSatProtocolDecoder.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'src/org/traccar/protocol/GlobalSatProtocolDecoder.java') diff --git a/src/org/traccar/protocol/GlobalSatProtocolDecoder.java b/src/org/traccar/protocol/GlobalSatProtocolDecoder.java index fd0c04bb4..1a0132c4a 100644 --- a/src/org/traccar/protocol/GlobalSatProtocolDecoder.java +++ b/src/org/traccar/protocol/GlobalSatProtocolDecoder.java @@ -25,6 +25,7 @@ import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.BaseProtocolDecoder; +import org.traccar.Context; import org.traccar.database.DataManager; import org.traccar.helper.Log; import org.traccar.model.ExtendedInfoFormatter; @@ -36,9 +37,10 @@ public class GlobalSatProtocolDecoder extends BaseProtocolDecoder { private String format0 = "TSPRXAB27GHKLMnaicz*U!"; private String format1 = "SARY*U!"; - public GlobalSatProtocolDecoder(DataManager dataManager, String protocol, Properties properties) { - super(dataManager, protocol, properties); + public GlobalSatProtocolDecoder(String protocol) { + super(protocol); + Properties properties = Context.getProps(); if (properties != null) { if (properties.containsKey(protocol + ".format0")) { format0 = properties.getProperty(protocol + ".format0"); @@ -97,12 +99,10 @@ public class GlobalSatProtocolDecoder extends BaseProtocolDecoder { switch(format.charAt(formatIndex)) { case 'S': - try { - position.setDeviceId(getDataManager().getDeviceByImei(value).getId()); - } catch(Exception error) { - Log.warning("Unknown device - " + value); + if (!identify(value)) { return null; } + position.setDeviceId(getDeviceId()); break; case 'A': if (value.isEmpty()) { @@ -215,13 +215,10 @@ public class GlobalSatProtocolDecoder extends BaseProtocolDecoder { Integer index = 1; // Identification - String imei = parser.group(index++); - try { - position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); - } catch(Exception error) { - Log.warning("Unknown device - " + imei); + if (!identify(parser.group(index++))) { return null; } + position.setDeviceId(getDeviceId()); // Validity position.setValid(parser.group(index++).compareTo("1") != 0); -- cgit v1.2.3