/**
 * @file comms_csw.h
 *
 * @brief This file has the control blocks, enumeration and function prototypes of SDR control layer of S-Band module
 *
 * @copyright Copyright 2023 Antaris, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#ifndef COMMS_CSW_H
#define COMMS_CSW_H

#include "exo_osal.h"
#include "exo_ral_cmn.h"
#include "exo_ral_mem_management.h"
#include "exo_types.h"

typedef float f32;
typedef double f64;

#ifdef __cplusplus
extern "C" {
#endif

#define RX_CH_0            0
#define RX_CH_1            1
#define MAX_RX_CH          2
#define TIM_RUN 			1
#define TIM_IDL 			0

///COMMS error codes
#define  COMMS_IPC_READ_ERROR                       -20
#define  COMMS_IPC_WRITE_ERROR                      -21
#define  COMMS_INVALID_COMMAND                      -10
#define  COMMS_NULL_PTR                              -1
#define  COMMS_OPERATION_SUCCESS                     1
#define  COMMS_IPC_OK                                2

#define MAX_IP_ADDR_CNT                              16
#define MAX_PORT_NUM_CNT                             5
#define MAX_SYS_CSP_ROUTES_CNT                       100
#define MAX_SYS_NET_EN_IP_CNT                        50
#define MAX_SYS_NET_EN_GW_CNT                        50
#define MAX_SYS_NET_RF_IP_CNT                        50
#define MAX_SYS_NET_RF_GW_CNT                        50
#define MAX_COMMS_TX_CRYPTO_KEY_CNT                  32
#define MAX_COMMS_RX_CRYPTO_KEY_CNT                  32
#define MAX_COMMS_SYS_NAME_CNT                       20

#define MAX_SBAND_PERIODIC_TM 						32

/**
  * @brief  comms State in enum definition
  */
typedef enum
{
     COMMS_INIT_STATE,       ///< Comms module initializes from reset state
     COMMS_BOOT_STATE,        ///< comms booting state
     COMMS_DFU_STATE,         ///< device firmware will be updated during this state
     COMMS_CFG_STATE,         ///< comms configuration state
     COMMS_CALIB_STATE,       ///< comms calibration state
     COMMS_SLEEP_IDLE_STATE,  ///< comms initialize sleep and idle state
     COMMS_ACTIVE_STATE,      ///< comms active state
     COMMS_SAFE_MODE_STATE,   ///< comms initialize safe mode state
     COMMS_ERROR_STATE,       ///< comms error state
     COMMS_BYPASS_STATE,      ///< comms bypass state
     COMMS_MAX_NUM_STATE
}e_comms_state;

//socket details
typedef struct comms_sock_info
{
    uint8_t ip_addr_cnt;
    uint8_t port_num_cnt;

    char ip_addr[MAX_IP_ADDR_CNT];
    char port_num[MAX_PORT_NUM_CNT];
}s_comms_sock_info;

typedef struct  __attribute__((packed)) 
{
    uint32_t    sys_serial;           /*!< Serial number/ID                      */
    uint32_t    sys_sw_version;       /*!< Running software version              */
    uint32_t    sys_bootcount;        /*!< Number of times the system was booted */
    uint16_t    sys_reboot;           /*!< Reboot timer                          */
}s_comms_boot_cfg;

typedef struct  __attribute__((packed)) 
{
    uint32_t    sys_gwdt_init;        /*!< GWDT timer reset value                */
    uint32_t    sys_gwdt_counter;     /*!< GWDT current counter value            */
    uint32_t    sys_gwdt_reset;       /*!< GWDT reset trigger                    */
}s_comms_gwdt_cfg;

typedef struct  __attribute__((packed)) 
{  uint8_t    sys_csp_routes_cnt;

    uint8_t     sys_csp_address;      /*!< csp address of the device             */
    uint8_t     sys_csp_routes[MAX_SYS_CSP_ROUTES_CNT];  /*!< csp routes in CIDR notation           */
}s_comms_csp_cfg;

typedef struct  __attribute__((packed)) 
{
    uint32_t    sys_can_rate;         /*!< CAN-bus bitrate                       */
    uint8_t     sys_can_promisc;      /*!< Accept all CSP CAN-frames             */
}s_comms_can_cfg;

typedef struct  __attribute__((packed)) 
{
    uint32_t    sys_uart_rate;        /*!< UART baudrate                         */
    uint8_t     sys_uart_multidrop;   /*!< UART multidrop mode                   */
}s_comms_uart_cfg;

typedef struct  __attribute__((packed)) 
{
    uint8_t sys_net_en_ip_cnt;
    uint8_t sys_net_en_gw_cnt;
    uint8_t sys_net_rf_ip_cnt;
    uint8_t sys_net_rf_gw_cnt;

    uint8_t     sys_net_enable;                          /*!< IP stack enable                       */
    uint8_t     sys_net_en_ip[MAX_SYS_NET_EN_IP_CNT];    /*!< Ethernet IP address                   */
    uint8_t     sys_net_en_prefix;                       /*!< Ethernet network prefix bits          */
    uint8_t     sys_net_en_gw[MAX_SYS_NET_EN_GW_CNT];    /*!< Ethernet gateway IP address           */
    uint8_t     sys_net_rf_ip[MAX_SYS_NET_RF_IP_CNT];    /*!< Spacelink IP address                  */
    uint8_t     sys_net_rf_prefix;                       /*!< Spacelink network prefix bits         */
    uint8_t     sys_net_rf_gw[MAX_SYS_NET_RF_GW_CNT];    /*!< Spacelink gateway IP address          */
}s_comms_net_cfg;

typedef struct {
    uint8_t comms_tx_crypto_key_cnt;

    uint8_t   crypto_key[MAX_COMMS_TX_CRYPTO_KEY_CNT];     /*!< Encryption key                                       */
    uint8_t   crypto_encrypt;                              /*!< Encrypt frames                                       */
    uint8_t   crypto_auth;                                 /*!< Add authentication tag                                        */
}s_comms_tx_crypto_cfg;

typedef struct {
    uint8_t comms_rx_crypto_key_cnt;

    uint8_t   crypto_key[MAX_COMMS_RX_CRYPTO_KEY_CNT];     /*!< Decryption key                                       */
    uint8_t   crypto_decrypt;                              /*!< Decrypt frames                                       */
    uint8_t   crypto_auth;                                 /*!< Add authentication tag                                        */
}s_comms_rx_crypto_cfg;

typedef struct  __attribute__((packed))
{
    uint8_t   rx_cfg_afc_enable;    /*!< Enable AFC                                    */
    uint32_t  rx_cfg_afc_range;     /*!< AFC adjustment range                          */
}s_comms_rx_afc_cfg;

/**
  * @brief comms transmit configuration Structure definition
  *
  */
