From ae9334236b91432b000144721b310a4fc81ab031 Mon Sep 17 00:00:00 2001 From: Thomas Hooge Date: Wed, 20 Aug 2025 21:33:08 +0200 Subject: [PATCH] Implemented string boatdata value WPName for next waypoint --- .gitignore | 1 + lib/api/GwApi.h | 1 + lib/boatData/GwBoatData.cpp | 7 +------ lib/boatData/GwBoatData.h | 12 ++++++++++++ lib/nmea0183ton2k/NMEA0183DataToN2K.cpp | 1 + lib/obp60task/PageXTETrack.cpp | 6 ++++-- src/main.cpp | 12 +++++++++--- 7 files changed, 29 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index b5ca1aa..a1e7d3d 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ generated/* lib/generated webinstall/token.php +*~ diff --git a/lib/api/GwApi.h b/lib/api/GwApi.h index 03f0e71..210519e 100644 --- a/lib/api/GwApi.h +++ b/lib/api/GwApi.h @@ -24,6 +24,7 @@ class GwApi{ bool formatSet=false; public: double value=0; + String svalue=""; bool valid=false; int source=-1; bool changed=false; //will be set by getBoatDataValues diff --git a/lib/boatData/GwBoatData.cpp b/lib/boatData/GwBoatData.cpp index 162e528..50fd583 100644 --- a/lib/boatData/GwBoatData.cpp +++ b/lib/boatData/GwBoatData.cpp @@ -2,12 +2,6 @@ #include #include #include "GWConfig.h" -#define GWTYPE_DOUBLE 1 -#define GWTYPE_UINT32 2 -#define GWTYPE_UINT16 3 -#define GWTYPE_INT16 4 -#define GWTYPE_STRING 5 -#define GWTYPE_USER 100 class GwBoatItemTypes { @@ -294,6 +288,7 @@ template class GwBoatItem; template class GwBoatItem; template class GwBoatItem; template class GwBoatItem; +template class GwBoatItem; void GwSatInfoList::houseKeeping(unsigned long ts) { if (ts == 0) diff --git a/lib/boatData/GwBoatData.h b/lib/boatData/GwBoatData.h index bfcda60..5c5cbbd 100644 --- a/lib/boatData/GwBoatData.h +++ b/lib/boatData/GwBoatData.h @@ -9,6 +9,13 @@ #define GW_BOAT_VALUE_LEN 32 #define GWSC(name) static constexpr const char* name=#name +#define GWTYPE_DOUBLE 1 +#define GWTYPE_UINT32 2 +#define GWTYPE_UINT16 3 +#define GWTYPE_INT16 4 +#define GWTYPE_STRING 5 +#define GWTYPE_USER 100 + //see https://github.com/wellenvogel/esp32-nmea2000/issues/44 //factor to convert from N2k/SI rad/s to current NMEA rad/min #define ROT_WA_FACTOR 60 @@ -93,6 +100,7 @@ class GwBoatItemBase{ virtual int getLastSource(){return lastUpdateSource;} virtual void refresh(unsigned long ts=0){uls(ts);} virtual double getDoubleValue()=0; + virtual String getStringValue()=0; String getName(){return name;} const String & getFormat() const{return format;} virtual void setInvalidTime(GwConfigHandler *cfg); @@ -128,6 +136,10 @@ template class GwBoatItem : public GwBoatItemBase{ return (double)data; } } + virtual String getStringValue(){ + return (String)data; + } + virtual void fillString(); virtual void toJsonDoc(GwJsonDocument *doc, unsigned long minTime); virtual int getLastSource(){return lastUpdateSource;} diff --git a/lib/nmea0183ton2k/NMEA0183DataToN2K.cpp b/lib/nmea0183ton2k/NMEA0183DataToN2K.cpp index ef17866..123755f 100644 --- a/lib/nmea0183ton2k/NMEA0183DataToN2K.cpp +++ b/lib/nmea0183ton2k/NMEA0183DataToN2K.cpp @@ -355,6 +355,7 @@ private: AppendN2kRouteWPInfo(n2kMsg,destinationId,rmb.destID,rmb.latitude,rmb.longitude); send(n2kMsg,msg.sourceId); } + boatData->WPName->update(String(rmb.destID), msg.sourceId); } void convertRMC(const SNMEA0183Msg &msg) { diff --git a/lib/obp60task/PageXTETrack.cpp b/lib/obp60task/PageXTETrack.cpp index 1952c16..afada12 100644 --- a/lib/obp60task/PageXTETrack.cpp +++ b/lib/obp60task/PageXTETrack.cpp @@ -133,6 +133,8 @@ public: epd->setCursor(360-w, 257); epd->print(sval_btw); + GwApi::BoatValue *bv_wpname = pageData.values[4]; // WPName + bool valid = bv_cog->valid && bv_btw->valid; // XTETrack view @@ -144,7 +146,7 @@ public: String sval_wpname = "no data"; if (valid) { - sval_wpname = "Tonne 122"; + sval_wpname = bv_wpname->svalue; } epd->setFont(&Ubuntu_Bold10pt8b); @@ -225,7 +227,7 @@ PageDescription registerPageXTETrack( "XTETrack", // Page name createPage, // Action 0, // Number of bus values depends on selection in Web configuration - {"XTE", "COG", "DTW", "BTW"}, // Bus values we need in the page + {"XTE", "COG", "DTW", "BTW", "WPName"}, // Bus values we need in the page true // Show display header on/off ); diff --git a/src/main.cpp b/src/main.cpp index 2dd1f2b..1e03760 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -302,9 +302,15 @@ public: if (newValid != list[i]->valid) list[i]->changed=true; list[i]->valid=newValid; if (newValid){ - double newValue=item->getDoubleValue(); - if (newValue != list[i]->value) list[i]->changed=true; - list[i]->value=newValue; + if (item->getCurrentType() == GWTYPE_STRING) { + String newValue=item->getStringValue(); + if (newValue != list[i]->svalue) list[i]->changed=true; + list[i]->svalue=newValue; + } else { + double newValue=item->getDoubleValue(); + if (newValue != list[i]->value) list[i]->changed=true; + list[i]->value=newValue; + } int newSource=item->getLastSource(); if (newSource != list[i]->source){ list[i]->source=newSource;