#ifndef _DEVICE_UHD_C_H_
#define _DEVICE_UHD_C_H_


#include "device_uhd_struct.h"
// #include "device_uhd_cpp.h"
#include <stdint.h>





typedef void (*rx_data_cbk_t)(int channel, void *pdata, int length);

extern "C"
{
    int32_t ex_declare init9002(void **phandle);
    int32_t ex_declare free9002(void **phandle);
    int32_t ex_declare isDevOpened(void *phandle, int32_t *result);
    // int32_t ex_declare findDevices(void *phandle, uhd::device_addrs_t *addrs);
    // int32_t ex_declare openDevice(void *phandle,uhd::device_addr_t addr);
    int32_t ex_declare closeDevice(void *phandle);
    int32_t ex_declare findDevInfos(void *phandle, char infos[1000]);
    int32_t ex_declare findDevInfos2(void *phandle, char infos[1000]);
    int32_t ex_declare getDevTree(void *phandle, char tree_infos[1000]);
    int32_t ex_declare setDevClockSource(void *phandle, char sourceStr[1000]);
    int32_t ex_declare getDevClockSource(void *phandle, char sourceStr[1000]);
    int32_t ex_declare setDevInClock(void *phandle, double clockFreq);
    int32_t ex_declare getDevInClockRange(void *phandle, double *min, double *max);
    int32_t ex_declare getDevInClock(void *phandle, double *val);
    int32_t ex_declare getDevRXChCount(void *phandle, size_t *val);
    int32_t ex_declare getDevTXChCount(void *phandle, size_t *val);
    int32_t ex_declare setDevParam(void *phandle, char chStr[50], UHD_ParamType paramType, double paramValue);
    int32_t ex_declare getDevParam(void *phandle, char chStr[50], UHD_ParamType paramType,double *paramValue);
    int32_t ex_declare getDevParamMin(void *phandle, double *val);
    int32_t ex_declare getDevParamMax(void *phandle, double *val);
    int32_t ex_declare setAllAntenna(void *phandle, int32_t *result);
    int32_t ex_declare setDevDDCParam_Any(void *phandle, char chStr[50], unsigned int jcqOffset, unsigned int jcqData);
    int32_t ex_declare getDevDDCParam_Any(void *phandle, char chStr[50], unsigned int jcqOffset, unsigned int *jcqData);
    int32_t ex_declare setDevDataSwitch(void *phandle, char chStr[50], UHD_ParamType dataType, unsigned char ZDCh, int bSwitch);
    int32_t ex_declare getDevDataSwitch(void *phandle, char chStr[50], UHD_ParamType dataType, unsigned char ZDCh, int *bSwitch);
    int32_t ex_declare setDevZDParam(void *phandle, char chStr[50], unsigned char ZDCh, long long centerfreq, int bw, int sample);
    int32_t ex_declare getDevZDParam(void *phandle, char chStr[50], unsigned char ZDCh, long long *centerfreq, int *bw, int *sample);
    int32_t ex_declare getDevZDCenterRange(void *phandle, char chStr[50], long long &min, long long &max);
    int32_t ex_declare getDevZDBandWidthRange(void *phandle, char chStr[50], int &min, int &max);
    int32_t ex_declare getDevZDSampleFreqRange(void *phandle, char chStr[50], int arr[13], int *valid_len);
    int32_t ex_declare setDevFFTParam(void *phandle, UHD_FFTWin fftWin, UHD_FFTLen fftLen, int fftPeriod_ms);
    int32_t ex_declare getDevFFTParam(void *phandle, UHD_FFTWin *fftWin, UHD_FFTLen *fftLen, int *fftPeriod_ms);
    int32_t ex_declare getDevRecvSpeed(void *phandle, int channel, double *val);
    int32_t ex_declare isDevRecving(void *phandle,int channel, int32_t *result);
    int32_t ex_declare startDevRecv(void *phandle, int channel, rx_data_cbk_t rx_cbk);
    int32_t ex_declare stopDevRecv(void *phandle, int channel);
    int32_t ex_declare getDevSendSpeed(void *phandle, int channel, double *val);
    int32_t ex_declare isDevSending(void *phandle, int channel, int32_t *rusult);
    int32_t ex_declare startDevSend(void *phandle, int channel, unsigned long long send_cf, unsigned long long data_sf, char *filename, int bwhile);
    int32_t ex_declare stopDevSend(void *phandle, int channel);
    int32_t ex_declare getGPSInfo(void *phandle, char gps_info[50]);
    int32_t ex_declare setLedEnable(void *phandle, int led_num, int bEnable);
    int32_t ex_declare getLedEnable(void *phandle,int led_num, int *bEnable);


   
    
    typedef void(*adsb_msg_cbk_t)(void *pusr,char *pmsg,int msglen);

    int32_t ex_declare init_adsb9002(void **phandle,adsb_msg_cbk_t cbk,void *pusr);
    int32_t ex_declare free_adsb9002(void **phandle);



    // 新接口 ：时间 20251107 ， 
     //TODO: 1 增加 dma 回调函数 iq 的（ddc,ffc）
}

#include <string>
#include "device_uhd_c.h"
#include <string>
#include <mutex>


extern "C"
{


    ex_declare void adsb_close();

    typedef void (*iq_cbk_t)(void* phandle, void* pdata, uint64_t length);

    typedef int (*adsb_set_less_30Mhz_ddc_param_t)(uint64_t cf_hz, uint64_t sf_hz, uint64_t bw_hz, int8_t sw);
    typedef int (*adsb_set_less_30Mhz_fft_param_t)(uint64_t fftWin, uint64_t fftLen, int fftPeriod_ms, int8_t sw);
    ex_declare int adsb_set_iq_cbk(iq_cbk_t recv_cbk, void* pusr);
    ex_declare int adsb_set_less_30Mhz_ddc_param(uint64_t cf_hz, uint64_t sf_hz, uint64_t bw_hz, int8_t sw);
    ex_declare int adsb_set_less_30Mhz_fft_param(uint64_t fftWin, uint64_t fftLen, int fftPeriod_ms, int8_t sw);

}


#endif //_DEVICE_UHD_C_H_