/*
 * sample_app.c
 *
 *  Created on: 30-Sep-2022
 *      Author: Invcuser52
 */

#include "ft_sample_app_dwnld.h"
#include "ft_sample_app_upload.h"

#include "stdio.h"
#include "file_transfer.h"
#include "ftfci_decode.h"
#include "ftci_decode.h"
#include "segmentation.h"
#include "notify_apps.h"
#include "ps_intf_ctrl_msg.h"



//#define APP_ID 0x1234

uint8_t *gui_savecontext_ptr;
uint16 savecontext_size;

uint8_t gui_savecontext_filebuf[1024];
uint16 savecontext_size_file;

extern uint8_t init_start;
extern uint8_t file_tx_running;

#ifdef FT_OBC
ft_obc_payload ft_pld_obc;


uint8_t obc_flash_handler_busycheck()
{
	return ft_pld_obc.write_request;
}


void Flash_Write_Data (uint64_t write_addr, uint8_t Data)
{
	uint8_t *flash_address;
	flash_address = (uint8_t*)write_addr;
	*flash_address = Data;
}



void obc_flash_write_handler(void)
{
	uint64_t mem_offset;
	if(ft_pld_obc.write_request != 0)
	{

		printf("F%d,",ft_pld_obc.payload_index_inc);

		if(ft_pld_obc.payload_index_inc < ft_pld_obc.payload_len)
		{
			mem_offset = ft_pld_obc.mem_add + ft_pld_obc.payload_index_inc;
			Flash_Write_Data(mem_offset,ft_pld_obc.payload_ptr[ft_pld_obc.payload_index_inc]);
			ft_pld_obc.payload_index_inc++;
		}
		else
		{
			printf("\n");
			ft_pld_obc.write_request = 0;
		}
	}
}




uint8_t ft_payload_obc(uint64_t mem_address, uint8_t *payload_ptr, uint16_t payload_len)
{
	uint8_t ret_busy_sts = 0;
	uint16_t u16cnt;
	if(payload_ptr != NULL)
	{
		if(ft_pld_obc.write_request != 1)
		{
			ft_pld_obc.payload_ptr = malloc(payload_len);
			if(ft_pld_obc.payload_ptr != NULL)
			{
				for(u16cnt = 0; u16cnt< payload_len; u16cnt++)
				{
					ft_pld_obc.payload_ptr[u16cnt] = payload_ptr[u16cnt];
				}
				ft_pld_obc.mem_add = mem_address;
				ft_pld_obc.payload_len = payload_len;
				ft_pld_obc.payload_index_inc = 0;
				ft_pld_obc.write_request = 1;
				ret_busy_sts = 1;
			}
		}
	}
	return ret_busy_sts;
}



uint64_t obc_file_memory_alloc(uint16_t mem_size)
{
	uint64_t mem_ptr;
	mem_ptr = (uint64_t)malloc(mem_size);
	if(mem_ptr != 0)
	{

	}

	return (uint64_t)mem_ptr;
}


#endif



void display_context_info()
{
	ft_contextsave_info *c_info;
	//s_transfer_info* t_info;
	//s_segment_info* s_info;
	uint16_t u16cnt;
	uint16_t calc_buf_size;


	c_info = (ft_contextsave_info*) gui_savecontext_ptr;
	if(c_info->node_operation == ft_upload)
	{

		calc_buf_size = sizeof(ft_contextsave_info);
		//t_info = (s_transfer_info*) &gui_savecontext_ptr[calc_buf_size];

		calc_buf_size = sizeof(ft_contextsave_info) + sizeof(s_transfer_info);
		//s_info = (s_segment_info*) &gui_savecontext_ptr[calc_buf_size];

		calc_buf_size = sizeof(ft_contextsave_info) + sizeof(s_transfer_info) + sizeof(s_segment_info);
		printf("\nFile name saved:size:%d | %d\n",c_info->file_name_size,tx_info.file_name_size);

	}
	else
	{
		calc_buf_size = sizeof(ft_contextsave_info) + sizeof(s_treceive_info);
		printf("\nFile name saved:size:%d | %d\n",c_info->file_name_size,dwnld_rqst.file_name_buf_length);

	}

	for (u16cnt = 0; u16cnt < c_info->file_name_size; u16cnt++)
	{
		printf("%c",gui_savecontext_ptr[calc_buf_size+u16cnt]);
	}
}





