From 113d83778acdff9288d8e68e54275bc73e8dbdc4 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 15 Nov 2012 22:24:40 +1300 Subject: Fix pt502 protocol (fix #90) --- .../traccar/protocol/Gps103ProtocolDecoder.java | 2 ++ src/org/traccar/protocol/Pt502ProtocolDecoder.java | 22 +++++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) (limited to 'src') 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++))); -- cgit v1.2.3