Merge remote-tracking branch 'origin/feature/sendCommands' into main

main
Jonas Arnold 4 years ago
commit 1d8ed622d8
  1. 40
      ADIS_tinyK22_SplitFlap/source/shell.c
  2. 5
      ADIS_tinyK22_SplitFlap/source/shell.h

@ -12,13 +12,13 @@
#include "McuShellUart.h" #include "McuShellUart.h"
#include "McuLog.h" #include "McuLog.h"
#include "McuUtility.h" #include "McuUtility.h"
#include "MotOffsetTable.h"
#include "multi-splitflap.h"
#define SHELL_CMD_ELEM_SIZE (sizeof(Shell_cmd_s)) #define SHELL_CMD_ELEM_SIZE (sizeof(Shell_cmd_s))
static QueueHandle_t shellCmdQueue; static QueueHandle_t shellCmdQueue;
static uint8_t splitFlapId = 0;
static void vQueueShellCmd(Shell_cmd_s shellCmd){ static void vQueueShellCmd(Shell_cmd_s shellCmd){
if(xQueueSendToBack(shellCmdQueue, &shellCmd, pdMS_TO_TICKS(100)) != pdPASS){ if(xQueueSendToBack(shellCmdQueue, &shellCmd, pdMS_TO_TICKS(100)) != pdPASS){
McuLog_warn("Failed adding shell cmd to queue, maybe full?"); McuLog_warn("Failed adding shell cmd to queue, maybe full?");
@ -26,31 +26,49 @@ static void vQueueShellCmd(Shell_cmd_s shellCmd){
} }
static uint8_t ParseCommand(const uint8_t *cmd, bool *handled, McuShell_ConstStdIOType *io){ static uint8_t ParseCommand(const uint8_t *cmd, bool *handled, McuShell_ConstStdIOType *io){
uint8_t size = sizeof(SHELL_CMD_IDENTIFY_SF)-1;
if (McuUtility_strcmp((char*)cmd, McuShell_CMD_HELP)==0) { if (McuUtility_strcmp((char*)cmd, McuShell_CMD_HELP)==0) {
McuShell_SendStr((unsigned char*)"\r\n", io->stdOut); McuShell_SendStr((unsigned char*)"\r\n", io->stdOut);
McuShell_SendStr((unsigned char*)McuShell_DASH_LINE, io->stdOut); McuShell_SendStr((unsigned char*)McuShell_DASH_LINE, io->stdOut);
McuShell_SendStr((unsigned char*)"\r\n", io->stdOut); McuShell_SendStr((unsigned char*)"\r\n", io->stdOut);
McuShell_SendHelpStr((unsigned char*)"SplitFlap Help", (const unsigned char*)"Group of SplitFlap commands\r\n", io->stdOut); McuShell_SendHelpStr((unsigned char*)"SplitFlap Help", (const unsigned char*)"Group of SplitFlap commands\r\n", io->stdOut);
McuShell_SendHelpStr((unsigned char*)" help", (const unsigned char*)"Print help this message\r\n", io->stdOut); McuShell_SendHelpStr((unsigned char*)" help", (const unsigned char*)"Print help this message\r\n", io->stdOut);
McuShell_SendHelpStr((unsigned char*)SHELL_CMD_IDENTIFY_SF, (const unsigned char*)"<SplitFlapId> (uint8_t)\r\n", io->stdOut); McuShell_SendHelpStr((unsigned char*)SHELL_CMD_IDENTIFY_SF, (const unsigned char*)"<SetupIdentifier> <HardwareIdentifier> (uint8_t) (uint8_t)\r\n", io->stdOut);
McuShell_SendHelpStr((unsigned char*)" ", (const unsigned char*)"the number printed on the splitflap\r\n", io->stdOut);
McuShell_SendHelpStr((unsigned char*)" ", (const unsigned char*)"Splitflap Number:16\r\n", io->stdOut);
McuShell_SendHelpStr((unsigned char*)SHELL_CMD_POWEROFF_RPI, (const unsigned char*)"power of the raspberry pi\r\n", io->stdOut); McuShell_SendHelpStr((unsigned char*)SHELL_CMD_POWEROFF_RPI, (const unsigned char*)"power of the raspberry pi\r\n", io->stdOut);
McuShell_SendHelpStr((unsigned char*)SHELL_CMD_INIT_ALL_SF, (const unsigned char*)"init all Splitflaps\r\n", io->stdOut);
*handled = TRUE; *handled = TRUE;
return ERR_OK; return ERR_OK;
} else if(McuUtility_strncmp((char*)cmd, SHELL_CMD_IDENTIFY_SF, size) == 0){ } else if(McuUtility_strncmp((char*)cmd, SHELL_CMD_IDENTIFY_SF, sizeof(SHELL_CMD_IDENTIFY_SF)-1) == 0){
int32_t hwId = 0;
int32_t setupId = 0;
*handled = TRUE; *handled = TRUE;
cmd += sizeof(SHELL_CMD_IDENTIFY_SF)-1; cmd += sizeof(SHELL_CMD_IDENTIFY_SF)-1;
if(McuUtility_ScanDecimal8uNumber(&cmd, &splitFlapId) != ERR_OK){ if(McuUtility_xatoi(&cmd, &setupId) == ERR_OK){
// Do not save id // validate param
if(setupId > NUM_FLAPS){
return ERR_FAILED;
}
}else{
return ERR_FAILED;
}
// second param
cmd++;
if(McuUtility_xatoi(&cmd, &hwId) == ERR_OK){
// validate param
if(MotOffset_Get(hwId, NULL) != ERR_OK){
return ERR_FAILED;
}
}else{
return ERR_FAILED; return ERR_FAILED;
} }
Shell_cmd_s shellCmd = {.shellCmd = Shell_Identify_SF, .value = (uint32_t)splitFlapId}; 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};
vQueueShellCmd(shellCmd); vQueueShellCmd(shellCmd);
} else if(McuUtility_strcmp((char*)cmd,SHELL_CMD_POWEROFF_RPI) == 0){ } else if(McuUtility_strcmp((char*)cmd,SHELL_CMD_POWEROFF_RPI) == 0){
// shutown rpi // shutown rpi
Shell_cmd_s shellCmd = {.shellCmd = Shell_Powerof_rpi, .value = 0}; Shell_cmd_s shellCmd = {.shellCmd = Shell_Powerof_rpi, .numberOfParams = 0};
vQueueShellCmd(shellCmd);
}else if(McuUtility_strcmp((char*)cmd, SHELL_CMD_INIT_ALL_SF) == 0){
Shell_cmd_s shellCmd = {.shellCmd = Shell_Init_All_SF, .numberOfParams = 0};
vQueueShellCmd(shellCmd); vQueueShellCmd(shellCmd);
} }
return ERR_OK; return ERR_OK;

@ -12,18 +12,21 @@
#define SHELL_CMD_IDENTIFY_SF "Splitflap Number:" #define SHELL_CMD_IDENTIFY_SF "Splitflap Number:"
#define SHELL_CMD_POWEROFF_RPI "Shutdown RPI" #define SHELL_CMD_POWEROFF_RPI "Shutdown RPI"
#define SHELL_CMD_INIT_ALL_SF "Init All SplitFlaps"
#define SHELL_CMD_QUEUE_LENGTH 5 #define SHELL_CMD_QUEUE_LENGTH 5
typedef enum ShellCmd { typedef enum ShellCmd {
Shell_Identify_SF, Shell_Identify_SF,
Shell_Init_All_SF,
Shell_Powerof_rpi Shell_Powerof_rpi
}Shell_cmd_t; }Shell_cmd_t;
typedef struct ShellCmd_s { typedef struct ShellCmd_s {
Shell_cmd_t shellCmd; Shell_cmd_t shellCmd;
uint32_t value; int32_t numberOfParams;
int32_t params[4];
}Shell_cmd_s; }Shell_cmd_s;

Loading…
Cancel
Save