
/* The following code is used to out the above result  if the printk statement
is not a comment. The current version does not print an results with the printk("%s", data_array);  statement 
at the location after "if ((index == UART_BUF_SIZE) ||
			   (data_array[index - 1] == '\n') ||
			   (data_array[index - 1] == '\r')) "*/
#include <zephyr.h>
#include <sys/printk.h>
#include <drivers/uart.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define UART_DEV_NAME DT_LABEL(DT_NODELABEL(uart0))
#define UART_BUF_SIZE 10

static void uart_cb(const struct device * uart, void * user_data)
{
	static uint8_t data_array[UART_BUF_SIZE];
    static uint8_t index = 0;
	uart_irq_update(uart);
	if (uart_irq_rx_ready(uart)) {
		int data_length;

		data_length = uart_fifo_read(uart, &data_array[index],
					     UART_BUF_SIZE-index);
		index += data_length;
                
		if (index > 0) {
                 // printk("Datalength = %d", data_length);
			// printk("%s", data_array);
			if ((index == UART_BUF_SIZE) ||
			   (data_array[index - 1] == '\n') ||
			   (data_array[index - 1] == '\r')) {
                            //printk("index: %c \n",data_array[index - 1]);
				// printk("index: %d \n",index);
				printk("data_array: %s", data_array);
				
				/*char dest[strlen(data_array)];
				strcpy(dest, data_array);
				printk("%s", dest);
				const char ch = ',';
				char *ret;
				ret = strchr(data_array, ch);
				
				if(ret != NULL){
				printk("%s", ret);*/
				}
                               
			}


                       // printk("%s",data_array);
		       index = 0;
		       memset(data_array, 0, sizeof(data_array));
		}
	}
  
void main(void)
{
        
	const struct device * uart = device_get_binding(UART_DEV_NAME);

	uart_irq_callback_set(uart, uart_cb);
	uart_irq_rx_enable(uart);
	printk("UART sample start!\n");
	//while (1) {
		//k_cpu_idle();
                
	//}
}
 