#ifndef __EPS_TC_TM_H__
#define __EPS_TC_TM_H__

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

#define  EPS_BTRY_SIM_EN
//#define  EPS_SIMU_EN

typedef unsigned int uint32;
typedef unsigned short uint16;
typedef unsigned char uint8;

typedef int int32;
typedef float f32;
typedef short int16;
typedef char int8;

#ifndef EPS_BRD_J2
typedef enum eps_ch
{
    EPS_PL_TRANSCELESTIAL = 0,
    EPS_X_BAND,
    EPS_S_BAND,
    EPS_PL_AICRAFT,
    EPS_ADCS,
    EPS_PROP_UNIT_THRUSTER,
    EPS_PL_ZES,
    EPS_PL_SAYARLABS,
    EPS_PL_NETRA,
    EPS_EDGE_BRD,
    EPS_OBC_PS_GPS_STD_PL_BRD,
    EPS_HRM,
    EPS_PL_SERVER,
    EPS_GPS,
    MAX_SAT_DEV_CNT
}eps_ch_s;
#else

typedef enum hw_ch
{
    EPS_PL_TRANSCELESTIAL = 0,
    EPS_S_BAND,
    EPS_X_BAND,
    EPS_PL_STS300,
    EPS_ADCS,
    EPS_PROP_UNIT_THRUSTER,
    EPS_UHF,
    EPS_PL_SCANWAY,
    EPS_PL_NETRA,
    EPS_EDGE_BRD,
    EPS_OBC_PS_GPS_STD_PL_BRD,
    EPS_HRM,
    EPS_PL_SERVER,
    EPS_GPS,
    MAX_SAT_DEV_CNT
}sat_hw_ch_s;
#endif

#ifdef DRISHTI_EN

#define EPS_PL_HW1  		EPS_PL_TRANSCELESTIAL
#define EPS_PL_HW2 			EPS_PL_ZES
#define EPS_EDGE_BRD1		EPS_PL_SAYARLABS
#define EPS_UHF_RADIO_		EPS_PL_AICRAFT
#define EPS_MSI_PL_HEATR	EPS_PL_NETRA
#define EPS_SSD_HEATR		EPS_HRM
#define EPS_ETH_SW			MAX_SAT_DEV_CNT

#endif

#define EPS_BATTERY_TMR MAX_SAT_DEV_CNT
#ifdef EPS_BTRY_SIM_EN
void eps_btry_val(float *_btry_volt);
#endif

#ifdef EPS_SIMU_EN
typedef struct 
{
	uint8_t expo_data_cnt;
    uint8_t mem_set;
    uint8_t solar_mode;
    uint8_t expo_data[EXPOSURE_LUT_SIZE];

}eps_sim_expo_s;


typedef struct
{
	uint8_t chnl_pwr_con_cnt;
    uint8_t mem_set;
    uint8_t ch_crnt_mode;
    float ch_power_con[MAX_VOLT_RAIL_CNT];
}eps_sim_ch_crnt_s;

typedef struct
{
    uint8_t mem_set;
    uint8_t btry_mode;
    float btry_volt;
}eps_sim_btry_volt_s;

typedef struct
{
    uint8_t mem_set;
    uint8_t temp_mode;
    uint8_t cell_num;
    uint8_t tempr;
    uint8_t btry_temp_mode;
    uint8_t temp_lmt_lwr;
    uint8_t temp_lmt_up;
}eps_sim_btry_temp_s;
#endif

typedef enum
{
    HW_BTRY_CRTCAL = 0,
    HW_BTRY_SAFE,
    HW_BTRY_NORMAL,
    HW_BTRY_FULL
}sat_btry_sts_s;

typedef struct
{
    float volt[MAX_VOLT_CNT];
}eps_btry_thrshld;

typedef struct  __attribute__((packed))
{
    uint8_t min;
    uint8_t sec;
    uint16_t msec;
}eps_time_s;

typedef struct  __attribute__((packed))
{
    uint8_t max_st_cnt;
    eps_time_s st_val[MAX_DEV_TMR_ST_VAL];
}eps_dev_tmr_s;

typedef struct  __attribute__((packed))
{
    eps_dev_tmr_s on_tmr;
    eps_dev_tmr_s off_tmr;
}eps_dev_tmr_t;

typedef struct __attribute__((packed))
{
    uint8_t ch_no;
    uint8_t ch_st;
}eps_dev_sts_s;

typedef struct  __attribute__((packed))
{
    uint8_t dev_no;
    eps_dev_tmr_t pwr_tmr;
}eps_dev_tmr_c;

typedef struct __attribute__((packed))
{
        uint8_t ch_map_cnt;
   //     uint8_t auto_on_cnt;
        uint16_t ch_map[MAX_CHNL_MAP_CNT];
        uint16_t auto_on[MAX_AUTO_ON_CNT];

}eps_btry_ch_map_s;

typedef enum
{
    PWR_OFF = 0,
    PWR_BOOT = 1,
    PWR_ON = 2,
    PWR_SD = 3,
    PWR_RSTRT = 4,
    PWR_ERR
}dev_hw_sts_s;


typedef enum dev_sw_st
{
    SW_INACTIVE = 0,
    SW_ACTIVE = 1,
    SW_ERROR = 2
}dev_sw_sts_s;

typedef struct
{
    uint8_t hw_sts;
    uint8_t sw_sts;
}sat_dev_sts_s;


static inline void eps_pl_trans_tmr_defaults(eps_dev_tmr_t *_pl_trans_tmr)
{
	_pl_trans_tmr->on_tmr.max_st_cnt= 2;

	_pl_trans_tmr->on_tmr.st_val[0].min  = 0;
	_pl_trans_tmr->on_tmr.st_val[0].sec  = 33;
	_pl_trans_tmr->on_tmr.st_val[0].msec = 0;
	_pl_trans_tmr->on_tmr.st_val[1].min  = 0;
	_pl_trans_tmr->on_tmr.st_val[1].sec  = 2;
	_pl_trans_tmr->on_tmr.st_val[1].msec = 10;

	_pl_trans_tmr->off_tmr.max_st_cnt= 2;

	_pl_trans_tmr->off_tmr.st_val[0].min  = 0;
	_pl_trans_tmr->off_tmr.st_val[0].sec  = 3;
	_pl_trans_tmr->off_tmr.st_val[0].msec = 0;
}
#ifndef EPS_BRD_J2

