/**
 * @file eps.h
 *
 * @brief This file contains function prototypes and data definitions that
 * helps to create and unpack a TC 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 DRIVERS_AHW_DRIVERS_EPS_INC_EPS_H_
#define DRIVERS_AHW_DRIVERS_EPS_INC_EPS_H_

#include "stdio.h"
#include <string.h>
#include "stdint.h"
#include "stdlib.h"
#include "eps_config.h"


#define I2C_TIMEOUT 100						 ///< I2C Timeout in ms

#define EPS_CONV_BRD_ADDR     (0x55 <<1) 	///< EPS Converter Board Address
#define EPS_OP_CH_BRD_ADDR    (0x56 <<1) 	///< EPS Operational Channel Board Address

#define GPS_EN_SLV_ADDR				0x4E	 ///< GPS Board Slave Address
#define GPS_BRD_EN_GPIO_PINS  		0x20	 ///< GPS Board GPIO Pin mask

#define PLD_SRVR_EN_SLV_ADDR  		0x42	 ///< Payload Server Board slave address
#define PLD_SRVR_EN_GPIO_PINS 		0xEC	 ///< Payload Server Board GPIO Pin mask

#define EPS_EN_SLV_ADDR            0x3C // 0x3A

#define EDGE_BRD_U14_EN_SLV_ADDR 	0x46	 ///< EDGE Board U14 slave address
#define EDGE_BRD_U16_EN_SLV_ADDR 	0x42	 ///< EDGE Board U16 slave address
#define EDGE_BRD_EN_GPIO_PIN0 		0x01	 ///< EDGE Board GPIO Pin 0 mask
#define EDGE_BRD_EN_GPIO_PIN1 		0x04	 ///< EDGE Board GPIO Pin 1 mask
#define EDGE_BRD_EN_GPIO_PIN3 		0x08	 ///< EDGE Board GPIO Pin 3 mask
#define EDGE_BRD_EN_GPIO_PINS	 	(EDGE_BRD_EN_GPIO_PIN0|EDGE_BRD_EN_GPIO_PIN1|EDGE_BRD_EN_GPIO_PIN3) ///< EDGE Board GPIO Pin mask
#if 0
#ifndef DRISHTI_EN

#define MAX_SLR_PNL_CNT                         4               ///< Number of solar panels
#define MAX_BTRY_CNT_PER_SET                    3               ///< Number of Battery Sets
#define MAX_VOLT_RAIL_CNT                       17              ///< Number of Channel Voltage Rails

#else

#define MAX_SLR_PNL_CNT                         5     			///< Number of solar panels
#define MAX_BTRY_CNT_PER_SET                    8				///< Number of Battery Sets
#define MAX_VOLT_RAIL_CNT                       19				///< Number of Channel Voltage Rails
#endif
#endif
#define MAX_MPPT_CONV_CNT                       4               ///< Number of MPPT Convertors
#define MAX_BTRY_TMP_SNSR_CNT           		8               ///< Number of Battery Temperature Sensors
#define EPS_MEM_ADDR_SIZE                       4               ///< EPS Address Size
#define EPS_DATA_SIZE                           8               ///< EPS Variable Data Size
#define RSVD_11                                 11

/*************************** Data structures *********************************/

/**
 * @brief Boards present in EPS module
 */
typedef enum
{
	conv_brd = 0,				/*!< convertor board			*/
	op_ch_brd					/*!< output channel board		*/
}eps_slv_type;

typedef enum
{
	EPS_CONV_BRD_EN = 0,				/*!< convertor board			*/
	EPS_OP_CHNL_EN,					/*!< output channel board		*/
	EPS_CONV_BRD_DIS,
	EPS_OP_CHNL_DIS,
	MAX_EPS_EN_DIS
}eps_slv_en_type;


/**
 * @brief EPS module parameter memory write type
 */
typedef enum
{
	TEMP_MEM=0,					/*!< Temperory memory			*/
	PERM_MEM=1,					/*!< permanent memory			*/
	DIS_MEM=2					/*!< Disable memory				*/
}eps_mem_wr_s;

/**
 * @brief EPS module output channel state
 */
typedef enum
{
	OFF=0,						///< Channel statie is OFF
	ON=1						///< Channel statie is ON
}ch_state;

