mirror of
https://github.com/thooge/esp32-nmea2000-obp60.git
synced 2026-01-26 08:13:05 +01:00
Initial change to history buffers taking any boat value
This commit is contained in:
@@ -1,46 +1,81 @@
|
|||||||
#include "OBPDataOperations.h"
|
#include "OBPDataOperations.h"
|
||||||
#include "BoatDataCalibration.h" // Functions lib for data instance calibration
|
#include "BoatDataCalibration.h" // Functions lib for data instance calibration
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <vector>
|
||||||
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
// --- Class HstryBuf ---------------
|
// --- Class HstryBuf ---------------
|
||||||
|
|
||||||
// Init history buffers for selected boat data
|
HstryBuf::HstryBuf(const String& name, int size, GwLog* log, BoatValueList* boatValues)
|
||||||
void HstryBuf::init(BoatValueList* boatValues, GwLog *log) {
|
: logger(log), boatDataName(name) {
|
||||||
|
hstry.resize(size);
|
||||||
|
boatValue = boatValues->findValueOrCreate(name);
|
||||||
|
}
|
||||||
|
|
||||||
logger = log;
|
void HstryBuf::init(const String& format, int updFreq, int mltplr, double minVal, double maxVal) {
|
||||||
|
hstry.setMetaData(boatDataName, format, updFreq, mltplr, minVal, maxVal);
|
||||||
|
hstryMin = minVal;
|
||||||
|
hstryMax = maxVal;
|
||||||
|
if (!boatValue->valid) {
|
||||||
|
boatValue->setFormat(format);
|
||||||
|
boatValue->value = std::numeric_limits<double>::max();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void HstryBuf::add(double value) {
|
||||||
|
if (value >= hstryMin && value <= hstryMax) {
|
||||||
|
hstry.add(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void HstryBuf::handle(bool useSimuData) {
|
||||||
|
GwApi::BoatValue *calBVal;
|
||||||
|
|
||||||
|
if (boatValue->valid) {
|
||||||
|
calBVal = new GwApi::BoatValue(boatDataName.c_str());
|
||||||
|
calBVal->setFormat(boatValue->getFormat());
|
||||||
|
calBVal->value = boatValue->value;
|
||||||
|
calBVal->valid = boatValue->valid;
|
||||||
|
calibrationData.calibrateInstance(calBVal, logger);
|
||||||
|
add(calBVal->value);
|
||||||
|
delete calBVal;
|
||||||
|
calBVal = nullptr;
|
||||||
|
} else if (useSimuData) {
|
||||||
|
double simValue = hstry.getLast();
|
||||||
|
if (boatDataName == "TWD" || boatDataName == "AWD") {
|
||||||
|
simValue += static_cast<double>(random(-349, 349) / 1000.0);
|
||||||
|
simValue = WindUtils::to2PI(simValue);
|
||||||
|
} else if (boatDataName == "TWS" || boatDataName == "AWS") {
|
||||||
|
simValue += static_cast<double>(random(-5000, 5000) / 1000.0);
|
||||||
|
simValue = constrain(simValue, 0, 40);
|
||||||
|
}
|
||||||
|
add(simValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Class HstryManager ---------------
|
||||||
|
HstryManager::HstryManager(int size, GwLog* log, BoatValueList* boatValues) {
|
||||||
|
// Create history buffers for each boat data type
|
||||||
|
hstryBufs["TWD"] = std::unique_ptr<HstryBuf>(new HstryBuf("TWD", size, log, boatValues));
|
||||||
|
hstryBufs["TWS"] = std::unique_ptr<HstryBuf>(new HstryBuf("TWS", size, log, boatValues));
|
||||||
|
hstryBufs["AWD"] = std::unique_ptr<HstryBuf>(new HstryBuf("AWD", size, log, boatValues));
|
||||||
|
hstryBufs["AWS"] = std::unique_ptr<HstryBuf>(new HstryBuf("AWS", size, log, boatValues));
|
||||||
|
|
||||||
|
// Initialize metadata for each buffer
|
||||||
int hstryUpdFreq = 1000; // Update frequency for history buffers in ms
|
int hstryUpdFreq = 1000; // Update frequency for history buffers in ms
|
||||||
int mltplr = 1000; // Multiplier which transforms original <double> value into buffer type format
|
int mltplr = 1000; // Multiplier which transforms original <double> value into buffer type format
|
||||||
double hstryMinVal = 0; // Minimum value for these history buffers
|
double hstryMinVal = 0; // Minimum value for these history buffers
|
||||||
twdHstryMax = 2 * M_PI; // Max value for wind direction (TWD, AWD) in rad [0...2*PI]
|
double courseMax = 2 * M_PI;
|
||||||
twsHstryMax = 65; // Max value for wind speed (TWS, AWS) in m/s [0..65] (limit due to type capacity of buffer - shifted by <mltplr>)
|
double speedMax = 65;
|
||||||
awdHstryMax = twdHstryMax;
|
|
||||||
awsHstryMax = twsHstryMax;
|
|
||||||
twdHstryMin = hstryMinVal;
|
|
||||||
twsHstryMin = hstryMinVal;
|
|
||||||
awdHstryMin = hstryMinVal;
|
|
||||||
awsHstryMin = hstryMinVal;
|
|
||||||
const double DBL_MAX = std::numeric_limits<double>::max();
|
|
||||||
|
|
||||||
// Initialize history buffers with meta data
|
|
||||||
mltplr = 10000; // Store 4 decimals for course data
|
mltplr = 10000; // Store 4 decimals for course data
|
||||||
hstryBufList.twdHstry->setMetaData("TWD", "formatCourse", hstryUpdFreq, mltplr, hstryMinVal, twdHstryMax);
|
hstryBufs["TWD"]->init("formatCourse", hstryUpdFreq, mltplr, hstryMinVal, courseMax);
|
||||||
hstryBufList.awdHstry->setMetaData("AWD", "formatCourse", hstryUpdFreq, mltplr, hstryMinVal, twdHstryMax);
|
hstryBufs["AWD"]->init("formatCourse", hstryUpdFreq, mltplr, hstryMinVal, courseMax);
|
||||||
|
|
||||||
mltplr = 1000; // Store 3 decimals for windspeed data
|
mltplr = 1000; // Store 3 decimals for windspeed data
|
||||||
hstryBufList.twsHstry->setMetaData("TWS", "formatKnots", hstryUpdFreq, mltplr, hstryMinVal, twsHstryMax);
|
hstryBufs["TWS"]->init("formatKnots", hstryUpdFreq, mltplr, hstryMinVal, speedMax);
|
||||||
hstryBufList.awsHstry->setMetaData("AWS", "formatKnots", hstryUpdFreq, mltplr, hstryMinVal, twsHstryMax);
|
hstryBufs["AWS"]->init("formatKnots", hstryUpdFreq, mltplr, hstryMinVal, speedMax);
|
||||||
|
|
||||||
// create boat values for history data types, if they don't exist yet
|
|
||||||
twdBVal = boatValues->findValueOrCreate(hstryBufList.twdHstry->getName());
|
|
||||||
twsBVal = boatValues->findValueOrCreate(hstryBufList.twsHstry->getName());
|
|
||||||
twaBVal = boatValues->findValueOrCreate("TWA");
|
|
||||||
awdBVal = boatValues->findValueOrCreate(hstryBufList.awdHstry->getName());
|
|
||||||
awsBVal = boatValues->findValueOrCreate(hstryBufList.awsHstry->getName());
|
|
||||||
|
|
||||||
if (!awdBVal->valid) { // AWD usually does not exist
|
|
||||||
awdBVal->setFormat(hstryBufList.awdHstry->getFormat());
|
|
||||||
awdBVal->value = DBL_MAX;
|
|
||||||
}
|
|
||||||
|
|
||||||
// collect boat values for true wind calculation
|
// collect boat values for true wind calculation
|
||||||
awaBVal = boatValues->findValueOrCreate("AWA");
|
awaBVal = boatValues->findValueOrCreate("AWA");
|
||||||
@@ -49,106 +84,58 @@ void HstryBuf::init(BoatValueList* boatValues, GwLog *log) {
|
|||||||
varBVal = boatValues->findValueOrCreate("VAR");
|
varBVal = boatValues->findValueOrCreate("VAR");
|
||||||
cogBVal = boatValues->findValueOrCreate("COG");
|
cogBVal = boatValues->findValueOrCreate("COG");
|
||||||
sogBVal = boatValues->findValueOrCreate("SOG");
|
sogBVal = boatValues->findValueOrCreate("SOG");
|
||||||
|
awdBVal = boatValues->findValueOrCreate("AWD");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle history buffers for TWD, TWS, AWD, AWS
|
// Handle history buffers for TWD, TWS, AWD, AWS
|
||||||
//void HstryBuf::handleHstryBuf(GwApi* api, BoatValueList* boatValues, bool useSimuData) {
|
void HstryManager::handleHstryBufs(bool useSimuData) {
|
||||||
void HstryBuf::handleHstryBuf(bool useSimuData) {
|
|
||||||
|
|
||||||
static double twd, tws, awd, aws, hdt = 20; //initial value only relevant if we use simulation data
|
static double hdt = 20; //initial value only relevant if we use simulation data
|
||||||
GwApi::BoatValue *calBVal; // temp variable just for data calibration -> we don't want to calibrate the original data here
|
GwApi::BoatValue *calBVal; // temp variable just for data calibration -> we don't want to calibrate the original data here
|
||||||
|
|
||||||
LOG_DEBUG(GwLog::DEBUG,"obp60task handleHstryBuf: TWD_isValid? %d, twdBVal: %.1f, twaBVal: %.1f, twsBVal: %.1f", twdBVal->valid, twdBVal->value * RAD_TO_DEG,
|
// Handle all registered history buffers
|
||||||
twaBVal->value * RAD_TO_DEG, twsBVal->value * 3.6 / 1.852);
|
for (auto& pair : hstryBufs) {
|
||||||
|
auto& buf = pair.second;
|
||||||
if (twdBVal->valid) {
|
buf->handle(useSimuData);
|
||||||
// if (!useSimuData) {
|
|
||||||
calBVal = new GwApi::BoatValue("TWD"); // temporary solution for calibration of history buffer values
|
|
||||||
calBVal->setFormat(twdBVal->getFormat());
|
|
||||||
calBVal->value = twdBVal->value;
|
|
||||||
calBVal->valid = twdBVal->valid;
|
|
||||||
calibrationData.calibrateInstance(calBVal, logger); // Check if boat data value is to be calibrated
|
|
||||||
twd = calBVal->value;
|
|
||||||
if (twd >= twdHstryMin && twd <= twdHstryMax) {
|
|
||||||
hstryBufList.twdHstry->add(twd);
|
|
||||||
LOG_DEBUG(GwLog::DEBUG,"obp60task handleHstryBuf: calBVal.value %.2f, twd: %.2f, twdHstryMin: %.1f, twdHstryMax: %.2f", calBVal->value, twd, twdHstryMin, twdHstryMax);
|
|
||||||
}
|
|
||||||
delete calBVal;
|
|
||||||
calBVal = nullptr;
|
|
||||||
} else if (useSimuData) {
|
|
||||||
// } else {
|
|
||||||
twd += random(-20, 20);
|
|
||||||
twd += static_cast<double>(random(-349, 349) / 1000.0); // add up to +/- 20 degree in RAD
|
|
||||||
twd = WindUtils::to2PI(twd);
|
|
||||||
hstryBufList.twdHstry->add(twd);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (twsBVal->valid) {
|
|
||||||
calBVal = new GwApi::BoatValue("TWS"); // temporary solution for calibration of history buffer values
|
|
||||||
calBVal->setFormat(twsBVal->getFormat());
|
|
||||||
calBVal->value = twsBVal->value;
|
|
||||||
calBVal->valid = twsBVal->valid;
|
|
||||||
calibrationData.calibrateInstance(calBVal, logger); // Check if boat data value is to be calibrated
|
|
||||||
tws = calBVal->value;
|
|
||||||
if (tws >= twsHstryMin && tws <= twsHstryMax) {
|
|
||||||
hstryBufList.twsHstry->add(tws);
|
|
||||||
}
|
|
||||||
delete calBVal;
|
|
||||||
calBVal = nullptr;
|
|
||||||
} else if (useSimuData) {
|
|
||||||
// tws += random(-5000, 5000); // TWS value in m/s; expands to 3 decimals
|
|
||||||
tws += static_cast<double>(random(-5000, 5000) / 1000.0); // add up to +/- 5 m/s TWS speed
|
|
||||||
tws = constrain(tws, 0, 40); // Limit TWS to [0..40] m/s
|
|
||||||
hstryBufList.twsHstry->add(tws);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Special handling for AWD which is calculated
|
||||||
if (awaBVal->valid) {
|
if (awaBVal->valid) {
|
||||||
if (hdtBVal->valid) {
|
if (hdtBVal->valid) {
|
||||||
hdt = hdtBVal->value; // Use HDT if available
|
hdt = hdtBVal->value; // Use HDT if available
|
||||||
} else {
|
} else {
|
||||||
hdt = WindUtils::calcHDT(&hdmBVal->value, &varBVal->value, &cogBVal->value, &sogBVal->value);
|
hdt = WindUtils::calcHDT(&hdmBVal->value, &varBVal->value, &cogBVal->value, &sogBVal->value);
|
||||||
}
|
}
|
||||||
|
double awd;
|
||||||
awd = awaBVal->value + hdt;
|
awd = awaBVal->value + hdt;
|
||||||
awd = WindUtils::to2PI(awd);
|
awd = WindUtils::to2PI(awd);
|
||||||
calBVal = new GwApi::BoatValue("AWD"); // temporary solution for calibration of history buffer values
|
calBVal = new GwApi::BoatValue("AWD"); // temporary solution for calibration of history buffer values
|
||||||
calBVal->value = awd;
|
calBVal->value = awd;
|
||||||
calBVal->setFormat(awdBVal->getFormat());
|
calBVal->setFormat(awdBVal->getFormat());
|
||||||
calBVal->valid = true;
|
calBVal->valid = true;
|
||||||
calibrationData.calibrateInstance(calBVal, logger); // Check if boat data value is to be calibrated
|
// We don't have a logger here, so we pass nullptr. This should be improved.
|
||||||
|
calibrationData.calibrateInstance(calBVal, nullptr); // Check if boat data value is to be calibrated
|
||||||
awdBVal->value = calBVal->value;
|
awdBVal->value = calBVal->value;
|
||||||
awdBVal->valid = true;
|
awdBVal->valid = true;
|
||||||
awd = calBVal->value;
|
// Find the AWD buffer and add the value.
|
||||||
if (awd >= awdHstryMin && awd <= awdHstryMax) {
|
auto it = hstryBufs.find("AWD");
|
||||||
hstryBufList.awdHstry->add(awd);
|
if (it != hstryBufs.end()) {
|
||||||
|
it->second->add(calBVal->value);
|
||||||
}
|
}
|
||||||
delete calBVal;
|
|
||||||
calBVal = nullptr;
|
|
||||||
} else if (useSimuData) {
|
|
||||||
awd += static_cast<double>(random(-349, 349) / 1000.0); // add up to +/- 20 degree in RAD
|
|
||||||
awd = WindUtils::to2PI(awd);
|
|
||||||
hstryBufList.awdHstry->add(awd);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (awsBVal->valid) {
|
|
||||||
calBVal = new GwApi::BoatValue("AWS"); // temporary solution for calibration of history buffer values
|
|
||||||
calBVal->setFormat(awsBVal->getFormat());
|
|
||||||
calBVal->value = awsBVal->value;
|
|
||||||
calBVal->valid = awsBVal->valid;
|
|
||||||
calibrationData.calibrateInstance(calBVal, logger); // Check if boat data value is to be calibrated
|
|
||||||
aws = calBVal->value;
|
|
||||||
if (aws >= awsHstryMin && aws <= awsHstryMax) {
|
|
||||||
hstryBufList.awsHstry->add(aws);
|
|
||||||
}
|
|
||||||
delete calBVal;
|
delete calBVal;
|
||||||
calBVal = nullptr;
|
calBVal = nullptr;
|
||||||
} else if (useSimuData) {
|
} else if (useSimuData) {
|
||||||
aws += static_cast<double>(random(-5000, 5000) / 1000.0); // add up to +/- 5 m/s TWS speed
|
// Simulation for AWD is handled inside HstryBuf::handle
|
||||||
aws = constrain(aws, 0, 40); // Limit TWS to [0..40] m/s
|
|
||||||
hstryBufList.awsHstry->add(aws);
|
|
||||||
}
|
}
|
||||||
LOG_DEBUG(GwLog::DEBUG,"obp60task handleHstryBuf-End: Buffer twdHstry: %.3f, twsHstry: %.3f, awdHstry: %.3f, awsHstry: %.3f", hstryBufList.twdHstry->getLast(), hstryBufList.twsHstry->getLast(),
|
}
|
||||||
hstryBufList.awdHstry->getLast(),hstryBufList.awsHstry->getLast());
|
|
||||||
|
RingBuffer<uint16_t>* HstryManager::getBuffer(const String& name) {
|
||||||
|
auto it = hstryBufs.find(name);
|
||||||
|
if (it != hstryBufs.end()) {
|
||||||
|
return &it->second->hstry;
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
// --- Class HstryBuf ---------------
|
// --- Class HstryBuf ---------------
|
||||||
|
|
||||||
|
|||||||
@@ -2,51 +2,38 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "OBPRingBuffer.h"
|
#include "OBPRingBuffer.h"
|
||||||
#include "obp60task.h"
|
#include "obp60task.h"
|
||||||
|
#include <vector>
|
||||||
typedef struct {
|
#include <memory>
|
||||||
RingBuffer<uint16_t>* twdHstry;
|
#include <map>
|
||||||
RingBuffer<uint16_t>* twsHstry;
|
|
||||||
RingBuffer<uint16_t>* awdHstry;
|
|
||||||
RingBuffer<uint16_t>* awsHstry;
|
|
||||||
} tBoatHstryData; // Holds pointers to all history buffers for boat data
|
|
||||||
|
|
||||||
class HstryBuf {
|
class HstryBuf {
|
||||||
private:
|
private:
|
||||||
GwLog *logger;
|
GwLog *logger;
|
||||||
|
RingBuffer<uint16_t> hstry; // Circular buffer to store history values
|
||||||
|
String boatDataName;
|
||||||
|
double hstryMin;
|
||||||
|
double hstryMax;
|
||||||
|
GwApi::BoatValue *boatValue;
|
||||||
|
|
||||||
RingBuffer<uint16_t> twdHstry; // Circular buffer to store true wind direction values
|
friend class HstryManager;
|
||||||
RingBuffer<uint16_t> twsHstry; // Circular buffer to store true wind speed values (TWS)
|
void handleHistory(bool useSimuData);
|
||||||
RingBuffer<uint16_t> awdHstry; // Circular buffer to store apparent wind direction values
|
|
||||||
RingBuffer<uint16_t> awsHstry; // Circular buffer to store apparent xwind speed values (AWS)
|
|
||||||
double twdHstryMin; // Min value for wind direction (TWD) in history buffer
|
|
||||||
double twdHstryMax; // Max value for wind direction (TWD) in history buffer
|
|
||||||
double twsHstryMin;
|
|
||||||
double twsHstryMax;
|
|
||||||
double awdHstryMin;
|
|
||||||
double awdHstryMax;
|
|
||||||
double awsHstryMin;
|
|
||||||
double awsHstryMax;
|
|
||||||
|
|
||||||
// boat values for buffers and for true wind calculation
|
|
||||||
GwApi::BoatValue *twdBVal, *twsBVal, *twaBVal, *awdBVal, *awsBVal;
|
|
||||||
GwApi::BoatValue *awaBVal, *hdtBVal, *hdmBVal, *varBVal, *cogBVal, *sogBVal;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
tBoatHstryData hstryBufList;
|
HstryBuf(const String& name, int size, GwLog* log, BoatValueList* boatValues);
|
||||||
|
void init(const String& format, int updFreq, int mltplr, double minVal, double maxVal);
|
||||||
|
void add(double value);
|
||||||
|
void handle(bool useSimuData);
|
||||||
|
};
|
||||||
|
|
||||||
HstryBuf(){
|
class HstryManager {
|
||||||
hstryBufList = {&twdHstry, &twsHstry, &awdHstry, &awsHstry}; // Generate history buffers of zero size
|
private:
|
||||||
};
|
std::map<String, std::unique_ptr<HstryBuf>> hstryBufs;
|
||||||
|
// boat values for true wind calculation
|
||||||
HstryBuf(int size) {
|
GwApi::BoatValue *awaBVal, *hdtBVal, *hdmBVal, *varBVal, *cogBVal, *sogBVal, *awdBVal;
|
||||||
hstryBufList = {&twdHstry, &twsHstry, &awdHstry, &awsHstry};
|
public:
|
||||||
hstryBufList.twdHstry->resize(size); // store <size> xWD values for <size>/60 minutes history
|
HstryManager(int size, GwLog* log, BoatValueList* boatValues);
|
||||||
hstryBufList.twsHstry->resize(size);
|
void handleHstryBufs(bool useSimuData);
|
||||||
hstryBufList.awdHstry->resize(size);
|
RingBuffer<uint16_t>* getBuffer(const String& name);
|
||||||
hstryBufList.awsHstry->resize(size);
|
|
||||||
};
|
|
||||||
void init(BoatValueList* boatValues, GwLog *log);
|
|
||||||
void handleHstryBuf(bool useSimuData);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class WindUtils {
|
class WindUtils {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "Pagedata.h"
|
#include "Pagedata.h"
|
||||||
#include "OBP60Extensions.h"
|
#include "OBP60Extensions.h"
|
||||||
|
#include "OBPDataOperations.h"
|
||||||
#include "OBPcharts.h"
|
#include "OBPcharts.h"
|
||||||
|
|
||||||
// ****************************************************************
|
// ****************************************************************
|
||||||
@@ -164,11 +165,8 @@ public:
|
|||||||
if (!twdFlChart) { // Create true wind charts if they don't exist
|
if (!twdFlChart) { // Create true wind charts if they don't exist
|
||||||
|
|
||||||
LOG_DEBUG(GwLog::DEBUG, "PageWindPlot: Creating true wind charts");
|
LOG_DEBUG(GwLog::DEBUG, "PageWindPlot: Creating true wind charts");
|
||||||
auto* twdHstry = pageData.boatHstry->hstryBufList.twdHstry;
|
auto* twdHstry = pageData.hstryManager->getBuffer("TWD");
|
||||||
auto* twsHstry = pageData.boatHstry->hstryBufList.twsHstry;
|
auto* twsHstry = pageData.hstryManager->getBuffer("TWS");
|
||||||
// LOG_DEBUG(GwLog::DEBUG,"History Buffer addresses PageWindPlot: twdBuf: %p, twsBuf: %p", (void*)pageData.boatHstry->hstryBufList.twdHstry,
|
|
||||||
// (void*)pageData.boatHstry->hstryBufList.twsHstry);
|
|
||||||
|
|
||||||
twdFlChart = std::unique_ptr<Chart<uint16_t>>(new Chart<uint16_t>(*twdHstry, 1, 0, dfltRngWd, *commonData, useSimuData));
|
twdFlChart = std::unique_ptr<Chart<uint16_t>>(new Chart<uint16_t>(*twdHstry, 1, 0, dfltRngWd, *commonData, useSimuData));
|
||||||
twsFlChart = std::unique_ptr<Chart<uint16_t>>(new Chart<uint16_t>(*twsHstry, 0, 0, dfltRngWs, *commonData, useSimuData));
|
twsFlChart = std::unique_ptr<Chart<uint16_t>>(new Chart<uint16_t>(*twsHstry, 0, 0, dfltRngWs, *commonData, useSimuData));
|
||||||
twdHfChart = std::unique_ptr<Chart<uint16_t>>(new Chart<uint16_t>(*twdHstry, 1, 1, dfltRngWd, *commonData, useSimuData));
|
twdHfChart = std::unique_ptr<Chart<uint16_t>>(new Chart<uint16_t>(*twdHstry, 1, 1, dfltRngWd, *commonData, useSimuData));
|
||||||
@@ -180,8 +178,8 @@ public:
|
|||||||
|
|
||||||
if (!awdFlChart) { // Create apparent wind charts if they don't exist
|
if (!awdFlChart) { // Create apparent wind charts if they don't exist
|
||||||
LOG_DEBUG(GwLog::DEBUG, "PageWindPlot: Creating apparent wind charts");
|
LOG_DEBUG(GwLog::DEBUG, "PageWindPlot: Creating apparent wind charts");
|
||||||
auto* awdHstry = pageData.boatHstry->hstryBufList.awdHstry;
|
auto* awdHstry = pageData.hstryManager->getBuffer("AWD");
|
||||||
auto* awsHstry = pageData.boatHstry->hstryBufList.awsHstry;
|
auto* awsHstry = pageData.hstryManager->getBuffer("AWS");
|
||||||
|
|
||||||
awdFlChart = std::unique_ptr<Chart<uint16_t>>(new Chart<uint16_t>(*awdHstry, 1, 0, dfltRngWd, *commonData, useSimuData));
|
awdFlChart = std::unique_ptr<Chart<uint16_t>>(new Chart<uint16_t>(*awdHstry, 1, 0, dfltRngWd, *commonData, useSimuData));
|
||||||
awsFlChart = std::unique_ptr<Chart<uint16_t>>(new Chart<uint16_t>(*awsHstry, 0, 0, dfltRngWs, *commonData, useSimuData));
|
awsFlChart = std::unique_ptr<Chart<uint16_t>>(new Chart<uint16_t>(*awsHstry, 0, 0, dfltRngWs, *commonData, useSimuData));
|
||||||
@@ -191,15 +189,15 @@ public:
|
|||||||
|
|
||||||
// Switch active charts based on showTruW
|
// Switch active charts based on showTruW
|
||||||
if (showTruW) {
|
if (showTruW) {
|
||||||
wdHstry = pageData.boatHstry->hstryBufList.twdHstry;
|
wdHstry = pageData.hstryManager->getBuffer("TWD");
|
||||||
wsHstry = pageData.boatHstry->hstryBufList.twsHstry;
|
wsHstry = pageData.hstryManager->getBuffer("TWS");
|
||||||
wdFlChart = twdFlChart.get();
|
wdFlChart = twdFlChart.get();
|
||||||
wsFlChart = twsFlChart.get();
|
wsFlChart = twsFlChart.get();
|
||||||
wdHfChart = twdHfChart.get();
|
wdHfChart = twdHfChart.get();
|
||||||
wsHfChart = twsHfChart.get();
|
wsHfChart = twsHfChart.get();
|
||||||
} else {
|
} else {
|
||||||
wdHstry = pageData.boatHstry->hstryBufList.awdHstry;
|
wdHstry = pageData.hstryManager->getBuffer("AWD");
|
||||||
wsHstry = pageData.boatHstry->hstryBufList.awsHstry;
|
wsHstry = pageData.hstryManager->getBuffer("AWS");
|
||||||
wdFlChart = awdFlChart.get();
|
wdFlChart = awdFlChart.get();
|
||||||
wsFlChart = awsFlChart.get();
|
wsFlChart = awsFlChart.get();
|
||||||
wdHfChart = awdHfChart.get();
|
wdHfChart = awdHfChart.get();
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ typedef struct{
|
|||||||
uint8_t pageNumber; // page number in sequence of visible pages
|
uint8_t pageNumber; // page number in sequence of visible pages
|
||||||
//the values will always contain the user defined values first
|
//the values will always contain the user defined values first
|
||||||
ValueList values;
|
ValueList values;
|
||||||
HstryBuf* boatHstry;
|
HstryManager* hstryManager;
|
||||||
} PageData;
|
} PageData;
|
||||||
|
|
||||||
// Sensor data structure (only for extended sensors, not for NMEA bus sensors)
|
// Sensor data structure (only for extended sensors, not for NMEA bus sensors)
|
||||||
|
|||||||
@@ -433,7 +433,7 @@ void OBP60Task(GwApi *api){
|
|||||||
int lastPage=pageNumber;
|
int lastPage=pageNumber;
|
||||||
|
|
||||||
BoatValueList boatValues; //all the boat values for the api query
|
BoatValueList boatValues; //all the boat values for the api query
|
||||||
HstryBuf hstryBufList(1920); // Create ring buffers for history storage of some boat data (1920 seconds = 32 minutes)
|
HstryManager hstryManager(1920, logger, &boatValues); // Create and manage history buffers
|
||||||
WindUtils trueWind(&boatValues); // Create helper object for true wind calculation
|
WindUtils trueWind(&boatValues); // Create helper object for true wind calculation
|
||||||
//commonData.distanceformat=config->getString(xxx);
|
//commonData.distanceformat=config->getString(xxx);
|
||||||
//add all necessary data to common data
|
//add all necessary data to common data
|
||||||
@@ -477,21 +477,19 @@ void OBP60Task(GwApi *api){
|
|||||||
LOG_DEBUG(GwLog::DEBUG,"added fixed value %s to page %d",value->getName().c_str(),i);
|
LOG_DEBUG(GwLog::DEBUG,"added fixed value %s to page %d",value->getName().c_str(),i);
|
||||||
pages[i].parameters.values.push_back(value);
|
pages[i].parameters.values.push_back(value);
|
||||||
}
|
}
|
||||||
// Add boat history data to page parameters
|
// Add history manager to page parameters
|
||||||
pages[i].parameters.boatHstry = &hstryBufList;
|
pages[i].parameters.hstryManager = &hstryManager;
|
||||||
}
|
}
|
||||||
// add out of band system page (always available)
|
// add out of band system page (always available)
|
||||||
Page *syspage = allPages.pages[0]->creator(commonData);
|
Page *syspage = allPages.pages[0]->creator(commonData);
|
||||||
|
|
||||||
// Read all calibration data settings from config
|
|
||||||
calibrationData.readConfig(config, logger);
|
|
||||||
|
|
||||||
// Check user settings for true wind calculation
|
// Check user settings for true wind calculation
|
||||||
bool calcTrueWnds = api->getConfig()->getBool(api->getConfig()->calcTrueWnds, false);
|
bool calcTrueWnds = api->getConfig()->getBool(api->getConfig()->calcTrueWnds, false);
|
||||||
bool useSimuData = api->getConfig()->getBool(api->getConfig()->useSimuData, false);
|
bool useSimuData = api->getConfig()->getBool(api->getConfig()->useSimuData, false);
|
||||||
|
|
||||||
// Initialize history buffer for certain boat data
|
// Initialize history buffer for certain boat data
|
||||||
hstryBufList.init(&boatValues, logger);
|
// Read all calibration data settings from config
|
||||||
|
calibrationData.readConfig(config, logger);
|
||||||
|
|
||||||
// Display screenshot handler for HTTP request
|
// Display screenshot handler for HTTP request
|
||||||
// http://192.168.15.1/api/user/OBP60Task/screenshot
|
// http://192.168.15.1/api/user/OBP60Task/screenshot
|
||||||
@@ -809,7 +807,7 @@ void OBP60Task(GwApi *api){
|
|||||||
trueWind.addTrueWind(api, &boatValues, logger);
|
trueWind.addTrueWind(api, &boatValues, logger);
|
||||||
}
|
}
|
||||||
// Handle history buffers for certain boat data for windplot page and other usage
|
// Handle history buffers for certain boat data for windplot page and other usage
|
||||||
hstryBufList.handleHstryBuf(useSimuData);
|
hstryManager.handleHstryBufs(useSimuData);
|
||||||
|
|
||||||
// Clear display
|
// Clear display
|
||||||
// getdisplay().fillRect(0, 0, getdisplay().width(), getdisplay().height(), commonData.bgcolor);
|
// getdisplay().fillRect(0, 0, getdisplay().width(), getdisplay().height(), commonData.bgcolor);
|
||||||
|
|||||||
Reference in New Issue
Block a user