static inline void eps_pl_aicraft_tmr_defaults(eps_dev_tmr_t *_pl_aicraft_tmr)
{
    _pl_aicraft_tmr->on_tmr.max_st_cnt= 2;

    _pl_aicraft_tmr->on_tmr.st_val[0].min  = 0;
    _pl_aicraft_tmr->on_tmr.st_val[0].sec  = 0;
    _pl_aicraft_tmr->on_tmr.st_val[0].msec = 50;
    _pl_aicraft_tmr->on_tmr.st_val[1].min  = 0;
    _pl_aicraft_tmr->on_tmr.st_val[1].sec  = 0;
    _pl_aicraft_tmr->on_tmr.st_val[1].msec = 10;

    _pl_aicraft_tmr->off_tmr.max_st_cnt= 2;
    _pl_aicraft_tmr->off_tmr.st_val[0].min  = 5;
    _pl_aicraft_tmr->off_tmr.st_val[0].sec  = 0;
    _pl_aicraft_tmr->off_tmr.st_val[0].msec = 0;
    _pl_aicraft_tmr->off_tmr.st_val[1].min  = 0;
    _pl_aicraft_tmr->off_tmr.st_val[1].sec  = 0;
    _pl_aicraft_tmr->off_tmr.st_val[1].msec = 10;
}
#else
static inline void eps_pl_sts300_tmr_defaults(eps_dev_tmr_t *_pl_sts300_tmr)
{
        _pl_sts300_tmr->on_tmr.max_st_cnt= 2;

        _pl_sts300_tmr->on_tmr.st_val[0].min  = 0;
        _pl_sts300_tmr->on_tmr.st_val[0].sec  = 0;
        _pl_sts300_tmr->on_tmr.st_val[0].msec = 50;
        _pl_sts300_tmr->on_tmr.st_val[1].min  = 0;
        _pl_sts300_tmr->on_tmr.st_val[1].sec  = 0;
        _pl_sts300_tmr->on_tmr.st_val[1].msec = 10;

        _pl_sts300_tmr->off_tmr.max_st_cnt= 2;

        _pl_sts300_tmr->off_tmr.st_val[0].min  = 0;
        _pl_sts300_tmr->off_tmr.st_val[0].sec  = 1;
        _pl_sts300_tmr->off_tmr.st_val[0].msec = 0;
}
#endif

static inline void eps_pl_netra_tmr_defaults(eps_dev_tmr_t *_pl_netra_tmr)
{
	_pl_netra_tmr->on_tmr.max_st_cnt= 2;

	_pl_netra_tmr->on_tmr.st_val[0].min  = 0;
	_pl_netra_tmr->on_tmr.st_val[0].sec  = 13;
	_pl_netra_tmr->on_tmr.st_val[0].msec = 0;
	_pl_netra_tmr->on_tmr.st_val[1].min  = 0;
	_pl_netra_tmr->on_tmr.st_val[1].sec  = 0;
	_pl_netra_tmr->on_tmr.st_val[1].msec = 10;

	_pl_netra_tmr->off_tmr.max_st_cnt= 2;

	_pl_netra_tmr->off_tmr.st_val[0].min  = 0;
	_pl_netra_tmr->off_tmr.st_val[0].sec  = 3;
	_pl_netra_tmr->off_tmr.st_val[0].msec = 0;
}

#ifndef EPS_BRD_J2

static inline void eps_pl_syrlbs_tmr_defaults(eps_dev_tmr_t *_pl_syrlbs_tmr)
{
    _pl_syrlbs_tmr->on_tmr.max_st_cnt= 2;

    _pl_syrlbs_tmr->on_tmr.st_val[0].min  = 0;
    _pl_syrlbs_tmr->on_tmr.st_val[0].sec  = 0;
    _pl_syrlbs_tmr->on_tmr.st_val[0].msec = 50;
    _pl_syrlbs_tmr->on_tmr.st_val[1].min  = 0;
    _pl_syrlbs_tmr->on_tmr.st_val[1].sec  = 0;
    _pl_syrlbs_tmr->on_tmr.st_val[1].msec = 10;

    _pl_syrlbs_tmr->off_tmr.max_st_cnt= 2;

    _pl_syrlbs_tmr->off_tmr.st_val[0].min  = 5;
    _pl_syrlbs_tmr->off_tmr.st_val[0].sec  = 0;
    _pl_syrlbs_tmr->off_tmr.st_val[0].msec = 0;
    _pl_syrlbs_tmr->off_tmr.st_val[1].min  = 0;
    _pl_syrlbs_tmr->off_tmr.st_val[1].sec  = 0;
    _pl_syrlbs_tmr->off_tmr.st_val[1].msec = 10;

}
#else
static inline void eps_pl_scanway_tmr_defaults(eps_dev_tmr_t *_pl_scanway_tmr)
{
	_pl_scanway_tmr->on_tmr.max_st_cnt= 2;

	_pl_scanway_tmr->on_tmr.st_val[0].min  = 0;
	_pl_scanway_tmr->on_tmr.st_val[0].sec  = 0;
	_pl_scanway_tmr->on_tmr.st_val[0].msec = 50;
	_pl_scanway_tmr->on_tmr.st_val[1].min  = 0;
	_pl_scanway_tmr->on_tmr.st_val[1].sec  = 0;
	_pl_scanway_tmr->on_tmr.st_val[1].msec = 10;

	_pl_scanway_tmr->off_tmr.max_st_cnt= 2;

	_pl_scanway_tmr->off_tmr.st_val[0].min  = 0;
	_pl_scanway_tmr->off_tmr.st_val[0].sec  = 1;
	_pl_scanway_tmr->off_tmr.st_val[0].msec = 0;
}
#endif

static inline void eps_pl_zes_tmr_defaults(eps_dev_tmr_t *_pl_zes_tmr)
{
    _pl_zes_tmr->on_tmr.max_st_cnt= 2;

    _pl_zes_tmr->on_tmr.st_val[0].min  = 0;
    _pl_zes_tmr->on_tmr.st_val[0].sec  = 0;
    _pl_zes_tmr->on_tmr.st_val[0].msec = 50;
    _pl_zes_tmr->on_tmr.st_val[1].min  = 0;
    _pl_zes_tmr->on_tmr.st_val[1].sec  = 0;
    _pl_zes_tmr->on_tmr.st_val[1].msec = 10;

    _pl_zes_tmr->off_tmr.max_st_cnt= 2;

    _pl_zes_tmr->off_tmr.st_val[0].min  = 5;
    _pl_zes_tmr->off_tmr.st_val[0].sec  = 0;
    _pl_zes_tmr->off_tmr.st_val[0].msec = 0;
    _pl_zes_tmr->off_tmr.st_val[1].min  = 0;
    _pl_zes_tmr->off_tmr.st_val[1].sec  = 0;
    _pl_zes_tmr->off_tmr.st_val[1].msec = 10;
}