/**
 * @brief EPS module success failure status
 */
typedef enum
{
	EPS_SUCCESS=0x00U,				///< EPS success
	EPS_CRC_FAIL=-1,				///< EPS CRC failure
	EPS_ERR=-2,						///< EPS error
	EPS_COM_FAIL=-3,				///< EPS communication failure
	EPS_INVLD_ARG=-4,				///< EPS invalid argument
	EPS_NULL_PTR_ERR=-5,			///< EPS NULL pointer error
	EPS_SET_PARAM_ERR=-6,			///< EPS set parameter error
	EPS_RESP_ERR = -7				///< EPS response error
}eps_err_sts_e;

typedef  eps_err_sts_e eps_err_sts;


/**
 * @brief EPS module group address id for reading individual set of parameters
 */
typedef enum
{
	EPS_RD_BUF  = 0,				///< EPS read buffer
	EPS_SET_CONV_BRD = 1,			///< EPS set convertor board
	EPS_GET_CONV_BRD_RD,			///< EPS get convertor board read
	EPS_GET_CONV_BRD_ST,			///< EPS get convertor board set
	EPS_SET_BTRY_BRD,				///< EPS set battery board
	EPS_GET_BTRY_BRD_RD,			///< EPS get battery board read
	EPS_GET_BTRY_BRD_ST,			///< EPS get battery board set
	EPS_SET_OP_CHNL_PARM,			///< EPS set output channel parameter
	EPS_SET_OP_CHNL_CUR,			///< EPS set output channel current limit parameter
    EPS_GET_OP_CHNL_CUR_RD,			///< EPS get output channel current read
	EPS_GET_OP_CHNL_PARM,			///< EPS get output channel parameter
    EPS_GET_OP_CHNL_CUR_LMT_SET,	///< EPS get output channel current limit set
    EPS_SET_MODE_PARM,				///< EPS set mode parameter
	EPS_GET_MODE_PARM,				///< EPS get mode parameter
	EPS_GET_ALRT_FLAG,				///< EPS get alert flag
	EPS_GET_ADDR_VAR_CONV_BRD,		///< EPS get variable address convertor board
	EPS_SET_RTC_DATA = 16,			///< EPS set RTC data
	EPS_GET_RTC_DATA,				///< EPS get RTC data
	EPS_GET_OP_CHNL_FW_VERS,						///< EPS get firmware
        EPS_SET_COM_TIMEOUT,
            EPS_GET_COM_TIMEOUT,
	EPS_GET_ADDR_VAR_OP_BRD,		///< EPS get variable address output board
	EPS_GET_CONV_BRD_FW_VERS,
}eps_cmd;

#define EPS_SIM_EXPOSURE_TYPE (EPS_SET_RTC_DATA +7)
#define EPS_SET_CH_CRNT_SIMU  (EPS_SET_RTC_DATA +8)
#define EPS_SET_BTRY_VOLT_SIMU (EPS_SET_RTC_DATA + 9)
#define EPS_SET_BTRY_TEMP_SIMU (EPS_SET_RTC_DATA + 10)

#if 0
/**
 * @brief EPS module battery mode based on current battery voltage
 *
 */
typedef enum _eps_mode
{
	//EPS_MODE_OFF = 0,				///< EPS off mode
	EPS_MODE_CRIT = 1,					///< EPS critical mode
	EPS_MODE_SAFE,					///< EPS safe mode
	EPS_MODE_NRML,					///< EPS normal mode
	//EPS_MODE_FULL,					///< EPS full mode
	//EPS_MODE_MAX
}eps_mode_e;
#endif
/**
 * @brief enumerated order of EPS output channel voltage
 */
typedef enum _crnt_set
{
	ch1_12v=0,					///< channel 1 12v
	ch2_12v,					///< channel 2 12v
	ch3_5v,						///< channel 3 5v
	ch4_5v,					///< channel 4 12v
	ch5_5v,						///< channel 5 5v
	ch5_3v,						///< channel 5 3v
	ch5_btry,					///< channel 5 battery
	ch6_12v,					///< channel 6 12v
	ch6_3v,						///< channel 6 3v
	ch7_5v,						///< channel 7 3v
	ch7_btry,						///< channel 8 5v
	ch8_12v,						///< channel 8 3v
	ch9_5v,						///< channel 9 5v
	ch10_btry,					///< channel 10 battery
	ch11_btry,					///< channel 11 battery
	ch12_btry,					///< channel 12 battery
}eps_crnt_chnl;
/**
 * @brief extracted data from eps_get_conv_brd_s added with latest system time when data received
 */
