/**
 * @file ft_debug.h
 *
 * @brief This file contains function prototypes and data definitions that
 * helps to encode debug telemetry message
 *
 * @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 _INC_FT_DEBUG_H_
#define _INC_FT_DEBUG_H_

#include "stdint.h"


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


/**
 * @brief Type of debug info request
 */
typedef enum ft_debug_sel_def
{
	e_ft_none          		    =0,
	e_ft_debug_gen_status  	    =1,
	e_ft_debug_sct_status 	    =2,
	e_ft_debug_terminate        =3,
	e_ft_get_version            =4,
	e_ft_reset 				    =5,
	e_ft_debug_integ_test 	    =6,
	e_ft_debug_max

}ft_debug_sel;



/**
 * Debug information to encode on debug message
 */
/*
 *
 *  Get FTM status  >> e_ft_debug_status
1	FT process = upload / download   = get_file_transfer_state(); 2 bit
2	FT fsm    = ft_fsm_read_state()             2 bit
3	Node type = master/ receiver
4	Sus / Resume status    = ft_get_suspend_resume_sts();   2 bit
5	Sequence loss status  = ft_get_seq_loss_status();    2 bit
6   Head position =  ft_get_receiver_head_seq_id();     32 bit
 *
 *
 */
typedef struct ft_debug_sts_def
{
	uint32_t head_pos;
	uint8_t fsm_st;
	uint8_t sus_res_st;
	uint8_t ft_proc_st:   2;
	uint8_t seq_loss_st:  2;
	uint8_t service_run_sts:      4;
	uint8_t reserv2;
	uint16_t prev_tctm_id;
	uint16_t prev_tctm_response;
}ft_debug_gen_sts;


/**
 * Structure for testing purpose
 */
typedef struct ftm_debug_params_def
{
	uint8_t ignore_sus_request:1;
	uint8_t dont_send_ack_for_sus_rqst:1;
	uint8_t ignore_res_request:1;
	uint8_t dont_send_ack_for_res_rqst:1;
	uint8_t skip_all_sus_ack_:1;
	uint8_t skip_all_res_ack_:1;
	uint8_t skip_all_sus_req_:1;
	uint8_t skip_all_res_req_:1;
}ftm_db_params;



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

/**
 * @brief This function decode the debug request type and prepare response
 *
 * @param[in] ftdb_data : pointer to buffer contains debug request type
 * @param[in] ftdb_data_length : length of frame
 *
 * @return none
 */
void ft_decode_debug_request_frame(uint8_t *ftdb_data, uint16_t ftdb_data_length);


/**
 * @brief This function prepares response frame for debug request
 *
 * @param[in] void : none
 *
 * @return none
 */
void ft_debug_handle(void);


/**
 * @brief This function decode the debug response frame
 *
 * @param[in] ftdr_data : pointer to buffer contains debug response data
 * @param[in] ftdr_data_length : length of frame
 *
 * @return none
 */
void ft_decode_debug_response_frame(uint8_t *ftdr_data, uint16_t ftdr_data_length);

/*
 * This function is used to save the previous frame information
 */
void ft_debug_save_prev_frame_info(uint16_t tctm_id , uint16_t response);

/*
 * This function is used to get the previous frame information
 */
void ft_get_debug_last_tctm_and_response(uint16_t* tctm_id , uint16_t* response);


#endif /* _INC_FT_DEBUG_H_ */