static inline void eps_thrstr_tmr_defaults(eps_dev_tmr_t *_thrstr_tmr)
{
    _thrstr_tmr->on_tmr.max_st_cnt= 2;

    _thrstr_tmr->on_tmr.st_val[0].min  = 0;
    _thrstr_tmr->on_tmr.st_val[0].sec  = 0;
    _thrstr_tmr->on_tmr.st_val[0].msec = 50;
    _thrstr_tmr->on_tmr.st_val[1].min  = 0;
    _thrstr_tmr->on_tmr.st_val[1].sec  = 0;
    _thrstr_tmr->on_tmr.st_val[1].msec = 10;

    _thrstr_tmr->off_tmr.max_st_cnt= 2;

    _thrstr_tmr->off_tmr.st_val[0].min  = 5;
    _thrstr_tmr->off_tmr.st_val[0].sec  = 0;
    _thrstr_tmr->off_tmr.st_val[0].msec = 0;
    _thrstr_tmr->off_tmr.st_val[1].min  = 0;
    _thrstr_tmr->off_tmr.st_val[1].sec  = 0;
    _thrstr_tmr->off_tmr.st_val[1].msec = 10;

}


static inline void eps_obc_tmr_defaults(eps_dev_tmr_t *_obc_tmr)
{
    _obc_tmr->on_tmr.max_st_cnt= 2;

    _obc_tmr->on_tmr.st_val[0].min  = 0;
    _obc_tmr->on_tmr.st_val[0].sec  = 0;
    _obc_tmr->on_tmr.st_val[0].msec = 50;
    _obc_tmr->on_tmr.st_val[1].min  = 0;
    _obc_tmr->on_tmr.st_val[1].sec  = 0;
    _obc_tmr->on_tmr.st_val[1].msec = 10;

    _obc_tmr->off_tmr.max_st_cnt= 2;

    _obc_tmr->off_tmr.st_val[0].min  = 5;
    _obc_tmr->off_tmr.st_val[0].sec  = 0;
    _obc_tmr->off_tmr.st_val[0].msec = 0;
    _obc_tmr->off_tmr.st_val[1].min  = 0;
    _obc_tmr->off_tmr.st_val[1].sec  = 0;
    _obc_tmr->off_tmr.st_val[1].msec = 10;

}

static inline void eps_xband_tmr_defaults(eps_dev_tmr_t *_xband_tmr)
{
    _xband_tmr->on_tmr.max_st_cnt= 2;

    _xband_tmr->on_tmr.st_val[0].min  = 0;
    _xband_tmr->on_tmr.st_val[0].sec  = 0;
    _xband_tmr->on_tmr.st_val[0].msec = 50;
    _xband_tmr->on_tmr.st_val[1].min  = 0;
    _xband_tmr->on_tmr.st_val[1].sec  = 0;
    _xband_tmr->on_tmr.st_val[1].msec = 10;

    _xband_tmr->off_tmr.max_st_cnt= 2;

    _xband_tmr->off_tmr.st_val[0].min  = 5;
    _xband_tmr->off_tmr.st_val[0].sec  = 0;
    _xband_tmr->off_tmr.st_val[0].msec = 0;
    _xband_tmr->off_tmr.st_val[1].min  = 0;
    _xband_tmr->off_tmr.st_val[1].sec  = 0;
    _xband_tmr->off_tmr.st_val[1].msec = 10;

}


static inline void eps_edge_tmr_defaults(eps_dev_tmr_t *_edge_brd_tmr)
{
	_edge_brd_tmr->on_tmr.max_st_cnt= 5;

	_edge_brd_tmr->on_tmr.st_val[0].min  = 0;
	_edge_brd_tmr->on_tmr.st_val[0].sec  = 2;
	_edge_brd_tmr->on_tmr.st_val[0].msec = 0;
	_edge_brd_tmr->on_tmr.st_val[1].min  = 0;
	_edge_brd_tmr->on_tmr.st_val[1].sec  = 0;
	_edge_brd_tmr->on_tmr.st_val[1].msec = 100;
	_edge_brd_tmr->on_tmr.st_val[2].min  = 0;
	_edge_brd_tmr->on_tmr.st_val[2].sec  = 2;
	_edge_brd_tmr->on_tmr.st_val[2].msec = 0;
	_edge_brd_tmr->on_tmr.st_val[3].min  = 1;
	_edge_brd_tmr->on_tmr.st_val[3].sec  = 35;
	_edge_brd_tmr->on_tmr.st_val[3].msec = 0;
	_edge_brd_tmr->on_tmr.st_val[4].min  = 5;
	_edge_brd_tmr->on_tmr.st_val[4].sec  = 0;
	_edge_brd_tmr->on_tmr.st_val[4].msec = 0;

	_edge_brd_tmr->off_tmr.max_st_cnt= 5;

	_edge_brd_tmr->off_tmr.st_val[0].min  = 1;
	_edge_brd_tmr->off_tmr.st_val[0].sec  = 0;
	_edge_brd_tmr->off_tmr.st_val[0].msec = 0;
	_edge_brd_tmr->off_tmr.st_val[1].min  = 0;
	_edge_brd_tmr->off_tmr.st_val[1].sec  = 0;
	_edge_brd_tmr->off_tmr.st_val[1].msec = 10;
	_edge_brd_tmr->off_tmr.st_val[2].min  = 0;
	_edge_brd_tmr->off_tmr.st_val[2].sec  = 0;
	_edge_brd_tmr->off_tmr.st_val[2].msec = 10;
	_edge_brd_tmr->off_tmr.st_val[3].min  = 2;
	_edge_brd_tmr->off_tmr.st_val[3].sec  = 3;
	_edge_brd_tmr->off_tmr.st_val[3].msec = 10;
	_edge_brd_tmr->off_tmr.st_val[4].min  = 0;
	_edge_brd_tmr->off_tmr.st_val[4].sec  = 0;
	_edge_brd_tmr->off_tmr.st_val[4].msec = 10;
}


