From 4880497db533eea993fc7abec61c91e4779a4733 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Thu, 5 Jul 2018 19:04:28 +0200 Subject: [PATCH] generate_datacopy.py fixes (#6015) * fix generate_datacopy on osx * more datacopy fixes * added support for linux & llvm-3.8 (default on debian stretch) --- radio/src/datastructs.h | 31 ++++++++------ radio/src/storage/datacopy.cpp | 59 +++++++++++--------------- radio/src/targets/horus/CMakeLists.txt | 2 +- radio/util/generate_datacopy.py | 18 +++++--- 4 files changed, 55 insertions(+), 55 deletions(-) diff --git a/radio/src/datastructs.h b/radio/src/datastructs.h index e2a0773c6..e04346ac7 100644 --- a/radio/src/datastructs.h +++ b/radio/src/datastructs.h @@ -22,7 +22,10 @@ // i.e. BACKUP RAM Backup/Restore functions #include + +#include "board.h" #include "dataconstants.h" +#include "definitions.h" #if defined(CPUARM) #define ARM_FIELD(x) x; @@ -266,10 +269,10 @@ PACK(struct CustomFunctionData { NOBACKUP(CFN_SPARE_TYPE spare); }) all; - PACK(struct { + NOBACKUP(PACK(struct { int32_t val1; NOBACKUP(CFN_SPARE_TYPE val2); - }) clear; + }) clear); }); uint8_t active; }); @@ -591,11 +594,11 @@ PACK(struct MavlinkTelemetryData { PACK(struct TelemetrySensor { union { uint16_t id; // data identifier, for FrSky we can reuse existing ones. Source unit is derived from type. - uint16_t persistentValue; + NOBACKUP(uint16_t persistentValue); }; union { uint8_t instance; // instance ID to allow handling multiple instances of same value type, for FrSky can be the physical ID of the sensor - uint8_t formula; + NOBACKUP(uint8_t formula); }; char label[TELEM_LABEL_LEN]; // user defined label uint8_t type:1; // 0=custom / 1=calculated @@ -608,27 +611,27 @@ PACK(struct TelemetrySensor { uint8_t onlyPositive:1; uint8_t subId:3; union { - PACK(struct { + NOBACKUP(PACK(struct { uint16_t ratio; int16_t offset; - }) custom; - PACK(struct { + }) custom); + NOBACKUP(PACK(struct { uint8_t source; uint8_t index; uint16_t spare; - }) cell; - PACK(struct { + }) cell); + NOBACKUP(PACK(struct { int8_t sources[4]; - }) calc; - PACK(struct { + }) calc); + NOBACKUP(PACK(struct { uint8_t source; uint8_t spare[3]; - }) consumption; - PACK(struct { + }) consumption); + NOBACKUP(PACK(struct { uint8_t gps; uint8_t alt; uint16_t spare; - }) dist; + }) dist); uint32_t param; }; NOBACKUP( diff --git a/radio/src/storage/datacopy.cpp b/radio/src/storage/datacopy.cpp index 103737df7..8b4d95cdd 100644 --- a/radio/src/storage/datacopy.cpp +++ b/radio/src/storage/datacopy.cpp @@ -1,4 +1,4 @@ -//This file was auto-generated by generate_datacopy.py script on Sat May 7 11:05:00 2016. Do not edit this file! +//This file was auto-generated by generate_datacopy.py script on Mon Jul 2 14:20:48 2018. Do not edit this file! @@ -91,7 +91,7 @@ void copytrim_t(A * dest, B * src) template void copyFlightModeData(A * dest, B * src) { - for (int i=0; itrim[i], &src->trim[i]); } dest->swtch = src->swtch; @@ -101,6 +101,14 @@ void copyFlightModeData(A * dest, B * src) memcpy(dest->gvars, src->gvars, sizeof(dest->gvars)); } +template +void copyCurveData(A * dest, B * src) +{ + dest->type = src->type; + dest->smooth = src->smooth; + dest->points = src->points; +} + template void copyGVarData(A * dest, B * src) { @@ -122,6 +130,7 @@ void copyTimerData(A * dest, B * src) dest->minuteBeep = src->minuteBeep; dest->persistent = src->persistent; dest->countdownStart = src->countdownStart; + dest->direction = src->direction; } template @@ -146,10 +155,13 @@ void copyScriptData(A * dest, B * src) } template -void copyFrSkyRSSIAlarm(A * dest, B * src) +void copyRssiAlarmData(A * dest, B * src) { - dest->level = src->level; - dest->value = src->value; + dest->disabled = src->disabled; + dest->spare = src->spare; + dest->warning = src->warning; + dest->spare2 = src->spare2; + dest->critical = src->critical; } template @@ -161,9 +173,6 @@ void copyFrSkyTelemetryData(A * dest, B * src) dest->varioCenterMin = src->varioCenterMin; dest->varioMin = src->varioMin; dest->varioMax = src->varioMax; - for (int i=0; i<2; i++) { - copyFrSkyRSSIAlarm(&dest->rssiAlarms[i], &src->rssiAlarms[i]); - } } template @@ -181,7 +190,7 @@ void copyTelemetrySensor(A * dest, B * src) dest->persistent = src->persistent; dest->onlyPositive = src->onlyPositive; dest->subId = src->subId; - copyTelemetrySensor_custom(&dest->custom, &src->custom); + dest->param = src->param; } template @@ -205,23 +214,6 @@ void copyModelHeader(A * dest, B * src) memcpy(dest->modelId, src->modelId, sizeof(dest->modelId)); } -template -void copyZone(A * dest, B * src) -{ - dest->x = src->x; - dest->y = src->y; - dest->w = src->w; - dest->h = src->h; -} - -template -void copyZoneOption(A * dest, B * src) -{ - dest->name = src->name; - dest->type = src->type; - dest->deflt = src->deflt; -} - template void copyCustomScreenData(A * dest, B * src) { @@ -257,7 +249,9 @@ void copyModelData(A * dest, B * src) for (int i=0; i<64; i++) { copyExpoData(&dest->expoData[i], &src->expoData[i]); } - memcpy(dest->curves, src->curves, sizeof(dest->curves)); + for (int i=0; i<32; i++) { + copyCurveData(&dest->curves[i], &src->curves[i]); + } memcpy(dest->points, src->points, sizeof(dest->points)); for (int i=0; i<64; i++) { copyLogicalSwitchData(&dest->logicalSw[i], &src->logicalSw[i]); @@ -309,10 +303,12 @@ void copyTrainerData(A * dest, B * src) template void copyRadioData(A * dest, B * src) { - for (int i=0; i<11; i++) { + for (int i=0; i<13; i++) { copyCalibData(&dest->calib[i], &src->calib[i]); } dest->stickMode = src->stickMode; + dest->telemetryBaudrate = src->telemetryBaudrate; + dest->splashSpares = src->splashSpares; dest->switchesDelay = src->switchesDelay; for (int i=0; i<64; i++) { copyCustomFunctionData(&dest->customFn[i], &src->customFn[i]); @@ -330,13 +326,6 @@ void copyCustomFunctionData_all(A * dest, B * src) dest->param = src->param; } -template -void copyTelemetrySensor_custom(A * dest, B * src) -{ - dest->ratio = src->ratio; - dest->offset = src->offset; -} - template void copyModuleData_ppm(A * dest, B * src) { diff --git a/radio/src/targets/horus/CMakeLists.txt b/radio/src/targets/horus/CMakeLists.txt index 4d5ded96c..565b102b6 100644 --- a/radio/src/targets/horus/CMakeLists.txt +++ b/radio/src/targets/horus/CMakeLists.txt @@ -155,7 +155,7 @@ set(STM32LIB_SRC if(PYTHONINTERP_FOUND) add_custom_target(datacopy WORKING_DIRECTORY ${RADIO_DIRECTORY}/src - COMMAND ${PYTHON_EXECUTABLE} ${RADIO_DIRECTORY}/util/generate_datacopy.py datastructs.h -DPCBHORUS -DCPUARM -DCOLORLCD -DCPUARM -DBACKUP > storage/datacopy.cpp + COMMAND ${PYTHON_EXECUTABLE} ${RADIO_DIRECTORY}/util/generate_datacopy.py datastructs.h -DPCBHORUS -DPCBX10 -DCPUARM -DCOLORLCD -DBACKUP -DVIRTUAL_INPUTS -Itargets/horus > storage/datacopy.cpp DEPENDS ${RADIO_DIRECTORY}/src/datastructs.h ${RADIO_DIRECTORY}/util/generate_datacopy.py ) endif() diff --git a/radio/util/generate_datacopy.py b/radio/util/generate_datacopy.py index 493ece838..4097de061 100755 --- a/radio/util/generate_datacopy.py +++ b/radio/util/generate_datacopy.py @@ -8,8 +8,16 @@ import time import os if sys.platform == "darwin": - clang.cindex.Config.set_library_file('/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libclang.dylib') + if os.path.exists('/usr/local/Cellar/llvm/6.0.0/lib/libclang.dylib'): + clang.cindex.Config.set_library_file('/usr/local/Cellar/llvm/6.0.0/lib/libclang.dylib') + elif os.path.exists('/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libclang.dylib'): + clang.cindex.Config.set_library_file('/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libclang.dylib') + elif os.path.exists('/Library/Developer/CommandLineTools/usr/lib/libclang.dylib'): + clang.cindex.Config.set_library_file('/Library/Developer/CommandLineTools/usr/lib/libclang.dylib') +if sys.platform == "linux2": + if os.path.exists('/usr/lib/x86_64-linux-gnu/libclang-3.8.so.1'): + clang.cindex.Config.set_library_file('/usr/lib/x86_64-linux-gnu/libclang-3.8.so.1') structs = [] extrastructs = [] @@ -41,15 +49,15 @@ def build_struct(cursor, anonymousUnion=False): elif c.kind == clang.cindex.CursorKind.FIELD_DECL: copy_decl(c, c.spelling) - if not anonymousUnion: print("}\n") def build(cursor): result = [] for c in cursor.get_children(): - if c.kind == clang.cindex.CursorKind.STRUCT_DECL: - build_struct(c) + if c.location.file.name == sys.argv[1]: + if c.kind == clang.cindex.CursorKind.STRUCT_DECL: + build_struct(c) for c, spelling in extrastructs: print("template \nvoid copy%s(A * dest, B * src)\n{" % spelling) build_struct(c, True) @@ -67,7 +75,7 @@ def copy_decl(c, 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: + elif len(childs)==1 and childs[0].kind == clang.cindex.CursorKind.STRUCT_DECL and not childs[0].spelling: # inline declared structs if c.semantic_parent.spelling: spellingFunc = c.semantic_parent.spelling + "_" + spelling