From 08af807cf97f59c2067d645723f429f4fe3eb0a2 Mon Sep 17 00:00:00 2001 From: andreas Date: Sat, 13 Nov 2021 12:32:38 +0100 Subject: [PATCH] max handling also from 0183, satInfo cleanup --- lib/boatData/GwBoatData.h | 22 ++++++++++++++++++++-- lib/nmea0183ton2k/NMEA0183DataToN2K.cpp | 4 ++++ lib/nmea2kto0183/N2kDataToNMEA0183.cpp | 5 +---- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/lib/boatData/GwBoatData.h b/lib/boatData/GwBoatData.h index 218545d..8063a42 100644 --- a/lib/boatData/GwBoatData.h +++ b/lib/boatData/GwBoatData.h @@ -52,6 +52,7 @@ class GwBoatItemBase{ virtual void toJsonDoc(JsonDocument *doc, unsigned long minTime)=0; virtual size_t getJsonSize(){return JSON_OBJECT_SIZE(15);} virtual int getLastSource()=0; + virtual void refresh(unsigned long ts=0){uls(ts);} }; class GwBoatData; template class GwBoatItem : public GwBoatItemBase{ @@ -82,6 +83,19 @@ template class GwBoatItem : public GwBoatItemBase{ uls(now); return true; } + bool updateMax(T nv,int sourceId=-1){ + unsigned long now=millis(); + if (! isValid(now)){ + return update(nv,sourceId); + } + if (getData() < nv){ + data=nv; + lastUpdateSource=sourceId; + uls(now); + return true; + } + return false; + } T getData(){ return data; } @@ -173,6 +187,10 @@ public: data.update(info); return true; } + virtual void toJsonDoc(JsonDocument *doc, unsigned long minTime){ + data.houseKeeping(); + GwBoatItem::toJsonDoc(doc,minTime); + } }; @@ -216,8 +234,8 @@ class GwBoatData{ GWBOATDATA(double,BTW,4000,formatCourse) GWBOATDATA(double,WPLatitude,4000,formatLatitude) GWBOATDATA(double,WPLongitude,4000,formatLongitude) - GWBOATDATA(uint32_t,Log,0,mtr2nm) - GWBOATDATA(uint32_t,TripLog,0,mtr2nm) + GWBOATDATA(uint32_t,Log,16000,mtr2nm) + GWBOATDATA(uint32_t,TripLog,16000,mtr2nm) GWBOATDATA(uint32_t,DaysSince1970,4000,formatFixed0) GWBOATDATA(int16_t,Timezone,8000,formatFixed0) GWSPECBOATDATA(GwBoatDataSatList,SatInfo,GwSatInfoList::lifeTime,formatFixed0); diff --git a/lib/nmea0183ton2k/NMEA0183DataToN2K.cpp b/lib/nmea0183ton2k/NMEA0183DataToN2K.cpp index 1ef60ef..785b86f 100644 --- a/lib/nmea0183ton2k/NMEA0183DataToN2K.cpp +++ b/lib/nmea0183ton2k/NMEA0183DataToN2K.cpp @@ -247,11 +247,13 @@ private: n2kRef=N2kWind_Apparent; shouldSend=updateDouble(boatData->AWA,WindAngle,msg.sourceId) && updateDouble(boatData->AWS,WindSpeed,msg.sourceId); + if (WindSpeed != NMEA0183DoubleNA) boatData->MaxAws->updateMax(WindSpeed); break; case NMEA0183Wind_True: n2kRef=N2kWind_True_North; shouldSend=updateDouble(boatData->TWD,WindAngle,msg.sourceId) && updateDouble(boatData->TWS,WindSpeed,msg.sourceId); + if (WindSpeed != NMEA0183DoubleNA) boatData->MaxTws->updateMax(WindSpeed); break; default: LOG_DEBUG(GwLog::DEBUG,"unknown wind reference %d in %s",(int)Reference,msg.line); @@ -295,6 +297,7 @@ private: bool shouldSend = false; shouldSend = updateDouble(boatData->AWA, WindAngle, msg.sourceId) && updateDouble(boatData->AWS, WindSpeed, msg.sourceId); + if (WindSpeed != NMEA0183DoubleNA) boatData->MaxAws->updateMax(WindSpeed); if (shouldSend) { SetN2kWindSpeed(n2kMsg, 1, WindSpeed, WindAngle, N2kWind_Apparent); @@ -337,6 +340,7 @@ private: if (WindAngle != NMEA0183DoubleNA){ shouldSend = updateDouble(boatData->TWD, WindAngle, msg.sourceId) && updateDouble(boatData->TWS, WindSpeed, msg.sourceId); + if (WindSpeed != NMEA0183DoubleNA) boatData->MaxTws->updateMax(WindSpeed); } if (shouldSend) { diff --git a/lib/nmea2kto0183/N2kDataToNMEA0183.cpp b/lib/nmea2kto0183/N2kDataToNMEA0183.cpp index bb616d3..b6efb74 100644 --- a/lib/nmea2kto0183/N2kDataToNMEA0183.cpp +++ b/lib/nmea2kto0183/N2kDataToNMEA0183.cpp @@ -71,10 +71,7 @@ private: unsigned long now = millis(); if (!item->isValid(now)) return; - if (item->getData() > maxItem->getData() || !maxItem->isValid(now)) - { - maxItem->update(item->getData(),sourceId); - } + maxItem->updateMax(item->getData(),sourceId); } void updateDouble(GwBoatItem *item, double value) {