aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/org/traccar/protocol/MegastekProtocolDecoder.java109
-rw-r--r--test/org/traccar/protocol/MegastekProtocolDecoderTest.java3
2 files changed, 56 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;
diff --git a/test/org/traccar/protocol/MegastekProtocolDecoderTest.java b/test/org/traccar/protocol/MegastekProtocolDecoderTest.java
index a9b7c4f0a..21a2d46b4 100644
--- a/test/org/traccar/protocol/MegastekProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/MegastekProtocolDecoderTest.java
@@ -12,6 +12,9 @@ public class MegastekProtocolDecoderTest extends ProtocolDecoderTest {
MegastekProtocolDecoder decoder = new MegastekProtocolDecoder(new MegastekProtocol());
verify(decoder.decode(null, null,
+ "STX,865067020439090,$GPRMC,171013.000,A,5919.1411,N,01804.1681,E,0.000,294.41,140815,,,A"));
+
+ verify(decoder.decode(null, null,
"$MGV002,013777007536434,,R,010114,000057,V,0000.0000,N,00000.0000,E,00,00,00,99.9,0.000,0.00,0.0,80.263,510,89,2342,030B,,0000,0000,200,96,0, , ,,,,Timer;!"));
verify(decoder.decode(null, null,