typedef struct _eps_get_conv_board_par_tmr
{
	uint8_t buff_cnt;
	uint8_t pv_volt_cnt;							/*!< This member specifies number of pv_volt 				    */
	uint8_t pv_cur_cnt;								/*!< This member specifies number of pv_cur						*/
	uint8_t op_conv_volt_cnt;						/*!< This member specifies number of op_conv_volt				*/
    uint64_t time;										/*!< Time								*/
    float      pv_volt[MAX_SLR_PNL_CNT];				/*!< pv volt							*/
    float      pv_cur[MAX_SLR_PNL_CNT];					/*!< pv current							*/
    float      op_volt_conv_read[MAX_MPPT_CONV_CNT];	/*!< output convertor voltage read		*/
}eps_get_conv_brd_tmr_s;


/**
 * @brief extracted data from eps_get_btry_brd_s added with latest system time when data received
 *
 */
typedef struct _eps_get_btry_board_par_tmr
{
	uint8_t buff_cnt;
	uint8_t btry_volt_cnt;							/*!< This member specifies number of btry_volt				*/
	uint8_t btry_temp_cnt;								/*!< This member specifies number of btry_temp		*/
    uint64_t  time;										/*!< time								*/
    float		totl_vol;								/*!< total voltage						*/
    float		vol_ch[MAX_BTRY_CNT_PER_SET];			/*!< voltage of individual channel		*/
    float 		totl_crnt;								/*!< total current						*/
    uint8_t 	tempr[MAX_BTRY_TMP_SNSR_CNT];			/*!< temperature						*/
    uint8_t 	btry_chrg_sts;							/*!< battery charge sts					*/
   // uint8_t rsvd[3];
}__attribute__((__packed__))eps_get_btry_brd_tmr_s;

/**
 * @brief extracted data from eps_get_chnl_par added with latest system time when data received
 *
 */
typedef struct _eps_get_chnl_par_tmr
{
	uint8_t buff_cnt;
	 uint8_t volt_rail_cnt;							/*!< This member specifies number of volt_rail			*/
    uint64_t  time;											/*!< time					*/
    float 		rd_crnt_val[MAX_VOLT_RAIL_CNT];				/*!< read current value		*/
}__attribute__((__packed__))eps_get_chnl_par_tmr_s;


/**
 * @brief extracted data from _eps_alert_flag_s added with latest system time when data received
 *
 */
typedef struct _eps_alert_flag_tmr
{
	uint8_t buff_cnt;
    uint64_t  time;									/*!< time			*/
    uint32_t    value;								/*!< value			*/
    uint8_t hour;
    uint8_t min;
    uint8_t sec;
}__attribute__((__packed__))eps_alert_flag_tmr_s;

#if 0
/**
 * @brief Individual parameters present in send frame of group EPS_SET_ADDR_VAR_OP_BRD
 *
 */
typedef struct
{
    uint8_t addr[EPS_MEM_ADDR_SIZE];				/*!< address			*/
    uint8_t reserved[RSVD_5];						/*!< reserved			*/
}__attribute__((__packed__))eps_set_var_addr_s;

/**
 * @brief Individual parameters present in recieve frame of group EPS_GET_ADDR_VAR_OP_BRD
 */
typedef struct
{
    uint8_t data[EPS_DATA_SIZE];			   	/*!< Data			*/
    uint8_t reserved[RSVD_11];					/*!< reserved		*/
}__attribute__((__packed__))eps_get_var_data_s;
#endif

#ifdef EPS_SIMU_ENABLE
#define EXPOSURE_LUT_SIZE 10
/**
 * @brief Individual parameters present in send frame of EPS_SIM_EXPO
 */
