From 3c15a1d6c30b01b73c5aacde5a48135b8278f3bd Mon Sep 17 00:00:00 2001 From: Julian Cable Date: Mon, 18 Nov 2013 10:53:15 -0800 Subject: [PATCH] Use Automake conditionals for G313 build Split G313 sources into POSIX and Windows versions and use Automake conditionals for building on *linux-gnu or mingw*, pw32*, or cygwin platforms. Fixed dlopen issue on g313 backend which broke rigmatrix generation. Signed-off-by: Nate Bargmann --- configure.ac | 32 +- winradio/Makefile.am | 12 +- winradio/g313-posix.c | 585 +++++++++++++++++ winradio/g313-win.c | 667 +++++++++++++++++++ winradio/g313.c | 1154 --------------------------------- winradio/linradio/wrg313api.c | 174 ++--- winradio/linradio/wrg313api.h | 2 +- 7 files changed, 1363 insertions(+), 1263 deletions(-) create mode 100644 winradio/g313-posix.c create mode 100644 winradio/g313-win.c delete mode 100644 winradio/g313.c diff --git a/configure.ac b/configure.ac index 37a111d80..eb2e24800 100644 --- a/configure.ac +++ b/configure.ac @@ -114,7 +114,7 @@ AM_PROG_CC_C_O ## Various parts of Hamlib need these headers ## ## ------------------------------------------ ## -AC_CHECK_HEADERS([dlfcn.h errno.h fcntl.h getopt.h limits.h locale.h malloc.h \ +AC_CHECK_HEADERS([errno.h fcntl.h getopt.h limits.h locale.h malloc.h \ netdb.h sgtty.h stddef.h termio.h termios.h values.h \ arpa/inet.h dev/ppbus/ppbconf.hdev/ppbus/ppi.h \ linux/hidraw.h linux/ioctl.h linux/parport.h linux/ppdev.h netinet/in.h \ @@ -601,14 +601,38 @@ AC_ARG_ENABLE([winradio], [cf_with_winradio="yes" AC_DEFINE([HAVE_WINRADIO],[1],[Define if winradio backend is built])]) AC_MSG_RESULT([$cf_with_winradio]) +DL_LIBS="" + AS_IF([test x"${cf_with_winradio}" = "xyes"], [BACKEND_LIST="$BACKEND_LIST winradio" -dnl Check for libdl and set DL_LIB if found--used for linradio backend - AC_CHECK_LIB([dl], [dlopen], [DL_LIB="-ldl"], +dnl Check for libdl and set DL_LIBS if found--used for linradio WR-G313 backend. + AC_CHECK_LIB([dl], [dlopen], [DL_LIBS="-ldl"], [AC_MSG_WARN([dlopen was not found in libdl--linradio backend will be disabled])]) - AC_SUBST([DL_LIB]) ]) +dnl Set conditional compilation for G-313. +AS_CASE(["$host_os"], + [mingw* | pw32* | cygwin ], [ + AM_CONDITIONAL(G313_LINUX_GNU, false) + AM_CONDITIONAL(G313_WINDOWS, true) + ], +dnl As g313-posix.c has a hard dependency on linux/types.h +dnl via linradio/wrg313api.h, disable compilation on other POSIX. + [ *linux-gnu ], [ + AM_CONDITIONAL(G313_LINUX_GNU, true) + AM_CONDITIONAL(G313_WINDOWS, false) + ], + [ + AM_CONDITIONAL(G313_LINUX_GNU, false) + AM_CONDITIONAL(G313_WINDOWS, false) + ]) + +dnl If libdl is present, check for its header file. +AS_IF([test x"${DL_LIBS}" = "x-ldl"], + [AC_CHECK_HEADERS([dlfcn.h])]) + +AC_SUBST([DL_LIBS]) + dnl stuff that requires C++ support AS_IF([test x"${cf_with_usrp}" = "xyes"],[ diff --git a/winradio/Makefile.am b/winradio/Makefile.am index 022a97261..9f436b276 100644 --- a/winradio/Makefile.am +++ b/winradio/Makefile.am @@ -1,9 +1,17 @@ WRSRC = wr1000.c wr1500.c wr1550.c wr3100.c wr3150.c wr3500.c wr3700.c \ - g303.c g313.c g305.c linradio/wrg313api.c linradio/wrg313api.h \ + g303.c g305.c \ winradio.c winradio.h linradio/radio_ioctl.h linradio/wrapi.h +if G313_LINUX_GNU +WRSRC += g313-posix.c linradio/wrg313api.c linradio/wrg313api.h +libhamlib_winradio_la_LDFLAGS = $(DL_LIBS) +endif + +if G313_WINDOWS +WRSRC += g313-win.c +endif + noinst_LTLIBRARIES = libhamlib-winradio.la libhamlib_winradio_la_SOURCES = $(WRSRC) -libhamlib_winradio_la_LDFLAGS = @DL_LIB@ EXTRA_DIST = NOTES Android.mk diff --git a/winradio/g313-posix.c b/winradio/g313-posix.c new file mode 100644 index 000000000..367d3ba9b --- /dev/null +++ b/winradio/g313-posix.c @@ -0,0 +1,585 @@ +/* + * Hamlib WiNRADiO backend - WR-G313 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + + +#include +#include +#include +#include +#include +#include +#include + +#include "config.h" + +#ifdef HAVE_DLFCN_H +# include +#endif + +#include + +#include "winradio.h" +#include "linradio/wrg313api.h" + + +#define G313_FUNC RIG_FUNC_NONE +#define G313_LEVEL (RIG_LEVEL_ATT | RIG_LEVEL_AGC | RIG_LEVEL_RF | RIG_LEVEL_STRENGTH | RIG_LEVEL_RAWSTR) +#define G313_MODES (RIG_MODE_NONE) + +#define TOK_SHM_AUDIO 0x150901 +#define TOK_SHM_IF 0x150902 +#define TOK_SHM_SPECTRUM 0x150903 + +#define FIFO_PATHNAME_SIZE 64 + + +const struct confparams g313_cfg_params[] = { + { TOK_SHM_AUDIO, "audio_path", "audio path name", + "POSIX shared memory path name to the audio ringbuffer", + "", RIG_CONF_STRING, + }, + { TOK_SHM_IF, "if_path", "I/F path name", + "POSIX shared memory path name to the I/F ringbuffer", + "", RIG_CONF_STRING, + }, + { TOK_SHM_SPECTRUM, "spectrum_path", "spectrum path name", + "POSIX shared memory path name to the spectrum ringbuffer", + "", RIG_CONF_STRING, + }, + { RIG_CONF_END, NULL, } +}; + +struct g313_fifo_data { + int fd; + char path[FIFO_PATHNAME_SIZE]; +}; + +struct g313_priv_data { + void *hWRAPI; + int hRadio; + int Opened; + struct g313_fifo_data if_buf; + struct g313_fifo_data audio_buf; + struct g313_fifo_data spectrum_buf; +}; + +static void g313_audio_callback(short* buffer, int count, void* arg); +static void g313_if_callback(short* buffer, int count, void* arg); +static void g313_spectrum_callback(float* buffer, int count, void* arg); + +void *g313_init_api(void) +{ + void *hWRAPI=dlopen("wrg313api.so", RTLD_LAZY); + if(hWRAPI==0) + { + rig_debug(RIG_DEBUG_ERR, "%s: Unable to load G313 shared library wrg313api.so\n", __FUNCTION__); + return 0; + } + if(InitAPI(hWRAPI)==0) + { + rig_debug(RIG_DEBUG_ERR, "%s: Unable to initialise G313 api\n", __FUNCTION__); + return 0; + } + return hWRAPI; +} + +int g313_init(RIG *rig) +{ + struct g313_priv_data *priv; + + priv = (struct g313_priv_data*)malloc(sizeof(struct g313_priv_data)); + + memset(priv, 0, sizeof(struct g313_priv_data)); + + if (!priv) { + /* whoops! memory shortage! */ + return -RIG_ENOMEM; + } + + priv->hWRAPI = g313_init_api(); + if(priv->hWRAPI) + rig_debug(RIG_DEBUG_VERBOSE, "%s: Initialised G313 API\n", __FUNCTION__); + /* otherwise try again when open rig */ + + rig->state.priv = (void*)priv; + + return RIG_OK; +} + +int g313_open(RIG *rig) +{ + int ret; + struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; + RADIO_DESC *List; + int Count; + + void* audio_callback = g313_audio_callback; + void* if_callback = g313_if_callback; + void* spectrum_callback = g313_spectrum_callback; + + if(priv->hWRAPI==0) /* might not be done yet, must be done now! */ + { + priv->hWRAPI = g313_init_api(); + if(priv->hWRAPI) + rig_debug(RIG_DEBUG_VERBOSE, "%s: Initialised G313 API\n", __FUNCTION__); + else + return -RIG_EIO; /* can't go any further */ + } + + if(priv->Opened) + return RIG_OK; + + ret = GetDeviceList(&List, &Count); + if(ret<0 || Count==0) + return -RIG_EIO; + + /* Open Winradio receiver handle (default to first device?) */ + + rig_debug(RIG_DEBUG_VERBOSE, "%s: found %d rigs 0 is %s\n", __FUNCTION__, Count, List[0].Path); + + if(rig->state.rigport.pathname[0]) + priv->hRadio = OpenDevice(rig->state.rigport.pathname); + else + priv->hRadio = OpenDevice(List[0].Path); + + DestroyDeviceList(List); + + + if (priv->hRadio < 0) + { + return -RIG_EIO; /* huh! */ + } + rig_debug(RIG_DEBUG_VERBOSE, "%s: Openned G313\n", __FUNCTION__); + + /* Make sure the receiver is switched on */ + SetPower(priv->hRadio, 1); + + priv->audio_buf.fd = open(priv->audio_buf.path, O_WRONLY|O_NONBLOCK); + rig_debug(RIG_DEBUG_VERBOSE, "%s: audio path %s fifo: %d\n", __FUNCTION__, priv->audio_buf.path, priv->audio_buf.fd); + if(priv->audio_buf.fd == -1) + audio_callback = NULL; + + priv->if_buf.fd = open(priv->if_buf.path, O_WRONLY|O_NONBLOCK); + rig_debug(RIG_DEBUG_VERBOSE, "%s: if path %s fifo: %d\n", __FUNCTION__, priv->if_buf.path, priv->if_buf.fd); + if(priv->if_buf.fd == -1) + if_callback = NULL; + + priv->spectrum_buf.fd = open(priv->spectrum_buf.path, O_WRONLY|O_NONBLOCK); + rig_debug(RIG_DEBUG_VERBOSE, "%s: spectrum path %s fifo: %d\n", __FUNCTION__, priv->spectrum_buf.path, priv->spectrum_buf.fd); + if(priv->spectrum_buf.fd == -1) + spectrum_callback = NULL; + + ret = StartStreaming(priv->hRadio, audio_callback, if_callback, spectrum_callback, priv); + if(ret) + { + return -RIG_EIO; + } + rig_debug(RIG_DEBUG_VERBOSE, "%s: told G313 to start streaming audio: %d, if: %d, spec: %d\n", + __FUNCTION__, + audio_callback?1:0, if_callback?1:0, spectrum_callback?1:0); + + priv->Opened=1; + + return RIG_OK; +} + +int g313_close(RIG *rig) +{ + struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; + + if(!priv->Opened) + { + return RIG_OK; + } + + priv->Opened=0; + + /* + rig_debug(RIG_DEBUG_VERBOSE, "%s: stop streaming\n", __FUNCTION__); + StopStreaming(priv->hRadio); + + req.tv_sec=0; + req.tv_nsec=500000000L; + nanosleep(&req, NULL); + */ + rig_debug(RIG_DEBUG_VERBOSE, "%s: Closing G313\n", __FUNCTION__); + CloseDevice(priv->hRadio); + + return RIG_OK; +} + +int g313_cleanup(RIG *rig) +{ + struct g313_priv_data *priv; + + if (!rig) + return -RIG_EINVAL; + + priv=(struct g313_priv_data *)rig->state.priv; + + rig_debug(RIG_DEBUG_VERBOSE, "%s: close fifos\n", __FUNCTION__); + if(priv->audio_buf.fd>=0) + close(priv->audio_buf.fd); + if(priv->if_buf.fd>=0) + close(priv->if_buf.fd); + if(priv->spectrum_buf.fd) + close(priv->spectrum_buf.fd); + + rig_debug(RIG_DEBUG_VERBOSE, "%s: Uninitialising G313 API\n", __FUNCTION__); + if(priv->hWRAPI) + { + dlclose(priv->hWRAPI); + } + if (rig->state.priv) + free(rig->state.priv); + rig->state.priv = NULL; + return RIG_OK; +} + +int g313_set_freq(RIG *rig, vfo_t vfo, freq_t freq) +{ + struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; + int ret; + + rig_debug(RIG_DEBUG_VERBOSE, "%s: %u\n", __FUNCTION__, (unsigned int)freq); + ret = SetFrequency(priv->hRadio, (unsigned int) (freq)); + ret = ret==0 ? RIG_OK : -RIG_EIO; + + return ret; +} + +int g313_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) +{ + struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; + + unsigned int f; + int ret = GetFrequency(priv->hRadio, &f); + rig_debug(RIG_DEBUG_VERBOSE, "%s: ret: %d f: %u\n", __FUNCTION__, ret, f); + if(ret) + return -RIG_EIO; + + *freq = (freq_t)f; + return RIG_OK; +} + +int g313_set_powerstat(RIG *rig, powerstat_t status) +{ + struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; + + int p = status==RIG_POWER_ON ? 1 : 0; + int ret = SetPower(priv->hRadio, p); + rig_debug(RIG_DEBUG_VERBOSE, "%s: ret: %d state: %d\n", __FUNCTION__, ret, p); + + return ret==0 ? RIG_OK : -RIG_EIO; +} + +int g313_get_powerstat(RIG *rig, powerstat_t *status) +{ + struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; + + int p; + int ret = GetPower(priv->hRadio, &p); + rig_debug(RIG_DEBUG_VERBOSE, "%s: ret: %d state: %d\n", __FUNCTION__, ret, p); + if(ret) + return -RIG_EIO; + + *status = p ? RIG_POWER_ON : RIG_POWER_OFF; + + return RIG_OK; +} + +int g313_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) +{ + struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; + int ret, agc; + + switch(level) { + case RIG_LEVEL_ATT: + ret = SetAttenuator(priv->hRadio, val.i != 0 ? 1 : 0); + rig_debug(RIG_DEBUG_VERBOSE, "%s: ret: %d Attenuator: %d\n", __FUNCTION__, ret, val.i); + break; + + case RIG_LEVEL_AGC: + switch (val.i) { + case RIG_AGC_OFF: + agc = 0; + break; + case RIG_AGC_SLOW: + agc = 1; + break; + case RIG_AGC_MEDIUM: + agc = 2; + break; + case RIG_AGC_FAST: + agc = 3; + break; + default: + return -RIG_EINVAL; + } + ret = SetAGC(priv->hRadio, agc); + rig_debug(RIG_DEBUG_VERBOSE, "%s: ret: %d AGC: %d\n", __FUNCTION__, ret, val.i); + break; + + case RIG_LEVEL_RF: + ret = SetIFGain(priv->hRadio, (int)(val.f*100)); + rig_debug(RIG_DEBUG_VERBOSE, "%s: ret: %d Gain: %f\n", __FUNCTION__, ret, val.f); + break; + + default: + return -RIG_EINVAL; + } + + return ret==0 ? RIG_OK : -RIG_EIO; +} + +int g313_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) +{ + struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; + int ret; + int value; + unsigned int uvalue; + double dbl; + unsigned char ch; + + switch(level) { + case RIG_LEVEL_ATT: + ret = GetAttenuator(priv->hRadio, &value); + rig_debug(RIG_DEBUG_VERBOSE, "%s: ret: %d Attenuator: %u\n", __FUNCTION__, ret, value); + if(ret) + return -RIG_EIO; + val->i = value?rig->caps->attenuator[0]:0; + break; + + case RIG_LEVEL_AGC: + ret = GetAGC(priv->hRadio, &value); + rig_debug(RIG_DEBUG_VERBOSE, "%s: ret: %d AGC: %u\n", __FUNCTION__, ret, value); + if(ret) + return -RIG_EIO; + + switch (value) { + case 0: + val->i = RIG_AGC_OFF; + break; + case 1: + val->i = RIG_AGC_SLOW; + break; + case 2: + val->i = RIG_AGC_MEDIUM; + break; + case 3: + val->i = RIG_AGC_FAST; + break; + default: + return -RIG_EINVAL; + } + break; + + case RIG_LEVEL_RF: + ret = GetIFGain(priv->hRadio, &uvalue); + rig_debug(RIG_DEBUG_VERBOSE, "%s: ret: %d Gain: %u\n", __FUNCTION__, ret, uvalue); + if(ret) + return -RIG_EIO; + val->f = ((float)uvalue)/100.0; + break; + + case RIG_LEVEL_STRENGTH: + ret = GetSignalStrength(priv->hRadio, &dbl); + rig_debug(RIG_DEBUG_VERBOSE, "%s: ret: %d sigstr: %f\n", __FUNCTION__, ret, dbl); + if(ret) + return -RIG_EIO; + val->i = ((int)dbl/1.0)+73; + break; + + case RIG_LEVEL_RAWSTR: + ret = GetRawSignalStrength(priv->hRadio, &ch); + rig_debug(RIG_DEBUG_VERBOSE, "%s: ret: %d Raw Sigstr: %u\n", __FUNCTION__, ret, (unsigned int)ch); + if(ret) + return -RIG_EIO; + val->i = ch; + break; + + default: + return -RIG_EINVAL; + } + + return RIG_OK; +} + +static const char* g313_get_info(RIG *rig) +{ + struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; + static RADIO_INFO info; + int ret; + + info.Size = sizeof(RADIO_INFO); + + ret = GetRadioInfo(priv->hRadio,&info); + + if(ret) + return NULL; + + rig_debug(RIG_DEBUG_VERBOSE, "%s: ret: %d sernum: %s\n", __FUNCTION__, ret, info.SerNum); + return info.SerNum; +} + +int g313_set_conf(RIG *rig, token_t token, const char *val) +{ + struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; + + size_t len = strlen(val); + + switch(token) + { + case TOK_SHM_AUDIO: + if(len>(FIFO_PATHNAME_SIZE-1)) + { + rig_debug(RIG_DEBUG_WARN, "%s: set audio_path %s is too long\n", __FUNCTION__, val); + return -RIG_EINVAL; + } + memset(priv->audio_buf.path, 0, FIFO_PATHNAME_SIZE); + strcpy(priv->audio_buf.path, val); + rig_debug(RIG_DEBUG_VERBOSE, "%s: set audio_path %s\n", __FUNCTION__, priv->audio_buf.path); + break; + case TOK_SHM_IF: + if(len>(FIFO_PATHNAME_SIZE-1)) + { + rig_debug(RIG_DEBUG_WARN, "%s: set if_path %s is too long\n", __FUNCTION__, val); + return -RIG_EINVAL; + } + memset(priv->if_buf.path, 0, FIFO_PATHNAME_SIZE); + strcpy(priv->if_buf.path, val); + rig_debug(RIG_DEBUG_VERBOSE, "%s: set if_path %s\n", __FUNCTION__, priv->if_buf.path); + break; + case TOK_SHM_SPECTRUM: + if(len>(FIFO_PATHNAME_SIZE-1)) + { + rig_debug(RIG_DEBUG_WARN, "%s: set spectrum_path %s is too long\n", __FUNCTION__, val); + return -RIG_EINVAL; + } + memset(priv->spectrum_buf.path, 0, FIFO_PATHNAME_SIZE); + strcpy(priv->spectrum_buf.path, val); + rig_debug(RIG_DEBUG_VERBOSE, "%s: set spectrum_path %s\n", __FUNCTION__, priv->spectrum_buf.path); + } + return RIG_OK; +} + +int g313_get_conf(RIG *rig, token_t token, char *val) +{ + struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; + switch(token) + { + case TOK_SHM_AUDIO: + strcpy(val, priv->audio_buf.path); + break; + case TOK_SHM_IF: + strcpy(val, priv->if_buf.path); + break; + case TOK_SHM_SPECTRUM: + strcpy(val, priv->spectrum_buf.path); + } + return RIG_OK; +} + +/* no need to check return from write - if not all can be written, accept overruns */ + +static void g313_audio_callback(short* buffer, int count, void* arg) +{ + struct g313_priv_data *priv = (struct g313_priv_data*)arg; + write(priv->audio_buf.fd, buffer, count*sizeof(short)); +} + +static void g313_if_callback(short* buffer, int count, void* arg) +{ + struct g313_priv_data *priv = (struct g313_priv_data*)arg; + write(priv->if_buf.fd, buffer, count*sizeof(short)); +} + +static void g313_spectrum_callback(float* buffer, int count, void* arg) +{ + struct g313_priv_data *priv = (struct g313_priv_data*)arg; + write(priv->spectrum_buf.fd, buffer, count*sizeof(float)); +} + +const struct rig_caps g313_caps = +{ + .rig_model = RIG_MODEL_G313, + .model_name = "WR-G313", + .mfg_name = "Winradio", + .version = "0.1", + .copyright = "LGPL", /* This wrapper, not the G313 shared library or driver */ + .status = RIG_STATUS_ALPHA, + .rig_type = RIG_TYPE_PCRECEIVER, + .port_type = RIG_PORT_NONE, + .targetable_vfo = 0, + .ptt_type = RIG_PTT_NONE, + .dcd_type = RIG_DCD_NONE, + .has_get_func = G313_FUNC, + .has_set_func = G313_FUNC, + .has_get_level = G313_LEVEL, + .has_set_level = RIG_LEVEL_SET(G313_LEVEL), + .has_get_parm = RIG_PARM_NONE, + .has_set_parm = RIG_PARM_NONE, + .ctcss_list = NULL, + .dcs_list = NULL, + .chan_list = { RIG_CHAN_END }, + .transceive = RIG_TRN_OFF, + .max_ifshift = kHz(2), + .attenuator = { 20, RIG_DBLST_END, }, /* TBC */ + .rx_range_list1 = { { + .start = kHz(9),.end = MHz(30),.modes = G313_MODES, + .low_power = -1,.high_power = -1,.vfo = RIG_VFO_A + }, + RIG_FRNG_END, + }, + .tx_range_list1 = { RIG_FRNG_END, }, + .rx_range_list2 = { { + .start = kHz(9),.end = MHz(30),.modes = G313_MODES, + .low_power = -1,.high_power = -1,.vfo = RIG_VFO_A + }, + RIG_FRNG_END, + }, + .tx_range_list2 = { RIG_FRNG_END, }, + + .tuning_steps = { {G313_MODES,1}, + RIG_TS_END, + }, + + .filters = { {G313_MODES, kHz(12)}, + RIG_FLT_END, + }, + + .cfgparams = g313_cfg_params, + .set_conf = g313_set_conf, + .get_conf = g313_get_conf, + + .rig_init = g313_init, + .rig_cleanup = g313_cleanup, + .rig_open = g313_open, + .rig_close = g313_close, + + .set_freq = g313_set_freq, + .get_freq = g313_get_freq, + + .set_powerstat = g313_set_powerstat, + .get_powerstat = g313_get_powerstat, + .set_level = g313_set_level, + .get_level = g313_get_level, + + .get_info = g313_get_info, +}; diff --git a/winradio/g313-win.c b/winradio/g313-win.c new file mode 100644 index 000000000..1d61da2a1 --- /dev/null +++ b/winradio/g313-win.c @@ -0,0 +1,667 @@ +/* + * Hamlib WiNRADiO backend - WR-G313 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include + +#include +#include "winradio.h" + +#define G313_FUNC RIG_FUNC_NONE +#define G313_LEVEL (RIG_LEVEL_ATT | RIG_LEVEL_AGC | RIG_LEVEL_RF | RIG_LEVEL_STRENGTH | RIG_LEVEL_RAWSTR) + +#define G313_MODES (RIG_MODE_NONE) + +#ifdef HAVE_WINDOWS_H +#include +#endif +#ifdef HAVE_WINBASE_H +#include +#endif + +/* + * Winradio G3 capabilities. + * + * TODO: rig_probe, rig_scan + */ + + +#define WAVEOUT_SOUNDCARDID 0x150901 + +const struct confparams g313_cfg_params[] = { + { WAVEOUT_SOUNDCARDID, "wodeviceid", "WaveOut Device ID", "Sound card device ID for playing IF signal from receiver", + "-1", RIG_CONF_NUMERIC, { .n = { -3, 32, 1 } } + }, + { RIG_CONF_END, NULL, } +}; + +#define WRG313DLL "wrg3130api.dll" + +#define G313_FUNC RIG_FUNC_NONE +#define G313_LEVEL (RIG_LEVEL_ATT | RIG_LEVEL_AGC | RIG_LEVEL_RF | RIG_LEVEL_STRENGTH | RIG_LEVEL_RAWSTR) + +#define G313_MODES (RIG_MODE_NONE) + +static int g313_init(RIG *rig); +static int g313_cleanup(RIG *rig); +static int g313_open(RIG *rig); +static int g313_close(RIG *rig); +static int g313_set_freq(RIG *rig, vfo_t vfo, freq_t freq); +static int g313_get_freq(RIG *rig, vfo_t vfo, freq_t *freq); +static int g313_set_powerstat(RIG *rig, powerstat_t status); +static int g313_get_powerstat(RIG *rig, powerstat_t *status); +static int g313_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val); +static int g313_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val); +static const char* g313_get_info(RIG *rig); +int g313_set_conf(RIG *rig, token_t token, const char *val); +int g313_get_conf(RIG *rig, token_t token, char *val); + +/* #pragma pack(1) // set byte packing */ +typedef struct { + int bLength; + char szSerNum[9]; + char szProdName[9]; + DWORD dwMinFreq; + DWORD dwMaxFreq; + BYTE bNumBands; + DWORD dwBandFreq[16]; + DWORD dwLOfreq; + BYTE bNumVcos; + DWORD dwVcoFreq[8]; + WORD wVcoDiv[8]; + BYTE bVcoBits[8]; + DWORD dwRefClk1; + DWORD dwRefClk2; + BYTE IF1DAC[8]; +} __attribute__((packed)) RADIO_INFO; +/* #pragma pack() // set back the default packing */ + +/* Some type definitions needed for dll access */ +typedef int (__stdcall *FNCOpenRadioDevice)(int iDeviceNum); +typedef BOOL (__stdcall *FNCCloseRadioDevice)(int hRadio); +typedef BOOL (__stdcall *FNCG3SetFrequency)(int hRadio, DWORD dwFreq); +typedef DWORD (__stdcall *FNCG3GetFrequency)(int hRadio); +typedef BOOL (__stdcall *FNCSetPower)(int hRadio, BOOL rPower); +typedef BOOL (__stdcall *FNCGetPower)(int hRadio); +typedef BOOL (__stdcall *FNCSetAtten)(int hRadio, BOOL rAtten); +typedef BOOL (__stdcall *FNCGetAtten)(int hRadio); +typedef BOOL (__stdcall *FNCSetAGC)(int hRadio, int rAGC); +typedef int (__stdcall *FNCGetAGC)(int hRadio); +typedef BOOL (__stdcall *FNCSetIFGain)(int hRadio, int rIFGain); +typedef int (__stdcall *FNCGetIFGain)(int hRadio); +typedef int (__stdcall *FNCGetSignalStrengthdBm)(int hRadio); +typedef int (__stdcall *FNCGetRawSignalStrength)(int hRadio); +typedef BOOL (__stdcall *FNCG3GetInfo)(int hRadio,RADIO_INFO *info); + +typedef MMRESULT (__stdcall *TwaveOutGetDevCaps)(UINT_PTR uDeviceID,LPWAVEOUTCAPS pwoc,UINT cbwoc); +typedef UINT (__stdcall *TwaveOutGetNumDevs)(void); + + +typedef HANDLE (__stdcall *TStartWaveOut)(LONG hRadio,LONG WaveOutDeviceIndex); +typedef void (__stdcall *TStopWaveOut)(HANDLE hWaveOut); + +struct g313_priv_data { + HMODULE dll; + int hRadio; + + FNCOpenRadioDevice OpenRadioDevice; + FNCCloseRadioDevice CloseRadioDevice; + FNCG3SetFrequency G3SetFrequency; + FNCG3GetFrequency G3GetFrequency; + FNCSetPower SetPower; + FNCGetPower GetPower; + FNCSetAtten SetAtten; + FNCGetAtten GetAtten; + FNCSetAGC SetAGC; + FNCGetAGC GetAGC; + FNCSetIFGain SetIFGain; + FNCGetIFGain GetIFGain; + FNCGetSignalStrengthdBm GetSignalStrengthdBm; + FNCGetRawSignalStrength GetRawSignalStrength; + FNCG3GetInfo G3GetInfo; + + + HMODULE WinMM; + TwaveOutGetDevCaps waveOutGetDevCaps; + TwaveOutGetNumDevs waveOutGetNumDevs; + + HMODULE hWRG313WO; + + int WaveOutDeviceID; + + HANDLE hWaveOut; + TStartWaveOut StartWaveOut; + TStopWaveOut StopWaveOut; + + int Opened; +}; + + +const struct rig_caps g313_caps = { + .rig_model = RIG_MODEL_G313, + .model_name = "WR-G313", + .mfg_name = "Winradio", + .version = "0.1", + .copyright = "LGPL", /* This wrapper, not the G313 DLL */ + .status = RIG_STATUS_BETA, + .rig_type = RIG_TYPE_PCRECEIVER, + .port_type = RIG_PORT_NONE, + .targetable_vfo = 0, + .ptt_type = RIG_PTT_NONE, + .dcd_type = RIG_DCD_NONE, + .has_get_func = G313_FUNC, + .has_set_func = G313_FUNC, + .has_get_level = G313_LEVEL, + .has_set_level = RIG_LEVEL_SET(G313_LEVEL), + .has_get_parm = RIG_PARM_NONE, + .has_set_parm = RIG_PARM_NONE, + .ctcss_list = NULL, + .dcs_list = NULL, + .chan_list = { RIG_CHAN_END }, + .transceive = RIG_TRN_OFF, + .max_ifshift = kHz(2), + .attenuator = { 20, RIG_DBLST_END, }, /* TBC */ + .rx_range_list1 = { { + .start = kHz(9),.end = MHz(30),.modes = G313_MODES, + .low_power = -1,.high_power = -1,.vfo = RIG_VFO_A + }, + RIG_FRNG_END, + }, + .tx_range_list1 = { RIG_FRNG_END, }, + .rx_range_list2 = { { + .start = kHz(9),.end = MHz(30),.modes = G313_MODES, + .low_power = -1,.high_power = -1,.vfo = RIG_VFO_A + }, + RIG_FRNG_END, + }, + .tx_range_list2 = { RIG_FRNG_END, }, + + .tuning_steps = { {G313_MODES,1}, + RIG_TS_END, + }, + + .filters = { {G313_MODES, kHz(12)}, + RIG_FLT_END, + }, + + .cfgparams = g313_cfg_params, + .set_conf = g313_set_conf, + .get_conf = g313_get_conf, + + .rig_init = g313_init, + .rig_cleanup = g313_cleanup, + .rig_open = g313_open, + .rig_close = g313_close, + + .set_freq = g313_set_freq, + .get_freq = g313_get_freq, + + .set_powerstat = g313_set_powerstat, + .get_powerstat = g313_get_powerstat, + .set_level = g313_set_level, + .get_level = g313_get_level, + + .get_info = g313_get_info, +}; + + + +int g313_init(RIG *rig) +{ + struct g313_priv_data *priv; + + priv = (struct g313_priv_data*)malloc(sizeof(struct g313_priv_data)); + if (!priv) { + /* whoops! memory shortage! */ + return -RIG_ENOMEM; + } + + priv->WaveOutDeviceID=-1; + + priv->Opened=0; + priv->hWaveOut=NULL; + + priv->WinMM=LoadLibrary("WinMM.dll"); + + if(priv->WinMM==NULL) + { + free(priv); + return -RIG_EIO; + } + + priv->hWRG313WO=LoadLibrary("WRG313WO.dll"); + + if(priv->hWRG313WO==NULL) + { + rig_debug(RIG_DEBUG_ERR, "%s: Unable to LoadLibrary WRG313WO.dll\n", + __FUNCTION__); + FreeLibrary(priv->WinMM); + free(priv); + return -RIG_EIO; + } + + priv->StartWaveOut=(TStartWaveOut)GetProcAddress(priv->hWRG313WO,"StartWaveOut"); + priv->StopWaveOut=(TStopWaveOut)GetProcAddress(priv->hWRG313WO,"StopWaveOut"); + + if(!priv->StartWaveOut || !priv->StopWaveOut) + { + rig_debug(RIG_DEBUG_ERR, "%s: Unable to load valid WRG313WO.dll library\n", + __FUNCTION__); + FreeLibrary(priv->hWRG313WO); + FreeLibrary(priv->WinMM); + free(priv); + return -RIG_EIO; + } + + + /* Try to load required dll */ + priv->dll = LoadLibrary(WRG313DLL); + + if (!priv->dll) { + rig_debug(RIG_DEBUG_ERR, "%s: Unable to LoadLibrary %s\n", + __FUNCTION__, WRG313DLL); + FreeLibrary(priv->hWRG313WO); + FreeLibrary(priv->WinMM); + free(priv); + return -RIG_EIO; /* huh! */ + } + + /* Get process addresses from dll for function access */ + priv->OpenRadioDevice = + (FNCOpenRadioDevice) GetProcAddress(priv->dll, "OpenRadioDevice"); + priv->CloseRadioDevice = + (FNCCloseRadioDevice) GetProcAddress(priv->dll, "CloseRadioDevice"); + priv->G3SetFrequency = + (FNCG3SetFrequency) GetProcAddress(priv->dll, "SetFrequency"); + priv->G3GetFrequency = + (FNCG3GetFrequency) GetProcAddress(priv->dll, "GetFrequency"); + priv->SetPower = (FNCSetPower) GetProcAddress(priv->dll, "SetPower"); + priv->GetPower = (FNCGetPower) GetProcAddress(priv->dll, "GetPower"); + priv->SetAtten = (FNCSetAtten) GetProcAddress(priv->dll, "SetAtten"); + priv->GetAtten = (FNCGetAtten) GetProcAddress(priv->dll, "GetAtten"); + priv->SetAGC = (FNCSetAGC) GetProcAddress(priv->dll, "SetAGC"); + priv->GetAGC = (FNCGetAGC) GetProcAddress(priv->dll, "GetAGC"); + priv->SetIFGain = (FNCSetIFGain) GetProcAddress(priv->dll, "SetIFGain"); + priv->GetIFGain = (FNCGetIFGain) GetProcAddress(priv->dll, "GetIFGain"); + priv->GetSignalStrengthdBm = + (FNCGetSignalStrengthdBm) GetProcAddress(priv->dll, "GetSignalStrengthdBm"); + priv->GetRawSignalStrength = + (FNCGetRawSignalStrength) GetProcAddress(priv->dll, "GetRawSignalStrength"); + priv->G3GetInfo = (FNCG3GetInfo) GetProcAddress(priv->dll, "G3GetInfo"); + + + if(!priv->OpenRadioDevice || !priv->CloseRadioDevice || !priv->G3SetFrequency || + !priv->G3GetFrequency || !priv->SetPower || !priv->GetPower || !priv->SetAtten || + !priv->GetAtten || !priv->SetAGC || !priv->GetAGC || !priv->SetIFGain || !priv->GetIFGain || + !priv->GetSignalStrengthdBm || !priv->GetRawSignalStrength) + { + rig_debug(RIG_DEBUG_ERR, "%s: Unable to load valid %s library\n", + __FUNCTION__, WRG313DLL); + FreeLibrary(priv->dll); + FreeLibrary(priv->hWRG313WO); + FreeLibrary(priv->WinMM); + free(priv); + return -RIG_EIO; + } + + priv->waveOutGetDevCaps=(TwaveOutGetDevCaps)GetProcAddress(priv->WinMM,"waveOutGetDevCapsA"); + priv->waveOutGetNumDevs=(TwaveOutGetNumDevs)GetProcAddress(priv->WinMM,"waveOutGetNumDevs"); + + + rig->state.priv = (void*)priv; + + + return RIG_OK; +} + +int g313_findVSC(struct g313_priv_data *priv) +{ + int OutIndex; + WAVEOUTCAPS Caps; + int Count; + int i; + + OutIndex=-1; + Count=priv->waveOutGetNumDevs(); + + for(i=0; iwaveOutGetDevCaps(i, &Caps, sizeof(Caps))==MMSYSERR_NOERROR) + { + if(strncmp(Caps.szPname,"WiNRADiO Virtual Sound Card",27)==0) + { + OutIndex=i; + break; + } + } + } + + return OutIndex; +} + +int g313_open(RIG *rig) +{ + struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; + int device_num; + int Count; + int id; + + device_num = atoi(rig->state.rigport.pathname); + + Count=priv->waveOutGetNumDevs(); + + if(Count==0) + { + return -RIG_EIO; + } + + if(priv->WaveOutDeviceID==-2) + { + id=g313_findVSC(priv); + } + else + { + id=priv->WaveOutDeviceID; + } + + + /* Open Winradio receiver handle */ + priv->hRadio = priv->OpenRadioDevice(device_num); + + if (priv->hRadio == 0) + { + return -RIG_EIO; /* huh! */ + } + + /* Make sure the receiver is switched on */ + priv->SetPower(priv->hRadio, TRUE); + + if(id>-3) + { + priv->hWaveOut=priv->StartWaveOut(priv->hRadio,id); + + if(priv->hWaveOut==NULL) + { + priv->CloseRadioDevice(priv->hRadio); + return -RIG_EIO; + } + } + else + { + priv->hWaveOut=NULL; + } + + + priv->Opened=1; + + return RIG_OK; +} + +int g313_close(RIG *rig) +{ + struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; + + + if(!priv->Opened) + { + return RIG_OK; + } + + priv->Opened=0; + + if(priv->hWaveOut) + { + priv->StopWaveOut(priv->hWaveOut); + } + priv->CloseRadioDevice(priv->hRadio); + + return RIG_OK; +} + +int g313_cleanup(RIG *rig) +{ + struct g313_priv_data *priv; + + if (!rig) + return -RIG_EINVAL; + + priv=(struct g313_priv_data *)rig->state.priv; + + /* Clean up the dll access */ + FreeLibrary(priv->dll); + FreeLibrary(priv->WinMM); + FreeLibrary(priv->hWRG313WO); + + + if (rig->state.priv) + free(rig->state.priv); + rig->state.priv = NULL; + + return RIG_OK; +} + +int g313_set_freq(RIG *rig, vfo_t vfo, freq_t freq) +{ + struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; + int ret; + + ret = priv->G3SetFrequency(priv->hRadio, (DWORD) (freq)); + ret = ret==TRUE ? RIG_OK : -RIG_EIO; + + return ret; +} + +int g313_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) +{ + struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; + + *freq = (freq_t) priv->G3GetFrequency(priv->hRadio); + + return *freq != 0 ? RIG_OK : -RIG_EIO; +} + +int g313_set_powerstat(RIG *rig, powerstat_t status) +{ + struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; + int ret; + + ret = priv->SetPower(priv->hRadio, status==RIG_POWER_ON ? TRUE : FALSE); + ret = ret==TRUE ? RIG_OK : -RIG_EIO; + + return ret; +} + +int g313_get_powerstat(RIG *rig, powerstat_t *status) +{ + struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; + int ret; + + ret = priv->GetPower(priv->hRadio); + *status = ret==TRUE ? RIG_POWER_ON : RIG_POWER_OFF; + + return RIG_OK; +} + +int g313_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) +{ + struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; + int ret, agc; + + switch(level) { + case RIG_LEVEL_ATT: + ret = priv->SetAtten(priv->hRadio, val.i != 0 ? TRUE : FALSE); + break; + + case RIG_LEVEL_AGC: + switch (val.i) { + case RIG_AGC_OFF: + agc = 0; + break; + case RIG_AGC_SLOW: + agc = 1; + break; + case RIG_AGC_MEDIUM: + agc = 2; + break; + case RIG_AGC_FAST: + agc = 3; + break; + default: + return -RIG_EINVAL; + } + ret = priv->SetAGC(priv->hRadio, agc); + break; + + case RIG_LEVEL_RF: + ret = priv->SetIFGain(priv->hRadio, (int)(val.f*100)); + break; + + default: + return -RIG_EINVAL; + } + + ret = ret==TRUE ? RIG_OK : -RIG_EIO; + return ret; +} + +int g313_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) +{ + struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; + int ret; + + ret = RIG_OK; + + switch(level) { + case RIG_LEVEL_ATT: + val->i = priv->GetAtten(priv->hRadio)?rig->caps->attenuator[0]:0; + break; + + case RIG_LEVEL_AGC: + switch (priv->GetAGC(priv->hRadio)) { + case 0: + val->i = RIG_AGC_OFF; + break; + case 1: + val->i = RIG_AGC_SLOW; + break; + case 2: + val->i = RIG_AGC_MEDIUM; + break; + case 3: + val->i = RIG_AGC_FAST; + break; + case -1: + ret = -RIG_EIO; + break; + default: + return -RIG_EINVAL; + } + break; + + case RIG_LEVEL_STRENGTH: + val->i = priv->GetSignalStrengthdBm(priv->hRadio)/10+73; + break; + + case RIG_LEVEL_RAWSTR: + val->i = priv->GetRawSignalStrength(priv->hRadio); + break; + + default: + return -RIG_EINVAL; + } + + return ret; +} + + +static const char* g313_get_info(RIG *rig) +{ + struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; + static RADIO_INFO info; + + info.bLength = sizeof(RADIO_INFO); + + if (priv->G3GetInfo(priv->hRadio,&info) == FALSE) + return NULL; + + return info.szSerNum; +} + + +int g313_set_conf(RIG *rig, token_t token, const char *val) +{ + struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; + int id; + + switch(token) + { + case WAVEOUT_SOUNDCARDID: + if (val[0] == '0' && val[1] == 'x') + id = strtol(val, (char **)NULL, 16); + else + id = atoi(val); + if(id<-3 || id>32) + { + return -RIG_EINVAL; + } + + priv->WaveOutDeviceID=id; + + if(priv->Opened) + { + if(id==-2) + { + id=g313_findVSC(priv); + } + + if(priv->hWaveOut) + { + priv->StopWaveOut(priv->hWaveOut); + } + + if(id>-3) + { + priv->hWaveOut=priv->StartWaveOut(priv->hRadio,id); + } + else + { + priv->hWaveOut=NULL; + } + } + + break; + default: + return -RIG_EINVAL; + } + return RIG_OK; +} + +int g313_get_conf(RIG *rig, token_t token, char *val) +{ + struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; + + switch(token) + { + case WAVEOUT_SOUNDCARDID: + sprintf(val,"%d",priv->WaveOutDeviceID); + break; + default: + return -RIG_EINVAL; + } + return RIG_OK; +} diff --git a/winradio/g313.c b/winradio/g313.c deleted file mode 100644 index 9dafe363f..000000000 --- a/winradio/g313.c +++ /dev/null @@ -1,1154 +0,0 @@ -/* - * Hamlib WiNRADiO backend - WR-G313 - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#include - -#include -#include "winradio.h" - -#define G313_FUNC RIG_FUNC_NONE -#define G313_LEVEL (RIG_LEVEL_ATT | RIG_LEVEL_AGC | RIG_LEVEL_RF | RIG_LEVEL_STRENGTH | RIG_LEVEL_RAWSTR) - -#define G313_MODES (RIG_MODE_NONE) - -#ifdef _WIN32 -#else -#ifdef __CYGWIN__ - -#ifdef HAVE_WINDOWS_H -#include -#endif -#ifdef HAVE_WINBASE_H -#include -#endif - -/* - * Winradio G3 capabilities. - * - * TODO: rig_probe, rig_scan - */ - - -#define WAVEOUT_SOUNDCARDID 0x150901 - -const struct confparams g313_cfg_params[] = { - { WAVEOUT_SOUNDCARDID, "wodeviceid", "WaveOut Device ID", "Sound card device ID for playing IF signal from receiver", - "-1", RIG_CONF_NUMERIC, { .n = { -3, 32, 1 } } - }, - { RIG_CONF_END, NULL, } -}; - -#define WRG313DLL "wrg3130api.dll" - -#define G313_FUNC RIG_FUNC_NONE -#define G313_LEVEL (RIG_LEVEL_ATT | RIG_LEVEL_AGC | RIG_LEVEL_RF | RIG_LEVEL_STRENGTH | RIG_LEVEL_RAWSTR) - -#define G313_MODES (RIG_MODE_NONE) - -static int g313_init(RIG *rig); -static int g313_cleanup(RIG *rig); -static int g313_open(RIG *rig); -static int g313_close(RIG *rig); -static int g313_set_freq(RIG *rig, vfo_t vfo, freq_t freq); -static int g313_get_freq(RIG *rig, vfo_t vfo, freq_t *freq); -static int g313_set_powerstat(RIG *rig, powerstat_t status); -static int g313_get_powerstat(RIG *rig, powerstat_t *status); -static int g313_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val); -static int g313_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val); -static const char* g313_get_info(RIG *rig); -int g313_set_conf(RIG *rig, token_t token, const char *val); -int g313_get_conf(RIG *rig, token_t token, char *val); - -/* #pragma pack(1) // set byte packing */ -typedef struct { - int bLength; - char szSerNum[9]; - char szProdName[9]; - DWORD dwMinFreq; - DWORD dwMaxFreq; - BYTE bNumBands; - DWORD dwBandFreq[16]; - DWORD dwLOfreq; - BYTE bNumVcos; - DWORD dwVcoFreq[8]; - WORD wVcoDiv[8]; - BYTE bVcoBits[8]; - DWORD dwRefClk1; - DWORD dwRefClk2; - BYTE IF1DAC[8]; -} __attribute__((packed)) RADIO_INFO; -/* #pragma pack() // set back the default packing */ - -/* Some type definitions needed for dll access */ -typedef int (__stdcall *FNCOpenRadioDevice)(int iDeviceNum); -typedef BOOL (__stdcall *FNCCloseRadioDevice)(int hRadio); -typedef BOOL (__stdcall *FNCG3SetFrequency)(int hRadio, DWORD dwFreq); -typedef DWORD (__stdcall *FNCG3GetFrequency)(int hRadio); -typedef BOOL (__stdcall *FNCSetPower)(int hRadio, BOOL rPower); -typedef BOOL (__stdcall *FNCGetPower)(int hRadio); -typedef BOOL (__stdcall *FNCSetAtten)(int hRadio, BOOL rAtten); -typedef BOOL (__stdcall *FNCGetAtten)(int hRadio); -typedef BOOL (__stdcall *FNCSetAGC)(int hRadio, int rAGC); -typedef int (__stdcall *FNCGetAGC)(int hRadio); -typedef BOOL (__stdcall *FNCSetIFGain)(int hRadio, int rIFGain); -typedef int (__stdcall *FNCGetIFGain)(int hRadio); -typedef int (__stdcall *FNCGetSignalStrengthdBm)(int hRadio); -typedef int (__stdcall *FNCGetRawSignalStrength)(int hRadio); -typedef BOOL (__stdcall *FNCG3GetInfo)(int hRadio,RADIO_INFO *info); - -typedef MMRESULT (__stdcall *TwaveOutGetDevCaps)(UINT_PTR uDeviceID,LPWAVEOUTCAPS pwoc,UINT cbwoc); -typedef UINT (__stdcall *TwaveOutGetNumDevs)(void); - - -typedef HANDLE (__stdcall *TStartWaveOut)(LONG hRadio,LONG WaveOutDeviceIndex); -typedef void (__stdcall *TStopWaveOut)(HANDLE hWaveOut); - -struct g313_priv_data { - HMODULE dll; - int hRadio; - - FNCOpenRadioDevice OpenRadioDevice; - FNCCloseRadioDevice CloseRadioDevice; - FNCG3SetFrequency G3SetFrequency; - FNCG3GetFrequency G3GetFrequency; - FNCSetPower SetPower; - FNCGetPower GetPower; - FNCSetAtten SetAtten; - FNCGetAtten GetAtten; - FNCSetAGC SetAGC; - FNCGetAGC GetAGC; - FNCSetIFGain SetIFGain; - FNCGetIFGain GetIFGain; - FNCGetSignalStrengthdBm GetSignalStrengthdBm; - FNCGetRawSignalStrength GetRawSignalStrength; - FNCG3GetInfo G3GetInfo; - - - HMODULE WinMM; - TwaveOutGetDevCaps waveOutGetDevCaps; - TwaveOutGetNumDevs waveOutGetNumDevs; - - HMODULE hWRG313WO; - - int WaveOutDeviceID; - - HANDLE hWaveOut; - TStartWaveOut StartWaveOut; - TStopWaveOut StopWaveOut; - - int Opened; -}; - - -const struct rig_caps g313_caps = { - .rig_model = RIG_MODEL_G313, - .model_name = "WR-G313", - .mfg_name = "Winradio", - .version = "0.1", - .copyright = "LGPL", /* This wrapper, not the G313 DLL */ - .status = RIG_STATUS_BETA, - .rig_type = RIG_TYPE_PCRECEIVER, - .port_type = RIG_PORT_NONE, - .targetable_vfo = 0, - .ptt_type = RIG_PTT_NONE, - .dcd_type = RIG_DCD_NONE, - .has_get_func = G313_FUNC, - .has_set_func = G313_FUNC, - .has_get_level = G313_LEVEL, - .has_set_level = RIG_LEVEL_SET(G313_LEVEL), - .has_get_parm = RIG_PARM_NONE, - .has_set_parm = RIG_PARM_NONE, - .ctcss_list = NULL, - .dcs_list = NULL, - .chan_list = { RIG_CHAN_END }, - .transceive = RIG_TRN_OFF, - .max_ifshift = kHz(2), - .attenuator = { 20, RIG_DBLST_END, }, /* TBC */ - .rx_range_list1 = { {.start = kHz(9),.end = MHz(30),.modes = G313_MODES, - .low_power = -1,.high_power = -1,.vfo = RIG_VFO_A}, - RIG_FRNG_END, }, - .tx_range_list1 = { RIG_FRNG_END, }, - .rx_range_list2 = { {.start = kHz(9),.end = MHz(30),.modes = G313_MODES, - .low_power = -1,.high_power = -1,.vfo = RIG_VFO_A}, - RIG_FRNG_END, }, - .tx_range_list2 = { RIG_FRNG_END, }, - - .tuning_steps = { {G313_MODES,1}, - RIG_TS_END, }, - - .filters = { {G313_MODES, kHz(12)}, - RIG_FLT_END, }, - - .cfgparams = g313_cfg_params, - .set_conf = g313_set_conf, - .get_conf = g313_get_conf, - - .rig_init = g313_init, - .rig_cleanup = g313_cleanup, - .rig_open = g313_open, - .rig_close = g313_close, - - .set_freq = g313_set_freq, - .get_freq = g313_get_freq, - - .set_powerstat = g313_set_powerstat, - .get_powerstat = g313_get_powerstat, - .set_level = g313_set_level, - .get_level = g313_get_level, - - .get_info = g313_get_info, -}; - - - -int g313_init(RIG *rig) -{ - struct g313_priv_data *priv; - - priv = (struct g313_priv_data*)malloc(sizeof(struct g313_priv_data)); - if (!priv) { - /* whoops! memory shortage! */ - return -RIG_ENOMEM; - } - - priv->WaveOutDeviceID=-1; - - priv->Opened=0; - priv->hWaveOut=NULL; - - priv->WinMM=LoadLibrary("WinMM.dll"); - - if(priv->WinMM==NULL) - { - free(priv); - return -RIG_EIO; - } - - priv->hWRG313WO=LoadLibrary("WRG313WO.dll"); - - if(priv->hWRG313WO==NULL) - { - rig_debug(RIG_DEBUG_ERR, "%s: Unable to LoadLibrary WRG313WO.dll\n", - __FUNCTION__); - FreeLibrary(priv->WinMM); - free(priv); - return -RIG_EIO; - } - - priv->StartWaveOut=(TStartWaveOut)GetProcAddress(priv->hWRG313WO,"StartWaveOut"); - priv->StopWaveOut=(TStopWaveOut)GetProcAddress(priv->hWRG313WO,"StopWaveOut"); - - if(!priv->StartWaveOut || !priv->StopWaveOut) - { - rig_debug(RIG_DEBUG_ERR, "%s: Unable to load valid WRG313WO.dll library\n", - __FUNCTION__); - FreeLibrary(priv->hWRG313WO); - FreeLibrary(priv->WinMM); - free(priv); - return -RIG_EIO; - } - - - /* Try to load required dll */ - priv->dll = LoadLibrary(WRG313DLL); - - if (!priv->dll) { - rig_debug(RIG_DEBUG_ERR, "%s: Unable to LoadLibrary %s\n", - __FUNCTION__, WRG313DLL); - FreeLibrary(priv->hWRG313WO); - FreeLibrary(priv->WinMM); - free(priv); - return -RIG_EIO; /* huh! */ - } - - /* Get process addresses from dll for function access */ - priv->OpenRadioDevice = - (FNCOpenRadioDevice) GetProcAddress(priv->dll, "OpenRadioDevice"); - priv->CloseRadioDevice = - (FNCCloseRadioDevice) GetProcAddress(priv->dll, "CloseRadioDevice"); - priv->G3SetFrequency = - (FNCG3SetFrequency) GetProcAddress(priv->dll, "SetFrequency"); - priv->G3GetFrequency = - (FNCG3GetFrequency) GetProcAddress(priv->dll, "GetFrequency"); - priv->SetPower = (FNCSetPower) GetProcAddress(priv->dll, "SetPower"); - priv->GetPower = (FNCGetPower) GetProcAddress(priv->dll, "GetPower"); - priv->SetAtten = (FNCSetAtten) GetProcAddress(priv->dll, "SetAtten"); - priv->GetAtten = (FNCGetAtten) GetProcAddress(priv->dll, "GetAtten"); - priv->SetAGC = (FNCSetAGC) GetProcAddress(priv->dll, "SetAGC"); - priv->GetAGC = (FNCGetAGC) GetProcAddress(priv->dll, "GetAGC"); - priv->SetIFGain = (FNCSetIFGain) GetProcAddress(priv->dll, "SetIFGain"); - priv->GetIFGain = (FNCGetIFGain) GetProcAddress(priv->dll, "GetIFGain"); - priv->GetSignalStrengthdBm = - (FNCGetSignalStrengthdBm) GetProcAddress(priv->dll, "GetSignalStrengthdBm"); - priv->GetRawSignalStrength = - (FNCGetRawSignalStrength) GetProcAddress(priv->dll, "GetRawSignalStrength"); - priv->G3GetInfo = (FNCG3GetInfo) GetProcAddress(priv->dll, "G3GetInfo"); - - - if(!priv->OpenRadioDevice || !priv->CloseRadioDevice || !priv->G3SetFrequency || - !priv->G3GetFrequency || !priv->SetPower || !priv->GetPower || !priv->SetAtten || - !priv->GetAtten || !priv->SetAGC || !priv->GetAGC || !priv->SetIFGain || !priv->GetIFGain || - !priv->GetSignalStrengthdBm || !priv->GetRawSignalStrength) - { - rig_debug(RIG_DEBUG_ERR, "%s: Unable to load valid %s library\n", - __FUNCTION__, WRG313DLL); - FreeLibrary(priv->dll); - FreeLibrary(priv->hWRG313WO); - FreeLibrary(priv->WinMM); - free(priv); - return -RIG_EIO; - } - - priv->waveOutGetDevCaps=(TwaveOutGetDevCaps)GetProcAddress(priv->WinMM,"waveOutGetDevCapsA"); - priv->waveOutGetNumDevs=(TwaveOutGetNumDevs)GetProcAddress(priv->WinMM,"waveOutGetNumDevs"); - - - rig->state.priv = (void*)priv; - - - return RIG_OK; -} - -int g313_findVSC(struct g313_priv_data *priv) -{ - int OutIndex; - WAVEOUTCAPS Caps; - int Count; - int i; - - OutIndex=-1; - Count=priv->waveOutGetNumDevs(); - - for(i=0;iwaveOutGetDevCaps(i, &Caps, sizeof(Caps))==MMSYSERR_NOERROR) - { - if(strncmp(Caps.szPname,"WiNRADiO Virtual Sound Card",27)==0) - { - OutIndex=i; - break; - } - } - } - - return OutIndex; -} - -int g313_open(RIG *rig) -{ - struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; - int device_num; - int Count; - int id; - - device_num = atoi(rig->state.rigport.pathname); - - Count=priv->waveOutGetNumDevs(); - - if(Count==0) - { - return -RIG_EIO; - } - - if(priv->WaveOutDeviceID==-2) - { - id=g313_findVSC(priv); - } - else - { - id=priv->WaveOutDeviceID; - } - - - /* Open Winradio receiver handle */ - priv->hRadio = priv->OpenRadioDevice(device_num); - - if (priv->hRadio == 0) - { - return -RIG_EIO; /* huh! */ - } - - /* Make sure the receiver is switched on */ - priv->SetPower(priv->hRadio, TRUE); - - if(id>-3) - { - priv->hWaveOut=priv->StartWaveOut(priv->hRadio,id); - - if(priv->hWaveOut==NULL) - { - priv->CloseRadioDevice(priv->hRadio); - return -RIG_EIO; - } - } - else - { - priv->hWaveOut=NULL; - } - - - priv->Opened=1; - - return RIG_OK; -} - -int g313_close(RIG *rig) -{ - struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; - - - if(!priv->Opened) - { - return RIG_OK; - } - - priv->Opened=0; - - if(priv->hWaveOut) - { - priv->StopWaveOut(priv->hWaveOut); - } - priv->CloseRadioDevice(priv->hRadio); - - return RIG_OK; -} - -int g313_cleanup(RIG *rig) -{ - struct g313_priv_data *priv; - - if (!rig) - return -RIG_EINVAL; - - priv=(struct g313_priv_data *)rig->state.priv; - - /* Clean up the dll access */ - FreeLibrary(priv->dll); - FreeLibrary(priv->WinMM); - FreeLibrary(priv->hWRG313WO); - - - if (rig->state.priv) - free(rig->state.priv); - rig->state.priv = NULL; - - return RIG_OK; -} - -int g313_set_freq(RIG *rig, vfo_t vfo, freq_t freq) -{ - struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; - int ret; - - ret = priv->G3SetFrequency(priv->hRadio, (DWORD) (freq)); - ret = ret==TRUE ? RIG_OK : -RIG_EIO; - - return ret; -} - -int g313_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) -{ - struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; - - *freq = (freq_t) priv->G3GetFrequency(priv->hRadio); - - return *freq != 0 ? RIG_OK : -RIG_EIO; -} - -int g313_set_powerstat(RIG *rig, powerstat_t status) -{ - struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; - int ret; - - ret = priv->SetPower(priv->hRadio, status==RIG_POWER_ON ? TRUE : FALSE); - ret = ret==TRUE ? RIG_OK : -RIG_EIO; - - return ret; -} - -int g313_get_powerstat(RIG *rig, powerstat_t *status) -{ - struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; - int ret; - - ret = priv->GetPower(priv->hRadio); - *status = ret==TRUE ? RIG_POWER_ON : RIG_POWER_OFF; - - return RIG_OK; -} - -int g313_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) -{ - struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; - int ret, agc; - - switch(level) { - case RIG_LEVEL_ATT: - ret = priv->SetAtten(priv->hRadio, val.i != 0 ? TRUE : FALSE); - break; - - case RIG_LEVEL_AGC: - switch (val.i) { - case RIG_AGC_OFF: agc = 0; break; - case RIG_AGC_SLOW: agc = 1; break; - case RIG_AGC_MEDIUM: agc = 2; break; - case RIG_AGC_FAST: agc = 3; break; - default: - return -RIG_EINVAL; - } - ret = priv->SetAGC(priv->hRadio, agc); - break; - - case RIG_LEVEL_RF: - ret = priv->SetIFGain(priv->hRadio, (int)(val.f*100)); - break; - - default: - return -RIG_EINVAL; - } - - ret = ret==TRUE ? RIG_OK : -RIG_EIO; - return ret; -} - -int g313_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) -{ - struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; - int ret; - - ret = RIG_OK; - - switch(level) { - case RIG_LEVEL_ATT: - val->i = priv->GetAtten(priv->hRadio)?rig->caps->attenuator[0]:0; - break; - - case RIG_LEVEL_AGC: - switch (priv->GetAGC(priv->hRadio)) { - case 0: val->i = RIG_AGC_OFF; break; - case 1: val->i = RIG_AGC_SLOW; break; - case 2: val->i = RIG_AGC_MEDIUM; break; - case 3: val->i = RIG_AGC_FAST; break; - case -1: ret = -RIG_EIO; break; - default: - return -RIG_EINVAL; - } - break; - - case RIG_LEVEL_STRENGTH: - val->i = priv->GetSignalStrengthdBm(priv->hRadio)/10+73; - break; - - case RIG_LEVEL_RAWSTR: - val->i = priv->GetRawSignalStrength(priv->hRadio); - break; - - default: - return -RIG_EINVAL; - } - - return ret; -} - - -static const char* g313_get_info(RIG *rig) -{ - struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; - static RADIO_INFO info; - - info.bLength = sizeof(RADIO_INFO); - - if (priv->G3GetInfo(priv->hRadio,&info) == FALSE) - return NULL; - - return info.szSerNum; -} - - -int g313_set_conf(RIG *rig, token_t token, const char *val) -{ - struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; - int id; - - switch(token) - { - case WAVEOUT_SOUNDCARDID: - if (val[0] == '0' && val[1] == 'x') - id = strtol(val, (char **)NULL, 16); - else - id = atoi(val); - if(id<-3 || id>32) - { - return -RIG_EINVAL; - } - - priv->WaveOutDeviceID=id; - - if(priv->Opened) - { - if(id==-2) - { - id=g313_findVSC(priv); - } - - if(priv->hWaveOut) - { - priv->StopWaveOut(priv->hWaveOut); - } - - if(id>-3) - { - priv->hWaveOut=priv->StartWaveOut(priv->hRadio,id); - } - else - { - priv->hWaveOut=NULL; - } - } - - break; - default: - return -RIG_EINVAL; - } - return RIG_OK; -} - -int g313_get_conf(RIG *rig, token_t token, char *val) -{ - struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; - - switch(token) - { - case WAVEOUT_SOUNDCARDID: - sprintf(val,"%d",priv->WaveOutDeviceID); - break; - default: - return -RIG_EINVAL; - } - return RIG_OK; -} - -/* end _WIN32 and __CYGWIN__ */ -#else - -/* linux, maybe other posix */ - -#include -#include "linradio/wrg313api.h" -#include -#include -#include -#include -#include - -#define TOK_SHM_AUDIO 0x150901 -#define TOK_SHM_IF 0x150902 -#define TOK_SHM_SPECTRUM 0x150903 - -#define FIFO_PATHNAME_SIZE 64 - -const struct confparams g313_cfg_params[] = { - { TOK_SHM_AUDIO, "audio_path", "audio path name", - "POSIX shared memory path name to the audio ringbuffer", - "", RIG_CONF_STRING, - }, - { TOK_SHM_IF, "if_path", "I/F path name", - "POSIX shared memory path name to the I/F ringbuffer", - "", RIG_CONF_STRING, - }, - { TOK_SHM_SPECTRUM, "spectrum_path", "spectrum path name", - "POSIX shared memory path name to the spectrum ringbuffer", - "", RIG_CONF_STRING, - }, - { RIG_CONF_END, NULL, } -}; - -struct g313_fifo_data { - int fd; - char path[FIFO_PATHNAME_SIZE]; -}; - -struct g313_priv_data { - int hRadio; - int Opened; - struct g313_fifo_data if_buf; - struct g313_fifo_data audio_buf; - struct g313_fifo_data spectrum_buf; -}; - -static void g313_audio_callback(short* buffer, int count, void* arg); -static void g313_if_callback(short* buffer, int count, void* arg); -static void g313_spectrum_callback(float* buffer, int count, void* arg); - -int g313_init(RIG *rig) -{ - struct g313_priv_data *priv; - - priv = (struct g313_priv_data*)malloc(sizeof(struct g313_priv_data)); - - memset(priv, 0, sizeof(struct g313_priv_data)); - - if (!priv) { - /* whoops! memory shortage! */ - return -RIG_ENOMEM; - } - - if(!InitAPI()) - { - rig_debug(RIG_DEBUG_ERR, "%s: Unable to initialise G313 api\n", __FUNCTION__); - free(priv); - return -RIG_EIO; - } - rig_debug(RIG_DEBUG_VERBOSE, "%s: Initialised G313 API\n", __FUNCTION__); - - rig->state.priv = (void*)priv; - - return RIG_OK; -} - -int g313_open(RIG *rig) -{ - int ret; - struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; - RADIO_DESC *List; - int Count; - - void* audio_callback = g313_audio_callback; - void* if_callback = g313_if_callback; - void* spectrum_callback = g313_spectrum_callback; - - if(priv->Opened) - return RIG_OK; - - ret = GetDeviceList(&List, &Count); - if(ret<0 || Count==0) - return -RIG_EIO; - - /* Open Winradio receiver handle (default to first device?) */ - - rig_debug(RIG_DEBUG_VERBOSE, "%s: found %d rigs 0 is %s\n", __FUNCTION__, Count, List[0].Path); - - if(rig->state.rigport.pathname[0]) - priv->hRadio = OpenDevice(rig->state.rigport.pathname); - else - priv->hRadio = OpenDevice(List[0].Path); - - DestroyDeviceList(List); - - - if (priv->hRadio < 0) - { - return -RIG_EIO; /* huh! */ - } - rig_debug(RIG_DEBUG_VERBOSE, "%s: Openned G313\n", __FUNCTION__); - - /* Make sure the receiver is switched on */ - SetPower(priv->hRadio, 1); - - priv->audio_buf.fd = open(priv->audio_buf.path, O_WRONLY|O_NONBLOCK); - rig_debug(RIG_DEBUG_VERBOSE, "%s: audio path %s fifo: %d\n", __FUNCTION__, priv->audio_buf.path, priv->audio_buf.fd); - if(priv->audio_buf.fd == -1) - audio_callback = NULL; - - priv->if_buf.fd = open(priv->if_buf.path, O_WRONLY|O_NONBLOCK); - rig_debug(RIG_DEBUG_VERBOSE, "%s: if path %s fifo: %d\n", __FUNCTION__, priv->if_buf.path, priv->if_buf.fd); - if(priv->if_buf.fd == -1) - if_callback = NULL; - - priv->spectrum_buf.fd = open(priv->spectrum_buf.path, O_WRONLY|O_NONBLOCK); - rig_debug(RIG_DEBUG_VERBOSE, "%s: spectrum path %s fifo: %d\n", __FUNCTION__, priv->spectrum_buf.path, priv->spectrum_buf.fd); - if(priv->spectrum_buf.fd == -1) - spectrum_callback = NULL; - - ret = StartStreaming(priv->hRadio, audio_callback, if_callback, spectrum_callback, priv); - if(ret) - { - return -RIG_EIO; - } - rig_debug(RIG_DEBUG_VERBOSE, "%s: told G313 to start streaming audio: %d, if: %d, spec: %d\n", - __FUNCTION__, - audio_callback?1:0, if_callback?1:0, spectrum_callback?1:0); - - priv->Opened=1; - - return RIG_OK; -} - -int g313_close(RIG *rig) -{ - struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; - - if(!priv->Opened) - { - return RIG_OK; - } - - priv->Opened=0; - -/* - rig_debug(RIG_DEBUG_VERBOSE, "%s: stop streaming\n", __FUNCTION__); - StopStreaming(priv->hRadio); - - req.tv_sec=0; - req.tv_nsec=500000000L; - nanosleep(&req, NULL); -*/ - rig_debug(RIG_DEBUG_VERBOSE, "%s: Closing G313\n", __FUNCTION__); - CloseDevice(priv->hRadio); - - return RIG_OK; -} - -int g313_cleanup(RIG *rig) -{ - struct g313_priv_data *priv; - - if (!rig) - return -RIG_EINVAL; - - priv=(struct g313_priv_data *)rig->state.priv; - - rig_debug(RIG_DEBUG_VERBOSE, "%s: close fifos\n", __FUNCTION__); - if(priv->audio_buf.fd>=0) - close(priv->audio_buf.fd); - if(priv->if_buf.fd>=0) - close(priv->if_buf.fd); - if(priv->spectrum_buf.fd) - close(priv->spectrum_buf.fd); - - if (rig->state.priv) - free(rig->state.priv); - rig->state.priv = NULL; - - rig_debug(RIG_DEBUG_VERBOSE, "%s: Uninitialising G313 API\n", __FUNCTION__); - UninitAPI(); - - return RIG_OK; -} - -int g313_set_freq(RIG *rig, vfo_t vfo, freq_t freq) -{ - struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; - int ret; - - rig_debug(RIG_DEBUG_VERBOSE, "%s: %u\n", __FUNCTION__, (unsigned int)freq); - ret = SetFrequency(priv->hRadio, (unsigned int) (freq)); - ret = ret==0 ? RIG_OK : -RIG_EIO; - - return ret; -} - -int g313_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) -{ - struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; - - unsigned int f; - int ret = GetFrequency(priv->hRadio, &f); - rig_debug(RIG_DEBUG_VERBOSE, "%s: ret: %d f: %u\n", __FUNCTION__, ret, f); - if(ret) - return -RIG_EIO; - - *freq = (freq_t)f; - return RIG_OK; -} - -int g313_set_powerstat(RIG *rig, powerstat_t status) -{ - struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; - - int p = status==RIG_POWER_ON ? 1 : 0; - int ret = SetPower(priv->hRadio, p); - rig_debug(RIG_DEBUG_VERBOSE, "%s: ret: %d state: %d\n", __FUNCTION__, ret, p); - - return ret==0 ? RIG_OK : -RIG_EIO; -} - -int g313_get_powerstat(RIG *rig, powerstat_t *status) -{ - struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; - - int p; - int ret = GetPower(priv->hRadio, &p); - rig_debug(RIG_DEBUG_VERBOSE, "%s: ret: %d state: %d\n", __FUNCTION__, ret, p); - if(ret) - return -RIG_EIO; - - *status = p ? RIG_POWER_ON : RIG_POWER_OFF; - - return RIG_OK; -} - -int g313_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) -{ - struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; - int ret, agc; - - switch(level) { - case RIG_LEVEL_ATT: - ret = SetAttenuator(priv->hRadio, val.i != 0 ? 1 : 0); - rig_debug(RIG_DEBUG_VERBOSE, "%s: ret: %d Attenuator: %d\n", __FUNCTION__, ret, val.i); - break; - - case RIG_LEVEL_AGC: - switch (val.i) { - case RIG_AGC_OFF: agc = 0; break; - case RIG_AGC_SLOW: agc = 1; break; - case RIG_AGC_MEDIUM: agc = 2; break; - case RIG_AGC_FAST: agc = 3; break; - default: - return -RIG_EINVAL; - } - ret = SetAGC(priv->hRadio, agc); - rig_debug(RIG_DEBUG_VERBOSE, "%s: ret: %d AGC: %d\n", __FUNCTION__, ret, val.i); - break; - - case RIG_LEVEL_RF: - ret = SetIFGain(priv->hRadio, (int)(val.f*100)); - rig_debug(RIG_DEBUG_VERBOSE, "%s: ret: %d Gain: %f\n", __FUNCTION__, ret, val.f); - break; - - default: - return -RIG_EINVAL; - } - - return ret==0 ? RIG_OK : -RIG_EIO; -} - -int g313_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) -{ - struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; - int ret; - int value; - unsigned int uvalue; - double dbl; - unsigned char ch; - - switch(level) { - case RIG_LEVEL_ATT: - ret = GetAttenuator(priv->hRadio, &value); - rig_debug(RIG_DEBUG_VERBOSE, "%s: ret: %d Attenuator: %u\n", __FUNCTION__, ret, value); - if(ret) - return -RIG_EIO; - val->i = value?rig->caps->attenuator[0]:0; - break; - - case RIG_LEVEL_AGC: - ret = GetAGC(priv->hRadio, &value); - rig_debug(RIG_DEBUG_VERBOSE, "%s: ret: %d AGC: %u\n", __FUNCTION__, ret, value); - if(ret) - return -RIG_EIO; - - switch (value) { - case 0: val->i = RIG_AGC_OFF; break; - case 1: val->i = RIG_AGC_SLOW; break; - case 2: val->i = RIG_AGC_MEDIUM; break; - case 3: val->i = RIG_AGC_FAST; break; - default: - return -RIG_EINVAL; - } - break; - - case RIG_LEVEL_RF: - ret = GetIFGain(priv->hRadio, &uvalue); - rig_debug(RIG_DEBUG_VERBOSE, "%s: ret: %d Gain: %u\n", __FUNCTION__, ret, uvalue); - if(ret) - return -RIG_EIO; - val->f = ((float)uvalue)/100.0; - break; - - case RIG_LEVEL_STRENGTH: - ret = GetSignalStrength(priv->hRadio, &dbl); - rig_debug(RIG_DEBUG_VERBOSE, "%s: ret: %d sigstr: %f\n", __FUNCTION__, ret, dbl); - if(ret) - return -RIG_EIO; - val->i = ((int)dbl/1.0)+73; - break; - - case RIG_LEVEL_RAWSTR: - ret = GetRawSignalStrength(priv->hRadio, &ch); - rig_debug(RIG_DEBUG_VERBOSE, "%s: ret: %d Raw Sigstr: %u\n", __FUNCTION__, ret, (unsigned int)ch); - if(ret) - return -RIG_EIO; - val->i = ch; - break; - - default: - return -RIG_EINVAL; - } - - return RIG_OK; -} - -static const char* g313_get_info(RIG *rig) -{ - struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; - static RADIO_INFO info; - int ret; - - info.Size = sizeof(RADIO_INFO); - - ret = GetRadioInfo(priv->hRadio,&info); - - if(ret) - return NULL; - - rig_debug(RIG_DEBUG_VERBOSE, "%s: ret: %d sernum: %s\n", __FUNCTION__, ret, info.SerNum); - return info.SerNum; -} - -int g313_set_conf(RIG *rig, token_t token, const char *val) -{ - struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; - - size_t len = strlen(val); - - switch(token) - { - case TOK_SHM_AUDIO: - if(len>(FIFO_PATHNAME_SIZE-1)) - { - rig_debug(RIG_DEBUG_WARN, "%s: set audio_path %s is too long\n", __FUNCTION__, val); - return -RIG_EINVAL; - } - memset(priv->audio_buf.path, 0, FIFO_PATHNAME_SIZE); - strcpy(priv->audio_buf.path, val); - rig_debug(RIG_DEBUG_VERBOSE, "%s: set audio_path %s\n", __FUNCTION__, priv->audio_buf.path); - break; - case TOK_SHM_IF: - if(len>(FIFO_PATHNAME_SIZE-1)) - { - rig_debug(RIG_DEBUG_WARN, "%s: set if_path %s is too long\n", __FUNCTION__, val); - return -RIG_EINVAL; - } - memset(priv->if_buf.path, 0, FIFO_PATHNAME_SIZE); - strcpy(priv->if_buf.path, val); - rig_debug(RIG_DEBUG_VERBOSE, "%s: set if_path %s\n", __FUNCTION__, priv->if_buf.path); - break; - case TOK_SHM_SPECTRUM: - if(len>(FIFO_PATHNAME_SIZE-1)) - { - rig_debug(RIG_DEBUG_WARN, "%s: set spectrum_path %s is too long\n", __FUNCTION__, val); - return -RIG_EINVAL; - } - memset(priv->spectrum_buf.path, 0, FIFO_PATHNAME_SIZE); - strcpy(priv->spectrum_buf.path, val); - rig_debug(RIG_DEBUG_VERBOSE, "%s: set spectrum_path %s\n", __FUNCTION__, priv->spectrum_buf.path); - } - return RIG_OK; -} - -int g313_get_conf(RIG *rig, token_t token, char *val) -{ - struct g313_priv_data *priv = (struct g313_priv_data *)rig->state.priv; - switch(token) - { - case TOK_SHM_AUDIO: - strcpy(val, priv->audio_buf.path); - break; - case TOK_SHM_IF: - strcpy(val, priv->if_buf.path); - break; - case TOK_SHM_SPECTRUM: - strcpy(val, priv->spectrum_buf.path); - } - return RIG_OK; -} - -/* no need to check return from write - if not all can be written, accept overruns */ - -static void g313_audio_callback(short* buffer, int count, void* arg) -{ - struct g313_priv_data *priv = (struct g313_priv_data*)arg; - write(priv->audio_buf.fd, buffer, count*sizeof(short)); -} - -static void g313_if_callback(short* buffer, int count, void* arg) -{ - struct g313_priv_data *priv = (struct g313_priv_data*)arg; - write(priv->if_buf.fd, buffer, count*sizeof(short)); -} - -static void g313_spectrum_callback(float* buffer, int count, void* arg) -{ - struct g313_priv_data *priv = (struct g313_priv_data*)arg; - write(priv->spectrum_buf.fd, buffer, count*sizeof(float)); -} - -const struct rig_caps g313_caps = -{ - .rig_model = RIG_MODEL_G313, - .model_name = "WR-G313", - .mfg_name = "Winradio", - .version = "0.1", - .copyright = "LGPL", /* This wrapper, not the G313 shared library or driver */ - .status = RIG_STATUS_ALPHA, - .rig_type = RIG_TYPE_PCRECEIVER, - .port_type = RIG_PORT_NONE, - .targetable_vfo = 0, - .ptt_type = RIG_PTT_NONE, - .dcd_type = RIG_DCD_NONE, - .has_get_func = G313_FUNC, - .has_set_func = G313_FUNC, - .has_get_level = G313_LEVEL, - .has_set_level = RIG_LEVEL_SET(G313_LEVEL), - .has_get_parm = RIG_PARM_NONE, - .has_set_parm = RIG_PARM_NONE, - .ctcss_list = NULL, - .dcs_list = NULL, - .chan_list = { RIG_CHAN_END }, - .transceive = RIG_TRN_OFF, - .max_ifshift = kHz(2), - .attenuator = { 20, RIG_DBLST_END, }, /* TBC */ - .rx_range_list1 = { {.start = kHz(9),.end = MHz(30),.modes = G313_MODES, - .low_power = -1,.high_power = -1,.vfo = RIG_VFO_A}, - RIG_FRNG_END, }, - .tx_range_list1 = { RIG_FRNG_END, }, - .rx_range_list2 = { {.start = kHz(9),.end = MHz(30),.modes = G313_MODES, - .low_power = -1,.high_power = -1,.vfo = RIG_VFO_A}, - RIG_FRNG_END, }, - .tx_range_list2 = { RIG_FRNG_END, }, - - .tuning_steps = { {G313_MODES,1}, - RIG_TS_END, }, - - .filters = { {G313_MODES, kHz(12)}, - RIG_FLT_END, }, - - .cfgparams = g313_cfg_params, - .set_conf = g313_set_conf, - .get_conf = g313_get_conf, - - .rig_init = g313_init, - .rig_cleanup = g313_cleanup, - .rig_open = g313_open, - .rig_close = g313_close, - - .set_freq = g313_set_freq, - .get_freq = g313_get_freq, - - .set_powerstat = g313_set_powerstat, - .get_powerstat = g313_get_powerstat, - .set_level = g313_set_level, - .get_level = g313_get_level, - - .get_info = g313_get_info, -}; - -#endif /* not __CYGWIN__ */ -#endif /* not _WIN32 */ diff --git a/winradio/linradio/wrg313api.c b/winradio/linradio/wrg313api.c index 6da279328..2b1f3f171 100644 --- a/winradio/linradio/wrg313api.c +++ b/winradio/linradio/wrg313api.c @@ -1,12 +1,14 @@ -#ifndef _WIN32 -#ifndef __CYGWIN__ +#if (!defined(_WIN32) || !defined(__CYGWIN__)) -#include #include -#include -#include "wrg313api.h" +#include "config.h" +#ifdef HAVE_DLFCN_H +# include +#endif + +#include "wrg313api.h" OPEN_DEVICE OpenDevice=0; @@ -55,119 +57,87 @@ LOAD_CALIBRATION_FILE LoadCalibrationFile=0; RESET_CALIBRATION ResetCalibration=0; GET_API_VERSION GetAPIVersion=0; -void *hWRAPI=0; - - - -int InitAPI(void) +int InitAPI(void *hWRAPI) { - if(hWRAPI) - { - return 1; - } - else - { - hWRAPI=dlopen("wrg313api.so",RTLD_LAZY); + if(hWRAPI == NULL) { + return 0; + } + GetAPIVersion=(GET_API_VERSION)dlsym(hWRAPI,"GetAPIVersion"); - if(hWRAPI==NULL) - { - fprintf(stderr,"Unable to load "WRG3APINAME" shared library (%s).\n",dlerror()); - return 0; - } - else - { - GetAPIVersion=(GET_API_VERSION)dlsym(hWRAPI,"GetAPIVersion"); + OpenDevice=(OPEN_DEVICE)dlsym(hWRAPI,"OpenDevice"); + CloseDevice=(CLOSE_DEVICE)dlsym(hWRAPI,"CloseDevice"); + SetPower=(SET_POWER)dlsym(hWRAPI,"SetPower"); + GetPower=(GET_POWER)dlsym(hWRAPI,"GetPower"); + SetFrequency=(SET_FREQUENCY)dlsym(hWRAPI,"SetFrequency"); + GetFrequency=(GET_FREQUENCY)dlsym(hWRAPI,"GetFrequency"); + GetRadioInfo=(GET_RADIO_INFO)dlsym(hWRAPI,"GetRadioInfo"); - OpenDevice=(OPEN_DEVICE)dlsym(hWRAPI,"OpenDevice"); - CloseDevice=(CLOSE_DEVICE)dlsym(hWRAPI,"CloseDevice"); - SetPower=(SET_POWER)dlsym(hWRAPI,"SetPower"); - GetPower=(GET_POWER)dlsym(hWRAPI,"GetPower"); - SetFrequency=(SET_FREQUENCY)dlsym(hWRAPI,"SetFrequency"); - GetFrequency=(GET_FREQUENCY)dlsym(hWRAPI,"GetFrequency"); - GetRadioInfo=(GET_RADIO_INFO)dlsym(hWRAPI,"GetRadioInfo"); + GetRSSI=(GET_RSSI)dlsym(hWRAPI,"GetRSSI"); + GetAGC=(GET_AGC)dlsym(hWRAPI,"GetAGC"); + SetAGC=(SET_AGC)dlsym(hWRAPI,"SetAGC"); + SetIFGain=(SET_IF_GAIN)dlsym(hWRAPI,"SetIFGain"); + GetIFGain=(GET_IF_GAIN)dlsym(hWRAPI,"GetIFGain"); - GetRSSI=(GET_RSSI)dlsym(hWRAPI,"GetRSSI"); - GetAGC=(GET_AGC)dlsym(hWRAPI,"GetAGC"); - SetAGC=(SET_AGC)dlsym(hWRAPI,"SetAGC"); - SetIFGain=(SET_IF_GAIN)dlsym(hWRAPI,"SetIFGain"); - GetIFGain=(GET_IF_GAIN)dlsym(hWRAPI,"GetIFGain"); + GetDeviceList=(GET_DEVICE_LIST)dlsym(hWRAPI,"GetDeviceList"); + DestroyDeviceList=(DESTROY_DEVICE_LIST)dlsym(hWRAPI,"DestroyDeviceList"); - GetDeviceList=(GET_DEVICE_LIST)dlsym(hWRAPI,"GetDeviceList"); - DestroyDeviceList=(DESTROY_DEVICE_LIST)dlsym(hWRAPI,"DestroyDeviceList"); + SetSoftAGC=(SET_SOFT_AGC)dlsym(hWRAPI,"SetSoftAGC"); + GetSoftAGC=(GET_SOFT_AGC)dlsym(hWRAPI,"GetSoftAGC"); + GetVolume=(GET_VOLUME)dlsym(hWRAPI,"GetVolume"); + SetVolume=(SET_VOLUME)dlsym(hWRAPI,"SetVolume"); + SetMode=(SET_MODE)dlsym(hWRAPI,"SetMode"); + GetMode=(GET_MODE)dlsym(hWRAPI,"GetMode"); + SetIFShift=(SET_IF_SHIFT)dlsym(hWRAPI,"SetIFShift"); + GetIFShift=(GET_IF_SHIFT)dlsym(hWRAPI,"GetIFShift"); + SetIFBandwidth=(SET_IF_BANDWIDTH)dlsym(hWRAPI,"SetIFBandwidth"); + GetIFBandwidth=(GET_IF_BANDWIDTH)dlsym(hWRAPI,"GetIFBandwidth"); - SetSoftAGC=(SET_SOFT_AGC)dlsym(hWRAPI,"SetSoftAGC"); - GetSoftAGC=(GET_SOFT_AGC)dlsym(hWRAPI,"GetSoftAGC"); - GetVolume=(GET_VOLUME)dlsym(hWRAPI,"GetVolume"); - SetVolume=(SET_VOLUME)dlsym(hWRAPI,"SetVolume"); - SetMode=(SET_MODE)dlsym(hWRAPI,"SetMode"); - GetMode=(GET_MODE)dlsym(hWRAPI,"GetMode"); - SetIFShift=(SET_IF_SHIFT)dlsym(hWRAPI,"SetIFShift"); - GetIFShift=(GET_IF_SHIFT)dlsym(hWRAPI,"GetIFShift"); - SetIFBandwidth=(SET_IF_BANDWIDTH)dlsym(hWRAPI,"SetIFBandwidth"); - GetIFBandwidth=(GET_IF_BANDWIDTH)dlsym(hWRAPI,"GetIFBandwidth"); + StartStreaming=(START_STREAMING)dlsym(hWRAPI,"StartStreaming"); + StopStreaming=(STOP_STREAMING)dlsym(hWRAPI,"StopStreaming"); - StartStreaming=(START_STREAMING)dlsym(hWRAPI,"StartStreaming"); - StopStreaming=(STOP_STREAMING)dlsym(hWRAPI,"StopStreaming"); + SetAttenuator=(SET_ATTENUATOR)dlsym(hWRAPI,"SetAttenuator"); + GetAttenuator=(GET_ATTENUATOR)dlsym(hWRAPI,"GetAttenuator"); - SetAttenuator=(SET_ATTENUATOR)dlsym(hWRAPI,"SetAttenuator"); - GetAttenuator=(GET_ATTENUATOR)dlsym(hWRAPI,"GetAttenuator"); + IsDeviceConnected=(IS_DEVICE_CONNECTED)dlsym(hWRAPI,"IsDeviceConnected"); - IsDeviceConnected=(IS_DEVICE_CONNECTED)dlsym(hWRAPI,"IsDeviceConnected"); + GetInterface=(GET_INTERFACE)dlsym(hWRAPI,"GetInterface"); - GetInterface=(GET_INTERFACE)dlsym(hWRAPI,"GetInterface"); + GetRawSignalStrength=(GET_RAW_SIGNAL_STRENGTH)dlsym(hWRAPI,"GetRawSignalStrength"); + GetSignalStrength=(GET_SIGNAL_STRENGTH)dlsym(hWRAPI,"GetSignalStrength"); - GetRawSignalStrength=(GET_RAW_SIGNAL_STRENGTH)dlsym(hWRAPI,"GetRawSignalStrength"); - GetSignalStrength=(GET_SIGNAL_STRENGTH)dlsym(hWRAPI,"GetSignalStrength"); + SetCWTone=(SET_CW_TONE)dlsym(hWRAPI,"SetCWTone"); + GetCWTone=(GET_CW_TONE)dlsym(hWRAPI,"GetCWTone"); - SetCWTone=(SET_CW_TONE)dlsym(hWRAPI,"SetCWTone"); - GetCWTone=(GET_CW_TONE)dlsym(hWRAPI,"GetCWTone"); + SetFMAFSquelchLevel=(SET_FM_AF_SQUELCH_LEVEL)dlsym(hWRAPI,"SetFMAFSquelchLevel"); + GetFMAFSquelchLevel=(GET_FM_AF_SQUELCH_LEVEL)dlsym(hWRAPI,"GetFMAFSquelchLevel"); - SetFMAFSquelchLevel=(SET_FM_AF_SQUELCH_LEVEL)dlsym(hWRAPI,"SetFMAFSquelchLevel"); - GetFMAFSquelchLevel=(GET_FM_AF_SQUELCH_LEVEL)dlsym(hWRAPI,"GetFMAFSquelchLevel"); + SetNotchFilter=(SET_NOTCH_FILTER)dlsym(hWRAPI,"SetNotchFilter"); + GetNotchFilter=(GET_NOTCH_FILTER)dlsym(hWRAPI,"GetNotchFilter"); - SetNotchFilter=(SET_NOTCH_FILTER)dlsym(hWRAPI,"SetNotchFilter"); - GetNotchFilter=(GET_NOTCH_FILTER)dlsym(hWRAPI,"GetNotchFilter"); + SetNoiseBlanker=(SET_NOISE_BLANKER)dlsym(hWRAPI,"SetNoiseBlanker"); + GetNoiseBlanker=(GET_NOISE_BLANKER)dlsym(hWRAPI,"GetNoiseBlanker"); - SetNoiseBlanker=(SET_NOISE_BLANKER)dlsym(hWRAPI,"SetNoiseBlanker"); - GetNoiseBlanker=(GET_NOISE_BLANKER)dlsym(hWRAPI,"GetNoiseBlanker"); + SetISBAudioChannel=(SET_ISB_AUDIO_CHANNEL)dlsym(hWRAPI,"SetISBAudioChannel"); + GetISBAudioChannel=(GET_ISB_AUDIO_CHANNEL)dlsym(hWRAPI,"GetISBAudioChannel"); - SetISBAudioChannel=(SET_ISB_AUDIO_CHANNEL)dlsym(hWRAPI,"SetISBAudioChannel"); - GetISBAudioChannel=(GET_ISB_AUDIO_CHANNEL)dlsym(hWRAPI,"GetISBAudioChannel"); + LoadCalibrationFile=(LOAD_CALIBRATION_FILE)dlsym(hWRAPI,"LoadCalibrationFile"); + ResetCalibration=(RESET_CALIBRATION)dlsym(hWRAPI,"ResetCalibration"); - LoadCalibrationFile=(LOAD_CALIBRATION_FILE)dlsym(hWRAPI,"LoadCalibrationFile"); - ResetCalibration=(RESET_CALIBRATION)dlsym(hWRAPI,"ResetCalibration"); - - if(!GetAPIVersion || !OpenDevice || !CloseDevice || !SetPower || !GetPower || !GetFrequency || !SetFrequency || - !GetRadioInfo || !GetRSSI || !GetAGC || !SetAGC || - !GetIFGain || !SetIFGain || !SetSoftAGC || !GetSoftAGC || !SetVolume || !GetVolume || !GetMode || - !SetMode || !GetDeviceList || !DestroyDeviceList || !ResetCalibration || - !StartStreaming || !StopStreaming || !LoadCalibrationFile || - !SetAttenuator || !GetAttenuator || !GetSignalStrength || - !SetIFShift || !SetIFBandwidth || !GetIFBandwidth || !GetIFShift || - !GetRawSignalStrength || !IsDeviceConnected || !GetInterface || - !SetCWTone || !GetCWTone || !SetFMAFSquelchLevel || !GetFMAFSquelchLevel || - !SetNotchFilter || !GetNotchFilter || !SetNoiseBlanker || !GetNoiseBlanker || - !SetISBAudioChannel || !GetISBAudioChannel) - { - fprintf(stderr,"Unable to load valid "WRG3APINAME" library.\n"); - dlclose(hWRAPI); - hWRAPI=0; - return 0; - } - - return 1; - } - } + if(!GetAPIVersion || !OpenDevice || !CloseDevice || !SetPower || !GetPower || !GetFrequency || !SetFrequency || + !GetRadioInfo || !GetRSSI || !GetAGC || !SetAGC || + !GetIFGain || !SetIFGain || !SetSoftAGC || !GetSoftAGC || !SetVolume || !GetVolume || !GetMode || + !SetMode || !GetDeviceList || !DestroyDeviceList || !ResetCalibration || + !StartStreaming || !StopStreaming || !LoadCalibrationFile || + !SetAttenuator || !GetAttenuator || !GetSignalStrength || + !SetIFShift || !SetIFBandwidth || !GetIFBandwidth || !GetIFShift || + !GetRawSignalStrength || !IsDeviceConnected || !GetInterface || + !SetCWTone || !GetCWTone || !SetFMAFSquelchLevel || !GetFMAFSquelchLevel || + !SetNotchFilter || !GetNotchFilter || !SetNoiseBlanker || !GetNoiseBlanker || + !SetISBAudioChannel || !GetISBAudioChannel) + { + return 0; + } + return 1; } -void UninitAPI(void) -{ - if(hWRAPI) - { - dlclose(hWRAPI); - hWRAPI=0; - } -} - -#endif /* not __CYGWIN__ */ -#endif /* not _WIN32 */ +#endif /* not _WIN32 or __CYGWIN__ */ diff --git a/winradio/linradio/wrg313api.h b/winradio/linradio/wrg313api.h index bb5a3bbdf..9e58b8f61 100644 --- a/winradio/linradio/wrg313api.h +++ b/winradio/linradio/wrg313api.h @@ -166,7 +166,7 @@ extern LOAD_CALIBRATION_FILE LoadCalibrationFile; extern RESET_CALIBRATION ResetCalibration; extern GET_API_VERSION GetAPIVersion; -int InitAPI(void); +int InitAPI(void *hWRAPI); void UninitAPI(void); #endif