From ce60f22e4fde1cd0645371291b2bf7016856f78b Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 26 Aug 2016 02:29:51 +1200 Subject: Better detection of Xirgo format --- src/org/traccar/protocol/XirgoProtocolDecoder.java | 38 ++++++++++++---------- 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'src/org') diff --git a/src/org/traccar/protocol/XirgoProtocolDecoder.java b/src/org/traccar/protocol/XirgoProtocolDecoder.java index 830caf6d9..edab1af11 100644 --- a/src/org/traccar/protocol/XirgoProtocolDecoder.java +++ b/src/org/traccar/protocol/XirgoProtocolDecoder.java @@ -25,7 +25,6 @@ import org.traccar.helper.UnitsConverter; import org.traccar.model.Position; import java.net.SocketAddress; -import java.util.regex.Matcher; import java.util.regex.Pattern; public class XirgoProtocolDecoder extends BaseProtocolDecoder { @@ -34,9 +33,7 @@ public class XirgoProtocolDecoder extends BaseProtocolDecoder { super(protocol); } - private boolean newFormat; - - private static final Pattern FIRMWARE = Pattern.compile("\\w{4}-([0-9A-F]{7})"); + private Boolean newFormat; private static final Pattern PATTERN_OLD = new PatternBuilder() .text("$$") @@ -88,23 +85,28 @@ public class XirgoProtocolDecoder extends BaseProtocolDecoder { String sentence = (String) msg; - Matcher matcher = FIRMWARE.matcher(sentence); - if (matcher.find()) { - String type = matcher.group(1); - if (type.equals("1137CD1") || type.equals("1137CC1") || type.equals("1137CA3")) { - newFormat = true; - } - } - Parser parser; - if (newFormat) { + if (newFormat == null) { parser = new Parser(PATTERN_NEW, sentence); + if (parser.matches()) { + newFormat = true; + } else { + parser = new Parser(PATTERN_OLD, sentence); + if (parser.matches()) { + newFormat = false; + } else { + return null; + } + } } else { - parser = new Parser(PATTERN_OLD, sentence); - } - - if (!parser.matches()) { - return null; + if (newFormat) { + parser = new Parser(PATTERN_NEW, sentence); + } else { + parser = new Parser(PATTERN_OLD, sentence); + } + if (!parser.matches()) { + return null; + } } Position position = new Position(); -- cgit v1.2.3