generate XDR field and selector defines

This commit is contained in:
andreas 2023-10-24 18:47:39 +02:00
parent f0643b636a
commit ffdfd917ae
2 changed files with 45 additions and 4 deletions

View File

@ -7,6 +7,7 @@ import inspect
import json
import glob
from datetime import datetime
import re
Import("env")
#print(env.Dump())
OWN_FILE="extra_script.py"
@ -172,7 +173,8 @@ def generateCfg(inFile,outFile,impl):
data+="#endif\n"
writeFileIfChanged(outFile,data)
def labelFilter(label):
return re.sub("[^a-zA-Z0-9]","",re.sub("\([0-9]*\)","",label))
def generateXdrMappings(fp,oh,inFile=''):
jdoc=json.load(fp)
oh.write("static GwXDRTypeMapping* typeMappings[]={\n")
@ -211,6 +213,35 @@ def generateXdrMappings(fp,oh,inFile=''):
oh.write(" new GwXDRTypeMapping(%d,%d,%d) /*%s:%s*/"%(cid,id,tc,cat,l))
oh.write("\n")
oh.write("};\n")
for cat in jdoc:
item=jdoc[cat]
cid=item.get('id')
if cid is None:
continue
selectors=item.get('selector')
if selectors is not None:
for selector in selectors:
label=selector.get('l')
value=selector.get('v')
if label is not None and value is not None:
label=labelFilter(label)
define=("GWXDRSEL_%s_%s"%(cat,label)).upper()
oh.write(" #define %s %s\n"%(define,value))
fields=item.get('fields')
if fields is not None:
idx=0
for field in fields:
v=field.get('v')
if v is None:
v=idx
else:
v=int(v)
label=field.get('l')
if v is not None and label is not None:
define=("GWXDRFIELD_%s_%s"%(cat,labelFilter(label))).upper();
oh.write(" #define %s %s\n"%(define,str(v)))
idx+=1
userTaskDirs=[]

View File

@ -7,6 +7,7 @@
#include "GWConfig.h"
#include <vector>
#include "N2kMessages.h"
#include "GwXdrTypeMappings.h"
/**
* INVALID!!! - the next interface declaration will not work
* as it is not in the correct header file
@ -39,11 +40,20 @@ void exampleInit(GwApi *api){
if (!voltageTransducer.isEmpty()){
int instance=api->getConfig()->getInt(GwConfigDefinitions::exInstanceId);
GwXDRMappingDef xdr;
//we send a battery message - so it is category battery
xdr.category=GwXDRCategory::XDRBAT;
//we only need a conversion from N2K to NMEA0183
xdr.direction=GwXDRMappingDef::Direction::M_FROM2K;
xdr.field=0; //refer to xdrconfig.json to pick up the field id (the index in the field list) - in this case 0 for Voltage
xdr.selector=0; //refer to xdrconfig.json - there is no selector under Battery, so we can leave it empty
xdr.instanceMode=GwXDRMappingDef::IS_SINGLE; //we just map exactly our instance
//you can find the XDR field and selector definitions
//in the generated GwXdrTypeMappings.h
xdr.field=GWXDRFIELD_BATTERY_BATTERYVOLTAGE;
//xdr.selector=-1; //refer to xdrconfig.json - there is no selector under Battery, so we can leave it empty
//we just map exactly our instance
xdr.instanceMode=GwXDRMappingDef::IS_SINGLE;
//those are the user configured values
//this instance is the one we use for the battery instance when we set up
//the N2K message
xdr.instanceId=instance;
xdr.xdrName=voltageTransducer;
if (!api->addXdrMapping(xdr)){