/* Data received by the nrf 52840 from the nrf 9160  when the 
print statement is placed in this part of the program 
                       printk("%s",data_array);
		       index = 0;
		       memset(data_array, 0, sizeof(data_array));
The nrf 9150 use the following progam to send the data

*/ 
*** Booting Zephyr OS build v2.4.99-ncs1  ***
UART sample start!
.** Booting Zephyr OS build v2.4.99-ncs2  ***



Flash regions		Domain		Permissions



00 00 000000 0x08000 	Secure		rwxl



01 31 x00 0x100000 	Non-Secure	rwxl







Non-sr lable region 0 placed in flash region 0 with size 32.







ÿÿ[02]I[19]}U[05]IQ[15][01][02][02][02][02][02][02][02][02][02]•ÕÉ•-%Aº[02]I[19]}Q]%5[01][02][02][02][02][02][02][02][02][02][02]½¹M•ÕÉ•=-Â[02]I[19]}MA%5[01][02][02][02][02][02][02][02][02][02][02]½¹M•ÕÉ•=-Ê[02]I[19]}Q%5[15]I[01][02][02][02][02][02][02][02][02][02]½¹M•ÕÉ•=-…‚[02]I[19]}Q%5[15]I[01][02][02][02][02][02][02][02][02][02]½¹M•ÕÉ•=-…Š[02]I[19]}Q%5[15]I[01][02][02][02][02][02][02][02][02][02]½¹M•ÕÉ•=-…’[02]I[19]}M[05][05][11]

[01][02][02][02][02][02][02][02][02][02]½¹M•ÕÉ•=-…š[02]I[19]}A]5[01][02][02][02][02][02][02][02][02][02][02][02]½¹M•ÕÉ•=-…¢[02]I[19]}A]5[01][02][02][02][02][02][02][02][02][02][02][02]½¹M•ÕÉ•=-…ª[02]I[19]}A]5[01][02][02][02][02][02][02][02][02][02][02][02]½¹M•ÕÉ•=-…²[02]I[19]}A]5[01][02][02][02][02][02][02][02][02][02][02][02]½¹M•ÕÉ•=-…º[02]I[19]}][11]Q[01][02][02][02][02][02][02][02][02][02][02][02]½¹M•ÕÉ•=-…Â[02]I[19]}%A

[01][02][02][02][02][02][02][02][02][02][02][02]½¹M•ÕÉ•=-…Ê[02]I[19]}Y5

[01][02][02][02][02][02][02][02][02][02][02][02]½¹M•ÕÉ•=-‰‚[02]I[19]}[19]AU[01][02][02][02][02][02][02][02][02][02][02][02]½¹M•ÕÉ•=-‰Š[02]I[19]}[15][1D]U[01][02][02][02][02][02][02][02][02][02][02][02]½¹M•ÕÉ•=-‘’[02]I[19]}[15][1D]U[01][02][02][02][02][02][02][02][02][02][02][02]½¹M•ÕÉ•=-™š[02]I[19]}[11]AA%

[01][02][02][02][02][02][02][02][02][02]½¹M•ÕÉ•=-‰¢[02]I[19]}I[15][1D]U1[05]Q=IM[01][02][02][02][02]½¹M•ÕÉ•=-‰ª[02]I[19]}[1D]A%=Q[15][01][02][02][02][02][02][02][02][02]½¹M•ÕÉ•=-A5M¥µ…•…ÑÁ:[05]¥[02]M5MA…ÑÁŠ‚²*A5MÉ•Í•ÑÙ•Ñ½É…ÑÁ‘‘A5É•Á…É•Ñ½©ÕµÁÑ½9½¹M•ÕÉ•¥µ…•*** Booting Zephyr OS build v2.4.99-ncs2  ***



ZT01201535554321



ÿ'SSS[13]Hø7SSS[13]HøZT01201535554321



ZT01201535554321



ZT01201535554321



Þ˜NMSS[13]HøZT01201535554321



ZT01201535554321



¯T0120153555432

þLæMSS[13]Høÿü’‚Šªšªªª¢š’Šþþ–Íªªª¢š’Šþ

/* 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_BUF_SIZE 1024

void uart_cb(struct device *uart)
{
	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("%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)
{
        
	struct device *uart = device_get_binding("UART_0");

	uart_irq_callback_set(uart, uart_cb);
	uart_irq_rx_enable(uart);
	printk("UART sample start!\n");
	while (1) {
		k_cpu_idle();
                
	}
}
 
/* prj file settings */
CONFIG_SERIAL=y
CONFIG_TRUSTED_EXECUTION_NONSECURE=y
CONFIG_UART_INTERRUPT_DRIVEN=y

#
# Copyright (c) 2019 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
#
# General config
#CONFIG_NEWLIB_LIBC=y
CONFIG_ASSERT=y
CONFIG_TEST_RANDOM_GENERATOR=y
CONFIG_REBOOT=y

# Network
#CONFIG_NETWORKING=y
#CONFIG_NET_NATIVE=n
#CONFIG_NET_SOCKETS=y
#CONFIG_NET_SOCKETS_OFFLOAD=y

# BSD library
#CONFIG_BSD_LIBRARY=y

# Stacks and heaps
CONFIG_MAIN_STACK_SIZE=8192
CONFIG_HEAP_MEM_POOL_SIZE=16384



#CONFIG_UART_1_NRF_UARTE=y
#CONFIG_UART_1_NRF_FLOW_CONTROL=y
#CONFIG_UART_INTERRUPT_DRIVEN=y

/* Code on the nrf 9160  to transmit the data */

include <zephyr.h>
#include <sys/printk.h>

void main(void)
{         
   char message[]="ZT01201535554321\n"; 
     /* for(int i=0; i <sizeof(message); i++)
          {     
	  printk("%c",message[i]);
         // k_sleep(K_MSEC(200));
        }
        printk("\n"); */
 for(int i=0; i < 20; i++)
 {
      printk("%s",message);
      k_sleep(K_MSEC(200));
  }     
}

