Code: Select all
bool ParseSystemCmd(char *line, uint16_t cmd_size)
{
if (!strncmp("ping", line,4))
{
printf("pong\n");
return true;
}
if (!strncmp("red:", line,4))
{
if (!isdigit(line[4]))
{
ESP_LOGW(TAG,"Entered input is not a number");
return 0;
}
char temp_buf[4];
uint16_t data_to_write=0;
for(int i = 0;i <=(strlen(line)-4);i++){
temp_buf[i] = line[4+i];
}
data_to_write = atoi(temp_buf);
RGB_set_red(data_to_write);
return true;
}
return 0;
}
This function is being called when I read incomming UART data:
Code: Select all
void UART0_task(void *argument)
{
UART0_setup();
unsigned int char_received=EOF;
unsigned int char_counter=0;
char command_line[UART0_COMMAND_LINE_MAX_SIZE];
for (;;)
{
int len = uart_read_bytes(UART_NUM_0, command_line, (UART0_COMMAND_LINE_MAX_SIZE - 1), 20 / portTICK_PERIOD_MS);
if (len) {
command_line[len] = 0;
ParseSystemCmd(command_line, len); // Line is complete. Execute it!
memset(&command_line, 0, sizeof(command_line));
}
vTaskDelay(10/portTICK_PERIOD_MS);
}
Code: Select all
error: array subscript has type 'char' [-Werror=char-subscripts]
Code: Select all
if (!isdigit(line[4]))
{
ESP_LOGW(TAG,"Entered input is not a number");
return 0;
}
red:50 is valid
red:x1 is not valid