typedef struct  __attribute__((packed)){

    uint32_t  tx_cfg_freq;           /*!< Transmit frequency                                            */
    uint8_t   tx_cfg_type;           /*!< Transmit modulation type (0 = BPSK, 1 = QPSK, 2 = 8PSK)       */
    uint32_t  tx_cfg_rate;           /*!< Transmit symbol rate                                          */
    uint8_t   tx_cfg_rolloff;        /*!< RRC roll-off (0 = 0.20,  1 = 0.25,  2 = 0.35)                 */
    f32       tx_cfg_pout;           /*!< Transmit power                                                */
    uint8_t   tx_cfg_alc_mode;       /*!< Automatic Level Control mode (0 = open-loop, 1 = closed-loop) */
    uint8_t   tx_cfg_rs;             /*!< Enable Reed-Solomon coding                                    */
    uint8_t   tx_cfg_cc;             /*!< Enable convolutional coding                                   */
    uint8_t   tx_cfg_rand;           /*!< Enable randomization                                          */
    uint8_t   tx_cfg_crc;            /*!< Enable CRC checksum                                           */
    uint16_t  tx_cfg_idletime;       /*!< Active transmitter time after each frame                      */
    uint16_t  tx_cfg_size;           /*!< Maximum payload size                                          */
    uint16_t  tx_cfg_id;             /*!< Satellite ID/address                                          */
    s_comms_tx_crypto_cfg crypto_cfg;
}s_comms_tx_gen_cfg;


/**
  * @brief comms receive configuration Structure definition
  *
  */
typedef struct  __attribute__((packed))
{
    uint32_t  rx_cfg_freq;          /*!< Receive frequency                             */
    uint8_t   rx_cfg_type;          /*!< Receive modulation type (0 = BPSK,  1 = QPSK) */
    uint32_t  rx_cfg_rate;          /*!< Receive symbol rate                           */
    uint8_t   rx_cfg_rolloff;       /*!< RRC roll-off (0 = 0.20, 1 = 0.25, 2 = 0.35)   */
    s_comms_rx_afc_cfg afc_cfg;
    uint8_t   rx_cfg_rs;            /*!< Enable Reed-Solomon coding                    */
    uint8_t   rx_cfg_cc;            /*!< Enable convolutional coding                   */
    uint8_t   rx_cfg_rand;          /*!< Enable randomization                          */
    uint8_t   rx_cfg_crc;           /*!< Enable CRC checksum                           */
    uint16_t  rx_cfg_size;          /*!< Maximum payload size                          */
    uint16_t  rx_cfg_id;            /*!< Satellite ID/address                          */
    s_comms_rx_crypto_cfg crypto_cfg;
}s_comms_rx_gen_cfg;


/**
  * @brief comms transmit configuration Structure definition
  *
  */
typedef struct  __attribute__((packed)){

    uint32_t  tx_cfg_freq;           /*!< Transmit frequency                                            */
    uint8_t   tx_cfg_type;           /*!< Transmit modulation type (0 = BPSK, 1 = QPSK, 2 = 8PSK)       */
    uint32_t  tx_cfg_rate;           /*!< Transmit symbol rate                                          */
    uint8_t   tx_cfg_rolloff;        /*!< RRC roll-off (0 = 0.20,  1 = 0.25,  2 = 0.35)                 */
    f32       tx_cfg_pout;           /*!< Transmit power                                                */
    uint8_t   tx_cfg_alc_mode;       /*!< Automatic Level Control mode (0 = open-loop, 1 = closed-loop) */
    uint8_t   tx_cfg_rs;             /*!< Enable Reed-Solomon coding                                    */
    uint8_t   tx_cfg_cc;             /*!< Enable convolutional coding                                   */
    uint8_t   tx_cfg_rand;           /*!< Enable randomization                                          */
    uint8_t   tx_cfg_crc;            /*!< Enable CRC checksum                                           */
    uint16_t  tx_cfg_idletime;       /*!< Active transmitter time after each frame                      */
    uint16_t  tx_cfg_size;           /*!< Maximum payload size                                          */
    uint16_t  tx_cfg_id;             /*!< Satellite ID/address                                          */
    s_comms_tx_crypto_cfg crypto_cfg;

    uint8_t   tx_cfg_pa_templimit;   /*!< PA temperature limit                                          */
    uint32_t  tx_cfg_frames;         /*!< Transmitted frames                                            */
    f32       tx_cfg_pwr_fwd;        /*!< Measured forward power                                        */
    f32       tx_cfg_pwr_rfl;        /*!< Transmit the Measured reflected power                         */
}s_comms_tx_cfg;

/**
  * @brief comms receive configuration Structure definition
  *
  */
typedef struct  __attribute__((packed))
{
    uint32_t  rx_cfg_freq;          /*!< Receive frequency                             */
    uint8_t   rx_cfg_type;          /*!< Receive modulation type (0 = BPSK,  1 = QPSK) */
    uint32_t  rx_cfg_rate;          /*!< Receive symbol rate                           */
    uint8_t   rx_cfg_rolloff;       /*!< RRC roll-off (0 = 0.20, 1 = 0.25, 2 = 0.35)   */
    s_comms_rx_afc_cfg afc_cfg;
    uint8_t   rx_cfg_rs;            /*!< Enable Reed-Solomon coding                    */
    uint8_t   rx_cfg_cc;            /*!< Enable convolutional coding                   */
    uint8_t   rx_cfg_rand;          /*!< Enable randomization                          */
    uint8_t   rx_cfg_crc;           /*!< Enable CRC checksum                           */
    uint16_t  rx_cfg_size;          /*!< Maximum payload size                          */
    uint16_t  rx_cfg_id;            /*!< Satellite ID/address                          */
    s_comms_rx_crypto_cfg crypto_cfg;
    uint32_t  rx_cfg_frames;        /*!< Received frames                               */
    uint32_t  rx_cfg_detected;      /*!< Detected frames                               */
    f32       rx_cfg_rssi;          /*!< Measured RSSI                                 */
    f32       rx_cfg_freqerr;       /*!< Estimated frequency error                     */
    f32       rx_cfg_symerr;        /*!< Estimated symbol rate error                   */
    f32       rx_cfg_ebn0;          /*!< Estimated Eb/N0                               */
    uint8_t   rx_cfg_carrier_lock;  /*!< comms receive config carrier lock             */
    uint8_t   rx_frame_lock;        /*!< comms receive frame lock                      */
}s_comms_rx_cfg;

/**
  * @brief comms receive TM Structure definition
  x
  */
typedef struct  __attribute__((packed))
{
    uint32_t  rx_cfg_frames;        /*!< Received frames                               */ //UDP recv frame for iqs
    uint32_t  rx_cfg_detected;      /*!< Detected frames                               */ //UDP detect frame  is same as recv frame
    f32       rx_cfg_rssi;          /*!< Measured RSSI                                 */ //update RSSI
    f32       rx_cfg_freqerr;       /*!< Estimated frequency error                     */ //Doppler freq
    f32       rx_cfg_symerr;        /*!< Estimated symbol rate error                   */ //invalid
    f32       rx_cfg_ebn0;          /*!< Estimated Eb/N0                               */ //invalid
    uint8_t   rx_cfg_carrier_lock;  /*!< comms receive config carrier lock             */ //sync
    uint8_t   rx_frame_lock;        /*!< comms receive frame lock                      */ //sync
}s_comms_rx_tm;

/**
  * @brief comms receive TM Structure definition
  x
  */
