1
0
mirror of https://github.com/thooge/esp32-nmea2000-obp60.git synced 2025-12-16 07:23:07 +01:00

make data store times configurable

This commit is contained in:
andreas
2024-09-29 19:56:39 +02:00
parent 358710ef03
commit c266bddea3
6 changed files with 176 additions and 62 deletions

View File

@@ -1,6 +1,7 @@
#include "GwBoatData.h"
#include <GwJsonDocument.h>
#include <ArduinoJson/Json/TextFormatter.hpp>
#include "GWConfig.h"
#define GWTYPE_DOUBLE 1
#define GWTYPE_UINT32 2
#define GWTYPE_UINT16 3
@@ -35,6 +36,23 @@ GwBoatItemBase::GwBoatItemBase(String name, String format, unsigned long invalid
this->format = format;
this->type = 0;
this->lastUpdateSource = -1;
this->toType=TOType::user;
}
GwBoatItemBase::GwBoatItemBase(String name, String format, GwBoatItemBase::TOType toType)
{
lastSet = 0;
this->invalidTime = INVALID_TIME;
this->toType=toType;
this->name = name;
this->format = format;
this->type = 0;
this->lastUpdateSource = -1;
this->toType=TOType::user;
}
void GwBoatItemBase::setInvalidTime(unsigned long it, bool force){
if (toType != TOType::user || force ){
invalidTime=it;
}
}
size_t GwBoatItemBase::getJsonSize() { return JSON_OBJECT_SIZE(10); }
#define STRING_SIZE 40
@@ -113,6 +131,16 @@ GwBoatItem<T>::GwBoatItem(String name, String formatInfo, unsigned long invalidT
(*map)[name] = this;
}
}
template <class T>
GwBoatItem<T>::GwBoatItem(String name, String formatInfo, GwBoatItemBase::TOType toType, GwBoatItemMap *map) : GwBoatItemBase(name, formatInfo, toType)
{
T dummy;
this->type = GwBoatItemTypes::getType(dummy);
if (map)
{
(*map)[name] = this;
}
}
template <class T>
bool GwBoatItem<T>::update(T nv, int source)
@@ -246,14 +274,13 @@ void GwSatInfoList::houseKeeping(unsigned long ts)
sats.end(),
[ts, this](const GwSatInfo &info)
{
return (info.timestamp + lifeTime) < ts;
return info.validTill < ts;
}),
sats.end());
}
void GwSatInfoList::update(GwSatInfo entry)
void GwSatInfoList::update(GwSatInfo entry, unsigned long validTill)
{
unsigned long now = millis();
entry.timestamp = now;
entry.validTill = validTill;
for (auto it = sats.begin(); it != sats.end(); it++)
{
if (it->PRN == entry.PRN)
@@ -267,7 +294,7 @@ void GwSatInfoList::update(GwSatInfo entry)
sats.push_back(entry);
}
GwBoatDataSatList::GwBoatDataSatList(String name, String formatInfo, unsigned long invalidTime, GwBoatItemMap *map) : GwBoatItem<GwSatInfoList>(name, formatInfo, invalidTime, map) {}
GwBoatDataSatList::GwBoatDataSatList(String name, String formatInfo, GwBoatItemBase::TOType toType, GwBoatItemMap *map) : GwBoatItem<GwSatInfoList>(name, formatInfo, toType, map) {}
bool GwBoatDataSatList::update(GwSatInfo info, int source)
{
@@ -284,7 +311,7 @@ bool GwBoatDataSatList::update(GwSatInfo info, int source)
}
lastUpdateSource = source;
uls(now);
data.update(info);
data.update(info,now+invalidTime);
return true;
}
void GwBoatDataSatList::toJsonDoc(GwJsonDocument *doc, unsigned long minTime)
@@ -293,9 +320,31 @@ void GwBoatDataSatList::toJsonDoc(GwJsonDocument *doc, unsigned long minTime)
GwBoatItem<GwSatInfoList>::toJsonDoc(doc, minTime);
}
GwBoatData::GwBoatData(GwLog *logger)
GwBoatData::GwBoatData(GwLog *logger, GwConfigHandler *cfg)
{
this->logger = logger;
for (auto &&it : values){
unsigned long timeout=GwBoatItemBase::INVALID_TIME;
switch(it.second->getToType()){
case GwBoatItemBase::TOType::ais:
timeout=cfg->getInt(GwConfigDefinitions::timoAis);
break;
case GwBoatItemBase::TOType::def:
timeout=cfg->getInt(GwConfigDefinitions::timoDefault);
break;
case GwBoatItemBase::TOType::lng:
timeout=cfg->getInt(GwConfigDefinitions::timoLong);
break;
case GwBoatItemBase::TOType::sensor:
timeout=cfg->getInt(GwConfigDefinitions::timoSensor);
break;
case GwBoatItemBase::TOType::keep:
timeout=0;
break;
}
it.second->setInvalidTime(timeout);
}
}
GwBoatData::~GwBoatData()
{