correctly handle data timeouts, always set source if for updates
This commit is contained in:
parent
98a95e62f7
commit
e982389c75
|
@ -47,7 +47,6 @@ GwBoatItemBase::GwBoatItemBase(String name, String format, GwBoatItemBase::TOTyp
|
||||||
this->format = format;
|
this->format = format;
|
||||||
this->type = 0;
|
this->type = 0;
|
||||||
this->lastUpdateSource = -1;
|
this->lastUpdateSource = -1;
|
||||||
this->toType=TOType::user;
|
|
||||||
}
|
}
|
||||||
void GwBoatItemBase::setInvalidTime(unsigned long it, bool force){
|
void GwBoatItemBase::setInvalidTime(unsigned long it, bool force){
|
||||||
if (toType != TOType::user || force ){
|
if (toType != TOType::user || force ){
|
||||||
|
@ -375,7 +374,7 @@ GwBoatItem<T> *GwBoatData::getOrCreate(T initial, GwBoatItemNameProvider *provid
|
||||||
provider->getBoatItemFormat(),
|
provider->getBoatItemFormat(),
|
||||||
provider->getInvalidTime(),
|
provider->getInvalidTime(),
|
||||||
&values);
|
&values);
|
||||||
rt->update(initial);
|
rt->update(initial,-1);
|
||||||
LOG_DEBUG(GwLog::LOG, "creating boatItem %s, type %d",
|
LOG_DEBUG(GwLog::LOG, "creating boatItem %s, type %d",
|
||||||
name.c_str(), rt->getCurrentType());
|
name.c_str(), rt->getCurrentType());
|
||||||
return rt;
|
return rt;
|
||||||
|
|
|
@ -105,8 +105,8 @@ template<class T> class GwBoatItem : public GwBoatItemBase{
|
||||||
GwBoatItem(String name,String formatInfo,unsigned long invalidTime=INVALID_TIME,GwBoatItemMap *map=NULL);
|
GwBoatItem(String name,String formatInfo,unsigned long invalidTime=INVALID_TIME,GwBoatItemMap *map=NULL);
|
||||||
GwBoatItem(String name,String formatInfo,TOType toType,GwBoatItemMap *map=NULL);
|
GwBoatItem(String name,String formatInfo,TOType toType,GwBoatItemMap *map=NULL);
|
||||||
virtual ~GwBoatItem(){}
|
virtual ~GwBoatItem(){}
|
||||||
bool update(T nv, int source=-1);
|
bool update(T nv, int source);
|
||||||
bool updateMax(T nv,int sourceId=-1);
|
bool updateMax(T nv,int sourceId);
|
||||||
T getData(){
|
T getData(){
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
@ -185,7 +185,6 @@ public:
|
||||||
#define GWSPECBOATDATA(clazz,name,toType,fmt) \
|
#define GWSPECBOATDATA(clazz,name,toType,fmt) \
|
||||||
clazz *name=new clazz(#name,GwBoatItemBase::fmt,toType,&values) ;
|
clazz *name=new clazz(#name,GwBoatItemBase::fmt,toType,&values) ;
|
||||||
class GwBoatData{
|
class GwBoatData{
|
||||||
static const unsigned long DEF_TIME=4000;
|
|
||||||
private:
|
private:
|
||||||
GwLog *logger;
|
GwLog *logger;
|
||||||
GwBoatItemBase::GwBoatItemMap values;
|
GwBoatItemBase::GwBoatItemMap values;
|
||||||
|
|
|
@ -103,7 +103,7 @@ private:
|
||||||
if (v != NMEA0183UInt32NA){
|
if (v != NMEA0183UInt32NA){
|
||||||
return target->update(v,sourceId);
|
return target->update(v,sourceId);
|
||||||
}
|
}
|
||||||
return v;
|
return false;
|
||||||
}
|
}
|
||||||
uint32_t getUint32(GwBoatItem<uint32_t> *src){
|
uint32_t getUint32(GwBoatItem<uint32_t> *src){
|
||||||
return src->getDataWithDefault(N2kUInt32NA);
|
return src->getDataWithDefault(N2kUInt32NA);
|
||||||
|
@ -406,13 +406,13 @@ private:
|
||||||
case NMEA0183Wind_Apparent:
|
case NMEA0183Wind_Apparent:
|
||||||
shouldSend=updateDouble(boatData->AWA,WindAngle,msg.sourceId) &&
|
shouldSend=updateDouble(boatData->AWA,WindAngle,msg.sourceId) &&
|
||||||
updateDouble(boatData->AWS,WindSpeed,msg.sourceId);
|
updateDouble(boatData->AWS,WindSpeed,msg.sourceId);
|
||||||
if (WindSpeed != NMEA0183DoubleNA) boatData->MaxAws->updateMax(WindSpeed);
|
if (WindSpeed != NMEA0183DoubleNA) boatData->MaxAws->updateMax(WindSpeed,msg.sourceId);
|
||||||
mapping=config.findWindMapping(GwConverterConfig::WindMapping::AWA_AWS);
|
mapping=config.findWindMapping(GwConverterConfig::WindMapping::AWA_AWS);
|
||||||
break;
|
break;
|
||||||
case NMEA0183Wind_True:
|
case NMEA0183Wind_True:
|
||||||
shouldSend=updateDouble(boatData->TWA,WindAngle,msg.sourceId) &&
|
shouldSend=updateDouble(boatData->TWA,WindAngle,msg.sourceId) &&
|
||||||
updateDouble(boatData->TWS,WindSpeed,msg.sourceId);
|
updateDouble(boatData->TWS,WindSpeed,msg.sourceId);
|
||||||
if (WindSpeed != NMEA0183DoubleNA) boatData->MaxTws->updateMax(WindSpeed);
|
if (WindSpeed != NMEA0183DoubleNA) boatData->MaxTws->updateMax(WindSpeed,msg.sourceId);
|
||||||
mapping=config.findWindMapping(GwConverterConfig::WindMapping::TWA_TWS);
|
mapping=config.findWindMapping(GwConverterConfig::WindMapping::TWA_TWS);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -458,7 +458,7 @@ private:
|
||||||
bool shouldSend = false;
|
bool shouldSend = false;
|
||||||
shouldSend = updateDouble(boatData->AWA, WindAngle, msg.sourceId) &&
|
shouldSend = updateDouble(boatData->AWA, WindAngle, msg.sourceId) &&
|
||||||
updateDouble(boatData->AWS, WindSpeed, msg.sourceId);
|
updateDouble(boatData->AWS, WindSpeed, msg.sourceId);
|
||||||
if (WindSpeed != NMEA0183DoubleNA) boatData->MaxAws->updateMax(WindSpeed);
|
if (WindSpeed != NMEA0183DoubleNA) boatData->MaxAws->updateMax(WindSpeed,msg.sourceId);
|
||||||
if (shouldSend)
|
if (shouldSend)
|
||||||
{
|
{
|
||||||
const GwConverterConfig::WindMapping mapping=config.findWindMapping(GwConverterConfig::WindMapping::AWA_AWS);
|
const GwConverterConfig::WindMapping mapping=config.findWindMapping(GwConverterConfig::WindMapping::AWA_AWS);
|
||||||
|
@ -503,7 +503,7 @@ private:
|
||||||
if (WindDirection != NMEA0183DoubleNA){
|
if (WindDirection != NMEA0183DoubleNA){
|
||||||
shouldSend = updateDouble(boatData->TWD, WindDirection, msg.sourceId) &&
|
shouldSend = updateDouble(boatData->TWD, WindDirection, msg.sourceId) &&
|
||||||
updateDouble(boatData->TWS, WindSpeed, msg.sourceId);
|
updateDouble(boatData->TWS, WindSpeed, msg.sourceId);
|
||||||
if (WindSpeed != NMEA0183DoubleNA) boatData->MaxTws->updateMax(WindSpeed);
|
if (WindSpeed != NMEA0183DoubleNA) boatData->MaxTws->updateMax(WindSpeed,msg.sourceId);
|
||||||
if(shouldSend && boatData->HDT->isValid()) {
|
if(shouldSend && boatData->HDT->isValid()) {
|
||||||
double twa = WindDirection-boatData->HDT->getData();
|
double twa = WindDirection-boatData->HDT->getData();
|
||||||
if(twa<0) { twa+=2*M_PI; }
|
if(twa<0) { twa+=2*M_PI; }
|
||||||
|
@ -602,10 +602,10 @@ private:
|
||||||
}
|
}
|
||||||
//offset == 0? SK does not allow this
|
//offset == 0? SK does not allow this
|
||||||
if (Offset != NMEA0183DoubleNA && Offset>=0 ){
|
if (Offset != NMEA0183DoubleNA && Offset>=0 ){
|
||||||
if (! boatData->DBS->update(DepthBelowTransducer+Offset)) return;
|
if (! boatData->DBS->update(DepthBelowTransducer+Offset,msg.sourceId)) return;
|
||||||
}
|
}
|
||||||
if (Offset == NMEA0183DoubleNA) Offset=N2kDoubleNA;
|
if (Offset == NMEA0183DoubleNA) Offset=N2kDoubleNA;
|
||||||
if (! boatData->DBT->update(DepthBelowTransducer)) return;
|
if (! boatData->DBT->update(DepthBelowTransducer,msg.sourceId)) return;
|
||||||
tN2kMsg n2kMsg;
|
tN2kMsg n2kMsg;
|
||||||
SetN2kWaterDepth(n2kMsg,1,DepthBelowTransducer,Offset);
|
SetN2kWaterDepth(n2kMsg,1,DepthBelowTransducer,Offset);
|
||||||
send(n2kMsg,msg.sourceId,String(n2kMsg.PGN)+String((Offset != N2kDoubleNA)?1:0));
|
send(n2kMsg,msg.sourceId,String(n2kMsg.PGN)+String((Offset != N2kDoubleNA)?1:0));
|
||||||
|
|
Loading…
Reference in New Issue