typedef struct
{
	uint8_t expo_data_cnt;
    uint8_t mem_set;							/*!< mem set			*/
    uint8_t solar_mode;							/*!< solar mode			*/
    uint8_t expo_data[EXPOSURE_LUT_SIZE];		/*!< exposure data		*/

}__attribute__((__packed__))eps_sim_expo_s;

/**
 * @brief Individual parameters present in send frame of EPS_SIM_CHNL_CRNT
 */
typedef struct
{
	uint8_t chnl_pwr_con_cnt;
    uint8_t mem_set;							/*!< mem set					*/
    uint8_t ch_crnt_mode;						/*!< channel current mode		*/
    float ch_power_con[MAX_VOLT_RAIL_CNT];		/*!< channel power 				*/
}eps_sim_ch_crnt_s;

/**
 * @brief Individual parameters present in send frame of EPS_SIM_BTRY_VOLT
 */
typedef struct
{
    uint8_t mem_set;							/*!< mem set					*/
    uint8_t btry_mode;							/*!< battery mode				*/
    float btry_volt;							/*!< battery voltage			*/
}eps_sim_btry_volt_s;

/**
 * @brief Individual parameters present in send frame of EPS_SIM_BTRY_TEMP
 */
typedef struct
{
    uint8_t mem_set;							/*!< mem set					*/
    uint8_t temp_mode;							/*!< temperature mode			*/
    uint8_t cell_num;							/*!< cell number				*/
    uint8_t tempr;								/*!< temperature				*/
    uint8_t btry_temp_mode;						/*!< battery temperature mode 	*/
    uint8_t temp_lmt_lwr;						/*!< temperature lower limit 	*/
    uint8_t temp_lmt_up;					    /*!< temperature upper limit 	*/
}eps_sim_btry_temp_s;

#endif


/**
 * @brief structure that holds address of transmit and receive frame that passes from wrapper to eps send function
 *
 */
typedef struct
{
    uint8_t *tx_buf_ptr;				/*!< Transmit buffer pointer			*/
    uint8_t *rx_buf_ptr;				/*!< Recieve buffer pointer				*/
    uint8_t len_t;						/*!< length of transmission data		*/
    uint8_t len_r;						/*!< length of recieve data				*/
    eps_cmd command;					/*!< EPS command						*/
}eps_send_s;


/**
 * @brief extracted data from eps_get_chnl_par_s added with latest system time when data received
 *
 */
typedef struct _eps_out_chnl_par
{
    uint8_t chnl_en_sts_cnt;					/*!< This member specifies number of ch_en_sts				*/
    uint8_t cur_val_cnt;						/*!< This member specifies number of set_crnt_val			*/
    uint8_t rd_cur_val_cnt;						/*!< This member specifies number of rd_crnt_val			*/
    uint8_t hrm_rls_sts_cnt;					/*!< This member specifies number of hrm_rls_sts			*/
    uint8_t ch_en_sts[MAX_EPS_OUT_CH_CNT];		/*!< channel enable status									*/
    float set_crnt_val[MAX_VOLT_RAIL_CNT];		/*!< set current value										*/
    float rd_crnt_val[MAX_VOLT_RAIL_CNT];		/*!< Read current value										*/
    uint8_t hrm_rls_sts[MAX_HRM_CNT];			/*!< hrm release status										*/
    uint8_t reserved[RSVD_4];					/*!< Reserved												*/
}__attribute__((__packed__))eps_get_chnl_par_s;

/**
 * @brief This API transfer received parameter data to EPS module converter board
 *
 * @param[in]   _set_conv_brd : pointer that has data to be set for converter board
 * @param[out]  _response  	 : response of EPS module for set parameters sent to it
 *
 * @return status of eps_err_sts_e
 * @retval equal to zero -> Success / greater than zero -> failure.
 *
 */
eps_err_sts_e eps_set_conv_brd_params(eps_set_conv_brd_s *_set_conv_brd, uint8_t *_response);

/**
 * @brief This API recieve latest EPS RTC parameter data from EPS module
 *
 * @param[out]   get_rtc_tm : pointer that has data recieved from eps module
 *
 * @return status of eps_err_sts_e
 * @retval equal to zero -> Success / greater than zero -> failure.
 *
 */
eps_err_sts_e eps_get_rtc_time(eps_get_rtc_tm_s *get_rtc_tm);

