diff --git a/lib/KBoxHardware/src/board.h b/lib/KBoxHardware/src/board.h index a7faca76..3ba3d078 100644 --- a/lib/KBoxHardware/src/board.h +++ b/lib/KBoxHardware/src/board.h @@ -82,7 +82,7 @@ static const pin_t nmea2_out_enable = 16; #define NMEA1_SERIAL Serial2 #define NMEA2_SERIAL Serial3 -/* Analag Inputs */ +/* Analog Inputs */ #ifdef BOARD_v1_revA static const pin_t adc1_analog = A10; static const pin_t adc2_analog = A11; @@ -97,4 +97,4 @@ static const float analog_max_voltage = 3.0 / (10000/(10000+56000.0)); static const pin_t supply_analog = A14; /* SDCard Interface */ -static const pin_t sdcard_cs = 15; \ No newline at end of file +static const pin_t sdcard_cs = 15; diff --git a/src/common/signalk/SKNMEAParser.cpp b/src/common/signalk/SKNMEAParser.cpp index 6cea5c23..18a9ffcd 100644 --- a/src/common/signalk/SKNMEAParser.cpp +++ b/src/common/signalk/SKNMEAParser.cpp @@ -133,10 +133,7 @@ const SKUpdate& SKNMEAParser::parseMWV(const SKSourceInput& input, NMEASentenceR // Wind sensors return a number between 0 and 360 but we want an // angle in radian with negative values when wind coming from port - if (windAngle > 180) { - windAngle = windAngle - 360; - } - windAngle = SKDegToRad(windAngle); + windAngle = SKNormalizeAngle(SKDegToRad(windAngle)); SKUpdateStatic<2>* wmv = new SKUpdateStatic<2>(); wmv->setTimestamp(time); diff --git a/src/test/signalk/SKNMEAParserTest.cpp b/src/test/signalk/SKNMEAParserTest.cpp index 4e141e04..63ab3da1 100644 --- a/src/test/signalk/SKNMEAParserTest.cpp +++ b/src/test/signalk/SKNMEAParserTest.cpp @@ -75,8 +75,8 @@ TEST_CASE("SKNMEAParser: MWV") { CHECK( update.getSource() != SKSourceUnknown ); CHECK( update.getContext() == SKContextSelf ); CHECK( update.getTimestamp().getTime() == 42 ); - CHECK( update.getEnvironmentWindSpeedApparent() == SKKnotToMs(5.19) ); - CHECK( update.getEnvironmentWindAngleApparent() == SKDegToRad(56) ); + CHECK( update.getEnvironmentWindSpeedApparent() == Approx(SKKnotToMs(5.19)) ); + CHECK( update.getEnvironmentWindAngleApparent() == Approx(SKDegToRad(56)) ); } SECTION("MWV true") { const SKUpdate& update = p.parse(SKSourceInputNMEA0183_1, "$IIMWV,027,T,3.82,N,A*19", SKTime(42)); @@ -111,6 +111,12 @@ TEST_CASE("SKNMEAParser: MWV") { CHECK( update.getSize() == 0 ); } + SECTION("MWV relative with wind angle > 180") { + // Unit S seems to be knots but I cannot find a real source here. + const SKUpdate& update = p.parse(SKSourceInputNMEA0183_1, "$WIMWV,271,R,5.6,K,A*3F", SKTime(42)); + + CHECK( update.getEnvironmentWindAngleApparent() == Approx(SKDegToRad(-89)) ); + } } TEST_CASE("SKNMEAParser: XDR wind temperature") {