1
0
mirror of https://github.com/thooge/esp32-nmea2000-obp60.git synced 2026-01-26 08:13:05 +01:00

General history buffers working; fine tuning required

This commit is contained in:
Ulrich Meine
2025-12-20 22:42:42 +01:00
parent d655674529
commit 41a8e7d078
5 changed files with 153 additions and 121 deletions

View File

@@ -2,36 +2,66 @@
#pragma once
#include "OBPRingBuffer.h"
#include "obp60task.h"
#include <vector>
#include <memory>
#include <map>
#include <memory>
#include <limits>
#include <cmath>
class HstryBuf {
private:
GwLog *logger;
RingBuffer<uint16_t> hstry; // Circular buffer to store history values
RingBuffer<uint16_t> hstryBuf; // Circular buffer to store history values
String boatDataName;
double hstryMin;
double hstryMax;
GwApi::BoatValue *boatValue;
GwLog *logger;
friend class HstryManager;
void handleHistory(bool useSimuData);
friend class HstryBuffers;
public:
HstryBuf(const String& name, int size, GwLog* log, BoatValueList* boatValues);
HstryBuf(const String& name, int size, BoatValueList* boatValues, GwLog* log);
void init(const String& format, int updFreq, int mltplr, double minVal, double maxVal);
void add(double value);
void handle(bool useSimuData);
};
class HstryManager {
class HstryBuffers {
private:
std::map<String, std::unique_ptr<HstryBuf>> hstryBufs;
// boat values for true wind calculation
GwApi::BoatValue *awaBVal, *hdtBVal, *hdmBVal, *varBVal, *cogBVal, *sogBVal, *awdBVal;
std::map<String, std::unique_ptr<HstryBuf>> hstryBuffers;
int size; // size of all history buffers
BoatValueList* boatValueList;
GwLog* logger;
GwApi::BoatValue *awaBVal, *hdtBVal, *hdmBVal, *varBVal, *cogBVal, *sogBVal, *awdBVal; // boat values for true wind calculation
struct HistoryParams {
int hstryUpdFreq;
int mltplr;
double bufferMinVal;
double bufferMaxVal;
String format;
};
// Define buffer parameters for each boat data type
std::map<String, HistoryParams> bufferParams = {
{"AWA", {1000, 10000, -M_PI, M_PI, "formatWind"}},
{"AWD", {1000, 10000, 0.0, M_TWOPI, "formatCourse"}},
{"AWS", {1000, 1000, 0.0, 65.0, "formatKnots"}},
{"DBS", {1000, 100, 0.0, 650, "formatDepth"}},
{"DBT", {1000, 100, 0.0, 650, "formatDepth"}},
{"DPT", {1000, 100, 0.0, 650, "formatDepth"}},
{"HDT", {1000, 10000, 0.0, M_TWOPI, "formatCourse"}},
{"HDM", {1000, 10000, 0.0, M_TWOPI, "formatCourse"}},
{"TWA", {1000, 10000, -M_PI, M_PI, "formatWind"}},
{"TWD", {1000, 10000, 0.0, M_TWOPI, "formatCourse"}},
{"TWS", {1000, 1000, 0.0, 65.0, "formatKnots"}},
{"SOG", {1000, 1000, 0.0, 65.0, "formatKnots"}},
{"STW", {1000, 1000, 0.0, 65.0, "formatKnots"}},
{"WTemp", {1000, 100, 0.0, 650.0, "kelvinToC"}}
};
public:
HstryManager(int size, GwLog* log, BoatValueList* boatValues);
HstryBuffers(int size, BoatValueList* boatValues, GwLog* log);
void addBuffer(const String& name);
void handleHstryBufs(bool useSimuData);
RingBuffer<uint16_t>* getBuffer(const String& name);
};
@@ -41,9 +71,11 @@ private:
GwApi::BoatValue *twdBVal, *twsBVal, *twaBVal;
GwApi::BoatValue *awaBVal, *awsBVal, *cogBVal, *stwBVal, *sogBVal, *hdtBVal, *hdmBVal, *varBVal;
static constexpr double DBL_MAX = std::numeric_limits<double>::max();
GwLog* logger;
public:
WindUtils(BoatValueList* boatValues){
WindUtils(BoatValueList* boatValues, GwLog* log)
: logger(log) {
twdBVal = boatValues->findValueOrCreate("TWD");
twsBVal = boatValues->findValueOrCreate("TWS");
twaBVal = boatValues->findValueOrCreate("TWA");
@@ -73,5 +105,6 @@ public:
bool calcTrueWind(const double* awaVal, const double* awsVal,
const double* cogVal, const double* stwVal, const double* sogVal, const double* hdtVal,
const double* hdmVal, const double* varVal, double* twdVal, double* twsVal, double* twaVal);
bool addTrueWind(GwApi* api, BoatValueList* boatValues, GwLog *log);
// bool addTrueWind(GwApi* api, BoatValueList* boatValues, GwLog *log);
bool addTrueWind();
};