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

Made CLI error messages consistent.

This commit is contained in:
Michael Keller 2018-09-19 10:35:13 +12:00
parent ea6c21f1e6
commit 811775748b

View file

@ -377,12 +377,12 @@ static void cliPrintLinef(const char *format, ...)
static void cliPrintErrorLinef(const char *format, ...) static void cliPrintErrorLinef(const char *format, ...)
{ {
cliPrint("###ERROR### "); cliPrint("###");
va_list va; va_list va;
va_start(va, format); va_start(va, format);
cliPrintfva(format, va); cliPrintfva(format, va);
va_end(va); va_end(va);
cliPrintLinefeed(); cliPrintLine("###");
} }
static void cliPrintCorruptMessage(int value) static void cliPrintCorruptMessage(int value)
@ -701,12 +701,12 @@ static void cliPrompt(void)
static void cliShowParseError(void) static void cliShowParseError(void)
{ {
cliPrintErrorLinef("Parse error"); cliPrintErrorLinef("PARSE ERROR");
} }
static void cliShowArgumentRangeError(char *name, int min, int max) static void cliShowArgumentRangeError(char *name, int min, int max)
{ {
cliPrintErrorLinef("%s not between %d and %d", name, min, max); cliPrintErrorLinef("%s NOT BETWEEN %d AND %d", name, min, max);
} }
static const char *nextArg(const char *currentArg) static const char *nextArg(const char *currentArg)
@ -857,7 +857,7 @@ static void cliRxFailsafe(char *cmdline)
); );
} }
} else { } else {
cliShowArgumentRangeError("channel", 0, MAX_SUPPORTED_RC_CHANNEL_COUNT - 1); cliShowArgumentRangeError("CHANNEL", 0, MAX_SUPPORTED_RC_CHANNEL_COUNT - 1);
} }
} }
} }
@ -967,7 +967,7 @@ static void cliAux(char *cmdline)
mac->linkedTo mac->linkedTo
); );
} else { } else {
cliShowArgumentRangeError("index", 0, MAX_MODE_ACTIVATION_CONDITION_COUNT - 1); cliShowArgumentRangeError("INDEX", 0, MAX_MODE_ACTIVATION_CONDITION_COUNT - 1);
} }
} }
} }
@ -1343,7 +1343,7 @@ static void cliAdjustmentRange(char *cmdline)
); );
} else { } else {
cliShowArgumentRangeError("index", 0, MAX_ADJUSTMENT_RANGE_COUNT - 1); cliShowArgumentRangeError("INDEX", 0, MAX_ADJUSTMENT_RANGE_COUNT - 1);
} }
} }
} }
@ -1410,7 +1410,7 @@ static void cliMotorMix(char *cmdline)
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) {
cliPrintErrorLinef("Invalid name"); cliPrintErrorLinef("INVALID NAME");
break; break;
} }
if (strncasecmp(ptr, mixerNames[i], len) == 0) { if (strncasecmp(ptr, mixerNames[i], len) == 0) {
@ -1451,7 +1451,7 @@ static void cliMotorMix(char *cmdline)
printMotorMix(DUMP_MASTER, customMotorMixer(0), NULL); printMotorMix(DUMP_MASTER, customMotorMixer(0), NULL);
} }
} else { } else {
cliShowArgumentRangeError("index", 0, MAX_SUPPORTED_MOTORS - 1); cliShowArgumentRangeError("INDEX", 0, MAX_SUPPORTED_MOTORS - 1);
} }
} }
#endif #endif
@ -1522,7 +1522,7 @@ static void cliRxRange(char *cmdline)
} }
} else { } else {
cliShowArgumentRangeError("channel", 0, NON_AUX_CHANNEL_COUNT - 1); cliShowArgumentRangeError("CHANNEL", 0, NON_AUX_CHANNEL_COUNT - 1);
} }
} }
} }
@ -1568,7 +1568,7 @@ static void cliLed(char *cmdline)
cliShowParseError(); cliShowParseError();
} }
} else { } else {
cliShowArgumentRangeError("index", 0, LED_MAX_STRIP_LENGTH - 1); cliShowArgumentRangeError("INDEX", 0, LED_MAX_STRIP_LENGTH - 1);
} }
} }
} }
@ -1605,7 +1605,7 @@ static void cliColor(char *cmdline)
cliShowParseError(); cliShowParseError();
} }
} else { } else {
cliShowArgumentRangeError("index", 0, LED_CONFIGURABLE_COLOR_COUNT - 1); cliShowArgumentRangeError("INDEX", 0, LED_CONFIGURABLE_COLOR_COUNT - 1);
} }
} }
} }
@ -1879,7 +1879,7 @@ static void cliServoMix(char *cmdline)
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) {
cliPrintErrorLinef("Invalid name"); cliPrintErrorLinef("INVALID NAME");
break; break;
} }
if (strncasecmp(ptr, mixerNames[i], len) == 0) { if (strncasecmp(ptr, mixerNames[i], len) == 0) {
@ -2235,7 +2235,7 @@ static void cliVtx(char *cmdline)
); );
} }
} else { } else {
cliShowArgumentRangeError("index", 0, MAX_CHANNEL_ACTIVATION_CONDITION_COUNT - 1); cliShowArgumentRangeError("INDEX", 0, MAX_CHANNEL_ACTIVATION_CONDITION_COUNT - 1);
} }
} }
} }
@ -2262,13 +2262,13 @@ static void cliName(char *cmdline)
#if defined(USE_BOARD_INFO) #if defined(USE_BOARD_INFO)
#define ERROR_MESSAGE "%s cannot be changed. Current value: '%s'" #define ERROR_MESSAGE "%s CANNOT BE CHANGED. CURRENT VALUE: '%s'"
static void cliBoardName(char *cmdline) static void cliBoardName(char *cmdline)
{ {
const unsigned int len = strlen(cmdline); const unsigned int len = strlen(cmdline);
if (len > 0 && boardInformationIsSet() && (len != strlen(getBoardName()) || strncmp(getBoardName(), cmdline, len))) { if (len > 0 && boardInformationIsSet() && (len != strlen(getBoardName()) || strncmp(getBoardName(), cmdline, len))) {
cliPrintErrorLinef(ERROR_MESSAGE, "board_name", getBoardName()); cliPrintErrorLinef(ERROR_MESSAGE, "BOARD_NAME", getBoardName());
} else { } else {
if (len > 0) { if (len > 0) {
setBoardName(cmdline); setBoardName(cmdline);
@ -2282,7 +2282,7 @@ static void cliManufacturerId(char *cmdline)
{ {
const unsigned int len = strlen(cmdline); const unsigned int len = strlen(cmdline);
if (len > 0 && boardInformationIsSet() && (len != strlen(getManufacturerId()) || strncmp(getManufacturerId(), cmdline, len))) { if (len > 0 && boardInformationIsSet() && (len != strlen(getManufacturerId()) || strncmp(getManufacturerId(), cmdline, len))) {
cliPrintErrorLinef(ERROR_MESSAGE, "manufacturer_id", getManufacturerId()); cliPrintErrorLinef(ERROR_MESSAGE, "MANUFACTURER_ID", getManufacturerId());
} else { } else {
if (len > 0) { if (len > 0) {
setManufacturerId(cmdline); setManufacturerId(cmdline);
@ -2307,7 +2307,7 @@ static void cliSignature(char *cmdline)
uint8_t signature[SIGNATURE_LENGTH] = {0}; uint8_t signature[SIGNATURE_LENGTH] = {0};
if (len > 0) { if (len > 0) {
if (len != 2 * SIGNATURE_LENGTH) { if (len != 2 * SIGNATURE_LENGTH) {
cliPrintErrorLinef("Invalid length: %d (expected: %d)", len, 2 * SIGNATURE_LENGTH); cliPrintErrorLinef("INVALID LENGTH: %d (EXPECTED: %d)", len, 2 * SIGNATURE_LENGTH);
return; return;
} }
@ -2322,7 +2322,7 @@ static void cliSignature(char *cmdline)
if (end == &temp[BLOCK_SIZE]) { if (end == &temp[BLOCK_SIZE]) {
signature[i] = result; signature[i] = result;
} else { } else {
cliPrintErrorLinef("Invalid character found: %c", end[0]); cliPrintErrorLinef("INVALID CHARACTER FOUND: %c", end[0]);
return; return;
} }
@ -2333,7 +2333,7 @@ static void cliSignature(char *cmdline)
char signatureStr[SIGNATURE_LENGTH * 2 + 1] = {0}; char signatureStr[SIGNATURE_LENGTH * 2 + 1] = {0};
if (len > 0 && signatureIsSet() && memcmp(signature, getSignature(), SIGNATURE_LENGTH)) { if (len > 0 && signatureIsSet() && memcmp(signature, getSignature(), SIGNATURE_LENGTH)) {
writeSignature(signatureStr, getSignature()); writeSignature(signatureStr, getSignature());
cliPrintErrorLinef(ERROR_MESSAGE, "signature", signatureStr); cliPrintErrorLinef(ERROR_MESSAGE, "SIGNATURE", signatureStr);
} else { } else {
if (len > 0) { if (len > 0) {
setSignature(signature); setSignature(signature);
@ -2436,7 +2436,7 @@ static void cliFeature(char *cmdline)
for (uint32_t i = 0; ; i++) { for (uint32_t i = 0; ; i++) {
if (featureNames[i] == NULL) { if (featureNames[i] == NULL) {
cliPrintErrorLinef("Invalid name"); cliPrintErrorLinef("INVALID NAME");
break; break;
} }
@ -2517,7 +2517,7 @@ static void processBeeperCommand(char *cmdline, uint32_t *offFlags, const uint32
for (uint32_t i = 0; ; i++) { for (uint32_t i = 0; ; i++) {
if (i == beeperCount) { if (i == beeperCount) {
cliPrintErrorLinef("Invalid name"); cliPrintErrorLinef("INVALID NAME");
break; break;
} }
if (strncasecmp(cmdline, beeperNameForTableIndex(i), len) == 0 && beeperModeMaskForTableIndex(i) & (allowedFlags | BEEPER_GET_FLAG(BEEPER_ALL))) { if (strncasecmp(cmdline, beeperNameForTableIndex(i), len) == 0 && beeperModeMaskForTableIndex(i) & (allowedFlags | BEEPER_GET_FLAG(BEEPER_ALL))) {
@ -2738,7 +2738,7 @@ static int parseOutputIndex(char *pch, bool allowAllEscs) {
} else if (allowAllEscs && outputIndex == ALL_MOTORS) { } else if (allowAllEscs && outputIndex == ALL_MOTORS) {
cliPrintLinef("Using all outputs."); cliPrintLinef("Using all outputs.");
} else { } else {
cliPrintErrorLinef("Invalid output number. Range: 0 %d.", getMotorCount() - 1); cliPrintErrorLinef("INVALID OUTPUT NUMBER. RANGE: 0 - %d.", getMotorCount() - 1);
return -1; return -1;
} }
@ -2909,7 +2909,7 @@ void printEscInfo(const uint8_t *escInfoBuffer, uint8_t bytesRead)
} }
} }
} else { } else {
cliPrintErrorLinef("Checksum Error."); cliPrintErrorLinef("CHECKSUM ERROR.");
} }
} }
} }
@ -2995,7 +2995,7 @@ static void cliDshotProg(char *cmdline)
cliPrintLinef("Command Sent: %d", command); cliPrintLinef("Command Sent: %d", command);
} else { } else {
cliPrintErrorLinef("Invalid command. Range: 1 - %d.", DSHOT_MIN_THROTTLE - 1); cliPrintErrorLinef("INVALID COMMAND. RANGE: 1 - %d.", DSHOT_MIN_THROTTLE - 1);
} }
} }
@ -3087,7 +3087,7 @@ static void cliMixer(char *cmdline)
for (uint32_t i = 0; ; i++) { for (uint32_t i = 0; ; i++) {
if (mixerNames[i] == NULL) { if (mixerNames[i] == NULL) {
cliPrintErrorLinef("Invalid name"); cliPrintErrorLinef("INVALID NAME");
return; return;
} }
if (strncasecmp(cmdline, mixerNames[i], len) == 0) { if (strncasecmp(cmdline, mixerNames[i], len) == 0) {
@ -3134,7 +3134,7 @@ static void cliMotor(char *cmdline)
if (index == 2) { if (index == 2) {
if (motorValue < PWM_RANGE_MIN || motorValue > PWM_RANGE_MAX) { if (motorValue < PWM_RANGE_MIN || motorValue > PWM_RANGE_MAX) {
cliShowArgumentRangeError("value", 1000, 2000); cliShowArgumentRangeError("VALUE", 1000, 2000);
} else { } else {
uint32_t motorOutputValue = convertExternalToMotor(motorValue); uint32_t motorOutputValue = convertExternalToMotor(motorValue);
@ -3171,7 +3171,7 @@ static void cliPlaySound(char *cmdline)
if ((name=beeperNameForTableIndex(i)) != NULL) if ((name=beeperNameForTableIndex(i)) != NULL)
break; //if name OK then play sound below break; //if name OK then play sound below
if (i == lastSoundIdx + 1) { //prevent infinite loop if (i == lastSoundIdx + 1) { //prevent infinite loop
cliPrintErrorLinef("Error playing sound"); cliPrintErrorLinef("ERROR PLAYING SOUND");
return; return;
} }
} }
@ -3361,7 +3361,7 @@ STATIC_UNIT_TESTED void cliGet(char *cmdline)
return; return;
} }
cliPrintErrorLinef("Invalid name"); cliPrintErrorLinef("INVALID NAME");
} }
static uint8_t getWordLength(char *bufBegin, char *bufEnd) static uint8_t getWordLength(char *bufBegin, char *bufEnd)
@ -3509,14 +3509,14 @@ STATIC_UNIT_TESTED void cliSet(char *cmdline)
cliPrintf("%s set to ", val->name); cliPrintf("%s set to ", val->name);
cliPrintVar(val, 0); cliPrintVar(val, 0);
} else { } else {
cliPrintErrorLinef("Invalid value"); cliPrintErrorLinef("INVALID VALUE");
cliPrintVarRange(val); cliPrintVarRange(val);
} }
return; return;
} }
} }
cliPrintErrorLinef("Invalid name"); cliPrintErrorLinef("INVALID NAME");
} else { } else {
// no equals, check for matching variables. // no equals, check for matching variables.
cliGet(cmdline); cliGet(cmdline);
@ -3994,7 +3994,7 @@ static void cliResource(char *cmdline)
pch = strtok_r(cmdline, " ", &saveptr); pch = strtok_r(cmdline, " ", &saveptr);
for (resourceIndex = 0; ; resourceIndex++) { for (resourceIndex = 0; ; resourceIndex++) {
if (resourceIndex >= ARRAYLEN(resourceTable)) { if (resourceIndex >= ARRAYLEN(resourceTable)) {
cliPrintErrorLinef("Invalid"); cliPrintErrorLinef("INVALID");
return; return;
} }
@ -4008,7 +4008,7 @@ static void cliResource(char *cmdline)
if (resourceTable[resourceIndex].maxIndex > 0 || index > 0) { if (resourceTable[resourceIndex].maxIndex > 0 || index > 0) {
if (index <= 0 || index > MAX_RESOURCE_INDEX(resourceTable[resourceIndex].maxIndex)) { if (index <= 0 || index > MAX_RESOURCE_INDEX(resourceTable[resourceIndex].maxIndex)) {
cliShowArgumentRangeError("index", 1, MAX_RESOURCE_INDEX(resourceTable[resourceIndex].maxIndex)); cliShowArgumentRangeError("INDEX", 1, MAX_RESOURCE_INDEX(resourceTable[resourceIndex].maxIndex));
return; return;
} }
index -= 1; index -= 1;
@ -4145,7 +4145,7 @@ static void cliTimer(char *cmdline)
} }
if (timerIOIndex < 0) { if (timerIOIndex < 0) {
cliPrintErrorLinef("Index out of range."); cliPrintErrorLinef("INDEX OUT OF RANGE.");
return; return;
} }