typedef struct  __attribute__((packed))
{
    uint32_t  rx_cfg_frames;        /*!< Received frames                               */ //UDP recv frame for iqs
    uint32_t  rx_cfg_detected;      /*!< Detected frames                               */ //UDP detect frame  is same as recv frame
    f32       rx_cfg_rssi;          /*!< Measured RSSI                                 */ //update RSSI
    f32	      rx_avg_rssi;
    f32		  rx_cfg_freqerr;       /*!< Estimated frequency error                     */ //Doppler freq
    uint8_t  rx_cfg_carrier_lock;  /*!< comms receive config carrier lock             */ //sync
    uint8_t  rx_frame_lock;        /*!< comms receive frame lock                      */ //sync
    f32       rx_cfg_symerr;        /*!< Estimated symbol rate error                   */ //invalid
    f32       rx_cfg_ebn0;          /*!< Estimated Eb/N0                               */ //invalid
    uint32_t  rx_sir_min;			/*!< signal noise ratio min 					   */
    uint32_t  rx_sir_max;			/*!< signal noise ratio max					       */
    uint32_t  rx_bch_block_cnt;		/*!< rcv channel bch block count			   	   */
    uint32_t  rx_bch_err_cnt; 		/*!< rcv channel bch error count 			       */
}s_comms_rx_tm_xlink;

/**
  * @brief comms TX TM Structure definition
  */
typedef struct  __attribute__((packed))
{
    uint32_t  tx_cfg_frames;         /*!< Transmitted frames                           */ // UDP tx frame for iqs
    f32       tx_cfg_pwr_fwd;        /*!< Measured forward power                       */ //
    f32       tx_cfg_pwr_rfl;        /*!< Transmit the Measured reflected power        */ //reverse calc att for iqs
}s_comms_tx_tm;

/**
  * @brief comms system details in Structure definition
  *
  */
typedef struct  __attribute__((packed))
{
    uint8_t comms_sys_name_cnt;
    uint8_t sys_name[MAX_COMMS_SYS_NAME_CNT];         /*!< system String name for system         */
    s_comms_boot_cfg boot_cfg;
    s_comms_gwdt_cfg gwdt_cfg;
    s_comms_csp_cfg csp_cfg;
    s_comms_can_cfg can_cfg;
    s_comms_uart_cfg uart_cfg;
    s_comms_net_cfg net_cfg;
}s_comms_sys_cfg;

/**
  * @brief comms telemetric details in Structure definition
  * 398
  */
typedef struct
{
    int32_t  temp_mcu;   /*!< MCU package temperature      */ //eth phy
    int32_t  temp_fpga;  /*!< FPGA temperature             */ //zynq
    int32_t  temp_xcvr;  /*!< Transceiver temperature      */ //AD9361
    int32_t  temp_resrv1;   /*!< LNA temperature              */
    int32_t  temp_resrv2;    /*!< PA temperature               */
    int32_t  temp_resrv3;   /*!< Power conversion temperature */
    double   volt_vint;   /*!< Input voltage                *///VCCINT
    double   volt_vaux;   /*!< 3.3 V rail voltage           */
    double   volt_vbram;   /*!< 1.8 V rail voltage           */
    double   volt_vpint;   /*!< 1.0 V rail voltage           */
    double   volt_vpaux;    /*!< PA voltage                   */
    double   volt_vpdro;    /*!< Input current                */
    int16_t  cur_resrv1;    /*!< 3.3 V rail current           */
    int16_t  cur_resrv2;    /*!< 1.8 V rail current           */
    int16_t  cur_resrv3;    /*!< 1.0 V rail current           */
    int16_t  cur_resrv4;     /*!< PA current                   */
    uint16_t power_resrv1;  /*!< Input power                  */
    uint16_t power_resrv2;  /*!< 3.3 V rail power             */
    uint16_t power_resrv3;  /*!< 1.8 V rail power             */
    uint16_t power_resrv4;  /*!< 1.0 V rail power             */
    uint16_t power_resrv5;   /*!< PA power                     */
    uint16_t rsvd;
}s_comms_tm_prop_xlink;

typedef struct  __attribute__((packed))
{
    int32_t  temp_mcu;   /*!< MCU package temperature      */ //eth phy
    int32_t  temp_fpga;  /*!< FPGA temperature             */ //zynq
    int32_t  temp_xcvr;  /*!< Transceiver temperature      */ //AD9361
    double   volt_vint;   /*!< Input voltage                *///VCCINT
    double   volt_vaux;   /*!< 3.3 V rail voltage           */
    double   volt_vbram;   /*!< 1.8 V rail voltage           */
    double   volt_vpint;   /*!< 1.0 V rail voltage           */
    double   volt_vpaux;    /*!< PA voltage                   */
    double   volt_vpdro;    /*!< Input current                */
}s_sband_cmn_tm;

typedef struct  __attribute__((packed))
{
    uint32_t  rx_cfg_frames;        /*!< Received frames                               */ //UDP recv frame for iqs
    uint32_t  rx_cfg_detected;      /*!< Detected frames                               */ //UDP detect frame  is same as recv frame
    f32       rx_cfg_rssi;          /*!< Measured RSSI                                 */ //update RSSI
    f32       rx_avg_rssi; 			/*|< Avg RSSI									   */
    int32     rx_cfg_freqerr;       /*!< Estimated frequency error                     */ //Doppler freq
    uint32_t  rx_cfg_carrier_lock;  /*!< comms receive config carrier lock             */ //sync
    uint32_t  rx_frame_lock;        /*!< comms receive frame lock                      */ //sync
    uint32_t  rx_sir_min;			/*!< signal noise ratio min 					   */
    uint32_t  rx_sir_max;			/*!< signal noise ratio max					       */
    uint32_t  rx_bch_block_cnt;		/*!< rcv channel bch block count			   	   */
    uint32_t  rx_bch_err_cnt; 		/*!< rcv channel bch error count 			       */
}s_sband_rx_tm;

typedef struct  __attribute__((packed))
{
    uint32_t  tx_cfg_frames;         /*!< Transmitted frames                           */ // UDP tx frame for iqs
    f32       tx_cfg_pwr_rfl;        /*!< Transmit the Measured reflected power        */ //reverse calc att for iqs
}s_sband_tx_tm;

typedef struct  __attribute__((packed))
{
    s_sband_cmn_tm cmn_tm;
    s_sband_rx_tm rx_tm[MAX_RX_CH];
    s_sband_tx_tm tx_tm;
}s_sband_periodic_tm;

typedef struct __attribute__((packed))
{
        uint64_t  time_stamp;
        s_sband_periodic_tm comms_sband_tm_stor;
}s_comms_sband_get_tm_prop_time;

typedef struct __attribute__((packed))
{
    uint8_t cnt_hk_id;
    s_comms_sband_get_tm_prop_time sband_tm_store[MAX_SBAND_PERIODIC_TM];

} s_sband_periodic_get_tm;


typedef struct
{
    int16_t  temp_psu;   /*!< Power conversion temperature */
    int16_t  temp_mcu;   /*!< MCU package temperature      */ //eth phy
    int16_t  temp_fpga;  /*!< FPGA temperature             */ //zynq
    int16_t  temp_xcvr;  /*!< Transceiver temperature      */ //AD9361
    int16_t  temp_lna;   /*!< LNA temperature              */
    int16_t  temp_pa;    /*!< PA temperature               */
    uint16_t volt_vin;   /*!< Input voltage                *///VCCINT
    uint16_t volt_3v3;   /*!< 3.3 V rail voltage           */
    uint16_t volt_1v8;   /*!< 1.8 V rail voltage           */
    uint16_t volt_1v0;   /*!< 1.0 V rail voltage           */
    uint16_t volt_pa;    /*!< PA voltage                   */
    int16_t  cur_vin;    /*!< Input current                */
    int16_t  cur_3v3;    /*!< 3.3 V rail current           */
    int16_t  cur_1v8;    /*!< 1.8 V rail current           */
    int16_t  cur_1v0;    /*!< 1.0 V rail current           */
    int16_t  cur_pa;     /*!< PA current                   */
    uint16_t power_vin;  /*!< Input power                  */
    uint16_t power_3v3;  /*!< 3.3 V rail power             */
    uint16_t power_1v8;  /*!< 1.8 V rail power             */
    uint16_t power_1v0;  /*!< 1.0 V rail power             */
    uint16_t power_pa;   /*!< PA power                     */
    uint16_t rsvd;
}s_comms_tm_prop;



