1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-23 16:25:31 +03:00

Merge pull request #1869 from martinbudden/bf_pg_cli

Changes to CLI to ease conversion to parameter groups
This commit is contained in:
J Blackman 2016-12-28 03:40:15 +11:00 committed by GitHub
commit c772ca6ea5
11 changed files with 491 additions and 299 deletions

View file

@ -101,6 +101,9 @@
#define pidConfig(x) (&masterConfig.pidConfig) #define pidConfig(x) (&masterConfig.pidConfig)
#define adjustmentProfile(x) (&masterConfig.adjustmentProfile) #define adjustmentProfile(x) (&masterConfig.adjustmentProfile)
#define modeActivationProfile(x) (&masterConfig.modeActivationProfile) #define modeActivationProfile(x) (&masterConfig.modeActivationProfile)
#define servoProfile(x) (&masterConfig.servoProfile)
#define customMotorMixer(i) (&masterConfig.customMotorMixer[i])
#define customServoMixer(i) (&masterConfig.customServoMixer[i])
// System-wide // System-wide
@ -121,7 +124,7 @@ typedef struct master_s {
servoMixerConfig_t servoMixerConfig; servoMixerConfig_t servoMixerConfig;
servoMixer_t customServoMixer[MAX_SERVO_RULES]; servoMixer_t customServoMixer[MAX_SERVO_RULES];
// Servo-related stuff // Servo-related stuff
servoParam_t servoConf[MAX_SUPPORTED_SERVOS]; // servo configuration servoProfile_t servoProfile;
// gimbal-related configuration // gimbal-related configuration
gimbalConfig_t gimbalConfig; gimbalConfig_t gimbalConfig;
#endif #endif

View file

@ -71,6 +71,16 @@ void pgResetCurrent(const pgRegistry_t *reg)
} }
} }
bool pgResetCopy(void *copy, pgn_t pgn)
{
const pgRegistry_t *reg = pgFind(pgn);
if (reg) {
pgResetInstance(reg, copy);
return true;
}
return false;
}
void pgLoad(const pgRegistry_t* reg, int profileIndex, const void *from, int size, int version) void pgLoad(const pgRegistry_t* reg, int profileIndex, const void *from, int size, int version)
{ {
pgResetInstance(reg, pgOffset(reg, profileIndex)); pgResetInstance(reg, pgOffset(reg, profileIndex));

View file

@ -17,6 +17,9 @@
#pragma once #pragma once
#include <stdint.h>
#include <stdbool.h>
typedef uint16_t pgn_t; typedef uint16_t pgn_t;
// parameter group registry flags // parameter group registry flags
@ -225,5 +228,6 @@ void pgLoad(const pgRegistry_t* reg, int profileIndex, const void *from, int siz
int pgStore(const pgRegistry_t* reg, void *to, int size, uint8_t profileIndex); int pgStore(const pgRegistry_t* reg, void *to, int size, uint8_t profileIndex);
void pgResetAll(int profileCount); void pgResetAll(int profileCount);
void pgResetCurrent(const pgRegistry_t *reg); void pgResetCurrent(const pgRegistry_t *reg);
bool pgResetCopy(void *copy, pgn_t pgn);
void pgReset(const pgRegistry_t* reg, int profileIndex); void pgReset(const pgRegistry_t* reg, int profileIndex);
void pgActivateProfile(int profileIndex); void pgActivateProfile(int profileIndex);

View file

@ -783,13 +783,13 @@ void createDefaultConfig(master_t *config)
#ifdef USE_SERVOS #ifdef USE_SERVOS
// servos // servos
for (int i = 0; i < MAX_SUPPORTED_SERVOS; i++) { for (int i = 0; i < MAX_SUPPORTED_SERVOS; i++) {
config->servoConf[i].min = DEFAULT_SERVO_MIN; config->servoProfile.servoConf[i].min = DEFAULT_SERVO_MIN;
config->servoConf[i].max = DEFAULT_SERVO_MAX; config->servoProfile.servoConf[i].max = DEFAULT_SERVO_MAX;
config->servoConf[i].middle = DEFAULT_SERVO_MIDDLE; config->servoProfile.servoConf[i].middle = DEFAULT_SERVO_MIDDLE;
config->servoConf[i].rate = 100; config->servoProfile.servoConf[i].rate = 100;
config->servoConf[i].angleAtMin = DEFAULT_SERVO_MIN_ANGLE; config->servoProfile.servoConf[i].angleAtMin = DEFAULT_SERVO_MIN_ANGLE;
config->servoConf[i].angleAtMax = DEFAULT_SERVO_MAX_ANGLE; config->servoProfile.servoConf[i].angleAtMax = DEFAULT_SERVO_MAX_ANGLE;
config->servoConf[i].forwardFromChannel = CHANNEL_FORWARDING_DISABLED; config->servoProfile.servoConf[i].forwardFromChannel = CHANNEL_FORWARDING_DISABLED;
} }
// gimbal // gimbal
@ -909,7 +909,7 @@ void activateConfig(void)
); );
#ifdef USE_SERVOS #ifdef USE_SERVOS
servoUseConfigs(&masterConfig.servoMixerConfig, masterConfig.servoConf, &masterConfig.gimbalConfig); servoUseConfigs(&masterConfig.servoMixerConfig, masterConfig.servoProfile.servoConf, &masterConfig.gimbalConfig);
#endif #endif

View file

@ -677,25 +677,25 @@ static bool mspFcProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst, mspPostProcessFn
break; break;
case MSP_SERVO_CONFIGURATIONS: case MSP_SERVO_CONFIGURATIONS:
for (int i = 0; i < MAX_SUPPORTED_SERVOS; i++) { for (int i = 0; i < MAX_SUPPORTED_SERVOS; i++) {
sbufWriteU16(dst, masterConfig.servoConf[i].min); sbufWriteU16(dst, servoProfile()->servoConf[i].min);
sbufWriteU16(dst, masterConfig.servoConf[i].max); sbufWriteU16(dst, servoProfile()->servoConf[i].max);
sbufWriteU16(dst, masterConfig.servoConf[i].middle); sbufWriteU16(dst, servoProfile()->servoConf[i].middle);
sbufWriteU8(dst, masterConfig.servoConf[i].rate); sbufWriteU8(dst, servoProfile()->servoConf[i].rate);
sbufWriteU8(dst, masterConfig.servoConf[i].angleAtMin); sbufWriteU8(dst, servoProfile()->servoConf[i].angleAtMin);
sbufWriteU8(dst, masterConfig.servoConf[i].angleAtMax); sbufWriteU8(dst, servoProfile()->servoConf[i].angleAtMax);
sbufWriteU8(dst, masterConfig.servoConf[i].forwardFromChannel); sbufWriteU8(dst, servoProfile()->servoConf[i].forwardFromChannel);
sbufWriteU32(dst, masterConfig.servoConf[i].reversedSources); sbufWriteU32(dst, servoProfile()->servoConf[i].reversedSources);
} }
break; break;
case MSP_SERVO_MIX_RULES: case MSP_SERVO_MIX_RULES:
for (int i = 0; i < MAX_SERVO_RULES; i++) { for (int i = 0; i < MAX_SERVO_RULES; i++) {
sbufWriteU8(dst, masterConfig.customServoMixer[i].targetChannel); sbufWriteU8(dst, customServoMixer(i)->targetChannel);
sbufWriteU8(dst, masterConfig.customServoMixer[i].inputSource); sbufWriteU8(dst, customServoMixer(i)->inputSource);
sbufWriteU8(dst, masterConfig.customServoMixer[i].rate); sbufWriteU8(dst, customServoMixer(i)->rate);
sbufWriteU8(dst, masterConfig.customServoMixer[i].speed); sbufWriteU8(dst, customServoMixer(i)->speed);
sbufWriteU8(dst, masterConfig.customServoMixer[i].min); sbufWriteU8(dst, customServoMixer(i)->min);
sbufWriteU8(dst, masterConfig.customServoMixer[i].max); sbufWriteU8(dst, customServoMixer(i)->max);
sbufWriteU8(dst, masterConfig.customServoMixer[i].box); sbufWriteU8(dst, customServoMixer(i)->box);
} }
break; break;
#endif #endif
@ -1419,14 +1419,14 @@ static mspResult_e mspFcProcessInCommand(uint8_t cmdMSP, sbuf_t *src)
if (i >= MAX_SUPPORTED_SERVOS) { if (i >= MAX_SUPPORTED_SERVOS) {
return MSP_RESULT_ERROR; return MSP_RESULT_ERROR;
} else { } else {
masterConfig.servoConf[i].min = sbufReadU16(src); servoProfile()->servoConf[i].min = sbufReadU16(src);
masterConfig.servoConf[i].max = sbufReadU16(src); servoProfile()->servoConf[i].max = sbufReadU16(src);
masterConfig.servoConf[i].middle = sbufReadU16(src); servoProfile()->servoConf[i].middle = sbufReadU16(src);
masterConfig.servoConf[i].rate = sbufReadU8(src); servoProfile()->servoConf[i].rate = sbufReadU8(src);
masterConfig.servoConf[i].angleAtMin = sbufReadU8(src); servoProfile()->servoConf[i].angleAtMin = sbufReadU8(src);
masterConfig.servoConf[i].angleAtMax = sbufReadU8(src); servoProfile()->servoConf[i].angleAtMax = sbufReadU8(src);
masterConfig.servoConf[i].forwardFromChannel = sbufReadU8(src); servoProfile()->servoConf[i].forwardFromChannel = sbufReadU8(src);
masterConfig.servoConf[i].reversedSources = sbufReadU32(src); servoProfile()->servoConf[i].reversedSources = sbufReadU32(src);
} }
#endif #endif
break; break;
@ -1437,13 +1437,13 @@ static mspResult_e mspFcProcessInCommand(uint8_t cmdMSP, sbuf_t *src)
if (i >= MAX_SERVO_RULES) { if (i >= MAX_SERVO_RULES) {
return MSP_RESULT_ERROR; return MSP_RESULT_ERROR;
} else { } else {
masterConfig.customServoMixer[i].targetChannel = sbufReadU8(src); customServoMixer(i)->targetChannel = sbufReadU8(src);
masterConfig.customServoMixer[i].inputSource = sbufReadU8(src); customServoMixer(i)->inputSource = sbufReadU8(src);
masterConfig.customServoMixer[i].rate = sbufReadU8(src); customServoMixer(i)->rate = sbufReadU8(src);
masterConfig.customServoMixer[i].speed = sbufReadU8(src); customServoMixer(i)->speed = sbufReadU8(src);
masterConfig.customServoMixer[i].min = sbufReadU8(src); customServoMixer(i)->min = sbufReadU8(src);
masterConfig.customServoMixer[i].max = sbufReadU8(src); customServoMixer(i)->max = sbufReadU8(src);
masterConfig.customServoMixer[i].box = sbufReadU8(src); customServoMixer(i)->box = sbufReadU8(src);
loadCustomServoMixer(); loadCustomServoMixer();
} }
#endif #endif

View file

@ -110,6 +110,10 @@ typedef struct servoMixerConfig_s{
int8_t servo_lowpass_enable; // enable/disable lowpass filter int8_t servo_lowpass_enable; // enable/disable lowpass filter
} servoMixerConfig_t; } servoMixerConfig_t;
typedef struct servoProfile_s {
servoParam_t servoConf[MAX_SUPPORTED_SERVOS];
} servoProfile_t;
extern int16_t servo[MAX_SUPPORTED_SERVOS]; extern int16_t servo[MAX_SUPPORTED_SERVOS];
void servoTable(void); void servoTable(void);

