[spirit] Qi rule for GPS NMEA
Hello, I'm digging into a qi rule for GPS NMEA and want to approach it as a kind of 2-pass parser. First pass to extract the message and hex-formatted checksum. Next pass to parse out the actual messages from the message. I believe I comprehend how to go about the second pass. For the first pass, I want to parse $XYZ*HH\r\n. That's the literal '$', and everything between there and the literal '*', followed by the two hex characters, as a complete field, followed by the terminal CR+LF. How do I express the "all characters excluding '*'" for the NMEA message? Then the hex field? Thanks... Regards, Michael Powell
Oh yeah, and then I am adapting it into a struct:
BOOST_FUSION_ADAPT_STRUCT(
dchem::drivers::nmea::basic_nmea_message_t,
(std::string, m_message)
(int, m_checksum)
)
Or at least I'd like to. I've got the general framework understood
from the employee-examples.
Thanks again.
On Thu, Sep 5, 2013 at 8:39 PM, Michael Powell
Hello,
I'm digging into a qi rule for GPS NMEA and want to approach it as a kind of 2-pass parser. First pass to extract the message and hex-formatted checksum. Next pass to parse out the actual messages from the message.
I believe I comprehend how to go about the second pass. For the first pass, I want to parse $XYZ*HH\r\n.
That's the literal '$', and everything between there and the literal '*', followed by the two hex characters, as a complete field, followed by the terminal CR+LF.
How do I express the "all characters excluding '*'" for the NMEA message? Then the hex field?
Thanks...
Regards,
Michael Powell
On Thu, Sep 5, 2013 at 8:42 PM, Michael Powell
Oh yeah, and then I am adapting it into a struct:
BOOST_FUSION_ADAPT_STRUCT( dchem::drivers::nmea::basic_nmea_message_t, (std::string, m_message) (int, m_checksum) )
Or at least I'd like to. I've got the general framework understood from the employee-examples.
Thanks again.
I came up with something like this, but I may be completely off the mark:
qi::rule
On Thu, Sep 5, 2013 at 8:39 PM, Michael Powell
wrote: Hello,
I'm digging into a qi rule for GPS NMEA and want to approach it as a kind of 2-pass parser. First pass to extract the message and hex-formatted checksum. Next pass to parse out the actual messages from the message.
I believe I comprehend how to go about the second pass. For the first pass, I want to parse $XYZ*HH\r\n.
That's the literal '$', and everything between there and the literal '*', followed by the two hex characters, as a complete field, followed by the terminal CR+LF.
How do I express the "all characters excluding '*'" for the NMEA message? Then the hex field?
Thanks...
Regards,
Michael Powell
On 09/05/2013 06:42 PM, Michael Powell wrote:
Oh yeah, and then I am adapting it into a struct:
BOOST_FUSION_ADAPT_STRUCT( dchem::drivers::nmea::basic_nmea_message_t, (std::string, m_message) (int, m_checksum) )
Or at least I'd like to. I've got the general framework understood from the employee-examples.
Thanks again.
On Thu, Sep 5, 2013 at 8:39 PM, Michael Powell
wrote: Hello,
I'm digging into a qi rule for GPS NMEA and want to approach it as a kind of 2-pass parser. First pass to extract the message and hex-formatted checksum. Next pass to parse out the actual messages from the message.
I believe I comprehend how to go about the second pass. For the first pass, I want to parse $XYZ*HH\r\n.
That's the literal '$', and everything between there and the literal '*', followed by the two hex characters, as a complete field, followed by the terminal CR+LF.
How do I express the "all characters excluding '*'" for the NMEA message? Then the hex field?
Hi Michael - Parsing NMEA is about as easy as you have described in english. rule = lit('$') >> ~char_('*') >> lit('$') >> hex >> lit("\r\n"); That should parse into the fusion adapted sequence you have described. hth - michael -- Michael Caisse ciere consulting ciere.com
On Thu, Sep 5, 2013 at 8:54 PM, Michael Caisse
On 09/05/2013 06:42 PM, Michael Powell wrote:
Oh yeah, and then I am adapting it into a struct:
BOOST_FUSION_ADAPT_STRUCT( dchem::drivers::nmea::basic_nmea_message_t, (std::string, m_message) (int, m_checksum) )
Or at least I'd like to. I've got the general framework understood from the employee-examples.
Thanks again.
On Thu, Sep 5, 2013 at 8:39 PM, Michael Powell
wrote: Hello,
I'm digging into a qi rule for GPS NMEA and want to approach it as a kind of 2-pass parser. First pass to extract the message and hex-formatted checksum. Next pass to parse out the actual messages from the message.
I believe I comprehend how to go about the second pass. For the first pass, I want to parse $XYZ*HH\r\n.
That's the literal '$', and everything between there and the literal '*', followed by the two hex characters, as a complete field, followed by the terminal CR+LF.
How do I express the "all characters excluding '*'" for the NMEA message? Then the hex field?
Hi Michael -
Parsing NMEA is about as easy as you have described in english.
rule = lit('$') >> ~char_('*') >> lit('$') >> hex >> lit("\r\n");
Pretty straightforward. How about the wrinkle of enforcing the NMEA 2-hex-digit checksum?
That should parse into the fusion adapted sequence you have described.
hth - michael
-- Michael Caisse ciere consulting ciere.com _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On 09/05/2013 07:00 PM, Michael Powell wrote:
On Thu, Sep 5, 2013 at 8:54 PM, Michael Caisse
wrote:
Hi Michael -
Parsing NMEA is about as easy as you have described in english.
rule = lit('$') >> ~char_('*') >> lit('$') >> hex >> lit("\r\n");
Pretty straightforward. How about the wrinkle of enforcing the NMEA 2-hex-digit checksum?
It ends up that the Spirit numeric parser is customizable. Simply create the parser you want. For example: qi::uint_parser< unsigned, 16, 2, 2 > nmea_hex_p; creates a parser that will synthesize unsigned values that are parsed as base 16 and must have exactly 2 digits. rule >> lit('$') >> ~char_('*') >> '*' >> nmea_hex_p >> "\r\n"; michael -- Michael Caisse ciere consulting ciere.com
On Thu, Sep 5, 2013 at 9:27 PM, Michael Caisse
On 09/05/2013 07:00 PM, Michael Powell wrote:
On Thu, Sep 5, 2013 at 8:54 PM, Michael Caisse
wrote: Hi Michael -
Parsing NMEA is about as easy as you have described in english.
rule = lit('$') >> ~char_('*') >> lit('$') >> hex >> lit("\r\n");
Pretty straightforward. How about the wrinkle of enforcing the NMEA 2-hex-digit checksum?
It ends up that the Spirit numeric parser is customizable. Simply create the parser you want. For example:
qi::uint_parser< unsigned, 16, 2, 2 > nmea_hex_p;
creates a parser that will synthesize unsigned values that are parsed as base 16 and must have exactly 2 digits.
rule >> lit('$') >> ~char_('*') >> '*' >> nmea_hex_p >> "\r\n";
Well, whaddaya know. Poifect! Thanks!
michael
-- Michael Caisse ciere consulting ciere.com _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On 05/09/2013 10:54 p.m., Michael Caisse wrote:
Parsing NMEA is about as easy as you have described in english.
rule = lit('$') >> ~char_('*') >> lit('$') >> hex >> lit("\r\n");
There should be a `>> '*'` right after `~char_('*')` to consume that '*'. Regards, -- Agustín K-ballo Bergé.- http://talesofcpp.fusionfenix.com
On 09/05/2013 07:13 PM, Agustín K-ballo Bergé wrote:
On 05/09/2013 10:54 p.m., Michael Caisse wrote:
Parsing NMEA is about as easy as you have described in english.
rule = lit('$') >> ~char_('*') >> lit('$') >> hex >> lit("\r\n");
There should be a `>> '*'` right after `~char_('*')` to consume that '*'.
Regards,
Whoops. K-ballo is correct of course. I got a little hasty. The second lit('$') should be lit('*') or just '*'. -- Michael Caisse ciere consulting ciere.com
On Thu, Sep 5, 2013 at 9:21 PM, Michael Caisse
On 09/05/2013 07:13 PM, Agustín K-ballo Bergé wrote:
On 05/09/2013 10:54 p.m., Michael Caisse wrote:
Parsing NMEA is about as easy as you have described in english.
rule = lit('$') >> ~char_('*') >> lit('$') >> hex >> lit("\r\n");
There should be a `>> '*'` right after `~char_('*')` to consume that '*'.
Regards,
Whoops. K-ballo is correct of course. I got a little hasty. The second lit('$') should be lit('*') or just '*'.
Yessir, I got all that. Pretty straightforward from the NMEA docs. How to specify the width of the hex field, though? I'm pretty sure it should go $XYZ*HH\r\n (only 2-hex-digits). Thank ye...
Michael Caisse ciere consulting ciere.com _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (3)
-
Agustín K-ballo Bergé
-
Michael Caisse
-
Michael Powell