mirror of
https://github.com/opentx/opentx.git
synced 2025-07-14 03:49:52 +03:00
Also backup members inside unions,
the code is a bit more complicated since unions can have structs or simple types. Also change Telemetry sensor to be a struct, since a class with all public is identical to a struct in C++
This commit is contained in:
parent
c24219cbcd
commit
86076bbf32
3 changed files with 94 additions and 19 deletions
|
@ -622,9 +622,7 @@ PACK(struct MavlinkTelemetryData {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined(CPUARM)
|
#if defined(CPUARM)
|
||||||
// TODO struct as others
|
PACK(struct TelemetrySensor {
|
||||||
PACK(class TelemetrySensor {
|
|
||||||
public:
|
|
||||||
union {
|
union {
|
||||||
uint16_t id; // data identifier, for FrSky we can reuse existing ones. Source unit is derived from type.
|
uint16_t id; // data identifier, for FrSky we can reuse existing ones. Source unit is derived from type.
|
||||||
uint16_t persistentValue;
|
uint16_t persistentValue;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
//This file was auto-generated by generate_datacopy.py script on Wed Mar 16 20:12:19 2016. Do not edit this file!
|
//This file was auto-generated by generate_datacopy.py script on Fri Mar 25 14:17:31 2016. Do not edit this file!
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -77,6 +77,7 @@ void copyCustomFunctionData(A * dest, B * src)
|
||||||
{
|
{
|
||||||
dest->swtch = src->swtch;
|
dest->swtch = src->swtch;
|
||||||
dest->func = src->func;
|
dest->func = src->func;
|
||||||
|
copyCustomFunctionData_all(&dest->all, &src->all);
|
||||||
dest->active = src->active;
|
dest->active = src->active;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,6 +166,24 @@ void copyFrSkyTelemetryData(A * dest, B * src)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class A, class B>
|
||||||
|
void copyTelemetrySensor(A * dest, B * src)
|
||||||
|
{
|
||||||
|
dest->id = src->id;
|
||||||
|
dest->instance = src->instance;
|
||||||
|
memcpy(dest->label, src->label, sizeof(dest->label));
|
||||||
|
dest->type = src->type;
|
||||||
|
dest->unit = src->unit;
|
||||||
|
dest->prec = src->prec;
|
||||||
|
dest->autoOffset = src->autoOffset;
|
||||||
|
dest->filter = src->filter;
|
||||||
|
dest->logs = src->logs;
|
||||||
|
dest->persistent = src->persistent;
|
||||||
|
dest->onlyPositive = src->onlyPositive;
|
||||||
|
dest->subId = src->subId;
|
||||||
|
copyTelemetrySensor_custom(&dest->custom, &src->custom);
|
||||||
|
}
|
||||||
|
|
||||||
template <class A, class B>
|
template <class A, class B>
|
||||||
void copyModuleData(A * dest, B * src)
|
void copyModuleData(A * dest, B * src)
|
||||||
{
|
{
|
||||||
|
@ -305,3 +324,17 @@ void copyRadioData(A * dest, B * src)
|
||||||
dest->potsConfig = src->potsConfig;
|
dest->potsConfig = src->potsConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class A, class B>
|
||||||
|
void copyCustomFunctionData_all(A * dest, B * src)
|
||||||
|
{
|
||||||
|
dest->val = src->val;
|
||||||
|
dest->mode = src->mode;
|
||||||
|
dest->param = src->param;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class A, class B>
|
||||||
|
void copyTelemetrySensor_custom(A * dest, B * src)
|
||||||
|
{
|
||||||
|
dest->ratio = src->ratio;
|
||||||
|
dest->offset = src->offset;
|
||||||
|
}
|
||||||
|
|
|
@ -12,33 +12,77 @@ if sys.platform == "darwin":
|
||||||
|
|
||||||
|
|
||||||
structs = []
|
structs = []
|
||||||
|
extrastructs = []
|
||||||
|
|
||||||
|
def build_struct(cursor, anonymousUnion=False):
|
||||||
|
if not anonymousUnion:
|
||||||
|
structs.append(cursor.spelling)
|
||||||
|
print("template <class A, class B>\nvoid copy%s(A * dest, B * src)\n{" % cursor.spelling)
|
||||||
|
|
||||||
def build_struct(cursor):
|
|
||||||
structs.append(cursor.spelling)
|
|
||||||
print("template <class A, class B>\nvoid copy%s(A * dest, B * src)\n{" % cursor.spelling)
|
|
||||||
for c in cursor.get_children():
|
for c in cursor.get_children():
|
||||||
if c.kind == clang.cindex.CursorKind.FIELD_DECL:
|
if c.kind == clang.cindex.CursorKind.UNION_DECL:
|
||||||
if c.type.get_array_size() > 0:
|
if c.spelling:
|
||||||
if c.type.get_array_element_type().spelling in structs:
|
raise "Cannot handle non anonymous unions"
|
||||||
print(" for (int i=0; i<%d; i++) {" % c.type.get_array_size())
|
|
||||||
print(" copy%s(&dest->%s[i], &src->%s[i]);" % (c.type.get_array_element_type().spelling, c.spelling, c.spelling))
|
copiedUnionMember = False
|
||||||
print(" }")
|
for uc in c.get_children():
|
||||||
|
if not uc.spelling or uc.kind == clang.cindex.CursorKind.PACKED_ATTR:
|
||||||
|
# Ignore
|
||||||
|
pass
|
||||||
else:
|
else:
|
||||||
print(" memcpy(dest->%s, src->%s, sizeof(dest->%s));" % (c.spelling, c.spelling, c.spelling))
|
# per default we copy only the first member of a union and warn if there are more
|
||||||
elif c.type.get_declaration().spelling in structs:
|
# members (declare the other members NOBACKUP)
|
||||||
print(" copy%s(&dest->%s, &src->%s);" % (c.type.get_declaration().spelling, c.spelling, c.spelling))
|
if copiedUnionMember:
|
||||||
else:
|
print ("Warning more than one union member (%s) in anynomous union inside struct %s, consider NOBACKUP statements" % (uc.spelling, cursor.spelling), file=sys.stderr)
|
||||||
print(" dest->%s = src->%s;" % (c.spelling, c.spelling))
|
else:
|
||||||
print("}\n")
|
copy_decl(uc, uc.spelling)
|
||||||
|
copiedUnionMember = True
|
||||||
|
|
||||||
|
elif c.kind == clang.cindex.CursorKind.FIELD_DECL:
|
||||||
|
copy_decl(c, c.spelling)
|
||||||
|
|
||||||
|
|
||||||
|
if not anonymousUnion:
|
||||||
|
print("}\n")
|
||||||
|
|
||||||
def build(cursor):
|
def build(cursor):
|
||||||
result = []
|
result = []
|
||||||
for c in cursor.get_children():
|
for c in cursor.get_children():
|
||||||
if c.kind == clang.cindex.CursorKind.STRUCT_DECL:
|
if c.kind == clang.cindex.CursorKind.STRUCT_DECL:
|
||||||
build_struct(c)
|
build_struct(c)
|
||||||
|
for c, spelling in extrastructs:
|
||||||
|
print("template <class A, class B>\nvoid copy%s(A * dest, B * src)\n{" % spelling)
|
||||||
|
build_struct(c, True)
|
||||||
|
print ("}\n")
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def copy_decl(c, spelling):
|
||||||
|
childs = [ch for ch in c.get_children()]
|
||||||
|
if c.type.get_array_size() > 0:
|
||||||
|
if c.type.get_array_element_type().spelling in structs:
|
||||||
|
print(" for (int i=0; i<%d; i++) {" % c.type.get_array_size())
|
||||||
|
print(" copy%s(&dest->%s[i], &src->%s[i]);" % (c.type.get_array_element_type().spelling, spelling, spelling))
|
||||||
|
print(" }")
|
||||||
|
else:
|
||||||
|
print(" memcpy(dest->%s, src->%s, sizeof(dest->%s));" % (spelling, spelling, spelling))
|
||||||
|
elif c.type.kind == clang.cindex.TypeKind.UNEXPOSED and len(childs)==1 and childs[0].kind == clang.cindex.CursorKind.STRUCT_DECL:
|
||||||
|
# inline declared structs
|
||||||
|
if c.semantic_parent.spelling:
|
||||||
|
spellingFunc = c.semantic_parent.spelling + "_" + spelling
|
||||||
|
else:
|
||||||
|
spellingFunc = c.semantic_parent.semantic_parent.spelling + "_" + spelling
|
||||||
|
|
||||||
|
extrastructs.append((childs[0], spellingFunc))
|
||||||
|
print(" copy%s(&dest->%s, &src->%s);" % (spellingFunc, spelling, spelling))
|
||||||
|
|
||||||
|
elif c.type.get_declaration().spelling in structs:
|
||||||
|
print(" copy%s(&dest->%s, &src->%s);" % (c.type.get_declaration().spelling, spelling, spelling))
|
||||||
|
else:
|
||||||
|
print(" dest->%s = src->%s;" % (spelling, spelling))
|
||||||
|
|
||||||
|
|
||||||
def header():
|
def header():
|
||||||
print("//This file was auto-generated by %s script on %s. Do not edit this file!\n\n\n" % (os.path.basename(sys.argv[0]), time.asctime()))
|
print("//This file was auto-generated by %s script on %s. Do not edit this file!\n\n\n" % (os.path.basename(sys.argv[0]), time.asctime()))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue