From 6a2c623ea03c387595c6a6348034e28193acee04 Mon Sep 17 00:00:00 2001 From: free-x Date: Tue, 25 Feb 2025 18:54:00 +0100 Subject: [PATCH] #103: using formatters --- lib/boatData/GwBoatData.cpp | 7 ++++++- lib/boatData/GwBoatData.h | 3 ++- lib/nmea2kto0183/N2kDataToNMEA0183.cpp | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/boatData/GwBoatData.cpp b/lib/boatData/GwBoatData.cpp index 39d22c8..424ebe4 100644 --- a/lib/boatData/GwBoatData.cpp +++ b/lib/boatData/GwBoatData.cpp @@ -493,6 +493,11 @@ double formatKnots(double cv) return cv * 3600.0 / 1852.0; } +double formatKmh(double cv) +{ + return cv *3600.0 / 1000.0; +} + uint32_t mtr2nm(uint32_t m) { return m / 1852; @@ -523,4 +528,4 @@ public: }; static XWriter xwriter; ARDUINOJSON_NAMESPACE::TextFormatter testWriter(xwriter); -#endif \ No newline at end of file +#endif diff --git a/lib/boatData/GwBoatData.h b/lib/boatData/GwBoatData.h index a4df3b4..ae50b3f 100644 --- a/lib/boatData/GwBoatData.h +++ b/lib/boatData/GwBoatData.h @@ -129,6 +129,7 @@ double formatCourse(double cv); double formatDegToRad(double deg); double formatWind(double cv); double formatKnots(double cv); +double formatKmh(double cv); uint32_t mtr2nm(uint32_t m); double mtr2nm(double m); @@ -251,4 +252,4 @@ class GwBoatData{ }; -#endif \ No newline at end of file +#endif diff --git a/lib/nmea2kto0183/N2kDataToNMEA0183.cpp b/lib/nmea2kto0183/N2kDataToNMEA0183.cpp index 11854f1..278c71e 100644 --- a/lib/nmea2kto0183/N2kDataToNMEA0183.cpp +++ b/lib/nmea2kto0183/N2kDataToNMEA0183.cpp @@ -537,7 +537,7 @@ private: return; if (!NMEA0183Msg.AddStrField((WindAngle >= 0 && WindAngle <= 180) ? 'R' : 'L')) return; - if (!NMEA0183Msg.AddDoubleField(WindSpeed * 3600.0/1852.0)) + if (!NMEA0183Msg.AddDoubleField(formatKnots(WindSpeed))) return; if (!NMEA0183Msg.AddStrField("N")) return; @@ -545,7 +545,7 @@ private: return; if (!NMEA0183Msg.AddStrField("M")) return; - if (!NMEA0183Msg.AddDoubleField(WindSpeed * 3600.0/1000.0)) + if (!NMEA0183Msg.AddDoubleField(formatKmh(WindSpeed))) return; if (!NMEA0183Msg.AddStrField("K")) return;