static inline void eps_adcs_tmr_defaults(eps_dev_tmr_t *_adcs_brd_tmr)
{
	_adcs_brd_tmr->on_tmr.max_st_cnt= 3;

	_adcs_brd_tmr->on_tmr.st_val[0].min  = 0;
	_adcs_brd_tmr->on_tmr.st_val[0].sec  = 1;
	_adcs_brd_tmr->on_tmr.st_val[0].msec = 0;
	_adcs_brd_tmr->on_tmr.st_val[1].min  = 0;
	_adcs_brd_tmr->on_tmr.st_val[1].sec  = 5;
	_adcs_brd_tmr->on_tmr.st_val[1].msec = 0;
	_adcs_brd_tmr->on_tmr.st_val[2].min  = 0;
	_adcs_brd_tmr->on_tmr.st_val[2].sec  = 5;
	_adcs_brd_tmr->on_tmr.st_val[2].msec = 0;

	_adcs_brd_tmr->off_tmr.max_st_cnt= 3;

	_adcs_brd_tmr->off_tmr.st_val[0].min  = 0;
	_adcs_brd_tmr->off_tmr.st_val[0].sec  = 5;
	_adcs_brd_tmr->off_tmr.st_val[0].msec = 0;
	_adcs_brd_tmr->off_tmr.st_val[1].min  = 0;
	_adcs_brd_tmr->off_tmr.st_val[1].sec  = 1;
	_adcs_brd_tmr->off_tmr.st_val[1].msec = 0;
	_adcs_brd_tmr->off_tmr.st_val[2].min   = 0;
	_adcs_brd_tmr->off_tmr.st_val[2].sec   = 1;
	_adcs_brd_tmr->off_tmr.st_val[2].msec  = 0;
}


static inline void eps_gps_dc_tmr_defaults(eps_dev_tmr_t *_gps_dc_brd_tmr)
{
	_gps_dc_brd_tmr->on_tmr.max_st_cnt= 3;

	_gps_dc_brd_tmr->on_tmr.st_val[0].min  = 0;
	_gps_dc_brd_tmr->on_tmr.st_val[0].sec  = 1;
	_gps_dc_brd_tmr->on_tmr.st_val[0].msec = 0;
	_gps_dc_brd_tmr->on_tmr.st_val[1].min  = 1;
	_gps_dc_brd_tmr->on_tmr.st_val[1].sec  = 3;
	_gps_dc_brd_tmr->on_tmr.st_val[1].msec = 0;
	_gps_dc_brd_tmr->on_tmr.st_val[2].min  = 0;
	_gps_dc_brd_tmr->on_tmr.st_val[2].sec  = 3;
	_gps_dc_brd_tmr->on_tmr.st_val[2].msec = 0;

	_gps_dc_brd_tmr->off_tmr.max_st_cnt= 3;

	_gps_dc_brd_tmr->off_tmr.st_val[0].min  = 0;
	_gps_dc_brd_tmr->off_tmr.st_val[0].sec  = 1;
	_gps_dc_brd_tmr->off_tmr.st_val[0].msec = 0;
	_gps_dc_brd_tmr->off_tmr.st_val[1].min  = 0;
	_gps_dc_brd_tmr->off_tmr.st_val[1].sec  = 1;
	_gps_dc_brd_tmr->off_tmr.st_val[1].msec = 0;
	_gps_dc_brd_tmr->off_tmr.st_val[2].min  = 0;
	_gps_dc_brd_tmr->off_tmr.st_val[2].sec  = 1;
	_gps_dc_brd_tmr->off_tmr.st_val[2].msec = 0;
}



static inline void eps_sband_tmr_defaults(eps_dev_tmr_t *_sband_tmr)
{
	_sband_tmr->on_tmr.max_st_cnt= 2;

	_sband_tmr->on_tmr.st_val[0].min  = 0;
	_sband_tmr->on_tmr.st_val[0].sec  = 13;
	_sband_tmr->on_tmr.st_val[0].msec = 0;
	_sband_tmr->on_tmr.st_val[1].min  = 0;
	_sband_tmr->on_tmr.st_val[1].sec  = 0;
	_sband_tmr->on_tmr.st_val[1].msec = 10;

	_sband_tmr->off_tmr.max_st_cnt= 2;

	_sband_tmr->off_tmr.st_val[0].min  = 0;
	_sband_tmr->off_tmr.st_val[0].sec  = 3;
	_sband_tmr->off_tmr.st_val[0].msec = 0;
	_sband_tmr->off_tmr.st_val[1].min  = 0;
	_sband_tmr->off_tmr.st_val[1].sec  = 0;
	_sband_tmr->off_tmr.st_val[1].msec = 10;
}





static inline void eps_ps_brd_tmr_defaults(eps_dev_tmr_t *_ps_brd_tmr)
{
	_ps_brd_tmr->on_tmr.max_st_cnt= 5;

	_ps_brd_tmr->on_tmr.st_val[0].min  = 0;
	_ps_brd_tmr->on_tmr.st_val[0].sec  = 0;
	_ps_brd_tmr->on_tmr.st_val[0].msec = 50;
	_ps_brd_tmr->on_tmr.st_val[1].min  = 0;
	_ps_brd_tmr->on_tmr.st_val[1].sec  = 0;
	_ps_brd_tmr->on_tmr.st_val[1].msec = 10;
	_ps_brd_tmr->on_tmr.st_val[2].min  = 1;
	_ps_brd_tmr->on_tmr.st_val[2].sec  = 35;
	_ps_brd_tmr->on_tmr.st_val[2].msec = 0;

	_ps_brd_tmr->off_tmr.max_st_cnt= 5;

	_ps_brd_tmr->off_tmr.st_val[0].min  = 1;
	_ps_brd_tmr->off_tmr.st_val[0].sec  = 0;
	_ps_brd_tmr->off_tmr.st_val[0].msec = 0;
	_ps_brd_tmr->off_tmr.st_val[1].min  = 0;
	_ps_brd_tmr->off_tmr.st_val[1].sec  = 0;
	_ps_brd_tmr->off_tmr.st_val[1].msec = 10;
	_ps_brd_tmr->off_tmr.st_val[2].min  = 2;
	_ps_brd_tmr->off_tmr.st_val[2].sec  = 3;
	_ps_brd_tmr->off_tmr.st_val[2].msec = 0;
}

