From d62168378f05949fe8fc3c1b6c209893ae058ca4 Mon Sep 17 00:00:00 2001 From: Bruce Luckcuck Date: Mon, 4 Mar 2019 20:43:36 -0500 Subject: [PATCH] Fix CLI vtx command parsing to allow reset Previously the validation was checking for channel and band values > 0 which caused a parsing error. Unfortunately this also prevented the ability to reset the entry. This resulted in the output from the `vtx` command not being usable to paste back in as any indexes not configured would cause errors. --- src/main/cli/cli.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/main/cli/cli.c b/src/main/cli/cli.c index c1b444c7fb..6095f0f8fa 100644 --- a/src/main/cli/cli.c +++ b/src/main/cli/cli.c @@ -2312,8 +2312,9 @@ static void cliVtx(char *cmdline) ptr = nextArg(ptr); if (ptr) { val = atoi(ptr); - // FIXME Use VTX API to get min/max - if (val >= VTX_SETTINGS_MIN_BAND && val <= VTX_SETTINGS_MAX_BAND) { + // FIXME Use VTX API to get max + // We check for the min value in final validation below + if (val >= 0 && val <= VTX_SETTINGS_MAX_BAND) { cac->band = val; validArgumentCount++; } @@ -2321,15 +2322,30 @@ static void cliVtx(char *cmdline) ptr = nextArg(ptr); if (ptr) { val = atoi(ptr); - // FIXME Use VTX API to get min/max - if (val >= VTX_SETTINGS_MIN_CHANNEL && val <= VTX_SETTINGS_MAX_CHANNEL) { + // FIXME Use VTX API to get max + // We check for the min value in final validation below + if (val >= 0 && val <= VTX_SETTINGS_MAX_CHANNEL) { cac->channel = val; validArgumentCount++; } } ptr = processChannelRangeArgs(ptr, &cac->range, &validArgumentCount); + bool parseError = false; if (validArgumentCount != 5) { + parseError = true; + } else { + // check for an empty activation condition for reset + vtxChannelActivationCondition_t emptyCac; + memset(&emptyCac, 0, sizeof(emptyCac)); + if (memcmp(cac, &emptyCac, sizeof(emptyCac)) != 0 + // FIXME Use VTX API to get min + && ((cac->band < VTX_SETTINGS_MIN_BAND) || (cac->channel < VTX_SETTINGS_MIN_CHANNEL))) { + parseError = true; + } + } + + if (parseError) { memset(cac, 0, sizeof(vtxChannelActivationCondition_t)); cliShowParseError(); } else {