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 /src/org | |
parent | 3ee4d2fba538eee4d1774bd79e07c64dc0af97e5 (diff) | |
download | traccar-server-113d83778acdff9288d8e68e54275bc73e8dbdc4.tar.gz traccar-server-113d83778acdff9288d8e68e54275bc73e8dbdc4.tar.bz2 traccar-server-113d83778acdff9288d8e68e54275bc73e8dbdc4.zip |
Fix pt502 protocol (fix #90)
Diffstat (limited to 'src/org')
-rw-r--r-- | src/org/traccar/protocol/Gps103ProtocolDecoder.java | 2 | ||||
-rw-r--r-- | src/org/traccar/protocol/Pt502ProtocolDecoder.java | 22 |
2 files changed, 19 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++)));
|