static inline void eps_pl_uhf_tmr_defaults(eps_dev_tmr_t *_pl_uhf_tmr)
{
	_pl_uhf_tmr->on_tmr.max_st_cnt= 2;

	_pl_uhf_tmr->on_tmr.st_val[0].min  = 0;
	_pl_uhf_tmr->on_tmr.st_val[0].sec  = 3;
	_pl_uhf_tmr->on_tmr.st_val[0].msec = 0;
	_pl_uhf_tmr->on_tmr.st_val[1].min  = 0;
	_pl_uhf_tmr->on_tmr.st_val[1].sec  = 0;
	_pl_uhf_tmr->on_tmr.st_val[1].msec = 10;

	_pl_uhf_tmr->off_tmr.max_st_cnt= 2;

	_pl_uhf_tmr->off_tmr.st_val[0].min  = 0;
	_pl_uhf_tmr->off_tmr.st_val[0].sec  = 3;
	_pl_uhf_tmr->off_tmr.st_val[0].msec = 0;
}


typedef struct
{
    uint8_t hour;
    uint8_t min;
    uint8_t sec;
}time_s;

typedef struct _eps_get_btry_board_par_tmr
{
    uint8_t buff_cnt;
    uint8_t btry_volt_cnt;
    uint8_t btry_temp_cnt;
    uint64_t  time;
    float       totl_vol;
    float       vol_ch[MAX_BTRY_CNT_PER_SET];
    float       totl_crnt;
    uint8_t     tempr[MAX_BTRY_TMP_SNSR_CNT];
    uint8_t     btry_chrg_sts;
 //   uint8_t revd[3];
}__attribute__((__packed__))eps_get_btry_brd_tmr_s;

typedef struct _eps_get_conv_board_par_tmr
{
    uint8_t buff_cnt;
    uint8_t pv_volt_cnt;							
    uint8_t pv_cur_cnt;								
    uint8_t op_conv_volt_cnt;						
    uint64_t time;
    float      pv_volt[MAX_SLR_PNL_CNT];
    float      pv_cur[MAX_SLR_PNL_CNT];
    float      op_volt_conv_read[MAX_MPPT_CONV_CNT];
}eps_get_conv_brd_tmr_s;


typedef struct eps_hlth_infor_t
{
    uint16_t        dev_hw_sts;
    uint32_t        alrt_value;
    uint32_t        com_fail_cnt;
    uint32_t        crc_fail_cnt;
    eps_get_btry_brd_tmr_s btry_params;
    eps_get_conv_brd_tmr_s conv_params;
}eps_hlth_info_s;


typedef struct _eps_get_chnl_par_tmr
{
    uint8_t buff_cnt;
    uint8_t volt_rail_cnt;	
    uint64_t time;
    float       rd_crnt_val[MAX_VOLT_RAIL_CNT];

}__attribute__((__packed__))eps_get_chnl_par_tmr_s;



typedef struct _tctm_eps_set_var_addr
{
    uint8_t mem_addr_cnt;
    uint8_t slv_addr;
    uint8_t addr[EPS_MEM_ADDR_SIZE];
    uint8_t reserved[RSVD_5];

}__attribute__((__packed__))tctm_eps_set_var_addr_s;

typedef struct _tctm_eps_get_var_addr
{
   uint8_t data[EPS_DATA_SIZE];
   uint8_t reserved[RSVD_11];

}__attribute__((__packed__))tctm_eps_get_var_val_s;

typedef struct _eps_alert_flag_tmr
{
    uint8_t buff_cnt;
    uint64_t  time;
    uint32_t    value;
    uint8_t hour;
    uint8_t min;
    uint8_t sec;
}__attribute__((__packed__))eps_alert_flag_tmr_s;


static inline void eps_btry_tmr_defaults(eps_dev_tmr_t *_btry_tmr)
{
    _btry_tmr->on_tmr.max_st_cnt= 1;

    _btry_tmr->on_tmr.st_val[0].min  = 5;
    _btry_tmr->on_tmr.st_val[0].sec  = 0;
    _btry_tmr->on_tmr.st_val[0].msec = 0;

    _btry_tmr->off_tmr.max_st_cnt= 1;

    _btry_tmr->off_tmr.st_val[0].min  = 5;
    _btry_tmr->off_tmr.st_val[0].sec  = 0;
    _btry_tmr->off_tmr.st_val[0].msec = 0;
}

static inline void eps_hrm_tmr_defaults(eps_dev_tmr_t *_hrm_tmr)
{
    _hrm_tmr->on_tmr.max_st_cnt= 3;

    _hrm_tmr->on_tmr.st_val[0].min  = 2;
    _hrm_tmr->on_tmr.st_val[0].sec  = 0;
    _hrm_tmr->on_tmr.st_val[0].msec = 0;
    _hrm_tmr->on_tmr.st_val[1].min  = 0;
    _hrm_tmr->on_tmr.st_val[1].sec  = 10;
    _hrm_tmr->on_tmr.st_val[1].msec = 0;
    _hrm_tmr->on_tmr.st_val[2].min  = 2;
    _hrm_tmr->on_tmr.st_val[2].sec  = 0;
    _hrm_tmr->on_tmr.st_val[2].msec = 0;

    _hrm_tmr->off_tmr.max_st_cnt= 5;
}

static inline void eps_chnl_eligible_to_restart(uint16_t *eps_chnl_num)
{
	*eps_chnl_num=									\
			(  0  <<  EPS_PL_TRANSCELESTIAL)|		\
			(  1  <<  EPS_S_BAND)|					\
			(  0  <<  EPS_X_BAND)|					\
			(  0  <<  EPS_PL_STS300)|				\
			(  1  <<  EPS_ADCS)|						\
			(  0  <<  EPS_PROP_UNIT_THRUSTER)|		\
			(  1  <<  EPS_UHF)|						\
			(  0  <<  EPS_PL_SCANWAY)|				\
			(  0  <<  EPS_PL_NETRA)|					\
			(  0  <<  EPS_EDGE_BRD)|					\
			(  0  <<  EPS_OBC_PS_GPS_STD_PL_BRD)|	\
			(  0  <<  EPS_HRM);
}