/**
  * @brief comms calibration details in Structure definition
  *
  */
typedef struct
{
    f32      cal_ps_gain;        /*!< Power sensor gain         */
    f32      cal_ps_intercept;   /*!< Power sensor intercept    */
    uint16_t cal_vctcxo;         /*!< VCTCXO adjust             */
    f32      cal_pwr_set;        /*!< Current pout setpoint     */
    uint8_t  cal_ber_enable;     /*!< Enable BER test           */
    uint32_t cal_ber_window;     /*!< BER window size           */
    uint32_t cal_ber_count;      /*!< BER test count            */
    uint32_t cal_ber_locks;      /*!< BER lock count            */

}s_comms_cal_cfg;

/**
  * @brief comms CSP TM Structure definition
  */
typedef struct  __attribute__((packed))
{
    uint16_t mtu;              //!< Maximum Transmission Unit of interface
    uint16_t reserved;
    uint32_t tx;               //!< Successfully transmitted packets
    uint32_t rx;               //!< Successfully received packets
    uint32_t tx_error;         //!< Transmit errors (packets)
    uint32_t rx_error;         //!< Receive errors, e.g. too large message
    uint32_t drop;             //!< Dropped packets
    uint32_t autherr;          //!< Authentication errors (packets)
    uint32_t frame;            //!< Frame format errors (packets)
    uint32_t txbytes;          //!< Transmitted bytes
    uint32_t rxbytes;          //!< Received bytes
}s_comms_csp_tm_details;

typedef struct  __attribute__((packed))
{
    s_comms_csp_tm_details csp_int[3];
    uint32_t csp_err_nomem	;             /**< Not enough memory */
    uint32_t csp_err_inval	;             /**< Invalid argument */
    uint32_t csp_err_timedout	;             /**< Operation timed out */
    uint32_t csp_err_used	;             /**< Resource already in use */
    uint32_t csp_err_notsup	;             /**< Operation not supported */
    uint32_t csp_err_busy	;             /**< Device or resource busy */
    uint32_t csp_err_already	;             /**< Connection already in progress */
    uint32_t csp_err_reset	;             /**< Connection reset */
    uint32_t csp_err_nobufs	;             /**< No more buffer space available */
    uint32_t csp_err_tx		;             /**< Transmission failed */
    uint32_t csp_err_driver	;             /**< Error in driver layer */
    uint32_t csp_err_again	;             /**< Resource temporarily unavailable */
    uint32_t csp_err_hmac	;             /**< HMAC failed */
    uint32_t csp_err_xtea	;             /**< XTEA failed */
    uint32_t csp_err_crc32	;             /**< CRC32 failed */
    uint32_t csp_err_sfp	;             /**< SFP protocol error or inconsistency */
}s_comms_csp_tm;


typedef struct  __attribute__((packed))
{
	uint32_t rx_freq;
	uint8_t  rx_type;
	uint32_t rx_rate;
	uint8_t  rx_rolloff;
	uint32_t rx_gain;
	uint8_t  rx_rs;
	uint8_t  rx_cc;
	uint8_t  rx_rand;
	uint8_t  rx_crc;
	uint16_t  rx_size;
	uint16_t  rx_id;
	uint32_t  rx_rsvd1;
	uint32_t  rx_frames;
	uint32_t  rx_detected;
	uint32_t  rx_rssi;
	uint32_t  rx_freqerr;
	uint32_t  rx_symerr;
	uint32_t  rx_rsvd2;
	uint8_t  rx_rsvd3;
	uint8_t  rx_rsvd4;
}s_comms_xlinks_rx_cfg;


typedef struct  __attribute__((packed))
{
	uint32_t tx_freq;
	uint8_t tx_type;
	uint32_t tx_rate;
	uint8_t tx_rolloff;
	float tx_pout;
	uint8_t tx_alc;
	uint8_t tx_rs;
	uint8_t tx_cc;
	uint8_t tx_rand;
	uint16_t tx_crc;
	uint16_t tx_idletime;
	uint16_t tx_size;
	uint16_t tx_id;
	uint32_t tx_rsvd1;
	uint8_t tx_tmp_limit;
	uint32_t tx_frames;
	uint32_t tx_rsvd2;
	uint32_t tx_rsvd3;
}s_comms_xlinks_tx_cfg;


typedef struct  __attribute__((packed))
{
	uint8_t ip_stack_enb;
	uint8_t dev_ip[50];
	uint32_t dev_port;
	uint8_t eth_prefix;
	uint8_t dev_ip_temp[50];
	uint32_t dev_port_udp;
	uint8_t dev_ip_udp[50];
}s_comms_xlinks_net_prop_cfg;

typedef struct  __attribute__((packed))
{
    char leop_prod_key[36];
    char con_prod_key[36];
}s_comms_xlinks_dev_prd_key;


typedef struct  __attribute__((packed))
{
    uint32_t rx_gain;
    uint32_t idx_gain;
    uint32_t pwr_min;
    uint32_t pwr_max;
    uint8_t rx_ch_no;
    uint32_t mtu_size;
    uint8_t pwr_attn_lut;
    uint32_t tx_attn_gain;

}s_comms_xlinks_dev_rssi_tx_atten;


typedef struct  __attribute__((packed))
{
    uint8_t fpga_ver[50];
    uint8_t swap_ver[50];
    uint8_t cpu_ver[50];

}s_comms_xlinks_fw_version;


typedef struct  __attribute__((packed))
{
    uint8_t gs_first_contact;
    uint8_t otsu_first_contact;
}s_comms_xlinks_gnd_cnt_duration;


typedef struct  __attribute__((packed))
{
	uint8_t beacon_tx_timeout;
	uint8_t tx_win_timeout;

}s_comms_xlinks_timeout;


/**
  * @brief  comms event in enum definition
  */
