From ab3e6bb5a59df1ab1681938420e64ff82d25753e Mon Sep 17 00:00:00 2001 From: Nate Bargmann Date: Wed, 4 Oct 2017 21:32:08 -0500 Subject: [PATCH] Formatted src/ to final coding guidelines --- src/cal.c | 23 +- src/cm108.c | 66 ++- src/conf.c | 314 +++++++---- src/debug.c | 32 +- src/event.c | 169 ++++-- src/ext.c | 81 ++- src/gpio.c | 28 +- src/iofunc.c | 223 +++++--- src/locator.c | 172 ++++-- src/mem.c | 433 +++++++++------ src/microham.c | 1000 ++++++++++++++++++++++------------- src/microham.h | 22 +- src/misc.c | 273 ++++++---- src/misc.h | 35 +- src/network.c | 101 ++-- src/par_nt.h | 6 +- src/parallel.c | 172 ++++-- src/parallel.h | 27 +- src/register.c | 126 +++-- src/rig.c | 1378 +++++++++++++++++++++++++++++++----------------- src/rot_conf.c | 187 ++++--- src/rot_reg.c | 96 ++-- src/rotator.c | 187 ++++--- src/serial.c | 126 +++-- src/settings.c | 181 ++++--- src/tones.c | 138 +++-- src/tones.h | 12 +- src/usb_port.c | 87 +-- 28 files changed, 3750 insertions(+), 1945 deletions(-) diff --git a/src/cal.c b/src/cal.c index 852551c08..fdafc3de6 100644 --- a/src/cal.c +++ b/src/cal.c @@ -31,7 +31,7 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +# include "config.h" #endif #include @@ -67,25 +67,32 @@ float HAMLIB_API rig_raw2val(int rawval, const cal_table_t *cal) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (cal->size == 0) { + if (cal->size == 0) + { return rawval; } for (i = 0; i < cal->size; i++) - if (rawval < cal->table[i].raw) { + { + if (rawval < cal->table[i].raw) + { break; } + } - if (i == 0) { + if (i == 0) + { return cal->table[0].val; } - if (i >= cal->size) { + if (i >= cal->size) + { return cal->table[i - 1].val; } /* catch divide by 0 error */ - if (cal->table[i].raw == cal->table[i - 1].raw) { + if (cal->table[i].raw == cal->table[i - 1].raw) + { return cal->table[i].val; } @@ -93,13 +100,13 @@ float HAMLIB_API rig_raw2val(int rawval, const cal_table_t *cal) /* cheap, less accurate, but no fp needed */ interpolation = ((cal->table[i].raw - rawval) * (cal->table[i].val - cal->table[i - 1].val)) - / (cal->table[i].raw - cal->table[i - 1].raw); + / (cal->table[i].raw - cal->table[i - 1].raw); return cal->table[i].val - interpolation; #else interpolation = ((cal->table[i].raw - rawval) * (float)(cal->table[i].val - cal->table[i - 1].val)) - / (float)(cal->table[i].raw - cal->table[i - 1].raw); + / (float)(cal->table[i].raw - cal->table[i - 1].raw); #endif return cal->table[i].val - interpolation; } diff --git a/src/cm108.c b/src/cm108.c index 112046608..2fd97bfb9 100644 --- a/src/cm108.c +++ b/src/cm108.c @@ -30,7 +30,7 @@ * \file cm108.c */ #ifdef HAVE_CONFIG_H -#include "config.h" +# include "config.h" #endif #include @@ -42,27 +42,30 @@ #include #include #include + #ifdef HAVE_SYS_IOCTL_H -#include +# include #endif #ifdef HAVE_SYS_PARAM_H -#include +# include #endif #ifdef HAVE_WINDOWS_H -#include -#include "par_nt.h" +# include +# include "par_nt.h" #endif + #ifdef HAVE_WINIOCTL_H -#include +# include #endif + #ifdef HAVE_WINBASE_H -#include +# include #endif #ifdef HAVE_LINUX_HIDRAW_H -#include +# include #endif #include @@ -80,13 +83,15 @@ int cm108_open(hamlib_port_t *port) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!port->pathname[0]) { + if (!port->pathname[0]) + { return -RIG_EINVAL; } fd = open(port->pathname, O_RDWR); - if (fd < 0) { + if (fd < 0) + { rig_debug(RIG_DEBUG_ERR, "%s: opening device \"%s\": %s\n", __func__, @@ -100,7 +105,7 @@ int cm108_open(hamlib_port_t *port) rig_debug(RIG_DEBUG_VERBOSE, "%s: checking for cm108 (or compatible) device\n", - __func__); + __func__); struct hidraw_devinfo hiddevinfo; @@ -116,14 +121,16 @@ int cm108_open(hamlib_port_t *port) || hiddevinfo.product == 0x1607 || hiddevinfo.product == 0x160b)))) { - rig_debug(RIG_DEBUG_VERBOSE, - "%s: cm108 compatible device detected\n", - __func__); - } else { + rig_debug(RIG_DEBUG_VERBOSE, + "%s: cm108 compatible device detected\n", + __func__); + } + else + { close(fd); rig_debug(RIG_DEBUG_VERBOSE, "%s: no cm108 (or compatible) device detected\n", - __func__); + __func__); return -RIG_EINVAL; } @@ -163,8 +170,10 @@ int cm108_ptt_set(hamlib_port_t *p, ptt_t pttx) // pins are accessible. The SSS1623 chips have a different pinout, so // we make the GPIO bit number configurable. - switch (p->type.ptt) { - case RIG_PTT_CM108: { + switch (p->type.ptt) + { + case RIG_PTT_CM108: + { // Build a packet for CM108 HID to turn GPIO bit on or off. // Packet is 4 bytes, preceded by a 'report number' byte @@ -181,7 +190,8 @@ int cm108_ptt_set(hamlib_port_t *p, ptt_t pttx) p->parm.cm108.ptt_bitnum, (pttx == RIG_PTT_ON) ? 1 : 0); - char out_rep[] = { + char out_rep[] = + { 0x00, // report number // HID output report 0x00, @@ -192,14 +202,16 @@ int cm108_ptt_set(hamlib_port_t *p, ptt_t pttx) ssize_t nw; - if (p->fd == -1) { + if (p->fd == -1) + { return -RIG_EINVAL; } // Send the HID packet nw = write(p->fd, out_rep, sizeof(out_rep)); - if (nw < 0) { + if (nw < 0) + { return -RIG_EIO; } @@ -228,8 +240,10 @@ int cm108_ptt_get(hamlib_port_t *p, ptt_t *pttx) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - switch (p->type.ptt) { - case RIG_PTT_CM108: { + switch (p->type.ptt) + { + case RIG_PTT_CM108: + { int status; return -RIG_ENIMPL; return status; @@ -261,8 +275,10 @@ int cm108_dcd_get(hamlib_port_t *p, dcd_t *dcdx) // in HID messages from the CM108 device, but I am not sure how // to query this state on demand. - switch (p->type.dcd) { - case RIG_DCD_CM108: { + switch (p->type.dcd) + { + case RIG_DCD_CM108: + { int status; return -RIG_ENIMPL; return status; diff --git a/src/conf.c b/src/conf.c index 6ac5788f4..551e54fa5 100644 --- a/src/conf.c +++ b/src/conf.c @@ -31,7 +31,7 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +# include "config.h" #endif #include @@ -47,7 +47,8 @@ /* * Configuration options available in the rig->state struct. */ -static const struct confparams frontend_cfg_params[] = { +static const struct confparams frontend_cfg_params[] = +{ { TOK_PATHNAME, "rig_pathname", "Rig path name", "Path name to the device file of the rig", @@ -117,7 +118,8 @@ static const struct confparams frontend_cfg_params[] = { }; -static const struct confparams frontend_serial_cfg_params[] = { +static const struct confparams frontend_serial_cfg_params[] = +{ { TOK_SERIAL_SPEED, "serial_speed", "Serial speed", "Serial port baud rate", @@ -172,13 +174,15 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val) caps = rig->caps; rs = &rig->state; - switch (token) { + switch (token) + { case TOK_PATHNAME: strncpy(rs->rigport.pathname, val, FILPATHLEN - 1); break; case TOK_WRITE_DELAY: - if (1 != sscanf(val, "%d", &val_i)) { + if (1 != sscanf(val, "%d", &val_i)) + { return -RIG_EINVAL;//value format error } @@ -186,7 +190,8 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val) break; case TOK_POST_WRITE_DELAY: - if (1 != sscanf(val, "%d", &val_i)) { + if (1 != sscanf(val, "%d", &val_i)) + { return -RIG_EINVAL;//value format error } @@ -194,7 +199,8 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val) break; case TOK_TIMEOUT: - if (1 != sscanf(val, "%d", &val_i)) { + if (1 != sscanf(val, "%d", &val_i)) + { return -RIG_EINVAL;//value format error } @@ -202,7 +208,8 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val) break; case TOK_RETRY: - if (1 != sscanf(val, "%d", &val_i)) { + if (1 != sscanf(val, "%d", &val_i)) + { return -RIG_EINVAL;//value format error } @@ -210,11 +217,13 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val) break; case TOK_SERIAL_SPEED: - if (rs->rigport.type.rig != RIG_PORT_SERIAL) { + if (rs->rigport.type.rig != RIG_PORT_SERIAL) + { return -RIG_EINVAL; } - if (1 != sscanf(val, "%d", &val_i)) { + if (1 != sscanf(val, "%d", &val_i)) + { return -RIG_EINVAL;//value format error } @@ -222,11 +231,13 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val) break; case TOK_DATA_BITS: - if (rs->rigport.type.rig != RIG_PORT_SERIAL) { + if (rs->rigport.type.rig != RIG_PORT_SERIAL) + { return -RIG_EINVAL; } - if (1 != sscanf(val, "%d", &val_i)) { + if (1 != sscanf(val, "%d", &val_i)) + { return -RIG_EINVAL;//value format error } @@ -234,11 +245,13 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val) break; case TOK_STOP_BITS: - if (rs->rigport.type.rig != RIG_PORT_SERIAL) { + if (rs->rigport.type.rig != RIG_PORT_SERIAL) + { return -RIG_EINVAL; } - if (1 != sscanf(val, "%d", &val_i)) { + if (1 != sscanf(val, "%d", &val_i)) + { return -RIG_EINVAL;//value format error } @@ -246,83 +259,121 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val) break; case TOK_PARITY: - if (rs->rigport.type.rig != RIG_PORT_SERIAL) { + if (rs->rigport.type.rig != RIG_PORT_SERIAL) + { return -RIG_EINVAL; } - if (!strcmp(val, "None")) { + if (!strcmp(val, "None")) + { rs->rigport.parm.serial.parity = RIG_PARITY_NONE; - } else if (!strcmp(val, "Odd")) { + } + else if (!strcmp(val, "Odd")) + { rs->rigport.parm.serial.parity = RIG_PARITY_ODD; - } else if (!strcmp(val, "Even")) { + } + else if (!strcmp(val, "Even")) + { rs->rigport.parm.serial.parity = RIG_PARITY_EVEN; - } else if (!strcmp(val, "Mark")) { + } + else if (!strcmp(val, "Mark")) + { rs->rigport.parm.serial.parity = RIG_PARITY_MARK; - } else if (!strcmp(val, "Space")) { + } + else if (!strcmp(val, "Space")) + { rs->rigport.parm.serial.parity = RIG_PARITY_SPACE; - } else { + } + else + { return -RIG_EINVAL; } break; case TOK_HANDSHAKE: - if (rs->rigport.type.rig != RIG_PORT_SERIAL) { + if (rs->rigport.type.rig != RIG_PORT_SERIAL) + { return -RIG_EINVAL; } - if (!strcmp(val, "None")) { + if (!strcmp(val, "None")) + { rs->rigport.parm.serial.handshake = RIG_HANDSHAKE_NONE; - } else if (!strcmp(val, "XONXOFF")) { + } + else if (!strcmp(val, "XONXOFF")) + { rs->rigport.parm.serial.handshake = RIG_HANDSHAKE_XONXOFF; - } else if (!strcmp(val, "Hardware")) { + } + else if (!strcmp(val, "Hardware")) + { rs->rigport.parm.serial.handshake = RIG_HANDSHAKE_HARDWARE; - } else { + } + else + { return -RIG_EINVAL; } break; case TOK_RTS_STATE: - if (rs->rigport.type.rig != RIG_PORT_SERIAL) { + if (rs->rigport.type.rig != RIG_PORT_SERIAL) + { return -RIG_EINVAL; } - if (!strcmp(val, "Unset")) { + if (!strcmp(val, "Unset")) + { rs->rigport.parm.serial.rts_state = RIG_SIGNAL_UNSET; - } else if (!strcmp(val, "ON")) { + } + else if (!strcmp(val, "ON")) + { rs->rigport.parm.serial.rts_state = RIG_SIGNAL_ON; - } else if (!strcmp(val, "OFF")) { + } + else if (!strcmp(val, "OFF")) + { rs->rigport.parm.serial.rts_state = RIG_SIGNAL_OFF; - } else { + } + else + { return -RIG_EINVAL; } break; case TOK_DTR_STATE: - if (rs->rigport.type.rig != RIG_PORT_SERIAL) { + if (rs->rigport.type.rig != RIG_PORT_SERIAL) + { return -RIG_EINVAL; } - if (!strcmp(val, "Unset")) { + if (!strcmp(val, "Unset")) + { rs->rigport.parm.serial.dtr_state = RIG_SIGNAL_UNSET; - } else if (!strcmp(val, "ON")) { + } + else if (!strcmp(val, "ON")) + { rs->rigport.parm.serial.dtr_state = RIG_SIGNAL_ON; - } else if (!strcmp(val, "OFF")) { + } + else if (!strcmp(val, "OFF")) + { rs->rigport.parm.serial.dtr_state = RIG_SIGNAL_OFF; - } else { + } + else + { return -RIG_EINVAL; } break; case TOK_ITU_REGION: - if (1 != sscanf(val, "%d", &val_i)) { + if (1 != sscanf(val, "%d", &val_i)) + { return -RIG_EINVAL;//value format error } - switch (val_i) { + switch (val_i) + { case RIG_ITU_REGION1: rs->itu_region = val_i; memcpy(rs->tx_range_list, caps->tx_range_list1, @@ -347,21 +398,36 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val) break; case TOK_PTT_TYPE: - if (!strcmp(val, "RIG")) { + if (!strcmp(val, "RIG")) + { rs->pttport.type.ptt = RIG_PTT_RIG; - } else if (!strcmp(val, "RIGMICDATA")) { + } + else if (!strcmp(val, "RIGMICDATA")) + { rs->pttport.type.ptt = RIG_PTT_RIG_MICDATA; - } else if (!strcmp(val, "DTR")) { + } + else if (!strcmp(val, "DTR")) + { rs->pttport.type.ptt = RIG_PTT_SERIAL_DTR; - } else if (!strcmp(val, "RTS")) { + } + else if (!strcmp(val, "RTS")) + { rs->pttport.type.ptt = RIG_PTT_SERIAL_RTS; - } else if (!strcmp(val, "Parallel")) { + } + else if (!strcmp(val, "Parallel")) + { rs->pttport.type.ptt = RIG_PTT_PARALLEL; - } else if (!strcmp(val, "CM108")) { + } + else if (!strcmp(val, "CM108")) + { rs->pttport.type.ptt = RIG_PTT_CM108; - } else if (!strcmp(val, "None")) { + } + else if (!strcmp(val, "None")) + { rs->pttport.type.ptt = RIG_PTT_NONE; - } else { + } + else + { return -RIG_EINVAL; } @@ -372,7 +438,8 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val) break; case TOK_PTT_BITNUM: - if (1 != sscanf(val, "%d", &val_i)) { + if (1 != sscanf(val, "%d", &val_i)) + { return -RIG_EINVAL;//value format error } @@ -380,21 +447,36 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val) break; case TOK_DCD_TYPE: - if (!strcmp(val, "RIG")) { + if (!strcmp(val, "RIG")) + { rs->dcdport.type.dcd = RIG_DCD_RIG; - } else if (!strcmp(val, "DSR")) { + } + else if (!strcmp(val, "DSR")) + { rs->dcdport.type.dcd = RIG_DCD_SERIAL_DSR; - } else if (!strcmp(val, "CTS")) { + } + else if (!strcmp(val, "CTS")) + { rs->dcdport.type.dcd = RIG_DCD_SERIAL_CTS; - } else if (!strcmp(val, "CD")) { + } + else if (!strcmp(val, "CD")) + { rs->dcdport.type.dcd = RIG_DCD_SERIAL_CAR; - } else if (!strcmp(val, "Parallel")) { + } + else if (!strcmp(val, "Parallel")) + { rs->dcdport.type.dcd = RIG_DCD_PARALLEL; - } else if (!strcmp(val, "CM108")) { + } + else if (!strcmp(val, "CM108")) + { rs->dcdport.type.dcd = RIG_DCD_CM108; - } else if (!strcmp(val, "None")) { + } + else if (!strcmp(val, "None")) + { rs->dcdport.type.dcd = RIG_DCD_NONE; - } else { + } + else + { return -RIG_EINVAL; } @@ -433,7 +515,8 @@ static int frontend_get_conf(RIG *rig, token_t token, char *val) rs = &rig->state; - switch (token) { + switch (token) + { case TOK_PATHNAME: strcpy(val, rs->rigport.pathname); break; @@ -460,7 +543,8 @@ static int frontend_get_conf(RIG *rig, token_t token, char *val) break; case TOK_SERIAL_SPEED: - if (rs->rigport.type.rig != RIG_PORT_SERIAL) { + if (rs->rigport.type.rig != RIG_PORT_SERIAL) + { return -RIG_EINVAL; } @@ -468,7 +552,8 @@ static int frontend_get_conf(RIG *rig, token_t token, char *val) break; case TOK_DATA_BITS: - if (rs->rigport.type.rig != RIG_PORT_SERIAL) { + if (rs->rigport.type.rig != RIG_PORT_SERIAL) + { return -RIG_EINVAL; } @@ -476,7 +561,8 @@ static int frontend_get_conf(RIG *rig, token_t token, char *val) break; case TOK_STOP_BITS: - if (rs->rigport.type.rig != RIG_PORT_SERIAL) { + if (rs->rigport.type.rig != RIG_PORT_SERIAL) + { return -RIG_EINVAL; } @@ -484,11 +570,13 @@ static int frontend_get_conf(RIG *rig, token_t token, char *val) break; case TOK_PARITY: - if (rs->rigport.type.rig != RIG_PORT_SERIAL) { + if (rs->rigport.type.rig != RIG_PORT_SERIAL) + { return -RIG_EINVAL; } - switch (rs->rigport.parm.serial.parity) { + switch (rs->rigport.parm.serial.parity) + { case RIG_PARITY_NONE: s = "None"; break; @@ -517,11 +605,13 @@ static int frontend_get_conf(RIG *rig, token_t token, char *val) break; case TOK_HANDSHAKE: - if (rs->rigport.type.rig != RIG_PORT_SERIAL) { + if (rs->rigport.type.rig != RIG_PORT_SERIAL) + { return -RIG_EINVAL; } - switch (rs->rigport.parm.serial.handshake) { + switch (rs->rigport.parm.serial.handshake) + { case RIG_HANDSHAKE_NONE: s = "None"; break; @@ -542,11 +632,13 @@ static int frontend_get_conf(RIG *rig, token_t token, char *val) break; case TOK_RTS_STATE: - if (rs->rigport.type.rig != RIG_PORT_SERIAL) { + if (rs->rigport.type.rig != RIG_PORT_SERIAL) + { return -RIG_EINVAL; } - switch (rs->rigport.parm.serial.rts_state) { + switch (rs->rigport.parm.serial.rts_state) + { case RIG_SIGNAL_UNSET: s = "Unset"; break; @@ -567,11 +659,13 @@ static int frontend_get_conf(RIG *rig, token_t token, char *val) break; case TOK_DTR_STATE: - if (rs->rigport.type.rig != RIG_PORT_SERIAL) { + if (rs->rigport.type.rig != RIG_PORT_SERIAL) + { return -RIG_EINVAL; } - switch (rs->rigport.parm.serial.dtr_state) { + switch (rs->rigport.parm.serial.dtr_state) + { case RIG_SIGNAL_UNSET: s = "Unset"; break; @@ -600,7 +694,8 @@ static int frontend_get_conf(RIG *rig, token_t token, char *val) break; case TOK_PTT_TYPE: - switch (rs->pttport.type.ptt) { + switch (rs->pttport.type.ptt) + { case RIG_PTT_RIG: s = "RIG"; break; @@ -645,7 +740,8 @@ static int frontend_get_conf(RIG *rig, token_t token, char *val) break; case TOK_DCD_TYPE: - switch (rs->dcdport.type.dcd) { + switch (rs->dcdport.type.dcd) + { case RIG_DCD_RIG: s = "RIG"; break; @@ -697,9 +793,9 @@ static int frontend_get_conf(RIG *rig, token_t token, char *val) * \brief call a function against each configuration token of a rig * \param rig The rig handle * \param cfunc The function to perform on each token - * \param data Any data to be passed to cfunc + * \param data Any data to be passed to cfunc() * - * Executes \a cfunc on all the elements stored in the conf table. + * Executes \a cfunc() on all the elements stored in the conf table. * rig_token_foreach starts first with backend conf table, then finish * with frontend table. * @@ -708,33 +804,45 @@ static int frontend_get_conf(RIG *rig, token_t token, char *val) * set appropriately). */ int HAMLIB_API rig_token_foreach(RIG *rig, - int (*cfunc)(const struct confparams *, rig_ptr_t), + int (*cfunc)(const struct confparams *, + rig_ptr_t), rig_ptr_t data) { const struct confparams *cfp; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !rig->caps || !cfunc) { + if (!rig || !rig->caps || !cfunc) + { return -RIG_EINVAL; } for (cfp = frontend_cfg_params; cfp->name; cfp++) - if ((*cfunc)(cfp, data) == 0) { + { + if ((*cfunc)(cfp, data) == 0) + { return RIG_OK; } + } - if (rig->caps->port_type == RIG_PORT_SERIAL) { + if (rig->caps->port_type == RIG_PORT_SERIAL) + { for (cfp = frontend_serial_cfg_params; cfp->name; cfp++) - if ((*cfunc)(cfp, data) == 0) { + { + if ((*cfunc)(cfp, data) == 0) + { return RIG_OK; } + } } for (cfp = rig->caps->cfgparams; cfp && cfp->name; cfp++) - if ((*cfunc)(cfp, data) == 0) { + { + if ((*cfunc)(cfp, data) == 0) + { return RIG_OK; } + } return RIG_OK; } @@ -749,15 +857,16 @@ int HAMLIB_API rig_token_foreach(RIG *rig, * * \return a pointer to the confparams struct if found, otherwise NULL. */ -const struct confparams *HAMLIB_API rig_confparam_lookup(RIG *rig, - const char *name) +const struct confparams * HAMLIB_API rig_confparam_lookup(RIG *rig, + const char *name) { const struct confparams *cfp; token_t token; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !rig->caps) { + if (!rig || !rig->caps) + { return NULL; } @@ -765,20 +874,30 @@ const struct confparams *HAMLIB_API rig_confparam_lookup(RIG *rig, token = strtol(name, NULL, 0); for (cfp = rig->caps->cfgparams; cfp && cfp->name; cfp++) - if (!strcmp(cfp->name, name) || token == cfp->token) { + { + if (!strcmp(cfp->name, name) || token == cfp->token) + { return cfp; } + } for (cfp = frontend_cfg_params; cfp->name; cfp++) - if (!strcmp(cfp->name, name) || token == cfp->token) { + { + if (!strcmp(cfp->name, name) || token == cfp->token) + { return cfp; } + } - if (rig->caps->port_type == RIG_PORT_SERIAL) { + if (rig->caps->port_type == RIG_PORT_SERIAL) + { for (cfp = frontend_serial_cfg_params; cfp->name; cfp++) - if (!strcmp(cfp->name, name) || token == cfp->token) { + { + if (!strcmp(cfp->name, name) || token == cfp->token) + { return cfp; } + } } return NULL; @@ -802,7 +921,8 @@ token_t HAMLIB_API rig_token_lookup(RIG *rig, const char *name) cfp = rig_confparam_lookup(rig, name); - if (!cfp) { + if (!cfp) + { return RIG_CONF_END; } @@ -828,28 +948,33 @@ int HAMLIB_API rig_set_conf(RIG *rig, token_t token, const char *val) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !rig->caps) { + if (!rig || !rig->caps) + { return -RIG_EINVAL; } - if (rig_need_debug(RIG_DEBUG_VERBOSE)) { + if (rig_need_debug(RIG_DEBUG_VERBOSE)) + { const struct confparams *cfp; char tokenstr[12]; sprintf(tokenstr, "%ld", token); cfp = rig_confparam_lookup(rig, tokenstr); - if (!cfp) { + if (!cfp) + { return -RIG_EINVAL; } rig_debug(RIG_DEBUG_VERBOSE, "%s: %s='%s'\n", __func__, cfp->name, val); } - if (IS_TOKEN_FRONTEND(token)) { + if (IS_TOKEN_FRONTEND(token)) + { return frontend_set_conf(rig, token, val); } - if (rig->caps->set_conf == NULL) { + if (rig->caps->set_conf == NULL) + { return -RIG_ENAVAIL; } @@ -876,15 +1001,18 @@ int HAMLIB_API rig_get_conf(RIG *rig, token_t token, char *val) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !rig->caps || !val) { + if (!rig || !rig->caps || !val) + { return -RIG_EINVAL; } - if (IS_TOKEN_FRONTEND(token)) { + if (IS_TOKEN_FRONTEND(token)) + { return frontend_get_conf(rig, token, val); } - if (rig->caps->get_conf == NULL) { + if (rig->caps->get_conf == NULL) + { return -RIG_ENAVAIL; } diff --git a/src/debug.c b/src/debug.c index bd43c6248..1ddfc910d 100644 --- a/src/debug.c +++ b/src/debug.c @@ -30,7 +30,7 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +# include "config.h" #endif #include @@ -44,7 +44,7 @@ #include #ifdef ANDROID -#include +# include #endif #include @@ -74,14 +74,17 @@ void dump_hex(const unsigned char ptr[], size_t size) unsigned char c; int i; - if (!rig_need_debug(RIG_DEBUG_TRACE)) { + if (!rig_need_debug(RIG_DEBUG_TRACE)) + { return; } line[sizeof(line) - 1] = '\0'; - for (i = 0; i < size; ++i) { - if (i % DUMP_HEX_WIDTH == 0) { + for (i = 0; i < size; ++i) + { + if (i % DUMP_HEX_WIDTH == 0) + { /* new line */ sprintf(line + 0, "%04x", i); memset(line + 4, ' ', sizeof(line) - 4 - 1); @@ -98,7 +101,8 @@ void dump_hex(const unsigned char ptr[], size_t size) && c < 0x7f) ? c : '.'; /* actually print the line */ - if (i + 1 == size || (i && i % DUMP_HEX_WIDTH == DUMP_HEX_WIDTH - 1)) { + if (i + 1 == size || (i && i % DUMP_HEX_WIDTH == DUMP_HEX_WIDTH - 1)) + { rig_debug(RIG_DEBUG_TRACE, "%s\n", line); } } @@ -135,17 +139,22 @@ void HAMLIB_API rig_debug(enum rig_debug_level_e debug_level, { va_list ap; - if (!rig_need_debug(debug_level)) { + if (!rig_need_debug(debug_level)) + { return; } va_start(ap, fmt); - if (rig_vprintf_cb) { + if (rig_vprintf_cb) + { rig_vprintf_cb(debug_level, rig_vprintf_arg, fmt, ap); - } else { - if (!rig_debug_stream) { + } + else + { + if (!rig_debug_stream) + { rig_debug_stream = stderr; } @@ -158,7 +167,8 @@ void HAMLIB_API rig_debug(enum rig_debug_level_e debug_level, int a; va_start(ap, fmt); - switch (debug_level) { + switch (debug_level) + { // case RIG_DEBUG_NONE: case RIG_DEBUG_BUG: a = ANDROID_LOG_FATAL; diff --git a/src/event.c b/src/event.c index a30f18185..0b54c00df 100644 --- a/src/event.c +++ b/src/event.c @@ -32,7 +32,7 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +# include "config.h" #endif #include @@ -40,13 +40,17 @@ #include #include #include + #ifdef HAVE_SYS_TIME_H -#include +# include #endif + #include + #ifdef HAVE_SYS_IOCTL_H -#include +# include #endif + #include #include #include @@ -56,8 +60,8 @@ #include "event.h" #if defined(WIN32) && !defined(HAVE_TERMIOS_H) -#include "win32termios.h" -#define select win32_serial_select +# include "win32termios.h" +# define select win32_serial_select #endif #ifndef DOC_HIDDEN @@ -114,7 +118,8 @@ int add_trn_rig(RIG *rig) status = sigaction(SIGIO, &act, &hamlib_trn_oldact); - if (status < 0) { + if (status < 0) + { rig_debug(RIG_DEBUG_ERR, "%s: sigaction failed: %s\n", __func__, @@ -123,7 +128,8 @@ int add_trn_rig(RIG *rig) status = fcntl(rig->state.rigport.fd, F_SETOWN, getpid()); - if (status < 0) { + if (status < 0) + { rig_debug(RIG_DEBUG_ERR, "%s: fcntl SETOWN failed: %s\n", __func__, @@ -134,7 +140,8 @@ int add_trn_rig(RIG *rig) #ifdef F_SETSIG status = fcntl(rig->state.rigport.fd, F_SETSIG, SIGIO); - if (status < 0) { + if (status < 0) + { rig_debug(RIG_DEBUG_ERR, "%s: fcntl SETSIG failed: %s\n", __func__, @@ -145,7 +152,8 @@ int add_trn_rig(RIG *rig) status = fcntl(rig->state.rigport.fd, F_SETFL, O_ASYNC); - if (status < 0) { + if (status < 0) + { rig_debug(RIG_DEBUG_ERR, "%s: fcntl SETASYNC failed: %s\n", __func__, @@ -179,7 +187,8 @@ int remove_trn_rig(RIG *rig) #if defined(HAVE_SIGINFO_T) && defined(O_ASYNC) status = fcntl(rig->state.rigport.fd, F_SETFL, 0); - if (status < 0) { + if (status < 0) + { rig_debug(RIG_DEBUG_ERR, "%s: fcntl SETASYNC failed: %s\n", __func__, @@ -190,7 +199,8 @@ int remove_trn_rig(RIG *rig) status = sigaction(SIGIO, &hamlib_trn_oldact, NULL); - if (status < 0) { + if (status < 0) + { rig_debug(RIG_DEBUG_ERR, "%s: sigaction failed: %s\n", __func__, @@ -233,7 +243,8 @@ static int add_trn_poll_rig(RIG *rig) status = sigaction(SIGALRM, &act, &hamlib_trn_poll_oldact); - if (status < 0) { + if (status < 0) + { rig_debug(RIG_DEBUG_ERR, "%s sigaction failed: %s\n", __func__, @@ -259,7 +270,8 @@ static int remove_trn_poll_rig(RIG *rig) status = sigaction(SIGALRM, &hamlib_trn_poll_oldact, NULL); - if (status < 0) { + if (status < 0) + { rig_debug(RIG_DEBUG_ERR, "%s sigaction failed: %s\n", __func__, @@ -291,15 +303,17 @@ static int search_rig_and_decode(RIG *rig, rig_ptr_t data) * so far, only file oriented ports have event reporting support */ if (rig->state.rigport.type.rig != RIG_PORT_SERIAL - || rig->state.rigport.fd == -1) { - return -1; + || rig->state.rigport.fd == -1) + { + return -1; } /* FIXME: siginfo is not portable, however use it where available */ #if 0&&defined(HAVE_SIGINFO_T) siginfo_t *si = (siginfo_t *)data; - if (rig->state.rigport.fd != si->si_fd) { + if (rig->state.rigport.fd != si->si_fd) + { return -1; } @@ -316,7 +330,8 @@ static int search_rig_and_decode(RIG *rig, rig_ptr_t data) */ retval = select(rig->state.rigport.fd + 1, &rfds, NULL, NULL, &tv); - if (retval < 0) { + if (retval < 0) + { rig_debug(RIG_DEBUG_ERR, "%s: select: %s\n", __func__, @@ -329,11 +344,13 @@ static int search_rig_and_decode(RIG *rig, rig_ptr_t data) /* * Do not disturb, the backend is currently receiving data */ - if (rig->state.hold_decode) { + if (rig->state.hold_decode) + { return -1; } - if (rig->caps->decode_event) { + if (rig->caps->decode_event) + { rig->caps->decode_event(rig); } @@ -352,26 +369,31 @@ static int search_rig_and_poll(RIG *rig, rig_ptr_t data) struct rig_state *rs = &rig->state; int retval; - if (rig->state.transceive != RIG_TRN_POLL) { + if (rig->state.transceive != RIG_TRN_POLL) + { return -1; } /* * Do not disturb, the backend is currently receiving data */ - if (rig->state.hold_decode) { + if (rig->state.hold_decode) + { return -1; } rig->state.hold_decode = 2; - if (rig->caps->get_vfo && rig->callbacks.vfo_event) { + if (rig->caps->get_vfo && rig->callbacks.vfo_event) + { vfo_t vfo = RIG_VFO_CURR; retval = rig->caps->get_vfo(rig, &vfo); - if (retval == RIG_OK) { - if (vfo != rs->current_vfo) { + if (retval == RIG_OK) + { + if (vfo != rs->current_vfo) + { rig->callbacks.vfo_event(rig, vfo, rig->callbacks.vfo_arg); } @@ -379,31 +401,42 @@ static int search_rig_and_poll(RIG *rig, rig_ptr_t data) } } - if (rig->caps->get_freq && rig->callbacks.freq_event) { + if (rig->caps->get_freq && rig->callbacks.freq_event) + { freq_t freq; retval = rig->caps->get_freq(rig, RIG_VFO_CURR, &freq); - if (retval == RIG_OK) { - if (freq != rs->current_freq) { - rig->callbacks.freq_event(rig, RIG_VFO_CURR, - freq, rig->callbacks.freq_arg); + if (retval == RIG_OK) + { + if (freq != rs->current_freq) + { + rig->callbacks.freq_event(rig, + RIG_VFO_CURR, + freq, + rig->callbacks.freq_arg); } rs->current_freq = freq; } } - if (rig->caps->get_mode && rig->callbacks.mode_event) { + if (rig->caps->get_mode && rig->callbacks.mode_event) + { rmode_t rmode; pbwidth_t width; retval = rig->caps->get_mode(rig, RIG_VFO_CURR, &rmode, &width); - if (retval == RIG_OK) { - if (rmode != rs->current_mode || width != rs->current_width) { - rig->callbacks.mode_event(rig, RIG_VFO_CURR, - rmode, width, rig->callbacks.mode_arg); + if (retval == RIG_OK) + { + if (rmode != rs->current_mode || width != rs->current_width) + { + rig->callbacks.mode_event(rig, + RIG_VFO_CURR, + rmode, + width, + rig->callbacks.mode_arg); } rs->current_mode = rmode; @@ -493,7 +526,8 @@ int HAMLIB_API rig_set_freq_callback(RIG *rig, freq_cb_t cb, rig_ptr_t arg) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig)) { + if (CHECK_RIG_ARG(rig)) + { return -RIG_EINVAL; } @@ -522,7 +556,8 @@ int HAMLIB_API rig_set_mode_callback(RIG *rig, mode_cb_t cb, rig_ptr_t arg) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig)) { + if (CHECK_RIG_ARG(rig)) + { return -RIG_EINVAL; } @@ -551,7 +586,8 @@ int HAMLIB_API rig_set_vfo_callback(RIG *rig, vfo_cb_t cb, rig_ptr_t arg) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig)) { + if (CHECK_RIG_ARG(rig)) + { return -RIG_EINVAL; } @@ -580,7 +616,8 @@ int HAMLIB_API rig_set_ptt_callback(RIG *rig, ptt_cb_t cb, rig_ptr_t arg) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig)) { + if (CHECK_RIG_ARG(rig)) + { return -RIG_EINVAL; } @@ -609,7 +646,8 @@ int HAMLIB_API rig_set_dcd_callback(RIG *rig, dcd_cb_t cb, rig_ptr_t arg) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig)) { + if (CHECK_RIG_ARG(rig)) + { return -RIG_EINVAL; } @@ -640,7 +678,8 @@ int HAMLIB_API rig_set_pltune_callback(RIG *rig, pltune_cb_t cb, rig_ptr_t arg) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig)) { + if (CHECK_RIG_ARG(rig)) + { return -RIG_EINVAL; } @@ -674,29 +713,37 @@ int HAMLIB_API rig_set_trn(RIG *rig, int trn) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig)) { + if (CHECK_RIG_ARG(rig)) + { return -RIG_EINVAL; } caps = rig->caps; /* detect whether tranceive is active already */ - if (trn != RIG_TRN_OFF && rig->state.transceive != RIG_TRN_OFF) { - if (trn == rig->state.transceive) { + if (trn != RIG_TRN_OFF && rig->state.transceive != RIG_TRN_OFF) + { + if (trn == rig->state.transceive) + { return RIG_OK; - } else { + } + else + { /* when going POLL<->RIG, transtition to OFF */ retcode = rig_set_trn(rig, RIG_TRN_OFF); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } } } - switch (trn) { + switch (trn) + { case RIG_TRN_RIG: - if (caps->transceive != RIG_TRN_RIG) { + if (caps->transceive != RIG_TRN_RIG) + { return -RIG_ENAVAIL; } @@ -704,7 +751,8 @@ int HAMLIB_API rig_set_trn(RIG *rig, int trn) /* some protocols (e.g. CI-V's) offer no way * to turn on/off the transceive mode */ - if (retcode == RIG_OK && caps->set_trn) { + if (retcode == RIG_OK && caps->set_trn) + { retcode = caps->set_trn(rig, RIG_TRN_RIG); } @@ -722,7 +770,8 @@ int HAMLIB_API rig_set_trn(RIG *rig, int trn) value.it_interval.tv_usec = rig->state.poll_interval * 1000; retcode = setitimer(ITIMER_REAL, &value, NULL); - if (retcode == -1) { + if (retcode == -1) + { rig_debug(RIG_DEBUG_ERR, "%s: setitimer: %s\n", __func__, @@ -737,7 +786,8 @@ int HAMLIB_API rig_set_trn(RIG *rig, int trn) break; case RIG_TRN_OFF: - if (rig->state.transceive == RIG_TRN_POLL) { + if (rig->state.transceive == RIG_TRN_POLL) + { #ifdef HAVE_SETITIMER retcode = remove_trn_poll_rig(rig); @@ -749,7 +799,8 @@ int HAMLIB_API rig_set_trn(RIG *rig, int trn) retcode = setitimer(ITIMER_REAL, &value, NULL); - if (retcode == -1) { + if (retcode == -1) + { rig_debug(RIG_DEBUG_ERR, "%s: setitimer: %s\n", __func__, strerror(errno)); @@ -759,10 +810,13 @@ int HAMLIB_API rig_set_trn(RIG *rig, int trn) #else return -RIG_ENAVAIL; #endif - } else if (rig->state.transceive == RIG_TRN_RIG) { + } + else if (rig->state.transceive == RIG_TRN_RIG) + { retcode = remove_trn_rig(rig); - if (caps->set_trn && caps->transceive == RIG_TRN_RIG) { + if (caps->set_trn && caps->transceive == RIG_TRN_RIG) + { retcode = caps->set_trn(rig, RIG_TRN_OFF); } } @@ -773,7 +827,8 @@ int HAMLIB_API rig_set_trn(RIG *rig, int trn) return -RIG_EINVAL; } - if (retcode == RIG_OK) { + if (retcode == RIG_OK) + { rig->state.transceive = trn; } @@ -799,11 +854,13 @@ int HAMLIB_API rig_get_trn(RIG *rig, int *trn) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig) || !trn) { + if (CHECK_RIG_ARG(rig) || !trn) + { return -RIG_EINVAL; } - if (rig->caps->get_trn != NULL) { + if (rig->caps->get_trn != NULL) + { return rig->caps->get_trn(rig, trn); } diff --git a/src/ext.c b/src/ext.c index 6f4ad5ca9..6b88db645 100644 --- a/src/ext.c +++ b/src/ext.c @@ -28,14 +28,14 @@ * \file ext.c * \brief Extension request parameter interface * - * An open-ended set of extension parameters and levels are available for each rig, - * as provided in the rigcaps extparms and extlevels lists. These provide a way - * to work with rig-specific functions that don't fit into the basic "virtual rig" of - * Hamlib. See icom/ic746.c for an example. + * An open-ended set of extension parameters and levels are available for each + * rig, as provided in the rigcaps extparms and extlevels lists. These + * provide a way to work with rig-specific functions that don't fit into the + * basic "virtual rig" of Hamlib. See icom/ic746.c for an example. */ #ifdef HAVE_CONFIG_H -#include "config.h" +# include "config.h" #endif #include @@ -54,9 +54,11 @@ * \param cfunc callback function of each extlevel * \param data cookie to be passed to \a cfunc callback * \brief Executes cfunc on all the elements stored in the extlevels table - * The callback \a cfunc is called until it returns a value which is not strictly positive. - * A zero value means a normal end of iteration, and a negative value an abnormal end, - * which will be the return value of rig_ext_level_foreach. + * + * The callback \a cfunc is called until it returns a value which is not + * strictly positive. A zero value means a normal end of iteration, and a + * negative value an abnormal end, which will be the return value of + * rig_ext_level_foreach. */ int HAMLIB_API rig_ext_level_foreach(RIG *rig, int (*cfunc)(RIG *, @@ -69,18 +71,22 @@ int HAMLIB_API rig_ext_level_foreach(RIG *rig, rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !rig->caps || !cfunc) { + if (!rig || !rig->caps || !cfunc) + { return -RIG_EINVAL; } - for (cfp = rig->caps->extlevels; cfp && cfp->name; cfp++) { + for (cfp = rig->caps->extlevels; cfp && cfp->name; cfp++) + { ret = (*cfunc)(rig, cfp, data); - if (ret == 0) { + if (ret == 0) + { return RIG_OK; } - if (ret < 0) { + if (ret < 0) + { return ret; } } @@ -94,9 +100,11 @@ int HAMLIB_API rig_ext_level_foreach(RIG *rig, * \param cfunc callback function of each extparm * \param data cookie to be passed to \a cfunc callback * \brief Executes cfunc on all the elements stored in the extparms table - * The callback \a cfunc is called until it returns a value which is not strictly positive. - * A zero value means a normal end of iteration, and a negative value an abnormal end, - * which will be the return value of rig_ext_parm_foreach. + * + * The callback \a cfunc is called until it returns a value which is not + * strictly positive. A zero value means a normal end of iteration, and a + * negative value an abnormal end, which will be the return value of + * rig_ext_parm_foreach. */ int HAMLIB_API rig_ext_parm_foreach(RIG *rig, int (*cfunc)(RIG *, @@ -109,18 +117,22 @@ int HAMLIB_API rig_ext_parm_foreach(RIG *rig, rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !rig->caps || !cfunc) { + if (!rig || !rig->caps || !cfunc) + { return -RIG_EINVAL; } - for (cfp = rig->caps->extparms; cfp && cfp->name; cfp++) { + for (cfp = rig->caps->extparms; cfp && cfp->name; cfp++) + { ret = (*cfunc)(rig, cfp, data); - if (ret == 0) { + if (ret == 0) + { return RIG_OK; } - if (ret < 0) { + if (ret < 0) + { return ret; } } @@ -140,25 +152,32 @@ int HAMLIB_API rig_ext_parm_foreach(RIG *rig, * * TODO: should use Lex to speed it up, strcmp hurts! */ -const struct confparams * HAMLIB_API rig_ext_lookup(RIG *rig, const char *name) +const struct confparams *HAMLIB_API rig_ext_lookup(RIG *rig, const char *name) { const struct confparams *cfp; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !rig->caps) { + if (!rig || !rig->caps) + { return NULL; } for (cfp = rig->caps->extlevels; cfp && cfp->name; cfp++) - if (!strcmp(cfp->name, name)) { + { + if (!strcmp(cfp->name, name)) + { return cfp; } + } for (cfp = rig->caps->extparms; cfp && cfp->name; cfp++) - if (!strcmp(cfp->name, name)) { + { + if (!strcmp(cfp->name, name)) + { return cfp; } + } return NULL; } @@ -179,19 +198,26 @@ const struct confparams * HAMLIB_API rig_ext_lookup_tok(RIG *rig, token_t token) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !rig->caps) { + if (!rig || !rig->caps) + { return NULL; } for (cfp = rig->caps->extlevels; cfp && cfp->token; cfp++) - if (cfp->token == token) { + { + if (cfp->token == token) + { return cfp; } + } for (cfp = rig->caps->extparms; cfp && cfp->token; cfp++) - if (cfp->token == token) { + { + if (cfp->token == token) + { return cfp; } + } return NULL; } @@ -210,7 +236,8 @@ token_t HAMLIB_API rig_ext_token_lookup(RIG *rig, const char *name) cfp = rig_ext_lookup(rig, name); - if (!cfp) { + if (!cfp) + { return RIG_CONF_END; } diff --git a/src/gpio.c b/src/gpio.c index cccec6dd4..0d3d38eb9 100644 --- a/src/gpio.c +++ b/src/gpio.c @@ -40,7 +40,8 @@ int gpio_open(hamlib_port_t *port, int on_value) snprintf(pathname, FILPATHLEN, "/sys/class/gpio/export"); fexp = fopen(pathname, "w"); - if (!fexp) { + if (!fexp) + { rig_debug(RIG_DEBUG_ERR, "Export GPIO%s (using %s): %s\n", port->pathname, @@ -58,7 +59,8 @@ int gpio_open(hamlib_port_t *port, int on_value) port->pathname); fdir = fopen(pathname, "w"); - if (!fdir) { + if (!fdir) + { rig_debug(RIG_DEBUG_ERR, "GPIO%s direction (using %s): %s\n", port->pathname, @@ -76,7 +78,8 @@ int gpio_open(hamlib_port_t *port, int on_value) port->pathname); fd = open(pathname, O_WRONLY); - if (fd < 0) { + if (fd < 0) + { rig_debug(RIG_DEBUG_ERR, "GPIO%s opening value file %s: %s\n", port->pathname, @@ -102,13 +105,17 @@ int gpio_ptt_set(hamlib_port_t *port, ptt_t pttx) port->parm.gpio.value = pttx != RIG_PTT_OFF; if ((port->parm.gpio.value && port->parm.gpio.on_value) - || (!port->parm.gpio.value && !port->parm.gpio.on_value)) { - val = "1\n"; - } else { + || (!port->parm.gpio.value && !port->parm.gpio.on_value)) + { + val = "1\n"; + } + else + { val = "0\n"; } - if (write(port->fd, val, strlen(val)) <= 0) { + if (write(port->fd, val, strlen(val)) <= 0) + { return -RIG_EIO; } @@ -118,9 +125,12 @@ int gpio_ptt_set(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) + { return RIG_PTT_ON; - } else { + } + else + { return RIG_PTT_OFF; } } diff --git a/src/iofunc.c b/src/iofunc.c index e8e29836e..8cd0966a9 100644 --- a/src/iofunc.c +++ b/src/iofunc.c @@ -31,7 +31,7 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +# include "config.h" #endif #include @@ -68,32 +68,38 @@ int HAMLIB_API port_open(hamlib_port_t *p) p->fd = -1; - switch (p->type.rig) { + switch (p->type.rig) + { case RIG_PORT_SERIAL: status = serial_open(p); - if (status < 0) { + if (status < 0) + { return status; } if (p->parm.serial.rts_state != RIG_SIGNAL_UNSET - && p->parm.serial.handshake != RIG_HANDSHAKE_HARDWARE) { - status = ser_set_rts(p, - p->parm.serial.rts_state == RIG_SIGNAL_ON); - want_state_delay = 1; + && p->parm.serial.handshake != RIG_HANDSHAKE_HARDWARE) + { + status = ser_set_rts(p, + p->parm.serial.rts_state == RIG_SIGNAL_ON); + want_state_delay = 1; } - if (status != 0) { + if (status != 0) + { return status; } - if (p->parm.serial.dtr_state != RIG_SIGNAL_UNSET) { + if (p->parm.serial.dtr_state != RIG_SIGNAL_UNSET) + { status = ser_set_dtr(p, p->parm.serial.dtr_state == RIG_SIGNAL_ON); want_state_delay = 1; } - if (status != 0) { + if (status != 0) + { return status; } @@ -101,7 +107,8 @@ int HAMLIB_API port_open(hamlib_port_t *p) * Wait whatever electrolytics in the circuit come up to voltage. * Is 100ms enough? Too much? */ - if (want_state_delay) { + if (want_state_delay) + { usleep(100 * 1000); } @@ -110,7 +117,8 @@ int HAMLIB_API port_open(hamlib_port_t *p) case RIG_PORT_PARALLEL: status = par_open(p); - if (status < 0) { + if (status < 0) + { return status; } @@ -119,7 +127,8 @@ int HAMLIB_API port_open(hamlib_port_t *p) case RIG_PORT_CM108: status = cm108_open(p); - if (status < 0) { + if (status < 0) + { return status; } @@ -128,7 +137,8 @@ int HAMLIB_API port_open(hamlib_port_t *p) case RIG_PORT_DEVICE: status = open(p->pathname, O_RDWR, 0); - if (status < 0) { + if (status < 0) + { return -RIG_EIO; } @@ -138,7 +148,8 @@ int HAMLIB_API port_open(hamlib_port_t *p) case RIG_PORT_USB: status = usb_port_open(p); - if (status < 0) { + if (status < 0) + { return status; } @@ -153,7 +164,8 @@ int HAMLIB_API port_open(hamlib_port_t *p) /* FIXME: hardcoded network port */ status = network_open(p, 4532); - if (status < 0) { + if (status < 0) + { return status; } @@ -181,8 +193,10 @@ int HAMLIB_API port_close(hamlib_port_t *p, rig_port_t port_type) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (p->fd != -1) { - switch (port_type) { + if (p->fd != -1) + { + switch (port_type) + { case RIG_PORT_SERIAL: ret = ser_close(p); break; @@ -221,7 +235,7 @@ int HAMLIB_API port_close(hamlib_port_t *p, rig_port_t port_type) #if defined(WIN32) && !defined(HAVE_TERMIOS_H) -#include "win32termios.h" +# include "win32termios.h" extern int is_uh_radio_fd(int fd); @@ -239,27 +253,35 @@ static ssize_t port_read(hamlib_port_t *p, void *buf, size_t count) * Note that we always have RIG_PORT_SERIAL in the * microHam case. */ - if (is_uh_radio_fd(p->fd)) { + if (is_uh_radio_fd(p->fd)) + { return read(p->fd, buf, count); } - if (p->type.rig == RIG_PORT_SERIAL) { + if (p->type.rig == RIG_PORT_SERIAL) + { ret = win32_serial_read(p->fd, buf, count); - if (p->parm.serial.data_bits == 7) { + if (p->parm.serial.data_bits == 7) + { unsigned char *pbuf = buf; /* clear MSB */ - for (i = 0; i < ret; i++) { + for (i = 0; i < ret; i++) + { pbuf[i] &= ~0x80; } } return ret; - } else if (p->type.rig == RIG_PORT_NETWORK - || p->type.rig == RIG_PORT_UDP_NETWORK) { - return recv(p->fd, buf, count, 0); - } else { + } + else if (p->type.rig == RIG_PORT_NETWORK + || p->type.rig == RIG_PORT_UDP_NETWORK) + { + return recv(p->fd, buf, count, 0); + } + else + { return read(p->fd, buf, count); } } @@ -272,23 +294,32 @@ static ssize_t port_write(hamlib_port_t *p, const void *buf, size_t count) * Note that we always have RIG_PORT_SERIAL in the * microHam case. */ - if (is_uh_radio_fd(p->fd)) { + if (is_uh_radio_fd(p->fd)) + { return write(p->fd, buf, count); } - if (p->type.rig == RIG_PORT_SERIAL) { + if (p->type.rig == RIG_PORT_SERIAL) + { return win32_serial_write(p->fd, buf, count); - } else if (p->type.rig == RIG_PORT_NETWORK - || p->type.rig == RIG_PORT_UDP_NETWORK) { - return send(p->fd, buf, count, 0); - } else { + } + else if (p->type.rig == RIG_PORT_NETWORK + || p->type.rig == RIG_PORT_UDP_NETWORK) + { + return send(p->fd, buf, count, 0); + } + else + { return write(p->fd, buf, count); } } -static int port_select(hamlib_port_t *p, int n, fd_set *readfds, - fd_set *writefds, fd_set *exceptfds, +static int port_select(hamlib_port_t *p, + int n, + fd_set *readfds, + fd_set *writefds, + fd_set *exceptfds, struct timeval *timeout) { #if 1 @@ -296,11 +327,13 @@ static int port_select(hamlib_port_t *p, int n, fd_set *readfds, /* select does not work very well with writefds/exceptfds * So let's pretend there's none of them */ - if (exceptfds) { + if (exceptfds) + { FD_ZERO(exceptfds); } - if (writefds) { + if (writefds) + { FD_ZERO(writefds); } @@ -314,13 +347,17 @@ static int port_select(hamlib_port_t *p, int n, fd_set *readfds, * Note that we always have RIG_PORT_SERIAL in the * microHam case. */ - if (is_uh_radio_fd(p->fd)) { + if (is_uh_radio_fd(p->fd)) + { return select(n, readfds, writefds, exceptfds, timeout); } - if (p->type.rig == RIG_PORT_SERIAL) { + if (p->type.rig == RIG_PORT_SERIAL) + { return win32_serial_select(n, readfds, writefds, exceptfds, timeout); - } else { + } + else + { return select(n, readfds, writefds, exceptfds, timeout); } } @@ -335,18 +372,22 @@ static ssize_t port_read(hamlib_port_t *p, void *buf, size_t count) int i; ssize_t ret; - if (p->type.rig == RIG_PORT_SERIAL && p->parm.serial.data_bits == 7) { + if (p->type.rig == RIG_PORT_SERIAL && p->parm.serial.data_bits == 7) + { unsigned char *pbuf = buf; ret = read(p->fd, buf, count); /* clear MSB */ - for (i = 0; i < ret; i++) { + for (i = 0; i < ret; i++) + { pbuf[i] &= ~0x80; } return ret; - } else { + } + else + { return read(p->fd, buf, count); } } @@ -393,7 +434,8 @@ int HAMLIB_API write_block(hamlib_port_t *p, const char *txbuffer, size_t count) #ifdef WANT_NON_ACTIVE_POST_WRITE_DELAY - if (p->post_write_date.tv_sec != 0) { + if (p->post_write_date.tv_sec != 0) + { signed int date_delay; /* in us */ struct timeval tv; @@ -403,7 +445,8 @@ int HAMLIB_API write_block(hamlib_port_t *p, const char *txbuffer, size_t count) ((tv.tv_sec - p->post_write_date.tv_sec) * 1000000 + (tv.tv_usec - p->post_write_date.tv_usec)); - if (date_delay > 0) { + if (date_delay > 0) + { /* * optional delay after last write */ @@ -415,38 +458,57 @@ int HAMLIB_API write_block(hamlib_port_t *p, const char *txbuffer, size_t count) #endif - if (p->write_delay > 0) { - for (i = 0; i < count; i++) { + if (p->write_delay > 0) + { + for (i = 0; i < count; i++) + { ret = port_write(p, txbuffer + i, 1); - if (ret != 1) { - rig_debug(RIG_DEBUG_ERR, "%s():%d failed %d - %s\n", - __func__, __LINE__, ret, strerror(errno)); + if (ret != 1) + { + rig_debug(RIG_DEBUG_ERR, + "%s():%d failed %d - %s\n", + __func__, + __LINE__, + ret, + strerror(errno)); + return -RIG_EIO; } usleep(p->write_delay * 1000); } - } else { + } + else + { ret = port_write(p, txbuffer, count); - if (ret != count) { - rig_debug(RIG_DEBUG_ERR, "%s():%d failed %d - %s\n", - __func__, __LINE__, ret, strerror(errno)); + if (ret != count) + { + rig_debug(RIG_DEBUG_ERR, + "%s():%d failed %d - %s\n", + __func__, + __LINE__, + ret, + strerror(errno)); + return -RIG_EIO; } } - if (p->post_write_delay > 0) { + if (p->post_write_delay > 0) + { #ifdef WANT_NON_ACTIVE_POST_WRITE_DELAY #define POST_WRITE_DELAY_TRSHLD 10 - if (p->post_write_delay > POST_WRITE_DELAY_TRSHLD) { + if (p->post_write_delay > POST_WRITE_DELAY_TRSHLD) + { struct timeval tv; gettimeofday(&tv, NULL); p->post_write_date.tv_sec = tv.tv_sec; p->post_write_date.tv_usec = tv.tv_usec; - } else + } + else #endif usleep(p->post_write_delay * 1000); /* optional delay after last write */ @@ -497,7 +559,8 @@ int HAMLIB_API read_block(hamlib_port_t *p, char *rxbuffer, size_t count) /* Store the time of the read loop start */ gettimeofday(&start_time, NULL); - while (count > 0) { + while (count > 0) + { tv = tv_timeout; /* select may have updated it */ FD_ZERO(&rfds); @@ -506,7 +569,8 @@ int HAMLIB_API read_block(hamlib_port_t *p, char *rxbuffer, size_t count) retval = port_select(p, p->fd + 1, &rfds, NULL, &efds, &tv); - if (retval == 0) { + if (retval == 0) + { /* Record timeout time and caculate elapsed time */ gettimeofday(&end_time, NULL); timersub(&end_time, &start_time, &elapsed_time); @@ -522,7 +586,8 @@ int HAMLIB_API read_block(hamlib_port_t *p, char *rxbuffer, size_t count) return -RIG_ETIMEOUT; } - if (retval < 0) { + if (retval < 0) + { dump_hex((unsigned char *) rxbuffer, total_count); rig_debug(RIG_DEBUG_ERR, "%s(): select() error after %d chars: %s\n", @@ -533,7 +598,8 @@ int HAMLIB_API read_block(hamlib_port_t *p, char *rxbuffer, size_t count) return -RIG_EIO; } - if (FD_ISSET(p->fd, &efds)) { + if (FD_ISSET(p->fd, &efds)) + { rig_debug(RIG_DEBUG_ERR, "%s(): fd error after %d chars\n", __func__, @@ -548,7 +614,8 @@ int HAMLIB_API read_block(hamlib_port_t *p, char *rxbuffer, size_t count) */ rd_count = port_read(p, rxbuffer + total_count, count); - if (rd_count < 0) { + if (rd_count < 0) + { rig_debug(RIG_DEBUG_ERR, "%s(): read() failed - %s\n", __func__, @@ -593,7 +660,9 @@ int HAMLIB_API read_block(hamlib_port_t *p, char *rxbuffer, size_t count) * * Assumes rxbuffer!=NULL */ -int HAMLIB_API read_string(hamlib_port_t *p, char *rxbuffer, size_t rxmax, +int HAMLIB_API read_string(hamlib_port_t *p, + char *rxbuffer, + size_t rxmax, const char *stopset, int stopset_len) { @@ -604,11 +673,13 @@ int HAMLIB_API read_string(hamlib_port_t *p, char *rxbuffer, size_t rxmax, rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!p || !rxbuffer) { + if (!p || !rxbuffer) + { return -RIG_EINVAL; } - if (rxmax < 1) { + if (rxmax < 1) + { return 0; } @@ -621,7 +692,8 @@ int HAMLIB_API read_string(hamlib_port_t *p, char *rxbuffer, size_t rxmax, /* Store the time of the read loop start */ gettimeofday(&start_time, NULL); - while (total_count < rxmax - 1) { + while (total_count < rxmax - 1) + { tv = tv_timeout; /* select may have updated it */ FD_ZERO(&rfds); @@ -630,8 +702,10 @@ int HAMLIB_API read_string(hamlib_port_t *p, char *rxbuffer, size_t rxmax, retval = port_select(p, p->fd + 1, &rfds, NULL, &efds, &tv); - if (retval == 0) { - if (0 == total_count) { + if (retval == 0) + { + if (0 == total_count) + { /* Record timeout time and caculate elapsed time */ gettimeofday(&end_time, NULL); timersub(&end_time, &start_time, &elapsed_time); @@ -650,7 +724,8 @@ int HAMLIB_API read_string(hamlib_port_t *p, char *rxbuffer, size_t rxmax, break; /* return what we have read */ } - if (retval < 0) { + if (retval < 0) + { dump_hex((unsigned char *) rxbuffer, total_count); rig_debug(RIG_DEBUG_ERR, "%s(): select() error after %d chars: %s\n", @@ -661,7 +736,8 @@ int HAMLIB_API read_string(hamlib_port_t *p, char *rxbuffer, size_t rxmax, return -RIG_EIO; } - if (FD_ISSET(p->fd, &efds)) { + if (FD_ISSET(p->fd, &efds)) + { rig_debug(RIG_DEBUG_ERR, "%s(): fd error after %d chars\n", __func__, @@ -676,7 +752,8 @@ int HAMLIB_API read_string(hamlib_port_t *p, char *rxbuffer, size_t rxmax, */ rd_count = port_read(p, &rxbuffer[total_count], 1); - if (rd_count < 0) { + if (rd_count < 0) + { dump_hex((unsigned char *) rxbuffer, total_count); rig_debug(RIG_DEBUG_ERR, "%s(): read() failed - %s\n", @@ -688,7 +765,8 @@ int HAMLIB_API read_string(hamlib_port_t *p, char *rxbuffer, size_t rxmax, ++total_count; - if (stopset && memchr(stopset, rxbuffer[total_count - 1], stopset_len)) { + if (stopset && memchr(stopset, rxbuffer[total_count - 1], stopset_len)) + { break; } } @@ -703,6 +781,7 @@ int HAMLIB_API read_string(hamlib_port_t *p, char *rxbuffer, size_t rxmax, "%s(): RX %d characters\n", __func__, total_count); + dump_hex((unsigned char *) rxbuffer, total_count); return total_count; /* return bytes count read */ diff --git a/src/locator.c b/src/locator.c index 4f2046557..473262bd4 100644 --- a/src/locator.c +++ b/src/locator.c @@ -54,7 +54,7 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +# include "config.h" #endif #include @@ -144,23 +144,29 @@ double HAMLIB_API dms2dec(int degrees, int minutes, double seconds, int sw) rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (degrees < 0) { + if (degrees < 0) + { degrees = abs(degrees); } - if (minutes < 0) { + if (minutes < 0) + { minutes = abs(minutes); } - if (seconds < 0) { + if (seconds < 0) + { seconds = fabs(seconds); } st = (double)degrees + (double)minutes / 60. + seconds / 3600.; - if (sw == 1) { + if (sw == 1) + { return -st; - } else { + } + else + { return st; } } @@ -193,19 +199,24 @@ double HAMLIB_API dmmm2dec(int degrees, double minutes, int sw) rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (degrees < 0) { + if (degrees < 0) + { degrees = abs(degrees); } - if (minutes < 0) { + if (minutes < 0) + { minutes = fabs(minutes); } st = (double)degrees + minutes / 60.; - if (sw == 1) { + if (sw == 1) + { return -st; - } else { + } + else + { return st; } } @@ -238,7 +249,10 @@ double HAMLIB_API dmmm2dec(int degrees, double minutes, int sw) * * \sa dms2dec() */ -int HAMLIB_API dec2dms(double dec, int *degrees, int *minutes, double *seconds, +int HAMLIB_API dec2dms(double dec, + int *degrees, + int *minutes, + double *seconds, int *sw) { int deg, min; @@ -247,7 +261,8 @@ int HAMLIB_API dec2dms(double dec, int *degrees, int *minutes, double *seconds, rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); /* bail if NULL pointers passed */ - if (!degrees || !minutes || !seconds || !sw) { + if (!degrees || !minutes || !seconds || !sw) + { return -RIG_EINVAL; } @@ -258,9 +273,12 @@ int HAMLIB_API dec2dms(double dec, int *degrees, int *minutes, double *seconds, * passed 361 st will be set to 1, etc. If passed * a value > -180 || < 180, value will be unchanged. */ - if (dec >= 0.0) { + if (dec >= 0.0) + { st = fmod(dec + 180, 360) - 180; - } else { + } + else + { st = fmod(dec - 180, 360) + 180; } @@ -268,9 +286,12 @@ int HAMLIB_API dec2dms(double dec, int *degrees, int *minutes, double *seconds, * to be negative as well except for 180 which we want * to be positive. */ - if (st < 0.0 && st != -180) { + if (st < 0.0 && st != -180) + { *sw = 1; - } else { + } + else + { *sw = 0; } @@ -329,13 +350,15 @@ int HAMLIB_API dec2dmmm(double dec, int *degrees, double *minutes, int *sw) rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); /* bail if NULL pointers passed */ - if (!degrees || !minutes || !sw) { + if (!degrees || !minutes || !sw) + { return -RIG_EINVAL; } r = dec2dms(dec, degrees, &min, &sec, sw); - if (r != RIG_OK) { + if (r != RIG_OK) + { return r; } @@ -370,9 +393,9 @@ int HAMLIB_API dec2dmmm(double dec, int *degrees, double *minutes, int *sw) * * \sa longlat2locator() */ - /* begin dph */ -int HAMLIB_API locator2longlat(double *longitude, double *latitude, +int HAMLIB_API locator2longlat(double *longitude, + double *latitude, const char *locator) { int x_or_y, paircount; @@ -383,33 +406,40 @@ int HAMLIB_API locator2longlat(double *longitude, double *latitude, rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); /* bail if NULL pointers passed */ - if (!longitude || !latitude) { + if (!longitude || !latitude) + { return -RIG_EINVAL; } paircount = strlen(locator) / 2; /* verify paircount is within limits */ - if (paircount > MAX_LOCATOR_PAIRS) { + if (paircount > MAX_LOCATOR_PAIRS) + { paircount = MAX_LOCATOR_PAIRS; - } else if (paircount < MIN_LOCATOR_PAIRS) { + } + else if (paircount < MIN_LOCATOR_PAIRS) + { return -RIG_EINVAL; } /* For x(=longitude) and y(=latitude) */ - for (x_or_y = 0; x_or_y < 2; ++x_or_y) { + for (x_or_y = 0; x_or_y < 2; ++x_or_y) + { ordinate = -90.0; divisions = 1; - for (pair = 0; pair < paircount; ++pair) { + for (pair = 0; pair < paircount; ++pair) + { locvalue = locator[pair * 2 + x_or_y]; /* Value of digit or letter */ locvalue -= (loc_char_range[pair] == 10) ? '0' : - (isupper(locvalue)) ? 'A' : 'a'; + (isupper(locvalue)) ? 'A' : 'a'; /* Check range for non-letter/digit or out of range */ - if ((locvalue < 0) || (locvalue >= loc_char_range[pair])) { + if ((locvalue < 0) || (locvalue >= loc_char_range[pair])) + { return -RIG_EINVAL; } @@ -452,9 +482,10 @@ int HAMLIB_API locator2longlat(double *longitude, double *latitude, * * \sa locator2longlat() */ - /* begin dph */ -int HAMLIB_API longlat2locator(double longitude, double latitude, char *locator, +int HAMLIB_API longlat2locator(double longitude, + double latitude, + char *locator, int pair_count) { int x_or_y, pair, locvalue, divisions; @@ -462,22 +493,26 @@ int HAMLIB_API longlat2locator(double longitude, double latitude, char *locator, rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!locator) { + if (!locator) + { return -RIG_EINVAL; } - if (pair_count < MIN_LOCATOR_PAIRS || pair_count > MAX_LOCATOR_PAIRS) { + if (pair_count < MIN_LOCATOR_PAIRS || pair_count > MAX_LOCATOR_PAIRS) + { return -RIG_EINVAL; } - for (x_or_y = 0; x_or_y < 2; ++x_or_y) { + for (x_or_y = 0; x_or_y < 2; ++x_or_y) + { ordinate = (x_or_y == 0) ? longitude / 2.0 : latitude; divisions = 1; /* The 1e-6 here guards against floating point rounding errors */ ordinate = fmod(ordinate + 270.000001, 180.0); - for (pair = 0; pair < pair_count; ++pair) { + for (pair = 0; pair < pair_count; ++pair) + { divisions *= loc_char_range[pair]; square_size = 180.0 / divisions; @@ -520,57 +555,72 @@ int HAMLIB_API longlat2locator(double longitude, double latitude, char *locator, * * \sa distance_long_path(), azimuth_long_path() */ -int HAMLIB_API qrb(double lon1, double lat1, double lon2, double lat2, - double *distance, double *azimuth) +int HAMLIB_API qrb(double lon1, + double lat1, + double lon2, + double lat2, + double *distance, + double *azimuth) { double delta_long, tmp, arc, az; rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); /* bail if NULL pointers passed */ - if (!distance || !azimuth) { + if (!distance || !azimuth) + { return -RIG_EINVAL; } - if ((lat1 > 90.0 || lat1 < -90.0) || (lat2 > 90.0 || lat2 < -90.0)) { + if ((lat1 > 90.0 || lat1 < -90.0) || (lat2 > 90.0 || lat2 < -90.0)) + { return -RIG_EINVAL; } - if ((lon1 > 180.0 || lon1 < -180.0) || (lon2 > 180.0 || lon2 < -180.0)) { + if ((lon1 > 180.0 || lon1 < -180.0) || (lon2 > 180.0 || lon2 < -180.0)) + { return -RIG_EINVAL; } /* Prevent ACOS() Domain Error */ - if (lat1 == 90.0) { + if (lat1 == 90.0) + { lat1 = 89.999999999; - } else if (lat1 == -90.0) { + } + else if (lat1 == -90.0) + { lat1 = -89.999999999; } - if (lat2 == 90.0) { + if (lat2 == 90.0) + { lat2 = 89.999999999; - } else if (lat2 == -90.0) { + } + else if (lat2 == -90.0) + { lat2 = -89.999999999; } /* Convert variables to Radians */ - lat1 /= RADIAN; - lon1 /= RADIAN; - lat2 /= RADIAN; - lon2 /= RADIAN; + lat1 /= RADIAN; + lon1 /= RADIAN; + lat2 /= RADIAN; + lon2 /= RADIAN; delta_long = lon2 - lon1; tmp = sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(delta_long); - if (tmp > .999999999999999) { + if (tmp > .999999999999999) + { /* Station points coincide, use an Omni! */ *distance = 0.0; *azimuth = 0.0; return RIG_OK; } - if (tmp < -.999999) { + if (tmp < -.999999) + { /* * points are antipodal, it's straight down. * Station is equal distance in all Azimuths. @@ -598,9 +648,12 @@ int HAMLIB_API qrb(double lon1, double lat1, double lon2, double lat2, az = fmod(360.0 + az, 360.0); - if (az < 0.0) { + if (az < 0.0) + { az += 360.0; - } else if (az >= 360.0) { + } + else if (az >= 360.0) + { az -= 360.0; } @@ -645,15 +698,24 @@ double HAMLIB_API azimuth_long_path(double azimuth) { rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (azimuth == 0.0 || azimuth == 360.0) { + if (azimuth == 0.0 || azimuth == 360.0) + { return 180.0; - } else if (azimuth > 0.0 && azimuth < 180.0) { + } + else if (azimuth > 0.0 && azimuth < 180.0) + { return 180.0 + azimuth; - } else if (azimuth == 180.0) { + } + else if (azimuth == 180.0) + { return 0.0; - } else if (azimuth > 180.0 && azimuth < 360.0) { + } + else if (azimuth > 180.0 && azimuth < 360.0) + { return (180.0 - azimuth) * -1.0; - } else { + } + else + { return -RIG_EINVAL; } } diff --git a/src/mem.c b/src/mem.c index fd3076e86..9c97be05d 100644 --- a/src/mem.c +++ b/src/mem.c @@ -33,7 +33,7 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +# include "config.h" #endif #include @@ -77,30 +77,35 @@ int HAMLIB_API rig_set_mem(RIG *rig, vfo_t vfo, int ch) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig)) { + if (CHECK_RIG_ARG(rig)) + { return -RIG_EINVAL; } caps = rig->caps; - if (caps->set_mem == NULL) { + if (caps->set_mem == NULL) + { return -RIG_ENAVAIL; } if ((caps->targetable_vfo & RIG_TARGETABLE_PURE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) { - return caps->set_mem(rig, vfo, ch); + || vfo == rig->state.current_vfo) + { + return caps->set_mem(rig, vfo, ch); } - if (!caps->set_vfo) { + if (!caps->set_vfo) + { return -RIG_ENTARGET; } curr_vfo = rig->state.current_vfo; retcode = caps->set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } @@ -135,35 +140,41 @@ int HAMLIB_API rig_get_mem(RIG *rig, vfo_t vfo, int *ch) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig) || !ch) { + if (CHECK_RIG_ARG(rig) || !ch) + { return -RIG_EINVAL; } caps = rig->caps; - if (caps->get_mem == NULL) { + if (caps->get_mem == NULL) + { return -RIG_ENAVAIL; } if ((caps->targetable_vfo & RIG_TARGETABLE_PURE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) { - return caps->get_mem(rig, vfo, ch); + || vfo == rig->state.current_vfo) + { + return caps->get_mem(rig, vfo, ch); } - if (!caps->set_vfo) { + if (!caps->set_vfo) + { return -RIG_ENTARGET; } curr_vfo = rig->state.current_vfo; retcode = caps->set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } retcode = caps->get_mem(rig, vfo, ch); caps->set_vfo(rig, curr_vfo); + return retcode; } @@ -192,30 +203,35 @@ int HAMLIB_API rig_set_bank(RIG *rig, vfo_t vfo, int bank) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig)) { + if (CHECK_RIG_ARG(rig)) + { return -RIG_EINVAL; } caps = rig->caps; - if (caps->set_bank == NULL) { + if (caps->set_bank == NULL) + { return -RIG_ENAVAIL; } if ((caps->targetable_vfo & RIG_TARGETABLE_PURE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) { - return caps->set_bank(rig, vfo, bank); + || vfo == rig->state.current_vfo) + { + return caps->set_bank(rig, vfo, bank); } - if (!caps->set_vfo) { + if (!caps->set_vfo) + { return -RIG_ENTARGET; } curr_vfo = rig->state.current_vfo; retcode = caps->set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } @@ -239,10 +255,14 @@ static int generic_retr_extl(RIG *rig, struct ext_list *p; unsigned el_size = 0; - if (chan->ext_levels == NULL) { + if (chan->ext_levels == NULL) + { p = chan->ext_levels = malloc(2 * sizeof(struct ext_list)); - } else { - for (p = chan->ext_levels; !RIG_IS_EXT_END(*p); p++) { + } + else + { + for (p = chan->ext_levels; !RIG_IS_EXT_END(*p); p++) + { el_size += sizeof(struct ext_list); } @@ -250,7 +270,8 @@ static int generic_retr_extl(RIG *rig, el_size + sizeof(struct ext_list)); } - if (!chan->ext_levels) { + if (!chan->ext_levels) + { rig_debug(RIG_DEBUG_ERR, "%s: %d memory allocation error!\n", __func__, @@ -267,7 +288,8 @@ static int generic_retr_extl(RIG *rig, } -static const channel_cap_t mem_cap_all = { +static const channel_cap_t mem_cap_all = +{ .bank_num = 1, .vfo = 1, .ant = 1, @@ -347,112 +369,139 @@ static int generic_save_channel(RIG *rig, channel_t *chan) chan->channel_num = chan_num; chan->vfo = vfo; - if (vfo == RIG_VFO_MEM) { + if (vfo == RIG_VFO_MEM) + { const chan_t *chan_cap; chan_cap = rig_lookup_mem_caps(rig, chan_num); - if (chan_cap) { + if (chan_cap) + { mem_cap = &chan_cap->mem_caps; } } /* If vfo!=RIG_VFO_MEM or incomplete backend, try all properties */ - if (mem_cap == NULL || rig_mem_caps_empty(mem_cap)) { + if (mem_cap == NULL || rig_mem_caps_empty(mem_cap)) + { mem_cap = &mem_cap_all; } - if (mem_cap->freq) { + if (mem_cap->freq) + { retval = rig_get_freq(rig, RIG_VFO_CURR, &chan->freq); /* empty channel ? */ - if (retval == -RIG_ENAVAIL || chan->freq == RIG_FREQ_NONE) { + if (retval == -RIG_ENAVAIL || chan->freq == RIG_FREQ_NONE) + { return -RIG_ENAVAIL; } } - if (mem_cap->vfo) { + if (mem_cap->vfo) + { rig_get_vfo(rig, &chan->vfo); } - if (mem_cap->mode || mem_cap->width) { + if (mem_cap->mode || mem_cap->width) + { rig_get_mode(rig, RIG_VFO_CURR, &chan->mode, &chan->width); } chan->split = RIG_SPLIT_OFF; - if (mem_cap->split) { + if (mem_cap->split) + { rig_get_split_vfo(rig, RIG_VFO_CURR, &chan->split, &chan->tx_vfo); } - if (chan->split != RIG_SPLIT_OFF) { - if (mem_cap->tx_freq) { + if (chan->split != RIG_SPLIT_OFF) + { + if (mem_cap->tx_freq) + { rig_get_split_freq(rig, RIG_VFO_CURR, &chan->tx_freq); } - if (mem_cap->tx_mode || mem_cap->tx_width) { + if (mem_cap->tx_mode || mem_cap->tx_width) + { rig_get_split_mode(rig, RIG_VFO_CURR, &chan->tx_mode, &chan->tx_width); } - } else { + } + else + { chan->tx_freq = chan->freq; chan->tx_mode = chan->mode; chan->tx_width = chan->width; } - if (mem_cap->rptr_shift) { + if (mem_cap->rptr_shift) + { rig_get_rptr_shift(rig, RIG_VFO_CURR, &chan->rptr_shift); } - if (mem_cap->rptr_offs) { + if (mem_cap->rptr_offs) + { rig_get_rptr_offs(rig, RIG_VFO_CURR, &chan->rptr_offs); } - if (mem_cap->ant) { + if (mem_cap->ant) + { rig_get_ant(rig, RIG_VFO_CURR, &chan->ant); } - if (mem_cap->tuning_step) { + if (mem_cap->tuning_step) + { rig_get_ts(rig, RIG_VFO_CURR, &chan->tuning_step); } - if (mem_cap->rit) { + if (mem_cap->rit) + { rig_get_rit(rig, RIG_VFO_CURR, &chan->rit); } - if (mem_cap->xit) { + if (mem_cap->xit) + { rig_get_xit(rig, RIG_VFO_CURR, &chan->xit); } - for (i = 0; i < RIG_SETTING_MAX; i++) { + for (i = 0; i < RIG_SETTING_MAX; i++) + { setting = rig_idx2setting(i); - if ((setting & mem_cap->levels) && RIG_LEVEL_SET(setting)) { + if ((setting & mem_cap->levels) && RIG_LEVEL_SET(setting)) + { rig_get_level(rig, RIG_VFO_CURR, setting, &chan->levels[i]); } } - for (i = 0; i < RIG_SETTING_MAX; i++) { + for (i = 0; i < RIG_SETTING_MAX; i++) + { int fstatus; setting = rig_idx2setting(i); if ((setting & mem_cap->funcs) - && (rig_get_func(rig, RIG_VFO_CURR, setting, &fstatus) == RIG_OK)) { - chan->funcs |= fstatus ? setting : 0; + && (rig_get_func(rig, RIG_VFO_CURR, setting, &fstatus) == RIG_OK)) + { + chan->funcs |= fstatus ? setting : 0; } } - if (mem_cap->ctcss_tone) { + if (mem_cap->ctcss_tone) + { rig_get_ctcss_tone(rig, RIG_VFO_CURR, &chan->ctcss_tone); } - if (mem_cap->ctcss_sql) { + if (mem_cap->ctcss_sql) + { rig_get_ctcss_sql(rig, RIG_VFO_CURR, &chan->ctcss_sql); } - if (mem_cap->dcs_code) { + if (mem_cap->dcs_code) + { rig_get_dcs_code(rig, RIG_VFO_CURR, &chan->dcs_code); } - if (mem_cap->dcs_sql) { + if (mem_cap->dcs_sql) + { rig_get_dcs_sql(rig, RIG_VFO_CURR, &chan->dcs_sql); } @@ -480,75 +529,92 @@ static int generic_restore_channel(RIG *rig, const channel_t *chan) setting_t setting; const channel_cap_t *mem_cap = NULL; - if (chan->vfo == RIG_VFO_MEM) { + if (chan->vfo == RIG_VFO_MEM) + { const chan_t *chan_cap; chan_cap = rig_lookup_mem_caps(rig, chan->channel_num); - if (chan_cap) { + if (chan_cap) + { mem_cap = &chan_cap->mem_caps; } } /* If vfo!=RIG_VFO_MEM or incomplete backend, try all properties */ - if (mem_cap == NULL || rig_mem_caps_empty(mem_cap)) { + if (mem_cap == NULL || rig_mem_caps_empty(mem_cap)) + { mem_cap = &mem_cap_all; } rig_set_vfo(rig, chan->vfo); - if (mem_cap->freq) { + if (mem_cap->freq) + { rig_set_freq(rig, RIG_VFO_CURR, chan->freq); } - if (mem_cap->mode || mem_cap->width) { + if (mem_cap->mode || mem_cap->width) + { rig_set_mode(rig, RIG_VFO_CURR, chan->mode, chan->width); } rig_set_split_vfo(rig, RIG_VFO_CURR, chan->split, chan->tx_vfo); - if (chan->split != RIG_SPLIT_OFF) { - if (mem_cap->tx_freq) { + if (chan->split != RIG_SPLIT_OFF) + { + if (mem_cap->tx_freq) + { rig_set_split_freq(rig, RIG_VFO_CURR, chan->tx_freq); } - if (mem_cap->tx_mode || mem_cap->tx_width) { + if (mem_cap->tx_mode || mem_cap->tx_width) + { rig_set_split_mode(rig, RIG_VFO_CURR, chan->tx_mode, chan->tx_width); } } - if (mem_cap->rptr_shift) { + if (mem_cap->rptr_shift) + { rig_set_rptr_shift(rig, RIG_VFO_CURR, chan->rptr_shift); } - if (mem_cap->rptr_offs) { + if (mem_cap->rptr_offs) + { rig_set_rptr_offs(rig, RIG_VFO_CURR, chan->rptr_offs); } - for (i = 0; i < RIG_SETTING_MAX; i++) { + for (i = 0; i < RIG_SETTING_MAX; i++) + { setting = rig_idx2setting(i); - if (setting & mem_cap->levels) { + if (setting & mem_cap->levels) + { rig_set_level(rig, RIG_VFO_CURR, setting, chan->levels[i]); } } - if (mem_cap->ant) { + if (mem_cap->ant) + { rig_set_ant(rig, RIG_VFO_CURR, chan->ant); } - if (mem_cap->tuning_step) { + if (mem_cap->tuning_step) + { rig_set_ts(rig, RIG_VFO_CURR, chan->tuning_step); } - if (mem_cap->rit) { + if (mem_cap->rit) + { rig_set_rit(rig, RIG_VFO_CURR, chan->rit); } - if (mem_cap->xit) { + if (mem_cap->xit) + { rig_set_xit(rig, RIG_VFO_CURR, chan->xit); } - for (i = 0; i < RIG_SETTING_MAX; i++) { + for (i = 0; i < RIG_SETTING_MAX; i++) + { setting = rig_idx2setting(i); if (setting & mem_cap->funcs) @@ -556,19 +622,23 @@ static int generic_restore_channel(RIG *rig, const channel_t *chan) chan->funcs & rig_idx2setting(i)); } - if (mem_cap->ctcss_tone) { + if (mem_cap->ctcss_tone) + { rig_set_ctcss_tone(rig, RIG_VFO_CURR, chan->ctcss_tone); } - if (mem_cap->ctcss_sql) { + if (mem_cap->ctcss_sql) + { rig_set_ctcss_sql(rig, RIG_VFO_CURR, chan->ctcss_sql); } - if (mem_cap->dcs_code) { + if (mem_cap->dcs_code) + { rig_set_dcs_code(rig, RIG_VFO_CURR, chan->dcs_code); } - if (mem_cap->dcs_sql) { + if (mem_cap->dcs_sql) + { rig_set_dcs_sql(rig, RIG_VFO_CURR, chan->dcs_sql); } @@ -580,7 +650,8 @@ static int generic_restore_channel(RIG *rig, const channel_t *chan) * - flags */ - for (p = chan->ext_levels; p && !RIG_IS_EXT_END(*p); p++) { + for (p = chan->ext_levels; p && !RIG_IS_EXT_END(*p); p++) + { rig_set_ext_level(rig, RIG_VFO_CURR, p->token, p->val); } @@ -623,7 +694,8 @@ int HAMLIB_API rig_set_channel(RIG *rig, const channel_t *chan) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig) || !chan) { + if (CHECK_RIG_ARG(rig) || !chan) + { return -RIG_EINVAL; } @@ -633,7 +705,8 @@ int HAMLIB_API rig_set_channel(RIG *rig, const channel_t *chan) rc = rig->caps; - if (rc->set_channel) { + if (rc->set_channel) + { return rc->set_channel(rig, chan); } @@ -644,22 +717,25 @@ int HAMLIB_API rig_set_channel(RIG *rig, const channel_t *chan) vfo = chan->vfo; - if (vfo == RIG_VFO_CURR) { + if (vfo == RIG_VFO_CURR) + { return generic_restore_channel(rig, chan); } /* any emulation requires set_mem() */ - if (vfo == RIG_VFO_MEM && !rc->set_mem) { + if (vfo == RIG_VFO_MEM && !rc->set_mem) + { return -RIG_ENAVAIL; } - can_emulate_by_vfo_mem = rc->set_vfo && - ((rig->state.vfo_list & RIG_VFO_MEM) == RIG_VFO_MEM); + can_emulate_by_vfo_mem = rc->set_vfo + && ((rig->state.vfo_list & RIG_VFO_MEM) == RIG_VFO_MEM); - can_emulate_by_vfo_op = rc->vfo_op && - rig_has_vfo_op(rig, RIG_OP_FROM_VFO); + can_emulate_by_vfo_op = rc->vfo_op + && rig_has_vfo_op(rig, RIG_OP_FROM_VFO); - if (!can_emulate_by_vfo_mem && !can_emulate_by_vfo_op) { + if (!can_emulate_by_vfo_mem && !can_emulate_by_vfo_op) + { return -RIG_ENTARGET; } @@ -669,38 +745,46 @@ int HAMLIB_API rig_set_channel(RIG *rig, const channel_t *chan) generic_save_channel(rig, &curr_chan); #endif - if (vfo == RIG_VFO_MEM) { + if (vfo == RIG_VFO_MEM) + { get_mem_status = rig_get_mem(rig, RIG_VFO_CURR, &curr_chan_num); } - if (can_emulate_by_vfo_mem && curr_vfo != vfo) { + if (can_emulate_by_vfo_mem && curr_vfo != vfo) + { retcode = rig_set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } } - if (vfo == RIG_VFO_MEM) { + if (vfo == RIG_VFO_MEM) + { rig_set_mem(rig, RIG_VFO_CURR, chan->channel_num); } retcode = generic_restore_channel(rig, chan); - if (!can_emulate_by_vfo_mem && can_emulate_by_vfo_op) { + if (!can_emulate_by_vfo_mem && can_emulate_by_vfo_op) + { retcode = rig_vfo_op(rig, RIG_VFO_CURR, RIG_OP_FROM_VFO); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } } /* restore current memory number */ - if (vfo == RIG_VFO_MEM && get_mem_status == RIG_OK) { + if (vfo == RIG_VFO_MEM && get_mem_status == RIG_OK) + { rig_set_mem(rig, RIG_VFO_CURR, curr_chan_num); } - if (can_emulate_by_vfo_mem) { + if (can_emulate_by_vfo_mem) + { rig_set_vfo(rig, curr_vfo); } @@ -762,7 +846,8 @@ int HAMLIB_API rig_get_channel(RIG *rig, channel_t *chan) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig) || !chan) { + if (CHECK_RIG_ARG(rig) || !chan) + { return -RIG_EINVAL; } @@ -772,7 +857,8 @@ int HAMLIB_API rig_get_channel(RIG *rig, channel_t *chan) rc = rig->caps; - if (rc->get_channel) { + if (rc->get_channel) + { return rc->get_channel(rig, chan); } @@ -783,22 +869,25 @@ int HAMLIB_API rig_get_channel(RIG *rig, channel_t *chan) */ vfo = chan->vfo; - if (vfo == RIG_VFO_CURR) { + if (vfo == RIG_VFO_CURR) + { return generic_save_channel(rig, chan); } /* any emulation requires set_mem() */ - if (vfo == RIG_VFO_MEM && !rc->set_mem) { + if (vfo == RIG_VFO_MEM && !rc->set_mem) + { return -RIG_ENAVAIL; } - can_emulate_by_vfo_mem = rc->set_vfo && - ((rig->state.vfo_list & RIG_VFO_MEM) == RIG_VFO_MEM); + can_emulate_by_vfo_mem = rc->set_vfo + && ((rig->state.vfo_list & RIG_VFO_MEM) == RIG_VFO_MEM); - can_emulate_by_vfo_op = rc->vfo_op && - rig_has_vfo_op(rig, RIG_OP_TO_VFO); + can_emulate_by_vfo_op = rc->vfo_op + && rig_has_vfo_op(rig, RIG_OP_TO_VFO); - if (!can_emulate_by_vfo_mem && !can_emulate_by_vfo_op) { + if (!can_emulate_by_vfo_mem && !can_emulate_by_vfo_op) + { return -RIG_ENTARGET; } @@ -808,26 +897,32 @@ int HAMLIB_API rig_get_channel(RIG *rig, channel_t *chan) generic_save_channel(rig, &curr_chan); #endif - if (vfo == RIG_VFO_MEM) { + if (vfo == RIG_VFO_MEM) + { get_mem_status = rig_get_mem(rig, RIG_VFO_CURR, &curr_chan_num); } - if (can_emulate_by_vfo_mem && curr_vfo != vfo) { + if (can_emulate_by_vfo_mem && curr_vfo != vfo) + { retcode = rig_set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } } - if (vfo == RIG_VFO_MEM) { + if (vfo == RIG_VFO_MEM) + { rig_set_mem(rig, RIG_VFO_CURR, chan->channel_num); } - if (!can_emulate_by_vfo_mem && can_emulate_by_vfo_op) { + if (!can_emulate_by_vfo_mem && can_emulate_by_vfo_op) + { retcode = rig_vfo_op(rig, RIG_VFO_CURR, RIG_OP_TO_VFO); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } } @@ -835,11 +930,13 @@ int HAMLIB_API rig_get_channel(RIG *rig, channel_t *chan) retcode = generic_save_channel(rig, chan); /* restore current memory number */ - if (vfo == RIG_VFO_MEM && get_mem_status == RIG_OK) { + if (vfo == RIG_VFO_MEM && get_mem_status == RIG_OK) + { rig_set_mem(rig, RIG_VFO_CURR, curr_chan_num); } - if (can_emulate_by_vfo_mem) { + if (can_emulate_by_vfo_mem) + { rig_set_vfo(rig, curr_vfo); } @@ -857,7 +954,8 @@ int get_chan_all_cb_generic(RIG *rig, chan_cb_t chan_cb, rig_ptr_t arg) chan_t *chan_list = rig->state.chan_list; channel_t *chan; - for (i = 0; !RIG_IS_CHAN_END(chan_list[i]) && i < CHANLSTSIZ; i++) { + for (i = 0; !RIG_IS_CHAN_END(chan_list[i]) && i < CHANLSTSIZ; i++) + { /* * setting chan to NULL means the application @@ -867,15 +965,18 @@ int get_chan_all_cb_generic(RIG *rig, chan_cb_t chan_cb, rig_ptr_t arg) chan = NULL; retval = chan_cb(rig, &chan, chan_list[i].start, chan_list, arg); - if (retval != RIG_OK) { + if (retval != RIG_OK) + { return retval; } - if (chan == NULL) { + if (chan == NULL) + { return -RIG_ENOMEM; } - for (j = chan_list[i].start; j <= chan_list[i].end; j++) { + for (j = chan_list[i].start; j <= chan_list[i].end; j++) + { int chan_next; chan->vfo = RIG_VFO_MEM; @@ -886,7 +987,8 @@ int get_chan_all_cb_generic(RIG *rig, chan_cb_t chan_cb, rig_ptr_t arg) */ retval = rig_get_channel(rig, chan); - if (retval == -RIG_ENAVAIL) { + if (retval == -RIG_ENAVAIL) + { /* * empty channel * @@ -895,7 +997,8 @@ int get_chan_all_cb_generic(RIG *rig, chan_cb_t chan_cb, rig_ptr_t arg) continue; } - if (retval != RIG_OK) { + if (retval != RIG_OK) + { return retval; } @@ -915,16 +1018,19 @@ int set_chan_all_cb_generic(RIG *rig, chan_cb_t chan_cb, rig_ptr_t arg) chan_t *chan_list = rig->state.chan_list; channel_t *chan; - for (i = 0; !RIG_IS_CHAN_END(chan_list[i]) && i < CHANLSTSIZ; i++) { + for (i = 0; !RIG_IS_CHAN_END(chan_list[i]) && i < CHANLSTSIZ; i++) + { - for (j = chan_list[i].start; j <= chan_list[i].end; j++) { + for (j = chan_list[i].start; j <= chan_list[i].end; j++) + { chan_cb(rig, &chan, j, chan_list, arg); chan->vfo = RIG_VFO_MEM; retval = rig_set_channel(rig, chan); - if (retval != RIG_OK) { + if (retval != RIG_OK) + { return retval; } } @@ -934,7 +1040,8 @@ int set_chan_all_cb_generic(RIG *rig, chan_cb_t chan_cb, rig_ptr_t arg) } -struct map_all_s { +struct map_all_s +{ channel_t *chans; const struct confparams *cfgps; value_t *vals; @@ -984,13 +1091,15 @@ int HAMLIB_API rig_set_chan_all_cb(RIG *rig, chan_cb_t chan_cb, rig_ptr_t arg) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig) || !chan_cb) { + if (CHECK_RIG_ARG(rig) || !chan_cb) + { return -RIG_EINVAL; } rc = rig->caps; - if (rc->set_chan_all_cb) { + if (rc->set_chan_all_cb) + { return rc->set_chan_all_cb(rig, chan_cb, arg); } @@ -1028,13 +1137,15 @@ int HAMLIB_API rig_get_chan_all_cb(RIG *rig, chan_cb_t chan_cb, rig_ptr_t arg) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig) || !chan_cb) { + if (CHECK_RIG_ARG(rig) || !chan_cb) + { return -RIG_EINVAL; } rc = rig->caps; - if (rc->get_chan_all_cb) { + if (rc->get_chan_all_cb) + { return rc->get_chan_all_cb(rig, chan_cb, arg); } @@ -1067,14 +1178,16 @@ int HAMLIB_API rig_set_chan_all(RIG *rig, const channel_t chans[]) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig) || !chans) { + if (CHECK_RIG_ARG(rig) || !chans) + { return -RIG_EINVAL; } rc = rig->caps; map_arg.chans = (channel_t *) chans; - if (rc->set_chan_all_cb) { + if (rc->set_chan_all_cb) + { return rc->set_chan_all_cb(rig, map_chan, (rig_ptr_t)&map_arg); } @@ -1107,14 +1220,16 @@ int HAMLIB_API rig_get_chan_all(RIG *rig, channel_t chans[]) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig) || !chans) { + if (CHECK_RIG_ARG(rig) || !chans) + { return -RIG_EINVAL; } rc = rig->caps; map_arg.chans = chans; - if (rc->get_chan_all_cb) { + if (rc->get_chan_all_cb) + { return rc->get_chan_all_cb(rig, map_chan, (rig_ptr_t)&map_arg); } @@ -1140,8 +1255,9 @@ int HAMLIB_API rig_copy_channel(RIG *rig, /* TODO: ext_levels[] of different sizes */ for (i = 0; !RIG_IS_EXT_END(src->ext_levels[i]) - && !RIG_IS_EXT_END(dest->ext_levels[i]); i++) { - dest->ext_levels[i] = src->ext_levels[i]; + && !RIG_IS_EXT_END(dest->ext_levels[i]); i++) + { + dest->ext_levels[i] = src->ext_levels[i]; } saved_ext_levels = dest->ext_levels; @@ -1205,13 +1321,15 @@ int HAMLIB_API rig_set_mem_all_cb(RIG *rig, rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig) || !chan_cb) { + if (CHECK_RIG_ARG(rig) || !chan_cb) + { return -RIG_EINVAL; } rc = rig->caps; - if (rc->set_mem_all_cb) { + if (rc->set_mem_all_cb) + { return rc->set_mem_all_cb(rig, chan_cb, parm_cb, arg); } @@ -1219,14 +1337,16 @@ int HAMLIB_API rig_set_mem_all_cb(RIG *rig, /* if not available, emulate it */ retval = rig_set_chan_all_cb(rig, chan_cb, arg); - if (retval != RIG_OK) { + if (retval != RIG_OK) + { return retval; } #if 0 retval = rig_set_parm_all_cb(rig, parm_cb, arg); - if (retval != RIG_OK) { + if (retval != RIG_OK) + { return retval; } @@ -1268,27 +1388,31 @@ int HAMLIB_API rig_get_mem_all_cb(RIG *rig, rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig) || !chan_cb) { + if (CHECK_RIG_ARG(rig) || !chan_cb) + { return -RIG_EINVAL; } rc = rig->caps; - if (rc->get_mem_all_cb) { + if (rc->get_mem_all_cb) + { return rc->get_mem_all_cb(rig, chan_cb, parm_cb, arg); } /* if not available, emulate it */ retval = rig_get_chan_all_cb(rig, chan_cb, arg); - if (retval != RIG_OK) { + if (retval != RIG_OK) + { return retval; } #if 0 retval = rig_get_parm_cb(rig, parm_cb, arg); - if (retval != RIG_OK) { + if (retval != RIG_OK) + { return retval; } @@ -1330,7 +1454,8 @@ int HAMLIB_API rig_set_mem_all(RIG *rig, rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig) || !chans || !cfgps || !vals) { + if (CHECK_RIG_ARG(rig) || !chans || !cfgps || !vals) + { return -RIG_EINVAL; } @@ -1346,14 +1471,16 @@ int HAMLIB_API rig_set_mem_all(RIG *rig, /* if not available, emulate it */ retval = rig_set_chan_all(rig, chans); - if (retval != RIG_OK) { + if (retval != RIG_OK) + { return retval; } #if 0 retval = rig_set_parm_all(rig, parms); - if (retval != RIG_OK) { + if (retval != RIG_OK) + { return retval; } @@ -1394,7 +1521,8 @@ int HAMLIB_API rig_get_mem_all(RIG *rig, rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig) || !chans || !cfgps || !vals) { + if (CHECK_RIG_ARG(rig) || !chans || !cfgps || !vals) + { return -RIG_EINVAL; } @@ -1414,7 +1542,8 @@ int HAMLIB_API rig_get_mem_all(RIG *rig, */ retval = rig_get_chan_all(rig, chans); - if (retval != RIG_OK) { + if (retval != RIG_OK) + { return retval; } @@ -1447,17 +1576,20 @@ const chan_t *HAMLIB_API rig_lookup_mem_caps(RIG *rig, int ch) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig)) { + if (CHECK_RIG_ARG(rig)) + { return NULL; } - if (ch == RIG_MEM_CAPS_ALL) { + if (ch == RIG_MEM_CAPS_ALL) + { memset(&chan_list_all, 0, sizeof(chan_list_all)); chan_list = rig->state.chan_list; chan_list_all.start = chan_list[0].start; chan_list_all.type = RIG_MTYPE_NONE; /* meaningless */ - for (i = 0; i < CHANLSTSIZ && !RIG_IS_CHAN_END(chan_list[i]); i++) { + for (i = 0; i < CHANLSTSIZ && !RIG_IS_CHAN_END(chan_list[i]); i++) + { unsigned char *p1, *p2; p1 = (unsigned char *)&chan_list_all.mem_caps; @@ -1466,7 +1598,8 @@ const chan_t *HAMLIB_API rig_lookup_mem_caps(RIG *rig, int ch) /* It's kind of hackish, we just want to do update set with: * chan_list_all.mem_caps |= chan_list[i].mem_caps */ - for (j = 0; j < sizeof(channel_cap_t); j++) { + for (j = 0; j < sizeof(channel_cap_t); j++) + { p1[j] |= p2[j]; } @@ -1479,8 +1612,10 @@ const chan_t *HAMLIB_API rig_lookup_mem_caps(RIG *rig, int ch) chan_list = rig->state.chan_list; - for (i = 0; i < CHANLSTSIZ && !RIG_IS_CHAN_END(chan_list[i]); i++) { - if (ch >= chan_list[i].start && ch <= chan_list[i].end) { + for (i = 0; i < CHANLSTSIZ && !RIG_IS_CHAN_END(chan_list[i]); i++) + { + if (ch >= chan_list[i].start && ch <= chan_list[i].end) + { return &chan_list[i]; } } @@ -1504,14 +1639,16 @@ int HAMLIB_API rig_mem_count(RIG *rig) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig)) { + if (CHECK_RIG_ARG(rig)) + { return -RIG_EINVAL; } chan_list = rig->state.chan_list; count = 0; - for (i = 0; i < CHANLSTSIZ && !RIG_IS_CHAN_END(chan_list[i]); i++) { + for (i = 0; i < CHANLSTSIZ && !RIG_IS_CHAN_END(chan_list[i]); i++) + { count += chan_list[i].end - chan_list[i].start + 1; } diff --git a/src/microham.c b/src/microham.c index 05f46eaa4..b440a6d35 100644 --- a/src/microham.c +++ b/src/microham.c @@ -1,3 +1,24 @@ +/* + * Hamlib Interface - Microham device support for POSIX systems + * Copyright (c) 2017 by Christoph van Wüllen + * + * + * 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 + * + */ + // // This file contains the support for microHam devices // @@ -7,9 +28,9 @@ // #ifdef HAVE_CONFIG_H -# include "config.h" +# include "config.h" #endif - + #include #include #include @@ -19,15 +40,15 @@ #include #ifdef HAVE_ERRNO_H -#include +# include #endif #ifdef HAVE_SYS_SELECT_H -#include +# include #endif #ifdef HAVE_SYS_SOCKET_H -#include +# include #endif //#define FRAME(s, ...) printf(s, ##__VA_ARGS__) @@ -36,43 +57,47 @@ //#define MYERROR(s, ...) printf(s, ##__VA_ARGS__) #ifndef FRAME -#define FRAME(s, ...) +# define FRAME(s, ...) #endif + #ifndef DEBUG -#define DEBUG(s, ...) +# define DEBUG(s, ...) #endif + #ifndef TRACE -#define TRACE(s, ...) +# define TRACE(s, ...) #endif + #ifndef MYERROR -#define MYERROR(s, ...) +# define MYERROR(s, ...) #endif #ifndef PATH_MAX // should not happen, should be defined in limits.h // but better paranoia than a code that does not work -#define PATH_MAX 256 + #define PATH_MAX 256 #endif -static char uh_device_path[PATH_MAX]; // use PATH_MAX since udev names can be VERY long! -static int uh_device_fd=-1; -static int uh_is_initialized=0; +static char +uh_device_path[PATH_MAX]; // use PATH_MAX since udev names can be VERY long! +static int uh_device_fd = -1; +static int uh_is_initialized = 0; -static int uh_radio_pair[2] = {-1, -1}; -static int uh_ptt_pair[2] = {-1, -1}; -static int uh_wkey_pair[2] = {-1, -1}; +static int uh_radio_pair[2] = { -1, -1}; +static int uh_ptt_pair[2] = { -1, -1}; +static int uh_wkey_pair[2] = { -1, -1}; static int uh_radio_in_use; static int uh_ptt_in_use; static int uh_wkey_in_use; -static int statusbyte=0; +static int statusbyte = 0; #ifdef HAVE_PTHREAD #include -static pthread_mutex_t mutex=PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_t readthread; #define getlock() if (pthread_mutex_lock(&mutex)) perror("GETLOCK:") #define freelock() if (pthread_mutex_unlock(&mutex)) perror("FREELOCK:") @@ -84,56 +109,74 @@ static pthread_t readthread; // // time of last heartbeat. Updated by heartbeat() // -static time_t lastbeat=0; +static time_t lastbeat = 0; static time_t starttime; #define TIME ((int) (time(NULL) - starttime)) + // // close all sockets and mark them free // static void close_all_files() { - if (uh_radio_pair[0] >= 0) { + if (uh_radio_pair[0] >= 0) + { close(uh_radio_pair[0]); } - if (uh_radio_pair[1] >= 0) { + + if (uh_radio_pair[1] >= 0) + { close(uh_radio_pair[1]); } - if (uh_ptt_pair[0] >= 0) { + + if (uh_ptt_pair[0] >= 0) + { close(uh_ptt_pair[0]); } - if (uh_ptt_pair[1] >= 0) { + + if (uh_ptt_pair[1] >= 0) + { close(uh_ptt_pair[1]); } - if (uh_wkey_pair[0] >= 0) { + + if (uh_wkey_pair[0] >= 0) + { close(uh_wkey_pair[0]); } - if (uh_wkey_pair[1] >= 0) { + + if (uh_wkey_pair[1] >= 0) + { close(uh_wkey_pair[1]); } - uh_radio_pair[0]=-1; - uh_radio_pair[1]=-1; - uh_ptt_pair[0]=-1; - uh_ptt_pair[1]=-1; - uh_wkey_pair[0]=-1; - uh_wkey_pair[1]=-1; - uh_radio_in_use=0; - uh_ptt_in_use=0; - uh_wkey_in_use=0; + + uh_radio_pair[0] = -1; + uh_radio_pair[1] = -1; + uh_ptt_pair[0] = -1; + uh_ptt_pair[1] = -1; + uh_wkey_pair[0] = -1; + uh_wkey_pair[1] = -1; + uh_radio_in_use = 0; + uh_ptt_in_use = 0; + uh_wkey_in_use = 0; + // finally, close connection to microHam device - if (uh_device_fd >= 0) { + if (uh_device_fd >= 0) + { close(uh_device_fd); } } + static void close_microham() { - if (!uh_is_initialized) { + if (!uh_is_initialized) + { return; } - TRACE("%10d:Closing MicroHam device\n",TIME); - uh_is_initialized=0; + + TRACE("%10d:Closing MicroHam device\n", TIME); + uh_is_initialized = 0; #ifdef HAVE_PTHREAD // wait for read_device thread to finish pthread_join(readthread, NULL); @@ -141,13 +184,14 @@ static void close_microham() close_all_files(); } + #if defined(WIN32) || !defined(HAVE_GLOB_H) /* * On Windows, this is not really needed since we have uhrouter.exe * creating virtual COM ports * * I do now know how to "find" a microham device under Windows. - * + * * Therefore, a dummy version of finddevices() is included such that it compiles * well on WIN32. Since the dummy version does not find anything, no reading thread * and no sockets are created. @@ -164,6 +208,7 @@ static void close_microham() static void finddevices() { } + #else /* @@ -195,10 +240,12 @@ static void finddevices() */ #define NUMUHTYPES 8 -static struct uhtypes { +static struct uhtypes +{ const char *name; const char *device; -} uhtypes[NUMUHTYPES] = { +} uhtypes[NUMUHTYPES] = +{ #ifdef __APPLE__ { "microKeyer", "/dev/tty.usbserial-MK*"}, @@ -221,6 +268,7 @@ static struct uhtypes { #endif }; + // // Find a microHamDevice. Here we assume that the device special // file has a name from which we can tell this is a microHam device @@ -233,88 +281,104 @@ static void finddevices() { struct stat st; glob_t gbuf; - int i,j; + int i, j; struct termios TTY; int fd; - uh_device_fd= -1; // indicates "no device is found" + uh_device_fd = -1; // indicates "no device is found" // // Check ALL device special files that might be relevant, - // - for (i=0; i= PATH_MAX) { + if (strlen(gbuf.gl_pathv[j]) >= PATH_MAX) + { // I do not know if this can happen, but if it happens, we just skip the device. - MYERROR("Name too long: %s\n",gbuf.gl_pathv[j]); + MYERROR("Name too long: %s\n", gbuf.gl_pathv[j]); continue; } + DEBUG("%s is a character special file\n", gbuf.gl_pathv[j]); strcpy(uh_device_path, gbuf.gl_pathv[j]); - TRACE("Found a %s, Device=%s\n",uhtypes[i].name,uh_device_path); + TRACE("Found a %s, Device=%s\n", uhtypes[i].name, uh_device_path); - fd = open(uh_device_path, O_RDWR | O_NONBLOCK | O_NOCTTY); - if (fd < 0) { - MYERROR("Cannot open serial port %s\n",uh_device_path); - perror("Open:"); - continue; - } - tcflush(fd, TCIFLUSH); - if (tcgetattr( fd, &TTY)) { - MYERROR("Cannot get comm params\n"); - close(fd); - continue; - } - // microHam devices always use 230400 baud, 8N1, only TxD/RxD is used (no h/w handshake) - // 8 data bits - TTY.c_cflag &= ~CSIZE; - TTY.c_cflag |= CS8; - // enable receiver, set local mode - TTY.c_cflag |= (CLOCAL | CREAD); - // no parity - TTY.c_cflag &= ~PARENB; - // 1 stop bit - TTY.c_cflag &= ~CSTOPB; + fd = open(uh_device_path, O_RDWR | O_NONBLOCK | O_NOCTTY); - cfsetispeed(&TTY, B230400); - cfsetospeed(&TTY, B230400); + if (fd < 0) + { + MYERROR("Cannot open serial port %s\n", uh_device_path); + perror("Open:"); + continue; + } - // NO h/w handshake - // TTY.c_cflag &= ~CRTSCTS; - // raw input - TTY.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); - // raw output - TTY.c_oflag &= ~OPOST; - // software flow control disabled - // TTY.c_iflag &= ~IXON; - // do not translate CR to NL - // TTY.c_iflag &= ~ICRNL; + tcflush(fd, TCIFLUSH); - // timeouts - TTY.c_cc[VMIN]=0; - TTY.c_cc[VTIME]=255; + if (tcgetattr(fd, &TTY)) + { + MYERROR("Cannot get comm params\n"); + close(fd); + continue; + } - if (tcsetattr(fd, TCSANOW, &TTY)) { - MYERROR("Can't set device communication parameters"); - close (fd); - continue; - } + // microHam devices always use 230400 baud, 8N1, only TxD/RxD is used (no h/w handshake) + // 8 data bits + TTY.c_cflag &= ~CSIZE; + TTY.c_cflag |= CS8; + // enable receiver, set local mode + TTY.c_cflag |= (CLOCAL | CREAD); + // no parity + TTY.c_cflag &= ~PARENB; + // 1 stop bit + TTY.c_cflag &= ~CSTOPB; - TRACE("SerialPort opened: %s fd=%d\n",uh_device_path,fd); - uh_device_fd=fd; - // The first time we were successfull, we skip all what might come - return; + cfsetispeed(&TTY, B230400); + cfsetospeed(&TTY, B230400); + + // NO h/w handshake + // TTY.c_cflag &= ~CRTSCTS; + // raw input + TTY.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); + // raw output + TTY.c_oflag &= ~OPOST; + // software flow control disabled + // TTY.c_iflag &= ~IXON; + // do not translate CR to NL + // TTY.c_iflag &= ~ICRNL; + + // timeouts + TTY.c_cc[VMIN] = 0; + TTY.c_cc[VTIME] = 255; + + if (tcsetattr(fd, TCSANOW, &TTY)) + { + MYERROR("Can't set device communication parameters"); + close(fd); + continue; + } + + TRACE("SerialPort opened: %s fd=%d\n", uh_device_path, fd); + uh_device_fd = fd; + // The first time we were successfull, we skip all what might come + return; } } } } } + #endif // @@ -323,21 +387,25 @@ static void finddevices() // once a complete frame has been received // Send Radio and Winkey bytes received to the client sockets. // -static int frameseq=0; -static int incontrol=0; +static int frameseq = 0; +static int incontrol = 0; static unsigned char controlstring[256]; -static int numcontrolbytes=0; +static int numcontrolbytes = 0; static void parseFrame(unsigned char *frame) { int i; unsigned char byte; - FRAME("RCV frame %02x %02x %02x %02x\n",frame[0],frame[1],frame[2],frame[3]); + FRAME("RCV frame %02x %02x %02x %02x\n", frame[0], frame[1], frame[2], + frame[3]); // frames come in sequences. The first frame of a sequence has bit6 cleared in the headerbyte. - if ((frame[0] & 0x40) == 0) { - frameseq=0; - } else { + if ((frame[0] & 0x40) == 0) + { + frameseq = 0; + } + else + { frameseq++; } @@ -350,13 +418,19 @@ static void parseFrame(unsigned char *frame) // seq=3 -> PS2 // if RADIO byte is valid, send it to client - if ((frame[0] & 0x20) != 0) { - byte=frame[1] & 0x7F; - if ((frame[0] & 0x04) != 0) { + if ((frame[0] & 0x20) != 0) + { + byte = frame[1] & 0x7F; + + if ((frame[0] & 0x04) != 0) + { byte |= 0x80; } + DEBUG("%10d:FromRadio: %02x\n", TIME, byte); - if (write(uh_radio_pair[0], &byte, 1) != 1) { + + if (write(uh_radio_pair[0], &byte, 1) != 1) + { MYERROR("Write Radio Socket\n"); } } @@ -364,87 +438,118 @@ static void parseFrame(unsigned char *frame) // ignore AUX/RADIO2 for the time being // check the shared channel for validity, if it is the CONTROL channel it is always valid - if ((frame[0] & 0x08) || (frameseq == 1)) { - byte=frame[3] & 0x7F; - if (frame[0] & 0x01) { + if ((frame[0] & 0x08) || (frameseq == 1)) + { + byte = frame[3] & 0x7F; + + if (frame[0] & 0x01) + { byte |= 0x80; } - - switch (frameseq) { - case 0: // Flag byte - DEBUG("%10d:RCV: Flags=%02x\n", TIME, byte); - // No reason to pass the flags to clients + + switch (frameseq) + { + case 0: // Flag byte + DEBUG("%10d:RCV: Flags=%02x\n", TIME, byte); + // No reason to pass the flags to clients + break; + + case 1: // part of control string + if ((frame[0] & 0x08) == 0 && !incontrol) + { + // start or end of a control sequence + numcontrolbytes = 1; + controlstring[0] = byte; + incontrol = 1; break; - case 1: // part of control string - if ((frame[0] & 0x08) == 0 && !incontrol) { - // start or end of a control sequence - numcontrolbytes=1; - controlstring[0]=byte; - incontrol=1; - break; - } - if ((frame[0] & 0x08) == 0 && incontrol) { - // end of a control sequence - controlstring[numcontrolbytes++]=byte; - DEBUG("%10d:FromControl:",TIME); - for (i=0; i 5) { + + // + // This is the right place to ensure that a heartbeat is sent + // to the microham device regularly (15 sec delay is the maximum + // allowed, let us use 5 secs to be on the safe side). + // + if ((time(NULL) - lastbeat) > 5) + { heartbeat(); } - // - // Wait for something to arrive, either from the microham device - // or from the sockets used for I/O from hamlib. - // If nothing arrives within 100 msec, restart the "infinite loop". - // + + // + // Wait for something to arrive, either from the microham device + // or from the sockets used for I/O from hamlib. + // If nothing arrives within 100 msec, restart the "infinite loop". + // FD_ZERO(&fds); FD_SET(uh_device_fd, &fds); - FD_SET(uh_radio_pair[0], &fds); - FD_SET(uh_ptt_pair[0], &fds); - FD_SET(uh_wkey_pair[0], &fds); + FD_SET(uh_radio_pair[0], &fds); + FD_SET(uh_ptt_pair[0], &fds); + FD_SET(uh_wkey_pair[0], &fds); // determine max of these fd's for use in select() - maxdev=uh_device_fd; - if (uh_radio_pair[0] > maxdev) { - maxdev=uh_radio_pair[0]; - } - if (uh_ptt_pair[0] > maxdev) { - maxdev=uh_ptt_pair[0]; - } - if (uh_wkey_pair[0] > maxdev) { - maxdev=uh_wkey_pair[0]; + maxdev = uh_device_fd; + + if (uh_radio_pair[0] > maxdev) + { + maxdev = uh_radio_pair[0]; } - tv.tv_usec=100000; - tv.tv_sec=0; - ret=select(maxdev+1, &fds, NULL, NULL, &tv); - // - // select returned error, or nothing has arrived: + if (uh_ptt_pair[0] > maxdev) + { + maxdev = uh_ptt_pair[0]; + } + + if (uh_wkey_pair[0] > maxdev) + { + maxdev = uh_wkey_pair[0]; + } + + tv.tv_usec = 100000; + tv.tv_sec = 0; + ret = select(maxdev + 1, &fds, NULL, NULL, &tv); + + // + // select returned error, or nothing has arrived: // continue "infinite" loop. - // - if (ret <=0) { + // + if (ret <= 0) + { continue; } - // - // Take care of the incoming data (microham device, sockets) - // - if (FD_ISSET(uh_device_fd, &fds)) { - // compose frame, if it is complete, all parseFrame - while(read(uh_device_fd, buf, 1) > 0) { - if (!(buf[0] & 0x80) && framepos != 0) { + + // + // Take care of the incoming data (microham device, sockets) + // + if (FD_ISSET(uh_device_fd, &fds)) + { + // compose frame, if it is complete, all parseFrame + while (read(uh_device_fd, buf, 1) > 0) + { + if (!(buf[0] & 0x80) && framepos != 0) + { MYERROR("FrameSyncStartError\n"); - framepos=0; + framepos = 0; } - if ((buf[0] & 0x80) && framepos == 0) { + + if ((buf[0] & 0x80) && framepos == 0) + { MYERROR("FrameSyncStartError\n"); - framepos=0; + framepos = 0; continue; } - frame[framepos++]=buf[0]; - if (framepos >= 4) { - framepos=0; + + frame[framepos++] = buf[0]; + + if (framepos >= 4) + { + framepos = 0; parseFrame(frame); } } } - if (FD_ISSET(uh_ptt_pair[0], &fds)) { - // we do not expect any data here, but drain the socket - while(read(uh_ptt_pair[0], buf, 1) >0) { + + if (FD_ISSET(uh_ptt_pair[0], &fds)) + { + // we do not expect any data here, but drain the socket + while (read(uh_ptt_pair[0], buf, 1) > 0) + { // do nothing } - } - if (FD_ISSET(uh_radio_pair[0], &fds)) { - // read everything that is there, and send it to the radio - while(read(uh_radio_pair[0], buf, 1) >0) { + } + + if (FD_ISSET(uh_radio_pair[0], &fds)) + { + // read everything that is there, and send it to the radio + while (read(uh_radio_pair[0], buf, 1) > 0) + { writeRadio(buf, 1); } - } - if (FD_ISSET(uh_wkey_pair[0], &fds)) { - // read everything that is there, and send it to the WinKey chip - while(read(uh_wkey_pair[0], buf, 1) >0) { + } + + if (FD_ISSET(uh_wkey_pair[0], &fds)) + { + // read everything that is there, and send it to the WinKey chip + while (read(uh_wkey_pair[0], buf, 1) > 0) + { writeWkey(buf, 1); } - } + } } + #endif return NULL; } + /* * If we do not have pthreads, we cannot use the microham device. - * This is so because we have to digest unsolicited messages + * This is so because we have to digest unsolicited messages * (e.g. voltage change) and since we have to send periodic * heartbeats. * Nevertheless, the program should compile well even we we do not @@ -711,97 +893,140 @@ static void start_thread() unsigned char buf[4]; pthread_attr_t attr; - if (uh_is_initialized) { + if (uh_is_initialized) + { return; // PARANOIA: this should not happen } + finddevices(); - if (uh_device_fd < 0) { + + if (uh_device_fd < 0) + { MYERROR("Could not open any microHam device.\n"); return; } + // Create socket pairs - if (socketpair(AF_UNIX, SOCK_STREAM, 0, uh_radio_pair) < 0) { - perror("RadioPair:"); - return; + if (socketpair(AF_UNIX, SOCK_STREAM, 0, uh_radio_pair) < 0) + { + perror("RadioPair:"); + return; } - if (socketpair(AF_UNIX, SOCK_STREAM, 0, uh_ptt_pair) < 0) { + + if (socketpair(AF_UNIX, SOCK_STREAM, 0, uh_ptt_pair) < 0) + { perror("PTTPair:"); return; } - if (socketpair(AF_UNIX, SOCK_STREAM, 0, uh_wkey_pair) < 0) { + + if (socketpair(AF_UNIX, SOCK_STREAM, 0, uh_wkey_pair) < 0) + { perror("WkeyPair:"); return; } - DEBUG("RADIO sockets: server=%d client=%d\n", uh_radio_pair[0], uh_radio_pair[1]); + DEBUG("RADIO sockets: server=%d client=%d\n", uh_radio_pair[0], + uh_radio_pair[1]); DEBUG("PTT sockets: server=%d client=%d\n", uh_ptt_pair[0], uh_ptt_pair[1]); - DEBUG("WinKey sockets: server=%d client=%d\n", uh_wkey_pair[0], uh_wkey_pair[1]); + DEBUG("WinKey sockets: server=%d client=%d\n", uh_wkey_pair[0], + uh_wkey_pair[1]); // // Make the sockets nonblocking // First try if we can set flags, then do set the flags // - fail=0; + fail = 0; - ret=fcntl(uh_radio_pair[0], F_GETFL, 0); - if (ret != -1) { - ret=fcntl(uh_radio_pair[0], F_SETFL, ret | O_NONBLOCK); + ret = fcntl(uh_radio_pair[0], F_GETFL, 0); + + if (ret != -1) + { + ret = fcntl(uh_radio_pair[0], F_SETFL, ret | O_NONBLOCK); } - if (ret == -1) { - fail=1; + + if (ret == -1) + { + fail = 1; } - ret=fcntl(uh_ptt_pair[0], F_GETFL, 0); - if (ret != -1) { - ret=fcntl(uh_ptt_pair[0], F_SETFL, ret | O_NONBLOCK); + + ret = fcntl(uh_ptt_pair[0], F_GETFL, 0); + + if (ret != -1) + { + ret = fcntl(uh_ptt_pair[0], F_SETFL, ret | O_NONBLOCK); } - if (ret == -1) { - fail=1; + + if (ret == -1) + { + fail = 1; } - ret=fcntl(uh_wkey_pair[0], F_GETFL, 0); - if (ret != -1) { - ret=fcntl(uh_wkey_pair[0], F_SETFL, ret | O_NONBLOCK); + + ret = fcntl(uh_wkey_pair[0], F_GETFL, 0); + + if (ret != -1) + { + ret = fcntl(uh_wkey_pair[0], F_SETFL, ret | O_NONBLOCK); } - if (ret == -1) { - fail=1; + + if (ret == -1) + { + fail = 1; } - ret=fcntl(uh_radio_pair[1], F_GETFL, 0); - if (ret != -1) { - ret=fcntl(uh_radio_pair[1], F_SETFL, ret | O_NONBLOCK); + + ret = fcntl(uh_radio_pair[1], F_GETFL, 0); + + if (ret != -1) + { + ret = fcntl(uh_radio_pair[1], F_SETFL, ret | O_NONBLOCK); } - if (ret == -1) { - fail=1; + + if (ret == -1) + { + fail = 1; } - ret=fcntl(uh_ptt_pair[1], F_GETFL, 0); - if (ret != -1) { - ret=fcntl(uh_ptt_pair[1], F_SETFL, ret | O_NONBLOCK); + + ret = fcntl(uh_ptt_pair[1], F_GETFL, 0); + + if (ret != -1) + { + ret = fcntl(uh_ptt_pair[1], F_SETFL, ret | O_NONBLOCK); } - if (ret == -1) { - fail=1; + + if (ret == -1) + { + fail = 1; } - ret=fcntl(uh_wkey_pair[1], F_GETFL, 0); - if (ret != -1) { - ret=fcntl(uh_wkey_pair[1], F_SETFL, ret | O_NONBLOCK); + + ret = fcntl(uh_wkey_pair[1], F_GETFL, 0); + + if (ret != -1) + { + ret = fcntl(uh_wkey_pair[1], F_SETFL, ret | O_NONBLOCK); } - if (ret == -1) { - fail=1; + + if (ret == -1) + { + fail = 1; } // // If something went wrong, close everything and return // - if (fail) { - close_all_files(); - return; + if (fail) + { + close_all_files(); + return; } // drain input from microHam device - while(read(uh_device_fd, buf, 1) >0) { + while (read(uh_device_fd, buf, 1) > 0) + { // do_nothing } - uh_is_initialized=1; - starttime=time(NULL); + uh_is_initialized = 1; + starttime = time(NULL); // Do some heartbeats to sync-in heartbeat(); @@ -809,22 +1034,26 @@ static void start_thread() heartbeat(); // Set keyer mode to DIGITAL - buf[0]=0x0A; buf[1]=0x03; buf[2]=0x8a; writeControl(buf,3); + buf[0] = 0x0A; buf[1] = 0x03; buf[2] = 0x8a; writeControl(buf, 3); // Start background thread reading the microham device and the sockets pthread_attr_init(&attr); - ret=pthread_create(&readthread, &attr, read_device, NULL); - if (ret != 0) { - MYERROR("Could not start read_device thread\n"); - close_all_files(); - uh_is_initialized=0; - return; + ret = pthread_create(&readthread, &attr, read_device, NULL); + + if (ret != 0) + { + MYERROR("Could not start read_device thread\n"); + close_all_files(); + uh_is_initialized = 0; + return; } + TRACE("Started daemonized thread reading microHam\n"); #endif // if we do not have pthreads, this function does nothing. } + /* * What comes now are "public" functions that can be called from outside * @@ -836,7 +1065,7 @@ static void start_thread() * Note that it is not intended that any I/O is done via the PTT sockets * but hamlib needs a valid file descriptor! - * + * */ /* @@ -849,52 +1078,71 @@ static void start_thread() */ void uh_close_ptt() { - uh_ptt_in_use=0; - if (!uh_radio_in_use && ! uh_wkey_in_use) { + uh_ptt_in_use = 0; + + if (!uh_radio_in_use && ! uh_wkey_in_use) + { close_microham(); } } + void uh_close_radio() { - uh_radio_in_use=0; - if (!uh_ptt_in_use && ! uh_wkey_in_use) { + uh_radio_in_use = 0; + + if (!uh_ptt_in_use && ! uh_wkey_in_use) + { close_microham(); } } + void uh_close_wkey() { - uh_wkey_in_use=0; - if (!uh_ptt_in_use && ! uh_radio_in_use) { + uh_wkey_in_use = 0; + + if (!uh_ptt_in_use && ! uh_radio_in_use) + { close_microham(); } } + int uh_open_ptt() { - if (!uh_is_initialized) { + if (!uh_is_initialized) + { start_thread(); } - if (!uh_is_initialized) { + + if (!uh_is_initialized) + { return -1; } - uh_ptt_in_use=1; + + uh_ptt_in_use = 1; return uh_ptt_pair[1]; } + int uh_open_wkey() { - if (!uh_is_initialized) { + if (!uh_is_initialized) + { start_thread(); } - if (!uh_is_initialized) { + + if (!uh_is_initialized) + { return -1; } - uh_wkey_in_use=1; + + uh_wkey_in_use = 1; return uh_wkey_pair[1]; } + // // Number of stop bits must be 1 or 2. // Number of data bits can be 5,6,7,8 @@ -906,61 +1154,89 @@ int uh_open_radio(int baud, int databits, int stopbits, int rtscts) unsigned char string[5]; int baudrateConst; - if (!uh_is_initialized) { + if (!uh_is_initialized) + { start_thread(); } - if (!uh_is_initialized) { + + if (!uh_is_initialized) + { return -1; } - baudrateConst = 11059200/baud ; + baudrateConst = 11059200 / baud ; string[0] = 0x01; string[1] = baudrateConst & 0xff ; - string[2] = baudrateConst/256 ; - switch (stopbits) { - case 1: string[3]=0x00; break; - case 2: string[3]=0x40; break; - default: return -1; + string[2] = baudrateConst / 256 ; + + switch (stopbits) + { + case 1: string[3] = 0x00; break; + + case 2: string[3] = 0x40; break; + + default: return -1; } - if (rtscts) { + + if (rtscts) + { string[3] |= 0x10; } - switch (databits) { - case 5: break; - case 6: string[3] |= 0x20; break; - case 7: string[3] |= 0x40; break; - case 8: string[3] |= 0x60; break; - default: return -1; + + switch (databits) + { + case 5: break; + + case 6: string[3] |= 0x20; break; + + case 7: string[3] |= 0x40; break; + + case 8: string[3] |= 0x60; break; + + default: return -1; } + string[4] = 0x81; writeControl(string, 5); - uh_radio_in_use=1; + uh_radio_in_use = 1; return uh_radio_pair[1]; } + void uh_set_ptt(int ptt) { - if (!uh_ptt_in_use) { - MYERROR("%10d:SetPTT but not open\n", TIME); - return; + if (!uh_ptt_in_use) + { + MYERROR("%10d:SetPTT but not open\n", TIME); + return; } + DEBUG("%10d:SET PTT = %d\n", TIME, ptt); - if (ptt) { + + if (ptt) + { statusbyte |= 0x04; - } else { + } + else + { statusbyte &= ~0x04; } + writeFlags(); } + int uh_get_ptt() { // Possibly we can do better, but we just reflect // what we have done via uh_set_ptt. - if (statusbyte & 0x04) { + if (statusbyte & 0x04) + { return 1; - } else { + } + else + { return 0; } } diff --git a/src/microham.h b/src/microham.h index d6adbe70b..8438b9637 100644 --- a/src/microham.h +++ b/src/microham.h @@ -1,3 +1,24 @@ +/* + * Hamlib Interface - Microham device support for POSIX systems + * Copyright (c) 2017 by Christoph van Wüllen + * + * + * 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 + * + */ + // // declaration of functions implemented in microham.c // @@ -9,4 +30,3 @@ extern void uh_set_ptt(int ptt); extern int uh_get_ptt(); extern void uh_close_radio(); extern void uh_close_ptt(); - diff --git a/src/misc.c b/src/misc.c index b11da8cae..aa10a2696 100644 --- a/src/misc.c +++ b/src/misc.c @@ -29,7 +29,7 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +# include "config.h" #endif #include @@ -39,12 +39,15 @@ #include /* UNIX standard function definitions */ #include /* File control definitions */ #include /* Error number definitions */ + #ifdef HAVE_SYS_TYPES_H -#include +# include #endif + #ifdef HAVE_SYS_TIME_H -#include +# include #endif + #include #include @@ -70,11 +73,11 @@ * * Returns a pointer to (unsigned char *)bcd_data. * - * \sa to_bcd_be + * \sa to_bcd_be() */ -unsigned char *HAMLIB_API to_bcd(unsigned char bcd_data[], - unsigned long long freq, - unsigned bcd_len) +unsigned char * HAMLIB_API to_bcd(unsigned char bcd_data[], + unsigned long long freq, + unsigned bcd_len) { int i; unsigned char a; @@ -84,7 +87,8 @@ unsigned char *HAMLIB_API to_bcd(unsigned char bcd_data[], /* '450'/4-> 5,0;0,4 */ /* '450'/3-> 5,0;x,4 */ - for (i = 0; i < bcd_len / 2; i++) { + for (i = 0; i < bcd_len / 2; i++) + { a = freq % 10; freq /= 10; a |= (freq % 10) << 4; @@ -92,7 +96,8 @@ unsigned char *HAMLIB_API to_bcd(unsigned char bcd_data[], bcd_data[i] = a; } - if (bcd_len & 1) { + if (bcd_len & 1) + { bcd_data[i] &= 0xf0; bcd_data[i] |= freq % 10; /* NB: high nibble is left uncleared */ } @@ -116,7 +121,7 @@ unsigned char *HAMLIB_API to_bcd(unsigned char bcd_data[], * * Returns frequency in Hz an unsigned long long integer. * - * \sa from_bcd_be + * \sa from_bcd_be() */ unsigned long long HAMLIB_API from_bcd(const unsigned char bcd_data[], unsigned bcd_len) @@ -126,11 +131,13 @@ unsigned long long HAMLIB_API from_bcd(const unsigned char bcd_data[], rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (bcd_len & 1) { + if (bcd_len & 1) + { f = bcd_data[bcd_len / 2] & 0x0f; } - for (i = (bcd_len / 2) - 1; i >= 0; i--) { + for (i = (bcd_len / 2) - 1; i >= 0; i--) + { f *= 10; f += bcd_data[i] >> 4; f *= 10; @@ -151,11 +158,11 @@ unsigned long long HAMLIB_API from_bcd(const unsigned char bcd_data[], * Same as to_bcd, but in big-endian order * (e.g. byte order 12 34 56 78 90 for 1234567890 Hz) * - * \sa to_bcd + * \sa to_bcd() */ -unsigned char *HAMLIB_API to_bcd_be(unsigned char bcd_data[], - unsigned long long freq, - unsigned bcd_len) +unsigned char * HAMLIB_API to_bcd_be(unsigned char bcd_data[], + unsigned long long freq, + unsigned bcd_len) { int i; unsigned char a; @@ -165,14 +172,16 @@ unsigned char *HAMLIB_API to_bcd_be(unsigned char bcd_data[], rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (bcd_len & 1) { + if (bcd_len & 1) + { bcd_data[bcd_len / 2] &= 0x0f; bcd_data[bcd_len / 2] |= (freq % 10) << 4; /* NB: low nibble is left uncleared */ freq /= 10; } - for (i = (bcd_len / 2) - 1; i >= 0; i--) { + for (i = (bcd_len / 2) - 1; i >= 0; i--) + { a = freq % 10; freq /= 10; a |= (freq % 10) << 4; @@ -193,7 +202,7 @@ unsigned char *HAMLIB_API to_bcd_be(unsigned char bcd_data[], * Same as from_bcd, but in big-endian order * (e.g. byte order 12 34 56 78 90 for 1234567890 Hz) * - * \sa from_bcd + * \sa from_bcd() */ unsigned long long HAMLIB_API from_bcd_be(const unsigned char bcd_data[], unsigned bcd_len) @@ -203,14 +212,16 @@ unsigned long long HAMLIB_API from_bcd_be(const unsigned char bcd_data[], rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - for (i = 0; i < bcd_len / 2; i++) { + for (i = 0; i < bcd_len / 2; i++) + { f *= 10; f += bcd_data[i] >> 4; f *= 10; f += bcd_data[i] & 0x0f; } - if (bcd_len & 1) { + if (bcd_len & 1) + { f *= 10; f += bcd_data[bcd_len / 2] >> 4; } @@ -240,16 +251,23 @@ int HAMLIB_API sprintf_freq(char *str, freq_t freq) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (llabs(freq) >= GHz(1)) { + if (llabs(freq) >= GHz(1)) + { hz = "GHz"; f = (double)freq / GHz(1); - } else if (llabs(freq) >= MHz(1)) { + } + else if (llabs(freq) >= MHz(1)) + { hz = "MHz"; f = (double)freq / MHz(1); - } else if (llabs(freq) >= kHz(1)) { + } + else if (llabs(freq) >= kHz(1)) + { hz = "kHz"; f = (double)freq / kHz(1); - } else { + } + else + { hz = "Hz"; f = (double)freq; } @@ -267,7 +285,8 @@ const char * HAMLIB_API rig_strstatus(enum rig_status_e status) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - switch (status) { + switch (status) + { case RIG_STATUS_ALPHA: return "Alpha"; @@ -288,10 +307,12 @@ const char * HAMLIB_API rig_strstatus(enum rig_status_e status) } -static struct { +static struct +{ rmode_t mode; const char *str; -} mode_str[] = { +} mode_str[] = +{ { RIG_MODE_AM, "AM" }, { RIG_MODE_CW, "CW" }, { RIG_MODE_USB, "USB" }, @@ -330,9 +351,12 @@ rmode_t HAMLIB_API rig_parse_mode(const char *s) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); for (i = 0 ; mode_str[i].str[0] != '\0'; i++) - if (!strcmp(s, mode_str[i].str)) { + { + if (!strcmp(s, mode_str[i].str)) + { return mode_str[i].mode; } + } return RIG_MODE_NONE; } @@ -351,23 +375,29 @@ const char * HAMLIB_API rig_strrmode(rmode_t mode) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (mode == RIG_MODE_NONE) { + if (mode == RIG_MODE_NONE) + { return ""; } for (i = 0 ; mode_str[i].str[0] != '\0'; i++) - if (mode == mode_str[i].mode) { + { + if (mode == mode_str[i].mode) + { return mode_str[i].str; } + } return ""; } -static struct { +static struct +{ vfo_t vfo; const char *str; -} vfo_str[] = { +} vfo_str[] = +{ { RIG_VFO_A, "VFOA" }, { RIG_VFO_B, "VFOB" }, { RIG_VFO_C, "VFOC" }, @@ -396,9 +426,12 @@ vfo_t HAMLIB_API rig_parse_vfo(const char *s) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); for (i = 0 ; vfo_str[i].str[0] != '\0'; i++) - if (!strcmp(s, vfo_str[i].str)) { + { + if (!strcmp(s, vfo_str[i].str)) + { return vfo_str[i].vfo; } + } return RIG_VFO_NONE; } @@ -417,23 +450,29 @@ const char * HAMLIB_API rig_strvfo(vfo_t vfo) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (vfo == RIG_VFO_NONE) { + if (vfo == RIG_VFO_NONE) + { return ""; } for (i = 0 ; vfo_str[i].str[0] != '\0'; i++) - if (vfo == vfo_str[i].vfo) { + { + if (vfo == vfo_str[i].vfo) + { return vfo_str[i].str; } + } return ""; } -static struct { +static struct +{ setting_t func; const char *str; -} func_str[] = { +} func_str[] = +{ { RIG_FUNC_FAGC, "FAGC" }, { RIG_FUNC_NB, "NB" }, { RIG_FUNC_COMP, "COMP" }, @@ -475,7 +514,7 @@ static struct { * \param s input alpha string * \return RIG_FUNC_... * - * \sa rig_func_e + * \sa rig_func_e() */ setting_t HAMLIB_API rig_parse_func(const char *s) { @@ -484,9 +523,12 @@ setting_t HAMLIB_API rig_parse_func(const char *s) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); for (i = 0 ; func_str[i].str[0] != '\0'; i++) - if (!strcmp(s, func_str[i].str)) { + { + if (!strcmp(s, func_str[i].str)) + { return func_str[i].func; } + } return RIG_FUNC_NONE; } @@ -497,7 +539,7 @@ setting_t HAMLIB_API rig_parse_func(const char *s) * \param func RIG_FUNC_... * \return alpha string * - * \sa rig_func_e + * \sa rig_func_e() */ const char * HAMLIB_API rig_strfunc(setting_t func) { @@ -505,23 +547,29 @@ const char * HAMLIB_API rig_strfunc(setting_t func) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (func == RIG_FUNC_NONE) { + if (func == RIG_FUNC_NONE) + { return ""; } for (i = 0; func_str[i].str[0] != '\0'; i++) - if (func == func_str[i].func) { + { + if (func == func_str[i].func) + { return func_str[i].str; } + } return ""; } -static struct { +static struct +{ setting_t level; const char *str; -} level_str[] = { +} level_str[] = +{ { RIG_LEVEL_PREAMP, "PREAMP" }, { RIG_LEVEL_ATT, "ATT" }, { RIG_LEVEL_VOX, "VOX" }, @@ -562,7 +610,7 @@ static struct { * \param s input alpha string * \return RIG_LEVEL_... * - * \sa rig_level_e + * \sa rig_level_e() */ setting_t HAMLIB_API rig_parse_level(const char *s) { @@ -571,9 +619,12 @@ setting_t HAMLIB_API rig_parse_level(const char *s) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); for (i = 0 ; level_str[i].str[0] != '\0'; i++) - if (!strcmp(s, level_str[i].str)) { + { + if (!strcmp(s, level_str[i].str)) + { return level_str[i].level; } + } return RIG_LEVEL_NONE; } @@ -584,7 +635,7 @@ setting_t HAMLIB_API rig_parse_level(const char *s) * \param level RIG_LEVEL_... * \return alpha string * - * \sa rig_level_e + * \sa rig_level_e() */ const char * HAMLIB_API rig_strlevel(setting_t level) { @@ -592,23 +643,29 @@ const char * HAMLIB_API rig_strlevel(setting_t level) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (level == RIG_LEVEL_NONE) { + if (level == RIG_LEVEL_NONE) + { return ""; } for (i = 0; level_str[i].str[0] != '\0'; i++) - if (level == level_str[i].level) { + { + if (level == level_str[i].level) + { return level_str[i].str; } + } return ""; } -static struct { +static struct +{ setting_t parm; const char *str; -} parm_str[] = { +} parm_str[] = +{ { RIG_PARM_ANN, "ANN" }, { RIG_PARM_APO, "APO" }, { RIG_PARM_BACKLIGHT, "BACKLIGHT" }, @@ -625,7 +682,7 @@ static struct { * \param s input alpha string * \return RIG_PARM_... * - * \sa rig_parm_e + * \sa rig_parm_e() */ setting_t HAMLIB_API rig_parse_parm(const char *s) { @@ -634,9 +691,12 @@ setting_t HAMLIB_API rig_parse_parm(const char *s) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); for (i = 0 ; parm_str[i].str[0] != '\0'; i++) - if (!strcmp(s, parm_str[i].str)) { + { + if (!strcmp(s, parm_str[i].str)) + { return parm_str[i].parm; } + } return RIG_PARM_NONE; } @@ -647,7 +707,7 @@ setting_t HAMLIB_API rig_parse_parm(const char *s) * \param parm RIG_PARM_... * \return alpha string * - * \sa rig_parm_e + * \sa rig_parm_e() */ const char * HAMLIB_API rig_strparm(setting_t parm) { @@ -655,23 +715,29 @@ const char * HAMLIB_API rig_strparm(setting_t parm) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (parm == RIG_PARM_NONE) { + if (parm == RIG_PARM_NONE) + { return ""; } for (i = 0; parm_str[i].str[0] != '\0'; i++) - if (parm == parm_str[i].parm) { + { + if (parm == parm_str[i].parm) + { return parm_str[i].str; } + } return ""; } -static struct { +static struct +{ vfo_op_t vfo_op; const char *str; -} vfo_op_str[] = { +} vfo_op_str[] = +{ { RIG_OP_CPY, "CPY" }, { RIG_OP_XCHG, "XCHG" }, { RIG_OP_FROM_VFO, "FROM_VFO" }, @@ -694,7 +760,7 @@ static struct { * \param s alpha string * \return RIG_OP_... * - * \sa vfo_op_t + * \sa vfo_op_t() */ vfo_op_t HAMLIB_API rig_parse_vfo_op(const char *s) { @@ -703,9 +769,12 @@ vfo_op_t HAMLIB_API rig_parse_vfo_op(const char *s) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); for (i = 0 ; vfo_op_str[i].str[0] != '\0'; i++) - if (!strcmp(s, vfo_op_str[i].str)) { + { + if (!strcmp(s, vfo_op_str[i].str)) + { return vfo_op_str[i].vfo_op; } + } return RIG_OP_NONE; } @@ -716,7 +785,7 @@ vfo_op_t HAMLIB_API rig_parse_vfo_op(const char *s) * \param op RIG_OP_... * \return alpha string * - * \sa vfo_op_t + * \sa vfo_op_t() */ const char * HAMLIB_API rig_strvfop(vfo_op_t op) { @@ -724,23 +793,28 @@ const char * HAMLIB_API rig_strvfop(vfo_op_t op) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (op == RIG_OP_NONE) { + if (op == RIG_OP_NONE) + { return ""; } for (i = 0; vfo_op_str[i].str[0] != '\0'; i++) - if (op == vfo_op_str[i].vfo_op) { + { if (op == vfo_op_str[i].vfo_op) + { return vfo_op_str[i].str; } + } return ""; } -static struct { +static struct +{ scan_t rscan; const char *str; -} scan_str[] = { +} scan_str[] = +{ { RIG_SCAN_STOP, "STOP" }, { RIG_SCAN_MEM, "MEM" }, { RIG_SCAN_SLCT, "SLCT" }, @@ -759,7 +833,7 @@ static struct { * \param s alpha string * \return RIG_SCAN_... * - * \sa scan_t + * \sa scan_t() */ scan_t HAMLIB_API rig_parse_scan(const char *s) { @@ -767,8 +841,10 @@ scan_t HAMLIB_API rig_parse_scan(const char *s) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - for (i = 0 ; scan_str[i].str[0] != '\0'; i++) { - if (strcmp(s, scan_str[i].str) == 0) { + for (i = 0 ; scan_str[i].str[0] != '\0'; i++) + { + if (strcmp(s, scan_str[i].str) == 0) + { return scan_str[i].rscan; } } @@ -782,7 +858,7 @@ scan_t HAMLIB_API rig_parse_scan(const char *s) * \param rscan RIG_SCAN_... * \return alpha string * - * \sa scan_t + * \sa scan_t() */ const char * HAMLIB_API rig_strscan(scan_t rscan) { @@ -790,14 +866,17 @@ const char * HAMLIB_API rig_strscan(scan_t rscan) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (rscan == RIG_SCAN_NONE) { + if (rscan == RIG_SCAN_NONE) + { return ""; } for (i = 0; scan_str[i].str[0] != '\0'; i++) - if (rscan == scan_str[i].rscan) { + { if (rscan == scan_str[i].rscan) + { return scan_str[i].str; } + } return ""; } @@ -808,11 +887,12 @@ const char * HAMLIB_API rig_strscan(scan_t rscan) * \param shift RIG_RPT_SHIFT_?? * \return alpha character */ -const char * HAMLIB_API rig_strptrshift(rptr_shift_t shift) +const char *HAMLIB_API rig_strptrshift(rptr_shift_t shift) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - switch (shift) { + switch (shift) + { case RIG_RPT_SHIFT_MINUS: return "-"; @@ -836,20 +916,27 @@ rptr_shift_t HAMLIB_API rig_parse_rptr_shift(const char *s) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (strcmp(s, "+") == 0) { + if (strcmp(s, "+") == 0) + { return RIG_RPT_SHIFT_PLUS; - } else if (strcmp(s, "-") == 0) { + } + else if (strcmp(s, "-") == 0) + { return RIG_RPT_SHIFT_MINUS; - } else { + } + else + { return RIG_RPT_SHIFT_NONE; } } -static struct { +static struct +{ chan_type_t mtype; const char *str; -} mtype_str[] = { +} mtype_str[] = +{ { RIG_MTYPE_MEM, "MEM" }, { RIG_MTYPE_EDGE, "EDGE" }, { RIG_MTYPE_CALL, "CALL" }, @@ -866,7 +953,7 @@ static struct { * \param s alpha string * \return RIG_MTYPE_... * - * \sa chan_type_t + * \sa chan_type_t() */ chan_type_t HAMLIB_API rig_parse_mtype(const char *s) { @@ -874,8 +961,10 @@ chan_type_t HAMLIB_API rig_parse_mtype(const char *s) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - for (i = 0 ; mtype_str[i].str[0] != '\0'; i++) { - if (strcmp(s, mtype_str[i].str) == 0) { + for (i = 0 ; mtype_str[i].str[0] != '\0'; i++) + { + if (strcmp(s, mtype_str[i].str) == 0) + { return mtype_str[i].mtype; } } @@ -889,7 +978,7 @@ chan_type_t HAMLIB_API rig_parse_mtype(const char *s) * \param mtype RIG_MTYPE_... * \return alpha string * - * \sa chan_type_t + * \sa chan_type_t() */ const char * HAMLIB_API rig_strmtype(chan_type_t mtype) { @@ -897,14 +986,18 @@ const char * HAMLIB_API rig_strmtype(chan_type_t mtype) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (mtype == RIG_MTYPE_NONE) { + if (mtype == RIG_MTYPE_NONE) + { return ""; } for (i = 0; mtype_str[i].str[0] != '\0'; i++) - if (mtype == mtype_str[i].mtype) { + { + if (mtype == mtype_str[i].mtype) + { return mtype_str[i].str; } + } return ""; } @@ -934,7 +1027,8 @@ int HAMLIB_API rig_check_cache_timeout(const struct timeval *tv, int timeout) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (tv->tv_sec == 0 && tv->tv_usec == 0) { + if (tv->tv_sec == 0 && tv->tv_usec == 0) + { rig_debug(RIG_DEBUG_VERBOSE, "%s: forced cache timeout\n", __func__); @@ -945,13 +1039,16 @@ int HAMLIB_API rig_check_cache_timeout(const struct timeval *tv, int timeout) t = timediff(&curr, tv); - if (t < timeout) { + if (t < timeout) + { rig_debug(RIG_DEBUG_VERBOSE, "%s: using cache (%ld ms)\n", __func__, t); return 0; - } else { + } + else + { rig_debug(RIG_DEBUG_VERBOSE, "%s: cache timed out (%ld ms)\n", __func__, diff --git a/src/misc.h b/src/misc.h index 768feaac7..c8f853192 100644 --- a/src/misc.h +++ b/src/misc.h @@ -57,7 +57,8 @@ extern HAMLIB_EXPORT(unsigned char *) to_bcd(unsigned char bcd_data[], unsigned long long freq, unsigned bcd_len); -extern HAMLIB_EXPORT(unsigned long long) from_bcd(const unsigned char bcd_data[], +extern HAMLIB_EXPORT(unsigned long long) from_bcd(const unsigned char + bcd_data[], unsigned bcd_len); /* @@ -67,7 +68,8 @@ extern HAMLIB_EXPORT(unsigned char *) to_bcd_be(unsigned char bcd_data[], unsigned long long freq, unsigned bcd_len); -extern HAMLIB_EXPORT(unsigned long long) from_bcd_be(const unsigned char bcd_data[], +extern HAMLIB_EXPORT(unsigned long long) from_bcd_be(const unsigned char + bcd_data[], unsigned bcd_len); extern HAMLIB_EXPORT(int) sprintf_freq(char *str, freq_t); @@ -82,10 +84,11 @@ extern int no_restore_ai; /* needs config.h included beforehand in .c file */ #ifdef HAVE_INTTYPES_H -#include +# include #endif + #ifdef HAVE_SYS_TIME_H -#include +# include #endif extern HAMLIB_EXPORT(int) rig_check_cache_timeout(const struct timeval *tv, @@ -96,24 +99,24 @@ extern HAMLIB_EXPORT(void) rig_force_cache_timeout(struct timeval *tv); #ifdef PRId64 /** \brief printf(3) format to be used for long long (64bits) type */ -#define PRIll PRId64 +# define PRIll PRId64 #else -#ifdef FBSD4 -#define PRIll "qd" -#else -#define PRIll "lld" -#endif +# ifdef FBSD4 +# define PRIll "qd" +# else +# define PRIll "lld" +# endif #endif #ifdef SCNd64 /** \brief scanf(3) format to be used for long long (64bits) type */ -#define SCNll SCNd64 +# define SCNll SCNd64 #else -#ifdef FBSD4 -#define SCNll "qd" -#else -#define SCNll "lld" -#endif +# ifdef FBSD4 +# define SCNll "qd" +# else +# define SCNll "lld" +# endif #endif diff --git a/src/network.c b/src/network.c index f7e1faf34..e573dc9c9 100644 --- a/src/network.c +++ b/src/network.c @@ -32,7 +32,7 @@ /* #define WINVER 0x0501 */ #ifdef HAVE_CONFIG_H -#include "config.h" +# include "config.h" #endif #include @@ -45,24 +45,26 @@ #include #include - #ifdef HAVE_NETINET_IN_H -#include +# include #endif + #if HAVE_NETDB_H -#include +# include #endif + #ifdef HAVE_ARPA_INET_H -#include +# include #endif + #if defined (HAVE_SYS_SOCKET_H) && defined (HAVE_SYS_IOCTL_H) -#include -#include +# include +# include #elif HAVE_WS2TCPIP_H -#include -# if defined(HAVE_WSPIAPI_H) -# include -# endif +# include +# if defined(HAVE_WSPIAPI_H) +# include +# endif #endif #include @@ -88,15 +90,19 @@ static void handle_error(enum rig_debug_level_e lvl, const char *msg) if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, e, + NULL, + e, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language (LPTSTR)&lpMsgBuf, 0, - NULL)) { + NULL)) + { rig_debug(lvl, "%s: Network error %d: %s\n", msg, e, lpMsgBuf); LocalFree(lpMsgBuf); - } else { + } + else + { rig_debug(lvl, "%s: Network error %d\n", msg, e); } @@ -131,44 +137,56 @@ int network_open(hamlib_port_t *rp, int default_port) #ifdef __MINGW32__ WSADATA wsadata; - if (!(wsstarted++) && WSAStartup(MAKEWORD(1, 1), &wsadata) == SOCKET_ERROR) { + if (!(wsstarted++) && WSAStartup(MAKEWORD(1, 1), &wsadata) == SOCKET_ERROR) + { rig_debug(RIG_DEBUG_ERR, "%s: error creating socket\n", __func__); return -RIG_EIO; } #endif - if (!rp) { + if (!rp) + { return -RIG_EINVAL; } memset(&hints, 0, sizeof(hints)); hints.ai_family = PF_UNSPEC; - if (rp->type.rig == RIG_PORT_UDP_NETWORK) { + if (rp->type.rig == RIG_PORT_UDP_NETWORK) + { hints.ai_socktype = SOCK_DGRAM; - } else { + } + else + { hints.ai_socktype = SOCK_STREAM; } /* default of all local interfaces */ hoststr = NULL; - if (rp->pathname[0] == ':') { + if (rp->pathname[0] == ':') + { portstr = rp->pathname + 1; - } else { - if (strlen(rp->pathname)) { + } + else + { + if (strlen(rp->pathname)) + { strncpy(hostname, rp->pathname, FILPATHLEN - 1); hoststr = hostname; /* look for IPv6 numeric form [] */ bracketstr1 = strchr(hoststr, '['); bracketstr2 = strrchr(hoststr, ']'); - if (bracketstr1 && bracketstr2 && bracketstr2 > bracketstr1) { + if (bracketstr1 && bracketstr2 && bracketstr2 > bracketstr1) + { hoststr = bracketstr1 + 1; *bracketstr2 = '\0'; portstr = bracketstr2 + 1; /* possible port after ]: */ - } else { + } + else + { bracketstr2 = NULL; portstr = hoststr; /* possible port after : */ } @@ -176,12 +194,14 @@ int network_open(hamlib_port_t *rp, int default_port) /* search last ':' */ portstr = strrchr(portstr, ':'); - if (portstr) { + if (portstr) + { *portstr++ = '\0'; } } - if (!portstr) { + if (!portstr) + { sprintf(defaultportstr, "%d", default_port); portstr = defaultportstr; } @@ -189,7 +209,8 @@ int network_open(hamlib_port_t *rp, int default_port) status = getaddrinfo(hoststr, portstr, &hints, &res); - if (status != 0) { + if (status != 0) + { rig_debug(RIG_DEBUG_ERR, "%s: cannot get host \"%s\": %s\n", __func__, @@ -205,16 +226,19 @@ int network_open(hamlib_port_t *rp, int default_port) signal(SIGPIPE, SIG_IGN); #endif - do { + do + { fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol); - if (fd < 0) { + if (fd < 0) + { handle_error(RIG_DEBUG_ERR, "socket"); freeaddrinfo(saved_res); return -RIG_EIO; } - if ((status = connect(fd, res->ai_addr, res->ai_addrlen)) == 0) { + if ((status = connect(fd, res->ai_addr, res->ai_addrlen)) == 0) + { break; } @@ -225,11 +249,13 @@ int network_open(hamlib_port_t *rp, int default_port) #else close(fd); #endif - } while ((res = res->ai_next) != NULL); + } + while ((res = res->ai_next) != NULL); freeaddrinfo(saved_res); - if (NULL == res) { + if (NULL == res) + { rig_debug(RIG_DEBUG_ERR, "%s: failed to connect to %s\n", __func__, @@ -260,20 +286,24 @@ void network_flush(hamlib_port_t *rp) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - for (;;) { + for (;;) + { #ifdef __MINGW32__ ioctlsocket(rp->fd, FIONREAD, &len); #else ioctl(rp->fd, FIONREAD, &len); #endif - if (len > 0) { + if (len > 0) + { len = read(rp->fd, &buffer, len < NET_BUFFER_SIZE ? len : NET_BUFFER_SIZE); rig_debug(RIG_DEBUG_WARN, "%s: network data cleared: %s\n", __func__, buffer); - } else { + } + else + { break; } } @@ -289,7 +319,8 @@ int network_close(hamlib_port_t *rp) #ifdef __MINGW32__ ret = closesocket(rp->fd); - if (--wsstarted) { + if (--wsstarted) + { WSACleanup(); } diff --git a/src/par_nt.h b/src/par_nt.h index 8a96104e4..5338f7384 100644 --- a/src/par_nt.h +++ b/src/par_nt.h @@ -28,7 +28,8 @@ */ /* The status pin functions operate in terms of these bits: */ -enum ieee1284_status_bits { +enum ieee1284_status_bits +{ S1284_NFAULT = 0x08, S1284_SELECT = 0x10, S1284_PERROR = 0x20, @@ -39,7 +40,8 @@ enum ieee1284_status_bits { }; /* The control pin functions operate in terms of these bits: */ -enum ieee1284_control_bits { +enum ieee1284_control_bits +{ C1284_NSTROBE = 0x01, C1284_NAUTOFD = 0x02, C1284_NINIT = 0x04, diff --git a/src/parallel.c b/src/parallel.c index 4160333ca..ae98445e4 100644 --- a/src/parallel.c +++ b/src/parallel.c @@ -29,7 +29,7 @@ * \file parallel.c */ #ifdef HAVE_CONFIG_H -#include "config.h" +# include "config.h" #endif #include @@ -41,36 +41,39 @@ #include #include #include + #ifdef HAVE_SYS_IOCTL_H -#include +# include #endif #ifdef HAVE_SYS_PARAM_H -#include +# include #endif #ifdef HAVE_WINDOWS_H -#include -#include "par_nt.h" +# include +# include "par_nt.h" #endif + #ifdef HAVE_WINIOCTL_H -#include +# include #endif + #ifdef HAVE_WINBASE_H -#include +# include #endif #include #include "parallel.h" #ifdef HAVE_LINUX_PPDEV_H -#include -#include +# include +# include #endif #ifdef HAVE_DEV_PPBUS_PPI_H -#include -#include +# include +# include #endif /* @@ -135,7 +138,8 @@ int par_open(hamlib_port_t *port) HANDLE handle; #endif - if (!port->pathname[0]) { + if (!port->pathname[0]) + { return -RIG_EINVAL; } @@ -143,7 +147,8 @@ int par_open(hamlib_port_t *port) /* TODO: open with O_NONBLOCK ? */ fd = open(port->pathname, O_RDWR); - if (fd < 0) { + if (fd < 0) + { rig_debug(RIG_DEBUG_ERR, "%s: opening device \"%s\": %s\n", __func__, @@ -154,7 +159,8 @@ int par_open(hamlib_port_t *port) mode = IEEE1284_MODE_COMPAT; - if (ioctl(fd, PPSETMODE, &mode) != 0) { + if (ioctl(fd, PPSETMODE, &mode) != 0) + { rig_debug(RIG_DEBUG_ERR, "%s: PPSETMODE \"%s\": %s\n", __func__, port->pathname, @@ -167,7 +173,8 @@ int par_open(hamlib_port_t *port) fd = open(port->pathname, O_RDWR); - if (fd < 0) { + if (fd < 0) + { rig_debug(RIG_DEBUG_ERR, "%s: opening device \"%s\": %s\n", __func__, @@ -180,17 +187,21 @@ int par_open(hamlib_port_t *port) handle = CreateFile(port->pathname, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); - if (handle == INVALID_HANDLE_VALUE) { + if (handle == INVALID_HANDLE_VALUE) + { rig_debug(RIG_DEBUG_ERR, "%s: opening device \"%s\"\n", __func__, port->pathname); CloseHandle(handle); return -RIG_EIO; - } else { + } + else + { fd = _open_osfhandle((intptr_t)handle, _O_APPEND | _O_RDONLY); - if (fd == -1) { + if (fd == -1) + { return -RIG_EIO; } } @@ -246,9 +257,11 @@ int HAMLIB_API par_write_data(hamlib_port_t *port, unsigned char data) handle = _get_osfhandle(port->fd); - if (handle != (intptr_t)INVALID_HANDLE_VALUE) { + if (handle != (intptr_t)INVALID_HANDLE_VALUE) + { if (!(DeviceIoControl((HANDLE)handle, NT_IOCTL_DATA, &data, sizeof(data), - NULL, 0, (LPDWORD)&dummy, NULL))) { + NULL, 0, (LPDWORD)&dummy, NULL))) + { rig_debug(RIG_DEBUG_ERR, "%s: DeviceIoControl failed!\n", __func__); return -RIG_EIO; } @@ -286,10 +299,21 @@ int HAMLIB_API par_read_data(hamlib_port_t *port, unsigned char *data) handle = _get_osfhandle(port->fd); - if (handle != (intptr_t)INVALID_HANDLE_VALUE) { - if (!(DeviceIoControl((HANDLE)handle, NT_IOCTL_STATUS, NULL, 0, &ret, - sizeof(ret), (LPDWORD)&dummy, NULL))) { - rig_debug(RIG_DEBUG_ERR, "%s: DeviceIoControl failed!\n", __func__); + if (handle != (intptr_t)INVALID_HANDLE_VALUE) + { + if (!(DeviceIoControl((HANDLE)handle, + NT_IOCTL_STATUS, + NULL, + 0, + &ret, + sizeof(ret), + (LPDWORD)&dummy, + NULL))) + { + rig_debug(RIG_DEBUG_ERR, + "%s: DeviceIoControl failed!\n", + __func__); + return -RIG_EIO; } } @@ -316,7 +340,8 @@ int HAMLIB_API par_write_control(hamlib_port_t *port, unsigned char control) unsigned char ctrl = control ^ CP_ACTIVE_LOW_BITS; status = ioctl(port->fd, PPWCONTROL, &ctrl); - if (status < 0) { + if (status < 0) + { rig_debug(RIG_DEBUG_ERR, "%s: ioctl(PPWCONTROL) failed: %s\n", __func__, @@ -339,10 +364,11 @@ int HAMLIB_API par_write_control(hamlib_port_t *port, unsigned char control) | C1284_NSELECTIN); intptr_t handle; - if (ctr & 0x20) { + if (ctr & 0x20) + { rig_debug(RIG_DEBUG_WARN, "%s: use ieee1284_data_dir to change data line direction!\n", - __func__); + __func__); } /* Deal with inversion issues. */ @@ -351,7 +377,8 @@ int HAMLIB_API par_write_control(hamlib_port_t *port, unsigned char control) handle = _get_osfhandle(port->fd); - if (handle != (intptr_t)INVALID_HANDLE_VALUE) { + if (handle != (intptr_t)INVALID_HANDLE_VALUE) + { if (!(DeviceIoControl((HANDLE)handle, NT_IOCTL_CONTROL, &ctr, @@ -359,10 +386,11 @@ int HAMLIB_API par_write_control(hamlib_port_t *port, unsigned char control) &dummyc, sizeof(dummyc), (LPDWORD)&dummy, - NULL))) { + NULL))) + { rig_debug(RIG_DEBUG_ERR, "%s: frob_control: DeviceIoControl failed!\n", - __func__); + __func__); return -RIG_EIO; } } @@ -388,7 +416,8 @@ int HAMLIB_API par_read_control(hamlib_port_t *port, unsigned char *control) unsigned char ctrl; status = ioctl(port->fd, PPRCONTROL, &ctrl); - if (status < 0) { + if (status < 0) + { rig_debug(RIG_DEBUG_ERR, "%s: ioctl(PPRCONTROL) failed: %s\n", __func__, @@ -411,10 +440,21 @@ int HAMLIB_API par_read_control(hamlib_port_t *port, unsigned char *control) handle = _get_osfhandle(port->fd); - if (handle != (intptr_t)INVALID_HANDLE_VALUE) { - if (!(DeviceIoControl((HANDLE)handle, NT_IOCTL_CONTROL, NULL, 0, &ret, - sizeof(ret), (LPDWORD)&dummy, NULL))) { - rig_debug(RIG_DEBUG_ERR, "%s: DeviceIoControl failed!\n", __func__); + if (handle != (intptr_t)INVALID_HANDLE_VALUE) + { + if (!(DeviceIoControl((HANDLE)handle, + NT_IOCTL_CONTROL, + NULL, + 0, + &ret, + sizeof(ret), + (LPDWORD)&dummy, + NULL))) + { + rig_debug(RIG_DEBUG_ERR, + "%s: DeviceIoControl failed!\n", + __func__); + return -RIG_EIO; } } @@ -441,15 +481,19 @@ int HAMLIB_API par_read_status(hamlib_port_t *port, unsigned char *status) #ifdef HAVE_LINUX_PPDEV_H int ret; unsigned char sta; + ret = ioctl(port->fd, PPRSTATUS, &sta); *status = sta ^ SP_ACTIVE_LOW_BITS; return ret == 0 ? RIG_OK : -RIG_EIO; + #elif defined(HAVE_DEV_PPBUS_PPI_H) int ret; unsigned char sta; + ret = ioctl(port->fd, PPIGSTATUS, &sta); *status = sta ^ SP_ACTIVE_LOW_BITS; return ret == 0 ? RIG_OK : -RIG_EIO; + #elif defined(__WIN64__) || defined(__WIN32__) unsigned char ret; unsigned int dummy; @@ -458,10 +502,21 @@ int HAMLIB_API par_read_status(hamlib_port_t *port, unsigned char *status) handle = _get_osfhandle(port->fd); - if (handle != (intptr_t)INVALID_HANDLE_VALUE) { - if (!(DeviceIoControl((HANDLE)handle, NT_IOCTL_STATUS, NULL, 0, &ret, - sizeof(ret), (LPDWORD)&dummy, NULL))) { - rig_debug(RIG_DEBUG_ERR, "%s: DeviceIoControl failed!\n", __func__); + if (handle != (intptr_t)INVALID_HANDLE_VALUE) + { + if (!(DeviceIoControl((HANDLE)handle, + NT_IOCTL_STATUS, + NULL, + 0, + &ret, + sizeof(ret), + (LPDWORD)&dummy, + NULL))) + { + rig_debug(RIG_DEBUG_ERR, + "%s: DeviceIoControl failed!\n", + __func__); + return -RIG_EIO; } } @@ -486,7 +541,8 @@ int HAMLIB_API par_lock(hamlib_port_t *port) #ifdef HAVE_LINUX_PPDEV_H - if (ioctl(port->fd, PPCLAIM) < 0) { + if (ioctl(port->fd, PPCLAIM) < 0) + { rig_debug(RIG_DEBUG_ERR, "%s: claiming device \"%s\": %s\n", __func__, @@ -517,7 +573,8 @@ int HAMLIB_API par_unlock(hamlib_port_t *port) #ifdef HAVE_LINUX_PPDEV_H - if (ioctl(port->fd, PPRELEASE) < 0) { + if (ioctl(port->fd, PPRELEASE) < 0) + { rig_debug(RIG_DEBUG_ERR, "%s: releasing device \"%s\": %s\n", __func__, @@ -538,10 +595,11 @@ int HAMLIB_API par_unlock(hamlib_port_t *port) #ifndef PARPORT_CONTROL_STROBE -#define PARPORT_CONTROL_STROBE 0x1 +# define PARPORT_CONTROL_STROBE 0x1 #endif + #ifndef PARPORT_CONTROL_INIT -#define PARPORT_CONTROL_INIT 0x4 +# define PARPORT_CONTROL_INIT 0x4 #endif @@ -555,15 +613,18 @@ int par_ptt_set(hamlib_port_t *p, ptt_t pttx) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - switch (p->type.ptt) { - case RIG_PTT_PARALLEL: { + switch (p->type.ptt) + { + case RIG_PTT_PARALLEL: + { unsigned char ctl; int status; par_lock(p); status = par_read_control(p, &ctl); - if (status != RIG_OK) { + if (status != RIG_OK) + { return status; } @@ -573,9 +634,12 @@ int par_ptt_set(hamlib_port_t *p, ptt_t pttx) /* TODO: kill parm.parallel.pin? */ /* PTT keying - /INIT bit (pin 16) (inverted) */ - if (pttx == RIG_PTT_ON) { + if (pttx == RIG_PTT_ON) + { ctl |= PARPORT_CONTROL_INIT; - } else { + } + else + { ctl &= ~PARPORT_CONTROL_INIT; } @@ -606,8 +670,10 @@ int par_ptt_get(hamlib_port_t *p, ptt_t *pttx) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - switch (p->type.ptt) { - case RIG_PTT_PARALLEL: { + switch (p->type.ptt) + { + case RIG_PTT_PARALLEL: + { unsigned char ctl; int status; @@ -643,8 +709,10 @@ int par_dcd_get(hamlib_port_t *p, dcd_t *dcdx) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - switch (p->type.dcd) { - case RIG_DCD_PARALLEL: { + switch (p->type.dcd) + { + case RIG_DCD_PARALLEL: + { unsigned char reg; int status; diff --git a/src/parallel.h b/src/parallel.h index 0bf6cba31..c676ee439 100644 --- a/src/parallel.h +++ b/src/parallel.h @@ -27,36 +27,43 @@ #include "iofunc.h" #ifdef HAVE_LINUX_PARPORT_H -#include +# include #endif #ifndef PARPORT_CONTROL_STROBE -#define PARPORT_CONTROL_STROBE 0x1 +# define PARPORT_CONTROL_STROBE 0x1 #endif + #ifndef PARPORT_CONTROL_AUTOFD -#define PARPORT_CONTROL_AUTOFD 0x2 +# define PARPORT_CONTROL_AUTOFD 0x2 #endif + #ifndef PARPORT_CONTROL_INIT -#define PARPORT_CONTROL_INIT 0x4 +# define PARPORT_CONTROL_INIT 0x4 #endif + #ifndef PARPORT_CONTROL_SELECT -#define PARPORT_CONTROL_SELECT 0x8 +# define PARPORT_CONTROL_SELECT 0x8 #endif #ifndef PARPORT_STATUS_ERROR -#define PARPORT_STATUS_ERROR 0x8 +# define PARPORT_STATUS_ERROR 0x8 #endif + #ifndef PARPORT_STATUS_SELECT -#define PARPORT_STATUS_SELECT 0x10 +# define PARPORT_STATUS_SELECT 0x10 #endif + #ifndef PARPORT_STATUS_PAPEROUT -#define PARPORT_STATUS_PAPEROUT 0x20 +# define PARPORT_STATUS_PAPEROUT 0x20 #endif + #ifndef PARPORT_STATUS_ACK -#define PARPORT_STATUS_ACK 0x40 +# define PARPORT_STATUS_ACK 0x40 #endif + #ifndef PARPORT_STATUS_BUSY -#define PARPORT_STATUS_BUSY 0x80 +# define PARPORT_STATUS_BUSY 0x80 #endif __BEGIN_DECLS diff --git a/src/register.c b/src/register.c index 6c502697c..226268b0d 100644 --- a/src/register.c +++ b/src/register.c @@ -27,7 +27,7 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +# include "config.h" #endif #include @@ -42,7 +42,7 @@ #include #ifndef PATH_MAX -# define PATH_MAX 1024 +# define PATH_MAX 1024 #endif #define RIG_BACKEND_MAX 32 @@ -93,19 +93,22 @@ DEFINE_INITRIG_BACKEND(winradio); #endif -/*! \def rig_backend_list +/** + * \def rig_backend_list * \brief Static list of rig models. * - * This is a NULL terminated list of available rig backends. Each entry - * in the list consists of two fields: The branch number, which is an integer, + * This is a NULL terminated list of available rig backends. Each entry in + * the list consists of two fields: The branch number, which is an integer, * and the branch name, which is a character string. */ -static struct { +static struct +{ int be_num; const char *be_name; int (* be_init_all)(void *handle); rig_model_t (* be_probe_all)(hamlib_port_t *, rig_probe_func_t, rig_ptr_t); -} rig_backend_list[RIG_BACKEND_MAX] = { +} rig_backend_list[RIG_BACKEND_MAX] = +{ { RIG_DUMMY, RIG_BACKEND_DUMMY, RIG_FUNCNAMA(dummy) }, { RIG_YAESU, RIG_BACKEND_YAESU, RIG_FUNCNAM(yaesu) }, { RIG_KENWOOD, RIG_BACKEND_KENWOOD, RIG_FUNCNAM(kenwood) }, @@ -144,7 +147,8 @@ static struct { * This struct to keep track of known rig models. * It is chained, and used in a hash table, see below. */ -struct rig_list { +struct rig_list +{ const struct rig_caps *caps; struct rig_list *next; }; @@ -174,7 +178,8 @@ int HAMLIB_API rig_register(const struct rig_caps *caps) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!caps) { + if (!caps) + { return -RIG_EINVAL; } @@ -185,7 +190,8 @@ int HAMLIB_API rig_register(const struct rig_caps *caps) #ifndef DONT_WANT_DUP_CHECK - if (rig_get_caps(caps->rig_model) != NULL) { + if (rig_get_caps(caps->rig_model) != NULL) + { return -RIG_EINVAL; } @@ -193,7 +199,8 @@ int HAMLIB_API rig_register(const struct rig_caps *caps) p = (struct rig_list *)malloc(sizeof(struct rig_list)); - if (!p) { + if (!p) + { return -RIG_ENOMEM; } @@ -211,12 +218,14 @@ int HAMLIB_API rig_register(const struct rig_caps *caps) * ie. rig_hash_table lookup */ -const struct rig_caps *HAMLIB_API rig_get_caps(rig_model_t rig_model) +const struct rig_caps * HAMLIB_API rig_get_caps(rig_model_t rig_model) { struct rig_list *p; - for (p = rig_hash_table[HASH_FUNC(rig_model)]; p; p = p->next) { - if (p->caps->rig_model == rig_model) { + for (p = rig_hash_table[HASH_FUNC(rig_model)]; p; p = p->next) + { + if (p->caps->rig_model == rig_model) + { return p->caps; } } @@ -233,9 +242,11 @@ static int rig_lookup_backend(rig_model_t rig_model) { int i; - for (i = 0; i < RIG_BACKEND_MAX && rig_backend_list[i].be_name; i++) { + for (i = 0; i < RIG_BACKEND_MAX && rig_backend_list[i].be_name; i++) + { if (RIG_BACKEND_NUM(rig_model) == - rig_backend_list[i].be_num) { + rig_backend_list[i].be_num) + { return i; } } @@ -258,7 +269,8 @@ int HAMLIB_API rig_check_backend(rig_model_t rig_model) /* already loaded ? */ caps = rig_get_caps(rig_model); - if (caps) { + if (caps) + { return RIG_OK; } @@ -267,10 +279,12 @@ int HAMLIB_API rig_check_backend(rig_model_t rig_model) /* * Never heard about this backend family! */ - if (be_idx == -1) { - rig_debug(RIG_DEBUG_VERBOSE, "rig_check_backend: unsupported " - "backend %d for model %d\n", - RIG_BACKEND_NUM(rig_model), rig_model); + if (be_idx == -1) + { + rig_debug(RIG_DEBUG_VERBOSE, + "rig_check_backend: unsupported backend %d for model %d\n", + RIG_BACKEND_NUM(rig_model), + rig_model); return -RIG_ENAVAIL; } @@ -289,11 +303,16 @@ int HAMLIB_API rig_unregister(rig_model_t rig_model) hval = HASH_FUNC(rig_model); q = NULL; - for (p = rig_hash_table[hval]; p; p = p->next) { - if (p->caps->rig_model == rig_model) { - if (q == NULL) { + for (p = rig_hash_table[hval]; p; p = p->next) + { + if (p->caps->rig_model == rig_model) + { + if (q == NULL) + { rig_hash_table[hval] = p->next; - } else { + } + else + { q->next = p->next; } @@ -312,22 +331,27 @@ int HAMLIB_API rig_unregister(rig_model_t rig_model) * executes cfunc on all the elements stored in the rig hash list */ int HAMLIB_API rig_list_foreach(int (*cfunc)(const struct rig_caps *, - rig_ptr_t), rig_ptr_t data) + rig_ptr_t), + rig_ptr_t data) { struct rig_list *p; int i; - if (!cfunc) { + if (!cfunc) + { return -RIG_EINVAL; } - for (i = 0; i < RIGLSTHASHSZ; i++) { + for (i = 0; i < RIGLSTHASHSZ; i++) + { struct rig_list *next = NULL; - for (p = rig_hash_table[i]; p; p = next) { + for (p = rig_hash_table[i]; p; p = next) + { next = p->next; /* read before call in case it is unregistered */ - if ((*cfunc)(p->caps, data) == 0) { + if ((*cfunc)(p->caps, data) == 0) + { return RIG_OK; } } @@ -336,13 +360,17 @@ int HAMLIB_API rig_list_foreach(int (*cfunc)(const struct rig_caps *, return RIG_OK; } -static int dummy_rig_probe(const hamlib_port_t *p, rig_model_t model, + +static int dummy_rig_probe(const hamlib_port_t *p, + rig_model_t model, rig_ptr_t data) { rig_debug(RIG_DEBUG_TRACE, "Found rig, model %d\n", model); + return RIG_OK; } + /* * rig_probe_first * called straight by rig_probe @@ -352,13 +380,16 @@ rig_model_t rig_probe_first(hamlib_port_t *p) int i; rig_model_t model; - for (i = 0; i < RIG_BACKEND_MAX && rig_backend_list[i].be_name; i++) { - if (rig_backend_list[i].be_probe_all) { + for (i = 0; i < RIG_BACKEND_MAX && rig_backend_list[i].be_name; i++) + { + if (rig_backend_list[i].be_probe_all) + { model = (*rig_backend_list[i].be_probe_all)(p, dummy_rig_probe, (rig_ptr_t)NULL); /* stop at first one found */ - if (model != RIG_MODEL_NONE) { + if (model != RIG_MODEL_NONE) + { return model; } } @@ -367,17 +398,21 @@ rig_model_t rig_probe_first(hamlib_port_t *p) return RIG_MODEL_NONE; } + /* * rig_probe_all_backends * called straight by rig_probe_all */ -int rig_probe_all_backends(hamlib_port_t *p, rig_probe_func_t cfunc, +int rig_probe_all_backends(hamlib_port_t *p, + rig_probe_func_t cfunc, rig_ptr_t data) { int i; - for (i = 0; i < RIG_BACKEND_MAX && rig_backend_list[i].be_name; i++) { - if (rig_backend_list[i].be_probe_all) { + for (i = 0; i < RIG_BACKEND_MAX && rig_backend_list[i].be_name; i++) + { + if (rig_backend_list[i].be_probe_all) + { (*rig_backend_list[i].be_probe_all)(p, cfunc, data); } } @@ -390,7 +425,8 @@ int rig_load_all_backends() { int i; - for (i = 0; i < RIG_BACKEND_MAX && rig_backend_list[i].be_name; i++) { + for (i = 0; i < RIG_BACKEND_MAX && rig_backend_list[i].be_name; i++) + { rig_load_backend(rig_backend_list[i].be_name); } @@ -400,6 +436,7 @@ int rig_load_all_backends() typedef int (*backend_init_t)(rig_ptr_t); + /* * rig_load_backend */ @@ -408,13 +445,18 @@ int HAMLIB_API rig_load_backend(const char *be_name) int i; backend_init_t be_init; - for (i = 0; i < RIG_BACKEND_MAX && rig_backend_list[i].be_name; i++) { - if (!strcmp(be_name, rig_backend_list[i].be_name)) { + for (i = 0; i < RIG_BACKEND_MAX && rig_backend_list[i].be_name; i++) + { + if (!strcmp(be_name, rig_backend_list[i].be_name)) + { be_init = rig_backend_list[i].be_init_all ; - if (be_init) { + if (be_init) + { return (*be_init)(NULL); - } else { + } + else + { return -RIG_EINVAL; } } diff --git a/src/rig.c b/src/rig.c index 2afcb377e..7f6bfd1e8 100644 --- a/src/rig.c +++ b/src/rig.c @@ -37,7 +37,8 @@ * the physical rig. */ -/*! \page rig Rig (radio) interface +/** + * \page rig Rig (radio) interface * * For us, a "rig" is an item of general remote controllable radio equipment. * Generally, there are a VFO settings, gain controls, etc. @@ -48,7 +49,7 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +# include "config.h" #endif #include @@ -71,6 +72,7 @@ /** * \brief Hamlib release number + * * The version number has the format x.y.z */ /* @@ -100,39 +102,39 @@ const char hamlib_copyright[231] = /* hamlib 1.2 ABI specifies 231 bytes */ #ifndef DOC_HIDDEN #if defined(WIN32) && !defined(__CYGWIN__) -# define DEFAULT_SERIAL_PORT "\\\\.\\COM1" +# define DEFAULT_SERIAL_PORT "\\\\.\\COM1" #elif BSD -# define DEFAULT_SERIAL_PORT "/dev/cuaa0" +# define DEFAULT_SERIAL_PORT "/dev/cuaa0" #elif MACOSX -# define DEFAULT_SERIAL_PORT "/dev/cu.usbserial" +# define DEFAULT_SERIAL_PORT "/dev/cu.usbserial" #else -# define DEFAULT_SERIAL_PORT "/dev/ttyS0" +# define DEFAULT_SERIAL_PORT "/dev/ttyS0" #endif #if defined(WIN32) -# define DEFAULT_PARALLEL_PORT "\\\\.\\$VDMLPT1" +# define DEFAULT_PARALLEL_PORT "\\\\.\\$VDMLPT1" #elif defined(HAVE_DEV_PPBUS_PPI_H) -# define DEFAULT_PARALLEL_PORT "/dev/ppi0" +# define DEFAULT_PARALLEL_PORT "/dev/ppi0" #else -# define DEFAULT_PARALLEL_PORT "/dev/parport0" +# define DEFAULT_PARALLEL_PORT "/dev/parport0" #endif #if defined(WIN32) && !defined(__CYGWIN__) -# define DEFAULT_CM108_PORT "fixme" +# define DEFAULT_CM108_PORT "fixme" #elif BSD -# define DEFAULT_CM108_PORT "fixme" +# define DEFAULT_CM108_PORT "fixme" #else -# define DEFAULT_CM108_PORT "/dev/hidraw0" +# define DEFAULT_CM108_PORT "/dev/hidraw0" #endif #if defined(WIN32) && !defined(__CYGWIN__) /* FIXME: Determine correct GPIO bit number for W32 using MinGW. */ -# define DEFAULT_CM108_PTT_BITNUM 2 +# define DEFAULT_CM108_PTT_BITNUM 2 #elif BSD /* FIXME: Determine correct GPIO bit number for *BSD. */ -# define DEFAULT_CM108_PTT_BITNUM 2 +# define DEFAULT_CM108_PTT_BITNUM 2 #else -# define DEFAULT_CM108_PTT_BITNUM 2 +# define DEFAULT_CM108_PTT_BITNUM 2 #endif #define DEFAULT_GPIO_PORT "0" @@ -143,7 +145,8 @@ const char hamlib_copyright[231] = /* hamlib 1.2 ABI specifies 231 bytes */ /* * Data structure to track the opened rig (by rig_open) */ -struct opened_rig_l { +struct opened_rig_l +{ RIG *rig; struct opened_rig_l *next; }; @@ -154,7 +157,8 @@ static struct opened_rig_l *opened_rig_list = { NULL }; * Careful, the order must be the same as their RIG_E* counterpart! * TODO: localise the messages.. */ -static const char *rigerror_table[] = { +static const char *rigerror_table[] = +{ "Command completed successfully", "Invalid parameter", "Invalid configuration", @@ -189,7 +193,8 @@ static int add_opened_rig(RIG *rig) p = (struct opened_rig_l *)malloc(sizeof(struct opened_rig_l)); - if (!p) { + if (!p) + { return -RIG_ENOMEM; } @@ -206,11 +211,16 @@ static int remove_opened_rig(RIG *rig) struct opened_rig_l *p, *q; q = NULL; - for (p = opened_rig_list; p; p = p->next) { - if (p->rig == rig) { - if (q == NULL) { + for (p = opened_rig_list; p; p = p->next) + { + if (p->rig == rig) + { + if (q == NULL) + { opened_rig_list = opened_rig_list->next; - } else { + } + else + { q->next = p->next; } @@ -247,8 +257,10 @@ int foreach_opened_rig(int (*cfunc)(RIG *, rig_ptr_t), rig_ptr_t data) { struct opened_rig_l *p; - for (p = opened_rig_list; p; p = p->next) { - if ((*cfunc)(p->rig, data) == 0) { + for (p = opened_rig_list; p; p = p->next) + { + if ((*cfunc)(p->rig, data) == 0) + { return RIG_OK; } } @@ -265,15 +277,17 @@ int foreach_opened_rig(int (*cfunc)(RIG *, rig_ptr_t), rig_ptr_t data) * \return the appropriate description string, otherwise a NULL pointer * if the error code is unknown. * - * Returns a string describing the error code passed in the argument \a errnum. + * Returns a string describing the error code passed in the argument \a + * errnum. * * \todo support gettext/localization */ -const char *HAMLIB_API rigerror(int errnum) +const char * HAMLIB_API rigerror(int errnum) { errnum = abs(errnum); - if (errnum > ERROR_TBL_SZ) { + if (errnum > ERROR_TBL_SZ) + { return NULL; } @@ -293,7 +307,7 @@ const char *HAMLIB_API rigerror(int errnum) * * \sa rig_cleanup(), rig_open() */ -RIG *HAMLIB_API rig_init(rig_model_t rig_model) +RIG * HAMLIB_API rig_init(rig_model_t rig_model) { RIG *rig; const struct rig_caps *caps; @@ -306,7 +320,8 @@ RIG *HAMLIB_API rig_init(rig_model_t rig_model) caps = rig_get_caps(rig_model); - if (!caps) { + if (!caps) + { return NULL; } @@ -316,7 +331,8 @@ RIG *HAMLIB_API rig_init(rig_model_t rig_model) */ rig = calloc(1, sizeof(RIG)); - if (rig == NULL) { + if (rig == NULL) + { /* * FIXME: how can the caller know it's a memory shortage, * and not "rig not found" ? @@ -340,7 +356,8 @@ RIG *HAMLIB_API rig_init(rig_model_t rig_model) rs->comm_state = 0; rs->rigport.type.rig = caps->port_type; /* default from caps */ - switch (caps->port_type) { + switch (caps->port_type) + { case RIG_PORT_SERIAL: strncpy(rs->rigport.pathname, DEFAULT_SERIAL_PORT, FILPATHLEN - 1); rs->rigport.parm.serial.rate = caps->serial_rate_max; /* fastest ! */ @@ -390,7 +407,8 @@ RIG *HAMLIB_API rig_init(rig_model_t rig_model) /* should it be a parameter to rig_init ? --SF */ rs->itu_region = RIG_ITU_REGION2; - switch (rs->itu_region) { + switch (rs->itu_region) + { case RIG_ITU_REGION1: memcpy(rs->tx_range_list, caps->tx_range_list1, sizeof(struct freq_range_list)*FRQRANGESIZ); @@ -411,12 +429,14 @@ RIG *HAMLIB_API rig_init(rig_model_t rig_model) rs->vfo_list = 0; rs->mode_list = 0; - for (i = 0; i < FRQRANGESIZ && !RIG_IS_FRNG_END(rs->rx_range_list[i]); i++) { + for (i = 0; i < FRQRANGESIZ && !RIG_IS_FRNG_END(rs->rx_range_list[i]); i++) + { rs->vfo_list |= rs->rx_range_list[i].vfo; rs->mode_list |= rs->rx_range_list[i].modes; } - for (i = 0; i < FRQRANGESIZ && !RIG_IS_FRNG_END(rs->tx_range_list[i]); i++) { + for (i = 0; i < FRQRANGESIZ && !RIG_IS_FRNG_END(rs->tx_range_list[i]); i++) + { rs->vfo_list |= rs->tx_range_list[i].vfo; rs->mode_list |= rs->tx_range_list[i].modes; } @@ -441,8 +461,9 @@ RIG *HAMLIB_API rig_init(rig_model_t rig_model) /* emulation by frontend */ if ((caps->has_get_level & RIG_LEVEL_STRENGTH) == 0 - && (caps->has_get_level & RIG_LEVEL_RAWSTR) == RIG_LEVEL_RAWSTR) { - rs->has_get_level |= RIG_LEVEL_STRENGTH; + && (caps->has_get_level & RIG_LEVEL_RAWSTR) == RIG_LEVEL_RAWSTR) + { + rs->has_get_level |= RIG_LEVEL_STRENGTH; } memcpy(rs->level_gran, caps->level_gran, sizeof(gran_t)*RIG_SETTING_MAX); @@ -460,10 +481,12 @@ RIG *HAMLIB_API rig_init(rig_model_t rig_model) * This must be done only once defaults are setup, * so the backend init can override rig_state. */ - if (caps->rig_init != NULL) { + if (caps->rig_init != NULL) + { retcode = caps->rig_init(rig); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { rig_debug(RIG_DEBUG_VERBOSE, "%s: backend_init failed!\n", __func__); @@ -501,59 +524,68 @@ int HAMLIB_API rig_open(RIG *rig) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !rig->caps) { + if (!rig || !rig->caps) + { return -RIG_EINVAL; } caps = rig->caps; rs = &rig->state; - if (rs->comm_state) { + if (rs->comm_state) + { return -RIG_EINVAL; } rs->rigport.fd = -1; - if (rs->rigport.type.rig == RIG_PORT_SERIAL) { + if (rs->rigport.type.rig == RIG_PORT_SERIAL) + { if (rs->rigport.parm.serial.rts_state != RIG_SIGNAL_UNSET - && rs->rigport.parm.serial.handshake == RIG_HANDSHAKE_HARDWARE) { - rig_debug(RIG_DEBUG_ERR, - "%s: cannot set RTS with hardware handshake \"%s\"\n", - __func__, - rs->rigport.pathname); - return -RIG_ECONF; + && rs->rigport.parm.serial.handshake == RIG_HANDSHAKE_HARDWARE) + { + rig_debug(RIG_DEBUG_ERR, + "%s: cannot set RTS with hardware handshake \"%s\"\n", + __func__, + rs->rigport.pathname); + return -RIG_ECONF; } if ('\0' == rs->pttport.pathname[0] - || !strcmp(rs->pttport.pathname, rs->rigport.pathname)) { - /* check for control line conflicts */ - if (rs->rigport.parm.serial.rts_state != RIG_SIGNAL_UNSET - && rs->pttport.type.ptt == RIG_PTT_SERIAL_RTS) { - rig_debug(RIG_DEBUG_ERR, - "%s: cannot set RTS with PTT by RTS \"%s\"\n", - __func__, - rs->rigport.pathname); - return -RIG_ECONF; - } + || !strcmp(rs->pttport.pathname, rs->rigport.pathname)) + { + /* check for control line conflicts */ + if (rs->rigport.parm.serial.rts_state != RIG_SIGNAL_UNSET + && rs->pttport.type.ptt == RIG_PTT_SERIAL_RTS) + { + rig_debug(RIG_DEBUG_ERR, + "%s: cannot set RTS with PTT by RTS \"%s\"\n", + __func__, + rs->rigport.pathname); + return -RIG_ECONF; + } - if (rs->rigport.parm.serial.dtr_state != RIG_SIGNAL_UNSET - && rs->pttport.type.ptt == RIG_PTT_SERIAL_DTR) { - rig_debug(RIG_DEBUG_ERR, - "%s: cannot set DTR with PTT by DTR \"%s\"\n", - __func__, - rs->rigport.pathname); - return -RIG_ECONF; - } + if (rs->rigport.parm.serial.dtr_state != RIG_SIGNAL_UNSET + && rs->pttport.type.ptt == RIG_PTT_SERIAL_DTR) + { + rig_debug(RIG_DEBUG_ERR, + "%s: cannot set DTR with PTT by DTR \"%s\"\n", + __func__, + rs->rigport.pathname); + return -RIG_ECONF; + } } } status = port_open(&rs->rigport); - if (status < 0) { + if (status < 0) + { return status; } - switch (rs->pttport.type.ptt) { + switch (rs->pttport.type.ptt) + { case RIG_PTT_NONE: case RIG_PTT_RIG: case RIG_PTT_RIG_MICDATA: @@ -562,28 +594,35 @@ int HAMLIB_API rig_open(RIG *rig) case RIG_PTT_SERIAL_RTS: case RIG_PTT_SERIAL_DTR: if (rs->pttport.pathname[0] == '\0' - && rs->rigport.type.rig == RIG_PORT_SERIAL) { - strcpy(rs->pttport.pathname, rs->rigport.pathname); + && rs->rigport.type.rig == RIG_PORT_SERIAL) + { + strcpy(rs->pttport.pathname, rs->rigport.pathname); } - if (!strcmp(rs->pttport.pathname, rs->rigport.pathname)) { + if (!strcmp(rs->pttport.pathname, rs->rigport.pathname)) + { rs->pttport.fd = rs->rigport.fd; /* Needed on Linux because the serial port driver sets RTS/DTR on open - only need to address the PTT line as we offer config parameters to control the other (dtr_state & rts_state) */ - if (rs->pttport.type.ptt == RIG_PTT_SERIAL_DTR) { + if (rs->pttport.type.ptt == RIG_PTT_SERIAL_DTR) + { status = ser_set_dtr(&rs->pttport, 0); } - if (rs->pttport.type.ptt == RIG_PTT_SERIAL_RTS) { + if (rs->pttport.type.ptt == RIG_PTT_SERIAL_RTS) + { status = ser_set_rts(&rs->pttport, 0); } - } else { + } + else + { rs->pttport.fd = ser_open(&rs->pttport); - if (rs->pttport.fd < 0) { + if (rs->pttport.fd < 0) + { rig_debug(RIG_DEBUG_ERR, "%s: cannot open PTT device \"%s\"\n", __func__, @@ -593,16 +632,18 @@ int HAMLIB_API rig_open(RIG *rig) if (RIG_OK == status && (rs->pttport.type.ptt == RIG_PTT_SERIAL_DTR - || rs->pttport.type.ptt == RIG_PTT_SERIAL_RTS)) { - /* Needed on Linux because the serial port driver sets - RTS/DTR high on open - set both low since we offer no - control of the non-PTT line and low is better than - high */ - status = ser_set_dtr(&rs->pttport, 0); + || rs->pttport.type.ptt == RIG_PTT_SERIAL_RTS)) + { + /* Needed on Linux because the serial port driver sets + RTS/DTR high on open - set both low since we offer no + control of the non-PTT line and low is better than + high */ + status = ser_set_dtr(&rs->pttport, 0); - if (RIG_OK == status) { - status = ser_set_rts(&rs->pttport, 0); - } + if (RIG_OK == status) + { + status = ser_set_rts(&rs->pttport, 0); + } } ser_close(&rs->pttport); @@ -613,13 +654,16 @@ int HAMLIB_API rig_open(RIG *rig) case RIG_PTT_PARALLEL: rs->pttport.fd = par_open(&rs->pttport); - if (rs->pttport.fd < 0) { + if (rs->pttport.fd < 0) + { rig_debug(RIG_DEBUG_ERR, "%s: cannot open PTT device \"%s\"\n", __func__, rs->pttport.pathname); status = -RIG_EIO; - } else { + } + else + { par_ptt_set(&rs->pttport, RIG_PTT_OFF); } @@ -628,13 +672,16 @@ int HAMLIB_API rig_open(RIG *rig) case RIG_PTT_CM108: rs->pttport.fd = cm108_open(&rs->pttport); - if (rs->pttport.fd < 0) { + if (rs->pttport.fd < 0) + { rig_debug(RIG_DEBUG_ERR, "%s: cannot open PTT device \"%s\"\n", __func__, rs->pttport.pathname); status = -RIG_EIO; - } else { + } + else + { cm108_ptt_set(&rs->pttport, RIG_PTT_OFF); } @@ -643,13 +690,16 @@ int HAMLIB_API rig_open(RIG *rig) case RIG_PTT_GPIO: rs->pttport.fd = gpio_open(&rs->pttport, 1); - if (rs->pttport.fd < 0) { + if (rs->pttport.fd < 0) + { rig_debug(RIG_DEBUG_ERR, "%s: cannot open PTT device \"%s\"\n", __func__, rs->pttport.pathname); status = -RIG_EIO; - } else { + } + else + { gpio_ptt_set(&rs->pttport, RIG_PTT_OFF); } @@ -658,13 +708,16 @@ int HAMLIB_API rig_open(RIG *rig) case RIG_PTT_GPION: rs->pttport.fd = gpio_open(&rs->pttport, 0); - if (rs->pttport.fd < 0) { + if (rs->pttport.fd < 0) + { rig_debug(RIG_DEBUG_ERR, "%s: cannot open PTT device \"%s\"\n", __func__, rs->pttport.pathname); status = -RIG_EIO; - } else { + } + else + { gpio_ptt_set(&rs->pttport, RIG_PTT_OFF); } @@ -678,7 +731,8 @@ int HAMLIB_API rig_open(RIG *rig) status = -RIG_ECONF; } - switch (rs->dcdport.type.dcd) { + switch (rs->dcdport.type.dcd) + { case RIG_DCD_NONE: case RIG_DCD_RIG: break; @@ -687,18 +741,22 @@ int HAMLIB_API rig_open(RIG *rig) case RIG_DCD_SERIAL_CTS: case RIG_DCD_SERIAL_CAR: if (rs->dcdport.pathname[0] == '\0' - && rs->rigport.type.rig == RIG_PORT_SERIAL) { - strcpy(rs->dcdport.pathname, rs->rigport.pathname); + && rs->rigport.type.rig == RIG_PORT_SERIAL) + { + strcpy(rs->dcdport.pathname, rs->rigport.pathname); } - if (strcmp(rs->dcdport.pathname, rs->rigport.pathname) == 0) { + if (strcmp(rs->dcdport.pathname, rs->rigport.pathname) == 0) + { rs->dcdport.fd = rs->rigport.fd; } - else { + else + { rs->dcdport.fd = ser_open(&rs->dcdport); } - if (rs->dcdport.fd < 0) { + if (rs->dcdport.fd < 0) + { rig_debug(RIG_DEBUG_ERR, "%s: cannot open DCD device \"%s\"\n", __func__, @@ -711,7 +769,8 @@ int HAMLIB_API rig_open(RIG *rig) case RIG_DCD_PARALLEL: rs->dcdport.fd = par_open(&rs->dcdport); - if (rs->dcdport.fd < 0) { + if (rs->dcdport.fd < 0) + { rig_debug(RIG_DEBUG_ERR, "%s: cannot open DCD device \"%s\"\n", __func__, @@ -729,7 +788,8 @@ int HAMLIB_API rig_open(RIG *rig) status = -RIG_ECONF; } - if (status < 0) { + if (status < 0) + { port_close(&rs->rigport, rs->rigport.type.rig); return status; } @@ -742,10 +802,12 @@ int HAMLIB_API rig_open(RIG *rig) * Maybe the backend has something to initialize * In case of failure, just close down and report error code. */ - if (caps->rig_open != NULL) { + if (caps->rig_open != NULL) + { status = caps->rig_open(rig); - if (status != RIG_OK) { + if (status != RIG_OK) + { return status; } } @@ -753,7 +815,8 @@ int HAMLIB_API rig_open(RIG *rig) /* * trigger state->current_vfo first retrieval */ - if (rig_get_vfo(rig, &rs->current_vfo) == RIG_OK) { + if (rig_get_vfo(rig, &rs->current_vfo) == RIG_OK) + { rs->tx_vfo = rs->current_vfo; } @@ -762,11 +825,13 @@ int HAMLIB_API rig_open(RIG *rig) /* * Check the current tranceive state of the rig */ - if (rs->transceive == RIG_TRN_RIG) { + if (rs->transceive == RIG_TRN_RIG) + { int retval, trn; retval = rig_get_trn(rig, &trn); - if (retval == RIG_OK && trn == RIG_TRN_RIG) { + if (retval == RIG_OK && trn == RIG_TRN_RIG) + { add_trn_rig(rig); } } @@ -796,18 +861,21 @@ int HAMLIB_API rig_close(RIG *rig) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !rig->caps) { + if (!rig || !rig->caps) + { return -RIG_EINVAL; } caps = rig->caps; rs = &rig->state; - if (!rs->comm_state) { + if (!rs->comm_state) + { return -RIG_EINVAL; } - if (rs->transceive != RIG_TRN_OFF) { + if (rs->transceive != RIG_TRN_OFF) + { rig_set_trn(rig, RIG_TRN_OFF); } @@ -815,7 +883,8 @@ int HAMLIB_API rig_close(RIG *rig) * Let the backend say 73s to the rig. * and ignore the return code. */ - if (caps->rig_close) { + if (caps->rig_close) + { caps->rig_close(rig); } @@ -823,18 +892,22 @@ int HAMLIB_API rig_close(RIG *rig) * FIXME: what happens if PTT and rig ports are the same? * (eg. ptt_type = RIG_PTT_SERIAL) */ - switch (rs->pttport.type.ptt) { + switch (rs->pttport.type.ptt) + { case RIG_PTT_NONE: case RIG_PTT_RIG: case RIG_PTT_RIG_MICDATA: break; case RIG_PTT_SERIAL_RTS: + // If port is already closed, do nothing - if (rs->pttport.fd > -1) { + if (rs->pttport.fd > -1) + { ser_set_rts(&rs->pttport, 0); - if (rs->pttport.fd != rs->rigport.fd) { + if (rs->pttport.fd != rs->rigport.fd) + { port_close(&rs->pttport, RIG_PORT_SERIAL); } } @@ -842,11 +915,14 @@ int HAMLIB_API rig_close(RIG *rig) break; case RIG_PTT_SERIAL_DTR: + // If port is already closed, do nothing - if (rs->pttport.fd > -1) { + if (rs->pttport.fd > -1) + { ser_set_dtr(&rs->pttport, 0); - if (rs->pttport.fd != rs->rigport.fd) { + if (rs->pttport.fd != rs->rigport.fd) + { port_close(&rs->pttport, RIG_PORT_SERIAL); } } @@ -875,7 +951,8 @@ int HAMLIB_API rig_close(RIG *rig) rs->pttport.type.ptt); } - switch (rs->dcdport.type.dcd) { + switch (rs->dcdport.type.dcd) + { case RIG_DCD_NONE: case RIG_DCD_RIG: break; @@ -928,21 +1005,24 @@ int HAMLIB_API rig_cleanup(RIG *rig) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !rig->caps) { + if (!rig || !rig->caps) + { return -RIG_EINVAL; } /* * check if they forgot to close the rig */ - if (rig->state.comm_state) { + if (rig->state.comm_state) + { rig_close(rig); } /* * basically free up the priv struct */ - if (rig->caps->rig_cleanup) { + if (rig->caps->rig_cleanup) + { rig->caps->rig_cleanup(rig); } @@ -974,32 +1054,40 @@ int HAMLIB_API rig_set_freq(RIG *rig, vfo_t vfo, freq_t freq) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig)) { + if (CHECK_RIG_ARG(rig)) + { return -RIG_EINVAL; } caps = rig->caps; - if (rig->state.vfo_comp != 0.0) { + if (rig->state.vfo_comp != 0.0) + { freq += (freq_t)((double)rig->state.vfo_comp * freq); } - if (caps->set_freq == NULL) { + if (caps->set_freq == NULL) + { return -RIG_ENAVAIL; } if ((caps->targetable_vfo & RIG_TARGETABLE_FREQ) - || vfo == RIG_VFO_CURR || vfo == rig->state.current_vfo) { + || vfo == RIG_VFO_CURR || vfo == rig->state.current_vfo) + { retcode = caps->set_freq(rig, vfo, freq); - } else { - if (!caps->set_vfo) { + } + else + { + if (!caps->set_vfo) + { return -RIG_ENTARGET; } curr_vfo = rig->state.current_vfo; retcode = caps->set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } @@ -1007,7 +1095,8 @@ int HAMLIB_API rig_set_freq(RIG *rig, vfo_t vfo, freq_t freq) /* try and revert even if we had an error above */ rc2 = caps->set_vfo(rig, curr_vfo); - if (RIG_OK == retcode) { + if (RIG_OK == retcode) + { /* return the first error code */ retcode = rc2; } @@ -1015,7 +1104,8 @@ int HAMLIB_API rig_set_freq(RIG *rig, vfo_t vfo, freq_t freq) if (retcode == RIG_OK && (vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo)) { + || vfo == rig->state.current_vfo)) + { rig->state.current_freq = freq; } @@ -1047,28 +1137,35 @@ int HAMLIB_API rig_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig) || !freq) { + if (CHECK_RIG_ARG(rig) || !freq) + { return -RIG_EINVAL; } caps = rig->caps; - if (caps->get_freq == NULL) { + if (caps->get_freq == NULL) + { return -RIG_ENAVAIL; } if ((caps->targetable_vfo & RIG_TARGETABLE_FREQ) - || vfo == RIG_VFO_CURR || vfo == rig->state.current_vfo) { + || vfo == RIG_VFO_CURR || vfo == rig->state.current_vfo) + { retcode = caps->get_freq(rig, vfo, freq); - } else { - if (!caps->set_vfo) { + } + else + { + if (!caps->set_vfo) + { return -RIG_ENAVAIL; } curr_vfo = rig->state.current_vfo; retcode = caps->set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } @@ -1076,19 +1173,22 @@ int HAMLIB_API rig_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) /* try and revert even if we had an error above */ rc2 = caps->set_vfo(rig, curr_vfo); - if (RIG_OK == retcode) { + if (RIG_OK == retcode) + { /* return the first error code */ retcode = rc2; } } /* VFO compensation */ - if (rig->state.vfo_comp != 0.0) { + if (rig->state.vfo_comp != 0.0) + { *freq += (freq_t)(rig->state.vfo_comp * (*freq)); } if (retcode == RIG_OK - && (vfo == RIG_VFO_CURR || vfo == rig->state.current_vfo)) { + && (vfo == RIG_VFO_CURR || vfo == rig->state.current_vfo)) + { rig->state.current_freq = *freq; } @@ -1123,29 +1223,37 @@ int HAMLIB_API rig_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig)) { + if (CHECK_RIG_ARG(rig)) + { return -RIG_EINVAL; } caps = rig->caps; - if (caps->set_mode == NULL) { + if (caps->set_mode == NULL) + { return -RIG_ENAVAIL; } if ((caps->targetable_vfo & RIG_TARGETABLE_MODE) - || vfo == RIG_VFO_CURR || vfo == rig->state.current_vfo) { - retcode = caps->set_mode(rig, vfo, mode, width); - } else { + || vfo == RIG_VFO_CURR + || vfo == rig->state.current_vfo) + { + retcode = caps->set_mode(rig, vfo, mode, width); + } + else + { - if (!caps->set_vfo) { + if (!caps->set_vfo) + { return -RIG_ENTARGET; } curr_vfo = rig->state.current_vfo; retcode = caps->set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } @@ -1154,15 +1262,17 @@ int HAMLIB_API rig_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) rc2 = caps->set_vfo(rig, curr_vfo); /* return the first error code */ - if (RIG_OK == retcode) { + if (RIG_OK == retcode) + { retcode = rc2; } } if (retcode == RIG_OK - && (vfo == RIG_VFO_CURR || vfo == rig->state.current_vfo)) { - rig->state.current_mode = mode; - rig->state.current_width = width; + && (vfo == RIG_VFO_CURR || vfo == rig->state.current_vfo)) + { + rig->state.current_mode = mode; + rig->state.current_width = width; } return retcode; @@ -1188,7 +1298,9 @@ int HAMLIB_API rig_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) * * \sa rig_set_mode() */ -int HAMLIB_API rig_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, +int HAMLIB_API rig_get_mode(RIG *rig, + vfo_t vfo, + rmode_t *mode, pbwidth_t *width) { const struct rig_caps *caps; @@ -1197,30 +1309,37 @@ int HAMLIB_API rig_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig) || !mode || !width) { + if (CHECK_RIG_ARG(rig) || !mode || !width) + { return -RIG_EINVAL; } caps = rig->caps; - if (caps->get_mode == NULL) { + if (caps->get_mode == NULL) + { return -RIG_ENAVAIL; } if ((caps->targetable_vfo & RIG_TARGETABLE_MODE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) { - retcode = caps->get_mode(rig, vfo, mode, width); - } else { + || vfo == rig->state.current_vfo) + { + retcode = caps->get_mode(rig, vfo, mode, width); + } + else + { - if (!caps->set_vfo) { + if (!caps->set_vfo) + { return -RIG_ENTARGET; } curr_vfo = rig->state.current_vfo; retcode = caps->set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } @@ -1228,19 +1347,22 @@ int HAMLIB_API rig_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, /* try and revert even if we had an error above */ rc2 = caps->set_vfo(rig, curr_vfo); - if (RIG_OK == retcode) { + if (RIG_OK == retcode) + { /* return the first error code */ retcode = rc2; } } if (retcode == RIG_OK - && (vfo == RIG_VFO_CURR || vfo == rig->state.current_vfo)) { - rig->state.current_mode = *mode; - rig->state.current_width = *width; + && (vfo == RIG_VFO_CURR || vfo == rig->state.current_vfo)) + { + rig->state.current_mode = *mode; + rig->state.current_width = *width; } - if (*width == RIG_PASSBAND_NORMAL && *mode != RIG_MODE_NONE) { + if (*width == RIG_PASSBAND_NORMAL && *mode != RIG_MODE_NONE) + { *width = rig_passband_normal(rig, *mode); } @@ -1267,14 +1389,17 @@ pbwidth_t HAMLIB_API rig_passband_normal(RIG *rig, rmode_t mode) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) { + if (!rig) + { return RIG_PASSBAND_NORMAL; /* huhu! */ } rs = &rig->state; - for (i = 0; i < FLTLSTSIZ && rs->filters[i].modes; i++) { - if (rs->filters[i].modes & mode) { + for (i = 0; i < FLTLSTSIZ && rs->filters[i].modes; i++) + { + if (rs->filters[i].modes & mode) + { return rs->filters[i].width; } } @@ -1305,19 +1430,24 @@ pbwidth_t HAMLIB_API rig_passband_narrow(RIG *rig, rmode_t mode) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) { + if (!rig) + { return 0; /* huhu! */ } rs = &rig->state; - for (i = 0; i < FLTLSTSIZ - 1 && rs->filters[i].modes; i++) { - if (rs->filters[i].modes & mode) { + for (i = 0; i < FLTLSTSIZ - 1 && rs->filters[i].modes; i++) + { + if (rs->filters[i].modes & mode) + { normal = rs->filters[i].width; - for (i++; i < FLTLSTSIZ && rs->filters[i].modes; i++) { + for (i++; i < FLTLSTSIZ && rs->filters[i].modes; i++) + { if ((rs->filters[i].modes & mode) && - (rs->filters[i].width < normal)) { + (rs->filters[i].width < normal)) + { return rs->filters[i].width; } } @@ -1352,19 +1482,24 @@ pbwidth_t HAMLIB_API rig_passband_wide(RIG *rig, rmode_t mode) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) { + if (!rig) + { return 0; /* huhu! */ } rs = &rig->state; - for (i = 0; i < FLTLSTSIZ - 1 && rs->filters[i].modes; i++) { - if (rs->filters[i].modes & mode) { + for (i = 0; i < FLTLSTSIZ - 1 && rs->filters[i].modes; i++) + { + if (rs->filters[i].modes & mode) + { normal = rs->filters[i].width; - for (i++; i < FLTLSTSIZ && rs->filters[i].modes; i++) { + for (i++; i < FLTLSTSIZ && rs->filters[i].modes; i++) + { if ((rs->filters[i].modes & mode) && - (rs->filters[i].width > normal)) { + (rs->filters[i].width > normal)) + { return rs->filters[i].width; } } @@ -1399,19 +1534,22 @@ int HAMLIB_API rig_set_vfo(RIG *rig, vfo_t vfo) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig)) { + if (CHECK_RIG_ARG(rig)) + { return -RIG_EINVAL; } caps = rig->caps; - if (caps->set_vfo == NULL) { + if (caps->set_vfo == NULL) + { return -RIG_ENAVAIL; } retcode = caps->set_vfo(rig, vfo); - if (retcode == RIG_OK) { + if (retcode == RIG_OK) + { rig->state.current_vfo = vfo; } @@ -1441,19 +1579,22 @@ int HAMLIB_API rig_get_vfo(RIG *rig, vfo_t *vfo) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig) || !vfo) { + if (CHECK_RIG_ARG(rig) || !vfo) + { return -RIG_EINVAL; } caps = rig->caps; - if (caps->get_vfo == NULL) { + if (caps->get_vfo == NULL) + { return -RIG_ENAVAIL; } retcode = caps->get_vfo(rig, vfo); - if (retcode == RIG_OK) { + if (retcode == RIG_OK) + { rig->state.current_vfo = *vfo; } @@ -1485,48 +1626,59 @@ int HAMLIB_API rig_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig)) { + if (CHECK_RIG_ARG(rig)) + { return -RIG_EINVAL; } caps = rig->caps; - switch (rig->state.pttport.type.ptt) { + switch (rig->state.pttport.type.ptt) + { case RIG_PTT_RIG: - if (ptt == RIG_PTT_ON_MIC || ptt == RIG_PTT_ON_DATA) { + if (ptt == RIG_PTT_ON_MIC || ptt == RIG_PTT_ON_DATA) + { ptt = RIG_PTT_ON; } /* fall through */ case RIG_PTT_RIG_MICDATA: - if (caps->set_ptt == NULL) { + if (caps->set_ptt == NULL) + { return -RIG_ENIMPL; } if ((caps->targetable_vfo & RIG_TARGETABLE_PURE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) { + || vfo == rig->state.current_vfo) + { retcode = caps->set_ptt(rig, vfo, ptt); - } else { - if (!caps->set_vfo) { + } + else + { + if (!caps->set_vfo) + { return -RIG_ENTARGET; } curr_vfo = rig->state.current_vfo; retcode = caps->set_vfo(rig, vfo); - if (retcode == RIG_OK) { + if (retcode == RIG_OK) + { retcode = caps->set_ptt(rig, vfo, ptt); /* try and revert even if we had an error above */ rc2 = caps->set_vfo(rig, curr_vfo); /* return the first error code */ - if (RIG_OK == retcode) { + if (RIG_OK == retcode) + { retcode = rc2; } } } + break; case RIG_PTT_SERIAL_DTR: @@ -1536,11 +1688,13 @@ int HAMLIB_API rig_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) applications so long as there is no contention */ if (strcmp(rs->pttport.pathname, rs->rigport.pathname) && rs->pttport.fd < 0 - && RIG_PTT_OFF != ptt) { + && RIG_PTT_OFF != ptt) + { rs->pttport.fd = ser_open(&rs->pttport); - if (rs->pttport.fd < 0) { + if (rs->pttport.fd < 0) + { rig_debug(RIG_DEBUG_ERR, "%s: cannot open PTT device \"%s\"\n", __func__, @@ -1553,7 +1707,8 @@ int HAMLIB_API rig_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) the non-PTT line and low is better than high */ retcode = ser_set_rts(&rs->pttport, 0); - if (RIG_OK != retcode) { + if (RIG_OK != retcode) + { return retcode; } } @@ -1561,7 +1716,8 @@ int HAMLIB_API rig_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) retcode = ser_set_dtr(&rig->state.pttport, ptt != RIG_PTT_OFF); if (strcmp(rs->pttport.pathname, rs->rigport.pathname) - && ptt == RIG_PTT_OFF) { + && ptt == RIG_PTT_OFF) + { /* free the port */ ser_close(&rs->pttport); @@ -1576,11 +1732,13 @@ int HAMLIB_API rig_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) applications so long as there is no contention */ if (strcmp(rs->pttport.pathname, rs->rigport.pathname) && rs->pttport.fd < 0 - && RIG_PTT_OFF != ptt) { + && RIG_PTT_OFF != ptt) + { rs->pttport.fd = ser_open(&rs->pttport); - if (rs->pttport.fd < 0) { + if (rs->pttport.fd < 0) + { rig_debug(RIG_DEBUG_ERR, "%s: cannot open PTT device \"%s\"\n", __func__, @@ -1593,18 +1751,22 @@ int HAMLIB_API rig_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) non-PTT line and low is better than high */ retcode = ser_set_dtr(&rs->pttport, 0); - if (RIG_OK != retcode) { + if (RIG_OK != retcode) + { return retcode; } } + retcode = ser_set_rts(&rig->state.pttport, ptt != RIG_PTT_OFF); if (strcmp(rs->pttport.pathname, rs->rigport.pathname) - && ptt == RIG_PTT_OFF) { + && ptt == RIG_PTT_OFF) + { /* free the port */ ser_close(&rs->pttport); } + break; case RIG_PTT_PARALLEL: @@ -1624,7 +1786,8 @@ int HAMLIB_API rig_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) return -RIG_EINVAL; } - if (RIG_OK == retcode) { + if (RIG_OK == retcode) + { rs->transmit = ptt != RIG_PTT_OFF; } @@ -1656,35 +1819,41 @@ int HAMLIB_API rig_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig) || !ptt) { + if (CHECK_RIG_ARG(rig) || !ptt) + { return -RIG_EINVAL; } caps = rig->caps; - switch (rig->state.pttport.type.ptt) { + switch (rig->state.pttport.type.ptt) + { case RIG_PTT_RIG: case RIG_PTT_RIG_MICDATA: - if (!caps->get_ptt) { + if (!caps->get_ptt) + { *ptt = rs->transmit ? RIG_PTT_ON : RIG_PTT_OFF; return RIG_OK; } if ((caps->targetable_vfo & RIG_TARGETABLE_PURE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) { + || vfo == rig->state.current_vfo) + { return caps->get_ptt(rig, vfo, ptt); } - if (!caps->set_vfo) { + if (!caps->set_vfo) + { return -RIG_ENTARGET; } curr_vfo = rig->state.current_vfo; retcode = caps->set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } @@ -1692,7 +1861,8 @@ int HAMLIB_API rig_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt) /* try and revert even if we had an error above */ rc2 = caps->set_vfo(rig, curr_vfo); - if (RIG_OK == retcode) { + if (RIG_OK == retcode) + { /* return the first error code */ retcode = rc2; } @@ -1700,16 +1870,20 @@ int HAMLIB_API rig_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt) return retcode; case RIG_PTT_SERIAL_RTS: - if (caps->get_ptt) { + if (caps->get_ptt) + { return caps->get_ptt(rig, vfo, ptt); } if (strcmp(rs->pttport.pathname, rs->rigport.pathname) - && rs->pttport.fd < 0) { + && rs->pttport.fd < 0) + { /* port is closed so assume PTT off */ *ptt = RIG_PTT_OFF; - } else { + } + else + { retcode = ser_get_rts(&rig->state.pttport, &status); *ptt = status ? RIG_PTT_ON : RIG_PTT_OFF; } @@ -1717,16 +1891,20 @@ int HAMLIB_API rig_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt) return retcode; case RIG_PTT_SERIAL_DTR: - if (caps->get_ptt) { + if (caps->get_ptt) + { return caps->get_ptt(rig, vfo, ptt); } if (strcmp(rs->pttport.pathname, rs->rigport.pathname) - && rs->pttport.fd < 0) { + && rs->pttport.fd < 0) + { /* port is closed so assume PTT off */ *ptt = RIG_PTT_OFF; - } else { + } + else + { retcode = ser_get_dtr(&rig->state.pttport, &status); *ptt = status ? RIG_PTT_ON : RIG_PTT_OFF; } @@ -1734,14 +1912,16 @@ int HAMLIB_API rig_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt) return retcode; case RIG_PTT_PARALLEL: - if (caps->get_ptt) { + if (caps->get_ptt) + { return caps->get_ptt(rig, vfo, ptt); } return par_ptt_get(&rig->state.pttport, ptt); case RIG_PTT_CM108: - if (caps->get_ptt) { + if (caps->get_ptt) + { return caps->get_ptt(rig, vfo, ptt); } @@ -1749,7 +1929,8 @@ int HAMLIB_API rig_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt) case RIG_PTT_GPIO: case RIG_PTT_GPION: - if (caps->get_ptt) { + if (caps->get_ptt) + { return caps->get_ptt(rig, vfo, ptt); } @@ -1787,32 +1968,38 @@ int HAMLIB_API rig_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig) || !dcd) { + if (CHECK_RIG_ARG(rig) || !dcd) + { return -RIG_EINVAL; } caps = rig->caps; - switch (rig->state.dcdport.type.dcd) { + switch (rig->state.dcdport.type.dcd) + { case RIG_DCD_RIG: - if (caps->get_dcd == NULL) { + if (caps->get_dcd == NULL) + { return -RIG_ENIMPL; } if ((caps->targetable_vfo & RIG_TARGETABLE_PURE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) { - return caps->get_dcd(rig, vfo, dcd); + || vfo == rig->state.current_vfo) + { + return caps->get_dcd(rig, vfo, dcd); } - if (!caps->set_vfo) { + if (!caps->set_vfo) + { return -RIG_ENTARGET; } curr_vfo = rig->state.current_vfo; retcode = caps->set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } @@ -1820,7 +2007,8 @@ int HAMLIB_API rig_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd) /* try and revert even if we had an error above */ rc2 = caps->set_vfo(rig, curr_vfo); - if (RIG_OK == retcode) { + if (RIG_OK == retcode) + { /* return the first error code */ retcode = rc2; } @@ -1881,30 +2069,35 @@ int HAMLIB_API rig_set_rptr_shift(RIG *rig, vfo_t vfo, rptr_shift_t rptr_shift) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig)) { + if (CHECK_RIG_ARG(rig)) + { return -RIG_EINVAL; } caps = rig->caps; - if (caps->set_rptr_shift == NULL) { + if (caps->set_rptr_shift == NULL) + { return -RIG_ENAVAIL; } if ((caps->targetable_vfo & RIG_TARGETABLE_PURE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) { - return caps->set_rptr_shift(rig, vfo, rptr_shift); + || vfo == rig->state.current_vfo) + { + return caps->set_rptr_shift(rig, vfo, rptr_shift); } - if (!caps->set_vfo) { + if (!caps->set_vfo) + { return -RIG_ENTARGET; } curr_vfo = rig->state.current_vfo; retcode = caps->set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } @@ -1912,7 +2105,8 @@ int HAMLIB_API rig_set_rptr_shift(RIG *rig, vfo_t vfo, rptr_shift_t rptr_shift) /* try and revert even if we had an error above */ rc2 = caps->set_vfo(rig, curr_vfo); - if (RIG_OK == retcode) { + if (RIG_OK == retcode) + { /* return the first error code */ retcode = rc2; } @@ -1943,30 +2137,35 @@ int HAMLIB_API rig_get_rptr_shift(RIG *rig, vfo_t vfo, rptr_shift_t *rptr_shift) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig) || !rptr_shift) { + if (CHECK_RIG_ARG(rig) || !rptr_shift) + { return -RIG_EINVAL; } caps = rig->caps; - if (caps->get_rptr_shift == NULL) { + if (caps->get_rptr_shift == NULL) + { return -RIG_ENAVAIL; } if ((caps->targetable_vfo & RIG_TARGETABLE_PURE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) { - return caps->get_rptr_shift(rig, vfo, rptr_shift); + || vfo == rig->state.current_vfo) + { + return caps->get_rptr_shift(rig, vfo, rptr_shift); } - if (!caps->set_vfo) { + if (!caps->set_vfo) + { return -RIG_ENTARGET; } curr_vfo = rig->state.current_vfo; retcode = caps->set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } @@ -1974,7 +2173,8 @@ int HAMLIB_API rig_get_rptr_shift(RIG *rig, vfo_t vfo, rptr_shift_t *rptr_shift) /* try and revert even if we had an error above */ rc2 = caps->set_vfo(rig, curr_vfo); - if (RIG_OK == retcode) { + if (RIG_OK == retcode) + { /* return the first error code */ retcode = rc2; } @@ -2005,30 +2205,35 @@ int HAMLIB_API rig_set_rptr_offs(RIG *rig, vfo_t vfo, shortfreq_t rptr_offs) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig)) { + if (CHECK_RIG_ARG(rig)) + { return -RIG_EINVAL; } caps = rig->caps; - if (caps->set_rptr_offs == NULL) { + if (caps->set_rptr_offs == NULL) + { return -RIG_ENAVAIL; } if ((caps->targetable_vfo & RIG_TARGETABLE_PURE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) { - return caps->set_rptr_offs(rig, vfo, rptr_offs); + || vfo == rig->state.current_vfo) + { + return caps->set_rptr_offs(rig, vfo, rptr_offs); } - if (!caps->set_vfo) { + if (!caps->set_vfo) + { return -RIG_ENTARGET; } curr_vfo = rig->state.current_vfo; retcode = caps->set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } @@ -2036,7 +2241,8 @@ int HAMLIB_API rig_set_rptr_offs(RIG *rig, vfo_t vfo, shortfreq_t rptr_offs) /* try and revert even if we had an error above */ rc2 = caps->set_vfo(rig, curr_vfo); - if (RIG_OK == retcode) { + if (RIG_OK == retcode) + { /* return the first error code */ retcode = rc2; } @@ -2067,30 +2273,35 @@ int HAMLIB_API rig_get_rptr_offs(RIG *rig, vfo_t vfo, shortfreq_t *rptr_offs) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig) || !rptr_offs) { + if (CHECK_RIG_ARG(rig) || !rptr_offs) + { return -RIG_EINVAL; } caps = rig->caps; - if (caps->get_rptr_offs == NULL) { + if (caps->get_rptr_offs == NULL) + { return -RIG_ENAVAIL; } if ((caps->targetable_vfo & RIG_TARGETABLE_PURE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) { - return caps->get_rptr_offs(rig, vfo, rptr_offs); + || vfo == rig->state.current_vfo) + { + return caps->get_rptr_offs(rig, vfo, rptr_offs); } - if (!caps->set_vfo) { + if (!caps->set_vfo) + { return -RIG_ENTARGET; } curr_vfo = rig->state.current_vfo; retcode = caps->set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } @@ -2098,7 +2309,8 @@ int HAMLIB_API rig_get_rptr_offs(RIG *rig, vfo_t vfo, shortfreq_t *rptr_offs) /* try and revert even if we had an error above */ rc2 = caps->set_vfo(rig, curr_vfo); - if (RIG_OK == retcode) { + if (RIG_OK == retcode) + { /* return the first error code */ retcode = rc2; } @@ -2129,7 +2341,8 @@ int HAMLIB_API rig_set_split_freq(RIG *rig, vfo_t vfo, freq_t tx_freq) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig)) { + if (CHECK_RIG_ARG(rig)) + { return -RIG_EINVAL; } @@ -2139,7 +2352,8 @@ int HAMLIB_API rig_set_split_freq(RIG *rig, vfo_t vfo, freq_t tx_freq) && ((caps->targetable_vfo & RIG_TARGETABLE_PURE) || vfo == RIG_VFO_CURR || vfo == RIG_VFO_TX - || vfo == rig->state.current_vfo)) { + || vfo == rig->state.current_vfo)) + { return caps->set_split_freq(rig, vfo, tx_freq); } @@ -2147,43 +2361,60 @@ int HAMLIB_API rig_set_split_freq(RIG *rig, vfo_t vfo, freq_t tx_freq) curr_vfo = rig->state.current_vfo; /* Use previously setup TxVFO */ - if (vfo == RIG_VFO_CURR || vfo == RIG_VFO_TX) { + if (vfo == RIG_VFO_CURR || vfo == RIG_VFO_TX) + { tx_vfo = rig->state.tx_vfo; - } else { + } + else + { tx_vfo = vfo; } - if (caps->set_freq && (caps->targetable_vfo & RIG_TARGETABLE_FREQ)) { + if (caps->set_freq && (caps->targetable_vfo & RIG_TARGETABLE_FREQ)) + { return caps->set_freq(rig, tx_vfo, tx_freq); } - if (caps->set_vfo) { + if (caps->set_vfo) + { retcode = caps->set_vfo(rig, tx_vfo); - } else if (rig_has_vfo_op(rig, RIG_OP_TOGGLE) && caps->vfo_op) { + } + else if (rig_has_vfo_op(rig, RIG_OP_TOGGLE) && caps->vfo_op) + { retcode = caps->vfo_op(rig, vfo, RIG_OP_TOGGLE); - } else { + } + else + { return -RIG_ENAVAIL; } - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } - if (caps->set_split_freq) { + if (caps->set_split_freq) + { retcode = caps->set_split_freq(rig, vfo, tx_freq); - } else { + } + else + { retcode = caps->set_freq(rig, RIG_VFO_CURR, tx_freq); } /* try and revert even if we had an error above */ - if (caps->set_vfo) { + if (caps->set_vfo) + { rc2 = caps->set_vfo(rig, curr_vfo); - } else { + } + else + { rc2 = caps->vfo_op(rig, vfo, RIG_OP_TOGGLE); } - if (RIG_OK == retcode) { + if (RIG_OK == retcode) + { /* return the first error code */ retcode = rc2; } @@ -2214,7 +2445,8 @@ int HAMLIB_API rig_get_split_freq(RIG *rig, vfo_t vfo, freq_t *tx_freq) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig) || !tx_freq) { + if (CHECK_RIG_ARG(rig) || !tx_freq) + { return -RIG_EINVAL; } @@ -2224,51 +2456,69 @@ int HAMLIB_API rig_get_split_freq(RIG *rig, vfo_t vfo, freq_t *tx_freq) && ((caps->targetable_vfo & RIG_TARGETABLE_PURE) || vfo == RIG_VFO_CURR || vfo == RIG_VFO_TX - || vfo == rig->state.current_vfo)) { - return caps->get_split_freq(rig, vfo, tx_freq); + || vfo == rig->state.current_vfo)) + { + return caps->get_split_freq(rig, vfo, tx_freq); } /* Assisted mode */ curr_vfo = rig->state.current_vfo; /* Use previously setup TxVFO */ - if (vfo == RIG_VFO_CURR || vfo == RIG_VFO_TX) { + if (vfo == RIG_VFO_CURR || vfo == RIG_VFO_TX) + { tx_vfo = rig->state.tx_vfo; - } else { + } + else + { tx_vfo = vfo; } - if (caps->get_freq && (caps->targetable_vfo & RIG_TARGETABLE_FREQ)) { + if (caps->get_freq && (caps->targetable_vfo & RIG_TARGETABLE_FREQ)) + { return caps->get_freq(rig, tx_vfo, tx_freq); } - if (caps->set_vfo) { + if (caps->set_vfo) + { retcode = caps->set_vfo(rig, tx_vfo); - } else if (rig_has_vfo_op(rig, RIG_OP_TOGGLE) && caps->vfo_op) { + } + else if (rig_has_vfo_op(rig, RIG_OP_TOGGLE) && caps->vfo_op) + { retcode = caps->vfo_op(rig, vfo, RIG_OP_TOGGLE); - } else { + } + else + { return -RIG_ENAVAIL; } - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } - if (caps->get_split_freq) { + if (caps->get_split_freq) + { retcode = caps->get_split_freq(rig, vfo, tx_freq); - } else { + } + else + { retcode = caps->get_freq(rig, RIG_VFO_CURR, tx_freq); } /* try and revert even if we had an error above */ - if (caps->set_vfo) { + if (caps->set_vfo) + { rc2 = caps->set_vfo(rig, curr_vfo); - } else { + } + else + { rc2 = caps->vfo_op(rig, vfo, RIG_OP_TOGGLE); } - if (RIG_OK == retcode) { + if (RIG_OK == retcode) + { /* return the first error code */ retcode = rc2; } @@ -2295,7 +2545,9 @@ int HAMLIB_API rig_get_split_freq(RIG *rig, vfo_t vfo, freq_t *tx_freq) * * \sa rig_get_split_mode() */ -int HAMLIB_API rig_set_split_mode(RIG *rig, vfo_t vfo, rmode_t tx_mode, +int HAMLIB_API rig_set_split_mode(RIG *rig, + vfo_t vfo, + rmode_t tx_mode, pbwidth_t tx_width) { const struct rig_caps *caps; @@ -2304,7 +2556,8 @@ int HAMLIB_API rig_set_split_mode(RIG *rig, vfo_t vfo, rmode_t tx_mode, rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig)) { + if (CHECK_RIG_ARG(rig)) + { return -RIG_EINVAL; } @@ -2314,51 +2567,69 @@ int HAMLIB_API rig_set_split_mode(RIG *rig, vfo_t vfo, rmode_t tx_mode, && ((caps->targetable_vfo & RIG_TARGETABLE_PURE) || vfo == RIG_VFO_CURR || vfo == RIG_VFO_TX - || vfo == rig->state.current_vfo)) { - return caps->set_split_mode(rig, vfo, tx_mode, tx_width); + || vfo == rig->state.current_vfo)) + { + return caps->set_split_mode(rig, vfo, tx_mode, tx_width); } /* Assisted mode */ curr_vfo = rig->state.current_vfo; /* Use previously setup TxVFO */ - if (vfo == RIG_VFO_CURR || vfo == RIG_VFO_TX) { + if (vfo == RIG_VFO_CURR || vfo == RIG_VFO_TX) + { tx_vfo = rig->state.tx_vfo; - } else { + } + else + { tx_vfo = vfo; } - if (caps->set_mode && (caps->targetable_vfo & RIG_TARGETABLE_MODE)) { + if (caps->set_mode && (caps->targetable_vfo & RIG_TARGETABLE_MODE)) + { return caps->set_mode(rig, tx_vfo, tx_mode, tx_width); } - if (caps->set_vfo) { + if (caps->set_vfo) + { retcode = caps->set_vfo(rig, tx_vfo); - } else if (rig_has_vfo_op(rig, RIG_OP_TOGGLE) && caps->vfo_op) { + } + else if (rig_has_vfo_op(rig, RIG_OP_TOGGLE) && caps->vfo_op) + { retcode = caps->vfo_op(rig, vfo, RIG_OP_TOGGLE); - } else { + } + else + { return -RIG_ENAVAIL; } - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } - if (caps->set_split_mode) { + if (caps->set_split_mode) + { retcode = caps->set_split_mode(rig, vfo, tx_mode, tx_width); - } else { + } + else + { retcode = caps->set_mode(rig, RIG_VFO_CURR, tx_mode, tx_width); } /* try and revert even if we had an error above */ - if (caps->set_vfo) { + if (caps->set_vfo) + { rc2 = caps->set_vfo(rig, curr_vfo); - } else { + } + else + { rc2 = caps->vfo_op(rig, vfo, RIG_OP_TOGGLE); } - if (RIG_OK == retcode) { + if (RIG_OK == retcode) + { /* return the first error code */ retcode = rc2; } @@ -2395,7 +2666,8 @@ int HAMLIB_API rig_get_split_mode(RIG *rig, vfo_t vfo, rmode_t *tx_mode, rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig) || !tx_mode || !tx_width) { + if (CHECK_RIG_ARG(rig) || !tx_mode || !tx_width) + { return -RIG_EINVAL; } @@ -2405,56 +2677,75 @@ int HAMLIB_API rig_get_split_mode(RIG *rig, vfo_t vfo, rmode_t *tx_mode, && ((caps->targetable_vfo & RIG_TARGETABLE_PURE) || vfo == RIG_VFO_CURR || vfo == RIG_VFO_TX - || vfo == rig->state.current_vfo)) { - return caps->get_split_mode(rig, vfo, tx_mode, tx_width); + || vfo == rig->state.current_vfo)) + { + return caps->get_split_mode(rig, vfo, tx_mode, tx_width); } /* Assisted mode */ curr_vfo = rig->state.current_vfo; /* Use previously setup TxVFO */ - if (vfo == RIG_VFO_CURR || vfo == RIG_VFO_TX) { + if (vfo == RIG_VFO_CURR || vfo == RIG_VFO_TX) + { tx_vfo = rig->state.tx_vfo; - } else { + } + else + { tx_vfo = vfo; } - if (caps->get_mode && (caps->targetable_vfo & RIG_TARGETABLE_MODE)) { + if (caps->get_mode && (caps->targetable_vfo & RIG_TARGETABLE_MODE)) + { return caps->get_mode(rig, tx_vfo, tx_mode, tx_width); } - if (caps->set_vfo) { + if (caps->set_vfo) + { retcode = caps->set_vfo(rig, tx_vfo); - } else if (rig_has_vfo_op(rig, RIG_OP_TOGGLE) && caps->vfo_op) { + } + else if (rig_has_vfo_op(rig, RIG_OP_TOGGLE) && caps->vfo_op) + { retcode = caps->vfo_op(rig, vfo, RIG_OP_TOGGLE); - } else { + } + else + { return -RIG_ENAVAIL; } - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } - if (caps->get_split_mode) { + if (caps->get_split_mode) + { retcode = caps->get_split_mode(rig, vfo, tx_mode, tx_width); - } else { + } + else + { retcode = caps->get_mode(rig, RIG_VFO_CURR, tx_mode, tx_width); } /* try and revert even if we had an error above */ - if (caps->set_vfo) { + if (caps->set_vfo) + { rc2 = caps->set_vfo(rig, curr_vfo); - } else { + } + else + { rc2 = caps->vfo_op(rig, vfo, RIG_OP_TOGGLE); } - if (RIG_OK == retcode) { + if (RIG_OK == retcode) + { /* return the first error code */ retcode = rc2; } - if (*tx_width == RIG_PASSBAND_NORMAL && *tx_mode != RIG_MODE_NONE) { + if (*tx_width == RIG_PASSBAND_NORMAL && *tx_mode != RIG_MODE_NONE) + { *tx_width = rig_passband_normal(rig, *tx_mode); } @@ -2486,27 +2777,33 @@ int HAMLIB_API rig_get_split_mode(RIG *rig, vfo_t vfo, rmode_t *tx_mode, * * \sa rig_set_split_freq(), rig_set_split_mode(), rig_get_split_freq_mode() */ -int HAMLIB_API rig_set_split_freq_mode(RIG *rig, vfo_t vfo, freq_t tx_freq, - rmode_t tx_mode, pbwidth_t tx_width) +int HAMLIB_API rig_set_split_freq_mode(RIG *rig, + vfo_t vfo, + freq_t tx_freq, + rmode_t tx_mode, + pbwidth_t tx_width) { const struct rig_caps *caps; int retcode; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig)) { + if (CHECK_RIG_ARG(rig)) + { return -RIG_EINVAL; } caps = rig->caps; - if (caps->set_split_freq_mode) { + if (caps->set_split_freq_mode) + { return caps->set_split_freq_mode(rig, vfo, tx_freq, tx_mode, tx_width); } retcode = rig_set_split_freq(rig, vfo, tx_freq); - if (RIG_OK == retcode) { + if (RIG_OK == retcode) + { retcode = rig_set_split_mode(rig, vfo, tx_mode, tx_width); } @@ -2539,27 +2836,33 @@ int HAMLIB_API rig_set_split_freq_mode(RIG *rig, vfo_t vfo, freq_t tx_freq, * * \sa rig_get_split_freq(), rig_get_split_mode(), rig_set_split_freq_mode() */ -int HAMLIB_API rig_get_split_freq_mode(RIG *rig, vfo_t vfo, freq_t *tx_freq, - rmode_t *tx_mode, pbwidth_t *tx_width) +int HAMLIB_API rig_get_split_freq_mode(RIG *rig, + vfo_t vfo, + freq_t *tx_freq, + rmode_t *tx_mode, + pbwidth_t *tx_width) { const struct rig_caps *caps; int retcode; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig) || !tx_freq || !tx_mode || !tx_width) { + if (CHECK_RIG_ARG(rig) || !tx_freq || !tx_mode || !tx_width) + { return -RIG_EINVAL; } caps = rig->caps; - if (caps->get_split_freq_mode) { + if (caps->get_split_freq_mode) + { return caps->get_split_freq_mode(rig, vfo, tx_freq, tx_mode, tx_width); } retcode = rig_get_split_freq(rig, vfo, tx_freq); - if (RIG_OK == retcode) { + if (RIG_OK == retcode) + { retcode = rig_get_split_mode(rig, vfo, tx_mode, tx_width); } @@ -2582,7 +2885,9 @@ int HAMLIB_API rig_get_split_freq_mode(RIG *rig, vfo_t vfo, freq_t *tx_freq, * * \sa rig_get_split_vfo() */ -int HAMLIB_API rig_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, +int HAMLIB_API rig_set_split_vfo(RIG *rig, + vfo_t vfo, + split_t split, vfo_t tx_vfo) { const struct rig_caps *caps; @@ -2591,36 +2896,42 @@ int HAMLIB_API rig_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig)) { + if (CHECK_RIG_ARG(rig)) + { return -RIG_EINVAL; } caps = rig->caps; - if (caps->set_split_vfo == NULL) { + if (caps->set_split_vfo == NULL) + { return -RIG_ENAVAIL; } if ((caps->targetable_vfo & RIG_TARGETABLE_PURE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) { - retcode = caps->set_split_vfo(rig, vfo, split, tx_vfo); + || vfo == rig->state.current_vfo) + { + retcode = caps->set_split_vfo(rig, vfo, split, tx_vfo); - if (retcode == RIG_OK) { - rig->state.tx_vfo = tx_vfo; - } + if (retcode == RIG_OK) + { + rig->state.tx_vfo = tx_vfo; + } - return retcode; + return retcode; } - if (!caps->set_vfo) { + if (!caps->set_vfo) + { return -RIG_ENTARGET; } curr_vfo = rig->state.current_vfo; retcode = caps->set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } @@ -2629,12 +2940,14 @@ int HAMLIB_API rig_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, /* try and revert even if we had an error above */ rc2 = caps->set_vfo(rig, curr_vfo); - if (RIG_OK == retcode) { + if (RIG_OK == retcode) + { /* return the first error code */ retcode = rc2; } - if (retcode == RIG_OK) { + if (retcode == RIG_OK) + { rig->state.tx_vfo = tx_vfo; } @@ -2657,7 +2970,9 @@ int HAMLIB_API rig_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, * * \sa rig_set_split_vfo() */ -int HAMLIB_API rig_get_split_vfo(RIG *rig, vfo_t vfo, split_t *split, +int HAMLIB_API rig_get_split_vfo(RIG *rig, + vfo_t vfo, + split_t *split, vfo_t *tx_vfo) { const struct rig_caps *caps; @@ -2666,13 +2981,15 @@ int HAMLIB_API rig_get_split_vfo(RIG *rig, vfo_t vfo, split_t *split, rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig) || !split || !tx_vfo) { + if (CHECK_RIG_ARG(rig) || !split || !tx_vfo) + { return -RIG_EINVAL; } caps = rig->caps; - if (caps->get_split_vfo == NULL) { + if (caps->get_split_vfo == NULL) + { return -RIG_ENAVAIL; } @@ -2681,18 +2998,21 @@ int HAMLIB_API rig_get_split_vfo(RIG *rig, vfo_t vfo, split_t *split, if ((caps->targetable_vfo & RIG_TARGETABLE_PURE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) { - return caps->get_split_vfo(rig, vfo, split, tx_vfo); + || vfo == rig->state.current_vfo) + { + return caps->get_split_vfo(rig, vfo, split, tx_vfo); } - if (!caps->set_vfo) { + if (!caps->set_vfo) + { return -RIG_ENTARGET; } curr_vfo = rig->state.current_vfo; retcode = caps->set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } @@ -2700,7 +3020,8 @@ int HAMLIB_API rig_get_split_vfo(RIG *rig, vfo_t vfo, split_t *split, /* try and revert even if we had an error above */ rc2 = caps->set_vfo(rig, curr_vfo); - if (RIG_OK == retcode) { + if (RIG_OK == retcode) + { /* return the first error code */ retcode = rc2; } @@ -2731,30 +3052,35 @@ int HAMLIB_API rig_set_rit(RIG *rig, vfo_t vfo, shortfreq_t rit) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig)) { + if (CHECK_RIG_ARG(rig)) + { return -RIG_EINVAL; } caps = rig->caps; - if (caps->set_rit == NULL) { + if (caps->set_rit == NULL) + { return -RIG_ENAVAIL; } if ((caps->targetable_vfo & RIG_TARGETABLE_PURE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) { - return caps->set_rit(rig, vfo, rit); + || vfo == rig->state.current_vfo) + { + return caps->set_rit(rig, vfo, rit); } - if (!caps->set_vfo) { + if (!caps->set_vfo) + { return -RIG_ENTARGET; } curr_vfo = rig->state.current_vfo; retcode = caps->set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } @@ -2762,7 +3088,8 @@ int HAMLIB_API rig_set_rit(RIG *rig, vfo_t vfo, shortfreq_t rit) /* try and revert even if we had an error above */ rc2 = caps->set_vfo(rig, curr_vfo); - if (RIG_OK == retcode) { + if (RIG_OK == retcode) + { /* return the first error code */ retcode = rc2; } @@ -2793,30 +3120,35 @@ int HAMLIB_API rig_get_rit(RIG *rig, vfo_t vfo, shortfreq_t *rit) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig) || !rit) { + if (CHECK_RIG_ARG(rig) || !rit) + { return -RIG_EINVAL; } caps = rig->caps; - if (caps->get_rit == NULL) { + if (caps->get_rit == NULL) + { return -RIG_ENAVAIL; } if ((caps->targetable_vfo & RIG_TARGETABLE_PURE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) { - return caps->get_rit(rig, vfo, rit); + || vfo == rig->state.current_vfo) + { + return caps->get_rit(rig, vfo, rit); } - if (!caps->set_vfo) { + if (!caps->set_vfo) + { return -RIG_ENTARGET; } curr_vfo = rig->state.current_vfo; retcode = caps->set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } @@ -2824,7 +3156,8 @@ int HAMLIB_API rig_get_rit(RIG *rig, vfo_t vfo, shortfreq_t *rit) /* try and revert even if we had an error above */ rc2 = caps->set_vfo(rig, curr_vfo); - if (RIG_OK == retcode) { + if (RIG_OK == retcode) + { /* return the first error code */ retcode = rc2; } @@ -2855,30 +3188,35 @@ int HAMLIB_API rig_set_xit(RIG *rig, vfo_t vfo, shortfreq_t xit) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig)) { + if (CHECK_RIG_ARG(rig)) + { return -RIG_EINVAL; } caps = rig->caps; - if (caps->set_xit == NULL) { + if (caps->set_xit == NULL) + { return -RIG_ENAVAIL; } if ((caps->targetable_vfo & RIG_TARGETABLE_PURE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) { - return caps->set_xit(rig, vfo, xit); + || vfo == rig->state.current_vfo) + { + return caps->set_xit(rig, vfo, xit); } - if (!caps->set_vfo) { + if (!caps->set_vfo) + { return -RIG_ENTARGET; } curr_vfo = rig->state.current_vfo; retcode = caps->set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } @@ -2886,7 +3224,8 @@ int HAMLIB_API rig_set_xit(RIG *rig, vfo_t vfo, shortfreq_t xit) /* try and revert even if we had an error above */ rc2 = caps->set_vfo(rig, curr_vfo); - if (RIG_OK == retcode) { + if (RIG_OK == retcode) + { /* return the first error code */ retcode = rc2; } @@ -2917,30 +3256,35 @@ int HAMLIB_API rig_get_xit(RIG *rig, vfo_t vfo, shortfreq_t *xit) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig) || !xit) { + if (CHECK_RIG_ARG(rig) || !xit) + { return -RIG_EINVAL; } caps = rig->caps; - if (caps->get_xit == NULL) { + if (caps->get_xit == NULL) + { return -RIG_ENAVAIL; } if ((caps->targetable_vfo & RIG_TARGETABLE_PURE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) { - return caps->get_xit(rig, vfo, xit); + || vfo == rig->state.current_vfo) + { + return caps->get_xit(rig, vfo, xit); } - if (!caps->set_vfo) { + if (!caps->set_vfo) + { return -RIG_ENTARGET; } curr_vfo = rig->state.current_vfo; retcode = caps->set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } @@ -2948,7 +3292,8 @@ int HAMLIB_API rig_get_xit(RIG *rig, vfo_t vfo, shortfreq_t *xit) /* try and revert even if we had an error above */ rc2 = caps->set_vfo(rig, curr_vfo); - if (RIG_OK == retcode) { + if (RIG_OK == retcode) + { /* return the first error code */ retcode = rc2; } @@ -2979,30 +3324,35 @@ int HAMLIB_API rig_set_ts(RIG *rig, vfo_t vfo, shortfreq_t ts) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig)) { + if (CHECK_RIG_ARG(rig)) + { return -RIG_EINVAL; } caps = rig->caps; - if (caps->set_ts == NULL) { + if (caps->set_ts == NULL) + { return -RIG_ENAVAIL; } if ((caps->targetable_vfo & RIG_TARGETABLE_PURE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) { - return caps->set_ts(rig, vfo, ts); + || vfo == rig->state.current_vfo) + { + return caps->set_ts(rig, vfo, ts); } - if (!caps->set_vfo) { + if (!caps->set_vfo) + { return -RIG_ENTARGET; } curr_vfo = rig->state.current_vfo; retcode = caps->set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } @@ -3010,7 +3360,8 @@ int HAMLIB_API rig_set_ts(RIG *rig, vfo_t vfo, shortfreq_t ts) /* try and revert even if we had an error above */ rc2 = caps->set_vfo(rig, curr_vfo); - if (RIG_OK == retcode) { + if (RIG_OK == retcode) + { /* return the first error code */ retcode = rc2; } @@ -3041,30 +3392,35 @@ int HAMLIB_API rig_get_ts(RIG *rig, vfo_t vfo, shortfreq_t *ts) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig) || !ts) { + if (CHECK_RIG_ARG(rig) || !ts) + { return -RIG_EINVAL; } caps = rig->caps; - if (caps->get_ts == NULL) { + if (caps->get_ts == NULL) + { return -RIG_ENAVAIL; } if ((caps->targetable_vfo & RIG_TARGETABLE_PURE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) { - return caps->get_ts(rig, vfo, ts); + || vfo == rig->state.current_vfo) + { + return caps->get_ts(rig, vfo, ts); } - if (!caps->set_vfo) { + if (!caps->set_vfo) + { return -RIG_ENTARGET; } curr_vfo = rig->state.current_vfo; retcode = caps->set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } @@ -3072,7 +3428,8 @@ int HAMLIB_API rig_get_ts(RIG *rig, vfo_t vfo, shortfreq_t *ts) /* try and revert even if we had an error above */ rc2 = caps->set_vfo(rig, curr_vfo); - if (RIG_OK == retcode) { + if (RIG_OK == retcode) + { /* return the first error code */ retcode = rc2; } @@ -3107,30 +3464,35 @@ int HAMLIB_API rig_set_ant(RIG *rig, vfo_t vfo, ant_t ant) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig)) { + if (CHECK_RIG_ARG(rig)) + { return -RIG_EINVAL; } caps = rig->caps; - if (caps->set_ant == NULL) { + if (caps->set_ant == NULL) + { return -RIG_ENAVAIL; } if ((caps->targetable_vfo & RIG_TARGETABLE_PURE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) { - return caps->set_ant(rig, vfo, ant); + || vfo == rig->state.current_vfo) + { + return caps->set_ant(rig, vfo, ant); } - if (!caps->set_vfo) { + if (!caps->set_vfo) + { return -RIG_ENTARGET; } curr_vfo = rig->state.current_vfo; retcode = caps->set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } @@ -3138,7 +3500,8 @@ int HAMLIB_API rig_set_ant(RIG *rig, vfo_t vfo, ant_t ant) /* try and revert even if we had an error above */ rc2 = caps->set_vfo(rig, curr_vfo); - if (RIG_OK == retcode) { + if (RIG_OK == retcode) + { /* return the first error code */ retcode = rc2; } @@ -3169,30 +3532,35 @@ int HAMLIB_API rig_get_ant(RIG *rig, vfo_t vfo, ant_t *ant) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig) || !ant) { + if (CHECK_RIG_ARG(rig) || !ant) + { return -RIG_EINVAL; } caps = rig->caps; - if (caps->get_ant == NULL) { + if (caps->get_ant == NULL) + { return -RIG_ENAVAIL; } if ((caps->targetable_vfo & RIG_TARGETABLE_PURE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) { - return caps->get_ant(rig, vfo, ant); + || vfo == rig->state.current_vfo) + { + return caps->get_ant(rig, vfo, ant); } - if (!caps->set_vfo) { + if (!caps->set_vfo) + { return -RIG_ENTARGET; } curr_vfo = rig->state.current_vfo; retcode = caps->set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } @@ -3200,7 +3568,8 @@ int HAMLIB_API rig_get_ant(RIG *rig, vfo_t vfo, ant_t *ant) /* try and revert even if we had an error above */ rc2 = caps->set_vfo(rig, curr_vfo); - if (RIG_OK == retcode) { + if (RIG_OK == retcode) + { /* return the first error code */ retcode = rc2; } @@ -3229,24 +3598,30 @@ int HAMLIB_API rig_get_ant(RIG *rig, vfo_t vfo, ant_t *ant) * * \sa rig_mW2power() */ -int HAMLIB_API rig_power2mW(RIG *rig, unsigned int *mwpower, float power, - freq_t freq, rmode_t mode) +int HAMLIB_API rig_power2mW(RIG *rig, + unsigned int *mwpower, + float power, + freq_t freq, + rmode_t mode) { const freq_range_t *txrange; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !rig->caps || !mwpower || power < 0.0 || power > 1.0) { + if (!rig || !rig->caps || !mwpower || power < 0.0 || power > 1.0) + { return -RIG_EINVAL; } - if (rig->caps->power2mW != NULL) { + if (rig->caps->power2mW != NULL) + { return rig->caps->power2mW(rig, mwpower, power, freq, mode); } txrange = rig_get_range(rig->state.tx_range_list, freq, mode); - if (!txrange) { + if (!txrange) + { /* * freq is not on the tx range! */ @@ -3279,38 +3654,46 @@ int HAMLIB_API rig_power2mW(RIG *rig, unsigned int *mwpower, float power, * * \sa rig_power2mW() */ -int HAMLIB_API rig_mW2power(RIG *rig, float *power, unsigned int mwpower, - freq_t freq, rmode_t mode) +int HAMLIB_API rig_mW2power(RIG *rig, + float *power, + unsigned int mwpower, + freq_t freq, + rmode_t mode) { const freq_range_t *txrange; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !rig->caps || !power || mwpower <= 0) { + if (!rig || !rig->caps || !power || mwpower <= 0) + { return -RIG_EINVAL; } - if (rig->caps->mW2power != NULL) { + if (rig->caps->mW2power != NULL) + { return rig->caps->mW2power(rig, power, mwpower, freq, mode); } txrange = rig_get_range(rig->state.tx_range_list, freq, mode); - if (!txrange) { + if (!txrange) + { /* * freq is not on the tx range! */ return -RIG_ECONF; /* could be RIG_EINVAL ? */ } - if (txrange->high_power == 0) { + if (txrange->high_power == 0) + { *power = 0.0; return RIG_OK; } *power = (float)mwpower / txrange->high_power; - if (*power > 1.0) { + if (*power > 1.0) + { *power = 1.0; } @@ -3336,14 +3719,17 @@ shortfreq_t HAMLIB_API rig_get_resolution(RIG *rig, rmode_t mode) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !rig->caps || !mode) { + if (!rig || !rig->caps || !mode) + { return -RIG_EINVAL; } rs = &rig->state; - for (i = 0; i < TSLSTSIZ && rs->tuning_steps[i].ts; i++) { - if (rs->tuning_steps[i].modes & mode) { + for (i = 0; i < TSLSTSIZ && rs->tuning_steps[i].ts; i++) + { + if (rs->tuning_steps[i].modes & mode) + { return rs->tuning_steps[i].ts; } } @@ -3371,11 +3757,13 @@ int HAMLIB_API rig_set_powerstat(RIG *rig, powerstat_t status) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig)) { + if (CHECK_RIG_ARG(rig)) + { return -RIG_EINVAL; } - if (rig->caps->set_powerstat == NULL) { + if (rig->caps->set_powerstat == NULL) + { return -RIG_ENAVAIL; } @@ -3401,11 +3789,13 @@ int HAMLIB_API rig_get_powerstat(RIG *rig, powerstat_t *status) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig) || !status) { + if (CHECK_RIG_ARG(rig) || !status) + { return -RIG_EINVAL; } - if (rig->caps->get_powerstat == NULL) { + if (rig->caps->get_powerstat == NULL) + { return -RIG_ENAVAIL; } @@ -3431,11 +3821,13 @@ int HAMLIB_API rig_reset(RIG *rig, reset_t reset) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig)) { + if (CHECK_RIG_ARG(rig)) + { return -RIG_EINVAL; } - if (rig->caps->reset == NULL) { + if (rig->caps->reset == NULL) + { return -RIG_ENAVAIL; } @@ -3444,7 +3836,9 @@ int HAMLIB_API rig_reset(RIG *rig, reset_t reset) extern int rig_probe_first(hamlib_port_t *p); -extern int rig_probe_all_backends(hamlib_port_t *p, rig_probe_func_t cfunc, + +extern int rig_probe_all_backends(hamlib_port_t *p, + rig_probe_func_t cfunc, rig_ptr_t data); @@ -3466,7 +3860,8 @@ rig_model_t HAMLIB_API rig_probe(hamlib_port_t *port) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!port) { + if (!port) + { return RIG_MODEL_NONE; } @@ -3491,12 +3886,14 @@ rig_model_t HAMLIB_API rig_probe(hamlib_port_t *port) * a negative value if an error occured (in which case, cause is * set appropriately). */ -int HAMLIB_API rig_probe_all(hamlib_port_t *port, rig_probe_func_t cfunc, +int HAMLIB_API rig_probe_all(hamlib_port_t *port, + rig_probe_func_t cfunc, rig_ptr_t data) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!port) { + if (!port) + { return -RIG_EINVAL; } @@ -3524,7 +3921,8 @@ vfo_op_t HAMLIB_API rig_has_vfo_op(RIG *rig, vfo_op_t op) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !rig->caps) { + if (!rig || !rig->caps) + { return 0; } @@ -3555,30 +3953,35 @@ int HAMLIB_API rig_vfo_op(RIG *rig, vfo_t vfo, vfo_op_t op) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig)) { + if (CHECK_RIG_ARG(rig)) + { return -RIG_EINVAL; } caps = rig->caps; - if (caps->vfo_op == NULL || !rig_has_vfo_op(rig, op)) { + if (caps->vfo_op == NULL || !rig_has_vfo_op(rig, op)) + { return -RIG_ENAVAIL; } if ((caps->targetable_vfo & RIG_TARGETABLE_PURE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) { - return caps->vfo_op(rig, vfo, op); + || vfo == rig->state.current_vfo) + { + return caps->vfo_op(rig, vfo, op); } - if (!caps->set_vfo) { + if (!caps->set_vfo) + { return -RIG_ENTARGET; } curr_vfo = rig->state.current_vfo; retcode = caps->set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } @@ -3586,7 +3989,8 @@ int HAMLIB_API rig_vfo_op(RIG *rig, vfo_t vfo, vfo_op_t op) /* try and revert even if we had an error above */ rc2 = caps->set_vfo(rig, curr_vfo); - if (RIG_OK == retcode) { + if (RIG_OK == retcode) + { /* return the first error code */ retcode = rc2; } @@ -3615,7 +4019,8 @@ scan_t HAMLIB_API rig_has_scan(RIG *rig, scan_t scan) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !rig->caps) { + if (!rig || !rig->caps) + { return 0; } @@ -3647,31 +4052,36 @@ int HAMLIB_API rig_scan(RIG *rig, vfo_t vfo, scan_t scan, int ch) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig)) { + if (CHECK_RIG_ARG(rig)) + { return -RIG_EINVAL; } caps = rig->caps; if (caps->scan == NULL - || (scan != RIG_SCAN_STOP && !rig_has_scan(rig, scan))) { - return -RIG_ENAVAIL; + || (scan != RIG_SCAN_STOP && !rig_has_scan(rig, scan))) + { + return -RIG_ENAVAIL; } if ((caps->targetable_vfo & RIG_TARGETABLE_PURE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) { - return caps->scan(rig, vfo, scan, ch); + || vfo == rig->state.current_vfo) + { + return caps->scan(rig, vfo, scan, ch); } - if (!caps->set_vfo) { + if (!caps->set_vfo) + { return -RIG_ENTARGET; } curr_vfo = rig->state.current_vfo; retcode = caps->set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } @@ -3679,7 +4089,8 @@ int HAMLIB_API rig_scan(RIG *rig, vfo_t vfo, scan_t scan, int ch) /* try and revert even if we had an error above */ rc2 = caps->set_vfo(rig, curr_vfo); - if (RIG_OK == retcode) { + if (RIG_OK == retcode) + { /* return the first error code */ retcode = rc2; } @@ -3710,30 +4121,35 @@ int HAMLIB_API rig_send_dtmf(RIG *rig, vfo_t vfo, const char *digits) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig) || !digits) { + if (CHECK_RIG_ARG(rig) || !digits) + { return -RIG_EINVAL; } caps = rig->caps; - if (caps->send_dtmf == NULL) { + if (caps->send_dtmf == NULL) + { return -RIG_ENAVAIL; } if ((caps->targetable_vfo & RIG_TARGETABLE_PURE) - ||vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) { - return caps->send_dtmf(rig, vfo, digits); + || vfo == RIG_VFO_CURR + || vfo == rig->state.current_vfo) + { + return caps->send_dtmf(rig, vfo, digits); } - if (!caps->set_vfo) { + if (!caps->set_vfo) + { return -RIG_ENTARGET; } curr_vfo = rig->state.current_vfo; retcode = caps->set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } @@ -3741,7 +4157,8 @@ int HAMLIB_API rig_send_dtmf(RIG *rig, vfo_t vfo, const char *digits) /* try and revert even if we had an error above */ rc2 = caps->set_vfo(rig, curr_vfo); - if (RIG_OK == retcode) { + if (RIG_OK == retcode) + { /* return the first error code */ retcode = rc2; } @@ -3773,30 +4190,35 @@ int HAMLIB_API rig_recv_dtmf(RIG *rig, vfo_t vfo, char *digits, int *length) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig) || !digits || !length) { + if (CHECK_RIG_ARG(rig) || !digits || !length) + { return -RIG_EINVAL; } caps = rig->caps; - if (caps->recv_dtmf == NULL) { + if (caps->recv_dtmf == NULL) + { return -RIG_ENAVAIL; } if ((caps->targetable_vfo & RIG_TARGETABLE_PURE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) { - return caps->recv_dtmf(rig, vfo, digits, length); + || vfo == rig->state.current_vfo) + { + return caps->recv_dtmf(rig, vfo, digits, length); } - if (!caps->set_vfo) { + if (!caps->set_vfo) + { return -RIG_ENTARGET; } curr_vfo = rig->state.current_vfo; retcode = caps->set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } @@ -3804,7 +4226,8 @@ int HAMLIB_API rig_recv_dtmf(RIG *rig, vfo_t vfo, char *digits, int *length) /* try and revert even if we had an error above */ rc2 = caps->set_vfo(rig, curr_vfo); - if (RIG_OK == retcode) { + if (RIG_OK == retcode) + { /* return the first error code */ retcode = rc2; } @@ -3835,30 +4258,35 @@ int HAMLIB_API rig_send_morse(RIG *rig, vfo_t vfo, const char *msg) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig) || !msg) { + if (CHECK_RIG_ARG(rig) || !msg) + { return -RIG_EINVAL; } caps = rig->caps; - if (caps->send_morse == NULL) { + if (caps->send_morse == NULL) + { return -RIG_ENAVAIL; } if ((caps->targetable_vfo & RIG_TARGETABLE_PURE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) { - return caps->send_morse(rig, vfo, msg); + || vfo == rig->state.current_vfo) + { + return caps->send_morse(rig, vfo, msg); } - if (!caps->set_vfo) { + if (!caps->set_vfo) + { return -RIG_ENTARGET; } curr_vfo = rig->state.current_vfo; retcode = caps->set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } @@ -3866,7 +4294,8 @@ int HAMLIB_API rig_send_morse(RIG *rig, vfo_t vfo, const char *msg) /* try and revert even if we had an error above */ rc2 = caps->set_vfo(rig, curr_vfo); - if (RIG_OK == retcode) { + if (RIG_OK == retcode) + { /* return the first error code */ retcode = rc2; } @@ -3888,21 +4317,24 @@ int HAMLIB_API rig_send_morse(RIG *rig, vfo_t vfo, const char *msg) * otherwise NULL if not found or if \a range_list is invalid. * */ -const freq_range_t * -HAMLIB_API rig_get_range(const freq_range_t range_list[], freq_t freq, - rmode_t mode) +const freq_range_t * HAMLIB_API rig_get_range(const freq_range_t range_list[], + freq_t freq, + rmode_t mode) { int i; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - for (i = 0; i < FRQRANGESIZ; i++) { - if (range_list[i].start == 0 && range_list[i].end == 0) { + for (i = 0; i < FRQRANGESIZ; i++) + { + if (range_list[i].start == 0 && range_list[i].end == 0) + { return NULL; } if (freq >= range_list[i].start && freq <= range_list[i].end && - (range_list[i].modes & mode)) { + (range_list[i].modes & mode)) + { return &range_list[i]; } } @@ -3922,15 +4354,17 @@ HAMLIB_API rig_get_range(const freq_range_t range_list[], freq_t freq, * if the operation has been sucessful, otherwise NULL if an error occured * or get_info not part of capabilities. */ -const char *HAMLIB_API rig_get_info(RIG *rig) +const char * HAMLIB_API rig_get_info(RIG *rig) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig)) { + if (CHECK_RIG_ARG(rig)) + { return NULL; } - if (rig->caps->get_info == NULL) { + if (rig->caps->get_info == NULL) + { return NULL; } @@ -3938,19 +4372,19 @@ const char *HAMLIB_API rig_get_info(RIG *rig) } -const char *HAMLIB_API rig_license() +const char * HAMLIB_API rig_license() { return hamlib_license; } -const char *HAMLIB_API rig_version() +const char * HAMLIB_API rig_version() { return hamlib_version2; } -const char *HAMLIB_API rig_copyright() +const char * HAMLIB_API rig_copyright() { return hamlib_copyright2; } diff --git a/src/rot_conf.c b/src/rot_conf.c index 2e2d4a42f..6d4838b57 100644 --- a/src/rot_conf.c +++ b/src/rot_conf.c @@ -30,7 +30,7 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +# include "config.h" #endif #include @@ -48,7 +48,8 @@ /* * Configuration options available in the rot->state struct. */ -static const struct confparams rotfrontend_cfg_params[] = { +static const struct confparams rotfrontend_cfg_params[] = +{ { TOK_PATHNAME, "rot_pathname", "Rig path name", "Path name to the device file of the rotator", @@ -98,7 +99,8 @@ static const struct confparams rotfrontend_cfg_params[] = { }; -static const struct confparams rotfrontend_serial_cfg_params[] = { +static const struct confparams rotfrontend_serial_cfg_params[] = +{ { TOK_SERIAL_SPEED, "serial_speed", "Serial speed", "Serial port baud rate", @@ -147,13 +149,15 @@ int frontrot_set_conf(ROT *rot, token_t token, const char *val) rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - switch (token) { + switch (token) + { case TOK_PATHNAME: strncpy(rs->rotport.pathname, val, FILPATHLEN - 1); break; case TOK_WRITE_DELAY: - if (1 != sscanf(val, "%d", &val_i)) { + if (1 != sscanf(val, "%d", &val_i)) + { return -RIG_EINVAL; } @@ -161,7 +165,8 @@ int frontrot_set_conf(ROT *rot, token_t token, const char *val) break; case TOK_POST_WRITE_DELAY: - if (1 != sscanf(val, "%d", &val_i)) { + if (1 != sscanf(val, "%d", &val_i)) + { return -RIG_EINVAL; } @@ -169,7 +174,8 @@ int frontrot_set_conf(ROT *rot, token_t token, const char *val) break; case TOK_TIMEOUT: - if (1 != sscanf(val, "%d", &val_i)) { + if (1 != sscanf(val, "%d", &val_i)) + { return -RIG_EINVAL; } @@ -177,7 +183,8 @@ int frontrot_set_conf(ROT *rot, token_t token, const char *val) break; case TOK_RETRY: - if (1 != sscanf(val, "%d", &val_i)) { + if (1 != sscanf(val, "%d", &val_i)) + { return -RIG_EINVAL; } @@ -185,11 +192,13 @@ int frontrot_set_conf(ROT *rot, token_t token, const char *val) break; case TOK_SERIAL_SPEED: - if (rs->rotport.type.rig != RIG_PORT_SERIAL) { + if (rs->rotport.type.rig != RIG_PORT_SERIAL) + { return -RIG_EINVAL; } - if (1 != sscanf(val, "%d", &val_i)) { + if (1 != sscanf(val, "%d", &val_i)) + { return -RIG_EINVAL; } @@ -197,11 +206,13 @@ int frontrot_set_conf(ROT *rot, token_t token, const char *val) break; case TOK_DATA_BITS: - if (rs->rotport.type.rig != RIG_PORT_SERIAL) { + if (rs->rotport.type.rig != RIG_PORT_SERIAL) + { return -RIG_EINVAL; } - if (1 != sscanf(val, "%d", &val_i)) { + if (1 != sscanf(val, "%d", &val_i)) + { return -RIG_EINVAL; } @@ -209,11 +220,13 @@ int frontrot_set_conf(ROT *rot, token_t token, const char *val) break; case TOK_STOP_BITS: - if (rs->rotport.type.rig != RIG_PORT_SERIAL) { + if (rs->rotport.type.rig != RIG_PORT_SERIAL) + { return -RIG_EINVAL; } - if (1 != sscanf(val, "%d", &val_i)) { + if (1 != sscanf(val, "%d", &val_i)) + { return -RIG_EINVAL; } @@ -221,38 +234,58 @@ int frontrot_set_conf(ROT *rot, token_t token, const char *val) break; case TOK_PARITY: - if (rs->rotport.type.rig != RIG_PORT_SERIAL) { + if (rs->rotport.type.rig != RIG_PORT_SERIAL) + { return -RIG_EINVAL; } - if (!strcmp(val, "None")) { + if (!strcmp(val, "None")) + { rs->rotport.parm.serial.parity = RIG_PARITY_NONE; - } else if (!strcmp(val, "Odd")) { + } + else if (!strcmp(val, "Odd")) + { rs->rotport.parm.serial.parity = RIG_PARITY_ODD; - } else if (!strcmp(val, "Even")) { + } + else if (!strcmp(val, "Even")) + { rs->rotport.parm.serial.parity = RIG_PARITY_EVEN; - } else if (!strcmp(val, "Mark")) { + } + else if (!strcmp(val, "Mark")) + { rs->rotport.parm.serial.parity = RIG_PARITY_MARK; - } else if (!strcmp(val, "Space")) { + } + else if (!strcmp(val, "Space")) + { rs->rotport.parm.serial.parity = RIG_PARITY_SPACE; - } else { + } + else + { return -RIG_EINVAL; } break; case TOK_HANDSHAKE: - if (rs->rotport.type.rig != RIG_PORT_SERIAL) { + if (rs->rotport.type.rig != RIG_PORT_SERIAL) + { return -RIG_EINVAL; } - if (!strcmp(val, "None")) { + if (!strcmp(val, "None")) + { rs->rotport.parm.serial.handshake = RIG_HANDSHAKE_NONE; - } else if (!strcmp(val, "XONXOFF")) { + } + else if (!strcmp(val, "XONXOFF")) + { rs->rotport.parm.serial.handshake = RIG_HANDSHAKE_XONXOFF; - } else if (!strcmp(val, "Hardware")) { + } + else if (!strcmp(val, "Hardware")) + { rs->rotport.parm.serial.handshake = RIG_HANDSHAKE_HARDWARE; - } else { + } + else + { return -RIG_EINVAL; } @@ -298,7 +331,8 @@ int frontrot_get_conf(ROT *rot, token_t token, char *val) rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - switch (token) { + switch (token) + { case TOK_PATHNAME: strcpy(val, rs->rotport.pathname); break; @@ -320,7 +354,8 @@ int frontrot_get_conf(ROT *rot, token_t token, char *val) break; case TOK_SERIAL_SPEED: - if (rs->rotport.type.rig != RIG_PORT_SERIAL) { + if (rs->rotport.type.rig != RIG_PORT_SERIAL) + { return -RIG_EINVAL; } @@ -328,7 +363,8 @@ int frontrot_get_conf(ROT *rot, token_t token, char *val) break; case TOK_DATA_BITS: - if (rs->rotport.type.rig != RIG_PORT_SERIAL) { + if (rs->rotport.type.rig != RIG_PORT_SERIAL) + { return -RIG_EINVAL; } @@ -336,7 +372,8 @@ int frontrot_get_conf(ROT *rot, token_t token, char *val) break; case TOK_STOP_BITS: - if (rs->rotport.type.rig != RIG_PORT_SERIAL) { + if (rs->rotport.type.rig != RIG_PORT_SERIAL) + { return -RIG_EINVAL; } @@ -344,11 +381,13 @@ int frontrot_get_conf(ROT *rot, token_t token, char *val) break; case TOK_PARITY: - if (rs->rotport.type.rig != RIG_PORT_SERIAL) { + if (rs->rotport.type.rig != RIG_PORT_SERIAL) + { return -RIG_EINVAL; } - switch (rs->rotport.parm.serial.parity) { + switch (rs->rotport.parm.serial.parity) + { case RIG_PARITY_NONE: s = "None"; break; @@ -377,11 +416,13 @@ int frontrot_get_conf(ROT *rot, token_t token, char *val) break; case TOK_HANDSHAKE: - if (rs->rotport.type.rig != RIG_PORT_SERIAL) { + if (rs->rotport.type.rig != RIG_PORT_SERIAL) + { return -RIG_EINVAL; } - switch (rs->rotport.parm.serial.handshake) { + switch (rs->rotport.parm.serial.handshake) + { case RIG_HANDSHAKE_NONE: s = "None"; break; @@ -434,33 +475,42 @@ int frontrot_get_conf(ROT *rot, token_t token, char *val) * start first with backend conf table, then finish with frontend table */ int HAMLIB_API rot_token_foreach(ROT *rot, - int (*cfunc)(const struct confparams *, rig_ptr_t), + int (*cfunc)(const struct confparams *, + rig_ptr_t), rig_ptr_t data) { const struct confparams *cfp; rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rot || !rot->caps || !cfunc) { + if (!rot || !rot->caps || !cfunc) + { return -RIG_EINVAL; } - for (cfp = rotfrontend_cfg_params; cfp->name; cfp++) { - if ((*cfunc)(cfp, data) == 0) { + for (cfp = rotfrontend_cfg_params; cfp->name; cfp++) + { + if ((*cfunc)(cfp, data) == 0) + { return RIG_OK; } } - if (rot->caps->port_type == RIG_PORT_SERIAL) { - for (cfp = rotfrontend_serial_cfg_params; cfp->name; cfp++) { - if ((*cfunc)(cfp, data) == 0) { + if (rot->caps->port_type == RIG_PORT_SERIAL) + { + for (cfp = rotfrontend_serial_cfg_params; cfp->name; cfp++) + { + if ((*cfunc)(cfp, data) == 0) + { return RIG_OK; } } } - for (cfp = rot->caps->cfgparams; cfp && cfp->name; cfp++) { - if ((*cfunc)(cfp, data) == 0) { + for (cfp = rot->caps->cfgparams; cfp && cfp->name; cfp++) + { + if ((*cfunc)(cfp, data) == 0) + { return RIG_OK; } } @@ -486,28 +536,36 @@ const struct confparams * HAMLIB_API rot_confparam_lookup(ROT *rot, rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rot || !rot->caps) { + if (!rot || !rot->caps) + { return NULL; } /* 0 returned for invalid format */ token = strtol(name, NULL, 0); - for (cfp = rot->caps->cfgparams; cfp && cfp->name; cfp++) { - if (!strcmp(cfp->name, name) || token == cfp->token) { + for (cfp = rot->caps->cfgparams; cfp && cfp->name; cfp++) + { + if (!strcmp(cfp->name, name) || token == cfp->token) + { return cfp; } } - for (cfp = rotfrontend_cfg_params; cfp->name; cfp++) { - if (!strcmp(cfp->name, name) || token == cfp->token) { + for (cfp = rotfrontend_cfg_params; cfp->name; cfp++) + { + if (!strcmp(cfp->name, name) || token == cfp->token) + { return cfp; } } - if (rot->caps->port_type == RIG_PORT_SERIAL) { - for (cfp = rotfrontend_serial_cfg_params; cfp->name; cfp++) { - if (!strcmp(cfp->name, name) || token == cfp->token) { + if (rot->caps->port_type == RIG_PORT_SERIAL) + { + for (cfp = rotfrontend_serial_cfg_params; cfp->name; cfp++) + { + if (!strcmp(cfp->name, name) || token == cfp->token) + { return cfp; } } @@ -531,7 +589,8 @@ token_t HAMLIB_API rot_token_lookup(ROT *rot, const char *name) cfp = rot_confparam_lookup(rot, name); - if (!cfp) { + if (!cfp) + { return RIG_CONF_END; } @@ -557,28 +616,33 @@ int HAMLIB_API rot_set_conf(ROT *rot, token_t token, const char *val) { rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rot || !rot->caps) { + if (!rot || !rot->caps) + { return -RIG_EINVAL; } - if (rig_need_debug(RIG_DEBUG_VERBOSE)) { + if (rig_need_debug(RIG_DEBUG_VERBOSE)) + { const struct confparams *cfp; char tokenstr[12]; sprintf(tokenstr, "%ld", token); cfp = rot_confparam_lookup(rot, tokenstr); - if (!cfp) { + if (!cfp) + { return -RIG_EINVAL; } rot_debug(RIG_DEBUG_VERBOSE, "%s: %s='%s'\n", __func__, cfp->name, val); } - if (IS_TOKEN_FRONTEND(token)) { + if (IS_TOKEN_FRONTEND(token)) + { return frontrot_set_conf(rot, token, val); } - if (rot->caps->set_conf == NULL) { + if (rot->caps->set_conf == NULL) + { return -RIG_ENAVAIL; } @@ -604,15 +668,18 @@ int HAMLIB_API rot_get_conf(ROT *rot, token_t token, char *val) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rot || !rot->caps || !val) { + if (!rot || !rot->caps || !val) + { return -RIG_EINVAL; } - if (IS_TOKEN_FRONTEND(token)) { + if (IS_TOKEN_FRONTEND(token)) + { return frontrot_get_conf(rot, token, val); } - if (rot->caps->get_conf == NULL) { + if (rot->caps->get_conf == NULL) + { return -RIG_ENAVAIL; } diff --git a/src/rot_reg.c b/src/rot_reg.c index f019400d0..d6bae5ca5 100644 --- a/src/rot_reg.c +++ b/src/rot_reg.c @@ -28,7 +28,7 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +# include "config.h" #endif #include @@ -83,21 +83,24 @@ DEFINE_INITROT_BACKEND(cnctrk); DEFINE_INITROT_BACKEND(prosistel); -/*! \def ROT_BACKEND_LIST +/** + * \def ROT_BACKEND_LIST * \brief Static list of rotator models. * * This is a NULL terminated list of available rotator backends. Each entry * in the list consists of two fields: The branch number, which is an integer, * and the branch name, which is a character string. - * An external library, loaded dynamically, could add its own functions pointers - * in this array. + * An external library, loaded dynamically, could add its own functions + * pointers in this array. */ -static struct { +static struct +{ int be_num; const char *be_name; int (*be_init)(void *); rot_model_t (*be_probe)(hamlib_port_t *); -} rot_backend_list[ROT_BACKEND_MAX] = { +} rot_backend_list[ROT_BACKEND_MAX] = +{ { ROT_DUMMY, ROT_BACKEND_DUMMY, ROT_FUNCNAMA(dummy) }, { ROT_EASYCOMM, ROT_BACKEND_EASYCOMM, ROT_FUNCNAMA(easycomm) }, { ROT_FODTRACK, ROT_BACKEND_FODTRACK, ROT_FUNCNAMA(fodtrack) }, @@ -131,7 +134,8 @@ static struct { * This struct to keep track of known rot models. * It is chained, and used in a hash table, see below. */ -struct rot_list { +struct rot_list +{ const struct rot_caps *caps; struct rot_list *next; }; @@ -159,7 +163,8 @@ int HAMLIB_API rot_register(const struct rot_caps *caps) int hval; struct rot_list *p; - if (!caps) { + if (!caps) + { return -RIG_EINVAL; } @@ -167,7 +172,8 @@ int HAMLIB_API rot_register(const struct rot_caps *caps) #ifndef DONT_WANT_DUP_CHECK - if (rot_get_caps(caps->rot_model) != NULL) { + if (rot_get_caps(caps->rot_model) != NULL) + { return -RIG_EINVAL; } @@ -175,7 +181,8 @@ int HAMLIB_API rot_register(const struct rot_caps *caps) p = (struct rot_list *)malloc(sizeof(struct rot_list)); - if (!p) { + if (!p) + { return -RIG_ENOMEM; } @@ -193,12 +200,14 @@ int HAMLIB_API rot_register(const struct rot_caps *caps) * Get rot capabilities. * i.e. rot_hash_table lookup */ -const struct rot_caps * HAMLIB_API rot_get_caps(rot_model_t rot_model) +const struct rot_caps *HAMLIB_API rot_get_caps(rot_model_t rot_model) { struct rot_list *p; - for (p = rot_hash_table[HASH_FUNC(rot_model)]; p; p = p->next) { - if (p->caps->rot_model == rot_model) { + for (p = rot_hash_table[HASH_FUNC(rot_model)]; p; p = p->next) + { + if (p->caps->rot_model == rot_model) + { return p->caps; } } @@ -216,9 +225,11 @@ static int rot_lookup_backend(rot_model_t rot_model) { int i; - for (i = 0; i < ROT_BACKEND_MAX && rot_backend_list[i].be_name; i++) { + for (i = 0; i < ROT_BACKEND_MAX && rot_backend_list[i].be_name; i++) + { if (ROT_BACKEND_NUM(rot_model) == - rot_backend_list[i].be_num) { + rot_backend_list[i].be_num) + { return i; } } @@ -242,7 +253,8 @@ int HAMLIB_API rot_check_backend(rot_model_t rot_model) /* already loaded ? */ caps = rot_get_caps(rot_model); - if (caps) { + if (caps) + { return RIG_OK; } @@ -251,11 +263,13 @@ int HAMLIB_API rot_check_backend(rot_model_t rot_model) /* * Never heard about this backend family! */ - if (be_idx == -1) { + if (be_idx == -1) + { rot_debug(RIG_DEBUG_VERBOSE, "%s: unsupported backend %d for model %d\n", __func__, - ROT_BACKEND_NUM(rot_model), rot_model); + ROT_BACKEND_NUM(rot_model), + rot_model); return -RIG_ENAVAIL; } @@ -274,11 +288,16 @@ int HAMLIB_API rot_unregister(rot_model_t rot_model) hval = HASH_FUNC(rot_model); q = NULL; - for (p = rot_hash_table[hval]; p; p = p->next) { - if (p->caps->rot_model == rot_model) { - if (q == NULL) { + for (p = rot_hash_table[hval]; p; p = p->next) + { + if (p->caps->rot_model == rot_model) + { + if (q == NULL) + { rot_hash_table[hval] = p->next; - } else { + } + else + { q->next = p->next; } @@ -297,19 +316,23 @@ int HAMLIB_API rot_unregister(rot_model_t rot_model) * rot_list_foreach * executes cfunc on all the elements stored in the rot hash list */ -int HAMLIB_API rot_list_foreach(int (*cfunc)(const struct rot_caps *, rig_ptr_t), +int HAMLIB_API rot_list_foreach(int (*cfunc)(const struct rot_caps *, + rig_ptr_t), rig_ptr_t data) { struct rot_list *p; int i; - if (!cfunc) { + if (!cfunc) + { return -RIG_EINVAL; } - for (i = 0; i < ROTLSTHASHSZ; i++) { + for (i = 0; i < ROTLSTHASHSZ; i++) + { for (p = rot_hash_table[i]; p; p = p->next) - if ((*cfunc)(p->caps, data) == 0) { + if ((*cfunc)(p->caps, data) == 0) + { return RIG_OK; } } @@ -327,11 +350,14 @@ rot_model_t HAMLIB_API rot_probe_all(hamlib_port_t *p) int i; rot_model_t rot_model; - for (i = 0; i < ROT_BACKEND_MAX && rot_backend_list[i].be_name; i++) { - if (rot_backend_list[i].be_probe) { + for (i = 0; i < ROT_BACKEND_MAX && rot_backend_list[i].be_name; i++) + { + if (rot_backend_list[i].be_probe) + { rot_model = (*rot_backend_list[i].be_probe)(p); - if (rot_model != ROT_MODEL_NONE) { + if (rot_model != ROT_MODEL_NONE) + { return rot_model; } } @@ -345,7 +371,8 @@ int rot_load_all_backends() { int i; - for (i = 0; i < ROT_BACKEND_MAX && rot_backend_list[i].be_name; i++) { + for (i = 0; i < ROT_BACKEND_MAX && rot_backend_list[i].be_name; i++) + { rot_load_backend(rot_backend_list[i].be_name); } @@ -363,11 +390,14 @@ int HAMLIB_API rot_load_backend(const char *be_name) int (*be_init)(rig_ptr_t); int i; - for (i = 0; i < ROT_BACKEND_MAX && rot_backend_list[i].be_name; i++) { - if (!strcmp(be_name, rot_backend_list[i].be_name)) { + for (i = 0; i < ROT_BACKEND_MAX && rot_backend_list[i].be_name; i++) + { + if (!strcmp(be_name, rot_backend_list[i].be_name)) + { be_init = rot_backend_list[i].be_init; - if (be_init == NULL) { + if (be_init == NULL) + { printf("Null\n"); return -EINVAL; } diff --git a/src/rotator.c b/src/rotator.c index 9383995c3..02467e729 100644 --- a/src/rotator.c +++ b/src/rotator.c @@ -35,14 +35,15 @@ */ -/*! \page rot Rotator interface +/** + * \page rot Rotator interface * * Rotator can be any kind of azimuth or azimuth and elevation controlled * antenna system. */ #ifdef HAVE_CONFIG_H -#include "config.h" +# include "config.h" #endif #include @@ -53,7 +54,6 @@ #include #include - #include #include "serial.h" #include "parallel.h" @@ -66,21 +66,21 @@ #ifndef DOC_HIDDEN #if defined(WIN32) && !defined(__CYGWIN__) -#define DEFAULT_SERIAL_PORT "\\\\.\\COM1" +# define DEFAULT_SERIAL_PORT "\\\\.\\COM1" #elif BSD -#define DEFAULT_SERIAL_PORT "/dev/cuaa0" +# define DEFAULT_SERIAL_PORT "/dev/cuaa0" #elif MACOSX -#define DEFAULT_SERIAL_PORT "/dev/cu.usbserial" +# define DEFAULT_SERIAL_PORT "/dev/cu.usbserial" #else -#define DEFAULT_SERIAL_PORT "/dev/ttyS0" +# define DEFAULT_SERIAL_PORT "/dev/ttyS0" #endif #if defined(WIN32) -#define DEFAULT_PARALLEL_PORT "\\\\.\\$VDMLPT1" +# define DEFAULT_PARALLEL_PORT "\\\\.\\$VDMLPT1" #elif defined(HAVE_DEV_PPBUS_PPI_H) -#define DEFAULT_PARALLEL_PORT "/dev/ppi0" +# define DEFAULT_PARALLEL_PORT "/dev/ppi0" #else -#define DEFAULT_PARALLEL_PORT "/dev/parport0" +# define DEFAULT_PARALLEL_PORT "/dev/parport0" #endif #define CHECK_ROT_ARG(r) (!(r) || !(r)->caps || !(r)->state.comm_state) @@ -89,7 +89,8 @@ /* * Data structure to track the opened rot (by rot_open) */ -struct opened_rot_l { +struct opened_rot_l +{ ROT *rot; struct opened_rot_l *next; }; @@ -105,7 +106,8 @@ static int add_opened_rot(ROT *rot) struct opened_rot_l *p; p = (struct opened_rot_l *)malloc(sizeof(struct opened_rot_l)); - if (!p) { + if (!p) + { return -RIG_ENOMEM; } @@ -121,11 +123,16 @@ static int remove_opened_rot(ROT *rot) struct opened_rot_l *p, *q; q = NULL; - for (p = opened_rot_list; p; p = p->next) { - if (p->rot == rot) { - if (q == NULL) { + for (p = opened_rot_list; p; p = p->next) + { + if (p->rot == rot) + { + if (q == NULL) + { opened_rot_list = opened_rot_list->next; - } else { + } + else + { q->next = p->next; } @@ -146,15 +153,13 @@ static int remove_opened_rot(ROT *rot) * \param cfunc The function to be executed on each rot * \param data Data pointer to be passed to cfunc() * - * Calls cfunc() function for each opened rot. - * The contents of the opened rot table - * is processed in random order according to a function - * pointed to by \a cfunc, whic is called with two arguments, - * the first pointing to the #ROT handle, the second - * to a data pointer \a data. - * If \a data is not needed, then it can be set to NULL. - * The processing of the opened rot table is stopped - * when cfunc() returns 0. + * Calls cfunc() function for each opened rot. The contents of the opened + * rot table is processed in random order according to a function pointed to + * by \a cfunc, whic is called with two arguments, the first pointing to the + * #ROT handle, the second to a data pointer \a data. + * + * If \a data is not needed, then it can be set to NULL. The processing of + * the opened rot table is stopped when cfunc() returns 0. * \internal * * \return always RIG_OK. @@ -165,8 +170,10 @@ int foreach_opened_rot(int (*cfunc)(ROT *, rig_ptr_t), rig_ptr_t data) rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - for (p = opened_rot_list; p; p = p->next) { - if ((*cfunc)(p->rot, data) == 0) { + for (p = opened_rot_list; p; p = p->next) + { + if ((*cfunc)(p->rot, data) == 0) + { return RIG_OK; } } @@ -187,7 +194,7 @@ int foreach_opened_rot(int (*cfunc)(ROT *, rig_ptr_t), rig_ptr_t data) * * \sa rot_cleanup(), rot_open() */ -ROT *HAMLIB_API rot_init(rot_model_t rot_model) +ROT * HAMLIB_API rot_init(rot_model_t rot_model) { ROT *rot; const struct rot_caps *caps; @@ -200,7 +207,8 @@ ROT *HAMLIB_API rot_init(rot_model_t rot_model) caps = rot_get_caps(rot_model); - if (!caps) { + if (!caps) + { return NULL; } @@ -210,7 +218,8 @@ ROT *HAMLIB_API rot_init(rot_model_t rot_model) */ rot = calloc(1, sizeof(ROT)); - if (rot == NULL) { + if (rot == NULL) + { /* * FIXME: how can the caller know it's a memory shortage, * and not "rot not found" ? @@ -236,7 +245,8 @@ ROT *HAMLIB_API rot_init(rot_model_t rot_model) rs->rotport.timeout = caps->timeout; rs->rotport.retry = caps->retry; - switch (caps->port_type) { + switch (caps->port_type) + { case RIG_PORT_SERIAL: strncpy(rs->rotport.pathname, DEFAULT_SERIAL_PORT, FILPATHLEN - 1); rs->rotport.parm.serial.rate = caps->serial_rate_max; /* fastest ! */ @@ -271,10 +281,12 @@ ROT *HAMLIB_API rot_init(rot_model_t rot_model) * This must be done only once defaults are setup, * so the backend init can override rot_state. */ - if (caps->rot_init != NULL) { + if (caps->rot_init != NULL) + { retcode = caps->rot_init(rot); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { rot_debug(RIG_DEBUG_VERBOSE, "%s: backend_init failed!\n", __func__); @@ -312,24 +324,28 @@ int HAMLIB_API rot_open(ROT *rot) rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rot || !rot->caps) { + if (!rot || !rot->caps) + { return -RIG_EINVAL; } caps = rot->caps; rs = &rot->state; - if (rs->comm_state) { + if (rs->comm_state) + { return -RIG_EINVAL; } rs->rotport.fd = -1; - switch (rs->rotport.type.rig) { + switch (rs->rotport.type.rig) + { case RIG_PORT_SERIAL: status = serial_open(&rs->rotport); - if (status != 0) { + if (status != 0) + { return status; } @@ -338,7 +354,8 @@ int HAMLIB_API rot_open(ROT *rot) case RIG_PORT_PARALLEL: status = par_open(&rs->rotport); - if (status < 0) { + if (status < 0) + { return status; } @@ -347,7 +364,8 @@ int HAMLIB_API rot_open(ROT *rot) case RIG_PORT_DEVICE: status = open(rs->rotport.pathname, O_RDWR, 0); - if (status < 0) { + if (status < 0) + { return -RIG_EIO; } @@ -357,7 +375,8 @@ int HAMLIB_API rot_open(ROT *rot) case RIG_PORT_USB: status = usb_port_open(&rs->rotport); - if (status < 0) { + if (status < 0) + { return status; } @@ -372,7 +391,8 @@ int HAMLIB_API rot_open(ROT *rot) /* FIXME: default port */ status = network_open(&rs->rotport, 4533); - if (status < 0) { + if (status < 0) + { return status; } @@ -391,10 +411,12 @@ int HAMLIB_API rot_open(ROT *rot) * Maybe the backend has something to initialize * In case of failure, just close down and report error code. */ - if (caps->rot_open != NULL) { + if (caps->rot_open != NULL) + { status = caps->rot_open(rot); - if (status != RIG_OK) { + if (status != RIG_OK) + { return status; } } @@ -423,14 +445,16 @@ int HAMLIB_API rot_close(ROT *rot) rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rot || !rot->caps) { + if (!rot || !rot->caps) + { return -RIG_EINVAL; } caps = rot->caps; rs = &rot->state; - if (!rs->comm_state) { + if (!rs->comm_state) + { return -RIG_EINVAL; } @@ -438,13 +462,16 @@ int HAMLIB_API rot_close(ROT *rot) * Let the backend say 73s to the rot. * and ignore the return code. */ - if (caps->rot_close) { + if (caps->rot_close) + { caps->rot_close(rot); } - if (rs->rotport.fd != -1) { - switch (rs->rotport.type.rig) { + if (rs->rotport.fd != -1) + { + switch (rs->rotport.type.rig) + { case RIG_PORT_SERIAL: ser_close(&rs->rotport); break; @@ -494,21 +521,24 @@ int HAMLIB_API rot_cleanup(ROT *rot) { rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rot || !rot->caps) { + if (!rot || !rot->caps) + { return -RIG_EINVAL; } /* * check if they forgot to close the rot */ - if (rot->state.comm_state) { + if (rot->state.comm_state) + { rot_close(rot); } /* * basically free up the priv struct */ - if (rot->caps->rot_cleanup) { + if (rot->caps->rot_cleanup) + { rot->caps->rot_cleanup(rot); } @@ -532,7 +562,8 @@ int HAMLIB_API rot_cleanup(ROT *rot) * * \sa rot_get_position() */ -int HAMLIB_API rot_set_position(ROT *rot, azimuth_t azimuth, +int HAMLIB_API rot_set_position(ROT *rot, + azimuth_t azimuth, elevation_t elevation) { const struct rot_caps *caps; @@ -540,7 +571,8 @@ int HAMLIB_API rot_set_position(ROT *rot, azimuth_t azimuth, rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_ROT_ARG(rot)) { + if (CHECK_ROT_ARG(rot)) + { return -RIG_EINVAL; } @@ -550,11 +582,13 @@ int HAMLIB_API rot_set_position(ROT *rot, azimuth_t azimuth, if (azimuth < rs->min_az || azimuth > rs->max_az || elevation < rs->min_el - || elevation > rs->max_el) { - return -RIG_EINVAL; + || elevation > rs->max_el) + { + return -RIG_EINVAL; } - if (caps->set_position == NULL) { + if (caps->set_position == NULL) + { return -RIG_ENAVAIL; } @@ -576,20 +610,23 @@ int HAMLIB_API rot_set_position(ROT *rot, azimuth_t azimuth, * * \sa rot_set_position() */ -int HAMLIB_API rot_get_position(ROT *rot, azimuth_t *azimuth, +int HAMLIB_API rot_get_position(ROT *rot, + azimuth_t *azimuth, elevation_t *elevation) { const struct rot_caps *caps; rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_ROT_ARG(rot) || !azimuth || !elevation) { + if (CHECK_ROT_ARG(rot) || !azimuth || !elevation) + { return -RIG_EINVAL; } caps = rot->caps; - if (caps->get_position == NULL) { + if (caps->get_position == NULL) + { return -RIG_ENAVAIL; } @@ -614,13 +651,15 @@ int HAMLIB_API rot_park(ROT *rot) rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_ROT_ARG(rot)) { + if (CHECK_ROT_ARG(rot)) + { return -RIG_EINVAL; } caps = rot->caps; - if (caps->park == NULL) { + if (caps->park == NULL) + { return -RIG_ENAVAIL; } @@ -645,13 +684,15 @@ int HAMLIB_API rot_stop(ROT *rot) rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_ROT_ARG(rot)) { + if (CHECK_ROT_ARG(rot)) + { return -RIG_EINVAL; } caps = rot->caps; - if (caps->stop == NULL) { + if (caps->stop == NULL) + { return -RIG_ENAVAIL; } @@ -677,13 +718,15 @@ int HAMLIB_API rot_reset(ROT *rot, rot_reset_t reset) rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_ROT_ARG(rot)) { + if (CHECK_ROT_ARG(rot)) + { return -RIG_EINVAL; } caps = rot->caps; - if (caps->reset == NULL) { + if (caps->reset == NULL) + { return -RIG_ENAVAIL; } @@ -706,13 +749,15 @@ int HAMLIB_API rot_move(ROT *rot, int direction, int speed) rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_ROT_ARG(rot)) { + if (CHECK_ROT_ARG(rot)) + { return -RIG_EINVAL; } caps = rot->caps; - if (caps->move == NULL) { + if (caps->move == NULL) + { return -RIG_ENAVAIL; } @@ -731,15 +776,17 @@ int HAMLIB_API rot_move(ROT *rot, int direction, int speed) * if the operation has been sucessful, otherwise NULL if an error occured * or get_info not part of capabilities. */ -const char *HAMLIB_API rot_get_info(ROT *rot) +const char * HAMLIB_API rot_get_info(ROT *rot) { rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_ROT_ARG(rot)) { + if (CHECK_ROT_ARG(rot)) + { return NULL; } - if (rot->caps->get_info == NULL) { + if (rot->caps->get_info == NULL) + { return NULL; } diff --git a/src/serial.c b/src/serial.c index 9e30e2ec4..c4e384af7 100644 --- a/src/serial.c +++ b/src/serial.c @@ -33,7 +33,7 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +# include "config.h" #endif #include @@ -45,33 +45,34 @@ #include #include #include + #ifdef HAVE_SYS_IOCTL_H -#include +# include #endif #ifdef HAVE_SYS_PARAM_H -#include +# include #endif #ifdef HAVE_TERMIOS_H -#include /* POSIX terminal control definitions */ +# include /* POSIX terminal control definitions */ #else -#ifdef HAVE_TERMIO_H -#include -#else /* sgtty */ -#ifdef HAVE_SGTTY_H -#include -#endif -#endif +# ifdef HAVE_TERMIO_H +# include +# else /* sgtty */ +# ifdef HAVE_SGTTY_H +# include +# endif +# endif #endif #if defined(WIN32) && !defined(HAVE_TERMIOS_H) -#include "win32termios.h" -#define HAVE_TERMIOS_H 1 /* we have replacement */ +# include "win32termios.h" +# define HAVE_TERMIOS_H 1 /* we have replacement */ #else -#define OPEN open -#define CLOSE close -#define IOCTL ioctl +# define OPEN open +# define CLOSE close +# define IOCTL ioctl #endif #include @@ -79,7 +80,7 @@ #include "misc.h" #ifdef HAVE_SYS_IOCCOM_H -#include +# include #endif #include "microham.h" @@ -87,21 +88,27 @@ static int uh_ptt_fd = -1; static int uh_radio_fd = -1; -int is_uh_radio_fd(int fd) { - /* - * This function simply returns TRUE if the argument - * matches uh_radio_fd and is >= 0 - * - * This function is only used in the WIN32 case and implements - * access "from outside" to uh_radio_fd. - */ - if (uh_radio_fd >= 0 && uh_radio_fd == fd) { + +/* + * This function simply returns TRUE if the argument matches uh_radio_fd and + * is >= 0 + * + * This function is only used in the WIN32 case and implements access "from + * outside" to uh_radio_fd. + */ +int is_uh_radio_fd(int fd) +{ + if (uh_radio_fd >= 0 && uh_radio_fd == fd) + { return 1; - } else { + } + else + { return 0; } } + /** * \brief Open serial port using rig.state data * \param rp port data structure (must spec port id eg /dev/ttyS1) @@ -115,7 +122,8 @@ int HAMLIB_API serial_open(hamlib_port_t *rp) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rp) { + if (!rp) + { return -RIG_EINVAL; } @@ -166,7 +174,8 @@ int HAMLIB_API serial_open(hamlib_port_t *rp) */ fd = OPEN(rp->pathname, O_RDWR | O_NOCTTY | O_NDELAY); - if (fd == -1) { + if (fd == -1) + { /* Could not open the port. */ rig_debug(RIG_DEBUG_ERR, "%s: Unable to open %s - %s\n", @@ -180,7 +189,8 @@ int HAMLIB_API serial_open(hamlib_port_t *rp) err = serial_setup(rp); - if (err != RIG_OK) { + if (err != RIG_OK) + { CLOSE(fd); return err; } @@ -206,12 +216,13 @@ int HAMLIB_API serial_setup(hamlib_port_t *rp) #elif defined(HAVE_SGTTY_H) struct sgttyb sg; #else -#error "No term control supported!" +# error "No term control supported!" #endif rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rp) { + if (!rp) + { return -RIG_EINVAL; } @@ -236,7 +247,8 @@ int HAMLIB_API serial_setup(hamlib_port_t *rp) /* * Set the baud rates to requested values */ - switch (rp->parm.serial.rate) { + switch (rp->parm.serial.rate) + { case 150: speed = B150; /* yikes... */ break; @@ -309,7 +321,8 @@ int HAMLIB_API serial_setup(hamlib_port_t *rp) * Set data to requested values. * */ - switch (rp->parm.serial.data_bits) { + switch (rp->parm.serial.data_bits) + { case 7: options.c_cflag &= ~CSIZE; options.c_cflag |= CS7; @@ -335,7 +348,8 @@ int HAMLIB_API serial_setup(hamlib_port_t *rp) * Set stop bits to requested values. * */ - switch (rp->parm.serial.stop_bits) { + switch (rp->parm.serial.stop_bits) + { case 1: options.c_cflag &= ~CSTOPB; break; @@ -359,7 +373,8 @@ int HAMLIB_API serial_setup(hamlib_port_t *rp) * Set parity to requested values. * */ - switch (rp->parm.serial.parity) { + switch (rp->parm.serial.parity) + { case RIG_PARITY_NONE: options.c_cflag &= ~PARENB; break; @@ -403,7 +418,8 @@ int HAMLIB_API serial_setup(hamlib_port_t *rp) * Set flow control to requested mode * */ - switch (rp->parm.serial.handshake) { + switch (rp->parm.serial.handshake) + { case RIG_HANDSHAKE_NONE: options.c_cflag &= ~CRTSCTS; options.c_iflag &= ~IXON; @@ -461,7 +477,8 @@ int HAMLIB_API serial_setup(hamlib_port_t *rp) */ #if defined(HAVE_TERMIOS_H) - if (tcsetattr(fd, TCSANOW, &options) == -1) { + if (tcsetattr(fd, TCSANOW, &options) == -1) + { rig_debug(RIG_DEBUG_ERR, "%s: tcsetattr failed: %s\n", __func__, @@ -473,7 +490,8 @@ int HAMLIB_API serial_setup(hamlib_port_t *rp) #elif defined(HAVE_TERMIO_H) - if (IOCTL(fd, TCSETA, &options) == -1) { + if (IOCTL(fd, TCSETA, &options) == -1) + { rig_debug(RIG_DEBUG_ERR, "%s: ioctl(TCSETA) failed: %s\n", __func__, @@ -484,8 +502,10 @@ int HAMLIB_API serial_setup(hamlib_port_t *rp) } #else + /* sgtty */ - if (IOCTL(fd, TIOCSETP, &sg) == -1) { + if (IOCTL(fd, TIOCSETP, &sg) == -1) + { rig_debug(RIG_DEBUG_ERR, "%s: ioctl(TIOCSETP) failed: %s\n", __func__, @@ -629,10 +649,14 @@ int HAMLIB_API ser_set_rts(hamlib_port_t *p, int state) #else rc = IOCTL(p->fd, TIOCMGET, &y); - if (rc >= 0) { - if (state) { + if (rc >= 0) + { + if (state) + { y |= TIOCM_RTS; - } else { + } + else + { y &= ~TIOCM_RTS; } @@ -641,7 +665,8 @@ int HAMLIB_API ser_set_rts(hamlib_port_t *p, int state) #endif - if (rc < 0) { + if (rc < 0) + { rig_debug(RIG_DEBUG_ERR, "%s: Cannot change RTS - %s\n", __func__, @@ -707,10 +732,14 @@ int HAMLIB_API ser_set_dtr(hamlib_port_t *p, int state) #else rc = IOCTL(p->fd, TIOCMGET, &y); - if (rc >= 0) { - if (state) { + if (rc >= 0) + { + if (state) + { y |= TIOCM_DTR; - } else { + } + else + { y &= ~TIOCM_DTR; } @@ -719,7 +748,8 @@ int HAMLIB_API ser_set_dtr(hamlib_port_t *p, int state) #endif - if (rc < 0) { + if (rc < 0) + { rig_debug(RIG_DEBUG_ERR, "%s: Cannot change DTR - %s\n", __func__, diff --git a/src/settings.c b/src/settings.c index 16461a13f..bfd7f425b 100644 --- a/src/settings.c +++ b/src/settings.c @@ -34,7 +34,7 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +# include "config.h" #endif #include @@ -51,7 +51,7 @@ #ifndef DOC_HIDDEN -#define CHECK_RIG_ARG(r) (!(r) || !(r)->caps || !(r)->state.comm_state) +# define CHECK_RIG_ARG(r) (!(r) || !(r)->caps || !(r)->state.comm_state) #endif /* !DOC_HIDDEN */ @@ -81,30 +81,35 @@ int HAMLIB_API rig_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig)) { + if (CHECK_RIG_ARG(rig)) + { return -RIG_EINVAL; } caps = rig->caps; - if (caps->set_level == NULL || !rig_has_set_level(rig, level)) { + if (caps->set_level == NULL || !rig_has_set_level(rig, level)) + { return -RIG_ENAVAIL; } if ((caps->targetable_vfo & RIG_TARGETABLE_PURE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) { - return caps->set_level(rig, vfo, level, val); + || vfo == rig->state.current_vfo) + { + return caps->set_level(rig, vfo, level, val); } - if (!caps->set_vfo) { + if (!caps->set_vfo) + { return -RIG_ENTARGET; } curr_vfo = rig->state.current_vfo; retcode = caps->set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } @@ -146,13 +151,15 @@ int HAMLIB_API rig_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig) || !val) { + if (CHECK_RIG_ARG(rig) || !val) + { return -RIG_EINVAL; } caps = rig->caps; - if (caps->get_level == NULL || !rig_has_get_level(rig, level)) { + if (caps->get_level == NULL || !rig_has_get_level(rig, level)) + { return -RIG_ENAVAIL; } @@ -162,36 +169,41 @@ int HAMLIB_API rig_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) if (level == RIG_LEVEL_STRENGTH && (caps->has_get_level & RIG_LEVEL_STRENGTH) == 0 && rig_has_get_level(rig, RIG_LEVEL_RAWSTR) - && rig->state.str_cal.size) { + && rig->state.str_cal.size) + { - value_t rawstr; + value_t rawstr; - retcode = rig_get_level(rig, vfo, RIG_LEVEL_RAWSTR, &rawstr); + retcode = rig_get_level(rig, vfo, RIG_LEVEL_RAWSTR, &rawstr); - if (retcode != RIG_OK) { - return retcode; - } + if (retcode != RIG_OK) + { + return retcode; + } - val->i = (int)rig_raw2val(rawstr.i, &rig->state.str_cal); - return RIG_OK; + val->i = (int)rig_raw2val(rawstr.i, &rig->state.str_cal); + return RIG_OK; } if ((caps->targetable_vfo & RIG_TARGETABLE_PURE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) { + || vfo == rig->state.current_vfo) + { - return caps->get_level(rig, vfo, level, val); + return caps->get_level(rig, vfo, level, val); } - if (!caps->set_vfo) { + if (!caps->set_vfo) + { return -RIG_ENTARGET; } curr_vfo = rig->state.current_vfo; retcode = caps->set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } @@ -221,11 +233,13 @@ int HAMLIB_API rig_set_parm(RIG *rig, setting_t parm, value_t val) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig)) { + if (CHECK_RIG_ARG(rig)) + { return -RIG_EINVAL; } - if (rig->caps->set_parm == NULL || !rig_has_set_parm(rig, parm)) { + if (rig->caps->set_parm == NULL || !rig_has_set_parm(rig, parm)) + { return -RIG_ENAVAIL; } @@ -253,11 +267,13 @@ int HAMLIB_API rig_get_parm(RIG *rig, setting_t parm, value_t *val) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig) || !val) { + if (CHECK_RIG_ARG(rig) || !val) + { return -RIG_EINVAL; } - if (rig->caps->get_parm == NULL || !rig_has_get_parm(rig, parm)) { + if (rig->caps->get_parm == NULL || !rig_has_get_parm(rig, parm)) + { return -RIG_ENAVAIL; } @@ -285,7 +301,8 @@ setting_t HAMLIB_API rig_has_get_level(RIG *rig, setting_t level) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !rig->caps) { + if (!rig || !rig->caps) + { return 0; } @@ -313,7 +330,8 @@ setting_t HAMLIB_API rig_has_set_level(RIG *rig, setting_t level) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !rig->caps) { + if (!rig || !rig->caps) + { return 0; } @@ -341,7 +359,8 @@ setting_t HAMLIB_API rig_has_get_parm(RIG *rig, setting_t parm) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !rig->caps) { + if (!rig || !rig->caps) + { return 0; } @@ -369,7 +388,8 @@ setting_t HAMLIB_API rig_has_set_parm(RIG *rig, setting_t parm) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !rig->caps) { + if (!rig || !rig->caps) + { return 0; } @@ -397,7 +417,8 @@ setting_t HAMLIB_API rig_has_get_func(RIG *rig, setting_t func) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !rig->caps) { + if (!rig || !rig->caps) + { return 0; } @@ -425,7 +446,8 @@ setting_t HAMLIB_API rig_has_set_func(RIG *rig, setting_t func) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !rig->caps) { + if (!rig || !rig->caps) + { return 0; } @@ -459,36 +481,42 @@ int HAMLIB_API rig_set_func(RIG *rig, vfo_t vfo, setting_t func, int status) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig)) { + if (CHECK_RIG_ARG(rig)) + { return -RIG_EINVAL; } caps = rig->caps; - if (caps->set_func == NULL || !rig_has_set_func(rig, func)) { + if (caps->set_func == NULL || !rig_has_set_func(rig, func)) + { return -RIG_ENAVAIL; } if ((caps->targetable_vfo & RIG_TARGETABLE_FUNC) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) { + || vfo == rig->state.current_vfo) + { - return caps->set_func(rig, vfo, func, status); + return caps->set_func(rig, vfo, func, status); } - if (!caps->set_vfo) { + if (!caps->set_vfo) + { return -RIG_ENTARGET; } curr_vfo = rig->state.current_vfo; retcode = caps->set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } retcode = caps->set_func(rig, vfo, func, status); caps->set_vfo(rig, curr_vfo); + return retcode; } @@ -520,31 +548,36 @@ int HAMLIB_API rig_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig) || !func) { + if (CHECK_RIG_ARG(rig) || !func) + { return -RIG_EINVAL; } caps = rig->caps; - if (caps->get_func == NULL || !rig_has_get_func(rig, func)) { + if (caps->get_func == NULL || !rig_has_get_func(rig, func)) + { return -RIG_ENAVAIL; } if ((caps->targetable_vfo & RIG_TARGETABLE_FUNC) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) { + || vfo == rig->state.current_vfo) + { - return caps->get_func(rig, vfo, func, status); + return caps->get_func(rig, vfo, func, status); } - if (!caps->set_vfo) { + if (!caps->set_vfo) + { return -RIG_ENTARGET; } curr_vfo = rig->state.current_vfo; retcode = caps->set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } @@ -570,7 +603,9 @@ int HAMLIB_API rig_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status) * * \sa rig_get_ext_level() */ -int HAMLIB_API rig_set_ext_level(RIG *rig, vfo_t vfo, token_t token, +int HAMLIB_API rig_set_ext_level(RIG *rig, + vfo_t vfo, + token_t token, value_t val) { const struct rig_caps *caps; @@ -579,31 +614,36 @@ int HAMLIB_API rig_set_ext_level(RIG *rig, vfo_t vfo, token_t token, rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig)) { + if (CHECK_RIG_ARG(rig)) + { return -RIG_EINVAL; } caps = rig->caps; - if (caps->set_ext_level == NULL) { + if (caps->set_ext_level == NULL) + { return -RIG_ENAVAIL; } if ((caps->targetable_vfo & RIG_TARGETABLE_PURE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) { + || vfo == rig->state.current_vfo) + { - return caps->set_ext_level(rig, vfo, token, val); + return caps->set_ext_level(rig, vfo, token, val); } - if (!caps->set_vfo) { + if (!caps->set_vfo) + { return -RIG_ENTARGET; } curr_vfo = rig->state.current_vfo; retcode = caps->set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } @@ -629,7 +669,9 @@ int HAMLIB_API rig_set_ext_level(RIG *rig, vfo_t vfo, token_t token, * * \sa rig_set_ext_level() */ -int HAMLIB_API rig_get_ext_level(RIG *rig, vfo_t vfo, token_t token, +int HAMLIB_API rig_get_ext_level(RIG *rig, + vfo_t vfo, + token_t token, value_t *val) { const struct rig_caps *caps; @@ -638,31 +680,36 @@ int HAMLIB_API rig_get_ext_level(RIG *rig, vfo_t vfo, token_t token, rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig) || !val) { + if (CHECK_RIG_ARG(rig) || !val) + { return -RIG_EINVAL; } caps = rig->caps; - if (caps->get_ext_level == NULL) { + if (caps->get_ext_level == NULL) + { return -RIG_ENAVAIL; } if ((caps->targetable_vfo & RIG_TARGETABLE_PURE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) { + || vfo == rig->state.current_vfo) + { - return caps->get_ext_level(rig, vfo, token, val); + return caps->get_ext_level(rig, vfo, token, val); } - if (!caps->set_vfo) { + if (!caps->set_vfo) + { return -RIG_ENTARGET; } curr_vfo = rig->state.current_vfo; retcode = caps->set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } @@ -691,11 +738,13 @@ int HAMLIB_API rig_set_ext_parm(RIG *rig, token_t token, value_t val) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig)) { + if (CHECK_RIG_ARG(rig)) + { return -RIG_EINVAL; } - if (rig->caps->set_ext_parm == NULL) { + if (rig->caps->set_ext_parm == NULL) + { return -RIG_ENAVAIL; } @@ -721,11 +770,13 @@ int HAMLIB_API rig_get_ext_parm(RIG *rig, token_t token, value_t *val) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig) || !val) { + if (CHECK_RIG_ARG(rig) || !val) + { return -RIG_EINVAL; } - if (rig->caps->get_ext_parm == NULL) { + if (rig->caps->get_ext_parm == NULL) + { return -RIG_ENAVAIL; } @@ -748,8 +799,10 @@ int HAMLIB_API rig_setting2idx(setting_t s) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - for (i = 0; i < RIG_SETTING_MAX; i++) { - if (s & rig_idx2setting(i)) { + for (i = 0; i < RIG_SETTING_MAX; i++) + { + if (s & rig_idx2setting(i)) + { return i; } } diff --git a/src/tones.c b/src/tones.c index 4c4b5b760..ff1beea7d 100644 --- a/src/tones.c +++ b/src/tones.c @@ -31,7 +31,7 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +# include "config.h" #endif #include @@ -105,31 +105,36 @@ int HAMLIB_API rig_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig)) { + if (CHECK_RIG_ARG(rig)) + { return -RIG_EINVAL; } caps = rig->caps; - if (caps->set_ctcss_tone == NULL) { + if (caps->set_ctcss_tone == NULL) + { return -RIG_ENAVAIL; } if ((caps->targetable_vfo & RIG_TARGETABLE_TONE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) { + || vfo == rig->state.current_vfo) + { - return caps->set_ctcss_tone(rig, vfo, tone); + return caps->set_ctcss_tone(rig, vfo, tone); } - if (!caps->set_vfo) { + if (!caps->set_vfo) + { return -RIG_ENTARGET; } curr_vfo = rig->state.current_vfo; retcode = caps->set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } @@ -167,31 +172,36 @@ int HAMLIB_API rig_get_ctcss_tone(RIG *rig, vfo_t vfo, tone_t *tone) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig) || !tone) { + if (CHECK_RIG_ARG(rig) || !tone) + { return -RIG_EINVAL; } caps = rig->caps; - if (caps->get_ctcss_tone == NULL) { + if (caps->get_ctcss_tone == NULL) + { return -RIG_ENAVAIL; } if ((caps->targetable_vfo & RIG_TARGETABLE_TONE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) { + || vfo == rig->state.current_vfo) + { - return caps->get_ctcss_tone(rig, vfo, tone); + return caps->get_ctcss_tone(rig, vfo, tone); } - if (!caps->set_vfo) { + if (!caps->set_vfo) + { return -RIG_ENTARGET; } curr_vfo = rig->state.current_vfo; retcode = caps->set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } @@ -225,31 +235,36 @@ int HAMLIB_API rig_set_dcs_code(RIG *rig, vfo_t vfo, tone_t code) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig)) { + if (CHECK_RIG_ARG(rig)) + { return -RIG_EINVAL; } caps = rig->caps; - if (caps->set_dcs_code == NULL) { + if (caps->set_dcs_code == NULL) + { return -RIG_ENAVAIL; } if ((caps->targetable_vfo & RIG_TARGETABLE_TONE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) { + || vfo == rig->state.current_vfo) + { - return caps->set_dcs_code(rig, vfo, code); + return caps->set_dcs_code(rig, vfo, code); } - if (!caps->set_vfo) { + if (!caps->set_vfo) + { return -RIG_ENTARGET; } curr_vfo = rig->state.current_vfo; retcode = caps->set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } @@ -282,31 +297,36 @@ int HAMLIB_API rig_get_dcs_code(RIG *rig, vfo_t vfo, tone_t *code) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig) || !code) { + if (CHECK_RIG_ARG(rig) || !code) + { return -RIG_EINVAL; } caps = rig->caps; - if (caps->get_dcs_code == NULL) { + if (caps->get_dcs_code == NULL) + { return -RIG_ENAVAIL; } if ((caps->targetable_vfo & RIG_TARGETABLE_TONE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) { + || vfo == rig->state.current_vfo) + { - return caps->get_dcs_code(rig, vfo, code); + return caps->get_dcs_code(rig, vfo, code); } - if (!caps->set_vfo) { + if (!caps->set_vfo) + { return -RIG_ENTARGET; } curr_vfo = rig->state.current_vfo; retcode = caps->set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } @@ -347,31 +367,36 @@ int HAMLIB_API rig_set_ctcss_sql(RIG *rig, vfo_t vfo, tone_t tone) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig)) { + if (CHECK_RIG_ARG(rig)) + { return -RIG_EINVAL; } caps = rig->caps; - if (caps->set_ctcss_sql == NULL) { + if (caps->set_ctcss_sql == NULL) + { return -RIG_ENAVAIL; } if ((caps->targetable_vfo & RIG_TARGETABLE_TONE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) { + || vfo == rig->state.current_vfo) + { - return caps->set_ctcss_sql(rig, vfo, tone); + return caps->set_ctcss_sql(rig, vfo, tone); } - if (!caps->set_vfo) { + if (!caps->set_vfo) + { return -RIG_ENTARGET; } curr_vfo = rig->state.current_vfo; retcode = caps->set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } @@ -409,31 +434,36 @@ int HAMLIB_API rig_get_ctcss_sql(RIG *rig, vfo_t vfo, tone_t *tone) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig) || !tone) { + if (CHECK_RIG_ARG(rig) || !tone) + { return -RIG_EINVAL; } caps = rig->caps; - if (caps->get_ctcss_sql == NULL) { + if (caps->get_ctcss_sql == NULL) + { return -RIG_ENAVAIL; } if ((caps->targetable_vfo & RIG_TARGETABLE_TONE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) { + || vfo == rig->state.current_vfo) + { - return caps->get_ctcss_sql(rig, vfo, tone); + return caps->get_ctcss_sql(rig, vfo, tone); } - if (!caps->set_vfo) { + if (!caps->set_vfo) + { return -RIG_ENTARGET; } curr_vfo = rig->state.current_vfo; retcode = caps->set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } @@ -466,31 +496,36 @@ int HAMLIB_API rig_set_dcs_sql(RIG *rig, vfo_t vfo, tone_t code) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig)) { + if (CHECK_RIG_ARG(rig)) + { return -RIG_EINVAL; } caps = rig->caps; - if (caps->set_dcs_sql == NULL) { + if (caps->set_dcs_sql == NULL) + { return -RIG_ENAVAIL; } if ((caps->targetable_vfo & RIG_TARGETABLE_TONE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) { + || vfo == rig->state.current_vfo) + { - return caps->set_dcs_sql(rig, vfo, code); + return caps->set_dcs_sql(rig, vfo, code); } - if (!caps->set_vfo) { + if (!caps->set_vfo) + { return -RIG_ENTARGET; } curr_vfo = rig->state.current_vfo; retcode = caps->set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } @@ -523,31 +558,36 @@ int HAMLIB_API rig_get_dcs_sql(RIG *rig, vfo_t vfo, tone_t *code) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (CHECK_RIG_ARG(rig) || !code) { + if (CHECK_RIG_ARG(rig) || !code) + { return -RIG_EINVAL; } caps = rig->caps; - if (caps->get_dcs_sql == NULL) { + if (caps->get_dcs_sql == NULL) + { return -RIG_ENAVAIL; } if ((caps->targetable_vfo & RIG_TARGETABLE_TONE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) { + || vfo == rig->state.current_vfo) + { - return caps->get_dcs_sql(rig, vfo, code); + return caps->get_dcs_sql(rig, vfo, code); } - if (!caps->set_vfo) { + if (!caps->set_vfo) + { return -RIG_ENTARGET; } curr_vfo = rig->state.current_vfo; retcode = caps->set_vfo(rig, vfo); - if (retcode != RIG_OK) { + if (retcode != RIG_OK) + { return retcode; } diff --git a/src/tones.h b/src/tones.h index 8e1de8a4a..2a78752f9 100644 --- a/src/tones.h +++ b/src/tones.h @@ -37,7 +37,8 @@ 2035, 2065, 2107, 2181, 2257, 2291, 2336, 2418, 2503, 2541, \ 0, -static const tone_t static_full_ctcss_list[] = { +static const tone_t static_full_ctcss_list[] = +{ FULL_CTCSS_LIST }; @@ -57,7 +58,8 @@ static const tone_t static_full_ctcss_list[] = { 2035, 2065, 2107, 2181, 2257, 2291, 2336, 2418, 2503, 2541, \ 0, -static const tone_t static_common_ctcss_list[] = { +static const tone_t static_common_ctcss_list[] = +{ COMMON_CTCSS_LIST }; @@ -77,7 +79,8 @@ static const tone_t static_common_ctcss_list[] = { 662, 664, 703, 712, 723, 731, 732, 734, 743, 754, \ 0, -static const tone_t static_common_dcs_list[] = { +static const tone_t static_common_dcs_list[] = +{ COMMON_DCS_LIST }; @@ -97,7 +100,8 @@ static const tone_t static_common_dcs_list[] = { 662, 664, 703, 712, 723, 731, 732, 734, 743, 754, \ 0, -static const tone_t static_full_dcs_list[] = { +static const tone_t static_full_dcs_list[] = +{ FULL_DCS_LIST }; diff --git a/src/usb_port.c b/src/usb_port.c index 739ddd189..5d38a19d3 100644 --- a/src/usb_port.c +++ b/src/usb_port.c @@ -32,7 +32,7 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +# include "config.h" #endif #include @@ -52,9 +52,9 @@ #include #ifdef HAVE_LIBUSB_H -# include +# include #elif defined HAVE_LIBUSB_1_0_LIBUSB_H -# include +# include #endif #include "usb_port.h" @@ -65,7 +65,7 @@ * \param port * \return usb_handle */ -static libusb_device_handle * find_and_open_device(const hamlib_port_t *port) +static libusb_device_handle *find_and_open_device(const hamlib_port_t *port) { libusb_device_handle *udh = NULL; libusb_device *dev, **devs; @@ -83,7 +83,8 @@ static libusb_device_handle * find_and_open_device(const hamlib_port_t *port) r = libusb_get_device_list(NULL, &devs); - if (r < 0) { + if (r < 0) + { rig_debug(RIG_DEBUG_ERR, "%s: failed getting usb device list: %s", __func__, @@ -92,7 +93,8 @@ static libusb_device_handle * find_and_open_device(const hamlib_port_t *port) return NULL; } - for (i = 0; (dev = devs[i]) != NULL; i++) { + for (i = 0; (dev = devs[i]) != NULL; i++) + { libusb_get_device_descriptor(dev, &desc); @@ -102,12 +104,14 @@ static libusb_device_handle * find_and_open_device(const hamlib_port_t *port) desc.idProduct); if (desc.idVendor == port->parm.usb.vid - && desc.idProduct == port->parm.usb.pid) { + && desc.idProduct == port->parm.usb.pid) + { /* we need to open the device in order to query strings */ r = libusb_open(dev, &udh); - if (r < 0) { + if (r < 0) + { rig_debug(RIG_DEBUG_WARN, "%s: Warning: Cannot open USB device: %s\n", __func__, @@ -117,7 +121,8 @@ static libusb_device_handle * find_and_open_device(const hamlib_port_t *port) } /* now check whether the names match: */ - if (port->parm.usb.vendor_name) { + if (port->parm.usb.vendor_name) + { string[0] = '\0'; r = libusb_get_string_descriptor_ascii(udh, @@ -125,7 +130,8 @@ static libusb_device_handle * find_and_open_device(const hamlib_port_t *port) (unsigned char *)string, sizeof(string)); - if (r < 0) { + if (r < 0) + { rig_debug(RIG_DEBUG_WARN, "Warning: cannot query manufacturer for USB device: %s\n", libusb_error_name(r)); @@ -136,7 +142,8 @@ static libusb_device_handle * find_and_open_device(const hamlib_port_t *port) rig_debug(RIG_DEBUG_VERBOSE, " vendor >%s<", string); - if (strcmp(string, port->parm.usb.vendor_name) != 0) { + if (strcmp(string, port->parm.usb.vendor_name) != 0) + { rig_debug(RIG_DEBUG_WARN, "%s: Warning: Vendor name string mismatch!\n", __func__); @@ -146,7 +153,8 @@ static libusb_device_handle * find_and_open_device(const hamlib_port_t *port) } } - if (port->parm.usb.product) { + if (port->parm.usb.product) + { string[0] = '\0'; r = libusb_get_string_descriptor_ascii(udh, @@ -154,7 +162,8 @@ static libusb_device_handle * find_and_open_device(const hamlib_port_t *port) (unsigned char *)string, sizeof(string)); - if (r < 0) { + if (r < 0) + { rig_debug(RIG_DEBUG_WARN, "Warning: cannot query product for USB device: %s\n", libusb_error_name(r)); @@ -165,7 +174,8 @@ static libusb_device_handle * find_and_open_device(const hamlib_port_t *port) rig_debug(RIG_DEBUG_VERBOSE, " product >%s<", string); - if (strcmp(string, port->parm.usb.product) != 0) { + if (strcmp(string, port->parm.usb.product) != 0) + { /* Now testing with strncasecmp() for case insensitive * match. Updating firmware on FUNcube Dongle to v18f resulted @@ -175,7 +185,8 @@ static libusb_device_handle * find_and_open_device(const hamlib_port_t *port) */ if (strncasecmp(string, port->parm.usb.product, - sizeof(port->parm.usb.product - 1)) != 0) { + sizeof(port->parm.usb.product - 1)) != 0) + { rig_debug(RIG_DEBUG_WARN, "%s: Warning: Product string mismatch!\n", @@ -220,7 +231,8 @@ int usb_port_open(hamlib_port_t *port) /* init defaut libusb-1.0 library contexte, if needed */ r = libusb_init(NULL); - if (r < 0) { + if (r < 0) + { rig_debug(RIG_DEBUG_ERR, "%s: libusb_init failed: %s\n", __func__, @@ -239,25 +251,29 @@ int usb_port_open(hamlib_port_t *port) p = pathname; q = strchr(p, ':'); - if (q) { + if (q) + { ++q; port->parm.usb.vid = strtol(q, NULL, 16); p = q; q = strchr(p, ':'); - if (q) { + if (q) + { ++q; port->parm.usb.pid = strtol(q, NULL, 16); p = q; q = strchr(p, ':'); - if (q) { + if (q) + { ++q; port->parm.usb.vendor_name = q; p = q; q = strchr(p, ':'); - if (q) { + if (q) + { *q++ = '\0'; port->parm.usb.product = q; } @@ -267,7 +283,8 @@ int usb_port_open(hamlib_port_t *port) udh = find_and_open_device(port); - if (udh == 0) { + if (udh == 0) + { libusb_exit(NULL); return -RIG_EIO; } @@ -279,24 +296,26 @@ int usb_port_open(hamlib_port_t *port) */ (void)libusb_set_auto_detach_kernel_driver(udh, port->parm.usb.iface); - if (port->parm.usb.iface >= 0) { + if (port->parm.usb.iface >= 0) + { #ifdef _WIN32 /* Is it still needed with libusb-1.0 ? */ if (port->parm.usb.conf >= 0 - && (r = libusb_set_configuration(udh, port->parm.usb.conf)) < 0) { + && (r = libusb_set_configuration(udh, port->parm.usb.conf)) < 0) + { - rig_debug(RIG_DEBUG_ERR, - "%s: libusb_set_configuration: failed conf %d: %s\n", - __func__, - port->parm.usb.conf, - libusb_error_name(r)); + rig_debug(RIG_DEBUG_ERR, + "%s: libusb_set_configuration: failed conf %d: %s\n", + __func__, + port->parm.usb.conf, + libusb_error_name(r)); - libusb_close(udh); - libusb_exit(NULL); + libusb_close(udh); + libusb_exit(NULL); - return -RIG_EIO; + return -RIG_EIO; } #endif @@ -308,7 +327,8 @@ int usb_port_open(hamlib_port_t *port) r = libusb_claim_interface(udh, port->parm.usb.iface); - if (r < 0) { + if (r < 0) + { rig_debug(RIG_DEBUG_ERR, "%s:libusb_claim_interface: failed interface %d: %s\n", __func__, @@ -325,7 +345,8 @@ int usb_port_open(hamlib_port_t *port) r = libusb_set_interface_alt_setting(udh, port->parm.usb.iface, port->parm.usb.alt); - if (r < 0) { + if (r < 0) + { fprintf(stderr, "%s:usb_set_alt_interface: failed: %s\n", __func__,