mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-15 20:35:33 +03:00
Changed CLI parser to allow multiple whitespaces. Fixes problem with 'mmix' dump.
This commit is contained in:
parent
00cad53a24
commit
a8bfa54ae0
1 changed files with 59 additions and 49 deletions
|
@ -968,14 +968,24 @@ static void cliShowArgumentRangeError(char *name, int min, int max)
|
||||||
cliPrintf("%s must be between %d and %d\r\n", name, min, max);
|
cliPrintf("%s must be between %d and %d\r\n", name, min, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char *nextArg(char *currentArg)
|
||||||
|
{
|
||||||
|
char *ptr = strchr(currentArg, ' ');
|
||||||
|
while (ptr && *ptr == ' ') {
|
||||||
|
ptr++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
static char *processChannelRangeArgs(char *ptr, channelRange_t *range, uint8_t *validArgumentCount)
|
static char *processChannelRangeArgs(char *ptr, channelRange_t *range, uint8_t *validArgumentCount)
|
||||||
{
|
{
|
||||||
int val;
|
int val;
|
||||||
|
|
||||||
for (uint32_t argIndex = 0; argIndex < 2; argIndex++) {
|
for (uint32_t argIndex = 0; argIndex < 2; argIndex++) {
|
||||||
ptr = strchr(ptr, ' ');
|
ptr = nextArg(ptr);
|
||||||
if (ptr) {
|
if (ptr) {
|
||||||
val = atoi(++ptr);
|
val = atoi(ptr);
|
||||||
val = CHANNEL_VALUE_TO_STEP(val);
|
val = CHANNEL_VALUE_TO_STEP(val);
|
||||||
if (val >= MIN_MODE_RANGE_STEP && val <= MAX_MODE_RANGE_STEP) {
|
if (val >= MIN_MODE_RANGE_STEP && val <= MAX_MODE_RANGE_STEP) {
|
||||||
if (argIndex == 0) {
|
if (argIndex == 0) {
|
||||||
|
@ -1058,9 +1068,9 @@ static void cliRxFail(char *cmdline)
|
||||||
rxFailsafeChannelMode_e mode = channelFailsafeConfiguration->mode;
|
rxFailsafeChannelMode_e mode = channelFailsafeConfiguration->mode;
|
||||||
bool requireValue = channelFailsafeConfiguration->mode == RX_FAILSAFE_MODE_SET;
|
bool requireValue = channelFailsafeConfiguration->mode == RX_FAILSAFE_MODE_SET;
|
||||||
|
|
||||||
ptr = strchr(ptr, ' ');
|
ptr = nextArg(ptr);
|
||||||
if (ptr) {
|
if (ptr) {
|
||||||
char *p = strchr(rxFailsafeModeCharacters, *(++ptr));
|
char *p = strchr(rxFailsafeModeCharacters, *(ptr));
|
||||||
if (p) {
|
if (p) {
|
||||||
uint8_t requestedMode = p - rxFailsafeModeCharacters;
|
uint8_t requestedMode = p - rxFailsafeModeCharacters;
|
||||||
mode = rxFailsafeModesTable[type][requestedMode];
|
mode = rxFailsafeModesTable[type][requestedMode];
|
||||||
|
@ -1074,13 +1084,13 @@ static void cliRxFail(char *cmdline)
|
||||||
|
|
||||||
requireValue = mode == RX_FAILSAFE_MODE_SET;
|
requireValue = mode == RX_FAILSAFE_MODE_SET;
|
||||||
|
|
||||||
ptr = strchr(ptr, ' ');
|
ptr = nextArg(ptr);
|
||||||
if (ptr) {
|
if (ptr) {
|
||||||
if (!requireValue) {
|
if (!requireValue) {
|
||||||
cliShowParseError();
|
cliShowParseError();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
value = atoi(++ptr);
|
value = atoi(ptr);
|
||||||
value = CHANNEL_VALUE_TO_RXFAIL_STEP(value);
|
value = CHANNEL_VALUE_TO_RXFAIL_STEP(value);
|
||||||
if (value > MAX_RXFAIL_RANGE_STEP) {
|
if (value > MAX_RXFAIL_RANGE_STEP) {
|
||||||
cliPrint("Value out of range\r\n");
|
cliPrint("Value out of range\r\n");
|
||||||
|
@ -1164,17 +1174,17 @@ static void cliAux(char *cmdline)
|
||||||
if (i < MAX_MODE_ACTIVATION_CONDITION_COUNT) {
|
if (i < MAX_MODE_ACTIVATION_CONDITION_COUNT) {
|
||||||
modeActivationCondition_t *mac = &masterConfig.modeActivationConditions[i];
|
modeActivationCondition_t *mac = &masterConfig.modeActivationConditions[i];
|
||||||
uint8_t validArgumentCount = 0;
|
uint8_t validArgumentCount = 0;
|
||||||
ptr = strchr(ptr, ' ');
|
ptr = nextArg(ptr);
|
||||||
if (ptr) {
|
if (ptr) {
|
||||||
val = atoi(++ptr);
|
val = atoi(ptr);
|
||||||
if (val >= 0 && val < CHECKBOX_ITEM_COUNT) {
|
if (val >= 0 && val < CHECKBOX_ITEM_COUNT) {
|
||||||
mac->modeId = val;
|
mac->modeId = val;
|
||||||
validArgumentCount++;
|
validArgumentCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ptr = strchr(ptr, ' ');
|
ptr = nextArg(ptr);
|
||||||
if (ptr) {
|
if (ptr) {
|
||||||
val = atoi(++ptr);
|
val = atoi(ptr);
|
||||||
if (val >= 0 && val < MAX_AUX_CHANNEL_COUNT) {
|
if (val >= 0 && val < MAX_AUX_CHANNEL_COUNT) {
|
||||||
mac->auxChannelIndex = val;
|
mac->auxChannelIndex = val;
|
||||||
validArgumentCount++;
|
validArgumentCount++;
|
||||||
|
@ -1254,20 +1264,20 @@ static void cliSerial(char *cmdline)
|
||||||
validArgumentCount++;
|
validArgumentCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
ptr = strchr(ptr, ' ');
|
ptr = nextArg(ptr);
|
||||||
if (ptr) {
|
if (ptr) {
|
||||||
val = atoi(++ptr);
|
val = atoi(ptr);
|
||||||
portConfig.functionMask = val & 0xFFFF;
|
portConfig.functionMask = val & 0xFFFF;
|
||||||
validArgumentCount++;
|
validArgumentCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < 4; i ++) {
|
for (i = 0; i < 4; i ++) {
|
||||||
ptr = strchr(ptr, ' ');
|
ptr = nextArg(ptr);
|
||||||
if (!ptr) {
|
if (!ptr) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
val = atoi(++ptr);
|
val = atoi(ptr);
|
||||||
|
|
||||||
uint8_t baudRateIndex = lookupBaudRateIndex(val);
|
uint8_t baudRateIndex = lookupBaudRateIndex(val);
|
||||||
if (baudRates[baudRateIndex] != (uint32_t) val) {
|
if (baudRates[baudRateIndex] != (uint32_t) val) {
|
||||||
|
@ -1434,17 +1444,17 @@ static void cliAdjustmentRange(char *cmdline)
|
||||||
adjustmentRange_t *ar = &masterConfig.adjustmentRanges[i];
|
adjustmentRange_t *ar = &masterConfig.adjustmentRanges[i];
|
||||||
uint8_t validArgumentCount = 0;
|
uint8_t validArgumentCount = 0;
|
||||||
|
|
||||||
ptr = strchr(ptr, ' ');
|
ptr = nextArg(ptr);
|
||||||
if (ptr) {
|
if (ptr) {
|
||||||
val = atoi(++ptr);
|
val = atoi(ptr);
|
||||||
if (val >= 0 && val < MAX_SIMULTANEOUS_ADJUSTMENT_COUNT) {
|
if (val >= 0 && val < MAX_SIMULTANEOUS_ADJUSTMENT_COUNT) {
|
||||||
ar->adjustmentIndex = val;
|
ar->adjustmentIndex = val;
|
||||||
validArgumentCount++;
|
validArgumentCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ptr = strchr(ptr, ' ');
|
ptr = nextArg(ptr);
|
||||||
if (ptr) {
|
if (ptr) {
|
||||||
val = atoi(++ptr);
|
val = atoi(ptr);
|
||||||
if (val >= 0 && val < MAX_AUX_CHANNEL_COUNT) {
|
if (val >= 0 && val < MAX_AUX_CHANNEL_COUNT) {
|
||||||
ar->auxChannelIndex = val;
|
ar->auxChannelIndex = val;
|
||||||
validArgumentCount++;
|
validArgumentCount++;
|
||||||
|
@ -1453,17 +1463,17 @@ static void cliAdjustmentRange(char *cmdline)
|
||||||
|
|
||||||
ptr = processChannelRangeArgs(ptr, &ar->range, &validArgumentCount);
|
ptr = processChannelRangeArgs(ptr, &ar->range, &validArgumentCount);
|
||||||
|
|
||||||
ptr = strchr(ptr, ' ');
|
ptr = nextArg(ptr);
|
||||||
if (ptr) {
|
if (ptr) {
|
||||||
val = atoi(++ptr);
|
val = atoi(ptr);
|
||||||
if (val >= 0 && val < ADJUSTMENT_FUNCTION_COUNT) {
|
if (val >= 0 && val < ADJUSTMENT_FUNCTION_COUNT) {
|
||||||
ar->adjustmentFunction = val;
|
ar->adjustmentFunction = val;
|
||||||
validArgumentCount++;
|
validArgumentCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ptr = strchr(ptr, ' ');
|
ptr = nextArg(ptr);
|
||||||
if (ptr) {
|
if (ptr) {
|
||||||
val = atoi(++ptr);
|
val = atoi(ptr);
|
||||||
if (val >= 0 && val < MAX_AUX_CHANNEL_COUNT) {
|
if (val >= 0 && val < MAX_AUX_CHANNEL_COUNT) {
|
||||||
ar->auxSwitchChannelIndex = val;
|
ar->auxSwitchChannelIndex = val;
|
||||||
validArgumentCount++;
|
validArgumentCount++;
|
||||||
|
@ -1531,9 +1541,9 @@ static void cliMotorMix(char *cmdline)
|
||||||
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;
|
masterConfig.customMotorMixer[i].throttle = 0.0f;
|
||||||
} else if (strncasecmp(cmdline, "load", 4) == 0) {
|
} else if (strncasecmp(cmdline, "load", 4) == 0) {
|
||||||
ptr = strchr(cmdline, ' ');
|
ptr = nextArg(cmdline);
|
||||||
if (ptr) {
|
if (ptr) {
|
||||||
len = strlen(++ptr);
|
len = strlen(ptr);
|
||||||
for (uint32_t i = 0; ; i++) {
|
for (uint32_t i = 0; ; i++) {
|
||||||
if (mixerNames[i] == NULL) {
|
if (mixerNames[i] == NULL) {
|
||||||
cliPrint("Invalid name\r\n");
|
cliPrint("Invalid name\r\n");
|
||||||
|
@ -1551,30 +1561,30 @@ static void cliMotorMix(char *cmdline)
|
||||||
ptr = cmdline;
|
ptr = cmdline;
|
||||||
uint32_t i = atoi(ptr); // get motor number
|
uint32_t i = atoi(ptr); // get motor number
|
||||||
if (i < MAX_SUPPORTED_MOTORS) {
|
if (i < MAX_SUPPORTED_MOTORS) {
|
||||||
ptr = strchr(ptr, ' ');
|
ptr = nextArg(ptr);
|
||||||
if (ptr) {
|
if (ptr) {
|
||||||
masterConfig.customMotorMixer[i].throttle = fastA2F(++ptr);
|
masterConfig.customMotorMixer[i].throttle = fastA2F(ptr);
|
||||||
check++;
|
check++;
|
||||||
}
|
}
|
||||||
ptr = strchr(ptr, ' ');
|
ptr = nextArg(ptr);
|
||||||
if (ptr) {
|
if (ptr) {
|
||||||
masterConfig.customMotorMixer[i].roll = fastA2F(++ptr);
|
masterConfig.customMotorMixer[i].roll = fastA2F(ptr);
|
||||||
check++;
|
check++;
|
||||||
}
|
}
|
||||||
ptr = strchr(ptr, ' ');
|
ptr = nextArg(ptr);
|
||||||
if (ptr) {
|
if (ptr) {
|
||||||
masterConfig.customMotorMixer[i].pitch = fastA2F(++ptr);
|
masterConfig.customMotorMixer[i].pitch = fastA2F(ptr);
|
||||||
check++;
|
check++;
|
||||||
}
|
}
|
||||||
ptr = strchr(ptr, ' ');
|
ptr = nextArg(ptr);
|
||||||
if (ptr) {
|
if (ptr) {
|
||||||
masterConfig.customMotorMixer[i].yaw = fastA2F(++ptr);
|
masterConfig.customMotorMixer[i].yaw = fastA2F(ptr);
|
||||||
check++;
|
check++;
|
||||||
}
|
}
|
||||||
if (check != 4) {
|
if (check != 4) {
|
||||||
cliShowParseError();
|
cliShowParseError();
|
||||||
} else {
|
} else {
|
||||||
cliMotorMix("");
|
printMotorMix(DUMP_MASTER, NULL);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
cliShowArgumentRangeError("index", 0, MAX_SUPPORTED_MOTORS - 1);
|
cliShowArgumentRangeError("index", 0, MAX_SUPPORTED_MOTORS - 1);
|
||||||
|
@ -1622,15 +1632,15 @@ static void cliRxRange(char *cmdline)
|
||||||
if (i >= 0 && i < NON_AUX_CHANNEL_COUNT) {
|
if (i >= 0 && i < NON_AUX_CHANNEL_COUNT) {
|
||||||
int rangeMin, rangeMax;
|
int rangeMin, rangeMax;
|
||||||
|
|
||||||
ptr = strchr(ptr, ' ');
|
ptr = nextArg(ptr);
|
||||||
if (ptr) {
|
if (ptr) {
|
||||||
rangeMin = atoi(++ptr);
|
rangeMin = atoi(ptr);
|
||||||
validArgumentCount++;
|
validArgumentCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
ptr = strchr(ptr, ' ');
|
ptr = nextArg(ptr);
|
||||||
if (ptr) {
|
if (ptr) {
|
||||||
rangeMax = atoi(++ptr);
|
rangeMax = atoi(ptr);
|
||||||
validArgumentCount++;
|
validArgumentCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1680,8 +1690,8 @@ static void cliLed(char *cmdline)
|
||||||
ptr = cmdline;
|
ptr = cmdline;
|
||||||
i = atoi(ptr);
|
i = atoi(ptr);
|
||||||
if (i < LED_MAX_STRIP_LENGTH) {
|
if (i < LED_MAX_STRIP_LENGTH) {
|
||||||
ptr = strchr(cmdline, ' ');
|
ptr = nextArg(cmdline);
|
||||||
if (!parseLedStripConfig(i, ++ptr)) {
|
if (!parseLedStripConfig(i, ptr)) {
|
||||||
cliShowParseError();
|
cliShowParseError();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1728,8 +1738,8 @@ static void cliColor(char *cmdline)
|
||||||
ptr = cmdline;
|
ptr = cmdline;
|
||||||
i = atoi(ptr);
|
i = atoi(ptr);
|
||||||
if (i < LED_CONFIGURABLE_COLOR_COUNT) {
|
if (i < LED_CONFIGURABLE_COLOR_COUNT) {
|
||||||
ptr = strchr(cmdline, ' ');
|
ptr = nextArg(cmdline);
|
||||||
if (!parseColor(i, ++ptr)) {
|
if (!parseColor(i, ptr)) {
|
||||||
cliShowParseError();
|
cliShowParseError();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1982,9 +1992,9 @@ static void cliServoMix(char *cmdline)
|
||||||
masterConfig.servoConf[i].reversedSources = 0;
|
masterConfig.servoConf[i].reversedSources = 0;
|
||||||
}
|
}
|
||||||
} else if (strncasecmp(cmdline, "load", 4) == 0) {
|
} else if (strncasecmp(cmdline, "load", 4) == 0) {
|
||||||
ptr = strchr(cmdline, ' ');
|
ptr = nextArg(cmdline);
|
||||||
if (ptr) {
|
if (ptr) {
|
||||||
len = strlen(++ptr);
|
len = strlen(ptr);
|
||||||
for (uint32_t i = 0; ; i++) {
|
for (uint32_t i = 0; ; i++) {
|
||||||
if (mixerNames[i] == NULL) {
|
if (mixerNames[i] == NULL) {
|
||||||
cliPrintf("Invalid name\r\n");
|
cliPrintf("Invalid name\r\n");
|
||||||
|
@ -2280,25 +2290,25 @@ static void cliVtx(char *cmdline)
|
||||||
if (i < MAX_CHANNEL_ACTIVATION_CONDITION_COUNT) {
|
if (i < MAX_CHANNEL_ACTIVATION_CONDITION_COUNT) {
|
||||||
vtxChannelActivationCondition_t *cac = &masterConfig.vtxChannelActivationConditions[i];
|
vtxChannelActivationCondition_t *cac = &masterConfig.vtxChannelActivationConditions[i];
|
||||||
uint8_t validArgumentCount = 0;
|
uint8_t validArgumentCount = 0;
|
||||||
ptr = strchr(ptr, ' ');
|
ptr = nextArg(ptr);
|
||||||
if (ptr) {
|
if (ptr) {
|
||||||
val = atoi(++ptr);
|
val = atoi(ptr);
|
||||||
if (val >= 0 && val < MAX_AUX_CHANNEL_COUNT) {
|
if (val >= 0 && val < MAX_AUX_CHANNEL_COUNT) {
|
||||||
cac->auxChannelIndex = val;
|
cac->auxChannelIndex = val;
|
||||||
validArgumentCount++;
|
validArgumentCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ptr = strchr(ptr, ' ');
|
ptr = nextArg(ptr);
|
||||||
if (ptr) {
|
if (ptr) {
|
||||||
val = atoi(++ptr);
|
val = atoi(ptr);
|
||||||
if (val >= VTX_BAND_MIN && val <= VTX_BAND_MAX) {
|
if (val >= VTX_BAND_MIN && val <= VTX_BAND_MAX) {
|
||||||
cac->band = val;
|
cac->band = val;
|
||||||
validArgumentCount++;
|
validArgumentCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ptr = strchr(ptr, ' ');
|
ptr = nextArg(ptr);
|
||||||
if (ptr) {
|
if (ptr) {
|
||||||
val = atoi(++ptr);
|
val = atoi(ptr);
|
||||||
if (val >= VTX_CHANNEL_MIN && val <= VTX_CHANNEL_MAX) {
|
if (val >= VTX_CHANNEL_MIN && val <= VTX_CHANNEL_MAX) {
|
||||||
cac->channel = val;
|
cac->channel = val;
|
||||||
validArgumentCount++;
|
validArgumentCount++;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue