/**
 * @file comms_sband_xlink_api.h
 *
 * @brief This file has the function prototypes of X-Band configuration APIs
 *
 */

#ifndef COMMS_SBAND_XLINK_API_H
#define COMMS_SBAND_XLINK_API_H

#include "exo_types.h"

#define BYTESWAP(x)				((((x) & 0xff) << 8) | (((x) & 0xff00) >> 8))
#define WORDSWAP(x)				((((x) & 0xff) << 24) | \
						 (((x) & 0xff00) << 8) | \
						 (((x) & 0xff0000UL) >> 8) | \
						 (((x) & 0xff000000UL) >> 24))


/*##########################################################################################*/
/*************	Function Declaration (Prototypes)						*********************/
/*##########################################################################################*/
/****************************************************************************************/
/**
 * @defgroup ServiceServerFunctionPub ServiceServer public functions
 * puplic declarations for ServiceServer functions
 * @{
 *****************************************************************************************/

/*	sband_Service_Validate_Key					*************************************************/
/**
 * @ingroup	ServiceServerFunctionPub
 * @brief	checks if service_server is not blocked and received key is valid. For next service
 * 			server processing commands, the received features are stored temporary!
 *
 * @param	[in] RcvData (Pointer to the received service_data)
 *
 * @return	-1 if key is invalid, -2 if processing blocked, 0 if succeed/valid
 * @note		Its recommended to call this function before next service processing
 * 			functions are called! (because of features)
 *********************************************************************************************/
int8 sband_Service_Validate_Key(uint8 *RcvData);

/*	sband_Service_Idle					*********************************************************/
/**
 * @ingroup	ServiceServerFunctionPub
 * @brief	processes a received SERVICE_IDLE command
 *
 * @param	[in] RcvData (Pointer to TcpRcvData after service_event)
 * @param	[in]  uint32 DataRead (number of received bytes in TCP Buffer)
 *
 * @return	number of bytes which processed
 * @note		none
 *********************************************************************************************/
uint32 sband_Service_Idle(uint8 *RcvData, uint32 DataRead);

/*	sband_Service_Reset					*********************************************************/
/**
 * @ingroup	ServiceServerFunctionPub
 * @brief	processes a received SERVICE_RESET command
 *
 * @param	[in] RcvData (Pointer to TcpRcvData after service_event)
 * @param	[in]  uint32 DataRead (number of received bytes in TCP Buffer)
 *
 * @return	number of bytes which processed
 * @note		none
 *********************************************************************************************/
uint32 sband_Service_Reset(uint8 *RcvData, uint32 DataRead);

/*	sband_Service_XmtData					*********************************************************/
/**
 * @ingroup	ServiceServerFunctionPub
 * @brief	processes a received SERVICE_RF_XMT_DATA command
 *
 * @param	[in] RcvData (Pointer to TcpRcvData -> service_event)
 * @param	[in]  uint32 DataRead (number of received bytes in TCP Buffer)
 *
 * @return	number of bytes which processed, 0- No Data processed or -1 if Error
 *
 * @note		count down NumByteForAi for test with reduced throughput -> TCP-Break
 *			==> no AiRcv and AiXmt Processing; no ADC-DMA is running -> for 10ms interval
 *			==> CountDown * 8Bit * 100(10ms Tick) = Mbits/s
 *
 *			-> max. 350000 => 280MBits/s
 *			350000 -> @1.000ms timer_tick -> ~168MBits/s @ 61% CPU-Load
 *			350000 -> @0.500us timer_tick -> ~256MBits/s @ 95% CPU-Load
 *			350000 -> @0.333us timer_tick -> ~280MBits/s @ 99% CPU-Load
 *
 *			-> min. < 5500 could be a problem for the other side because long TCP-Break (>1s)
 *			500    -> @1.000ms timer_tick -> 400kBits/s @ 2.0% CPU-Load (smaller basic load)
 *			500    -> @0.500ms timer_tick -> 400kBits/s @ 3.3% CPU-Load
 *			500    -> @0.333ms timer_tick -> 400kBits/s @ 4.7% CPU-Load (more throughput possible)
 *
 *********************************************************************************************/
int32 sband_Service_XmtData(uint8 *RcvData, uint32 DataRead);

/*	sband_Service_DevConf				*************************************************************/
/**
 * @ingroup	ServiceServerFunctionPub
 * @brief	processes a received SERVICE_DEVICE_CONF command
 *
 * @param	[in] RcvData (Pointer to TcpRcvData after service_event)
 * @param	[in] uint32 DataRead (number of received bytes in TCP Buffer)
 *
 * @return	number of bytes which processed
 * @note		Call sband_Service_Validate_Key function before, to ensure features are filled
 *********************************************************************************************/
uint32 sband_Service_DevConf(uint8 *RcvData, uint32 DataRead);

