generate XDR field and selector defines
This commit is contained in:
parent
f0643b636a
commit
ffdfd917ae
|
@ -7,6 +7,7 @@ import inspect
|
||||||
import json
|
import json
|
||||||
import glob
|
import glob
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
import re
|
||||||
Import("env")
|
Import("env")
|
||||||
#print(env.Dump())
|
#print(env.Dump())
|
||||||
OWN_FILE="extra_script.py"
|
OWN_FILE="extra_script.py"
|
||||||
|
@ -172,7 +173,8 @@ def generateCfg(inFile,outFile,impl):
|
||||||
data+="#endif\n"
|
data+="#endif\n"
|
||||||
writeFileIfChanged(outFile,data)
|
writeFileIfChanged(outFile,data)
|
||||||
|
|
||||||
|
def labelFilter(label):
|
||||||
|
return re.sub("[^a-zA-Z0-9]","",re.sub("\([0-9]*\)","",label))
|
||||||
def generateXdrMappings(fp,oh,inFile=''):
|
def generateXdrMappings(fp,oh,inFile=''):
|
||||||
jdoc=json.load(fp)
|
jdoc=json.load(fp)
|
||||||
oh.write("static GwXDRTypeMapping* typeMappings[]={\n")
|
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(" new GwXDRTypeMapping(%d,%d,%d) /*%s:%s*/"%(cid,id,tc,cat,l))
|
||||||
oh.write("\n")
|
oh.write("\n")
|
||||||
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=[]
|
userTaskDirs=[]
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include "GWConfig.h"
|
#include "GWConfig.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "N2kMessages.h"
|
#include "N2kMessages.h"
|
||||||
|
#include "GwXdrTypeMappings.h"
|
||||||
/**
|
/**
|
||||||
* INVALID!!! - the next interface declaration will not work
|
* INVALID!!! - the next interface declaration will not work
|
||||||
* as it is not in the correct header file
|
* as it is not in the correct header file
|
||||||
|
@ -39,11 +40,20 @@ void exampleInit(GwApi *api){
|
||||||
if (!voltageTransducer.isEmpty()){
|
if (!voltageTransducer.isEmpty()){
|
||||||
int instance=api->getConfig()->getInt(GwConfigDefinitions::exInstanceId);
|
int instance=api->getConfig()->getInt(GwConfigDefinitions::exInstanceId);
|
||||||
GwXDRMappingDef xdr;
|
GwXDRMappingDef xdr;
|
||||||
|
//we send a battery message - so it is category battery
|
||||||
xdr.category=GwXDRCategory::XDRBAT;
|
xdr.category=GwXDRCategory::XDRBAT;
|
||||||
|
//we only need a conversion from N2K to NMEA0183
|
||||||
xdr.direction=GwXDRMappingDef::Direction::M_FROM2K;
|
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
|
//you can find the XDR field and selector definitions
|
||||||
xdr.selector=0; //refer to xdrconfig.json - there is no selector under Battery, so we can leave it empty
|
//in the generated GwXdrTypeMappings.h
|
||||||
xdr.instanceMode=GwXDRMappingDef::IS_SINGLE; //we just map exactly our instance
|
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.instanceId=instance;
|
||||||
xdr.xdrName=voltageTransducer;
|
xdr.xdrName=voltageTransducer;
|
||||||
if (!api->addXdrMapping(xdr)){
|
if (!api->addXdrMapping(xdr)){
|
||||||
|
|
Loading…
Reference in New Issue