make changing timeouts working correctly
This commit is contained in:
parent
7ea500bad6
commit
2c87be78db
|
@ -48,12 +48,36 @@ GwBoatItemBase::GwBoatItemBase(String name, String format, GwBoatItemBase::TOTyp
|
|||
this->type = 0;
|
||||
this->lastUpdateSource = -1;
|
||||
}
|
||||
void GwBoatItemBase::setInvalidTime(unsigned long it, bool force){
|
||||
if (toType != TOType::user || force ){
|
||||
invalidTime=it;
|
||||
void GwBoatItemBase::setInvalidTime(GwConfigHandler *cfg){
|
||||
if (toType != TOType::user){
|
||||
unsigned long timeout=GwBoatItemBase::INVALID_TIME;
|
||||
switch(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;
|
||||
}
|
||||
invalidTime=timeout;
|
||||
}
|
||||
}
|
||||
size_t GwBoatItemBase::getJsonSize() { return JSON_OBJECT_SIZE(10); }
|
||||
|
||||
void GwBoatItemBase::GwBoatItemMap::add(const String &name,GwBoatItemBase *item){
|
||||
boatData->setInvalidTime(item);
|
||||
(*this)[name]=item;
|
||||
}
|
||||
|
||||
#define STRING_SIZE 40
|
||||
GwBoatItemBase::StringWriter::StringWriter()
|
||||
{
|
||||
|
@ -127,7 +151,7 @@ GwBoatItem<T>::GwBoatItem(String name, String formatInfo, unsigned long invalidT
|
|||
this->type = GwBoatItemTypes::getType(dummy);
|
||||
if (map)
|
||||
{
|
||||
(*map)[name] = this;
|
||||
map->add(name,this);
|
||||
}
|
||||
}
|
||||
template <class T>
|
||||
|
@ -137,7 +161,7 @@ GwBoatItem<T>::GwBoatItem(String name, String formatInfo, GwBoatItemBase::TOType
|
|||
this->type = GwBoatItemTypes::getType(dummy);
|
||||
if (map)
|
||||
{
|
||||
(*map)[name] = this;
|
||||
map->add(name,this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -322,28 +346,12 @@ void GwBoatDataSatList::toJsonDoc(GwJsonDocument *doc, unsigned long minTime)
|
|||
GwBoatData::GwBoatData(GwLog *logger, GwConfigHandler *cfg)
|
||||
{
|
||||
this->logger = logger;
|
||||
this->config = cfg;
|
||||
}
|
||||
void GwBoatData::begin(){
|
||||
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);
|
||||
it.second->setInvalidTime(config);
|
||||
}
|
||||
|
||||
}
|
||||
GwBoatData::~GwBoatData()
|
||||
{
|
||||
|
@ -456,6 +464,10 @@ double GwBoatData::getDoubleValue(String name, double defaultv)
|
|||
return defaultv;
|
||||
return it->second->getDoubleValue();
|
||||
}
|
||||
|
||||
void GwBoatData::setInvalidTime(GwBoatItemBase *item){
|
||||
if (config != nullptr) item->setInvalidTime(config);
|
||||
}
|
||||
double formatCourse(double cv)
|
||||
{
|
||||
double rt = cv * 180.0 / M_PI;
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#define ROT_WA_FACTOR 60
|
||||
|
||||
class GwJsonDocument;
|
||||
class GwBoatData;
|
||||
|
||||
class GwBoatItemBase{
|
||||
public:
|
||||
using TOType=enum{
|
||||
|
@ -56,7 +58,6 @@ class GwBoatItemBase{
|
|||
GWSC(formatRot);
|
||||
GWSC(formatDate);
|
||||
GWSC(formatTime);
|
||||
typedef std::map<String,GwBoatItemBase*> GwBoatItemMap;
|
||||
protected:
|
||||
int type;
|
||||
unsigned long lastSet=0;
|
||||
|
@ -93,10 +94,15 @@ class GwBoatItemBase{
|
|||
virtual double getDoubleValue()=0;
|
||||
String getName(){return name;}
|
||||
const String & getFormat() const{return format;}
|
||||
virtual void setInvalidTime(unsigned long it, bool force=true);
|
||||
virtual void setInvalidTime(GwConfigHandler *cfg);
|
||||
TOType getToType(){return toType;}
|
||||
class GwBoatItemMap : public std::map<String,GwBoatItemBase*>{
|
||||
GwBoatData *boatData;
|
||||
public:
|
||||
GwBoatItemMap(GwBoatData *bd):boatData(bd){}
|
||||
void add(const String &name,GwBoatItemBase *item);
|
||||
};
|
||||
};
|
||||
class GwBoatData;
|
||||
template<class T> class GwBoatItem : public GwBoatItemBase{
|
||||
protected:
|
||||
T data;
|
||||
|
@ -186,8 +192,9 @@ public:
|
|||
clazz *name=new clazz(#name,GwBoatItemBase::fmt,toType,&values) ;
|
||||
class GwBoatData{
|
||||
private:
|
||||
GwLog *logger;
|
||||
GwBoatItemBase::GwBoatItemMap values;
|
||||
GwLog *logger=nullptr;
|
||||
GwConfigHandler *config=nullptr;
|
||||
GwBoatItemBase::GwBoatItemMap values{this};
|
||||
public:
|
||||
|
||||
GWBOATDATA(double,COG,formatCourse) // course over ground
|
||||
|
@ -231,9 +238,11 @@ class GwBoatData{
|
|||
public:
|
||||
GwBoatData(GwLog *logger, GwConfigHandler *cfg);
|
||||
~GwBoatData();
|
||||
void begin();
|
||||
template<class T> GwBoatItem<T> *getOrCreate(T initial,GwBoatItemNameProvider *provider);
|
||||
template<class T> bool update(T value,int source,GwBoatItemNameProvider *provider);
|
||||
template<class T> T getDataWithDefault(T defaultv, GwBoatItemNameProvider *provider);
|
||||
void setInvalidTime(GwBoatItemBase *item);
|
||||
bool isValid(String name);
|
||||
double getDoubleValue(String name,double defaultv);
|
||||
GwBoatItemBase *getBase(String name);
|
||||
|
|
|
@ -784,6 +784,7 @@ void setup() {
|
|||
logger.prefix="FALLBACK:";
|
||||
logger.setWriter(new DefaultLogWriter());
|
||||
#endif
|
||||
boatData.begin();
|
||||
userCodeHandler.startInitTasks(MIN_USER_TASK);
|
||||
channels.preinit();
|
||||
config.stopChanges();
|
||||
|
|
Loading…
Reference in New Issue