/*
 * ftfci.c
 *
 *  Created on: 05-Oct-2022
 *      Author: Invcuser52
 */

#include "ftfci.h"
#include "file_transfer.h"
#include "ft_sender.h"

s_string_info ftfci_tctm_data;



void send_ftfci(e_ftfci_response_code set, uint16_t waiting_time)
{
	s_file_tx_framework_ctrl_info fw_sts;
	fw_sts.ctrl.bit.file_tx_session_id = ft_tx_session_id_read();
	fw_sts.ctrl.bit.response_code = set;
	fw_sts.suspend_wait_timeout = waiting_time;

	ftfci_tctm_data.str_ptr = malloc(sizeof(s_file_tx_framework_ctrl_info));
	if(ftfci_tctm_data.str_ptr != NULL)
	{
		memcpy(ftfci_tctm_data.str_ptr, &fw_sts, sizeof(s_file_tx_framework_ctrl_info));
		ftfci_tctm_data.size = sizeof(s_file_tx_framework_ctrl_info);

	  	if(tx_info.seq_loss_detect_enable != SEQ_LOSS_DETECTION_OFF)
	  	{
		#ifndef FT_SAT
			ft_save_tc_request(FT_TC_FTFCI);
			ft_send_tctm(FT_TC_FTFCI,ftfci_tctm_data.str_ptr,ftfci_tctm_data.size);
		#else
			ft_save_tm_request(FT_TM_FTFCI);
			ft_send_tctm(FT_TM_FTFCI,ftfci_tctm_data.str_ptr,ftfci_tctm_data.size);
		#endif
	  	}
		free(ftfci_tctm_data.str_ptr);
	}
	else
	{
		printf("FTM: malloc error\n");
	}
}
