/******************************************************************************/
/**
 * @file ftfci.c
 *
 * @brief This file contains functions that provides demonstration of
 *        usage of FTFCI frame encoding
 *
 * The functions provided in the file provides demonstration on
 * usage of frame encoding for FTFCT frame
 *
 * @copyright Copyright 2023 Antaris, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *        usage of TC TM Library APIs
 */
/******************************************************************************/

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


/******************************************************************************/
/*                       Definition of local variables                        */
/******************************************************************************/

static s_string_info ftfci_tctm_data;

/******************************************************************************/
/*                      Definition of exported functions                      */
/******************************************************************************/


/**
 * @brief This function used to encode response frame FTFCI
 * It will form FTFCI frame with response code
 *
 */
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 = os_malloc_eram(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_send_tm_to_obc(FT_TC_FTFCI,ftfci_tctm_data.str_ptr,ftfci_tctm_data.size);
		#else
			ft_send_tm_to_obc(FT_TM_FTFCI,ftfci_tctm_data.str_ptr,ftfci_tctm_data.size);
		#endif
	  	}
		os_free(ftfci_tctm_data.str_ptr);
	}
	else
	{
		DEBUG_CPRINT(("FTM: malloc error\n"));
	}
}
