Skip to content

Commit 98e627c

Browse files
Performed a cleanup pass on all comments and variable names. Also added better range checks to PL commands. Hooked the new configuration into settings.yaml. Added preprocessor conditionals to static functions for tramp PL configuration to ensure that when the tramp option excludes the commands from the build the static processing functions are not left unused. Added tramp_pl_table command to ease updating the configuration in the cases where no default hard coded PL table values are to be reused. If less than the max number of PL entries are provided, remaining entries are filled with that of the last passed PL to ensure that the default values are not used. Tested on F405, worked without issue.
1 parent c2a8146 commit 98e627c

File tree

4 files changed

+108
-77
lines changed

4 files changed

+108
-77
lines changed

src/main/fc/cli.c

Lines changed: 61 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3221,74 +3221,106 @@ static void cliTimerOutputMode(char *cmdline)
32213221

32223222
}
32233223

3224+
#if defined(USE_VTX_TRAMP) && defined(USE_VTX_CONTROL)
3225+
32243226
static void printTrampConfig(char* cmdline)
32253227
{
3226-
(void) cmdline;
3228+
UNUSED(cmdline);
32273229
dumpLiveVtxTrampConfig(cliPrintf);
32283230
}
32293231

3232+
static void printTrampOverride(uint8_t dumpMask, const vtxTrampPwOverride_t* trampOverrideConfig, const vtxTrampPwOverride_t* defaultTrampOverrideConfig)
3233+
{
3234+
const char* dumpFormat = VTX_TRAMP_PL_OR_CMD " %d %d";
3235+
for (uint32_t currentPwLvl = 0; currentPwLvl < VTX_TRAMP_MAX_SUPPORTED_PW_LEVELS; currentPwLvl++)
3236+
{
3237+
const vtxTrampPwOverride_t* currentConfig = &trampOverrideConfig[currentPwLvl];
3238+
bool equalsDefault = false;
3239+
if (defaultTrampOverrideConfig) {
3240+
const vtxTrampPwOverride_t* defaultConfig = &defaultTrampOverrideConfig[currentPwLvl];
3241+
equalsDefault = currentConfig->vtxPwOverrideMw == defaultConfig->vtxPwOverrideMw;
3242+
cliDefaultPrintLinef(dumpMask, equalsDefault, dumpFormat, currentPwLvl + 1, defaultConfig->vtxPwOverrideMw);
3243+
}
3244+
3245+
cliDumpPrintLinef(dumpMask, equalsDefault, dumpFormat, currentPwLvl + 1, currentConfig->vtxPwOverrideMw);
3246+
}
3247+
}
3248+
32303249
static void cliTrampPwOr(char *cmdline)
32313250
{
3232-
static const char parseErrString[] = "ERROR. Cannot parse tramp PL override.\n";
32333251
if(isEmpty(cmdline))
32343252
{
3235-
// Nothing sent, so fail and bail.
3236-
cliPrint(parseErrString);
3253+
printTrampOverride(DUMP_ALL, vtxTrampPwOverride(0), NULL);
32373254
return;
32383255
}
32393256

32403257
// Command structure is: <PL Override IDX> <Power_MW>
3241-
const char* current_cmd = cmdline++;
3258+
const char* currentCmd = cmdline++;
32423259

3243-
// Get the PL index.
3244-
int powerIdx = fastA2I(current_cmd);
3260+
int powerIdx = fastA2I(currentCmd);
32453261
if(powerIdx > VTX_TRAMP_MAX_SUPPORTED_PW_LEVELS || powerIdx < 1)
32463262
{
3247-
// Invalid range, fail and bail
3248-
cliPrint(parseErrString);
3263+
cliPrint("ERROR. Cannot parse command.\n");
32493264
return;
32503265
}
32513266

32523267
// Convert PL Index to array indexable value
32533268
powerIdx--;
32543269

3255-
// Get the PL value.
32563270
int reqPlMw = VTX_TRAMP_NULL_PW_CONFIG;
3257-
current_cmd = nextArg(current_cmd);
3258-
if(current_cmd)
3271+
currentCmd = nextArg(currentCmd);
3272+
if(currentCmd)
32593273
{
3260-
reqPlMw = fastA2I(current_cmd);
3274+
reqPlMw = fastA2I(currentCmd);
32613275
}
32623276

32633277
// If invalid, set to null (user may request that the VTX table is used as-is or it is not implemented)
3264-
if(reqPlMw < 0)
3278+
if(reqPlMw < 0 || reqPlMw > VTX_TRAMP_PL_MAX_MW)
32653279
{
32663280
reqPlMw = VTX_TRAMP_NULL_PW_CONFIG;
32673281
}
32683282

3269-
cliPrintf("Tramp Override stat - PL IDX: %d; PL (mw): %d", powerIdx + 1, reqPlMw);
3270-
32713283
vtxTrampPwOverride_t* powerConfig = vtxTrampPwOverrideMutable(powerIdx);
32723284
powerConfig->vtxPwOverrideMw = reqPlMw;
32733285
}
32743286

