|
|
|
@ -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) { |
|
|
|
void HandleIncomingUdpMessage(const char *rxMsg, int sock, struct sockaddr *source_addr_p, socklen_t source_addr_len) { |
|
|
|
unsigned char response[128]; |
|
|
|
unsigned char response[128]; |
|
|
|
int err; |
|
|
|
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); |
|
|
|
ESP_LOGI(TAG, "handling incoming message %s", rxMsg); |
|
|
|
McuUtility_strcpy(response, sizeof(response), (unsigned char*)"OK"); /* default response */ |
|
|
|
McuUtility_strcpy(response, sizeof(response), (unsigned char*)"OK"); /* default response */ |
|
|
|
/* check framing */ |
|
|
|
/* 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); |
|
|
|
size_t strLen = McuUtility_strlen(rxMsg); |
|
|
|
if (rxMsg[strLen-1]=='!') { |
|
|
|
if (rxMsg[strLen-1]=='!') { |
|
|
|
/* send to ESP32 shell */ |
|
|
|
/* send to ESP32 shell */ |
|
|
|
rxMsg += sizeof("@esp:")-1; |
|
|
|
for(int i = 0; i < strLen-McuUtility_strlen(espMsgPrefix)-McuUtility_strlen(espMsgPostfix); i++){ |
|
|
|
unsigned char *cmd = (unsigned char*)calloc(strLen, sizeof(unsigned char)); |
|
|
|
espMsg[i] = rxMsg[i + McuUtility_strlen(espMsgPrefix)]; |
|
|
|
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!"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
SHELL_SendToESPAndGetResponse(espMsg, response, sizeof(response)); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
McuUtility_strcpy(response, sizeof(response), (unsigned char*)"!missing!"); |
|
|
|
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) { |
|
|
|
static void udp_server_task(void *pvParameters) { |
|
|
|
char rx_buffer[128]; |
|
|
|
char rx_buffer[128]; |
|
|
|
char addr_str[128]; |
|
|
|
char addr_str[128]; |
|
|
|
|