typedef enum
{
    COMMS_BOOT_REQ,             ///< comms boot request
    COMMS_BOOT_STS,             ///< comms boot status
    COMMS_RESET_REQ,            ///< comms reset request
    COMMS_RESET_RSP,            ///< comms reset response
    COMMS_RESET_NOTF,           ///< comms reset notification
    COMMS_ACTIVE_REQ,           ///< comms active request
    COMMS_ACTIVE_RSP,           ///< comms active response
    COMMS_ACTIVE_NOTF,          ///< comms active notification
    COMMS_SLEEP_REQ,            ///< comms sleep request
    COMMS_SLEEP_RSP,            ///< comms sleep response
    COMMS_SLEEP_NOTF,           ///< comms sleep notification
    COMMS_DFU_REQ,              ///< comms device firmware request
    COMMS_DFU_RSP,              ///< comms device firmware response
    COMMS_DFU_NOTF,             ///< comms device firmware notification
    COMMS_HEALTH_DATA_REQ,      ///< comms health data request
    COMMS_HEALTH_DATA_RSP,      ///< comms health data response
    COMMS_HEALTH_DATA_NOTF,     ///< comms health data notification
    COMMS_LOG_CFG_REQ,          ///< comms log configuration request
    COMMS_LOG_CFG_STS,          ///< comms log configuration status
    COMMS_TX_CFG_REQ,           ///< comms transmit configuration request
    COMMS_TX_CFG_STS,           ///< comms transmit configuration status
    COMMS_RX_CFG_REQ,           ///< comms receive configuration request
    COMMS_RX_CFG_STS,           ///< comms receive configuration status
    COMMS_SYS_CFG_REQ,
    COMMS_SYS_CFG_STS,
    COMMS_FE_CFG_REQ,           ///< comms feed configuration request
    COMMS_FE_CFG_STS,           ///< comms feed configuration status
    COMMS_CALIB_REQ,            ///< comms calibration request
    COMMS_CALIB_STS,            ///< comms calibration status
    COMMS_FRMWR_UPDT_REQ,       ///< comms framework update request
    COMMS_FRMWR_UPDT_STS,       ///< comms framework update status
    COMMS_TX_REQ,               ///< comms transmit request
    COMMS_TX_STS,               ///< comms transmit status
    COMMS_RX_REQ,               ///< comms receive request
    COMMS_RX_STS,               ///< comms receive status
    COMMS_IDLE_REQ,             ///< comms idle request
    COMMS_IDLE_STS,             ///< comms idle status
    COMMS_TX_RX_REQ,            ///< comms transmit and receive request
    COMMS_TX_RX_STS,            ///< comms transmit and receive status
}e_comms_event;

typedef enum
{
    COMMS_EXTRNL_SET_TX_CFG_REQ = 100, ///< comms external tx configuration set request
    COMMS_EXTRNL_SET_TX_CFG_STS,       ///< comms external tx configuration set status
    COMMS_EXTRNL_GET_TX_CFG_REQ,       ///< comms external tx configuration get request
    COMMS_EXTRNL_GET_TX_CFG_STS,       ///< comms external tx configuration get status
    COMMS_EXTRNL_SET_RX_CFG_REQ,       ///< comms external rx configuration set request
    COMMS_EXTRNL_SET_RX_CFG_STS,       ///< comms external rx configuration set status
    COMMS_EXTRNL_GET_RX_CFG_REQ,       ///< comms external rx configuration get request
    COMMS_EXTRNL_GET_RX_CFG_STS,       ///< comms external rx configuration get status
    COMMS_EXTRNL_SET_SYS_CFG_REQ,      ///< comms external sys configuration set request
    COMMS_EXTRNL_SET_SYS_CFG_STS,      ///< comms external sys configuration set status
    COMMS_EXTRNL_GET_SYS_CFG_REQ,      ///< comms external sys configuration get request
    COMMS_EXTRNL_GET_SYS_CFG_STS,      ///< comms external sys configuration get status
}e_comms_extrnl_event;

/**
  * @brief param option in comms
  */
typedef enum
{
    COMMS_FALSE,
    COMMS_TRUE
}e_comms_param_opt_sts;

/**
  * @brief  tx,rx simentaneously run in comms
  */
typedef enum
{
    COMMS_TX_MODE,             ///< mode in comms transmit
    COMMS_RX_MODE,             ///< mode in comms receiving
    COMMS_TX_RX_MODE           ///< mode for both comms transmit and receive
}e_comms_tx_rx_mode;

/**
  * @brief  It selects type of primary and secondary boot mode
  */
typedef enum
{
    COMMS_BOOT_MODE_PRIMARY,       ///< select the primary boot mode
    COMMS_BOOT_MODE_SECONDARY      ///< select the secondary boot mode
}e_comms_boot_mode;
/**
  * @brief  It define the various calibration type
  */
typedef enum
{
    COMMS_TX_CALIB_MODE,     ///< execute tx calibration mode
    COMMS_RX_CALIB_MODE,     ///< execute rx calibration mode
    COMMS_FE_CALIB_MODE,     ///< execute fe calibration mode
    COMMS_CALIB_ALL          ///< calibrate the all mode
}e_comms_calib_type;
/**
  * @brief  Read all telemetry or param telemetry
  */
typedef enum
{
    COMMS_READ_TM_ALL,        ///< comms read telemetry all
    COMMS_READ_TM_PARAM       ///< comms read telemetry parameter
}e_comms_tm_type;
/**
  * @brief  Read DFU trigger all or trigger particular parameter
  */
typedef enum
{
    COMMS_DFU_TRIGGER_ALL,        ///< comms dfu trigger all
    COMMS_DFU_TRIGGER_PARAM      ///< comms dfu trigger param
}u8;

typedef enum
{
	COMMS_RESET_SUCCESS,
	COMMS_RESET_FAILURE
}e_comms_reset_sts;

typedef enum
{
	COMMS_BOOT_CFG_SUCCESS,
	COMMS_BOOT_CFG_FAILURE

}e_comms_boot_cfg_sts;

/**
 * @brief It decides whether read telemetry is a success or failure.
*/
typedef enum
{
    SBAND_TM_SUCCESS=0,     ///< sband read telemetry is success
    SBAND_TM_FAILURE=1,       ///< sband read telemetry is fail
    SBAND_TM_BUSY=2       ///< sband read telemetry is fail
}e_sband_tm_sts;

/**
  * @brief  comms tc id enum definition
  */
