/**
 * @file segmentation.h
 *
 * @brief This file contains function prototypes and data definitions that
 * helps to process file data into segments and  frame FTDS 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.
 *
 */

#ifndef SEGMENTATION_H_
#define SEGMENTATION_H_

#include "data_type.h"
#include "ftci.h"
#include "message_frame_def.h"
#include "tc_tm_sample.h"



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

/**
 * @brief Sender side transmission handling info
 */
typedef struct segment_info
{
	uint32_t current_seg;				///< Current sequence to send
	uint32_t next_seg;					///< Next sequence to send
	uint32_t resend_pckt_list[100];		///< Sequence ID for re transmission
	uint32_t total_resend_seq_ID;		///< Total sequence count for re transmission
	uint8_t * ftds_buf_ptr;				///< FTDS data buffer pointer
	uint16_t packet_buf_length;			///< FTDS length
	uint8_t resend_rqst;				///< Resend request flag
	uint8_t rx_ping_count;				///< Receiver side ping request counter
	uint16_t ping_fail_cnt;				///< Count failure ping request
}

s_segment_info;


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

/**
 * @brief This function initialize segmentation data variables
 *
 *
 * @param[in]  none
 *
 * @return none
 * @retval void
 */
void init_seg(void);

/**
 * @brief This function manipulates the parameters required to start transmission
 * It will find the total number of sequence to be sent and FTDS frame length
 *
 *
 * @param[in]  none
 *
 * @return none
 * @retval void
 */
void segmentation(void);

/**
 * @brief This function used to encode FTDS frame.
 * It will read file based on sequence number and data length then fill the FTDS data buffer
 * with file content data
 *
 *
 * @param[in]  none
 *
 * @return status of FTDS frame encoding
 * @retval 1 indicates success, 0 is error
 */
uint16_t seg_preapre_frame_ftds(void);

/**
 * @brief This function used to update the sequence number
 *
 *
 * @param[in]  set : sequence to set
 *
 * @return none
 * @retval void : none
 */
void seg_sequence_num_set(uint32_t set);

/**
 * @brief This function used to re opening the file on sender side
 *
 *
 * @param[in]  void : none
 *
 * @return none
 * @retval void : none
 */
uint8_t ft_file_reopen_upload(void);

/**
 * @brief This function used to re opening the file on receiver side to download
 *
 *
 * @param[in]  void : none
 *
 * @return none
 * @retval void : none
 */
uint8_t ft_file_reopen_download(void);

#ifndef FT_OBC
/**
 * @brief This function used to close a file
 *
 *
 * @param[in]  void : none
 *
 * @return none
 * @retval void : none
 */
void ft_file_close(FILE * fptr, uint8_t *file_open_sts, uint8_t tx_mode);
#endif

extern s_segment_info seg_info;

#endif /*SEGMENTATION_H_ */
