#include "obc_tc_tm.h"
#include "obc_main.h"
#include "obc_main_fsm_hdlr.h"
#include "obc_icd.h"
#include "obc_intf_ctrl_msg.h"
#include "eps.h"
//#include "eps_config.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <time.h>
#include "file_transfer.h"
#include "exo_common.h"
#include "eps_ctrlr.h"
#include "otsu_tctm_msg_def.h"
#ifndef LINUX_TEMP_PORT
#include "log_thread.h"
#endif
#include "nvm.h"
#include "exo_osal_mem_cpy.h"
#include "obc_ipc.h"

#include "exo_osal_mem_debug.h"
#include "schedular.h"
#include "file_transfer.h"
#include "sensor_driver_intf.h"
#include "ds620_interface.h"
#include "adm1176_interface.h"
#include "ina230_interface.h"
#include "mcp9843_intf.h"
#include "ucd9081_interface.h"
#include "logger.h"
#include "eps_btlr_driver.h"
#include "exo_types.h"
#include "exo_io_al_sos_timer.h"
#include "exo_osal_mem_management.h"
#include "schedular.h"
#include "exo_tctm_ipc.h"
#include "obc_mcu_info.h"
#include "version.h"
#include "obc_mem_info.h"
#include "otsu_ftm.h"
#include "notify_apps.h"
#include "system_init_exit.h"
#include "adcs_vapi_common.h"
#include "thruster_tc_tm.h"
#include "mux.h"
#include "exo_ahw_al_data_logger_common.h"
#include "obc_bringup_test.h"

#define MEM_DATA_LEN 100
#define _XOPEN_SOURCE
#define IPCC_TRIG_SUCCESS     0
//#define EPS_RD_BFR_MAX_SIZE 5
uint32_t sns_ahw_id;

uint32_t rbt_time;

volatile uint8_t security_sts;
volatile uint8_t authentication_sts;
volatile uint8_t def_radio_id;

extern uint8_t sub_mod_sts[OBC_SUB_MOD_MAX];
extern uint8_t icd_socket_conn_sts;
extern exo_sw_dbg_cb exo_sw_dbg;
#if 0
extern uint16 obc_evnt_trig;
#endif
#ifndef LINUX_TEMP_PORT
extern uint32_t mcu_uptime;
#endif

/** declared as driver files were not compiled in linux */
typedef struct _eps_get_btry_board_par
{
    uint8_t btry_temp_sns_cnt ;
    uint8_t volt_chnl_cnt;
    uint8_t temp_cnt;
        float   crnt_lmt_chrg;
        float   crnt_lmt_dischrg;
        uint8_t temp_lmt[MAX_BTRY_TMP_SNSR_CNT][UPP_LWR_TEMP_THSH_LMT];
        float   totl_vol;
        float   vol_ch[MAX_BTRY_CNT_PER_SET];
        float   totl_crnt;
        uint8_t tempr[MAX_BTRY_TMP_SNSR_CNT];
        uint8_t reserved[RSVD_7];
}__attribute__((__packed__))eps_get_btry_brd_s;

extern eps_get_btry_brd_rd_s get_btry_brd_rd;
extern eps_get_btry_brd_stng_s get_btry_brd_st;

#if 0
//extern eps_get_conv_brd_rd_s get_conv_brd_rd;
//extern eps_get_conv_brd_stng_s get_conv_brd_st;
extern eps_get_out_chnl_sts_s get_out_chnl_params;
extern eps_get_chnl_cur_rd_s get_cur_chnl_rd;
extern eps_get_chnl_cur_stng_s get_cur_chnl_st;
extern eps_get_stng_mode_resp_s get_mode_params;
extern eps_alert_flag_resp_s get_alert_info;
#endif

#if 0
extern eps_get_btry_brd_s eps_get_btry_params;
extern eps_get_conv_brd_s get_conv_brd;
extern eps_get_chnl_par_s  eps_get_out_chnl_params;
extern eps_get_mode_s eps_mode_params;
extern eps_alert_flag_s eps_alert_info;
#endif
extern uint32 obc_staged_tc_id;
extern uint16 lut_cfg_rsp;
extern uint8 sch_ctrl_rsp;
extern uint8_t obc_test_sns_rsp;
extern uint8_t obc_test_gpio_exp_rsp;
extern uint8_t obc_nvm_commit_rsp;
extern uint8_t obc_nvm_commit_prdcty_tim_rsp;
extern uint8_t obc_test_gpio_rsp;
extern uint32 seg_exec_info_rsp;
extern uint32 seg_rcv_info_rsp;
extern obc_memcpy_memory_layout look_up_table[MAX_MEM];         ///< Maximum memcpy size
extern void log_ftm_notificataion_api_upld(ft_notification_info *ft_sts);
uint32_t sw_rst_typ=0;
uint32 sch_lut_cfg_sts = 0;
uint32 cur_time_rsp_sts=0;

temp_sens_cfg temp_sns_cfg;
digital_thermostat_cfg dgtl_thrmst_cfg;
hotswap_cntlr_cfg htswp_cntlr_cfg;
power_sense_mntr_cfg pwr_sns_mtr_cfg;
voltage_seq_mntr_cfg vltg_seq_mntr_cfg;
gpio_exp_cfg gpx_exp_cfg;

thruster_info thrstr_inf;
thruster_param thrstr_para;
data_acq_dvc_info  data_acq_inf;
data_acq_dvc_param data_acq_para;
imu_info imu_inf;
imu_param imu_para;
uint8_t tm_buff_ctrl_flag = 0;

//eps_btry_ch_map_s data1;
sat_dev_sts_s dev_sts[14];

nvm_param *nvm_data_hdr;
uint8_t *nvm_data_pld;

//uint8_t eps_get_buf[EPS_RD_BFR_MAX_SIZE];
//uint8_t *eps_get_buf;
//uint32 eps_get_buff_len;

tctm_spi_init_s spii;
tctm_ethernet_init_s eth;
tctm_can_init_s cis;
tctm_i2c_init_s i2ci;
tctm_usb_otg_cfg_s usbo;
tctm_uart_init_s uarti;
uint32 tm_rsp_id;

uint32 trgt_pt_config_rsp_sts = 0;
uint32 spi_intf_param_rsp_sts = 0;
uint32 eth_intf_param_rsp_sts = 0;
uint32 can_intf_param_rsp_sts = 0;
uint32 i2c_intf_param_rsp_sts = 0;
uint32 usb_intf_param_rsp_sts = 0;
uint32 uart_intf_param_rsp_sts = 0;
uint32 set_rbt_time_sts =0;
uint32 temp_sen_set_parm_sts =0;
uint32 imu_set_parm_sts = 0;
uint32 thruster_ctrl_set_parm_sts =0;
uint32 gpio_exp_set_parm_sts = 0;
uint32 dgtl_therm_set_parm_sts = 0;
uint32 pwr_mon_set_parm_sts = 0;
uint32 volt_ctrl_mon_set_parm_sts = 0;
uint32 pwr_seq_mon_set_parm_sts = 0;
uint32 data_log_set_parm_sts = 0;
uint16 ipcc_test_dec = 0;
uint8 ipcc_test_sts = 0;
uint8 obc_mem_debug_data = 0;
uint8 obc_mem_debug_sts = 0;
uint8 eps_sts = 0;
extern uint8_t obc_test_spi_uart_conv_rsp;
//eps_btry_thrshld sat_bat_volt;
float btr;

uint8 ssd_slec_typ;
uint8 ssd_slec_dec;
uint32  ssd_slec_sts = 0;
uint8 obc_ssd_heat_slec_dec[2];
uint8 obc_ssd_board_slec_dec;
uint32 ssd_heat_slec_sts = 0;
ext_mem_test_tc_tm_s mem_test_sts;
char *tty_drdu = "Sample TTY debug response data uint";
extern ft_tctm_payload_tx ft_pld_tx;
extern icm_pld_hw_pwr_off_info_s phw_poi;
extern icm_vm_pwr_off_info_s poi;


extern uint16 ps_vm_id ;
#if 0
extern uint8_t eps_set_conv_brd_resp[SET_CONV_BRD_RESP_LEN];
extern uint8_t eps_set_btry_brd_resp[SET_BTRY_BRD_RESP_LEN];
extern uint8_t eps_set_out_ch_enb_resp[SET_OP_CHNL_RESP_LEN];
extern uint8_t eps_set_op_chnl_cur_lmt_rsp[SET_OP_CHNL_CUR_LMT];
extern uint8_t eps_set_mode_resp[SET_EPS_MODE_RESP_LEN];
#endif

//eps_get_var_data_s eps_var_val_resp;

s_otsu_tctm_info otsu_tm_pld;
extern strFTM_queue_tctm_info s_ftm_queue_tm_frame;
eps_dev_tmr_c dec_var;

extern psm_data_s psm_ps_data_buffer[SENSOR_MAX_BUFF_SIZE];
extern psm_data_s psm_obc_data_buffer[SENSOR_MAX_BUFF_SIZE];
extern dt_data_s dt_ps_data_buffer[SENSOR_MAX_BUFF_SIZE];
extern dt_data_s dt_edge_data_buffer[SENSOR_MAX_BUFF_SIZE];
extern hsc_data_s hsc_edge_data_buffer[SENSOR_MAX_BUFF_SIZE];
extern hsc_data_s hsc_ps_1_data_buffer[SENSOR_MAX_BUFF_SIZE];
extern hsc_data_s hsc_ps_2_data_buffer[SENSOR_MAX_BUFF_SIZE];
extern temp_data_s temp_obc_data_buffer[SENSOR_MAX_BUFF_SIZE];
extern temp_data_s temp_ps_data_buffer[SENSOR_MAX_BUFF_SIZE];
extern temp_data_s temp_edge_data_buffer[SENSOR_MAX_BUFF_SIZE];
extern vsm_data_s vsm_obc_data_buffer[SENSOR_MAX_BUFF_SIZE];
extern temp_data_s temp_gps_data_buffer[SENSOR_MAX_BUFF_SIZE];

extern dt_data_s temp_spe01_data_buffer[SENSOR_MAX_BUFF_SIZE];
extern dt_data_s temp_spe02_data_buffer[SENSOR_MAX_BUFF_SIZE];
extern dt_data_s temp_spb01_data_buffer[SENSOR_MAX_BUFF_SIZE];
extern dt_data_s temp_spw01_data_buffer[SENSOR_MAX_BUFF_SIZE];
extern dt_data_s temp_spw02_data_buffer[SENSOR_MAX_BUFF_SIZE];

/***** GEN2 *****/
extern temp_data_s temp_edge1_gen2_data_buffer[SENSOR_MAX_BUFF_SIZE];
extern temp_data_s temp_edge2_gen2_data_buffer[SENSOR_MAX_BUFF_SIZE];
extern temp_data_s temp_ps_gen2_data_buffer[SENSOR_MAX_BUFF_SIZE];
extern temp_data_s temp_nic1_data_buffer[SENSOR_MAX_BUFF_SIZE];
extern temp_data_s temp_ssd1_data_buffer[SENSOR_MAX_BUFF_SIZE];
extern temp_data_s temp_ssd2_data_buffer[SENSOR_MAX_BUFF_SIZE];
extern temp_data_s temp_ssd3_data_buffer[SENSOR_MAX_BUFF_SIZE];
extern temp_data_s temp_ssd3_data_buffer[SENSOR_MAX_BUFF_SIZE];

extern hsc_data_s hsc_ps_brd_supply_data_buffer[SENSOR_MAX_BUFF_SIZE];
extern hsc_data_s hsc_ps1_sup_data_buffer[SENSOR_MAX_BUFF_SIZE];
extern hsc_data_s hsc_ps2_sup_data_buffer[SENSOR_MAX_BUFF_SIZE];
extern hsc_data_s hsc_edge1_sup_data_buffer[SENSOR_MAX_BUFF_SIZE];
extern hsc_data_s hsc_edge2_sup_data_buffer[SENSOR_MAX_BUFF_SIZE];
extern hsc_data_s hsc_edge1_heat_coil_data_buffer[SENSOR_MAX_BUFF_SIZE];
extern hsc_data_s hsc_edge2_heat_coil_data_buffer[SENSOR_MAX_BUFF_SIZE];
extern hsc_data_s hsc_io_brd_sup_data_buffer[SENSOR_MAX_BUFF_SIZE];
extern hsc_data_s hsc_io_brd_top1_data_buffer[SENSOR_MAX_BUFF_SIZE];
extern hsc_data_s hsc_io_brd_top2_data_buffer[SENSOR_MAX_BUFF_SIZE];
extern hsc_data_s hsc_io_brd_bot1_data_buffer[SENSOR_MAX_BUFF_SIZE];
extern hsc_data_s hsc_io_brd_bot2_data_buffer[SENSOR_MAX_BUFF_SIZE];

extern psm_data_s psm_ps_gen2_data_buffer[SENSOR_MAX_BUFF_SIZE];
extern psm_data_s psm_core_brd_a_data_buffer[SENSOR_MAX_BUFF_SIZE];
extern psm_data_s psm_core_brd_b_data_buffer[SENSOR_MAX_BUFF_SIZE];
extern psm_data_s psm_ps1_data_buffer[SENSOR_MAX_BUFF_SIZE];
extern psm_data_s psm_ps2_data_buffer[SENSOR_MAX_BUFF_SIZE];
extern psm_data_s psm_edge1_data_buffer[SENSOR_MAX_BUFF_SIZE];
extern psm_data_s psm_edge2_sup_data_buffer[SENSOR_MAX_BUFF_SIZE];
extern psm_data_s psm_io_sup_data_buffer[SENSOR_MAX_BUFF_SIZE];


/**
 * @brief Global variable for TCTM debug information
 */
s_tc_dbg_info tc_dbg_info[MAX_TCTM_DBG_INFO] = {0};
s_tm_dbg_info tm_dbg_info[MAX_TCTM_DBG_INFO] = {0};
uint8_t tc_dbg_info_idx = 0;
uint8_t tm_dbg_info_idx = 0;

#if defined(COREBOARD) || defined(STM32F769xx)
#define PLACE_IN_EXT_RAM_TCTM_MEM   __attribute__((aligned(4))) __attribute__ ((section (".ext_ram_data_tctm")))
#else
#define PLACE_IN_EXT_RAM_TCTM_MEM
#endif

uint8 tc_storage[TC_DEFERRED_STORAGE_LENGTH]PLACE_IN_EXT_RAM_MEM = {0};
void log_lev_cfg_decode(uint8_t *tc_data);

#ifdef LINUX_TEMP_PORT

uint64_t uptime;
float cpu_ld;
char usage_sts[1000];

void execute_terminal_cmd(char* cmd, char* response)
{
    FILE *fptr;
    fptr = popen(cmd,"r");
    fread(response,1000,1,fptr);
    pclose(fptr);
}

time_t calender_time_to_epoch(char* datetime_str)
{
    struct tm tm_time = {0};
    time_t epoch_time;
    // Parse the datetime string into a struct tm
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wimplicit-function-declaration"
    strptime(datetime_str, "%Y-%m-%d %H:%M:%S", &tm_time);
#pragma GCC diagnostic pop
    // Convert the struct tm to epoch time
    epoch_time = mktime(&tm_time);
    DEBUG_CPRINT(("Datetime: %s\n", datetime_str));
    DEBUG_CPRINT(("Epoch time: %ld\n", epoch_time));
    return epoch_time;
}

uint64_t linux_get_uptime()
{
    time_t up_time,curr_time;
    execute_terminal_cmd("uptime -s",usage_sts);
    DEBUG_CPRINT(("uptime ===== %s\n",usage_sts));
    curr_time=time(NULL);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat"
    DEBUG_CPRINT(("curr_time ===== %llu\n",curr_time));
#pragma GCC diagnostic pop
    up_time = calender_time_to_epoch(usage_sts);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat"
    DEBUG_CPRINT(("uptime ===== %llu\n",up_time));
#pragma GCC diagnostic pop

    return (curr_time-up_time);
}

float linux_get_cpuload()
{
   float cpu_ld;
    execute_terminal_cmd("uptime",usage_sts);
    DEBUG_CPRINT(("uptime ===== %s\n",usage_sts));
    cpu_ld=(float)strtod(usage_sts+54,NULL);
    DEBUG_CPRINT(("CPU LOAD ===== %f\n",cpu_ld));
    cpu_ld=cpu_ld*100.0;
    return cpu_ld;
}

void linux_get_memusage(iram_heap_status *iram_lnx_sts)
{
    execute_terminal_cmd("free -b",usage_sts);
    iram_lnx_sts->total_mem=atol(usage_sts+88);
    iram_lnx_sts->used_mem=atol(usage_sts+101);
    iram_lnx_sts->available_mem=atol(usage_sts+148);
}

#endif

typedef struct
{
        uint8_t log_dwn_cfg : 1;
        uint8_t log_lev_mod_sel : 7;

}__attribute__((__packed__))log_mod_ctr_data;

/*********************************************************************************/
/******************* TeleCommand Decode Functions ********************************/
/*********************************************************************************/

uint8_t check_tm_buffer_cntrl_flag(void)
{
	return tm_buff_ctrl_flag;
}

uint8_t otsu_payload_transmitter_to_obc(uint16 tc_tm_id, uint8_t *payload_ptr, uint16_t payload_len)
{
	uint8_t ret_busy_sts = 0;
	uint16_t u16cnt;
	if(payload_ptr != NULL)
	{
			otsu_tm_pld.tctm_ptr = os_malloc_eram(payload_len);
			if(otsu_tm_pld.tctm_ptr != NULL)
			{
				for(u16cnt = 0; u16cnt< payload_len; u16cnt++)
				{
					otsu_tm_pld.tctm_ptr[u16cnt] = payload_ptr[u16cnt];
				}
				otsu_tm_pld.tctm_size = payload_len;
				tm_rsp_id = tc_tm_id;
				obc_pack_tm_data(NULL);
			}
			else
			{
				DEBUG_CPRINT(("\nOTSU TM malloc fail at OBC"));
			}

	}
	return ret_busy_sts;
}

#if 0
int8 obc_tc_eps_set_conv_brd_dec(const uint8 *data)
{
    /* Decode data */
	eps_err_sts eps_sts=EPS_ERR;
	eps_set_conv_brd_s brd;

    os_memcpy(&brd,data,sizeof(eps_set_conv_brd_s));

	eps_sts = eps_set_conv_brd_params(&brd,eps_set_conv_brd_resp);

/*    if((eps_sts != EPS_SUCCESS) && (eps_sts != EPS_SET_PARAM_ERR))
    {
    	memset(eps_set_conv_brd_resp,0,SET_CONV_BRD_RESP_LEN);
    	eps_set_conv_brd_resp[SET_CONV_BRD_RESP_LEN-1] = eps_sts;
    }
*/

    tm_rsp_id = TM_SET_CONV_BOARD_PARM;
    obc_pack_tm_data();
    UNUSED(eps_sts);
    return TCTM_OK;
}
#endif


#if 0
int8 obc_tc_eps_get_var_val(const uint8 *data)
{

    eps_err_sts eps_sts=EPS_ERR;
    obc_pck_data eps_var_sts;
    eps_set_var_addr_s eps_var;
    tctm_eps_set_var_addr_s *eps_var_addr = (tctm_eps_set_var_addr_s *)data;

    os_memcpy(eps_var.addr,eps_var_addr->var_addr,sizeof(eps_var.addr));
    os_memcpy(eps_var.reserved,eps_var_addr->reserved,sizeof(eps_var.reserved));
#ifndef LINUX_TEMP_PORT
    eps_sts = eps_get_variable_data(eps_var_addr->slv_addr,&eps_var,&eps_var_val_resp);
    if(eps_sts != EPS_SUCCESS)
    {
    	memset(eps_var_val_resp.data,0,8);
    }
    eps_var_sts.tx_data_len = 1;
    eps_var_sts.tx_data = (uint8_t*)&eps_sts;

#endif
    eps_var_sts.tm_rsp_id = TM_GET_EPS_VAR_VAL;
    obc_pack_tm_data(&eps_var_sts);

    UNUSED(eps_sts);
    return TCTM_OK;
}
#endif
#ifndef LINUX_TEMP_PORT
uint8_t obc_memory_downloader_start(obc_mem_dwldr_request_form_def *request_form)
{
	uint8_t status =0;
	uint32_t temp_addr;

	if(request_form->mem_type < MAX_MEM)
	{
		temp_addr = request_form->mem_address;
		if(((uint8_t *)temp_addr >= look_up_table[request_form->mem_type].start_addr) && (((uint8_t *)temp_addr + request_form->mem_size) <= look_up_table[request_form->mem_type].end_addr))
		{
			if(request_form->ftm_mtu_cfg == 0 || request_form->ftm_mtu_cfg > 1350)
			{
				request_form->ftm_mtu_cfg = 1350;
			}

			if(request_form->ftm_ftds_cfg < 2)
			{
				request_form->ftm_ftds_cfg = 2;
			}


			/*
			 * send TM response that download has been stared
			 */



			/*
			 * Initiate ftm session
			 */
			ft_register_sender_app(TM_SRC_FTM_DBGLOG, log_ftm_notificataion_api_upld);
			ft_config_app_id(TM_SRC_FTM_DBGLOG);
			ft_mode_select(M_DATA);
			ft_config_file_id(2);
			ft_config_mtu_size(request_form->ftm_mtu_cfg);
			ft_config_ftds_delay(request_form->ftm_ftds_cfg);
			ft_sequenceLoss_mode_select(request_form->ftm_seq_detct_cfg);
			ft_config_rx_node_conn_failure_time(45);
			ft_config_bulk_data_input_buffer((uint8_t*)temp_addr, request_form->mem_size);
			ft_transfer_request(Start_Transmission_rqst,0);
		}
		else
		{
			/*
			 * invalid memory address or not in memory range
			 *
			 */
			status = 2;
		}
	}
	else
	{
		/*
		 * invalid memory type chose
		 */
		status = 1;
	}

	return status;
}