/**
 * @brief This API transfer received rtc parameter data to EPS module
 *
 * @param[in]   set_rtc_tm  : pointer that has data to be set for rtc
 * @param[out]  _response  	 : response of EPS module for set parameters sent to it
 *
 * @return status of eps_err_sts_e
 * @retval equal to zero -> Success / greater than zero -> failure.
*/
eps_err_sts_e eps_set_rtc_time(eps_set_rtc_tm_s  *set_rtc_tm, uint8_t *_response);

/**
 * @brief This API transfer received parameter data to EPS module battery board
 *
 * @param[in]   _set_bat_brd  : pointer that has data to be set for battery board
 * @param[out]  _response  	 : response of EPS module for set parameters sent to it
 *
 * @return status of eps_err_sts_e
 * @retval equal to zero -> Success / greater than zero -> failure.
*/
eps_err_sts_e eps_set_btry_brd_params(eps_set_btry_brd_s *_set_bat_brd,uint8_t *_response);

/**
 * @brief This API transfer EPS channel state value for all individual output channel
 *
 * @param[in]   _out_ch_en_sts  : enable / disable state of all the channel
 * @param[out]  _response  	   : response of EPS module for set parameters sent to it
 *
 * @return status of eps_err_sts_e
 * @retval equal to zero -> Success / greater than zero -> failure.
 *
 */
eps_err_sts_e eps_set_chnl_state(eps_set_out_chnl_enb_s *_out_ch_en_sts, uint8_t *_response);

/**
 * @brief This API transfer received output channel current limits parameter data to EPS module
 *
 * @param[in]   _out_ch_cur_lmt  : pointer that has array of current limit data
 * @param[out]  _response  	    : response of EPS module for set parameters sent to it
 *
 * @return status of eps_err_sts_e
 * @retval equal to zero -> Success / greater than zero -> failure.
 *
 */
eps_err_sts_e eps_set_chnl_crnt_lmt(eps_set_out_chnl_crnt_lmt_s  *_out_ch_cur_lmt, uint8_t *_response);

/**
 *
 * @brief This API transfer received data to EPS mode parameter data
 *
 * @param[in]   _set_mode_params  : pointer that has data to be set for mode parameters
 * @param[out]  _response  	   	 : response of EPS module for set parameters sent to it
 *
 * @return status of eps_err_sts_e
 * @retval equal to zero -> Success / greater than zero -> failure.
 *
 */

eps_err_sts_e eps_set_mode_params(eps_set_mode_s *_set_mode_params,uint8_t *_response);

/**
 * @brief This API receives latest EPS converter board read parameter data received
 *
 * @param[out]  _get_conv_brd_rd  : pointer that has data to be get for converter board read parameters
 *
 * @return status of eps_err_sts_e
 * @retval equal to zero -> Success / greater than zero -> failure.
 *
 */
eps_err_sts_e eps_get_conv_brd_read_params(eps_get_conv_brd_rd_s *_get_conv_brd_rd);

/**
 * @brief This API receives latest EPS converter board set parameter data received
 *
 * @param[out]  _get_conv_brd_st  : pointer that has data to be get for converter board set parameters
 *
 * @return status of eps_err_sts_e
 * @retval equal to zero -> Success / greater than zero -> failure.
 *
 */
eps_err_sts_e eps_get_conv_brd_set_params(eps_get_conv_brd_stng_s *_get_conv_brd_st);

/**
 * @brief This API receives latest EPS battery board read parameter data received
 *
 * @param[out]  _get_batt_brd_rd  : pointer that has data to be get for battery board read parameters
 *
 * @return status of eps_err_sts_e
 * @retval equal to zero -> Success / greater than zero -> failure.
 *
 */
eps_err_sts_e eps_get_btry_brd_read_params(eps_get_btry_brd_rd_s *_get_batt_brd_rd);

/**
 * @brief This API receives latest EPS battery board set parameter data received
 *
 * @param[out]  _get_batt_brd_st  : pointer that has data to be get for battery board set parameters
 *
 * @return status of eps_err_sts_e
 * @retval equal to zero -> Success / greater than zero -> failure.
 *
 */
