ttlappalainen / NMEA0183

Library for handling NMEA0183 messages
76 stars 48 forks source link

Add parser for DPT #32

Closed mjsneijders closed 2 years ago

mjsneijders commented 2 years ago

add the parser for DPT,
as mentioned in issue #30

ttlappalainen commented 2 years ago

I prefer to use double for real world values. E.g., range is real value even message can internally handle it only as int.

ttlappalainen commented 2 years ago

I prefer to use NMEA0183Msg.AddDoubleField, since that handles NA. On parser use NMEA0183GetDouble. And result should be true or false.

bool NMEA0183ParseDPT_nc(const tNMEA0183Msg &NMEA0183Msg,  double &DepthBelowTransducer, double &Offset, double &Range ) {
  bool result=( NMEA0183Msg.FieldCount()>= 2);

  if ( result ) {
    DepthBelowTransducer=NMEA0183GetDouble(NMEA0183Msg.Field(0));
    Offset=NMEA0183GetDouble(NMEA0183Msg.Field(1));
    if ( NMEA0183Msg.FieldCount()>2  ) Range=NMEA0183GetDouble(NMEA0183Msg.Field(2));
  }
  return result;
}
ttlappalainen commented 2 years ago