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/GpsGateProtocolDecoder.java | 23 +++++++++------------- 1 file changed, 9 insertions(+), 14 deletions(-) (limited to 'src/org/traccar/protocol/GpsGateProtocolDecoder.java') diff --git a/src/org/traccar/protocol/GpsGateProtocolDecoder.java b/src/org/traccar/protocol/GpsGateProtocolDecoder.java index 80e06c911..cb26d3a61 100644 --- a/src/org/traccar/protocol/GpsGateProtocolDecoder.java +++ b/src/org/traccar/protocol/GpsGateProtocolDecoder.java @@ -33,15 +33,10 @@ import org.traccar.model.Position; public class GpsGateProtocolDecoder extends BaseProtocolDecoder { - private Long deviceId; - - public GpsGateProtocolDecoder(DataManager dataManager, String protocol, Properties properties) { - super(dataManager, protocol, properties); + public GpsGateProtocolDecoder(String protocol) { + super(protocol); } - /** - * Regular expressions pattern - */ private static final Pattern pattern = Pattern.compile( "\\$GPRMC," + "(\\d{2})(\\d{2})(\\d{2})\\.?(\\d+)?," + // Time (HHMMSS.SSS) @@ -76,11 +71,11 @@ public class GpsGateProtocolDecoder extends BaseProtocolDecoder { int endIndex = sentence.indexOf(',', beginIndex); if (endIndex != -1) { String imei = sentence.substring(beginIndex, endIndex); - try { - deviceId = getDataManager().getDeviceByImei(imei).getId(); - send(channel, "$FRSES," + channel.getId()); - } catch(Exception error) { - Log.warning("Unknown device - " + imei); + if (identify(imei)) { + if (channel != null) { + send(channel, "$FRSES," + channel.getId()); + } + } else { send(channel, "$FRERR,AuthError,Unknown device"); } } else { @@ -97,7 +92,7 @@ public class GpsGateProtocolDecoder extends BaseProtocolDecoder { } // Process data - else if (sentence.startsWith("$GPRMC,") && deviceId != null) { + else if (sentence.startsWith("$GPRMC,") && hasDeviceId()) { // Parse message Matcher parser = pattern.matcher(sentence); @@ -108,7 +103,7 @@ public class GpsGateProtocolDecoder extends BaseProtocolDecoder { // Create new position Position position = new Position(); ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol()); - position.setDeviceId(deviceId); + position.setDeviceId(getDeviceId()); Integer index = 1; -- cgit v1.2.3