mirror of
https://github.com/thooge/esp32-nmea2000-obp60.git
synced 2025-12-13 05:53:06 +01:00
dynamic adding of xdr boat data for implemented n2k conversions
This commit is contained in:
@@ -17,6 +17,8 @@ template<class T> GwBoatItem<T> *GwBoatData::getOrCreate(T initial, GwBoatItemNa
|
||||
if (it != values.end()) {
|
||||
int expectedType=GwBoatItemTypes::getType(initial);
|
||||
if (expectedType != it->second->getCurrentType()){
|
||||
LOG_DEBUG(GwLog::DEBUG,"invalid type for boat item %s, expected %d, got %d",
|
||||
name.c_str(),expectedType,it->second->getCurrentType());
|
||||
return NULL;
|
||||
}
|
||||
return (GwBoatItem<T>*)(it->second);
|
||||
@@ -26,6 +28,8 @@ template<class T> GwBoatItem<T> *GwBoatData::getOrCreate(T initial, GwBoatItemNa
|
||||
provider->getInvalidTime(),
|
||||
&values);
|
||||
rt->update(initial);
|
||||
LOG_DEBUG(GwLog::LOG,"creating boatItem %s, type %d",
|
||||
name.c_str(),rt->getCurrentType());
|
||||
return rt;
|
||||
}
|
||||
template<class T> bool GwBoatData::update(T value,int source,GwBoatItemNameProvider *provider){
|
||||
|
||||
@@ -80,7 +80,7 @@ template<class T> class GwBoatItem : public GwBoatItemBase{
|
||||
public:
|
||||
GwBoatItem(int type,String name,String formatInfo,unsigned long invalidTime=INVALID_TIME,GwBoatItemMap *map=NULL):
|
||||
GwBoatItemBase(name,formatInfo,invalidTime){
|
||||
type=type;
|
||||
this->type=type;
|
||||
if (map){
|
||||
(*map)[name]=this;
|
||||
}
|
||||
@@ -93,7 +93,7 @@ template<class T> class GwBoatItem : public GwBoatItemBase{
|
||||
//priority handling
|
||||
//sources with lower ids will win
|
||||
//and we will not overwrite their value
|
||||
if (lastUpdateSource < source){
|
||||
if (lastUpdateSource < source && lastUpdateSource >= 0){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,6 +105,10 @@ private:
|
||||
return false;
|
||||
return item->update(value,sourceId);
|
||||
}
|
||||
bool updateDouble(GwXDRFoundMapping * mapping, double &value){
|
||||
if (mapping->empty) return false;
|
||||
return boatData->update(value,sourceId,mapping);
|
||||
}
|
||||
|
||||
unsigned long LastPosSend;
|
||||
unsigned long NextRMCSend;
|
||||
@@ -1187,7 +1191,7 @@ private:
|
||||
return;
|
||||
}
|
||||
GwXDRFoundMapping mapping=xdrMappings->getMapping(XDRTEMP,(int)TemperatureSource,0,TemperatureInstance);
|
||||
if (mapping.empty) return;
|
||||
if (! updateDouble(&mapping,Temperature)) return;
|
||||
LOG_DEBUG(GwLog::DEBUG+1,"found temperature mapping %s",mapping.definition->toString().c_str());
|
||||
addToXdr(mapping.buildXdrEntry(Temperature));
|
||||
finalizeXdr();
|
||||
@@ -1204,7 +1208,7 @@ private:
|
||||
return;
|
||||
}
|
||||
GwXDRFoundMapping mapping=xdrMappings->getMapping(XDRHUMIDITY,(int)HumiditySource,0,HumidityInstance);
|
||||
if (mapping.empty) return;
|
||||
if (! updateDouble(&mapping,ActualHumidity)) return;
|
||||
LOG_DEBUG(GwLog::DEBUG+1,"found humidity mapping %s",mapping.definition->toString().c_str());
|
||||
addToXdr(mapping.buildXdrEntry(ActualHumidity));
|
||||
finalizeXdr();
|
||||
@@ -1221,8 +1225,7 @@ private:
|
||||
return;
|
||||
}
|
||||
GwXDRFoundMapping mapping=xdrMappings->getMapping(XDRPRESSURE,(int)PressureSource,0,PressureInstance);
|
||||
if (mapping.empty) return;
|
||||
if (! boatData->update(ActualPressure,sourceId,&mapping)) return;
|
||||
if (! updateDouble(&mapping,ActualPressure)) return;
|
||||
LOG_DEBUG(GwLog::DEBUG+1,"found pressure mapping %s",mapping.definition->toString().c_str());
|
||||
addToXdr(mapping.buildXdrEntry(ActualPressure));
|
||||
finalizeXdr();
|
||||
|
||||
@@ -188,6 +188,10 @@ GwXDRMappingDef *GwXDRMappingDef::fromString(String s)
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
if (rt->direction == GwXDRMappingDef::M_DISABLED || rt->xdrName == ""){
|
||||
delete rt;
|
||||
return NULL;
|
||||
}
|
||||
return rt;
|
||||
}
|
||||
String GwXDRMappingDef::getTransducerName(int instance)
|
||||
|
||||
@@ -166,7 +166,7 @@ class GwXDRFoundMapping : public GwBoatItemNameProvider{
|
||||
String buildXdrEntry(double value);
|
||||
//boat Data info
|
||||
virtual String getBoatItemName(){
|
||||
return getTransducerName();
|
||||
return String("xdr")+getTransducerName();
|
||||
};
|
||||
virtual String getBoatItemFormat(){
|
||||
return "formatXdr"+type->xdrunit; //TODO: use the type def for the correct format
|
||||
|
||||
Reference in New Issue
Block a user