eps_err_sts_e eps_get_btry_brd_set_params(eps_get_btry_brd_stng_s *_get_batt_brd_st);

/**
 * @brief This API receives latest EPS stored output channel parameter data received
 *
 * @param[out]  _out_chnl_rd  : pointer that has data to be get for output channel parameter
 *
 * @return status of eps_err_sts_e
 * @retval equal to zero -> Success / greater than zero -> failure.
 *
 */
eps_err_sts_e eps_get_chnl_params(eps_get_out_chnl_sts_s *_out_chnl_rd);

/**
 * @brief This API receives previously stored EPS mode parameter value.
 *
 * @param[out]  _get_mode_par  : pointer that has data to be get mode
 *
 * @return status of eps_err_sts_e
 * @retval equal to zero -> Success / greater than zero -> failure.
 *
 */
eps_err_sts_e eps_get_mode_params(eps_get_stng_mode_resp_s *_get_mode_par);

/**
 * @brief This API receives alert flag values if threshold reaches maximum or minimum limit in EPS
 *
 * @param[out]  _alert_flag  : pointer array of alert flag values
 *
 * @return status of eps_err_sts_e
 * @retval equal to zero -> Success / greater than zero -> failure.
 *
 */
eps_err_sts_e eps_get_alert_flag(eps_alert_flag_resp_s *_alert_flag);
#if 0
/**
 * @brief This API receives variable data from given address value
 *
 * @param[in]  slv_type	: output channel board, convertor board
 * @param[in]  _addr  	: address of the variable to read
 * @param[out] _var  	: variable value from the data
 *
 * @return status of eps_err_sts_e
 * @retval equal to zero -> Success / greater than zero -> failure.
 *
 */
eps_err_sts_e eps_get_variable_data(eps_slv_type slv_type,eps_set_var_addr_s *_addr, eps_get_var_data_s *_var);
#endif
/**
 * @brief This API controls on off state of output channel
 *
 * @param[in]  ch_no  : output channel number
 * @param[in]  state  : on-off state of channel
 *
 * @return status of eps_err_sts_e
 * @retval equal to zero -> Success / greater than zero -> failure.
 *
 */
eps_err_sts_e eps_en_chnl(uint8_t ch_no, ch_state state);


/**
 * @brief This API receives total battery voltage from battery board parameters
 *
 * @param[out]  btry_volt  : total battery voltage
 *
 * @return status of eps_err_sts_e
 * @retval equal to zero -> Success / greater than zero -> failure.
 *
 */
eps_err_sts_e eps_get_totl_btry_volt(float *btry_volt);

/**
 * @brief This API receives EPS converter board parameter, extract and store latest necessary
 * 		 parameters from entire set of parameters
 *
 * @param[out]  _get_conv_brd_params_tmr  :  extracted converter board parameters reading
 *
 * @return status of eps_err_sts_e
 * @retval equal to zero -> Success / greater than zero -> failure.
 *
 */
eps_err_sts_e eps_get_conv_brd_params_read(eps_get_conv_brd_tmr_s *_get_conv_brd_params_tmr);

/**
 * @brief This API receives EPS battery board parameter, extract and store latest necessary
 * 		 parameters from entire set of parameters
 *
 * @param[out]  _eps_get_btry_board_par_tmr  :  extracted board parameters reading
 *
 * @return status of eps_err_sts_e
 * @retval equal to zero -> Success / greater than zero -> failure.
 *
 */
eps_err_sts_e eps_get_btry_brd_params_read(eps_get_btry_brd_tmr_s *_eps_get_btry_board_par_tmr);

/**
 * @brief This API receives EPS output channel parameters, extract and store latest necessary
 * 		 parameters from entire set of parameters
 *
 * @param[out]  _eps_get_chnl_par :  extracted latest channel parameters reading
 *
 * @return status of eps_err_sts_e
 * @retval equal to zero -> Success / greater than zero -> failure.
 *
 */
eps_err_sts_e eps_get_chnl_params_read(eps_get_chnl_par_tmr_s *_eps_get_chnl_par);

/**
 * @brief This API receives EPS alert flag values and store latest necessary values
 *
 * @param[out]  _eps_alert_flag_tmr :  extracted alert flag values
 *
 * @return status of eps_err_sts_e
 * @retval equal to zero -> Success / greater than zero -> failure.
 *
 */
