max handling also from 0183, satInfo cleanup
This commit is contained in:
parent
28abd16749
commit
08af807cf9
|
@ -52,6 +52,7 @@ class GwBoatItemBase{
|
|||
virtual void toJsonDoc(JsonDocument *doc, unsigned long minTime)=0;
|
||||
virtual size_t getJsonSize(){return JSON_OBJECT_SIZE(15);}
|
||||
virtual int getLastSource()=0;
|
||||
virtual void refresh(unsigned long ts=0){uls(ts);}
|
||||
};
|
||||
class GwBoatData;
|
||||
template<class T> class GwBoatItem : public GwBoatItemBase{
|
||||
|
@ -82,6 +83,19 @@ template<class T> class GwBoatItem : public GwBoatItemBase{
|
|||
uls(now);
|
||||
return true;
|
||||
}
|
||||
bool updateMax(T nv,int sourceId=-1){
|
||||
unsigned long now=millis();
|
||||
if (! isValid(now)){
|
||||
return update(nv,sourceId);
|
||||
}
|
||||
if (getData() < nv){
|
||||
data=nv;
|
||||
lastUpdateSource=sourceId;
|
||||
uls(now);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
T getData(){
|
||||
return data;
|
||||
}
|
||||
|
@ -173,6 +187,10 @@ public:
|
|||
data.update(info);
|
||||
return true;
|
||||
}
|
||||
virtual void toJsonDoc(JsonDocument *doc, unsigned long minTime){
|
||||
data.houseKeeping();
|
||||
GwBoatItem<GwSatInfoList>::toJsonDoc(doc,minTime);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
@ -216,8 +234,8 @@ class GwBoatData{
|
|||
GWBOATDATA(double,BTW,4000,formatCourse)
|
||||
GWBOATDATA(double,WPLatitude,4000,formatLatitude)
|
||||
GWBOATDATA(double,WPLongitude,4000,formatLongitude)
|
||||
GWBOATDATA(uint32_t,Log,0,mtr2nm)
|
||||
GWBOATDATA(uint32_t,TripLog,0,mtr2nm)
|
||||
GWBOATDATA(uint32_t,Log,16000,mtr2nm)
|
||||
GWBOATDATA(uint32_t,TripLog,16000,mtr2nm)
|
||||
GWBOATDATA(uint32_t,DaysSince1970,4000,formatFixed0)
|
||||
GWBOATDATA(int16_t,Timezone,8000,formatFixed0)
|
||||
GWSPECBOATDATA(GwBoatDataSatList,SatInfo,GwSatInfoList::lifeTime,formatFixed0);
|
||||
|
|
|
@ -247,11 +247,13 @@ private:
|
|||
n2kRef=N2kWind_Apparent;
|
||||
shouldSend=updateDouble(boatData->AWA,WindAngle,msg.sourceId) &&
|
||||
updateDouble(boatData->AWS,WindSpeed,msg.sourceId);
|
||||
if (WindSpeed != NMEA0183DoubleNA) boatData->MaxAws->updateMax(WindSpeed);
|
||||
break;
|
||||
case NMEA0183Wind_True:
|
||||
n2kRef=N2kWind_True_North;
|
||||
shouldSend=updateDouble(boatData->TWD,WindAngle,msg.sourceId) &&
|
||||
updateDouble(boatData->TWS,WindSpeed,msg.sourceId);
|
||||
if (WindSpeed != NMEA0183DoubleNA) boatData->MaxTws->updateMax(WindSpeed);
|
||||
break;
|
||||
default:
|
||||
LOG_DEBUG(GwLog::DEBUG,"unknown wind reference %d in %s",(int)Reference,msg.line);
|
||||
|
@ -295,6 +297,7 @@ private:
|
|||
bool shouldSend = false;
|
||||
shouldSend = updateDouble(boatData->AWA, WindAngle, msg.sourceId) &&
|
||||
updateDouble(boatData->AWS, WindSpeed, msg.sourceId);
|
||||
if (WindSpeed != NMEA0183DoubleNA) boatData->MaxAws->updateMax(WindSpeed);
|
||||
if (shouldSend)
|
||||
{
|
||||
SetN2kWindSpeed(n2kMsg, 1, WindSpeed, WindAngle, N2kWind_Apparent);
|
||||
|
@ -337,6 +340,7 @@ private:
|
|||
if (WindAngle != NMEA0183DoubleNA){
|
||||
shouldSend = updateDouble(boatData->TWD, WindAngle, msg.sourceId) &&
|
||||
updateDouble(boatData->TWS, WindSpeed, msg.sourceId);
|
||||
if (WindSpeed != NMEA0183DoubleNA) boatData->MaxTws->updateMax(WindSpeed);
|
||||
}
|
||||
if (shouldSend)
|
||||
{
|
||||
|
|
|
@ -71,10 +71,7 @@ private:
|
|||
unsigned long now = millis();
|
||||
if (!item->isValid(now))
|
||||
return;
|
||||
if (item->getData() > maxItem->getData() || !maxItem->isValid(now))
|
||||
{
|
||||
maxItem->update(item->getData(),sourceId);
|
||||
}
|
||||
maxItem->updateMax(item->getData(),sourceId);
|
||||
}
|
||||
void updateDouble(GwBoatItem<double> *item, double value)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue