Boost logo

Boost Users :

Subject: Re: [Boost-users] [spirit] Qi rule for GPS NMEA
From: Michael Caisse (mcaisse-lists_at_[hidden])
Date: 2013-09-05 22:27:35


On 09/05/2013 07:00 PM, Michael Powell wrote:
> On Thu, Sep 5, 2013 at 8:54 PM, Michael Caisse <mcaisse-lists_at_[hidden]> 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

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net