diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2014-09-28 22:41:06 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2014-09-28 22:41:06 +1300 |
commit | b1fd39287427aaf16768ee697263cb2aa872f1c9 (patch) | |
tree | 436e718a89ed5dbd8eeb8806f43d3c75860f5625 | |
parent | 2251e122d955b3ea8f0493e157a00cc3355e1606 (diff) | |
download | trackermap-server-b1fd39287427aaf16768ee697263cb2aa872f1c9.tar.gz trackermap-server-b1fd39287427aaf16768ee697263cb2aa872f1c9.tar.bz2 trackermap-server-b1fd39287427aaf16768ee697263cb2aa872f1c9.zip |
Support Megastek log message (fix #895)
-rw-r--r-- | src/org/traccar/protocol/MegastekProtocolDecoder.java | 18 | ||||
-rw-r--r-- | test/org/traccar/protocol/MegastekProtocolDecoderTest.java | 13 |
2 files changed, 18 insertions, 13 deletions
diff --git a/src/org/traccar/protocol/MegastekProtocolDecoder.java b/src/org/traccar/protocol/MegastekProtocolDecoder.java index a6479d399..96b2d564d 100644 --- a/src/org/traccar/protocol/MegastekProtocolDecoder.java +++ b/src/org/traccar/protocol/MegastekProtocolDecoder.java @@ -46,16 +46,17 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { "(\\d{2})(\\d{2})(\\d{2})" + // Date (DDMMYY) "[^\\*]+\\*[0-9a-fA-F]{2}"); // Checksum + //F,,imei:123456789012345,0/6,,Battery=100%,,0,,,5856,78A3;24 private static final Pattern patternSimple = Pattern.compile( "[FL]," + // Flag "([^,]*)," + // Alarm "imei:(\\d+)," + // IMEI "(\\d+/?\\d*)?," + // Satellites - "(\\d+\\.\\d+)," + // Altitude + "(\\d+\\.\\d+)?," + // Altitude "Battery=(\\d+)%,," + // Battery "(\\d)?," + // Charger - "(\\d+)," + // MCC - "(\\d+)," + // MNC + "(\\d+)?," + // MCC + "(\\d+)?," + // MNC "(\\p{XDigit}{4},\\p{XDigit}{4});" + // Location code ".+"); // Checksum @@ -139,7 +140,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { String sentence = (String) msg; // Detect type - boolean simple = (sentence.charAt(3) == ','); + boolean simple = (sentence.charAt(3) == ',' || sentence.charAt(6) == ','); // Split message String id; @@ -147,7 +148,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { String status; if (simple) { - int beginIndex = 4; + int beginIndex = sentence.indexOf(',') + 1; int endIndex = sentence.indexOf(',', beginIndex); id = sentence.substring(beginIndex, endIndex); @@ -212,7 +213,12 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { extendedInfo.set("satellites", parser.group(index++)); // Altitude - position.setAltitude(Double.valueOf(parser.group(index++))); + String altitude = parser.group(index++); + if (altitude != null) { + position.setAltitude(Double.valueOf(altitude)); + } else { + position.setAltitude(0.0); + } // Battery extendedInfo.set("power", Double.valueOf(parser.group(index++))); diff --git a/test/org/traccar/protocol/MegastekProtocolDecoderTest.java b/test/org/traccar/protocol/MegastekProtocolDecoderTest.java index b2d799449..f7d682dba 100644 --- a/test/org/traccar/protocol/MegastekProtocolDecoderTest.java +++ b/test/org/traccar/protocol/MegastekProtocolDecoderTest.java @@ -1,9 +1,8 @@ package org.traccar.protocol; -import static org.junit.Assert.assertNull; -import org.junit.Test; -import static org.traccar.helper.DecoderVerifier.verify; import org.traccar.helper.TestDataManager; +import static org.traccar.helper.DecoderVerifier.verify; +import org.junit.Test; public class MegastekProtocolDecoderTest { @@ -33,14 +32,14 @@ public class MegastekProtocolDecoderTest { verify(decoder.decode(null, null, "STX260475 $GPRMC,104032.001,A,4022.1119,N,01811.4081,E,000.0,000.0,060913,,,A*67,222,01,815A,D455,11,99,0000,0001,0,Timer;")); - - assertNull(decoder.decode(null, null, + + verify(decoder.decode(null, null, "LOGSTX,123456789012345,$GPRMC,225419.000,A,3841.82201,N,09494.73357,W,12.46,135.33,270914,,,A*47,F,,imei:123456789012345,0/6,,Battery=100%,,0,,,5856,78A3;24")); - assertNull(decoder.decode(null, null, + verify(decoder.decode(null, null, "LOGSTX,123456789012345,$GPRMC,230551.000,A,3841.81956,N,09494.45403,W,0.00,0.00,270914,,,A*7C,L,,imei:123456789012345,0/7,269.7,Battery=100%,,0,,,5856,78A3;83")); - assertNull(decoder.decode(null, null, + verify(decoder.decode(null, null, "LOGSTX,123456789012345,$GPRMC,230739.000,A,3841.81895,N,09494.12409,W,0.00,0.00,270914,,,A*70,L,,imei:123456789012345,0/7,269.7,Battery=100%,,0,,,5856,78A3;78")); } |