/*
typedef enum
{
    TC_SET_COMMS_TX_CFG = 300,
    TC_SET_COMMS_TX_CFG_FREQ,
    TC_SET_COMMS_TX_CFG_TYPE,
    TC_SET_COMMS_TX_CFG_RATE,
    TC_SET_COMMS_TX_CFG_ROLLOFF,
    TC_SET_COMMS_TX_CFG_POUT,
    TC_SET_COMMS_TX_CFG_ALC_MODE,
    TC_SET_COMMS_TX_CFG_RS,
    TC_SET_COMMS_TX_CFG_CC,
    TC_SET_COMMS_TX_CFG_RAND,
    TC_SET_COMMS_TX_CFG_CRC,
    TC_SET_COMMS_TX_CFG_IDLETIME,
    TC_SET_COMMS_TX_CFG_SIZE,
    TC_SET_COMMS_TX_CFG_ID,
    TC_SET_COMMS_TX_CFG_CRYPTO,
    TC_SET_COMMS_TX_CFG_PA_TEMPLIMIT,
	TC_SET_COMMS_ASM_CFG,

    TC_SET_COMMS_RX_CFG = 319,
    TC_SET_COMMS_RX_CFG_FREQ,
    TC_SET_COMMS_RX_CFG_TYPE,
    TC_SET_COMMS_RX_CFG_RATE,
    TC_SET_COMMS_RX_CFG_ROLLOFF,
    TC_SET_COMMS_RX_CFG_AFC,
    TC_SET_COMMS_RX_CFG_RS,
    TC_SET_COMMS_RX_CFG_CC,
    TC_SET_COMMS_RX_CFG_RAND,
    TC_SET_COMMS_RX_CFG_CRC,
    TC_SET_COMMS_RX_CFG_SIZE,
    TC_SET_COMMS_RX_CFG_ID,
    TC_SET_COMMS_RX_CFG_CRYPTO,
	TC_SET_COMMS_BCH_CFG,
	TC_COMMS_SBAND_BEACON_CFG,
	TC_COMMS_SBAND_BEACON_START,
	TC_COMMS_SBAND_BEACON_STOP,


    TC_SET_COMMS_SYS_CFG = 340,
	TC_SET_COMMS_ERR_CFG,
    TC_SET_COMMS_BOOT_CFG,
    TC_SET_COMMS_GWDT_CFG,
    TC_SET_COMMS_CAN_CFG,
    TC_SET_COMMS_UART_CFG,
    TC_SET_COMMS_CSP_CFG,
    TC_SET_COMMS_NET_CFG,

    TC_GET_COMMS_TX_CFG = 350,
    TC_GET_COMMS_TX_CFG_FREQ,
    TC_GET_COMMS_TX_CFG_TYPE,
    TC_GET_COMMS_TX_CFG_RATE,
    TC_GET_COMMS_TX_CFG_ROLLOFF,
    TC_GET_COMMS_TX_CFG_POUT,
    TC_GET_COMMS_TX_CFG_ALC_MODE,
    TC_GET_COMMS_TX_CFG_RS,
    TC_GET_COMMS_TX_CFG_CC,
    TC_GET_COMMS_TX_CFG_RAND,
    TC_GET_COMMS_TX_CFG_CRC,
    TC_GET_COMMS_TX_CFG_IDLETIME,
    TC_GET_COMMS_TX_CFG_SIZE,
    TC_GET_COMMS_TX_CFG_ID,
    TC_GET_COMMS_TX_CFG_CRYPTO,
    TC_GET_COMMS_TX_CFG_PA_TEMPLIMIT,
    TC_GET_COMMS_TX_CFG_FRAMES,
    TC_GET_COMMS_TX_CFG_PWR_FWD,
    TC_GET_COMMS_TX_CFG_PWR_RFL,
    TC_GET_COMMS_RX_CFG,
    TC_GET_COMMS_RX_CFG_FREQ,
    TC_GET_COMMS_RX_CFG_TYPE,
    TC_GET_COMMS_RX_CFG_RATE,
    TC_GET_COMMS_RX_CFG_ROLLOFF,
    TC_GET_COMMS_RX_CFG_AFC,
    TC_GET_COMMS_RX_CFG_RS,
    TC_GET_COMMS_RX_CFG_CC,
    TC_GET_COMMS_RX_CFG_RAND,
    TC_GET_COMMS_RX_CFG_CRC,
    TC_GET_COMMS_RX_CFG_SIZE,
    TC_GET_COMMS_RX_CFG_ID,
    TC_GET_COMMS_RX_CFG_CRYPTO,
    TC_GET_COMMS_RX_CFG_FRAMES,
    TC_GET_COMMS_RX_CFG_DETECTED,
    TC_GET_COMMS_RX_CFG_RSSI,
    TC_GET_COMMS_RX_CFG_FREQERR,
    TC_GET_COMMS_RX_CFG_SYMERR,
    TC_GET_COMMS_RX_CFG_EBN0,
    TC_GET_COMMS_RX_CFG_CARRIER_LOCK,
    TC_GET_COMMS_RX_FRAME_LOCK,
    TC_GET_COMMS_SYS_CFG,
    TC_GET_COMMS_BOOT_ACTIVATE,
    TC_GET_COMMS_BOOT_CFG,
    TC_GET_COMMS_GWDT_CFG,
    TC_GET_COMMS_CAN_CFG,
    TC_GET_COMMS_UART_CFG,
    TC_GET_COMMS_CSP_CFG,
    TC_GET_COMMS_NET_CFG,
    TC_GET_COMMS_TM_INFO,
    TC_GET_COMMS_RX_TM_INFO,
    TC_GET_COMMS_TX_TM_INFO,
    TC_COMMS_LOAD_CFG,
    TC_COMMS_SAVE_CFG,
    TC_COMMS_RESET_CFG,
    TC_COMMS_LOCK_CFG,
    TC_COMMS_UNLOCK_CFG,
    TC_COMMS_ERASE_CFG,
    TC_COMMS_FW_CFG,
    TC_COMMS_CUSTOM_TX,
	TC_COMMS_RESERVED,
    TC_COMMS_INITIAL_SYNC,
	TC_SBAND_GET_TM_STORE,
	TC_SBAND_GET_TM_ALL,
	TC_COMMS_BEACON_TX,
	TC_GET_COMMS_CSP_TM_INFO,
	TC_GET_COMMS_ASM_CFG,
	TC_GET_COMMS_BCH_CFG,
	TC_GET_COMMS_BEACON_CFG,
	TC_COMMS_RX_SEL_CFG,
	TC_COMMS_RX_SEL_DSB,

    TC_SBAND_SET_IDLE_CFG = 450,
    TC_SBAND_SET_RESET,
    TC_SBAND_SET_START_RF_RCV,
    TC_SBAND_SET_RF_XMT_DATA,
    TC_SBAND_SET_DVBS2_CONF,
    TC_SBAND_SET_IP_ADR_SAVE,
    TC_SBAND_SET_IP_ADR,
    TC_SBAND_GET_IP_ADR,
    TC_SBAND_GET_FLAGS_CONF,
    TC_SBAND_SET_FLAGS_CONF,
    TC_SBAND_SET_VERSION,
    TC_SBAND_GET_VERSION,
    TC_SBAND_SET_DEVICE_CONF,
    TC_SBAND_GET_DEVICE_CONF,
    TC_SBAND_GET_FEATURE_SELECT,
    TC_SBAND_GET_COMMS_TM_INFO,
    TC_SBAND_GET_XPA_INF,
    TC_SBAND_SET_PROD_KEY,


}e_comms_tc_id;
*/

/**
  * @brief  comms tm id enum definition
  */
