From 01ff478c29a7995e5976e189f2415865e8c550f2 Mon Sep 17 00:00:00 2001 From: Ulrich Meine <145987006+Scorgan01@users.noreply.github.com> Date: Sun, 31 May 2026 21:32:39 +0200 Subject: [PATCH] Extend history buffer for flexible data storage frequency --- lib/obp60task/OBPDataOperations.cpp | 33 +++++++++++++++++------------ lib/obp60task/OBPDataOperations.h | 5 ++++- lib/obp60task/OBPRingBuffer.h | 1 + lib/obp60task/OBPRingBuffer.tpp | 7 ++++++ 4 files changed, 32 insertions(+), 14 deletions(-) diff --git a/lib/obp60task/OBPDataOperations.cpp b/lib/obp60task/OBPDataOperations.cpp index 1ed7662..3834fba 100644 --- a/lib/obp60task/OBPDataOperations.cpp +++ b/lib/obp60task/OBPDataOperations.cpp @@ -228,6 +228,7 @@ void HstryBuf::init(const String& format, int updFreq, int mltplr, double minVal hstryBuf.setMetaData(boatDataName, format, updFreq, mltplr, minVal, maxVal); hstryMin = minVal; hstryMax = maxVal; + bufUpdateTime = 0; if (!boatValue->valid) { boatValue->setFormat(format); boatValue->value = std::numeric_limits::max(); // mark current value invalid @@ -244,19 +245,24 @@ void HstryBuf::add(double value) void HstryBuf::handle(bool useSimuData, CommonData& common) { - std::unique_ptr tmpBVal; // Temp variable to get formatted and converted data value from OBP60Formatter + if (millis() >= (bufUpdateTime + hstryBuf.getUpdFreq())) { + bufUpdateTime = millis(); + LOG_DEBUG(GwLog::DEBUG, "HstryBuf::handle: name: %s, frequency: %d, bufUpdateTime: %d, value: %.3f", hstryBuf.getName(), hstryBuf.getUpdFreq(), bufUpdateTime, boatValue->value); - if (boatValue->valid) { - add(boatValue->value); - } else if (useSimuData) { // add simulated value to history buffer - tmpBVal = std::unique_ptr(new GwApi::BoatValue(boatDataName)); // create temporary boat value for retrieval of simulation value - tmpBVal->setFormat(boatValue->getFormat()); - tmpBVal->value = boatValue->value; - tmpBVal->valid = boatValue->valid; - double simSIValue = formatValue(tmpBVal.get(), common).value; // simulated value is generated at ; here: retreive SI value - add(simSIValue); - } else { - // here we will add invalid (DBL_MAX) value; this will mark periods of missing data in buffer together with a timestamp + if (boatValue->valid) { + add(boatValue->value); + + } else if (useSimuData) { // add simulated value to history buffer + std::unique_ptr tmpBVal; // Temp variable to get formatted and converted data value from OBP60Formatter + tmpBVal = std::unique_ptr(new GwApi::BoatValue(boatDataName)); // create temporary boat value for retrieval of simulation value + tmpBVal->setFormat(boatValue->getFormat()); + tmpBVal->value = boatValue->value; + tmpBVal->valid = boatValue->valid; + double simSIValue = formatValue(tmpBVal.get(), common).value; // simulated value is generated at ; here: retreive SI value + add(simSIValue); + } else { + // here we will add invalid (DBL_MAX) value; this will mark periods of missing data in buffer together with a timestamp + } } } // --- End Class HstryBuf --------------- @@ -287,7 +293,8 @@ void HstryBuffers::addBuffer(const String& name) hstryBuffers[name] = std::unique_ptr(new HstryBuf(name, size, boatValueList, logger)); hstryBuffers[name]->init(valueFormat, hstryUpdFreq, mltplr, bufferMinVal, bufferMaxVal); - LOG_DEBUG(GwLog::DEBUG, "HstryBuffers: new buffer added: name: %s, format: %s, multiplier: %d, min value: %.2f, max value: %.2f", name, valueFormat, mltplr, bufferMinVal, bufferMaxVal); + LOG_DEBUG(GwLog::DEBUG, "HstryBuffers: new buffer added: name: %s, format: %s, frequency: %d, multiplier: %d, min value: %.2f, max value: %.2f", name, valueFormat, hstryUpdFreq, + mltplr, bufferMinVal, bufferMaxVal); } // Handle all registered history buffers diff --git a/lib/obp60task/OBPDataOperations.h b/lib/obp60task/OBPDataOperations.h index 5631483..ee44f0b 100644 --- a/lib/obp60task/OBPDataOperations.h +++ b/lib/obp60task/OBPDataOperations.h @@ -39,6 +39,7 @@ private: String boatDataName; double hstryMin; double hstryMax; + unsigned long bufUpdateTime; GwApi::BoatValue* boatValue; GwLog* logger; @@ -62,17 +63,19 @@ private: struct HistoryParams { int hstryUpdFreq; // update frequency of history buffer (documentation only) int mltplr; // specifies actual value precision being storable: - // [10000: 0 - 6.5535 | 1000: 0 - 65.535 | 100: 0 - 650.35 | 10: 0 - 6503.5 + // [10000: 0 - 6.5535 | 1000: 0 - 65.535 | 100: 0 - 655.35 | 10: 0 - 6553.5 | 1: 0 - 65535] double bufferMinVal; // minimum valid data value double bufferMaxVal; // maximum valid data value String format; // format of data type }; // Define buffer parameters for supported boat data type + // Structure: name, frequency, multiplier, minVal, maxVal, format std::map bufferParams = { { "AWA", { 1000, 10000, 0.0, M_TWOPI, "formatWind" } }, { "AWD", { 1000, 10000, 0.0, M_TWOPI, "formatCourse" } }, { "AWS", { 1000, 1000, 0.0, 65.0, "formatKnots" } }, + { "BARO", {60000, 10, 0.0, 6553, "formatXdr:P:B"}}, { "COG", { 1000, 10000, 0.0, M_TWOPI, "formatCourse" } }, { "DBS", { 1000, 100, 0.0, 650.0, "formatDepth" } }, { "DBT", { 1000, 100, 0.0, 650.0, "formatDepth" } }, diff --git a/lib/obp60task/OBPRingBuffer.h b/lib/obp60task/OBPRingBuffer.h index 970245e..b8047ab 100644 --- a/lib/obp60task/OBPRingBuffer.h +++ b/lib/obp60task/OBPRingBuffer.h @@ -68,6 +68,7 @@ public: bool getMetaData(String& name, String& format); String getName() const; // Get buffer name String getFormat() const; // Get buffer data format + int getUpdFreq() const; // Get buffer update frequency void add(const double& value); // Add a new value to buffer double get(size_t index) const; // Get value at specific position (0-based index from oldest to newest) double getFirst() const; // Get the first (oldest) value in buffer diff --git a/lib/obp60task/OBPRingBuffer.tpp b/lib/obp60task/OBPRingBuffer.tpp index 7d73f46..a1fdf06 100644 --- a/lib/obp60task/OBPRingBuffer.tpp +++ b/lib/obp60task/OBPRingBuffer.tpp @@ -106,6 +106,13 @@ String RingBuffer::getFormat() const return dataFmt; } +// Get buffer update frequency +template +int RingBuffer::getUpdFreq() const +{ + return updFreq; +} + // Add a new value to buffer template void RingBuffer::add(const double& value)