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

intermediate: allow to exchange simple data between tasks

This commit is contained in:
andreas
2023-10-14 20:21:20 +02:00
parent 015b4762f8
commit 371372f1f4
3 changed files with 88 additions and 5 deletions

View File

@@ -32,6 +32,29 @@ class GwApi{
return format;
}
};
/**
* a simple value container
* to exchange data between tasks
*/
class Value{
long lvalue=0;
String svalue;
bool isString=false;
bool isValid=false;
public:
Value(const String &v){isString=true;svalue=v;isValid=true;}
Value(long l){lvalue=l;isValid=true;}
Value(){}
long getLValue() const{
if(!isString) return lvalue;
return atol(svalue.c_str());
}
String getSValue() const{
if(isString) return svalue;
return String(lvalue);
}
bool valid() const{return isValid;}
};
class Status{
public:
@@ -133,6 +156,15 @@ class GwApi{
virtual void increment(int idx,const String &name,bool failed=false){}
virtual void reset(int idx){}
virtual void remove(int idx){}
/**
* exchange data between different user tasks
* each task can set arbitrary items
* that can be accessed by other tasks
*/
virtual void setTaskValue(const String &name,const Value &v){}
virtual Value getTaskValue(const String &taskName,const String &name){return Value();}
/**
* not thread safe methods
* accessing boat data must only be executed from within the main thread