#endif

int8 obc_sns_thread_send_ipc(uint8_t ah_type, void* src_ptr)
{
    os_itc_msg_handle_t* sns_cfg_ipc=os_malloc_eram(sizeof(os_itc_msg_handle_t));
   	sns_cfg_ipc->Msg_id=SNS_CFG_EVNT;
   	sns_cfg_ipc->src_entity=0;
   	sns_cfg_ipc->pld.pld_ptr=src_ptr;
   	os_itc_msg_send(sns_cfg_ipc,OBC_SENSOR_HDLR,1000);
	os_free(sns_cfg_ipc);
   	return 0;
}

int8 obc_tc_set_min_reboot_dec(const uint8 *data)
{
    os_memcpy(&rbt_time,data,sizeof(uint32_t));
    nvm_parameter_write(NVM_DATA,NVM_MIN_RBT_TIME,(uint8_t*)&rbt_time);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat"
    DEBUG_CPRINT(("Received reboot time cfg == %lu\n",rbt_time));
#pragma GCC diagnostic pop
    tm_rsp_id = TM_SET_MIN_REBOOT_TIME;
    obc_pack_tm_data(NULL);

    return TCTM_OK;
}


int8 obc_tc_temp_sns_param_dec(const uint8 *data)
{
    os_memcpy(&temp_sns_cfg,data,sizeof(temp_sens_cfg ));
    uint8_t *ptr = os_malloc(sizeof(temp_sens_cfg));
    os_memcpy(ptr,data,sizeof(temp_sens_cfg ));
    obc_sns_thread_send_ipc(TEMP_SENSOR,ptr);
    tm_rsp_id = TM_SET_TEMP_SNS_CFG;
    obc_pack_tm_data(NULL);

    return TCTM_OK;
}

int8 obc_tc_dig_therm_param_dec(const uint8 *data)
{
    int8 status;

    os_memcpy(&dgtl_thrmst_cfg,data,sizeof(digital_thermostat_cfg ));
    uint8_t *ptr = os_malloc(sizeof(digital_thermostat_cfg ));
    os_memcpy(ptr,data,sizeof(digital_thermostat_cfg));
    obc_sns_thread_send_ipc(DIGI_THERM,ptr);
    tm_rsp_id = TM_SET_DIG_THERM_CFG ;
    obc_pack_tm_data(NULL);

    status = TCTM_OK;
    return status;


}

int8 obc_tc_imu_param_dec(const uint8 *data)
{
    int8 status;

    os_memcpy(&imu_para,data,sizeof(imu_param ));
    uint8_t *ptr = os_malloc(sizeof(imu_param));
    os_memcpy(ptr,data,sizeof(imu_param ));
    obc_sns_thread_send_ipc(IMU,ptr);
    tm_rsp_id = TM_SET_IMU_CFG ;
    obc_pack_tm_data(NULL);

    status = TCTM_OK;
    return status;


}

int8 obc_tc_thrstr_ctlr_param_dec(const uint8 *data)
{
    int8 status;

    os_memcpy(&thrstr_para,data,sizeof(thruster_param ));

    tm_rsp_id = TM_SET_THRUST_CTRL_CFG;
    obc_pack_tm_data(NULL);

    status = TCTM_OK;
    return status;


}

int8 obc_tc_gpio_exp_param_dec(const uint8 *data)
{
    int8 status;

    os_memcpy(&gpx_exp_cfg,data,sizeof(gpio_exp_cfg ));

    tm_rsp_id = TM_SET_GPIO_EXP_CFG;
    obc_pack_tm_data(NULL);

    status = TCTM_OK;
    return status;


}

int8 obc_tc_data_log_param_dec(const uint8 *data)
{
    int8 status;

    os_memcpy(&data_acq_para,data,sizeof(data_acq_dvc_param ));

    tm_rsp_id = TM_SET_DATA_LOG_CFG;
    obc_pack_tm_data(NULL);

    status = TCTM_OK;
    return status;


}
int8 obc_tc_pwr_mon_param_dec(const uint8 *data)
{
    int8 status;

    os_memcpy(&pwr_sns_mtr_cfg,data,sizeof(power_sense_mntr_cfg ));
    uint8_t *ptr = os_malloc(sizeof(power_sense_mntr_cfg));
    os_memcpy(ptr,data,sizeof(power_sense_mntr_cfg));
    obc_sns_thread_send_ipc(POWER_SENSE_MONITOR,ptr);
    tm_rsp_id = TM_SET_PWR_MON_CFG;
    obc_pack_tm_data(NULL);

    status = TCTM_OK;
    return status;


}
int8 obc_tc_vltg_ctlr_ctlr_param_dec(const uint8 *data)
{
    int8 status;

    os_memcpy(&htswp_cntlr_cfg,data,sizeof(hotswap_cntlr_cfg));
    uint8_t *ptr = os_malloc(sizeof(hotswap_cntlr_cfg));
    os_memcpy(ptr,data,sizeof(hotswap_cntlr_cfg ));
    obc_sns_thread_send_ipc(HOT_SWP_CNTLR,ptr);
    tm_rsp_id = TM_SET_VOLT_CTRL_MON_CFG;
    obc_pack_tm_data(NULL);

    status = TCTM_OK;
    return status;


}
int8 obc_tc_pwr_seq_mntr_param_dec(const uint8 *data)
{
    int8 status;

    os_memcpy(&vltg_seq_mntr_cfg,data,sizeof(voltage_seq_mntr_cfg ));
    uint8_t *ptr = os_malloc(sizeof(voltage_seq_mntr_cfg));
    os_memcpy(ptr,data,sizeof(voltage_seq_mntr_cfg));
    obc_sns_thread_send_ipc(VOLTAGE_SEQ_MONITOR,ptr);
    tm_rsp_id = TM_SET_PWR_SEQ_MON_CFG;
    obc_pack_tm_data(NULL);

    status = TCTM_OK;
    return status;
}

int8 obc_tc_temp_sns_info_dec(const uint8 *data)
{
    int8 status;
    temp_sens_cfg config;
    obc_pck_data tm_data;
    get_temperature_sensor_cfg(*data, &config);
    tm_data.rx_data=(uint8_t*)&config;
    tm_data.rx_data_len = sizeof(temp_sens_cfg);
    tm_data.tm_rsp_id = TM_GET_TEMP_SNS_CFG;

    obc_pack_tm_data(&tm_data);

    status = TCTM_OK;
    return status;
}

int8 obc_tc_dgtl_thrm_info_dec(const uint8 *data)
{
    int8 status;

    digital_thermostat_cfg config;
    obc_pck_data tm_data;
    get_dgtl_thermst_sensor_cfg(*data, &config);
    tm_data.rx_data=(uint8_t*)&config;
    tm_data.rx_data_len = sizeof(digital_thermostat_cfg);
    tm_data.tm_rsp_id = TM_GET_DIG_THERM_CFG;

    obc_pack_tm_data(&tm_data);

    status = TCTM_OK;
    return status;
}

int8 obc_tc_thruster_ctlr_info_dec(const uint8 *data)
{
    int8 status;

    tm_rsp_id = TM_GET_THRUST_CTRL_CFG;
    obc_pack_tm_data(NULL);

    status = TCTM_OK;
    return status;
}

int8 obc_tc_imu_info_dec(const uint8 *data)
{
    int8 status;

    tm_rsp_id = TM_GET_IMU_CFG;
    obc_pack_tm_data(NULL);

    status = TCTM_OK;
    return status;
}

int8 obc_tc_gpio_exp_info_dec(const uint8 *data)
{
    int8 status;

    tm_rsp_id = TM_GET_GPIO_EXP_CFG;
    obc_pack_tm_data(NULL);

    status = TCTM_OK;
    return status;
}

int8 obc_tc_data_log_info_dec(const uint8 *data)
{
    int8 status;

    tm_rsp_id = TM_GET_DATA_LOG_CFG;
    obc_pack_tm_data(NULL);

    status = TCTM_OK;
    return status;
}

int8 obc_tc_get_sns_data_dec(const uint8 *data)
{
	int8 status;
	os_memcpy(&sns_ahw_id,data,sizeof(uint32_t));
	tm_rsp_id = TM_GET_SENSOR_DATA;
	obc_pack_tm_data(NULL);
	status = TCTM_OK;
	return status;
}


#if 0
int8 obc_tc_get_tmp_sns_data_dec(const uint8 *data)
{
    int8 status;
    os_memcpy(&sns_ahw_id,data,sizeof(uint32_t));
    tm_rsp_id = TM_GET_TEMP_SNS_DATA;
    obc_pack_tm_data();
    status = TCTM_OK;
    return status;
}
int8 obc_tc_get_dt_sns_data_dec(const uint8 *data)
{
    int8 status;
    os_memcpy(&sns_ahw_id,data,sizeof(uint32_t));
    tm_rsp_id = TM_GET_DT_SNS_DATA;
    obc_pack_tm_data();
    status = TCTM_OK;
    return status;
}
int8 obc_tc_get_pwr_mon_sns_data_dec(const uint8 *data)
{
    int8 status;
    os_memcpy(&sns_ahw_id,data,sizeof(uint32_t));
    tm_rsp_id = TM_GET_PWR_MON_DATA;
    obc_pack_tm_data();
    status = TCTM_OK;
    return status;
}
int8 obc_tc_hsc_get_data_dec(const uint8 *data)
{
    int8 status;
    os_memcpy(&sns_ahw_id,data,sizeof(uint32_t));
    tm_rsp_id = TM_GET_VOLT_CTRL_DATA;
    obc_pack_tm_data();
    status = TCTM_OK;
    return status;
}
int8 obc_tc_pwr_seq_mon_dec(const uint8 *data)
{
    int8 status;
    os_memcpy(&sns_ahw_id,data,sizeof(uint32_t));
    tm_rsp_id = TM_GET_PWR_SEQ_MON_DATA;
    obc_pack_tm_data();
    status = TCTM_OK;
    return status;
}
#endif
int8 obc_tc_obc_soft_reset_dec(const uint8 *data)
{
    int8 status;
    os_memcpy(&sw_rst_typ,data,sizeof(uint32_t));
    tm_rsp_id = TM_OBC_SOFT_RESET;
    obc_pack_tm_data(NULL);
    status = TCTM_OK;
    return status;
}

int8 obc_tc_ps_brd_select(uint8 *tc_data)
{
	ps_brd_ssd_id ps_brd_id = {0};
    uint8_t status = 1;
    obc_pck_data tm_data = {0};
	os_memcpy(&ps_brd_id,tc_data,sizeof(ps_brd_ssd_id));
#ifdef GEN2
    status = paylaod_board_select(ps_brd_id);
#endif
    tm_data.rx_data=(uint8_t*)&status;
    tm_data.rx_data_len = sizeof(status);
    tm_data.tm_rsp_id = TM_PS_BRD_SELECT;
    obc_pack_tm_data(&tm_data);
    return status;
}

int8 obc_tc_es_brd_select(const uint8 *data)
{
    uint8_t status = 1;
    obc_pck_data tm_data;
#ifdef GEN2
    status = edge_board_select(data[0]);
#endif
    tm_data.rx_data=&status;
    tm_data.rx_data_len = sizeof(status);
    tm_data.tm_rsp_id = TM_ES_BRD_SELECT;
    obc_pack_tm_data(&tm_data);
    return status;
}

int8 obc_tc_adc_brd_select(const uint8 *tc_data)
{
	adc_board_read adc_brd_read = {0};
	uint8_t status = 1;
	obc_pck_data tm_info = {0};
	os_memcpy(&adc_brd_read,tc_data,sizeof(adc_board_read));
	status = ahw_al_data_logger_getvoltage_convertion(adc_brd_read.adc_id,adc_brd_read.adc_chnl_id,adc_brd_read.adc_vltge);
	if(status != 0 )
	{
		status = 1;
	}
	tm_info.rx_data_len = sizeof(adc_brd_read);
	tm_info.rx_data = (uint8_t*)&adc_brd_read;
	tm_info.tm_rsp_id = TM_ADC_SELECT;
	obc_pack_tm_data(&tm_info);
	return status;
}

int8 obc_tc_io_brd_select(const uint8 *data)
{
    uint8_t status = 1;
    obc_pck_data tm_data;
#ifdef GEN2
    status = io_board_select(data[0]);
#endif
    tm_data.rx_data = &status;
    tm_data.rx_data_len = sizeof(status);
    tm_data.tm_rsp_id = TM_IO_BRD_SELECT;
    obc_pack_tm_data(&tm_data);
    return status;
}

int8 obc_tc_i2c_adxl345_test(const uint8 *data)
{
    uint8_t status = 1;
    obc_pck_data tm_data;
#ifdef GEN2
    status = i2c_test_adxl345(data[0]);
#endif
    tm_data.rx_data = &status;
    tm_data.rx_data_len = sizeof(status);
    tm_data.tm_rsp_id = TM_I2C_ADXL345_TEST;
    obc_pack_tm_data(&tm_data);
    return status;
}

int8 obc_tc_spi_adxl345_test()
{
	uint8_t status = 1;
	obc_pck_data tm_data;
	uint8_t *data = 0;
#ifdef GEN2
	status = spi_test_adxl345(data);
#endif
	if(status == HAL_SCS)
	{
		tm_data.rx_data = malloc(sizeof(status) +  sizeof(uint8_t));
		tm_data.rx_data[0] = status;
		tm_data.rx_data[1] = *data;
		tm_data.rx_data_len = sizeof(status) + 1;
	}
	else
	{
		tm_data.rx_data = &status;
		tm_data.rx_data_len = sizeof(status);
	}
	tm_data.tm_rsp_id = TM_SPI_ADXL345_TEST;
	obc_pack_tm_data(&tm_data);
	return status;
}

int8 obc_tc_uart_test(uint8_t *data) {
	uint8_t status = HAL_MAX_ERR;
	obc_pck_data tm_data;
	uint8_t rx_data[11];  // Buffer for received CAN data
	size_t rx_data_len = 0;
#ifdef GEN2
	status = uart_test(data, rx_data, &rx_data_len);
#endif

	if (data[1] == 1) { // TX operation
		// Only return the status
		tm_data.rx_data = &status;
		tm_data.rx_data_len = sizeof(status);
	}
	else if (data[1] == 2)
	{ // RX operation
		if (status == HAL_SCS && rx_data_len > 0)
		{
			tm_data.rx_data = malloc(sizeof(status) + rx_data_len);
			if (tm_data.rx_data != NULL)
			{
				tm_data.rx_data[0] = status;  // Include status
				memcpy(tm_data.rx_data + 1, rx_data, rx_data_len); // Append received data
				tm_data.rx_data_len = sizeof(status) + rx_data_len;
			}
			else
			{
				status = HAL_MEM_ALLOC_ERR;
				tm_data.rx_data = &status;
				tm_data.rx_data_len = sizeof(status);
			}
		}
		else {
			// RX failed, send status only
			tm_data.rx_data = &status;
			tm_data.rx_data_len = sizeof(status);
		}
	}
	tm_data.tm_rsp_id = TM_UART_TX_RX_TEST; // Telemetry response ID
	obc_pack_tm_data(&tm_data); // Pack telemetry
	return status;
}

int8 obc_tc_can_test(const uint8_t *data) {
    uint8_t status = HAL_MAX_ERR;
    obc_pck_data tm_data;
    uint8_t rx_data[9] = {0};  // Buffer for received CAN data
    size_t rx_data_len = 0;    // Length of received data

#ifdef GEN2
    status = core_can_test((uint8_t *)data, rx_data, &rx_data_len);
#endif
    if (data[0] == 1)
    { // TX operation
        tm_data.rx_data = &status;
        tm_data.rx_data_len = sizeof(status);
    }
    else if (data[0] == 2)
    { // RX operation
        if (status == HAL_SCS && rx_data_len > 0)
        {
            tm_data.rx_data = malloc(sizeof(status) + rx_data_len);
            if (tm_data.rx_data != NULL)
            {
                tm_data.rx_data[0] = status;  // Include status
                memcpy(tm_data.rx_data + 1, rx_data, rx_data_len); // Append received data
                tm_data.rx_data_len = sizeof(status) + rx_data_len;
            }
            else
            {
                status = HAL_MEM_ALLOC_ERR;
                tm_data.rx_data = &status;
                tm_data.rx_data_len = sizeof(status);
            }
        }
        else
        {
            tm_data.rx_data = &status;
            tm_data.rx_data_len = sizeof(status);
        }
    }
    tm_data.tm_rsp_id = TM_CAN_TX_RX_TEST;  // Telemetry response ID
    obc_pack_tm_data(&tm_data);  // Pack telemetry
    return status;
}
/*
int8 obc_tc_ps_ssd_select(const uint8 *data)
{
    uint8_t status = 1;
    obc_pck_data tm_data;
#ifdef GEN2
    status = payload_board_ssd_select(data[0]);
#endif
    tm_data.rx_data = &status;
    tm_data.rx_data_len = sizeof(status);
    tm_data.tm_rsp_id = TM_PS_SSD_BRD_SELECT;
    obc_pack_tm_data(&tm_data);
    return status;
}
*/
int8 obc_tc_es_ssd_select(const uint8 *data)
{
    uint8_t status = 1;
    obc_pck_data tm_data;
#ifdef GEN2
    status = edge_board_ssd_select(data[0]);
#endif
    tm_data.rx_data = &status;
    tm_data.rx_data_len = sizeof(status);
    tm_data.tm_rsp_id = TM_ES_SSD_BRD_SELECT;
    obc_pack_tm_data(&tm_data);
    return status;
}

int8 obc_tc_auto_sensor_test(const uint8 *data)
{
    uint64_t status = 1;
    obc_pck_data tm_data;
#ifdef GEN2
    status = obc_auto_sensor_test();
#endif
    tm_data.rx_data = (uint8_t*)&status;
    tm_data.rx_data_len = sizeof(status);
    tm_data.tm_rsp_id = TM_AUTO_SENSOR_TEST;
    obc_pack_tm_data(&tm_data);
    return status;
}

int8 obc_tc_set_cur_time_dec(const uint8 *data)
{
    int8 status;
    eps_set_rtc_tm_s eps_rtc_time;
    os_itc_msg_handle_t eps_rtc_ipc;
    os_itc_msg_handle_t adcs_time_ipc;
 //   uint8_t rtc_time[8];
    sys_time_date_s cur_time;
    os_memcpy(&cur_time,data,sizeof(sys_time_date_s));
    //set_crnt_time_date(&cur_time);
    set_crnt_time_date_withnvm(&cur_time);
    DEBUG_CPRINT(("sos time %d :%d :%d \n",cur_time.hour,cur_time.minute,cur_time.seconds));
    DEBUG_CPRINT(("sos date %d :%d :%d \n",cur_time.date,cur_time.month,cur_time.year));
    obc_encode_icd_cmd(OBC_PS_UTC_TIME_CMD, 0, NULL);
#if 0
    DEBUG_CPRINT(("RTC time\n"));
#endif
    eps_rtc_time.hour= cur_time.hour;
    eps_rtc_time.minute= cur_time.minute;
    eps_rtc_time.second= cur_time.seconds;
    eps_rtc_time.date= cur_time.date;
    eps_rtc_time.month= cur_time.month;
    eps_rtc_time.year = cur_time.year%100;

   //eps_set_rtc_time(&eps_rtc_time,&rtc_time[0]);
    eps_rtc_ipc.Msg_id= TC_SET_CUR_TIME;
    eps_rtc_ipc.Msg_len= sizeof(eps_set_rtc_tm_s);
    eps_rtc_ipc.src_entity= OBC_MAIN;
    eps_rtc_ipc.pld.pld_ptr=os_malloc(eps_rtc_ipc.Msg_len);
    os_memcpy(eps_rtc_ipc.pld.pld_ptr,&eps_rtc_time,eps_rtc_ipc.Msg_len);
    //eps_rtc_ipc.pld_info= TM_SET_CUR_TIME;
    os_itc_msg_send(&eps_rtc_ipc,EPS_TASK,os_send_itc_wait);

    adcs_time_ipc.Msg_id = OBC_ADCS_TIME_SYNC_REQ;
    adcs_time_ipc.Msg_len = sizeof(sys_time_date_s);
    adcs_time_ipc.src_entity= OBC_MAIN;
    adcs_time_ipc.pld.pld_ptr=os_malloc(adcs_time_ipc.Msg_len);
    os_memcpy(adcs_time_ipc.pld.pld_ptr,data,adcs_time_ipc.Msg_len);
    os_itc_msg_send(&adcs_time_ipc,ADCS_CONTROLLER,os_send_itc_wait);
    os_delay(2);
    tm_rsp_id = TM_SET_CUR_TIME;
    obc_pack_tm_data(NULL);
    status = TCTM_OK;
    return status;
}

int8 obc_tc_pwr_seq_mtr_info_dec(const uint8 *data)
{
    int8 status;

    tm_rsp_id = TM_GET_PWR_SEQ_MON_CFG;
    obc_pack_tm_data(NULL);

    status = TCTM_OK;
    return status;
}

int8 obc_tc_vltg_ctlr_info_dec(const uint8 *data)
{
    int8 status;

    hotswap_cntlr_cfg config;
    obc_pck_data tm_data;
    get_hotswap_cntlr_sensor_cfg(*data, &config);
    tm_data.rx_data=(uint8_t*)&config;
    tm_data.rx_data_len = sizeof(hotswap_cntlr_cfg);
    tm_data.tm_rsp_id = TM_GET_VOLT_CTRL_MON_CFG;

    obc_pack_tm_data(&tm_data);

    status = TCTM_OK;
    return status;
}