/*
 *
 *  Application API which will be invoked during file transmission by FT framework
 *
 */
void app1234_notificataion_api_dwld(ft_notification_info *ft_sts)
{
	uint16_t u16cnt;
	e_avtive_type node_act_type;
	uint8_t ret_sts;

#ifdef FT_OBC
	uint64_t mem_address_alloc;
#endif

	static uint8_t nack_test = 1;

	printf("App notification API invoked !!!!\n");

	if(ft_sts->status == transfer_download_success)
	{
		printf("1. download success\n");
		if(ft_sts->dwld_info.tx_mode == 1)
		{
			printf("2. Transfer mode : DATA\n");
			printf("3. Bulkdata received :");

			for (u16cnt = 0; u16cnt < ft_sts->dwld_info.size_file_or_data; u16cnt++)
			{
				printf("%d,",ft_sts->dwld_info.bulkdata_ptr[u16cnt]);
			}
			printf("\n");
		}
		else
		{
			printf("2. Transfer mode : FILE\n");
			printf("3. File Stored path : ");
			for (u16cnt = 0; u16cnt < ft_sts->dwld_info.path_filename_buf_length; u16cnt++)
			{
				printf("%c",ft_sts->dwld_info.storage_path_and_File_name[u16cnt]);
			}
			printf("\n4. File size : %u",ft_sts->dwld_info.size_file_or_data);
			
#if 0
			printf("\n5. Bin data: \n");
			for (u16cnt = 0; u16cnt < ft_sts->dwld_info.size_file_or_data; u16cnt++)
			{
				printf("%c",ft_sts->dwld_info.bulkdata_ptr[u16cnt]);
			}
			printf("\n");
#endif
		}
		init_start = 0;
	//	file_tx_running = 0;


	}
	else if(ft_sts->status == crc_error)
	{
		printf("1. download failed/ CRC error\n");
		if(ft_sts->dwld_info.tx_mode == 1)
		{
			printf("2. Transfer mode : DATA\n");
		}
		init_start = 0;
	//	file_tx_running = 0;

	}
	else if(ft_sts->status == transfer_suspended)
	{
		printf("1. download suspended by sender [Timeout mode]\n");
	//	display_ft_sts();

	}
	else if(ft_sts->status == transfer_suspended_savecontext)
	{
		printf("1. download suspended by sender [Save Context Mode]\n");
		printf("1. malloc req: %d \n",ft_sts->context_info.context_info_size);

		FILE *fptr_write;
		if ((fptr_write = fopen("ftsct_ps_dnlink.bin","wb")) == NULL)
		{
			printf("Error! file ftsct_ps_dnlink.bin not create fail\n");
		}
		else
		{
			/* write data size */
			fwrite(&ft_sts->context_info.context_info_size, sizeof(uint16_t), 1, fptr_write);
			/* write data */
			for(u16cnt = 0; u16cnt < ft_sts->context_info.context_info_size; u16cnt++)
			{
				fwrite(&ft_sts->context_info.context_info_buf_ptr[u16cnt], sizeof(unsigned char), 1, fptr_write);
			}
			printf("SCT info saved in file ftsct_ps_dnlink.bin\n");
			fclose(fptr_write);
		}


		gui_savecontext_ptr = malloc(ft_sts->context_info.context_info_size);
		if(gui_savecontext_ptr != NULL)
		{
			savecontext_size = ft_sts->context_info.context_info_size;
			printf("2. context data size: %d\n",savecontext_size);
			printf("3. context data : ");
			for (u16cnt = 0; u16cnt < savecontext_size; u16cnt++)
			{
				gui_savecontext_ptr[u16cnt] = ft_sts->context_info.context_info_buf_ptr[u16cnt];
				//printf("%x ",gui_savecontext_ptr[u16cnt]);
			}
			/* send ack */

			display_context_info();

			node_act_type = ft_get_master_slave_status();
			if(node_act_type == sus_res_slave)
			{
				if(nack_test != 0)
				{
					ft_transfer_request(Suspend_Savecontext_ack_rqst,0);
					init_start = 0;
					//file_tx_running = 0;
				}
				else
				{
					ft_transfer_request(Suspend_Savecontext_nack_rqst,0);
					nack_test = 1;
				}
			}
			free(gui_savecontext_ptr);
		}

	}
	else if(ft_sts->status == transfer_resumed)
	{
		printf("1. downloading resumed by sender\n");
	}
	else if(ft_sts->status == transfer_resume_accepted)
	{
		printf("1. downloading resumed back by sender\n");
	}
	else if(ft_sts->status == tx_terminated_suspend_timeout_expired)
	{
		printf("1. download Terminated due to suspend timeout expired\n");
		init_start = 0;
		//file_tx_running = 0;

	}
	else if(ft_sts->status == transfer_suspend_accepted)
	{
		printf("1. download Suspend - Timeout mode Accepted by Sender\n");
	//	display_ft_sts();

	}
	else if(ft_sts->status == transfer_suspend_savecontext_accepeted)
	{
		printf("1. Download Suspend - SaveContext mode Accepted by Sender\n");
		printf("1. malloc req: %d \n",ft_sts->context_info.context_info_size);	
		gui_savecontext_ptr = malloc(ft_sts->context_info.context_info_size);
		if(gui_savecontext_ptr != NULL)
		{
			savecontext_size = ft_sts->context_info.context_info_size;
			printf("2. context data size: %d\n",savecontext_size);
			printf("3. context data : ");
			for (u16cnt = 0; u16cnt < savecontext_size; u16cnt++)
			{
				gui_savecontext_ptr[u16cnt] = ft_sts->context_info.context_info_buf_ptr[u16cnt];
				//printf("%x ",gui_savecontext_ptr[u16cnt]);
			}
			/* send ack */

			display_context_info();

			node_act_type = ft_get_master_slave_status();
			if(node_act_type == sus_res_slave)
			{
				if(nack_test != 0)
				{
					ft_transfer_request(Suspend_Savecontext_ack_rqst,0);
				}
				else
				{
					/* send NACK to check suspend context is aborted */
					ft_transfer_request(Suspend_Savecontext_nack_rqst,0);
					nack_test = 1;
				}
			}
			else
			{
				/* go back to input mode to intaite another FT */
				init_start = 0;
				//file_tx_running = 0;

				display_ft_sts();
			}

		}

	}
	else if(ft_sts->status == transfer_resumed_restorecontext)
	{
		printf("1. Download Resume Savecontext mode Requested by Sender\n");


		printf("\r\nResume-SaveContext mode [Bulkdata] selected \r\n");

		FILE *fptr_read;
		if ((fptr_read = fopen("ftsct_ps_dnlink.bin","rb")) == NULL)
		{
			printf("Error! file ftsct_ps_dnlink.bin not create fail\n");
		}
		else
		{
			printf("SCT info read from file ftsct_ps_dnlink.bin\n");
			/* read data size */
			fread(&savecontext_size_file, sizeof(uint16_t), 1, fptr_read);
			printf("Data size to read from file %d\n",savecontext_size_file);

			/* read data */
			for(u16cnt = 0; u16cnt < savecontext_size_file; u16cnt++)
			{
				fread(&gui_savecontext_filebuf[u16cnt], sizeof(unsigned char), 1, fptr_read);
				//printf("G:%d-F:%d\n",gui_savecontext_filebuf[u16cnt],gui_savecontext_ptr[u16cnt]);
			}
			fclose(fptr_read);

			gui_savecontext_ptr = gui_savecontext_filebuf;
			savecontext_size = savecontext_size_file;
		}


		ft_contextsave_info *c_inf = (ft_contextsave_info*)gui_savecontext_ptr;

		if(c_inf->tx_mode == 1)
		{
			printf("Mem address passing 0x%lux of size %d \n",c_inf->bulkdata_mem_addr,c_inf->bulkdata_len);
			ft_get_receiver_node_storage_address(c_inf->bulkdata_mem_addr);
		}



		ret_sts = ft_resume_context(gui_savecontext_ptr,savecontext_size);
		if(ret_sts == 0)
		{
			init_start = 1;
		}
		else
		{
			printf("Resume-SaveContext Error %d\n",ret_sts);
		}
	}
	else if(ft_sts->status == transfer_download_ready)
	{
		printf("1. Download request received\n");
		if(ft_sts->dwld_info.tx_mode == 1)
		{
			printf("2. Transfer mode : DATA\n");
		}
		else
		{
			printf("2. Transfer mode : FILE\n");
			printf("3. File size: %d\n",ft_sts->dwld_info.size_file_or_data);
			
#ifdef FT_OBC
			mem_address_alloc = obc_file_memory_alloc(ft_sts->dwld_info.size_file_or_data);
			printf("[OBC] Allocated memory for binary file, addr:0x%lux\n",mem_address_alloc);
			ft_get_receiver_node_storage_address(mem_address_alloc);
#else
			ft_get_receiver_node_storage_address(0x12345678);
#endif
		}
	}
	else if(ft_sts->status == transfer_resume_savecontext_accepeted)
	{
		printf("1. download Resume - Savecontext mode Accepted by Sender\n");
		init_start = 1;
	}
	else if(ft_sts->status == transmission_terminated_by_rx_node)
	{
		printf("1. download Terminated by Receiver node\n");
		init_start = 0;
	}
	else if(ft_sts->status == transfer_otsu)
	{

	}
	else if(ft_sts->status == transfer_suspend_tout_not_accepted)
	{
		printf("1. suspend timeout request not completed\n");
	}
	else if(ft_sts->status == transfer_suspend_savecontext_failed)
	{
		printf("1. suspend savecontxt request not completed\n");
	}
	else if(ft_sts->status == transfer_rseume_tout_not_accepted)
	{
		printf("1. resume timeout request not completed\n");
	}
	else if(ft_sts->status == transfer_resume_restorecontext_failed)
	{
		printf("1. resume savecontxt request not completed\n");
	}
	else if(ft_sts->status == transfer_suspended_savecontext_etended_sts)
	{
		printf("1. Suspend savecontxt request 100%% completed\n");
	}
	else
	{
		printf("Invalid Notification not processed\n");
	}

	printf("\n-------------/End/---------------\n\n");


}