View file

@ -122,8 +122,8 @@ void cliDfu(char *cmdLine);
static void cliDump(char *cmdLine); static void cliDump(char *cmdLine);
static void cliDiff(char *cmdLine); static void cliDiff(char *cmdLine);
static void printConfig(char *cmdLine, bool doDiff); static void printConfig(char *cmdLine, bool doDiff);
static void cliDumpProfile(uint8_t profileIndex, uint8_t dumpMask, master_t *defaultProfile); static void cliDumpProfile(uint8_t profileIndex, uint8_t dumpMask, const master_t *defaultProfile);
static void cliDumpRateProfile(uint8_t rateProfileIndex, uint8_t dumpMask, master_t *defaultProfile) ; static void cliDumpRateProfile(uint8_t rateProfileIndex, uint8_t dumpMask, const master_t *defaultProfile) ;
static void cliExit(char *cmdline); static void cliExit(char *cmdline);
static void cliFeature(char *cmdline); static void cliFeature(char *cmdline);
static void cliMotor(char *cmdline); static void cliMotor(char *cmdline);
@ -155,7 +155,7 @@ static void cliTasks(char *cmdline);
static void cliVersion(char *cmdline); static void cliVersion(char *cmdline);
static void cliRxRange(char *cmdline); static void cliRxRange(char *cmdline);
#if (FLASH_SIZE > 64) #if (FLASH_SIZE > 64)
static void printResource(uint8_t dumpMask, master_t *defaultConfig); static void printResource(uint8_t dumpMask, const master_t *defaultConfig);
static void cliResource(char *cmdline); static void cliResource(char *cmdline);
#endif #endif
#ifdef GPS #ifdef GPS
@ -1013,7 +1013,7 @@ typedef union {
static void cliSetVar(const clivalue_t *var, const int_float_value_t value); static void cliSetVar(const clivalue_t *var, const int_float_value_t value);
static void cliPrintVar(const clivalue_t *var, uint32_t full); static void cliPrintVar(const clivalue_t *var, uint32_t full);
static void cliPrintVarDefault(const clivalue_t *var, uint32_t full, master_t *defaultConfig); static void cliPrintVarDefault(const clivalue_t *var, uint32_t full, const master_t *defaultConfig);
static void cliPrintVarRange(const clivalue_t *var); static void cliPrintVarRange(const clivalue_t *var);
static void cliPrint(const char *str); static void cliPrint(const char *str);
static void cliPrintf(const char *fmt, ...); static void cliPrintf(const char *fmt, ...);
@ -1087,16 +1087,16 @@ static bool isEmpty(const char *string)
return *string == '\0'; return *string == '\0';
} }
static void printRxFail(uint8_t dumpMask, master_t *defaultConfig) static void printRxFail(uint8_t dumpMask, const rxConfig_t *defaultRxConfig)
{ {
// print out rxConfig failsafe settings // print out rxConfig failsafe settings
rxFailsafeChannelConfiguration_t *channelFailsafeConfiguration; const rxFailsafeChannelConfiguration_t *channelFailsafeConfiguration;
rxFailsafeChannelConfiguration_t *channelFailsafeConfigurationDefault; const rxFailsafeChannelConfiguration_t *channelFailsafeConfigurationDefault;
bool equalsDefault; bool equalsDefault;
bool requireValue; bool requireValue;
for (uint32_t channel = 0; channel < MAX_SUPPORTED_RC_CHANNEL_COUNT; channel++) { for (uint32_t channel = 0; channel < MAX_SUPPORTED_RC_CHANNEL_COUNT; channel++) {
channelFailsafeConfiguration = &rxConfig()->failsafe_channel_configurations[channel]; channelFailsafeConfiguration = &rxConfig()->failsafe_channel_configurations[channel];
channelFailsafeConfigurationDefault = &defaultConfig->rxConfig.failsafe_channel_configurations[channel]; channelFailsafeConfigurationDefault = &defaultRxConfig->failsafe_channel_configurations[channel];
equalsDefault = channelFailsafeConfiguration->mode == channelFailsafeConfigurationDefault->mode equalsDefault = channelFailsafeConfiguration->mode == channelFailsafeConfigurationDefault->mode
&& channelFailsafeConfiguration->step == channelFailsafeConfigurationDefault->step; && channelFailsafeConfiguration->step == channelFailsafeConfigurationDefault->step;
requireValue = channelFailsafeConfiguration->mode == RX_FAILSAFE_MODE_SET; requireValue = channelFailsafeConfiguration->mode == RX_FAILSAFE_MODE_SET;
@ -1210,16 +1210,13 @@ static void cliRxFail(char *cmdline)
} }
} }
static void printAux(uint8_t dumpMask, master_t *defaultConfig) static void printAux(uint8_t dumpMask, const modeActivationProfile_t *defaultModeActivationProfile)
{ {
// print out aux channel settings // print out aux channel settings
modeActivationCondition_t *mac;
modeActivationCondition_t *macDefault;
bool equalsDefault;
for (uint32_t i = 0; i < MAX_MODE_ACTIVATION_CONDITION_COUNT; i++) { for (uint32_t i = 0; i < MAX_MODE_ACTIVATION_CONDITION_COUNT; i++) {
mac = &modeActivationProfile()->modeActivationConditions[i]; const modeActivationCondition_t *mac = &modeActivationProfile()->modeActivationConditions[i];
macDefault = &defaultConfig->modeActivationProfile.modeActivationConditions[i]; const modeActivationCondition_t *macDefault = &defaultModeActivationProfile->modeActivationConditions[i];
equalsDefault = mac->modeId == macDefault->modeId const bool equalsDefault = mac->modeId == macDefault->modeId
&& mac->auxChannelIndex == macDefault->auxChannelIndex && mac->auxChannelIndex == macDefault->auxChannelIndex
&& mac->range.startStep == macDefault->range.startStep && mac->range.startStep == macDefault->range.startStep
&& mac->range.endStep == macDefault->range.endStep; && mac->range.endStep == macDefault->range.endStep;
@ -1281,18 +1278,14 @@ static void cliAux(char *cmdline)
} }
} }
static void printSerial(uint8_t dumpMask, master_t *defaultConfig) static void printSerial(uint8_t dumpMask, const serialConfig_t *serialConfigDefault)
{ {
serialConfig_t *serialConfig; const serialConfig_t *serialConfig = serialConfig();
serialConfig_t *serialConfigDefault;
bool equalsDefault;
for (uint32_t i = 0; i < SERIAL_PORT_COUNT; i++) { for (uint32_t i = 0; i < SERIAL_PORT_COUNT; i++) {
serialConfig = &masterConfig.serialConfig;
if (!serialIsPortAvailable(serialConfig->portConfigs[i].identifier)) { if (!serialIsPortAvailable(serialConfig->portConfigs[i].identifier)) {
continue; continue;
}; };
serialConfigDefault = &defaultConfig->serialConfig; const bool equalsDefault = serialConfig->portConfigs[i].identifier == serialConfigDefault->portConfigs[i].identifier
equalsDefault = serialConfig->portConfigs[i].identifier == serialConfigDefault->portConfigs[i].identifier
&& serialConfig->portConfigs[i].functionMask == serialConfigDefault->portConfigs[i].functionMask && serialConfig->portConfigs[i].functionMask == serialConfigDefault->portConfigs[i].functionMask
&& serialConfig->portConfigs[i].msp_baudrateIndex == serialConfigDefault->portConfigs[i].msp_baudrateIndex && serialConfig->portConfigs[i].msp_baudrateIndex == serialConfigDefault->portConfigs[i].msp_baudrateIndex
&& serialConfig->portConfigs[i].gps_baudrateIndex == serialConfigDefault->portConfigs[i].gps_baudrateIndex && serialConfig->portConfigs[i].gps_baudrateIndex == serialConfigDefault->portConfigs[i].gps_baudrateIndex
@ -1479,16 +1472,13 @@ static void cliSerialPassthrough(char *cmdline)
} }
#endif #endif
static void printAdjustmentRange(uint8_t dumpMask, master_t *defaultConfig) static void printAdjustmentRange(uint8_t dumpMask, const adjustmentProfile_t *defaultAdjustmentProfile)
{ {
// print out adjustment ranges channel settings // print out adjustment ranges channel settings
adjustmentRange_t *ar;
adjustmentRange_t *arDefault;
bool equalsDefault;
for (uint32_t i = 0; i < MAX_ADJUSTMENT_RANGE_COUNT; i++) { for (uint32_t i = 0; i < MAX_ADJUSTMENT_RANGE_COUNT; i++) {
ar = &adjustmentProfile()->adjustmentRanges[i]; const adjustmentRange_t *ar = &adjustmentProfile()->adjustmentRanges[i];
arDefault = &defaultConfig->adjustmentProfile.adjustmentRanges[i]; const adjustmentRange_t *arDefault = &defaultAdjustmentProfile->adjustmentRanges[i];
equalsDefault = ar->auxChannelIndex == arDefault->auxChannelIndex const bool equalsDefault = ar->auxChannelIndex == arDefault->auxChannelIndex
&& ar->range.startStep == arDefault->range.startStep && ar->range.startStep == arDefault->range.startStep
&& ar->range.endStep == arDefault->range.endStep && ar->range.endStep == arDefault->range.endStep
&& ar->adjustmentFunction == arDefault->adjustmentFunction && ar->adjustmentFunction == arDefault->adjustmentFunction
@ -1577,24 +1567,24 @@ static void cliAdjustmentRange(char *cmdline)
} }
#ifndef USE_QUAD_MIXER_ONLY #ifndef USE_QUAD_MIXER_ONLY
static void printMotorMix(uint8_t dumpMask, master_t *defaultConfig) static void printMotorMix(uint8_t dumpMask, const motorMixer_t *defaultCustomMotorMixer)
{ {
char buf0[8]; char buf0[8];
char buf1[8]; char buf1[8];
char buf2[8]; char buf2[8];
char buf3[8]; char buf3[8];
for (uint32_t i = 0; i < MAX_SUPPORTED_MOTORS; i++) { for (uint32_t i = 0; i < MAX_SUPPORTED_MOTORS; i++) {
if (masterConfig.customMotorMixer[i].throttle == 0.0f) if (customMotorMixer(i)->throttle == 0.0f)
break; break;
float thr = masterConfig.customMotorMixer[i].throttle; float thr = customMotorMixer(i)->throttle;
float roll = masterConfig.customMotorMixer[i].roll; float roll = customMotorMixer(i)->roll;
float pitch = masterConfig.customMotorMixer[i].pitch; float pitch = customMotorMixer(i)->pitch;
float yaw = masterConfig.customMotorMixer[i].yaw; float yaw = customMotorMixer(i)->yaw;
float thrDefault = defaultConfig->customMotorMixer[i].throttle; float thrDefault = defaultCustomMotorMixer[i].throttle;
float rollDefault = defaultConfig->customMotorMixer[i].roll; float rollDefault = defaultCustomMotorMixer[i].roll;
float pitchDefault = defaultConfig->customMotorMixer[i].pitch; float pitchDefault = defaultCustomMotorMixer[i].pitch;
float yawDefault = defaultConfig->customMotorMixer[i].yaw; float yawDefault = defaultCustomMotorMixer[i].yaw;
bool equalsDefault = thr == thrDefault && roll == rollDefault && pitch == pitchDefault && yaw == yawDefault; const bool equalsDefault = thr == thrDefault && roll == rollDefault && pitch == pitchDefault && yaw == yawDefault;
const char *format = "mmix %d %s %s %s %s\r\n"; const char *format = "mmix %d %s %s %s %s\r\n";
cliDefaultPrintf(dumpMask, equalsDefault, format, cliDefaultPrintf(dumpMask, equalsDefault, format,
@ -1627,7 +1617,7 @@ static void cliMotorMix(char *cmdline)
} else if (strncasecmp(cmdline, "reset", 5) == 0) { } else if (strncasecmp(cmdline, "reset", 5) == 0) {
// erase custom mixer // erase custom mixer
for (uint32_t i = 0; i < MAX_SUPPORTED_MOTORS; i++) for (uint32_t i = 0; i < MAX_SUPPORTED_MOTORS; i++)
masterConfig.customMotorMixer[i].throttle = 0.0f; customMotorMixer(i)->throttle = 0.0f;
} else if (strncasecmp(cmdline, "load", 4) == 0) { } else if (strncasecmp(cmdline, "load", 4) == 0) {
ptr = nextArg(cmdline); ptr = nextArg(cmdline);
if (ptr) { if (ptr) {
@ -1651,22 +1641,22 @@ static void cliMotorMix(char *cmdline)
if (i < MAX_SUPPORTED_MOTORS) { if (i < MAX_SUPPORTED_MOTORS) {
ptr = nextArg(ptr); ptr = nextArg(ptr);
if (ptr) { if (ptr) {
masterConfig.customMotorMixer[i].throttle = fastA2F(ptr); customMotorMixer(i)->throttle = fastA2F(ptr);
check++; check++;
} }
ptr = nextArg(ptr); ptr = nextArg(ptr);
if (ptr) { if (ptr) {
masterConfig.customMotorMixer[i].roll = fastA2F(ptr); customMotorMixer(i)->roll = fastA2F(ptr);
check++; check++;
} }
ptr = nextArg(ptr); ptr = nextArg(ptr);
if (ptr) { if (ptr) {
masterConfig.customMotorMixer[i].pitch = fastA2F(ptr); customMotorMixer(i)->pitch = fastA2F(ptr);
check++; check++;
} }
ptr = nextArg(ptr); ptr = nextArg(ptr);
if (ptr) { if (ptr) {
masterConfig.customMotorMixer[i].yaw = fastA2F(ptr); customMotorMixer(i)->yaw = fastA2F(ptr);
check++; check++;
} }
if (check != 4) { if (check != 4) {
@ -1681,14 +1671,14 @@ static void cliMotorMix(char *cmdline)
#endif #endif
} }
static void printRxRange(uint8_t dumpMask, master_t *defaultConfig) static void printRxRange(uint8_t dumpMask, const rxConfig_t *defaultRxConfig)
{ {
rxChannelRangeConfiguration_t *channelRangeConfiguration; const rxChannelRangeConfiguration_t *channelRangeConfiguration;
rxChannelRangeConfiguration_t *channelRangeConfigurationDefault; const rxChannelRangeConfiguration_t *channelRangeConfigurationDefault;
bool equalsDefault; bool equalsDefault;
for (uint32_t i = 0; i < NON_AUX_CHANNEL_COUNT; i++) { for (uint32_t i = 0; i < NON_AUX_CHANNEL_COUNT; i++) {
channelRangeConfiguration = &rxConfig()->channelRanges[i]; channelRangeConfiguration = &rxConfig()->channelRanges[i];
channelRangeConfigurationDefault = &defaultConfig->rxConfig.channelRanges[i]; channelRangeConfigurationDefault = &defaultRxConfig->channelRanges[i];
equalsDefault = channelRangeConfiguration->min == channelRangeConfigurationDefault->min equalsDefault = channelRangeConfiguration->min == channelRangeConfigurationDefault->min
&& channelRangeConfiguration->max == channelRangeConfigurationDefault->max; && channelRangeConfiguration->max == channelRangeConfigurationDefault->max;
const char *format = "rxrange %u %u %u\r\n"; const char *format = "rxrange %u %u %u\r\n";
@ -1748,17 +1738,16 @@ static void cliRxRange(char *cmdline)
} }
#ifdef LED_STRIP #ifdef LED_STRIP
static void printLed(uint8_t dumpMask, master_t *defaultConfig) static void printLed(uint8_t dumpMask, const ledStripConfig_t *defaultLedStripConfig)
{ {
bool equalsDefault;
ledConfig_t ledConfig; ledConfig_t ledConfig;
ledConfig_t ledConfigDefault; ledConfig_t ledConfigDefault;
char ledConfigBuffer[20]; char ledConfigBuffer[20];
char ledConfigDefaultBuffer[20]; char ledConfigDefaultBuffer[20];
for (uint32_t i = 0; i < LED_MAX_STRIP_LENGTH; i++) { for (uint32_t i = 0; i < LED_MAX_STRIP_LENGTH; i++) {
ledConfig = ledStripConfig()->ledConfigs[i]; ledConfig = ledStripConfig()->ledConfigs[i];
ledConfigDefault = defaultConfig->ledStripConfig.ledConfigs[i]; ledConfigDefault = defaultLedStripConfig->ledConfigs[i];
equalsDefault = ledConfig == ledConfigDefault; const bool equalsDefault = ledConfig == ledConfigDefault;
generateLedConfig(&ledConfig, ledConfigBuffer, sizeof(ledConfigBuffer)); generateLedConfig(&ledConfig, ledConfigBuffer, sizeof(ledConfigBuffer));
generateLedConfig(&ledConfigDefault, ledConfigDefaultBuffer, sizeof(ledConfigDefaultBuffer)); generateLedConfig(&ledConfigDefault, ledConfigDefaultBuffer, sizeof(ledConfigDefaultBuffer));
const char *format = "led %u %s\r\n"; const char *format = "led %u %s\r\n";
@ -1788,15 +1777,12 @@ static void cliLed(char *cmdline)
} }
} }
static void printColor(uint8_t dumpMask, master_t *defaultConfig) static void printColor(uint8_t dumpMask, const ledStripConfig_t *defaultLedStripConfig)
{ {
hsvColor_t *color;
hsvColor_t *colorDefault;
bool equalsDefault;
for (uint32_t i = 0; i < LED_CONFIGURABLE_COLOR_COUNT; i++) { for (uint32_t i = 0; i < LED_CONFIGURABLE_COLOR_COUNT; i++) {
color = &ledStripConfig()->colors[i]; const hsvColor_t *color = &ledStripConfig()->colors[i];
colorDefault = &defaultConfig->ledStripConfig.colors[i]; const hsvColor_t *colorDefault = &defaultLedStripConfig->colors[i];
equalsDefault = color->h == colorDefault->h const bool equalsDefault = color->h == colorDefault->h
&& color->s == colorDefault->s && color->s == colorDefault->s
&& color->v == colorDefault->v; && color->v == colorDefault->v;
const char *format = "color %u %d,%u,%u\r\n"; const char *format = "color %u %d,%u,%u\r\n";
@ -1836,12 +1822,12 @@ static void cliColor(char *cmdline)
} }
} }
static void printModeColor(uint8_t dumpMask, master_t *defaultConfig) static void printModeColor(uint8_t dumpMask, const ledStripConfig_t *defaultLedStripConfig)
{ {
for (uint32_t i = 0; i < LED_MODE_COUNT; i++) { for (uint32_t i = 0; i < LED_MODE_COUNT; i++) {
for (uint32_t j = 0; j < LED_DIRECTION_COUNT; j++) { for (uint32_t j = 0; j < LED_DIRECTION_COUNT; j++) {
int colorIndex = ledStripConfig()->modeColors[i].color[j]; int colorIndex = ledStripConfig()->modeColors[i].color[j];
int colorIndexDefault = defaultConfig->ledStripConfig.modeColors[i].color[j]; int colorIndexDefault = defaultLedStripConfig->modeColors[i].color[j];
const char *format = "mode_color %u %u %u\r\n"; const char *format = "mode_color %u %u %u\r\n";
cliDefaultPrintf(dumpMask, colorIndex == colorIndexDefault, format, i, j, colorIndexDefault); cliDefaultPrintf(dumpMask, colorIndex == colorIndexDefault, format, i, j, colorIndexDefault);
cliDumpPrintf(dumpMask, colorIndex == colorIndexDefault, format, i, j, colorIndex); cliDumpPrintf(dumpMask, colorIndex == colorIndexDefault, format, i, j, colorIndex);
@ -1851,13 +1837,13 @@ static void printModeColor(uint8_t dumpMask, master_t *defaultConfig)
const char *format = "mode_color %u %u %u\r\n"; const char *format = "mode_color %u %u %u\r\n";
for (uint32_t j = 0; j < LED_SPECIAL_COLOR_COUNT; j++) { for (uint32_t j = 0; j < LED_SPECIAL_COLOR_COUNT; j++) {
int colorIndex = ledStripConfig()->specialColors.color[j]; int colorIndex = ledStripConfig()->specialColors.color[j];
int colorIndexDefault = defaultConfig->ledStripConfig.specialColors.color[j]; int colorIndexDefault = defaultLedStripConfig->specialColors.color[j];
cliDefaultPrintf(dumpMask, colorIndex == colorIndexDefault, format, LED_SPECIAL, j, colorIndexDefault); cliDefaultPrintf(dumpMask, colorIndex == colorIndexDefault, format, LED_SPECIAL, j, colorIndexDefault);
cliDumpPrintf(dumpMask, colorIndex == colorIndexDefault, format, LED_SPECIAL, j, colorIndex); cliDumpPrintf(dumpMask, colorIndex == colorIndexDefault, format, LED_SPECIAL, j, colorIndex);
} }
int ledStripAuxChannel = ledStripConfig()->ledstrip_aux_channel; int ledStripAuxChannel = ledStripConfig()->ledstrip_aux_channel;
int ledStripAuxChannelDefault = defaultConfig->ledStripConfig.ledstrip_aux_channel; int ledStripAuxChannelDefault = defaultLedStripConfig->ledstrip_aux_channel;
cliDefaultPrintf(dumpMask, ledStripAuxChannel == ledStripAuxChannelDefault, format, LED_AUX_CHANNEL, 0, ledStripAuxChannelDefault); cliDefaultPrintf(dumpMask, ledStripAuxChannel == ledStripAuxChannelDefault, format, LED_AUX_CHANNEL, 0, ledStripAuxChannelDefault);
cliDumpPrintf(dumpMask, ledStripAuxChannel == ledStripAuxChannelDefault, format, LED_AUX_CHANNEL, 0, ledStripAuxChannel); cliDumpPrintf(dumpMask, ledStripAuxChannel == ledStripAuxChannelDefault, format, LED_AUX_CHANNEL, 0, ledStripAuxChannel);
} }
@ -1895,13 +1881,13 @@ static void cliModeColor(char *cmdline)
#endif #endif
#ifdef USE_SERVOS #ifdef USE_SERVOS
static void printServo(uint8_t dumpMask, master_t *defaultConfig) static void printServo(uint8_t dumpMask, servoProfile_t *defaultServoProfile)
{ {
// print out servo settings // print out servo settings
for (uint32_t i = 0; i < MAX_SUPPORTED_SERVOS; i++) { for (uint32_t i = 0; i < MAX_SUPPORTED_SERVOS; i++) {
servoParam_t *servoConf = &masterConfig.servoConf[i]; const servoParam_t *servoConf = &servoProfile()->servoConf[i];
servoParam_t *servoConfDefault = &defaultConfig->servoConf[i]; const servoParam_t *servoConfDefault = &defaultServoProfile->servoConf[i];
bool equalsDefault = servoConf->min == servoConfDefault->min const bool equalsDefault = servoConf->min == servoConfDefault->min
&& servoConf->max == servoConfDefault->max && servoConf->max == servoConfDefault->max
&& servoConf->middle == servoConfDefault->middle && servoConf->middle == servoConfDefault->middle
&& servoConf->angleAtMin == servoConfDefault->angleAtMax && servoConf->angleAtMin == servoConfDefault->angleAtMax
@ -1981,7 +1967,7 @@ static void cliServo(char *cmdline)
return; return;
} }
servo = &masterConfig.servoConf[i]; servo = &servoProfile()->servoConf[i];
if ( if (
arguments[MIN] < PWM_PULSE_MIN || arguments[MIN] > PWM_PULSE_MAX || arguments[MIN] < PWM_PULSE_MIN || arguments[MIN] > PWM_PULSE_MAX ||
@ -2009,16 +1995,16 @@ static void cliServo(char *cmdline)
#endif #endif
#ifdef USE_SERVOS #ifdef USE_SERVOS
static void printServoMix(uint8_t dumpMask, master_t *defaultConfig) static void printServoMix(uint8_t dumpMask, const master_t *defaultConfig)
{ {
for (uint32_t i = 0; i < MAX_SERVO_RULES; i++) { for (uint32_t i = 0; i < MAX_SERVO_RULES; i++) {
servoMixer_t customServoMixer = masterConfig.customServoMixer[i]; servoMixer_t customServoMixer = *customServoMixer(i);
servoMixer_t customServoMixerDefault = defaultConfig->customServoMixer[i]; servoMixer_t customServoMixerDefault = defaultConfig->customServoMixer[i];
if (customServoMixer.rate == 0) { if (customServoMixer.rate == 0) {
break; break;
} }
bool equalsDefault = customServoMixer.targetChannel == customServoMixerDefault.targetChannel const bool equalsDefault = customServoMixer.targetChannel == customServoMixerDefault.targetChannel
&& customServoMixer.inputSource == customServoMixerDefault.inputSource && customServoMixer.inputSource == customServoMixerDefault.inputSource
&& customServoMixer.rate == customServoMixerDefault.rate && customServoMixer.rate == customServoMixerDefault.rate
&& customServoMixer.speed == customServoMixerDefault.speed && customServoMixer.speed == customServoMixerDefault.speed
@ -2053,8 +2039,8 @@ static void printServoMix(uint8_t dumpMask, master_t *defaultConfig)
// print servo directions // print servo directions
for (uint32_t i = 0; i < MAX_SUPPORTED_SERVOS; i++) { for (uint32_t i = 0; i < MAX_SUPPORTED_SERVOS; i++) {
servoParam_t *servoConf = &masterConfig.servoConf[i]; const servoParam_t *servoConf = &servoProfile()->servoConf[i];
servoParam_t *servoConfDefault = &defaultConfig->servoConf[i]; const servoParam_t *servoConfDefault = &defaultConfig->servoProfile.servoConf[i];
bool equalsDefault = servoConf->reversedSources == servoConfDefault->reversedSources; bool equalsDefault = servoConf->reversedSources == servoConfDefault->reversedSources;
for (uint32_t channel = 0; channel < INPUT_SOURCE_COUNT; channel++) { for (uint32_t channel = 0; channel < INPUT_SOURCE_COUNT; channel++) {
equalsDefault = ~(servoConf->reversedSources ^ servoConfDefault->reversedSources) & (1 << channel); equalsDefault = ~(servoConf->reversedSources ^ servoConfDefault->reversedSources) & (1 << channel);
@ -2082,7 +2068,7 @@ static void cliServoMix(char *cmdline)
// erase custom mixer // erase custom mixer
memset(masterConfig.customServoMixer, 0, sizeof(masterConfig.customServoMixer)); memset(masterConfig.customServoMixer, 0, sizeof(masterConfig.customServoMixer));
for (uint32_t i = 0; i < MAX_SUPPORTED_SERVOS; i++) { for (uint32_t i = 0; i < MAX_SUPPORTED_SERVOS; i++) {
masterConfig.servoConf[i].reversedSources = 0; servoProfile()->servoConf[i].reversedSources = 0;
} }
} else if (strncasecmp(cmdline, "load", 4) == 0) { } else if (strncasecmp(cmdline, "load", 4) == 0) {
ptr = nextArg(cmdline); ptr = nextArg(cmdline);
@ -2115,7 +2101,7 @@ static void cliServoMix(char *cmdline)
for (uint32_t servoIndex = 0; servoIndex < MAX_SUPPORTED_SERVOS; servoIndex++) { for (uint32_t servoIndex = 0; servoIndex < MAX_SUPPORTED_SERVOS; servoIndex++) {
cliPrintf("%d", servoIndex); cliPrintf("%d", servoIndex);
for (uint32_t inputSource = 0; inputSource < INPUT_SOURCE_COUNT; inputSource++) for (uint32_t inputSource = 0; inputSource < INPUT_SOURCE_COUNT; inputSource++)
cliPrintf("\t%s ", (masterConfig.servoConf[servoIndex].reversedSources & (1 << inputSource)) ? "r" : "n"); cliPrintf("\t%s ", (servoProfile()->servoConf[servoIndex].reversedSources & (1 << inputSource)) ? "r" : "n");
cliPrintf("\r\n"); cliPrintf("\r\n");
} }
return; return;
@ -2136,9 +2122,9 @@ static void cliServoMix(char *cmdline)
&& args[INPUT] >= 0 && args[INPUT] < INPUT_SOURCE_COUNT && args[INPUT] >= 0 && args[INPUT] < INPUT_SOURCE_COUNT
&& (*ptr == 'r' || *ptr == 'n')) { && (*ptr == 'r' || *ptr == 'n')) {
if (*ptr == 'r') if (*ptr == 'r')
masterConfig.servoConf[args[SERVO]].reversedSources |= 1 << args[INPUT]; servoProfile()->servoConf[args[SERVO]].reversedSources |= 1 << args[INPUT];
else else
masterConfig.servoConf[args[SERVO]].reversedSources &= ~(1 << args[INPUT]); servoProfile()->servoConf[args[SERVO]].reversedSources &= ~(1 << args[INPUT]);
} else } else
cliShowParseError(); cliShowParseError();
@ -2165,13 +2151,13 @@ static void cliServoMix(char *cmdline)
args[MIN] >= 0 && args[MIN] <= 100 && args[MIN] >= 0 && args[MIN] <= 100 &&
args[MAX] >= 0 && args[MAX] <= 100 && args[MIN] < args[MAX] && args[MAX] >= 0 && args[MAX] <= 100 && args[MIN] < args[MAX] &&
args[BOX] >= 0 && args[BOX] <= MAX_SERVO_BOXES) { args[BOX] >= 0 && args[BOX] <= MAX_SERVO_BOXES) {
masterConfig.customServoMixer[i].targetChannel = args[TARGET]; customServoMixer(i)->targetChannel = args[TARGET];
masterConfig.customServoMixer[i].inputSource = args[INPUT]; customServoMixer(i)->inputSource = args[INPUT];
masterConfig.customServoMixer[i].rate = args[RATE]; customServoMixer(i)->rate = args[RATE];
masterConfig.customServoMixer[i].speed = args[SPEED]; customServoMixer(i)->speed = args[SPEED];
masterConfig.customServoMixer[i].min = args[MIN]; customServoMixer(i)->min = args[MIN];
masterConfig.customServoMixer[i].max = args[MAX]; customServoMixer(i)->max = args[MAX];
masterConfig.customServoMixer[i].box = args[BOX]; customServoMixer(i)->box = args[BOX];
cliServoMix(""); cliServoMix("");
} else { } else {
cliShowParseError(); cliShowParseError();
@ -2351,7 +2337,7 @@ static void cliFlashRead(char *cmdline)
#endif #endif
#ifdef VTX #ifdef VTX
static void printVtx(uint8_t dumpMask, master_t *defaultConfig) static void printVtx(uint8_t dumpMask, const master_t *defaultConfig)
{ {
// print out vtx channel settings // print out vtx channel settings
vtxChannelActivationCondition_t *cac; vtxChannelActivationCondition_t *cac;
@ -2452,7 +2438,7 @@ static void cliName(char *cmdline)
printName(DUMP_MASTER); printName(DUMP_MASTER);
} }
static void printFeature(uint8_t dumpMask, master_t *defaultConfig) static void printFeature(uint8_t dumpMask, const master_t *defaultConfig)
{ {
uint32_t mask = featureMask(); uint32_t mask = featureMask();
uint32_t defaultMask = defaultConfig->enabledFeatures; uint32_t defaultMask = defaultConfig->enabledFeatures;
@ -2544,7 +2530,7 @@ static void cliFeature(char *cmdline)
} }
#ifdef BEEPER #ifdef BEEPER
static void printBeeper(uint8_t dumpMask, master_t *defaultConfig) static void printBeeper(uint8_t dumpMask, const master_t *defaultConfig)
{ {
uint8_t beeperCount = beeperTableEntryCount(); uint8_t beeperCount = beeperTableEntryCount();
uint32_t mask = getBeeperOffMask(); uint32_t mask = getBeeperOffMask();
@ -2627,7 +2613,7 @@ static void cliBeeper(char *cmdline)
} }
#endif #endif
static void printMap(uint8_t dumpMask, master_t *defaultConfig) static void printMap(uint8_t dumpMask, const rxConfig_t *defaultRxConfig)
{ {
bool equalsDefault = true; bool equalsDefault = true;
char buf[16]; char buf[16];
@ -2635,8 +2621,8 @@ static void printMap(uint8_t dumpMask, master_t *defaultConfig)
uint32_t i; uint32_t i;
for (i = 0; i < MAX_MAPPABLE_RX_INPUTS; i++) { for (i = 0; i < MAX_MAPPABLE_RX_INPUTS; i++) {
buf[rxConfig()->rcmap[i]] = rcChannelLetters[i]; buf[rxConfig()->rcmap[i]] = rcChannelLetters[i];
bufDefault[defaultConfig->rxConfig.rcmap[i]] = rcChannelLetters[i]; bufDefault[defaultRxConfig->rcmap[i]] = rcChannelLetters[i];
equalsDefault = equalsDefault && (rxConfig()->rcmap[i] == defaultConfig->rxConfig.rcmap[i]); equalsDefault = equalsDefault && (rxConfig()->rcmap[i] == defaultRxConfig->rcmap[i]);
} }
buf[i] = '\0'; buf[i] = '\0';
@ -2687,12 +2673,12 @@ void *getValuePointer(const clivalue_t *value)
return ptr; return ptr;
} }
static void *getDefaultPointer(void *valuePointer, master_t *defaultConfig) static void *getDefaultPointer(void *valuePointer, const master_t *defaultConfig)
{ {
return ((uint8_t *)valuePointer) - (uint32_t)&masterConfig + (uint32_t)defaultConfig; return ((uint8_t *)valuePointer) - (uint32_t)&masterConfig + (uint32_t)defaultConfig;
} }
static bool valueEqualsDefault(const clivalue_t *value, master_t *defaultConfig) static bool valueEqualsDefault(const clivalue_t *value, const master_t *defaultConfig)
{ {
void *ptr = getValuePointer(value); void *ptr = getValuePointer(value);
@ -2727,7 +2713,7 @@ static bool valueEqualsDefault(const clivalue_t *value, master_t *defaultConfig)
return result; return result;
} }
static void dumpValues(uint16_t valueSection, uint8_t dumpMask, master_t *defaultConfig) static void dumpValues(uint16_t valueSection, uint8_t dumpMask, const master_t *defaultConfig)
{ {
const clivalue_t *value; const clivalue_t *value;
for (uint32_t i = 0; i < VALUE_COUNT; i++) { for (uint32_t i = 0; i < VALUE_COUNT; i++) {
@ -2827,13 +2813,13 @@ static void printConfig(char *cmdline, bool doDiff)
cliDumpPrintf(dumpMask, masterConfig.customMotorMixer[0].throttle == 0.0f, "\r\nmmix reset\r\n\r\n"); cliDumpPrintf(dumpMask, masterConfig.customMotorMixer[0].throttle == 0.0f, "\r\nmmix reset\r\n\r\n");
printMotorMix(dumpMask, &defaultConfig); printMotorMix(dumpMask, defaultConfig.customMotorMixer);
#ifdef USE_SERVOS #ifdef USE_SERVOS
#ifndef CLI_MINIMAL_VERBOSITY #ifndef CLI_MINIMAL_VERBOSITY
cliPrint("\r\n# servo\r\n"); cliPrint("\r\n# servo\r\n");
#endif #endif
printServo(dumpMask, &defaultConfig); printServo(dumpMask, &defaultConfig.servoProfile);
#ifndef CLI_MINIMAL_VERBOSITY #ifndef CLI_MINIMAL_VERBOSITY
cliPrint("\r\n# servo mix\r\n"); cliPrint("\r\n# servo mix\r\n");
@ -2859,44 +2845,44 @@ static void printConfig(char *cmdline, bool doDiff)
#ifndef CLI_MINIMAL_VERBOSITY #ifndef CLI_MINIMAL_VERBOSITY
cliPrint("\r\n# map\r\n"); cliPrint("\r\n# map\r\n");
#endif #endif
printMap(dumpMask, &defaultConfig); printMap(dumpMask, &defaultConfig.rxConfig);
#ifndef CLI_MINIMAL_VERBOSITY #ifndef CLI_MINIMAL_VERBOSITY
cliPrint("\r\n# serial\r\n"); cliPrint("\r\n# serial\r\n");
#endif #endif
printSerial(dumpMask, &defaultConfig); printSerial(dumpMask, &defaultConfig.serialConfig);
#ifdef LED_STRIP #ifdef LED_STRIP
#ifndef CLI_MINIMAL_VERBOSITY #ifndef CLI_MINIMAL_VERBOSITY
cliPrint("\r\n# led\r\n"); cliPrint("\r\n# led\r\n");
#endif #endif
printLed(dumpMask, &defaultConfig); printLed(dumpMask, &defaultConfig.ledStripConfig);
#ifndef CLI_MINIMAL_VERBOSITY #ifndef CLI_MINIMAL_VERBOSITY
cliPrint("\r\n# color\r\n"); cliPrint("\r\n# color\r\n");
#endif #endif
printColor(dumpMask, &defaultConfig); printColor(dumpMask, &defaultConfig.ledStripConfig);
#ifndef CLI_MINIMAL_VERBOSITY #ifndef CLI_MINIMAL_VERBOSITY
cliPrint("\r\n# mode_color\r\n"); cliPrint("\r\n# mode_color\r\n");
#endif #endif
printModeColor(dumpMask, &defaultConfig); printModeColor(dumpMask, &defaultConfig.ledStripConfig);
#endif #endif
#ifndef CLI_MINIMAL_VERBOSITY #ifndef CLI_MINIMAL_VERBOSITY
cliPrint("\r\n# aux\r\n"); cliPrint("\r\n# aux\r\n");
#endif #endif
printAux(dumpMask, &defaultConfig); printAux(dumpMask, &defaultConfig.modeActivationProfile);
#ifndef CLI_MINIMAL_VERBOSITY #ifndef CLI_MINIMAL_VERBOSITY
cliPrint("\r\n# adjrange\r\n"); cliPrint("\r\n# adjrange\r\n");
#endif #endif
printAdjustmentRange(dumpMask, &defaultConfig); printAdjustmentRange(dumpMask, &defaultConfig.adjustmentProfile);
#ifndef CLI_MINIMAL_VERBOSITY #ifndef CLI_MINIMAL_VERBOSITY
cliPrint("\r\n# rxrange\r\n"); cliPrint("\r\n# rxrange\r\n");
#endif #endif
printRxRange(dumpMask, &defaultConfig); printRxRange(dumpMask, &defaultConfig.rxConfig);
#ifdef VTX #ifdef VTX
#ifndef CLI_MINIMAL_VERBOSITY #ifndef CLI_MINIMAL_VERBOSITY
@ -2908,7 +2894,7 @@ static void printConfig(char *cmdline, bool doDiff)
#ifndef CLI_MINIMAL_VERBOSITY #ifndef CLI_MINIMAL_VERBOSITY
cliPrint("\r\n# rxfail\r\n"); cliPrint("\r\n# rxfail\r\n");
#endif #endif
printRxFail(dumpMask, &defaultConfig); printRxFail(dumpMask, &defaultConfig.rxConfig);
#ifndef CLI_MINIMAL_VERBOSITY #ifndef CLI_MINIMAL_VERBOSITY
cliPrint("\r\n# master\r\n"); cliPrint("\r\n# master\r\n");
@ -2954,7 +2940,7 @@ static void printConfig(char *cmdline, bool doDiff)
} }
} }
static void cliDumpProfile(uint8_t profileIndex, uint8_t dumpMask, master_t *defaultConfig) static void cliDumpProfile(uint8_t profileIndex, uint8_t dumpMask, const master_t *defaultConfig)
{ {
if (profileIndex >= MAX_PROFILE_COUNT) { if (profileIndex >= MAX_PROFILE_COUNT) {
// Faulty values // Faulty values
@ -2970,7 +2956,7 @@ static void cliDumpProfile(uint8_t profileIndex, uint8_t dumpMask, master_t *def
cliRateProfile(""); cliRateProfile("");
} }
static void cliDumpRateProfile(uint8_t rateProfileIndex, uint8_t dumpMask, master_t *defaultConfig) static void cliDumpRateProfile(uint8_t rateProfileIndex, uint8_t dumpMask, const master_t *defaultConfig)
{ {
if (rateProfileIndex >= MAX_RATEPROFILES) { if (rateProfileIndex >= MAX_RATEPROFILES) {
// Faulty values // Faulty values
@ -3408,7 +3394,7 @@ static void cliPrintVar(const clivalue_t *var, uint32_t full)
printValuePointer(var, ptr, full); printValuePointer(var, ptr, full);
} }
static void cliPrintVarDefault(const clivalue_t *var, uint32_t full, master_t *defaultConfig) static void cliPrintVarDefault(const clivalue_t *var, uint32_t full, const master_t *defaultConfig)
{ {
void *ptr = getValuePointer(var); void *ptr = getValuePointer(var);
@ -3847,7 +3833,7 @@ const cliResourceValue_t resourceTable[] = {
#endif #endif
}; };
static void printResource(uint8_t dumpMask, master_t *defaultConfig) static void printResource(uint8_t dumpMask, const master_t *defaultConfig)
{ {
for (unsigned int i = 0; i < ARRAYLEN(resourceTable); i++) { for (unsigned int i = 0; i < ARRAYLEN(resourceTable); i++) {
const char* owner; const char* owner;

View file

@ -627,25 +627,25 @@ static bool bstSlaveProcessFeedbackCommand(uint8_t bstRequest)
break; break;
case BST_SERVO_CONFIGURATIONS: case BST_SERVO_CONFIGURATIONS:
for (i = 0; i < MAX_SUPPORTED_SERVOS; i++) { for (i = 0; i < MAX_SUPPORTED_SERVOS; i++) {
bstWrite16(masterConfig.servoConf[i].min); bstWrite16(servoProfile()->servoConf[i].min);
bstWrite16(masterConfig.servoConf[i].max); bstWrite16(servoProfile()->servoConf[i].max);
bstWrite16(masterConfig.servoConf[i].middle); bstWrite16(servoProfile()->servoConf[i].middle);
bstWrite8(masterConfig.servoConf[i].rate); bstWrite8(servoProfile()->servoConf[i].rate);
bstWrite8(masterConfig.servoConf[i].angleAtMin); bstWrite8(servoProfile()->servoConf[i].angleAtMin);
bstWrite8(masterConfig.servoConf[i].angleAtMax); bstWrite8(servoProfile()->servoConf[i].angleAtMax);
bstWrite8(masterConfig.servoConf[i].forwardFromChannel); bstWrite8(servoProfile()->servoConf[i].forwardFromChannel);
bstWrite32(masterConfig.servoConf[i].reversedSources); bstWrite32(servoProfile()->servoConf[i].reversedSources);
} }
break; break;
case BST_SERVO_MIX_RULES: case BST_SERVO_MIX_RULES:
for (i = 0; i < MAX_SERVO_RULES; i++) { for (i = 0; i < MAX_SERVO_RULES; i++) {
bstWrite8(masterConfig.customServoMixer[i].targetChannel); bstWrite8(customServoMixer(i)->targetChannel);
bstWrite8(masterConfig.customServoMixer[i].inputSource); bstWrite8(customServoMixer(i)->inputSource);
bstWrite8(masterConfig.customServoMixer[i].rate); bstWrite8(customServoMixer(i)->rate);
bstWrite8(masterConfig.customServoMixer[i].speed); bstWrite8(customServoMixer(i)->speed);
bstWrite8(masterConfig.customServoMixer[i].min); bstWrite8(customServoMixer(i)->min);
bstWrite8(masterConfig.customServoMixer[i].max); bstWrite8(customServoMixer(i)->max);
bstWrite8(masterConfig.customServoMixer[i].box); bstWrite8(customServoMixer(i)->box);
} }
break; break;
#endif #endif
@ -1157,14 +1157,14 @@ static bool bstSlaveProcessWriteCommand(uint8_t bstWriteCommand)
if (i >= MAX_SUPPORTED_SERVOS) { if (i >= MAX_SUPPORTED_SERVOS) {
ret = BST_FAILED; ret = BST_FAILED;
} else { } else {
masterConfig.servoConf[i].min = bstRead16(); servoProfile()->servoConf[i].min = bstRead16();
masterConfig.servoConf[i].max = bstRead16(); servoProfile()->servoConf[i].max = bstRead16();
masterConfig.servoConf[i].middle = bstRead16(); servoProfile()->servoConf[i].middle = bstRead16();
masterConfig.servoConf[i].rate = bstRead8(); servoProfile()->servoConf[i].rate = bstRead8();
masterConfig.servoConf[i].angleAtMin = bstRead8(); servoProfile()->servoConf[i].angleAtMin = bstRead8();
masterConfig.servoConf[i].angleAtMax = bstRead8(); servoProfile()->servoConf[i].angleAtMax = bstRead8();
masterConfig.servoConf[i].forwardFromChannel = bstRead8(); servoProfile()->servoConf[i].forwardFromChannel = bstRead8();
masterConfig.servoConf[i].reversedSources = bstRead32(); servoProfile()->servoConf[i].reversedSources = bstRead32();
} }
#endif #endif
break; break;
@ -1174,13 +1174,13 @@ static bool bstSlaveProcessWriteCommand(uint8_t bstWriteCommand)
if (i >= MAX_SERVO_RULES) { if (i >= MAX_SERVO_RULES) {
ret = BST_FAILED; ret = BST_FAILED;
} else { } else {
masterConfig.customServoMixer[i].targetChannel = bstRead8(); customServoMixer(i)->targetChannel = bstRead8();
masterConfig.customServoMixer[i].inputSource = bstRead8(); customServoMixer(i)->inputSource = bstRead8();
masterConfig.customServoMixer[i].rate = bstRead8(); customServoMixer(i)->rate = bstRead8();
masterConfig.customServoMixer[i].speed = bstRead8(); customServoMixer(i)->speed = bstRead8();
masterConfig.customServoMixer[i].min = bstRead8(); customServoMixer(i)->min = bstRead8();
masterConfig.customServoMixer[i].max = bstRead8(); customServoMixer(i)->max = bstRead8();
masterConfig.customServoMixer[i].box = bstRead8(); customServoMixer(i)->box = bstRead8();
loadCustomServoMixer(); loadCustomServoMixer();
} }
#endif #endif

View file

@ -48,6 +48,14 @@ COVERAGE_FLAGS := --coverage
C_FLAGS += $(COVERAGE_FLAGS) C_FLAGS += $(COVERAGE_FLAGS)
CXX_FLAGS += $(COVERAGE_FLAGS) CXX_FLAGS += $(COVERAGE_FLAGS)
# Determine the OS and set up the parameter group linker flags accordingly
UNAME := $(shell uname -s)
ifeq ($(UNAME), Darwin)
PG_FLAGS = -Wl,-map,$(OBJECT_DIR)/$@.map
else
PG_FLAGS = -Wl,-T,$(TEST_DIR)/parameter_group.ld -Wl,-Map,$(OBJECT_DIR)/$@.map
endif
# Gather up all of the tests. # Gather up all of the tests.
TEST_SRC = $(sort $(wildcard $(TEST_DIR)/*.cc)) TEST_SRC = $(sort $(wildcard $(TEST_DIR)/*.cc))
TESTS = $(TEST_SRC:$(TEST_DIR)/%.cc=%) TESTS = $(TEST_SRC:$(TEST_DIR)/%.cc=%)
@ -59,11 +67,14 @@ GTEST_HEADERS = $(GTEST_DIR)/inc/gtest/*.h
# House-keeping build targets. # House-keeping build targets.
## all : Build all Unit Tests (Default goal)
all : $(TEST_BINARIES) all : $(TEST_BINARIES)
## clean : Cleanup the UnitTest binaries.
clean : clean :
rm -rf $(OBJECT_DIR) rm -rf $(OBJECT_DIR)
# Builds gtest.a and gtest_main.a. # Builds gtest.a and gtest_main.a.
# Usually you shouldn't tweak such internal variables, indicated by a # Usually you shouldn't tweak such internal variables, indicated by a
@ -110,13 +121,19 @@ $(OBJECT_DIR)/common/maths.o : \
@mkdir -p $(dir $@) @mkdir -p $(dir $@)
$(CC) $(C_FLAGS) $(TEST_CFLAGS) -c $(USER_DIR)/common/maths.c -o $@ $(CC) $(C_FLAGS) $(TEST_CFLAGS) -c $(USER_DIR)/common/maths.c -o $@
$(OBJECT_DIR)/common/typeconversion.o : \ $(OBJECT_DIR)/maths_unittest.o : \
$(USER_DIR)/common/typeconversion.c \ $(TEST_DIR)/maths_unittest.cc \
$(USER_DIR)/common/typeconversion.h \
$(GTEST_HEADERS) $(GTEST_HEADERS)
@mkdir -p $(dir $@) @mkdir -p $(dir $@)
$(CC) $(C_FLAGS) $(TEST_CFLAGS) -c $(USER_DIR)/common/typeconversion.c -o $@ $(CXX) $(CXX_FLAGS) $(TEST_CFLAGS) -c $(TEST_DIR)/maths_unittest.cc -o $@
$(OBJECT_DIR)/maths_unittest : \
$(OBJECT_DIR)/maths_unittest.o \
$(OBJECT_DIR)/common/maths.o \
$(OBJECT_DIR)/gtest_main.a
$(CXX) $(CXX_FLAGS) $^ -o $(OBJECT_DIR)/$@
$(OBJECT_DIR)/common/filter.o : \ $(OBJECT_DIR)/common/filter.o : \
$(USER_DIR)/common/filter.c \ $(USER_DIR)/common/filter.c \
@ -140,54 +157,6 @@ $(OBJECT_DIR)/common_filter_unittest : \
$(CXX) $(CXX_FLAGS) $^ -o $(OBJECT_DIR)/$@ $(CXX) $(CXX_FLAGS) $^ -o $(OBJECT_DIR)/$@
$(OBJECT_DIR)/common/streambuf.o : \
$(USER_DIR)/common/streambuf.c \
$(USER_DIR)/common/streambuf.h \
$(GTEST_HEADERS)
@mkdir -p $(dir $@)
$(CC) $(C_FLAGS) $(TEST_CFLAGS) -D'__TARGET__="TEST"' -D'__REVISION__="revision"' -c $(USER_DIR)/common/streambuf.c -o $@
$(OBJECT_DIR)/drivers/io.o : \
$(USER_DIR)/drivers/io.c \
$(USER_DIR)/drivers/io.h \
$(GTEST_HEADERS)
@mkdir -p $(dir $@)
$(CC) $(C_FLAGS) $(TEST_CFLAGS) -c $(USER_DIR)/drivers/io.c -o $@
$(OBJECT_DIR)/fc/runtime_config.o : \
$(USER_DIR)/fc/runtime_config.c \
$(USER_DIR)/fc/runtime_config.h \
$(GTEST_HEADERS)
@mkdir -p $(dir $@)
$(CC) $(C_FLAGS) $(TEST_CFLAGS) -D'FLASH_SIZE = 128' -DSTM32F10X_MD -c $(USER_DIR)/fc/runtime_config.c -o $@
$(OBJECT_DIR)/sensors/battery.o : $(USER_DIR)/sensors/battery.c $(USER_DIR)/sensors/battery.h $(GTEST_HEADERS)
@mkdir -p $(dir $@)
$(CC) $(C_FLAGS) $(TEST_CFLAGS) -c $(USER_DIR)/sensors/battery.c -o $@
$(OBJECT_DIR)/battery_unittest.o : \
$(TEST_DIR)/battery_unittest.cc \
$(USER_DIR)/sensors/battery.h \
$(GTEST_HEADERS)
@mkdir -p $(dir $@)
$(CXX) $(CXX_FLAGS) $(TEST_CFLAGS) -c $< -o $@
$(OBJECT_DIR)/battery_unittest : \
$(OBJECT_DIR)/sensors/battery.o \
$(OBJECT_DIR)/common/maths.o \
$(OBJECT_DIR)/battery_unittest.o \
$(OBJECT_DIR)/gtest_main.a
$(CXX) $(CXX_FLAGS) $^ -o $@
$(OBJECT_DIR)/common/encoding.o : $(USER_DIR)/common/encoding.c $(USER_DIR)/common/encoding.h $(GTEST_HEADERS) $(OBJECT_DIR)/common/encoding.o : $(USER_DIR)/common/encoding.c $(USER_DIR)/common/encoding.h $(GTEST_HEADERS)
@mkdir -p $(dir $@) @mkdir -p $(dir $@)
$(CC) $(C_FLAGS) $(TEST_CFLAGS) -c $(USER_DIR)/common/encoding.c -o $@ $(CC) $(C_FLAGS) $(TEST_CFLAGS) -c $(USER_DIR)/common/encoding.c -o $@
@ -207,6 +176,37 @@ $(OBJECT_DIR)/encoding_unittest : \
$(CXX) $(CXX_FLAGS) $^ -o $(OBJECT_DIR)/$@ $(CXX) $(CXX_FLAGS) $^ -o $(OBJECT_DIR)/$@
$(OBJECT_DIR)/common/typeconversion.o : \
$(USER_DIR)/common/typeconversion.c \
$(USER_DIR)/common/typeconversion.h \
$(GTEST_HEADERS)
@mkdir -p $(dir $@)
$(CC) $(C_FLAGS) $(TEST_CFLAGS) -c $(USER_DIR)/common/typeconversion.c -o $@
$(OBJECT_DIR)/type_conversion_unittest.o : \
$(TEST_DIR)/type_conversion_unittest.cc \
$(USER_DIR)/common/typeconversion.h \
$(GTEST_HEADERS)
@mkdir -p $(dir $@)
$(CXX) $(CXX_FLAGS) $(TEST_CFLAGS) -c $(TEST_DIR)/type_conversion_unittest.cc -o $@
$(OBJECT_DIR)/type_conversion_unittest : \
$(OBJECT_DIR)/common/typeconversion.o \
$(OBJECT_DIR)/type_conversion_unittest.o \
$(OBJECT_DIR)/gtest_main.a
$(CXX) $(CXX_FLAGS) $^ -o $(OBJECT_DIR)/$@
$(OBJECT_DIR)/fc/runtime_config.o : \
$(USER_DIR)/fc/runtime_config.c \
$(USER_DIR)/fc/runtime_config.h \
$(GTEST_HEADERS)
@mkdir -p $(dir $@)
$(CC) $(C_FLAGS) $(TEST_CFLAGS) -D'FLASH_SIZE = 128' -DSTM32F10X_MD -c $(USER_DIR)/fc/runtime_config.c -o $@
$(OBJECT_DIR)/flight/imu.o : \ $(OBJECT_DIR)/flight/imu.o : \
$(USER_DIR)/flight/imu.c \ $(USER_DIR)/flight/imu.c \
$(USER_DIR)/flight/imu.h \ $(USER_DIR)/flight/imu.h \
@ -232,20 +232,6 @@ $(OBJECT_DIR)/flight_imu_unittest : \
$(CXX) $(CXX_FLAGS) $^ -o $(OBJECT_DIR)/$@ $(CXX) $(CXX_FLAGS) $^ -o $(OBJECT_DIR)/$@
$(OBJECT_DIR)/maths_unittest.o : \
$(TEST_DIR)/maths_unittest.cc \
$(GTEST_HEADERS)
@mkdir -p $(dir $@)
$(CXX) $(CXX_FLAGS) $(TEST_CFLAGS) -c $(TEST_DIR)/maths_unittest.cc -o $@
$(OBJECT_DIR)/maths_unittest : \
$(OBJECT_DIR)/maths_unittest.o \
$(OBJECT_DIR)/common/maths.o \
$(OBJECT_DIR)/gtest_main.a
$(CXX) $(CXX_FLAGS) $^ -o $(OBJECT_DIR)/$@
$(OBJECT_DIR)/flight/altitudehold.o : \ $(OBJECT_DIR)/flight/altitudehold.o : \
$(USER_DIR)/flight/altitudehold.c \ $(USER_DIR)/flight/altitudehold.c \
$(USER_DIR)/flight/altitudehold.h \ $(USER_DIR)/flight/altitudehold.h \
@ -295,6 +281,65 @@ $(OBJECT_DIR)/gps_conversion_unittest : \
$(OBJECT_DIR)/flight/mixer.o : \
$(USER_DIR)/flight/mixer.c \
$(USER_DIR)/flight/mixer.h \
$(GTEST_HEADERS)
@mkdir -p $(dir $@)
$(CC) $(C_FLAGS) $(TEST_CFLAGS) -c $(USER_DIR)/flight/mixer.c -o $@
$(OBJECT_DIR)/flight/servos.o : \
$(USER_DIR)/flight/servos.c \
$(USER_DIR)/flight/servos.h \
$(GTEST_HEADERS)
@mkdir -p $(dir $@)
$(CC) $(C_FLAGS) $(TEST_CFLAGS) -c $(USER_DIR)/flight/servos.c -o $@
$(OBJECT_DIR)/flight_mixer_unittest.o : \
$(TEST_DIR)/flight_mixer_unittest.cc \
$(USER_DIR)/flight/mixer.h \
$(GTEST_HEADERS)
@mkdir -p $(dir $@)
$(CXX) $(CXX_FLAGS) $(TEST_CFLAGS) -c $(TEST_DIR)/flight_mixer_unittest.cc -o $@
$(OBJECT_DIR)/flight_mixer_unittest : \
$(OBJECT_DIR)/flight/mixer.o \
$(OBJECT_DIR)/flight/servos.o \
$(OBJECT_DIR)/flight_mixer_unittest.o \
$(OBJECT_DIR)/common/maths.o \
$(OBJECT_DIR)/gtest_main.a
$(CXX) $(CXX_FLAGS) $^ -o $(OBJECT_DIR)/$@
$(OBJECT_DIR)/flight/failsafe.o : \
$(USER_DIR)/flight/failsafe.c \
$(USER_DIR)/flight/failsafe.h \
$(GTEST_HEADERS)
@mkdir -p $(dir $@)
$(CC) $(C_FLAGS) $(TEST_CFLAGS) -c $(USER_DIR)/flight/failsafe.c -o $@
$(OBJECT_DIR)/flight_failsafe_unittest.o : \
$(TEST_DIR)/flight_failsafe_unittest.cc \
$(USER_DIR)/flight/failsafe.h \
$(GTEST_HEADERS)
@mkdir -p $(dir $@)
$(CXX) $(CXX_FLAGS) $(TEST_CFLAGS) -c $(TEST_DIR)/flight_failsafe_unittest.cc -o $@
$(OBJECT_DIR)/flight_failsafe_unittest : \
$(OBJECT_DIR)/flight/failsafe.o \
$(OBJECT_DIR)/flight_failsafe_unittest.o \
$(OBJECT_DIR)/common/maths.o \
$(OBJECT_DIR)/gtest_main.a
$(CXX) $(CXX_FLAGS) $^ -o $(OBJECT_DIR)/$@
$(OBJECT_DIR)/telemetry/hott.o : \ $(OBJECT_DIR)/telemetry/hott.o : \
$(USER_DIR)/telemetry/hott.c \ $(USER_DIR)/telemetry/hott.c \
$(USER_DIR)/telemetry/hott.h \ $(USER_DIR)/telemetry/hott.h \
@ -320,18 +365,17 @@ $(OBJECT_DIR)/telemetry_hott_unittest : \
$(CXX) $(CXX_FLAGS) $^ -o $(OBJECT_DIR)/$@ $(CXX) $(CXX_FLAGS) $^ -o $(OBJECT_DIR)/$@
$(OBJECT_DIR)/fc/rc_controls.o : \
$(OBJECT_DIR)/io/rc_controls.o : \ $(USER_DIR)/fc/rc_controls.c \
$(USER_DIR)/io/rc_controls.c \ $(USER_DIR)/fc/rc_controls.h \
$(USER_DIR)/io/rc_controls.h \
$(GTEST_HEADERS) $(GTEST_HEADERS)
@mkdir -p $(dir $@) @mkdir -p $(dir $@)
$(CC) $(C_FLAGS) $(TEST_CFLAGS) -c $(USER_DIR)/io/rc_controls.c -o $@ $(CC) $(C_FLAGS) $(TEST_CFLAGS) -c $(USER_DIR)/fc/rc_controls.c -o $@
$(OBJECT_DIR)/rc_controls_unittest.o : \ $(OBJECT_DIR)/rc_controls_unittest.o : \
$(TEST_DIR)/rc_controls_unittest.cc \ $(TEST_DIR)/rc_controls_unittest.cc \
$(USER_DIR)/io/rc_controls.h \ $(USER_DIR)/fc/rc_controls.h \
$(GTEST_HEADERS) $(GTEST_HEADERS)
@mkdir -p $(dir $@) @mkdir -p $(dir $@)
@ -339,7 +383,7 @@ $(OBJECT_DIR)/rc_controls_unittest.o : \
$(OBJECT_DIR)/rc_controls_unittest : \ $(OBJECT_DIR)/rc_controls_unittest : \
$(OBJECT_DIR)/common/maths.o \ $(OBJECT_DIR)/common/maths.o \
$(OBJECT_DIR)/io/rc_controls.o \ $(OBJECT_DIR)/fc/rc_controls.o \
$(OBJECT_DIR)/rc_controls_unittest.o \ $(OBJECT_DIR)/rc_controls_unittest.o \
$(OBJECT_DIR)/gtest_main.a $(OBJECT_DIR)/gtest_main.a
@ -395,54 +439,6 @@ $(OBJECT_DIR)/ws2811_unittest : \
$(CXX) $(CXX_FLAGS) $^ -o $(OBJECT_DIR)/$@ $(CXX) $(CXX_FLAGS) $^ -o $(OBJECT_DIR)/$@
$(OBJECT_DIR)/flight/mixer.o : \
$(USER_DIR)/flight/mixer.c \
$(USER_DIR)/flight/mixer.h \
$(GTEST_HEADERS)
@mkdir -p $(dir $@)
$(CC) $(C_FLAGS) $(TEST_CFLAGS) -c $(USER_DIR)/flight/mixer.c -o $@
$(OBJECT_DIR)/flight_mixer_unittest.o : \
$(TEST_DIR)/flight_mixer_unittest.cc \
$(USER_DIR)/flight/mixer.h \
$(GTEST_HEADERS)
@mkdir -p $(dir $@)
$(CXX) $(CXX_FLAGS) $(TEST_CFLAGS) -c $(TEST_DIR)/flight_mixer_unittest.cc -o $@
$(OBJECT_DIR)/flight_mixer_unittest : \
$(OBJECT_DIR)/flight/mixer.o \
$(OBJECT_DIR)/flight_mixer_unittest.o \
$(OBJECT_DIR)/common/maths.o \
$(OBJECT_DIR)/gtest_main.a
$(CXX) $(CXX_FLAGS) $^ -o $(OBJECT_DIR)/$@
$(OBJECT_DIR)/flight/failsafe.o : \
$(USER_DIR)/flight/failsafe.c \
$(USER_DIR)/flight/failsafe.h \
$(GTEST_HEADERS)
@mkdir -p $(dir $@)
$(CC) $(C_FLAGS) $(TEST_CFLAGS) -c $(USER_DIR)/flight/failsafe.c -o $@
$(OBJECT_DIR)/flight_failsafe_unittest.o : \
$(TEST_DIR)/flight_failsafe_unittest.cc \
$(USER_DIR)/flight/failsafe.h \
$(GTEST_HEADERS)
@mkdir -p $(dir $@)
$(CXX) $(CXX_FLAGS) $(TEST_CFLAGS) -c $(TEST_DIR)/flight_failsafe_unittest.cc -o $@
$(OBJECT_DIR)/flight_failsafe_unittest : \
$(OBJECT_DIR)/flight/failsafe.o \
$(OBJECT_DIR)/flight_failsafe_unittest.o \
$(OBJECT_DIR)/common/maths.o \
$(OBJECT_DIR)/gtest_main.a
$(CXX) $(CXX_FLAGS) $^ -o $(OBJECT_DIR)/$@
$(OBJECT_DIR)/io/serial.o : \ $(OBJECT_DIR)/io/serial.o : \
$(USER_DIR)/io/serial.c \ $(USER_DIR)/io/serial.c \
$(USER_DIR)/io/serial.h \ $(USER_DIR)/io/serial.h \
@ -563,6 +559,27 @@ $(OBJECT_DIR)/rx_ranges_unittest : \
$(CXX) $(CXX_FLAGS) $^ -o $(OBJECT_DIR)/$@ $(CXX) $(CXX_FLAGS) $^ -o $(OBJECT_DIR)/$@
$(OBJECT_DIR)/sensors/battery.o : $(USER_DIR)/sensors/battery.c $(USER_DIR)/sensors/battery.h $(GTEST_HEADERS)
@mkdir -p $(dir $@)
$(CC) $(C_FLAGS) $(TEST_CFLAGS) -c $(USER_DIR)/sensors/battery.c -o $@
$(OBJECT_DIR)/battery_unittest.o : \
$(TEST_DIR)/battery_unittest.cc \
$(USER_DIR)/sensors/battery.h \
$(GTEST_HEADERS)
@mkdir -p $(dir $@)
$(CXX) $(CXX_FLAGS) $(TEST_CFLAGS) -c $< -o $@
$(OBJECT_DIR)/battery_unittest : \
$(OBJECT_DIR)/sensors/battery.o \
$(OBJECT_DIR)/common/maths.o \
$(OBJECT_DIR)/battery_unittest.o \
$(OBJECT_DIR)/gtest_main.a
$(CXX) $(CXX_FLAGS) $^ -o $@
$(OBJECT_DIR)/drivers/barometer_ms5611.o : \ $(OBJECT_DIR)/drivers/barometer_ms5611.o : \
$(USER_DIR)/drivers/barometer_ms5611.c \ $(USER_DIR)/drivers/barometer_ms5611.c \
$(USER_DIR)/drivers/barometer_ms5611.h \ $(USER_DIR)/drivers/barometer_ms5611.h \
@ -658,6 +675,30 @@ $(OBJECT_DIR)/alignsensor_unittest : \
$(CXX) $(CXX_FLAGS) $^ -o $(OBJECT_DIR)/$@ $(CXX) $(CXX_FLAGS) $^ -o $(OBJECT_DIR)/$@
$(OBJECT_DIR)/build/version.o : \
$(USER_DIR)/build/version.c \
$(USER_DIR)/build/version.h \
$(GTEST_HEADERS)
@mkdir -p $(dir $@)
$(CC) $(C_FLAGS) $(TEST_CFLAGS) -D'__TARGET__="TEST"' -D'__REVISION__="revision"' -c $(USER_DIR)/build/version.c -o $@
$(OBJECT_DIR)/drivers/buf_writer.o : \
$(USER_DIR)/drivers/buf_writer.c \
$(USER_DIR)/drivers/buf_writer.h \
$(GTEST_HEADERS)
@mkdir -p $(dir $@)
$(CC) $(C_FLAGS) $(TEST_CFLAGS) -D'__TARGET__="TEST"' -D'__REVISION__="revision"' -c $(USER_DIR)/drivers/buf_writer.c -o $@
$(OBJECT_DIR)/common/streambuf.o : \
$(USER_DIR)/common/streambuf.c \
$(USER_DIR)/common/streambuf.h \
$(GTEST_HEADERS)
@mkdir -p $(dir $@)
$(CC) $(C_FLAGS) $(TEST_CFLAGS) -D'__TARGET__="TEST"' -D'__REVISION__="revision"' -c $(USER_DIR)/common/streambuf.c -o $@
$(OBJECT_DIR)/drivers/display.o : \ $(OBJECT_DIR)/drivers/display.o : \
$(USER_DIR)/drivers/display.c \ $(USER_DIR)/drivers/display.c \
$(USER_DIR)/drivers/display.h \ $(USER_DIR)/drivers/display.h \
@ -690,6 +731,36 @@ $(OBJECT_DIR)/cms_unittest : \
$(CXX) $(CXX_FLAGS) $^ -o $(OBJECT_DIR)/$@ $(CXX) $(CXX_FLAGS) $^ -o $(OBJECT_DIR)/$@
$(OBJECT_DIR)/drivers/io.o : \
$(USER_DIR)/drivers/io.c \
$(USER_DIR)/drivers/io.h \
$(GTEST_HEADERS)
@mkdir -p $(dir $@)
$(CC) $(C_FLAGS) $(TEST_CFLAGS) -c $(USER_DIR)/drivers/io.c -o $@
$(OBJECT_DIR)/config/parameter_group.o : \
$(USER_DIR)/config/parameter_group.c \
$(USER_DIR)/config/parameter_group.h \
$(GTEST_HEADERS)
@mkdir -p $(dir $@)
$(CC) $(C_FLAGS) $(TEST_CFLAGS) -c $(USER_DIR)/config/parameter_group.c -o $@
$(OBJECT_DIR)/parameter_groups_unittest.o : \
$(TEST_DIR)/parameter_groups_unittest.cc \
$(GTEST_HEADERS)
@mkdir -p $(dir $@)
$(CXX) $(CXX_FLAGS) $(TEST_CFLAGS) -c $(TEST_DIR)/parameter_groups_unittest.cc -o $@
$(OBJECT_DIR)/parameter_groups_unittest : \
$(OBJECT_DIR)/parameter_groups_unittest.o \
$(OBJECT_DIR)/config/parameter_group.o \
$(OBJECT_DIR)/gtest_main.a
$(CXX) $(CXX_FLAGS) $(PG_FLAGS) $^ -o $(OBJECT_DIR)/$@
## test : Build and run the Unit Tests ## test : Build and run the Unit Tests
test: $(TESTS:%=test-%) test: $(TESTS:%=test-%)

View file

@ -0,0 +1,22 @@
SECTIONS {
/* BLOCK: on Windows (PE) output section must be page-aligned. Use 4-byte alignment otherwise */
/* SUBALIGN: force 4-byte alignment of input sections for pg_registry.
Gcc defaults to 32 bytes; padding is then inserted between object files, breaking the init structure. */
.pg_registry BLOCK( DEFINED(__section_alignment__) ? __section_alignment__ : 4 ) : SUBALIGN(4)
{
PROVIDE_HIDDEN (__pg_registry_start = . );
PROVIDE_HIDDEN (___pg_registry_start = . );
KEEP (*(.pg_registry))
KEEP (*(SORT(.pg_registry.*)))
PROVIDE_HIDDEN (__pg_registry_end = . );
PROVIDE_HIDDEN (___pg_registry_end = . );
PROVIDE_HIDDEN (__pg_resetdata_start = . );
PROVIDE_HIDDEN (___pg_resetdata_start = . );
KEEP (*(.pg_resetdata))
PROVIDE_HIDDEN (__pg_resetdata_end = . );
PROVIDE_HIDDEN (___pg_resetdata_end = . );
}
}
INSERT AFTER .text;

View file

@ -0,0 +1,92 @@
/*
* This file is part of Cleanflight.
*
* Cleanflight is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Cleanflight is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <limits.h>
extern "C" {
#include "build/debug.h"
#include <platform.h>
#include "config/parameter_group.h"
#include "config/parameter_group_ids.h"
#include "io/motors.h"
PG_DECLARE(motorConfig_t, motorConfig);
PG_REGISTER_WITH_RESET_TEMPLATE(motorConfig_t, motorConfig, PG_MOTOR_CONFIG, 1);
PG_RESET_TEMPLATE(motorConfig_t, motorConfig,
.minthrottle = 1150,
.maxthrottle = 1850,
.mincommand = 1000,
.motorPwmRate = 400,
);
}
#include "unittest_macros.h"
#include "gtest/gtest.h"
TEST(ParameterGroupsfTest, Test_pgResetAll)
{
memset(motorConfig(), 0, sizeof(motorConfig_t));
pgResetAll(0);
EXPECT_EQ(1150, motorConfig()->minthrottle);
EXPECT_EQ(1850, motorConfig()->maxthrottle);
EXPECT_EQ(1000, motorConfig()->mincommand);
EXPECT_EQ(400, motorConfig()->motorPwmRate);
}
TEST(ParameterGroupsfTest, Test_pgFind)
{
memset(motorConfig(), 0, sizeof(motorConfig_t));
const pgRegistry_t *pgRegistry = pgFind(PG_MOTOR_CONFIG);
pgResetCurrent(pgRegistry);
EXPECT_EQ(1150, motorConfig()->minthrottle);
EXPECT_EQ(1850, motorConfig()->maxthrottle);
EXPECT_EQ(1000, motorConfig()->mincommand);
EXPECT_EQ(400, motorConfig()->motorPwmRate);
motorConfig_t motorConfig2;
memset(&motorConfig2, 0, sizeof(motorConfig_t));
motorConfig()->motorPwmRate = 500;
pgStore(pgRegistry, &motorConfig2, sizeof(motorConfig_t), 0);
EXPECT_EQ(1150, motorConfig2.minthrottle);
EXPECT_EQ(1850, motorConfig2.maxthrottle);
EXPECT_EQ(1000, motorConfig2.mincommand);
EXPECT_EQ(500, motorConfig2.motorPwmRate);
motorConfig_t motorConfig3;
memset(&motorConfig3, 0, sizeof(motorConfig_t));
pgResetCopy(&motorConfig3, PG_MOTOR_CONFIG);
EXPECT_EQ(1150, motorConfig3.minthrottle);
EXPECT_EQ(1850, motorConfig3.maxthrottle);
EXPECT_EQ(1000, motorConfig3.mincommand);
EXPECT_EQ(400, motorConfig3.motorPwmRate);
}
// STUBS
extern "C" {
}