int8 obc_tc_pwr_mon_info_dec(const uint8 *data)
{
    int8 status;

    power_sense_mntr_cfg config;
    obc_pck_data tm_data;
    get_power_monitor_sensor_cfg(*data, &config);
    tm_data.rx_data=(uint8_t*)&config;
    tm_data.rx_data_len = sizeof(power_sense_mntr_cfg);
    tm_data.tm_rsp_id = TM_GET_TEMP_SNS_CFG;

    obc_pack_tm_data(&tm_data);

    status = TCTM_OK;
    return status;
}

/*!
 * @brief This API decodes the Telecommand payload of
 * PS power ON request
 */
#if 0
int8 obc_tc_ps_pwr_on_dec(const uint8 *data)
{
    int8 status;

#ifdef LINUX_TEMP_PORT
    DEBUG_CPRINT(("PS Powr ON request received\n"));
#else
    eps_ctrl_en_chnl(EPS_PL_SERVER,ON);
#endif

    tm_rsp_id = TM_PS_PWR_ON;
    obc_pack_tm_data();

    /* Trigger next set of events */
    obc_evnt_trig = 1000;
    obc_encode_icd_cmd(obc_evnt_trig,0);

    status = TCTM_OK;
    return status;
}
#endif
int8 obc_tc_spi_intf_param_dec(const uint8 *data)
{
    int8 status;

    tm_rsp_id = TM_GET_SPI_INTF_PARM;
    obc_pack_tm_data(NULL);

    status = TCTM_OK;
    return status;
}

int8 obc_tc_ethernet_intf_param_dec(const uint8 *data)
{
    int8 status;

    tm_rsp_id = TM_GET_ETH_INTF_PARM;
    obc_pack_tm_data(NULL);

    status = TCTM_OK;
    return status;
}

int8 obc_tc_can_intf_param_dec(const uint8 *data)
{
    int8 status;

    tm_rsp_id = TM_GET_CAN_INTF_PARM;
    obc_pack_tm_data(NULL);

    status = TCTM_OK;
    return status;
}

int8 obc_tc_i2c_intf_param_dec(const uint8 *data)
{
    int8 status;

    tm_rsp_id = TM_GET_I2C_INTF_PARM;
    obc_pack_tm_data(NULL);

    status = TCTM_OK;
    return status;
}

int8 obc_tc_usb_intf_param_dec(const uint8 *data)
{
    int8 status;

    tm_rsp_id = TM_GET_USB_INTF_PARM;
    obc_pack_tm_data(NULL);

    status = TCTM_OK;
    return status;
}

int8 obc_tc_uart_intf_param_dec(const uint8 *data)
{
    int8 status;

    tm_rsp_id = TM_GET_UART_INTF_PARM;
    obc_pack_tm_data(NULL);

    status = TCTM_OK;
    return status;
}

int8 obc_tc_spi_intf_set_dec(const uint8 *data)
{
    int8 status;
    os_memcpy(&spii,data,sizeof(tctm_spi_init_s));
    tm_rsp_id = TM_SET_SPI_INTF_PARM;
    obc_pack_tm_data(NULL);

    status = TCTM_OK;
    return status;
}

int8 obc_tc_ethernet_intf_set_dec(const uint8 *data)
{
    int8 status;
    os_memcpy(&eth,data,sizeof(tctm_ethernet_init_s));
    tm_rsp_id = TM_SET_ETH_INTF_PARM;
    obc_pack_tm_data(NULL);

    status = TCTM_OK;
    return status;
}

int8 obc_tc_can_intf_set_dec(const uint8 *data)
{
    int8 status;
    os_memcpy(&cis,data,sizeof(tctm_can_init_s));
    tm_rsp_id = TM_SET_CAN_INTF_PARM;
    obc_pack_tm_data(NULL);

    status = TCTM_OK;
    return status;
}

int8 obc_tc_i2c_intf_set_dec(const uint8 *data)
{
    int8 status;
    os_memcpy(&i2ci,data,sizeof(tctm_i2c_init_s));
    tm_rsp_id = TM_SET_I2C_INTF_PARM;
    obc_pack_tm_data(NULL);

    status = TCTM_OK;
    return status;
}

int8 obc_tc_usb_intf_set_dec(const uint8 *data)
{
    int8 status;
    os_memcpy(&usbo,data,sizeof(tctm_usb_otg_cfg_s));
    tm_rsp_id = TM_SET_USB_INTF_PARM;
    obc_pack_tm_data(NULL);

    status = TCTM_OK;
    return status;
}

int8 obc_tc_uart_intf_set_dec(const uint8 *data)
{
    int8 status;
    os_memcpy(&uarti,data,sizeof(tctm_uart_init_s));
    tm_rsp_id = TM_SET_UART_INTF_PARM;
    obc_pack_tm_data(NULL);

    status = TCTM_OK;
    return status;
}
#if 0
int8 obc_tc_pld_hw_pwr_on_dec(const uint8 *data)
{
    int8 status=1;
    uint8_t eps_id;
    DEBUG_CPRINT(("PLD HW Power ON request received\n"));
    uint32 pld_hw_id;
    os_memcpy(&pld_hw_id, data, sizeof(pld_hw_id));

#ifdef LINUX_TEMP_PORT
    DEBUG_CPRINT(("Received Power ON request for PLD HW ID: %d",pld_hw_id));
#endif

    uint16 tm_len = 4;
    uint8 *tm_data = NULL;
    tm_data = (uint8_t *) os_malloc_eram(tm_len);

    if((PLD_HW_ID_TRANS == pld_hw_id) || \
       (PLD_HW_ID_AICraft == pld_hw_id) || \
       (PLD_HW_ID_ZES == pld_hw_id) || \
       (PLD_HW_ID_SAYAR == pld_hw_id) || \
       (PLD_HW_ID_NETRA == pld_hw_id))
    {
        /* TODO - Invoke EPS power ON command here - respective power rail should be passed as argument */
        /* TRANS - Output Channel 1
         * AICraft - Output Channel 4
         * ZES - Output Channel 7
         * SAYAR - Output Channel 8
         * NETRA - Output Channel 9
         */
#ifndef LINUX_TEMP_PORT

    	switch(pld_hw_id)
    	{
			case PLD_HW_ID_TRANS: 	eps_id = EPS_PL_TRANSCELESTIAL; break;
			case PLD_HW_ID_AICraft:	eps_id = EPS_PL_AICRAFT;  		break;
			case PLD_HW_ID_ZES:		eps_id = EPS_PL_ZES;  			break;
			case PLD_HW_ID_SAYAR: 	eps_id = EPS_PL_SAYARLABS;  	break;
			case PLD_HW_ID_NETRA: 	eps_id = EPS_PL_NETRA;     		break;
    	}

	    if(eps_ctrl_en_chnl(eps_id,ON)==EPS_SUCCESS)
	        status = 0;
#else
	    	status = 0;
#endif

        /* Based on success / failure status from EPS, update the status variable here */
        /* Success - 0; Failure - 1 */
    }

	obc_tm_pld_hw_pwr_on_enc(tm_data, status);
	obc_prepare_ipc_msg(tm_data, tm_len, TM_PLD_HW_PWR_ON ,TM_SRC_OBC);
	os_free(tm_data);
	tm_data = NULL;
    //tm_rsp_id = TM_PLD_HW_PWR_ON;

    status = TCTM_OK;
    return status;
}
#endif
int8 obc_tc_pld_vm_pwr_on_dec(const uint8 *data)
{
    int8 status;
    os_memcpy(&ps_vm_id,data,2);
    DEBUG_CPRINT(("PLD VM Power ON request received for %d\n",ps_vm_id));
    //Send ICD message request
    obc_encode_icd_cmd(OBC_PS_VM_PWR_ON_CMD, ps_vm_id, NULL);

    status = TCTM_OK;
    return status;
}
#if 0
int8 obc_tc_sband_pwr_ctrl_dec(const uint8 *data)
{
    int8 status;
    uint8 pwr_ctrl = *data;;
    uint16 tm_len = 1;
    uint8 tm_data;

#if LINUX_TEMP_PORT
    if(pwr_ctrl)
        DEBUG_CPRINT(("SBand Power ON request received\n"));
    else
        DEBUG_CPRINT(("SBand Power OFF request received\n"));
#else
    eps_ctrl_en_chnl(EPS_S_BAND,pwr_ctrl);
#endif

    /* TODO - Invoke EPS function here */
    /* Update status variable from EPS function */
    status = 0;

    /* Update EPS response */
    os_memcpy(&tm_data,&status,tm_len);

    obc_prepare_ipc_msg(&tm_data, tm_len, TM_PWR_CTRL_SBAND,TM_SRC_OBC);

    status = TCTM_OK;
    return status;
}

int8 obc_tc_xband_pwr_ctrl_dec(const uint8 *data)
{
    int8 status;
    uint8 pwr_ctrl = *data;;
    uint16 tm_len = 1;
    uint8 tm_data;

#if LINUX_TEMP_PORT
    if(pwr_ctrl)
        DEBUG_CPRINT(("XBand Power ON request received\n"));
    else
        DEBUG_CPRINT(("XBand Power OFF request received\n"));
#else
    eps_ctrl_en_chnl(EPS_X_BAND,pwr_ctrl);
#endif
    /* TODO - Invoke EPS function here */
    /* Update status variable from EPS function */
    status = 0;

    /* Update EPS response */
    os_memcpy(&tm_data,&status,tm_len);

    obc_prepare_ipc_msg(&tm_data, tm_len, TM_PWR_CTRL_XBAND,TM_SRC_OBC);

    status = TCTM_OK;
    return status;
}

int8 obc_tc_adcs_pwr_ctrl_dec(const uint8 *data)
{
    int8 status;
    uint8 pwr_ctrl = *data;;
    uint16 tm_len = 1;
    uint8 tm_data;

#if LINUX_TEMP_PORT
    if(pwr_ctrl)
        DEBUG_CPRINT(("ADCS Power ON request received\n"));
    else
        DEBUG_CPRINT(("ADCS Power OFF request received\n"));
#else
    eps_ctrl_en_chnl(EPS_ADCS,pwr_ctrl);
#endif

    /* TODO - Invoke EPS function here */
    /* Update status variable from EPS function */
    status = 0;

    /* Update EPS response */
    os_memcpy(&tm_data,&status,tm_len);

    obc_prepare_ipc_msg(&tm_data, tm_len, TM_PWR_CTRL_ADCS,TM_SRC_OBC);

    status = TCTM_OK;
    return status;
}

int8 obc_tc_thrust_pwr_ctrl_dec(const uint8 *data)
{
    int8 status;
    uint8 pwr_ctrl = *data;;
    uint16 tm_len = 1;
    uint8 tm_data;

#if LINUX_TEMP_PORT
    if(pwr_ctrl)
        DEBUG_CPRINT(("Thruster Power ON request received\n"));
    else
        DEBUG_CPRINT(("Thruster Power OFF request received\n"));
#else
    eps_ctrl_en_chnl(EPS_PROP_UNIT_THRUSTER,pwr_ctrl);
#endif
    /* TODO - Invoke EPS function here */
    /* Update status variable from EPS function */
    status = 0;

    /* Update EPS response */
    os_memcpy(&tm_data,&status,tm_len);

    obc_prepare_ipc_msg(&tm_data, tm_len, TM_PWR_CTRL_THRUSTER,TM_SRC_OBC);

    status = TCTM_OK;
    return status;
}

int8 obc_tc_edge_board_pwr_ctrl_dec(const uint8 *data)
{
    int8 status;
    uint8 pwr_ctrl = *data;;
    uint16 tm_len = 1;
    uint8 tm_data;

#if LINUX_TEMP_PORT
    if(pwr_ctrl)
        DEBUG_CPRINT(("Edge Board Power ON request received\n"));
    else
        DEBUG_CPRINT(("Edge Board Power OFF request received\n"));
#else
    eps_ctrl_en_chnl(EPS_EDGE_BRD,pwr_ctrl);
#endif

    /* TODO - Invoke EPS function here */
    /* Update status variable from EPS function */
    status = 0;

    /* Update EPS response */
    os_memcpy(&tm_data,&status,tm_len);

    obc_prepare_ipc_msg(&tm_data, tm_len, TM_PWR_CTRL_EDGE_BOARD, TM_SRC_OBC);

    status = TCTM_OK;
    return status;
}

int8 obc_tc_pld_hw_pwr_off_dec(const uint8 *data)
{
    int8 status;
    //uint8 eps_id;
    uint16 tm_len = 4;
    uint8 *tm_data = NULL;
    uint8 *icd_data = NULL;
    uint16 icd_data_len;
    tm_data = (uint8_t *) os_malloc_eram(tm_len);

    uint32 pld_hw_id;
    os_memcpy(&pld_hw_id, data, sizeof(pld_hw_id));
    DEBUG_CPRINT(("Received Power OFF request for PLD HW ID: %d",pld_hw_id));

    /* Check for valid Payload Hardware ID */
    if((PLD_HW_ID_TRANS == pld_hw_id) || \
       (PLD_HW_ID_AICraft == pld_hw_id) || \
       (PLD_HW_ID_ZES == pld_hw_id) || \
       (PLD_HW_ID_SAYAR == pld_hw_id) || \
       (PLD_HW_ID_NETRA == pld_hw_id))
    {
        phw_poi.pld_hw_id = pld_hw_id;
        phw_poi.shut_tmr_min = 2;
        phw_poi.shut_tmr_sec = 40;
        phw_poi.shut_tmr_ms = 200;
        phw_poi.shut_purpose = ICM_SP_LOW_BTRY;
        obc_ps_pld_hw_pwr_off_cmd (&icd_data,&icd_data_len,&phw_poi);

#if 0
#ifndef LINUX_TEMP_PORT

    	switch(pld_hw_id)
    	{
			case PLD_HW_ID_TRANS: 	eps_id = EPS_PL_TRANSCELESTIAL; break;
			case PLD_HW_ID_AICraft:	eps_id = EPS_PL_AICRAFT;  		break;
			case PLD_HW_ID_ZES:		eps_id = EPS_PL_ZES;  			break;
			case PLD_HW_ID_SAYAR: 	eps_id = EPS_PL_SAYARLABS;  	break;
			case PLD_HW_ID_NETRA: 	eps_id = EPS_PL_NETRA;     		break;
    	}

	    if(eps_ctrl_en_chnl(eps_id,OFF)==EPS_SUCCESS)
	        status = 0;
#else
	    	status = 0;
#endif

#endif

        /* Send ICD Message to PS */
        obc_icd_socket_send(icd_data,icd_data_len);
        os_free(icd_data);
        icd_data = NULL;
    }
    /* Send TM Failure response for invalid HW ID */
    else
    {
        obc_tm_pld_hw_pwr_off_enc(tm_data, 1);
        obc_prepare_ipc_msg(tm_data, tm_len, TM_PLD_HW_PWR_OFF ,TM_SRC_OBC);
        os_free(tm_data);
        tm_data = NULL;
    }

    status = TCTM_OK;
    return status;
}
#endif
int8 obc_tc_pld_vm_pwr_off_dec(const uint8 *data)
{
    int8 status;
    os_memcpy(&poi,data,sizeof(icm_vm_pwr_off_info_s));
    DEBUG_CPRINT(("PLD VM Power OFF request received for %d\n",poi.vm_id));

    //Send ICD message request
    obc_encode_icd_cmd(OBC_PS_VM_PWR_OFF_CMD, poi.vm_id, NULL);

    status = TCTM_OK;
    return status;
}
#if 1
int8 obc_tc_ps_pwr_off_dec(const uint8 *data)
{
    int8 status;

#ifdef LINUX_TEMP_PORT
    DEBUG_CPRINT(("PS Power OFF request received\n"));
#else
    eps_ctrl_en_chnl(HW_PL_SERVER,OFF);
#endif
    //Send PS PWR OFF Request
    obc_encode_icd_cmd(OBC_PS_PWR_OFF_CMD,0,NULL);

    status = TCTM_OK;
    return status;
}
#endif

int8 obc_tc_tty_start_dec(const uint8 *data)
{
    int8 status;
    DEBUG_CPRINT(("TTY start request received\n"));

    tm_rsp_id = TM_TTY_START;
    obc_pack_tm_data(NULL);

    status = TCTM_OK;
    return status;
}

int8 obc_tc_tty_end_dec(const uint8 *data)
{
    int8 status;
    DEBUG_CPRINT(("TTY end request received\n"));

    tm_rsp_id = TM_TTY_END;
    obc_pack_tm_data(NULL);

    status = TCTM_OK;
    return status;
}

int8 obc_tc_tty_data_dec(uint8* data, uint8* tc_tty_data, uint32 data_size)
{
    int8 status;
    os_memcpy(tc_tty_data,data,data_size);
    tm_rsp_id = TM_TTY_DEBUG;
    obc_pack_tm_data(NULL);

    status = TCTM_OK;
    return status;
}
/*
 * @brief This API performs the following funtions
 * 1.Sends required TC data for encoding IPCC messages based on the CRRN ID
 * 2.It packs TM response to notify IPCC trigger status.
 */
int16 obc_ipcc_test_tc_dec(uint8 *data)
{
    int8 status;
    uint16_t arg1 = 0;
    obc_pck_data ipcc_trig_resp;
    os_memcpy(&ipcc_test_dec,data,sizeof(ipcc_test_dec));
    DEBUG_CPRINT(("tc decode: %hd\n",ipcc_test_dec));

    if((ipcc_test_dec == 32) || (ipcc_test_dec == 33))
    {
    	obc_encode_icd_cmd(ipcc_test_dec, arg1, data);
    }
    else if((ipcc_test_dec == 3) || (ipcc_test_dec == 4))
    {
        os_memcpy(&arg1, &data[2], sizeof(arg1));
        obc_encode_icd_cmd(ipcc_test_dec, arg1, NULL);
    }
    else
    {
    	obc_encode_icd_cmd(ipcc_test_dec, arg1, NULL);
    }

    ipcc_trig_resp.tm_rsp_id = TM_OBC_IPCC_TEST;
    ipcc_trig_resp.tx_data_len = 2;                 //1Byte to indicate whether the TM is Trigger status or Payload response
                                                    //1Byte to transmit Trigger success status
    ipcc_trig_resp.tx_data = os_malloc_eram(2);
    ipcc_trig_resp.tx_data[0] = OBC_PS_IPCC_TRIG_STS_NTF;
    ipcc_trig_resp.tx_data[1] = IPCC_TRIG_SUCCESS;
    obc_pack_tm_data(&ipcc_trig_resp);
    status = TCTM_OK;
    return status;
}
#if 0
int16 obc_get_dev_temp_info_dec(uint8 *data)
{
	 int8 status;
	if(data[0] == 0)
	{
		/*TODO for OBC*/
	}
	else if(data[0] == 1)
	{
	//ps_get_temp_s ps_get_temp;
	obc_encode_icd_cmd(OBC_PS_TEMP_INFO, 0, NULL);
	}
	else
	{
		/*TODO for Edge*/
	}
	status = TCTM_OK;
	    return status;
//	obc_pack_tm_data(&ipcc_trig_resp);
}

int16 obc_get_dev_time_info_dec(uint8 *data)
{
	 int8 status;
	if(data[0] == 0)
	{
		/*TODO for OBC*/
	}
	else if(data[0] == 1)
	{
	//ps_get_temp_s ps_get_temp;
	obc_encode_icd_cmd(OBC_PS_TIME_INFO, 0, NULL);
	}
	else
	{
		/*TODO for Edge*/
	}
	status = TCTM_OK;
	    return status;
//	obc_pack_tm_data(&ipcc_trig_resp);
}

int16 obc_get_dev_chip_info_dec(uint8 *data)
{
	 int8 status;
	if(data[0] == 0)
	{
		/*TODO for OBC*/
	}
	else if(data[0] == 1)
	{
	//ps_get_temp_s ps_get_temp;
	obc_encode_icd_cmd(OBC_PS_CHIP_INFO, 0,NULL);
	}
	else
	{
		/*TODO for Edge*/
	}
	status = TCTM_OK;
	    return status;
//	obc_pack_tm_data(&ipcc_trig_resp);
}

int16 obc_get_dev_ext_mem_dec(uint8 *data)
{
	 int8 status;
	if(data[0] == 0)
	{
		/*TODO for OBC*/
	}
	else if(data[0] == 1)
	{
	//ps_get_temp_s ps_get_temp;
	obc_encode_icd_cmd(OBC_PS_EXT_MEM, 0, NULL);
	}
	else
	{
		/*TODO for Edge*/
	}
	status = TCTM_OK;
	    return status;
//	obc_pack_tm_data(&ipcc_trig_resp);
}
#endif

int16 obc_ex_mem_test_tc_dec(uint8 *data)
{
    int8 status;

    tm_rsp_id = TM_EXTRNL_MEM_TEST;
#ifndef LINUX_TEMP_PORT
    // TBD: /// 
    os_memcpy(&mem_test_sts,data,sizeof(ext_mem_test_tc_tm_s));
    mem_test_sts.sts = ext_mem_validation(&mem_test_sts);
#endif
    obc_pack_tm_data(NULL);

    status = TCTM_OK;
    return status;
}

