#ifndef __WRG526API_H__
#define __WRG526API_H__

#include <stdint.h>


#pragma pack(push,1)

typedef struct
{
    char        SerNum[9];
    uint8_t     Model;
    uint8_t     Spare;
    int32_t     Handle;
    uint16_t    Status;
    uint8_t     Power;
    uint8_t     Phase;
} G5_RADIO;

typedef struct
{
    uint32_t freq;    // receive frequency
    uint32_t freq_hi; // (reserved to extend frequency range)
    uint32_t fbot;    // bottom of current band filter
    uint32_t fbot_hi; // (reserved to extend frequency range)
    uint32_t ftop;    // top of current band filter
    uint32_t ftop_hi; // (reserved to extend frequency range)
    uint8_t  band;    // band#
    uint8_t  atten;   // Attenuation in dB
    uint8_t  filter;  // tuneable filter value
    uint8_t  flags;   // 0: 1 for preamp on,
                    // 1: 1 if manual filter setting, 
                    // 2: 0=860MHz IF, 1=480MHz IF 
} WR_RF;

typedef struct
{
    uint32_t freq;    // LO module output freq
    uint32_t ddsfreq; // dds output freq
    uint32_t vcofreq; // vco output freq
    uint16_t pllN;
    uint16_t pllR;
    uint8_t  index;   // index in VCO lookup table
    uint8_t  vconum;  // which VCO
    uint8_t  div;     // always=0 => not used
    uint8_t  flags;   // 0: 0 for hi-side, 1 for lo-side
                    // 1: settling speed
                    // 2: 0 for 480MHz IF, 1 for 860 (LO2 only)
} WR_LO;

typedef struct
{
    uint8_t gain;
    uint8_t spare[3];
} WR_IF;

typedef struct 
{
    uint32_t refclk;
    WR_RF    rf;
    WR_LO    lo1;
    WR_LO    lo2;
    WR_IF    if2;
    uint8_t  phase[8];
} G5_STATUS;

typedef struct 
{
    uint32_t   LO1_PLL;  // MASTER  (i2c-0xC0)
    uint32_t   LO1_DDS;  // MASTER  (not used in ver1)
    uint32_t   LO2_PLL;  // MASTER  (i2c-0xC2)
    uint32_t   LO2_DDS;  // MASTER (CS-IF2)
    uint8_t    RF_BAND;  // SLAVES (SR LSB)
    uint8_t    RF_ATTN;  // SLAVES (SR MSB)
    uint8_t    IF2_GAIN; // SLAVES (IF2-STB)
    uint8_t    LO1_PCA;   //MASTER (only for ver2)
    uint32_t   LO1_DACS;
    uint32_t   LO2_DACS;
    uint32_t   SPURA;
    uint32_t   SPURB;
} G5_HW;

#pragma pack(pop)

#ifdef __cplusplus
extern "C"
{
#endif

typedef int32_t (*G5_FIND_RADIOS)(G5_RADIO *Radios,uint32_t NumberOfRadios,uint32_t *RadiosFound);
typedef int32_t (*G5_OPEN_RADIOS)(G5_RADIO *Radios,uint32_t NumberOfRadios);
typedef void (*G5_CLOSE_RADIOS)(G5_RADIO *Radios,uint32_t NumberOfRadios);
typedef int32_t (*G5_SET_POWER)(G5_RADIO *Radios,uint32_t NumberOfRadios);
typedef int32_t (*G5_SET_FREQUENCY)(G5_RADIO *Radios,uint32_t NumberOfRadios,uint32_t Frequency,G5_STATUS *Status,G5_HW *Hw,uint8_t Force);
typedef int32_t (*G5_SET_RF_ATTN)(G5_RADIO *Radios,uint32_t NumberOfRadios,uint8_t Attn,G5_STATUS *Status,G5_HW *Hw);
typedef int32_t (*G5_SET_IF_GAIN)(G5_RADIO *Radios,uint32_t NumberOfRadios,uint8_t Gain,G5_STATUS *Status,G5_HW *Hw);
typedef int32_t (*G5_SET_PHASE)(G5_RADIO *Radios,uint32_t NumberOfRadios);
typedef int32_t (*G5_SET_PLL_SPEED)(G5_RADIO *Radios,uint32_t NumberOfRadios,uint8_t SlowSpeed,G5_STATUS *Status,G5_HW *Hw);
typedef int32_t (*G5_GET_HW_STATUS)(G5_RADIO *Radios,uint32_t NumberOfRadios,uint32_t *Status);
typedef int32_t (*G5_UPDATE_HW)(G5_RADIO *Radios,uint32_t NumberOfRadios,G5_HW *Hw);


#ifdef __cplusplus
};
#endif

extern G5_FIND_RADIOS G5_FindRadios;
extern G5_OPEN_RADIOS G5_OpenRadios;
extern G5_CLOSE_RADIOS G5_CloseRadios;
extern G5_SET_POWER G5_SetPower;
extern G5_SET_FREQUENCY G5_SetFrequency;
extern G5_SET_RF_ATTN G5_SetRFAttn;
extern G5_SET_IF_GAIN G5_SetIFGain;
extern G5_SET_PHASE G5_SetPhase;
extern G5_SET_PLL_SPEED G5_SetPllSpeed;
extern G5_GET_HW_STATUS G5_GetHwStatus;
extern G5_UPDATE_HW G5_UpdateHw;

uint8_t LoadG526API(void);
void UnloadG526API(void);

#endif

