kopia lustrzana https://github.com/Hamlib/Hamlib
Porównaj commity
7 Commity
148e22799e
...
624f663d4a
Autor | SHA1 | Data |
---|---|---|
Addison Schuhardt | 624f663d4a | |
Mike Black W9MDB | dce80d264a | |
Mike Black W9MDB | 4c111da0d1 | |
Mike Black W9MDB | d9b589d254 | |
Mike Black W9MDB | 95b0af114f | |
Mike Black W9MDB | 9e42ca2052 | |
Addison Schuhardt | cf91e96333 |
|
@ -529,6 +529,9 @@ AS_IF([test x"${cf_with_xml_support}" = "xyes"], [
|
||||||
AC_SUBST([LIBXML2_LIBS])
|
AC_SUBST([LIBXML2_LIBS])
|
||||||
AC_SUBST([LIBXML2_CFLAGS])
|
AC_SUBST([LIBXML2_CFLAGS])
|
||||||
|
|
||||||
|
# TODO: I don't know how to use autoconf
|
||||||
|
LIBS="$LIBS -lgpiod"
|
||||||
|
|
||||||
|
|
||||||
## ----------------- ##
|
## ----------------- ##
|
||||||
## Language bindings ##
|
## Language bindings ##
|
||||||
|
|
|
@ -2340,6 +2340,7 @@ typedef struct hamlib_port {
|
||||||
|
|
||||||
int fd; /*!< File descriptor */
|
int fd; /*!< File descriptor */
|
||||||
void *handle; /*!< handle for USB */
|
void *handle; /*!< handle for USB */
|
||||||
|
void *gpio; /*!< handle for GPIO */
|
||||||
|
|
||||||
int write_delay; /*!< Delay between each byte sent out, in mS */
|
int write_delay; /*!< Delay between each byte sent out, in mS */
|
||||||
int post_write_delay; /*!< Delay between each commands send out, in mS */
|
int post_write_delay; /*!< Delay between each commands send out, in mS */
|
||||||
|
|
|
@ -143,7 +143,7 @@ struct rig_caps flrig_caps =
|
||||||
RIG_MODEL(RIG_MODEL_FLRIG),
|
RIG_MODEL(RIG_MODEL_FLRIG),
|
||||||
.model_name = "",
|
.model_name = "",
|
||||||
.mfg_name = "FLRig",
|
.mfg_name = "FLRig",
|
||||||
.version = "20240325.0",
|
.version = "20240418.0",
|
||||||
.copyright = "LGPL",
|
.copyright = "LGPL",
|
||||||
.status = RIG_STATUS_STABLE,
|
.status = RIG_STATUS_STABLE,
|
||||||
.rig_type = RIG_TYPE_TRANSCEIVER,
|
.rig_type = RIG_TYPE_TRANSCEIVER,
|
||||||
|
@ -1305,6 +1305,8 @@ static int flrig_set_freq(RIG *rig, vfo_t vfo, freq_t freq)
|
||||||
|
|
||||||
retval = flrig_transaction(rig, cmd, cmd_arg, NULL, 0);
|
retval = flrig_transaction(rig, cmd, cmd_arg, NULL, 0);
|
||||||
|
|
||||||
|
hl_usleep(100*1000); // FLRig needs a moment to update the active VFO
|
||||||
|
|
||||||
if (retval != RIG_OK)
|
if (retval != RIG_OK)
|
||||||
{
|
{
|
||||||
RETURNFUNC2(retval);
|
RETURNFUNC2(retval);
|
||||||
|
|
|
@ -2790,6 +2790,8 @@ int netrigctl_get_lock_mode(RIG *rig, int *lock)
|
||||||
char cmdbuf[256];
|
char cmdbuf[256];
|
||||||
char buf[BUF_MAX];
|
char buf[BUF_MAX];
|
||||||
int ret;
|
int ret;
|
||||||
|
hamlib_port_t *rp = RIGPORT(rig);
|
||||||
|
|
||||||
SNPRINTF(cmdbuf, sizeof(cmdbuf), "\\get_lock_mode\n");
|
SNPRINTF(cmdbuf, sizeof(cmdbuf), "\\get_lock_mode\n");
|
||||||
ret = netrigctl_transaction(rig, cmdbuf, strlen(cmdbuf), buf);
|
ret = netrigctl_transaction(rig, cmdbuf, strlen(cmdbuf), buf);
|
||||||
|
|
||||||
|
@ -2799,6 +2801,7 @@ int netrigctl_get_lock_mode(RIG *rig, int *lock)
|
||||||
}
|
}
|
||||||
|
|
||||||
sscanf(buf, "%d", lock);
|
sscanf(buf, "%d", lock);
|
||||||
|
ret = read_string(rp, (unsigned char *) buf, BUF_MAX, "\n", 1, 0, 1);
|
||||||
return (RIG_OK);
|
return (RIG_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2819,7 +2822,7 @@ struct rig_caps netrigctl_caps =
|
||||||
RIG_MODEL(RIG_MODEL_NETRIGCTL),
|
RIG_MODEL(RIG_MODEL_NETRIGCTL),
|
||||||
.model_name = "NET rigctl",
|
.model_name = "NET rigctl",
|
||||||
.mfg_name = "Hamlib",
|
.mfg_name = "Hamlib",
|
||||||
.version = "20240304.0",
|
.version = "20240418.0",
|
||||||
.copyright = "LGPL",
|
.copyright = "LGPL",
|
||||||
.status = RIG_STATUS_STABLE,
|
.status = RIG_STATUS_STABLE,
|
||||||
.rig_type = RIG_TYPE_OTHER,
|
.rig_type = RIG_TYPE_OTHER,
|
||||||
|
|
|
@ -2223,6 +2223,9 @@ static int icom_set_mode_without_data(RIG *rig, vfo_t vfo, rmode_t mode,
|
||||||
|| RIG_IS_IC375
|
|| RIG_IS_IC375
|
||||||
|| RIG_IS_IC726
|
|| RIG_IS_IC726
|
||||||
|| RIG_IS_IC475
|
|| RIG_IS_IC475
|
||||||
|
|| RIG_IS_IC756
|
||||||
|
|| RIG_IS_IC756PROII
|
||||||
|
|| RIG_IS_IC756PROIII
|
||||||
|| RIG_IS_IC910
|
|| RIG_IS_IC910
|
||||||
|| RIG_IS_IC7000)
|
|| RIG_IS_IC7000)
|
||||||
{
|
{
|
||||||
|
@ -2668,6 +2671,8 @@ static int icom_get_mode_without_data(RIG *rig, vfo_t vfo, rmode_t *mode,
|
||||||
(RIG_IS_IC706MKII) ||
|
(RIG_IS_IC706MKII) ||
|
||||||
(RIG_IS_IC706MKIIG) ||
|
(RIG_IS_IC706MKIIG) ||
|
||||||
(RIG_IS_IC756) ||
|
(RIG_IS_IC756) ||
|
||||||
|
(RIG_IS_IC756PROII) ||
|
||||||
|
(RIG_IS_IC756PROIII) ||
|
||||||
(RIG_IS_ICR30))
|
(RIG_IS_ICR30))
|
||||||
{
|
{
|
||||||
RETURNFUNC2(RIG_OK);
|
RETURNFUNC2(RIG_OK);
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define BACKEND_VER "20240303"
|
#define BACKEND_VER "20240415"
|
||||||
|
|
||||||
#define ICOM_IS_ID31 rig_is_model(rig, RIG_MODEL_ID31)
|
#define ICOM_IS_ID31 rig_is_model(rig, RIG_MODEL_ID31)
|
||||||
#define ICOM_IS_ID51 rig_is_model(rig, RIG_MODEL_ID51)
|
#define ICOM_IS_ID51 rig_is_model(rig, RIG_MODEL_ID51)
|
||||||
|
|
140
src/gpio.c
140
src/gpio.c
|
@ -19,135 +19,91 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
|
|
||||||
#include "gpio.h"
|
#include "gpio.h"
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <gpiod.h>
|
||||||
|
|
||||||
|
#ifndef GPIOD_PATH
|
||||||
|
// This is what's used on the Raspberry Pi 4; I'm not sure about others
|
||||||
|
#define GPIO_CHIP_NAME "gpiochip0"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define GPIO_CHIP_CONSUMER "Hamlib"
|
||||||
|
|
||||||
int gpio_open(hamlib_port_t *port, int output, int on_value)
|
int gpio_open(hamlib_port_t *port, int output, int on_value)
|
||||||
{
|
{
|
||||||
char pathname[HAMLIB_FILPATHLEN * 2];
|
struct gpiod_chip *chip;
|
||||||
FILE *fexp, *fdir;
|
struct gpiod_line *line;
|
||||||
int fd;
|
|
||||||
char *dir;
|
|
||||||
|
|
||||||
port->parm.gpio.on_value = on_value;
|
port->parm.gpio.on_value = on_value;
|
||||||
|
|
||||||
SNPRINTF(pathname, HAMLIB_FILPATHLEN, "/sys/class/gpio/export");
|
chip = gpiod_chip_open_by_name(GPIO_CHIP_NAME);
|
||||||
fexp = fopen(pathname, "w");
|
|
||||||
|
|
||||||
if (!fexp)
|
if (!chip)
|
||||||
{
|
{
|
||||||
rig_debug(RIG_DEBUG_ERR,
|
rig_debug(RIG_DEBUG_ERR, "Failed to open GPIO chip %s: %s\n", GPIO_CHIP_NAME, strerror(errno));
|
||||||
"Export GPIO%s (using %s): %s\n",
|
|
||||||
port->pathname,
|
|
||||||
pathname,
|
|
||||||
strerror(errno));
|
|
||||||
return -RIG_EIO;
|
return -RIG_EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(fexp, "%s\n", port->pathname);
|
line = gpiod_chip_get_line(chip, atoi(port->pathname));
|
||||||
fclose(fexp);
|
if (!line)
|
||||||
|
|
||||||
SNPRINTF(pathname,
|
|
||||||
sizeof(pathname),
|
|
||||||
"/sys/class/gpio/gpio%s/direction",
|
|
||||||
port->pathname);
|
|
||||||
fdir = fopen(pathname, "w");
|
|
||||||
|
|
||||||
if (!fdir)
|
|
||||||
{
|
{
|
||||||
rig_debug(RIG_DEBUG_ERR,
|
rig_debug(RIG_DEBUG_ERR, "Failed to acquire GPIO%s: %s\n", port->pathname, strerror(errno));
|
||||||
"GPIO%s direction (using %s): %s\n",
|
gpiod_chip_close(chip);
|
||||||
port->pathname,
|
|
||||||
pathname,
|
|
||||||
strerror(errno));
|
|
||||||
return -RIG_EIO;
|
return -RIG_EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
dir = output ? "out" : "in";
|
if ((output && gpiod_line_request_output(line, GPIO_CHIP_CONSUMER, 0) < 0) ||
|
||||||
rig_debug(RIG_DEBUG_VERBOSE, "Setting direction of GPIO%s to %s\n",
|
(!output && gpiod_line_request_input(line, GPIO_CHIP_CONSUMER) < 0))
|
||||||
port->pathname, dir);
|
|
||||||
fprintf(fdir, "%s\n", dir);
|
|
||||||
fclose(fdir);
|
|
||||||
|
|
||||||
SNPRINTF(pathname,
|
|
||||||
sizeof(pathname),
|
|
||||||
"/sys/class/gpio/gpio%s/value",
|
|
||||||
port->pathname);
|
|
||||||
fd = open(pathname, O_RDWR);
|
|
||||||
|
|
||||||
if (fd < 0)
|
|
||||||
{
|
{
|
||||||
rig_debug(RIG_DEBUG_ERR,
|
rig_debug(RIG_DEBUG_ERR, "Failed to set GPIO%s to %s mode: %s\n",
|
||||||
"GPIO%s opening value file %s: %s\n",
|
port->pathname, (output ? "OUTPUT" : "INPUT"), strerror(errno));
|
||||||
port->pathname,
|
gpiod_line_release(line);
|
||||||
pathname,
|
gpiod_chip_close(chip);
|
||||||
strerror(errno));
|
|
||||||
return -RIG_EIO;
|
return -RIG_EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
port->fd = fd;
|
port->gpio = line;
|
||||||
return fd;
|
|
||||||
|
return RIG_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int gpio_close(hamlib_port_t *port)
|
int gpio_close(hamlib_port_t *port)
|
||||||
{
|
{
|
||||||
int retval;
|
gpiod_line_close_chip((struct gpiod_line*)port->gpio);
|
||||||
char pathname[HAMLIB_FILPATHLEN * 2];
|
return RIG_OK;
|
||||||
FILE *fexp;
|
|
||||||
|
|
||||||
retval = close(port->fd);
|
|
||||||
|
|
||||||
SNPRINTF(pathname, HAMLIB_FILPATHLEN, "/sys/class/gpio/unexport");
|
|
||||||
fexp = fopen(pathname, "w");
|
|
||||||
|
|
||||||
if (!fexp)
|
|
||||||
{
|
|
||||||
rig_debug(RIG_DEBUG_ERR,
|
|
||||||
"Export GPIO%s (using %s): %s\n",
|
|
||||||
port->pathname,
|
|
||||||
pathname,
|
|
||||||
strerror(errno));
|
|
||||||
return -RIG_EIO;
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(fexp, "%s\n", port->pathname);
|
|
||||||
fclose(fexp);
|
|
||||||
return retval;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int gpio_ptt_set(hamlib_port_t *port, ptt_t pttx)
|
int gpio_ptt_set(hamlib_port_t *port, ptt_t pttx)
|
||||||
{
|
{
|
||||||
char *val;
|
int result = 0;
|
||||||
port->parm.gpio.value = pttx != RIG_PTT_OFF;
|
port->parm.gpio.value = pttx != RIG_PTT_OFF;
|
||||||
|
|
||||||
if ((port->parm.gpio.value && port->parm.gpio.on_value)
|
if ((port->parm.gpio.value && port->parm.gpio.on_value) ||
|
||||||
|| (!port->parm.gpio.value && !port->parm.gpio.on_value))
|
(!port->parm.gpio.value && !port->parm.gpio.on_value))
|
||||||
{
|
{
|
||||||
val = "1\n";
|
result = gpiod_line_set_value((struct gpiod_line*)port->gpio, 1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
val = "0\n";
|
result = gpiod_line_set_value((struct gpiod_line*)port->gpio, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (write(port->fd, val, strlen(val)) <= 0)
|
if (result)
|
||||||
{
|
{
|
||||||
|
rig_debug(RIG_DEBUG_ERR, "Failed to set the value of GPIO%s: %s\n", port->pathname, strerror(errno));
|
||||||
return -RIG_EIO;
|
return -RIG_EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
return RIG_OK;
|
return RIG_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int gpio_ptt_get(hamlib_port_t *port, ptt_t *pttx)
|
int gpio_ptt_get(hamlib_port_t *port, ptt_t *pttx)
|
||||||
{
|
{
|
||||||
if (port->parm.gpio.value)
|
if (port->parm.gpio.value)
|
||||||
|
@ -164,21 +120,15 @@ int gpio_ptt_get(hamlib_port_t *port, ptt_t *pttx)
|
||||||
|
|
||||||
int gpio_dcd_get(hamlib_port_t *port, dcd_t *dcdx)
|
int gpio_dcd_get(hamlib_port_t *port, dcd_t *dcdx)
|
||||||
{
|
{
|
||||||
char val;
|
int val = gpiod_line_get_value((struct gpiod_line*)port->gpio);
|
||||||
int port_value;
|
if (val < 0)
|
||||||
|
|
||||||
lseek(port->fd, 0, SEEK_SET);
|
|
||||||
|
|
||||||
if (read(port->fd, &val, sizeof(val)) <= 0)
|
|
||||||
{
|
{
|
||||||
return -RIG_EIO;
|
rig_debug(RIG_DEBUG_ERR, "Failed to read the value of GPIO%s: %s\n", port->pathname, strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
rig_debug(RIG_DEBUG_VERBOSE, "DCD GPIO pin value: %c\n", val);
|
rig_debug(RIG_DEBUG_VERBOSE, "DCD GPIO pin value: %c\n", val);
|
||||||
|
|
||||||
port_value = val - '0';
|
if (val == port->parm.gpio.on_value)
|
||||||
|
|
||||||
if (port_value == port->parm.gpio.on_value)
|
|
||||||
{
|
{
|
||||||
*dcdx = RIG_DCD_ON;
|
*dcdx = RIG_DCD_ON;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ static setting_t bitmap_func, bitmap_level, bitmap_parm;
|
||||||
int create_png_range(const freq_range_t rx_range_list[],
|
int create_png_range(const freq_range_t rx_range_list[],
|
||||||
const freq_range_t tx_range_list[], int num);
|
const freq_range_t tx_range_list[], int num);
|
||||||
|
|
||||||
int print_caps_sum(const struct rig_caps *caps, void *data)
|
int print_caps_sum(struct rig_caps *caps, void *data)
|
||||||
{
|
{
|
||||||
|
|
||||||
printf("<TR><TD><A HREF=\"support/model%u.txt\">%s</A></TD><TD>%s</TD>"
|
printf("<TR><TD><A HREF=\"support/model%u.txt\">%s</A></TD><TD>%s</TD>"
|
||||||
|
@ -111,7 +111,7 @@ int print_caps_sum(const struct rig_caps *caps, void *data)
|
||||||
/*
|
/*
|
||||||
* IO params et al.
|
* IO params et al.
|
||||||
*/
|
*/
|
||||||
int print_caps_parameters(const struct rig_caps *caps, void *data)
|
int print_caps_parameters(struct rig_caps *caps, void *data)
|
||||||
{
|
{
|
||||||
printf("<A NAME=\"parms%u\"><TR><TD>%s</TD><TD>",
|
printf("<A NAME=\"parms%u\"><TR><TD>%s</TD><TD>",
|
||||||
caps->rig_model,
|
caps->rig_model,
|
||||||
|
@ -222,7 +222,7 @@ int print_caps_parameters(const struct rig_caps *caps, void *data)
|
||||||
*
|
*
|
||||||
* TODO: add new API calls!
|
* TODO: add new API calls!
|
||||||
*/
|
*/
|
||||||
int print_caps_caps(const struct rig_caps *caps, void *data)
|
int print_caps_caps(struct rig_caps *caps, void *data)
|
||||||
{
|
{
|
||||||
printf("<A NAME=\"caps%u\"><TR><TD>%s</TD>",
|
printf("<A NAME=\"caps%u\"><TR><TD>%s</TD>",
|
||||||
caps->rig_model,
|
caps->rig_model,
|
||||||
|
@ -270,7 +270,7 @@ int print_caps_caps(const struct rig_caps *caps, void *data)
|
||||||
/*
|
/*
|
||||||
* Get/Set parm abilities
|
* Get/Set parm abilities
|
||||||
*/
|
*/
|
||||||
int print_caps_parm(const struct rig_caps *caps, void *data)
|
int print_caps_parm(struct rig_caps *caps, void *data)
|
||||||
{
|
{
|
||||||
setting_t parm;
|
setting_t parm;
|
||||||
int i;
|
int i;
|
||||||
|
@ -307,7 +307,7 @@ int print_caps_parm(const struct rig_caps *caps, void *data)
|
||||||
/*
|
/*
|
||||||
* Get/Set level abilities
|
* Get/Set level abilities
|
||||||
*/
|
*/
|
||||||
int print_caps_level(const struct rig_caps *caps, void *data)
|
int print_caps_level(struct rig_caps *caps, void *data)
|
||||||
{
|
{
|
||||||
setting_t level;
|
setting_t level;
|
||||||
int i;
|
int i;
|
||||||
|
@ -344,7 +344,7 @@ int print_caps_level(const struct rig_caps *caps, void *data)
|
||||||
/*
|
/*
|
||||||
* Get/Set func abilities
|
* Get/Set func abilities
|
||||||
*/
|
*/
|
||||||
int print_caps_func(const struct rig_caps *caps, void *data)
|
int print_caps_func(struct rig_caps *caps, void *data)
|
||||||
{
|
{
|
||||||
setting_t func;
|
setting_t func;
|
||||||
int i;
|
int i;
|
||||||
|
@ -383,7 +383,7 @@ int print_caps_func(const struct rig_caps *caps, void *data)
|
||||||
*
|
*
|
||||||
* FIXME: default output pics is for region2: add region 1 too!
|
* FIXME: default output pics is for region2: add region 1 too!
|
||||||
*/
|
*/
|
||||||
int print_caps_range(const struct rig_caps *caps, void *data)
|
int print_caps_range(struct rig_caps *caps, void *data)
|
||||||
{
|
{
|
||||||
create_png_range(caps->rx_range_list2, caps->tx_range_list2,
|
create_png_range(caps->rx_range_list2, caps->tx_range_list2,
|
||||||
caps->rig_model);
|
caps->rig_model);
|
||||||
|
|
Ładowanie…
Reference in New Issue