/*	sband_Service_GetFeatureSel		*************************************************************/
/**
 * @ingroup	ServiceServerFunctionPub
 * @brief	processes a received SERVICE_FEATURE_SELECT command
 *
 * @param	[in] RcvData (Pointer to TcpRcvData after service_event)
 * @param	[in] uint32 DataRead (number of received bytes in TCP Buffer)
 *
 * @return	number of bytes which processed
 * @note		Call sband_Service_Validate_Key function before, to ensure features are filled
 *********************************************************************************************/
uint32 sband_Service_GetFeatureSel(uint8 *RcvData, uint32 DataRead);

/*	sband_Service_GetHouseKeep		*************************************************************/
/**
 * @ingroup	ServiceServerFunctionPub
 * @brief	processes a received SERVICE_HOUSE_KEEP command
 *
 * @param	[in] RcvData (Pointer to TcpRcvData after service_event)
 * @param	[in] uint32 DataRead (number of received bytes in TCP Buffer)
 *
 * @return	number of bytes which processed
 * @note		none
 *********************************************************************************************/
uint32 sband_Service_GetHouseKeep(uint8 *RcvData, uint32 DataRead);

/*	sband_Service_StartRfRcv			*************************************************************/
/**
 * @ingroup	ServiceServerFunctionPub
 * @brief	processes a received SERVICE_START_RF_RCV command
 *
 * @param	[in] RcvData (Pointer to TcpRcvData after service_event)
 * @param	[in] uint32 DataRead (number of received bytes in TCP Buffer)
 *
 * @return	number of bytes which processed
 * @note		none
 *********************************************************************************************/
uint32 sband_Service_StartRfRcv(uint8 *RcvData, uint32 DataRead);

/*	sband_Service_Version				*************************************************************/
/**
 * @ingroup	ServiceServerFunctionPub
 * @brief	processes a received SERVICE_VERSION command
 *
 * @param	[in] RcvData (Pointer to TcpRcvData after service_event)
 * @param	[in] uint32 DataRead (number of received bytes in TCP Buffer)
 *
 * @return	number of bytes which processed
 * @note		none
 *********************************************************************************************/
uint32 sband_Service_Version(uint8 *RcvData, uint32 DataRead);

/*	sband_Service_IpAdr				*************************************************************/
/**
 * @ingroup	ServiceServerFunctionPub
 * @brief	processes a received SERVICE_IP_ADR or SERVICE_IP_ADR_SAVE command
 *
 * @param	[in] RcvData (Pointer to TcpRcvData after service_event)
 * @param	[in] uint32 DataRead (number of received bytes in TCP Buffer)
 *
 * @return	number of bytes which processed
 * @note		none
 *********************************************************************************************/
uint32 sband_Service_IpAdr(uint8 *RcvData, uint32 DataRead);
/**
* @brief 
*
* @param serv_event
* @param pld
*
* @return 
*/
uint32 sband_proc_tc_pld(uint32 serv_event, uint8 *pld);
/**
* @brief 
*
* @param RcvData
*
* @return 
*/
uint32 sband_proc_rcv_data(uint8 *RcvData, int len);

/**
* @brief 
*
* @param serv_event
*
* @return 
*/
uint32 sband_proc_tc(uint32 serv_event);

/**
 * @brief This function is used for processing the telecommand and
 *       send request to X-Band module via PS IPCC interface
 */
uint32 sband_proc_tc_pld(uint32 serv_event, uint8 *pld);

/**
 * @brief This function is used for processing the telecommand and
 *       send request to X-Band module via PS IPCC interface
 */
uint32 sband_proc_tc(uint32 serv_event);

void comms_init_iqs_cfg(void);
/** @} *//*defgroup ServiceServerFunctionPub ********************************************/
/** @} *//*defgroup ServiceServer ***********************************************************/

/**
 * @brief this function is handler for power vs atenuation look up table
 *
 */
float xlink_pwr_attn_val(int pwr, int frq);

/**
 * @brief this function is for get parameter and compute rssi
 *
 */
float xlink_rssi_compute(void);

/**
 * @brief this function is for get parameter and compute rssi
 *
 */
float comms_xlink_s_get_rssi( uint8_t rcv_ch_no );


/**
 * @brief this function is for set and get Device TX parameter
 *
 */
uint8_t comms_sband_xlink_tx_on(uint8 sband_iqs_tx_on);

/**
 * @brief this function is for set and get Device TX parameter
 *
 */
uint8 comms_sband_xlink_beacon_data(void);

/**
 *@Brief this is to read back initialize value of Xlink tx cfg
 */
uint8_t comms_sband_xlink_tx_cfg(void);

/**
 * @Brief this is to read back initialize value of xlink rx cfg
 */
uint8_t comms_sband_xlink_rx_cfg(void);

void comms_sband_rx_rcv_cfg(void);

void comms_sband_rx_tx_turn_on(void);

#endif /*COMMS_SBAND_XLINK_API_H */