/*
 *
 *  Application API which will be invoked during file transmission by FT framework
 *
 */
void iqs_comms_notificataion_api_dwld(ft_notification_info *ft_sts)
{
	uint16_t u16cnt;
	e_avtive_type node_act_type;
	uint8_t ret_sts;

#ifdef FT_OBC
	uint64_t mem_address_alloc;
#endif

	static uint8_t nack_test = 1;

	printf("IQS-COMMS App notification API invoked !!!!\n");

	if(ft_sts->status == transfer_download_success)
	{
		printf("1. download success\n");
                if(ft_sts->dwld_info.rx_file_id == 1)
                {
                    printf("2. IQS Firware file One download successful\n");
                }
                else if(ft_sts->dwld_info.rx_file_id == 2)
                {
                    printf("2. IQS Firware file Two download successful\n");
                }
                else if(ft_sts->dwld_info.rx_file_id == 3)
                {
                    printf("2. IQS Firware file Three download successful\n");
                }
		if(ft_sts->dwld_info.tx_mode == 1)
		{
			printf("3. Transfer mode : DATA\n");
			printf("4. Bulkdata received :");

			for (u16cnt = 0; u16cnt < ft_sts->dwld_info.size_file_or_data; u16cnt++)
			{
				printf("%d,",ft_sts->dwld_info.bulkdata_ptr[u16cnt]);
			}
			printf("\n");
		}
		else
		{
			printf("3. Transfer mode : FILE\n");
			printf("4. File Stored path : ");
			for (u16cnt = 0; u16cnt < ft_sts->dwld_info.path_filename_buf_length; u16cnt++)
			{
				printf("%c",ft_sts->dwld_info.storage_path_and_File_name[u16cnt]);
			}
			printf("\n5. File size : %u",ft_sts->dwld_info.size_file_or_data);
			
#if 0
			printf("\n5. Bin data: \n");
			for (u16cnt = 0; u16cnt < ft_sts->dwld_info.size_file_or_data; u16cnt++)
			{
				printf("%c",ft_sts->dwld_info.bulkdata_ptr[u16cnt]);
			}
			printf("\n");
#endif
		}
		init_start = 0;
	//	file_tx_running = 0;


	}
	else if(ft_sts->status == crc_error)
	{
		printf("1. download failed/ CRC error\n");
		if(ft_sts->dwld_info.tx_mode == 1)
		{
			printf("2. Transfer mode : DATA\n");
		}
		init_start = 0;
	//	file_tx_running = 0;

	}
	else if(ft_sts->status == transfer_suspended)
	{
		printf("1. download suspended by sender [Timeout mode]\n");
	//	display_ft_sts();

	}
	else if(ft_sts->status == transfer_suspended_savecontext)
	{
		printf("1. download suspended by sender [Save Context Mode]\n");
		printf("1. malloc req: %d \n",ft_sts->context_info.context_info_size);

		FILE *fptr_write;
		if ((fptr_write = fopen("ftsct_iqs_comms.bin","wb")) == NULL)
		{
			printf("Error! file ftsct_iqs_comms.bin not create fail\n");
		}
		else
		{
			/* write data size */
			fwrite(&ft_sts->context_info.context_info_size, sizeof(uint16_t), 1, fptr_write);
			/* write data */
			for(u16cnt = 0; u16cnt < ft_sts->context_info.context_info_size; u16cnt++)
			{
				fwrite(&ft_sts->context_info.context_info_buf_ptr[u16cnt], sizeof(unsigned char), 1, fptr_write);
			}
			printf("SCT info saved in file ftsct_iqs_comms.bin\n");
			fclose(fptr_write);
		}


		gui_savecontext_ptr = malloc(ft_sts->context_info.context_info_size);
		if(gui_savecontext_ptr != NULL)
		{
			savecontext_size = ft_sts->context_info.context_info_size;
			printf("2. context data size: %d\n",savecontext_size);
			printf("3. context data : ");
			for (u16cnt = 0; u16cnt < savecontext_size; u16cnt++)
			{
				gui_savecontext_ptr[u16cnt] = ft_sts->context_info.context_info_buf_ptr[u16cnt];
				//printf("%x ",gui_savecontext_ptr[u16cnt]);
			}
			/* send ack */

			display_context_info();

			node_act_type = ft_get_master_slave_status();
			if(node_act_type == sus_res_slave)
			{
				if(nack_test != 0)
				{
					ft_transfer_request(Suspend_Savecontext_ack_rqst,0);
					init_start = 0;
					//file_tx_running = 0;
				}
				else
				{
					ft_transfer_request(Suspend_Savecontext_nack_rqst,0);
					nack_test = 1;
				}
			}
			free(gui_savecontext_ptr);
		}

	}
	else if(ft_sts->status == transfer_resumed)
	{
		printf("1. downloading resumed by sender\n");
	}
	else if(ft_sts->status == transfer_resume_accepted)
	{
		printf("1. downloading resumed back by sender\n");
	}
	else if(ft_sts->status == tx_terminated_suspend_timeout_expired)
	{
		printf("1. download Terminated due to suspend timeout expired\n");
		init_start = 0;
		//file_tx_running = 0;

	}
	else if(ft_sts->status == transfer_suspend_accepted)
	{
		printf("1. download Suspend - Timeout mode Accepted by Sender\n");
	//	display_ft_sts();

	}
	else if(ft_sts->status == transfer_suspend_savecontext_accepeted)
	{
		printf("1. Download Suspend - SaveContext mode Accepted by Sender\n");
		printf("1. malloc req: %d \n",ft_sts->context_info.context_info_size);

		gui_savecontext_ptr = malloc(ft_sts->context_info.context_info_size);
		if(gui_savecontext_ptr != NULL)
		{
			savecontext_size = ft_sts->context_info.context_info_size;
			printf("2. context data size: %d\n",savecontext_size);
			printf("3. context data : ");
			for (u16cnt = 0; u16cnt < savecontext_size; u16cnt++)
			{
				gui_savecontext_ptr[u16cnt] = ft_sts->context_info.context_info_buf_ptr[u16cnt];
				//printf("%x ",gui_savecontext_ptr[u16cnt]);
			}
			/* send ack */

			display_context_info();

			node_act_type = ft_get_master_slave_status();
			if(node_act_type == sus_res_slave)
			{
				if(nack_test != 0)
				{
					ft_transfer_request(Suspend_Savecontext_ack_rqst,0);
				}
				else
				{
					/* send NACK to check suspend context is aborted */
					ft_transfer_request(Suspend_Savecontext_nack_rqst,0);
					nack_test = 1;
				}
			}
			else
			{
				/* go back to input mode to intaite another FT */
				init_start = 0;
				//file_tx_running = 0;

				display_ft_sts();
			}

		}

	}
	else if(ft_sts->status == transfer_resumed_restorecontext)
	{
		printf("1. Download Resume Savecontext mode Requested by Sender\n");


		printf("\r\nResume-SaveContext mode [Bulkdata] selected \r\n");

		FILE *fptr_read;
                if ((fptr_read = fopen("ftsct_iqs_comms.bin","rb")) == NULL)
                {
                        printf("Error! file ftsct_iqs_comms.bin not create fail\n");
                }
                else
                {
                        printf("SCT info read from file ftsct_iqs_comms.bin\n");
                        /* read data size */
                        fread(&savecontext_size_file, sizeof(uint16_t), 1, fptr_read);
                        printf("Data size to read from file %d\n",savecontext_size_file);

                        /* read data */
                        for(u16cnt = 0; u16cnt < savecontext_size_file; u16cnt++)
                        {
                                fread(&gui_savecontext_filebuf[u16cnt], sizeof(unsigned char), 1, fptr_read);
                                //printf("G:%d-F:%d\n",gui_savecontext_filebuf[u16cnt],gui_savecontext_ptr[u16cnt]);
                        }
                        fclose(fptr_read);

                        gui_savecontext_ptr = gui_savecontext_filebuf;
                        savecontext_size = savecontext_size_file;
                }

		ft_contextsave_info *c_inf = (ft_contextsave_info*)gui_savecontext_ptr;

		if(c_inf->tx_mode == 1)
		{
			printf("Mem address passing 0x%lux of size %d \n",c_inf->bulkdata_mem_addr,c_inf->bulkdata_len);
			ft_get_receiver_node_storage_address(c_inf->bulkdata_mem_addr);
		}



		ret_sts = ft_resume_context(gui_savecontext_ptr,savecontext_size);
		if(ret_sts == 0)
		{
			init_start = 1;
		}
		else
		{
			printf("Resume-SaveContext Error %d\n",ret_sts);
		}
	}
	else if(ft_sts->status == transfer_download_ready)
	{
		printf("1. Download request received\n");
		if(ft_sts->dwld_info.tx_mode == 1)
		{
			printf("2. Transfer mode : DATA\n");
		}
		else
		{
			printf("2. Transfer mode : FILE\n");
			printf("3. File size: %d\n",ft_sts->dwld_info.size_file_or_data);
			
#ifdef FT_OBC
			mem_address_alloc = obc_file_memory_alloc(ft_sts->dwld_info.size_file_or_data);
			printf("[OBC] Allocated memory for binary file, addr:0x%lux\n",mem_address_alloc);
			ft_get_receiver_node_storage_address(mem_address_alloc);
#else
			ft_get_receiver_node_storage_address(0x12345678);
#endif
		}
	}
	else if(ft_sts->status == transfer_resume_savecontext_accepeted)
	{
		printf("1. download Resume - Savecontext mode Accepted by Sender\n");
		init_start = 1;
	}
	else if(ft_sts->status == transmission_terminated_by_rx_node)
	{
		printf("1. download Terminated by Receiver node\n");
		init_start = 0;
	}
	else if(ft_sts->status == transfer_otsu)
	{

	}
	else if(ft_sts->status == transfer_suspend_tout_not_accepted)
	{
		printf("1. suspend timeout request not completed\n");
	}
	else if(ft_sts->status == transfer_suspend_savecontext_failed)
	{
		printf("1. suspend savecontxt request not completed\n");
	}
	else if(ft_sts->status == transfer_rseume_tout_not_accepted)
	{
		printf("1. resume timeout request not completed\n");
	}
	else if(ft_sts->status == transfer_resume_restorecontext_failed)
	{
		printf("1. resume savecontxt request not completed\n");
	}
	else if(ft_sts->status == transfer_suspended_savecontext_etended_sts)
	{
		printf("1. Suspend savecontxt request 100%% completed\n");
	}
	else
	{
		printf("Invalid Notification not processed\n");
	}

	printf("\n-------------/End/---------------\n\n");


}

void sample_app_regisration_dwld(void)
{
	uint8_t ret;

	ret = ft_register_receiver_app(TC_DST_PS, app1234_notificataion_api_dwld);
    ret = ft_register_receiver_app(TC_DST_FTM_PS_COMMS, iqs_comms_notificataion_api_dwld);
	if(ret != 0)
	{
		printf("Receiver app registered\n");
	}
	else
	{
		printf("Receiver app registration failed\n");
	}

}






