ttlappalainen / NMEA0183

Library for handling NMEA0183 messages
76 stars 48 forks source link

MWV True wind != Theoretical wind #26

Open lsoltero opened 3 years ago

lsoltero commented 3 years ago

http://caxapa.ru/thumbs/214299/NMEA0183_.pdf

MWV is referenced as Apparent wind OR Theoretical wind. I quote

When the reference field is set to T (Theoretical, calculated actual wind), data is provided giving the wind angle in relation to the vessel's bow/centerline and the wind speed as if the vessel was stationary. On a moving ship these data can be calculated by combining the measured relative wind with the vessel's own speed.

The code assumes that 'T' refers to True which is misleading. There is nothing wrong with the way things are written but an implementor might be mislead sending true wind values instead of Theoretical.

The library should probably be modified to change references to NMEA0183Wind_True to NMEA0183Wind_Theoretical

enum tNMEA0183WindReference {
                            NMEA0183Wind_True=0,
                            // Apparent Wind (relative to the vessel centerline)
                            NMEA0183Wind_Apparent=1
                          };

//*****************************************************************************
// MWV - Wind Speed and Angle
//$IIMWV,120.1,R,9.5,M,A,a*hh
bool NMEA0183ParseMWV_nc(const tNMEA0183Msg &NMEA0183Msg,double &WindAngle, tNMEA0183WindReference &Reference, double &WindSpeed) {
  bool result=( NMEA0183Msg.FieldCount()>=4 );

  if ( result ) {
    WindAngle=atof(NMEA0183Msg.Field(0))*degToRad;
    switch ( NMEA0183Msg.Field(1)[0] ) {
      case 'T' : Reference=NMEA0183Wind_True; break;
      case 'R' :
      default : Reference=NMEA0183Wind_Apparent; break;
    }
    WindSpeed=atof(NMEA0183Msg.Field(2));
    switch ( NMEA0183Msg.Field(3)[0] ) {
      case 'K' : WindSpeed*=kmhToms; break;
      case 'N' : WindSpeed*=knToms; break;
      case 'M' :
      default : ;
    }
  }

  return result;
}
ttlappalainen commented 3 years ago

Damn. https://gpsd.gitlab.io/gpsd/NMEA.html#_mwv_wind_speed_and_angle says True.

It is problematic, since it changes compatibility.

lsoltero commented 3 years ago

Hi Temo,

I agree that this is very problematic. But the link I sent you is for the NMEA183 spec from NMEA. And it clearly states that "T" means Theoretical and not true. It then goes on to describe what that means.

I first ran into this when looking at output from the YD N2k to NMEA converter. They use the correct definition for "theoretical" as defined by NMEA.

Here is the link again..

http://caxapa.ru/thumbs/214299/NMEA0183_.pdf

and here is the title page for the guide.

NMEA 0183 Standard For Interfacing Marine Electronic Devices Version 3.01 January 1, 2002

I would say that the entry for this sentence at gpsd.gitlab.io is suspect and should be looked at more closely.

The question is what to do... Although changing True to Theoretical will break many applications the fact is that these applications are probably broken anyway. So... changing NMEA0183Wind_True to NMEA0183Wind_Theoretical will cause a compile error that will cause the developer to revisit this. I suggest putting a note in the include file that describes the issue with possibly a link to the NMEA0183 spec.

Take care.

--luis