#ifndef H2_API_MATLAB_H
#define H2_API_MATLAB_H

#include <stdint.h>
#include "h2_typedef_matlab.h"

#if defined(_WIN32) || defined(__CYGWIN__)
#define H2_API
#else
#define H2_API
#endif

/*
 * MATLAB R2016a friendly API header.
 *
 * MATLAB R2016a cannot reliably pass a C struct array that is modified by the
 * DLL. For channel arrays, use void* in the MATLAB prototype and pass a uint8
 * buffer whose size is sizeof(channel) * MAXCHANNELS.
 */

H2_API int device_list_usb(device_info *devInfo, uint32_t *count);
H2_API int device_open_usb(void **device, uint8_t dnum, void *ch_o, uint16_t *chn, device_info *dinfo);
H2_API int device_open_eth(void **device, eth_setting settings, void *ch_o, uint16_t *chn, device_info *dinfo);
H2_API int device_close(void **device);
H2_API int device_preset(void **device);
H2_API int device_query_temperature(void **device, float *temp_o);
H2_API int device_config_fan(void **device, fan_mode mode, float auto_threshold);
H2_API int device_query_supply(void **device, supply_info *supplyInfo_o);
H2_API int device_config_gnss(void **device, gnss_setting gnss);
H2_API int device_query_gnss(void **device, gnss_setting *gnss_o);
H2_API int device_query_gnss_info(void **device, gnss_info *gnss_o);
H2_API uint32_t device_query_apiverion();
H2_API int device_config_clock(void **device, referenceclock_source source, double fref, state out);
H2_API int device_query_clock(void **device, referenceclock_source *source_o, double *fref_o, state *out_o, state *locked_o);
H2_API int device_reset_clock_monitor(void **device);

H2_API int tx_clear_waveform(void **device);
H2_API int tx_download_waveform(void **device, int16_t iq[], uint32_t points, uint16_t *waveform_o);

H2_API int channel_preset(void *ch);
H2_API int channel_start(void *ch);
H2_API int channel_stop(void *ch);
H2_API int channel_trigger_bus(void *ch);

H2_API int tx_config_ffm(void *ch, double fc, float level);
H2_API int tx_query_ffm(void *ch, double *fc_o, float *level_o);
H2_API int tx_config_fscan(void *ch, double start, double stop, double step, float level, float dwell);
H2_API int tx_query_fscan(void *ch, double *start_o, double *stop_o, double *step_o, float *level_o, float *dwell_o);
H2_API int tx_config_lscan(void *ch, double fc, float level_start, float level_stop, float level_step, float dwell);
H2_API int tx_query_lscan(void *ch, double *fc_o, float *level_start_o, float *level_stop_o, float *level_step_o, float *dwell_o);
H2_API int tx_config_mscan(void *ch, const double fc[], const float level[], const float dwell[], int16_t n);
H2_API int tx_query_mscan(void *ch, double fc_o[], float level_o[], float dwell_o[], int16_t *n);

H2_API int channel_config_trigger(void *ch, const tx_trigger *trg);
H2_API int channel_query_trigger(void *ch, tx_trigger *trg_o);
H2_API int channel_config_trigger_out(void *ch, const trigger_out *trg);
H2_API int channel_query_trigger_out(void *ch, trigger_out *trg_o);
H2_API int channel_config_lo_mode(void *ch, lomode mode);
H2_API int channel_query_lo_mode(void *ch, lomode *mode_o);

H2_API int tx_config_output(void *ch, state rfout, state mod);
H2_API int tx_query_output(void *ch, state *rfout_o, state *mod_o);
H2_API int tx_config_cw(void *ch);
H2_API int tx_config_stream(void *ch, double sample_rate);
H2_API int tx_send_stream(void *ch, int16_t iq[], uint32_t points);
H2_API int tx_config_playback(void *ch, const int16_t waveform[], const int32_t repeat[], const double sample_rate[], int16_t waveforms);

H2_API void device_epoch_to_utc(uint64_t ns_sinceepoch, int16_t *year, int16_t *mon, int16_t *day, int16_t *hour, int16_t *min, int16_t *sec, int16_t *ms, int16_t *us, int16_t *ns);

#endif /* H2_API_MATLAB_H */
