diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2012-11-15 22:24:40 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2012-11-15 22:24:40 +1300 |
commit | 113d83778acdff9288d8e68e54275bc73e8dbdc4 (patch) | |
tree | b28c6325419d71712258ceccb0c1041f0e3a96ac | |
parent | 3ee4d2fba538eee4d1774bd79e07c64dc0af97e5 (diff) | |
download | trackermap-server-113d83778acdff9288d8e68e54275bc73e8dbdc4.tar.gz trackermap-server-113d83778acdff9288d8e68e54275bc73e8dbdc4.tar.bz2 trackermap-server-113d83778acdff9288d8e68e54275bc73e8dbdc4.zip |
Fix pt502 protocol (fix #90)
-rw-r--r-- | src/org/traccar/protocol/Gps103ProtocolDecoder.java | 2 | ||||
-rw-r--r-- | src/org/traccar/protocol/Pt502ProtocolDecoder.java | 22 | ||||
-rw-r--r-- | test/org/traccar/protocol/Pt502ProtocolDecoderTest.java | 9 |
3 files changed, 28 insertions, 5 deletions
diff --git a/src/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/org/traccar/protocol/Gps103ProtocolDecoder.java index 4c8c4255c..1f19b56e4 100644 --- a/src/org/traccar/protocol/Gps103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gps103ProtocolDecoder.java @@ -22,6 +22,7 @@ import java.util.regex.Pattern; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.GenericProtocolDecoder; +import org.traccar.helper.Log; import org.traccar.model.DataManager; import org.traccar.model.Position; @@ -81,6 +82,7 @@ public class Gps103ProtocolDecoder extends GenericProtocolDecoder { // Parse message Matcher parser = pattern.matcher(sentence); if (!parser.matches()) { + Log.info("Parsing error"); return null; } diff --git a/src/org/traccar/protocol/Pt502ProtocolDecoder.java b/src/org/traccar/protocol/Pt502ProtocolDecoder.java index a010f936f..b08b6c1bd 100644 --- a/src/org/traccar/protocol/Pt502ProtocolDecoder.java +++ b/src/org/traccar/protocol/Pt502ProtocolDecoder.java @@ -51,8 +51,8 @@ public class Pt502ProtocolDecoder extends GenericProtocolDecoder { "([NS])," +
"(\\d{3})(\\d{2}\\.\\d{4})," + // Longitude (DDDMM.MMMM)
"([EW])," +
- "(\\d+\\.\\d+)," + // Speed
- "(\\d+\\.\\d+)," + // Course (or Distance???)
+ "(\\d+\\.\\d+)?," + // Speed
+ "(\\d+\\.\\d+)?," + // Course
"(\\d{2})(\\d{2})(\\d{2})," + // Date
".*");
@@ -68,7 +68,7 @@ public class Pt502ProtocolDecoder extends GenericProtocolDecoder { // Parse message
Matcher parser = pattern.matcher(sentence);
if (!parser.matches()) {
- Log.getLogger().info("Parsing error");
+ Log.info("Parsing error");
return null;
}
@@ -113,8 +113,20 @@ public class Pt502ProtocolDecoder extends GenericProtocolDecoder { position.setAltitude(0.0);
// Speed
- position.setSpeed(Double.valueOf(parser.group(index++)));
- position.setCourse(Double.valueOf(parser.group(index++)));
+ String speed = parser.group(index++);
+ if (speed != null) {
+ position.setSpeed(Double.valueOf(speed));
+ } else {
+ position.setSpeed(0.0);
+ }
+
+ // Course
+ String course = parser.group(index++);
+ if (course != null) {
+ position.setCourse(Double.valueOf(course));
+ } else {
+ position.setCourse(0.0);
+ }
// Date
time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(parser.group(index++)));
diff --git a/test/org/traccar/protocol/Pt502ProtocolDecoderTest.java b/test/org/traccar/protocol/Pt502ProtocolDecoderTest.java index 8b8881bd8..5cf3318d6 100644 --- a/test/org/traccar/protocol/Pt502ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Pt502ProtocolDecoderTest.java @@ -13,6 +13,15 @@ public class Pt502ProtocolDecoderTest { assertNotNull(decoder.decode(null, null, "$POS,6094,205523.000,A,1013.6223,N,06728.4248,W,0.0,99.3,011112,,,A/00000,00000/0/23895000//")); + assertNotNull(decoder.decode(null, null, + "$POS,6120,233326.000,V,0935.1201,N,06914.6933,W,0.00,,151112,,,A/00000,00000/0/0/")); + + assertNotNull(decoder.decode(null, null, + "$POS,6002,233257.000,A,0931.0430,N,06912.8707,W,0.05,146.98,141112,,,A/00010,00000/0/5360872")); + + assertNotNull(decoder.decode(null, null, + "$POS,6095,233344.000,V,0933.0451,N,06912.3360,W,,,151112,,,N/00000,00000/0/1677600/")); + } } |