mirror of
https://github.com/thooge/esp32-nmea2000-obp60.git
synced 2025-12-13 05:53:06 +01:00
free GwApi from ArduinoJson
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
#include "GwBoatData.h"
|
||||
#include <GwJsonDocument.h>
|
||||
#include <ArduinoJson/Json/TextFormatter.hpp>
|
||||
#define GWTYPE_DOUBLE 1
|
||||
#define GWTYPE_UINT32 2
|
||||
#define GWTYPE_UINT16 3
|
||||
#define GWTYPE_INT16 4
|
||||
#define GWTYPE_USER 100
|
||||
|
||||
|
||||
class GwBoatItemTypes{
|
||||
public:
|
||||
static int getType(const uint32_t &x){return GWTYPE_UINT32;}
|
||||
@@ -33,6 +36,7 @@ GwBoatItemBase::GwBoatItemBase(String name, String format, unsigned long invalid
|
||||
this->type = 0;
|
||||
this->lastUpdateSource=-1;
|
||||
}
|
||||
size_t GwBoatItemBase::getJsonSize(){return JSON_OBJECT_SIZE(10);}
|
||||
#define STRING_SIZE 40
|
||||
GwBoatItemBase::StringWriter::StringWriter(){
|
||||
buffer=new uint8_t[STRING_SIZE];
|
||||
@@ -126,7 +130,7 @@ bool GwBoatItem<T>::updateMax(T nv, int sourceId)
|
||||
return false;
|
||||
}
|
||||
template <class T>
|
||||
void GwBoatItem<T>::toJsonDoc(JsonDocument *doc, unsigned long minTime)
|
||||
void GwBoatItem<T>::toJsonDoc(GwJsonDocument *doc, unsigned long minTime)
|
||||
{
|
||||
JsonObject o = doc->createNestedObject(name);
|
||||
o[F("value")] = getData();
|
||||
@@ -246,7 +250,7 @@ bool GwBoatDataSatList::update(GwSatInfo info, int source)
|
||||
data.update(info);
|
||||
return true;
|
||||
}
|
||||
void GwBoatDataSatList::toJsonDoc(JsonDocument *doc, unsigned long minTime)
|
||||
void GwBoatDataSatList::toJsonDoc(GwJsonDocument *doc, unsigned long minTime)
|
||||
{
|
||||
data.houseKeeping();
|
||||
GwBoatItem<GwSatInfoList>::toJsonDoc(doc, minTime);
|
||||
@@ -309,7 +313,7 @@ String GwBoatData::toJson() const {
|
||||
}
|
||||
int sz=JSON_OBJECT_SIZE(count)+elementSizes+10;
|
||||
LOG_DEBUG(GwLog::DEBUG,"size for boatData: %d",sz);
|
||||
DynamicJsonDocument json(sz);
|
||||
GwJsonDocument json(sz);
|
||||
for (it=values.begin() ; it != values.end();it++){
|
||||
it->second->toJsonDoc(&json,minTime);
|
||||
}
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
#define _GWBOATDATA_H
|
||||
|
||||
#include "GwLog.h"
|
||||
#include <ArduinoJson.h>
|
||||
#include <Arduino.h>
|
||||
#include <map>
|
||||
#define GW_BOAT_VALUE_LEN 32
|
||||
#define GWSC(name) static constexpr const __FlashStringHelper* name=F(#name)
|
||||
|
||||
class GwJsonDocument;
|
||||
class GwBoatItemBase{
|
||||
public:
|
||||
class StringWriter{
|
||||
@@ -65,8 +65,8 @@ class GwBoatItemBase{
|
||||
return writer.c_str();
|
||||
}
|
||||
virtual void fillString()=0;
|
||||
virtual void toJsonDoc(JsonDocument *doc, unsigned long minTime)=0;
|
||||
virtual size_t getJsonSize(){return JSON_OBJECT_SIZE(10);}
|
||||
virtual void toJsonDoc(GwJsonDocument *doc, unsigned long minTime)=0;
|
||||
virtual size_t getJsonSize();
|
||||
virtual int getLastSource(){return lastUpdateSource;}
|
||||
virtual void refresh(unsigned long ts=0){uls(ts);}
|
||||
String getName(){return name;}
|
||||
@@ -89,7 +89,7 @@ template<class T> class GwBoatItem : public GwBoatItemBase{
|
||||
return data;
|
||||
}
|
||||
virtual void fillString();
|
||||
virtual void toJsonDoc(JsonDocument *doc, unsigned long minTime);
|
||||
virtual void toJsonDoc(GwJsonDocument *doc, unsigned long minTime);
|
||||
virtual int getLastSource(){return lastUpdateSource;}
|
||||
};
|
||||
double formatCourse(double cv);
|
||||
@@ -127,7 +127,7 @@ class GwBoatDataSatList : public GwBoatItem<GwSatInfoList>
|
||||
public:
|
||||
GwBoatDataSatList(String name, String formatInfo, unsigned long invalidTime = INVALID_TIME, GwBoatItemMap *map = NULL);
|
||||
bool update(GwSatInfo info, int source);
|
||||
virtual void toJsonDoc(JsonDocument *doc, unsigned long minTime);
|
||||
virtual void toJsonDoc(GwJsonDocument *doc, unsigned long minTime);
|
||||
GwSatInfo *getAt(int idx){
|
||||
if (! isValid()) return NULL;
|
||||
return data.getAt(idx);
|
||||
|
||||
Reference in New Issue
Block a user