/**
 * @file mfcc_tc_tm_sample.c
 *
 * @brief This file contains functions that provides demonstration of
 *        usage of TC TM Library APIs
 *
 * The functions provided in the file provides demonstration on
 * usage of TC TM library APIs
 */
/*********************************************************************/

#include <errno.h>
#include <stdbool.h>
#include "eps_tc_tm.h"
#include "mfcc_tc_tm_sample.h"
#include "tc_tm_lib_common.h"
#include <sys/stat.h>
#include "eps_tc_tm.h"

#define  EPS_BTRY_SIM_EN

#define EPS_CHNL_OFF(x,y)  (x = x&~(1<<y))
#define EPS_CHNL_ON(x,y)  (x = x|(1<<y))
#define EPS_GET_CHNL(x,y) (x&1<<y)>0?1:0;

#define SAT_DEV_MAX_CNT 14
#define EPS_RD_BFR_MAX_SIZE 18

#define FIRMWARE_AVAILABILITY_CHECK     01
#define FIRMWARE_UPDATE                 02
#define FIRMWARE_UPDATE_STATUS_CHECK    03
#define BCKUP_FIRMWARE_AVAILABILITY_CHECK  04
#define BCKUP_FIRMWARE_UPDATE           05
#define TM_BCKUP_FW_INTR_FAIL           05


uint32 set_batt_brd_par = 0;
uint32 out_chnl_enb = 0;
uint32 out_chnl_cur_lmt = 0;
uint32 set_eps_mode = 0;
uint32 chnl_1_pld_tc;
uint32 chnl_2_xband;
uint32 chnl_3_sband;
uint32 chnl_4_pld_aic;
uint32 chnl_5_adcs;
uint32 chnl_6_thrus;
uint32 chnl_7_pld_zes;
uint32 chnl_8_pld_syr;
uint32 chnl_9_pld_net;
uint32 chnl_10_edge;
uint32 chnl_11_obc_ps;
uint32 eps_btry_chnl_map = 0;

uint16 dev_no;
uint8 cnt;
uint16 eps_len;
float btr;

uint8_t eps_ch;
uint8_t eps_get_buffer[EPS_RD_BFR_MAX_SIZE];

uint16_t eps_crc_cnt_sts[2];
eps_hlth_info_s eps_hlth_resp;

eps_get_conv_brd_rd_s read_brd;
eps_get_conv_brd_stng_s set_brd;
eps_get_btry_brd_rd_s read_batt;
eps_get_btry_brd_stng_s set_batt;
eps_get_out_chnl_sts_s chnl;
eps_get_chnl_cur_rd_s cur_chnl_rd;
eps_get_chnl_cur_stng_s cur_chnl_stng;
eps_set_out_chnl_crnt_lmt_s cur;
eps_get_stng_mode_resp_s eps_mode;
eps_alert_flag_resp_s eps_alert_info;
eps_get_fw_s get_fw[2];
tctm_eps_get_var_val_s eps_var_info;

//uint8_t eps_set_conv_brd_resp[SET_CONV_BRD_RESP_LEN];
uint8_t eps_set_conv_brd_resp[SET_CONV_BRD_RESP_LEN];
uint8_t eps_set_btry_brd_resp[SET_BTRY_BRD_RESP_LEN];
uint8_t eps_set_out_ch_enb_resp[SET_OP_CHNL_RESP_LEN];
uint8_t eps_set_op_chnl_cur_lmt_rsp[OP_CHNL_CUR_RESP_LEN];
uint8_t eps_set_mode_resp[SET_EPS_MODE_RESP_LEN];
uint8_t eps_set_com_timeout[2];
eps_dev_sts_s eps_dev_sts;
sat_dev_sts_s dev_sts[14];


eps_alert_flag_tmr_s     eps_get_alert[EPS_RD_BFR_MAX_SIZE];
eps_get_btry_brd_tmr_s   eps_get_btry_brd[EPS_RD_BFR_MAX_SIZE];
eps_get_conv_brd_tmr_s   eps_get_conv_brd[EPS_RD_BFR_MAX_SIZE];
eps_get_chnl_par_tmr_s   eps_get_out_chnl[EPS_RD_BFR_MAX_SIZE];


eps_btry_thrshld sat_bat_volt;
eps_dev_tmr_c tc_eps;
//sat_crc_sts sat_crc_sts_s;
eps_btry_ch_map_s tc_btry_ch_map_on;
//eps_btry_ch_map_s tc_btry_ch_map;
//  tctm_eps_set_var_addr_s eps_get_var;



int8_t tc_set_conv_brd_par_enc(uint8_t* data,eps_set_conv_brd_s *eps_board)
{
	int8_t status;
	memcpy(data,eps_board,sizeof(eps_set_conv_brd_s));
	printf("Encoded Convertor board values to be configured are: \n");
	printf("MPPT 1 Enable status %d\n",eps_board->mppt_enb[0]);
	printf("MPPT 2 Enable status %d\n",eps_board->mppt_enb[1]);
	printf("MPPT 3 Enable status %d\n",eps_board->mppt_enb[2]);
	printf("MPPT 4 Enable status %d\n",eps_board->mppt_enb[3]);

	printf("Conv OP Channel 1 enable status %d\n",eps_board->op_conv_enb[0]);
	printf("Conv OP Channel 2 enable status %d\n",eps_board->op_conv_enb[1]);
	printf("Conv OP Channel 3 enable status %d\n",eps_board->op_conv_enb[2]);
	printf("Conv OP Channel 4 enable status %d\n",eps_board->op_conv_enb[3]);

	status = TCTM_OK;

	return status;
}

int8_t tc_set_batt_brd_par_enc(uint8_t* data,eps_set_btry_brd_s *eps_batt)
{
	int8_t status;
	memcpy(data,eps_batt,sizeof(eps_set_btry_brd_s));

	status = TCTM_OK;

	return status;
}

int8_t tc_out_chnl_enb_enc(uint8_t* data,eps_set_out_chnl_enb_s *eps_chnl)
{
	int8_t status;
	memcpy(data,eps_chnl,sizeof(eps_set_out_chnl_enb_s));

	status = TCTM_OK;

	return status;
}

int8_t tc_out_chnl_cur_lmt_enc(uint8_t* data,eps_set_out_chnl_crnt_lmt_s *eps_cur)
{
	int8_t status;
	memcpy(data,eps_cur,sizeof(eps_set_out_chnl_crnt_lmt_s));

	status = TCTM_OK;

	return status;
}

int8_t tc_set_eps_mode_cfg_enc(uint8_t* data,eps_set_mode_s *eps_mode)
{
	int8_t status;
	memcpy(data,eps_mode,sizeof(eps_set_mode_s));

	status = TCTM_OK;

	return status;
}

int8_t tc_get_var_addr_enc(uint8_t* data, tctm_eps_set_var_addr_s *eps)
{
	int8_t status;
	memcpy(data,eps,sizeof(tctm_eps_set_var_addr_s));

	status = TCTM_OK;
	return status;
}


int8_t tm_get_conv_brd_read_dec(uint8* data, eps_get_conv_brd_rd_s *eps_rd_board)
{
    int8_t status;
    int i;
    int8_t eps_sts_var;
    eps_sts_var = (int8_t)data[0];
    /* Decode data parameters */
    if(eps_sts_var == EPS_SUCCESS || eps_sts_var == EPS_CRC_FAIL || eps_sts_var == EPS_SET_PARAM_ERR)
    {
        eps_status_func(eps_sts_var);
        memcpy(eps_rd_board,&data[1],sizeof(eps_get_conv_brd_rd_s));
        if(eps_rd_board->mppt_enb_cnt == MAX_MPPT_CONV_CNT && eps_rd_board->op_conv_enb_cnt == MAX_MPPT_CONV_CNT &&eps_rd_board->pv_volt_cnt == MAX_SLR_PNL_CNT &&eps_rd_board->pv_cur_cnt == MAX_SLR_PNL_CNT &&eps_rd_board->op_conv_volt_cnt == MAX_MPPT_CONV_CNT)
        {
            printf("Received Convertor board configuration Information \n");
            printf("mppt_conv1_enb/dis value : %d\n",eps_rd_board->mppt_enb[0]);
            printf("mppt_conv2_enb/dis value : %d\n",eps_rd_board->mppt_enb[1]);
            printf("mppt_conv3_enb/dis value : %d\n",eps_rd_board->mppt_enb[2]);
            printf("mppt_conv4_enb/dis value : %d\n",eps_rd_board->mppt_enb[3]);
            printf("OP conv 1 enb/dis status : %d\n",eps_rd_board->op_conv_enb_sts[0]);
            printf("OP conv 2 enb/dis status : %d\n",eps_rd_board->op_conv_enb_sts[1]);
            printf("OP conv 3 enb/dis status : %d\n",eps_rd_board->op_conv_enb_sts[2]);
            printf("OP conv 4 enb/dis status : %d\n",eps_rd_board->op_conv_enb_sts[3]);

            for(i=0;i<MAX_SLR_PNL_CNT;i++)
            {
                printf("PV %d voltage read value : %f\n",i+1,eps_rd_board->pv_volt[i]);
                printf("PV %d current read value : %f\n",i+1,eps_rd_board->pv_cur[i]);
            }
            printf("Conv 1 OP voltage read value : %f\n",eps_rd_board->op_conv_volt[0]);
            printf("Conv 2 OP voltage read value : %f\n",eps_rd_board->op_conv_volt[1]);
            printf("Conv 3 OP voltage read value : %f\n",eps_rd_board->op_conv_volt[2]);
            printf("Conv 4 OP voltage read value : %f\n",eps_rd_board->op_conv_volt[3]);


            status = TCTM_OK;
        }
        else
        {
            printf("error\n");
            status = 1;
        }
    }
	else if(eps_sts_var == EPS_ERR || eps_sts_var == EPS_COM_FAIL || eps_sts_var == EPS_INVLD_ARG || eps_sts_var == EPS_NULL_PTR_ERR || eps_sts_var == EPS_RESP_ERR)
	{
		eps_status_func(eps_sts_var);
	}
	else
	{
		printf("Invalid Status\n");
	}

	return status;
}


int8_t tm_get_conv_brd_set_dec(uint8* data,eps_get_conv_brd_stng_s *eps_stng_board)
{
    int8_t status;
    int8_t eps_sts_var;
    eps_sts_var = (int8_t)data[0];
    /* Decode data parameters */
    if(eps_sts_var == EPS_SUCCESS || eps_sts_var == EPS_CRC_FAIL || eps_sts_var == EPS_SET_PARAM_ERR)
    {
        eps_status_func(eps_sts_var);
        memcpy(eps_stng_board,&data[1],sizeof(eps_get_conv_brd_stng_s));
        if(eps_stng_board->op_conv_volt_cnt == MAX_MPPT_CONV_CNT)
        {
            printf("Received Convertor board configuration Information \n");
            printf("conv1 op voltage set value : %f\n",eps_stng_board->op_conv_volt[0]);
            printf("conv2 op voltage set value : %f\n",eps_stng_board->op_conv_volt[1]);
            printf("conv3 op voltage set value : %f\n",eps_stng_board->op_conv_volt[2]);
            printf("conv4 op voltage set value : %f\n",eps_stng_board->op_conv_volt[3]);

            status = TCTM_OK;
        }
        else
        {
            printf("error\n");
            status = 1;
        }
    }
    else if(eps_sts_var == EPS_ERR || eps_sts_var == EPS_COM_FAIL || eps_sts_var == EPS_INVLD_ARG || eps_sts_var == EPS_NULL_PTR_ERR || eps_sts_var == EPS_RESP_ERR)
    {
        eps_status_func(data[0]);
    }
    else
    {
        printf("Invalid Status\n");
    }

    return status;
}


void eps_get_dev_hw_sts_print(uint8 val)
{
    switch(val)
    {
	case 0:
		printf("OFF\n");
		break;
	case 1:
		printf("ON\n");
		break;
	case 2:
		printf("RESTART\n");
		break;
	case 3:
		printf("BOOT\n");
		break;
	case 4:
		printf("SHUT_DOWN\n");
		break;
	case 5:
		printf("ERROR\n");
		break;
	}
}

int8_t tm_get_batt_brd_read_dec(uint8* data, eps_get_btry_brd_rd_s *eps_rd_batt)
{
	int8_t status;
	uint8_t i=0;
	int8_t eps_sts_var;
	eps_sts_var = (int8_t)data[0];
        /* Decode data parameters */
        if(eps_sts_var == EPS_SUCCESS || eps_sts_var == EPS_CRC_FAIL || eps_sts_var == EPS_SET_PARAM_ERR)
        {
            eps_status_func(eps_sts_var);
            memcpy(eps_rd_batt,&data[1],sizeof(eps_get_btry_brd_rd_s));
            printf("Received Battery board configuration Information \n");
            printf("Total battery voltage read value : %f\n",eps_rd_batt->tot_btry_volt);
            for(i=0;i<MAX_VOLT_THRSH_CNT;i++)
            {
                printf("Battery  voltage read value of %d : %f\n",i+1,eps_rd_batt->btry_volt[i]);
            }
            printf("Battery current read value :%f\n",eps_rd_batt->btry_cur);
            for(uint8_t i = 0;i<MAX_BTRY_TMP_SNSR_CNT;i++)
            {
                printf("Battery temperature read value of %d : %hhu\n",i+1,eps_rd_batt->btry_temp[i]);
            }
            printf("Battery charging/discharging flag : %hhu\n",eps_rd_batt->btry_flg);

		status=TCTM_OK;
	}
	else if(eps_sts_var == EPS_ERR || eps_sts_var == EPS_COM_FAIL || eps_sts_var == EPS_INVLD_ARG || eps_sts_var == EPS_NULL_PTR_ERR || eps_sts_var == EPS_RESP_ERR)
	{
		eps_status_func(eps_sts_var);
	}
	else
	{
		printf("Invalid Status\n");
	}
	return status;
}

