From 465278bde947273d2db352eba2dfeea2addc7b11 Mon Sep 17 00:00:00 2001 From: Simon Frei Date: Thu, 1 Dec 2022 16:07:32 +0100 Subject: [PATCH] receive cmd from esp, parsing no working yet --- ADIS_Sumo_Styger/Sumo/Remote.c | 33 ++++++++++++++++++- ADIS_Sumo_Styger/source/IncludeMcuLibConfig.h | 7 ++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/ADIS_Sumo_Styger/Sumo/Remote.c b/ADIS_Sumo_Styger/Sumo/Remote.c index 7b806fe..661de1d 100644 --- a/ADIS_Sumo_Styger/Sumo/Remote.c +++ b/ADIS_Sumo_Styger/Sumo/Remote.c @@ -12,6 +12,7 @@ #include "Shell.h" #include "Buzzer.h" #include "McuESP32.h" +#include "McuLog.h" /*! \todo ADIS: This is a (mostly empty) template where the remote commands from the ESP32 could be handled. This module should be extended to send data back to the ESP32 */ @@ -30,7 +31,11 @@ void REMOTE_GatewayRxFromESP(unsigned char ch) { static void RemoteTask(void *pv) { unsigned char ch; BaseType_t res; - + unsigned char espMsg[McuShell_DEFAULT_SHELL_BUFFER_SIZE] = ""; + const char espMsgPrefix[] = "@robot:cmd "; + const char espMsgPostfix[] = "!\r\n"; + uint8_t saveChar = 0; + uint8_t writeIndex = 0; (void)pv; /* not used */ #if 0 /* example making a beep */ BUZ_Beep(200, 500); @@ -55,13 +60,39 @@ static void RemoteTask(void *pv) { res = xQueueReceive(REMOTE_RxFromESP_Queue, &ch, pdMS_TO_TICKS(10)); /* wait max 10 ms */ if (res==errQUEUE_EMPTY) { ch = '\0'; /* nothing received */ + } else if(res == pdPASS) { /* something was received */ /* handle remote stream from ESP */ +// uint8_t mCh = (uint8_t)ch; +// uint8_t mCh[10] = "Char: "; +// unsigned char newLine = '\n'; +// McuUtility_strcat(mCh, 10, &ch); +// McuUtility_strcat(mCh, 10, &newLine); +// McuShell_SendStr(mCh, McuShell_GetStdio()->stdOut); if(ch == '@'){ + saveChar = 1; + writeIndex = 0; BUZ_Beep(200, 500); } + if(saveChar == 1){ + espMsg[writeIndex++] = ch; + } + if(ch == '!' && saveChar == 1){ + saveChar = 0; + McuShell_SendStr(espMsg, McuShell_GetStdio()->stdOut); + McuShell_SendStr((uint8_t*)" okok.\r\n", McuShell_GetStdio()->stdOut); + if (McuUtility_strncmp(espMsg, espMsgPrefix, sizeof(espMsgPrefix)-1)==0) { /* check prefix */ + unsigned char recCmd[32] = {0}; + memmove(recCmd,espMsg[11],writeIndex); + McuShell_SendStr(recCmd, McuShell_GetStdio()->stdOut); + } + }else if(writeIndex == McuShell_DEFAULT_SHELL_BUFFER_SIZE && saveChar == 1){ + saveChar = 0; + McuShell_SendStr(espMsg, McuShell_GetStdio()->stdOut); + McuShell_SendStr((uint8_t*)" Error in cmd.\r\n", McuShell_GetStdio()->stdOut); + } } } } diff --git a/ADIS_Sumo_Styger/source/IncludeMcuLibConfig.h b/ADIS_Sumo_Styger/source/IncludeMcuLibConfig.h index 5df2d11..fd62bd0 100644 --- a/ADIS_Sumo_Styger/source/IncludeMcuLibConfig.h +++ b/ADIS_Sumo_Styger/source/IncludeMcuLibConfig.h @@ -31,6 +31,13 @@ #define McuShell_CONFIG_MULTI_CMD_SIZE (96) /* maximum size of a single command in a multi-command string */ #define McuShell_CONFIG_PROMPT_STRING "ROBO> " #define McuShell_CONFIG_ECHO_ENABLED (1) + +/* Mcu log */ +#define McuLog_CONFIG_IS_ENABLED (1) +#define McuLog_CONFIG_USE_RTT_CONSOLE (1) +#define McuLog_CONFIG_LOG_TIMESTAMP_DATE (0) // disable since time is not used +#define McuLog_CONFIG_LOG_TIMESTAMP_TIME (0) + /* ---------------------------------------------------------------------------------------*/ /* I2C and OLED */ //#define CONFIG_I2C_USE_PORT_B (1) /* tinyK22: PTB0, PTB1 */