eps_err_sts_e eps_get_alert_flag_read(eps_alert_flag_tmr_s *_eps_alert_flag_tmr);

/**
 * @brief This API receives EPS mode parameters and extract charging status from it.
 *
 * @param[out]  btry_chrg_info : 1 - charging, 0- discharging
 *
 * @return status of eps_err_sts_e
 * @retval equal to zero -> Success / greater than zero -> failure.
 *
 */
eps_err_sts_e eps_btry_chrg_sts_read(uint8_t *btry_chrg_info);


/**
 * @brief This API control MCU IO pin state of SBAND enable pin
 *
 * @param[in]  pin   : which state to be enabled or disabled
 * @param[in]  state : output channel state (on / off)
 *
 * @return status of eps_err_sts_e
 * @retval equal to zero -> Success / less than zero -> failure.
 *
 */
eps_err_sts_e eps_set_chnl_state_sband(uint8_t pin,ch_state state);

/**
 * @brief This API initialize pin value of GPIO expander present in edge, PL server and GPS board.
 *
 * @param[in]  pin   : which state to be enabled or disabled
 * @param[in]  state : output channel state (on / off)
 *
 * @return status of eps_err_sts_e
 * @retval equal to zero -> Success / less than zero -> failure.
 *
 */
eps_err_sts_e eps_set_chnl_state_gps(uint8_t pin,ch_state state);

/**
 * @brief This API control MCU IO & GPIO expander pin state and for PL server board
 *
 * @param[in]  pin   : which state to be enabled or disabled
 * @param[in]  state : output channel state (on / off)
 *
 * @return status of eps_err_sts_e
 * @retval equal to zero -> Success / less than zero -> failure.
 *
 */
eps_err_sts_e eps_set_chnl_state_pl_srvr(uint8_t pin, ch_state state);

/**
 * @brief This API control GPIO expander pin state present in edge board
 *
 * @param[in]  pin   : which state to be enabled or disabled
 * @param[in]  state : output channel state (on / off)
 *
 * @return status of eps_err_sts_e
 * @retval equal to zero -> Success / less than zero -> failure.
 *
 */
eps_err_sts_e eps_set_chnl_state_edge(uint8_t pin, ch_state state);

/**
 * @brief This API initialize i2c instance and SSD selection
 *
 */
void eps_gpio_init();

/**
 * @brief This API used for selecting one of two SSD present in PL server board. Data will be written in NVM memory
 *
 * @param[in]  num : SSD selection input
 *
 */
void set_ssd_slot_slec(uint8_t* num);

/**
 * @brief This API used for selecting one of two SSD present in edge board. Data will be written in NVM memory
 *
 * @param[in]  num : SSD selection input
 *
 */
uint8_t get_ssd_slot_slec(uint8_t board_id);

/**
 * @brief This API checks the CRC
 *
 * @param[in]  message   : Buffer pointer
 * @param[in]  length : lemgth of the data
 *
 * @return status of eps_err_sts_e
 * @retval equal to zero -> Success / less than zero -> failure.
 *
 */
uint8_t CRC_8_Bit(uint8_t *message,uint8_t length);

/**
 * @brief This API receives output channel current read parameter
 *
 * @param[out]  _out_chnl_cur_rd  : pointer that has data to be get for output channel current read parameter
 *
 * @return status of eps_err_sts_e
 * @retval equal to zero -> Success / greater than zero -> failure.
 *
 */
eps_err_sts_e eps_get_op_chnl_cur_rd(eps_get_chnl_cur_rd_s *_out_chnl_cur_rd);

/**
 * @brief This API receives output channel current set parameter
 *
 * @param[out]  _out_chnl_cur_lmt_st  : pointer that has data to be get for output channel current set parameter
 *
 * @return status of eps_err_sts_e
 * @retval equal to zero -> Success / greater than zero -> failure.
 *
 */
eps_err_sts_e eps_get_op_chnl_cur_lmt_st(eps_get_chnl_cur_stng_s *_out_chnl_cur_lmt_st);