int8_t tm_get_batt_brd_set_dec(uint8* data,eps_get_btry_brd_stng_s *eps_stng_batt)
{
	int8_t status;
	uint8_t i=0;
	int8_t eps_sts_var;
        eps_sts_var = (int8_t)data[0];
        /* Decode data parameters */
        if(eps_sts_var == EPS_SUCCESS || eps_sts_var == EPS_CRC_FAIL || eps_sts_var == EPS_SET_PARAM_ERR)
        {
            eps_status_func(eps_sts_var);
            memcpy(eps_stng_batt,&data[1],sizeof(eps_get_btry_brd_stng_s));
            printf("Received Battery board configuration Information \n");
            printf("Battery current charging limit : %f\n",eps_stng_batt->cur_lmt_chrg);
            printf("Battery current discharging limit : %f\n",eps_stng_batt->cur_lmt_dischrg);
            for(i=0;i<MAX_BTRY_TMP_SNSR_CNT;i++)
            {
                printf("Battery temp lower limit set of %hhu : %hhu\n",(i+1),eps_stng_batt->temp_lmt[i][0]);
                printf("Battery temp upper limit set of %hhu : %hhu\n",(i+1),eps_stng_batt->temp_lmt[i][1]);
            }
            printf("Battery heat mode : %hu\n",eps_stng_batt->heat_mode);
            printf("Battery heat mode flag : %hu\n",eps_stng_batt->heat_mode_flgs);

		status=TCTM_OK;
	}
	else if(eps_sts_var == EPS_ERR || eps_sts_var == EPS_COM_FAIL || eps_sts_var == EPS_INVLD_ARG || eps_sts_var == EPS_NULL_PTR_ERR || eps_sts_var == EPS_RESP_ERR)
	{
		eps_status_func(eps_sts_var);
	}
	else
	{
		printf("Invalid Status\n");
	}
	return status;
}


int8_t tm_get_out_chnl_par_dec(uint8* data, eps_get_out_chnl_sts_s *eps_get_chnl_sts)
{
    int8_t status;
    int8_t eps_sts_var;
    eps_sts_var = (int8_t)data[0];

    /* Decode data parameters */
    if(eps_sts_var == EPS_SUCCESS || eps_sts_var == EPS_CRC_FAIL || eps_sts_var == EPS_SET_PARAM_ERR)
    {
        eps_status_func(eps_sts_var);
        memcpy(eps_get_chnl_sts,&data[1],sizeof(eps_get_out_chnl_sts_s));
        printf("Received Output Channel configuration Information \n");
        for(uint8_t i = 0; i < 12; i++)
        {
            if(i < 8)
            {
                printf("Channel %d status:",i);
                ((eps_get_chnl_sts->chnl1_8 >> i) & 0x01 ? printf("ON\n"):printf("OFF\n"));

            }
            else
            {
                printf("Channel %d status:",i);
                ((eps_get_chnl_sts->chnl9_12 >> i%8) & 0x01 ? printf("ON\n"):printf("OFF\n"));
            }
        }
        //   printf("ch_enb1_8 value is %d\n",eps_get_chnl_sts->chnl1_8);
        //  printf("ch_enb9_12 value is %d\n",eps_get_chnl_sts->chnl9_12);
        printf("HRM release indication left : %hhu\n",eps_get_chnl_sts->hrm_rls_left);
        printf("HRM release indication right : %hhu\n",eps_get_chnl_sts->hrm_rls_right);

                status=TCTM_OK;
	}
	else if(eps_sts_var == EPS_ERR || eps_sts_var == EPS_COM_FAIL || eps_sts_var == EPS_INVLD_ARG || eps_sts_var == EPS_NULL_PTR_ERR || eps_sts_var == EPS_RESP_ERR)
	{
		eps_status_func(eps_sts_var);
	}
	else
	{
		printf("Invalid Status\n");
	}
	return status;
}

int8_t tm_get_cur_chnl_rd_dec(uint8* data, eps_get_chnl_cur_rd_s *eps_cur_chnl_rd)
{
	int8_t status;
	int8_t eps_sts_var;

	eps_sts_var = (int8_t)data[0];
	if(eps_sts_var == EPS_SUCCESS || eps_sts_var == EPS_CRC_FAIL || eps_sts_var == EPS_SET_PARAM_ERR)
	{
		eps_status_func(eps_sts_var);
		memcpy(eps_cur_chnl_rd,&data[1],sizeof(eps_get_chnl_cur_rd_s));
		if(eps_cur_chnl_rd->volt_rail_cnt == MAX_VOLT_RAIL_CNT)
		{
			for(int i = 0;i<MAX_VOLT_RAIL_CNT;i++)
			{
                             printf("Get chnl current read value of %d :%f\n",i+1,eps_cur_chnl_rd->volt_rail[i]);
			}

			/* Decode data parameters */
			status=TCTM_OK;
		}
		else
		{
			status = 1;
		}
	}
	else if(eps_sts_var == EPS_ERR || eps_sts_var == EPS_COM_FAIL || eps_sts_var == EPS_INVLD_ARG || eps_sts_var == EPS_NULL_PTR_ERR || eps_sts_var == EPS_RESP_ERR)
	{
		eps_status_func(eps_sts_var);
	}
	else
	{
		printf("Invalid Status\n");
	}
	return status;
}

int8_t tm_get_cur_chnl_stng_dec(uint8* data, eps_get_chnl_cur_stng_s *eps_cur_chnl_stng)
{
	int8_t status;
	int8_t eps_sts_var;
	eps_sts_var = (int8_t)data[0];
	if(eps_sts_var == EPS_SUCCESS || eps_sts_var == EPS_CRC_FAIL || eps_sts_var == EPS_SET_PARAM_ERR)
	{
		eps_status_func(eps_sts_var);
		memcpy(eps_cur_chnl_stng,&data[1],sizeof(eps_get_chnl_cur_stng_s));
		if(eps_cur_chnl_stng->volt_rail_cnt == MAX_VOLT_RAIL_CNT)
		{
			for(int i = 0;i<MAX_VOLT_RAIL_CNT;i++)
			{
                            printf("Get chnl current set value of %d :%f\n",i+1,eps_cur_chnl_stng->volt_rail[i]);
			}
			/* Decode data parameters */
			status=TCTM_OK;
		}
		else
		{
			status = 1;
		}
	}
	else if(eps_sts_var == EPS_ERR || eps_sts_var == EPS_COM_FAIL || eps_sts_var == EPS_INVLD_ARG || eps_sts_var == EPS_NULL_PTR_ERR || eps_sts_var == EPS_RESP_ERR)
	{
		eps_status_func(eps_sts_var);
	}
	else
	{
		printf("Invalid Status\n");
	}
	return status;
}

int8_t tm_get_eps_mode_dec(uint8* data, eps_get_stng_mode_resp_s *eps_mode)
{
	int8_t status;
	int8_t eps_sts_var;
	eps_sts_var = (int8_t)data[0];
        /* Decode data parameters */
        if(eps_sts_var == EPS_SUCCESS || eps_sts_var == EPS_CRC_FAIL || eps_sts_var == EPS_SET_PARAM_ERR)
        {
            eps_status_func(eps_sts_var);
            memcpy(eps_mode,&data[1],sizeof(eps_get_stng_mode_resp_s));
            printf("Received EPS Mode Information \n");
            printf("Normal mode threshold voltage value : %f\n",eps_mode->nrml_mode_thrld_volt);
            printf("Safe mode threshold voltage value : %f\n",eps_mode->safe_mode_thrld_volt);
            printf("Critical mode threshold voltage value : %f\n",eps_mode->crtl_mode_thrld_volt);

            status=TCTM_OK;
        }
	else if(eps_sts_var == EPS_ERR || eps_sts_var == EPS_COM_FAIL || eps_sts_var == EPS_INVLD_ARG || eps_sts_var == EPS_NULL_PTR_ERR || eps_sts_var == EPS_RESP_ERR)
	{
		eps_status_func(eps_sts_var);
	}
	else
	{
		printf("Invalid Status\n");
	}
	return status;
}
#if 0
int8_t tm_get_eps_var_info_dec(uint8* data, tctm_eps_get_var_val_s *eps_var_info)
{
	int8_t status;
	int loop;
	int8_t eps_var_sts;
	eps_var_sts = data[0];
	if(eps_var_sts == EPS_SUCCESS|| eps_var_sts == EPS_CRC_FAIL || eps_var_sts == EPS_SET_PARAM_ERR)
	{
		eps_status_func(eps_var_sts);
		memcpy(eps_var_info,&data[1],sizeof(tctm_eps_get_var_val_s));
		printf("EPS Variable value info is \n");
		for(loop = 0; loop < 8; loop++)
		{
			printf("%hhu ",eps_var_info->data[loop]);
		}
	}
	else if(eps_var_sts == EPS_ERR|| eps_var_sts == EPS_COM_FAIL|| eps_var_sts == EPS_INVLD_ARG||eps_var_sts == EPS_NULL_PTR_ERR || eps_var_sts == EPS_RESP_ERR)
	{
		eps_status_func(eps_var_sts);
	}
	else
	{
		printf("INVALID STATUS\n");
	}
	status = TCTM_OK;
	return status;
}
#endif
int8_t tm_get_eps_alert_info_dec(uint8* data,eps_alert_flag_resp_s *eps_alert_info)
{
	uint8_t status;
	int8_t eps_sts_var;

	eps_sts_var = (int8_t)data[0];
        if(eps_sts_var == EPS_SUCCESS || eps_sts_var == EPS_CRC_FAIL || eps_sts_var == EPS_SET_PARAM_ERR)
        {
            eps_status_func(eps_sts_var);
            memcpy(eps_alert_info, &data[1], sizeof(eps_alert_flag_resp_s));
            printf("Received EPS Alert information \n");
            printf("EPS Mode - %hhu\n",eps_alert_info->mode);
            printf("EPS overcurrent sts flag from channel 1 to 6 : %x\n",eps_alert_info->chnl1_5_ovr_cur_flg);
            printf("EPS overcurrent sts flag from channel 6 to 12 : %x\n",eps_alert_info->chnl6_11_ovr_cur_flg);
            printf("EPS battery charging overcurrent flag : %x\n",eps_alert_info->btry_chrg_ovrcur_flg);
            printf("EPS battery discharging overcurrent flag : %x\n",eps_alert_info->btry_dischrg_ovrcur_flg);
            printf("EPS battery voltage below 10.7v : %x\n",eps_alert_info->btry_volt_blw_10_7v);
            printf("EPS overcurrent occured channel number : %d\n",eps_alert_info->chnl_num);
            printf("EPS ovrcurrent log hour : %d\n",eps_alert_info->hour);
            printf("EPS ovrcurrent log minute : %d\n",eps_alert_info->min);
            printf("EPS ovrcurrent log sec : %d\n",eps_alert_info->sec);

            status = TCTM_OK;
        }
	else if(eps_sts_var == EPS_ERR || eps_sts_var == EPS_COM_FAIL || eps_sts_var == EPS_INVLD_ARG || eps_sts_var == EPS_NULL_PTR_ERR || eps_sts_var == EPS_RESP_ERR)
	{
		eps_status_func(eps_sts_var);
	}
	else
	{
		printf("Invalid Status\n");
	}
	return status;
}

int8_t tm_get_eps_fw_update(uint8* data,eps_get_fw_s *eps_fw)
{
	uint8_t status;
	int8_t eps_sts_var;

	eps_sts_var = (int8_t)data[0];
	if(eps_sts_var == EPS_SUCCESS || eps_sts_var == EPS_CRC_FAIL || eps_sts_var == EPS_SET_PARAM_ERR)
	{
		eps_status_func(eps_sts_var);
		memcpy(eps_fw, &data[1], sizeof(eps_get_fw_s)*2);
		printf("EPS FIRMWARE UPDATE\n");
		for(uint8_t i =0;i<2;i++)
		{
			if(i==0)
			{
				printf("EPS OUTPUT CHNL FW VERSION\n");
			}else
			{
				printf("EPS CONV BRD FW VERSION\n");
			}
			printf("EPS fw major version :%d\n",eps_fw[i].fw_mjr_vers);
			printf("EPS fw minor version :%d\n",eps_fw[i].fw_mnr_vers);
			printf("EPS fw patch version :%d\n",eps_fw[i].fw_patch_vers);
			printf("EPS communication protocol  major version :%d\n",eps_fw[i].com_prtcl_mjr_vers);
			printf("EPS communication protocol  minor version :%d\n",eps_fw[i].com_prtcl_mnr_vers);
		}
		status = TCTM_OK;
	}
	else if(eps_sts_var == EPS_ERR || eps_sts_var == EPS_COM_FAIL || eps_sts_var == EPS_INVLD_ARG || eps_sts_var == EPS_NULL_PTR_ERR || eps_sts_var == EPS_RESP_ERR)
	{
		eps_status_func(eps_sts_var);
	}
	else
	{
		printf("Invalid Status\n");
	}
	return status;
}

