1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-15 12:25:20 +03:00

Changed CLI parser to allow multiple whitespaces. Fixes problem with 'mmix' dump.

This commit is contained in:
mikeller 2016-08-28 01:07:01 +12:00
parent 00cad53a24
commit a8bfa54ae0

View file

@ -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);
}
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)
{
int val;
for (uint32_t argIndex = 0; argIndex < 2; argIndex++) {
ptr = strchr(ptr, ' ');
ptr = nextArg(ptr);
if (ptr) {
val = atoi(++ptr);
val = atoi(ptr);
val = CHANNEL_VALUE_TO_STEP(val);
if (val >= MIN_MODE_RANGE_STEP && val <= MAX_MODE_RANGE_STEP) {
if (argIndex == 0) {
@ -1058,9 +1068,9 @@ static void cliRxFail(char *cmdline)
rxFailsafeChannelMode_e mode = channelFailsafeConfiguration->mode;
bool requireValue = channelFailsafeConfiguration->mode == RX_FAILSAFE_MODE_SET;
ptr = strchr(ptr, ' ');
ptr = nextArg(ptr);
if (ptr) {
char *p = strchr(rxFailsafeModeCharacters, *(++ptr));
char *p = strchr(rxFailsafeModeCharacters, *(ptr));
if (p) {
uint8_t requestedMode = p - rxFailsafeModeCharacters;
mode = rxFailsafeModesTable[type][requestedMode];
@ -1074,13 +1084,13 @@ static void cliRxFail(char *cmdline)
requireValue = mode == RX_FAILSAFE_MODE_SET;
ptr = strchr(ptr, ' ');
ptr = nextArg(ptr);
if (ptr) {
if (!requireValue) {
cliShowParseError();
return;
}
value = atoi(++ptr);
value = atoi(ptr);
value = CHANNEL_VALUE_TO_RXFAIL_STEP(value);
if (value > MAX_RXFAIL_RANGE_STEP) {
cliPrint("Value out of range\r\n");
@ -1164,17 +1174,17 @@ static void cliAux(char *cmdline)
if (i < MAX_MODE_ACTIVATION_CONDITION_COUNT) {
modeActivationCondition_t *mac = &masterConfig.modeActivationConditions[i];
uint8_t validArgumentCount = 0;
ptr = strchr(ptr, ' ');
ptr = nextArg(ptr);
if (ptr) {
val = atoi(++ptr);
val = atoi(ptr);
if (val >= 0 && val < CHECKBOX_ITEM_COUNT) {
mac->modeId = val;
validArgumentCount++;
}
}
ptr = strchr(ptr, ' ');
ptr = nextArg(ptr);
if (ptr) {
val = atoi(++ptr);
val = atoi(ptr);
if (val >= 0 && val < MAX_AUX_CHANNEL_COUNT) {
mac->auxChannelIndex = val;
validArgumentCount++;
@ -1254,20 +1264,20 @@ static void cliSerial(char *cmdline)
validArgumentCount++;
}
ptr = strchr(ptr, ' ');
ptr = nextArg(ptr);
if (ptr) {
val = atoi(++ptr);
val = atoi(ptr);
portConfig.functionMask = val & 0xFFFF;
validArgumentCount++;
}
for (i = 0; i < 4; i ++) {
ptr = strchr(ptr, ' ');
ptr = nextArg(ptr);
if (!ptr) {
break;
}
val = atoi(++ptr);
val = atoi(ptr);
uint8_t baudRateIndex = lookupBaudRateIndex(val);
if (baudRates[baudRateIndex] != (uint32_t) val) {
@ -1434,17 +1444,17 @@ static void cliAdjustmentRange(char *cmdline)
adjustmentRange_t *ar = &masterConfig.adjustmentRanges[i];
uint8_t validArgumentCount = 0;
ptr = strchr(ptr, ' ');
ptr = nextArg(ptr);
if (ptr) {
val = atoi(++ptr);
val = atoi(ptr);
if (val >= 0 && val < MAX_SIMULTANEOUS_ADJUSTMENT_COUNT) {
ar->adjustmentIndex = val;
validArgumentCount++;
}
}
ptr = strchr(ptr, ' ');
ptr = nextArg(ptr);
if (ptr) {
val = atoi(++ptr);
val = atoi(ptr);
if (val >= 0 && val < MAX_AUX_CHANNEL_COUNT) {
ar->auxChannelIndex = val;
validArgumentCount++;
@ -1453,17 +1463,17 @@ static void cliAdjustmentRange(char *cmdline)
ptr = processChannelRangeArgs(ptr, &ar->range, &validArgumentCount);
ptr = strchr(ptr, ' ');
ptr = nextArg(ptr);
if (ptr) {
val = atoi(++ptr);
val = atoi(ptr);
if (val >= 0 && val < ADJUSTMENT_FUNCTION_COUNT) {
ar->adjustmentFunction = val;
validArgumentCount++;
}
}
ptr = strchr(ptr, ' ');
ptr = nextArg(ptr);
if (ptr) {
val = atoi(++ptr);
val = atoi(ptr);
if (val >= 0 && val < MAX_AUX_CHANNEL_COUNT) {
ar->auxSwitchChannelIndex = val;
validArgumentCount++;
@ -1531,9 +1541,9 @@ static void cliMotorMix(char *cmdline)
for (uint32_t i = 0; i < MAX_SUPPORTED_MOTORS; i++)
masterConfig.customMotorMixer[i].throttle = 0.0f;
} else if (strncasecmp(cmdline, "load", 4) == 0) {
ptr = strchr(cmdline, ' ');
ptr = nextArg(cmdline);
if (ptr) {
len = strlen(++ptr);
len = strlen(ptr);
for (uint32_t i = 0; ; i++) {
if (mixerNames[i] == NULL) {
cliPrint("Invalid name\r\n");
@ -1551,30 +1561,30 @@ static void cliMotorMix(char *cmdline)
ptr = cmdline;
uint32_t i = atoi(ptr); // get motor number
if (i < MAX_SUPPORTED_MOTORS) {
ptr = strchr(ptr, ' ');
ptr = nextArg(ptr);
if (ptr) {
masterConfig.customMotorMixer[i].throttle = fastA2F(++ptr);
masterConfig.customMotorMixer[i].throttle = fastA2F(ptr);
check++;
}
ptr = strchr(ptr, ' ');
ptr = nextArg(ptr);
if (ptr) {
masterConfig.customMotorMixer[i].roll = fastA2F(++ptr);
masterConfig.customMotorMixer[i].roll = fastA2F(ptr);
check++;
}
ptr = strchr(ptr, ' ');
ptr = nextArg(ptr);
if (ptr) {
masterConfig.customMotorMixer[i].pitch = fastA2F(++ptr);
masterConfig.customMotorMixer[i].pitch = fastA2F(ptr);
check++;
}
ptr = strchr(ptr, ' ');
ptr = nextArg(ptr);
if (ptr) {
masterConfig.customMotorMixer[i].yaw = fastA2F(++ptr);
masterConfig.customMotorMixer[i].yaw = fastA2F(ptr);
check++;
}
if (check != 4) {
cliShowParseError();
} else {
cliMotorMix("");
printMotorMix(DUMP_MASTER, NULL);
}
} else {
cliShowArgumentRangeError("index", 0, MAX_SUPPORTED_MOTORS - 1);
@ -1622,15 +1632,15 @@ static void cliRxRange(char *cmdline)
if (i >= 0 && i < NON_AUX_CHANNEL_COUNT) {
int rangeMin, rangeMax;
ptr = strchr(ptr, ' ');
ptr = nextArg(ptr);
if (ptr) {
rangeMin = atoi(++ptr);
rangeMin = atoi(ptr);
validArgumentCount++;
}
ptr = strchr(ptr, ' ');
ptr = nextArg(ptr);
if (ptr) {
rangeMax = atoi(++ptr);
rangeMax = atoi(ptr);
validArgumentCount++;
}
@ -1680,8 +1690,8 @@ static void cliLed(char *cmdline)
ptr = cmdline;
i = atoi(ptr);
if (i < LED_MAX_STRIP_LENGTH) {
ptr = strchr(cmdline, ' ');
if (!parseLedStripConfig(i, ++ptr)) {
ptr = nextArg(cmdline);
if (!parseLedStripConfig(i, ptr)) {
cliShowParseError();
}
} else {
@ -1728,8 +1738,8 @@ static void cliColor(char *cmdline)
ptr = cmdline;
i = atoi(ptr);
if (i < LED_CONFIGURABLE_COLOR_COUNT) {
ptr = strchr(cmdline, ' ');
if (!parseColor(i, ++ptr)) {
ptr = nextArg(cmdline);
if (!parseColor(i, ptr)) {
cliShowParseError();
}
} else {
@ -1982,9 +1992,9 @@ static void cliServoMix(char *cmdline)
masterConfig.servoConf[i].reversedSources = 0;
}
} else if (strncasecmp(cmdline, "load", 4) == 0) {
ptr = strchr(cmdline, ' ');
ptr = nextArg(cmdline);
if (ptr) {
len = strlen(++ptr);
len = strlen(ptr);
for (uint32_t i = 0; ; i++) {
if (mixerNames[i] == NULL) {
cliPrintf("Invalid name\r\n");
@ -2280,25 +2290,25 @@ static void cliVtx(char *cmdline)
if (i < MAX_CHANNEL_ACTIVATION_CONDITION_COUNT) {
vtxChannelActivationCondition_t *cac = &masterConfig.vtxChannelActivationConditions[i];
uint8_t validArgumentCount = 0;
ptr = strchr(ptr, ' ');
ptr = nextArg(ptr);
if (ptr) {
val = atoi(++ptr);
val = atoi(ptr);
if (val >= 0 && val < MAX_AUX_CHANNEL_COUNT) {
cac->auxChannelIndex = val;
validArgumentCount++;
}
}
ptr = strchr(ptr, ' ');
ptr = nextArg(ptr);
if (ptr) {
val = atoi(++ptr);
val = atoi(ptr);
if (val >= VTX_BAND_MIN && val <= VTX_BAND_MAX) {
cac->band = val;
validArgumentCount++;
}
}
ptr = strchr(ptr, ' ');
ptr = nextArg(ptr);
if (ptr) {
val = atoi(++ptr);
val = atoi(ptr);
if (val >= VTX_CHANNEL_MIN && val <= VTX_CHANNEL_MAX) {
cac->channel = val;
validArgumentCount++;