/**
 * @brief This API controls the TC and TM for EPS simulator
 *
 * @param[out]  ptr  : pointer
 *
 * @return status of eps_err_sts_e
 * @retval equal to zero -> Success / greater than zero -> failure.
 *
 */

/**
 * @brief This function handle the I2C reset while error occur
 * in I2C
 */
uint8_t eps_i2c_reset();


void eps_tctm_code(obc_pck_data_eps *data);

extern uint8_t sock_sim_cntct_flag;

/**
 * @brief This API write the data
 *
 * @param[out]  buff  : buffer pointer
 * @param[in]  length  : length of the data
 *
 * @return status of eps_err_sts_e
 * @retval equal to zero -> Success / greater than zero -> failure.
 *
 */
uint8_t eps_simu_data_write(uint8_t* buff, uint16_t length);

/**
 * @brief This API read the data
 *
 * @param[out]  buff  : buffer pointer
 * @param[in]  length  : length of the data
 *
 * @return status of eps_err_sts_e
 * @retval equal to zero -> Success / greater than zero -> failure.
 *
 */
uint8_t eps_simu_data_read(uint8_t* buff, uint16_t length);

/**
 * @brief This API write the data
 *
 * @param[out]  args  : buffer pointer
 *
 * @return status of eps_err_sts_e
 * @retval equal to zero -> Success / greater than zero -> failure.
 *
 */
void* eps_skt_simu(void* args);

/**
 * @brief This API set the exposure
 *
 * @param[out]  data : buffer pointer
 *
 * @return status of eps_err_sts_e
 * @retval equal to zero -> Success / greater than zero -> failure.
 *
 */
eps_err_sts_e eps_set_expo_simu(uint8_t* data);

/**
 * @brief This API set the channel current
 *
 * @param[out]  data : buffer pointer
 *
 * @return status of eps_err_sts_e
 * @retval equal to zero -> Success / greater than zero -> failure.
 *
 */
eps_err_sts_e eps_set_ch_crnt_simu(uint8_t* data);

/**
 * @brief This API set the battery voltage
 *
 * @param[out]  data : buffer pointer
 *
 * @return status of eps_err_sts_e
 * @retval equal to zero -> Success / greater than zero -> failure.
 *
 */
eps_err_sts_e eps_set_btry_volt_simu(uint8_t* data);

/**
 * @brief This API set the battery temperature
 *
 * @param[out]  data : buffer pointer
 *
 * @return status of eps_err_sts_e
 * @retval equal to zero -> Success / greater than zero -> failure.
 *
 */
eps_err_sts_e eps_set_btry_temp_simu(uint8_t* data);

/**
 * @brief This API get the firmware
 *
 * @param[out]  _get_fw : buffer pointer
 *
 * @return status of eps_err_sts_e
 * @retval equal to zero -> Success / greater than zero -> failure.
 *
 */
eps_err_sts_e eps_get_fw_update(eps_get_fw_s *_get_fw);

/**
 * @brief This API get the payload server channel state
 *
 * @return status of eps_err_sts_e
 * @retval equal to zero -> Success / greater than zero -> failure.
 *
 */
eps_err_sts_e eps_get_chnl_state_pl_srvr();

/**
 * @brief This API get the GPS channel state
 *
 * @return status of eps_err_sts_e
 * @retval equal to zero -> Success / greater than zero -> failure.
 *
 */
eps_err_sts_e eps_get_chnl_state_gps();
eps_err_sts_e eps_set_obc_com_time_out(eps_set_obc_com_timeout_s *eps_set_obc_com_timeout,uint8_t *_response);
eps_err_sts_e eps_get_obc_com_time_out(eps_get_obc_com_timeout_s *eps_get_obc_com_timeout);
int check_socket_disconnected(int sockfd_info);
#if 0
eps_err_sts_e eps_fw_boot_en(eps_slv_en_type boot_mode_en);
#endif
void eps_fw_boot_en(eps_slv_en_type boot_mode_en);
void eps_fw_boot_en_mcu2();
void eps_fw_boot_dis_mcu2();
void eps_fw_boot_en_mcu1();
void eps_fw_boot_dis_mcu1();
void eps_gpio_exp_init();
void ps_ethernet_enable();
#endif /* DRIVERS_AHW_DRIVERS_EPS_INC_EPS_H_ */