void eps_pwr_tmr_val(eps_dev_tmr_c *dev_id) // this will load the parameter value
{
	switch(dev_id->dev_no)
	{
	case EPS_EDGE_BRD:
	{
		eps_edge_tmr_defaults(&(dev_id)->pwr_tmr);

	}
	break;
	case EPS_ADCS:
	{
		eps_adcs_tmr_defaults(&(dev_id)->pwr_tmr);
	}
	break;
	case EPS_GPS:
	{
		eps_gps_dc_tmr_defaults(&(dev_id)->pwr_tmr);
	}
	break;
	case EPS_PL_SERVER:
	{
		eps_ps_brd_tmr_defaults(&(dev_id)->pwr_tmr);
	}
	break;
	case EPS_S_BAND:
	{
		eps_sband_tmr_defaults(&(dev_id)->pwr_tmr);
	}
	break;
	case EPS_X_BAND:
	{
		eps_xband_tmr_defaults(&(dev_id)->pwr_tmr);
	}
	break;
	case EPS_PL_TRANSCELESTIAL:
	{
		eps_pl_trans_tmr_defaults(&(dev_id)->pwr_tmr);
	}
	break;
#ifndef EPS_BRD_J2
	case EPS_PL_AICRAFT:
	{
		eps_pl_aicraft_tmr_defaults(&(dev_id)->pwr_tmr);
	}
#else
	case EPS_PL_STS300:
	{
		eps_pl_sts300_tmr_defaults(&(dev_id)->pwr_tmr);
	}
#endif
	break;
	case EPS_PL_NETRA:
	{
		eps_pl_netra_tmr_defaults(&(dev_id)->pwr_tmr);
	}
	break;
#ifndef EPS_BRD_J2
	case EPS_PL_SAYARLABS:
	{
		eps_pl_syrlbs_tmr_defaults(&(dev_id)->pwr_tmr);
	}
#else
	case EPS_PL_SCANWAY:
	{
		eps_pl_scanway_tmr_defaults(&(dev_id)->pwr_tmr);
	}
#endif
	break;
#ifndef EPS_BRD_J2
	case EPS_PL_ZES:
	{
		eps_pl_zes_tmr_defaults(&(dev_id)->pwr_tmr);
	}
#else
	case EPS_UHF:
	{
		eps_pl_uhf_tmr_defaults(&(dev_id)->pwr_tmr);
	}
#endif
	break;
	case EPS_OBC_PS_GPS_STD_PL_BRD:
	{
		eps_obc_tmr_defaults(&(dev_id)->pwr_tmr);
	}
	break;
	case EPS_PROP_UNIT_THRUSTER:
	{
		eps_thrstr_tmr_defaults(&(dev_id)->pwr_tmr);
	}
	break;
	case EPS_HRM:
	{
		eps_hrm_tmr_defaults(&(dev_id)->pwr_tmr);
	}
	break;
	case EPS_BATTERY_TMR:
	{
		eps_btry_tmr_defaults(&(dev_id)->pwr_tmr);
	}
	break;

	default :
		printf("input device error");
	}
}

void eps_ctrl_status_func(uint8_t eps_ctrl_data)
{
	switch(eps_ctrl_data)
	{
	case EPS_CTRL_SUCCESS:
		printf("EPS controller status - SUCCESS\n");
		break;
	case EPS_CTRL_COMM_ERR:
		printf("EPS controller status - COMMUNICATION FAILURE\n");
		break;
	case EPS_CTRL_PARAM_ERR:
		printf("EPS controller status - PARAMETER ERROR\n");
		break;
	case EPS_CTRL_HW_ERR:
		printf("EPS controller status - HARDWARE ERROR\n");
		break;

	case EPS_CTRL_ERR:
		printf("EPS controller status - ERROR\n");
		break;
	case EPS_CTRL_BTRY_ERR:
		printf("EPS controller status - BATTERY ERROR\n");
		break;
	case EPS_CTRL_IN_PROG:
		printf("EPS controller status - IN PROGRESS\n");
		break;

	case EPS_CTRL_CHNL_OVR_CUR_ERR:
		printf("EPS controller status - Over current error\n");

		break;
	default:
		printf("INVALID ERROR\n");
		break;
	}
}

void eps_status_func(int8_t eps_data)
{
	if(eps_data == EPS_SUCCESS)
	{
		printf("EPS status - SUCCESS\n");
	}
	else if(eps_data == EPS_CRC_FAIL)
	{
		printf("EPS status - CRC FAILURE\n");
	}
	else if(eps_data == EPS_ERR)
	{
		printf("EPS status - ERROR\n");
	}
	else if(eps_data == EPS_COM_FAIL)
	{
		printf("EPS status - COMMUNICATION FAILURE\n");
	}
	else if(eps_data == EPS_INVLD_ARG)
	{
		printf("EPS status - INVALID ARGUMENT\n");
	}
	else if(eps_data == EPS_NULL_PTR_ERR)
	{
		printf("EPS status - NULL POINTER ERROR\n");
	}
	else if(eps_data == EPS_SET_PARAM_ERR)
	{
		printf("EPS status - SET PARAMETER ERROR\n");
	}
	else if(eps_data == EPS_RESP_ERR)
	{
		printf("EPS status - RESPONSE ERROR\n");
	}
	else
	{
		printf("Invalid status\n");
	}
}