/*
typedef enum
{
    TM_SET_COMMS_TX_CFG = 300,
    TM_SET_COMMS_TX_CFG_FREQ,
    TM_SET_COMMS_TX_CFG_TYPE,
    TM_SET_COMMS_TX_CFG_RATE,
    TM_SET_COMMS_TX_CFG_ROLLOFF,
    TM_SET_COMMS_TX_CFG_POUT,
    TM_SET_COMMS_TX_CFG_ALC_MODE,
    TM_SET_COMMS_TX_CFG_RS,
    TM_SET_COMMS_TX_CFG_CC,
    TM_SET_COMMS_TX_CFG_RAND,
    TM_SET_COMMS_TX_CFG_CRC,
    TM_SET_COMMS_TX_CFG_IDLETIME,
    TM_SET_COMMS_TX_CFG_SIZE,
    TM_SET_COMMS_TX_CFG_ID,
    TM_SET_COMMS_TX_CFG_CRYPTO,
    TM_SET_COMMS_TX_CFG_PA_TEMPLIMIT,
	TM_SET_COMMS_ASM_CFG,

    TM_SET_COMMS_RX_CFG = 319,
    TM_SET_COMMS_RX_CFG_FREQ,
    TM_SET_COMMS_RX_CFG_TYPE,
    TM_SET_COMMS_RX_CFG_RATE,
    TM_SET_COMMS_RX_CFG_ROLLOFF,
    TM_SET_COMMS_RX_CFG_AFC,
    TM_SET_COMMS_RX_CFG_RS,
    TM_SET_COMMS_RX_CFG_CC,
    TM_SET_COMMS_RX_CFG_RAND,
    TM_SET_COMMS_RX_CFG_CRC,
    TM_SET_COMMS_RX_CFG_SIZE,
    TM_SET_COMMS_RX_CFG_ID,
    TM_SET_COMMS_RX_CFG_CRYPTO,
	TM_SET_COMMS_BCH_CFG,
	TM_COMMS_SBAND_BEACON_CFG,
	TM_COMMS_SBAND_BEACON_START,
	TM_COMMS_SBAND_BEACON_STOP,

    TM_SET_COMMS_SYS_CFG = 340,
	TM_SET_COMMS_ERR_CFG,
    TM_SET_COMMS_BOOT_CFG,
    TM_SET_COMMS_GWDT_CFG,
    TM_SET_COMMS_CAN_CFG,
    TM_SET_COMMS_UART_CFG,
    TM_SET_COMMS_CSP_CFG,
    TM_SET_COMMS_NET_CFG,
    TM_GET_COMMS_TX_CFG = 350,
    TM_GET_COMMS_TX_CFG_FREQ,
    TM_GET_COMMS_TX_CFG_TYPE,
    TM_GET_COMMS_TX_CFG_RATE,
    TM_GET_COMMS_TX_CFG_ROLLOFF,
    TM_GET_COMMS_TX_CFG_POUT,
    TM_GET_COMMS_TX_CFG_ALC_MODE,
    TM_GET_COMMS_TX_CFG_RS,
    TM_GET_COMMS_TX_CFG_CC,
    TM_GET_COMMS_TX_CFG_RAND,
    TM_GET_COMMS_TX_CFG_CRC,
    TM_GET_COMMS_TX_CFG_IDLETIME,
    TM_GET_COMMS_TX_CFG_SIZE,
    TM_GET_COMMS_TX_CFG_ID,
    TM_GET_COMMS_TX_CFG_CRYPTO,
    TM_GET_COMMS_TX_CFG_PA_TEMPLIMIT,
    TM_GET_COMMS_TX_CFG_FRAMES,
    TM_GET_COMMS_TX_CFG_PWR_FWD,
    TM_GET_COMMS_TX_CFG_PWR_RFL,
    TM_GET_COMMS_RX_CFG,
    TM_GET_COMMS_RX_CFG_FREQ,
    TM_GET_COMMS_RX_CFG_TYPE,
    TM_GET_COMMS_RX_CFG_RATE,
    TM_GET_COMMS_RX_CFG_ROLLOFF,
    TM_GET_COMMS_RX_CFG_AFC,
    TM_GET_COMMS_RX_CFG_RS,
    TM_GET_COMMS_RX_CFG_CC,
    TM_GET_COMMS_RX_CFG_RAND,
    TM_GET_COMMS_RX_CFG_CRC,
    TM_GET_COMMS_RX_CFG_SIZE,
    TM_GET_COMMS_RX_CFG_ID,
    TM_GET_COMMS_RX_CFG_CRYPTO,
    TM_GET_COMMS_RX_CFG_FRAMES,
    TM_GET_COMMS_RX_CFG_DETECTED,
    TM_GET_COMMS_RX_CFG_RSSI,
    TM_GET_COMMS_RX_CFG_FREQERR,
    TM_GET_COMMS_RX_CFG_SYMERR,
    TM_GET_COMMS_RX_CFG_EBN0,
    TM_GET_COMMS_RX_CFG_CARRIER_LOCK,
    TM_GET_COMMS_RX_FRAME_LOCK,
    TM_GET_COMMS_SYS_CFG,
    TM_GET_COMMS_BOOT_ACTIVATE,
    TM_GET_COMMS_BOOT_CFG,
    TM_GET_COMMS_GWDT_CFG,
    TM_GET_COMMS_CAN_CFG,
    TM_GET_COMMS_UART_CFG,
    TM_GET_COMMS_CSP_CFG,
    TM_GET_COMMS_NET_CFG,
    TM_GET_COMMS_TM_INFO,
    TM_GET_COMMS_RX_TM_INFO,
    TM_GET_COMMS_TX_TM_INFO,
    TM_COMMS_LOAD_CFG,
    TM_COMMS_SAVE_CFG,
    TM_COMMS_RESET_CFG,
    TM_COMMS_LOCK_CFG,
    TM_COMMS_UNLOCK_CFG,
    TM_COMMS_ERASE_CFG,
    TM_COMMS_FW_CFG,
    TM_COMMS_CUSTOM_TX,
    TM_COMMS_RESERVED,
    TM_COMMS_INITIAL_SYNC,
	TM_SBAND_GET_TM_STORE,
	TM_SBAND_GET_TM_ALL,
	TM_COMMS_BEACON_TX,
	TM_GET_COMMS_CSP_TM_INFO,
	TM_GET_COMMS_ASM_CFG,
	TM_GET_COMMS_BCH_CFG,
	TM_GET_COMMS_BEACON_CFG,
	TM_COMMS_RX_SEL_CFG,
	TM_COMMS_RX_SEL_DSB,

    TM_SBAND_SET_IDLE_CFG = 450,
    TM_SBAND_SET_RESET,
    TM_SBAND_SET_START_RF_RCV,
    TM_SBAND_SET_RF_XMT_DATA,
    TM_SBAND_SET_DVBS2_CONF,
    TM_SBAND_SET_IP_ADR_SAVE,
    TM_SBAND_SET_IP_ADR,
    TM_SBAND_GET_IP_ADR,
    TM_SBAND_GET_FLAGS_CONF,
    TM_SBAND_SET_FLAGS_CONF,
    TM_SBAND_SET_VERSION,
    TM_SBAND_GET_VERSION,
    TM_SBAND_SET_DEVICE_CONF,
    TM_SBAND_GET_DEVICE_CONF,
    TM_SBAND_GET_FEATURE_SELECT,
	TM_SBAND_GET_COMMS_TM_INFO,
    TM_SBAND_GET_XPA_INF,
    TM_SBAND_SET_PROD_KEY,


}e_comms_tm_id;
*/

typedef struct
{
    uint32_t type;
    uint32_t size;
    uint32_t periodicity;
    uint32_t pld_count;
    uint32_t node;
}comms_sync_s;


/**
 * @brief It decides the comms tx config success or failure.
 */
