diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-08-24 09:40:01 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-08-24 09:40:01 +1200 |
commit | d2163edd62feddf812e99e1ce918e7567eba95c8 (patch) | |
tree | d10e37dc2f9e0aadeb80612ad85ad9bcd505b641 /src/org/traccar/protocol | |
parent | 4757c4c9f6bf780ecedbbcb0312712a617070226 (diff) | |
download | trackermap-server-d2163edd62feddf812e99e1ce918e7567eba95c8.tar.gz trackermap-server-d2163edd62feddf812e99e1ce918e7567eba95c8.tar.bz2 trackermap-server-d2163edd62feddf812e99e1ce918e7567eba95c8.zip |
Extend Megastek decoder class
Diffstat (limited to 'src/org/traccar/protocol')
-rw-r--r-- | src/org/traccar/protocol/MegastekProtocolDecoder.java | 109 |
1 files changed, 53 insertions, 56 deletions
diff --git a/src/org/traccar/protocol/MegastekProtocolDecoder.java b/src/org/traccar/protocol/MegastekProtocolDecoder.java index 019bb69de..f9a0cfc05 100644 --- a/src/org/traccar/protocol/MegastekProtocolDecoder.java +++ b/src/org/traccar/protocol/MegastekProtocolDecoder.java @@ -44,7 +44,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { "(\\d+\\.\\d+)?," + // Speed "(\\d+\\.\\d+)?," + // Course "(\\d{2})(\\d{2})(\\d{2})" + // Date (DDMMYY) - "[^\\*]+\\*[0-9a-fA-F]{2}"); // Checksum + ".*"); // Checksum private static final Pattern patternSimple = Pattern.compile( "[FL]," + // Flag @@ -143,10 +143,18 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { id = sentence.substring(beginIndex, endIndex); beginIndex = endIndex + 1; - endIndex = sentence.indexOf('*', beginIndex) + 3; + endIndex = sentence.indexOf('*', beginIndex); + if (endIndex != -1) { + endIndex += 3; + } else { + endIndex = sentence.length(); + } gprmc = sentence.substring(beginIndex, endIndex); beginIndex = endIndex + 1; + if (beginIndex > sentence.length()) { + beginIndex = endIndex; + } status = sentence.substring(beginIndex); } else { @@ -175,78 +183,67 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { if (simple) { - // Parse status Matcher parser = patternSimple.matcher(status); - if (!parser.matches()) { - return null; - } + if (parser.matches()) { - int index = 1; + int index = 1; - // Alarm - position.set(Event.KEY_ALARM, parser.group(index++)); + position.set(Event.KEY_ALARM, parser.group(index++)); - // IMEI - if (!identify(parser.group(index++), channel, null, false)) { - if (!identify(id, channel)) { - return null; + // IMEI + if (!identify(parser.group(index++), channel, null, false)) { + if (!identify(id, channel)) { + return null; + } } - } - position.setDeviceId(getDeviceId()); + position.setDeviceId(getDeviceId()); - // Satellites - position.set(Event.KEY_SATELLITES, parser.group(index++)); + position.set(Event.KEY_SATELLITES, parser.group(index++)); - // Altitude - String altitude = parser.group(index++); - if (altitude != null) { - position.setAltitude(Double.valueOf(altitude)); - } + String altitude = parser.group(index++); + if (altitude != null) { + position.setAltitude(Double.valueOf(altitude)); + } - // Battery - position.set(Event.KEY_POWER, Double.valueOf(parser.group(index++))); + position.set(Event.KEY_POWER, Double.valueOf(parser.group(index++))); - // Charger - String charger = parser.group(index++); - if (charger != null) { - position.set(Event.KEY_CHARGE, Integer.valueOf(charger) == 1); - } + String charger = parser.group(index++); + if (charger != null) { + position.set(Event.KEY_CHARGE, Integer.valueOf(charger) == 1); + } - position.set(Event.KEY_MCC, parser.group(index++)); - position.set(Event.KEY_MNC, parser.group(index++)); - position.set(Event.KEY_LAC, parser.group(index++)); + position.set(Event.KEY_MCC, parser.group(index++)); + position.set(Event.KEY_MNC, parser.group(index++)); + position.set(Event.KEY_LAC, parser.group(index++)); + } } else { - // Parse status Matcher parser = patternAlternative.matcher(status); if (!parser.matches()) { - return null; - } - int index = 1; + int index = 1; - if (!identify(id, channel)) { - return null; + if (!identify(id, channel)) { + return null; + } + position.setDeviceId(getDeviceId()); + + position.set(Event.KEY_MCC, parser.group(index++)); + position.set(Event.KEY_MNC, parser.group(index++)); + position.set(Event.KEY_LAC, parser.group(index++)); + position.set(Event.KEY_GSM, parser.group(index++)); + + position.set(Event.KEY_BATTERY, Double.valueOf(parser.group(index++))); + + position.set(Event.KEY_FLAGS, parser.group(index++)); + position.set(Event.KEY_INPUT, parser.group(index++)); + position.set(Event.KEY_OUTPUT, parser.group(index++)); + position.set(Event.PREFIX_ADC + 1, parser.group(index++)); + position.set(Event.PREFIX_ADC + 2, parser.group(index++)); + position.set(Event.PREFIX_ADC + 3, parser.group(index++)); + position.set(Event.KEY_ALARM, parser.group(index++)); } - position.setDeviceId(getDeviceId()); - - position.set(Event.KEY_MCC, parser.group(index++)); - position.set(Event.KEY_MNC, parser.group(index++)); - position.set(Event.KEY_LAC, parser.group(index++)); - position.set(Event.KEY_GSM, parser.group(index++)); - - // Battery - position.set(Event.KEY_BATTERY, Double.valueOf(parser.group(index++))); - - position.set(Event.KEY_FLAGS, parser.group(index++)); - position.set(Event.KEY_INPUT, parser.group(index++)); - position.set(Event.KEY_OUTPUT, parser.group(index++)); - position.set(Event.PREFIX_ADC + 1, parser.group(index++)); - position.set(Event.PREFIX_ADC + 2, parser.group(index++)); - position.set(Event.PREFIX_ADC + 3, parser.group(index++)); - position.set(Event.KEY_ALARM, parser.group(index++)); - } return position; |