uint8_t eps_tc(uint32_t tc_id, uint8_t** tc_data, uint16_t *tc_len)
{
    uint8_t tmp_cntr=0;
    eps_set_mode_s eps_btry_mode;
    uint8_t status=0;
    eps_set_conv_brd_s eps_board;
    uint16_t len;
    eps_set_btry_brd_s eps_batt;
    eps_set_out_chnl_enb_s eps_chnl;
    eps_set_out_chnl_crnt_lmt_s eps_cur;
    eps_set_obc_com_timeout_s eps_set_obc_com_timeout;
    switch(tc_id)
    {
        case TC_SET_CONV_BOARD_PARM:
            {

                len = sizeof(eps_set_conv_brd_s);
                *tc_data = (uint8_t *) malloc(len);
                eps_board.mppt_enb_cnt = MAX_MPPT_CONV_CNT;
                eps_board.conv_op_enb_cnt = MAX_MPPT_CONV_CNT;
                eps_board.conv_op_volt_cnt = MAX_MPPT_CONV_CNT;
                eps_board.mem_set = 0;
                eps_board.mppt_enb[0] = 1;
                eps_board.mppt_enb[1] = 1;
                eps_board.mppt_enb[2] = 1;
                eps_board.mppt_enb[3] = 1;
                eps_board.op_conv_enb[0] = 1;
                eps_board.op_conv_enb[1] = 1;
                eps_board.op_conv_enb[2] = 1;
                eps_board.op_conv_enb[3] = 1;
                eps_board.op_conv_volt[0] = 12;
                eps_board.op_conv_volt[1] = 3.3;
                eps_board.op_conv_volt[2] = 5;
                eps_board.op_conv_volt[3] = 5;

               status = tc_set_conv_brd_par_enc(*tc_data, &eps_board);
            }
            break;
        case TC_SET_BATT_BOARD_PARM:
            {
                len = sizeof(eps_set_btry_brd_s);
                *tc_data = (uint8_t *) malloc(len);
                eps_batt.temp_lmt_sns_cnt = MAX_BTRY_TMP_SNSR_CNT;
                eps_batt.mem_set = 0;
                eps_batt.cur_lmt_chrg = 10;
                eps_batt.cur_lmt_dischrg = -20;
                eps_batt.temp_lmt[0][0] = 5;
                eps_batt.temp_lmt[0][1] = 7;
                eps_batt.temp_lmt[1][0] = 5;
                eps_batt.temp_lmt[1][1] = 7;
                eps_batt.temp_lmt[2][0] = 5;
                eps_batt.temp_lmt[2][1] = 7;
                eps_batt.temp_lmt[3][0] = 5;
                eps_batt.temp_lmt[3][1] = 7;
                eps_batt.temp_lmt[4][0] = 5;
                eps_batt.temp_lmt[4][1] = 7;
                eps_batt.temp_lmt[5][0] = 5;
                eps_batt.temp_lmt[5][1] = 7;
                eps_batt.temp_lmt[6][0] = 5;
                eps_batt.temp_lmt[6][1] = 7;
                eps_batt.temp_lmt[7][0] = 5;
                eps_batt.temp_lmt[7][1] = 7;
                eps_batt.heat_mode =0 ;
                eps_batt.heat_mode_flgs=0;
                status = tc_set_batt_brd_par_enc(*tc_data, &eps_batt);

            }
            break;

        case TC_SET_OUT_CHNL_ENB:
            {
                len = sizeof(eps_set_out_chnl_enb_s);
                *tc_data = (uint8_t *) malloc(len);
                uint8_t state;
                printf("Enter [0-Disable/1-Enable] states in order for %d channels \n", MAX_EPS_OUT_CH_CNT);
                eps_chnl.mem_set = 0;
                for(tmp_cntr=0;tmp_cntr < MAX_EPS_OUT_CH_CNT; tmp_cntr++)
                {
                    scanf("%hhd",&state);
                    if(state == 1)
                    {
                        if(tmp_cntr < 8)
                        {
                            EPS_CHNL_ON(eps_chnl.chnl1_8,tmp_cntr);
                        }
                        else if(tmp_cntr >= 8 || tmp_cntr <12)
                        {
                            EPS_CHNL_ON(eps_chnl.chnl9_12,tmp_cntr%8);
                        }
                    }
                    else if(state == 0)
                    {
                        if(tmp_cntr < 8)
                        {
                            EPS_CHNL_OFF(eps_chnl.chnl1_8,tmp_cntr);
                        }
                        else if(tmp_cntr >= 8 || tmp_cntr <12)
                        {
                            EPS_CHNL_OFF(eps_chnl.chnl9_12,tmp_cntr%8);
                        }
                    }
                    else
                    {
                    }
                }

                status = tc_out_chnl_enb_enc(*tc_data, &eps_chnl);
            }
            break;

        case TC_SET_OUT_CHNL_CUR_LMT:
            {
                len = sizeof(eps_set_out_chnl_crnt_lmt_s);
                *tc_data = (uint8_t *) malloc(len);
                eps_cur.chnl_cnt=MAX_VOLT_RAIL_CNT;
                eps_cur.mem_set = 0;
                eps_cur.chnl[0] = 2.5;
                eps_cur.chnl[1] = 2.5;
                eps_cur.chnl[2] = 2;
                eps_cur.chnl[3] = 1;
                eps_cur.chnl[4] = 1;
                eps_cur.chnl[5] = 1;
                eps_cur.chnl[6] = 2;
                eps_cur.chnl[7] = 4;
                eps_cur.chnl[8] = 4;
                eps_cur.chnl[9] = 3;
                eps_cur.chnl[10] = 3;
                eps_cur.chnl[11] = 3;
                eps_cur.chnl[12] = 8;
                eps_cur.chnl[13] = 4;
                eps_cur.chnl[14] = 4;
                eps_cur.chnl[15] = 2;
                status = tc_out_chnl_cur_lmt_enc(*tc_data, &eps_cur);
            }
            break;

        case TC_SET_EPS_MODE_CFG:
            {
                len = sizeof(eps_set_mode_s);
                *tc_data = (uint8_t *) malloc(len);
                eps_btry_mode.mem_set = 0;
                eps_btry_mode.nrml_mode_thrld_volt = EPS_BTRY_NORMAL_VAL;
                eps_btry_mode.safe_mode_thrld_volt = EPS_BTRY_SAFE_VAL;
                eps_btry_mode.crtl_mode_thrld_volt = EPS_BTRY_CRTCAL_VAL;
                status = tc_set_eps_mode_cfg_enc(*tc_data, &eps_btry_mode);
            }
            break;

        case TC_EPS_FW_UPDATE:
            {
                uint8_t *eps_fw_tc_data=NULL;
                uint8_t type = 0;
                uint8_t board;
                char loc_str[50];
                uint32_t file_size,checksum;
                printf("Enter your selection: \n");
                printf("1.Check firmware availability info:\n");
                printf("2.Trigger EPS firmware update\n");
                printf("3.Get firmware update result\n");
                printf("4.Get backup firmware availability info:\n");
                printf("5.Trigger EPS backup firmware update\n");
                scanf("%hhu",&type);
                printf("Select Board\n Conveter board - 1 \n Output channel Board - 2\n");
                scanf("%hhu",&board);
                if(board ==1 || board ==2)
                {

                    if(type == 1 || type == 3 || type == 4)
                    {
                        len = 10;
                        eps_fw_tc_data = (uint8_t *)malloc(len);
                        eps_fw_tc_data[0] = type;
                        eps_fw_tc_data[1] = board;
                        status = 0;
                        //do nothing
                    }
                    else if(type == 2 || type == 5)
                    {
                        len = 13;
                        eps_fw_tc_data = (uint8_t *)malloc(len);
                        eps_fw_tc_data[0] = type;
                        eps_fw_tc_data[1] = board;
                        status = 0;
                        printf("\r\nEnter input file name\r\n");
                        scanf("%s",loc_str);
                        FILE *fp = fopen(loc_str, "r");
                        if (fp == NULL)
                        {
                            printf("File %s Not Found! Enter again\n",loc_str);

                        }
                        else
                        {
                            fclose(fp);
                            file_size = file_findSize(loc_str);
                            if ((file_size != -1) && (file_size != 0))
                            {
                                checksum = file_checksum(loc_str, file_size);
                                memcpy(&eps_fw_tc_data[2],&file_size,4);
                                memcpy(&eps_fw_tc_data[6],&checksum,4);
                                printf("Size = %d\n", file_size);
                                printf("CRC = %d\n", checksum);
                            }
                            else
                            {
                                printf("NO data in the selected file\n");
                            }

                        }
			if(board == 1)
			{
				eps_fw_tc_data[10] = 1;
				eps_fw_tc_data[11] = 3;
				eps_fw_tc_data[12] = 1;
			}
			else
			{
				eps_fw_tc_data[10] = 1;
				eps_fw_tc_data[11] = 3;
				eps_fw_tc_data[12] = 3;
			}

                    }
                    else
                    {
                        status = -1;
                        printf("Invalid Selection\n");
                    }
                }
                else 
                {
                        status = -1;
                    printf("Invalid board id \n");
                }
                *tc_data=eps_fw_tc_data;
            }
            break;


#ifdef EPS_SIMU_EN
        case TC_SET_EPS_SIM_EXPOSURE_TYPE:
            {
                int i;
                eps_sim_expo_s eps_sim_expo;

                len = sizeof(eps_sim_expo_s);
                *tc_data = (uint8_t *) malloc(len);
                printf("\n0-auto mode(pre stored array value),\n 1-auto mode(new array value),\n2.Manual mode(single exp value)");
                scanf("%hhd",&eps_sim_expo.solar_mode);
                eps_sim_expo.expo_data_cnt = EXPOSURE_LUT_SIZE;
                if(eps_sim_expo.solar_mode == 1)
                {
                    printf("Enter the exposure data(10 cnt) - 0 to 100 :");
                    for(i=0;i<10;i++)
                    {
                        scanf("%hhd",&eps_sim_expo.expo_data[i]);
                    }
                }
                else if(eps_sim_expo.solar_mode == 2)
                {
                    printf("Enter the expo_persentage (0 - 100):");
                    scanf("%hhd",&eps_sim_expo.expo_data[0]);
                }
                memcpy(*tc_data,&eps_sim_expo,sizeof(eps_sim_expo_s));
            }
            break;

        case TC_SET_EPS_SIM_CH_CRNT:
            {
                eps_sim_ch_crnt_s eps_sim_ch_crnt;
                int i;

                len = sizeof(eps_sim_ch_crnt_s);
                *tc_data = (uint8_t *) malloc(len);
                printf("Set sim channel current-Auto mode (predefined values)->0,\n Change all channel power consumption(Watts)->1,\n change individual channel power cosumption(watts)->2 :");
                scanf("%hhu",&eps_sim_ch_crnt.ch_crnt_mode);
                eps_sim_ch_crnt.chnl_pwr_con_cnt=MAX_VOLT_RAIL_CNT;
                if(eps_sim_ch_crnt.ch_crnt_mode == 2)
                {
                    printf("\nEnter the channel number: ");
                    scanf("%f",&eps_sim_ch_crnt.ch_power_con[0]);
                    printf("Enter pow_con for channel %lf: ",eps_sim_ch_crnt.ch_power_con[0]);
                    scanf("%f",&eps_sim_ch_crnt.ch_power_con[1]);
                }
                else if(eps_sim_ch_crnt.ch_crnt_mode == 1)
                {
                    printf("\nEnter the channel power consumption(watts): \n");

                    for(i = 0;i<MAX_EPS_OUT_CH_CNT;i++)
                    {
                        printf("channel %d: ",i+1);
                        scanf("%f",&eps_sim_ch_crnt.ch_power_con[i]);
                    }
                }
                else
                {

                }
                memcpy(*tc_data,&eps_sim_ch_crnt,len);

            }
            break;
        case TC_SET_EPS_SIM_BTRY_VOLT:
            {
                eps_sim_btry_volt_s eps_sim_btry_volt;
                len = sizeof(eps_sim_btry_volt_s);
                *tc_data = (uint8_t *) malloc(len);
                printf("Set sim btry volt-Auto mode(predefined value)->0,Manual mode->1: ");
                scanf("%hhu",&eps_sim_btry_volt.btry_mode);
                if(eps_sim_btry_volt.btry_mode==1)
                {
                    printf("Enter the Battery voltage: ");
                    scanf("%f",&eps_sim_btry_volt.btry_volt);
                }
                else
                {
                }
                memcpy(*tc_data,&eps_sim_btry_volt,len);

            }
            break;
        case TC_SET_EPS_SIM_BTRY_TEMP:
            {
                eps_sim_btry_temp_s eps_sim_btry_temp;

                len = sizeof(eps_sim_btry_temp_s);
                *tc_data = (uint8_t *) malloc(len);
                printf("Set btry temperature-Auto mode(predefined value)->0, Manual mode(Btry temp->1, Btry_temp_range->2): ");
                scanf("%hhu",&eps_sim_btry_temp.temp_mode);
                if(eps_sim_btry_temp.temp_mode == 1)
                {
                    printf("Set all cell->1 or individual cell->2: ");
                    scanf("%hhu",&eps_sim_btry_temp.btry_temp_mode);
                    if(eps_sim_btry_temp.btry_temp_mode == 1)
                    {
                        printf("Enter Battery temperature: ");
                        scanf("%hhu",&eps_sim_btry_temp.tempr);
                    }
                    else
                    {
                        printf("Enter the cell number: ");
                        scanf("%hhu",&eps_sim_btry_temp.cell_num);
                        printf("Enter Battery temperature:");
                        scanf("%hhu",&eps_sim_btry_temp.tempr);
                    }
                }
                else if(eps_sim_btry_temp.temp_mode == 2)
                {
                    printf("set all btry->1 or Individual btry->2: ");
                    scanf("%hhu",&eps_sim_btry_temp.btry_temp_mode);
                    if(eps_sim_btry_temp.btry_temp_mode == 1)
                    {
                        printf("Enter the battery temperature range: ");
                        scanf("%hhu",&eps_sim_btry_temp.temp_lmt_lwr);
                        scanf("%hhu",&eps_sim_btry_temp.temp_lmt_up);
                    }
                    else
                    {
                        printf("Enter battery num: ");
                        scanf("%hhu",&eps_sim_btry_temp.cell_num);
                        printf("Enter the battery temperature range: ");
                        scanf("%hhu",&eps_sim_btry_temp.temp_lmt_lwr);
                        scanf("%hhu",&eps_sim_btry_temp.temp_lmt_up);
                    }

                }
                else
                {
                }
                memcpy(*tc_data,&eps_sim_btry_temp,len);

            }
            break;
#endif
        case TC_GET_CONV_BOARD_PARM:
            {
                /* pack TC payload */
                uint8_t get_data;
                printf("Choose the get data(1-read data/0-set data):\n");
                scanf("%hhu",&get_data);
                if(get_data >= 2)
                {
                    printf("Invalid input\n");
                    status = -1;
                }
                else
                {
                    len = 1;
                    *tc_data = (uint8_t *) malloc(len);
                    memcpy(*tc_data,&get_data,1);
                    status = 0;
                }
            }
            break;

        case TC_GET_BATT_BOARD_PARM:
            {
                /* pack TC payload */
                uint8_t get_data;
                printf("Choose the get data(1-read data/0-set data):\n");
                scanf("%hhu",&get_data);
                if(get_data >= 2)
                {
                    printf("Invalid input\n");
                    status = -1;
                }
                else
                {
                    len = 1;
                    *tc_data = (uint8_t *) malloc(len);
                    memcpy(*tc_data,&get_data,1);
                    status = 0;
                }
            }
            break;

        case TC_GET_OUT_CHNL_PARM:
            {
                /* pack TC payload */
                uint8_t get_data;
                printf("Choose the get data(0-get channel parameter/1-get current channel read value/2-get current channel set value):\n");
                scanf("%hhu",&get_data);
                if(get_data >= 3)
                {
                    printf("Invalid input\n");
                    status = -1;
                }
                else
                {
                    len = 1;
                    *tc_data = (uint8_t *) malloc(len);
                    memcpy(*tc_data,&get_data,1);
                    status = 0;

                }
            }
            break;

        case TC_GET_EPS_MODE_CFG:
            {
                /* pack TC payload */
                len = 0;
                *tc_data = (uint8_t *) malloc(len);
                    status = 0;

            }
            break;

        case TC_GET_EPS_ALERT_INFO:
            {
                len = 0;
                *tc_data = (uint8_t *) malloc(len);
                    status = 0;
            }break;

        case TC_GET_EPS_FW:
            {
                len = 0;
                *tc_data = (uint8_t *) malloc(len);
                    status = 0;
            }break;
#if 0
        case TC_GET_EPS_VAR_VAL:
            {
                tc_len = sizeof(tctm_eps_set_var_addr_s);
                tc_data = (uint8_t *) malloc(tc_len);
                uint32 var_addr = 0x20000198;
                eps_get_var.mem_addr_cnt=EPS_MEM_ADDR_SIZE;
                eps_get_var.slv_addr = 0;
                memcpy(eps_get_var.addr,&var_addr,sizeof(var_addr));
                memset(eps_get_var.reserved,0,5);
                tc_get_var_addr_enc(tc_data,&eps_get_var);
            }break;
#endif
        case TC_SET_EPS_CTRL_DEV_TMR:
            {
                len = sizeof(eps_dev_tmr_c);
                *tc_data= (uint8_t *)malloc(len);
                printf("Device ON/OFF timer\n");
                sat_dev_print();
                printf("14. BATTERY NORMAL/CRITICAL RUN TIMER VALUE\n");
                printf("Enter device number(0 to 13)\n");
                scanf("%hhd",&tc_eps.dev_no);
                if(tc_eps.dev_no <= MAX_SAT_DEV_CNT )
                {
                    eps_pwr_tmr_val(&tc_eps);
                    os_memcpy(*tc_data,&tc_eps,sizeof(eps_dev_tmr_c));
                    status = 0;
                }
                else{

                    printf("error device number\n");
                    status = -1;
                }
            }
            break;

#if 0
        case TC_SET_EPS_BTRY_VOLT_THRSHLD:
            {
                tc_len = sizeof(sat_bat_volt);
                tc_data= (uint8_t *)malloc(tc_len);

                printf("Enter threshold values\n");
                printf("ENTER THE VALUE FOR 0. HW_BTRY_CRTCAL/1. HW_BTRY_SAFE/2. HW_BTRY_NORMAL/3. HW_BTRY_FULL/4. TMR_VOLT_REFERNCE\n");
                scanf("%f%f%f%f%f",&sat_bat_volt.volt[0],&sat_bat_volt.volt[1],&sat_bat_volt.volt[2],&sat_bat_volt.volt[3],&sat_bat_volt.volt[4]);

                if(sat_bat_volt.volt[0] && sat_bat_volt.volt[1] && sat_bat_volt.volt[2] && sat_bat_volt.volt[3] && sat_bat_volt.volt[4] > 0)
                {
                    os_memcpy(tc_data,&sat_bat_volt,tc_len);
                }
                else
                    printf("entered invalid voltage");
                status = 0;

            }
            break;
#endif
        case TC_SET_EPS_CTRL_CHNL_ST:
            {
                len = sizeof(eps_dev_sts_s);
                *tc_data= (uint8_t *)malloc(len);

                sat_dev_print();

                printf("Enter channel number (0 to 13):");
                scanf("%hhd",&eps_dev_sts.ch_no);
                if(eps_dev_sts.ch_no < MAX_SAT_DEV_CNT)
                {
                    printf("ENTER POWER ON(1)/OFF(0)/RESTART(2):");
                    scanf("%hhd",&eps_dev_sts.ch_st);
                    if(eps_dev_sts.ch_st<3)
                    {
                        os_memcpy(*tc_data,&eps_dev_sts,len);
                        status = 0;
                    }
                    else
                    {
                        printf("\npower state error");
                        status = -1;
                    }
                }
                else
                {
                    printf("\nchannel input error");
                    status = -1;
                }
            }
            break;
        case TC_SET_EPS_BTRY_CTRL_CH_MAP:
            {
                printf("Enter EPS CHANNEL MAP\n");
                len =  sizeof(eps_btry_ch_map_s);
                *tc_data = (uint8_t *)malloc(len);

                tc_btry_ch_map_on.ch_map_cnt = MAX_CHNL_MAP_CNT;
                //tc_btry_ch_map_on.auto_on_cnt = MAX_AUTO_ON_CNT;
                eps_ctrlr_set_ch_valid_defaults(&tc_btry_ch_map_on);
                printf("tc btry stage vs channel valid:%x\n",tc_btry_ch_map_on.ch_map[0]);
                printf("tc btry stage vs channel valid:%x\n",tc_btry_ch_map_on.ch_map[1]);
                printf("tc btry stage vs channel valid:%x\n",tc_btry_ch_map_on.ch_map[2]);
                printf("tc btry stage vs channel valid:%x\n",tc_btry_ch_map_on.ch_map[3]);

                printf("tc btry stage vs channel auto on:%x\n",tc_btry_ch_map_on.auto_on[0]);
                printf("tc btry stage vs channel auto on:%x\n",tc_btry_ch_map_on.auto_on[1]);
                printf("tc btry stage vs channel auto on:%x\n",tc_btry_ch_map_on.auto_on[2]);
                printf("tc btry stage vs channel auto on:%x\n",tc_btry_ch_map_on.auto_on[3]);

                os_memcpy(*tc_data,&tc_btry_ch_map_on,len);
                status = 0;

            }
            break;
        case TC_GET_EPS_BTRY_CTRL_CH_MAP:
            {
                len = 0;
                *tc_data = (uint8*)malloc(len);
                printf("TM eps btry chnl \n");
                status = 0;
            }
            break;

        case TC_GET_EPS_DEV_HW_STS:
            {
                len = 0;
                *tc_data = (uint8*)malloc(len);
                printf("TC Hardware status \n");
                status = 0;

            }
            break;

#ifdef EPS_BTRY_SIM_EN
        case TC_EPS_SIM_BTRY_VOLT:
            {
                len = sizeof(float);
                *tc_data= (uint8_t *)malloc(len);

                printf("Enter Simulated battery volt to transmit\n");
                scanf("%f",&btr);
                if(btr > 0){
                    os_memcpy(*tc_data,&btr,len);
                }
                else
                {
                    printf("invalid battery value");
                }
                status = 0;

            }
            break;
#endif
        case TC_EPS_GET_BUFFER:
            {
                uint8_t *eps_get_buff= NULL;
                len = 1;
                eps_get_buff= (uint8*)malloc(len);

                printf("Enter the EPS read buffer choice:(0:eps_get_conv_brd_tmr/1:eps_get_btry_brd_tmr/2:eps_get_chnl_par_tmr/3:eps_alert_flag_tmr)\n");
                scanf("%hhd",&eps_get_buff[0]);
                if(eps_get_buff[0] <4)
                {
                    status = 0;
                }
                else
                {
                    status = -1;
                    printf("Invalid Input\n");
                
                }
                *tc_data = eps_get_buff;
            }
            break;

        case TC_EPS_HEALTH_STS:
            {
                len = 0;
                *tc_data = (uint8*)malloc(len);
                status = 0;
            }
            break;

        case TC_EPS_GET_CRC:
            {
                len = 1;
                *tc_data = (uint8 *)malloc(len);
                status = 0;

            }
            break;
        case TC_ALERT_FLAG_OVR_CUR_ERR_HANDLE:
            {
                uint8_t data;
                uint8_t *eps_alert_data=NULL;
                printf("Enter the choice(0- get the chnl ovr cur err status/1- overwrite the chnl ovr cur err status/2 - Set the chnl eligiblity status : ");
                scanf("%hhu",&data);
                if(data== 0)
                {
                    len = 1;
                    eps_alert_data = (uint8 *)malloc(len);
                    memcpy(eps_alert_data,&data,len);
                    status = 0;
                    *tc_data=eps_alert_data;
                }
                else if(data == 1)
                {
                    uint8_t choice;
                    printf("0 - Clear all channel /1 - specific channel : ");
                    scanf("%hhu",&choice);
                    len = 3;
                    eps_alert_data = (uint8 *)malloc(len);
                    memcpy(eps_alert_data+1,&choice,len-2);
                    memcpy(eps_alert_data,&data,len-2);
                    if(choice == 1)
                    {
                        uint8_t chnl;
                        printf("Enter the channel number to clear the ovr cur set bit (0 - 12) : ");
                        scanf("%hhu",&chnl);
                        memcpy(eps_alert_data+2,&chnl,len-2);
                    }
                    status = 0;
                    *tc_data=eps_alert_data;

                }
                else if(data == 2)
                {
                    len =  3;
                    eps_alert_data = (uint8_t *)malloc(len);
                    memcpy(eps_alert_data,&data,1);
                    uint16_t eps_set_chnl_eligibility;
                    eps_chnl_eligible_to_restart(&eps_set_chnl_eligibility);
                    memcpy(eps_alert_data+1,&eps_set_chnl_eligibility,len-1);
                    status = 0;
                    *tc_data=eps_alert_data;

                }
                else
                {
                    *tc_data=eps_alert_data;
                    printf("Invalid input\n");
                    status = -1;
                }
            }
            break;

        case TC_EPS_MCU_RST :
            {
                uint8_t *eps_mcu_rst=NULL;
                len = 1;
                eps_mcu_rst = (uint8*)malloc(len);
                printf("Select the MCU to reset(7- Convertor board/ 8- output channel board board/ 9- Emergency reset convertor board/ 10- Emergency reset output channel board(Must not use this emergency reset option in actual running satellite): ");
                scanf("%hhu",&eps_mcu_rst[0]);
                *tc_data=eps_mcu_rst;
                status = 0;
            }
            break;

        case TC_SET_EPS_COM_TIMEOUT:
            {
                len = sizeof(eps_set_obc_com_timeout_s);
                *tc_data = (uint8_t*)malloc(len);
                eps_set_obc_com_timeout.obc_com_timeout_sec = 60;
                eps_set_obc_com_timeout.num_of_obc_rst_for_eps_rst = 3;
                memcpy(*tc_data,&eps_set_obc_com_timeout,len);
                status=0;
            }
            break;

        case TC_GET_EPS_COM_TIMEOUT:
            {
                len = 0;
                *tc_data = (uint8_t*)malloc(len);
                status = 0;
            }
            break;
        default :
            {
                status = -1;
                printf("Invalid TC ID Received - %d. Please try again. \n",tc_id);
            }
    }
    *tc_len = len;
    return status;

}


