void vSerialHandlerTask ( void * pvParameters) { char buf[BUFFER_SIZE]; char line[BUFFER_SIZE]; char index = 0; char c; // Take the semaphore before entering infinite loop to make sure it's empty. xSemaphoreTake(xSerialHandlerSemaphore, 0); // initialise buffer for (index = 0; index < BUFFER_SIZE; index++){ buf[index] = 0; line[index] = 0; } index = 0; xCommandQueue = xQueueCreate(32, BUFFER_SIZE); for (;;) { xSemaphoreTake(xSerialHandlerSemaphore, portMAX_DELAY); //get char c = 0; c = comm_get(); if (c != 0) { //printf("%c", c); //save in buffer and increment buffer index buf[index++] = c; portENTER_CRITICAL(); //if newline or full, print it and copy the buffer to 'line' string if (c == '\r' || c == '\n' || index >= BUFFER_SIZE){ buf[index] = '\0'; strcpy(line, buf); printf("%s\r\n", buf); fflush(stdout); for (index = 0; index < BUFFER_SIZE; index++) buf[index] = 0; index = 0; printf("Contents of 'line':%s\r\n", line); xQueueSend(xCommandQueue, line, portMAX_DELAY); } portEXIT_CRITICAL(); } else { vConsolePrint("Failed READING\r\n"); } } }
unsigned char xcomm_get(void) { return (unsigned char) comm_get(); }
//for scanf?? int8_t _getc(void){ xprintf("%s{\n",__func__); return comm_get(); }