int8 obc_mem_debug_tm_send(void)
{
    int8 status;

    tm_rsp_id = TM_MEMD;
    obc_pack_tm_data(NULL);

    status = TCTM_OK;
    return status;
}
#if 0
int8 obc_tc_eps_set_dev_tmr(uint8 *data)
{
	uint8_t eps_sts;
	obc_pck_data eps_data_info;
    int8 status;
#if 0
    eps_dev_tmr_c eps_dev_tmr;
    //uint8_t len = sizeof(eps_dev_tmr_c);
    os_memcpy(&eps_dev_tmr,data,sizeof(eps_dev_tmr_c));
    eps_sts = eps_ctrl_set_pwr_tmr(&eps_dev_tmr);
#ifdef LINUX_TEMP_PORT
    DEBUG_CPRINT(("Decode DATA cnt:%d\n",eps_dev_tmr.ch_tmr_val.on_tmr.max_st_cnt));        
    
    for(uint8_t cnt = 0 ; cnt < eps_dev_tmr.ch_tmr_val.on_tmr.max_st_cnt; cnt++)
    {
      DEBUG_CPRINT(("on_tmr[%d] \n",eps_dev_tmr.ch_tmr_val.on_tmr.st_val[cnt].min));
      DEBUG_CPRINT(("on_tmr[%d] \n",eps_dev_tmr.ch_tmr_val.on_tmr.st_val[cnt].sec));
      DEBUG_CPRINT(("on_tmr[%d] \n",eps_dev_tmr.ch_tmr_val.on_tmr.st_val[cnt].msec));
     }

    DEBUG_CPRINT(("Decode DATA cnt:%d\n",eps_dev_tmr.ch_tmr_val.off_tmr.max_st_cnt));

    for(uint8_t cnt = 0 ; cnt < eps_dev_tmr.ch_tmr_val.on_tmr.max_st_cnt; cnt++)
    {
        DEBUG_CPRINT(("off_tmr[%d] \n",eps_dev_tmr.ch_tmr_val.off_tmr.st_val[cnt].min));
        DEBUG_CPRINT(("off_tmr[%d] \n",eps_dev_tmr.ch_tmr_val.off_tmr.st_val[cnt].sec));
        DEBUG_CPRINT(("off_tmr[%d] \n",eps_dev_tmr.ch_tmr_val.off_tmr.st_val[cnt].msec));
    }
#endif
#endif

    
 	eps_sts = eps_ctrl_set_pwr_tmr((eps_dev_tmr_c *)data);
	eps_data_info.tm_rsp_id = TM_SET_EPS_CTRL_DEV_TMR;
    eps_data_info.tx_data = &eps_sts;
    eps_data_info.tx_data_len = 1;
    obc_pack_tm_data(&eps_data_info);

    status = TCTM_OK;
    return status;

}

int16 obc_tc_eps_btry_thrshld_dec(uint8 *data)
{
    int8 status;
    eps_btry_thrshld_s sat_bat_volt;
    os_memcpy(&sat_bat_volt,data,sizeof(eps_btry_thrshld_s));
    eps_set_btry_thrshld(&sat_bat_volt);

#if LINUX_TEMP_PORT
    uint8 i;
    for(i=0;i<5;i++)
    {
    DEBUG_CPRINT(("Eps battery threshold of %d : %f\n",i,sat_bat_volt.volt[i]));
    }
    #endif

    tm_rsp_id = TM_SET_EPS_BTRY_VOLT_THRSHLD;
    obc_pack_tm_data(NULL);
    status = TCTM_OK;
    return status;
}
#endif

#if 0
int16 obc_tc_eps_ch_pwr_dec(uint8 *data)
{
	eps_ctrlr_err_sts_s eps_ch_pwr_sts;
	obc_pck_data eps_data_info;
    int8 status;
    eps_dev_sts_s eps_dec;
    os_memcpy(&eps_dec,data,sizeof(eps_dev_sts_s));
    eps_ch_pwr_sts = eps_ctrl_en_chnl(eps_dec.ch_no,eps_dec.ch_st);

#ifdef LINUX_TEMP_PORT
    DEBUG_CPRINT(("CHANNEL NO: %d\n",eps_dec.ch_no));
    DEBUG_CPRINT(("STATE: %d\n",eps_dec.ch_st));
#endif

    eps_data_info.tm_rsp_id = TM_SET_EPS_CTRL_CHNL_ST;
    eps_data_info.tx_data_len = 1;
    eps_data_info.tx_data = (uint8_t*)&eps_ch_pwr_sts;
    obc_pack_tm_data(&eps_data_info);

    status = TCTM_OK;
    return status;

}