3275-
static void printTrampOverride(uint8_t dumpMask, const vtxTrampPwOverride_t* trampOverrideConfig, const vtxTrampPwOverride_t* defaultTrampOverrideConfig)
3287+
static void cliTrampPwTable(char* cmdline)
32763288
{
3277-
const char* dumpFormat = VTX_TRAMP_PL_OR_CMD " %d %d";
3278-
for (uint32_t currentPwLvl = 0; currentPwLvl < VTX_TRAMP_MAX_SUPPORTED_PW_LEVELS; currentPwLvl++)
3289+
if(isEmpty(cmdline))
32793290
{
3280-
const vtxTrampPwOverride_t* current_config = &trampOverrideConfig[currentPwLvl];
3281-
bool equalsDefault = false;
3282-
if (defaultTrampOverrideConfig) {
3283-
const vtxTrampPwOverride_t* default_config = &defaultTrampOverrideConfig[currentPwLvl];
3284-
equalsDefault = current_config->vtxPwOverrideMw == default_config->vtxPwOverrideMw;
3285-
cliDefaultPrintLinef(dumpMask, equalsDefault, dumpFormat, currentPwLvl + 1, default_config->vtxPwOverrideMw);
3291+
printTrampOverride(DUMP_ALL, vtxTrampPwOverride(0), NULL);
3292+
return;
3293+
}
3294+
3295+
// Command structure is: <Power_MW_1> <Power_MW_2> <Power_MW_3> ... <Power_MW_n>
3296+
const char* currentCmd = cmdline++;
3297+
int currentPlMw = 0;
3298+
int currentPlIdx = 0;
3299+
vtxTrampPwOverride_t* powerConfig = NULL;
3300+
while(currentCmd != NULL && currentPlIdx < VTX_TRAMP_MAX_SUPPORTED_PW_LEVELS)
3301+
{
3302+
currentPlMw = fastA2I(currentCmd);
3303+
if(currentPlMw < 0 || currentPlMw > VTX_TRAMP_PL_MAX_MW)
3304+
{
3305+
currentPlMw = VTX_TRAMP_NULL_PW_CONFIG;
32863306
}
3307+
powerConfig = vtxTrampPwOverrideMutable(currentPlIdx);
3308+
powerConfig->vtxPwOverrideMw = currentPlMw;
3309+
currentPlIdx++;
3310+
currentCmd = nextArg(currentCmd);
3311+
}
32873312

3288-
cliDumpPrintLinef(dumpMask, equalsDefault, dumpFormat, currentPwLvl + 1, current_config->vtxPwOverrideMw);
3313+
// If not all table entries were passed, then fill the remaining with the last sent power. This will clear out any remaining
3314+
// default values picked up by the tramp PL table generation.
3315+
for(int currentEmptyPlIdx = currentPlIdx; currentEmptyPlIdx < VTX_TRAMP_MAX_SUPPORTED_PW_LEVELS; currentEmptyPlIdx++)
3316+
{
3317+
powerConfig = vtxTrampPwOverrideMutable(currentEmptyPlIdx);
3318+
powerConfig->vtxPwOverrideMw = currentPlMw;
32893319
}
32903320
}
32913321

3322+
#endif
3323+
32923324
static void printFeature(uint8_t dumpMask, const featureConfig_t *featureConfig, const featureConfig_t *featureConfigDefault)
32933325
{
32943326
uint32_t mask = featureConfig->enabledFeatures;
@@ -4600,7 +4632,7 @@ static void printConfig(const char *cmdline, bool doDiff)
46004632
printOsdLayout(dumpMask, &osdLayoutsConfig_Copy, osdLayoutsConfig(), -1, -1);
46014633
#endif
46024634

4603-
#ifdef USE_VTX_TRAMP
4635+
#if defined(USE_VTX_TRAMP) && defined(USE_VTX_CONTROL)
46044636
cliPrintHashLine("IRC Tramp VTX Table Overrides");
46054637
printTrampOverride(dumpMask, vtxTrampPwOverride_CopyArray, vtxTrampPwOverride(0));
46064638
#endif
@@ -5016,8 +5048,9 @@ const clicmd_t cmdTable[] = {
50165048
CLI_COMMAND_DEF("osd_layout", "get or set the layout of OSD items", "[<layout> [<item> [<col> <row> [<visible>]]]]", cliOsdLayout),
50175049
#endif
50185050
CLI_COMMAND_DEF("timer_output_mode", "get or set the outputmode for a given timer.", "[<timer> [<AUTO|MOTORS|SERVOS>]]", cliTimerOutputMode),
5019-
#ifdef USE_VTX_TRAMP
5051+
#if defined(USE_VTX_TRAMP) && defined(USE_VTX_CONTROL)
50205052
CLI_COMMAND_DEF(VTX_TRAMP_PL_OR_CMD, "Set the power level override of an IRC tramp VTX table", NULL, cliTrampPwOr),
5053+
CLI_COMMAND_DEF(VTX_TRAMP_PL_CMD, "Set all entries in the power level table", NULL, cliTrampPwTable),
50215054
CLI_COMMAND_DEF(VTX_TRAMP_CONFIG_DUMP_CMD, "Dump the live operating tramp config", NULL, printTrampConfig),
50225055
#endif
50235056
};

src/main/fc/settings.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4501,3 +4501,15 @@ groups:
45014501
field: noWayHomeAction
45024502
table: geozone_rth_no_way_home
45034503
type: uint8_t
4504+
- name: PG_TRAMP_TABLE_O_RIDE
4505+
type: vtxTrampPwOverride_t
4506+
headers: ["io/vtx_tramp.h"]
4507+
condition: USE_VTX_TRAMP && USE_VTX_CONTROL
4508+
members:
4509+
- name: vtx_pw_override_mw
4510+
type: int16_t
4511+
description: "Overrides default tramp VTX power level with user defined value in mw"
4512+
default_value: -1
4513+
field: vtxPwOverrideMw
4514+
min: -1
4515+
max: UINT16_MAX

src/main/io/vtx_tramp.c

Lines changed: 32 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ PG_REGISTER_ARRAY_WITH_RESET_FN(vtxTrampPwOverride_t, VTX_TRAMP_MAX_SUPPORTED_PW
5959

6060
void pgResetFn_vtxTrampPwOverride(vtxTrampPwOverride_t* table)
6161
{
62-
for (int current_pw_lvl = 0; current_pw_lvl < VTX_TRAMP_MAX_SUPPORTED_PW_LEVELS; current_pw_lvl++)
62+
for (int currentPwLvl = 0; currentPwLvl < VTX_TRAMP_MAX_SUPPORTED_PW_LEVELS; currentPwLvl++)
6363
{
64-
RESET_CONFIG(vtxTrampPwOverride_t, &table[current_pw_lvl],
65-
.vtxPwOverrideMw = -1
64+
RESET_CONFIG(vtxTrampPwOverride_t, &table[currentPwLvl],
65+
.vtxPwOverrideMw = VTX_TRAMP_NULL_PW_CONFIG
6666
);
6767
}
6868
}
@@ -576,87 +576,71 @@ static vtxDevice_t impl_vtxDevice = {
576576
};
577577

578578
// Backwards compatable mutable data structures to allow for configuration to be added.
579-
static uint16_t mutableTablePowers[VTX_TRAMP_MAX_SUPPORTED_PW_LEVELS];
580-
#define MAX_VTX_PWR_NAME_CHARS 6
581-
static char mutableTablePowerNames[VTX_TRAMP_MAX_SUPPORTED_PW_LEVELS + 1][MAX_VTX_PWR_NAME_CHARS];
579+
static uint16_t mutablePowerTable[VTX_TRAMP_MAX_SUPPORTED_PW_LEVELS];
580+
#define MAX_VTX_POWER_PLACES_DECIMAL 6
581+
static char mutablePowerTableNames[VTX_TRAMP_MAX_SUPPORTED_PW_LEVELS + 1][MAX_VTX_POWER_PLACES_DECIMAL + 1];
582582

583-
// Default table power levels
583+
// Default power level tables
584584
const uint16_t trampPowerTable_5G8_200[VTX_TRAMP_5G8_MAX_POWER_COUNT] = { 25, 100, 200, 200, 200 };
585585
const uint16_t trampPowerTable_5G8_400[VTX_TRAMP_5G8_MAX_POWER_COUNT] = { 25, 100, 200, 400, 400 };
586586
const uint16_t trampPowerTable_5G8_600[VTX_TRAMP_5G8_MAX_POWER_COUNT] = { 25, 100, 200, 400, 600 };
587587
const uint16_t trampPowerTable_5G8_800[VTX_TRAMP_5G8_MAX_POWER_COUNT] = { 25, 100, 200, 500, 800 };
588588
const uint16_t trampPowerTable_1G3_800[VTX_TRAMP_1G3_MAX_POWER_COUNT] = { 25, 200, 800 };
589589
const uint16_t trampPowerTable_1G3_2000[VTX_TRAMP_1G3_MAX_POWER_COUNT] = { 25, 200, 2000 };
590590

591-
// Dump the VTX operating params to the console. Used for configuration validation to ensure that the VTX is being commanded as
592-
// expected. Used to debug VTX issues such as inconsistent power levels (IE command 1 mw for first power, 2 mw for second, etc),
593-
// frequency issues (commanded != requested), etc. This does require that the CLI serial interface is exposed, but better that than
594-
// exposing the VTX driver internals to the CLI.
595591
void dumpLiveVtxTrampConfig(consolePrintf_t consolePrint)
596592
{
597-
// Dump configuration
598-
consolePrint("Configured power levels: %d\n", impl_vtxDevice.capability.powerCount);
593+
consolePrint("PLs Configured: %d\n", impl_vtxDevice.capability.powerCount);
599594
for(uint8_t current_pl = 0; current_pl < VTX_TRAMP_MAX_SUPPORTED_PW_LEVELS; current_pl++)
600595
{
601-
consolePrint("PL %d: %d mw\n", current_pl + 1, mutableTablePowers[current_pl]);
596+
consolePrint("PL %d: %d mw\n", current_pl + 1, mutablePowerTable[current_pl]);
602597
}
603598

604-
consolePrint("Actual VTX Freq: %u\n", vtxState.state.freq);
605-
consolePrint("Actual VTX Power: %u\n", vtxState.state.power);
599+
const char actual[] = "Act";
600+
const char req[] = "Req";
601+
const char pwr[] = "Pwr";
602+
const char freq[] = "Freq";
603+
consolePrint("%s %s: %u\n", actual, freq, vtxState.state.freq);
604+
consolePrint("%s %s: %u\n", actual, pwr, vtxState.state.power);
606605

607-
consolePrint("Requested VTX Freq: %u\n", vtxState.request.freq);
608-
consolePrint("Requested VTX Power: %u\n", vtxState.request.power);
609-
consolePrint("Requested VTX Power IDX: %u\n", vtxState.request.powerIndex);
606+
consolePrint("%s %s: %u\n", req, freq, vtxState.request.freq);
607+
consolePrint("%s %s: %u\n", req, pwr, vtxState.request.power);
608+
consolePrint("%s %s IDX: %u\n", req, pwr, vtxState.request.powerIndex);
610609
}
611610

612-
// Construct the power table. Takes into account any configured override power values.
613-
// baseTable - Pointer to the base table configuration
614-
// tableCount - Entries in the table configuration
615-
static void constructPowerTable(const uint16_t* baseTable, const uint16_t tableCount)
611+
static void constructPowerTable(const uint16_t* defaultTable, const uint16_t defaultTableSize)
616612
{
617-
// Update the 0th power index
618-
strcpy(mutableTablePowerNames[0], "---");
613+
// Update the 0th power index to the common start entry string
614+
strcpy(mutablePowerTableNames[0], "---");
619615

620616
// Now construct each table
621-
const vtxTrampPwOverride_t* pwr_config;
617+
const vtxTrampPwOverride_t* pwrConfig;
622618
uint16_t currentPwLvl = 0;
623619
for(currentPwLvl = 0; currentPwLvl < VTX_TRAMP_MAX_SUPPORTED_PW_LEVELS; currentPwLvl++)
624620
{
625-
pwr_config = vtxTrampPwOverride(currentPwLvl);
626-
if(pwr_config->vtxPwOverrideMw >= 0)
621+
pwrConfig = vtxTrampPwOverride(currentPwLvl);
622+
// If user defined table entry contains valid data, use it in place of the default
623+
if(pwrConfig->vtxPwOverrideMw >= 0)
627624
{
628-
// Only override if power is configured to a valid value. If negative, this value is not configured and
629-
// will be set to the default table for the power level.
630-
mutableTablePowers[currentPwLvl] = (uint16_t) pwr_config->vtxPwOverrideMw;
625+
mutablePowerTable[currentPwLvl] = (uint16_t) pwrConfig->vtxPwOverrideMw;
631626
}
632-
633-
else if(currentPwLvl < tableCount)
627+
// Otherwise, use the default's entry.
628+
else if(currentPwLvl < defaultTableSize)
634629
{
635-
// Not configured, so use the default.
636-
mutableTablePowers[currentPwLvl] = *(baseTable + currentPwLvl);
630+
mutablePowerTable[currentPwLvl] = *(defaultTable + currentPwLvl);
637631
}
638632
else
639633
{
640-
// No default value and no configured value. Nothing to write, so terminate from the loop.
641634
break;
642635
}
643636

644-
// Update the "stringified" power. Always add 1 to the working power level since 0 is reserved.
645-
sprintf(mutableTablePowerNames[currentPwLvl + 1], "%u", mutableTablePowers[currentPwLvl]);
637+
sprintf(mutablePowerTableNames[currentPwLvl + 1], "%u", mutablePowerTable[currentPwLvl]);
646638
}
647639

648-
// Update the stored params.
649-
vtxState.metadata.powerTablePtr = mutableTablePowers;
650-
651-
// NOTE: If loop broke before max (IE 2 overrides and three default, < 5, idx = 3) the last loop index will be the total
652-
// quantity configured. Set that here.
653640
vtxState.metadata.powerTableCount = currentPwLvl;
654-
655-
impl_vtxDevice.capability.powerNames = (char**) mutableTablePowerNames;
641+
vtxState.metadata.powerTablePtr = mutablePowerTable;
656642
impl_vtxDevice.capability.powerCount = currentPwLvl;
657-
658-
// NOTE: If less power levels than max supported are passed, then the upper values in the config are left as-is.
659-
// The result is that they are not used.
643+
impl_vtxDevice.capability.powerNames = (char**) mutablePowerTableNames;
660644
}
661645

662646
static void vtxProtoUpdatePowerMetadata(uint16_t maxPower)

src/main/io/vtx_tramp.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,16 @@
4040
#define VTX_TRAMP_1G3_MIN_FREQUENCY_MHZ 1000
4141
#define VTX_TRAMP_1G3_MAX_FREQUENCY_MHZ 1399
4242

43-
// Defines a 'zero' config value.
43+
// Defines an unconfigured power level
4444
#define VTX_TRAMP_NULL_PW_CONFIG -1
4545

4646
#define VTX_TRAMP_MAX_SUPPORTED_PW_LEVELS VTX_TRAMP_5G8_MAX_POWER_COUNT
47+
#define VTX_TRAMP_PL_MAX_MW UINT16_MAX
4748
#define VTX_TRAMP_PW_OVERRIDE_VER 1
4849

4950
#define VTX_TRAMP_PL_OR_CMD "tramp_pl_override"
5051
#define VTX_TRAMP_CONFIG_DUMP_CMD "tramp_dump_config"
52+
#define VTX_TRAMP_PL_CMD "tramp_pl_table"
5153

5254
typedef struct {
5355
int vtxPwOverrideMw;

0 commit comments

Comments
 (0)