From bfa948ebc5e4a9f8244a56b1cc961900173b545b Mon Sep 17 00:00:00 2001 From: Jeroen Vreeken Date: Thu, 29 Mar 2018 23:55:25 +0200 Subject: [PATCH] Add GPIO and GPION options for DCD. Also bump abi version since the config params struct needed resizing. --- configure.ac | 6 +++--- include/hamlib/rig.h | 6 ++++-- src/conf.c | 36 ++++++++++++++++++++++++++++++++++-- src/gpio.c | 33 +++++++++++++++++++++++++++++++-- src/gpio.h | 3 ++- src/rig.c | 40 ++++++++++++++++++++++++++++++++++++++-- tests/rigctl.c | 8 ++++++++ 7 files changed, 120 insertions(+), 12 deletions(-) diff --git a/configure.ac b/configure.ac index 706561cb9..7c84dad46 100644 --- a/configure.ac +++ b/configure.ac @@ -55,9 +55,9 @@ ROT_BACKEND_LIST="amsat ars celestron cnctrk easycomm ether6 fodtrack gs232a hea dnl See README.release on setting these values # Values given to -version-info when linking. See libtool documentation. # Set them here to keep c++/Makefile and src/Makefile in sync. -ABI_VERSION=3 -ABI_REVISION=3 -ABI_AGE=1 +ABI_VERSION=4 +ABI_REVISION=0 +ABI_AGE=0 AC_DEFINE_UNQUOTED([ABI_VERSION], [$ABI_VERSION], [Frontend ABI version]) AC_DEFINE_UNQUOTED([ABI_REVISION], [$ABI_REVISION], [Frontend ABI revision]) diff --git a/include/hamlib/rig.h b/include/hamlib/rig.h index b94af30ce..be501d7d8 100644 --- a/include/hamlib/rig.h +++ b/include/hamlib/rig.h @@ -431,7 +431,9 @@ typedef enum { RIG_DCD_SERIAL_CTS, /*!< DCD status from serial CTS signal */ RIG_DCD_SERIAL_CAR, /*!< DCD status from serial CD signal */ RIG_DCD_PARALLEL, /*!< DCD status from parallel port pin */ - RIG_DCD_CM108 /*!< DCD status from CM108 vol dn pin */ + RIG_DCD_CM108, /*!< DCD status from CM108 vol dn pin */ + RIG_DCD_GPIO, /*!< DCD status from GPIO pin */ + RIG_DCD_GPION, /*!< DCD status from inverted GPIO pin */ } dcd_type_t; @@ -571,7 +573,7 @@ enum rig_conf_e { }; -#define RIG_COMBO_MAX 8 +#define RIG_COMBO_MAX 16 /** * \brief Configuration parameter structure. diff --git a/src/conf.c b/src/conf.c index 551e54fa5..3b1ca1656 100644 --- a/src/conf.c +++ b/src/conf.c @@ -91,7 +91,7 @@ static const struct confparams frontend_cfg_params[] = { TOK_PTT_TYPE, "ptt_type", "PTT type", "Push-To-Talk interface type override", - "RIG", RIG_CONF_COMBO, { .c = {{ "RIG", "DTR", "RTS", "Parallel", "CM108", "None", NULL }} } + "RIG", RIG_CONF_COMBO, { .c = {{ "RIG", "DTR", "RTS", "Parallel", "CM108", "GPIO", "GPION", "None", NULL }} } }, { TOK_PTT_PATHNAME, "ptt_pathname", "PTT path name", @@ -106,7 +106,7 @@ static const struct confparams frontend_cfg_params[] = { TOK_DCD_TYPE, "dcd_type", "DCD type", "Data Carrier Detect (or squelch) interface type override", - "RIG", RIG_CONF_COMBO, { .c = {{ "RIG", "DSR", "CTS", "CD", "Parallel", "CM108", "None", NULL }} } + "RIG", RIG_CONF_COMBO, { .c = {{ "RIG", "DSR", "CTS", "CD", "Parallel", "CM108", "GPIO", "GPION", "None", NULL }} } }, { TOK_DCD_PATHNAME, "dcd_pathname", "DCD path name", @@ -422,6 +422,14 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val) { rs->pttport.type.ptt = RIG_PTT_CM108; } + else if (!strcmp(val, "GPIO")) + { + rs->pttport.type.ptt = RIG_PTT_GPIO; + } + else if (!strcmp(val, "GPION")) + { + rs->pttport.type.ptt = RIG_PTT_GPION; + } else if (!strcmp(val, "None")) { rs->pttport.type.ptt = RIG_PTT_NONE; @@ -471,6 +479,14 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val) { rs->dcdport.type.dcd = RIG_DCD_CM108; } + else if (!strcmp(val, "GPIO")) + { + rs->dcdport.type.dcd = RIG_DCD_GPIO; + } + else if (!strcmp(val, "GPION")) + { + rs->dcdport.type.dcd = RIG_DCD_GPION; + } else if (!strcmp(val, "None")) { rs->dcdport.type.dcd = RIG_DCD_NONE; @@ -720,6 +736,14 @@ static int frontend_get_conf(RIG *rig, token_t token, char *val) s = "CM108"; break; + case RIG_PTT_GPIO: + s = "GPIO"; + break; + + case RIG_PTT_GPION: + s = "GPION"; + break; + case RIG_PTT_NONE: s = "None"; break; @@ -766,6 +790,14 @@ static int frontend_get_conf(RIG *rig, token_t token, char *val) s = "CM108"; break; + case RIG_DCD_GPIO: + s = "GPIO"; + break; + + case RIG_DCD_GPION: + s = "GPION"; + break; + case RIG_DCD_NONE: s = "None"; break; diff --git a/src/gpio.c b/src/gpio.c index 0d3d38eb9..d6dc99be1 100644 --- a/src/gpio.c +++ b/src/gpio.c @@ -29,7 +29,7 @@ #include "gpio.h" -int gpio_open(hamlib_port_t *port, int on_value) +int gpio_open(hamlib_port_t *port, int output, int on_value) { char pathname[FILPATHLEN]; FILE *fexp, *fdir; @@ -69,7 +69,13 @@ int gpio_open(hamlib_port_t *port, int on_value) return -RIG_EIO; } - fprintf(fdir, "out\n"); + if (output) + { + fprintf(fdir, "out\n"); + } else + { + fprintf(fdir, "in\n"); + } fclose(fdir); snprintf(pathname, @@ -134,3 +140,26 @@ int gpio_ptt_get(hamlib_port_t *port, ptt_t *pttx) return RIG_PTT_OFF; } } + +int gpio_dcd_get(hamlib_port_t *port, dcd_t *dcdx) +{ + char val; + int port_value; + + lseek(port->fd, 0, SEEK_SET); + if (read(port->fd, &val, sizeof(val)) <= 0) + { + return -RIG_EIO; + } + + port_value = val - '0'; + + if (port_value == port->parm.gpio.on_value) + { + return RIG_DCD_ON; + } else + { + return RIG_DCD_OFF; + } +} + diff --git a/src/gpio.h b/src/gpio.h index c72a2b53f..d53054bf2 100644 --- a/src/gpio.h +++ b/src/gpio.h @@ -28,10 +28,11 @@ __BEGIN_DECLS /* Hamlib internal use, see rig.c */ -int gpio_open(hamlib_port_t *p, int on_value); +int gpio_open(hamlib_port_t *p, int output, int on_value); int gpio_close(hamlib_port_t *p); int gpio_ptt_set(hamlib_port_t *p, ptt_t pttx); int gpio_ptt_get(hamlib_port_t *p, ptt_t *pttx); +int gpio_dcd_get(hamlib_port_t *p, dcd_t *dcdx); __END_DECLS diff --git a/src/rig.c b/src/rig.c index 5e0b483d0..5a973c713 100644 --- a/src/rig.c +++ b/src/rig.c @@ -688,7 +688,7 @@ int HAMLIB_API rig_open(RIG *rig) break; case RIG_PTT_GPIO: - rs->pttport.fd = gpio_open(&rs->pttport, 1); + rs->pttport.fd = gpio_open(&rs->pttport, 1, 1); if (rs->pttport.fd < 0) { @@ -706,7 +706,7 @@ int HAMLIB_API rig_open(RIG *rig) break; case RIG_PTT_GPION: - rs->pttport.fd = gpio_open(&rs->pttport, 0); + rs->pttport.fd = gpio_open(&rs->pttport, 1, 0); if (rs->pttport.fd < 0) { @@ -780,6 +780,34 @@ int HAMLIB_API rig_open(RIG *rig) break; + case RIG_DCD_GPIO: + rs->dcdport.fd = gpio_open(&rs->dcdport, 0, 1); + + if (rs->dcdport.fd < 0) + { + rig_debug(RIG_DEBUG_ERR, + "%s: cannot open DCD device \"%s\"\n", + __func__, + rs->dcdport.pathname); + status = -RIG_EIO; + } + + break; + + case RIG_DCD_GPION: + rs->dcdport.fd = gpio_open(&rs->dcdport, 0, 0); + + if (rs->dcdport.fd < 0) + { + rig_debug(RIG_DEBUG_ERR, + "%s: cannot open DCD device \"%s\"\n", + __func__, + rs->dcdport.pathname); + status = -RIG_EIO; + } + + break; + default: rig_debug(RIG_DEBUG_ERR, "%s: unsupported DCD type %d\n", @@ -969,6 +997,10 @@ int HAMLIB_API rig_close(RIG *rig) port_close(&rs->dcdport, RIG_PORT_PARALLEL); break; + case RIG_DCD_GPIO: + case RIG_DCD_GPION: + port_close(&rs->dcdport, RIG_PORT_GPIO); + default: rig_debug(RIG_DEBUG_ERR, "%s: unsupported DCD type %d\n", @@ -2036,6 +2068,10 @@ int HAMLIB_API rig_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd) case RIG_DCD_PARALLEL: return par_dcd_get(&rig->state.dcdport, dcd); + case RIG_DCD_GPIO: + case RIG_DCD_GPION: + return gpio_dcd_get(&rig->state.dcdport, dcd); + case RIG_DCD_NONE: return -RIG_ENAVAIL; /* not available */ diff --git a/tests/rigctl.c b/tests/rigctl.c index 82458eabf..bcfa4b6a3 100644 --- a/tests/rigctl.c +++ b/tests/rigctl.c @@ -300,6 +300,14 @@ int main(int argc, char *argv[]) { dcd_type = RIG_DCD_CM108; } + else if (!strcmp(optarg, "GPIO")) + { + dcd_type = RIG_DCD_GPIO; + } + else if (!strcmp(optarg, "GPION")) + { + dcd_type = RIG_DCD_GPION; + } else if (!strcmp(optarg, "NONE")) { dcd_type = RIG_DCD_NONE;