/**
 * @file download_def.h
 *
 * @brief This file contains data definitions for file receive information
 *
 * @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 DOWNLOAD_DEF_H_
#define DOWNLOAD_DEF_H_

#include "data_type.h"
#include "stdio.h"

/******************************************************************************/
/*                Definition of exported macros                 			  */
/******************************************************************************/

#define MAX_PCKT_LOSS_DETECTION_CNTR 8


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


/**
 * @brief Sequence Loss Information
 */
typedef struct lost_seg_info
{
	uint32_t lost_packet_list[MAX_PCKT_LOSS_DETECTION_CNTR]; ///< Buffer to hold sequnce loss ID
    uint32_t resend_rqst_flag;
	uint16_t total_lost_segment_count;   ///< total lost ID saved
	uint8_t head_change_request;   		///< Head change request is enabled
	uint8_t ftsr_frame_full;
	uint8_t re_request_initiate_timer;
}s_lost_seg_info;


/**
 * @brief Sender Side file upload handling info
 */
typedef struct receive_info
{
#ifndef FT_OBC
	FILE * fptr;
#endif
	uint8_t *mptr; 								///< memory pointer for download if DATA mode is chosen
	uint32_t size;      						///< file or memory size
	uint32_t pckt_seq_num; 						///< last sequence number received
	uint32_t checksum; 							///< calculated checksum
	uint32_t mem_address; 						///< memory address in hex to transfer if DATA mode is chosen
	uint32_t pckt_seq_head;  					///< last sequence number received
	uint16_t packet_data_size; 					///< Received Sequence data buffer length
	uint16_t mtu_size;  						///< MTU size
	uint8_t tx_mode; 							///< Transmission mode; 1-> data mode , 0 -> file mode
	uint8_t file_format; 						///< Format of input file
	uint8_t *file_name;							///< File name
	uint16_t file_name_buf_length; 				///< FIle name string length
	uint8_t *ftds_payload_ptr;					///< Pointer to FTDS payload
	s_lost_seg_info data_loss;					///< Info of sequence loss
	uint8_t receive_busy;						///< Status of current session
	uint8_t download_pending_by_loss;			///< Status after last packet received, if any packet still not received
	uint16_t seq_payload_len;					///< Length of payload
	uint8_t file_opened; 						///< Status of file open / close
	uint64_t obc_mem_addr;						///< OBC sdram address
	uint8_t dwnld_cmp_sts;						///< Status of completion
	uint8_t seq_loss_detect_enable; 			///< Sequence loss enable flag
    uint8_t session_id;
    uint8_t file_id;                            ///< file id to differentiate multiple files send to same app
    uint16_t rx_node_conn_fail_timeout;
}s_treceive_info;


#endif /* DOWNLOAD_DEF_H_ */
