Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extending parser with proprietary sentences #36

Open
jtojnar opened this issue Oct 20, 2022 · 1 comment
Open

Extending parser with proprietary sentences #36

jtojnar opened this issue Oct 20, 2022 · 1 comment

Comments

@jtojnar
Copy link
Contributor

jtojnar commented Oct 20, 2022

I need to interact with a proprietary GPS logger that sends sentences like:

$PMTK182,8,0001F800,FFFFFFFFFFFFFF…FFFFF*52

Now I could wrap the parse_sentence function and handle those proprietary functions in the wrapper but I would have to duplicate code like checksum verification.

Possible solutions:

  • Include the whole sentence as a struct field in ParseError::UnsupportedSentenceType so that wrapper can attempt to handle it after running parse_sentence.
  • Return Ok(ParsedMessage::Proprietary(String)) from parse_sentence instead of ParseError::UnsupportedSentenceType.
  • Factor out the verify_and_strip_checksum function and make it public.
  • Add NmeaParserFull<ProprietaryMessagesType> (NmeaParser would become NmeaParserFull<()>) and a method like NmeaParserFull::register_parser_for_prefix<H>(prefix: &str, handler: H) where H: Fn(&str) -> Option<ProprietaryMessagesType>
@zaari
Copy link
Owner

zaari commented Nov 17, 2022

I would be in favor of the first option (ParseError::UnsupportedSentenceType). Feel free to make a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants