From 1bf631b1e02fb275e3e11768512356113d0ad24c Mon Sep 17 00:00:00 2001 From: Simon Frei Date: Fri, 18 Nov 2022 15:39:11 +0100 Subject: [PATCH] improve logs for failure in shell --- ADIS_tinyK22_SplitFlap/source/shell.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/ADIS_tinyK22_SplitFlap/source/shell.c b/ADIS_tinyK22_SplitFlap/source/shell.c index 4c453bd..3b3f159 100644 --- a/ADIS_tinyK22_SplitFlap/source/shell.c +++ b/ADIS_tinyK22_SplitFlap/source/shell.c @@ -30,6 +30,16 @@ static uint8_t PrintHelp(const McuShell_StdIOType *io) { McuShell_SendHelpStr((unsigned char*)" Display ", (const unsigned char*)"displays as many chars of the string as sf are available\r\n", io->stdOut); return ERR_OK; } + +static uint8_t PrintError(const uint8_t *cmd, const uint8_t *msg, const McuShell_StdIOType *io){ + McuShell_SendStr((unsigned char*)"*** Failed command: ", io->stdErr); + McuShell_SendStr(cmd, io->stdErr); + McuShell_SendStr((unsigned char*)"\r\n", io->stdErr); + McuShell_SendStr((unsigned char*)"*** Message: ", io->stdErr); + McuShell_SendStr(msg, io->stdErr); + McuShell_SendStr((unsigned char*)"\r\n", io->stdErr); + return ERR_FAILED; +} #endif static QueueHandle_t shellCmdQueue; @@ -41,6 +51,7 @@ static void vQueueShellCmd(Shell_cmd_s shellCmd){ } static uint8_t ParseCommand(const uint8_t *cmd, bool *handled, McuShell_ConstStdIOType *io){ + const uint8_t *cmdCpy = cmd; if (McuUtility_strcmp((char*)cmd, McuShell_CMD_HELP)==0 || McuUtility_strcmp((char*)cmd, "SplitFlap help")==0) { *handled = TRUE; return PrintHelp(io); @@ -52,12 +63,10 @@ static uint8_t ParseCommand(const uint8_t *cmd, bool *handled, McuShell_ConstStd if(McuUtility_xatoi(&cmd, &setupId) == ERR_OK){ // validate param if(setupId > NUM_MAX_AMOUNT_FLAPS){ - McuLog_error("setupId cannot exists"); - return ERR_FAILED; + return PrintError(cmdCpy, (const uint8_t*)"setupId cannot exist", io); } }else{ - McuLog_error("failed to parse setupId"); - return ERR_FAILED; + return PrintError(cmdCpy, (const uint8_t*)"failed to parse setupId", io); } // second param cmd++; @@ -65,12 +74,10 @@ static uint8_t ParseCommand(const uint8_t *cmd, bool *handled, McuShell_ConstStd // validate param int32_t offset = 0; if(MotOffset_Get(hwId, &offset) != ERR_OK){ - McuLog_error("Splitflap with id %i does not exists",hwId); - return ERR_FAILED; + return PrintError(cmdCpy, (const uint8_t*)"Splitflap with this id does not exist", io); } }else{ - McuLog_error("failed to parse hwId"); - return ERR_FAILED; + return PrintError(cmdCpy, (const uint8_t*)"failed to parse hwId", io); } Shell_cmd_s shellCmd = {.shellCmd = Shell_Identify_SF, .numberOfParams = 2, .params = {hwId,setupId}}; //Shell_cmd_s shellCmd = {.shellCmd = Shell_Identify_SF, .value1 = setupId, .value2 = hwId};