Hi Mynewt Team, It seems UART is not capable of handling non-asci characters and instead enters new line on occurrence of one.
Thanks, Aditya Xavier. > On 21-Apr-2018, at 5:28 PM, Aditya Xavier <[email protected]> wrote: > > Hi Mynewt Team, > > Am facing issues with console_read API. > > I have a MCU sending CBOR data to nRF over UART. > > Console_read works perfect when receiving data from USB->Serial adapter > (Computer) & RTT. > > Console_read give multiple hits ( i.e. multiple times it would reach either > /*Got Full line - break …*/ or /*Do some work…*/ > > How do I fix such a situation. > > Thanks, > Aditya Xavier. > > > #define MAX_INPUT 128 > > static void > read_function(void *arg) > { > char buf[MAX_INPUT]; > int rc; > int full_line; > int off; > > off = 0; > while (1) { > rc = console_read(buf + off, MAX_INPUT - off, &full_line); > if (rc <= 0 && !full_line) { > continue; > } > off += rc; > if (!full_line) { > if (off == MAX_INPUT) { > /* > * Full line, no newline yet. Reset the input buffer. > */ > off = 0; > } > continue; > } > /* Got full line - break out of the loop and process the input data */ > break; > } > > /* Process the input line here */ > .... > > return; > } > static void myapp_process_input(struct os_event *ev); > > static struct os_eventq avail_queue; > > static struct console_input myapp_console_buf; > > static struct os_event myapp_console_event = { > .ev_cb = myapp_process_input, > .ev_arg = &myapp_console_buf > }; > > /* Event callback to process a line of input from console. */ > static void > myapp_process_input(struct os_event *ev) > { > char *line; > struct console_input *input; > > input = ev->ev_arg; > assert (input != NULL); > > line = input->line; > /* Do some work with line */ > .... > /* Done processing line. Add the event back to the avail_queue */ > os_eventq_put(&avail_queue, ev); > return; > } > > static void > myapp_init(void) > { > os_eventq_init(&avail_queue); > os_eventq_put(&avail_queue, &myapp_console_event); > > console_set_queues(&avail_queue, os_eventq_dflt_get()); > } >