int8 obc_tc_set_eps_btry_chnl_map(uint8* data)
{
    int8 status;
    eps_ctrlr_err_sts_s eps_btry_chnl_sts;
    obc_pck_data eps_data_info;
    //eps_btry_ch_map_s btry_ch;
    //os_memcpy(&btry_ch,data,sizeof(eps_btry_ch_map_s));
    eps_btry_chnl_sts = eps_ctrl_set_btry_ch_map((eps_btry_ch_map_s *)data);
#if 0    
  eps_btry_chnl_sts = eps_ctrl_set_btry_ch_map(&btry_ch);
  
if(btry_ch.valid_on_cnt == EPS_VALID_ON && btry_ch.auto_on_cnt == EPS_AUTO_ON)
    {
#ifdef LINUX_TEMP_PORT
        DEBUG_CPRINT(("btry chnl map valid : %x \n",btry_ch.valid_on[0]));
        DEBUG_CPRINT(("btry chnl map valid: %x \n",btry_ch.valid_on[1]));
        DEBUG_CPRINT(("btry chnl map valid: %x \n",btry_ch.valid_on[2]));
        DEBUG_CPRINT(("btry chnl map auto on: %x \n",btry_ch.auto_on[0]));
        DEBUG_CPRINT(("btry chnl map auto on : %x \n",btry_ch.auto_on[1]));
        DEBUG_CPRINT(("btry chnl map auto on : %x \n",btry_ch.auto_on[2]));
#endif
#endif
        eps_data_info.tm_rsp_id =TM_SET_EPS_BTRY_CTRL_CH_MAP;
        eps_data_info.tx_data_len = 1;
        eps_data_info.tx_data = (uint8_t*)&eps_btry_chnl_sts;
    obc_pack_tm_data(&eps_data_info);
    status = TCTM_OK;
    //}
    //else 
    //{
      //  status = 1;
    //}
    return status;

}

int8 obc_tc_get_eps_btry_chnl_map(uint8* data)
{
    int8 status;
    tm_rsp_id = TM_GET_EPS_BTRY_CTRL_CH_MAP;
    obc_pack_tm_data(NULL);
   status = TCTM_OK;
   return status;
}

int8 obc_tc_eps_get_hw_sts_dec(uint8* data)

{
    int8 status;

    tm_rsp_id = TM_GET_EPS_DEV_HW_STS;
    obc_pack_tm_data(NULL);
    status = TCTM_OK;
    return status;
}
#endif

int8 obc_tc_set_ssd_heat_coil_periodicty_dec(uint8* tc_data)
{
    int8 status;
	obc_pck_data tm_in;
	uint8_t* ssd_heat_coil_prdcty_ptr = os_malloc_eram(2);
	ssd_heat_coil_prdcty_ptr[0]=tc_data[0];
#ifndef LINUX_TEMP_PORT
    status = set_ssd_heat_coil_periodicity(tc_data[0],(uint32_t)tc_data[1]);
#endif
	os_memcpy(ssd_heat_coil_prdcty_ptr+1,&status,1);
	tm_in.rx_data=ssd_heat_coil_prdcty_ptr;
	tm_in.rx_data_len=2;
	tm_in.tm_rsp_id = TM_SET_SSD_HEAT_COIL_PRDCTY;
    obc_pack_tm_data(&tm_in);
    status = TCTM_OK;
    os_free(ssd_heat_coil_prdcty_ptr);
    return status;

}

int8 obc_tc_ssd_select_dec(uint8 *data)
{
    int8 status;
   
#ifndef LINUX_TEMP_PORT
       set_ssd_slot_slec(data);
#endif
    tm_rsp_id = TM_SET_SSD_SLOT_SELC;
   //  DEBUG_CPRINT(("The recieved ssd select :%d\n",obc_ssd_slec_dec));
    obc_pack_tm_data(NULL);
    status = TCTM_OK;
    return status;

}
int8 obc_tc_ssd_heat_select_dec(uint8_t *data)
{
	    int8 status;
	    set_ssd_heat_coil_enable(data[0], data[1]);
	    obc_pack_tm_data(NULL);
	    status = TCTM_OK;
	    return status;
}
int8 obc_tc_get_ssd_slot_selc(uint8 data)
{
	int8 status;
	obc_pck_data tm_inf;
	uint8_t* ssd_slot_selec_ptr = os_malloc_eram(2);
	ssd_slot_selec_ptr[0]=data;
	ssd_slot_selec_ptr[1]=get_ssd_slot_slec(data);
	tm_inf.rx_data=ssd_slot_selec_ptr;
	tm_inf.rx_data_len=2;
	tm_inf.tm_rsp_id=TM_GET_SSD_SLOT_SELEC;
	obc_pack_tm_data(&tm_inf);
	os_free(ssd_slot_selec_ptr);
	//os_memcpy(&tm_data,sts,1);
	//os_memcpy(&tm_data,sts+1,1);
    status = TCTM_OK;
    return status;
}

int8 obc_tc_get_ssd_heat_coil_selc(uint8 data)
{
	int8 status;
	obc_pck_data tm_in;
	uint8_t* ssd_heat_coil_selec_ptr = os_malloc_eram(2);
	ssd_heat_coil_selec_ptr[0]=data;
	ssd_heat_coil_selec_ptr[1]= get_ssd_heat_coil_sts(data);
	tm_in.rx_data=ssd_heat_coil_selec_ptr;
	tm_in.rx_data_len=2;
	tm_in.tm_rsp_id=TM_GET_SSD_HEAT_COIL_STS;
	obc_pack_tm_data(&tm_in);
	os_free(ssd_heat_coil_selec_ptr);
    status = TCTM_OK;
    return status;
}

int8 obc_tc_get_ssd_heat_coil_periodicity(uint8* data)
{
	int8 status;
	uint32 prdcty;
	obc_pck_data tm_in;
	uint8_t* ssd_heat_coil_prdcty_ptr = os_malloc_eram(5);
	ssd_heat_coil_prdcty_ptr[0]=data[0];
	prdcty= get_ssd_heat_coil_periodicity(data[0]);
	os_memcpy(ssd_heat_coil_prdcty_ptr+1,&prdcty,4);
	tm_in.rx_data=ssd_heat_coil_prdcty_ptr;
	tm_in.rx_data_len=5;
	tm_in.tm_rsp_id=TM_GET_SSD_HEAT_COIL_PRDCTY;
	obc_pack_tm_data(&tm_in);
	os_free(ssd_heat_coil_prdcty_ptr);
    status = TCTM_OK;
    return status;
}

int8 obc_tc_ps_staged_tc_trig(uint8 *data)
{
    int8 status;
    tm_rsp_id = TM_PS_STAGED_TC;
    os_memcpy(&obc_staged_tc_id,data,sizeof(uint32));
#ifdef LINUX_TEMP_PORT
    DEBUG_CPRINT(("Received Trigger for Staged TC ID %u\n",obc_staged_tc_id));
#endif
    obc_encode_icd_cmd(OBC_PS_STAGED_TC_CMD,0, NULL);
    obc_pack_tm_data(NULL);
    status = TCTM_OK;
    return status;
}

int8 obc_tc_log_buf_dwnld_read_set_config(uint16 tele_cmd_id, uint8 *data)
{

    log_data_s log_buff;
    int8 status;

#ifndef LINUX_TEMP_PORT
    uint8_t dwn_size;
#endif

    if(TC_LOG_DOWNLOAD_BLOCKS == tele_cmd_id)
    {
        os_memcpy(&log_buff,data,sizeof(log_buff));
        uint8_t input = log_buff.down_via_tm_or_ftm;
        if(input == 2)
        {
            log_send_logs(log_buff.down_blocks, log_buff.down_mtu, log_buff.sat_ftds, log_buff.seq_loss_enable);
        }
        else
        {
        	log_send_logs_via_telementary(log_buff.down_blocks);

        }
    }
    else if(TC_LOG_LEVEL_FILTER_CONFIG == tele_cmd_id)
    {
        DEBUG_CPRINT(("OBC LOG:%hhu \n",data[0]));
        log_lev_cfg_decode(data);
    }
    else if(TC_READ_LOG_INFO == tele_cmd_id)
    {
        DEBUG_CPRINT(("OBC LOG:%hhu \n",data[0]));
        read_log_info(data);
    }
    else if(TC_LOG_DOWNLOAD_BACKUP_BLOCKS == tele_cmd_id)
    {
    	os_memcpy(&log_buff, data, sizeof(log_buff));
#ifndef LINUX_TEMP_PORT

    	if(log_buff.reserved == 0)
    	{
        	dwn_size = data[7];
        	log_send_backup_data(log_buff.down_blocks, log_buff.down_mtu, log_buff.sat_ftds, log_buff.seq_loss_enable, dwn_size);
    	}
    	else
    	{
    		log_backup_cfg(log_buff.reserved,log_buff.down_mtu);
    	}
#endif
    }


    status = TCTM_OK;
    return status;
}

int8 obc_tc_set_ctrl_flag_tm_buffer()
{
	uint8_t status = 0;
	obc_pck_data tm_pack;
	tm_buff_ctrl_flag = 1; //set control flag
	tm_pack.tx_data = os_malloc_eram(1);
	tm_pack.tx_data[0] = tm_buff_ctrl_flag;
	tm_pack.tx_data_len = 1;
	tm_pack.tm_rsp_id = TM_SET_CONTROL_FLAG_TM_BUFFER;
	obc_pack_tm_data(&tm_pack);

	status = TCTM_OK;
    return status;
}

int8 obc_tc_set_comms_tm_dlreq()
{
	uint8_t status = 0, ipc_send_sts;
//	obc_pck_data tm_pack;
	os_itc_msg_handle_t comms_gs_pass_ipc;
	os_memset(&comms_gs_pass_ipc, 0, sizeof(comms_gs_pass_ipc));
    // Prepare IPC data to TM manager - Simulation of comms ipc message to indicate ground pass
	comms_gs_pass_ipc.src_entity = COMMS_SBAND_CTLR;
	comms_gs_pass_ipc.pld.pld_ptr = NULL;
	comms_gs_pass_ipc.Msg_id= TC_TM_STORAGE_TM_DLREQ;

    ipc_send_sts = os_itc_msg_send(&comms_gs_pass_ipc,
            TM_STORAGE,
            os_send_itc_wait);
    (void)ipc_send_sts;
/*
	tm_pack.tx_data = os_malloc_eram(1);
	tm_pack.tx_data[0] = ipc_send_sts;
	tm_pack.tx_data_len = 1;
	tm_pack.tm_rsp_id = TM_SET_COMMS_TM_DLREQ;
	obc_pack_tm_data(&tm_pack);*/

	status = TCTM_OK;
	return status;
}


int8 obc_conops_sch_lut_ctrl(uint8 *data)
{
    uint8_t status,sch_ctrl_rsp=0;
	obc_pck_data tm_pack;

	sch_ctrl_rsp = conops_sch_lut_trig_req(data);  // os malloc need to be added
	tm_pack.tx_data = os_malloc_eram(1);
    tm_pack.tx_data[0] = sch_ctrl_rsp;
    tm_pack.tx_data_len = 1;
    tm_pack.tm_rsp_id = TM_CONOPS_SCH_LUT_RUN_CTRL;
    obc_pack_tm_data(&tm_pack);

	 status = TCTM_OK;
	 return status;
}

int8 obc_conops_sch_status_check(uint8 *data)
{
	obc_pck_data tm_pack;

	uint8_t *tx_data = NULL;
    conops_sch_lut_info_tm_pack(data[0], &tx_data, &tm_pack.tx_data_len);
    tm_pack.tx_data = tx_data;
    tm_pack.tm_rsp_id = TM_CONOPS_SCH_STS_INFO;
    obc_pack_tm_data(&tm_pack);

	 return TCTM_OK;
}




int8 obc_tc_deffered_strg(uint8 *data)
{
    int8 status;
    s_tc_defferd_strg strg_strct;
    uint8* tm_data;
    uint16 tm_len;
    ptr_typ tc_def_ptr = 0;
    os_memcpy(&strg_strct.wrt_offset,data, 4);
    os_memcpy(&strg_strct.data_len,&data[4], 2);
#ifndef LINUX_TEMP_PORT
    os_memcpy((void *)tc_storage+(strg_strct.wrt_offset),&data[6],strg_strct.data_len);

    tc_def_ptr = (ptr_typ)(tc_storage+(strg_strct.wrt_offset));
#else
    // File operation variable decleration
    //uint16 line_no = 0;
    int itr = 0;
    FILE *fp;
    //const unsigned MAX_LENGTH = 1024;
    //char buffer[MAX_LENGTH];
    uint32 file_offset = 0;

    // Open file in both reading and writing mode
    fp = fopen("tc_deffered_strng.txt", "r+");
    if(fp == NULL)
    {
        // Create a file there's no existing file
        fp = fopen("tc_deffered_strng.txt", "a+");
        DEBUG_CPRINT(("Deffered String File Created\n"));
    }
    if(fp != NULL)
    {
        // Set file pointer to offset
        file_offset = strg_strct.wrt_offset * 5;
        fseek(fp, file_offset, SEEK_SET);
#if 0
        // To point file cursor to start of the file
        fseek(fp, 0, SEEK_SET);
        if(strg_strct.wrt_offset)
        {
            // To point at the selected line
            while(line_no < strg_strct.wrt_offset-1)
            {
                fgets(buffer, MAX_LENGTH, fp);
                // Add new line character if file reaches the end
                if (feof(fp))
                {
                    fprintf(fp,"\n");
                }
                line_no++;
            }
        } 

        // Delete the existing line if already available
        ftruncate(fileno(fp), ftell(fp));
#endif
        // Write data to the file
        for(itr = 0; itr < strg_strct.data_len; itr++)
        {
            fprintf(fp,"0x%02x,", data[6+itr]);
        }
        //fprintf(fp,"\n");
        // Close the file
        fclose(fp);
    }
    else
    {
        DEBUG_CPRINT(("Deffered String File Open failed\n"));
    }
    tc_def_ptr = (ptr_typ)strg_strct.wrt_offset;
#endif
    tm_len = 4;
    tm_data = os_malloc_eram(tm_len);
    os_memcpy(tm_data, &tc_def_ptr, tm_len);
    obc_prepare_ipc_msg(tm_data, tm_len, TM_DEFERRED_STRG,TM_SRC_OBC);
    os_free(tm_data);
    tm_data = NULL;
    status = TCTM_OK;
    return status;
}

uint8_t get_security_sts()
{
	//0 - disable //1-enable
	nvm_parameter_read(NVM_DATA,RSVD_BIT_3,(uint8_t*)&security_sts);
	return security_sts;
}

void set_security_sts(uint8_t sec_sts)
{
	security_sts=sec_sts;
	nvm_parameter_write(NVM_DATA,RSVD_BIT_3,(uint8_t*)&security_sts);
}

uint8_t get_authentication_sts()
{
	//0 - disable //1-enable
	nvm_parameter_read(NVM_DATA,RSVD_BIT_4,(uint8_t*)&authentication_sts);
	return authentication_sts;
}

void set_authentication_sts(uint8_t auth_sts)
{
	authentication_sts=auth_sts;
	nvm_parameter_write(NVM_DATA,RSVD_BIT_4,(uint8_t*)&authentication_sts);
}

uint8_t get_radio_id()
{
    uint8_t rm_id=0;
    nvm_parameter_read(NVM_DATA,RSVD_BIT_7,(uint8_t*)&rm_id);
    if(rm_id < MAX_RADIO_MOD)
    {
        def_radio_id = rm_id;
    }
    else
    {
        def_radio_id = DEFAULT_RADIO_ID;
        nvm_parameter_write(NVM_DATA,RSVD_BIT_7,(uint8_t*)&def_radio_id);
    }
    def_radio_id = 0;
    return def_radio_id;
}

void set_radio_id(uint8_t rm_id)
{
    if(rm_id < MAX_RADIO_MOD)
    {
        def_radio_id = rm_id;
        nvm_parameter_write(NVM_DATA,RSVD_BIT_7,(uint8_t*)&def_radio_id);
    }
}

int8 obc_mem_data_dec(uint8* data)
{
	obc_pck_data nvm_pck_data;
    int8 status;
    ptr_typ address;
    uint16 len;
    nvm_param *nvm_data = (nvm_param *) data;
    uint8_t offset = 0;
    uint8_t *nvm_data_ptr_temp = NULL;
    uint16_t data_len = nvm_data->len;
    address = nvm_data->address;
    switch(nvm_data->mode)
    {
    // (0 - Read/1 - Write/2 - Flash_Read/3 - Flash_write_witherase/4 - Flash_write_withouterase/5 - NVM_Read/6 - NVM_Write
    // /7 - Flash_Erase
    // /8-encryption_disabled/9-encryption_enabled/10-authentication disabled/11-authentication enabled)
    case 8:
    	DEBUG_CPRINT(("mode_8\n"));
    	set_security_sts(0);
    	break;
    case 9:
    	DEBUG_CPRINT(("mode_9\n"));
    	set_security_sts(1);
    	break;
    case 10:
    	DEBUG_CPRINT(("mode_10\n"));
    	set_authentication_sts(0);
    	break;
    case 11:
    	DEBUG_CPRINT(("mode_11\n"));
    	set_authentication_sts(1);
    	break;
    case 7:
    {
		switch(nvm_data->mem_type)
		{
			case MEM_TYPE_IFLASH:
			case MEM_TYPE_NOR_FLASH:
			case MEM_TYPE_QSPI:
			{
#ifndef LINUX_TEMP_PORT
				flash_sector_erase_by_add_n_len((uint8_t*)address,data_len,nvm_data->mem_type);
#endif
			}
			break;
    	}
    }
    break;

		case 5:                         //NVM READ
        {
            nvm_data_ptr_temp = os_malloc_eram(nvm_data->len);
            nvm_parameter_read(NVM_DATA,nvm_data->address,(uint8_t*)nvm_data_ptr_temp);
            address = (ptr_typ)nvm_data_ptr_temp;
        }
	case 2:
        case 0:                         //RAM READ
        {


            if(nvm_data->mode == 2)
            {

                if(nvm_data_ptr_temp == NULL)
                {
                    nvm_data_ptr_temp = os_malloc_eram(nvm_data->len);
                }
                os_memcpy_extmem(nvm_data_ptr_temp,(uint8_t*)nvm_data->address,nvm_data->len,NULL,1,1);
                address = (ptr_typ)nvm_data_ptr_temp;
            }
            nvm_data_hdr = os_malloc_eram(sizeof(nvm_param));
            nvm_data_hdr->mode = nvm_data->mode;
            nvm_data_hdr->mem_type = nvm_data->mem_type; // type
            nvm_pck_data.tx_data_len = sizeof(nvm_param);
            //nvm_pck_data.tx_data = os_malloc_eram(nvm_pck_data.tx_data_len);

            while(data_len>0)
            {
                if(data_len >= MEM_DATA_LEN)
                {
                    len = MEM_DATA_LEN;
                    //tm_rsp_id = TM_NVM;
                    nvm_pck_data.tm_rsp_id = TM_NVM;

                    nvm_data_hdr->address =address + offset;
                    nvm_data_hdr->len =  len;
                    nvm_pck_data.tx_data = (uint8_t*)nvm_data_hdr;
                   // obc_pack_tm_data(nvm_data_hdr);
                    obc_pack_tm_data(&nvm_pck_data);
                    //nvm_flag++;
                }
                else if(data_len < MEM_DATA_LEN)
                {
                    len = data_len;
                    nvm_data_hdr->address =address + offset;
                    nvm_data_hdr->len =  len;
                    //tm_rsp_id = TM_NVM;
                    nvm_pck_data.tm_rsp_id = TM_NVM;
                    nvm_pck_data.tx_data = (uint8_t*)nvm_data_hdr;
                    //obc_pack_tm_data(nvm_data_hdr);
                    obc_pack_tm_data(&nvm_pck_data);
                }
                offset += len;
                data_len = data_len - len;
            }

			if(nvm_data_ptr_temp)
			{
				os_free(nvm_data_ptr_temp);
				nvm_data_ptr_temp = NULL;
			}
			}
			break;

		case 4:						//4 - Flash_write_withouterase
		{
			switch(nvm_data->mem_type)
			{
			case MEM_TYPE_IFLASH:
			case MEM_TYPE_NOR_FLASH:
			case MEM_TYPE_QSPI:
				{
					nvm_data_ptr_temp = data+sizeof(nvm_param);
					//call write function
					os_memcpy_extmem((uint8_t*)nvm_data->address,nvm_data_ptr_temp,nvm_data->len,NULL,1,0);
				}
				break;
			}
		}
		break;

		case 3:						//3 - Flash_write_witherase
		{
			switch(nvm_data->mem_type)
			{
				case MEM_TYPE_IFLASH:
				case  MEM_TYPE_NOR_FLASH:
				case MEM_TYPE_QSPI:
				{
					nvm_data_ptr_temp = data+sizeof(nvm_param);
					//call erase function
					//flash_sector_erase_by_add_n_len((uint8_t*)address,data_len,nvm_data->mem_type);
					//call write function
					os_memcpy_extmem((uint8_t*)nvm_data->address,nvm_data_ptr_temp,nvm_data->len,NULL,1,1);
				}
				break;
			}
		}
		break;

        case 1:                  //RAM WRITE
        {
            nvm_data_ptr_temp = data+sizeof(nvm_param);
//            os_memcpy((uint8_t*)nvm_data->address,nvm_data_ptr_temp,nvm_data->len);
            os_memcpy_extmem((uint8_t*)nvm_data->address,nvm_data_ptr_temp,nvm_data->len,NULL,1,1);
        }
        break;

        case 6:                 //NVM WRITE
        {
            nvm_data_ptr_temp = data+sizeof(nvm_param);
                nvm_parameter_write(NVM_DATA,nvm_data->address,(uint8_t*)nvm_data_ptr_temp);
        }
        break;
        default:
        {
            DEBUG_CPRINT(("Invalid mode\n"));
        }
        break;
    }
    status = TCTM_OK;
    return status;
}


int8 obc_set_gs_contact(uint8 *data)
{
    int8 status;
    uint8 gs_cntct;
    uint8* tm_data;
    uint16 tm_len;
    os_status_t obc_ipc_sts;
    os_itc_msg_handle_t obc_send_ipc_gs_cntct;
    os_memcpy(&gs_cntct, data, 1);
    // src_entity is mentioned as COMMS_SBAND_CTLR for simulation purpose
    obc_send_ipc_gs_cntct.src_entity = COMMS_SBAND_CTLR;
    if(1 == gs_cntct)
    {
        obc_send_ipc_gs_cntct.Msg_id = SBAND_TC_TM_ST_REQ;
    }
    else
    {
        obc_send_ipc_gs_cntct.Msg_id = SBAND_TC_TM_STOP_REQ;
    }
    obc_send_ipc_gs_cntct.pld.pld_ptr = NULL;
    obc_ipc_sts = os_itc_msg_send(&obc_send_ipc_gs_cntct,
                                  TM_STORAGE,
                                  os_send_itc_wait);

    if(ral_success == obc_ipc_sts)
    {
        status = 0;
    }
    else
    {
        status = 1;
    }

    tm_len = 1;
    tm_data = os_malloc_eram(tm_len);
    os_memcpy(tm_data, &status, tm_len);
    obc_prepare_ipc_msg(tm_data, tm_len, TM_MNGR_GS_CONTACT,TM_SRC_OBC);
    /* TBD: Check whether this free is needed here */
    os_free(tm_data);
    tm_data = NULL;
    status = TCTM_OK;
    return status;

}
#if 0
int8 obc_get_eps_buffer_dec(uint8* data)
{
    int8 status;

    switch(data[0])
    	{
    	case  EPS_GS_GET_CONV_BRD_BUFF:
    		eps_get_buf = (uint8_t*) os_malloc_eram(sizeof(eps_get_conv_brd_tmr_s)*EPS_RD_BFR_MAX_SIZE+1);
    		eps_get_buff_len = sizeof(eps_get_conv_brd_tmr_s)*EPS_RD_BFR_MAX_SIZE+1;
    		break;

    	case EPS_GS_GET_BTRY_BRD_BUFF:
    		eps_get_buf = (uint8_t*) os_malloc_eram(sizeof(eps_get_btry_brd_tmr_s)*EPS_RD_BFR_MAX_SIZE+1);
    		eps_get_buff_len = sizeof(eps_get_btry_brd_tmr_s)*EPS_RD_BFR_MAX_SIZE+1;
    		break;

    	case EPS_GS_GET_CHNL_PARM_BUFF:
    		eps_get_buf = (uint8_t*) os_malloc_eram(sizeof(eps_get_chnl_par_tmr_s)*EPS_RD_BFR_MAX_SIZE+1);
    		eps_get_buff_len = sizeof(eps_get_chnl_par_tmr_s)*EPS_RD_BFR_MAX_SIZE+1;
    		break;

    	case EPS_GS_GET_ALRT_BRD_BUFF:
    		eps_get_buf = (uint8_t*) os_malloc_eram(sizeof(eps_alert_flag_tmr_s)*EPS_RD_BFR_MAX_SIZE+1);
    		eps_get_buff_len = sizeof(eps_alert_flag_tmr_s)*EPS_RD_BFR_MAX_SIZE+1;
    		break;
    	}
    eps_gs_read_buffer(eps_get_buf,data[0]);

    
    tm_rsp_id = TM_EPS_GET_BUFFER;
    obc_pack_tm_data(NULL);
   status = TCTM_OK;
   return status;
}
#endif

int8 obc_eps_get_health_sts_dec(uint8* data)
{
    int8 status;
   // obc_eps_get_hlth_info();
    tm_rsp_id = TM_EPS_HEALTH_STS;
    obc_pack_tm_data(NULL);
   status = TCTM_OK;
    return status;
}
#if 0
int8 obc_eps_crc_sts(uint8* data)
{
int8 status;
//sat_crc_sts sat_crc_sts_s;
//os_memcpy(&sat_crc_sts_s,data,sizeof(sat_crc_sts));
tm_rsp_id = TM_EPS_GET_CRC;

obc_pack_tm_data(NULL);

status = TCTM_OK;
return status;

}
#endif

#ifndef LINUX_TEMP_PORT
int8 obc_get_cpu_stats(uint8* data)
{
    int8 status;

    obc_pck_data tm_data_info;

    /** Update the TM response id */
    tm_data_info.tm_rsp_id = TM_GET_PROC_UTIL_INFO;

    /** Get the CPU stats */
    obc_get_cpu_load(&tm_data_info);

    /** Pack the TM back to GS */
    obc_pack_tm_data(&tm_data_info);

    /** free the pointer allocated inside task_stats */
    if(tm_data_info.rx_data)
    {
        os_free(tm_data_info.rx_data);
    }

    status = TCTM_OK;
    return status;
}
#endif
int8 obc_tc_flush_queue(uint8* data)
{
	int8 status;
	uint16_t flush_cnt;
	os_memcpy(&flush_cnt,data,sizeof(flush_cnt));
	obc_send_ipc_msg_pld(TM_STORAGE_FLUSH_REQ,TM_STORAGE,(uint8_t*)&flush_cnt,2);
#if 0
	tm_rsp_id = TM_TCTM_DEQUEUE;
	obc_pack_tm_data();
#endif
	status = TCTM_OK;
	return status;
}

int8 obc_get_tctm_dbg_info()
{
    int8 status;

    obc_pck_data tm_data_info;

    /** Update the TM response id */
    tm_data_info.tm_rsp_id = TM_GET_TCTM_DBG_INFO;

    /** 1 byte status, 1 byte dbg info count, tc dbg info & tm dbg info */
    tm_data_info.rx_data_len = 2 + ((sizeof(s_tc_dbg_info) + sizeof(s_tm_dbg_info)) * MAX_TCTM_DBG_INFO);
    tm_data_info.rx_data = os_malloc(tm_data_info.rx_data_len);

    /** Get TCTM debu information in rx_data */
    get_tc_tm_dbg_info(&tm_data_info.rx_data[2]);

    /** Assign status */
    tm_data_info.rx_data[0] = 0;
    /** Assign debug info max count */
    tm_data_info.rx_data[1] = MAX_TCTM_DBG_INFO;

    /** Pack the TM back to GS */
    obc_pack_tm_data(&tm_data_info);

    status = TCTM_OK;
    return status;
}

/*********************************************************************************/
/******************* TeleCommand Encode Functions ********************************/
/*********************************************************************************/

/*!
 * @brief This API encodes the Telemetry payload for
 * Target pointing request
 */

int8 obc_tm_obc_sw_rst_enc(uint8* data, uint32 tm_sw_rst_typ)
{
    int8 status;

    os_memcpy(data,&tm_sw_rst_typ,4);

    status = TCTM_OK;
    return status;
}

int8 obc_tm_set_min_reboot_enc(uint8* data, uint32 rbt_tm_sts)
{
    int8 status;

    os_memcpy(data,&rbt_tm_sts,4);

    status = TCTM_OK;
    return status;
}


int8 obc_tm_temp_sns_param_enc(uint8* data, uint32 temp_sen_set_parm_sts)
{
    int8 status;

    os_memcpy(data,&temp_sen_set_parm_sts,4);

    status = TCTM_OK;
    return status;
}

int8 obc_tm_dgtl_thrmst_param_enc(uint8* data, uint32 dig_therm_set_parm_sts)
{
    int8 status;

    os_memcpy(data,&dig_therm_set_parm_sts,4);

    status = TCTM_OK;
    return status;
}

int8 obc_tm_imu_param_enc(uint8* data, uint32 imu_set_parm_sts)
{
    int8 status;

    os_memcpy(data,&imu_set_parm_sts,4);

    status = TCTM_OK;
    return status;
}

int8 obc_tm_thrstr_cntlr_param_enc(uint8* data, uint32 thruster_ctrl_set_parm_sts)
{
    int8 status;

    os_memcpy(data,&thruster_ctrl_set_parm_sts,4);

    status = TCTM_OK;
    return status;
}

int8 obc_tm_data_lgr_param_enc(uint8* data, uint32 data_log_set_parm_sts)
{
    int8 status;

    os_memcpy(data,&data_log_set_parm_sts,4);

    status = TCTM_OK;
    return status;
}

int8 obc_tm_gpio_exp_param_enc(uint8* data, uint32 gpio_exp_set_parm_sts)
{
    int8 status;

    os_memcpy(data,&gpio_exp_set_parm_sts,4);

    status = TCTM_OK;
    return status;
}

int8 obc_tm_pwr_mon_param_enc(uint8* data, uint32 pwr_mon_set_param_sts)
{
    int8 status;

    os_memcpy(data,&pwr_mon_set_param_sts,4);

    status = TCTM_OK;
    return status;
}

int8 obc_tm_vlt_ctlr_param_enc(uint8* data, uint32 vlt_ctlr_set_param_sts)
{
    int8 status;

    os_memcpy(data,&vlt_ctlr_set_param_sts,4);

    status = TCTM_OK;
    return status;
}

int8 obc_tm_pwr_seq_mon_param_enc(uint8* data, uint32 pwr_seq_mon_set_param_sts)
{
    int8 status;

    os_memcpy(data,&pwr_seq_mon_set_param_sts,4);

    status = TCTM_OK;
    return status;
}

int8 obc_tm_schedule_deploy_rsp_enc(uint8* data, uint32 rsp_sts)
{
    int8 status;

    memcpy(data,&rsp_sts,4);

    status = TCTM_OK;
    return status;
}


int8 tm_set_cur_time_enc(uint8* data, uint8_t *cur_time_rsp_sts)
{
    int8 status;
    
    os_memcpy(data,cur_time_rsp_sts,sizeof(sys_time_date_s));
    status = TCTM_OK;
    return status;
}
#if 0
int8 obc_tm_get_eps_var_info(uint8* data, eps_get_var_data_s *eps_var_info)
{
    int8 status;

    /* Encode data parameters */
    os_memcpy(data,eps_var_info,sizeof(eps_get_var_data_s));

    status = TCTM_OK;
    return status;
}
#endif
/*!
 * @brief This API encodes the Telemetry payload for
 * PS power ON
 */
int8 obc_tm_ps_pwr_on_enc(uint8* data, uint32 ps_pwr_on_rsp_sts)
{
    int8 status;

    os_memcpy(data,&ps_pwr_on_rsp_sts,4);

    status = TCTM_OK;
    return status;
}

int8 obc_tm_tty_end_enc(uint8* data, uint32 tty_end_rsp_sts)
{
    int8 status;

    os_memcpy(data,&tty_end_rsp_sts,4);

    status = TCTM_OK;
    return status;
}

int8 obc_tm_tty_data_enc(uint8* data,uint8* tty_data,uint32 data_size)
{
    int8 status;

    os_memcpy(data,tty_data,data_size);

    status = TCTM_OK;
    return status;
}

int8 obc_tm_tty_start_enc(uint8* data, uint32 tty_start_rsp_sts)
{
    int8 status;

    os_memcpy(data,&tty_start_rsp_sts,4);

    status = TCTM_OK;
    return status;
}

int8 obc_tm_spi_intf_rsp_enc(uint8* data, uint32 spi_intf_param_rsp_sts)
{
    int8 status;

    /* Encode data parameters */
    os_memcpy(data,&spi_intf_param_rsp_sts,4);
    status = TCTM_OK;

    return status;
}

int8 obc_tm_ethernet_intf_rsp_enc(uint8* data, uint32 eth_intf_param_rsp_sts)
{
    int8 status;

    /* Encode data parameters */
    os_memcpy(data,&eth_intf_param_rsp_sts,4);
    status = TCTM_OK;

    return status;
}

int8 obc_tm_can_intf_rsp_enc(uint8* data, uint32 can_intf_param_rsp_sts)
{
    int8 status;

    /* Encode data parameters */
    os_memcpy(data,&can_intf_param_rsp_sts,4);
    status = TCTM_OK;

    return status;
}

int8 obc_tm_i2c_intf_rsp_enc(uint8* data, uint32 i2c_intf_param_rsp_sts)
{
    int8 status;

    /* Encode data parameters */
    os_memcpy(data,&i2c_intf_param_rsp_sts,4);
    status = TCTM_OK;

    return status;
}

int8 obc_tm_usb_intf_rsp_enc(uint8* data, uint32 usb_intf_param_rsp_sts)
{
    int8 status;

    /* Encode data parameters */
    os_memcpy(data,&usb_intf_param_rsp_sts,4);
    status = TCTM_OK;

    return status;
}

int8 obc_tm_uart_intf_rsp_enc(uint8* data, uint32 uart_intf_param_rsp_sts)
{
    int8 status;

    /* Encode data parameters */
    os_memcpy(data,&uart_intf_param_rsp_sts,4);
    status = TCTM_OK;

    return status;
}

int8 obc_tm_spi_intf_param_enc(uint8* data, tctm_spi_init_s *spii)
{
    int8 status;

    /* Encode data parameters */
    os_memcpy(data,spii,sizeof(tctm_spi_init_s));
    status = TCTM_OK;

    return status;
}

int8 obc_tm_ethernet_intf_param_enc(uint8* data, tctm_ethernet_init_s *eth)
{
    int8 status;

    /* Encode data parameters */
    os_memcpy(data,eth,sizeof(tctm_ethernet_init_s));
    status = TCTM_OK;

    return status;
}

int8 obc_tm_can_intf_param_enc(uint8* data, tctm_can_init_s *cis)
{
    int8 status;

    /* Encode data parameters */
    os_memcpy(data,cis,sizeof(tctm_can_init_s));
    status = TCTM_OK;

    return status;
}

int8 obc_tm_i2c_intf_param_enc(uint8* data, tctm_i2c_init_s *i2ci)
{
    int8 status;

    /* Encode data parameters */
    os_memcpy(data,i2ci,sizeof(tctm_i2c_init_s));
    status = TCTM_OK;

    return status;
}

int8 obc_tm_usb_intf_param_enc(uint8* data, tctm_usb_otg_cfg_s *usbo)
{
    int8 status;

    /* Encode data parameters */
    os_memcpy(data,usbo,sizeof(tctm_usb_otg_cfg_s));
    status = TCTM_OK;

    return status;
}

int8 obc_tm_uart_intf_param_enc(uint8* data, tctm_uart_init_s *uarti)
{
    int8 status;

    /* Encode data parameters */
    os_memcpy(data,uarti,sizeof(tctm_uart_init_s));
    status = TCTM_OK;

    return status;
}
#if 0
int8 obc_tm_pld_hw_pwr_on_enc(uint8* data, uint32 pld_hw_pwr_on_rsp_sts)
{
    int8 status;

    os_memcpy(data,&pld_hw_pwr_on_rsp_sts,4);

    status = TCTM_OK;
    return status;
}
#endif
int8 obc_tm_pld_vm_pwr_on_enc(uint8* data, uint32 pld_vm_pwr_on_rsp_sts)
{
    int8 status;

    os_memcpy(data,&pld_vm_pwr_on_rsp_sts,4);

    status = TCTM_OK;
    return status;
}
#if 0
int8 obc_tm_pld_hw_pwr_off_enc(uint8* data, uint32 pld_hw_pwr_off_rsp_sts)
{
    int8 status;

    os_memcpy(data,&pld_hw_pwr_off_rsp_sts,4);

    status = TCTM_OK;
    return status;
}
#endif
int8 obc_tm_pld_vm_pwr_off_enc(uint8* data, uint32 pld_vm_pwr_off_rsp_sts)
{
    int8 status;

    os_memcpy(data,&pld_vm_pwr_off_rsp_sts,4);

    status = TCTM_OK;
    return status;
}
#if 1
int8 obc_tm_ps_pwr_off_enc(uint8* data, uint32 ps_pwr_off_rsp_sts)
{
    int8 status;

    os_memcpy(data,&ps_pwr_off_rsp_sts,4);

    status = TCTM_OK;
    return status;
}
#endif
int8 obc_tm_temp_sns_cfg_enc(uint8* data, temp_sens_cfg *sns_inf)
{
    int8 status;

    /* Encode data parameters */

    os_memcpy(data,sns_inf,sizeof(temp_sens_cfg));

    status = TCTM_OK;
    return status;
}


int8 obc_tm_dgtl_thrm_info_enc(uint8* data, digital_thermostat_cfg *sns_inf)
{
    int8 status;

    /* Encode data parameters */

    os_memcpy(data,sns_inf,sizeof(digital_thermostat_cfg));

    status = TCTM_OK;
    return status;
}

int8 obc_tm_thruster_ctlr_info_enc(uint8* data, thruster_info *sns_inf)
{
    int8 status;

    /* Encode data parameters */
    sns_inf->calib_data_cnt = SNS_CALIB_DATA_CNT;
    os_memcpy(data,sns_inf,sizeof(thruster_info));
    status = TCTM_OK;
    return status;
}

int8 obc_tm_imu_info_enc(uint8* data, imu_info *sns_inf)
{
    int8 status;

    /* Encode data parameters */

    os_memcpy(data,sns_inf,sizeof(imu_info));

    status = TCTM_OK;
    return status;
}

int8 obc_tm_gpio_exp_info_enc(uint8* data, gpio_exp_cfg *sns_inf)
{
    int8 status;

    /* Encode data parameters */

    os_memcpy(data,sns_inf,sizeof(gpio_exp_cfg));

    status = TCTM_OK;
    return status;
}

int8 obc_tm_data_log_info_enc(uint8* data, data_acq_dvc_info *sns_inf)
{
    int8 status;

    /* Encode data parameters */

    os_memcpy(data,sns_inf,sizeof(data_acq_dvc_info));

    status = TCTM_OK;
    return status;
}

int8 obc_tm_get_sns_data_enc(uint8* data, void* src_buff, uint32_t len)
{
    int8 status;
	os_memcpy(data,&sns_ahw_id,4);
	os_memcpy((data+4),src_buff,len-4);
    status = TCTM_OK;
    return status;
}
int8 obc_tm_pwr_seq_mtr_info_enc(uint8* data, voltage_seq_mntr_cfg *sns_inf)
{
    int8 status;

    /* Encode data parameters */

    os_memcpy(data,sns_inf,sizeof(voltage_seq_mntr_cfg));

    status = TCTM_OK;
    return status;
}

int8 obc_tm_vltg_ctlr_info_enc(uint8* data, hotswap_cntlr_cfg *sns_inf)
{
    int8 status;

    /* Encode data parameters */

    os_memcpy(data,sns_inf,sizeof(hotswap_cntlr_cfg));

    status = TCTM_OK;
    return status;
}

int8 obc_tm_pwr_mon_info_enc(uint8* data, power_sense_mntr_cfg *sns_inf)
{
    int8 status;

    /* Encode data parameters */
    os_memcpy(data,sns_inf,sizeof(power_sense_mntr_cfg));

    status = TCTM_OK;
    return status;
}

int8 obc_tm_eps_enc(uint8 *data,uint8_t eps_sts)
{
    int8 status;

    os_memcpy(data,&eps_sts,sizeof(eps_sts));

    status = TCTM_OK;
    return status;
}

int8 obc_tm_btry_enc(uint8 *data,uint8_t btry_sts)
{
    int8 status;

    os_memcpy(data,&btry_sts,sizeof(btry_sts));

    DEBUG_CPRINT(("tm encode\n"));
    status = TCTM_OK;
    return status;
}

int8 obc_tm_ps_staged_tc_enc(uint8 *data,uint8_t rsp_sts)
{
    int8 status;

    os_memcpy(data,&rsp_sts,sizeof(rsp_sts));

    DEBUG_CPRINT(("tm encode\n"));
    status = TCTM_OK;
    return status;
}

int8 obc_tm_btry_volt_enc(uint8 *data,uint8_t btry_sts)
{
    int8 status;

    os_memcpy(data,&btry_sts,sizeof(btry_sts));

    DEBUG_CPRINT(("tm encode\n"));
    status = TCTM_OK;
    return status;
}




#if 0
int8 obc_tm_set_eps_btry_chnl_map(uint8* data)
{
	//eps_btry_ch_map_s btry_ch;
    int8 status;
    eps_ctrl_set_btry_ch_map((eps_btry_ch_map_s *)data);
#if 0
    os_memcpy(&btry_ch,data,sizeof(eps_btry_ch_map_s));
    eps_ctrl_set_btry_ch_map(&btry_ch);
#endif
    status = TCTM_OK;
    return status;
}

int8 obc_tm_get_eps_btry_chnl_map(uint8* data)
{
	//eps_btry_ch_map_s btry_ch;
	//eps_ctrlr_err_sts_s eps_ctrl_btry_sts;
    int8 status = 0;
    data[0] = eps_ctrl_get_btry_ch_map((eps_btry_ch_map_s *)&data[1]);
#if 0
    eps_ctrl_btry_sts = eps_ctrl_get_btry_ch_map(&btry_ch);
    os_memcpy(data,&eps_ctrl_btry_sts,1);
    os_memcpy(data+1,&btry_ch,sizeof(eps_btry_ch_map_s));

#if LINUX_TEMP_PORT
	DEBUG_CPRINT(("btry chnl : %x \n",btry_ch.valid_on[0]));
	DEBUG_CPRINT(("btry chnl : %x \n",btry_ch.valid_on[1]));
	DEBUG_CPRINT(("btry chnl : %x \n",btry_ch.valid_on[2]));

	DEBUG_CPRINT(("btry chnl : %x \n",btry_ch.auto_on[0]));
	DEBUG_CPRINT(("btry chnl : %x \n",btry_ch.auto_on[1]));
	DEBUG_CPRINT(("btry chnl : %x \n",btry_ch.auto_on[2]));
#endif
#endif
    status = TCTM_OK;
    return status;
}
#endif
int8  obc_tm_ssd_select_enc(uint8* data,uint32* obc_ssd_slec_resp)
{
     int8 status;
     os_memcpy(data,obc_ssd_slec_resp,4);
    status = TCTM_OK;
    return status;
}

int8 obc_tm_ssd_heat_select_enc(uint8* data,uint32* obc_ssd_heat_slec_resp)
{
    int8 status;
    os_memcpy(data,obc_ssd_heat_slec_resp,4);
    status = TCTM_OK;
     return status;
}

int8 obc_tm_mem_data_enc(uint8* data,nvm_param *rec_data)
{
    int8 status;
    if(rec_data->mode == 0 || rec_data->mode == 2 || rec_data->mode == 5)
    {
    os_memcpy(data,rec_data,sizeof(nvm_param));
#ifndef LINUX_TEMP_PORT
    os_memcpy(data+sizeof(nvm_param),(uint8_t*)rec_data->address,rec_data->len);
#endif
    }
    status = TCTM_OK;
    return status;
}
#if 0
int8 obc_eps_get_hlth_info(uint8* data)
{
    int8 status;
    eps_gs_hlth_chk(data);
  //  eps_gs_hlth_chkt(data,size);
    status = TCTM_OK;
    return status;
}
#endif

void obc_pack_tm_data(obc_pck_data *tm_data_info)
{
    /*Control variable - Incements when every TM packed*/
    exo_sw_dbg.obc_dbg.no_tm_pakd++;
    int status = 0;
    uint32_t mem_debug_data=0;
    uint16_t ver = 0;
    sys_time_date_s time_date;

    //sensor_info_init();
    uint16 tm_len = 0;
    uint8 *tm_data = NULL;
   // eps_err_sts eps_sts=EPS_SUCCESS;
    /* Send buffer and frame memory allocations */
if(tm_data_info != NULL)
{
	tm_rsp_id = tm_data_info->tm_rsp_id;
}
    switch(tm_rsp_id)
    {
    // GPS Related TM
    case TM_GPS_GET_NMEA_GPGGA:
    case TM_GPS_GET_NMEA_GPRMC:
    case TM_GPS_GET_LOCATION_INFO:
    case TM_GPS_GET_DATE_TIME:
    case TM_GPS_GET_3D_POSITION_VELOCITY:
    case TM_GPS_SET_TIME_SYNC_PRDCTY:
    case TM_GPS_GET_TIME_SYNC_PRDCTY:
    case TM_SYNC_GPS_TIME:
    case TM_GPS_GET_GPS_TIME_INFO:
    case TM_GPS_COMPUTE_TLE:
    	tm_len = tm_data_info->rx_data_len;
    	tm_data = os_malloc_eram(tm_len);
    	os_memcpy(tm_data,tm_data_info->rx_data,tm_len);
    	break;

case TM_THRUSTER_SET_MODE:
case TM_THRUSTER_GET_MODE:
case TM_THRUSTER_SET_FIRING_DURATION:
case TM_THRUSTER_GET_FIRING_DURATION:
case TM_THRUSTER_GET_INPUT_POWER_CONSMP:
case TM_THRUSTER_SET_RADIATOR_TEMP_LIMIT:
case TM_THRUSTER_GET_RADIATOR_TEMP_LIMIT:
case TM_THRUSTER_SET_TANK_PRESSURE_LIMIT:
case TM_THRUSTER_GET_TANK_PRESSURE_LIMIT:
case TM_THRUSTER_GET_REMAINING_PROPELLANT:
//case TM_THRUSTER_GET_ACTIVE_STATUS:
case TM_THRUSTER_GET_ONBOARD_TEMPERATURE:
    	tm_len = tm_data_info->rx_data_len;
    	tm_data = os_malloc_eram(tm_len);
    	os_memcpy(tm_data,tm_data_info->rx_data,tm_len);
   	break;

    case TM_GET_OBC_NVM_REVISION_NUM:
    	tm_len = 4;
    	tm_data = os_malloc_eram(4);
        VER_vidGetVersionInfo((uint8_t*)&ver);
    	os_memcpy(&tm_data[0],&ver,2);
        ver = get_nvm_revision_no();
    	os_memcpy(&tm_data[2],&ver,2);
    	break;

#if 0
        case TM_PS_PWR_ON:
            {
                //pack payload
                tm_len = 4;
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                obc_tm_ps_pwr_on_enc(tm_data, 0);

            }
            break;
        case TM_PLD_HW_PWR_ON:
            {
                //pack payload
                tm_len = 4;
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                obc_tm_pld_hw_pwr_on_enc(tm_data, 0);

            }
            break;
#endif
        case TM_PLD_VM_PWR_ON:
            {
                //pack payload
                tm_len = 4;
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                obc_tm_pld_vm_pwr_on_enc(tm_data, 0);

            }
            break;
#if 0
        case TM_PLD_HW_PWR_OFF:
            {
                //pack payload
                tm_len = 4;
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                obc_tm_pld_hw_pwr_off_enc(tm_data, 0);

            }
            break;
#endif
        case TM_PLD_VM_PWR_OFF:
            {
                //pack payload
                tm_len = 4;
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                obc_tm_pld_vm_pwr_off_enc(tm_data, 0);

            }
            break;
#if 1
        case TM_PS_PWR_OFF:
            {
                //pack payload
                tm_len = 4;
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                obc_tm_ps_pwr_off_enc(tm_data, 0);

            }
            break;
#endif
        case TM_TTY_START:
            {
                //pack payload
                tm_len = 4;
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                obc_tm_tty_start_enc(tm_data, 0);
            }
            break;

        case TM_TTY_END:
            {
                //pack payload
                tm_len = 4;
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                obc_tm_tty_end_enc(tm_data, 0);
            }
            break;

        case TM_TTY_DEBUG:
            {
                //pack payload
                tm_len = strlen(tty_drdu)+1;
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                obc_tm_tty_data_enc(tm_data,(uint8*)tty_drdu,tm_len);
            }
            break;

        case TM_SET_SPI_INTF_PARM:
            {

                //pack payload
                tm_len = 4;
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                obc_tm_spi_intf_rsp_enc(tm_data, spi_intf_param_rsp_sts);

            }
            break;
        case TM_SET_ETH_INTF_PARM:
            {

                //pack payload
                tm_len = 4;
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                obc_tm_ethernet_intf_rsp_enc(tm_data, eth_intf_param_rsp_sts);

            }
            break;
        case TM_SET_CAN_INTF_PARM:
            {

                //pack payload
                tm_len = 4;
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                obc_tm_can_intf_rsp_enc(tm_data, can_intf_param_rsp_sts);

            }
            break;

        case TM_SET_I2C_INTF_PARM:
            {

                //pack payload
                tm_len = 4;
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                obc_tm_i2c_intf_rsp_enc(tm_data, i2c_intf_param_rsp_sts);

            }
            break;

        case TM_SET_USB_INTF_PARM:
            {

                //pack payload
                tm_len = 4;
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                obc_tm_usb_intf_rsp_enc(tm_data, usb_intf_param_rsp_sts);

            }
            break;

        case TM_SET_UART_INTF_PARM:
            {

                //pack payload
                tm_len = 4;
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                obc_tm_uart_intf_rsp_enc(tm_data, uart_intf_param_rsp_sts);

            }
            break;
        case TM_GET_SPI_INTF_PARM:
            {

                //pack payload
                tm_len = sizeof(spii);
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                spii.mode = 1;
                spii.direction = 23;
                spii.datasize = 0;
                spii.clk_polarity = 11;
                spii.clk_phase = 13;
                spii.nss = 31;
                spii.baudrate_prescaler = 14;
                spii.firstbit = 80;
                spii.timode = 34;
                spii.crc_calculation = 23;
                spii.crc_polynomial = 21;
                spii.crc_length = 10;
                spii.nssp_mode = 20;

                obc_tm_spi_intf_param_enc(tm_data, &spii);

            }
            break;
        case TM_GET_ETH_INTF_PARM:
            {

                //pack payload
                tm_len = sizeof(eth);
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                eth.auto_negotiation = 0;
                eth.speed = 1;
                eth.duplex_mode = 4;
                eth.phy_address = 6;
                eth.mac_addr = (uint8*)45;
                eth.rx_mode = 23;
                eth.checksum_mode = 12;
                eth.media_interface = 24;
                obc_tm_ethernet_intf_param_enc(tm_data, &eth);

            }
            break;
        case TM_GET_CAN_INTF_PARM:
            {

                //pack payload
                tm_len = sizeof(cis);
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                cis.prescaler = 12;
                cis.mode = 0;
                cis.syncjumpwidth = 11;
                cis.time_seg1 = 1;
                cis.time_seg2 = 2;
                cis.time_triggered_mode = 13;
                cis.autobus_off = 34;
                cis.autowake_up = 80;
                cis.auto_retransmission = 5;
                cis.receive_fifo_locked = 45;
                cis.transmit_fifo_priority = 3;

                obc_tm_can_intf_param_enc(tm_data, &cis);

            }
            break;

        case TM_GET_I2C_INTF_PARM:
            {

                //pack payload
                tm_len = sizeof(i2ci);
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                i2ci.timing = 0;
                i2ci.own_address1 = 1;
                i2ci.addressing_mode = 56;
                i2ci.dual_address_mode = 23;
                i2ci.own_address2 = 12;
                i2ci.own_address2_masks = 13;
                i2ci.generalcall_mode = 21;
                i2ci.no_stretch_mode = 15;

                obc_tm_i2c_intf_param_enc(tm_data, &i2ci);

            }
            break;

        case TM_GET_USB_INTF_PARM:
            {

                //pack payload
                tm_len = sizeof(usbo);
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                usbo.dev_endpoints = 23;
                usbo.host_channels = 1;
                usbo.speed = 0;
                usbo.dma_enable = 90;
                usbo.ep0_mps = 23;
                usbo.phy_itface = 11;
                usbo.sof_enable = 12;
                usbo.low_power_enable = 22;
                usbo.lpm_enable = 10;
                usbo.battery_charging_enable = 21;
                usbo.vbus_sensing_enable = 34;
                usbo.use_dedicated_ep1 = 45;
                usbo.use_external_vbus = 55;

                obc_tm_usb_intf_param_enc(tm_data, &usbo);

            }
            break;

        case TM_GET_UART_INTF_PARM:
            {

                //pack payload
                tm_len = sizeof(uarti);
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                uarti.baudrate = 23;
                uarti.wordlength = 0;
                uarti.stopbits = 1;
                uarti.parity = 2;
                uarti.mode = 4;
                uarti.hw_flow_ctl = 3;
                uarti.over_sampling = 5;
                uarti.onebit_sampling = 7;

                obc_tm_uart_intf_param_enc(tm_data, &uarti);

            }
            break;
#if 0
        case TM_SET_CONV_BOARD_PARM:
            {
                //pack payload
                tm_len = tm_data_info->rx_data_len;
				tm_data = tm_data_info->rx_data;
            }
            break;

        case TM_SET_BATT_BOARD_PARM:
            {
                //pack payload
            	tm_len = tm_data_info->rx_data_len;
            	tm_data = tm_data_info->rx_data;
            }
            break;

        case TM_SET_OUT_CHNL_ENB:
            {
                //pack payload
            	tm_len = tm_data_info->rx_data_len;
            	tm_data = tm_data_info->rx_data;
            }
            break;

        case TM_SET_OUT_CHNL_CUR_LMT:
            {
                //pack payload
            	tm_len = tm_data_info->rx_data_len;
            	tm_data = tm_data_info->rx_data;
            }
            break;

        case TM_SET_EPS_MODE_CFG:
            {
                //pack payload
            	tm_len = tm_data_info->rx_data_len;
            	tm_data = tm_data_info->rx_data;
                
            }
            break;

        case TM_EPS_FW_UPDATE:
            {

            	tm_len = tm_data_info->rx_data_len;
                tm_data = tm_data_info->rx_data;
            }
            break;
#endif
        case TM_LOG_LEVEL_FILTER_CONFIG:
			{
				tm_len = tm_data_info->tx_data_len;
				tm_data = tm_data_info->tx_data;
			}
			break;
        case TM_LOG_DOWNLOAD_BLOCKS:
            {
            	tm_len  = tm_data_info->tx_data_len;
            	tm_data = tm_data_info->tx_data;
            }
            break;
        case TM_READ_LOG_INFO:
            {
                tm_len = tm_data_info->tx_data_len;
                tm_data = tm_data_info->tx_data;
            }
            break;
        case TM_LOG_DOWNLOAD_BACKUP_BLOCKS:
			{
				tm_len = tm_data_info->tx_data_len;
				tm_data = tm_data_info->tx_data;
			}
			break;


        case TM_SET_CONTROL_FLAG_TM_BUFFER:
   			{
   				tm_len = tm_data_info->tx_data_len;
   				tm_data = tm_data_info->tx_data;
   			}
   			break;

        case TM_SET_COMMS_TM_DLREQ:
			{
				tm_len = tm_data_info->tx_data_len;
				tm_data = tm_data_info->tx_data;
			}
			break;


#if 0

        case TM_GET_CONV_BOARD_PARM:
            {
                //pack payload
                

                if(tm_data_info->rx_data[0] == 1 || tm_data_info->rx_data[0] == 0)
                {                
                tm_len = tm_data_info->rx_data_len;
                tm_data=tm_data_info->rx_data;
                }
                else
                {
                	status = -1;
                    DEBUG_CPRINT(("Invalid id\n"));
                }

            }
            break;

        case TM_GET_BATT_BOARD_PARM:
            {
                if(tm_data_info->rx_data[0] == 1 || tm_data_info->rx_data[0] == 0)
                {
                    tm_len = tm_data_info->rx_data_len;
                    tm_data=tm_data_info->rx_data;
                }
                else
                {
                    status = -1;
                    DEBUG_CPRINT(("Invalid id\n"));
                }

            }
            break;

        case TM_GET_OUT_CHNL_PARM:
            {
                if(tm_data_info->rx_data[0] == 1 || tm_data_info->rx_data[0] == 0 || tm_data_info->rx_data[0] == 2)
				{
				tm_len = tm_data_info->rx_data_len;
				tm_data=tm_data_info->rx_data;
				}
				else
				{
					status = -1;
					DEBUG_CPRINT(("Invalid id\n"));
				}
            }
                break;


                case TM_GET_EPS_MODE_CFG:
                {
                	
                	tm_len = tm_data_info->rx_data_len;
                	tm_data=tm_data_info->rx_data;
            }
            break;

        case TM_GET_EPS_ALERT_INFO:
            {

            	tm_len = tm_data_info->rx_data_len;
            	tm_data=tm_data_info->rx_data;
            }break;
        case TM_GET_EPS_FW:
            {
                tm_len = tm_data_info->rx_data_len;
                tm_data=tm_data_info->rx_data;
            }
            break;
        case TM_GET_EPS_VAR_VAL:
            {
#ifdef LINUX_TEMP_PORT
                eps_var_val_resp.data[0] = 1;
                eps_var_val_resp.data[1] = 2;
                eps_var_val_resp.data[2] = 3;
                eps_var_val_resp.data[3] = 4;
                eps_var_val_resp.data[4] = 5;
                eps_var_val_resp.data[5] = 6;
                eps_var_val_resp.data[6] = 7;
                eps_var_val_resp.data[7] = 8;
                memset(eps_var_val_resp.reserved,0,11);
                eps_sts = EPS_SUCCESS;
#else 
                eps_sts = (eps_err_sts)tm_data_info->tx_data;
#endif
                if(eps_sts == EPS_SUCCESS)
                {
                    tm_len = sizeof(eps_get_var_data_s)+1;
                    tm_data = (uint8_t *) os_malloc_eram(tm_len);
                    tm_data[0] = eps_sts;
                    obc_tm_get_eps_var_info(&tm_data[1], &eps_var_val_resp);
                }
            }break;

        case TM_SET_EPS_SIM_EXPOSURE_TYPE:
            {
                tm_len =tm_data_info->rx_data_len;
                tm_data =tm_data_info->rx_data;

            }
            break;

        case TM_SET_EPS_SIM_CH_CRNT:
            {
                tm_len =tm_data_info->rx_data_len; 
                tm_data =tm_data_info->rx_data;
            }
            break;
        case TM_SET_EPS_SIM_BTRY_VOLT:
            {
                tm_len = tm_data_info->rx_data_len;
                tm_data =tm_data_info->rx_data;
            }
            break;
        case TM_SET_EPS_SIM_BTRY_TEMP:
            {
                tm_len = tm_data_info->rx_data_len;
                tm_data =tm_data_info->rx_data;
            }
            break;
#endif
        case TM_SET_MIN_REBOOT_TIME:
            {
            	set_rbt_time_sts=0;
                //pack payload
                tm_len = 4;
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                obc_tm_set_min_reboot_enc(tm_data, set_rbt_time_sts);
            }
            break;

        case TM_GET_SYS_UPTIME:
            {
                //pack payload
                tm_len = sizeof(uint64_t);
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
#ifdef LINUX_TEMP_PORT
               uptime = linux_get_uptime();
               memcpy(tm_data,(uint8_t *)&uptime,tm_len);
#endif                
            }
            break;

        case TM_GET_PROC_UTIL_INFO:
            {
#ifdef LINUX_TEMP_PORT
                //pack payload
                tm_len = sizeof(float);
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
               cpu_ld = linux_get_cpuload();
               memcpy(tm_data,(uint8_t *)&cpu_ld,tm_len);
#else
               tm_len = tm_data_info->rx_data_len;
               tm_data = os_malloc_eram(tm_len);
               os_memcpy(tm_data,tm_data_info->rx_data,tm_len);
#endif                
            }
            break;

        case TM_GET_MEM_UTIL_INFO:
            {
                tm_len = sizeof(sys_mem_status) + sizeof(sys_time_date_s);
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
            	sys_mem_status mem_sts;
            	uint64_t used_eram_mem = 0;
            	uint64_t total_eram_size = 0;
                sys_time_date_s cur_rtc;
                get_crnt_time_date(&cur_rtc);
#ifndef LINUX_TEMP_PORT
                // os heap for target
                os_heap_memory_info_s mem_info;
                get_os_heap_mem_info(&mem_info);
		        mem_sts.iram_heap_mem_total = mem_info.os_total_heapsize;
		        mem_sts.iram_heap_mem_used = mem_info.os_used_heapsize;

                // eram heap for target
                eram_heap_mem_cal(&used_eram_mem, &total_eram_size);
#else
                // iram heap for linux
            	iram_heap_status iram_lnx_sts;
                linux_get_memusage(&iram_lnx_sts);
		mem_sts.iram_heap_mem_total = iram_lnx_sts.total_mem;
		mem_sts.iram_heap_mem_used = iram_lnx_sts.used_mem;
#endif
		mem_sts.eram_heap_mem_total = total_eram_size;
		mem_sts.eram_heap_mem_used = used_eram_mem;

		// eram static memory info
        mem_sts.eram_mem_total = OBC_ERAM_FLASH_TOTAL;
        mem_sts.eram_mem_used = OBC_ERAM_FLASH_USED;
        // qspi flash static memory info
		mem_sts.eflash_qspi_mem_total = OBC_QSPI_FLASH_TOTAL;
		mem_sts.eflash_qspi_mem_used = OBC_QSPI_FLASH_USED;
        // fmc flash static memory info
		mem_sts.eflash_fmc_mem_total = OBC_FMC_FLASH_TOTAL;
		mem_sts.eflash_fmc_mem_used = OBC_FMC_FLASH_USED;
        // pack data
		os_memcpy(tm_data,&cur_rtc,sizeof(sys_time_date_s));
		os_memcpy(tm_data+(sizeof(sys_time_date_s)),&mem_sts,sizeof(sys_mem_status));            
            }
            break;
#ifndef LINUX_TEMP_PORT
        case TM_GET_FTM_SAVECONTEXT_STS:
           {
				uint8_t module_id, sts;
				tm_len = 1;
				tm_data = (uint8_t *) os_malloc_eram(tm_len);
				module_id = *tm_data_info->tx_data;
				sts = ftm_get_savecontext_status(module_id);
				os_memcpy(tm_data, &sts, tm_len);
           }
           break;


        case TM_OBC_MEM_DOWLOAD:
        {
        	tm_len = 1;
        	tm_data = (uint8_t *) os_malloc_eram(tm_len);
        	tm_data[0] = obc_memory_downloader_start((obc_mem_dwldr_request_form_def *)tm_data_info->tx_data);
        }
        break;
#endif
        case TM_SET_TEMP_SNS_CFG:
            {
                temp_sen_set_parm_sts=0;
                //pack payload
                tm_len = 4;
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                obc_tm_temp_sns_param_enc(tm_data, temp_sen_set_parm_sts);
            }
            break;

        case TM_SET_IMU_CFG:
            {
                imu_set_parm_sts=0;
                //pack payload
                tm_len = 4;
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                obc_tm_imu_param_enc(tm_data,imu_set_parm_sts);
            }
            break;
        case TM_SET_THRUST_CTRL_CFG:
            {
                thruster_ctrl_set_parm_sts=0;
                //pack payload
                tm_len = 4;
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                obc_tm_thrstr_cntlr_param_enc(tm_data,thruster_ctrl_set_parm_sts);
            }
            break;
        case TM_SET_DIG_THERM_CFG:
            {
                dgtl_therm_set_parm_sts= 0;
                //pack payload
                tm_len = 4;
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                obc_tm_dgtl_thrmst_param_enc(tm_data,dgtl_therm_set_parm_sts);
            }
            break;
        case TM_SET_GPIO_EXP_CFG:
            {
                gpio_exp_set_parm_sts = 0;

                //pack payload
                tm_len = 4;
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                obc_tm_gpio_exp_param_enc(tm_data, gpio_exp_set_parm_sts);
            }
            break;
        case TM_SET_PWR_MON_CFG:
            {
                pwr_mon_set_parm_sts = 0;

                //pack payload
                tm_len = 4;
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                obc_tm_pwr_mon_param_enc(tm_data, pwr_mon_set_parm_sts);
            }
            break;
        case TM_SET_PWR_SEQ_MON_CFG:
            {
                pwr_seq_mon_set_parm_sts = 0;

                //pack payload
                tm_len = 4;
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                obc_tm_pwr_seq_mon_param_enc(tm_data, pwr_seq_mon_set_parm_sts);
            }
            break;
        case TM_SET_VOLT_CTRL_MON_CFG:
            {
                volt_ctrl_mon_set_parm_sts = 0;

                //pack payload
                tm_len = 4;
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                obc_tm_vlt_ctlr_param_enc(tm_data, volt_ctrl_mon_set_parm_sts);
            }
            break;
        case TM_SET_DATA_LOG_CFG:
            {
                data_log_set_parm_sts = 0;

                //pack payload
                tm_len = 4;
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                obc_tm_data_lgr_param_enc(tm_data, data_log_set_parm_sts);
            }
            break;

        case TM_GET_PWR_MON_CFG:
        case TM_GET_VOLT_CTRL_MON_CFG:
        case TM_GET_DIG_THERM_CFG:
        case TM_GET_TEMP_SNS_CFG:
            {
            	tm_len = tm_data_info->rx_data_len;
            	tm_data = os_malloc_eram(tm_len);
            	os_memcpy(tm_data,tm_data_info->rx_data,tm_len);
                //os_free(tm_data);
            }
            break;
        case TM_GET_IMU_CFG:
            {
                //update payload
                //pack payload
                tm_len = sizeof(imu_info);
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                obc_tm_imu_info_enc(tm_data, &imu_inf);
#ifdef SNS_GET_INF_PRINT

                DEBUG_CPRINT(("instance_id = %d \n",imu_inf.instance_id));
                DEBUG_CPRINT(("power = %d \n",imu_inf.power));
                DEBUG_CPRINT(("accel_x = %d \n",imu_inf.accel_x));
                DEBUG_CPRINT(("gyro_y = %d \n",imu_inf.gyro_y));
                DEBUG_CPRINT(("mag_y = %d \n",imu_inf.mag_y));

#endif
                //os_free(tm_data);
            }
            break;
        case TM_GET_THRUST_CTRL_CFG:
            {
                //update payload
                //pack payload
                tm_len = sizeof(thruster_info);
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                obc_tm_thruster_ctlr_info_enc(tm_data, &thrstr_inf);
#ifdef SNS_GET_INF_PRINT
                DEBUG_CPRINT(("instance_id = %d \n",thrstr_inf.instance_id));
                DEBUG_CPRINT(("brd_err_count = %d \n",thrstr_inf.brd_err_count));
                DEBUG_CPRINT(("strt_tm = %d \n",thrstr_inf.strt_tm));
                DEBUG_CPRINT(("master_tm = %d \n",thrstr_inf.master_tm));
                DEBUG_CPRINT(("bkpln_master_tm = %d \n",thrstr_inf.bkpln_master_tm));

#endif
                //os_free(tm_data);
            }
            break;
			case TM_GET_GPIO_EXP_CFG:
            {
                //update payload
                //pack payload
                tm_len = sizeof(gpio_exp_cfg);
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                obc_tm_gpio_exp_info_enc(tm_data, &gpx_exp_cfg);
#ifdef SNS_GET_INF_PRINT
                DEBUG_CPRINT(("instance_id = %d \n",gpx_exp_cfg.instance_id));
                DEBUG_CPRINT(("intr_pin_polarity = %d \n",gpx_exp_cfg.intr_pin_polarity));
#endif
                //os_free(tm_data);
            }
            break;

        case TM_GET_PWR_SEQ_MON_CFG:
            {
                //update payload
                //pack payload
                tm_len = sizeof(voltage_seq_mntr_cfg);
                tm_data = (uint8_t *) os_malloc(tm_len);
                obc_tm_pwr_seq_mtr_info_enc(tm_data, &vltg_seq_mntr_cfg);
#ifdef SNS_GET_INF_PRINT
                DEBUG_CPRINT(("instance_id = %d \n",vltg_seq_mntr_cfg.instance_id));

#endif
                //os_free(tm_data);
            }
            break;
        case TM_GET_DATA_LOG_CFG:
            {
                //update payload
                //pack payload
                tm_len = sizeof(data_acq_dvc_info);
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                obc_tm_data_log_info_enc(tm_data, &data_acq_inf);
#ifdef SNS_GET_INF_PRINT
                DEBUG_CPRINT(("instance_id = %d \n",data_acq_inf.instance_id));
                DEBUG_CPRINT(("chnl_num = %d \n",data_acq_inf.chnl_num));
                DEBUG_CPRINT(("pwr_dwn_optn = %d \n",data_acq_inf.pwr_dwn_optn));
                DEBUG_CPRINT(("data = %d \n",data_acq_inf.data));
#endif
                //os_free(tm_data);
            }
            break;
        case TM_GET_SSD_SLOT_SELEC:
            {
                //pack payload
            	tm_len = tm_data_info->rx_data_len;
            	tm_data = os_malloc_eram(tm_len);
            	os_memcpy(tm_data,tm_data_info->rx_data,tm_len);
            }
            break;
        case TM_GET_SSD_HEAT_COIL_STS:
                    {
                    	tm_len = tm_data_info->rx_data_len;
                    	tm_data = os_malloc_eram(tm_len);
                    	os_memcpy(tm_data,tm_data_info->rx_data,tm_len);
                    }
                    break;
        case TM_SET_SSD_HEAT_COIL_PRDCTY:
                    {
                    	tm_len = tm_data_info->rx_data_len;
                    	tm_data = os_malloc_eram(tm_len);
                    	os_memcpy(tm_data,tm_data_info->rx_data,tm_len);
                    }
                    break;
        case TM_GET_SSD_HEAT_COIL_PRDCTY:
                    {
                    	tm_len = tm_data_info->rx_data_len;
                    	tm_data = os_malloc_eram(tm_len);
                    	os_memcpy(tm_data,tm_data_info->rx_data,tm_len);
                    }
                    break;
        case TM_GET_SENSOR_DATA:
            {
                void* data_buff=NULL;
                switch(sns_ahw_id)
                {
                    case PSM_INA230_OBC:
                        {
                            data_buff=psm_obc_data_buffer;
                            tm_len = sizeof(psm_data_s)* SENSOR_MAX_BUFF_SIZE;
                        }
                        break;
                    case PSM_INA230_PS:
                        {
                            data_buff=psm_ps_data_buffer;
                            tm_len = sizeof(psm_data_s)* SENSOR_MAX_BUFF_SIZE;
                        }
                        break;
                    case TEMP_SENSOR_MCP9843_OBC:
                        {
                            data_buff=temp_obc_data_buffer;
                            tm_len = sizeof(temp_data_s)* SENSOR_MAX_BUFF_SIZE;
                        }
                        break;
                    case TEMP_SENSOR_MCP9843_PS:
                        {
                            data_buff=temp_ps_data_buffer;
                            tm_len = sizeof(temp_data_s)*SENSOR_MAX_BUFF_SIZE;
                        }
                        break;
                    case TEMP_SENSOR_MCP9843_EDGE:
                        {
                            data_buff=temp_edge_data_buffer;
                            tm_len = sizeof(temp_data_s) *SENSOR_MAX_BUFF_SIZE;
                        }
                        break;
                    case TEMP_SENSOR_MCP9843_GPS:
                        {
                            data_buff=temp_gps_data_buffer;
                            tm_len = sizeof(temp_data_s)*SENSOR_MAX_BUFF_SIZE;
                        }
                        break;
                    case DIGITAL_THERMOSTAT_DS620_SPE01:
                        {
                            data_buff=temp_spe01_data_buffer;
                            tm_len = sizeof(dt_data_s)*SENSOR_MAX_BUFF_SIZE;
                        }
                        break;
                    case DIGITAL_THERMOSTAT_DS620_SPE02:
                        {
                            data_buff=temp_spe02_data_buffer;
                            tm_len = sizeof(dt_data_s)*SENSOR_MAX_BUFF_SIZE;
                        }
                        break;
                    case DIGITAL_THERMOSTAT_DS620_SPB01:
                        {
                            data_buff=temp_spb01_data_buffer;
                            tm_len = sizeof(dt_data_s)*SENSOR_MAX_BUFF_SIZE;
                        }
                        break;
                    case DIGITAL_THERMOSTAT_DS620_SPW01:
                        {
                            data_buff=temp_spw01_data_buffer;
                            tm_len = sizeof(dt_data_s)*SENSOR_MAX_BUFF_SIZE;
                        }
                        break;
                    case DIGITAL_THERMOSTAT_DS620_SPW02:
                        {
                            data_buff=temp_spw02_data_buffer;
                            tm_len = sizeof(dt_data_s)*SENSOR_MAX_BUFF_SIZE;
                        }
                        break;
                    case DIGITAL_THERMOSTAT_DS620_EDGE:
                        {
                            data_buff=dt_edge_data_buffer;
                            tm_len = sizeof(dt_data_s)*SENSOR_MAX_BUFF_SIZE;
                        }
                        break;
                    case DIGITAL_THERMOSTAT_DS620_PS:
                        {
                            data_buff=dt_ps_data_buffer;
                            tm_len = sizeof(dt_data_s)*SENSOR_MAX_BUFF_SIZE;
                        }
                        break;
                    case HSC_ADM1176_PS_2:
                        {
                            data_buff=hsc_ps_2_data_buffer;
                            tm_len = sizeof(hsc_data_s)*SENSOR_MAX_BUFF_SIZE;
                        }
                        break;
                    case HSC_ADM1176_PS_1:
                        {
                            data_buff=hsc_ps_1_data_buffer;
                            tm_len = sizeof(hsc_data_s)*SENSOR_MAX_BUFF_SIZE;
                        }
                        break;
                    case HSC_ADM1176_EDGE:
                        {
                            data_buff=hsc_edge_data_buffer;
                            tm_len = sizeof(hsc_data_s)*SENSOR_MAX_BUFF_SIZE;
                        }
                        break;
                    case VOLTAGE_SEQUENCER_UCD9801_OBC:
                        {
                            data_buff=vsm_obc_data_buffer;
                            tm_len = sizeof(vsm_data_s)*SENSOR_MAX_BUFF_SIZE;
                            break;
                        }
                }
                tm_len =tm_len+4;
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                obc_tm_get_sns_data_enc(tm_data,data_buff,tm_len);
                break;
#ifdef SNS_GET_INF_PRINT
                DEBUG_CPRINT(("instance_id = %d \n",data_acq_inf.instance_id));
                DEBUG_CPRINT(("chnl_num = %d \n",data_acq_inf.chnl_num));
                DEBUG_CPRINT(("pwr_dwn_optn = %d \n",data_acq_inf.pwr_dwn_optn));
                DEBUG_CPRINT(("data = %d \n",data_acq_inf.data));
#endif
            }
            break;


        case TM_FTCI:
        case TM_FTFCI:
        case TM_FTDS:
        case TM_FTSR:
        case TM_FTDR:
            {
                tm_len  = s_ftm_queue_tm_frame.Q_payload_len;
                tm_data = s_ftm_queue_tm_frame.Q_payload_ptr;
                obc_prepare_ipc_msg(tm_data, tm_len, tm_rsp_id,s_ftm_queue_tm_frame.src_dst_id);
                status = 1;
            }
            break;


        case TM_CONOPS_SCH_LUT_CFG:
            {
                //pack payload
                tm_len = sizeof(lut_cfg_rsp)+1;
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                tm_data[0] = 1;
                os_memcpy(&tm_data[1], &lut_cfg_rsp, sizeof(lut_cfg_rsp));
            }
            break;

        case TM_CONOPS_SCH_LUT_RUN_CTRL:
            {
            	tm_len = tm_data_info->tx_data_len;
                tm_data = tm_data_info->tx_data;
            }
            break;

        case TM_CONOPS_SCH_STS_INFO:
            {
                tm_len = tm_data_info->tx_data_len;
                tm_data = tm_data_info->tx_data;
            }
            break;

        case TM_SET_CUR_TIME:
            {
            	uint8_t rtc_sts;
            	rtc_sts = get_crnt_time_date(&time_date);
            	tm_len = sizeof(sys_time_date_s)+1;
				tm_data = (uint8_t *) os_malloc_eram(tm_len);
				os_memcpy(tm_data,&rtc_sts,1);
				tm_set_cur_time_enc(&tm_data[1],(uint8_t*)&time_date);

            }
            break;

        case TM_OBC_SOFT_RESET:
            {
                tm_len = 4;
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                obc_tm_obc_sw_rst_enc(tm_data,sw_rst_typ);
            }
            break;

        case TM_PS_BRD_SELECT:
            {
               tm_len = tm_data_info->rx_data_len;
               tm_data = (uint8_t *) os_malloc_eram(tm_len);
               os_memcpy(tm_data,tm_data_info->rx_data,tm_len);
            }
            break;

        case TM_ES_BRD_SELECT:
            {
               tm_len = tm_data_info->rx_data_len;
               tm_data = (uint8_t *) os_malloc_eram(tm_len);
               os_memcpy(tm_data,tm_data_info->rx_data,tm_len);
            }
            break;

        case TM_I2C_ADXL345_TEST:
        {
        	tm_len = tm_data_info->rx_data_len;
        	tm_data = (uint8_t *) os_malloc_eram(tm_len);
        	os_memcpy(tm_data,tm_data_info->rx_data,tm_len);
        }
        break;

        case TM_UART_TX_RX_TEST:
           {
        	   tm_len = tm_data_info->rx_data_len;
        	   tm_data = (uint8_t *) os_malloc_eram(tm_len);
               os_memcpy(tm_data, tm_data_info->rx_data, tm_len);
           }
           break;

        case TM_CAN_TX_RX_TEST:
           {
        	   tm_len = tm_data_info->rx_data_len;
               tm_data = (uint8_t *) os_malloc_eram(tm_len);
               os_memcpy(tm_data, tm_data_info->rx_data, tm_len);
           }
           break;

        case TM_SPI_ADXL345_TEST:
        {
        	tm_len = tm_data_info->rx_data_len;
        	tm_data = (uint8_t *) os_malloc_eram(tm_len);
        	os_memcpy(tm_data,tm_data_info->rx_data,tm_len);
        }
        break;

        case TM_ADC_SELECT:
            {
               tm_len = tm_data_info->rx_data_len;
               tm_data = (uint8_t *) os_malloc_eram(tm_len);
               os_memcpy(tm_data,tm_data_info->rx_data,tm_len); 
            }
            break;

        case TM_AUTO_SENSOR_TEST:
        {
        	tm_len = sizeof(uint64_t);
        	tm_data = (uint8_t *) os_malloc_eram(tm_len);
        	os_memcpy(tm_data,tm_data_info->rx_data,tm_len);
        }
        break;

        case TM_IO_BRD_SELECT:
        {
        	tm_len = tm_data_info->rx_data_len;
        	tm_data = (uint8_t *) os_malloc_eram(tm_len);
        	os_memcpy(tm_data,tm_data_info->rx_data,tm_len);
        }
        break;
        case TM_PS_SSD_BRD_SELECT:
        {
        	tm_len = tm_data_info->rx_data_len;
        	tm_data = (uint8_t *) os_malloc_eram(tm_len);
        	os_memcpy(tm_data,tm_data_info->rx_data,tm_len);
        }
        break;

        case TM_ES_SSD_BRD_SELECT:
        {
        	tm_len = tm_data_info->rx_data_len;
        	tm_data = (uint8_t *) os_malloc_eram(tm_len);
        	os_memcpy(tm_data,tm_data_info->rx_data,tm_len);
        }
        break;

                case    TM_OTSU_GET_VERSION:
                case	TM_OTSU_CURRENT_STATUS:
                case	TM_OTSU_SEND_FW_UPDATE_BOOT_CFG:
                case	TM_OTSU_INTEGERATION_TEST_CMD:
                case	TM_OTSU_GET_FW_UPDATE_STS:
                case	TM_OTSU_GET_BOOT_CFG_INFO:
                case	TM_OTSU_READ_GSCONATCT_WAIT_TIME:
                case	TM_OTSU_SET_GSCONATCT_WAIT_TIME:
                case	TM_OTSU_READ_BOOTABLE_BLT1:
                case	TM_OTSU_READ_BOOTABLE_BLT2:
                case    TM_OTSU_GET_NVM_FW_VERSION:
                case	TM_OTSU_NOTIFICATION:
                 {
                         tm_len = otsu_tm_pld.tctm_size;
                         tm_data = otsu_tm_pld.tctm_ptr;
                     }
                     break;
					 
        case TM_OBC_IPCC_TEST:
            {
                tm_len = tm_data_info->tx_data_len;
                tm_data = tm_data_info->tx_data;
            }
            break;

 case TM_MEMD:
            {
                tm_len = 4;
                tm_data =  (uint8_t*)os_malloc_eram(tm_len);
                mem_debug_data = obc_mem_debug_tm_pack_data();
                tm_data[0] = mem_debug_data&0xFF;
                tm_data[1] = (mem_debug_data>>8)&0xFF;
                tm_data[2] = (mem_debug_data>>16)&0xFF;
                tm_data[3] = (mem_debug_data>>24)&0xFF;
            }
            break;

#if 0
        case TM_SET_EPS_CTRL_DEV_TMR:
            {
#if 0
            	tm_len = 1;
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                tm_data [0] = 1;
#endif
                tm_len = tm_data_info->tx_data_len;
				tm_data = (uint8_t *) os_malloc_eram(tm_len);
				tm_data[0] = tm_data_info->tx_data[0];

            }
            break;
#endif

#if 0
        case TM_SET_EPS_BTRY_VOLT_THRSHLD:
            {
                tm_len = 1;
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                tm_data [0] = 1;
            }
            break;
#endif

#if 0
        case TM_SET_EPS_CTRL_CHNL_ST:
            {

#if 0
				tm_len = 1;
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                tm_data[0] = (uint8_t)eps_ch_pwr_sts;
#endif
               	tm_len = tm_data_info->tx_data_len;
				tm_data = (uint8_t *) os_malloc_eram(tm_len);
				tm_data[0] = tm_data_info->tx_data[0];
            }
            break;
#endif

#if 0
        case TM_SET_EPS_BTRY_CTRL_CH_MAP:
            {
#if 0
            	tm_len = 1;
                tm_data = (uint8_t*)os_malloc_eram(tm_len);
                tm_data[0] = 1;
#endif
                tm_len = tm_data_info->tx_data_len;
				tm_data = (uint8_t*)os_malloc_eram(tm_len);
				tm_data[0] = tm_data_info->tx_data[0];
            }
           break; 
    
        case TM_GET_EPS_BTRY_CTRL_CH_MAP:
            { 
                tm_len =sizeof(eps_btry_ch_map_s);
                tm_data =(uint8*)os_malloc_eram(sizeof(eps_btry_ch_map_s)+1);
                obc_tm_get_eps_btry_chnl_map(tm_data);
            }
            break;

        case TM_GET_EPS_DEV_HW_STS:
            {
                tm_len = sizeof(sat_dev_sts)+1;
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                tm_data[0] = 1;
                os_memcpy(&tm_data[1],(uint8_t *)&sat_dev_sts[0],tm_len);

            }
            break;
#endif
        case TM_GET_OBC_SW_STS:
            {
                tm_len = sizeof(sub_mod_sts);
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                os_memcpy(tm_data,(uint8_t *)&sub_mod_sts[0],tm_len);

                os_memcpy(&tm_data[tm_len],(uint8_t *)&icd_socket_conn_sts,sizeof(uint8_t));
                tm_len += sizeof(uint8_t);
            }
            break;
        
        case TM_SET_SSD_SLOT_SELC:
            {
                ssd_slec_sts = 0;

                //pack payload
                tm_len = 4;
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                obc_tm_ssd_select_enc(tm_data, &ssd_slec_sts);
            }
            break;
        case TM_PS_STAGED_TC:
            {
                tm_len = 1;
                tm_data = (uint8*)os_malloc_eram(1);
                obc_tm_ps_staged_tc_enc(tm_data,0);
            }
            break;

        case TM_SSD_HEAT_COIL_ENABLE:
            {
                ssd_heat_slec_sts = 0;
        
                tm_len = 4;
                tm_data = (uint8_t *) os_malloc_eram(tm_len);
                obc_tm_ssd_heat_select_enc(tm_data, &ssd_heat_slec_sts);
            }
            break;
        case TM_EXTRNL_MEM_TEST:
		   {
			   tm_len = sizeof(ext_mem_test_tc_tm_s);
			   tm_data =  (uint8_t*)os_malloc_eram(tm_len);
			   os_memcpy(tm_data,&mem_test_sts,tm_len);
		   }
		   break;
    
        case TM_NVM:
                {
                   // nvm_param *rec_data_1 = (nvm_param*)tm_data_info;
                	nvm_param *rec_data_1 = (nvm_param*)tm_data_info->tx_data;
                    tm_len =sizeof(nvm_param) + rec_data_1->len;
                    tm_data = (uint8_t*)os_malloc_eram(tm_len);
                    obc_tm_mem_data_enc(tm_data,rec_data_1);
                }
                break;
#if 0
        case TM_EPS_GET_BUFFER:
                {
                    tm_len = eps_get_buff_len+1;
                    tm_data =(uint8_t*)os_malloc_eram(tm_len);
                    tm_data[0] = 1;
                    os_memcpy(&tm_data[1],eps_get_buf,eps_get_buff_len);
                    os_free(eps_get_buf);
#if 0
#ifndef LINUX_TEMP_PORT
                    tm_len = eps_get_buff_len+1;
                    tm_data =(uint8_t*)os_malloc_eram(tm_len);
                    tm_data[0] = 1;
                   memcpy(&tm_data[1],eps_get_buf,eps_get_buff_len);//(uint8_t*)os_malloc_eram(tm_len);
#else
                    tm_len = 1;
                     tm_data=(uint8_t*) os_malloc_eram(tm_len);
                     tm_data[0] = 0xff;
#endif 
#endif
                }
                break;
    case TM_EPS_HEALTH_STS:
                {
                    uint8* data;
                    data = (uint8*)os_malloc_eram(200+1);
                    obc_eps_get_hlth_info(&data[1]);
                     tm_len = data[1]+2;
                     data[0] = 1;
                     tm_data = data;
                     //os_memcpy(tm_data,data+1,tm_len);
                     // tm_len = sizeof(eps_hlth_info_s);
                   // tm_data = (uint8*)os_malloc_eram(tm_len);
                    //os_memcpy(tm_data,&eps_hlth_info,tm_len);
                }
                break;

    	case TM_EPS_GET_CRC:
                {
                    tm_len = sizeof(eps_crc_cnt)+1;
                    tm_data = (uint8_t*)os_malloc_eram(tm_len);
                    tm_data[0] = 1;
                    os_memcpy(&tm_data[1],eps_crc_cnt,tm_len-1);
                }
                break;
#endif
    	case TM_GET_CUR_TIME:
    	{
    		uint8_t rtc_sts;
    		os_memset(&time_date,0,sizeof(sys_time_date_s));
        	rtc_sts = get_crnt_time_date(&time_date);
        	tm_len = sizeof(sys_time_date_s)+1;
			tm_data = (uint8_t *) os_malloc_eram(tm_len);
			os_memcpy(tm_data,&rtc_sts,1);
			os_memcpy(tm_data+1,&time_date,tm_len);
    	}
		break;
    	case TM_TEST_GPIO:
    	{
    		tm_len = 1;
    	    tm_data =  (uint8_t*)os_malloc_eram(tm_len);
    	    tm_data[0] = obc_test_gpio_rsp;
    	}
    	break;
    	case TM_TEST_SENSOR:
		{
			tm_len = 1;
			 tm_data =  (uint8_t*)os_malloc_eram(tm_len);
			 tm_data[0] = obc_test_sns_rsp;
		}
		break;
    	case TM_TEST_GPIO_EXP:
    	{
    		tm_len = 1;
    		tm_data =  (uint8_t*)os_malloc_eram(tm_len);
    	   tm_data[0] = obc_test_gpio_exp_rsp;
    	}
    	break;

    	case TM_SPI_UART_CONV_TEST:
    	{
    		tm_len = tm_data_info->rx_data_len;
    		tm_data = tm_data_info->rx_data;
    	}
        	break;

    	case TM_NVM_COMMIT:
    			{
    				tm_len = 1;
    				 tm_data =  (uint8_t*)os_malloc_eram(tm_len);
    				 tm_data[0] = obc_nvm_commit_rsp;
    			}
    		break;

    	case TM_NVM_COMMIT_PRDCTY_TIM_CFG:
    	    	{
    	   			tm_len = 1;
     				 tm_data = (uint8_t*)os_malloc_eram(tm_len);
 	   				 tm_data[0] =obc_nvm_commit_prdcty_tim_rsp;
       			}
    	    break;


    	case TM_TCTM_DEQUEUE:
    	{
    		uint32_t dequeue_sts = 0;
			tm_len = sizeof(uint32_t);
			tm_data = (uint8_t *) os_malloc_eram(tm_len);
			os_memcpy(tm_data,&dequeue_sts,tm_len);
    	}
    	break;
        case TM_OBC_GET_CPU_STATS:
        {
            status = -1;
            DEBUG_CPRINT(("TM_OBC_GET_CPU_STATS TBF\n"));
        }
        break;
		
    	case TM_ERR_HANDLER_READ_FAULTS:
    	case TM_ERR_HANDER_READ_GROUP_ERROR_STATUS:
    	case TM_ERR_HANDLER_GET_ERROR_HISTORY:
    	case TM_ERR_HANDLER_RUN_BIST:
    	{

   	     tm_len = tm_data_info->tx_data_len;
   	     tm_data = tm_data_info->tx_data;

    	}
		break;
    	case TM_GET_PS_TEMP:
    	{
    		mcu_get_temp_s mcu_get_temp;
    		if(tm_data_info->tx_data[0] == 0)
    		{
    			mcu_get_temp.dev_id = tm_data_info->tx_data[0];
    			obc_tm_get_temp_enc(&mcu_get_temp.temp);
    		}
    		else if(tm_data_info->tx_data[0] == 1)
    		{
    			mcu_get_temp.dev_id = tm_data_info->tx_data[0];
    			mcu_get_temp.temp = tm_data_info->tx_data[1];
    		}
    		else
    		{
    			/*TODO*/
    		}
    		tm_len = sizeof(mcu_get_temp_s);
    		tm_data = (uint8_t *) os_malloc_eram(tm_len);
    		os_memcpy(tm_data,&mcu_get_temp,tm_len);

    	}
    	break;
    	case TM_GET_PS_TIME:
		{
			mcu_get_time_s mcu_get_time;
			if(tm_data_info->tx_data[0] == 0)
			{
				mcu_get_time.dev_id = tm_data_info->tx_data[0];
#ifndef LINUX_TEMP_PORT
				mcu_get_time.mcu_uptime = mcu_uptime;
#endif
				obc_tm_get_time_enc(&mcu_get_time.epoch_time);

			}
			else if(tm_data_info->tx_data[0] == 1)
			{
				mcu_get_time.dev_id = tm_data_info->tx_data[0];
				os_memcpy(&mcu_get_time.mcu_uptime,&tm_data_info->tx_data[1],sizeof(mcu_get_time.mcu_uptime));
				os_memcpy(&mcu_get_time.epoch_time,tm_data_info->tx_data+5,sizeof(mcu_get_time.epoch_time));
			}
			else
			{
				/*TODO*/
			}
			tm_len = sizeof(mcu_get_time_s);
			tm_data = (uint8_t *) os_malloc_eram(tm_len) ;
			os_memcpy(tm_data,&mcu_get_time,tm_len);

		}
		break;
        case TM_GET_MCU_CHIP_INFO:
		{
			mcu_get_chip_info_s mcu_get_chip_info;
			if(tm_data_info->tx_data[0] == 0)
			{
				obc_tm_get_mcu_info_enc(&mcu_get_chip_info,tm_data_info->tx_data[0]);
			}
			else if(tm_data_info->tx_data[0] == 1)
			{
			os_memcpy(&mcu_get_chip_info,tm_data_info->tx_data,sizeof(mcu_get_chip_info_s));
			//mcu_get_chip_info.dev_id = 1;
			}
			else
			{
				/*TODO*/
			}
			tm_len = sizeof(mcu_get_chip_info_s);
			tm_data = (uint8_t *) os_malloc_eram(tm_len) ;
			os_memcpy(tm_data,&mcu_get_chip_info,tm_len);

		}
		break;

        case TM_GET_MCU_EXT_MEM_INFO:
		{
			mcu_get_ext_mem_s mcu_get_ext_mem;
			if(tm_data_info->tx_data[0] == 0)
			{
#if 0
				obc_get_ext_mem_s obc_get_ext_mem;
				obc_tm_get_mcu_ext_mem_info_enc(&obc_get_ext_mem,tm_data_info->tx_data[0]);
#endif
				obc_tm_get_mcu_ext_mem_info_enc(&mcu_get_ext_mem,tm_data_info->tx_data[0]);
				tm_len = sizeof(mcu_get_ext_mem_s);
				tm_data = (uint8_t *) os_malloc_eram(tm_len);
				os_memcpy(tm_data,&mcu_get_ext_mem,tm_len);
			}
			else if(tm_data_info->tx_data[0] ==1)
			{
#if 0
				ps_get_ext_mem_s ps_get_ext_mem;
#endif
			mcu_get_ext_mem.dev_id = tm_data_info->tx_data[0];
			mcu_get_ext_mem.mem_cnt=1;

			os_memcpy(&mcu_get_ext_mem.ext_mem_info[0].tot_mem,&tm_data_info->tx_data[1],sizeof(ext_mem_info_s));
			tm_len = sizeof(ext_mem_info_s)+5;
			tm_data = (uint8_t *) os_malloc_eram(tm_len);
			os_memcpy(tm_data,&mcu_get_ext_mem,tm_len);
			}
			else
			{
					/*TODO*/
			}

		}
		break;
        case TM_GET_MCU_INT_MEM_INFO:
		{
			obc_get_int_mem_s obc_get_int_mem;
			obc_tm_get_mcu_int_mem_info_enc(&obc_get_int_mem);
			tm_len = sizeof(obc_get_int_mem_s);
			tm_data = (uint8_t *) os_malloc_eram(tm_len);
			os_memcpy(tm_data,&obc_get_int_mem,tm_len);

		}
		break;
        case TM_GET_MCU_INT_PHERIPHARL_INFO:
        {
        	obc_get_int_pher_info_s obc_get_int_pher_info;
        	obc_tm_get_mcu_int_pher_info_enc(&obc_get_int_pher_info);
        	tm_len = sizeof(obc_get_int_pher_info_s);
			tm_data = (uint8_t *) os_malloc_eram(tm_len);
			os_memcpy(tm_data,&obc_get_int_pher_info,tm_len);
        }
        break;
        case TM_GET_MCU_EXT_PHERIPHARL_INFO:
		{
			obc_get_ext_pher_info_s obc_get_ext_pher_info;
			obc_tm_get_mcu_ext_pher_info_enc(&obc_get_ext_pher_info);
			tm_len = sizeof(obc_get_ext_pher_info_s);
			tm_data = (uint8_t *) os_malloc_eram(tm_len);
			os_memcpy(tm_data,&obc_get_ext_pher_info,tm_len);
		}
		break;
        case TM_GET_MCU_RST_INFO:
                {
                    tm_len = sizeof(reset_info);
                    tm_data = os_malloc_eram(tm_len);
#ifndef LINUX_TEMP_PORT
                    get_mcu_reset_reason_info((reset_info*)tm_data);
#endif

                }
		break;
        case TM_CHNGE_QUEUE_PRIORITY:
                {
                    DEBUG_CPRINT(("Sending TM for CHNGE_QUEUE_PRIORITY\n"));
			tm_len = sizeof(uint32_t);
			tm_data = (uint8_t *) os_malloc(tm_len);
                        tm_data[0] = *tm_data_info->rx_data;
                }
               break;

        case TM_CHNGE_MODULE_PRIORITY: 
                {
                    DEBUG_CPRINT(("Sending TM for CHNGE_MODULE_PRIORITY\n"));
			tm_len = sizeof(uint32_t);
			tm_data = (uint8_t *) os_malloc(tm_len);
                        tm_data[0] = *tm_data_info->rx_data;
                }
               break; 
        case TM_HM_TEST_CASE_REQ:
			   {
				   DEBUG_CPRINT(("Sending TM for HM_TEST_CASE\n"));
				   tm_len = 8;
				   tm_data = (uint8_t *) os_malloc(tm_len);
                                   os_memcpy(tm_data, tm_data_info->rx_data, tm_len);
				 //  tm_data[0] = *tm_data_info->rx_data;
			   }
			  break;
        case TM_GET_TCTM_DBG_INFO:
        {
            tm_len = tm_data_info->rx_data_len;
            tm_data = tm_data_info->rx_data;
        }
        break;
        case TM_PRINT_MEM_LEAK:
        {
            tm_len = get_mem_leak_info(&tm_data);
        }
        break;

        default :
            {
                status = -1;
                DEBUG_CPRINT(("Invalid TM ID received %d\n",tm_rsp_id));
            }
    }
    if(0 == status)
    {
        obc_prepare_ipc_msg(tm_data, tm_len, tm_rsp_id,TM_SRC_OBC);
        /*Control variable - Increments on every IPC sent*/
        exo_sw_dbg.obc_dbg.obc_main_ipc_sent++;
        os_free(tm_data);
        tm_data = NULL;

    }
    tm_rsp_id = 0;
}
/**
 * @brief This API store the received TC information
 */
void store_rcvd_tc_info(uint32_t utc_time, uint16_t dst_id, uint16_t tc_id)
{
    tc_dbg_info[tc_dbg_info_idx].tc_rcvd_time = utc_time;
    tc_dbg_info[tc_dbg_info_idx].tc_id = tc_id;
    tc_dbg_info[tc_dbg_info_idx].dst_id = dst_id;
    if(++tc_dbg_info_idx >= MAX_TCTM_DBG_INFO)
    {
        tc_dbg_info_idx = 0;
    }
}

/**
 * @brief This API store the Sent/Genrated TM information
 */
void store_snt_tm_info(uint32_t utc_time, uint16_t src_id, uint16_t tm_id)
{
    tm_dbg_info[tm_dbg_info_idx].tm_sent_time = utc_time;
    tm_dbg_info[tm_dbg_info_idx].tm_id = tm_id;
    tm_dbg_info[tm_dbg_info_idx].src_id = src_id;
    if(++tm_dbg_info_idx >= MAX_TCTM_DBG_INFO)
    {
        tm_dbg_info_idx = 0;
    }
}

/**
 * @brief This API used to get TCTM debug information
 */
void get_tc_tm_dbg_info(uint8_t *data)
{
    int8_t temp_tc_dbg_idx = tc_dbg_info_idx - 1;
    int8_t temp_tm_dbg_idx = tm_dbg_info_idx - 1;

    for(int i = 0; i < MAX_TCTM_DBG_INFO; i++)
    {
        if(temp_tc_dbg_idx < 0)
        {
            temp_tc_dbg_idx = MAX_TCTM_DBG_INFO - 1;
        }
        os_memcpy(&data[i * sizeof(s_tc_dbg_info)],\
                &tc_dbg_info[temp_tc_dbg_idx], sizeof(s_tc_dbg_info));
        temp_tc_dbg_idx--;
    }

    for(int i = 0; i < MAX_TCTM_DBG_INFO; i++)
    {
        if(temp_tm_dbg_idx < 0)
        {
            temp_tm_dbg_idx = MAX_TCTM_DBG_INFO - 1;
        }
        os_memcpy(&data[(MAX_TCTM_DBG_INFO * sizeof(s_tc_dbg_info)) + (i * sizeof(s_tm_dbg_info))],\
                &tm_dbg_info[temp_tm_dbg_idx], sizeof(s_tm_dbg_info));
        temp_tm_dbg_idx--;
    }
}

/**
 * @brief Function to generate alert TM when memoery threshold exceed
 */
void gen_alert_tm_mem_exd_thrs()
{
    uint8_t *tm_data = NULL;
    uint16_t tm_len = 0;
    uint8_t seq_no_radio_id[3] = {0};
    seq_no_radio_id[0] = 0xFF;
    seq_no_radio_id[1] = 0xFF;
    seq_no_radio_id[2] = 0x04;
    set_seq_no_radio_id(seq_no_radio_id);

    // Generate Memory leak telemetry
    tm_len = get_mem_leak_info(&tm_data);

    obc_prepare_ipc_msg(tm_data, tm_len, TM_PRINT_MEM_LEAK,TM_SRC_OBC);
    os_free(tm_data);

    // Generate Memory utilization telemetry
    tm_len = sizeof(sys_mem_status) + sizeof(sys_time_date_s);
    tm_data = (uint8_t *) os_malloc_eram(tm_len);
    sys_mem_status mem_sts;
    uint64_t used_eram_mem = 0;
    uint64_t total_eram_size = 0;
    sys_time_date_s cur_rtc;
    get_crnt_time_date(&cur_rtc);
#ifndef LINUX_TEMP_PORT
    // os heap for target
    os_heap_memory_info_s mem_info;
    get_os_heap_mem_info(&mem_info);
    mem_sts.iram_heap_mem_total = mem_info.os_total_heapsize;
    mem_sts.iram_heap_mem_used = mem_info.os_used_heapsize;

    // eram heap for target
    eram_heap_mem_cal(&used_eram_mem, &total_eram_size);
#else
    // iram heap for linux
    iram_heap_status iram_lnx_sts;
    linux_get_memusage(&iram_lnx_sts);
    mem_sts.iram_heap_mem_total = iram_lnx_sts.total_mem;
    mem_sts.iram_heap_mem_used = iram_lnx_sts.used_mem;
#endif
    mem_sts.eram_heap_mem_total = total_eram_size;
    mem_sts.eram_heap_mem_used = used_eram_mem;

    // eram static memory info
    mem_sts.eram_mem_total = OBC_ERAM_FLASH_TOTAL;
    mem_sts.eram_mem_used = OBC_ERAM_FLASH_USED;
    // qspi flash static memory info
    mem_sts.eflash_qspi_mem_total = OBC_QSPI_FLASH_TOTAL;
    mem_sts.eflash_qspi_mem_used = OBC_QSPI_FLASH_USED;
    // fmc flash static memory info
    mem_sts.eflash_fmc_mem_total = OBC_FMC_FLASH_TOTAL;
    mem_sts.eflash_fmc_mem_used = OBC_FMC_FLASH_USED;
    // pack data
    os_memcpy(tm_data,&cur_rtc,sizeof(sys_time_date_s));
    os_memcpy(tm_data+(sizeof(sys_time_date_s)),&mem_sts,sizeof(sys_mem_status));
    obc_prepare_ipc_msg(tm_data, tm_len, TM_GET_MEM_UTIL_INFO,TM_SRC_OBC);
    os_free(tm_data);
}
