
/**
 * @file obc_main_fsm_hdlr.h
 *
 * @brief #TODO
 *
 */

#ifndef OBC_MAIN_FSM_HDLR_H
#define OBC_MAIN_FSM_HDLR_H

#include"exo_types.h"

#include "exo_osal_itc.h"
#include "exo_common.h"

/**
  * @brief  OBC Sub module in enum definition
  */
typedef enum
{
    OBC_SUB_MOD_PL_TRANSCELESTIAL     = HW_PL_TRANSCELESTIAL,
    OBC_SUB_MOD_X_BAND                = HW_X_BAND,
    OBC_SUB_MOD_S_BAND                = HW_S_BAND,
    OBC_SUB_MOD_ADCS                  = HW_ADCS,
    OBC_SUB_MOD_PROP_UNIT_THRUSTER    = HW_PROP_UNIT_THRUSTER,
#ifdef JANUS1
    OBC_SUB_MOD_ADCS0                 = HW_ADCS0,
    OBC_SUB_MOD_PL_ZES                = HW_PL_ZES,
    OBC_SUB_MOD_PL_SAYARLABS          = HW_PL_SAYARLABS,
#else
    OBC_SUB_MOD_PL_SCANWAY            = HW_PL_SCANWAY,
    OBC_SUB_MOD_PL_STS300	          = HW_PL_STS300,
#endif
    OBC_SUB_MOD_PL_NETRA              = HW_PL_NETRA,
    OBC_SUB_MOD_EDGE_BRD              = HW_EDGE_BRD,
    OBC_SUB_MOD_OBC_PS_GPS_STD_PL_BRD = HW_OBC_PS_GPS_STD_PL_BRD,
    OBC_SUB_MOD_HRM                   = HW_HRM,
    OBC_SUB_MOD_PLD_SRVR              = HW_PL_SERVER,
    OBC_SUB_MOD_GPS                   = HW_GPS,
    OBC_SUB_MOD_UHF                   = HW_UHF,
    OBC_SUB_MOD_TC_TM                 = MAX_SAT_DEV_CNT,
    OBC_SUB_MOD_SCH,
    OBC_SUB_MOD_OTSU,
    OBC_SUB_MOD_MAX
}e_obc_sub_mod;

/**
  * @brief  OBC MAIN FSM State in enum definition
  */
typedef enum
{
     OBC_INIT_STATE,                ///< OBC module initializes from reset state
     OBC_ACTIVE_PWR_CRITICAL_STATE, ///< OBC Active critical state - Only OBC is active
     OBC_ACTIVE_PWR_SAFE_STATE,     ///< OBC Active safe state - Only Schedular, OBC, Comms and ADCS are active
     OBC_ACTIVE_PWR_NORM_STATE,     ///< OBC Active Normal state - all dependent modules are active
     OBC_POWER_SAVE_STATE,          ///< OBC power save state - all modules are turned off or configured to low power mode
     OBC_RESET_STATE,               ///< OBC reset state - all modules are reset and needs further reconfiguration to move to active state
     OBC_ERROR_STATE,               ///< OBC error state - all modules are reset and needs further reconfiguration to move to active state
     OBC_MAX_NUM_STATE
}e_obc_fsm_state;


/**
 * @brief OBC Beacon health structure
 */
typedef struct
{
    /** FSM current state */
    uint8_t fsm_state;

    /** No of OBC resets */
    uint8_t num_resets;

    /** IO errors */
    uint16_t io_err;

    /** System errors */
    uint8_t sys_err;

}s_obc_beacon_info; 


uint8 obc_fsm(uint8_t state, os_itc_msg_handle_t *payload);
uint8 obc_init_state_hdlr(os_itc_msg_handle_t *payload);
uint8 obc_active_pwr_critical_state_hdlr(os_itc_msg_handle_t *payload);
uint8 obc_active_pwr_safe_state_hdlr(os_itc_msg_handle_t *payload);
uint8 obc_active_pwr_normal_state_hdlr(os_itc_msg_handle_t *payload);
uint8 obc_power_save_state_hdlr(os_itc_msg_handle_t *payload);
uint8 obc_reset_state_hdlr(os_itc_msg_handle_t *payload);
uint8 obc_error_state_hdlr(os_itc_msg_handle_t *payload);

uint8_t obc_eps_battery_sts_proc(uint8_t obc_eps_bat_sts);
void obc_eps_proc_dev_sts(uint8_t dev_id, uint8_t obc_eps_dev_sts);
void obc_otsu_deinit_rsp_hdlr(void);
void obc_shutdown_hdlr(void);
void obc_proc_sband_health_check_req(void);
void obc_proc_sband_ground_sync_ind(void);
void obc_sdr_beacon_health_metric_enc(void);

#endif /*OBC_MAIN_FSM_HDLR_H */