static inline void eps_ctrlr_set_ch_valid_defaults(eps_btry_ch_map_s *_eps_btry_ch_map)
{
#ifndef EPS_BRD_J2
    //1 - channel enable   , 0 - channel disable
    _eps_btry_ch_map->ch_map[HW_BTRY_CRTCAL]=(  0  <<  EPS_PL_TRANSCELESTIAL)|      \
                                             (  0  <<  EPS_X_BAND)|                  \
                                             (  0  <<  EPS_S_BAND)|                  \
                                             (  0  <<  EPS_PL_AICRAFT)|              \
                                             (  0  <<  EPS_ADCS)|                    \
                                             (  0  <<  EPS_PROP_UNIT_THRUSTER)|      \
                                             (  0  <<  EPS_PL_ZES)|                  \
                                             (  0  <<  EPS_PL_SAYARLABS)|            \
                                             (  0  <<  EPS_PL_NETRA)|                \
                                             (  0  <<  EPS_EDGE_BRD)|                \
                                             (  1  <<  EPS_OBC_PS_GPS_STD_PL_BRD)|   \
                                             (  0  <<  EPS_PL_SERVER)|               \
                                             (  0  <<  EPS_GPS)|                     \
                                             (  0  <<  EPS_HRM);

    _eps_btry_ch_map->ch_map[HW_BTRY_SAFE] =(  0  <<  EPS_PL_TRANSCELESTIAL)|       \
                                            (  0  <<  EPS_X_BAND)|                  \
                                            (  0  <<  EPS_S_BAND)|                  \
                                            (  0  <<  EPS_PL_AICRAFT)|              \
                                            (  1  <<  EPS_ADCS)|                    \
                                            (  0  <<  EPS_PROP_UNIT_THRUSTER)|      \
                                            (  0  <<  EPS_PL_ZES)|                  \
                                            (  0  <<  EPS_PL_SAYARLABS)|            \
                                            (  0  <<  EPS_PL_NETRA)|                \
                                            (  0  <<  EPS_EDGE_BRD)|                \
                                            (  1  <<  EPS_OBC_PS_GPS_STD_PL_BRD)|   \
                                            (  0  <<  EPS_PL_SERVER)|               \
                                            (  0  <<  EPS_GPS)|                     \
                                            (  1  <<  EPS_HRM);

    _eps_btry_ch_map->ch_map[HW_BTRY_NORMAL]=(  1  <<  EPS_PL_TRANSCELESTIAL)|      \
                                             (  1  <<  EPS_X_BAND)|                  \
                                             (  1  <<  EPS_S_BAND)|                  \
                                             (  1  <<  EPS_PL_AICRAFT)|              \
                                             (  1  <<  EPS_ADCS)|                    \
                                             (  1  <<  EPS_PROP_UNIT_THRUSTER)|      \
                                             (  1  <<  EPS_PL_ZES)|                  \
                                             (  1  <<  EPS_PL_SAYARLABS)|            \
                                             (  1  <<  EPS_PL_NETRA)|                \
                                             (  1  <<  EPS_EDGE_BRD)|                \
                                             (  1  <<  EPS_OBC_PS_GPS_STD_PL_BRD)|   \
                                             (  1  <<  EPS_PL_SERVER)|               \
                                             (  1  <<  EPS_GPS)|                     \
                                             (  1  <<  EPS_HRM);

    _eps_btry_ch_map->ch_map[HW_BTRY_FULL] = (  1  <<  EPS_PL_TRANSCELESTIAL)|      \
                                             (  1  <<  EPS_X_BAND)|                  \
                                             (  1  <<  EPS_S_BAND)|                  \
                                             (  1  <<  EPS_PL_AICRAFT)|              \
                                             (  1  <<  EPS_ADCS)|                    \
                                             (  1  <<  EPS_PROP_UNIT_THRUSTER)|      \
                                             (  1  <<  EPS_PL_ZES)|                  \
                                             (  1  <<  EPS_PL_SAYARLABS)|            \
                                             (  1  <<  EPS_PL_NETRA)|                \
                                             (  1  <<  EPS_EDGE_BRD)|                \
                                             (  1  <<  EPS_OBC_PS_GPS_STD_PL_BRD)|   \
                                             (  1  <<  EPS_PL_SERVER)|               \
                                             (  1  <<  EPS_GPS)|                     \
                                             (  1  <<  EPS_HRM);

    _eps_btry_ch_map->auto_on[HW_BTRY_CRTCAL]=(  0  <<  EPS_PL_TRANSCELESTIAL)|       \
                                             (  0  <<  EPS_X_BAND)|                  \
                                             (  1  <<  EPS_S_BAND)|                  \
                                             (  0  <<  EPS_PL_AICRAFT)|              \
                                             (  1  <<  EPS_ADCS)|                    \
                                             (  0  <<  EPS_PROP_UNIT_THRUSTER)|      \
                                             (  0  <<  EPS_PL_ZES)|                  \
                                             (  0  <<  EPS_PL_SAYARLABS)|            \
                                             (  0  <<  EPS_PL_NETRA)|                \
                                             (  0  <<  EPS_EDGE_BRD)|                \
                                             (  1  <<  EPS_OBC_PS_GPS_STD_PL_BRD)|   \
                                             (  0  <<  EPS_PL_SERVER)|               \
                                             (  0  <<  EPS_GPS)|                     \
                                             (  1  <<  EPS_HRM);

    _eps_btry_ch_map->auto_on[HW_BTRY_SAFE] =(  0  <<  EPS_PL_TRANSCELESTIAL)|       \
                                            (  0  <<  EPS_X_BAND)|                  \
                                            (  1  <<  EPS_S_BAND)|                  \
                                            (  0  <<  EPS_PL_AICRAFT)|              \
                                            (  1  <<  EPS_ADCS)|                    \
                                            (  0  <<  EPS_PROP_UNIT_THRUSTER)|      \
                                            (  0  <<  EPS_PL_ZES)|                  \
                                            (  0  <<  EPS_PL_SAYARLABS)|            \
                                            (  0  <<  EPS_PL_NETRA)|                \
                                            (  0  <<  EPS_EDGE_BRD)|                \
                                            (  1  <<  EPS_OBC_PS_GPS_STD_PL_BRD)|   \
                                            (  0  <<  EPS_PL_SERVER)|               \
                                            (  0  <<  EPS_GPS)|                     \
                                            (  1  <<  EPS_HRM);

    _eps_btry_ch_map->auto_on[HW_BTRY_NORMAL]=(  0  <<  EPS_PL_TRANSCELESTIAL)|       \
                                             (  0  <<  EPS_X_BAND)|                  \
                                             (  1  <<  EPS_S_BAND)|                  \
                                             (  0  <<  EPS_PL_AICRAFT)|              \
                                             (  1  <<  EPS_ADCS)|                    \
                                             (  0  <<  EPS_PROP_UNIT_THRUSTER)|      \
                                             (  0  <<  EPS_PL_ZES)|                  \
                                             (  0  <<  EPS_PL_SAYARLABS)|            \
                                             (  0  <<  EPS_PL_NETRA)|                \
                                             (  0  <<  EPS_EDGE_BRD)|                \
                                             (  1  <<  EPS_OBC_PS_GPS_STD_PL_BRD)|   \
                                             (  0  <<  EPS_PL_SERVER)|               \
                                             (  0  <<  EPS_GPS)|                     \
                                             (  1  <<  EPS_HRM);

    _eps_btry_ch_map->auto_on[HW_BTRY_FULL] =(  0  <<  EPS_PL_TRANSCELESTIAL)|       \
                                            (  0  <<  EPS_X_BAND)|                  \
                                            (  1  <<  EPS_S_BAND)|                  \
                                            (  0  <<  EPS_PL_AICRAFT)|              \
                                            (  1  <<  EPS_ADCS)|                    \
                                            (  0  <<  EPS_PROP_UNIT_THRUSTER)|      \
                                            (  0  <<  EPS_PL_ZES)|                  \
                                            (  0  <<  EPS_PL_SAYARLABS)|            \
                                            (  0  <<  EPS_PL_NETRA)|                \
                                            (  0  <<  EPS_EDGE_BRD)|                \
                                            (  1  <<  EPS_OBC_PS_GPS_STD_PL_BRD)|   \
                                            (  0  <<  EPS_PL_SERVER)|               \
                                            (  0  <<  EPS_GPS)|                     \
                                            (  1  <<  EPS_HRM);
#else
    _eps_btry_ch_map->ch_map[HW_BTRY_CRTCAL]=(  0  <<  EPS_PL_TRANSCELESTIAL)|      \
                                             (  0  <<  EPS_X_BAND)|                  \
                                             (  0  <<  EPS_S_BAND)|                  \
                                             (  0  <<  EPS_PL_STS300)|              \
                                             (  0  <<  EPS_ADCS)|                    \
                                             (  0  <<  EPS_PROP_UNIT_THRUSTER)|      \
                                             (  0  <<  EPS_UHF)|                  \
                                             (  0  <<  EPS_PL_SCANWAY)|            \
                                             (  0  <<  EPS_PL_NETRA)|                \
                                             (  0  <<  EPS_EDGE_BRD)|                \
                                             (  1  <<  EPS_OBC_PS_GPS_STD_PL_BRD)|   \
                                             (  0  <<  EPS_PL_SERVER)|               \
                                             (  0  <<  EPS_GPS)|                     \
                                             (  1  <<  EPS_HRM);

    _eps_btry_ch_map->ch_map[HW_BTRY_SAFE] =(  0  <<  EPS_PL_TRANSCELESTIAL)|       \
                                            (  0  <<  EPS_X_BAND)|                  \
                                            (  1  <<  EPS_S_BAND)|                  \
                                            (  0  <<  EPS_PL_STS300)|              \
                                            (  1  <<  EPS_ADCS)|                    \
                                            (  0  <<  EPS_PROP_UNIT_THRUSTER)|      \
                                            (  1  <<  EPS_UHF)|                  \
                                            (  0  <<  EPS_PL_SCANWAY)|            \
                                            (  0  <<  EPS_PL_NETRA)|                \
                                            (  0  <<  EPS_EDGE_BRD)|                \
                                            (  1  <<  EPS_OBC_PS_GPS_STD_PL_BRD)|   \
                                            (  0  <<  EPS_PL_SERVER)|               \
                                            (  0  <<  EPS_GPS)|                     \
                                            (  1  <<  EPS_HRM);
    _eps_btry_ch_map->ch_map[HW_BTRY_NORMAL]=(  1  <<  EPS_PL_TRANSCELESTIAL)|      \
                                             (  1  <<  EPS_X_BAND)|                  \
                                             (  1  <<  EPS_S_BAND)|                  \
                                             (  1  <<  EPS_PL_STS300)|              \
                                             (  1  <<  EPS_ADCS)|                    \
                                             (  1  <<  EPS_PROP_UNIT_THRUSTER)|      \
                                             (  1  <<  EPS_UHF)|                  \
                                             (  1  <<  EPS_PL_SCANWAY)|            \
                                             (  1  <<  EPS_PL_NETRA)|                \
                                             (  1  <<  EPS_EDGE_BRD)|                \
                                             (  1  <<  EPS_OBC_PS_GPS_STD_PL_BRD)|   \
                                             (  1  <<  EPS_PL_SERVER)|               \
                                             (  1  <<  EPS_GPS)|                     \
                                             (  1  <<  EPS_HRM);

    _eps_btry_ch_map->ch_map[HW_BTRY_FULL] = (  1  <<  EPS_PL_TRANSCELESTIAL)|      \
                                             (  1  <<  EPS_X_BAND)|                  \
                                             (  1  <<  EPS_S_BAND)|                  \
                                             (  1  <<  EPS_PL_STS300)|              \
                                             (  1  <<  EPS_ADCS)|                    \
                                             (  1  <<  EPS_PROP_UNIT_THRUSTER)|      \
                                             (  1  <<  EPS_UHF)|                  \
                                             (  1  <<  EPS_PL_SCANWAY)|            \
                                             (  1  <<  EPS_PL_NETRA)|                \
                                             (  1  <<  EPS_EDGE_BRD)|                \
                                             (  1  <<  EPS_OBC_PS_GPS_STD_PL_BRD)|   \
                                             (  1  <<  EPS_PL_SERVER)|               \
                                             (  1  <<  EPS_GPS)|                     \
                                             (  1  <<  EPS_HRM);
    _eps_btry_ch_map->auto_on[HW_BTRY_CRTCAL]=(  0  <<  EPS_PL_TRANSCELESTIAL)|       \
                                              (  0  <<  EPS_X_BAND)|                  \
                                              (  0  <<  EPS_S_BAND)|                  \
                                              (  0  <<  EPS_PL_STS300)|              \
                                              (  0  <<  EPS_ADCS)|                    \
                                              (  0  <<  EPS_PROP_UNIT_THRUSTER)|      \
                                              (  0  <<  EPS_UHF)|                  \
                                              (  0  <<  EPS_PL_SCANWAY)|            \
                                              (  0  <<  EPS_PL_NETRA)|                \
                                              (  0  <<  EPS_EDGE_BRD)|                \
                                              (  0  <<  EPS_OBC_PS_GPS_STD_PL_BRD)|   \
                                              (  0  <<  EPS_PL_SERVER)|               \
                                              (  0  <<  EPS_GPS)|                     \
                                              (  0  <<  EPS_HRM);

    _eps_btry_ch_map->auto_on[HW_BTRY_SAFE] =(  0  <<  EPS_PL_TRANSCELESTIAL)|       \
                                             (  0  <<  EPS_X_BAND)|                  \
                                             (  1  <<  EPS_S_BAND)|                  \
                                             (  0  <<  EPS_PL_STS300)|              \
                                             (  1  <<  EPS_ADCS)|                    \
                                             (  0  <<  EPS_PROP_UNIT_THRUSTER)|      \
                                             (  1  <<  EPS_UHF)|                  \
                                             (  0  <<  EPS_PL_SCANWAY)|            \
                                             (  0  <<  EPS_PL_NETRA)|                \
                                             (  0  <<  EPS_EDGE_BRD)|                \
                                             (  0  <<  EPS_OBC_PS_GPS_STD_PL_BRD)|   \
                                             (  0  <<  EPS_PL_SERVER)|               \
                                             (  0  <<  EPS_GPS)|                     \
                                             (  0  <<  EPS_HRM);
    _eps_btry_ch_map->auto_on[HW_BTRY_NORMAL]=(  0  <<  EPS_PL_TRANSCELESTIAL)|       \
                                              (  0  <<  EPS_X_BAND)|                  \
                                              (  1  <<  EPS_S_BAND)|                  \
                                              (  0  <<  EPS_PL_STS300)|              \
                                              (  1  <<  EPS_ADCS)|                    \
                                              (  0  <<  EPS_PROP_UNIT_THRUSTER)|      \
                                              (  1  <<  EPS_UHF)|                  \
                                              (  0  <<  EPS_PL_SCANWAY)|            \
                                              (  0  <<  EPS_PL_NETRA)|                \
                                              (  0  <<  EPS_EDGE_BRD)|                \
                                              (  0  <<  EPS_OBC_PS_GPS_STD_PL_BRD)|   \
                                              (  0  <<  EPS_PL_SERVER)|               \
                                              (  0  <<  EPS_GPS)|                     \
                                              (  0  <<  EPS_HRM);

    _eps_btry_ch_map->auto_on[HW_BTRY_FULL] =(  0  <<  EPS_PL_TRANSCELESTIAL)|       \
                                             (  0  <<  EPS_X_BAND)|                  \
                                             (  1  <<  EPS_S_BAND)|                  \
                                             (  0  <<  EPS_PL_STS300)|              \
                                             (  1  <<  EPS_ADCS)|                    \
                                             (  0  <<  EPS_PROP_UNIT_THRUSTER)|      \
                                             (  1  <<  EPS_UHF)|                  \
                                             (  0  <<  EPS_PL_SCANWAY)|            \
                                             (  0  <<  EPS_PL_NETRA)|                \
                                             (  0  <<  EPS_EDGE_BRD)|                \
                                             (  0  <<  EPS_OBC_PS_GPS_STD_PL_BRD)|   \
                                             (  0  <<  EPS_PL_SERVER)|               \
                                             (  0  <<  EPS_GPS)|                     \
                                             (  0  <<  EPS_HRM);
#endif
}

