updated esp command parsing in UDP server on ESP32

main
Jonas Arnold 4 years ago
parent a4c634eccc
commit 67598ab560
  1. 19
      ADIS_ESP32_Eclipse/main/udp_server.c

@ -43,24 +43,21 @@ static int SendToSocket(int sock, const char *msg, const struct sockaddr *to, so
void HandleIncomingUdpMessage(const char *rxMsg, int sock, struct sockaddr *source_addr_p, socklen_t source_addr_len) {
unsigned char response[128];
int err;
unsigned char espMsg[McuShell_DEFAULT_SHELL_BUFFER_SIZE] = "";
const char espMsgPrefix[] = "@esp:";
const char espMsgPostfix[] = "!";
ESP_LOGI(TAG, "handling incoming message %s", rxMsg);
McuUtility_strcpy(response, sizeof(response), (unsigned char*)"OK"); /* default response */
/* check framing */
if (McuUtility_strncmp(rxMsg, "@esp:", sizeof("@esp:")-1)==0) { /* check prefix */
if (McuUtility_strncmp(rxMsg, espMsgPrefix, sizeof(espMsgPrefix)-1)==0) { /* check prefix */
size_t strLen = McuUtility_strlen(rxMsg);
if (rxMsg[strLen-1]=='!') {
/* send to ESP32 shell */
rxMsg += sizeof("@esp:")-1;
unsigned char *cmd = (unsigned char*)calloc(strLen, sizeof(unsigned char));
if(cmd != NULL){
size_t cmdLen = strLen-(sizeof("@esp:")-1)-1;
McuUtility_strcpy(cmd, cmdLen, (const unsigned char *)rxMsg);
SHELL_SendToESPAndGetResponse((unsigned char*)cmd, response, sizeof(response));
}else{
McuUtility_strcpy(response, sizeof(response), (unsigned char*)"Failed to parse cmd!");
for(int i = 0; i < strLen-McuUtility_strlen(espMsgPrefix)-McuUtility_strlen(espMsgPostfix); i++){
espMsg[i] = rxMsg[i + McuUtility_strlen(espMsgPrefix)];
}
SHELL_SendToESPAndGetResponse(espMsg, response, sizeof(response));
} else {
McuUtility_strcpy(response, sizeof(response), (unsigned char*)"!missing!");
}
@ -75,6 +72,8 @@ void HandleIncomingUdpMessage(const char *rxMsg, int sock, struct sockaddr *sour
static void udp_server_task(void *pvParameters) {
char rx_buffer[128];
char addr_str[128];

Loading…
Cancel
Save