aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/org/traccar/protocol/MegastekProtocolDecoder.java17
-rw-r--r--test/org/traccar/protocol/MegastekProtocolDecoderTest.java3
2 files changed, 10 insertions, 10 deletions
diff --git a/src/org/traccar/protocol/MegastekProtocolDecoder.java b/src/org/traccar/protocol/MegastekProtocolDecoder.java
index 8032a0b9d..9d77c4b8d 100644
--- a/src/org/traccar/protocol/MegastekProtocolDecoder.java
+++ b/src/org/traccar/protocol/MegastekProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 - 2014 Anton Tananaev (anton.tananaev@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,7 +33,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder {
super(serverManager);
}
- static private Pattern patternGPRMC = Pattern.compile(
+ private static final Pattern patternGPRMC = Pattern.compile(
"\\$GPRMC," +
"(\\d{2})(\\d{2})(\\d{2})\\.\\d+," + // Time (HHMMSS.SSS)
"([AV])," + // Validity
@@ -46,11 +46,11 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder {
"(\\d{2})(\\d{2})(\\d{2})" + // Date (DDMMYY)
"[^\\*]+\\*[0-9a-fA-F]{2}"); // Checksum
- static private Pattern patternSimple = Pattern.compile(
+ private static final Pattern patternSimple = Pattern.compile(
"[FL]," + // Flag
"([^,]*)," + // Alarm
"imei:(\\d+)," + // IMEI
- "(\\d+)?," + // Satellites
+ "(\\d+/?\\d*)?," + // Satellites
"(\\d+\\.\\d+)," + // Altitude
"Battery=(\\d+)%,," + // Battery
"(\\d)?," + // Charger
@@ -59,7 +59,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder {
"(\\p{XDigit}{4},\\p{XDigit}{4});" + // Location code
".+"); // Checksum
- static private Pattern patternAlternative = Pattern.compile(
+ private static final Pattern patternAlternative = Pattern.compile(
"(\\d+)," + // MCC
"(\\d+)," + // MNC
"(\\p{XDigit}{4},\\p{XDigit}{4})," + // Location code
@@ -92,7 +92,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder {
time.set(Calendar.SECOND, Integer.valueOf(parser.group(index++)));
// Validity
- position.setValid(parser.group(index++).compareTo("A") == 0 ? true : false);
+ position.setValid(parser.group(index++).compareTo("A") == 0);
// Latitude
Double latitude = Double.valueOf(parser.group(index++));
@@ -209,10 +209,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder {
}
// Satellites
- String satellites = parser.group(index++);
- if (satellites != null) {
- extendedInfo.set("satellites", satellites);
- }
+ extendedInfo.set("satellites", parser.group(index++));
// Altitude
position.setAltitude(Double.valueOf(parser.group(index++)));
diff --git a/test/org/traccar/protocol/MegastekProtocolDecoderTest.java b/test/org/traccar/protocol/MegastekProtocolDecoderTest.java
index a157f01c0..de5d6454f 100644
--- a/test/org/traccar/protocol/MegastekProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/MegastekProtocolDecoderTest.java
@@ -17,6 +17,9 @@ public class MegastekProtocolDecoderTest {
verify(decoder.decode(null, null,
"STX,GerAL22,$GPRMC,000051.000,A,3637.079590,S,6416.2148,W,1.72,332.98,010109,,,A*52,L,,imei:861785000249353,03,275.3,Battery=68%,,1,722,07,0515,1413;41"));
+
+ verify(decoder.decode(null, null,
+ "STX,,$GPRMC,001339.000,A,4710.85395,N,02733.58209,E,1.65,238.00,010109,,,A*67,L,Help,imei:013227009737796,0/8,137.1,Battery=100%,,0,226,01,2B9B,BBBF;8D"));
verify(decoder.decode(null, null,
"STX,102110830074542,$GPRMC,114229.000,A,2238.2024,N,11401.9619,E,0.00,0.00,310811,,,A*64,F,LowBattery,imei:012207005553885,03,113.1,Battery=24%,,1,460,01,2531,647E;57"));