correct backward xdr mapping for unknown instance, prefer instance mode single for unmapped, improve traces

This commit is contained in:
wellenvogel 2021-12-03 22:51:31 +01:00
parent 236c417fb5
commit 84483024ac
4 changed files with 47 additions and 37 deletions

View File

@ -216,7 +216,10 @@ private:
if (found.empty) continue; if (found.empty) continue;
value=found.valueFromXdr(value); value=found.valueFromXdr(value);
if (!boatData->update(value,msg.sourceId,&found)) continue; if (!boatData->update(value,msg.sourceId,&found)) continue;
LOG_DEBUG(GwLog::DEBUG,"found mapped XDR %s, value %f",transducerName,value); LOG_DEBUG(GwLog::DEBUG,"found mapped XDR %s:%s, value %f",
transducerName.c_str(),
found.definition->toString().c_str(),
value);
foundMappings.push_back(XdrMappingAndValue(found,value)); foundMappings.push_back(XdrMappingAndValue(found,value));
} }
static const int maxFields=20; static const int maxFields=20;
@ -291,7 +294,7 @@ private:
} }
} }
else{ else{
if (fillFieldList(current, fields, 12,13)){ if (fillFieldList(current, fields, 10,13)){
SetN2kPGN127488(n2kMsg,current.mapping.instanceId, SetN2kPGN127488(n2kMsg,current.mapping.instanceId,
fields[10],fields[11],fields[12]); fields[10],fields[11],fields[12]);
send(n2kMsg, buildN2KKey(n2kMsg, current.mapping)); send(n2kMsg, buildN2KKey(n2kMsg, current.mapping));

View File

@ -325,41 +325,48 @@ void GwXDRMappings::begin()
* select the best matching mapping * select the best matching mapping
* depending on the instance id * depending on the instance id
*/ */
GwXDRFoundMapping GwXDRMappings::selectMapping(GwXDRMapping::MappingList *list,int instance,const char * key){ GwXDRFoundMapping GwXDRMappings::selectMapping(GwXDRMapping::MappingList *list, int instance, const char *key)
{
GwXDRMapping *candidate = NULL; GwXDRMapping *candidate = NULL;
for (auto mit=list->begin();mit != list->end();mit++){ for (auto mit = list->begin(); mit != list->end(); mit++)
{
GwXDRMappingDef *def = (*mit)->definition; GwXDRMappingDef *def = (*mit)->definition;
//if there is no instance we take a mapping with instance type ignore //if there is no instance (coming from xdr with no instance) we take a mapping with instance type ignore
//otherwise we prefer a matching instance before we use auto/ignore //or the first explicit mapping
if (instance < 0){ //for coming from xdr we only should have one mapping in the list
if (def->instanceMode != GwXDRMappingDef::IS_IGNORE) continue; //but auto will not match for unknwn instance
LOG_DEBUG(GwLog::DEBUG,"selected mapping %s for %s",def->toString().c_str(),key); switch (def->instanceMode)
return GwXDRFoundMapping(*mit); {
}
else{
switch(def->instanceMode){
case GwXDRMappingDef::IS_SINGLE: case GwXDRMappingDef::IS_SINGLE:
if (def->instanceId == instance){ if (def->instanceId == instance)
{
LOG_DEBUG(GwLog::DEBUG + 1, "selected mapping %s for %s, i=%d", LOG_DEBUG(GwLog::DEBUG + 1, "selected mapping %s for %s, i=%d",
def->toString().c_str(), key, instance); def->toString().c_str(), key, instance);
return GwXDRFoundMapping(*mit, instance); return GwXDRFoundMapping(*mit, instance);
} }
if (instance < 0)
{
if (candidate == NULL)
candidate = *mit;
}
case GwXDRMappingDef::IS_AUTO: case GwXDRMappingDef::IS_AUTO:
if (instance >= 0)
candidate = *mit; candidate = *mit;
break; break;
case GwXDRMappingDef::IS_IGNORE: case GwXDRMappingDef::IS_IGNORE:
if (candidate == NULL) candidate=*mit; if (candidate == NULL)
candidate = *mit;
break; break;
default: default:
break; break;
} }
} }
} if (candidate != NULL)
if (candidate != NULL){ {
LOG_DEBUG(GwLog::DEBUG + 1, "selected mapping %s for %s, i=%d", LOG_DEBUG(GwLog::DEBUG + 1, "selected mapping %s for %s, i=%d",
candidate->definition->toString().c_str(), key, instance); candidate->definition->toString().c_str(), key, instance);
return GwXDRFoundMapping(candidate,instance); return GwXDRFoundMapping(candidate, instance>=0?instance:candidate->definition->instanceId);
} }
LOG_DEBUG(GwLog::DEBUG + 1, "no instance mapping found for key=%s, i=%d", key, instance); LOG_DEBUG(GwLog::DEBUG + 1, "no instance mapping found for key=%s, i=%d", key, instance);
return GwXDRFoundMapping(); return GwXDRFoundMapping();

View File

@ -161,7 +161,7 @@ class GwXDRFoundMapping : public GwBoatItemNameProvider{
this->type=type; this->type=type;
empty=false; empty=false;
} }
GwXDRFoundMapping(GwXDRMapping* mapping,int instance=-1){ GwXDRFoundMapping(GwXDRMapping* mapping,int instance=0){
this->definition=mapping->definition; this->definition=mapping->definition;
this->type=mapping->type; this->type=mapping->type;
this->instanceId=instance; this->instanceId=instance;

View File

@ -719,7 +719,7 @@ function convertUnassigned(value){
if (parseInt(s.v) == selector) selectorName=s.l; if (parseInt(s.v) == selector) selectorName=s.l;
}); });
rt.l=cname+","+selectorName+","+fieldName+","+instance; rt.l=cname+","+selectorName+","+fieldName+","+instance;
rt.v=cid+",1,"+selector+","+field+",1,"+instance+","; rt.v=cid+",1,"+selector+","+field+",0,"+instance+",";
return rt; return rt;
} }