/**
 * @file ft_config.h
 *
 * @brief This file contains function prototypes and data definitions that
 * helps to collect input required for file transfer and initiate file transfer by invoking FTCI frame prepare
 *
 * @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.
*/

#ifndef FT_CONFIG_H_
#define FT_CONFIG_H_


#include "string.h"
#include "data_type.h"
#include "tc_tm_sample.h"
#include "exo_types.h"

/******************************************************************************/
/*         Definition of exported types (typedef, enum, struct, union)        */
/******************************************************************************/

/* enumeration for transfer control request */
typedef enum ft_request
{
	Start_Transmission_rqst, 		///< a.	Start File transfer process
	Suspend_Timeout_Mode_rqst, 		///< b.	Suspend ongoing transfer process with timeout value
	Resume_Timeout_Mode_rqst, 		///< c.	Resume ongoing transfer process
	Terminate_Transmission_rqst, 	///< d.	Terminate ongoing transfer process
	Suspend_Savecontext_Mode_rqst, 	///< e.	Suspend & Save context of ongoing transfer process
	Suspend_Savecontext_ack_rqst, 	///< f.	Suspend & Save context acknowledged
	Suspend_Savecontext_nack_rqst, 	///< g.	Suspend & Save context not acknowledged
	Resume_Savecontext_nack_rqst, 	///< h.	Resume & Save context not acknowledged
	T_SuspendTimeout, 				///< i.	Not applicable for App usage
	T_Txnode, 						///< j.	Not applicable for App usage
	T_Rxnode, 						///< k.	Not applicable for App usage
	Suspend_Savecontext_Auto_rqst   ///< l.   Suspend & Save context mode enabled by FTM during SBAND failure

}ft_request;

/******************************************************************************/
/*                    Declaration of exported variables                       */
/******************************************************************************/

extern char* input_file_name;



/******************************************************************************/
/*               Declaration of exported function prototypes                  */
/******************************************************************************/

/*!
 * @brief This API configure the mode of FT operation
 * options: file mode or Bulk data mode
 *
 * @param[in] mode Mode of opearation such as file or data mode
 *
 * @return status of configuration
 * @retval 1 -> configuration success | 0 -> configuration rejected
 */
uint8_t ft_mode_select(uint8_t mode);



/*!
 * @brief This API configure input file name to be transfered
 *
 *
 * @param[in] name_and_path : pointer to input file name and path
 *
 * @return status of configuration
 * @retval 1 -> configuration success | 0 -> configuration rejected
 */
uint8_t ft_config_sender_file_name_path(char name_and_path[]);

/*!
 * @brief This API configure input bulk data buffer with length
 *
 * @param[in] buffer : pointer to input bulk data to transfered
 * @param[in] buf_length : length of bilk data
 *
 * @return status of configuration
 * @retval 1 -> configuration success | 0 -> configuration rejected
 */
uint8_t ft_config_bulk_data_input_buffer(uint8_t *buffer, uint32_t buf_length);



/*!
 * @brief This API configure receiver side folder path and file name
 *
 * @param[in] name_and_path : pointer to receiver side file name and path
 *
 * @return status of configuration
 * @retval 1 -> configuration success | 0 -> configuration rejected
 */
uint8_t ft_config_receiver_file_name_path(char name_and_path[]);



/*!
 * @brief This API configure receiver side storage address if bulk data transfer mode was chosen
 *
 * @param[in] mem_address : receiver side storage memory start address
 *
 * @return status of configuration
 * @retval 1 -> configuration success | 0 -> configuration rejected
 */
uint8_t ft_config_receiver_node_storage_address(ptr_typ mem_address);



/*!
 * @brief This API configure MTU size, this is used for segmentation process to split data
 *
 * @param[in] size : MTU size in bytes,
 *
 * @return status of configuration
 * @retval 1 -> configuration success | 0 -> configuration rejected
 */
uint8_t ft_config_mtu_size(uint16_t size);



/*!
 * @brief This API control all FT operation
 * 1. Start transmission
 * 2. Terminate transmission
 * 3. Resume transmission
 * 4. Suspend transmission - timeout mode
 * 5. Suspend transmission - save context mode
 * 6. Store context ack 
 *
 * @param[in] request : type of request
 * @param[in] timeout : suspend timeout value, it is valid only for suspend request
 *
 *
 * @return status of configuration
 * @retval 1 -> configuration success | 0 -> configuration rejected
 */
uint8_t ft_transfer_request(ft_request request, uint16 timeout);



/*!
 * @brief This API configure APP id
 *
 * @param[in] app_id : Application ID
 *
 *
 * @return status of configuration
 * @retval 1 -> configuration success | 0 -> configuration rejected
 */
uint8_t ft_config_app_id(uint16 app_id);



/*!
 * @brief This API used to resume transmission by save context mode
 *
 * @param[in] save_info : context info data buffer
 * @param[in] size : context info data length
 *
 * @return status of configuration
 * @retval 1 -> configuration success | 0 -> configuration rejected
 */
uint8_t ft_resume_context(uint8_t *save_info, uint16_t size);


/*!
 * @brief This API used to read APP id
 *
 * @param[in] none
 *
 * @return ID of receiver app
 */
uint16_t ft_read_app_id_tx(void);

/*!
 * @brief This API used to configure enable/disable sequence loss detection
 *
 * @param[in] mode enable/disable sequnec loss detection
 *
 * @return status of configuration
 * @retval 1 -> configuration success | 0 -> configuration rejected
 *
 */
uint8_t ft_sequenceLoss_mode_select(uint8_t mode);




void ft_config_ftds_delay(uint16_t set);

void ft_config_file_id(uint8_t f_id);

/*
*   This API is used to configure timeout value for connection failure for receiver side.
*   Receiver node will terminate the transmission if communication with sender is not restored in timeout value
*   This timeout value should be greater than 44 seconds and multiples of 15 such as 45, 60, 75, 300 are some valid timeout value can be used.
*/
void ft_config_rx_node_conn_failure_time(uint16_t conn_fail_time);



/* internal FT functions */
//void debug_select_mode(void);
//void debug_inputHandler(void);

#endif /*GET_INPUT_H_ */