uint8_t eps_tc(uint32_t tc_id, uint8_t** tc_data, uint16_t *tc_len);
//void eps_tm_decode(uint8_t tm_id,uint8_t *tm_frame_tm_data, uint8_t *tm_data ,uint8_t tm_len);
void eps_tm_decode(uint32_t tm_id,uint8_t *tm_frame_tm_data, uint16_t tm_len);
int8_t tc_set_conv_brd_par_enc(uint8_t* data,eps_set_conv_brd_s *eps_board);
int8_t tc_set_batt_brd_par_enc(uint8_t* data,eps_set_btry_brd_s *eps_batt);
int8_t tc_out_chnl_enb_enc(uint8_t* data,eps_set_out_chnl_enb_s *eps_chnl);
int8_t tc_out_chnl_cur_lmt_enc(uint8_t* data,eps_set_out_chnl_crnt_lmt_s *eps_cur);
int8_t tc_set_eps_mode_cfg_enc(uint8_t* data,eps_set_mode_s *eps_mode);
int8_t tc_get_var_addr_enc(uint8_t* data, tctm_eps_set_var_addr_s *eps);
int8_t tm_get_conv_brd_read_dec(uint8* data, eps_get_conv_brd_rd_s *eps_rd_board);
int8_t tm_get_conv_brd_set_dec(uint8* data,eps_get_conv_brd_stng_s *eps_stng_board);
int8_t tm_get_batt_brd_read_dec(uint8* data, eps_get_btry_brd_rd_s *eps_rd_batt);
int8_t tm_get_batt_brd_set_dec(uint8* data,eps_get_btry_brd_stng_s *eps_stng_batt);
int8_t tm_get_out_chnl_par_dec(uint8* data, eps_get_out_chnl_sts_s *eps_get_chnl_sts);
int8_t tm_get_cur_chnl_rd_dec(uint8* data, eps_get_chnl_cur_rd_s *eps_cur_chnl_rd);
int8_t tm_get_cur_chnl_stng_dec(uint8* data, eps_get_chnl_cur_stng_s *eps_cur_chnl_stng);
int8_t tm_get_eps_mode_dec(uint8* data, eps_get_stng_mode_resp_s *eps_mode);
int8_t tm_get_eps_var_info_dec(uint8* data, tctm_eps_get_var_val_s *eps_var_info);
int8_t tm_get_eps_alert_info_dec(uint8* data,eps_alert_flag_resp_s *eps_alert_info);
int8_t tm_get_eps_fw_update(uint8* data,eps_get_fw_s *eps_fw);
void eps_get_dev_hw_sts_print(uint8 val);


#endif
