revised Remote.c in Sumo project

main
Jonas Arnold 4 years ago
parent bd07596ada
commit 956f4b9736
  1. 51
      ADIS_Sumo/Sumo/Remote.c

@ -38,7 +38,6 @@ static void RemoteTask(void *pv) {
unsigned char espMsg[McuShell_DEFAULT_SHELL_BUFFER_SIZE] = ""; unsigned char espMsg[McuShell_DEFAULT_SHELL_BUFFER_SIZE] = "";
uint8_t saveChar = 0; uint8_t saveChar = 0;
uint8_t writeIndex = 0; uint8_t writeIndex = 0;
uint8_t readIndex = 0;
(void)pv; /* not used */ (void)pv; /* not used */
#if 0 /* example making a beep */ #if 0 /* example making a beep */
BUZ_Beep(200, 500); BUZ_Beep(200, 500);
@ -69,39 +68,33 @@ static void RemoteTask(void *pv) {
/* something was received */ /* something was received */
/* handle remote stream from ESP */ /* handle remote stream from ESP */
if(ch == '@'){ if(ch == '@'){
saveChar = 1; saveChar = 1; // enable saving
} writeIndex = 0; // initialize string to first position
if(saveChar == 1){ // empty string
espMsg[writeIndex++] = ch; for(uint8_t i = 0; i < McuShell_DEFAULT_SHELL_BUFFER_SIZE; i++){
if(writeIndex >= McuShell_DEFAULT_SHELL_BUFFER_SIZE){ espMsg[i] = '\0';
writeIndex = 0;
} }
} }
/* save characters on and character is termination character */
if(ch == '!' && saveChar == 1){ if(ch == '!' && saveChar == 1){
saveChar = 0; saveChar = 0; // turn off
unsigned char str[McuShell_DEFAULT_SHELL_BUFFER_SIZE] = {'\0'}; // send to shell
if(str != NULL){ McuShell_SendStr((uint8_t *)"Parsed command from ESP32: ", McuShell_GetStdio()->stdOut);
uint8_t i; McuShell_SendStr((uint8_t *)espMsg, McuShell_GetStdio()->stdOut);
for(i = 0; i < McuShell_DEFAULT_SHELL_BUFFER_SIZE; i++){ McuShell_SendStr((uint8_t *)"\r\n", McuShell_GetStdio()->stdOut);
str[i] = espMsg[readIndex++]; // if it is a robot cmd => parse command
if(readIndex >= McuShell_DEFAULT_SHELL_BUFFER_SIZE){ if(McuUtility_strncmp((char *)espMsg,"@robot:cmd ",sizeof("@robot:cmd ")-1) == 0){
readIndex = 0; unsigned char *p;
} p = (unsigned char*)espMsg + sizeof(ESP_MSG_PREFIX) - 1;
if(str[i] == '!'){ //McuUtility_strCutTail((uint8_t*)p, (uint8_t*)ESP_MSG_POSTFIX);
break;
}
}
}
McuShell_SendStr((const uint8_t *)str, McuShell_GetStdio()->stdOut);
if(McuUtility_strncmp((char *)str,"@robot:cmd ",sizeof("@robot:cmd ")-1) == 0){
unsigned char *p;
p = (unsigned char*)str + sizeof(ESP_MSG_PREFIX) - 1;
McuUtility_strCutTail((uint8_t*)p, (uint8_t*)ESP_MSG_POSTFIX);
McuShell_SendStr((uint8_t*)p, McuShell_GetStdio()->stdOut);
SHELL_ParseCommandWithIO((unsigned char*)p, McuESP32_GetTxToESPStdio()); SHELL_ParseCommandWithIO((unsigned char*)p, McuESP32_GetTxToESPStdio());
free(p); }
/* save characters on but character is not termination character */
}else if(saveChar == 1){
espMsg[writeIndex++] = ch;
if(writeIndex >= McuShell_DEFAULT_SHELL_BUFFER_SIZE){
writeIndex = 0; // reset to 0
} }
free(str);
} }
} }
} }

Loading…
Cancel
Save