Merge with latest 2.3

This commit is contained in:
Bertrand Songis
2020-01-14 17:34:13 +01:00
21 changed files with 170 additions and 105 deletions
+5 -3
View File
@@ -114,11 +114,13 @@ GeneralSettings::GeneralSettings()
speakerVolume = 12;
}
if (IS_HORUS(board)) {
strcpy(bluetoothName, "Horus");
if (IS_JUMPER_T16(board))
strcpy(bluetoothName, "t16");
else if (IS_HORUS(board)) {
strcpy(bluetoothName, "horus");
}
else if (IS_TARANIS_X9E(board) || IS_TARANIS_SMALL(board)) {
strcpy(bluetoothName, "Taranis");
strcpy(bluetoothName, "taranis");
}
templateSetup = g.profile[g.sessionId()].channelOrder();
+1 -1
View File
@@ -1536,7 +1536,7 @@ void MdiChild::writeEeprom() // write to Tx
qDebug() << "Searching for SD card, found" << radioPath;
if (radioPath.isEmpty()) {
qDebug() << "MdiChild::writeEeprom(): Horus radio not found";
QMessageBox::critical(this, CPN_STR_TTL_ERROR, tr("Unable to find Horus radio SD card!"));
QMessageBox::critical(this, CPN_STR_TTL_ERROR, tr("Unable to find radio SD card!"));
return;
}
if (saveFile(radioPath, false)) {
+1 -1
View File
@@ -319,7 +319,7 @@ bool readEeprom(const QString & filename, ProgressWidget * progress)
qDebug() << "Searching for SD card, found" << radioPath;
if (radioPath.isEmpty()) {
QMessageBox::critical(progress, CPN_STR_TTL_ERROR,
QCoreApplication::translate("RadioInterface", "Unable to find Horus radio SD card!"));
QCoreApplication::translate("RadioInterface", "Unable to find radio SD card!"));
return false;
}
RadioData radioData;
+9 -11
View File
@@ -14,12 +14,9 @@ local function create(zone, options)
end
local function update(wgt, options)
if (wgt==nil) then
print("update(nil)")
return
end
if (wgt == nil) then return end
wgt.options = options
print("TimerNumB:" .. options.Timer)
--print("TimerNumB:" .. options.Timer)
end
local function background(wgt)
@@ -28,11 +25,11 @@ end
------------------------------------------------------------
-- This size is for top bar wgts
-- Zone size: top bar widgets
local function refreshZoneTiny(wgt)
end
--- Size is 160x32 1/8th
--- Zone size: 160x32 1/8th
local function refreshZoneSmall(wgt)
local t1 = model.getTimer(wgt.options.Timer-1)
local timerInfo = string.format("T%s: ", wgt.options.Timer)
@@ -41,7 +38,8 @@ local function refreshZoneSmall(wgt)
return
end
--- Size is 225x98 1/4th (no sliders/trim)
--- Zone size: 180x70 1/4th (with sliders/trim)
--- Zone size: 225x98 1/4th (no sliders/trim)
local function refreshZoneMedium(wgt)
local t1 = model.getTimer(wgt.options.Timer-1)
--print(t1.value)
@@ -50,7 +48,7 @@ local function refreshZoneMedium(wgt)
lcd.drawTimer(wgt.zone.x, wgt.zone.y+3, t1.value, XXLSIZE + CUSTOM_COLOR)
end
--- Size is 192x152 1/2
--- Zone size: 192x152 1/2
local function refreshZoneLarge(wgt)
local t1 = model.getTimer(wgt.options.Timer-1)
--print(t1.value)
@@ -59,8 +57,8 @@ local function refreshZoneLarge(wgt)
lcd.drawTimer(wgt.zone.x, wgt.zone.y+15, t1.value, XXLSIZE + CUSTOM_COLOR)
end
--- Size is 390x172 1/1
--- Size is 460x252 1/1 (no sliders/trim/topbar)
--- Zone size: 390x172 1/1
--- Zone size: 460x252 1/1 (no sliders/trim/topbar)
local function refreshZoneXLarge(wgt)
local t1 = model.getTimer(wgt.options.Timer-1)
--print(t1.value)
+1 -1
View File
@@ -27,7 +27,7 @@
bool menuStatsGraph(event_t event)
{
switch(event) {
switch (event) {
case EVT_KEY_LONG(KEY_ENTER):
g_eeGeneral.globalTimer = 0;
storageDirty(EE_GENERAL);
+1
View File
@@ -10,6 +10,7 @@ endmacro(add_lua_export_target)
set(LUA_INCLUDES
-DCPUARM -DLUA -DLUA_INPUTS -DLUA_EXPORT_GENERATION -DSIMU
-I${RADIO_SRC_DIRECTORY}
-I${RADIO_SRC_DIR}/targets/${TARGET_DIR}
-I${RADIO_SRC_DIR}/thirdparty
-I${RADIO_SRC_DIR}/targets/common/arm/stm32
+4 -3
View File
@@ -201,7 +201,8 @@ void checkEeprom()
{
#if defined(RTC_BACKUP_RAM) && !defined(SIMU)
if (TIME_TO_BACKUP_RAM()) {
rambackupWrite();
if (!globalData.unexpectedShutdown)
rambackupWrite();
rambackupDirtyMsk = 0;
}
#endif
@@ -522,10 +523,10 @@ void perMain()
periodicTick();
DEBUG_TIMER_STOP(debugTimerPerMain1);
if (mainRequestFlags & (1 << REQUEST_FLIGHT_RESET)) {
if (mainRequestFlags & (1u << REQUEST_FLIGHT_RESET)) {
TRACE("Executing requested Flight Reset");
flightReset();
mainRequestFlags &= ~(1 << REQUEST_FLIGHT_RESET);
mainRequestFlags &= ~(1u << REQUEST_FLIGHT_RESET);
}
checkBacklight();
+3 -1
View File
@@ -505,10 +505,12 @@ extern uint8_t flightModeTransitionLast;
#define availableMemory() ((unsigned int)((unsigned char *)&_heap_end - heap))
#endif
extern uint32_t nextMixerTime[NUM_MODULES];
void evalFlightModeMixes(uint8_t mode, uint8_t tick10ms);
void evalMixes(uint8_t tick10ms);
void doMixerCalculations();
void scheduleNextMixerCalculation(uint8_t module, uint16_t period_ms);
void scheduleNextMixerCalculation(uint8_t module, uint32_t period_ms);
void checkTrims();
void perMain();
+6 -1
View File
@@ -372,6 +372,11 @@ inline int8_t defaultModuleChannels_M8(uint8_t idx)
return maxModuleChannels_M8(idx);
}
inline uint8_t sentModulePXXChannels(uint8_t idx)
{
return 8 + g_model.moduleData[idx].channelsCount;
}
inline int8_t sentModuleChannels(uint8_t idx)
{
if (isModuleCrossfire(idx))
@@ -381,7 +386,7 @@ inline int8_t sentModuleChannels(uint8_t idx)
else if (isModuleSBUS(idx))
return 16;
else
return 8 + g_model.moduleData[idx].channelsCount;
return sentModulePXXChannels(idx);
}
inline bool isDefaultModelRegistrationID()
+21 -16
View File
@@ -219,21 +219,21 @@ void enablePulsesExternalModule(uint8_t protocol)
}
}
void setupPulsesExternalModule(uint8_t protocol)
bool setupPulsesExternalModule(uint8_t protocol)
{
switch (protocol) {
#if defined(PXX1)
case PROTOCOL_CHANNELS_PXX1_PULSES:
extmodulePulsesData.pxx.setupFrame(EXTERNAL_MODULE);
scheduleNextMixerCalculation(EXTERNAL_MODULE, PXX_PULSES_PERIOD);
break;
return true;
#endif
#if defined(PXX1) && defined(HARDWARE_EXTERNAL_MODULE_SIZE_SML)
case PROTOCOL_CHANNELS_PXX1_SERIAL:
extmodulePulsesData.pxx_uart.setupFrame(EXTERNAL_MODULE);
scheduleNextMixerCalculation(EXTERNAL_MODULE, EXTMODULE_PXX1_SERIAL_PERIOD);
break;
return true;
#endif
#if defined(PXX2)
@@ -241,14 +241,14 @@ void setupPulsesExternalModule(uint8_t protocol)
case PROTOCOL_CHANNELS_PXX2_LOWSPEED:
extmodulePulsesData.pxx2.setupFrame(EXTERNAL_MODULE);
scheduleNextMixerCalculation(EXTERNAL_MODULE, PXX2_PERIOD);
break;
return true;
#endif
#if defined(SBUS)
case PROTOCOL_CHANNELS_SBUS:
setupPulsesSbus();
scheduleNextMixerCalculation(EXTERNAL_MODULE, SBUS_PERIOD);
break;
return true;
#endif
#if defined(DSM2)
@@ -257,32 +257,33 @@ void setupPulsesExternalModule(uint8_t protocol)
case PROTOCOL_CHANNELS_DSM2_DSMX:
setupPulsesDSM2();
scheduleNextMixerCalculation(EXTERNAL_MODULE, DSM2_PERIOD);
break;
return true;
#endif
#if defined(CROSSFIRE)
case PROTOCOL_CHANNELS_CROSSFIRE:
setupPulsesCrossfire();
scheduleNextMixerCalculation(EXTERNAL_MODULE, CROSSFIRE_PERIOD);
break;
return true;
#endif
#if defined(MULTIMODULE)
case PROTOCOL_CHANNELS_MULTIMODULE:
setupPulsesMultiExternalModule();
scheduleNextMixerCalculation(EXTERNAL_MODULE, MULTIMODULE_PERIOD);
break;
return true;
#endif
#if defined(PPM)
case PROTOCOL_CHANNELS_PPM:
setupPulsesPPMExternalModule();
scheduleNextMixerCalculation(EXTERNAL_MODULE, PPM_PERIOD(EXTERNAL_MODULE));
break;
return true;
#endif
default:
break;
scheduleNextMixerCalculation(EXTERNAL_MODULE, 50/*ms*/);
return false;
}
}
@@ -338,7 +339,9 @@ bool setupPulsesInternalModule(uint8_t protocol)
#if defined(PXX1) && defined(INTMODULE_USART)
case PROTOCOL_CHANNELS_PXX1_SERIAL:
intmodulePulsesData.pxx_uart.setupFrame(INTERNAL_MODULE);
#if !defined(INTMODULE_HEARTBEAT)
#if defined(INTMODULE_HEARTBEAT)
scheduleNextMixerCalculation(INTERNAL_MODULE, INTMODULE_PXX1_SERIAL_PERIOD + 1 /* backup */);
#else
scheduleNextMixerCalculation(INTERNAL_MODULE, INTMODULE_PXX1_SERIAL_PERIOD);
#endif
return true;
@@ -351,11 +354,13 @@ bool setupPulsesInternalModule(uint8_t protocol)
if (moduleState[INTERNAL_MODULE].mode == MODULE_MODE_SPECTRUM_ANALYSER || moduleState[INTERNAL_MODULE].mode == MODULE_MODE_POWER_METER) {
scheduleNextMixerCalculation(INTERNAL_MODULE, PXX2_TOOLS_PERIOD);
}
#if !defined(INTMODULE_HEARTBEAT)
else {
#if defined(INTMODULE_HEARTBEAT)
scheduleNextMixerCalculation(INTERNAL_MODULE, PXX2_PERIOD + 1 /* backup */);
#else
scheduleNextMixerCalculation(INTERNAL_MODULE, PXX2_PERIOD);
}
#endif
}
return result;
}
#endif
@@ -375,7 +380,8 @@ bool setupPulsesInternalModule(uint8_t protocol)
#endif
default:
return true;
scheduleNextMixerCalculation(INTERNAL_MODULE, 50/*ms*/);
return false;
}
}
@@ -410,8 +416,7 @@ bool setupPulsesExternalModule()
return false;
}
else {
setupPulsesExternalModule(protocol);
return true;
return setupPulsesExternalModule(protocol);
}
}
+10 -10
View File
@@ -69,17 +69,17 @@ void Pxx1Pulses<PxxTransport>::addExtraFlags(uint8_t module)
}
template <class PxxTransport>
void Pxx1Pulses<PxxTransport>::addChannels(uint8_t port, uint8_t sendFailsafe, uint8_t sendUpperChannels)
void Pxx1Pulses<PxxTransport>::addChannels(uint8_t moduleIdx, uint8_t sendFailsafe, uint8_t sendUpperChannels)
{
uint16_t pulseValue = 0;
uint16_t pulseValueLow = 0;
for (int8_t i=0; i<8; i++) {
for (uint8_t i = 0; i < 8; i++) {
if (sendFailsafe) {
if (g_model.moduleData[port].failsafeMode == FAILSAFE_HOLD) {
if (g_model.moduleData[moduleIdx].failsafeMode == FAILSAFE_HOLD) {
pulseValue = (i < sendUpperChannels ? 4095 : 2047);
}
else if (g_model.moduleData[port].failsafeMode == FAILSAFE_NOPULSES) {
else if (g_model.moduleData[moduleIdx].failsafeMode == FAILSAFE_NOPULSES) {
pulseValue = (i < sendUpperChannels ? 2048 : 0);
}
else {
@@ -92,7 +92,7 @@ void Pxx1Pulses<PxxTransport>::addChannels(uint8_t port, uint8_t sendFailsafe, u
pulseValue = 2048;
}
else {
failsafeValue += 2*PPM_CH_CENTER(8+g_model.moduleData[port].channelsStart+i) - 2*PPM_CENTER;
failsafeValue += 2*PPM_CH_CENTER(8+g_model.moduleData[moduleIdx].channelsStart+i) - 2*PPM_CENTER;
pulseValue = limit(2049, (failsafeValue * 512 / 682) + 3072, 4094);
}
}
@@ -105,7 +105,7 @@ void Pxx1Pulses<PxxTransport>::addChannels(uint8_t port, uint8_t sendFailsafe, u
pulseValue = 0;
}
else {
failsafeValue += 2*PPM_CH_CENTER(g_model.moduleData[port].channelsStart+i) - 2*PPM_CENTER;
failsafeValue += 2*PPM_CH_CENTER(g_model.moduleData[moduleIdx].channelsStart+i) - 2*PPM_CENTER;
pulseValue = limit(1, (failsafeValue * 512 / 682) + 1024, 2046);
}
}
@@ -113,12 +113,12 @@ void Pxx1Pulses<PxxTransport>::addChannels(uint8_t port, uint8_t sendFailsafe, u
}
else {
if (i < sendUpperChannels) {
int channel = 8 + g_model.moduleData[port].channelsStart + i;
int channel = 8 + g_model.moduleData[moduleIdx].channelsStart + i;
int value = channelOutputs[channel] + 2*PPM_CH_CENTER(channel) - 2*PPM_CENTER;
pulseValue = limit(2049, (value * 512 / 682) + 3072, 4094);
}
else if (i < sentModuleChannels(port)) {
int channel = g_model.moduleData[port].channelsStart + i;
else if (i < sentModulePXXChannels(moduleIdx)) {
int channel = g_model.moduleData[moduleIdx].channelsStart + i;
int value = channelOutputs[channel] + 2*PPM_CH_CENTER(channel) - 2*PPM_CENTER;
pulseValue = limit(1, (value * 512 / 682) + 1024, 2046);
}
@@ -186,7 +186,7 @@ void Pxx1Pulses<PxxTransport>::setupFrame(uint8_t module)
moduleState[module].counter = 1000;
}
add8ChannelsFrame(module, 0, sendFailsafe);
if (sentModuleChannels(module) > 8) {
if (sentModulePXXChannels(module) > 8) {
add8ChannelsFrame(module, 8, sendFailsafe);
}
return;
+4
View File
@@ -25,8 +25,12 @@
#include "crc.h"
struct HeartbeatCapture {
#if !defined(INTMODULE_USART)
uint32_t timestamp;
#endif
#if defined(DEBUG_LATENCY)
uint32_t count;
#endif
uint8_t valid;
};
+1 -1
View File
@@ -25,7 +25,7 @@ uint8_t storageDirtyMsk;
tmr10ms_t storageDirtyTime10ms;
#if defined(RTC_BACKUP_RAM)
uint8_t rambackupDirtyMsk;
uint8_t rambackupDirtyMsk = EE_GENERAL | EE_MODEL;
tmr10ms_t rambackupDirtyTime10ms;
#endif
@@ -20,9 +20,9 @@
#include "opentx.h"
#if defined(INTMODULE_HEARTBEAT_GPIO)
volatile HeartbeatCapture heartbeatCapture;
#if defined(INTMODULE_HEARTBEAT_GPIO)
void init_intmodule_heartbeat()
{
GPIO_InitTypeDef GPIO_InitStructure;
@@ -69,11 +69,13 @@ void check_intmodule_heartbeat()
{
if (EXTI_GetITStatus(INTMODULE_HEARTBEAT_EXTI_LINE) != RESET) {
#if defined(INTMODULE_USART)
heartbeatCapture.timestamp = RTOS_GET_MS();
nextMixerTime[INTERNAL_MODULE] = RTOS_GET_MS();
#else
heartbeatCapture.timestamp = getTmr2MHz();
#endif
#if defined(DEBUG_LATENCY)
heartbeatCapture.count++;
#endif
EXTI_ClearITPendingBit(INTMODULE_HEARTBEAT_EXTI_LINE);
}
}
+36 -1
View File
@@ -204,11 +204,46 @@ set(STM32LIB_SRC
STM32F4xx_StdPeriph_Driver/src/stm32f4xx_dma2d.c
)
MACRO(GET_GCC_INCLUDE_PATH gcc_include_path)
if (WIN32)
execute_process(COMMAND arm-none-eabi-gcc -v -x c -E NUL ERROR_VARIABLE _gcc_output OUTPUT_QUIET)
else()
execute_process(COMMAND arm-none-eabi-gcc -v -x c -E - INPUT_FILE /dev/null ERROR_VARIABLE _gcc_output OUTPUT_QUIET)
endif()
# Build an array of string from the GCC output
string(REPLACE "\n" ";" _gcc_output "${_gcc_output}")
set(_capture_include FALSE)
set(_include_path "")
# Go through the lines and capture between '"#include <...> search starts here:"' and 'End of search list.'
foreach(_line ${_gcc_output})
if(${_line} STREQUAL "End of search list.")
set(_capture_include FALSE)
endif()
if(_capture_include)
# Remove the leading and trailing empty characters
string(REPLACE "\r" "" _line ${_line})
string(SUBSTRING "${_line}" 1 -1 _line)
set(_include_path "${_include_path}" "-I${_line}")
endif()
if(${_line} STREQUAL "#include <...> search starts here:")
set(_capture_include TRUE)
endif()
endforeach()
set(${gcc_include_path} ${_include_path})
ENDMACRO()
if(PYTHONINTERP_FOUND)
GET_GCC_INCLUDE_PATH(arm_gcc_include_path)
add_custom_command(
OUTPUT ${PROJECT_BINARY_DIR}/radio/src/datacopy.cpp
WORKING_DIRECTORY ${RADIO_DIRECTORY}/src
COMMAND ${PYTHON_EXECUTABLE} ${RADIO_DIRECTORY}/util/generate_datacopy.py datastructs.h -DPCBHORUS -DPCBX10 -DCPUARM -DCOLORLCD -DBACKUP -Itargets/horus > ${PROJECT_BINARY_DIR}/radio/src/datacopy.cpp
COMMAND ${PYTHON_EXECUTABLE} ${RADIO_DIRECTORY}/util/generate_datacopy.py datastructs.h -DPCBHORUS -DPCBX10 -DCPUARM -DSTM32F4 -DSTM32F429_439xx -DCOLORLCD -DBACKUP -DSIMU -I. -Itargets/horus -Itargets/common/arm/stm32 -I${THIRDPARTY_DIR} -I${THIRDPARTY_DIR}/STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/CMSIS/Device/ST/STM32F4xx/Include ${arm_gcc_include_path} > ${PROJECT_BINARY_DIR}/radio/src/datacopy.cpp
DEPENDS ${RADIO_DIRECTORY}/src/datastructs.h ${RADIO_DIRECTORY}/util/generate_datacopy.py
)
add_custom_target(datacopy
+2 -2
View File
@@ -21,8 +21,8 @@
#ifndef _BOARD_H_
#define _BOARD_H_
#include "../definitions.h"
#include "../opentx_constants.h"
#include "definitions.h"
#include "opentx_constants.h"
#include "board_common.h"
#include "hal.h"
+2 -2
View File
@@ -22,8 +22,8 @@
#define _BOARD_H_
#include <inttypes.h>
#include "../definitions.h"
#include "../opentx_constants.h"
#include "definitions.h"
#include "opentx_constants.h"
#include "board_common.h"
#include "hal.h"
+13 -27
View File
@@ -73,9 +73,9 @@ bool isForcePowerOffRequested()
return false;
}
bool isModuleSynchronous(uint8_t module)
bool isModuleSynchronous(uint8_t moduleIdx)
{
uint8_t protocol = moduleState[module].protocol;
uint8_t protocol = moduleState[moduleIdx].protocol;
if (protocol == PROTOCOL_CHANNELS_PXX2_HIGHSPEED || protocol == PROTOCOL_CHANNELS_PXX2_LOWSPEED || protocol == PROTOCOL_CHANNELS_CROSSFIRE || protocol == PROTOCOL_CHANNELS_NONE)
return true;
#if defined(INTMODULE_USART) || defined(EXTMODULE_USART)
@@ -85,16 +85,16 @@ bool isModuleSynchronous(uint8_t module)
return false;
}
void sendSynchronousPulses()
void sendSynchronousPulses(uint8_t runMask)
{
#if defined(HARDWARE_INTERNAL_MODULE)
if (isModuleSynchronous(INTERNAL_MODULE)) {
if ((runMask & (1 << INTERNAL_MODULE)) && isModuleSynchronous(INTERNAL_MODULE)) {
if (setupPulsesInternalModule())
intmoduleSendNextFrame();
}
#endif
if (isModuleSynchronous(EXTERNAL_MODULE)) {
if ((runMask & (1 << EXTERNAL_MODULE)) && isModuleSynchronous(EXTERNAL_MODULE)) {
if (setupPulsesExternalModule())
extmoduleSendNextFrame();
}
@@ -104,7 +104,6 @@ uint32_t nextMixerTime[NUM_MODULES];
TASK_FUNCTION(mixerTask)
{
static uint32_t lastRunTime;
s_pulses_paused = true;
while (true) {
@@ -134,35 +133,22 @@ TASK_FUNCTION(mixerTask)
#endif
uint32_t now = RTOS_GET_MS();
bool run = false;
uint8_t runMask = 0;
if (now - lastRunTime >= 10) {
// run at least every 10ms
run = true;
}
#if defined(INTMODULE_USART) && defined(INTMODULE_HEARTBEAT)
if ((moduleState[INTERNAL_MODULE].protocol == PROTOCOL_CHANNELS_PXX2_HIGHSPEED || moduleState[INTERNAL_MODULE].protocol == PROTOCOL_CHANNELS_PXX1_SERIAL) && heartbeatCapture.valid && heartbeatCapture.timestamp > lastRunTime) {
run = true;
}
#endif
if (now == nextMixerTime[0]) {
run = true;
if (now >= nextMixerTime[0]) {
runMask |= (1 << 0);
}
#if NUM_MODULES >= 2
if (now == nextMixerTime[1]) {
run = true;
if (now >= nextMixerTime[1]) {
runMask |= (1 << 1);
}
#endif
if (!run) {
if (!runMask) {
continue; // go back to sleep
}
lastRunTime = now;
if (!s_pulses_paused) {
uint16_t t0 = getTmr2MHz();
@@ -197,12 +183,12 @@ TASK_FUNCTION(mixerTask)
if (t0 > maxMixerDuration)
maxMixerDuration = t0;
sendSynchronousPulses();
sendSynchronousPulses(runMask);
}
}
}
void scheduleNextMixerCalculation(uint8_t module, uint16_t period_ms)
void scheduleNextMixerCalculation(uint8_t module, uint32_t period_ms)
{
// Schedule next mixer calculation time,
+2 -2
View File
@@ -21,9 +21,9 @@
#ifndef _FRSKY_H_
#define _FRSKY_H_
#include "../definitions.h"
#include "../../definitions.h"
#include "telemetry_holders.h"
#include "../io/frsky_pxx2.h"
#include "../../io/frsky_pxx2.h"
// Receive buffer state machine state enum
enum FrSkyDataState {
+43 -19
View File
@@ -1,30 +1,33 @@
#!/usr/bin/env python
from __future__ import print_function
import sys
import clang.cindex
import time
import os
if sys.platform == "darwin":
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')
elif sys.platform.startswith("linux"):
for version in ("7", "6.0", "3.8"):
libclang = "/usr/lib/x86_64-linux-gnu/libclang-%s.so.1" % version
if os.path.exists(libclang):
clang.cindex.Config.set_library_file(libclang)
break
structs = []
extrastructs = []
def find_libclang():
if sys.platform == "darwin":
for path in ("/usr/local/Cellar/llvm/6.0.0/lib/libclang.dylib",
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libclang.dylib",
"/Library/Developer/CommandLineTools/usr/lib/libclang.dylib"):
if os.path.exists(path):
return path
elif sys.platform.startswith("linux"):
for version in ("7", "6.0", "3.8"):
path = "/usr/lib/x86_64-linux-gnu/libclang-%s.so.1" % version
if os.path.exists(path):
return path
for path in ("/usr/local/lib/libclang.so",
"/usr/lib/libclang.so"):
if os.path.exists(path):
return path
def build_struct(cursor, anonymousUnion=False):
if not anonymousUnion:
structs.append(cursor.spelling)
@@ -98,7 +101,28 @@ 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()))
index = clang.cindex.Index.create()
translation_unit = index.parse(sys.argv[1], ['-x', 'c++', '-std=c++11'] + sys.argv[2:])
header()
build(translation_unit.cursor)
def print_translation_unit_diags(diags, prefix=''):
for diag in diags:
print(prefix + str(diag), file=sys.stderr)
print_translation_unit_diags(diag.children, ' ' + prefix)
def main():
libclang = find_libclang()
if libclang:
# print(libclang, file=sys.stderr)
clang.cindex.Config.set_library_file(libclang)
index = clang.cindex.Index.create()
translation_unit = index.parse(sys.argv[1], ['-x', 'c++', '-std=c++11'] + sys.argv[2:])
if translation_unit.diagnostics:
print_translation_unit_diags(translation_unit.diagnostics)
sys.exit(-1)
header()
build(translation_unit.cursor)
if __name__ == "__main__":
main()