void eps_tm_decode(uint32_t tm_id,uint8_t *tm_frame_tm_data,uint16_t tm_len)
{
    uint8_t sts =0;
    uint8_t loop=0;
    uint8_t eps_sts_var=0;
    switch(tm_id)
    {
        case TM_SET_EPS_CTRL_DEV_TMR:
            {
                os_memcpy(&sts,tm_frame_tm_data,tm_len);
                eps_ctrl_status_func(sts);
                printf("Received : %d\n",sts);
            }
            break;
#if 0

        case TM_SET_EPS_BTRY_VOLT_THRSHLD:
            {
                printf("tm decode\n");
                os_memcpy(&sts,tm_data,tm_len);
                printf("Received : %d\n",sts);
            }
            break;
#endif

        case TM_SET_EPS_CTRL_CHNL_ST:
            {
                printf("tm decode\n");
                os_memcpy(&sts,tm_frame_tm_data,tm_len);
                eps_ctrl_status_func(sts);
                printf("Received : %d\n",sts);

            }
            break;
        case TM_SET_EPS_BTRY_CTRL_CH_MAP:
            {
                printf("tm decode\n");
                os_memcpy(&sts,tm_frame_tm_data,tm_len);
                eps_ctrl_status_func(sts);
                printf("Received : %d\n",sts);

                break;
            }
        case TM_GET_EPS_BTRY_CTRL_CH_MAP:
            {
                os_memcpy(&sts,tm_frame_tm_data,1);
                eps_ctrl_status_func(sts);
                os_memcpy(&tc_btry_ch_map_on,&tm_frame_tm_data[1],sizeof(eps_btry_ch_map_s));

                printf("tc btry stage vs channel valid:%x\n",tc_btry_ch_map_on.ch_map[0]);
                printf("tc btry stage vs channel valid:%x\n",tc_btry_ch_map_on.ch_map[1]);
                printf("tc btry stage vs channel valid:%x\n",tc_btry_ch_map_on.ch_map[2]);
                printf("tc btry stage vs channel valid:%x\n",tc_btry_ch_map_on.ch_map[3]);

                printf("tc btry stage vs channel auto on:%x\n",tc_btry_ch_map_on.auto_on[0]);
                printf("tc btry stage vs channel auto on:%x\n",tc_btry_ch_map_on.auto_on[1]);
                printf("tc btry stage vs channel auto on:%x\n",tc_btry_ch_map_on.auto_on[2]);
                printf("tc btry stage vs channel auto on:%x\n",tc_btry_ch_map_on.auto_on[3]);


            }
            break;
        case TM_GET_EPS_DEV_HW_STS:
            {
                os_memcpy(&sts,&tm_frame_tm_data[0],1);
                if(sts)
                {
                    printf("EPS STATUS - SUCCESS\n");
                }
                else
                {
                    printf("INVALID STATUS\n");
                }
                os_memcpy((uint8 *)dev_sts,&tm_frame_tm_data[1],sizeof(sat_dev_sts_s) * SAT_DEV_MAX_CNT);
                printf("PL_TRANSCELESTIAL :");
                eps_get_dev_hw_sts_print(dev_sts[0].hw_sts);
                printf("S_BAND :");
                eps_get_dev_hw_sts_print(dev_sts[1].hw_sts);
                printf("X_BAND :");
                eps_get_dev_hw_sts_print(dev_sts[2].hw_sts);
#ifndef EPS_BRD_J2
                printf("ADCS0 :");
#else
                printf("HW_PL_STS300 :");
#endif
                eps_get_dev_hw_sts_print(dev_sts[3].hw_sts);
                printf("ADCS :");
                eps_get_dev_hw_sts_print(dev_sts[4].hw_sts);
                printf("PROP_UNIT_THRUSTER :");
                eps_get_dev_hw_sts_print(dev_sts[5].hw_sts);
#ifndef EPS_BRD_J2
                printf("PL_ZES :");
#else
                printf("HW_UHF :");
#endif
                eps_get_dev_hw_sts_print(dev_sts[6].hw_sts);
#ifndef EPS_BRD_J2
                printf("PL_SAYARLABS :");
#else
                printf("HW_PL_SCANWAY :");
#endif
                eps_get_dev_hw_sts_print(dev_sts[7].hw_sts);
                printf("PL_NETRA :");
                eps_get_dev_hw_sts_print(dev_sts[8].hw_sts);
                printf("EDGE_BRD :");
                eps_get_dev_hw_sts_print(dev_sts[9].hw_sts);
                printf("OBC_PS_GPS_STD_PL_BRD :");
                eps_get_dev_hw_sts_print(dev_sts[10].hw_sts);
                printf("HRM :");
                eps_get_dev_hw_sts_print(dev_sts[11].hw_sts);
                printf("PL_SERVER :");
                eps_get_dev_hw_sts_print(dev_sts[12].hw_sts);
                printf("GPS:");
                eps_get_dev_hw_sts_print(dev_sts[13].hw_sts);

            }
            break;

#ifdef EPS_BTRY_SIM_EN
        case TM_EPS_SIM_BTRY_VOLT:
            {
                printf("tm decode\n");
                os_memcpy(&sts,tm_frame_tm_data,tm_len);
                printf("Received : %d\n",sts);
            }
            break;
#endif

        case TM_ALERT_FLAG_OVR_CUR_ERR_HANDLE:
            {
                if(tm_frame_tm_data[0] == 0)
                {
                    uint16_t chnl_ovr_cur_err;
                    memcpy(&chnl_ovr_cur_err,tm_frame_tm_data+1,2);
                    printf("The channel ovr cur error : %d\n",chnl_ovr_cur_err);
                }
                else if(tm_frame_tm_data[0] == 1)
                {
                    if(tm_frame_tm_data[1] == 0)
                    {
                        if(tm_frame_tm_data[2] == 1)
                            printf("The ovr cur err value for all channel is set successfully\n");
                    }
                    else
                    {
                        if(tm_frame_tm_data[2] == 1)
                            printf("The ovr cur err value for specific channel is set successfully\n");
                    }

                }
                else
                {
                    if(tm_frame_tm_data[1] == 1)
                        printf("The chnl eligibility is set successfully\n");
                }
            }
            break;
        case TM_SET_CONV_BOARD_PARM:
            {
                memcpy(&eps_sts_var,&tm_frame_tm_data[0],1);
                memcpy(&eps_set_conv_brd_resp[0],&tm_frame_tm_data[1],SET_CONV_BRD_RESP_LEN);
                if(eps_sts_var == EPS_SUCCESS || eps_sts_var == EPS_CRC_FAIL || eps_sts_var == EPS_SET_PARAM_ERR)
                {
                    eps_status_func(eps_sts_var);
                    for(loop = 0; loop < SET_CONV_BRD_RESP_LEN; loop++)
                    {
                        printf("%hhu ",eps_set_conv_brd_resp[loop]);
                    }
                    printf("\n");
                }
                else if(eps_sts_var == EPS_ERR || eps_sts_var == EPS_COM_FAIL || eps_sts_var == EPS_INVLD_ARG || eps_sts_var == EPS_NULL_PTR_ERR || eps_sts_var == EPS_RESP_ERR)
                {
                    eps_status_func(eps_sts_var);
                }
                else
                {
                    printf("Invalid status\n");
                }

            }
            break;
        case TM_SET_BATT_BOARD_PARM:
            {
                memcpy(&eps_sts_var,&tm_frame_tm_data[0],1);
                memcpy(&eps_set_btry_brd_resp[0],&tm_frame_tm_data[1],SET_BTRY_BRD_RESP_LEN);
                if(eps_sts_var== EPS_SUCCESS || eps_sts_var == EPS_CRC_FAIL || eps_sts_var == EPS_SET_PARAM_ERR)
                {
                    eps_status_func(eps_sts_var);
                    for(loop = 0; loop < SET_BTRY_BRD_RESP_LEN; loop++)
                    {
                        printf("%d ",eps_set_btry_brd_resp[loop]);
                    }
                    printf("\n");
                }
                else if(eps_sts_var == EPS_ERR || eps_sts_var == EPS_COM_FAIL || eps_sts_var == EPS_INVLD_ARG || eps_sts_var == EPS_NULL_PTR_ERR || eps_sts_var == EPS_RESP_ERR)
                {
                    eps_status_func(eps_sts_var);
                }
                else
                {
                    printf("Invalid status\n");
                }

            }
            break;

        case TM_SET_OUT_CHNL_ENB:
            {
                memcpy(&eps_sts_var,&tm_frame_tm_data[0],1);
                memcpy(&eps_set_out_ch_enb_resp[0],&tm_frame_tm_data[1],SET_OP_CHNL_RESP_LEN);
                if(eps_sts_var == EPS_SUCCESS || eps_sts_var == EPS_CRC_FAIL || eps_sts_var == EPS_SET_PARAM_ERR)
                {
                    eps_status_func(eps_sts_var);
                    for(loop = 0; loop < SET_OP_CHNL_RESP_LEN; loop++)
                    {
                        printf("%hhu ",eps_set_out_ch_enb_resp[loop]);
                    }
                    printf("\n");
                }
                else if(eps_sts_var == EPS_ERR || eps_sts_var == EPS_COM_FAIL || eps_sts_var == EPS_INVLD_ARG || eps_sts_var == EPS_NULL_PTR_ERR || eps_sts_var == EPS_RESP_ERR)
                {
                    eps_status_func(eps_sts_var);
                }
                else
                {
                    printf("Invalid status\n");
                }

            }
            break;

        case TM_SET_OUT_CHNL_CUR_LMT:
            {
                memcpy(&eps_sts_var,&tm_frame_tm_data[0],1);
                memcpy(&eps_set_op_chnl_cur_lmt_rsp[0],&tm_frame_tm_data[1],OP_CHNL_CUR_RESP_LEN);
                if(eps_sts_var == EPS_SUCCESS || eps_sts_var == EPS_CRC_FAIL || eps_sts_var == EPS_SET_PARAM_ERR)
                {
                    eps_status_func(eps_sts_var);
                    for(loop = 0; loop < OP_CHNL_CUR_RESP_LEN; loop++)
                    {
                        printf("%hhu ",eps_set_op_chnl_cur_lmt_rsp[loop]);
                    }
                    printf("\n");
                }
                else if(eps_sts_var == EPS_ERR || eps_sts_var == EPS_COM_FAIL || eps_sts_var == EPS_INVLD_ARG || eps_sts_var == EPS_NULL_PTR_ERR || eps_sts_var == EPS_RESP_ERR)
                {
                    eps_status_func(eps_sts_var);
                }
                else
                {
                    printf("Invalid status\n");
                }
            }
            break;

        case TM_SET_EPS_MODE_CFG:
            {
                memcpy(&eps_sts_var,&tm_frame_tm_data[0],1);
                memcpy(&eps_set_mode_resp[0],&tm_frame_tm_data[1],SET_EPS_MODE_RESP_LEN);
                if(eps_sts_var == EPS_SUCCESS || eps_sts_var == EPS_CRC_FAIL || eps_sts_var == EPS_SET_PARAM_ERR)
                {
                    eps_status_func(eps_sts_var);
                    for(loop = 0; loop < SET_EPS_MODE_RESP_LEN; loop++)
                    {
                        printf("%hhu ",eps_set_mode_resp[loop]);
                    }
                    printf("\n");
                }
                else if(eps_sts_var == EPS_ERR || eps_sts_var == EPS_COM_FAIL || eps_sts_var == EPS_INVLD_ARG || eps_sts_var == EPS_NULL_PTR_ERR || eps_sts_var == EPS_RESP_ERR)
                {
                    eps_status_func(eps_sts_var);
                }
                else
                {
                    printf("Invalid status\n");
                }
            }
            break;
        case TM_GET_CONV_BOARD_PARM:
            {
                if(tm_frame_tm_data[0] == 1)
                {
                    tm_get_conv_brd_read_dec(&tm_frame_tm_data[1], &read_brd);
                }
                else if(tm_frame_tm_data[0] == 0)
                {
                    tm_get_conv_brd_set_dec(&tm_frame_tm_data[1], &set_brd);
                }
                else
                {
                    printf("Invalid id\n");
                }
            }
            break;
        case TM_GET_BATT_BOARD_PARM:
            {
                if(tm_frame_tm_data[0] == 1)
                {
                    tm_get_batt_brd_read_dec(&tm_frame_tm_data[1], &read_batt);

                }
                else if(tm_frame_tm_data[0] == 0)
                {
                    tm_get_batt_brd_set_dec(&tm_frame_tm_data[1], &set_batt);
                }
                else
                {
                    printf("Invalid id\n");
                }
            }
            break;
        case TM_GET_OUT_CHNL_PARM:
            {
                if(tm_frame_tm_data[0] == 0)
                {
                    tm_get_out_chnl_par_dec(&tm_frame_tm_data[1], &chnl);
                }
                else if(tm_frame_tm_data[0] == 1)
                {
                    tm_get_cur_chnl_rd_dec(&tm_frame_tm_data[1],&cur_chnl_rd);
                }
                else if(tm_frame_tm_data[0] == 2)
                {
                    tm_get_cur_chnl_stng_dec(&tm_frame_tm_data[1],&cur_chnl_stng);
                }
                else
                {
                    printf("Invalid id\n");
                }
            }
            break;
        case TM_GET_EPS_MODE_CFG:
            {
                tm_get_eps_mode_dec(tm_frame_tm_data, &eps_mode);
            }
            break;

        case TM_GET_EPS_ALERT_INFO:
            {
                tm_get_eps_alert_info_dec(tm_frame_tm_data, &eps_alert_info);
            }break;
        case TM_GET_EPS_FW:
            {
                tm_get_eps_fw_update(tm_frame_tm_data, get_fw);
            }
            break;
        case TM_EPS_FW_UPDATE:
            {
                eps_fw_data_s fw_info;
                if (tm_frame_tm_data[0] == FIRMWARE_AVAILABILITY_CHECK)
                {
                    if(tm_frame_tm_data[1] == 1)
                    {
                        memcpy(&fw_info,&tm_frame_tm_data[2],9);
                        printf("Convertor Board Firmware status\n");
                    }
                    else
                    {
                        memcpy(&fw_info,&tm_frame_tm_data[2],9);
                        printf("Output channel Board Firmware status\n");
                    }
                    if(fw_info.fw_status == 1)
                    {

                        printf("Firmware available to update\n");
                        printf("Firmware size = %d\n",fw_info.fw_size);
                        printf("Firmware crc = %x\n",fw_info.fw_crc);
                    }
                    else
                    {
                        printf("Firmware not available\n");
                    }
                }

                else if(tm_frame_tm_data[0] == FIRMWARE_UPDATE || tm_frame_tm_data[0] == BCKUP_FIRMWARE_UPDATE)
                {
                    if(tm_frame_tm_data[1] == 1 && tm_frame_tm_data[0] == FIRMWARE_UPDATE )
                    {
                        printf("Convertor Board Firmware Update Status:\n");
                    }
                    else if(tm_frame_tm_data[1] == 1 && tm_frame_tm_data[0] == BCKUP_FIRMWARE_UPDATE)
                    {
                        printf("Convertor Board Backup Firmware Update Status:\n");
                    }
                    else if(tm_frame_tm_data[1] == 2 && tm_frame_tm_data[0] == FIRMWARE_UPDATE)
                    {

                        printf("Output channel Board Firmware Update Status:\n");
                    }
                    else if(tm_frame_tm_data[1] == 2 && tm_frame_tm_data[0] == BCKUP_FIRMWARE_UPDATE)
                    {
                        printf("Output channel Board backup Firmware Update Status:\n");
                    }
                    else
                    {
                        printf("invalid id\n");
                    }
		    if(tm_frame_tm_data[0] == 1)
		    {
			if(tm_frame_tm_data[1] == 0)
		            printf("EPS MCU1 FW SIZE OR CRC FAIL");
		    }
		    else if(tm_frame_tm_data[0] == 2)
		    {
			if(tm_frame_tm_data[1] == 1)
       			    printf("EPS MCU2 FW SIZE OR CRC FAIL");
		    }
		    else
		    {

		    }

                    if(tm_frame_tm_data[2] == 0)
                    {
                        printf("Firmware update success\n");
                        printf("Trial one:%d\n",tm_frame_tm_data[4]);
                        printf("Trial two:%d\n",tm_frame_tm_data[5]);
                        printf("Trial three:%d\n",tm_frame_tm_data[6]);
                        if(tm_frame_tm_data[4]!= 0xff && tm_frame_tm_data[5]!=0xff && tm_frame_tm_data[6]==0xff)
                        {
                            printf("Firmware update passed at 3rd attempt\n");
                        }
                        else if(tm_frame_tm_data[4]!=0xff && tm_frame_tm_data[5]==0xff)
                        {
                            printf("Firmware update passed at 2nd attempt\n");
                        }
                        else if(tm_frame_tm_data[4]==0xff && tm_frame_tm_data[5]==0xff && tm_frame_tm_data[6]==0xff)
                        {
                            printf("Firmware update passed at 1st attempt\n");
                        }
                        else
                        {
                        }

                    }
                    else if(tm_frame_tm_data[2] == 1)
                    {
                        printf("Firmware update failure\n");
                        printf("ERROR CODE: %d",tm_frame_tm_data[3]);
                        switch(tm_frame_tm_data[3])
                        {
                            case 1:
                                printf("Boot command rejected\n");
                                break;
                            case 2:
                                printf("Received NACK for command frame\n");
                                break;
                            case 3:
                                printf("Received NACK for data frame\n");
                                break;
                            case 6:
                                printf("Received NACK for write command\n");
                                break;
                            case 7:
                                printf("Data transmit fail\n");
                                break;
                            case 8:
                                printf("Received NACK for address frame\n");
                                break;
                            case 9:
                                printf("Address transmit fail\n");
                                break;
                            case 10:
                                printf("Read data fail\n");
                                break;
                            case 11:
                                printf("Received NACK for Read\n");
                                break;
                            case 12:
                                printf("BOOT startup fail\n");
                                break;
                            case 13:
                                printf("Recieved NACK for sector count\n");
                                break;
                            case 14:
                                printf("Received sector count fail\n");
                                break;
                            case 15:
                                printf("Received NACK for sector id \n");
                                break;
                            case 16:
                                printf("Received sector id fail\n");
                                break;
                            case 20:
                                printf("Read and write mismatch\n");
                                break;
                            case 21:
                                printf("Invalid ACK for sector count\n");
                                break;
                            case 23:
                                printf("Invalid ACK for sector id\n");
                                break;
                            case 24:
                                printf("Invalid ACK for write\n");
                                break;
                            case 25:
                                printf("Invalid ACK for read\n");
                                break;
                        }


                    }
                    else if(tm_frame_tm_data[2] == 2)
                    {
                        printf("Downloaded firmware integrity check failed\n");
                    }
                    else if(tm_frame_tm_data[2] == 3)
                    {
                        printf("Size or CRC mismatch\n");
                    }
                    else if(tm_frame_tm_data[2] == 4)
                    {
                        printf("No firmware available\n");
                    }
                    else if(tm_frame_tm_data[2] == 5)
                    {
                        printf("Backup Firmware integrity fail\n");
                    }
                    else
                    {
                        //do nothing
                    }
                }

                else if(tm_frame_tm_data[0] == FIRMWARE_UPDATE_STATUS_CHECK)
                {

                    if(tm_frame_tm_data[1] == 1)
                    {
                        printf("Convertor Board Firmware Update Status:\n");
                    }
                    else
                    {
                        printf("Output channel Board Firmware Update Status:\n");
                    }

                    if(tm_frame_tm_data[2] == 0)
                    {
                        printf("No Firmware Available\n");
                    }
                    else if(tm_frame_tm_data[2] == 1)
                    {
                        printf("Firmware Available to update\n");
                    }
                    else if(tm_frame_tm_data[2] == 2)
                    {
                        printf("Firmware update pass\n");
                    }
                    else if(tm_frame_tm_data[2] == 3)
                    {
                        printf("Firmware update Fail\n");
                    }
                    else
                    {
                    }

                }
                else if (tm_frame_tm_data[0] == BCKUP_FIRMWARE_AVAILABILITY_CHECK)
                {
                    if(tm_frame_tm_data[1] == 1)
                    {
                        memcpy(&fw_info,&tm_frame_tm_data[2],9);
                        printf("Convertor Board Firmware status\n");
                    }
                    else
                    {
                        memcpy(&fw_info,&tm_frame_tm_data[2],9);
                        printf("Output channel Board Firmware status\n");
                    }
                    if(fw_info.fw_status == 1)
                    {

                        printf("Firmware available to update\n");
                        printf("Firmware size = %d\n",fw_info.fw_size);
                        printf("Firmware crc = %x\n",fw_info.fw_crc);
                    }
                    else
                    {
                        printf("Firmware not available\n");
                    }
                }

                else {
                    printf("invalid input");
                }

            }
            break;

        case	TM_EPS_MCU_RST :
            {
                if(tm_frame_tm_data[0] == 1)
                {
                    printf("MCU 2 reset success\n");
                }
                else
                {
                    printf("MCU 2 reset success\n");
                }
            }break;
            case TM_SET_EPS_COM_TIMEOUT:
                    {
                        memcpy(&eps_sts_var,tm_frame_tm_data,1);
                        memcpy(&eps_set_com_timeout[0],&tm_frame_tm_data[1],2);
                        if(eps_sts_var == EPS_SUCCESS || eps_sts_var == EPS_CRC_FAIL || eps_sts_var == EPS_SET_PARAM_ERR)
                        {
                            eps_status_func(eps_sts_var);
                        for(loop = 0; loop < 2 ; loop++)
                        {
                            printf("%hhu ",eps_set_com_timeout[loop]);
                        }
                        printf("\n");
                        }
                        else if(eps_sts_var == EPS_ERR || eps_sts_var == EPS_COM_FAIL || eps_sts_var == EPS_INVLD_ARG || eps_sts_var == EPS_NULL_PTR_ERR || eps_sts_var == EPS_RESP_ERR)
                        {
                            eps_status_func(eps_sts_var);
                        }
                        else
                        {
                            printf("Invalid status\n");
                        }

                    }
                    break;

        case TM_GET_EPS_COM_TIMEOUT :
            {
                eps_get_obc_com_timeout_s eps_get_obc_com_timeout;
                int8_t eps_sts_var;
                memcpy(&eps_sts_var,&tm_frame_tm_data[0],1);
                /* Decode data parameters */
                if(eps_sts_var == EPS_SUCCESS || eps_sts_var == EPS_CRC_FAIL || eps_sts_var == EPS_SET_PARAM_ERR)
                {
                    eps_status_func(eps_sts_var);
                    memcpy(&eps_get_obc_com_timeout,&tm_frame_tm_data[1],sizeof(eps_get_obc_com_timeout_s));
                    printf("OBC com timeout in sec limit byte 1:%x\n",eps_get_obc_com_timeout.obc_com_timeout_sec_byte1);
                    printf("OBC com timeout in sec limit byte 2:%x\n",eps_get_obc_com_timeout.obc_com_timeout_sec_byte2);
                    printf("Number of OBC reset for EPS reset:%d\n",eps_get_obc_com_timeout.num_of_obc_rst_for_eps_rst);
                }
                else if(eps_sts_var == EPS_ERR || eps_sts_var == EPS_COM_FAIL || eps_sts_var == EPS_INVLD_ARG || eps_sts_var == EPS_NULL_PTR_ERR || eps_sts_var == EPS_RESP_ERR)
                {
                    eps_status_func(eps_sts_var);
                }
                else
                {
                    printf("Invalid Status\n");
                }
            }
            break;


#ifdef EPS_SIMU_EN
        case TM_SET_EPS_SIM_EXPOSURE_TYPE:
            {
                memcpy(&eps_sts_var,&tm_frame_tm_data[0],1);
                eps_status_func(eps_sts_var);
            }
            break;

        case TM_SET_EPS_SIM_CH_CRNT:
            {
                memcpy(&eps_sts_var,tm_frame_tm_data,1);
                eps_status_func(eps_sts_var);
            }
            break;
        case TM_SET_EPS_SIM_BTRY_VOLT:
            {
                memcpy(&eps_sts_var,&tm_frame_tm_data[0],1);
                eps_status_func(eps_sts_var);
            }
            break;
        case TM_SET_EPS_SIM_BTRY_TEMP:
            {
                memcpy(&eps_sts_var,&tm_frame_tm_data[0],1);
                eps_status_func(eps_sts_var);
            }
            break;
#endif
#if 0
        case TM_GET_EPS_VAR_VAL:
            {
                tm_get_eps_var_info_dec(tm_data, &eps_var_info);
            }break;
#endif

        case TM_EPS_GET_BUFFER:
            {
                uint8_t i,eps_sts;
                os_memcpy(&eps_sts,&tm_frame_tm_data[0],1);
                if(eps_sts == 1)
                {
                    printf("EPS STATUS - SUCCESS\n");
                    os_memcpy(&sts,&tm_frame_tm_data[1],1);
                    switch(sts)
                    {
                        case EPS_GS_GET_CONV_BRD_BUFF:
                            {
                                os_memcpy(&eps_get_conv_brd,tm_frame_tm_data+2,tm_len-2);
                                printf("EPS get conv brd\n");
                                for(i =0; i < EPS_RD_BFR_MAX_SIZE; i++)
                                {
                                    printf("Buffer count :%hhu\t\n",eps_get_conv_brd[i].buff_cnt);
                                    printf("RTC time :%lu\t\n",eps_get_conv_brd[i].time);
                                    printf("output convertor voltage cnt \t:%d\n",eps_get_conv_brd[i].op_conv_volt_cnt);
                                    printf("pannel voltage count \t:%d\n",eps_get_conv_brd[i].pv_volt_cnt);
                                    printf("pannel current count \t:%d\n",eps_get_conv_brd[i].pv_cur_cnt);
                                    printf("pv_volt_1 \t:%f\n",eps_get_conv_brd[i].pv_volt[0]);
                                    printf("pv_volt_2 \t:%f\n",eps_get_conv_brd[i].pv_volt[1]);
                                    printf("pv_volt_3 \t:%f\n",eps_get_conv_brd[i].pv_volt[2]);
                                    printf("pv_volt_4 \t:%f\n",eps_get_conv_brd[i].pv_volt[3]);
                                    printf("pv_cur_1  \t:%f\n",eps_get_conv_brd[i].pv_cur[0]);
                                    printf("pv_cur_2  \t:%f\n",eps_get_conv_brd[i].pv_cur[1]);
                                    printf("pv_cur_3  \t:%f\n",eps_get_conv_brd[i].pv_cur[2]);
                                    printf("pv_cur_4  \t:%f\n",eps_get_conv_brd[i].pv_cur[3]);
                                    printf("op_volt_conv_1 \t:%f\n",eps_get_conv_brd[i].op_volt_conv_read[0]);
                                    printf("op_volt_conv_2 \t:%f\n",eps_get_conv_brd[i].op_volt_conv_read[1]);
                                    printf("op_volt_conv_3 \t:%f\n",eps_get_conv_brd[i].op_volt_conv_read[2]);
                                    printf("op_volt_conv_4 \t:%f\n",eps_get_conv_brd[i].op_volt_conv_read[3]);

                                }

                            }

                            break;

                        case EPS_GS_GET_BTRY_BRD_BUFF:
                            {
                                os_memcpy(&eps_get_btry_brd,tm_frame_tm_data+2,tm_len-2);
                                printf("EPS get battery brd \n");
                                for(i =0; i < EPS_RD_BFR_MAX_SIZE; i++)
                                {
                                    printf("Buffer count :%hhu\t\n",eps_get_btry_brd[i].buff_cnt);
                                    printf("RTC time :%lu\t\n",eps_get_btry_brd[i].time);
                                    printf("battery temperature count \t:%d\n",eps_get_btry_brd[i].btry_temp_cnt);
                                    printf("battery voltage count \t:%d\n",eps_get_btry_brd[i].btry_volt_cnt);
                                    printf("tot_vol     \t:%f\n",eps_get_btry_brd[i].totl_vol);
                                    printf("batt_volt_1 \t:%f\n",eps_get_btry_brd[i].vol_ch[0]);
                                    printf("batt_volt_2 \t:%f\n",eps_get_btry_brd[i].vol_ch[1]);
                                    printf("batt_volt_3 \t:%f\n",eps_get_btry_brd[i].vol_ch[2]);
                                    printf("batt_total_current\t:%f\n",eps_get_btry_brd[i].totl_crnt);
                                    printf("temp_1      \t:%d\n",eps_get_btry_brd[i].tempr[0]);
                                    printf("temp_2      \t:%d\n",eps_get_btry_brd[i].tempr[1]);
                                    printf("temp_3      \t:%d\n",eps_get_btry_brd[i].tempr[2]);
                                    printf("temp_4      \t:%d\n",eps_get_btry_brd[i].tempr[3]);
                                    printf("temp_5      \t:%d\n",eps_get_btry_brd[i].tempr[4]);
                                    printf("temp_6      \t:%d\n",eps_get_btry_brd[i].tempr[5]);
                                    printf("temp_7      \t:%d\n",eps_get_btry_brd[i].tempr[6]);
                                    printf("temp_8      \t:%d\n",eps_get_btry_brd[i].tempr[7]);
                                    printf("Battery charging/discharging status : ");
                                    if(eps_get_btry_brd[i].btry_chrg_sts == 0xFF)
                                        printf("ERROR\n");
                                    else if(eps_get_btry_brd[i].btry_chrg_sts == 1)
                                        printf("CHARGE\n");
                                    else if(eps_get_btry_brd[i].btry_chrg_sts == 0)
                                        printf("DISCHARGE\n");
                                    else
                                        printf("INVALID VALUE\n");

                                }
                            }
                            break;

                        case EPS_GS_GET_CHNL_PARM_BUFF:
                            {
                                os_memcpy(&eps_get_out_chnl,tm_frame_tm_data+2,tm_len-2);
                                printf("EPS get OUTPUT_CNANNEL_PARAM\n");
                                for(i =0; i < EPS_RD_BFR_MAX_SIZE; i++)
                                {
                                    printf("Buffer count :%hhu\t\n",eps_get_out_chnl[i].buff_cnt);
                                    printf("RTC time \t:%lu \n",eps_get_out_chnl[i].time);
                                    printf("output voltage rail count \t:%d\n",eps_get_out_chnl[i].volt_rail_cnt);
                                    printf("chnl_1 tot_volt_12v  \t:%f\n",eps_get_out_chnl[i].rd_crnt_val[0]);
                                    printf("chnl_2 tot_volt_12v  \t:%f\n",eps_get_out_chnl[i].rd_crnt_val[1]);
                                    printf("chnl_3 tot_volt_5v    \t:%f\n",eps_get_out_chnl[i].rd_crnt_val[2]);
                                    printf("chnl_4 tot_volt_5v   \t:%f\n",eps_get_out_chnl[i].rd_crnt_val[3]);
                                    printf("chnl_5 tot_volt_5v    \t:%f\nn",eps_get_out_chnl[i].rd_crnt_val[4]);
                                    printf("chnl_5 tot_volt_3.3v  \t:%f\n",eps_get_out_chnl[i].rd_crnt_val[5]);
                                    printf("chnl_5 tot_volt_BATTV \t:%f\n",eps_get_out_chnl[i].rd_crnt_val[6]);
                                    printf("chnl_6 tot_volt_12v   \t:%f\n",eps_get_out_chnl[i].rd_crnt_val[7]);
                                    printf("chnl_6 tot_volt_3.3v  \t:%f\n",eps_get_out_chnl[i].rd_crnt_val[8]);
                                    printf("chnl_7 tot_volt_5v   \t:%f\n",eps_get_out_chnl[i].rd_crnt_val[9]);
                                    printf("chnl_7 tot_volt_BATTv    \t:%f\n",eps_get_out_chnl[i].rd_crnt_val[10]);
                                    printf("chnl_8 tot_volt_12v  \t:%f\n",eps_get_out_chnl[i].rd_crnt_val[11]);
                                    printf("chnl_9 tot_volt_5V\t:%f\n",eps_get_out_chnl[i].rd_crnt_val[12]);
                                    printf("chnl_10 tot_volt_BATTV\t:%f\n",eps_get_out_chnl[i].rd_crnt_val[13]);
                                    printf("chnl_11 tot_volt_BATTV\t:%f\n",eps_get_out_chnl[i].rd_crnt_val[14]);
                                    printf("chnl_12 tot_volt_BATTV\t:%f\n",eps_get_out_chnl[i].rd_crnt_val[15]);

                                }
                            }break;

                        case EPS_GS_GET_ALRT_BRD_BUFF:
                            {
                                os_memcpy(&eps_get_alert,tm_frame_tm_data+2,tm_len-2);
                                uint32_t tmp_val = 0;

                                printf("EPS get ALERT FLAG \n");
                                for(i =0; i < EPS_RD_BFR_MAX_SIZE; i++)
                                {
                                    printf("Buffer count :%hhu\t\n",eps_get_alert[i].buff_cnt);
                                    printf("RTC time \t:%lu \n",eps_get_alert[i].time);
                                    tmp_val = eps_get_alert[i].value;

                                    printf("mode \t:%d\n",tmp_val & 0x07);

                                    if(tmp_val & 0x08)
                                    {
                                        printf("chnl_1_12v ovf : 1\n");
                                    }
                                    else
                                    {
                                        printf("chnl_1_12v ovf : 0\n");
                                    }

                                    if(tmp_val & 0x10)
                                    {
                                        printf("chnl_2_12v ovf : 1\n");
                                    }
                                    else
                                    {
                                        printf("chnl_2_12v ovf : 0\n");
                                    }
                                    if(tmp_val & 0x20)
                                    {
                                        printf("chnl_3_5v ovf : 1\n");
                                    }
                                    else
                                    {
                                        printf("chnl_3_5v ovf : 0\n");
                                    }

                                    if(tmp_val & 0x40)
                                    {
                                        printf("chnl_4_5v ovf : 1\n");
                                    }
                                    else
                                    {
                                        printf("chnl_4_5v ovf : 0\n");
                                    }


                                    if(tmp_val & 0x80)
                                    {
                                        printf("chnl_5_5v ovf : 1\n");
                                    }
                                    else
                                    {
                                        printf("chnl_5_5v ovf : 0\n");
                                    }
                                    if(tmp_val & 0x0100)
                                    {
                                        printf("chnl_5_3.3v ovf : 1\n");
                                    }
                                    else
                                    {
                                        printf("chnl_5_3.3v ovf : 0\n");
                                    }

                                    if(tmp_val & 0x0200)
                                    {
                                        printf("chnl_5_battv ovf : 1\n");
                                    }
                                    else
                                    {
                                        printf("chnl_5_battv ovf : 0\n");
                                    }

                                    if(tmp_val & 0x0400)
                                    {
                                        printf("chnl_6_12v ovf : 1\n");
                                    }
                                    else
                                    {
                                        printf("chn_6_l12v ovf : 0\n");
                                    }
                                    if(tmp_val & 0x0800)
                                    {
                                        printf("chnl_6_3.3v ovf : 1\n");
                                    }
                                    else
                                    {
                                        printf("chnl_6_3.3v ovf : 0\n");
                                    }

                                    if(tmp_val & 0x1000)
                                    {
                                        printf("chnl_7_5v ovf : 1\n");
                                    }
                                    else
                                    {
                                        printf("chnl_7_5v ovf : 0\n");
                                    }

                                    if(tmp_val & 0x2000)
                                    {
                                        printf("chnl_7_BATTv ovf : 1\n");
                                    }
                                    else
                                    {
                                        printf("chnl_7_BATTv ovf : 0\n");
                                    }
                                    if(tmp_val & 0x4000)
                                    {
                                        printf("chnl_8_12v ovf : 1\n");
                                    }
                                    else
                                    {
                                        printf("chnl_8_12v ovf : 0\n");
                                    }

                                    if(tmp_val & 0x8000 )
                                    {
                                        printf("chnl_9_5v ovf : 1\n");
                                    }
                                    else
                                    {
                                        printf("chnl_9_5v ovf : 0\n");
                                    }

                                    if(tmp_val & 0x010000 )
                                    {
                                        printf("chnl_10_battv ovf : 1\n");
                                    }
                                    else
                                    {
                                        printf("chnl_10_battv ovf : 0\n");
                                    }
                                    if(tmp_val & 0x020000)
                                    {
                                        printf("chnl_11_battv ovf : 1\n");
                                    }
                                    else
                                    {
                                        printf("chnl_11_battv ovf : 0\n");
                                    }

                                    if(tmp_val & 0x040000)
                                    {
                                        printf("chnl_12_battv ovf : 1\n");
                                    }
                                    else
                                    {
                                        printf("chnl_12_battv ovf : 0\n");
                                    }

                                    if(tmp_val & 0x080000)
                                    {
                                        printf("battery charging ovf flag: 1\n");
                                    }
                                    else
                                    {
                                        printf("battery charging ovf flag: 0\n");
                                    }
                                    if(tmp_val & 0x100000)
                                    {
                                        printf("battery discharging ovfflag : 1\n");
                                    }
                                    else
                                    {
                                        printf("battey discharging ovf flag : 0\n");
                                    }
                                    if(tmp_val & 0x200000)
                                    {
                                        printf("battery voltage below 10.7v : 1\n");
                                    }
                                    else
                                    {
                                        printf("battey voltage below 10.7v : 0\n");
                                    }
                                    printf("overcurrent Channel number:%d\n",((tmp_val >> 22) &0xf));
                                    printf("overcurrent log hour:%d\n",eps_get_alert[i].hour);
                                    printf("overcurrent log min:%d\n",eps_get_alert[i].min);
                                    printf("overcurrent log sec:%d\n",eps_get_alert[i].sec);

                                }
                            } break;

                        default:
                            printf("invalid id\n");
                            break;

                    }
                }
                else
                {
                    printf("INVALID STATUS\n");
                }
            }
            break;

        case TM_EPS_HEALTH_STS:
            {
                os_memcpy(&sts,&tm_frame_tm_data[0],1);
                if(sts)
                {
                    printf("EPS STATUS - SUCCESS\n");
                }
                else
                {
                    printf("INVALID STATUS\n");
                }
                os_memcpy(&eps_hlth_resp,&tm_frame_tm_data[2],tm_len-2);
                printf("EPS HEALTH STATUS\n");
                printf("Dev hrd sts\n");
                printf("PL_TRANSCELESTIAL   :");
                (eps_hlth_resp.dev_hw_sts & 0x01 ? printf("ON\n"):printf("OFF\n"));
                printf("X_BAND             :");
                (eps_hlth_resp.dev_hw_sts & 0x02 ? printf("ON\n"):printf("OFF\n"));
                printf("S_BAND             :");
                (eps_hlth_resp.dev_hw_sts& 0x04 ? printf("ON\n"):printf("OFF\n"));
#ifndef EPS_BRD_J2
                printf("ADCS0              :");
#else
                printf("HW_PL_STS300       :");
#endif
                (eps_hlth_resp.dev_hw_sts & 0x08 ? printf("ON\n"):printf("OFF\n"));
                printf("ADCS               :");
                (eps_hlth_resp.dev_hw_sts & 0x10 ? printf("ON\n"):printf("OFF\n"));
                printf("PROP_UNIT_THRUSTER :");
                (eps_hlth_resp.dev_hw_sts & 0x20 ? printf("ON\n"):printf("OFF\n"));
#ifndef EPS_BRD_J2
                printf("PL_ZES             :");
#else
                printf("HW_UHF             :");
#endif
                (eps_hlth_resp.dev_hw_sts & 0x40 ? printf("ON\n"):printf("OFF\n"));
#ifndef EPS_BRD_J2
                printf("PL_SAYARLABS       :");
#else
                printf("HW_PL_SCANWAY       :");
#endif
                (eps_hlth_resp.dev_hw_sts & 0x80 ? printf("ON\n"):printf("OFF\n"));
                printf("PL_NETRA           :");
                (eps_hlth_resp.dev_hw_sts & 0x0100 ? printf("ON\n"):printf("OFF\n"));
                printf("EDGE_BRD           :");
                (eps_hlth_resp.dev_hw_sts & 0x0200 ? printf("ON\n"):printf("OFF\n"));
                printf("OBC_PS_GPS_STD_PL_BRD :");
                (eps_hlth_resp.dev_hw_sts & 0x0400 ? printf("ON\n"):printf("OFF\n"));
                printf("HRM                :");
                (eps_hlth_resp.dev_hw_sts & 0x0800 ? printf("ON\n"):printf("OFF\n"));
                printf("PL_SERVER          :");
                (eps_hlth_resp.dev_hw_sts & 0x1000 ? printf("ON\n"):printf("OFF\n"));
                printf("GPS                :");
                (eps_hlth_resp.dev_hw_sts & 0x2000 ? printf("ON\n"):printf("OFF\n"));
                printf("HRM_open_sts      :%d\n",eps_hlth_resp.dev_hw_sts & 0xC000 >> 14);

                printf("Alert value\n");
                printf("Mode            : %d\n", eps_hlth_resp. alrt_value & 0x07);
                printf("chnl_1_12v     :");
                (eps_hlth_resp. alrt_value & 0x08 ? printf("1\n"):printf("0\n"));
                printf("chnl_2_12v     :");
                (eps_hlth_resp. alrt_value & 0x10 ? printf("1\n"):printf("0\n"));
                printf("chnl_3_5v      :");
                (eps_hlth_resp. alrt_value & 0x20 ? printf("1\n"):printf("0\n"));
                printf("chnl_4_5v     :");
                (eps_hlth_resp. alrt_value & 0x40 ? printf("1\n"):printf("0\n"));
                printf("chnl_5_5v      :");
                (eps_hlth_resp. alrt_value & 0x80 ? printf("1\n"):printf("0\n"));
                printf("chnl_5_3.3v    :");
                (eps_hlth_resp. alrt_value & 0x0100 ? printf("1\n"):printf("0\n"));
                printf("chnl_5_Battv   :");
                (eps_hlth_resp. alrt_value & 0x0200 ? printf("1\n"):printf("0\n"));
                printf("chnl_6_12v     :");
                (eps_hlth_resp. alrt_value & 0x0400 ? printf("1\n"):printf("0\n"));
                printf("chnl_6_3.3v    :");
                (eps_hlth_resp. alrt_value & 0x0800 ? printf("1\n"):printf("0\n"));
                printf("chnl_7_5v    :");
                (eps_hlth_resp. alrt_value & 0x1000 ? printf("1\n"):printf("0\n"));
                printf("chnl_7_BATTv      :");
                (eps_hlth_resp. alrt_value & 0x2000 ? printf("1\n"):printf("0\n"));
                printf("chnl_8_12v    :");
                (eps_hlth_resp. alrt_value & 0x4000 ? printf("1\n"):printf("0\n"));
                printf("chnl_9_5v      :");
                (eps_hlth_resp. alrt_value & 0x8000 ? printf("1\n"):printf("0\n"));
                printf("chnl_10_Battv  :");
                (eps_hlth_resp. alrt_value & 0x010000 ? printf("1\n"):printf("0\n"));
                printf("chnl_11_Battv  :");
                (eps_hlth_resp. alrt_value & 0x020000 ? printf("1\n"):printf("0\n"));
                printf("chnl_12_Battv  :");
                (eps_hlth_resp. alrt_value & 0x040000 ? printf("1\n"):printf("0\n"));
                printf("Batt chrge     :");
                (eps_hlth_resp. alrt_value & 0x080000 ? printf("1\n"):printf("0\n"));
                printf("Batt dischrge  :");
                (eps_hlth_resp. alrt_value & 0x100000 ? printf("1\n"):printf("0\n"));
                printf("Batt voltage below 10.7v  :");
                (eps_hlth_resp. alrt_value & 0x200000 ? printf("1\n"):printf("0\n"));
                printf("ovr cur occured channel number:%d \n",((eps_hlth_resp.alrt_value >> 22)&0xf));

                printf("com fail cnt   :%d\n",eps_hlth_resp.com_fail_cnt);
                printf("crc fail cnt   :%d\n",eps_hlth_resp.crc_fail_cnt);
                printf("Buffer count :%hhu\t\n",eps_hlth_resp.btry_params.buff_cnt);
                printf("RTC time : %lu\t\n",eps_hlth_resp.btry_params.time);
                printf("tot_vol     \t:%f\n",eps_hlth_resp.btry_params.totl_vol);
                printf("batt_volt_1 \t:%f\n",eps_hlth_resp.btry_params.vol_ch[0]);
                printf("batt_volt_2 \t:%f\n",eps_hlth_resp.btry_params.vol_ch[1]);
                printf("batt_volt_3 \t:%f\n",eps_hlth_resp.btry_params.vol_ch[2]);
                printf("batt_total_current\t:%f\n",eps_hlth_resp.btry_params.totl_crnt);
                printf("temp_1      \t:%d\n",eps_hlth_resp.btry_params.tempr[0]);
                printf("temp_2      \t:%d\n",eps_hlth_resp.btry_params.tempr[1]);
                printf("temp_3      \t:%d\n",eps_hlth_resp.btry_params.tempr[2]);
                printf("temp_4      \t:%d\n",eps_hlth_resp.btry_params.tempr[3]);
                printf("temp_5      \t:%d\n",eps_hlth_resp.btry_params.tempr[4]);
                printf("temp_6      \t:%d\n",eps_hlth_resp.btry_params.tempr[5]);
                printf("temp_7      \t:%d\n",eps_hlth_resp.btry_params.tempr[6]);
                printf("temp_8      \t:%d\n",eps_hlth_resp.btry_params.tempr[7]);
                printf("Battery charging/discharging status : ");
                if(eps_hlth_resp.btry_params.btry_chrg_sts == 0xFF)
                    printf("ERROR\n");
                else if(eps_hlth_resp.btry_params.btry_chrg_sts == 1)
                    printf("CHARGE\n");
                else if(eps_hlth_resp.btry_params.btry_chrg_sts == 0)
                    printf("DISCHARGE\n");
                printf("Buffer count :%hhu\t\n",eps_hlth_resp.conv_params.buff_cnt);
                printf("RTC time :%lu \t\n",eps_hlth_resp.conv_params.time);
                printf("pv_volt_1 \t:%f\n",eps_hlth_resp.conv_params.pv_volt[0]);
                printf("pv_volt_2 \t:%f\n",eps_hlth_resp.conv_params.pv_volt[1]);
                printf("pv_volt_3 \t:%f\n",eps_hlth_resp.conv_params.pv_volt[2]);
                printf("pv_volt_4 \t:%f\n",eps_hlth_resp.conv_params.pv_volt[3]);
                printf("pv_cur_1  \t:%f\n",eps_hlth_resp.conv_params.pv_cur[0]);
                printf("pv_cur_2  \t:%f\n",eps_hlth_resp.conv_params.pv_cur[1]);
                printf("pv_cur_3  \t:%f\n",eps_hlth_resp.conv_params.pv_cur[2]);
                printf("pv_cur_4  \t:%f\n",eps_hlth_resp.conv_params.pv_cur[3]);
                printf("op_volt_conv_1 \t:%f\n",eps_hlth_resp.conv_params.op_volt_conv_read[0]);
                printf("op_volt_conv_2 \t:%f\n",eps_hlth_resp.conv_params.op_volt_conv_read[1]);
                printf("op_volt_conv_3 \t:%f\n",eps_hlth_resp.conv_params.op_volt_conv_read[2]);
                printf("op_volt_conv_4 \t:%f\n",eps_hlth_resp.conv_params.op_volt_conv_read[3]);
            }
            break;

        case TM_EPS_GET_CRC:// need to be removed
            {
                uint8 i;
                os_memcpy(&sts,&tm_frame_tm_data[0],1);
                if(sts)
                {
                    printf("EPS STATUS - SUCCESS\n");
                }
                else
                {
                    printf("INVALID STATUS\n");
                }
                os_memcpy(eps_crc_cnt_sts,&tm_frame_tm_data[1],sizeof(eps_crc_cnt_sts));
                for(i = 0;i<2;i++)
                {
                    printf("Counter value : %d\n",eps_crc_cnt_sts[i]);
                }

            }
            break;
        default:
            break;

    }

}