typedef enum
{
    COMMS_TX_CFG_SUCCESS=0,  ///< tx comms config is success
    COMMS_TX_CFG_FAILURE=1    ///< tx comms config is fail
}e_comms_tx_cfg_sts;
/**
 * @brief It decides Rx comms config success or failure.
*/
typedef enum
{
    COMMS_RX_CFG_SUCCESS=0,  ///< rx comms config is success
    COMMS_RX_CFG_FAILURE=1    ///< rx comms config is fail
}e_comms_rx_cfg_sts;
/**
 * @brief It decides system config succeeds or fails.
*/
typedef enum
{
    COMMS_SYS_CFG_SUCCESS=0,   ///< comms  system config is success
    COMMS_SYS_CFG_FAILURE=1     ///< comms system config is fail
}e_comms_sys_cfg_sts;
/**
 * @brief It decides calibration trigger is a success or failure.
*/
typedef enum
{
    COMMS_CALIB_TRGR_SUCCESS=0,   ///< comms calibration trigger is success
    COMMS_CALIB_TRGR_FAILURE=1     ///< comms calibration trigger is fail
}e_comms_calib_trgr_sts;
/**
 * @brief It decides comms tx_rx enable is a success or failure.
*/
typedef enum
{
    COMMS_TX_RX_ENBL_SUCCESS=0,    ///< enable comms tx_rx is success
    COMMS_TX_RX_ENBL_FAILURE=1      ///< enable comms tx_rx is fail
}e_comms_tx_rx_enbl_sts;
/**
 * @brief It decides whether the comms DFU trigger is a success or failure.
*/
typedef enum
{
    COMMS_DFU_TRGR_SUCCESS=0,      ///< comms trigger DFU is success
    COMMS_DFU_TRGR_FAILURE=1        ///< comms trigger DFU is fail
}e_comms_dfu_trgr_sts;
/**
 * @brief It decides whether read telemetry is a success or failure.
*/
typedef enum
{
    COMMS_READ_TM_SUCCESS=0,     ///< comms read telemetry is success
    COMMS_READ_TM_FAILURE=1       ///< comms read telemetry is fail
}e_comms_read_tm_sts;

/// comms operation status
typedef enum
{
    COMMS_RESET_DONE,
    COMMS_RESET_FAIL,
    COMMS_BYPASS_RQST,
    COMMS_BOOT_DONE,
    COMMS_BOOT_FAIL,
    COMMS_DFU_DONE,
    COMMS_DFU_FAIL,
    COMMS_LOG_CFG_DONE,
    COMMS_LOG_CFG_FAIL,
    COMMS_TX_CFG_DONE,
    COMMS_TX_CFG_FAIL,
    COMMS_RX_CFG_DONE,
    COMMS_RX_CFG_FAIL,
    COMMS_FE_CFG_DONE,
    COMMS_FE_CFG_FAIL,
    COMMS_CALIB_DONE,
    COMMS_CALIB_FAIL,
    COMMS_SLEEP_DONE,
    COMMS_SLEEP_FAIL,
    COMMS_TX_DONE,
    COMMS_TX_FAIL,
    COMMS_RX_DONE,
    COMMS_RX_FAIL,
    COMMS_TX_RX_DONE,
    COMMS_TX_RX_FAIL,
    COMMS_IDLE_DONE,
    COMMS_IDLE_FAIL
}e_comms_et;

/**
 * @brief UHF buffered TM information queue id
 */
typedef enum
{
	SBAND_PERIODIC_TM_QUEUE_ID,
        SBAND_TM_MAX_QUEUE_ID
}sband_buff_fw_queue_id;



//TODO: Resolve this
#ifndef LINUX_TEMP_PORT
typedef signed char int8_t;
typedef signed long int32_t;
#endif

//extern typedef uint8_t (*CSW_SM_HDLR)(uint16_t msg_id, void *payload);

/**
* @brief This function create the COMMS state and event threads 
*
* @return Thread status
*/
int32_t comms_csw_init(void);
/**
* @brief This function step-by-step process the COMMS states to the help
* of event thread request
*
* @param param : unused pointer
*/
void comms_csw_main(void *param);

/**
* @brief This API handle the comms finite states machine
*
* @param state   : current state
* @param msg_id  : Identity of state
* @param payload : pointer to payload
*
* @return state
*/
uint8_t comms_fsm_hdlr_fn(uint8_t state,uint16_t msg_id, void *payload);

/**
* @brief This function handle comms initialization state
*
* @param msg_id  : Identity of state
* @param payload : Pointer to payload
*
* @return state of comms
*/
uint8_t comms_init_state_hdlr(uint16_t msg_id, void *payload);
/**
* @brief This function handle the comms boot state
*
* @param msg_id  : Identity of state
* @param payload : Pointer to payload
*
* @return state of comms
*/
uint8_t comms_boot_state_hdlr(uint16_t msg_id, void *payload);
/**
* @brief This function handles comms DFU states
*
* @param msg_id  : Identity of state
* @param payload : Pointer to payload
*
* @return state of comms
*/
uint8_t comms_dfu_state_hdlr(uint16_t msg_id, void *payload);
/**
* @brief This function handle comms configuration states
*
* @param msg_id  : Identity of state
* @param payload : Pointer to payload
*
* @return state of comms
*/
uint8_t comms_cfg_state_hdlr(uint16_t msg_id, void *payload);
/**
* @brief This function handle comms calibration state
*
* @param msg_id  : Identity of state
* @param payload : Pointer to payload
*
* @return state of comms
*/
uint8_t comms_calib_state_hdlr(uint16_t msg_id, void *payload);
/**
* @brief This API handle the comms idle state
*
* @param msg_id  : Identity of state
* @param payload : Pointer to payload
*
* @return state of comms
*/
uint8_t comms_sleep_idle_state_hdlr(uint16_t msg_id, void *payload);
/**
* @brief This API handle the comms active states
*
* @param msg_id  : Identity of state
* @param payload : Pointer to payload
*
* @return state of comms
*/
uint8_t comms_active_state_hdlr(uint16_t msg_id, void *payload);
/**
* @brief This functions handle the comms safe mode state
*
* @param msg_id  : Identity of state
* @param payload : Pointer to payload
*
* @return safe mode state
*/
uint8_t comms_safe_mode_state_hdlr(uint16_t msg_id, void *payload);
/**
* @brief This function handle the comms error state
*
* @param msg_id  : Identity of state
* @param payload : Pointer to payload
*
* @return Error state
*/
uint8_t comms_error_state_hdlr(uint16_t msg_id, void *payload);
/**
* @brief This function handling Bypass the comms states
*
* @param msg_id  : Identity of state
* @param payload : Pointer to payload
*
* @return state of comms
*/
uint8_t comms_bypass_state_hdlr(uint16_t msg_id, void *payload);
/**
* @brief This function send the sband ground contact status
*
* @param state : sband state
*/
void sband_gs_contact_status_upd_itc(uint16_t state,uint8_t radio_id);

/**
* @brief This function send the sband ground contact status
*
* @param state : sband state
*/
void sband_gs_contact_status_upd(uint16_t state);

void backdoor_soc_gs_contact_status_upd_itc(uint16_t state);

/**
* @brief This function check the sband ground contact
*
* @return sband ground contact
*/
uint8_t is_sband_gs_contact_valid(void);

/**
 * @brief This function send ground contact status to OTSU module
 */
void send_otsu_gssync_sts(uint8_t sts);

/**
* @brief This function monitor and report the sband health
*/
void sband_health_report_tm(void);

/**
 *@brief This function monitor sband health and update it
*/
void sband_xlinks_health_report_tm(void);

/**
 *@brief This function monitor sband health and update it
*/
void sband_reinit_exp_hdlr(void);

uint8 sband_get_state(void);

uint8 sband_get_state_X(void);

/**
 * @brief This function used to reqquest queue to push the health data 
 */
void tc_sband_buff_fw_req_queue(uint32 instance_size, uint32 num_of_instance, uint8 queue_id);

/**
 * @brief This function used to enqueue the data into the health metric queue
 */
void tc_sband_buff_fw_enqueue_req(uint8* data, uint8 queue_id);

#ifdef __cplusplus
}
#endif
#endif /*COMMS_CSW_H */
