diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2016-08-26 02:29:51 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2016-08-26 02:29:51 +1200 |
commit | ce60f22e4fde1cd0645371291b2bf7016856f78b (patch) | |
tree | 4a8ab3eaaf2aef9cefc20c429023e67f731ecafb /src | |
parent | dd07064905c4a25f92cbe105346783bedd75a320 (diff) | |
download | traccar-server-ce60f22e4fde1cd0645371291b2bf7016856f78b.tar.gz traccar-server-ce60f22e4fde1cd0645371291b2bf7016856f78b.tar.bz2 traccar-server-ce60f22e4fde1cd0645371291b2bf7016856f78b.zip |
Better detection of Xirgo format
Diffstat (limited to 'src')
-rw-r--r-- | src/org/traccar/protocol/XirgoProtocolDecoder.java | 38 |
1 files changed, 20 insertions, 18 deletions
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(); |