From 60b5b78b834c0151e0db4a86b5e8c5f7ad031f0a Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sat, 7 Dec 2019 15:37:16 -0600 Subject: [PATCH 001/205] Fix cppcheck warnings in nrd525.c --- jrc/nrd525.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jrc/nrd525.c b/jrc/nrd525.c index c897bfbdb..9e7ca52ed 100644 --- a/jrc/nrd525.c +++ b/jrc/nrd525.c @@ -239,7 +239,7 @@ static int nrd525_set_mem(RIG *rig, vfo_t vfo, int ch) { char membuf[12]; - sprintf(membuf, "C%03u", ch); + sprintf(membuf, "C%03d", ch); return write_block(&rig->state.rigport, membuf, strlen(membuf)); } From a6ba2bc1981a2eadd490db474a8d5aeed78dda61 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sat, 7 Dec 2019 15:40:43 -0600 Subject: [PATCH 002/205] Fix cppcheck warnings in elecraft.c --- kenwood/elecraft.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/kenwood/elecraft.c b/kenwood/elecraft.c index 8e1410f4b..027241091 100644 --- a/kenwood/elecraft.c +++ b/kenwood/elecraft.c @@ -96,11 +96,6 @@ int elecraft_open(RIG *rig) rig_debug(RIG_DEBUG_VERBOSE, "%s called, rig version=%s\n", __func__, rig->caps->version); - if (!rig) - { - return -RIG_EINVAL; - } - int err; char id[KENWOOD_MAX_BUF_LEN]; @@ -378,7 +373,7 @@ int elecraft_get_firmware_revision_level(RIG *rig, const char *cmd, bufptr += strlen(cmd); /* Skip leading zero(s) as the revision number has the format of: "04.67" */ - while (bufptr && *bufptr == '0') { bufptr++; } + while (*bufptr == '0') { bufptr++; } /* Copy out */ strncpy(fw_rev, bufptr, fw_rev_sz - 1); From 584a9592b2c15e219df7d057120de43369262e47 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sat, 7 Dec 2019 15:51:53 -0600 Subject: [PATCH 003/205] Fix cppcheck warnings in k3.c --- kenwood/k3.c | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/kenwood/k3.c b/kenwood/k3.c index 5ebeb68e2..b18ab34bd 100644 --- a/kenwood/k3.c +++ b/kenwood/k3.c @@ -912,7 +912,6 @@ int k3_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) int err; char cmd_m[4]; - char cmd_s[64]; switch (mode) { @@ -980,6 +979,7 @@ int k3_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) width = pb_wid; } + char cmd_s[64]; snprintf(cmd_s, sizeof(cmd_s), "BW%04ld", width / 10); err = kenwood_transaction(rig, cmd_s, NULL, 0); @@ -1240,7 +1240,6 @@ int k3_set_split_mode(RIG *rig, vfo_t vfo, rmode_t tx_mode, pbwidth_t tx_width) int err; char cmd_m[4]; - char cmd_s[32]; switch (tx_mode) { @@ -1339,6 +1338,7 @@ int k3_set_split_mode(RIG *rig, vfo_t vfo, rmode_t tx_mode, pbwidth_t tx_width) tx_width = pb_wid; } + char cmd_s[32]; snprintf(cmd_s, sizeof(cmd_s), "BW$%04ld", tx_width / 10); err = kenwood_transaction(rig, cmd_s, NULL, 0); @@ -1468,7 +1468,7 @@ int k3_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) } char levelbuf[16]; - int i, kenwood_val; + int kenwood_val; if (RIG_LEVEL_IS_FLOAT(level)) { @@ -1517,6 +1517,8 @@ int k3_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) } else { + int i; + for (i = 0; i < MAXDBLSTSIZ && rig->state.attenuator[i]; i++) { if (val.i == rig->state.attenuator[i]) @@ -1577,20 +1579,21 @@ int k3_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) } char lvlbuf[50]; - int retval, i; + int retval; int lvl; struct kenwood_priv_data *priv = rig->state.priv; switch (level) { + float firmwareVersion; case RIG_LEVEL_STRENGTH: /* As of FW rev 4.37 the K3 supports an 'SMH' command that * offers a higher resolution, 0-100 (mine went to 106), * rawstr value for more precise S-meter reporting. */ - retval = strncmp(priv->fw_rev, "4.37", 4); + firmwareVersion = atof(priv->fw_rev); - if (retval < 0) + if (firmwareVersion < 4.37) { cal_table_t str_cal = K3_SM_CAL; @@ -1605,7 +1608,7 @@ int k3_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) val->i = (int) rig_raw2val(val->i, &str_cal); } - else if (retval >= 0) + else { cal_table_t str_cal = K3_SMH_CAL; @@ -1620,12 +1623,6 @@ int k3_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) val->i = (int) rig_raw2val(val->i, &str_cal); } - else - { - rig_debug(RIG_DEBUG_ERR, "%s: Firmware version comparison failed!\n", - __func__); - return -RIG_EINVAL; - } break; @@ -1732,6 +1729,8 @@ int k3_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) } else { + int i; + for (i = 0; i < lvl && i < MAXDBLSTSIZ; i++) { if (rig->state.attenuator[i] == 0) @@ -1823,8 +1822,6 @@ int k3_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) int kx3_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) { - int retval; - switch (level) { case RIG_LEVEL_RFPOWER_METER: @@ -1833,7 +1830,7 @@ int kx3_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) float pwr; // Return zero RF power when not in TX mode - retval = get_kenwood_func(rig, "TQ", &tx_status); + int retval = get_kenwood_func(rig, "TQ", &tx_status); if (retval != RIG_OK) { @@ -1945,8 +1942,6 @@ int set_rit_xit(RIG *rig, shortfreq_t rit) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); int err; - char offs; - char cmd[16]; if (!rig) { @@ -1969,6 +1964,8 @@ int set_rit_xit(RIG *rig, shortfreq_t rit) /* Set offset */ if (rit <= 9999 && rit >= -9999) { + char cmd[16]; + char offs; offs = (rit < 0) ? '-' : '+'; snprintf(cmd, 8, "RO%c%04d", offs, abs((int)rit)); @@ -1998,7 +1995,6 @@ int k3_set_nb_level(RIG *rig, float dsp_nb, float if_nb) } char lvlbuf[16]; - int retval; int dsp_nb_raw = 0; int if_nb_raw = 0; @@ -2018,7 +2014,7 @@ int k3_set_nb_level(RIG *rig, float dsp_nb, float if_nb) int current_dsp_nb_raw; int current_if_nb_raw; - retval = kenwood_safe_transaction(rig, "NL", lvlbuf, sizeof(lvlbuf), 6); + int retval = kenwood_safe_transaction(rig, "NL", lvlbuf, sizeof(lvlbuf), 6); if (retval != RIG_OK) { From 3065325b7ba88009a5b518a73aad087ebecfb285 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sat, 7 Dec 2019 15:58:13 -0600 Subject: [PATCH 004/205] Fix some cppcheck warnings in k2.c --- kenwood/k2.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/kenwood/k2.c b/kenwood/k2.c index c0fa63540..3dc074bdc 100644 --- a/kenwood/k2.c +++ b/kenwood/k2.c @@ -301,7 +301,6 @@ int k2_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) int err; char f; - char fcmd[16]; struct k2_filt_lst_s *flt; struct kenwood_priv_data *priv = rig->state.priv; shortfreq_t freq = 0; @@ -400,6 +399,7 @@ int k2_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) } /* Construct the filter command and set the radio mode and width*/ + char fcmd[16]; snprintf(fcmd, 8, "FW0000%c", f); /* Set the filter slot */ @@ -735,7 +735,6 @@ int k2_pop_fw_lst(RIG *rig, const char *cmd) int err, f; char fcmd[16]; char buf[KENWOOD_MAX_BUF_LEN]; - char *bufptr; char tmp[16]; struct k2_filt_lst_s *flt; @@ -788,7 +787,7 @@ int k2_pop_fw_lst(RIG *rig, const char *cmd) * f = crystal filter slot number--1-4 * a = audio filter slot number--0-2 */ - bufptr = buf; + char *bufptr = buf; strncpy(tmp, bufptr + 2, 4); tmp[4] = '\0'; From d838cacaffa6489cdb545f89d17ab0dbeedf32fe Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sat, 7 Dec 2019 16:05:39 -0600 Subject: [PATCH 005/205] Fix some cppcheck warnings in kenwood.c --- kenwood/kenwood.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/kenwood/kenwood.c b/kenwood/kenwood.c index ee70efcde..320fa2a77 100644 --- a/kenwood/kenwood.c +++ b/kenwood/kenwood.c @@ -566,12 +566,12 @@ rmode_t kenwood2rmode(unsigned char mode, const rmode_t mode_table[]) char rmode2kenwood(rmode_t mode, const rmode_t mode_table[]) { - int i; - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); if (mode != RIG_MODE_NONE) { + int i; + for (i = 0; i < KENWOOD_MODE_TABLE_MAX; i++) { if (mode_table[i] == mode) @@ -1827,9 +1827,9 @@ int kenwood_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) } snprintf(buf, sizeof(buf), "OM0%c", c); /* target vfo is ignored */ - int err = kenwood_transaction(rig, buf, NULL, 0); + err = kenwood_transaction(rig, buf, NULL, 0); - if (vfo != RIG_VFO_CURR && vfo != curr_vfo) + if (err == RIG_OK && vfo != RIG_VFO_CURR && vfo != curr_vfo) { int err2 = kenwood_set_vfo_main_sub(rig, curr_vfo); @@ -2097,7 +2097,7 @@ int kenwood_get_mode_if(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) || rig->caps->rig_model == RIG_MODEL_TS950SDX) { - err = kenwood_get_filter(rig, width); + kenwood_get_filter(rig, width); /* non fatal */ } @@ -2822,8 +2822,7 @@ int kenwood_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone) caps = rig->caps; - /* TODO: replace 200 by something like RIGTONEMAX */ - for (i = 0; caps->ctcss_list[i] != 0 && i < 200; i++) + for (i = 0; caps->ctcss_list[i] != 0; i++) { if (caps->ctcss_list[i] == tone) { @@ -2855,8 +2854,7 @@ int kenwood_set_ctcss_tone_tn(RIG *rig, vfo_t vfo, tone_t tone) char buf[6]; int i; - /* XXX 40 is a fixed constant */ - for (i = 0; caps->ctcss_list[i] != 0 && i < 40; i++) + for (i = 0; caps->ctcss_list[i] != 0; i++) { if (tone == caps->ctcss_list[i]) { @@ -3008,7 +3006,7 @@ int kenwood_set_ctcss_sql(RIG *rig, vfo_t vfo, tone_t tone) char buf[6]; int i; - for (i = 0; caps->ctcss_list[i] != 0 && i < 40; i++) + for (i = 0; caps->ctcss_list[i] != 0; i++) { if (tone == caps->ctcss_list[i]) { @@ -3338,7 +3336,6 @@ int kenwood_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) if (ptt == RIG_PTT_OFF && RIG_MODEL_TS480 == rig->caps->rig_model) { /* if not in PTT TS-480 will return RX0; */ - char ackbuf[8]; ptt_t ptttmp; int err = kenwood_get_ptt(rig, vfo, &ptttmp); @@ -3347,7 +3344,11 @@ int kenwood_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) return err; } - if (ptt) { return kenwood_transaction(rig, ptt_cmd, ackbuf, sizeof(ackbuf)); } + if (ptt) + { + char ackbuf[8]; + return kenwood_transaction(rig, ptt_cmd, ackbuf, sizeof(ackbuf)); + } } return kenwood_transaction(rig, ptt_cmd, NULL, 0); @@ -3634,7 +3635,7 @@ int kenwood_send_morse(RIG *rig, vfo_t vfo, const char *msg) } char morsebuf[40], m2[30]; - int msg_len, buff_len, retval, i; + int msg_len, retval, i; const char *p; p = msg; @@ -3666,7 +3667,7 @@ int kenwood_send_morse(RIG *rig, vfo_t vfo, const char *msg) else { return -RIG_EINVAL; } } - buff_len = msg_len > 24 ? 24 : msg_len; + int buff_len = msg_len > 24 ? 24 : msg_len; strncpy(m2, p, 24); m2[24] = '\0'; From 6d34361386fcffd69ea47a67820795b3ec0bab94 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sat, 7 Dec 2019 16:05:47 -0600 Subject: [PATCH 006/205] Fix some cppcheck warnings in kenwood.c --- kenwood/kenwood.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kenwood/kenwood.h b/kenwood/kenwood.h index 1fb61af95..d002b97ed 100644 --- a/kenwood/kenwood.h +++ b/kenwood/kenwood.h @@ -27,7 +27,7 @@ #include #include "token.h" -#define BACKEND_VER "1.3" +#define BACKEND_VER "1.4" #define EOM_KEN ';' #define EOM_TH '\r' From 3875e4db041b756dbc0bc8aa9583bb8acd981613 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sat, 7 Dec 2019 16:14:53 -0600 Subject: [PATCH 007/205] Fix some cppcheck warnings in th.c --- kenwood/th.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/kenwood/th.c b/kenwood/th.c index 3dfec8af0..fb06e6159 100644 --- a/kenwood/th.c +++ b/kenwood/th.c @@ -421,7 +421,6 @@ int th_set_vfo(RIG *rig, vfo_t vfo) { const char *cmd; - int retval; rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); @@ -454,7 +453,7 @@ th_set_vfo(RIG *rig, vfo_t vfo) return kenwood_wrong_vfo(__func__, vfo); } - retval = kenwood_simple_transaction(rig, cmd, 5); + int retval = kenwood_simple_transaction(rig, cmd, 5); if (retval != RIG_OK) { @@ -1137,7 +1136,8 @@ int th_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) { char vch, buf[10], ackbuf[20]; - int retval, v, l; + int retval, v; + unsigned int l; vfo_t tvfo; @@ -1413,7 +1413,7 @@ th_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone) caps = rig->caps; - for (i = 0; caps->ctcss_list[i] != 0 && i < RIG_TONEMAX; i++) + for (i = 0; caps->ctcss_list[i] != 0; i++) { if (caps->ctcss_list[i] == tone) { @@ -1471,7 +1471,7 @@ th_get_ctcss_tone(RIG *rig, vfo_t vfo, tone_t *tone) } /* verify tone index for TH-7DA rig */ - if (tone_idx <= 0 || tone_idx == 2 || tone_idx > 39) + if (tone_idx == 0 || tone_idx == 2 || tone_idx > 39) { rig_debug(RIG_DEBUG_ERR, "%s: Unexpected CTCSS tone no (%04d)\n", __func__, tone_idx); @@ -1498,7 +1498,7 @@ th_set_ctcss_sql(RIG *rig, vfo_t vfo, tone_t tone) caps = rig->caps; - for (i = 0; caps->ctcss_list[i] != 0 && i < RIG_TONEMAX; i++) + for (i = 0; caps->ctcss_list[i] != 0; i++) { if (caps->ctcss_list[i] == tone) { @@ -1556,7 +1556,7 @@ th_get_ctcss_sql(RIG *rig, vfo_t vfo, tone_t *tone) } /* verify tone index for TH-7DA rig */ - if (tone_idx <= 0 || tone_idx == 2 || tone_idx > 39) + if (tone_idx == 0 || tone_idx == 2 || tone_idx > 39) { rig_debug(RIG_DEBUG_ERR, "%s: Unexpected CTCSS no (%04d)\n", __func__, tone_idx); @@ -1592,7 +1592,7 @@ th_set_dcs_sql(RIG *rig, vfo_t vfo, tone_t code) return kenwood_transaction(rig, "DCS 0", NULL, 0); } - for (i = 0; caps->dcs_list[i] != 0 && i < RIG_CODEMAX; i++) + for (i = 0; caps->dcs_list[i] != 0; i++) { if (caps->dcs_list[i] == code) { @@ -1646,7 +1646,7 @@ th_get_dcs_sql(RIG *rig, vfo_t vfo, tone_t *code) return retval; } - retval = sscanf(buf, "DCSN %u", (int *)&code_idx); + retval = sscanf(buf, "DCSN %d", (int *)&code_idx); if (retval != 1) { @@ -1668,7 +1668,7 @@ th_get_dcs_sql(RIG *rig, vfo_t vfo, tone_t *code) return retval; } - retval = sscanf(buf, "DCSN %u", (int *)&code_idx); + retval = sscanf(buf, "DCSN %d", (int *)&code_idx); if (retval != 1) { @@ -2226,7 +2226,7 @@ static int find_tone_index(const tone_t *tone_list, tone_t tone) { int i; - for (i = 0; tone_list[i] != 0 && i < RIG_TONEMAX; i++) + for (i = 0; tone_list[i] != 0; i++) { if (tone_list[i] == tone) { @@ -2245,7 +2245,7 @@ int th_set_channel(RIG *rig, const channel_t *chan) char req[64]; char lockoutstr[8]; int channel_num, step, shift, rev, tone, ctcss, tonefq, ctcssfq, dcs, dcscode, - mode, lockout; + lockout; const char *mr_extra; const struct kenwood_priv_caps *priv = (const struct kenwood_priv_caps *) rig->caps->priv; @@ -2414,8 +2414,8 @@ int th_set_channel(RIG *rig, const channel_t *chan) return -RIG_EINVAL; } - rev = chan->funcs & RIG_FUNC_REV ? 1 : 0; - lockout = chan->flags & RIG_CHFLAG_SKIP ? 1 : 0; + rev = (chan->funcs & RIG_FUNC_REV) ? 1 : 0; + lockout = (chan->flags & RIG_CHFLAG_SKIP) ? 1 : 0; if (chan_caps->mem_caps.flags) { @@ -2436,7 +2436,7 @@ int th_set_channel(RIG *rig, const channel_t *chan) return -RIG_ENIMPL; } - mode = rmode2kenwood(chan->mode, priv->mode_table); + int mode = rmode2kenwood(chan->mode, priv->mode_table); if (mode == -1) { @@ -2457,8 +2457,7 @@ int th_set_channel(RIG *rig, const channel_t *chan) { /* Without DCS,mode */ - retval = sprintf(membuf, - "%s,%011"PRIll",%X,%d,%d,%d,%d,,%02d,,%02d,%09"PRIll"%s", + sprintf(membuf, "%s,%011"PRIll",%X,%d,%d,%d,%d,,%02d,,%02d,%09"PRIll"%s", req, (int64_t)chan->freq, step, shift, rev, tone, ctcss, tonefq, ctcssfq, (int64_t)labs((long)(chan->rptr_offs)), lockoutstr From d3c9c8113c6f1d7c2ee250a5f263f68ab7ea7865 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sat, 7 Dec 2019 16:20:13 -0600 Subject: [PATCH 008/205] Fix cppcheck warnings in thd72.c --- kenwood/thd72.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/kenwood/thd72.c b/kenwood/thd72.c index f2f6a66aa..2cae19cd5 100644 --- a/kenwood/thd72.c +++ b/kenwood/thd72.c @@ -378,7 +378,7 @@ static int thd72_get_freq_info(RIG *rig, vfo_t vfo, char *buf) sprintf(cmd, "FO %c", c); retval = kenwood_transaction(rig, cmd, buf, 53); - return RIG_OK; + return retval; } /* item is an offset into reply buf that is a single char */ @@ -1047,7 +1047,7 @@ static int thd72_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) retval = sscanf(buf, "SQ %d,%d", &v, &l); - if (retval != 2 || l < 0 || l > 6) + if (retval != 2 || l < 0 || l >= 6) { rig_debug(RIG_DEBUG_ERR, "%s: Unexpected reply '%s'\n", __func__, buf); return -RIG_ERJCTED; @@ -1353,13 +1353,14 @@ static int thd72_parse_channel(int kind, const char *buf, channel_t *chan) static int thd72_get_channel(RIG *rig, channel_t *chan) { - int retval, len; - char cmd[8], buf[72]; + int retval; + char buf[72]; rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); if (chan->vfo == RIG_VFO_MEM) /* memory channel */ { + char cmd[16]; sprintf(cmd, "ME %03d", chan->channel_num); retval = kenwood_transaction(rig, cmd, buf, sizeof(buf)); @@ -1383,7 +1384,7 @@ static int thd72_get_channel(RIG *rig, channel_t *chan) return retval; } - len = strlen(buf); + int len = strlen(buf); memcpy(chan->channel_desc, buf + 7, len - 7); } else /* current channel */ @@ -1467,6 +1468,7 @@ static int thd72_get_block(RIG *rig, int block_num, char *block) return RIG_OK; } +#ifdef XXREMOVEDXX int thd72_get_chan_all_cb(RIG *rig, chan_cb_t chan_cb, rig_ptr_t arg) { int i, j, ret; @@ -1599,6 +1601,7 @@ int thd72_get_chan_all_cb(RIG *rig, chan_cb_t chan_cb, rig_ptr_t arg) return RIG_OK; } +#endif #endif /* none working stuff */ /* * th-d72a rig capabilities. @@ -1608,7 +1611,7 @@ const struct rig_caps thd72a_caps = .rig_model = RIG_MODEL_THD72A, .model_name = "TH-D72A", .mfg_name = "Kenwood", - .version = TH_VER ".3", + .version = TH_VER ".4", .copyright = "LGPL", .status = RIG_STATUS_BETA, .rig_type = RIG_TYPE_HANDHELD | RIG_FLAG_APRS | RIG_FLAG_TNC | RIG_FLAG_DXCLUSTER, From 16eac108f52a303214ff66f086dc42e8a7b51042 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sat, 7 Dec 2019 22:58:15 -0600 Subject: [PATCH 009/205] Improve firmware check in k3.c --- kenwood/k3.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/kenwood/k3.c b/kenwood/k3.c index b18ab34bd..75a4424d7 100644 --- a/kenwood/k3.c +++ b/kenwood/k3.c @@ -1585,15 +1585,18 @@ int k3_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) switch (level) { - float firmwareVersion; + float firmware_have; + float firmware_need; case RIG_LEVEL_STRENGTH: /* As of FW rev 4.37 the K3 supports an 'SMH' command that * offers a higher resolution, 0-100 (mine went to 106), * rawstr value for more precise S-meter reporting. */ - firmwareVersion = atof(priv->fw_rev); + firmware_have = 0; + if (priv->fw_rev != NULL) sscanf(priv->fw_rev,"%f",&firmware_have); + sscanf("4.37","%f",&firmware_need); - if (firmwareVersion < 4.37) + if (firmware_have < firmware_need) { cal_table_t str_cal = K3_SM_CAL; From a0943890d23cb7ef94082a6dacfe1e01afdd43a3 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sat, 7 Dec 2019 23:01:23 -0600 Subject: [PATCH 010/205] Fix cppcheck warnings in thd74.c --- kenwood/thd74.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/kenwood/thd74.c b/kenwood/thd74.c index bafbd9f96..6cec9ec4b 100644 --- a/kenwood/thd74.c +++ b/kenwood/thd74.c @@ -458,6 +458,11 @@ int thd74_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) retval = thd74_vfoc(rig, vfo, &v); + if (retval != RIG_OK) + { + return retval; + } + if (priv->mode_table) { kmode = rmode2kenwood(mode, priv->mode_table); @@ -1021,7 +1026,7 @@ static int thd74_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) retval = sscanf(buf, "SQ %d,%d", &v, &l); - if (retval != 2 || l < 0 || l > 6) + if (retval != 2 || l < 0 || l >= 6) { rig_debug(RIG_DEBUG_ERR, "%s: Unexpected reply '%s'\n", __func__, buf); return -RIG_ERJCTED; From ecadeda486d163be72800b6cf6fda4f4c734790d Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sat, 7 Dec 2019 23:05:21 -0600 Subject: [PATCH 011/205] Fix more cppcheck warnings in thd74.c --- kenwood/thd74.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/kenwood/thd74.c b/kenwood/thd74.c index 6cec9ec4b..8b12077f8 100644 --- a/kenwood/thd74.c +++ b/kenwood/thd74.c @@ -1279,13 +1279,14 @@ static int thd74_parse_channel(int kind, const char *buf, channel_t *chan) static int thd74_get_channel(RIG *rig, channel_t *chan) { - int retval, len; - char cmd[8], buf[72]; + int retval; + char buf[72]; rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); if (chan->vfo == RIG_VFO_MEM) /* memory channel */ { + char cmd[16]; sprintf(cmd, "ME %03d", chan->channel_num); retval = kenwood_transaction(rig, cmd, buf, sizeof(buf)); @@ -1309,7 +1310,7 @@ static int thd74_get_channel(RIG *rig, channel_t *chan) return retval; } - len = strlen(buf); + int len = strlen(buf); memcpy(chan->channel_desc, buf + 7, len - 7); } else /* current channel */ @@ -1400,14 +1401,13 @@ otherwise return -RIG_EPROTO int thd74_set_split_freq(RIG *rig, vfo_t vfo, freq_t tx_freq) { struct kenwood_priv_data *priv = rig->state.priv; - int retval; - char fbuf[12], buf[128]; rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); if (priv->split == RIG_SPLIT_ON) { - retval = thd74_get_freq_info(rig, RIG_VFO_A, buf); + char fbuf[12], buf[128]; + int retval = thd74_get_freq_info(rig, RIG_VFO_A, buf); if (retval != RIG_OK) { @@ -1489,6 +1489,7 @@ static int thd74_get_block(RIG *rig, int block_num, char *block) return RIG_OK; } +#ifdef XXREMOVEDXX int thd74_get_chan_all_cb(RIG *rig, chan_cb_t chan_cb, rig_ptr_t arg) { int i, j, ret; @@ -1621,6 +1622,7 @@ int thd74_get_chan_all_cb(RIG *rig, chan_cb_t chan_cb, rig_ptr_t arg) return RIG_OK; } +#endif #endif /* none working stuff */ /* * th-d74 rig capabilities. From fdc18a62dee653538d15334db87f2e62b54f9826 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sat, 7 Dec 2019 23:07:07 -0600 Subject: [PATCH 012/205] Fix more cppcheck warnings in thg71.c --- kenwood/thg71.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/kenwood/thg71.c b/kenwood/thg71.c index 22e15f383..0f07458b0 100644 --- a/kenwood/thg71.c +++ b/kenwood/thg71.c @@ -455,8 +455,6 @@ int thg71_get_vfo(RIG *rig, vfo_t *vfo) /* --------------------------------------------------------------------- */ int thg71_set_func(RIG *rig, vfo_t vfo, setting_t func, int status) { - int retval; - if (func != RIG_FUNC_TBURST) { return -RIG_EINVAL; @@ -464,7 +462,7 @@ int thg71_set_func(RIG *rig, vfo_t vfo, setting_t func, int status) if (status == 1) { - retval = kenwood_transaction(rig, "TT", NULL, 0); + int retval = kenwood_transaction(rig, "TT", NULL, 0); if (retval != RIG_OK) { @@ -485,7 +483,7 @@ int thg71_set_func(RIG *rig, vfo_t vfo, setting_t func, int status) /* --------------------------------------------------------------------- */ int thg71_open(RIG *rig) { - char ackbuf[ACKBUF_LEN], *strl, *stru; + char ackbuf[ACKBUF_LEN], *strl; int retval, i; const freq_range_t frend = RIG_FRNG_END; @@ -512,7 +510,7 @@ int thg71_open(RIG *rig) freq_range_t frng; strl = strtok(NULL, ","); - stru = strtok(NULL, ","); + char *stru = strtok(NULL, ","); if (strl == NULL && stru == NULL) { From 38dca9ccea6047a3baf20af08362c29ecaaa4890 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sat, 7 Dec 2019 23:10:04 -0600 Subject: [PATCH 013/205] Fix more cppcheck warnings in tmd710.c --- kenwood/tmd710.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kenwood/tmd710.c b/kenwood/tmd710.c index 1f165f510..a796f0f0f 100644 --- a/kenwood/tmd710.c +++ b/kenwood/tmd710.c @@ -2114,7 +2114,8 @@ int tmd710_vfo_op(RIG *rig, vfo_t vfo, vfo_op_t op) int tmd710_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) { char buf[10], ackbuf[20]; - int retval, v, l; + int retval, v; + unsigned int l; int vfonum; rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); From 5438fe29055bc63a1e511b448fa7d1b77165541c Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sat, 7 Dec 2019 23:11:01 -0600 Subject: [PATCH 014/205] Fix more cppcheck warnings in tmv7.c --- kenwood/tmv7.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/kenwood/tmv7.c b/kenwood/tmv7.c index bd1f8eccd..aa981b83a 100644 --- a/kenwood/tmv7.c +++ b/kenwood/tmv7.c @@ -691,8 +691,7 @@ int tmv7_set_channel(RIG *rig, const channel_t *chan) { tone = 1; - for (tonefq = 0; rig->caps->ctcss_list[tonefq] != 0 - && tonefq < RIG_TONEMAX; tonefq++) + for (tonefq = 0; rig->caps->ctcss_list[tonefq] != 0; tonefq++) { if (rig->caps->ctcss_list[tonefq] == chan->ctcss_tone) { @@ -711,8 +710,7 @@ int tmv7_set_channel(RIG *rig, const channel_t *chan) { ctcss = 1; - for (ctcssfq = 0; rig->caps->ctcss_list[ctcssfq] != 0 - && ctcssfq < RIG_TONEMAX; ctcssfq++) + for (ctcssfq = 0; rig->caps->ctcss_list[ctcssfq] != 0; ctcssfq++) { if (rig->caps->ctcss_list[ctcssfq] == chan->ctcss_sql) { From e964a0542aa5fcdfb7a8efffb387a9d031b8a5c4 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sat, 7 Dec 2019 23:19:10 -0600 Subject: [PATCH 015/205] Fix more cppcheck warnings in ltdl.c --- android/ltdl.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/android/ltdl.c b/android/ltdl.c index e7af28ee2..75eb70680 100644 --- a/android/ltdl.c +++ b/android/ltdl.c @@ -70,13 +70,18 @@ char *getlibpath(void) return libpath; } +#ifdef XXREMOVEDXX +// Not referenced anywhere int lt_dlinit(void) { // __android_log_print(ANDROID_LOG_DEBUG, PACKAGE_NAME, "lt_dlinit"); return 0; } +#endif // not called from hamlib +#ifdef XXREMOVEDXX +// Not referenced anywhere int lt_dlexit(void) { // __android_log_print(ANDROID_LOG_DEBUG, PACKAGE_NAME, "lt_dlexit"); @@ -89,6 +94,7 @@ int lt_dlexit(void) return 0; } +#endif int lt_dladdsearchdir(const char *search_dir) { @@ -119,34 +125,49 @@ lt_dlhandle adlopen(const char *filename) return ret; } +#ifdef XXREMOVEDXX +// Not referenced anywhere lt_dlhandle lt_dlopen(const char *filename) { // __android_log_print(ANDROID_LOG_DEBUG, PACKAGE_NAME, "lt_dlopen(%s)", filename); return adlopen(filename); } +#endif +#ifdef XXREMOVEDXX +// Not referenced anywhere lt_dlhandle lt_dlopenext(const char *filename) { // __android_log_print(ANDROID_LOG_DEBUG, PACKAGE_NAME, "lt_dlopenext(%s)", filename); return adlopen(filename); } +#endif +#ifdef XXREMOVEDXX +// Not referenced anywhere int lt_dlclose(lt_dlhandle handle) { // __android_log_print(ANDROID_LOG_DEBUG, PACKAGE_NAME, "lt_dlclose"); return dlclose(handle); } +#endif +#ifdef XXREMOVEDXX +// Not referenced anywhere void *lt_dlsym(lt_dlhandle handle, const char *name) { void *ret = dlsym(handle, name); // __android_log_print(ANDROID_LOG_DEBUG, PACKAGE_NAME, "lt_dlsym(%s)=%p", name, ret); return ret; } +#endif +#ifdef XXREMOVEDXX +// Not referenced anywhere const char *lt_dlerror(void) { const char *ret = dlerror(); // __android_log_print(ANDROID_LOG_DEBUG, PACKAGE_NAME, "lt_dlerror=%s", ret); return ret; } +#endif From d34c8b9d5059c6d4dd3f261aa5362448714c445a Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sat, 7 Dec 2019 23:20:31 -0600 Subject: [PATCH 016/205] Fix more cppcheck warnings in ltdl.c --- android/ltdl.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/android/ltdl.c b/android/ltdl.c index 75eb70680..4e1a1651d 100644 --- a/android/ltdl.c +++ b/android/ltdl.c @@ -96,11 +96,13 @@ int lt_dlexit(void) } #endif +#ifdef XXREMOVEDXX int lt_dladdsearchdir(const char *search_dir) { // __android_log_print(ANDROID_LOG_DEBUG, PACKAGE_NAME, "lt_dladdsearchdir"); return 0; } +#endif lt_dlhandle adlopen(const char *filename) { From 099182e8375b9697eb7cfcc179d473a957e52e4d Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sat, 7 Dec 2019 23:21:28 -0600 Subject: [PATCH 017/205] Fix more cppcheck warnings in ic9100.c --- icom/ic9100.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/icom/ic9100.c b/icom/ic9100.c index 8be1b950b..5c7ed320b 100644 --- a/icom/ic9100.c +++ b/icom/ic9100.c @@ -280,6 +280,8 @@ const struct rig_caps ic9100_caps = }; +#ifdef XXREMOVEDXX +// Not referenced anywhere int ic9100_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) { unsigned char cmdbuf[MAXFRAMELEN]; @@ -297,7 +299,10 @@ int ic9100_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) return icom_set_level(rig, vfo, level, val); } } +#endif +#ifdef XXREMOVEDXX +// Not referenced anywhere int ic9100_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) { unsigned char cmdbuf[MAXFRAMELEN]; @@ -315,3 +320,4 @@ int ic9100_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) return icom_get_level(rig, vfo, level, val); } } +#endif From 0fb8454d4e85ac341ef2833a6d41d836c827277d Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sat, 7 Dec 2019 23:22:36 -0600 Subject: [PATCH 018/205] Fix more cppcheck warnings in ic10.c --- kenwood/ic10.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kenwood/ic10.c b/kenwood/ic10.c index c411456a4..d0d73677f 100644 --- a/kenwood/ic10.c +++ b/kenwood/ic10.c @@ -500,6 +500,8 @@ int ic10_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt) } +#ifdef XXREMOVEDXX +// Not referenced anywhere /* * ic10_set_ptt * Assumes rig!=NULL @@ -527,6 +529,7 @@ int ic10_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) return retval; } +#endif /* From 55fc3398ad6abeb518434e12de8c9e411b955ea0 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sat, 7 Dec 2019 23:30:41 -0600 Subject: [PATCH 019/205] Fix cppcheck warnings in ts570.c and remove old files --- kenwood/ts570.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/kenwood/ts570.c b/kenwood/ts570.c index 856e2e654..da44fdcc4 100644 --- a/kenwood/ts570.c +++ b/kenwood/ts570.c @@ -337,7 +337,6 @@ ts570_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) { char levelbuf[16]; int kenwood_val; - int i; switch (level) { @@ -349,7 +348,9 @@ ts570_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) { sprintf(levelbuf, "PA0"); } - else + else { + int i; + for (i = 0; i < MAXDBLSTSIZ; i++) if (kenwood_val == rig->state.preamp[i]) { @@ -360,6 +361,7 @@ ts570_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) { return -RIG_EINVAL; } + } return kenwood_transaction(rig, levelbuf, NULL, 0); @@ -394,7 +396,6 @@ ts570_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) size_t ack_len; int levelint; int retval; - int i; switch (level) { @@ -471,6 +472,8 @@ ts570_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) } else { + int i; + for (i = 0; i < levelint && i < MAXDBLSTSIZ; i++) { if (rig->state.preamp[i] == 0) From 9ed28fb0db884321d1f2b529552b5551e6d58d8e Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sat, 7 Dec 2019 23:31:43 -0600 Subject: [PATCH 020/205] Fix cppcheck warnings in ts870s --- kenwood/ts870s.c | 1 - 1 file changed, 1 deletion(-) diff --git a/kenwood/ts870s.c b/kenwood/ts870s.c index 44df5ad20..e32eedb6b 100644 --- a/kenwood/ts870s.c +++ b/kenwood/ts870s.c @@ -108,7 +108,6 @@ static int ts870s_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) size_t buf_len; int retval; - buf_len = 50; retval = kenwood_transaction(rig, "MD", buf, sizeof(buf)); if (retval != RIG_OK) From ba69e3d876e6670eab417d526272e58720b9bc4a Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sat, 7 Dec 2019 23:33:19 -0600 Subject: [PATCH 021/205] Fix cppcheck warnings in xg3.c --- kenwood/xg3.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/kenwood/xg3.c b/kenwood/xg3.c index 87d4894c7..b9064d0a9 100644 --- a/kenwood/xg3.c +++ b/kenwood/xg3.c @@ -348,7 +348,7 @@ int xg3_get_vfo(RIG *rig, vfo_t *vfo) struct xg3_priv_data *priv = (struct xg3_priv_data *)rig->state.priv; - if (!rig || !vfo) + if (!vfo) { return -RIG_EINVAL; } @@ -366,7 +366,7 @@ int xg3_set_vfo(RIG *rig, vfo_t vfo) struct xg3_priv_data *priv = (struct xg3_priv_data *)rig->state.priv; - if (!rig || !vfo) + if (!vfo) { return -RIG_EINVAL; } @@ -506,10 +506,11 @@ int xg3_set_powerstat(RIG *rig, powerstat_t status) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); struct xg3_priv_data *priv = (struct xg3_priv_data *)rig->state.priv; - const char *cmd = "X"; if (status == RIG_POWER_OFF) { + const char *cmd = "X"; + priv->powerstat = RIG_POWER_OFF; return kenwood_transaction(rig, cmd, NULL, 0); } @@ -627,11 +628,6 @@ int xg3_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) struct xg3_priv_data *priv = (struct xg3_priv_data *)rig->state.priv; - if (!rig) - { - return -RIG_EINVAL; - } - int retval; retval = kenwood_simple_transaction(rig, @@ -654,7 +650,7 @@ int xg3_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt) struct xg3_priv_data *priv = (struct xg3_priv_data *)rig->state.priv; - if (!rig || !ptt) + if (!ptt) { return -RIG_EINVAL; } From 535da9ef2e11a819af87706108a27bc1cbdfe532 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sat, 7 Dec 2019 23:35:30 -0600 Subject: [PATCH 022/205] Fix cppcheck warnings in drt1.c --- kit/drt1.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/kit/drt1.c b/kit/drt1.c index e7c750846..1e2c60b48 100644 --- a/kit/drt1.c +++ b/kit/drt1.c @@ -224,7 +224,7 @@ int drt1_set_conf(RIG *rig, token_t token, const char *val) break; case TOK_REFMULT: - sscanf(val, "%d", &priv->ref_mult); + sscanf(val, "%u", &priv->ref_mult); break; case TOK_IFMIXFREQ: @@ -232,7 +232,7 @@ int drt1_set_conf(RIG *rig, token_t token, const char *val) break; case TOK_PUMPCRNT: - sscanf(val, "%d", &priv->pump_crrnt); + sscanf(val, "%u", &priv->pump_crrnt); break; default: @@ -260,7 +260,7 @@ int drt1_get_conf(RIG *rig, token_t token, char *val) break; case TOK_REFMULT: - sprintf(val, "%d", priv->ref_mult); + sprintf(val, "%u", priv->ref_mult); break; case TOK_IFMIXFREQ: @@ -268,7 +268,7 @@ int drt1_get_conf(RIG *rig, token_t token, char *val) break; case TOK_PUMPCRNT: - sprintf(val, "%d", priv->pump_crrnt); + sprintf(val, "%u", priv->pump_crrnt); break; default: @@ -377,7 +377,7 @@ static int ad_write_reg(hamlib_port_t *port, unsigned addr, unsigned nb_bytes, for (i = 7; i >= 0; i--) { - ad_sdio(port, addr & (1U << i) ? 0 : 1); /* RTS 0 or 1 */ + ad_sdio(port, (addr & (1U << i)) ? 0 : 1); /* RTS 0 or 1 */ ad_sclk(port, 1); /* TXD 1, clock */ ad_sclk(port, 0); /* TXD 0 */ } @@ -386,7 +386,7 @@ static int ad_write_reg(hamlib_port_t *port, unsigned addr, unsigned nb_bytes, for (i = nb_bytes * 8 - 1; i >= 0; i--) { - ad_sdio(port, data & (1U << i) ? 0 : 1); /* RTS 0 or 1 */ + ad_sdio(port, (data & (1U << i)) ? 0 : 1); /* RTS 0 or 1 */ ad_sclk(port, 1); /* TXD 1, clock */ ad_sclk(port, 0); /* TXD 0 */ } From dc5b9a99934e561b0c975e936fdd2b39e770626e Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sat, 7 Dec 2019 23:37:29 -0600 Subject: [PATCH 023/205] Fix cppcheck warnings in elektor304.c --- kit/elektor304.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kit/elektor304.c b/kit/elektor304.c index 9fb6b81e5..0db59ad62 100644 --- a/kit/elektor304.c +++ b/kit/elektor304.c @@ -323,7 +323,7 @@ static int ad_write(hamlib_port_t *port, unsigned data) for (i = 0; i < 16; i++) { - ad_sdata(port, data & mask ? 0 : 1); /* RTS 0 or 1 */ + ad_sdata(port, (data & mask ? 0) : 1); /* RTS 0 or 1 */ ad_sclk(port, 1); /* TXD 1, clock */ ad_sclk(port, 0); /* TXD 0 */ mask >>= 1; /* Next bit for masking */ From 75a8f23045cb4bd850078137e540a18024d9bd19 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sat, 7 Dec 2019 23:40:03 -0600 Subject: [PATCH 024/205] Fix parenthesis in elektor304.c --- kit/elektor304.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kit/elektor304.c b/kit/elektor304.c index 0db59ad62..1002451a2 100644 --- a/kit/elektor304.c +++ b/kit/elektor304.c @@ -323,7 +323,7 @@ static int ad_write(hamlib_port_t *port, unsigned data) for (i = 0; i < 16; i++) { - ad_sdata(port, (data & mask ? 0) : 1); /* RTS 0 or 1 */ + ad_sdata(port, (data & mask) ? 0 : 1); /* RTS 0 or 1 */ ad_sclk(port, 1); /* TXD 1, clock */ ad_sclk(port, 0); /* TXD 0 */ mask >>= 1; /* Next bit for masking */ From 1b7b5bb941f97fccf5b62add0be8041869ae89c9 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sat, 7 Dec 2019 23:40:28 -0600 Subject: [PATCH 025/205] Fix cppcheck warnings in elektor507.c --- kit/elektor507.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/kit/elektor507.c b/kit/elektor507.c index 7622d5c01..af0d81580 100644 --- a/kit/elektor507.c +++ b/kit/elektor507.c @@ -967,10 +967,10 @@ static void find_P_Q_DIV1N( { #define VCO_MIN 100000000 #define VCO_MAX 400000000 - int Ptotal, Pmin, Pmax; + int Ptotal; int Qtotal, Qmax = 40; int Div1N; - double REFdivQ, PmulREFdivQ; + double PmulREFdivQ; double Ref = priv->osc_freq * 1000.0; double freq4 = freq * 4; double newdelta, delta = fabs((priv->P * (Ref / priv->Q) / priv->Div1N) - @@ -980,11 +980,11 @@ static void find_P_Q_DIV1N( /* Qmax = (int) ( Ref / 250000); */ for (Qtotal = 2; Qtotal <= Qmax; Qtotal++) { - REFdivQ = (Ref / Qtotal); + double REFdivQ = (Ref / Qtotal); /* For stable operation: Ptotal*(Ref/Qtotal) must be ... */ - Pmin = (int)(VCO_MIN / REFdivQ); /* ... >= 100mHz */ - Pmax = (int)(VCO_MAX / REFdivQ); /* ... <= 400mHz */ + int Pmin = (int)(VCO_MIN / REFdivQ); /* ... >= 100mHz */ + int Pmax = (int)(VCO_MAX / REFdivQ); /* ... <= 400mHz */ for (Ptotal = Pmin; Ptotal <= Pmax; Ptotal++) { @@ -1023,10 +1023,11 @@ int elektor507_set_freq(RIG *rig, vfo_t vfo, freq_t freq) rig->state.priv; freq_t final_freq; int ret = 0; - int Mux; if (priv->ant == ANT_AUTO) { + int Mux; + /* Automatically select appropriate filter */ if (freq <= kHz(1600)) { From ba168e2c75208b939b1a96736d546ae0bc84c02a Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sat, 7 Dec 2019 23:41:30 -0600 Subject: [PATCH 026/205] Fix cppcheck warnings in fifisdr.c --- kit/fifisdr.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/kit/fifisdr.c b/kit/fifisdr.c index c84dcd593..820b49ee7 100644 --- a/kit/fifisdr.c +++ b/kit/fifisdr.c @@ -418,7 +418,7 @@ const char *fifisdr_get_info(RIG *rig) return NULL; } - snprintf(buf, sizeof(buf), "Firmware version: %d", svn_version); + snprintf(buf, sizeof(buf), "Firmware version: %u", svn_version); return buf; } @@ -639,11 +639,6 @@ static int fifisdr_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) /* Transform Hamlib value (float: 0...1) to an integer range (0...100) */ fifi_squelch = (uint8_t)(val.f * 100.0f); - if (fifi_squelch < 0) - { - fifi_squelch = 0; - } - if (fifi_squelch > 100) { fifi_squelch = 100; From 56d096fd1af799d7140fe0c0a0cb3f8c17c1b81d Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sat, 7 Dec 2019 23:47:41 -0600 Subject: [PATCH 027/205] Fix cppcheck warnings in si570avrusb.c --- kit/si570avrusb.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/kit/si570avrusb.c b/kit/si570avrusb.c index b53a00e88..461066a6f 100644 --- a/kit/si570avrusb.c +++ b/kit/si570avrusb.c @@ -869,7 +869,7 @@ int si570xxxusb_set_conf(RIG *rig, token_t token, const char *val) struct si570xxxusb_priv_data *priv; freq_t freq; double multiplier; - int i2c_addr; + unsigned int i2c_addr; priv = (struct si570xxxusb_priv_data *)rig->state.priv; @@ -964,7 +964,7 @@ static int setBPF(RIG *rig, int enable) libusb_device_handle *udh = rig->state.rigport.handle; /* allocate enough space for up to 16 filters */ unsigned short FilterCrossOver[16]; - int nBytes, i; + int nBytes; // Does FilterCrossOver needs endianess ordering ? @@ -982,18 +982,21 @@ static int setBPF(RIG *rig, int enable) if (nBytes > 2) { - nBytes = libusb_control_transfer(udh, REQUEST_TYPE_IN, + int retval = libusb_control_transfer(udh, REQUEST_TYPE_IN, REQUEST_FILTERS, enable, (nBytes / 2) - 1, (unsigned char *) FilterCrossOver, sizeof(FilterCrossOver), rig->state.rigport.timeout); - if (nBytes < 0) + if (retval < 0) { return -RIG_EIO; } + nBytes = retval; rig_debug(RIG_DEBUG_TRACE, "%s: Filter Bank 1:\n", __func__); + int i; + for (i = 0; i < (nBytes / 2) - 1; i++) { rig_debug(RIG_DEBUG_TRACE, " CrossOver[%d] = %f\n", From 0683c199bf25f022ac5d25a3f5cf572ab5f44bbe Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 10:07:00 -0600 Subject: [PATCH 028/205] Fix cppcheck warnings in lowe.c --- lowe/lowe.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lowe/lowe.c b/lowe/lowe.c index 8bb2b7c03..b75baa722 100644 --- a/lowe/lowe.c +++ b/lowe/lowe.c @@ -292,6 +292,18 @@ const char *lowe_get_info(RIG *rig) /* hack: no idea what INF is for */ retval = lowe_transaction(rig, "INF?" EOM, 5, idbuf, &id_len); + if (retval != RIG_OK) + { + rig_debug(RIG_DEBUG_VERBOSE,"%s: INF didn't work\n", __func__); + // non-fatal + } + + if (retval != RIG_OK) + { + return NULL; + } + + /* this is the real one */ retval = lowe_transaction(rig, "TYP?" EOM, 5, idbuf, &id_len); From 98d7e1b285636e5d5ae5b53e310da41964b964ec Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 10:10:10 -0600 Subject: [PATCH 029/205] Fix cppcheck warnings in rc2800.c --- m2/rc2800.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/m2/rc2800.c b/m2/rc2800.c index cd0e2b52c..8d905300c 100644 --- a/m2/rc2800.c +++ b/m2/rc2800.c @@ -68,7 +68,7 @@ static int rc2800_parse(char *s, char *device, float *value) { - int i, msgtype = 0, errcode = 0; + int msgtype = 0, errcode = 0; rig_debug(RIG_DEBUG_TRACE, "%s: device return->%s", __func__, s); @@ -83,6 +83,7 @@ static int rc2800_parse(char *s, char *device, float *value) { if (*s == 'A' || *s == 'E') { + int i; *device = *s; if (!strncmp(s + 2, "ERR=", 4)) @@ -324,15 +325,25 @@ rc2800_rot_stop(ROT *rot) /* Stop AZ*/ retval = rc2800_transaction(rot, "A" CR, NULL, 0); /* select AZ */ + + if (retval != RIG_OK) { rig_debug(RIG_DEBUG_VERBOSE, "%s: A command failed?\n", __func__); } + retval = rc2800_transaction(rot, "S" CR, NULL, 0); /* STOP */ + if (retval != RIG_OK) { rig_debug(RIG_DEBUG_VERBOSE, "%s: az S command failed?\n", __func__); } + /* do not overwhelm the MCU? */ usleep(200 * 1000); /* Stop EL*/ retval = rc2800_transaction(rot, "E" CR, NULL, 0); /* select EL */ + + if (retval != RIG_OK) { rig_debug(RIG_DEBUG_VERBOSE, "%s: E command failed?\n", __func__); } + retval = rc2800_transaction(rot, "S" CR, NULL, 0); /* STOP */ + if (retval != RIG_OK) { rig_debug(RIG_DEBUG_VERBOSE, "%s: el S command failed?\n", __func__); } + return retval; } From ff4a8acb9c60dab46ef7c3f7331f270e10bd9021 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 10:15:31 -0600 Subject: [PATCH 030/205] Fix cppcheck warnings in miniVNA.c --- miniVNA/miniVNA.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/miniVNA/miniVNA.c b/miniVNA/miniVNA.c index 6a052179f..07a79b29b 100644 --- a/miniVNA/miniVNA.c +++ b/miniVNA/miniVNA.c @@ -64,12 +64,14 @@ static int miniVNA_set_freq(RIG *rig, vfo_t vfo, freq_t freq) } +#ifdef XXREMOVEDXX static const char *miniVNA_get_info(RIG *rig) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); return "miniVNA"; } +#endif const struct rig_caps miniVNA_caps = { From 41c4a43e7f832b93a3e0af7bf9641607b1cdbe65 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 10:21:17 -0600 Subject: [PATCH 031/205] Fix cppcheck warnings in pcr --- pcr/pcr.c | 19 +++++++++---------- pcr/pcr.h | 4 ++-- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/pcr/pcr.c b/pcr/pcr.c index ea87c429d..f4422aa8a 100644 --- a/pcr/pcr.c +++ b/pcr/pcr.c @@ -167,7 +167,6 @@ static int is_sub_rcvr(RIG *rig, vfo_t vfo); static int pcr_read_block(RIG *rig, char *rxbuffer, size_t count) { - int err; int read = 0, tries = 4; struct rig_state *rs = &rig->state; @@ -188,7 +187,7 @@ pcr_read_block(RIG *rig, char *rxbuffer, size_t count) char *p = &rxbuffer[0]; /* read first char */ - err = read_block(&rs->rigport, p, 1); + int err = read_block(&rs->rigport, p, 1); if (err < 0) { @@ -813,7 +812,7 @@ pcr_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) unsigned char buf[20]; int buf_len, err; - int pcrmode, pcrfilter; + int pcrmode; rig_debug(RIG_DEBUG_VERBOSE, "%s: mode = %s, width = %d\n", __func__, rig_strrmode(mode), (int)width); @@ -862,6 +861,7 @@ pcr_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) if (width != RIG_PASSBAND_NOCHANGE) { + int pcrfilter; if (width == RIG_PASSBAND_NORMAL) { width = rig_passband_normal(rig, mode); @@ -1076,8 +1076,8 @@ pcr_get_info(RIG *rig) "Optional devices:%s%s%s, Country: %s", priv->firmware / 10, priv->firmware % 10, priv->protocol / 10, priv->protocol % 10, - priv->options & OPT_UT106 ? " DSP" : "", - priv->options & OPT_UT107 ? " DARC" : "", + (priv->options & OPT_UT106) ? " DSP" : "", + (priv->options & OPT_UT107) ? " DARC" : "", priv->options ? "" : " none", country); @@ -1086,8 +1086,8 @@ pcr_get_info(RIG *rig) __func__, priv->firmware / 10, priv->firmware % 10, priv->protocol / 10, priv->protocol % 10, - priv->options & OPT_UT106 ? " DSP" : "", - priv->options & OPT_UT107 ? " DARC" : "", + (priv->options & OPT_UT106) ? " DSP" : "", + (priv->options & OPT_UT107) ? " DARC" : "", priv->options ? "" : " none", country); @@ -1974,11 +1974,10 @@ int pcr_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd) struct pcr_priv_data *priv = (struct pcr_priv_data *) rig->state.priv; struct pcr_rcvr *rcvr = is_sub_rcvr(rig, vfo) ? &priv->sub_rcvr : &priv->main_rcvr; - int err; if (priv->auto_update == 0) { - err = pcr_transaction(rig, is_sub_rcvr(rig, vfo) ? "I4?" : "I0?"); + int err = pcr_transaction(rig, is_sub_rcvr(rig, vfo) ? "I4?" : "I0?"); if (err != RIG_OK) { @@ -1993,7 +1992,7 @@ int pcr_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd) * Bit 2: VSC open * Bit 3: RX error (not ready to receive) */ - *dcd = rcvr->squelch_status & 0x02 ? RIG_DCD_ON : RIG_DCD_OFF; + *dcd = (rcvr->squelch_status & 0x02) ? RIG_DCD_ON : RIG_DCD_OFF; return RIG_OK; } diff --git a/pcr/pcr.h b/pcr/pcr.h index e9e3938ab..bc8d7f106 100644 --- a/pcr/pcr.h +++ b/pcr/pcr.h @@ -49,8 +49,8 @@ struct pcr_priv_data float volume; float squelch; - int raw_level; - int squelch_status; + unsigned int raw_level; + unsigned int squelch_status; } main_rcvr, sub_rcvr; From 8af5a675d0c0223d9b4dcd89ed56d2c5253f2322 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 10:24:55 -0600 Subject: [PATCH 032/205] Fix cppcheck warnings in prm80.c --- prm80/prm80.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/prm80/prm80.c b/prm80/prm80.c index e168ae5d4..d7c29c440 100644 --- a/prm80/prm80.c +++ b/prm80/prm80.c @@ -99,7 +99,6 @@ static int prm80_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, return retval; } - retbuf[retval] = '\0'; #if 0 /* @@ -230,7 +229,7 @@ int prm80_set_mem(RIG *rig, vfo_t vfo, int ch) return -RIG_EINVAL; } - cmd_len = sprintf(cmdbuf, "N%02u", ch); + cmd_len = sprintf(cmdbuf, "N%02d", ch); return prm80_transaction(rig, cmdbuf, cmd_len, NULL, NULL); } @@ -318,9 +317,9 @@ int prm80_get_channel(RIG *rig, channel_t *chan) chanstate = hhtoi(statebuf + 4) & 0x0f; /* is it rptr_shift or split mode ? */ chan->rptr_shift = (chanstate & 0x01) == 0 ? RIG_RPT_SHIFT_NONE : - chanstate & 0x02 ? RIG_RPT_SHIFT_MINUS : - chanstate & 0x04 ? RIG_RPT_SHIFT_PLUS : RIG_RPT_SHIFT_NONE; - chan->flags = chanstate & 0x08 ? RIG_CHFLAG_SKIP : 0; + (chanstate & 0x02) ? RIG_RPT_SHIFT_MINUS : + (chanstate & 0x04) ? RIG_RPT_SHIFT_PLUS : RIG_RPT_SHIFT_NONE; + chan->flags = (chanstate & 0x08) ? RIG_CHFLAG_SKIP : 0; chan->levels[LVL_SQL].f = ((float)(hhtoi(statebuf + 6) >> 4)) / 15.; chan->levels[LVL_AF].f = ((float)(hhtoi(statebuf + 8) >> 4)) / 15.; @@ -356,12 +355,12 @@ int prm80_set_channel(RIG *rig, const channel_t *chan) /* [T] = Set current channel state. (Mode-Chan-Chanstate-Sql-Vol-Lock-RX freq-TX freq) ? */ /* Example: 1240080AFF0033F02D40 ? */ statebuf_len = sprintf(statebuf, "T%02X%02X%02X%02X%02X%02X%04X%04X", - chan->mode == RIG_MODE_FM ? 0x12 : 0x12, + (chan->mode == RIG_MODE_FM) ? 0x12 : 0x12, chan->channel_num, - chan->flags & RIG_CHFLAG_SKIP ? 0x08 : 0, /* TODO: tx shift */ + (chan->flags & RIG_CHFLAG_SKIP) ? 0x08 : 0, /* TODO: tx shift */ (unsigned)(chan->levels[LVL_SQL].f * 15), (unsigned)(chan->levels[LVL_AF].f * 15), - chan->flags & RIG_CHFLAG_SKIP ? 0x01 : 0x00, /* Lock */ + (chan->flags & RIG_CHFLAG_SKIP) ? 0x01 : 0x00, /* Lock */ (unsigned)(chan->freq / 12500.), (unsigned)(chan->tx_freq / 12500.) ); From dc14ae10d45d21dc15d6853f8e5cf6aeb0455d95 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 10:27:15 -0600 Subject: [PATCH 033/205] Fix cppcheck warnings in prosistel.c --- prosistel/prosistel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prosistel/prosistel.c b/prosistel/prosistel.c index 5fc94eafc..e9ea6b80e 100644 --- a/prosistel/prosistel.c +++ b/prosistel/prosistel.c @@ -119,7 +119,7 @@ transaction_write: } //check if reply match issued command - if (data[0] == 0x02 && data[3] == cmdstr[2]) + if ( cmdstr && data[0] == 0x02 && data[3] == cmdstr[2]) { rig_debug(RIG_DEBUG_VERBOSE, "%s Command %c reply received\n", __func__, data[3]); From 1db7580cf28997a56cadc3363b87e8a427228bd3 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 15:50:47 -0600 Subject: [PATCH 034/205] Fix cppcheck warnings in ra37xx.c --- racal/ra37xx.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/racal/ra37xx.c b/racal/ra37xx.c index ce02f6266..d5d8dc0b9 100644 --- a/racal/ra37xx.c +++ b/racal/ra37xx.c @@ -341,7 +341,7 @@ int ra37xx_set_freq(RIG *rig, vfo_t vfo, freq_t freq) char freqbuf[BUFSZ]; int freq_len; - freq_len = sprintf(freqbuf, "F%ld", (unsigned long)freq); + freq_len = sprintf(freqbuf, "F%lu", (unsigned long)freq); if (freq_len < 0) { @@ -377,7 +377,7 @@ int ra37xx_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) int ra37xx_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) { //struct ra37xx_priv_data *priv = (struct ra37xx_priv_data*)rig->state.priv; - int ra_mode, widthtype, widthnum; + int ra_mode, widthtype, widthnum=0; char buf[BUFSZ]; switch (mode) @@ -407,19 +407,19 @@ int ra37xx_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) width = rig_passband_normal(rig, mode); } + rig_debug(RIG_DEBUG_TRACE, "%s: widthtype = %i, widthnum = %i not implemented\n", __func__, widthtype, widthnum); +#ifdef XXREMOVEDXX widthtype = 0; /* FIXME: no bandwidth for now */ widthnum = 0; /* width set using 'B', QBCON must be queried firsthand */ +#endif -#if 0 +#ifdef XXREMOVEDXX sprintf(buf, "M%d;B%d,%d", ra_mode, widthtype, widthnum); #else sprintf(buf, "M%d", ra_mode); #endif - rig_debug(RIG_DEBUG_TRACE, "%s: widthtype = %i, widthnum = %i\n", __func__, - widthtype, widthnum); - return ra37xx_transaction(rig, buf, NULL, NULL); } From 14578fb36d36a63839c7a9ca59b935c7caaf1835 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 15:51:30 -0600 Subject: [PATCH 035/205] Fix cppcheck warnings in racal.c --- racal/racal.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/racal/racal.c b/racal/racal.c index 30df4869d..c8a7cebd2 100644 --- a/racal/racal.c +++ b/racal/racal.c @@ -82,7 +82,7 @@ static int racal_transaction(RIG *rig, const char *cmd, char *data, int cmd_len; int retval; - cmd_len = sprintf(cmdbuf, SOM "%d%s" EOM, priv->receiver_id, cmd); + cmd_len = sprintf(cmdbuf, SOM "%u%s" EOM, priv->receiver_id, cmd); serial_flush(&rs->rigport); @@ -198,7 +198,7 @@ int racal_get_conf(RIG *rig, token_t token, char *val) switch (token) { case TOK_RIGID: - sprintf(val, "%d", priv->receiver_id); + sprintf(val, "%u", priv->receiver_id); break; default: From 6ea235496d9951bbdd00c88c93228e78b4abb83d Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 15:59:50 -0600 Subject: [PATCH 036/205] Fix cppcheck warnings in gp2000.c --- rs/gp2000.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/rs/gp2000.c b/rs/gp2000.c index 20e2160ab..2a93ad594 100644 --- a/rs/gp2000.c +++ b/rs/gp2000.c @@ -289,6 +289,8 @@ gp2000_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) } +#ifdef XXREMOVEDXX +// Not referenced anywhere int gp2000_set_func(RIG *rig, vfo_t vfo, setting_t func, int status) { @@ -312,7 +314,10 @@ gp2000_set_func(RIG *rig, vfo_t vfo, setting_t func, int status) return retval; } +#endif +#ifdef XXREMOVEDXX +// Not referenced anywhere int gp2000_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status) { @@ -343,6 +348,7 @@ gp2000_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status) return retval; } +#endif int gp2000_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) @@ -469,15 +475,15 @@ gp2000_get_info(RIG *rig) switch (p[0]) { case 0x0a: - sscanf(p, "%*cIDENT%s", type); + sscanf(p, "%*cIDENT%31s", type); break; case 'i': - sscanf(p, "id%s", rigid); + sscanf(p, "id%31s", rigid); break; case 's': - sscanf(p, "sn%s", sernum); + sscanf(p, "sn%31s", sernum); break; default: From 5630996b3d6ce8761252a4a04ce99f9de714f710 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 16:01:13 -0600 Subject: [PATCH 037/205] Fix cppcheck warnings in skanti.c --- skanti/skanti.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skanti/skanti.c b/skanti/skanti.c index 1f53e2588..cc6e1bfed 100644 --- a/skanti/skanti.c +++ b/skanti/skanti.c @@ -68,7 +68,6 @@ static int skanti_transaction(RIG *rig, const char *cmd, int cmd_len, { int retval; struct rig_state *rs; - char retbuf[BUFSZ + 1]; rs = &rig->state; @@ -88,6 +87,7 @@ static int skanti_transaction(RIG *rig, const char *cmd, int cmd_len, /* * Transceiver sends back ">" */ + char retbuf[BUFSZ + 1]; retval = read_string(&rs->rigport, retbuf, BUFSZ, PROMPT, strlen(PROMPT)); if (retval < 0) From 00572f9ae7834f267e1c0e884a8e836d766b021d Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 16:03:38 -0600 Subject: [PATCH 038/205] Fix cppcheck warnings in trp8255.c --- skanti/trp8255.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/skanti/trp8255.c b/skanti/trp8255.c index 9a3bf1c4b..af21d54f7 100644 --- a/skanti/trp8255.c +++ b/skanti/trp8255.c @@ -183,13 +183,13 @@ const struct rig_caps trp8255_caps = /* TODO: retry */ static int cu_transaction(RIG *rig, const char *cmd, int cmd_len) { - int i, ret; + int i; char retchar; for (i = 0; i < cmd_len; i++) { - ret = write_block(&rig->state.rigport, &cmd[i], 1); + int ret = write_block(&rig->state.rigport, &cmd[i], 1); if (ret != RIG_OK) { @@ -396,8 +396,7 @@ int cu_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) { cmdbuf[0] = 'S'; /* low */ } - - if (val.f < 0.6) + else if (val.f < 0.6) { cmdbuf[0] = 'U'; /* medium */ } From 6305ff4cd40f1c47edca65237b5f608663afaaa8 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 16:04:46 -0600 Subject: [PATCH 039/205] Fix cppcheck warnings in spid.c --- spid/spid.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spid/spid.c b/spid/spid.c index 82cca236a..7948397a9 100644 --- a/spid/spid.c +++ b/spid/spid.c @@ -47,8 +47,6 @@ struct spid_rot2prog_priv_data static int spid_rot_init(ROT *rot) { - struct spid_rot2prog_priv_data *priv; - rig_debug(RIG_DEBUG_TRACE, "%s called\n", __func__); if (!rot || !rot->caps) @@ -59,6 +57,8 @@ static int spid_rot_init(ROT *rot) if (rot->caps->rot_model == ROT_MODEL_SPID_ROT2PROG || rot->caps->rot_model == ROT_MODEL_SPID_MD01_ROT2PROG) { + struct spid_rot2prog_priv_data *priv; + priv = (struct spid_rot2prog_priv_data *)malloc(sizeof(struct spid_rot2prog_priv_data)); From 8e5dc87ffdd5b6b6d76a5ac195238741fd7d03b1 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 16:06:58 -0600 Subject: [PATCH 040/205] Fix cppcheck warnings in amp_conf.c --- src/amp_conf.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/amp_conf.c b/src/amp_conf.c index 1723f729f..bd22176bd 100644 --- a/src/amp_conf.c +++ b/src/amp_conf.c @@ -432,6 +432,8 @@ int frontamp_get_conf(AMP *amp, token_t token, char *val) } +#ifdef XXREMOVEDXXC +// Not referenced anywhere /** * \brief Executes cfunc on all the elements stored in the conf table * \param amp non-null @@ -483,6 +485,7 @@ int HAMLIB_API amp_token_foreach(AMP *amp, return RIG_OK; } +#endif /** From 91678ef5730f7034b2b2df6fc4237cc142ba9ac4 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 16:27:46 -0600 Subject: [PATCH 041/205] Fix cppcheck warnings in amplifier.c --- src/amplifier.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/amplifier.c b/src/amplifier.c index d83affa78..266a06811 100644 --- a/src/amplifier.c +++ b/src/amplifier.c @@ -125,6 +125,7 @@ static int remove_opened_amp(AMP *amp) } +#ifdef XXREMOVEDXX /** * \brief execs cfunc() on each opened amp * \param cfunc The function to be executed on each amp @@ -157,6 +158,7 @@ int foreach_opened_amp(int (*cfunc)(AMP *, rig_ptr_t), rig_ptr_t data) return RIG_OK; } +#endif /** @@ -176,7 +178,6 @@ AMP *HAMLIB_API amp_init(amp_model_t amp_model) AMP *amp; const struct amp_caps *caps; struct amp_state *rs; - int retcode; amp_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -253,7 +254,7 @@ AMP *HAMLIB_API amp_init(amp_model_t amp_model) */ if (caps->amp_init != NULL) { - retcode = caps->amp_init(amp); + int retcode = caps->amp_init(amp); if (retcode != RIG_OK) { @@ -654,6 +655,8 @@ int HAMLIB_API amp_get_ext_level(AMP *amp, token_t level, value_t *val) return amp->caps->get_ext_level(amp, level, val); } +#if XXREMOVEDXX +// Not referenced anywhere /** * \brief turn on/off the amplifier or standby/operate toggle * \param amp The amp handle @@ -686,6 +689,7 @@ int HAMLIB_API amp_set_powerstat(AMP *amp, powerstat_t status) return amp->caps->set_powerstat(amp, status); } +#endif int HAMLIB_API amp_get_powerstat(AMP *amp, powerstat_t *status) { From 910d799494dbb8f96149a86274360bcf7f5bdcb9 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 16:29:39 -0600 Subject: [PATCH 042/205] Fix cppcheck warnings in cm108.c --- src/cm108.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/cm108.c b/src/cm108.c index 0ad93c692..efe373d71 100644 --- a/src/cm108.c +++ b/src/cm108.c @@ -246,9 +246,7 @@ int cm108_ptt_get(hamlib_port_t *p, ptt_t *pttx) { case RIG_PTT_CM108: { - int status; return -RIG_ENIMPL; - return status; } default: @@ -262,6 +260,8 @@ int cm108_ptt_get(hamlib_port_t *p, ptt_t *pttx) return RIG_OK; } +#ifdef XXREMOVEXX +// Not referenced anywhere /** * \brief get Data Carrier Detect (squelch) from CM108 GPIO * \param p @@ -281,9 +281,7 @@ int cm108_dcd_get(hamlib_port_t *p, dcd_t *dcdx) { case RIG_DCD_CM108: { - int status; return -RIG_ENIMPL; - return status; } default: @@ -296,5 +294,6 @@ int cm108_dcd_get(hamlib_port_t *p, dcd_t *dcdx) return RIG_OK; } +#endif /** @} */ From 531782d339fd8bb651ec5091b7f57181fe7ccf03 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 16:30:33 -0600 Subject: [PATCH 043/205] Fix cppcheck warnings in debug.c --- src/debug.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/debug.c b/src/debug.c index 8c06ecf41..74746e553 100644 --- a/src/debug.c +++ b/src/debug.c @@ -73,7 +73,6 @@ void dump_hex(const unsigned char ptr[], size_t size) * 0010 30 30 0d 0a 00.. */ char line[4 + 4 + 3 * DUMP_HEX_WIDTH + 4 + DUMP_HEX_WIDTH + 1]; - unsigned char c; int i; if (!rig_need_debug(RIG_DEBUG_TRACE)) @@ -92,7 +91,7 @@ void dump_hex(const unsigned char ptr[], size_t size) memset(line + 4, ' ', sizeof(line) - 4 - 1); } - c = ptr[i]; + char c = ptr[i]; /* hex print */ sprintf(line + 8 + 3 * (i % DUMP_HEX_WIDTH), "%02x", c); From 67c3b56ccd5ac5779b0db2eb4be95c945d6775e4 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 16:32:13 -0600 Subject: [PATCH 044/205] Fix cppcheck warnings in event.c --- src/event.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/event.c b/src/event.c index 0b54c00df..47993d671 100644 --- a/src/event.c +++ b/src/event.c @@ -790,7 +790,8 @@ int HAMLIB_API rig_set_trn(RIG *rig, int trn) { #ifdef HAVE_SETITIMER - retcode = remove_trn_poll_rig(rig); + // don't care about the return code here + remove_trn_poll_rig(rig); value.it_value.tv_sec = 0; value.it_value.tv_usec = 0; From 314fe20f396cd9ce9b421cbb8b498dd81bf4d8e8 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 16:35:55 -0600 Subject: [PATCH 045/205] Fix cppcheck warnings in ext.c --- src/ext.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/ext.c b/src/ext.c index 2dc17aa4b..1cdb6123c 100644 --- a/src/ext.c +++ b/src/ext.c @@ -67,7 +67,6 @@ int HAMLIB_API rig_ext_level_foreach(RIG *rig, rig_ptr_t data) { const struct confparams *cfp; - int ret; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -78,7 +77,7 @@ int HAMLIB_API rig_ext_level_foreach(RIG *rig, for (cfp = rig->caps->extlevels; cfp && cfp->name; cfp++) { - ret = (*cfunc)(rig, cfp, data); + int ret = (*cfunc)(rig, cfp, data); if (ret == 0) { @@ -113,7 +112,6 @@ int HAMLIB_API rig_ext_parm_foreach(RIG *rig, rig_ptr_t data) { const struct confparams *cfp; - int ret; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -124,7 +122,7 @@ int HAMLIB_API rig_ext_parm_foreach(RIG *rig, for (cfp = rig->caps->extparms; cfp && cfp->name; cfp++) { - ret = (*cfunc)(rig, cfp, data); + int ret = (*cfunc)(rig, cfp, data); if (ret == 0) { From 55e36895bf7febb42db1d8bea34dfc413260bd19 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 16:36:45 -0600 Subject: [PATCH 046/205] Fix cppcheck warnings in extamp.c --- src/extamp.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/extamp.c b/src/extamp.c index 89bb77691..b93785a7b 100644 --- a/src/extamp.c +++ b/src/extamp.c @@ -69,7 +69,6 @@ int HAMLIB_API amp_ext_level_foreach(AMP *amp, amp_ptr_t data) { const struct confparams *cfp; - int ret; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -80,7 +79,7 @@ int HAMLIB_API amp_ext_level_foreach(AMP *amp, for (cfp = amp->caps->extlevels; cfp && cfp->name; cfp++) { - ret = (*cfunc)(amp, cfp, data); + int ret = (*cfunc)(amp, cfp, data); if (ret == 0) { @@ -115,7 +114,6 @@ int HAMLIB_API amp_ext_parm_foreach(AMP *amp, amp_ptr_t data) { const struct confparams *cfp; - int ret; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -126,7 +124,7 @@ int HAMLIB_API amp_ext_parm_foreach(AMP *amp, for (cfp = amp->caps->extparms; cfp && cfp->name; cfp++) { - ret = (*cfunc)(amp, cfp, data); + int ret = (*cfunc)(amp, cfp, data); if (ret == 0) { From 0ec255366f8f3a5faf79edb7aaf6ea42eb6cd532 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 16:54:15 -0600 Subject: [PATCH 047/205] Fix gpio file descriptor leak in gpio.c --- src/rig.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/rig.c b/src/rig.c index d7cac221c..d535457b7 100644 --- a/src/rig.c +++ b/src/rig.c @@ -703,6 +703,7 @@ int HAMLIB_API rig_open(RIG *rig) else { gpio_ptt_set(&rs->pttport, RIG_PTT_OFF); + gpio_close(&rs->pttport); } break; @@ -721,6 +722,7 @@ int HAMLIB_API rig_open(RIG *rig) else { gpio_ptt_set(&rs->pttport, RIG_PTT_OFF); + gpio_close(&rs->pttport); } break; @@ -793,6 +795,9 @@ int HAMLIB_API rig_open(RIG *rig) rs->dcdport.pathname); status = -RIG_EIO; } + else { + gpio_close(&rs->dcdport); + } break; @@ -807,6 +812,9 @@ int HAMLIB_API rig_open(RIG *rig) rs->dcdport.pathname); status = -RIG_EIO; } + else { + gpio_close(&rs->dcdport); + } break; From 1011ea16e49e0a3e627ad25cb62489e58c1ab98f Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 16:56:14 -0600 Subject: [PATCH 048/205] Fix cppcheck warnings in iofunc.c --- src/iofunc.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/iofunc.c b/src/iofunc.c index d7c71bb83..bda352b52 100644 --- a/src/iofunc.c +++ b/src/iofunc.c @@ -369,16 +369,15 @@ static int port_select(hamlib_port_t *p, 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) { unsigned char *pbuf = buf; - ret = read(p->fd, buf, count); + int ret = read(p->fd, buf, count); /* clear MSB */ + int i; + for (i = 0; i < ret; i++) { pbuf[i] &= ~0x80; @@ -428,7 +427,7 @@ static ssize_t port_read(hamlib_port_t *p, void *buf, size_t count) int HAMLIB_API write_block(hamlib_port_t *p, const char *txbuffer, size_t count) { - int i, ret; + int ret; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -460,6 +459,8 @@ int HAMLIB_API write_block(hamlib_port_t *p, const char *txbuffer, size_t count) if (p->write_delay > 0) { + int i; + for (i = 0; i < count; i++) { ret = port_write(p, txbuffer + i, 1); @@ -545,8 +546,7 @@ int HAMLIB_API read_block(hamlib_port_t *p, char *rxbuffer, size_t count) { fd_set rfds, efds; struct timeval tv, tv_timeout, start_time, end_time, elapsed_time; - int rd_count, total_count = 0; - int retval; + int total_count = 0; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -567,7 +567,7 @@ int HAMLIB_API read_block(hamlib_port_t *p, char *rxbuffer, size_t count) FD_SET(p->fd, &rfds); efds = rfds; - retval = port_select(p, p->fd + 1, &rfds, NULL, &efds, &tv); + int retval = port_select(p, p->fd + 1, &rfds, NULL, &efds, &tv); if (retval == 0) { @@ -612,7 +612,7 @@ int HAMLIB_API read_block(hamlib_port_t *p, char *rxbuffer, size_t count) * grab bytes from the rig * The file descriptor must have been set up non blocking. */ - rd_count = port_read(p, rxbuffer + total_count, count); + int rd_count = port_read(p, rxbuffer + total_count, count); if (rd_count < 0) { @@ -668,8 +668,7 @@ int HAMLIB_API read_string(hamlib_port_t *p, { fd_set rfds, efds; struct timeval tv, tv_timeout, start_time, end_time, elapsed_time; - int rd_count, total_count = 0; - int retval; + int total_count = 0; rig_debug(RIG_DEBUG_TRACE, "%s called\n", __func__); @@ -702,7 +701,7 @@ int HAMLIB_API read_string(hamlib_port_t *p, FD_SET(p->fd, &rfds); efds = rfds; - retval = port_select(p, p->fd + 1, &rfds, NULL, &efds, &tv); + int retval = port_select(p, p->fd + 1, &rfds, NULL, &efds, &tv); if (retval == 0) { @@ -752,7 +751,7 @@ int HAMLIB_API read_string(hamlib_port_t *p, * read 1 character from the rig, (check if in stop set) * The file descriptor must have been set up non blocking. */ - rd_count = port_read(p, &rxbuffer[total_count], 1); + int rd_count = port_read(p, &rxbuffer[total_count], 1); /* if we get 0 bytes or an error something is wrong */ if (rd_count <= 0) From 5be9dfe161a0a4681ca76b6f469e98bb5b997258 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 16:58:18 -0600 Subject: [PATCH 049/205] Fix cppcheck warnings in locator.c --- src/locator.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/locator.c b/src/locator.c index cd90309ec..bb936ec9b 100644 --- a/src/locator.c +++ b/src/locator.c @@ -400,8 +400,7 @@ int HAMLIB_API locator2longlat(double *longitude, { int x_or_y, paircount; int locvalue, pair; - int divisions; - double xy[2], ordinate; + double xy[2]; rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -426,8 +425,8 @@ int HAMLIB_API locator2longlat(double *longitude, /* For x(=longitude) and y(=latitude) */ for (x_or_y = 0; x_or_y < 2; ++x_or_y) { - ordinate = -90.0; - divisions = 1; + double ordinate = -90.0; + int divisions = 1; for (pair = 0; pair < paircount; ++pair) { @@ -488,8 +487,8 @@ int HAMLIB_API longlat2locator(double longitude, char *locator, int pair_count) { - int x_or_y, pair, locvalue, divisions; - double square_size, ordinate; + int x_or_y, pair, locvalue; + double square_size; rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -505,8 +504,8 @@ int HAMLIB_API longlat2locator(double longitude, for (x_or_y = 0; x_or_y < 2; ++x_or_y) { - ordinate = (x_or_y == 0) ? longitude / 2.0 : latitude; - divisions = 1; + double ordinate = (x_or_y == 0) ? longitude / 2.0 : latitude; + int divisions = 1; /* The 1e-6 here guards against floating point rounding errors */ ordinate = fmod(ordinate + 270.000001, 180.0); From 7020aba16df0c4bf3805edfdb734d6cd97fe4d46 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 17:04:08 -0600 Subject: [PATCH 050/205] Fix cppcheck warnings in mem.c --- src/mem.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/mem.c b/src/mem.c index f588ad0d1..5831ba2b4 100644 --- a/src/mem.c +++ b/src/mem.c @@ -253,7 +253,6 @@ static int generic_retr_extl(RIG *rig, { channel_t *chan = (channel_t *)ptr; struct ext_list *p; - unsigned el_size = 0; if (chan->ext_levels == NULL) { @@ -261,6 +260,7 @@ static int generic_retr_extl(RIG *rig, } else { + unsigned el_size = 0; for (p = chan->ext_levels; !RIG_IS_EXT_END(*p); p++) { el_size += sizeof(struct ext_list); @@ -357,7 +357,7 @@ static int rig_mem_caps_empty(const channel_cap_t *mem_cap) */ static int generic_save_channel(RIG *rig, channel_t *chan) { - int i, retval; + int i; int chan_num; vfo_t vfo; setting_t setting; @@ -388,7 +388,7 @@ static int generic_save_channel(RIG *rig, channel_t *chan) if (mem_cap->freq) { - retval = rig_get_freq(rig, RIG_VFO_CURR, &chan->freq); + int retval = rig_get_freq(rig, RIG_VFO_CURR, &chan->freq); /* empty channel ? */ if (retval == -RIG_ENAVAIL || chan->freq == RIG_FREQ_NONE) @@ -950,7 +950,7 @@ int HAMLIB_API rig_get_channel(RIG *rig, channel_t *chan) #ifndef DOC_HIDDEN int get_chan_all_cb_generic(RIG *rig, chan_cb_t chan_cb, rig_ptr_t arg) { - int i, j, retval; + int i, j; chan_t *chan_list = rig->state.chan_list; channel_t *chan; @@ -963,7 +963,7 @@ int get_chan_all_cb_generic(RIG *rig, chan_cb_t chan_cb, rig_ptr_t arg) * future data for channel channel_num */ chan = NULL; - retval = chan_cb(rig, &chan, chan_list[i].startc, chan_list, arg); + int retval = chan_cb(rig, &chan, chan_list[i].startc, chan_list, arg); if (retval != RIG_OK) { @@ -1572,7 +1572,7 @@ const chan_t *HAMLIB_API rig_lookup_mem_caps(RIG *rig, int ch) { chan_t *chan_list; static chan_t chan_list_all; - int i, j; + int i; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -1598,6 +1598,7 @@ 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 */ + int j; for (j = 0; j < sizeof(channel_cap_t); j++) { p1[j] |= p2[j]; @@ -1624,6 +1625,8 @@ const chan_t *HAMLIB_API rig_lookup_mem_caps(RIG *rig, int ch) } +#ifdef XXREMOVEDXX +// Not referenced anywhere /** * \brief get memory channel count * \param rig The rig handle @@ -1654,5 +1657,6 @@ int HAMLIB_API rig_mem_count(RIG *rig) return count; } +#endif /*! @} */ From 6ba8f88e2fb6e83ee9035b09d00684173418eba4 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 17:09:08 -0600 Subject: [PATCH 051/205] Fix cppcheck warnings in network.c --- src/network.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/network.c b/src/network.c index 953a6d79e..192a48ad3 100644 --- a/src/network.c +++ b/src/network.c @@ -280,7 +280,6 @@ int network_open(hamlib_port_t *rp, int default_port) */ void network_flush(hamlib_port_t *rp) { - int ret; #ifdef __MINGW32__ ULONG len = 0; #else @@ -293,6 +292,7 @@ void network_flush(hamlib_port_t *rp) for (;;) { + int ret; len = 0; #ifdef __MINGW32__ ret = ioctlsocket(rp->fd, FIONREAD, &len); From c90b1dd7c6d403f3e719159933f74a4d5edb111f Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 22:27:44 -0600 Subject: [PATCH 052/205] Fix cppcheck warnings in microham.c --- src/microham.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/microham.c b/src/microham.c index 9b00ed20b..ce3161bfd 100644 --- a/src/microham.c +++ b/src/microham.c @@ -406,7 +406,6 @@ 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]); @@ -482,6 +481,7 @@ static void parseFrame(unsigned char *frame) controlstring[numcontrolbytes++] = byte; DEBUG("%10d:FromControl:", TIME); + int i; for (i = 0; i < numcontrolbytes; i++) { DEBUG(" %02x", controlstring[i]); } DEBUG(".\n"); @@ -522,7 +522,7 @@ static void parseFrame(unsigned char *frame) static void writeRadio(unsigned char *bytes, int len) { unsigned char seq[4]; - int i, ret; + int i; DEBUG("%10d:Send radio data: ", TIME); @@ -549,6 +549,7 @@ static void writeRadio(unsigned char *bytes, int len) seq[0] |= 0x04; } + int ret; if ((ret = write(uh_device_fd, seq, 4)) < 4) { MYERROR("WriteRadio failed with %d\n", ret); @@ -607,7 +608,7 @@ static void writeFlags() static void writeWkey(unsigned char *bytes, int len) { unsigned char seq[12]; - int i, ret; + int i; DEBUG("%10d:Send WinKey data: ", TIME); for (i = 0; i < len; i++) { DEBUG(" %02x", (int) bytes[i]); } @@ -642,6 +643,7 @@ static void writeWkey(unsigned char *bytes, int len) seq[ 8] |= 0x01; } + int ret; if ((ret = write(uh_device_fd, seq, 12)) < 12) { MYERROR("WriteWINKEY failed with %d\n", ret); @@ -663,7 +665,7 @@ static void writeWkey(unsigned char *bytes, int len) // static void writeControl(unsigned char *data, int len) { - int i, ret; + int i; unsigned char seq[8]; DEBUG("%10d:WriteControl:", TIME); @@ -703,6 +705,7 @@ static void writeControl(unsigned char *data, int len) seq[4] |= 0x01; } + int ret; if ((ret = write(uh_device_fd, seq, 8)) < 8) { MYERROR("WriteControl failed, ret=%d\n", ret); @@ -747,12 +750,9 @@ static void *read_device(void *p) { unsigned char frame[4]; int framepos = 0; - int ret; unsigned char buf[2]; fd_set fds; struct timeval tv; - int maxdev; - // the bytes from the microHam decive come in "frames" // a frame is a four-byte sequence. The first byte has the MSB unset, @@ -792,7 +792,7 @@ static void *read_device(void *p) FD_SET(uh_wkey_pair[0], &fds); // determine max of these fd's for use in select() - maxdev = uh_device_fd; + int maxdev = uh_device_fd; if (uh_radio_pair[0] > maxdev) { @@ -811,7 +811,7 @@ static void *read_device(void *p) tv.tv_usec = 100000; tv.tv_sec = 0; - ret = select(maxdev + 1, &fds, NULL, NULL, &tv); + int ret = select(maxdev + 1, &fds, NULL, NULL, &tv); // // select returned error, or nothing has arrived: @@ -1117,6 +1117,8 @@ void uh_close_radio() } +#ifdef XXREMOVEDXX +// Not referenced anywhere void uh_close_wkey() { uh_wkey_in_use = 0; @@ -1126,7 +1128,7 @@ void uh_close_wkey() close_microham(); } } - +#endif int uh_open_ptt() { @@ -1145,6 +1147,8 @@ int uh_open_ptt() } +#ifdef XXREVMOVEDXX +// Not referenced anywhere int uh_open_wkey() { if (!uh_is_initialized) @@ -1160,6 +1164,7 @@ int uh_open_wkey() uh_wkey_in_use = 1; return uh_wkey_pair[1]; } +#endif // From 8f5ac2d68cdfd1ee495245d3e0987594e753705b Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 22:29:48 -0600 Subject: [PATCH 053/205] Fix cppcheck warnings in misc.c --- src/misc.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/misc.c b/src/misc.c index 480a98240..b3e86ee9e 100644 --- a/src/misc.c +++ b/src/misc.c @@ -81,7 +81,6 @@ unsigned char *HAMLIB_API to_bcd(unsigned char bcd_data[], unsigned bcd_len) { int i; - unsigned char a; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -90,7 +89,7 @@ unsigned char *HAMLIB_API to_bcd(unsigned char bcd_data[], for (i = 0; i < bcd_len / 2; i++) { - a = freq % 10; + unsigned char a = freq % 10; freq /= 10; a |= (freq % 10) << 4; freq /= 10; @@ -166,7 +165,6 @@ unsigned char *HAMLIB_API to_bcd_be(unsigned char bcd_data[], unsigned bcd_len) { int i; - unsigned char a; /* '450'/4 -> 0,4;5,0 */ /* '450'/3 -> 4,5;0,x */ @@ -183,7 +181,7 @@ unsigned char *HAMLIB_API to_bcd_be(unsigned char bcd_data[], for (i = (bcd_len / 2) - 1; i >= 0; i--) { - a = freq % 10; + unsigned char a = freq % 10; freq /= 10; a |= (freq % 10) << 4; freq /= 10; From 9aa920a873a0a32d089561acedfb8368a9a6e79e Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 22:35:33 -0600 Subject: [PATCH 054/205] Fix cppcheck warnings in parallel.c --- src/parallel.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/parallel.c b/src/parallel.c index 763c82435..827451db6 100644 --- a/src/parallel.c +++ b/src/parallel.c @@ -251,7 +251,7 @@ int HAMLIB_API par_write_data(hamlib_port_t *port, unsigned char data) status = ioctl(port->fd, PPISDATA, &data); return status == 0 ? RIG_OK : -RIG_EIO; #elif defined(__WIN64__) || defined(__WIN32__) - unsigned int dummy; + unsigned int dummy = 0; intptr_t handle; @@ -293,7 +293,7 @@ int HAMLIB_API par_read_data(hamlib_port_t *port, unsigned char *data) return status == 0 ? RIG_OK : -RIG_EIO; #elif defined(__WIN64__) || defined(__WIN32__) unsigned char ret = 0; - unsigned int dummy; + unsigned int dummy = 0; intptr_t handle; @@ -357,7 +357,7 @@ int HAMLIB_API par_write_control(hamlib_port_t *port, unsigned char control) #elif defined(__WIN64__) || defined(__WIN32__) unsigned char ctr = control; unsigned char dummyc; - unsigned int dummy; + unsigned int dummy = 0; const unsigned char wm = (C1284_NSTROBE | C1284_NAUTOFD | C1284_NINIT @@ -434,7 +434,7 @@ int HAMLIB_API par_read_control(hamlib_port_t *port, unsigned char *control) return status == 0 ? RIG_OK : -RIG_EIO; #elif defined(__WIN64__) || defined(__WIN32__) unsigned char ret = 0; - unsigned int dummy; + unsigned int dummy = 0; intptr_t handle; @@ -479,7 +479,7 @@ int HAMLIB_API par_read_status(hamlib_port_t *port, unsigned char *status) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); #ifdef HAVE_LINUX_PPDEV_H - int ret; + int ret0; unsigned char sta; ret = ioctl(port->fd, PPRSTATUS, &sta); @@ -496,7 +496,7 @@ int HAMLIB_API par_read_status(hamlib_port_t *port, unsigned char *status) #elif defined(__WIN64__) || defined(__WIN32__) unsigned char ret = 0; - unsigned int dummy; + unsigned int dummy = 0; intptr_t handle; @@ -724,7 +724,7 @@ int par_dcd_get(hamlib_port_t *p, dcd_t *dcdx) if (status == RIG_OK) { - *dcdx = reg & (1 << p->parm.parallel.pin) ? + *dcdx = (reg & (1 << p->parm.parallel.pin)) ? RIG_DCD_ON : RIG_DCD_OFF; } From 03b39da00b8b2a89bb7b93d81bfeeb1b51317190 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 22:35:50 -0600 Subject: [PATCH 055/205] Fix cppcheck warnings in parallel.c --- src/parallel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parallel.c b/src/parallel.c index 827451db6..5b93dab75 100644 --- a/src/parallel.c +++ b/src/parallel.c @@ -479,7 +479,7 @@ int HAMLIB_API par_read_status(hamlib_port_t *port, unsigned char *status) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); #ifdef HAVE_LINUX_PPDEV_H - int ret0; + int ret; unsigned char sta; ret = ioctl(port->fd, PPRSTATUS, &sta); From dddf63ca163be27c8a661758f595279db2c23518 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 22:37:56 -0600 Subject: [PATCH 056/205] Fix cppcheck warnings in rig.c --- src/rig.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/rig.c b/src/rig.c index d535457b7..a2dbc7316 100644 --- a/src/rig.c +++ b/src/rig.c @@ -1093,7 +1093,7 @@ int HAMLIB_API rig_cleanup(RIG *rig) int HAMLIB_API rig_set_freq(RIG *rig, vfo_t vfo, freq_t freq) { const struct rig_caps *caps; - int retcode, rc2; + int retcode; vfo_t curr_vfo; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -1143,7 +1143,7 @@ int HAMLIB_API rig_set_freq(RIG *rig, vfo_t vfo, freq_t freq) retcode = caps->set_freq(rig, vfo, freq); /* try and revert even if we had an error above */ - rc2 = caps->set_vfo(rig, curr_vfo); + int rc2 = caps->set_vfo(rig, curr_vfo); if (RIG_OK == retcode) { @@ -1182,7 +1182,7 @@ int HAMLIB_API rig_set_freq(RIG *rig, vfo_t vfo, freq_t freq) int HAMLIB_API rig_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) { const struct rig_caps *caps; - int retcode, rc2; + int retcode; vfo_t curr_vfo; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -1221,7 +1221,7 @@ int HAMLIB_API rig_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) retcode = caps->get_freq(rig, vfo, freq); /* try and revert even if we had an error above */ - rc2 = caps->set_vfo(rig, curr_vfo); + int rc2 = caps->set_vfo(rig, curr_vfo); if (RIG_OK == retcode) { @@ -1273,7 +1273,7 @@ int HAMLIB_API rig_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) int HAMLIB_API rig_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) { const struct rig_caps *caps; - int retcode, rc2; + int retcode; vfo_t curr_vfo; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -1314,7 +1314,7 @@ int HAMLIB_API rig_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) retcode = caps->set_mode(rig, vfo, mode, width); /* try and revert even if we had an error above */ - rc2 = caps->set_vfo(rig, curr_vfo); + int rc2 = caps->set_vfo(rig, curr_vfo); /* return the first error code */ if (RIG_OK == retcode) @@ -1359,7 +1359,7 @@ int HAMLIB_API rig_get_mode(RIG *rig, pbwidth_t *width) { const struct rig_caps *caps; - int retcode, rc2; + int retcode; vfo_t curr_vfo; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -1400,7 +1400,7 @@ int HAMLIB_API rig_get_mode(RIG *rig, retcode = caps->get_mode(rig, vfo, mode, width); /* try and revert even if we had an error above */ - rc2 = caps->set_vfo(rig, curr_vfo); + int rc2 = caps->set_vfo(rig, curr_vfo); if (RIG_OK == retcode) { @@ -1676,7 +1676,6 @@ int HAMLIB_API rig_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) const struct rig_caps *caps; struct rig_state *rs = &rig->state; int retcode = RIG_OK; - int rc2; vfo_t curr_vfo; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -1724,7 +1723,7 @@ int HAMLIB_API rig_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) { retcode = caps->set_ptt(rig, vfo, ptt); /* try and revert even if we had an error above */ - rc2 = caps->set_vfo(rig, curr_vfo); + int rc2 = caps->set_vfo(rig, curr_vfo); /* return the first error code */ if (RIG_OK == retcode) From 6c0f10190098611df98f53a1b5ade9451adfa359 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 22:45:29 -0600 Subject: [PATCH 057/205] Fix cppcheck warnings in rig.c --- src/rig.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/rig.c b/src/rig.c index a2dbc7316..dc2bb3928 100644 --- a/src/rig.c +++ b/src/rig.c @@ -286,7 +286,7 @@ const char *HAMLIB_API rigerror(int errnum) { errnum = abs(errnum); - if (errnum > ERROR_TBL_SZ) + if (errnum >= ERROR_TBL_SZ) { return NULL; } @@ -312,7 +312,7 @@ RIG *HAMLIB_API rig_init(rig_model_t rig_model) RIG *rig; const struct rig_caps *caps; struct rig_state *rs; - int i, retcode; + int i; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -352,7 +352,6 @@ RIG *HAMLIB_API rig_init(rig_model_t rig_model) rs->rigport.fd = -1; rs->pttport.fd = -1; - rs->pttport.fd = -1; rs->comm_state = 0; rs->rigport.type.rig = caps->port_type; /* default from caps */ @@ -485,7 +484,7 @@ RIG *HAMLIB_API rig_init(rig_model_t rig_model) */ if (caps->rig_init != NULL) { - retcode = caps->rig_init(rig); + int retcode = caps->rig_init(rig); if (retcode != RIG_OK) { @@ -3724,7 +3723,7 @@ int HAMLIB_API rig_mW2power(RIG *rig, 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; } From ddfa1546945632f4a0cb85a2c4cde17d14941e65 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 22:47:51 -0600 Subject: [PATCH 058/205] Fix cppcheck warnings in rotator.c --- src/rotator.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/rotator.c b/src/rotator.c index 4ab003518..4817be3c8 100644 --- a/src/rotator.c +++ b/src/rotator.c @@ -199,7 +199,6 @@ ROT *HAMLIB_API rot_init(rot_model_t rot_model) ROT *rot; const struct rot_caps *caps; struct rot_state *rs; - int retcode; rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -283,7 +282,7 @@ ROT *HAMLIB_API rot_init(rot_model_t rot_model) */ if (caps->rot_init != NULL) { - retcode = caps->rot_init(rot); + int retcode = caps->rot_init(rot); if (retcode != RIG_OK) { From bc94558fe3f3be2734f687a1e57cecef20f2ff56 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 22:48:02 -0600 Subject: [PATCH 059/205] Fix cppcheck warnings in usb_port.c --- src/usb_port.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usb_port.c b/src/usb_port.c index 4c8e6b410..8dfc7a7c9 100644 --- a/src/usb_port.c +++ b/src/usb_port.c @@ -185,7 +185,7 @@ 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, From 86660a0b97e4c1973a20938c38f5cc642aaf2b60 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 22:49:41 -0600 Subject: [PATCH 060/205] Fix cppcheck warnings in jupiter.c --- tentec/jupiter.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tentec/jupiter.c b/tentec/jupiter.c index 3b91fa2c6..88176c6bc 100644 --- a/tentec/jupiter.c +++ b/tentec/jupiter.c @@ -1135,6 +1135,11 @@ int tt538_set_func(RIG *rig, vfo_t vfo, setting_t func, int status) fresplen = 6; retval = tt538_transaction(rig, "?K" EOM, 3, frespbuf, &fresplen); + if (retval != RIG_OK) + { + return retval; + } + for (i = 0; i < 5; i++) { fcmdbuf[i + 1] = frespbuf[i]; @@ -1173,6 +1178,11 @@ int tt538_set_func(RIG *rig, vfo_t vfo, setting_t func, int status) fresplen = 6; retval = tt538_transaction(rig, "?K" EOM, 3, frespbuf, &fresplen); + if (retval != RIG_OK) + { + return retval; + } + for (i = 0; i < 5; i++) { fcmdbuf[i + 1] = frespbuf[i]; @@ -1195,6 +1205,11 @@ int tt538_set_func(RIG *rig, vfo_t vfo, setting_t func, int status) fresplen = 6; retval = tt538_transaction(rig, "?K" EOM, 3, frespbuf, &fresplen); + if (retval != RIG_OK) + { + return retval; + } + for (i = 0; i < 5; i++) { fcmdbuf[i + 1] = frespbuf[i]; From 4d97a5eb5e68b692bb6abd97883eb8a55c8aadd3 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 22:50:25 -0600 Subject: [PATCH 061/205] Fix cppcheck warnings in jupiter.c --- tentec/jupiter.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tentec/jupiter.c b/tentec/jupiter.c index 88176c6bc..614c51095 100644 --- a/tentec/jupiter.c +++ b/tentec/jupiter.c @@ -815,7 +815,8 @@ int tt538_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) that integer (S units * 256) */ { char hex[5]; - int i, ival; + int i; + unsigned int ival; for (i = 0; i < 4; i++) { hex[i] = lvlbuf[i + 1]; } From a827bbb217d2a982e915977d0e9a9f33118f58f1 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 22:51:13 -0600 Subject: [PATCH 062/205] Fix cppcheck warnings in omnivii.c --- tentec/omnivii.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tentec/omnivii.c b/tentec/omnivii.c index 7becff279..417872ff4 100644 --- a/tentec/omnivii.c +++ b/tentec/omnivii.c @@ -513,7 +513,7 @@ int tt588_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) int tt588_set_freq(RIG *rig, vfo_t vfo, freq_t freq) { char bytes[4]; - int cmd_len, retval; + int cmd_len; unsigned char cmdbuf[16]; rig_debug(RIG_DEBUG_VERBOSE, "%s: vfo=%s freq=%g\n", __func__, rig_strvfo(vfo), @@ -527,6 +527,8 @@ int tt588_set_freq(RIG *rig, vfo_t vfo, freq_t freq) if (vfo == RIG_VFO_CURR) { + int retval; + if ((retval = tt588_get_vfo(rig, &vfo)) != RIG_OK) { return retval; From 398f20b7e188666ac153939d40d8267945029e70 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 22:54:45 -0600 Subject: [PATCH 063/205] Fix cppcheck warnings in orion.c --- tentec/orion.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/tentec/orion.c b/tentec/orion.c index 6f1b752d4..c5d4f6ff1 100644 --- a/tentec/orion.c +++ b/tentec/orion.c @@ -116,7 +116,7 @@ double tt565_timenow() /* returns current time in secs+microsecs */ static int tt565_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *data_len) { - int retval, data_len_init, itry; + int data_len_init, itry; struct rig_state *rs; static int passcount = 0; #ifdef TT565_TIME @@ -131,7 +131,7 @@ static int tt565_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, { rs = &rig->state; serial_flush(&rs->rigport); /* discard pending i/p */ - retval = write_block(&rs->rigport, cmd, cmd_len); + int retval = write_block(&rs->rigport, cmd, cmd_len); if (retval != RIG_OK) { @@ -488,8 +488,6 @@ int tt565_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) int tt565_set_vfo(RIG *rig, vfo_t vfo) { struct tt565_priv_data *priv = (struct tt565_priv_data *)rig->state.priv; - int vfo_len; - char vfobuf[TT565_BUFSIZE]; if (vfo == RIG_VFO_CURR) { @@ -498,9 +496,10 @@ int tt565_set_vfo(RIG *rig, vfo_t vfo) if (vfo == RIG_VFO_MAIN || vfo == RIG_VFO_SUB) { + char vfobuf[TT565_BUFSIZE]; /* Select Sub or Main RX */ - vfo_len = sprintf(vfobuf, "*K%c" EOM, - vfo == RIG_VFO_SUB ? 'S' : 'M'); + int vfo_len = sprintf(vfobuf, "*K%c" EOM, + vfo == RIG_VFO_SUB ? 'S' : 'M'); return tt565_transaction(rig, vfobuf, vfo_len, NULL, NULL); } @@ -1323,7 +1322,7 @@ int tt565_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) if (lvlbuf[2] == 'R') { - char *raw_field, *raw_field2; + char *raw_field; /* response is @SRMnnnSnnn, incl main & sub rx. */ /* TT's spec indicates variable length data 1-3 digits */ @@ -1334,7 +1333,7 @@ int tt565_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) else /* look at main rx info */ { raw_field = lvlbuf + 4; - raw_field2 = strchr(raw_field, 'S'); /* position may vary */ + char *raw_field2 = strchr(raw_field, 'S'); /* position may vary */ if (raw_field2) { *raw_field2 = '\0'; } /* valid string */ } @@ -1818,7 +1817,7 @@ int tt565_vfo_op(RIG *rig, vfo_t vfo, vfo_op_t op) */ int tt565_send_morse(RIG *rig, vfo_t vfo, const char *msg) { - int msg_len, retval, ic, cmdl; + int msg_len, retval, ic; char morsecmd[8]; static int keyer_set = FALSE; /*Shouldn't be here!*/ @@ -1842,7 +1841,7 @@ int tt565_send_morse(RIG *rig, vfo_t vfo, const char *msg) for (ic = 0; ic < msg_len; ic++) { - cmdl = sprintf(morsecmd, "/%c" EOM, msg[ic]); + int cmdl = sprintf(morsecmd, "/%c" EOM, msg[ic]); retval = tt565_transaction(rig, morsecmd, cmdl, NULL, NULL); if (retval != RIG_OK) From 4f55f69d2385208f385f8f6571928114e85a7492 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 22:54:55 -0600 Subject: [PATCH 064/205] Fix cppcheck warnings in paragon.c --- tentec/paragon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tentec/paragon.c b/tentec/paragon.c index c9277c40b..305853016 100644 --- a/tentec/paragon.c +++ b/tentec/paragon.c @@ -268,7 +268,7 @@ int tt585_get_vfo(RIG *rig, vfo_t *vfo) return ret; } - *vfo = priv->status_data[9] & 0x08 ? RIG_VFO_A : RIG_VFO_B; + *vfo = (priv->status_data[9] & 0x08) ? RIG_VFO_A : RIG_VFO_B; return RIG_OK; } @@ -332,7 +332,7 @@ int tt585_get_split_vfo(RIG *rig, vfo_t vfo, split_t *split, vfo_t *txvfo) return ret; } - *split = priv->status_data[9] & 0x02 ? RIG_SPLIT_ON : RIG_SPLIT_OFF; + *split = (priv->status_data[9] & 0x02) ? RIG_SPLIT_ON : RIG_SPLIT_OFF; *txvfo = RIG_VFO_B; return RIG_OK; From 1b981c9a64badd543dc606d180bfe69829ad903c Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 23:03:50 -0600 Subject: [PATCH 065/205] Fix cppcheck warnings in rx331.c --- tentec/rx331.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tentec/rx331.c b/tentec/rx331.c index e638d3160..9e109247c 100644 --- a/tentec/rx331.c +++ b/tentec/rx331.c @@ -275,7 +275,9 @@ static int rx331_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, return retval; } - sscanf(data + 1, "%i%s", &rig_id, data); + char fmt[16]; + snprintf(fmt,sizeof(fmt)-1,"%%i%%%ds",BUFSZ); + sscanf(data + 1, fmt, &rig_id, data); if (rig_id != priv->receiver_id) { @@ -353,7 +355,7 @@ int rx331_get_conf(RIG *rig, token_t token, char *val) switch (token) { case TOK_RIGID: - sprintf(val, "%d", priv->receiver_id); + sprintf(val, "%u", priv->receiver_id); break; default: @@ -569,13 +571,13 @@ int rx331_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) switch (level) { case RIG_LEVEL_ATT: - cmd_len = sprintf(cmdbuf, "$%iK%i" EOM, + cmd_len = sprintf(cmdbuf, "$%uK%i" EOM, priv->receiver_id, val.i ? RX331_ATT_ON : RX331_ATT_OFF); break; case RIG_LEVEL_PREAMP: - cmd_len = sprintf(cmdbuf, "$%iK%i" EOM, + cmd_len = sprintf(cmdbuf, "$%uK%i" EOM, priv->receiver_id, val.i ? RX331_PREAMP_ON : RX331_PREAMP_OFF); break; @@ -598,17 +600,17 @@ int rx331_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) return -RIG_EINVAL; } - cmd_len = sprintf(cmdbuf, "$%iM%i" EOM, + cmd_len = sprintf(cmdbuf, "$%uM%i" EOM, priv->receiver_id, val.i); break; case RIG_LEVEL_RF: - cmd_len = sprintf(cmdbuf, "$%iA%d" EOM, priv->receiver_id, + cmd_len = sprintf(cmdbuf, "$%uA%d" EOM, priv->receiver_id, 120 - (int)(val.f * 120)); break; case RIG_LEVEL_SQL: - cmd_len = sprintf(cmdbuf, "$%iQ%d" EOM, priv->receiver_id, + cmd_len = sprintf(cmdbuf, "$%uQ%d" EOM, priv->receiver_id, 120 - (int)(val.f * 120)); break; From 5e2f45f9875727b3b2fffce92df0daac2f808557 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 23:05:59 -0600 Subject: [PATCH 066/205] Fix cppcheck warnings in tentec2.c --- tentec/tentec2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tentec/tentec2.c b/tentec/tentec2.c index aaf247fbb..ac59d7a32 100644 --- a/tentec/tentec2.c +++ b/tentec/tentec2.c @@ -656,7 +656,7 @@ int tentec2_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt) return -RIG_EPROTO; } - *ptt = buf[2] & 0x01 ? RIG_PTT_ON : RIG_PTT_OFF; + *ptt = (buf[2] & 0x01) ? RIG_PTT_ON : RIG_PTT_OFF; return RIG_OK; } From fac207d37b9bef8b9ef351d00d3654d8b434abe9 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 23:06:51 -0600 Subject: [PATCH 067/205] Fix cppcheck warnings in tt550.c --- tentec/tt550.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tentec/tt550.c b/tentec/tt550.c index de7477b70..15a6943ca 100644 --- a/tentec/tt550.c +++ b/tentec/tt550.c @@ -232,7 +232,7 @@ tt550_tuning_factor_calc(RIG *rig, int tx) int TBfo = 0; // temporary BFO int IBfo = 1500; // Intermediate BFO Freq int FilterBw; // Filter Bandwidth determined from table - int Mode, bwBFO, PbtAdj, RitAdj, XitAdj; + int Mode, PbtAdj, RitAdj, XitAdj; priv = (struct tt550_priv_data *) rig->state.priv; @@ -245,7 +245,7 @@ tt550_tuning_factor_calc(RIG *rig, int tx) if (tx) { - bwBFO = (FilterBw / 2) + 200; + int bwBFO = (FilterBw / 2) + 200; IBfo = (bwBFO > IBfo) ? bwBFO : IBfo; @@ -1706,7 +1706,6 @@ tt550_decode_event(RIG *rig) struct rig_state *rs; unsigned char buf[MAXFRAMELEN]; int data_len; - short movement = 0; // char key; @@ -1744,7 +1743,7 @@ tt550_decode_event(RIG *rig) case '!': if (rig->callbacks.freq_event) { - movement = buf[1] << 8; + int movement = buf[1] << 8; movement = movement | buf[2]; // key = buf[3]; rig_debug(RIG_DEBUG_VERBOSE, From 8a3df9735e05e1d23ee6ff6d5e5a415fd1f6546e Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 23:13:33 -0600 Subject: [PATCH 068/205] Fix cppcheck warnings for ampctl_parse.c and redef amp_set_powerstat --- kenwood/ts2k.c | 3428 ------------------------------------------ kenwood/ts2k.h | 174 --- kenwood/ts2k.status | 23 - kenwood/ts2k_menu.c | 319 ---- kenwood/ts2k_menu.h | 240 --- src/amplifier.c | 3 - tests/ampctl_parse.c | 4 +- 7 files changed, 2 insertions(+), 4189 deletions(-) delete mode 100644 kenwood/ts2k.c delete mode 100644 kenwood/ts2k.h delete mode 100644 kenwood/ts2k.status delete mode 100644 kenwood/ts2k_menu.c delete mode 100644 kenwood/ts2k_menu.h diff --git a/kenwood/ts2k.c b/kenwood/ts2k.c deleted file mode 100644 index ef852fd18..000000000 --- a/kenwood/ts2k.c +++ /dev/null @@ -1,3428 +0,0 @@ -/* - * Hamlib Kenwood backend - TS2000 description - * Copyright (c) 2000-2002 by Stephane Fillod - * - * - * 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 code is has been substatiantially altered from the original - * author's. Also, many new functions have been added and are - * (C) Copyrighted 2002 by Dale E. Edmons (KD7ENI). The license - * is unchanged, and fitness disclaimers still apply. - */ - -/* - * Copied kenwood.c to end of this file. When I change a function for the - * ts2000 I will already have the kenwood version with the function prefix - * changed to ts2k. Unique functions will be pointed to in this file, - * whereas the unmodified version will be in kenwood.c. This simplifies - * things during development and unused ts2k_() functions should go away - * as soon as possible. - * - * Dale KD7ENI - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include "kenwood.h" -#include "ts2k.h" - - -/* - * I just read in kenwood.c and will modify the functions here. This way, - * kenwood functions that actually work on other rigs won't be broken by - * my hacks. Anything that works for all can be sent back over to kenwood.c - * - * Note: due to my compulsive laziness, I often abbreviate Kenwood TS-2000 - * as simply ts2k, especially for code! - * - * Dale kd7eni - */ - -/* - * Hamlib Kenwood backend - main file - * Copyright (c) 2000-2002 by Stephane Fillod - * - */ - - -#include -#include /* Standard input/output definitions */ -#include /* String function definitions */ -#include /* UNIX standard function definitions */ -#include /* File control definitions */ -#include /* Error number definitions */ -#include /* POSIX terminal control definitions */ -#include -#include - -#include -#include - - -// Added the following two lists --Dale, kd7eni -// FIXME: RIG_MODE_[FSKR|CWR] undefined in rig.h -const int ts2k_mode_list[] = -{ - RIG_MODE_NONE, RIG_MODE_LSB, RIG_MODE_USB, RIG_MODE_CW, - RIG_MODE_FM, RIG_MODE_AM, RIG_MODE_RTTY, RIG_MODE_CW, - RIG_MODE_RTTY -}; - -long int ts2k_steps[2][10] = -{ - {1000, 2500, 5000, 10000, 0, 0, 0, 0, 0, 0}, // ssb, cw, fsk - { - 5000, 6250, 10000, 12500, 15000, 20000, - 25000, 30000, 50000, 100000 - } // am/fm -}; - - -struct ts2k_id -{ - rig_model_t model; - int id; -}; - -struct ts2k_id_string -{ - rig_model_t model; - const char *id; -}; - - -#define UNKNOWN_ID -1 - -/* - * Identification number as returned by "ID;" - * Please, if the model number of your rig is listed as UNKNOWN_ID, - * send the value to for inclusion. Thanks --SF - * - * TODO: sort this list with most frequent rigs first. - */ -static const struct ts2k_id ts2k_id_list[] = -{ - {RIG_MODEL_R5000, 5}, - {RIG_MODEL_TS870S, 15}, - {RIG_MODEL_TS570D, 17}, - {RIG_MODEL_TS570S, 18}, - {RIG_MODEL_TS2000, 19}, /* correct --kd7eni */ - {RIG_MODEL_NONE, UNKNOWN_ID}, /* end marker */ -}; - -static const struct ts2k_id_string ts2k_id_string_list[] = -{ - {RIG_MODEL_THD7A, "TH-D7"}, - {RIG_MODEL_THD7AG, "TH-D7G"}, - {RIG_MODEL_THF6A, "TH-F6"}, - {RIG_MODEL_THF7E, "TH-F7"}, - {RIG_MODEL_NONE, NULL}, /* end marker */ -}; - - -/* - * 38 CTCSS sub-audible tones (17500 invalid for ctcss --kd7eni) - */ -const int ts2k_ctcss_list[] = -{ - 670, 719, 744, 770, 797, 825, 854, 885, 915, 948, - 974, 1000, 1035, 1072, 1109, 1148, 1188, 1230, 1273, 1318, - 1365, 1413, 1462, 1514, 1567, 1622, 1679, 1738, 1799, 1862, - 1928, 2035, 2107, 2181, 2257, 2336, 2418, 2503, // 17500, - /* Note: 17500 is not available as ctcss, only tone. --kd7eni */ - 0, -}; - -#define cmd_trm(rig) ((struct ts2k_priv_caps *)(rig)->caps->priv)->cmdtrm -#define ta_quit rs->hold_decode = 0; return retval - -/** - * kenwood_transaction - * Assumes rig!=NULL rig->state!=NULL rig->caps!=NULL - * - * cmdstr - Command to be sent to the rig. Cmdstr can also be NULL, indicating - * that only a reply is needed (nothing will be send). - * data - Buffer for reply string. Can be NULL, indicating that no reply is - * is needed and will return with RIG_OK after command was sent. - * datasize - in: Size of buffer. It is the caller's responsibily to provide - * a large enough buffer for all possible replies for a command. - * out: location where to store number of bytes read. - * - * returns: - * RIG_OK - if no error occured. - * RIG_EIO - if an I/O error occured while sending/receiving data. - * RIG_ETIMEOUT - if timeout expires without any characters received. - * RIG_REJECTED - if a negative acknowledge was received or command not - * recognized by rig. - */ - -/* FIXME: cmd_len appears to change and needs set every invocation? --Dale */ - -int -ts2k_transaction(RIG *rig, const char *cmdstr, int cmd_len, - char *data, size_t *datasize) -{ -// return kenwood_transaction(rig, cmdstr, data, datasize); - - struct rig_state *rs; - int retval; - const char *cmdtrm = EOM_KEN; /* Default Command/Reply termination char */ - int retry_read = 0; - char *errtxt; - -#define MAX_RETRY_READ 5 - - rs = &rig->state; - rs->hold_decode = 1; - - serial_flush(&rs->rigport); - - cmdtrm = cmd_trm(rig); - - if (cmdstr != NULL) - { - // rig_debug(RIG_DEBUG_ERR, __func__": 1) sending '%s'\n\n", cmdstr); - retval = write_block(&rs->rigport, cmdstr, strlen(cmdstr)); - - if (retval != RIG_OK) - { ta_quit; } - -#undef TH_ADD_CMDTRM -#ifdef TH_ADD_CMDTRM - // rig_debug(RIG_DEBUG_ERR, __func__": 2) sending '%s'\n\n", cmdtrm); - retval = write_block(&rs->rigport, cmdtrm, strlen(cmdtrm)); - - if (retval != RIG_OK) - { ta_quit; } - -#endif - } - - /* FIXME: Everything below this line wants to be completely rewritten!!!! */ - - if (data == NULL || datasize <= 0) - { - rig->state.hold_decode = 0; - return RIG_OK; /* don't want a reply */ - } - -transaction_read: - /* FIXME : TS-2000 gets alot of 'timedout' on read_string()! */ - //rig_debug(RIG_DEBUG_ERR, __func__": 3a) reading %u bytes...\n", *datasize); - retval = - read_string(&rs->rigport, data, *datasize, cmdtrm, - strlen(cmdtrm)); - //rig_debug(RIG_DEBUG_ERR, __func__": 3b) read '%s', retval=%u\n\n", data, retval); - *datasize = retval; - - if (retval > 0) - { - //rig_debug(RIG_DEBUG_ERR, __func__": 3b) read cmd '%s', retval=%u\n\n", data, retval); - retval = RIG_OK; - goto transaction_check; - } - - /* Check that command termination is correct */ - if (!strchr(cmdtrm, data[strlen(data)])) - { - if (retry_read++ < MAX_RETRY_READ) - { - goto transaction_read; - } - - rig_debug(RIG_DEBUG_ERR, - __func__ - ": Command is not correctly terminated '%s'\n", - data); - retval = -RIG_EPROTO; - ta_quit; - } - - /* Errors */ - if (strlen(data) == 2 && data[0] == 'E') - { - switch (data[0]) - { - case 'E': - rig_debug(RIG_DEBUG_ERR, - __func__ - ": Communication Error for '%s'\n", - cmdstr); - break; - - case 'O': - rig_debug(RIG_DEBUG_ERR, - __func__ - ": Communication Error for '%s'\n", - cmdstr); - break; - - case '?': - rig_debug(RIG_DEBUG_ERR, - __func__ - ": Communication Error for '%s'\n", - cmdstr); - break; - - default: - rig_debug(RIG_DEBUG_ERR, - __func__ ": Hamlib Error for '%s'\n", - cmdstr); - break; - - } - - retval = -RIG_ERJCTED; - ta_quit; - } - -#undef CONFIG_STRIP_CMDTRM -#ifdef CONFIG_STRIP_CMDTRM - - if (strlen(data) > 0) - { - data[strlen(data) - 1] = '\0'; /* not very elegant, but should work. */ - } - else - { - data[0] = '\0'; - } - -#endif - /* - * Check that received the correct reply. The first two characters - * should be the same as command. - */ -transaction_check: - - if (cmdstr && (toupper(data[0]) != toupper(cmdstr[0]) - || toupper(data[1]) != toupper(cmdstr[1]))) - { - /* - * TODO: When RIG_TRN is enabled, we can pass the string - * to the decoder for callback. That way we don't ignore - * any commands. - */ - if (retry_read++ < MAX_RETRY_READ) - { - goto transaction_read; - } - - rig_debug(RIG_DEBUG_ERR, - __func__ ": Unexpected reply '%s'\n", data); - retval = -RIG_EPROTO; - { ta_quit; } - } - - retval = RIG_OK; - -transaction_quit: - { ta_quit; } -} - -/* - * kenwood_set_vfo - * Assumes rig!=NULL - * - * status: VFOA, VFOB, VFOC, Main, Sub, - * MEMA, MEMC, CALLA, CALLC - * VFO_AB, VFO_BA, ... - * They all work! --Dale - */ -int ts2k_set_vfo(RIG *rig, vfo_t vfo) -{ - unsigned char cmdbuf[10]; - int ptt, ctrl, v, cmd_len, retval; - static int sat_on; // temporary! to be removed! - char vfo_function; - - // trivial case, but needs checked if enabled - /*// if( (vfo == RIG_CTRL_MODE(RIG_CTRL_MAIN,RIG_VFO_ALL)) - // || (vfo == RIG_CTRL_MODE(RIG_CTRL_SUB,RIG_VFO_ALL)) ) { - // rig_debug(RIG_DEBUG_ERR, __func__ \ - // ": Geez, you can't set *all* VFO's!\n"); - // return -RIG_EINVAL; - // } - */ - cmd_len = 10; - ptt = ctrl = v = 0; - - // be optimistic (and ensure initialization) - retval = RIG_OK; - - // Main/Sub Active Transceiver - switch (vfo) - { - case RIG_VFO_A: - case RIG_VFO_B: - case RIG_VFO_AB: // split - case RIG_VFO_BA: - case RIG_CTRL_SAT: // FIXME: Not even close to correct - case RIG_VFO_MAIN: - case RIG_VFO_MEM_A: - case RIG_VFO_CALL_A: - ctrl = TS2K_CTRL_ON_MAIN; // FIXME : these are independent! - ptt = TS2K_PTT_ON_MAIN; - break; - - case RIG_VFO_C: - case RIG_VFO_SUB: - case RIG_VFO_MEM_C: - case RIG_VFO_CALL_C: - ctrl = TS2K_CTRL_ON_SUB; - ptt = TS2K_PTT_ON_SUB; - break; - - default: - break; - } - - // set now so "ft...;" and "fr...;" don't fail - retval = ts2k_set_ctrl(rig, ptt, ctrl); - - if (retval != RIG_OK) - { - return -RIG_EINVAL; - } - - // check if we need to skip the remainder - v = (vfo == RIG_VFO_SUB) - || (vfo == RIG_VFO_MAIN) - || (vfo == RIG_VFO_CURR) - || (vfo == RIG_VFO_VFO) -// || (vfo == RIG_VFO_ALL) // yea, I know - /* bit mask checks */ - || (vfo & RIG_CTRL_SAT) // "fr...;", "ft...;" won't do! - ; - - rig_debug(RIG_DEBUG_ERR, __func__ \ - ": starting check.... vfo = 0x%X, v=%d\n", vfo, v); - - if (!v) // start check - { - - // FIXME: this is a speed-up kludge but won't *always* work! - if (sat_on) - { - retval = ts2k_sat_off(rig, vfo); // we gotta do it. - - if (retval != RIG_OK) - { - return retval; - } - - sat_on = 0; - } - - // RX Active Tuning - switch (vfo) - { - case RIG_VFO_AB: // TX is opposite - case RIG_VFO_A: - case RIG_VFO_C: - vfo_function = '0'; - break; - - case RIG_VFO_BA: // TX is opposite - case RIG_VFO_B: - vfo_function = '1'; - break; - - case RIG_VFO_MEM_A: - case RIG_VFO_MEM_C: - vfo_function = '2'; - break; - - case RIG_VFO_CALL_A: - case RIG_VFO_CALL_C: - vfo_function = '3'; - break; - - default: - rig_debug(RIG_DEBUG_ERR, __func__ - ": unsupported VFO %u\n", vfo); - return -RIG_EINVAL; - break; - } - - // ack_len is tmp - cmd_len = - sprintf(cmdbuf, "fr%c%s", vfo_function, cmd_trm(rig)); - - /* set RX VFO */ - retval = - ts2k_transaction(rig, cmdbuf, cmd_len, NULL, NULL); - - if (retval != RIG_OK) - { - return -RIG_EINVAL; - } - - // TX Active tuning - switch (vfo) - { - case RIG_VFO_A: - case RIG_VFO_C: - case RIG_VFO_BA: // opposite of above - vfo_function = '0'; - break; - - case RIG_VFO_AB: // opposite of above - case RIG_VFO_B: - vfo_function = '1'; - break; - - case RIG_VFO_MEM_A: - case RIG_VFO_MEM_C: // FIXME: need to handle vfo/mem split - vfo_function = '2'; - break; - - case RIG_VFO_CALL_A: - case RIG_VFO_CALL_C: - vfo_function = '3'; - break; - - default: - rig_debug(RIG_DEBUG_ERR, __func__ - ": unsupported VFO %u\n", - vfo); - return -RIG_EINVAL; - } - - /* set TX VFO */ - cmdbuf[1] = 't'; - - // removing this causes split to not function!!!! - cmd_len = - sprintf(cmdbuf, "ft%c%s", vfo_function, cmd_trm(rig)); - - retval = - ts2k_transaction(rig, cmdbuf, cmd_len, NULL, NULL); - - if (retval != RIG_OK) - { - return retval; - } - - } - else // Check further for special modes not using "fr...;", "ft...;" - { - if (vfo & RIG_CTRL_SAT) // test the SAT bit - { - retval = ts2k_sat_on(rig, vfo); - - if (retval != RIG_OK) - { - return retval; - } - - sat_on = 1; - } - else - { - rig_debug(RIG_DEBUG_ERR, __func__ \ - ": VFO not changed, only PTT/CTRL\n"); - } - } - - /* - * FIXME: some items like scan, satellite need checked and turned off here. - * I've got a simple kludge to turn SAT *off* but it wants to be done - * here. It's a bit expensive though and I'm trying to find a better - * way to do SAT as well as others. ts2k_sat_off() reads the current, - * sets it off, then writes it back so the user selected stuff don't - * change unexpectedly. Now, SAT won't get turned off if first turned - * on via the front panel. MEM and SCAN have similar quirks. - * --Dale - */ - return retval; -} - -/* we just turn SAT on here. It'll take some doing to run it! */ -int ts2k_sat_on(RIG *rig, vfo_t vfo) -{ - char cmd[20], ack[20]; - int cmdlen, acklen; - - acklen = 20; - - if (!(vfo & RIG_CTRL_SAT)) - { - return -RIG_EINTERNAL; // All right. Who called us!? - } - -// cmdlen = sprintf(cmd, "sa%07u;", 0); // Initial string to modify - acklen = ts2k_transaction(rig, "sa;", 3, ack, &acklen); - - // Sat mode ON - ack[2] = '1'; // Everything below is *nice*, this is *required* - - goto STest; // testing - - /* cmd is already full of '0's, but we set them again explicitly */ - // SAT_VFO or SAT_MEM? - if (vfo & RIG_CTRL_MEM) - { - ack[8] = '1'; // sat mem ch 0-9 - } - else - { - ack[8] = '0'; // sat vfo - } - - /* Main or Sub as uplink? */ - // Note: if both are set, Main is still uplink - if (vfo & RIG_CTRL_MAIN) - { - ack[4] = '0'; // sat main=uplink - } - else if (vfo & RIG_CTRL_SUB) - { - ack[4] = '1'; // sat sub=uplink - } - - // FIXME: Add Sat Trace here! - - // Trace REV - if (vfo & RIG_CTRL_REV) - { - ack[7] = '1'; // sat trace REV - } - else - { - ack[7] = '0'; - } - - // CTRL to main or sub? - if ((vfo & RIG_VFO_CTRL) && (vfo & RIG_CTRL_SUB)) - { - ack[5] = '1'; // sat CTRL on sub - } - else - { - ack[5] = '0'; // sat CTRL on main - } - -STest: - rig_debug(RIG_DEBUG_ERR, __func__ \ - ": sat = %s, vfo = 0x%X\n", cmd, vfo); - // of coure, this is *required* too! - return ts2k_transaction(rig, ack, acklen, NULL, NULL); -} - -int ts2k_sat_off(RIG *rig, vfo_t vfo) -{ - char cmd[20], ack[20]; - int cmdlen, acklen, retval; - - acklen = 10; - - cmdlen = sprintf(cmd, "sa;"); - retval = ts2k_transaction(rig, cmd, cmdlen, ack, &acklen); - - if (retval != RIG_OK) - { - return retval; - } - - ack[2] = '0'; - cmdlen = 20; - return ts2k_transaction(rig, ack, acklen, NULL, NULL); -} - -/* - * kenwood_get_vfo_if - * Assumes rig!=NULL, !vfo - * - * status: works perfect for implemented modes! --Dale - * code's getting a little ugly. okay, real ugly. - */ -int ts2k_get_vfo(RIG *rig, vfo_t *vfo) -{ - char vfobuf[50], r_vfo; - char *ctrl_ptt; - int vfo_len, retval, tmp; - - /* - * FIXME: if FR != FT && rcvr==main, the mode = split! --kd7eni - */ - - // Check which receiver so VFO_C may be detected (PTT/CTRL) - - ctrl_ptt = ts2k_get_ctrl(rig); - - if (ctrl_ptt == NULL) - { - return -RIG_EINVAL; - } - -// rig_debug(RIG_DEBUG_ERR, "ts2k_get_vfo: PTT/CTRL is %s\n", ctrl_ptt); - - /* query RX VFO */ - vfo_len = 50; - rig_debug(RIG_DEBUG_ERR, __func__ - ": sending fr; cmd/checking SAT. Expect TIMEDOUT if in SAT mode!\n"); - retval = ts2k_transaction(rig, "fr;", 3, vfobuf, &vfo_len); - - /* "fr;" fails in satellite mode; interesting... */ - if (retval != RIG_OK) - { - rig_debug(RIG_DEBUG_ERR, __func__": kenwood/ts2k.c\n" - "FIXME: ts2k.c,\tThis is timeout cannot be prevented.\n"); - tmp = retval; - retval = ts2k_transaction(rig, "sa;", 3, vfobuf, &vfo_len); - - if (retval == RIG_OK) - { - rig_debug(RIG_DEBUG_ERR, __func__": SAT=%s\n", vfobuf); - - if (vfobuf[2] == '1') - { - /* yes, we're in satellite mode! */ - *vfo = RIG_CTRL_SAT; // FIXME: set the rest! - /* TODO: write get_sat() and let it do the work */ - return RIG_OK; - } - } - - return tmp; // return original "fr;" error! - } - -// rig_debug(RIG_DEBUG_ERR, __func__": checking fr; cmd.\n"); - r_vfo = vfobuf[2]; - - //if (vfo_len != 4 || vfobuf[1] != 'R') { - if (vfobuf[1] != 'R') - { - rig_debug(RIG_DEBUG_ERR, __func__ - ": unexpected answer %s, " - "len=%u\n", vfobuf, vfo_len); - return -RIG_ERJCTED; - } - - rig_debug(RIG_DEBUG_ERR, __func__": sending ft; cmd.\n"); - vfo_len = 50; - retval = ts2k_transaction(rig, "ft;", 3, vfobuf, &vfo_len); - - if (retval != RIG_OK) - { - return retval; - } - - rig_debug(RIG_DEBUG_ERR, __func__": checking ft; cmd.\n"); - - if (vfobuf[2] == r_vfo) // check most common first - { - rig_debug(RIG_DEBUG_ERR, "ts2k_get_vfo: Non-Split.\n"); - - /* TODO: replace 0,1,2,.. constants by defines */ - /* FIXME: return based on RIG_PTT_ON_???? or RIG_CTRL_ON_???? - * may be different. We need to specify actual status. - * Right now we pretend things are simpler. --kd7eni - */ - switch (vfobuf[2]) - { - case '0': - if (ctrl_ptt[3] == '0') // we use CTRL as Active Transceiver - { - *vfo = RIG_VFO_A; - } - else if (ctrl_ptt[3] == '1') - { - *vfo = RIG_VFO_C; - } - else // "There be errors here!" - { - rig_debug(RIG_DEBUG_ERR, - "ts2k_get_vfo: VFO1 on erroneous xcvr %c\n", - vfobuf[2]); - return -RIG_EPROTO; - } - - break; - - case '1': - // only valid on Main--no checks required. - *vfo = RIG_VFO_B; - break; - - case '2': - if (ctrl_ptt[3] == '0') // we use CTRL as Active Transceiver. - { - *vfo = RIG_VFO_MEM_A; - } - else if (ctrl_ptt[3] == '1') - { - *vfo = RIG_VFO_MEM_C; - } - else - { - return -RIG_EPROTO; - } - - break; - - case '3': - if (ctrl_ptt[3] == '0') // we use CTRL as current - { - *vfo = RIG_VFO_CALL_A; - } - else if (ctrl_ptt[3] == '1') // we use CTRL as current - { - *vfo = RIG_VFO_CALL_C; - } - else - { - return -RIG_EPROTO; - } - - break; - - default: // Different or newer rig types... - rig_debug(RIG_DEBUG_ERR, - "ts2k_get_vfo: unsupported VFO %c\n", - vfobuf[2]); - return -RIG_EPROTO; - - } // end switch - } - else // end rx == tx; start split checks. - { - rig_debug(RIG_DEBUG_ERR, "ts2k_get_vfo: Split.\n"); - - if (r_vfo == '0' && vfobuf[2] == '1') - { - *vfo = RIG_VFO_AB; - } - else if (r_vfo == '1' && vfobuf[2] == '0') - { - *vfo = RIG_VFO_BA; - } - else // FIXME: need vfo <--> mem split - { - rig_debug(RIG_DEBUG_ERR, - __func__ - ":FIXME: vfo<->mem split! -kd7eni!\n"); - return -RIG_EPROTO; - } - } - - return RIG_OK; -} - -/* - * kenwood_set_freq - * Assumes rig!=NULL - * - * status: correctly sets FA, FB, FC --Dale - */ -int ts2k_set_freq(RIG *rig, vfo_t vfo, freq_t freq) -{ - unsigned char freqbuf[16]; - int freq_len, ack_len = 0, retval; - char vfo_letter; - - /* - * better FIXME: vfo==RIG_VFO_CURR - */ - if (vfo == RIG_VFO_CURR) - { - retval = ts2k_get_vfo(rig, &vfo); - - if (retval != RIG_OK) - { - return retval; - } - } - - switch (vfo) - { - case RIG_VFO_A: - vfo_letter = 'A'; - break; - - case RIG_VFO_B: - vfo_letter = 'B'; - break; - - case RIG_VFO_C: - vfo_letter = 'C'; - break; - - default: - rig_debug(RIG_DEBUG_ERR, - "ts2k_set_freq: unsupported VFO %u\n", vfo); - return -RIG_EINVAL; - } - - freq_len = sprintf(freqbuf, "F%c%011"PRIll";", vfo_letter, freq); - - ack_len = 14; - retval = ts2k_transaction(rig, freqbuf, freq_len, NULL, NULL); - - return retval; -} - -/* - * kenwood_get_freq - * Assumes rig!=NULL, freq!=NULL - */ -int ts2k_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) -{ - unsigned char freqbuf[50]; - unsigned char cmdbuf[4]; - int cmd_len, freq_len, retval; - char vfo_letter; - - /* - * FIXME: need to handle RIG_VFO_MEM, etc... - */ - if (vfo == RIG_VFO_CURR) - { - retval = ts2k_get_vfo(rig, &vfo); - - if (retval != RIG_OK) - { - return retval; - } - } - - switch (vfo) - { - case RIG_VFO_A: - vfo_letter = 'a'; - break; - - case RIG_VFO_B: - vfo_letter = 'b'; - break; - - case RIG_VFO_C: - vfo_letter = 'c'; - break; - - default: - rig_debug(RIG_DEBUG_ERR, - __func__": unsupported VFO %u\n", vfo); - return -RIG_EPROTO; - } - - cmd_len = sprintf(cmdbuf, "f%c%s", vfo_letter, cmd_trm(rig)); - - freq_len = 15; - retval = - ts2k_transaction(rig, cmdbuf, cmd_len, freqbuf, &freq_len); - - //rig_debug(RIG_DEBUG_ERR,"__func__: received %s\n", cmdbuf); - if (retval != RIG_OK) - { - return retval; - } - - //if (freq_len != 14 || freqbuf[0] != 'F') { - if (freqbuf[0] != 'F') - { - rig_debug(RIG_DEBUG_ERR, - __func__": unexpected answer '%s', " - "len=%u\n", freqbuf, freq_len); - return -RIG_ERJCTED; - } - - sscanf(freqbuf + 2, "%"SCNll, freq); - - return RIG_OK; -} - -/* - * kenwood_set_mode - * Assumes rig!=NULL - */ -int ts2k_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) -{ - unsigned char mdbuf[16], ackbuf[16]; - int mdbuf_len, ack_len = 0, kmode, retval; - - switch (mode) - { - case RIG_MODE_CW: - kmode = MD_CW; - break; - - case RIG_MODE_USB: - kmode = MD_USB; - break; - - case RIG_MODE_LSB: - kmode = MD_LSB; - break; - - case RIG_MODE_FM: - kmode = MD_FM; - break; - - case RIG_MODE_AM: - kmode = MD_AM; - break; - - case RIG_MODE_RTTY: - kmode = MD_FSK; - break; - - default: - rig_debug(RIG_DEBUG_ERR, "ts2k_set_mode: " - "unsupported mode %u\n", mode); - return -RIG_EINVAL; - } - - mdbuf_len = sprintf(mdbuf, "MD%c;", kmode); - ack_len = 16; - rig_debug(RIG_DEBUG_ERR, "ts2k_set_mode: sending %s\n", mdbuf); - retval = ts2k_transaction(rig, mdbuf, mdbuf_len, NULL, NULL); - - return retval; -} - -/* - * kenwood_get_mode - * Assumes rig!=NULL, mode!=NULL - */ -int ts2k_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) -{ - unsigned char modebuf[50]; - int mode_len, retval; - - - mode_len = 50; - retval = ts2k_transaction(rig, "MD;", 3, modebuf, &mode_len); - - if (retval != RIG_OK) - { - return retval; - } - - if (mode_len != 4 || modebuf[1] != 'D') - { - rig_debug(RIG_DEBUG_ERR, - "ts2k_get_mode: unexpected answer, len=%u\n", - mode_len); - return -RIG_ERJCTED; - } - - *width = RIG_PASSBAND_NORMAL; /* FIXME */ - - switch (modebuf[2]) - { - case MD_CW: - *mode = RIG_MODE_CW; - break; - - case MD_USB: - *mode = RIG_MODE_USB; - break; - - case MD_LSB: - *mode = RIG_MODE_LSB; - break; - - case MD_FM: - *mode = RIG_MODE_FM; - break; - - case MD_AM: - *mode = RIG_MODE_AM; - break; - - case MD_FSK: - *mode = RIG_MODE_RTTY; - break; -#ifdef RIG_MODE_CWR - - case MD_CWR: - *mode = RIG_MODE_CWR; - break; -#endif -#ifdef RIG_MODE_RTTYR - - case MD_FSKR: - *mode = RIG_MODE_RTTY; - break; -#endif - - case MD_NONE: - *mode = RIG_MODE_NONE; - break; - - default: - rig_debug(RIG_DEBUG_ERR, "ts2k_get_mode: " - "unsupported mode '%c'\n", modebuf[2]); - return -RIG_EINVAL; - } - - return RIG_OK; -} - -/* added a whole buch of stuff --Dale */ -int ts2k_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) -{ - unsigned char levelbuf[16], ackbuf[16], ctrl; - char *dc; // to be replaced. -// char dc[10]; // use this when ts2k_get_ctrl() is fixed. -// int dc_len; // use this when ts2k_get_ctrl() is fixed. - int level_len, ack_len = 0, retval, reply; - int ts2k_val; - - if (RIG_LEVEL_IS_FLOAT(level)) - { - ts2k_val = val.f * 255; - } - else - { - ts2k_val = val.i; - } - - /* Several commands need to know status of CTRL */ - -// dc_len = 10; // these are to be used when ts2k_get_ctrl() is changed. -// if( ts2k_get_ctrl(rig, dc, 10) != RIG_OK) -// return -RIG_EINVAL; -// we shouldn't really change dc; its a static and will get changed. - dc = ts2k_get_ctrl(rig); // will get fixed -// m = dc[2]; s = dc[3]; // set defaults - -// FIXME: Just handles simple stuff RIG_VFO_CURR,VFOA,VFOB,VFOC; *may* work as intended. - ctrl = '0'; // Assume Main - - if (vfo & RIG_CTRL_SUB) // Change only if sub (bitwise, not logical) - { - ctrl = '1'; - } - - // assume no replies - reply = 0; - - switch (level) - { - case RIG_LEVEL_RFPOWER: - level_len = sprintf(levelbuf, "pc%03d;", ts2k_val); - break; - - case RIG_LEVEL_AF: // I call this volume. :) - level_len = sprintf(levelbuf, "ag%c%03u;", ctrl, ts2k_val); - break; - - case RIG_LEVEL_RF: - level_len = sprintf(levelbuf, "rg%03d;", ts2k_val); - break; - - case RIG_LEVEL_SQL: // fixed: uses main/sub --Dale - level_len = sprintf(levelbuf, "sq%c%03u;", ctrl, ts2k_val); - break; - - - /* I added the following levels --Dale */ - case RIG_LEVEL_PREAMP: - level_len = sprintf(levelbuf, "pa%c;", (ts2k_val == 0) ? '0' : '1'); - break; - - case RIG_LEVEL_ATT: - if (ts2k_val < 1 || ts2k_val > 2) // only 1 or 2, 0=read - { - return -RIG_EINVAL; - } - - level_len = sprintf(levelbuf, "an%01u;", ts2k_val); - break; - - case RIG_LEVEL_NR: - if (ts2k_val < 0 || ts2k_val > 2) // only 1 or 2, 0=read - { - return -RIG_EINVAL; - } - - level_len = sprintf(levelbuf, "nr%01u;", ts2k_val); - break; - - /* FIXME: FM mic gain is low/mid/high; cmd="ex0410000n;" 0=low --Dale */ - case RIG_LEVEL_MICGAIN: - level_len = sprintf(levelbuf, "mg%03u;", (ts2k_val > 100) ? 100 : ts2k_val); - break; - - /* no rig error on invalid values */ - case RIG_LEVEL_KEYSPD: - if (ts2k_val < 10 || ts2k_val > 60) // only 1 or 2, 0=read - { - return -RIG_EINVAL; - } - - level_len = sprintf(levelbuf, "ks%03u;", ts2k_val); - break; - - case RIG_LEVEL_NOTCHF: // actually, this is autonotch--same thing? - level_len = sprintf(levelbuf, "al%03u;", (ts2k_val > 4) ? 4 : ts2k_val); - break; - - case RIG_LEVEL_AGC: - level_len = sprintf(levelbuf, "gt%03u;", (ts2k_val > 20) ? 20 : ts2k_val); - break; - - case RIG_LEVEL_BKINDL: // 0-1000ms in 50ms steps; this'll be good 'nuff. - level_len = sprintf(levelbuf, "sd%04u;", - (int)((float) ts2k_val * 1000.0 / 255.0)); - break; - - case RIG_LEVEL_VOXGAIN: - level_len = sprintf(levelbuf, "vg%03u;", (ts2k_val > 9) ? 9 : ts2k_val); -// alternate -// level_len = sprintf(levelbuf, "vg%03u;",(int)((float) ts2k_val*9.0/255.0)); - break; - -// case RIG_LEVEL_VOX: // header file declares these the same - case RIG_LEVEL_VOXDELAY: - level_len = sprintf(levelbuf, "vg%03u;", - (int)((float) ts2k_val * 3000.0 / 255.0)); - break; - -// vox on/off -// level_len = sprintf(levelbuf, "vx%c;", (ts2k_val==0)? '0' : '1'); -// break; - - /* Check unsupported just so we can complain if one is found. :) */ - case RIG_LEVEL_APF: - - /* readonly */ - case RIG_LEVEL_SWR: - case RIG_LEVEL_ALC: - case RIG_LEVEL_STRENGTH: - return -RIG_EINTERNAL; // and complain loud! - - /* not currently implemented */ - case RIG_LEVEL_METER: // readonly + needs rechecked. - case RIG_LEVEL_PBT_IN: // nnn - case RIG_LEVEL_PBT_OUT: // NNN; "plnnnNNN;" - case RIG_LEVEL_IF: // hmmmm.... - case RIG_LEVEL_CWPITCH: // "ex0310000n;" and a fair bit of programming... - case RIG_LEVEL_COMP: // available?, processor's not the same is it? - case RIG_LEVEL_BALANCE: // AF R/L balance? See "ex01600002;" for similar(?) - case RIG_LEVEL_SQLSTAT: // need more info; avail? - return -RIG_ENIMPL; - - default: - rig_debug(RIG_DEBUG_ERR, - "Unsupported set_level %u", level); - return -RIG_EINVAL; - } - - // The following might make a nifty macro --Dale - ack_len = reply ? 16 : 0; // This'd work by itself wouldn't it? --Dale - retval = ts2k_transaction(rig, levelbuf, level_len, - reply ? ackbuf : NULL, reply ? &ack_len : NULL); - - if (retval != RIG_OK) - { - return retval; - } - - return RIG_OK; -} - -/* - * assumes f!=NULL - */ -static int -get_ts2k_level(RIG *rig, const char *cmd, int cmd_len, float *f) -{ - unsigned char lvlbuf[50]; - int lvl_len, retval; - int lvl; - - lvl_len = 50; - retval = ts2k_transaction(rig, cmd, cmd_len, lvlbuf, &lvl_len); - - if (retval != RIG_OK) - { - return retval; - } - - if (lvl_len != 6) - { - rig_debug(RIG_DEBUG_ERR, - "ts2k_get_level: wrong answer len=%u\n", - lvl_len); - return -RIG_ERJCTED; - } - - /* - * 000..255 - */ - sscanf(lvlbuf + 2, "%u", &lvl); - *f = (float) lvl / 255.0; - - return RIG_OK; -}; - - -/* - * kenwood_get_level - * Assumes rig!=NULL, val!=NULL - */ -int ts2k_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) -{ - unsigned char lvlbuf[50]; - int lvl_len, retval; - int lvl; - int i; - - lvl_len = 50; - - /* Optimize: - * sort the switch cases with the most frequent first - */ - switch (level) - { - case RIG_LEVEL_STRENGTH: - // fixme: "sm0;" VFO must be specified! --kd7eni - retval = ts2k_transaction(rig, "SM;", 3, lvlbuf, &lvl_len); - - if (retval != RIG_OK) - { - return retval; - } - - if (lvl_len != 7 || lvlbuf[1] != 'M') - { - rig_debug(RIG_DEBUG_ERR, "ts2k_get_level: " - "wrong answer len=%u\n", lvl_len); - return -RIG_ERJCTED; - } - - /* - * Frontend expects: - * -54 = S0 - * 0 = S9 - */ - sscanf(lvlbuf + 2, "%u", &val->i); - val->i = (val->i * 4) - 54; - break; - - case RIG_LEVEL_SQLSTAT: - return -RIG_ENIMPL; /* get_dcd ? */ - - case RIG_LEVEL_PREAMP: - return -RIG_ENIMPL; - - case RIG_LEVEL_ATT: - retval = ts2k_transaction(rig, "RA;", 3, lvlbuf, &lvl_len); - - if (retval != RIG_OK) - { - return retval; - } - - if (lvl_len != 5) - { - rig_debug(RIG_DEBUG_ERR, "ts2k_get_level: " - "unexpected answer len=%u\n", lvl_len); - return -RIG_ERJCTED; - } - - sscanf(lvlbuf + 2, "%u", &lvl); - - if (lvl == 0) - { - val->i = 0; - } - else - { - for (i = 0; i < lvl && i < MAXDBLSTSIZ; i++) - if (rig->state.attenuator[i] == 0) - { - rig_debug(RIG_DEBUG_ERR, - "ts2k_get_level: " - "unexpected att level %u\n", - lvl); - return -RIG_EPROTO; - } - - if (i != lvl) - { - return -RIG_EINTERNAL; - } - - val->i = rig->state.attenuator[i - 1]; - } - - break; - - case RIG_LEVEL_RFPOWER: - return get_ts2k_level(rig, "PC;", 3, &val->f); - - case RIG_LEVEL_AF: - return get_ts2k_level(rig, "AG;", 3, &val->f); - - case RIG_LEVEL_RF: - return get_ts2k_level(rig, "RG;", 3, &val->f); - - case RIG_LEVEL_SQL: - return get_ts2k_level(rig, "SQ;", 3, &val->f); - - case RIG_LEVEL_MICGAIN: - return get_ts2k_level(rig, "MG;", 3, &val->f); - - case RIG_LEVEL_AGC: - return get_ts2k_level(rig, "GT;", 3, &val->f); - - case RIG_LEVEL_IF: - case RIG_LEVEL_APF: - case RIG_LEVEL_NR: - case RIG_LEVEL_PBT_IN: - case RIG_LEVEL_PBT_OUT: - case RIG_LEVEL_CWPITCH: - case RIG_LEVEL_KEYSPD: - case RIG_LEVEL_NOTCHF: - case RIG_LEVEL_COMP: - case RIG_LEVEL_BKINDL: - case RIG_LEVEL_BALANCE: - return -RIG_ENIMPL; - - default: - rig_debug(RIG_DEBUG_ERR, - "Unsupported get_level %u", level); - return -RIG_EINVAL; - } - - return RIG_OK; -} - - -int ts2k_set_func(RIG *rig, vfo_t vfo, setting_t func, int status) -{ - unsigned char fctbuf[16], ackbuf[16]; - int fct_len, ack_len = 16; - - /* Optimize: - * sort the switch cases with the most frequent first - */ - switch (func) - { - case RIG_FUNC_NB: - fct_len = - sprintf(fctbuf, "NB%c;", - status == RIG_FUNC_NB ? '0' : '1'); - return ts2k_transaction(rig, fctbuf, fct_len, NULL, NULL); - - case RIG_FUNC_ABM: - fct_len = - sprintf(fctbuf, "AM%c;", - status == RIG_FUNC_ABM ? '0' : '1'); - return ts2k_transaction(rig, fctbuf, fct_len, NULL, NULL); - - case RIG_FUNC_COMP: - fct_len = - sprintf(fctbuf, "PR%c;", - status == RIG_FUNC_COMP ? '0' : '1'); - return ts2k_transaction(rig, fctbuf, fct_len, NULL, NULL); - - case RIG_FUNC_TONE: - fct_len = - sprintf(fctbuf, "TO%c;", - status == RIG_FUNC_TONE ? '0' : '1'); - return ts2k_transaction(rig, fctbuf, fct_len, NULL, NULL); - - case RIG_FUNC_TSQL: - // fixme: see ts2000.doc and follow the proceedure! --kdeni - // rigbug! - fct_len = - sprintf(fctbuf, "CT%c;", - status == RIG_FUNC_TSQL ? '0' : '1'); - return ts2k_transaction(rig, fctbuf, fct_len, - ackbuf, &ack_len); - - case RIG_FUNC_VOX: - fct_len = - sprintf(fctbuf, "VX%c;", - status == RIG_FUNC_VOX ? '0' : '1'); - return ts2k_transaction(rig, fctbuf, fct_len, NULL, NULL); - - case RIG_FUNC_NR: - fct_len = - sprintf(fctbuf, "NR%c;", - status == RIG_FUNC_NR ? '0' : '1'); - return ts2k_transaction(rig, fctbuf, fct_len, NULL, NULL); - - case RIG_FUNC_BC: - fct_len = - sprintf(fctbuf, "BC%c;", - status == RIG_FUNC_BC ? '0' : '1'); - return ts2k_transaction(rig, fctbuf, fct_len, NULL, NULL); - - case RIG_FUNC_ANF: - fct_len = - sprintf(fctbuf, "NT%c;", - status == RIG_FUNC_ANF ? '0' : '1'); - return ts2k_transaction(rig, fctbuf, fct_len, NULL, NULL); - - case RIG_FUNC_LOCK: - fct_len = - sprintf(fctbuf, "LK%c0;", - status == RIG_FUNC_LOCK ? '0' : '1'); - return ts2k_transaction(rig, fctbuf, fct_len, NULL, NULL); - - default: - rig_debug(RIG_DEBUG_ERR, "Unsupported set_func %#x", func); - return -RIG_EINVAL; - } - - return RIG_OK; -} - - -/* - * assumes status!=NULL - * works for any 'format 1' command - */ -static int -get_ts2k_func(RIG *rig, const char *cmd, int cmd_len, int *status) -{ - unsigned char fctbuf[50]; - int fct_len, retval; - - fct_len = 50; - retval = ts2k_transaction(rig, cmd, cmd_len, fctbuf, &fct_len); - - if (retval != RIG_OK) - { - return retval; - } - - if (fct_len != 4) - { - rig_debug(RIG_DEBUG_ERR, - __func__": wrong answer len=%u\n", fct_len); - return -RIG_ERJCTED; - } - - *status = fctbuf[2] == '0' ? 0 : 1; - - return RIG_OK; -}; - - -/* - * kenwood_get_func - * Assumes rig!=NULL, val!=NULL - */ -int ts2k_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status) -{ - unsigned char fctbuf[50]; - int fct_len, retval; - - fct_len = 50; - - /* Optimize: - * sort the switch cases with the most frequent first - */ - switch (func) - { - case RIG_FUNC_FAGC: - retval = ts2k_transaction(rig, "GT;", 3, fctbuf, &fct_len); - - if (retval != RIG_OK) - { - return retval; - } - - if (fct_len != 6) - { - rig_debug(RIG_DEBUG_ERR, "ts2k_get_func: " - "wrong answer len=%u\n", fct_len); - return -RIG_ERJCTED; - } - - *status = fctbuf[4] != '4' ? 1 : 0; - break; - - case RIG_FUNC_NB: - return get_ts2k_func(rig, "NB;", 3, status); - - case RIG_FUNC_ABM: - return get_ts2k_func(rig, "AM;", 3, status); - - case RIG_FUNC_COMP: - return get_ts2k_func(rig, "PR;", 3, status); - - case RIG_FUNC_TONE: - return get_ts2k_func(rig, "TO;", 3, status); - - case RIG_FUNC_TSQL: - return get_ts2k_func(rig, "CT;", 3, status); - - case RIG_FUNC_VOX: - return get_ts2k_func(rig, "VX;", 3, status); - - case RIG_FUNC_NR: - return get_ts2k_func(rig, "NR;", 3, status); - - /* FIXME on TS2000 */ - case RIG_FUNC_BC: - return get_ts2k_func(rig, "BC;", 3, status); - - case RIG_FUNC_ANF: - return get_ts2k_func(rig, "NT;", 3, status); - - case RIG_FUNC_LOCK: - return get_ts2k_func(rig, "LK;", 3, status); - - default: - rig_debug(RIG_DEBUG_ERR, "Unsupported get_func %#x", func); - return -RIG_EINVAL; - } - - return RIG_OK; -} - -/* - * kenwood_set_ctcss_tone - * Assumes rig!=NULL, rig->caps->ctcss_list != NULL - * - * Warning! This is untested stuff! May work at least on TS-870S - * Please owners report to me , thanks. --SF - * - * TODO: TS-2000 uses CN/CT - * ex057 menu is AutoPower off for TS-2000 --kd7eni - */ -int ts2k_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone) -{ - return ts2k_set_Tones(rig, vfo, tone, (char)'c'); -} - -int ts2k_set_tone(RIG *rig, vfo_t vfo, tone_t tone) -{ - return ts2k_set_Tones(rig, vfo, tone, (char)'t'); -} - -int ts2k_set_Tones(RIG *rig, vfo_t vfo, tone_t tone, const char ct) -{ - const struct rig_caps *caps; - unsigned char tonebuf[16], ackbuf[16]; - int tone_len, ack_len = 0; - int i; - - caps = rig->caps; - - /* TODO: replace 200 by something like RIGTONEMAX */ - for (i = 0; ts2k_ctcss_list[i] != 0 && i < 38; i++) - { - if ((ts2k_ctcss_list[i] >= tone) - && (ts2k_ctcss_list[i - 1] < tone)) // at least get close - { - break; - } - } - - if (ts2k_ctcss_list[i - 1] == tone) - { - i--; - } - - if (ts2k_ctcss_list[i] > tone) - { - return -RIG_EINVAL; - } - - tone_len = sprintf(tonebuf, "%cn%02u;", ct, i + 1); - - ack_len = 16; - return ts2k_transaction(rig, tonebuf, tone_len, NULL, NULL); - rig_debug(RIG_DEBUG_ERR, __func__": sent %s", tonebuf); -} - -/* - * kenwood_get_ctcss_tone - * Assumes rig!=NULL, rig->state.priv!=NULL - */ -int ts2k_get_ctcss_tone(RIG *rig, vfo_t vfo, tone_t *tone) -{ - return ts2k_get_Tones(rig, vfo, tone, "cn;"); -} - -int ts2k_get_tone(RIG *rig, vfo_t vfo, tone_t *tone) -{ - return ts2k_get_Tones(rig, vfo, tone, "tn;"); -} - -int ts2k_get_Tones(RIG *rig, vfo_t vfo, tone_t *tone, const char *ct) -{ - const struct rig_caps *caps; - unsigned char tonebuf[10]; - int tone_len, i, retval; - unsigned int tone_idx; - - caps = rig->caps; - - tone_len = 10; - retval = ts2k_transaction(rig, ct, 3, tonebuf, &tone_len); - - if (retval != RIG_OK) - { - return retval; - } - - if (tone_len != 5) - { - rig_debug(RIG_DEBUG_ERR, - __func__": unexpected reply " - "'%s', len=%u\n", tonebuf, tone_len); - return -RIG_ERJCTED; - } - - sscanf(tonebuf + 2, "%u", (int *) &tone_idx); - - if (tone_idx == 0) - { - rig_debug(RIG_DEBUG_ERR, - __func__": Unexpected Tone " - "no (%04d)\n", tone_idx); - return -RIG_EPROTO; - } - - /* check this tone exists. That's better than nothing. */ - for (i = 0; i < tone_idx; i++) - { - if (caps->ctcss_list[i] == 0) - { - rig_debug(RIG_DEBUG_ERR, - __func__": Tone NG " - "(%04d)\n", tone_idx); - return -RIG_EPROTO; - } - } - - *tone = caps->ctcss_list[tone_idx - 1]; - - return RIG_OK; -} - -/* - * kenwood_get_ptt - * Assumes rig!=NULL, ptt!=NULL - */ -int ts2k_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt) -{ - unsigned char infobuf[50]; - int info_len, retval; - - info_len = 50; - retval = ts2k_transaction(rig, "IF;", 3, infobuf, &info_len); - - if (retval != RIG_OK) - { - return retval; - } - - if (info_len != 38 || infobuf[1] != 'F') - { - rig_debug(RIG_DEBUG_ERR, - "ts2k_get_ptt: wrong answer len=%u\n", info_len); - return -RIG_ERJCTED; - } - - *ptt = infobuf[28] == '0' ? RIG_PTT_OFF : RIG_PTT_ON; - - return RIG_OK; -} - -/* - * kenwood_set_ptt - * Assumes rig!=NULL - */ -int ts2k_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) -{ - unsigned char ackbuf[16]; - int ack_len = 16; - - - return ts2k_transaction(rig, - ptt == - RIG_PTT_ON ? "TX;" : "RX;", 3, NULL, NULL); -} -/* - * kenwood_get_dcd - * Assumes rig!=NULL, dcd!=NULL - */ -int ts2k_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd) -{ - unsigned char busybuf[50]; - int busy_len, retval; - - busy_len = 50; - retval = ts2k_transaction(rig, "BY;", 3, busybuf, &busy_len); - - if (retval != RIG_OK) - { - return retval; - } - - if (busy_len != 4) - { - rig_debug(RIG_DEBUG_ERR, - "ts2k_get_dcd: wrong answer len=%u\n", busy_len); - return -RIG_ERJCTED; - } - - *dcd = (busybuf[2] == 0x01) ? RIG_DCD_ON : RIG_DCD_OFF; - - return RIG_OK; -} - -/* - * kenwood_set_trn - * Assumes rig!=NULL - */ -int ts2k_set_trn(RIG *rig, int trn) -{ - unsigned char trnbuf[16], ackbuf[16]; - int trn_len, ack_len = 16; - - /* changed to TS-2000 --D.E. kd7eni */ - - trn_len = sprintf(trnbuf, "AI%c;", trn == RIG_TRN_RIG ? '2' : '0'); - - return ts2k_transaction(rig, trnbuf, trn_len, NULL, NULL); - // No reply on "ai2;"--how quaint! -} -/* - * kenwood_get_trn - * Assumes rig!=NULL, trn!=NULL - */ int ts2k_get_trn(RIG *rig, int *trn) -{ - unsigned char trnbuf[50]; - int trn_len, retval; - - trn_len = 50; - retval = ts2k_transaction(rig, "AI;", 3, trnbuf, &trn_len); - - if (retval != RIG_OK) - { - return retval; - } - - if (trn_len != 4) - { - rig_debug(RIG_DEBUG_ERR, - "ts2k_get_trn: wrong answer" "len=%u\n", - trn_len); - return -RIG_ERJCTED; - } - - *trn = trnbuf[2] != '0' ? RIG_TRN_RIG : RIG_TRN_OFF; - - return RIG_OK; -} - -/* - * kenwood_set_powerstat - * Assumes rig!=NULL - */ -int ts2k_set_powerstat(RIG *rig, powerstat_t status) -{ - unsigned char pwrbuf[16], ackbuf[16]; - int pwr_len, ack_len = 16; - - pwr_len = - sprintf(pwrbuf, "PS%c;", status == RIG_POWER_ON ? '1' : '0'); - - return ts2k_transaction(rig, pwrbuf, pwr_len, ackbuf, &ack_len); -} -/* - * kenwood_get_powerstat - * Assumes rig!=NULL, trn!=NULL - */ -int ts2k_get_powerstat(RIG *rig, powerstat_t *status) -{ - unsigned char pwrbuf[50]; - int pwr_len = 50, retval; - - // No reply when powered off, 1=power on. Geez! - retval = ts2k_transaction(rig, "PS;", 3, pwrbuf, &pwr_len); - - if (retval != RIG_OK) - { - return retval; - } - - if (pwr_len != 4) - { - rig_debug(RIG_DEBUG_ERR, - "ts2k_get_powerstat: wrong answer " - "len=%u\n", pwr_len); - return -RIG_ERJCTED; - } - - *status = pwrbuf[2] == '0' ? RIG_POWER_OFF : RIG_POWER_ON; - - return RIG_OK; -} - -/* - * kenwood_reset - * Assumes rig!=NULL - */ -int ts2k_reset(RIG *rig, reset_t reset) -{ - unsigned char rstbuf[16], ackbuf[16]; - int rst_len, ack_len = 16; - char rst; - - switch (reset) - { - case RIG_RESET_VFO: - rst = '1'; - break; - - case RIG_RESET_MASTER: - rst = '2'; - break; - - default: - rig_debug(RIG_DEBUG_ERR, - "ts2k_reset: unsupported reset %u\n", reset); - return -RIG_EINVAL; - } - - rst_len = sprintf(rstbuf, "SR%c;", rst); - - // Largely untested! ;) --kd7eni - return ts2k_transaction(rig, rstbuf, rst_len, ackbuf, &ack_len); -} - -/* - * kenwood_send_morse - * Assumes rig!=NULL - */ -int ts2k_send_morse(RIG *rig, vfo_t vfo, const char *msg) -{ - unsigned char morsebuf[30], ackbuf[16]; - int morse_len, ack_len = 0; - int msg_len, buff_len, retval; - const char *p; - - p = msg; - msg_len = strlen(msg); - - while (msg_len > 0) - { - /* - * TODO: check with "KY;" if char buffer is available. - * if not, sleep. - */ - buff_len = msg_len > 24 ? 24 : msg_len; - - strcpy(morsebuf, "KY "); - strncat(morsebuf, p, buff_len); - strcat(morsebuf, ";"); - morse_len = 4 + buff_len; - ack_len = 16; - retval = - ts2k_transaction(rig, morsebuf, morse_len, - ackbuf, &ack_len); - - if (retval != RIG_OK) - { - return retval; - } - - msg_len -= buff_len; - p += buff_len; - } - - return RIG_OK; -} - -/* - * kenwood_vfo_op - * Assumes rig!=NULL - */ -int ts2k_vfo_op(RIG *rig, vfo_t vfo, vfo_op_t op) -{ - unsigned char *cmd, ackbuf[16]; - int ack_len = 0; - - switch (op) - { - case RIG_OP_UP: - cmd = "UP;"; - break; - - case RIG_OP_DOWN: - cmd = "DN;"; - break; - - case RIG_OP_BAND_UP: - cmd = "BD;"; - break; - - case RIG_OP_BAND_DOWN: - cmd = "BU;"; - break; - - default: - rig_debug(RIG_DEBUG_ERR, - "ts2k_vfo_op: unsupported op %#x\n", op); - return -RIG_EINVAL; - } - - ack_len = 16; - return ts2k_transaction(rig, cmd, 3, NULL, NULL); -} - -/* - * kenwood_set_mem - * Assumes rig!=NULL - */ -int ts2k_set_mem(RIG *rig, vfo_t vfo, int ch) -{ - unsigned char membuf[16], ackbuf[16]; - int mem_len, ack_len = 16; - - /* - * "MCbmm;" - * where b is the bank number, mm the memory number. - * b can be a space ( *not*! manual wrong. --kd7eni - */ - mem_len = sprintf(membuf, "MC%03d;", ch); - - return ts2k_transaction(rig, membuf, mem_len, NULL, NULL); -} -/* - * kenwood_get_mem - * Assumes rig!=NULL - */ int ts2k_get_mem(RIG *rig, vfo_t vfo, int *ch) -{ - unsigned char membuf[50]; - int retval, mem_len; - - /* - * "MCbmm;" - * where b is the bank number, mm the memory number. - * b can be a space (*not* --kd7eni) - */ - - mem_len = 10; - retval = ts2k_transaction(rig, "MC;", 3, membuf, &mem_len); - - if (retval != RIG_OK) - { - return retval; - } - - if (mem_len != 6) - { - rig_debug(RIG_DEBUG_ERR, - "ts2k_get_mem: wrong answer " "len=%u\n", - mem_len); - return -RIG_ERJCTED; - } - - membuf[5] = '\0'; - *ch = atoi(membuf + 2); - - return RIG_OK; -} - -/* - * kenwood_get_info - * supposed to work only for TS2000... - * Assumes rig!=NULL - */ -const char *ts2k_get_info(RIG *rig) -{ - unsigned char firmbuf[50]; - int firm_len, retval; - - firm_len = 50; - retval = ts2k_transaction(rig, "TY;", 3, firmbuf, &firm_len); - - if (retval != RIG_OK) - { - return NULL; - } - - if (firm_len != 6) - { - rig_debug(RIG_DEBUG_ERR, - "ts2k_get_info: wrong answer len=%u\n", - firm_len); - return NULL; - } - - switch (firmbuf[4]) - { - case '0': - return "Firmware: Overseas type"; - - case '1': - return "Firmware: Japanese 100W type"; - - case '2': - return "Firmware: Japanese 20W type"; - - default: - return "Firmware: unknown"; - } -} - -#define IDBUFSZ 16 - -/* - * probe_kenwood - */ -rig_model_t probe_ts2k(port_t *port) -{ - unsigned char idbuf[IDBUFSZ]; - int id_len, i, k_id; - int retval; - - if (!port) - { - return RIG_MODEL_NONE; - } - - port->write_delay = port->post_write_delay = 0; - port->timeout = 50; - port->retry = 1; - - retval = serial_open(port); - - if (retval != RIG_OK) - { - return RIG_MODEL_NONE; - } - - retval = write_block(port, "ID;", 3); - id_len = read_string(port, idbuf, IDBUFSZ, EOM_KEN EOM_TH, 2); - - close(port->fd); - - if (retval != RIG_OK) - { - return RIG_MODEL_NONE; - } - - /* - * reply should be something like 'IDxxx;' - */ - if (id_len != 5 && id_len != 6) - { - idbuf[7] = '\0'; - rig_debug(RIG_DEBUG_VERBOSE, - "probe_ts2k: protocol error," - " expected %u, received %u: %s\n", 6, - id_len, idbuf); - return RIG_MODEL_NONE; - } - - - /* first, try ID string */ - for (i = 0; ts2k_id_string_list[i].model != RIG_MODEL_NONE; i++) - { - if (!strncmp(ts2k_id_string_list[i].id, idbuf + 2, 16)) - { - rig_debug(RIG_DEBUG_VERBOSE, - "probe_ts2k: " "found %s\n", idbuf + 2); - return ts2k_id_string_list[i].model; - } - } - - /* then, try ID numbers */ - - k_id = atoi(idbuf + 2); - - for (i = 0; ts2k_id_list[i].model != RIG_MODEL_NONE; i++) - { - if (ts2k_id_list[i].id == k_id) - { - rig_debug(RIG_DEBUG_VERBOSE, - "probe_ts2k: " "found %03d\n", k_id); - return ts2k_id_list[i].model; - } - } - - /* - * not found in known table.... - * update ts2k_id_list[]! - */ - rig_debug(RIG_DEBUG_WARN, - "probe_ts2k: found unknown device " - "with ID %03d, please report to Hamlib " - "developers.\n", k_id); - - return RIG_MODEL_NONE; -} - - -/* kenwood_init - * - * Basically, it sets up *priv - * REM: serial port is already open (rig->state.rigport.fd) - */ -int ts2k_init(RIG *rig) -{ - const struct rig_caps *caps; - const struct ts2k_priv_caps *priv_caps; - rig_debug(RIG_DEBUG_TRACE, __func__ ": called\n"); - - if (!rig || !rig->caps) - { - return -RIG_EINVAL; - } - - caps = rig->caps; - - if (!caps->priv) - { - return -RIG_ECONF; - } - - priv_caps = (const struct ts2k_priv_caps *) caps->priv; - -#if 0 /* No private data for Kenwood backends */ - priv = (struct ts2k_priv_data *) - malloc(sizeof(struct ts2k_priv_data)); - - if (!priv) - { - /* whoops! memory shortage! */ - return -RIG_ENOMEM; - } - - rig->state.priv = (void *) priv; - /* Assign default values */ - priv->dummy = -1; // placeholder for real entries. -#endif - - return RIG_OK; -} - -/* kenwood_cleanup - * the serial port is closed by the frontend - */ -int ts2k_cleanup(RIG *rig) -{ - rig_debug(RIG_DEBUG_TRACE, __func__ ": called\n"); - - if (!rig) - { - return -RIG_EINVAL; - } - - if (rig->state.priv) - { - free(rig->state.priv); - } - - rig->state.priv = NULL; - - return RIG_OK; -} -/* - * initrigs_kenwood is called by rig_backend_load - */ int initrigs_ts2k(void *be_handle) -{ - rig_debug(RIG_DEBUG_VERBOSE, "ts2k: _init called\n"); - - rig_register(&ts950sdx_caps); - rig_register(&ts50s_caps); - rig_register(&ts450s_caps); - rig_register(&ts570d_caps); - rig_register(&ts570s_caps); - rig_register(&ts790_caps); - rig_register(&ts850_caps); - rig_register(&ts870s_caps); - rig_register(&ts2000_caps); - rig_register(&thd7a_caps); - rig_register(&thf7e_caps); - - return RIG_OK; -} - -/***************************************************************************** - Added the following functions. - (C) Copyright 2002 by Dale E. Edmons. All rights Reserved. - License: Identical to all other Hamlib code. -*****************************************************************************/ - -#define CHKERR(c) if((c) != RIG_OK) return c -#define STUFF(c) int retval, acklen=(c); char ack[c] -//#define STUFF(c) static int retval, acklen=(c); static char ack[c] - -// The following two are expensive but convenient! - -int ncpy(char *tmp, char *src, int cnt) -{ - strncpy(tmp, src, cnt); - tmp[cnt] = '\0'; - return RIG_OK; -} - -int int_n(char *tmp, char *src, const int cnt) -{ - ncpy(tmp, src, cnt); - return atoi(tmp); -} - -/* - * ts2k_get_ctrl() ts2000 transceiver check. Tests and returns the value of the current - * PTT/CTRL (using "dc;") for main and sub transceivers. The settings are: - * - * PTT __ __ CTRL '0' = main; '1' = sub - * \ / - * "dc00;" PTT && CTRL both on main - * "dc01;" PTT on main; CTRL on sub - * "dc10;" PTT on sub; CTRL both on main - * "dc11;" PTT && CTRL both on sub - */ -//int ts2k_get_ctrl(RIG * rig, char *dc_buf, int dc_len) // use this when static removed. -char *ts2k_get_ctrl(RIG *rig) -{ - // FIXME: I guess this shouldn't be static for re-entrancy --Dale - static char dc_buf[16]; - static int dc_len; - - static int retval; - dc_len = 16; - -// rig_debug(RIG_DEBUG_VERBOSE, "ts2k_get_ctrl: getting PTT/CTRL bytes\n"); - - retval = ts2k_transaction(rig, "dc;", 3, dc_buf, &dc_len); - - if (retval != RIG_OK) - { - rig_debug(RIG_DEBUG_VERBOSE, - "ts2k_get_ctrl:error: retval=%u, dc_buf=%s\n", - retval, dc_buf); - return NULL; - } - -// rig_debug(RIG_DEBUG_VERBOSE, "ts2k_get_ctrl: returning %u PTT/CTRL bytes\n", dc_len); - -// return RIG_OK; // use this when static variable removed and all other code changed. - return dc_buf; -} - -/* NOTE: PTT/CTRL enable is set only if ptt != 0 (or ctrl) */ -int ts2k_set_ctrl(RIG *rig, int ptt, int ctrl) -{ - STUFF(10); - char *buf; - int buflen = 10; - - buf = ts2k_get_ctrl(rig); - - if (buf == NULL) - { - rig_debug(RIG_DEBUG_VERBOSE, __func__ \ - ": returned NULL!\n"); - return -RIG_EINVAL; - } - - rig_debug(RIG_DEBUG_VERBOSE, __func__": curr='%s'," - "ptt=%u, ctrl=%u\n", buf, ptt, ctrl); - - if (ptt != 0) - { - buf[2] = (TS2K_PTT_ON_SUB == ptt) ? '1' : '0'; - } - - if (ctrl != 0) - { - buf[3] = (TS2K_CTRL_ON_SUB == ctrl) ? '1' : '0'; - } - - buf[4] = ';'; - buf[5] = '\0'; // just for printing debug - - acklen = 10; - retval = ts2k_transaction(rig, buf, 5, NULL, NULL); - CHKERR(retval); - - return RIG_OK; -} - -/* - * FIXME: simple ascii to integer converter--expensive! - * Prevents trashing original string, otherwise - * just drop a (char)0 where you need it. - */ -int ts2k_get_int(char *src, int cnt) -{ - static char buf[20]; - - strncpy(buf, src, cnt); - buf[cnt] = (char) 0; - - return atoi(buf); -} - -int ts2k_get_rit(RIG *rig, vfo_t vfo, shortfreq_t *rit) -{ - int retval, acklen; - char ack[40]; - char *ctrl; - - ctrl = ts2k_get_ctrl(rig); - - if (ctrl == NULL) // do we have valid "dc;" ? - { - return -RIG_EINVAL; // don't know proper errors yet! - } - - // sub shows main's rit! We return 0 if subreceiver. - if (ctrl[3] == '1') - { - *rit = 0; - return RIG_OK; // not really, but it's paid for... - } - - retval = ts2k_transaction(rig, "if;", 3, ack, &acklen); - CHKERR(retval); - - ack[23] = (char) 0; - *rit = atoi(&ack[17]); - - return RIG_OK; -} - -/* - * ts2k_get_xit() We just call ts2k_get_rit() - * On the ts2k, they're the same. The rig - * acts this way. -*/ -int ts2k_get_xit(RIG *rig, vfo_t vfo, shortfreq_t *rit) -{ - return ts2k_get_rit(rig, vfo, rit); -} - -int ts2k_set_rit(RIG *rig, vfo_t vfo, shortfreq_t rit) -{ - char buf[40], c; - int retval, i, len; - - // Clear current rit/xit. - retval = ts2k_transaction(rig, "rc;", 3, NULL, NULL); - CHKERR(retval); - - // Execute up/down request. - if (rit > 0) - { - c = 'u'; - i = rit; - } - else - { - c = 'd'; - i = -rit; - } - - len = sprintf(buf, "r%c%6d;", c, i); - - return ts2k_transaction(rig, buf, len, NULL, NULL); -} - -int ts2k_set_xit(RIG *rig, vfo_t vfo, shortfreq_t rit) -{ - return ts2k_set_rit(rig, vfo, rit); -} - -int ts2k_get_ts(RIG *rig, vfo_t vfo, shortfreq_t *ts) -{ - STUFF(10); - int m, s; - - retval = ts2k_transaction(rig, "ST;", 5, ack, &acklen); - CHKERR(retval); - - ack[4] = '\0'; - s = atoi(&ack[2]); - - rig_debug(RIG_DEBUG_VERBOSE, __func__": received: '%s', %u\n", ack, s); - - retval = ts2k_transaction(rig, "MD;", 5, ack, &acklen); - CHKERR(retval); - - // fm or am mode selects 1 - m = (ack[2] == '4' || ack[2] == '5') ? 1 : 0; - - rig_debug(RIG_DEBUG_VERBOSE, __func__": received: '%s', %u\n", ack, m); - - *ts = ts2k_steps[m][s]; - return RIG_OK; -} - -// FIXME: should get nearest, not easiest. :) -/* - * status: working. fixed timeout. --Dale - */ -int ts2k_set_ts(RIG *rig, vfo_t vfo, shortfreq_t ts) -{ - STUFF(10); - char st[10]; - int m, s, k; - long int aver, diff[2]; - - retval = ts2k_transaction(rig, "md;", 5, ack, &acklen); - CHKERR(retval); - - // fm or am mode selects 1 - m = (ack[2] == '4' || ack[2] == '5') ? 1 : 0; - - // fm or am selects 10 step freq. else 4. - k = (m) ? 10 : 4; - - s = 0; - - if (ts < ts2k_steps[m][0]) - { - k = s; - } - - if (ts > ts2k_steps[m][9]) - { - s = 9; - } - - for (s = 1 ; s < k; s++) - { - if (ts2k_steps[m][s - 1] <= ts && ts <= ts2k_steps[m][s]) - { - diff[0] = ts - ts2k_steps[m][s - 1]; - diff[1] = ts2k_steps[m][s] - ts; - - if (diff[0] > diff[1]) // closer to [s] - { - break; - } - else // closer to [s-1] - { - s--; - break; - } - } - } - - // m is tmp now - m = sprintf(st, "st0%1u;", s); - - // no reply! - retval = ts2k_transaction(rig, st, m, NULL, NULL); - CHKERR(retval); - - return RIG_OK; -} - -/* Rig truncates in kHz(50) steps, so we don't. */ -int ts2k_get_rptr_offs(RIG *rig, vfo_t vfo, shortfreq_t *rptr_offs) -{ - STUFF(20); - - retval = ts2k_transaction(rig, "of;", 3, ack, &acklen); - CHKERR(retval); - - if (ack[0] != 'O' || ack[1] != 'F') - { - return -RIG_EINVAL; - } - - if (acklen != 12) - { - return -RIG_EINVAL; - } - - ack[11] = '\0'; - *rptr_offs = atoi(&ack[2]); - - return RIG_OK; -} - -/* Rig truncates in kHz(50) steps, so we don't. */ -int ts2k_set_rptr_offs(RIG *rig, vfo_t vfo, shortfreq_t rptr_offs) -{ - STUFF(20); - char buf[20]; - int buflen = 20, i; - - i = sprintf(buf, "of%09u;", (unsigned int) rptr_offs); - - retval = ts2k_transaction(rig, buf, i, NULL, NULL); - CHKERR(retval); - - return RIG_OK; -} - -/* - * status: working, leaves vfo intact. - */ -int ts2k_get_rptr_shift(RIG *rig, vfo_t vfo, rptr_shift_t *rptr_shift) -{ - STUFF(20); - vfo_t vfo_tmp; - - // FIXME: I don't know if I should change back to currVFO, but I do. - retval = ts2k_get_vfo(rig, &vfo_tmp); - CHKERR(retval); - - retval = ts2k_transaction(rig, "os;", 3, ack, &acklen); - CHKERR(retval); - - retval = ts2k_vfo_ctrl(rig, vfo); - - if (ack[0] != 'O' || ack[1] != 'S') - { - return -RIG_EINVAL; - } - - //if(acklen != 4) return -RIG_EINVAL; - - switch (ack[2]) - { - case '0': - *rptr_shift = RIG_RPT_SHIFT_NONE; - break; - - case '1': - *rptr_shift = RIG_RPT_SHIFT_MINUS; - break; - - case '2': - *rptr_shift = RIG_RPT_SHIFT_PLUS; - break; - - case '3': - *rptr_shift = RIG_RPT_SHIFT_1750; - break; - - default: - return -RIG_EINVAL; - break; - } - - // FIXME: I don't know if I should change back to currVFO, but I do. - retval = ts2k_set_vfo(rig, vfo_tmp); - CHKERR(retval); - - return RIG_OK; -} - -/* - * ts2k_set_rptr_shift() - * - * status: doesn't check VFO yet --Dale - */ -int ts2k_set_rptr_shift(RIG *rig, vfo_t vfo, rptr_shift_t rptr_shift) -{ - STUFF(10); - char c; - - switch (rptr_shift) - { - case RIG_RPT_SHIFT_NONE: - c = '0'; - break; - - case RIG_RPT_SHIFT_PLUS: - c = '1'; - break; - - case RIG_RPT_SHIFT_MINUS: - c = '2'; - break; - - case RIG_RPT_SHIFT_1750: // FIXME: invalid for mine! (non-Etype) - c = '3'; - break; - - default: - return -RIG_EINVAL; - break; - } - - acklen = sprintf(ack, "os%c;", c); - - retval = ts2k_transaction(rig, ack, 4, NULL, NULL); - CHKERR(retval); - - return RIG_OK; -} - -int ts2k_get_split(RIG *rig, vfo_t vfo, split_t *split) -{ - STUFF(10); - char ack2[10]; - int ack2len = 10; - - retval = ts2k_transaction(rig, "fr;", 3, ack, &acklen); - CHKERR(retval); - - retval = ts2k_transaction(rig, "ft;", 3, ack2, &ack2len); - CHKERR(retval); - - if (ack[2] != ack2[2]) - { - *split = RIG_SPLIT_ON; - } - else - { - *split = RIG_SPLIT_OFF; - } - - return RIG_OK; -} - -/* no VFO check, and no mem. Yet. */ -int ts2k_set_split(RIG *rig, vfo_t vfo, split_t split) -{ - STUFF(10); - char ack2[10]; - int ack2len = 10; - - retval = ts2k_transaction(rig, "fr;", 3, ack, &acklen); - CHKERR(retval); - - retval = ts2k_transaction(rig, "ft;", 3, ack2, &ack2len); - CHKERR(retval); - - if (split == RIG_SPLIT_ON) // RX/TX on different vfo's - { - if (ack[2] == '0') - { - ack2[2] = '1'; - } - else if (ack[2] == '1') - { - ack2[2] = '0'; - } - - /* FIXME: mem split. mem/vfo split must enable menu 6a - * with the "ex...;" or mem/vfo won't work. A split - * memory operates simply by storing a memory with the - * freq with RX != TX then recalling it. Don't know if - * if two separate memories can be used (e.g. 100/101) - */ - else - { - return -RIG_EINVAL; - } - } - else // RX/TX on same vfo (or mem etc...) - { - ack2[2] = ack[2]; - } - - // now, just send back the rig's strings :) - retval = ts2k_transaction(rig, ack, acklen, NULL, NULL); - CHKERR(retval); - - retval = ts2k_transaction(rig, ack2, ack2len, NULL, NULL); - CHKERR(retval); - - return RIG_OK; -} - -int ts2k_get_split_freq(RIG *rig, vfo_t vfo, freq_t *tx_freq) -{ - // FIXME : This makes too many assumptions--I'll fix it later...d PTT/CTRL bytes\n", dc_len);*//* The following are functions I've added for the TS-2000. (C) 2002 D. Edmons and all that. *//*-------------------------------------------------------------------------------------------*/ - return ts2k_get_freq(rig, vfo, tx_freq); -} - -int ts2k_set_split_freq(RIG *rig, vfo_t vfo, freq_t tx_freq) -{ - // FIXME : This makes too many assumptions--I'll fix it later...d PTT/CTRL bytes\n", dc_len);*//* The following are functions I've added for the TS-2000. (C) 2002 D. Edmons and all that. *//*-------------------------------------------------------------------------------------------*/ - return ts2k_set_freq(rig, vfo, tx_freq); -} - -/* ts2k_get_channel() - * - * status: working! reading unset memory is an error. this - * is the rig. vfo_t is not needed for regular memory - * and we don't check it now. when we start to access - * other memory we'll split into multiple functions - * each dedicated to the unique type (e.g. quick/tmp). - * - * memory range not checked. - * - * Note: the manual erroneously states bank should be ' ' if - * memory is <100. The "correct" way is to *never* - * send a ' ' or you'll get a "?;" response. Always - * set memory with (e.g.) "mc1020;". --kd7eni - */ -int ts2k_get_channel(RIG *rig, channel_t *chan) -{ -// channel_t tch; // needed? - char rxtx, mrtxt[2][60], mrcmd[15], ack[60], tmp[20]; - int i, check, retval, curr_mem, mrtxt_len, mrcmd_len, ack_len; - vfo_t curr_vfo; -#ifdef _USEVFO - vfo_t v; - - v = vfo; - - // check the memory bit - if (!(v & RIG_VFO_MEM)) - { - rig_debug(RIG_DEBUG_ERR, __func__ - ": Non Memory VFO='%u', v=%u\n", vfo, v); - return -RIG_EINVAL; // not a channel! - } - -// get needed info if rig's mem pointers used - if ((vfo == RIG_VFO_MEM_A - || vfo == RIG_VFO_MEM_C)) - { - rig_debug(RIG_DEBUG_ERR, __func__": using rig's ptr\n"); - retval = ts2k_get_vfo(rig, &curr_vfo); - CHKERR(retval); - retval = ts2k_get_mem(rig, curr_vfo, &curr_mem); - CHKERR(retval); - chan->channel_num = curr_mem; - } - -#endif - - mrtxt_len = ack_len = 60; - mrcmd_len = 15; - - if (chan == NULL) - { - return -RIG_EINVAL; - } - -// send request for both rx mem and tx mem - for (i = 0; i < 2; i++) // 0=rx; 1=tx - { - - mrcmd_len = sprintf(mrcmd, "mr%01d%03u;", i, chan->channel_num); - ack_len = 60; // must be reset inside loop! - retval = ts2k_transaction(rig, mrcmd, mrcmd_len, ack, &ack_len); - CHKERR(retval); - - rig_debug(RIG_DEBUG_ERR, __func__": read \n\t'%s'\n", ack); - - ack[50] = '\0'; // May be too far, but helps. - - // watch out. |= and != look the same! - // Perform checks on data. - check = (ack[0] != 'M'); - check |= (ack[1] != 'R'); - check |= (ack[2] != ((i == 0) ? '0' : '1')); - check |= (chan->channel_num != int_n(tmp, &ack[3], 3)); - - if (check) - { - rig_debug(RIG_DEBUG_ERR, __func__ - ":check failed!\n"); - return -RIG_EINVAL; // correct error type? - } - - // all is well, save string - strncpy(&mrtxt[i][0], ack, 52); - } - - // FIXME: handle mem split - // final check on data. (if RX!=TX mem split, or limit!) - if (strncmp(&mrtxt[0][3], &mrtxt[1][3], 41 - 3) != 0) - { - rig_debug(RIG_DEBUG_ERR, "\n"__func__ - ": MEM split and band limits not yet supported!\n"); - return -RIG_EINVAL; // FIXME: sending proper error? - } - - // FIXME: 1) Since chan is not an array, we fudge and only do TX! - // even if split!!!!!!!! - // FIXME: 2) we only handle regular memories, not everything - // FIXME: 3) I store only data ts2k actually saves in memory - // some values are the ts2k value, not the hamlib value! - - // (keep same order as channel struct to ease debugging!) -// chan->channel_num = ; // already set? - -// The following may be used to indicate we're reading limits (290-299). -// At any rate, it's currently unused. - chan->bank_num = 0; // I merge the two--do not use! --Dale - - chan->lock = int_n(tmp, &mrtxt[0][18], 1); - chan->freq = int_n(tmp, &mrtxt[0][06], 11); - chan->mode = ts2k_mode_list[ int_n(tmp, &mrtxt[0][17], 1) ]; - - if (chan->mode == RIG_MODE_AM || chan->tx_mode == RIG_MODE_FM) - { - i = 1; - } - else - { - i = 0; - } - - chan->width = 0; - chan->tx_freq = int_n(tmp, &mrtxt[1][06], 11); - chan->tx_mode = ts2k_mode_list[ int_n(tmp, &mrtxt[1][17], 1)]; - chan->tx_width = 0; - chan->split = 0; - chan->rptr_shift = int_n(tmp, &mrtxt[1][28], 1); - chan->rptr_offs = int_n(tmp, &mrtxt[1][29], 9); - - if (chan->tx_mode == RIG_MODE_AM || chan->tx_mode == RIG_MODE_FM) - { - i = 1; - } - else - { - i = 0; - } - - chan->tuning_step = ts2k_steps[i][ int_n(tmp, & mrtxt[1][38], 2) ]; - chan->rit = 0; - chan->xit = 0; - chan->funcs = 0; - - for (i = 0; i < RIG_SETTING_MAX; i++) - { - // the following shamelessly stolen from rigctl.c --Dale - setting_t level = rig_idx2setting(i); // now, I understand - - if (RIG_LEVEL_IS_FLOAT(level)) - { - chan->levels[i].f = 0.0; // I'd figured this out. - } - else - { - chan->levels[i].f = 0.0; - } - } - - chan->ctcss_tone = ts2k_ctcss_list[ int_n(tmp, &mrtxt[1][22], 2) + 1 ]; - chan->ctcss_sql = int_n(tmp, &mrtxt[1][19], 1); - chan->dcs_code = ts2k_dcs_list[ int_n(tmp, &mrtxt[1][24], 3) ]; - chan->dcs_sql = int_n(tmp, &mrtxt[1][19], 1); - chan->scan_group = int_n(tmp, &mrtxt[1][40], 1); -// chan->flags = curr_vfo; // n/a - // FIXME : The following may have trailing garbage - strncpy(chan->channel_desc, &mrtxt[1][41], 8); - chan->channel_desc[8] = '\0'; - -#ifdef _USEVFO - -// if curr mem is changed at top, this'll restore it - if ((vfo == RIG_VFO_MEM_A - || vfo == RIG_VFO_MEM_C)) - { - } - - rig_debug(RIG_DEBUG_ERR, __func__": restoring mem=%i\n", curr_mem); - retval = ts2k_set_mem(rig, curr_vfo, curr_mem); - CHKERR(retval); -#endif - - return RIG_OK; -} - -/* - * ts2k_set_channel() Here I read a channel_t and memory data. I'm - * assuming this is correct. Anyway, this is a useful function. - * The only quirk is that the TS-2000 saves both TX as well - * as RX data separately. This function can easily be modified - * to write as if there were 600 memories but that would lead - * to confusion and the rig certainly don't operate that way. - * I hope to channel_t *chan changed to channel_t *chan[2]. - * (As well as vfo_t too.) Much thanks to Stephane for already - * having the most important stuff working from the start - * (mostly anyway). - * - * From here on out I'm gonna try to use hamlib-1.1.0.pdf - * for the design document and hopefully I'll know which way - * to go when things aren't the way they should be. We'll - * see how things go. - * --Dale kd7e - */ -int ts2k_set_channel(RIG *rig, const channel_t *chan) -{ - char mrtxt[2][60], mrcmd[10], ack[60]; - int retval, i, j, mr_len[2], ack_len; - - // the following are the actual memory data to be written. - unsigned int - p1, // RX/TX (bool) - p2p3, // this is not a bug--I combine bank/channel - p4, // freq - p5, // mode - p6, // lockout - p7, // tone, ctcss, dcs - p8, // tone # - p9, // CTCSS # - p10, // DCS code - p11, // revers status - p12, // repeater shift - p13, // offset freq - p14, // step size - p15; // memory group (0-9) - char *p16; // 8 char + 1 null byte - - ack_len = 10; - /* - * Write everthing in order. We only set things that - * the rig actually puts in memory. This way, a set - * followed by a get will match exactly. Otherwise, - * we'll have to fudge and won't know when we have - * a valid save. (FIXME: delete all this useless - * comment stuff after the code is working. --Dale) - */ - - /* FIXME: we are required to have RX/TX match */ - if (chan->freq != chan->tx_freq) - { - return -RIG_EINVAL; // should be 'unimplemented' - } - - for (i = 0; i < 2; i++) - { - p1 = (unsigned int) i; // 0=RX, 1=TX - - p2p3 = (unsigned int) chan->channel_num; // we'll compare 'em later - - if (i == 0) - { - p4 = (unsigned int) chan->freq; - } - else - { - p4 = (unsigned int) chan->tx_freq; - } - - for (j = 0; j < (sizeof(ts2k_mode_list) / sizeof(int)); j++) - { - if (chan->mode == ts2k_mode_list[j]) - { - break; - } - } - - p5 = (unsigned int) j; // FIXME: either not found, or last! - p6 = (unsigned int) chan->lock; - p7 = 0; // FIXME: to lazy to sort this out right now - p8 = 0; // " " " " " - p9 = 0; // " " " " " - p10 = 0; // " " " " " - p11 = 0; // " " " " " - p12 = 0; // " " " " " - p13 = 0; // " " " " " - p14 = 0; // " " " " " - p15 = (unsigned int) chan->scan_group; - p16 = &(chan->channel_desc[0]); - - mr_len[i] = sprintf(&(mrtxt[i][0]), - "mr%1u%3u%11u%1u%1u%1u%2u%2u%3u%1u%1u%9u%2u%1u%s;", - p1, p2p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, - p14, p15, - p16 - ); // yikes! - retval = ts2k_transaction(rig, &mrtxt[i][0], mr_len[i], - ack, &ack_len); - CHKERR(retval); - - // FIXME: now readback the string and make sure it worked! - } - - return retval; -} - -/* - * ts2k_vfo_ctrl() set PTT/CTRL based on VFO arg - * - * (Taken from my revision of ts2k_set_vfo()) - * - * status: VFOA, VFOB, VFOC, Main, Sub, - * MEMA, MEMC, CALLA, CALLC - * VFO_AB, VFO_BA, ... - * They all work! --Dale - */ -int ts2k_vfo_ctrl(RIG *rig, vfo_t vfo) -{ - int ptt, ctrl; - int retval; - - ptt = ctrl = 0; - - // Main/Sub Active Transceiver - switch (vfo) - { - case RIG_VFO_A: - case RIG_VFO_B: - case RIG_VFO_AB: // split - case RIG_VFO_BA: - case RIG_CTRL_SAT: // Should be PTT on main CTRL on sub (?) - case RIG_VFO_MAIN: - case RIG_VFO_MEM_A: - case RIG_VFO_CALL_A: - ctrl = TS2K_CTRL_ON_MAIN; // FIXME : these are independent! - ptt = TS2K_PTT_ON_MAIN; - break; - - case RIG_VFO_C: - case RIG_VFO_SUB: - case RIG_VFO_MEM_C: - case RIG_VFO_CALL_C: - ctrl = TS2K_CTRL_ON_SUB; - ptt = TS2K_PTT_ON_SUB; - break; - - default: - break; - } - - // set PTT/CTRL - retval = ts2k_set_ctrl(rig, ptt, ctrl); - - if (retval != RIG_OK) - { - return -RIG_EINVAL; - } - - return retval; -} - -/* - * status: ok, no vfo checks - */ -int ts2k_get_dcs_code(RIG *rig, vfo_t vfo, tone_t *code) -{ - char ack[10], tmp[10]; - int retval, acklen, i; - - acklen = 10; - retval = ts2k_transaction(rig, "qc;", 6, ack, &acklen); - CHKERR(retval); - - i = int_n(tmp, &ack[2], 3); - *code = ts2k_dcs_list[i]; - - return RIG_OK; -} - -/* - * status: ok, no vfo checks - */ -int ts2k_set_dcs_code(RIG *rig, vfo_t vfo, tone_t code) -{ - char ack[10], cmd[10], tmp[10]; - int retval, acklen, cmdlen, i; - - // we only allow exact matches here - i = 0; - - while (code != ts2k_dcs_list[i]) - { - if (ts2k_dcs_list[i] == 0) - { - return -RIG_EINVAL; - } - - i++; - } - - cmdlen = sprintf(cmd, "qc%03u;", i); - return ts2k_transaction(rig, cmd, cmdlen, NULL, NULL); -} - -/* - * status: new, all guesses and assumptions! - * know nothing about txwidth (which one?) - * or tx = rx + txwidth? - */ -int ts2k_set_split_mode(RIG *rig, - vfo_t vfo, rmode_t txmode, pbwidth_t txwidth) -{ - vfo_t vtmp; - - switch (vfo) - { - case RIG_VFO_AB: - vtmp = RIG_VFO_B; break; - - case RIG_VFO_BA: - vtmp = RIG_VFO_A; break; - - default: - return -RIG_EINVAL; - } - - return ts2k_set_mode(rig, vtmp, txmode, txwidth); -} - -int ts2k_get_split_mode(RIG *rig, - vfo_t vfo, rmode_t *txmode, pbwidth_t *txwidth) -{ - vfo_t vtmp; - - switch (vfo) - { - case RIG_VFO_AB: - vtmp = RIG_VFO_B; break; - - case RIG_VFO_BA: - vtmp = RIG_VFO_A; break; - - default: - return -RIG_EINVAL; - } - - return ts2k_get_mode(rig, vtmp, txmode, txwidth); -} - -/* - * status: new - */ -int ts2k_scan(RIG *rig, vfo_t vfo, scan_t scan, int ch) -{ - int retval; - vfo_t v; - - rig_debug(RIG_DEBUG_ERR, __func__": starting...\n"); - - if (vfo == RIG_VFO_CURR) - { - retval = ts2k_get_vfo(rig, &v); - CHKERR(retval); - } - else - { - v = vfo; - } - - // hopefully, this'll work. rig does nothing if already in scan! - retval = ts2k_scan_off(rig); - CHKERR(retval); - - rig_debug(RIG_DEBUG_ERR, __func__": got VFO = %x\n", v); - - // set proper vfo first (already done?) - switch (v) - { - case RIG_VFO_MEM: // Currently selected Main/Sub - case RIG_VFO_MEM_A: // Main - case RIG_VFO_MEM_C: // Sub - - // FIXME: we should set the group and fall through - /* nobreak */ -// case RIG_VFO_VFO: // Currently selected Main/Sub - case RIG_VFO_A: // Main - case RIG_VFO_B: // Main - case RIG_VFO_C: // Sub - retval = ts2k_set_vfo(rig, v); // already set? - CHKERR(retval); - break; - - case RIG_VFO_CALL_A: // - case RIG_VFO_CALL_C: - default: - rig_debug(RIG_DEBUG_ERR, __func__": vfo 'defaulted'\n"); - return -RIG_ENIMPL; // unimplemented, but valid scan - } - - rig_debug(RIG_DEBUG_ERR, __func__": VFO set!\n"); - retval = ts2k_scan_off(rig); - CHKERR(retval); - - switch (scan) - { - - case RIG_SCAN_STOP: - return ts2k_scan_off(rig); - break; - - case RIG_SCAN_PROG: - if (ch < 290) - { - return -RIG_EINVAL; - } - - retval = ts2k_set_mem(rig, vfo, ch); - CHKERR(retval); - - /* nobreak */ - case RIG_SCAN_MEM: - - /* nobreak */ - case RIG_SCAN_VFO: - return ts2k_scan_on(rig, '1'); // Look Ma, I'm scanning! - break; - - case RIG_SCAN_SLCT: - - /* nobreak */ - case RIG_SCAN_PRIO: - - /* nobreak */ - default: - rig_debug(RIG_DEBUG_ERR, __func__": scan 'defaulted'\n"); - return -RIG_ENIMPL; // unimplemented, but valid scan - } -} - -int ts2k_scan_on(RIG *rig, char sc) -{ - char cmd[] = "sc0;", ack[10]; - int retval, cmdlen, acklen, i; - - rig_debug(RIG_DEBUG_ERR, __func__": turning scan on\n"); - cmd[2] = sc; - retval = ts2k_transaction(rig, cmd, 4, NULL, NULL); - CHKERR(retval); - - rig_debug(RIG_DEBUG_ERR, __func__": turned scan on\n"); - - // force reply when turning scan on - if (sc != '0') - { - cmd[2] = ';'; cmd[3] = '\0'; - retval = ts2k_transaction(rig, cmd, 3, ack, &acklen); - CHKERR(retval); - - if (ack[2] != sc) - { - return -RIG_EINVAL; - } - } - - return RIG_OK; -} - -int ts2k_scan_off(RIG *rig) -{ - rig_debug(RIG_DEBUG_ERR, __func__": turning scan off\n"); - return ts2k_scan_on(rig, '0'); -} - - -int ts2k_get_parm(RIG *rig, setting_t parm, value_t *val) -{ - int retval, acklen, cmdlen; - char ack[30], cmd[30]; - - switch (parm) - { - case RIG_PARM_BEEP: - cmdlen = sprintf(cmd, "ex0120000;"); break; - - case RIG_PARM_BACKLIGHT: - cmdlen = sprintf(cmd, "ex0000000;"); break; - - case RIG_PARM_KEYLIGHT: - cmdlen = sprintf(cmd, "ex0010000;"); break; - - case RIG_PARM_APO: - cmdlen = sprintf(cmd, "ex0570000;"); break; - - case RIG_PARM_ANN: - return -RIG_ENIMPL; - - case RIG_PARM_TIME: - return -RIG_ENAVAIL; - - default: - return -RIG_EINTERNAL; - } - - acklen = 30; - retval = ts2k_transaction(rig, cmd, cmdlen, ack, &acklen); - - if (retval == RIG_OK) - { - switch (parm) - { - case RIG_PARM_BEEP: - val->i = (int)(ack[9] - '0'); - break; - - case RIG_PARM_BACKLIGHT: - case RIG_PARM_KEYLIGHT: - val->f = (float)(ack[9] - '0'); - break; - - case RIG_PARM_APO: - val->i = (int) int_n(cmd, &ack[9], 2); // cmd is TMP now - break; - - default: - return -RIG_EINTERNAL; - } - } - - return retval; -} - -int ts2k_set_parm(RIG *rig, setting_t parm, value_t val) -{ - char cmd[30]; - int retval, cmdlen, i; - - rig_debug(RIG_DEBUG_ERR, __func__": val.i = %u\n", val.i); - rig_debug(RIG_DEBUG_ERR, __func__": val.f = %f\n", val.f); - - switch (parm) - { - case RIG_PARM_APO: - cmdlen = sprintf(cmd, "ex0570000%01u;", - (val.i > 180) ? 3 : val.i / 60); - break; - - case RIG_PARM_BEEP: - cmdlen = sprintf(cmd, "ex0120000%01u;", (val.i > 9) ? 9 : val.i); - break; - - case RIG_PARM_BACKLIGHT: - cmdlen = sprintf(cmd, "ex0000000%01u;", - (int)((val.f > 1.0) ? 4.0 : val.f * 4.0)); - break; - - case RIG_PARM_KEYLIGHT: - cmdlen = sprintf(cmd, "ex0010000%01u;", (val.i == 0) ? 0 : 1); - break; - - case RIG_PARM_ANN: - return -RIG_ENIMPL; - - case RIG_PARM_TIME: - case RIG_PARM_BAT: - return -RIG_ENAVAIL; - - default: - return -RIG_EINTERNAL; - } - - retval = ts2k_transaction(rig, cmd, cmdlen, NULL, NULL); - - return retval; -} - -#undef CHKERR -#undef STUFF - -// End diff --git a/kenwood/ts2k.h b/kenwood/ts2k.h deleted file mode 100644 index 51386d827..000000000 --- a/kenwood/ts2k.h +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Hamlib TS2000 backend - main header - * Copyright (c) 2000-2002 by Stephane Fillod - * - * - * 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 - * - */ - -/* - * created from kenwood.h --Dale kd7eni - */ - -/*//+kd7eni*/ - -#ifndef _TS2K_H -#define _TS2K_H - -#undef _USEVFO - -// imported from ts2000.h --Dale kd7eni -/* - * 103 available DCS codes - */ -static const tone_t ts2k_dcs_list[] = { - 23, 25, 26, 31, 32, 36, 43, 47, 51, 53, 54, - 65, 71, 72, 73, 74, 114, 115, 116, 122, 125, 131, - 132, 134, 143, 145, 152, 155, 156, 162, 165, 172, 174, - 205, 212, 223, 225, 226, 243, 244, 245, 246, 251, 252, - 255, 261, 263, 265, 266, 271, 274, 306, 311, 315, 325, - 331, 332, 343, 346, 351, 356, 364, 365, 371, 411, 412, - 413, 423, 431, 432, 445, 446, 452, 454, 455, 462, 464, - 465, 466, 503, 506, 516, 523, 526, 532, 546, 565, 606, - 612, 624, 627, 631, 632, 654, 662, 664, 703, 712, 723, - 731, 732, 734, 743, 754, - 0 -}; - -#define TS2K_PTT_ON_MAIN 8 -#define TS2K_CTRL_ON_MAIN 4 -#define TS2K_PTT_ON_SUB 2 -#define TS2K_CTRL_ON_SUB 1 - -// Needed to prevent ts2k_transaction (kenwood_transaction) from -// expecting a reply from the ts2000 in cases where there is none. -#define NOREPLY 0 -// some commands reply "?;" if rig currently in requested mode -// usually, there is NOREPLY when mode is changed. This can be -// put in the acknowledge length to signify the error is no error. -#define BUGERR -1 - -//-kd7eni - -#define EOM_KEN ";" -#define EOM_TH "\r" - -struct ts2k_priv_caps { - /* read-only values */ - const char *cmdtrm; /* Command termination chars (ken=';' or th='\r') */ - /* changable values */ - // nothing -}; - -#if 0 /* No private data for Kenwood backends. */ -struct ts2k_priv_data { - int dummy; // placeholder for real entries. -}; -#endif - -extern int ts2k_init(RIG *rig); -extern int ts2k_cleanup(RIG *rig); - - -extern const int ts2k_ctcss_list[]; - -int ts2k_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, - size_t *data_len); -int ts2k_set_vfo(RIG *rig, vfo_t vfo); -int ts2k_get_vfo(RIG *rig, vfo_t *vfo); -int ts2k_set_freq(RIG *rig, vfo_t vfo, freq_t freq); -int ts2k_get_freq(RIG *rig, vfo_t vfo, freq_t *freq); -int ts2k_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width); -int ts2k_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width); -int ts2k_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val); -int ts2k_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val); -int ts2k_set_func(RIG *rig, vfo_t vfo, setting_t func, int status); -int ts2k_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status); -int ts2k_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone); -int ts2k_set_tone(RIG *rig, vfo_t vfo, tone_t tone); -int ts2k_get_ctcss_tone(RIG *rig, vfo_t vfo, tone_t *tone); -int ts2k_get_tone(RIG *rig, vfo_t vfo, tone_t *tone); -int ts2k_set_Tones(RIG *rig, vfo_t vfo, tone_t tone, const char ct); -int ts2k_get_Tones(RIG *rig, vfo_t vfo, tone_t *tone, const char *ct); -int ts2k_set_powerstat(RIG *rig, powerstat_t status); -int ts2k_get_powerstat(RIG *rig, powerstat_t *status); -int ts2k_reset(RIG *rig, reset_t reset); -int ts2k_send_morse(RIG *rig, vfo_t vfo, const char *msg); -int ts2k_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt); -int ts2k_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt); -int ts2k_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd); -int ts2k_vfo_op(RIG *rig, vfo_t vfo, vfo_op_t op); -int ts2k_set_mem(RIG *rig, vfo_t vfo, int ch); -int ts2k_get_mem(RIG *rig, vfo_t vfo, int *ch); -const char* ts2k_get_info(RIG *rig); - -int ts2k_get_trn(RIG *rig, int *trn); -int ts2k_set_trn(RIG *rig, int trn); - -/* - * functions I've written -- Dale KD7ENI - */ -int ts2k_scan(RIG *rig, vfo_t vfo, scan_t scan, int ch); -int ts2k_scan_on(RIG *rig, char ch); -int ts2k_scan_off(RIG *rig); -int ts2k_get_channel(RIG *rig, channel_t *chan); -int ts2k_set_channel(RIG *rig, const channel_t *chan); -char *ts2k_get_ctrl(RIG *rig); -int ts2k_set_ctrl(RIG *rig, int ptt, int ctrl); -int ts2k_vfo_ctrl(RIG *rig, vfo_t vfo); -int ts2k_get_dcs_code(RIG *rig, vfo_t vfo, tone_t *tone); -int ts2k_set_dcs_code(RIG *rig, vfo_t vfo, tone_t tone); -int ts2k_get_int(char *c, int i); -int ts2k_sat_off(RIG *rig, vfo_t vfo); -int ts2k_sat_on(RIG *rig, vfo_t vfo); -int ts2k_get_parm(RIG *rig, setting_t parm, value_t *val); -int ts2k_set_parm(RIG *rig, setting_t parm, value_t val); -int ts2k_get_rit(RIG *rig, vfo_t vfo, shortfreq_t *rit); -int ts2k_set_rit(RIG *rig, vfo_t vfo, shortfreq_t rit); -int ts2k_get_rptr_offs(RIG *rig, vfo_t vfo, shortfreq_t *offs); -int ts2k_set_rptr_offs(RIG *rig, vfo_t vfo, shortfreq_t offs); -int ts2k_get_rptr_shift(RIG *rig, vfo_t vfo, rptr_shift_t *shift); -int ts2k_set_rptr_shift(RIG *rig, vfo_t vfo, rptr_shift_t shift); -int ts2k_get_split(RIG *rig, vfo_t vfo, split_t *split); -int ts2k_set_split(RIG *rig, vfo_t vfo, split_t split); -int ts2k_get_split_freq(RIG *rig, vfo_t vfo, freq_t *tx_freq); -int ts2k_set_split_freq(RIG *rig, vfo_t vfo, freq_t tx_freq); -int ts2k_get_split_mode(RIG *rig, vfo_t vfo, rmode_t *txmode, pbwidth_t *txwidth); -int ts2k_set_split_mode(RIG *rig, vfo_t vfo, rmode_t txmode, pbwidth_t txwidth); -int ts2k_get_ts(RIG *rig, vfo_t vfo, shortfreq_t *ts); -int ts2k_set_ts(RIG *rig, vfo_t vfo, shortfreq_t ts); -int ts2k_get_xit(RIG *rig, vfo_t vfo, shortfreq_t *freq); -int ts2k_set_xit(RIG *rig, vfo_t vfo, shortfreq_t freq); - -/* end kd7eni functions */ - -extern const struct rig_caps thd7a_caps; -extern const struct rig_caps thf7a_caps; -extern const struct rig_caps thf7e_caps; -extern const struct rig_caps ts450s_caps; -extern const struct rig_caps ts50s_caps; -extern const struct rig_caps ts570d_caps; -extern const struct rig_caps ts570s_caps; -extern const struct rig_caps ts790_caps; -extern const struct rig_caps ts850_caps; -extern const struct rig_caps ts870s_caps; -extern const struct rig_caps ts950sdx_caps; -extern const struct rig_caps ts2000_caps; - -extern BACKEND_EXPORT(int) initrigs_ts2k(void *be_handle); -extern BACKEND_EXPORT(rig_model_t) proberigs_ts2k(port_t *port); - -#endif /* _TS2000_H */ diff --git a/kenwood/ts2k.status b/kenwood/ts2k.status deleted file mode 100644 index 8c9bc10ea..000000000 --- a/kenwood/ts2k.status +++ /dev/null @@ -1,23 +0,0 @@ -Rig: TS-2000, ts2k.c Thought this might help. --Dale kd73ni -n/i = not written, orig = original/rewritten, new = new, ok = works as written -F: ok (no limit check) orig f: ok, (vfo only) orig -M: ok orig m: ok (no vfo check) orig -V: ok (trivial only) orig v: ok (trivial only) orig -T: ok (even in CALL_C) orig t: ok orig -R: ok new r: ok (vfo only) new -O: bugs new o: ok new -C: ok (requires exact) orig c: ok orig -D: ok new d: ok new -I: broken new i: broken new -X: ok (TX only!) new x: replies new -S: ok (default only!) new s: on (not broken!) new -N: ok (default only) new n: ok new -L: ok (PREAMP at least) new l: bad new -U: bugs (VOX always on) new u: bugs orig -P: ok (BEEP 0.0 works!) new p: ok new -E: ok orig e: ok orig -G: ok (up/down at least) new g: broken new -H: n/i (rigctl too!) h: ok (needs work) new -A: ok (see a) orig a: ok (sigio remains on) orig -B: n/a _: ok (which Sea?) :) orig -2: bugs (don't understand) orig #: ok (rigctl comment) new diff --git a/kenwood/ts2k_menu.c b/kenwood/ts2k_menu.c deleted file mode 100644 index 4c3de51eb..000000000 --- a/kenwood/ts2k_menu.c +++ /dev/null @@ -1,319 +0,0 @@ -/* - * ts2k_menu.c (C) Copyright 2002 by Dale E. Edmons. All rights reserved. - */ - -/* - * License: GNU - */ - -/* - * status: Never been compiled! - */ - -/* - * Functions to initialize, read, set, and list menus - * for the TS-2000. These functions will be added to - * src/rig.c as rig_*menu_*() as time permits. - * - * This is likely a can of worms nobody has wanted to - * deal with--until now. The ts2k is especially a - * pain as you'll soon seen (but cool nonetheless.) - */ - -#include -#include "ts2k.h" -#include "ts2k_menu.h" -#include - -/* - * Set the menu number(s) and terminate with ";" (not ';') - */ -int ts2k_set_menu_no(RIG *rig, ts2k_menu_t *menu, int main, int sub) -{ - int i; - - menu->menu_no[0] = main; - menu->menu_no[1] = sub; - menu->menu_no[2] = menu->menu_no[3] = 0; - - i = sprintf(&menu->cmd[0], "ex%03u%02u%01u%01u;", main, sub, 0, 0); - - if (i != 10) - { - return -RIG_EINVAL; - } - - return RIG_OK; -} - -/* - * Get the menu number(s) from cmd[] - */ -int ts2k_get_menu_no(RIG *rig, ts2k_menu_t *menu, int *main, int *sub) -{ - char tmp[30]; - int m, s; - - if (menu == NULL) - { - return -RIG_EINVAL; - } - - m = int_n(tmp, &menu->cmd[2], 3); - s = int_n(tmp, &menu->cmd[7], 2); - - menu->menu_no[0] = m; - menu->menu_no[1] = s; - menu->menu_no[2] = menu->menu_no[3] = 0; - - if (main != NULL) - { - *main = m; - } - - if (sub != NULL) - { - *sub = s; - } - - return RIG_OK; -} - -/* - * When called by ts2k_pm_init we read all of - * the rig's current menu options and set them - * in the current menu array. We don't do the - * memory allocation so you can init as many - * as you want. The reason for this is huge. - * First, after full reset the rig can access - * menuA or menuB and different values retained. - * Second, by sending "pm...;" we can select - * Programmable Memory 0-5, with 0 being the - * the default. Amazingly, each PM seems to - * have its own menuA and menuB. Thus, all - * told, we have up to twelve distinct menus - * each with (potentially) unique values. We - * do the allocation in the PM routines and - * leave this one much simpler and just call - * it up to twelve times with uniq ts2k_menu_t - * pointers. Third, the user may wish to use - * this to obtain a private copy for local use - * and only has to call this routine to make - * sure its current. (A ts2k_pm_t should be - * allocated as well!) - */ -int ts2k_menu_init(RIG *rig, ts2k_menu_t *menu[]) -{ - int retval, i; - ts2k_menu_t *m, *mref; - - if (menu == NULL || menu == ts2k_menus) - { - rig_debug(rig, __func__": invalid menu pointer\n"); - return -RIG_EINVAL; - } - - // One set of defaults has been globally defined (mref) - for (i = 0, i < (sizeof(menu) / sizeof(ts2k_menu_t)); i++) - { - m = menu[i]; - mref = ts2k_menus[i]; - retval = ts2k_set_menu_no(rig, m, mref->menu[0], mref->menu[1]); - - if (retval != RIG_OK) - { - return retval; - } - - retval = ts2k_get_menu(rig, m); - - if (retval != RIG_OK) - { - return retval; - } - - // FIXME: set some debug traces here? - } - - return RIG_OK; -} - -/* - * read the rig and get the parameters for menu[n]. - * convert them to a ts2k_menu_t, and eventually to - * a rig_menu_t. I do a lot of checking to ensure - * nothing breaks (hi!). - */ -int ts2k_get_menu(RIG *rig, ts2k_menu_t *menu,) -{ - int retval, i, j, k, acklen; - char ack[30]; - - if (menu == NULL) - { - return -RIG_EINVAL; - } - else if ((toupper(menu->cmd[0]) != 'E') - || (toupper(menu->cmd[1]) != 'X')) - { - return -RIG_EINVAL; - } - else if (menu->cmd[9] != ';') - { - retval = -RIG_EINVAL; - } - - retval = ts2k_transaction(rig, menu->cmd, 10, ack, &acklen); - - if (retval != RIG_OK) - { - return retval; - } - - strncpy(menu->cmd, ack, 30); - retval = ts2k_menu_parse(rig, menu); - - if (retval != RIG_OK) - { - return retval; - } - - return retval; -} - -/* - * Here, I expect everything to be setup for me. - * All we do is determe the value and param_txt - * for the menu item we are given. - * - * status: real ugly! - */ -int ts2k_menu_parse(RIG *rig, ts2k_menu_t *menu) -{ - ts2k_menu_t *mref, *m; - char *vptr; - int on_off[] = { 01, 03, 04, 05, 07, 09, 17, 18, 23, 25, 26, - 27, 30, 34, 35, 36, 37, 43, 44, 52, 53, 63, 54, 55, - -1 - }, - zero2nine = - { - - m = menu; // to lazy to spell menu-> all the time - - if (m->cmd[0] == '\0' || m->cmd[1] == '\0') - { - return -RIG_EINVAL; // Caller has blown it! - } - - // find matching refence menu - i = 0; - - do - { - mref = ts2k_menus[i]; - - if (mref == NULL) // Either Caller or I blew it! - { - return -RIG_EINTERNAL; - } - - if (mref->menu_no[i] == NULL) - { - return -RIG_EINVAL; // It has to match one! - } - - if (menu == ts2k_menus[i]) // Nobody changes our REF! - { - return -RIG_EINTERNAL; - } - - if (mref->menu[0] == m->menu[0]) - && mref->menu[1] == m->menu[1] - && mref->menu[2] == m->menu[2] - /*&& mref->menu[3] == m->menu[3]*/) - { - break; - } - } - while (++i) - - /* Match the main menu and only look for sub-menus later */ - - // check for menus that are simple on/off first - // FIXME: this isn't fast, it just eliminates alot of cases! - for (i = 0; on_off == -1; i++) - { - if (m->menu[0] == m->menu[0]) - { - m->val = m->cmd[9] - '0'; - m->param_txt = (m->val == 1) ? m_on : m_off; - return RIG_OK; - } - } - - // Use mref to do all we can - retval = -RIG_EINTERNAL; - - for (i = 0; mref->param_txt != NULL; i++) - { - if (retval == RIG_OK) - { - return retval; - } - - switch (mref->param_txt[i]) - { - case m_tbd: // menu item under development! - m->param_txt = m_tbd; - vptr = malloc(17); - - if (vptr == NULL) - { - return -RIG_NOMEM; - } - - for (j = 0; vptr[i] != ';' && i < 17; i++) - { - vptr[i] == m->cmd[i]; - } - - vptr[i] = '\0'; - return -RIG_NIMPL; - - case m_off: - if (m->cmd[9] == '0') - { - m->param_txt = mref->param_txt[i]; - m->val = 0; - retval = RIG_OK; - } - - break; - - case m_num: - default: - return -RIG_NIMPL; - } - } - - switch (m->menu[0]) - { - - case 00: - case 00: - case 00: - case 00: - case 00: - case 00: - case 00: - case 00: - - default: - return -RIG_EINTERNAL; // I'm requiring 100% match - } - - return RIG_OK; - } - -// End of ts2k_menu.c diff --git a/kenwood/ts2k_menu.h b/kenwood/ts2k_menu.h deleted file mode 100644 index 95312ba6b..000000000 --- a/kenwood/ts2k_menu.h +++ /dev/null @@ -1,240 +0,0 @@ -/* - * ts2k_menu.h (C) Copyright 2002 by Dale E. Edmons. All rights reserved. - */ - -/* - * License: GNU (same as what hamlib currently is using) - */ - -/* - * status: uncompiled. Haven't finished factory defaults. - * anything with m_tbd is: to be developed - */ - -/* Header to implement menus equivalent to those on the TS-2000. */ - -// sub-menu defines -#define MENU_A 1 -#define MENU_B 2 -#define MENU_C 3 -#define MENU_D 4 -#define MENU_E 5 -#define MENU_F 6 - -// parameter value text. may be used in any menu. -const char m_on[]="On"; -const char m_off[]="Off"; -const char m_to[]="TO"; -const char m_co[]="CO"; -const char m_h_boost[]="High Boost"; -const char m_b_boost[]="Bass Boost"; -const char m_f_pass[]="F Pass"; -const char m_conven[]="Conven"; -const char m_user[]="User"; -const char m_auto[]="Auto"; -const char m_norm[]="Normal"; -const char m_inv[]="Inverse"; -const char m_low[]="Low"; -const char m_mid[]="Mid"; -const char m_hi[]="High"; -const char m_burst[]="Burst"; -const char m_cont[]="Cont"; -const char m_slow[]="Slow"; -const char m_fast[]="Fast"; -const char m_main[]="Main"; -const char m_sub[]="Sub"; -const char m_tnc_band[]="TNC Band"; -const char m_main_sub[]="Main & Sub"; -const char m_man[]="Manual"; -const char m_morse[]="Morse"; -const char m_voice[]="Voice"; -const char m_neg[]="Negative"; -const char m_pos[]="Positive"; -const char m_locked[]="Locked"; -const char m_cross[]="Cross"; -const char m_client[]="Client"; -const char m_commander[]="Commander"; -const char m_transporter[]="Transporter"; -const char m_font1[]="font1"; -const char m_font2[]="font2"; -const char m_num[8+2]; // storage for numeric constants -const char m_text[8+2]; // storage for text constants -//const char m_[]=""; - -// array valued constants (mostly) or other undefined text -const char m_tbd[]="hamlib: t.b.d."; - -// PF1 key assignments -#define KEY_MENU_MAX 62 -#define KEY_KEY_MAX 90 -#define KEY_UNASSIGNED 99 -const char key_menu[]="Menu"; // menu # 0-62 -const char key_none[]="None"; -const char key_key[][KEY_KEY_MAX-KEY_MENU_MAX] = { - "Voice1", Voice2", "Voice3", "RX Moni", "DSP Moni", - "Quick Memo MR", "Quick Memo M.IN", "Split", "TF-SET", - "A/B", "VFO/M", "A=B", "Scan", "M>VFO", "M.IN", "CW TUNE", - "CH1", "CH2", "CH3", "Fine", "CLR", "Call", "CTRL", - "1MHz", "ANT1/2", "N.B.", "N.R.", "B.C.", "A.N.", - "" -}; - -typedef struct { - const char menu_no[]; - const char txt[]; - const char *param_txt[]; - char cmd[30]; - const int menu[4]; - int val; // same as P5 -} ts2k_menu_t; - -/* - * Defaults for menu_t.val were obtained via minicom - * on my rig after doing a full reset to factory defaults. - * (unfinished) - */ - -const ts2k_menu_t ts2k_menus[] = { - { "00", "Display Brightness", {m_off, m_num, NULL}, "", {00,0,0,0}, 3}, - { "01", "Key Illumination", {m_off, m_on, NULL}, "", {01,0,0,0}, 1}, - { "02", "Tuning Control Change Per Revolution", {m_num, NULL}, "", {02,0,0,0}, 1}, - { "03", "Tune using MULTI/CH Frequency Step", {m_off, m_on, NULL}, "", {03,0,0,0}, 1}, - { "04", "Round off VFO using MULTI/CH Control", {m_off, m_on, NULL}, "", {04,0,0,0}, 1}, - { "05", "9kHz step size for MULTI/CH in AM Broadcast Band", {m_off, m_on, NULL}, "", {05,0,0,0}, 0}, - { "06A", "Mem: Memory-VFO Split", {m_off, m_on, NULL}, "", {06,1,0,0}, 0}, - { "06B", "Mem: Temporary Frequency change after Memory Recall", {m_off, m_on, NULL}, "", {06,2,0,0}, 0}, - { "07", "Program scan partially slowed", {m_off, m_on, NULL}, "", {07,0,0,0}, 0}, - { "08", "Program Slow-Scan Range", {m_num, NULL}, "", {08,0,0,0}, 0}, - { "09", "Program scan hold", {m_off, m_on, NULL}, "", {09,0,0,0}, 0}, - { "10", "Scan Resume Method", {m_to, m_co, NULL}, "", {10,0,0,0}, 0}, - { "11", "Visual Scan Range", {m_tbd, NULL}, "", {11,0,0,0}, 0}, - { "12", "Beep Volume", {m_off, m_num, NULL}, "", {12,0,0,0}, 0}, - { "13", "Sidetone Volume", {m_off, m_num, NULL}, "", {13,0,0,0}, 0}, - { "14", "Message Playback Volume", {m_off, m_num, NULL}, "", {14,0,0,0}, 0}, - { "15", "Voice Volume", {m_off, m_num, NULL}, "", {15,0,0,0}, 0}, - { "16", "Output Configuration for sp2 or headphones", {m_tbd, NULL}, "", {16,0,0,0}, 0}, - { "17", "Reversed output configuration for sp2 or headphones", {m_off, m_on, NULL}, "", {17,0,0,0}, 0}, - { "18", "RX-Dedicated antenna", {m_off, m_on, NULL}, "", {18,0,0,0}, 0}, - { "19A", "S-Meter: SQ", {m_off, m_on, NULL}, "", {19,1,0,0}, 0}, - { "19B", "S-Meter: Hang Time", {m_off, m_tbd, NULL}, "", {19,2,0,0}, 0}, - { "20", "RX Equalizer", {m_off, m_h_boost, m_b_boost, m_conven, m_user, NULL}, "", {20,0,0,0}, 0}, - { "21", "TX Equalizer", {m_off, m_h_boost, m_b_boost, m_conven, m_user, NULL}, "", {21,0,0,0}, 0}, - { "22", "TX Filter Bandwidth for SSB or AM", {m_tbd, NULL}, "", {22,0,0,0}, 0}, - { "23", "Fine Transmit power change step", {m_off, m_on, NULL}, "", {23,0,0,0}, 0}, - { "24", "Time-out Timer", {m_off, m_tbd, NULL}, "", {24,0,0,0}, 0}, - { "25", "Transverter Frequency Display", {m_off, m_on, NULL}, "", {25,0,0,0}, 0}, - { "26", "TX Hold; Antenna tuner", {m_off, m_on, NULL}, "", {26,0,0,0}, 0}, - { "27", "Antenna tuner while receiving", {m_off, m_on, NULL}, "", {27,0,0,0}, 0}, - { "28A", "Linear Amp Control Relay: HF", {m_off, m_num, NULL}, "", {28,1,0,0}, 0}, - { "28B", "Linear Amp Control Relay: 50MHz", {m_off, m_num, NULL}, "", {28,2,0,0}, 0}, - { "28C", "Linear Amp Control Relay: 144MHz", {m_off, m_num, NULL}, "", {28,3,0,0}, 0}, - { "28D", "Linear Amp Control Relay: 430MHz", {m_off, m_num, NULL}, "", {28,4,0,0}, 0}, - { "28E", "Linear Amp Control Relay: 1.2GHz", {m_off, m_num, NULL}, "", {28,5,0,0}, 0}, - { "29A", "CW Message: Playback Repeat", {m_off, m_on, NULL}, "", {29,1,0,0}, 0}, - { "29B", "CW Message: Playback Interval", {m_num, NULL}, "", {29,2,0,0}, 0}, - { "30", "Keying Priority over playback", {m_off, m_on, NULL}, "", {30,0,0,0}, 0}, - { "31", "CW RX Pitch/TX sidetone frequency", {m_tbd, NULL}, "", {31,0,0,0}, 0}, - { "32", "CW rise time", {m_tbd, NULL}, "", {32,0,0,0}, 0}, - { "33", "CW weighting", {m_auto, m_tbd, NULL}, "", {33,0,0,0}, 0}, - { "34", "Reversed CW weighting", {m_off, m_on, NULL}, "", {34,0,0,0}, 0}, - { "35", "Bug key function", {m_off, m_on, NULL}, "", {35,0,0,0}, 0}, - { "36", "Auto CW TX when keying in SSB", {m_off, m_on, NULL}, "", {36,0,0,0}, 0}, - { "37", "Frequency correction for SSB-to-CW change", {m_off, m_on, NULL}, "", {37,0,0,0}, 0}, - { "38", "FSK shift", {m_tbd, NULL}, "", {38,0,0,0}, 0}, - { "39", "FSK key-down polarity", {m_norm, m_inv, NULL}, "", {39,0,0,0}, 0}, - { "40", "FSK tone frequency", {m_tbd, NULL}, "", {40,0,0,0}, 0}, - { "41", "FM mic gain", {m_low, m_mid, m_high, NULL}, "", {41,0,0,0}, 0}, - { "42", "FM sub-tone type", {m_burst, m_cont, NULL}, "", {42,0,0,0}, 0}, - { "43", "Auto repeater offset", {m_off, m_on, NULL}, "", {43,0,0,0}, 0}, - { "44", "TX hold; 1750Hz tone", {m_off, m_on, NULL}, "", {44,0,0,0}, 0}, - { "45A", "DTMF: Memory", {m_tbd, NULL}, "", {45,1,0,0}, 0}, - { "45B", "DTMF: TX speed", {m_fast, m_slow, NULL}, "", {45,2,0,0}, 0}, - { "45C", "DTMF: Pause duration", {m_tbd, NULL}, "", {45,3,0,0}, 0}, - { "45D", "DTMF: Mic control", {m_off, m_on, NULL}, "", {45,4,0,0}, 0}, - { "46", "TNC: Main/Sub", {m_main, m_sub, NULL}, "", {46,0,0,0}, 0}, - { "47", "Data transfer rate; Built-in TNC", {m_tbd, NULL}, "", {47,0,0,0}, 0}, - { "48", "DCD sense", {m_tnc, m_main_sub, NULL}, "", {48,0,0,0}, 0}, - { "49A", "Packet Cluster: Tune", {m_auto, m_man, NULL}, "", {49,1,0,0}, 0}, - { "49B", "Packet Cluster: RX confirmation tone", {m_off, m_morse, m_voice, NULL}, "", {49,2,0,0}, 0}, - { "50A", "TNC: filter bandwidth", {m_off, m_on, NULL}, "", {50,1,0,0}, 0}, - { "50B", "TNC: AF input level", {m_tbd, NULL}, "", {50,2,0,0}, 0}, - { "50C", "TNC: Main band AF output level", {m_tbd, NULL}, "", {50,3,0,0}, 0}, - { "50D", "TNC: Sub band AF output level", {m_tbd, NULL}, "", {50,4,0,0}, 0}, - { "50E", "TNC: External", {m_main, m_sub, NULL}, "", {50,5,0,0}, 0}, - { "50F", "TNC: Ext. Data transfer rate", {m_tbd, NULL}, "", {50,6,0,0}, 0}, - { "51A", "Front panel PF key program", {key_menu, key_key, NULL}, "", {51,1,0,0}, 0}, - { "51B", "Mic key program: PF1", {key_menu, key_key, NULL}, "", {51,2,0,0}, 0}, - { "51C", "Mic key program: PF2", {key_menu, key_key, NULL}, "", {51,3,0,0}, 0}, - { "51D", "Mic key program: PF3", {key_menu, key_key, NULL}, "", {51,4,0,0}, 0}, - { "51E", "Mic key program: PF4", {key_menu, key_key, NULL}, "", {51,5,0,0}, 0}, - { "52", "Settings copy to another transceiver", {m_off, m_on, NULL}, "", {52,0,0,0}, 0}, - { "53", "Settings Copy to VFO", {m_off, m_on, NULL}, "", {53,0,0,0}, 0}, - { "54", "TX inhibit", {m_off, m_on, NULL}, "", {54,0,0,0}, 0}, - { "55", "Packet operation", {m_off, m_on, NULL}, "", {0550,0,0}, 0}, - { "56", "COM connector parameters", {m_tbd, NULL}, "", {56,0,0,0}, 0}, - { "57", "Auto power off", {m_off, m_on, NULL}, "", {57,0,0,0}, 0}, - { "58", "Detachable-panel Display font in easy operation mode", {m_font1, m_font1, NULL}, "", {58,0,0,0}, 0}, - { "59", "Panel display contrast", {m_tbd, NULL}, "", {59,0,0,0}, 0}, - { "60", "Detachable-panel display reversal", {m_tbd, NULL}, "", {60,0,0,0}, 0}, - { "61A", "Repeater mode select", {m_off, m_locked, m_cross, NULL}, "", {61,1,0,0}, 0}, - { "61B", "TX hold; repeater", {m_off, m_on, NULL}, "", {61,2,0,0}, 0}, - { "61C", "Remote Control ID code", {m_num, NULL}, "", {61,3,0,0}, 0}, - { "61D", "Remote control acknowledge", {m_off, m_on, NULL}, "", {61,4,0,0}, 0}, - { "61E", "Remote control", {m_off, m_on, NULL}, "", {61,5,0,0}, 0}, - { "62A", "Commander callsign", {m_text, NULL}, "", {62,1,0,0}, 0}, - { "62B", "Transporter callsign", {m_text, NULL}, "", {62,2,0,0}, 0}, - { "62C", "Sky Command tone frequency", {m_tbd, NULL}, "", {62,3,0,0}, 0}, - { "62D", "Sky command communication speed", {m_tbd, NULL}, "", {62,4,0,0}, 0}, - { "62E", "Transceiver define", {m_off, m_client, m_command, m_transporter, NULL}, "", {62,5,0,0}, 0}, - { NULL, NULL, NULL, {00,0,0,0}, 0} -}; - -/* - * Items related to menu structure - */ - -// Programmable memories -typedef struct { - int curr; // PM now in use - int orig; // what PM to restore on exit - int orig_menu; // orignal menu in effect - - int menu; // menuA or menuB of current PM - - // the following set which PM's are private or public - // they are set on init and enforced until exit - unsigned int pub; - unsigned int priv; -#ifdef TS2K_ENFORCE_PM -# define TS2K_PM_PUB ( (1<<2) | (1<<3) ) -# define TS2K_PM_PRIV ( (1<<0) | (1<<1) | (1<<4) | (1<<5) ) -#else -# define TS2K_PM_PUB ( (1<<0) | (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5) ) -# define TS2K_PM_PRIV (0) -#endif - -} ts2k_pm_t; - -// Implemented/coded functions -int ts2k_menu_init(RIG *rig, ts2k_menu_t *menu[]); -int ts2k_menu_close(RIG *rig, ts2k_menu_t *menu[]); -int ts2k_get_menu_no(RIG *rig, ts2k_menu_t *menu, int *main, int *sub); -int ts2k_set_menu_no(RIG *rig, ts2k_menu_t *menu, int main, int sub); - -// Unimplemented/uncoded functions -char * ts2k_list_menu_no(RIG *rig, ts2k_menu_t *menu, int main, int sub); -int ts2k_get_menu(RIG *rig, ts2k_menu_t *menu); -int ts2k_set_menu(RIG *rig, ts2k_menu_t *menu); -int ts2k_menu_parse(RIG *rig, ts2k_menu_t *menu); - -/* - * Related functions specific to this rig - */ -// Programmable memories[0, ..., 5] + menu[A, ..., B] -int ts2k_get_menu_mode(RIG *rig, ts2k_menu_t *menu, ts2k_pm_t *pm); -int ts2k_set_menu_mode(RIG *rig, ts2k_menu_t *menu, ts2k_pm_t *pm); - -int ts2k_pm_init(RIG *rig, ts2k_pm_t *pm); -int ts2k_pm_close(RIG *rig, ts2k_pm_t *pm); - -// End ts2k_menu.c diff --git a/src/amplifier.c b/src/amplifier.c index 266a06811..a6bf8fe86 100644 --- a/src/amplifier.c +++ b/src/amplifier.c @@ -655,8 +655,6 @@ int HAMLIB_API amp_get_ext_level(AMP *amp, token_t level, value_t *val) return amp->caps->get_ext_level(amp, level, val); } -#if XXREMOVEDXX -// Not referenced anywhere /** * \brief turn on/off the amplifier or standby/operate toggle * \param amp The amp handle @@ -689,7 +687,6 @@ int HAMLIB_API amp_set_powerstat(AMP *amp, powerstat_t status) return amp->caps->set_powerstat(amp, status); } -#endif int HAMLIB_API amp_get_powerstat(AMP *amp, powerstat_t *status) { diff --git a/tests/ampctl_parse.c b/tests/ampctl_parse.c index 7f970e3e5..6ac847de3 100644 --- a/tests/ampctl_parse.c +++ b/tests/ampctl_parse.c @@ -494,13 +494,13 @@ int ampctl_parse(AMP *my_amp, FILE *fin, FILE *fout, char *argv[], int argc) char arg4[MAXARGSZ + 1], *p4 = NULL; char *p5 = NULL; char *p6 = NULL; - static int last_was_ret = 1; /* cmd, internal, ampctld */ if (!(interactive && prompt && have_rl)) { if (interactive) { + static int last_was_ret = 1; if (prompt) { fprintf_flush(fout, "\nAmplifier command: "); @@ -1060,7 +1060,7 @@ int ampctl_parse(AMP *my_amp, FILE *fin, FILE *fout, char *argv[], int argc) rp_getline(pmptstr); /* Blank line entered */ - if (!(strcmp(input_line, ""))) + if (input_line && !(strcmp(input_line, ""))) { fprintf(fout, "? for help, q to quit.\n"); fflush(fout); From f7399eb8dfe915da36ba154686170da0a768b0dd Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 23:30:23 -0600 Subject: [PATCH 069/205] Fix cppcheck warnings in example.c --- tests/example.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/tests/example.c b/tests/example.c index e4275978e..9ac890029 100644 --- a/tests/example.c +++ b/tests/example.c @@ -3,7 +3,7 @@ * Edit to specify your rig model and serial port, and baud rate * before compiling. * To compile: - * gcc -L/usr/local/lib -lhamlib -o example example.c + * gcc -L/usr/local/lib -o example example.c -lhamlib * if hamlib is installed in /usr/local/... * */ @@ -21,7 +21,8 @@ int main() freq_t freq; value_t rawstrength, power, strength; float s_meter, rig_raw2val(); - int status, retcode, isz, mwpower; + int status, retcode; + unsigned int mwpower; rmode_t mode; pbwidth_t width; @@ -41,6 +42,13 @@ int main() /* Open my rig */ retcode = rig_open(my_rig); + if (retcode != RIG_OK) + { + rig_debug(RIG_DEBUG_ERR, "%s: rig_open failed %s\n", __func__, + rigerror(retcode)); + return 1; + } + /* Give me ID info, e.g., firmware version. */ info_buf = (char *)rig_get_info(my_rig); @@ -100,24 +108,28 @@ int main() break; /* there are more possibilities! */ } - printf("Current mode = 0x%X = %s, width = %d\n", mode, mm, width); + printf("Current mode = 0x%lX = %s, width = %ld\n", mode, mm, width); /* rig power output */ status = rig_get_level(my_rig, RIG_VFO_CURR, RIG_LEVEL_RFPOWER, &power); + if (status != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s: error rig_get_level: %s\n", __func__, rigerror(status)); } + printf("RF Power relative setting = %.3f (0.0 - 1.0)\n", power.f); /* Convert power reading to watts */ status = rig_power2mW(my_rig, &mwpower, power.f, freq, mode); + if (status != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s: error rig_get_level: %s\n", __func__, rigerror(status)); } + printf("RF Power calibrated = %.1f Watts\n", mwpower / 1000.); /* Raw and calibrated S-meter values */ status = rig_get_level(my_rig, RIG_VFO_CURR, RIG_LEVEL_RAWSTR, &rawstrength); - printf("Raw receive strength = %d\n", rawstrength.i); + if (status != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s: error rig_get_level: %s\n", __func__, rigerror(status)); } - isz = my_rig->caps->str_cal.size; + printf("Raw receive strength = %d\n", rawstrength.i); s_meter = rig_raw2val(rawstrength.i, &my_rig->caps->str_cal); @@ -126,5 +138,7 @@ int main() /* now try using RIG_LEVEL_STRENGTH itself */ status = rig_get_strength(my_rig, RIG_VFO_CURR, &strength); + if (status != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s: error rig_get_level: %s\n", __func__, rigerror(status)); } + printf("LEVEL_STRENGTH returns %d\n", strength.i); }; From e56db8c985362ca298390da0ddc444456875f95a Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 23:33:51 -0600 Subject: [PATCH 070/205] Fix cppcheck warnings in rigctl.c --- tests/rigctl.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/rigctl.c b/tests/rigctl.c index 42d804938..b2f892a6f 100644 --- a/tests/rigctl.c +++ b/tests/rigctl.c @@ -151,7 +151,7 @@ int main(int argc, char *argv[]) int serial_rate = 0; char *civaddr = NULL; /* NULL means no need to set conf */ char conf_parms[MAXCONFLEN] = ""; - int interactive = 1; /* if no cmd on command line, switch to interactive */ + int interactive; /* if no cmd on command line, switch to interactive */ int prompt = 1; /* Print prompt in rigctl */ int vfo_mode = 0; /* vfo_mode = 0 means target VFO is 'currVFO' */ char send_cmd_term = '\r'; /* send_cmd termination char */ @@ -432,6 +432,9 @@ int main(int argc, char *argv[]) { interactive = 0; } + else { + interactive = 1; + } my_rig = rig_init(my_model); From 2d94431848761ad14f865b61263dc8f8c549a39d Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 23:37:46 -0600 Subject: [PATCH 071/205] Fix cppcheck warnings in rigctl_parse.c --- tests/rigctl_parse.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/tests/rigctl_parse.c b/tests/rigctl_parse.c index d0748d37b..766ba7dbd 100644 --- a/tests/rigctl_parse.c +++ b/tests/rigctl_parse.c @@ -470,11 +470,9 @@ static char parse_arg(const char *arg) */ static int scanfc(FILE *fin, const char *format, void *p) { - int ret; - do { - ret = fscanf(fin, format, p); + int ret = fscanf(fin, format, p); if (ret < 0) { @@ -610,12 +608,12 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc, char arg1[MAXARGSZ + 1], *p1 = NULL; char arg2[MAXARGSZ + 1], *p2 = NULL; char arg3[MAXARGSZ + 1], *p3 = NULL; - static int last_was_ret = 1; vfo_t vfo = RIG_VFO_CURR; /* cmd, internal, rigctld */ if (!(interactive && prompt && have_rl)) { + static int last_was_ret = 1; if (interactive) { if (prompt) @@ -1270,7 +1268,7 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc, rp_getline(pmptstr); /* Blank line entered */ - if (!(strcmp(input_line, ""))) + if (input_line && !(strcmp(input_line, ""))) { fprintf(fout, "? for help, q to quit.\n"); fflush(fout); @@ -1637,7 +1635,7 @@ void version() void usage_rig(FILE *fout) { - int i, nbspaces; + int i; fprintf(fout, "Commands (some may not be available for this rig):\n"); @@ -1648,7 +1646,7 @@ void usage_rig(FILE *fout) isprint(test_list[i].cmd) ? test_list[i].cmd : '?', test_list[i].name); - nbspaces = 18; + int nbspaces = 18; if (test_list[i].arg1 && (test_list[i].flags & ARG_IN1)) { @@ -1793,15 +1791,14 @@ void list_models() int set_conf(RIG *my_rig, char *conf_parms) { - char *p, *q, *n; - int ret; + char *p, *n; p = conf_parms; while (p && *p != '\0') { /* FIXME: left hand value of = cannot be null */ - q = strchr(p, '='); + char *q = strchr(p, '='); if (!q) { @@ -1816,7 +1813,7 @@ int set_conf(RIG *my_rig, char *conf_parms) *n++ = '\0'; } - ret = rig_set_conf(my_rig, rig_token_lookup(my_rig, p), q); + int ret = rig_set_conf(my_rig, rig_token_lookup(my_rig, p), q); if (ret != RIG_OK) { From 0207b45ff88b39268193302149c921a7fde81ce1 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 23:39:56 -0600 Subject: [PATCH 072/205] Fix cppcheck warnings in rigctlcom.c --- tests/rigctlcom.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/rigctlcom.c b/tests/rigctlcom.c index 13ea4ae28..3583333d8 100644 --- a/tests/rigctlcom.c +++ b/tests/rigctlcom.c @@ -1407,14 +1407,14 @@ static int handle_ts2000(void *arg) { freq_t freq; - sscanf(arg + 2, "%"SCNfreq, &freq); + sscanf((char*)arg + 2, "%"SCNfreq, &freq); return rig_set_freq(my_rig, RIG_VFO_A, freq); } else if (strncmp(arg, "FB0", 3) == 0) { freq_t freq; - sscanf(arg + 2, "%"SCNfreq, &freq); + sscanf((char*)arg + 2, "%"SCNfreq, &freq); return rig_set_freq(my_rig, RIG_VFO_A, freq); } else if (strncmp(arg, "MD", 2) == 0) @@ -1422,7 +1422,7 @@ static int handle_ts2000(void *arg) mode_t mode = 0; int imode = 0; - sscanf(arg + 2, "%d", &imode); + sscanf((char*)arg + 2, "%d", &imode); switch (imode) { From ddd5c43a71b0c7b5c43dd346def39791d49c5b3d Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 23:42:32 -0600 Subject: [PATCH 073/205] Fix cppcheck warnings in rigmem.c --- tests/rigmem.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/rigmem.c b/tests/rigmem.c index 981979043..5c26646ca 100644 --- a/tests/rigmem.c +++ b/tests/rigmem.c @@ -421,15 +421,14 @@ void usage() int set_conf(RIG *rig, char *conf_parms) { - char *p, *q, *n; - int ret; + char *p, *n; p = conf_parms; while (p && *p != '\0') { /* FIXME: left hand value of = cannot be null */ - q = strchr(p, '='); + char *q = strchr(p, '='); if (!q) { @@ -444,7 +443,7 @@ int set_conf(RIG *rig, char *conf_parms) *n++ = '\0'; } - ret = rig_set_conf(rig, rig_token_lookup(rig, p), q); + int ret = rig_set_conf(rig, rig_token_lookup(rig, p), q); if (ret != RIG_OK) { @@ -473,7 +472,7 @@ int clear_chans(RIG *rig, const char *infilename) chan.tx_mode = RIG_MODE_NONE; chan.vfo = RIG_VFO_MEM; - for (i = 0; rig->state.chan_list[i].type && i < CHANLSTSIZ; i++) + for (i = 0; rig->state.chan_list[i].type; i++) { for (j = rig->state.chan_list[i].startc; j <= rig->state.chan_list[i].endc; j++) From 646900862b74f9460c4fa9bfa40acd272b67b970 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 23:42:47 -0600 Subject: [PATCH 074/205] Fix cppcheck warnings in dumpmem.c --- tests/dumpmem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/dumpmem.c b/tests/dumpmem.c index 76791cbbe..57d09811f 100644 --- a/tests/dumpmem.c +++ b/tests/dumpmem.c @@ -86,7 +86,7 @@ int main(int argc, char *argv[]) * } */ - for (i = 0; my_rig->state.chan_list[i].type && i < CHANLSTSIZ; i++) + for (i = 0; my_rig->state.chan_list[i].type; i++) { for (j = my_rig->state.chan_list[i].startc; j <= my_rig->state.chan_list[i].endc; j++) From 8e0ddf743c6bdc5bb37f33b17984867e26758255 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 8 Dec 2019 23:43:01 -0600 Subject: [PATCH 075/205] Fix cppcheck warnings in ampctl_parse.c --- tests/ampctl_parse.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/ampctl_parse.c b/tests/ampctl_parse.c index 6ac847de3..4c63a593d 100644 --- a/tests/ampctl_parse.c +++ b/tests/ampctl_parse.c @@ -347,11 +347,9 @@ char parse_arg(const char *arg) */ static int scanfc(FILE *fin, const char *format, void *p) { - int ret; - do { - ret = fscanf(fin, format, p); + int ret = fscanf(fin, format, p); if (ret < 0) { From fb73e5abd7b8f980f62a31db0eac495f274fbf35 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Mon, 9 Dec 2019 17:12:13 -0600 Subject: [PATCH 076/205] Fix some cppcheck warnings Fix declarations after statements Remove some !rig checks...we either don't need them or need them everywhere with a new error code If you pass a NULL rig you get what you deserve :-) --- amplifiers/elecraft/kpa.c | 85 +++-- aor/aor.c | 8 +- aor/ar3030.c | 2 +- aor/ar7030p.c | 16 +- aor/sr2200.c | 5 +- barrett/barrett.c | 49 +-- dorji/dra818.c | 9 +- dummy/flrig.c | 200 ++++++----- dummy/netrigctl.c | 94 +++--- dummy/trxmanager.c | 168 +++++----- elad/elad.c | 618 ++++++++++------------------------ elad/fdm_duo.c | 3 +- icmarine/icmarine.c | 7 +- icom/optoscan.c | 6 +- ioptron/rot_ioptron.c | 2 +- jrc/jrc.c | 11 +- kenwood/elecraft.c | 46 +-- kenwood/flex.c | 19 +- kenwood/flex6xxx.c | 28 +- kenwood/k2.c | 86 +++-- kenwood/k3.c | 179 +++------- kenwood/kenwood.c | 677 ++++++++++++++------------------------ kenwood/pihpsdr.c | 63 ++-- kenwood/th.c | 18 +- kenwood/thd72.c | 25 +- kenwood/thd74.c | 11 +- kenwood/thg71.c | 3 +- kenwood/ts2000.c | 43 ++- kenwood/ts480.c | 3 +- kenwood/ts570.c | 3 +- kenwood/ts590.c | 9 +- kenwood/xg3.c | 122 +++---- kit/rs_hfiq.c | 8 +- kit/si570avrusb.c | 4 +- m2/rc2800.c | 4 +- meade/meade.c | 5 +- prosistel/prosistel.c | 3 +- rs/gp2000.c | 22 +- src/cm108.c | 30 +- src/debug.c | 5 +- src/gpio.c | 3 +- src/iofunc.c | 12 +- src/mem.c | 6 +- src/microham.c | 17 +- src/network.c | 2 +- src/parallel.c | 38 ++- src/rig.c | 15 +- src/rotator.c | 3 +- src/usb_port.c | 3 +- tentec/jupiter.c | 21 +- tentec/omnivii.c | 10 +- tentec/orion.c | 6 +- tentec/rx331.c | 2 +- tests/ampctl.c | 3 +- tests/ampctl_parse.c | 10 +- tests/ampctld.c | 4 +- tests/memcsv.c | 6 +- tests/rigctl.c | 6 +- tests/rigctl_parse.c | 14 +- tests/rigctlcom.c | 97 +++--- tests/rigctld.c | 9 +- tests/rigmem.c | 4 +- tests/rotctl.c | 3 +- tests/rotctl_parse.c | 13 +- tests/rotctld.c | 4 +- yaesu/ft1000d.c | 3 +- yaesu/ft817.c | 3 +- yaesu/ft891.c | 3 +- yaesu/ft900.c | 4 +- yaesu/ft991.c | 4 +- yaesu/newcat.c | 98 +----- 71 files changed, 1306 insertions(+), 1819 deletions(-) diff --git a/amplifiers/elecraft/kpa.c b/amplifiers/elecraft/kpa.c index 73591f706..e21ab813c 100644 --- a/amplifiers/elecraft/kpa.c +++ b/amplifiers/elecraft/kpa.c @@ -100,6 +100,7 @@ int kpa_transaction(AMP *amp, const char *cmd, char *response, int response_len) int err; int len = 0; char responsebuf[KPABUFSZ]; + int loop; rig_debug(RIG_DEBUG_VERBOSE, "%s called, cmd=%s\n", __func__, cmd); @@ -109,12 +110,12 @@ int kpa_transaction(AMP *amp, const char *cmd, char *response, int response_len) rs = &->state; - int loop = 3; + loop = 3; do // wake up the amp by sending ; until we receive ; { - rig_debug(RIG_DEBUG_VERBOSE, "%s waiting for ;\n", __func__); char c = ';'; + rig_debug(RIG_DEBUG_VERBOSE, "%s waiting for ;\n", __func__); err = write_block(&rs->ampport, &c, 1); if (err != RIG_OK) { return err; } @@ -132,8 +133,9 @@ int kpa_transaction(AMP *amp, const char *cmd, char *response, int response_len) if (response) // if response expected get it { + int len; responsebuf[0] = 0; - int len = read_string(&rs->ampport, responsebuf, KPABUFSZ, ";", 1); + len = read_string(&rs->ampport, responsebuf, KPABUFSZ, ";", 1); if (len < 0) { @@ -151,13 +153,14 @@ int kpa_transaction(AMP *amp, const char *cmd, char *response, int response_len) do { - rig_debug(RIG_DEBUG_VERBOSE, "%s waiting for ;\n", __func__); + int len; char c = ';'; + rig_debug(RIG_DEBUG_VERBOSE, "%s waiting for ;\n", __func__); err = write_block(&rs->ampport, &c, 1); if (err != RIG_OK) { return err; } - int len = read_string(&rs->ampport, responsebuf, KPABUFSZ, ";", 1); + len = read_string(&rs->ampport, responsebuf, KPABUFSZ, ";", 1); if (len < 0) { return len; } } @@ -187,17 +190,19 @@ const char *kpa_get_info(AMP *amp) int kpa_get_freq(AMP *amp, freq_t *freq) { char responsebuf[KPABUFSZ]; + int retval; + unsigned long tfreq; + int nargs; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); if (!amp) { return -RIG_EINVAL; } - int retval = kpa_transaction(amp, "^FR;", responsebuf, sizeof(responsebuf)); + retval = kpa_transaction(amp, "^FR;", responsebuf, sizeof(responsebuf)); if (retval != RIG_OK) { return retval; } - unsigned long tfreq; - int nargs = sscanf(responsebuf, "^FR%lu", &tfreq); + nargs = sscanf(responsebuf, "^FR%lu", &tfreq); if (nargs != 1) { @@ -213,19 +218,21 @@ int kpa_get_freq(AMP *amp, freq_t *freq) int kpa_set_freq(AMP *amp, freq_t freq) { char responsebuf[KPABUFSZ]; + int retval; + unsigned long tfreq; + int nargs; + char cmd[KPABUFSZ]; rig_debug(RIG_DEBUG_VERBOSE, "%s called, freq=%"PRIfreq"\n", __func__, freq); if (!amp) { return -RIG_EINVAL; } - char cmd[KPABUFSZ]; sprintf(cmd, "^FR%05ld;", (long)freq / 1000); - int retval = kpa_transaction(amp, cmd, NULL, 0); + retval = kpa_transaction(amp, cmd, NULL, 0); if (retval != RIG_OK) { return retval; } - unsigned long tfreq; - int nargs = sscanf(responsebuf, "^FR%lu", &tfreq); + nargs = sscanf(responsebuf, "^FR%lu", &tfreq); if (nargs != 1) { @@ -249,6 +256,20 @@ int kpa_get_level(AMP *amp, setting_t level, value_t *val) { char responsebuf[KPABUFSZ]; char *cmd; + int retval; + int fault; + int i; + int nargs; + int antenna; + int pwrpeak; + int pwrref; + int pwrfwd; + int pwrinput; + float float_value = 0; + int int_value = 0, int_value2 = 0; + struct amp_state *rs = &->state; + struct kpa_priv_data *priv = amp->state.priv; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -256,12 +277,12 @@ int kpa_get_level(AMP *amp, setting_t level, value_t *val) // get the current antenna selected cmd = "^AE;"; - int retval = kpa_transaction(amp, cmd, responsebuf, sizeof(responsebuf)); + retval = kpa_transaction(amp, cmd, responsebuf, sizeof(responsebuf)); if (retval != RIG_OK) { return retval; } - int antenna = 0; - int nargs = sscanf(responsebuf, "^AE%d", &antenna); + antenna = 0; + nargs = sscanf(responsebuf, "^AE%d", &antenna); if (nargs != 1) { @@ -312,10 +333,6 @@ int kpa_get_level(AMP *amp, setting_t level, value_t *val) if (retval != RIG_OK) { return retval; } - float float_value = 0; - int int_value = 0, int_value2 = 0; - struct amp_state *rs = &->state; - switch (level) { case AMP_LEVEL_SWR: @@ -381,7 +398,6 @@ int kpa_get_level(AMP *amp, setting_t level, value_t *val) case AMP_LEVEL_PWR_INPUT: cmd = "^PWI;"; - int pwrinput; nargs = sscanf(responsebuf, "^SW%d", &pwrinput); if (nargs != 1) @@ -398,7 +414,6 @@ int kpa_get_level(AMP *amp, setting_t level, value_t *val) case AMP_LEVEL_PWR_FWD: cmd = "^PWF;"; - int pwrfwd; nargs = sscanf(responsebuf, "^SW%d", &pwrfwd); if (nargs != 1) @@ -415,7 +430,6 @@ int kpa_get_level(AMP *amp, setting_t level, value_t *val) case AMP_LEVEL_PWR_REFLECTED: cmd = "^PWR;"; - int pwrref; nargs = sscanf(responsebuf, "^SW%d", &pwrref); if (nargs != 1) @@ -432,7 +446,6 @@ int kpa_get_level(AMP *amp, setting_t level, value_t *val) case AMP_LEVEL_PWR_PEAK: cmd = "^PWK;"; - int pwrpeak; nargs = sscanf(responsebuf, "^SW%d", &pwrpeak); if (nargs != 1) @@ -449,7 +462,6 @@ int kpa_get_level(AMP *amp, setting_t level, value_t *val) case AMP_LEVEL_FAULT: cmd = "^SF;"; - int fault; nargs = sscanf(responsebuf, "^SW%d", &fault); if (nargs != 1) @@ -459,8 +471,6 @@ int kpa_get_level(AMP *amp, setting_t level, value_t *val) return -RIG_EPROTO; } - int i; - for (i = 0; kpa_fault_list[i].errmsg != NULL; ++i) { if (kpa_fault_list[i].code == fault) @@ -471,7 +481,6 @@ int kpa_get_level(AMP *amp, setting_t level, value_t *val) } rig_debug(RIG_DEBUG_ERR, "%s unknown fault from %s\n", __func__, responsebuf); - struct kpa_priv_data *priv = amp->state.priv; sprintf(priv->tmpbuf, "Unknown fault code=0x%02x", fault); val->s = priv->tmpbuf; return RIG_OK; @@ -490,6 +499,11 @@ int kpa_get_level(AMP *amp, setting_t level, value_t *val) int kpa_get_powerstat(AMP *amp, powerstat_t *status) { char responsebuf[KPABUFSZ]; + int retval; + int operate; + int ampon; + int nargs = sscanf(responsebuf, "^ON%d", &on); + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -497,13 +511,10 @@ int kpa_get_powerstat(AMP *amp, powerstat_t *status) if (!amp) { return -RIG_EINVAL; } - int retval = kpa_transaction(amp, "^ON;", responsebuf, sizeof(responsebuf)); + retval = kpa_transaction(amp, "^ON;", responsebuf, sizeof(responsebuf)); if (retval != RIG_OK) { return retval; } - int ampon; - int nargs = sscanf(responsebuf, "^ON%d", &on); - if (nargs != 1) { rig_debug(RIG_DEBUG_VERBOSE, "%s Error: ^ON response='%s'\n", __func__, @@ -527,7 +538,6 @@ int kpa_get_powerstat(AMP *amp, powerstat_t *status) if (retval != RIG_OK) { return retval; } - int operate; nargs = sscanf(responsebuf, "^ON%d", &operate); if (nargs != 1) @@ -544,12 +554,13 @@ int kpa_get_powerstat(AMP *amp, powerstat_t *status) int kpa_set_powerstat(AMP *amp, powerstat_t status) { + int retval; + char *cmd = NULL; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); if (!amp) { return -RIG_EINVAL; } - char *cmd = NULL; - switch (status) { case RIG_POWER_UNKNOWN: break; @@ -568,7 +579,7 @@ int kpa_set_powerstat(AMP *amp, powerstat_t status) } - int retval = kpa_transaction(amp, cmd, NULL, 0); + retval = kpa_transaction(amp, cmd, NULL, 0); if (retval != RIG_OK) { return retval; } @@ -577,10 +588,12 @@ int kpa_set_powerstat(AMP *amp, powerstat_t status) int kpa_reset(AMP *amp, amp_reset_t reset) { + int retval; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); // toggling from standby to operate supposed to reset - int retval = kpa_set_powerstat(amp, RIG_POWER_STANDBY); + retval = kpa_set_powerstat(amp, RIG_POWER_STANDBY); if (retval != RIG_OK) { diff --git a/aor/aor.c b/aor/aor.c index 3d62d2320..c509d54e9 100644 --- a/aor/aor.c +++ b/aor/aor.c @@ -1143,6 +1143,7 @@ static int parse_chan_line(RIG *rig, channel_t *chan, char *basep, /* mode and width */ if (mem_caps->mode && mem_caps->width) { + int retval; char *tag2p; tagp = strstr(basep, "MD"); @@ -1161,7 +1162,7 @@ static int parse_chan_line(RIG *rig, channel_t *chan, char *basep, tag2p = tagp; } - int retval = priv->parse_aor_mode(rig, tagp[2], tag2p[2], &chan->mode, + retval = priv->parse_aor_mode(rig, tagp[2], tag2p[2], &chan->mode, &chan->width); if (retval != RIG_OK) @@ -1254,6 +1255,8 @@ int aor_get_channel(RIG *rig, channel_t *chan) } else { + int mem_num; + char bank_base; /* * find mem_caps in caps, we'll need it later @@ -1280,8 +1283,7 @@ int aor_get_channel(RIG *rig, channel_t *chan) * MW should be called the first time instead, * and sizing memorized. */ - int mem_num = channel_num % 100; - char bank_base; + mem_num = channel_num % 100; if (mem_num >= 50 && priv->bank_base1 != priv->bank_base2) { bank_base = priv->bank_base2; diff --git a/aor/ar3030.c b/aor/ar3030.c index b89a148cc..bc03c253c 100644 --- a/aor/ar3030.c +++ b/aor/ar3030.c @@ -402,6 +402,7 @@ int ar3030_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) char *rfp; int freq_len, retval; char freqbuf[BUFSZ]; + long lfreq; /* * D Rn Gn Bn Tn Fnnnnnnnn C @@ -422,7 +423,6 @@ int ar3030_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) return -RIG_EPROTO; } - long lfreq; sscanf(rfp + 1, "%ld", &lfreq); *freq = lfreq; rig_debug(RIG_DEBUG_ERR, "%s: read lfreq=%ld, freq=%.6f\n", __func__, lfreq, diff --git a/aor/ar7030p.c b/aor/ar7030p.c index a46ed98e7..0cc715fa8 100644 --- a/aor/ar7030p.c +++ b/aor/ar7030p.c @@ -268,6 +268,8 @@ static int ar7030p_init(RIG *rig) } else { + int i; + rig->state.priv = (void *) priv; rig->state.rigport.type.rig = RIG_PORT_SERIAL; @@ -279,8 +281,6 @@ static int ar7030p_init(RIG *rig) memset(priv->mem, 0, sizeof(priv->mem)); - int i; - for (i = 0; i < NB_CHAN; i++) { priv->mem[ i ].channel_num = i; @@ -377,11 +377,11 @@ static int ar7030p_open(RIG *rig) if (RIG_OK == rc) { + int i; + /* Load calibration table */ rig->state.str_cal.size = rig->caps->str_cal.size; - int i; - for (i = 0; i < rig->state.str_cal.size; i++) { rc = readByte(rig, EEPROM1, SM_CAL + i, &v); @@ -603,11 +603,11 @@ static int ar7030p_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, } else { + int i; + /* TODO - get filter BWs at startup */ ar_filter = (unsigned char) 6; - int i; - for (i = 1; i <= 6; i++) { if (width <= filterTab[ i ]) @@ -1632,6 +1632,8 @@ static int ar7030p_get_channel(RIG *rig, channel_t *chan) if (RIG_OK == rc) { + int i; + /* Squelch values */ /* TODO - fix magic numbers */ if (100 > ch) @@ -1704,8 +1706,6 @@ static int ar7030p_get_channel(RIG *rig, channel_t *chan) /* Memory ID values */ p = (unsigned char *) chan->channel_desc; - int i; - for (i = 0; i < 14; i++) { if (176 > ch) diff --git a/aor/sr2200.c b/aor/sr2200.c index 1312c1798..f08586647 100644 --- a/aor/sr2200.c +++ b/aor/sr2200.c @@ -343,6 +343,7 @@ int sr2200_set_freq(RIG *rig, vfo_t vfo, freq_t freq) { char freqbuf[BUFSZ], ackbuf[BUFSZ], *rfp; int freq_len, ret_freq_len; + int retval; ret_freq_len = BUFSZ; @@ -367,7 +368,7 @@ int sr2200_set_freq(RIG *rig, vfo_t vfo, freq_t freq) strcpy(freqbuf + freq_len, EOM); freq_len += strlen(EOM); - int retval = sr2200_transaction(rig, freqbuf, freq_len, ackbuf, &ret_freq_len); + retval = sr2200_transaction(rig, freqbuf, freq_len, ackbuf, &ret_freq_len); if (retval != RIG_OK) { @@ -728,6 +729,7 @@ int sr2200_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) switch (level) { + float tmp; case RIG_LEVEL_STRENGTH: if (ack_len < 7 || ackbuf[0] != 'L' || ackbuf[1] != 'B') { @@ -802,7 +804,6 @@ int sr2200_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) return -RIG_EPROTO; } - float tmp; sscanf(ackbuf + 2, "%f", &tmp); if (tmp != 0.0) diff --git a/barrett/barrett.c b/barrett/barrett.c index a8f773eb0..a0c39c145 100644 --- a/barrett/barrett.c +++ b/barrett/barrett.c @@ -221,11 +221,14 @@ int barrett_transaction(RIG *rig, char *cmd, int expected, char **result) { char cmd_buf[MAXCMDLEN]; int retval, cmd_len; - - rig_debug(RIG_DEBUG_VERBOSE, "%s: cmd=%s\n", __func__, cmd); + char *p; + char xon; + char xoff; struct rig_state *rs = &rig->state; struct barrett_priv_data *priv = rig->state.priv; + rig_debug(RIG_DEBUG_VERBOSE, "%s: cmd=%s\n", __func__, cmd); + cmd_len = snprintf(cmd_buf, sizeof(cmd_buf), "%s%s", cmd, EOM); serial_flush(&rs->rigport); @@ -261,9 +264,9 @@ int barrett_transaction(RIG *rig, char *cmd, int expected, char **result) rig_debug(RIG_DEBUG_VERBOSE, "%s: retval=%d\n", __func__, retval); dump_hex((const unsigned char *)priv->ret_data, strlen(priv->ret_data)); - char *p = priv->ret_data; - char xon = p[0]; - char xoff = p[strlen(p) - 1]; + p = priv->ret_data; + xon = p[0]; + xoff = p[strlen(p) - 1]; if (xon == 0x13 && xoff == 0x11) { @@ -288,6 +291,8 @@ int barrett_transaction(RIG *rig, char *cmd, int expected, char **result) if (result != NULL) { + int n = 0; + rig_debug(RIG_DEBUG_VERBOSE, "%s: setting result\n", __func__); if (priv->ret_data[0] == 0x13) // we'll return from the 1st good char @@ -300,8 +305,6 @@ int barrett_transaction(RIG *rig, char *cmd, int expected, char **result) } // See how many CR's we have - int n = 0; - for (p = *result; *p; ++p) { if (*p == 0x0d) @@ -332,6 +335,7 @@ int barrett_transaction(RIG *rig, char *cmd, int expected, char **result) int barrett_init(RIG *rig) { + struct barrett_priv_data *priv = (struct barrett_priv_data *)calloc(1, sizeof(struct barrett_priv_data)); rig_debug(RIG_DEBUG_VERBOSE, "%s version %s\n", __func__, rig->caps->version); @@ -340,7 +344,6 @@ int barrett_init(RIG *rig) return -RIG_EINVAL; } - struct barrett_priv_data *priv = (struct barrett_priv_data *)calloc(1, sizeof(struct barrett_priv_data)); if (!priv) { @@ -386,12 +389,11 @@ int barrett_cleanup(RIG *rig) int barrett_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) { int retval; + char *response = NULL; rig_debug(RIG_DEBUG_VERBOSE, "%s: vfo=%s\n", __func__, rig_strvfo(vfo)); *freq = 0; - char *response = NULL; - if (vfo == RIG_VFO_B) // We treat the TX VFO as VFO_B and RX VFO as VFO_A { retval = barrett_transaction(rig, "IT", 0, &response); @@ -435,8 +437,8 @@ int barrett_set_freq(RIG *rig, vfo_t vfo, freq_t freq) // If we are not explicity asking for VFO_B then we'll set the receive side also if (vfo != RIG_VFO_B) { - sprintf((char *) cmd_buf, "TR%08.0f", freq); char *response = NULL; + sprintf((char *) cmd_buf, "TR%08.0f", freq); retval = barrett_transaction(rig, cmd_buf, 0, &response); if (retval < 0) @@ -457,8 +459,8 @@ int barrett_set_freq(RIG *rig, vfo_t vfo, freq_t freq) || vfo == RIG_VFO_B) // if we aren't in split mode we have to set the TX VFO too { - sprintf((char *) cmd_buf, "TT%08.0f", freq); char *response = NULL; + sprintf((char *) cmd_buf, "TT%08.0f", freq); retval = barrett_transaction(rig, cmd_buf, 0, &response); if (retval < 0) @@ -485,6 +487,7 @@ int barrett_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) { int retval; char cmd_buf[MAXCMDLEN]; + char *response; rig_debug(RIG_DEBUG_VERBOSE, "%s: ptt=%d\n", __func__, ptt); @@ -493,7 +496,7 @@ int barrett_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) // WSJT-X is just a little faster without the network timing usleep(100 * 1000); sprintf(cmd_buf, "XP%d", ptt); - char *response = NULL; + response = NULL; retval = barrett_transaction(rig, cmd_buf, 0, &response); if (retval < 0) @@ -522,6 +525,7 @@ int barrett_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt) { int retval; char *response = NULL; + char c; rig_debug(RIG_DEBUG_VERBOSE, "%s: vfo=%s\n", __func__, rig_strvfo(vfo)); @@ -533,7 +537,7 @@ int barrett_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt) return retval; } - char c = response[0]; + c = response[0]; if (c == '1' || c == '0') { @@ -612,10 +616,12 @@ int barrett_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) */ int barrett_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) { + char *result=NULL; + int retval; + rig_debug(RIG_DEBUG_VERBOSE, "%s: vfo=%s\n", __func__, rig_strvfo(vfo)); - char *result = NULL; - int retval = barrett_transaction(rig, "IB", 0, &result); + retval = barrett_transaction(rig, "IB", 0, &result); if (retval != RIG_OK) { @@ -686,13 +692,14 @@ int barrett_set_split_freq(RIG *rig, vfo_t vfo, freq_t tx_freq) { // The 2050 only has one RX and one TX VFO -- it's not treated as VFOA/VFOB char cmd_buf[MAXCMDLEN]; + int retval; rig_debug(RIG_DEBUG_VERBOSE, "%s: vfo=%s freq=%g\n", __func__, rig_strvfo(vfo), tx_freq); sprintf((char *) cmd_buf, "TT%08.0f" EOM, tx_freq); - int retval = barrett_transaction(rig, cmd_buf, 0, NULL); + retval = barrett_transaction(rig, cmd_buf, 0, NULL); if (retval < 0) { @@ -742,6 +749,8 @@ int barrett_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) switch (level) { + int strength; + int n; case RIG_LEVEL_STRENGTH: retval = barrett_transaction(rig, "IAL", 0, &response); @@ -752,8 +761,7 @@ int barrett_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) return retval; } - int strength; - int n = sscanf(response, "%2d", &strength); + n = sscanf(response, "%2d", &strength); if (n == 1) { @@ -787,10 +795,11 @@ int barrett_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) const char *barrett_get_info(RIG *rig) { char *response = NULL; + int retval; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - int retval = barrett_transaction(rig, "IVF", 0, &response); + retval = barrett_transaction(rig, "IVF", 0, &response); if (retval == RIG_OK) { diff --git a/dorji/dra818.c b/dorji/dra818.c index 11f67c6fe..f7f479243 100644 --- a/dorji/dra818.c +++ b/dorji/dra818.c @@ -137,10 +137,10 @@ static int dra818_setvolume(RIG *rig) int dra818_init(RIG *rig) { - rig_debug(RIG_DEBUG_VERBOSE, "%s: dra818_init called\n", __func__); - struct dra818_priv *priv = calloc(sizeof(*priv), 1); + rig_debug(RIG_DEBUG_VERBOSE, "%s: dra818_init called\n", __func__); + if (!priv) { return -RIG_ENOMEM; @@ -285,13 +285,14 @@ int dra818_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd) { struct dra818_priv *priv = rig->state.priv; char cmd[80]; + char response[8]; + int r; sprintf(cmd, "S+%03d.%04d\r\n", (int)(priv->rx_freq / 1000000), (int)((priv->rx_freq % 1000000) / 100)); write_block(&rig->state.rigport, cmd, strlen(cmd)); - char response[8]; - int r = read_string(&rig->state.rigport, response, sizeof(response), "\n", 1); + r = read_string(&rig->state.rigport, response, sizeof(response), "\n", 1); if (r != 5) { diff --git a/dummy/flrig.c b/dummy/flrig.c index ddb551fc2..2b84d460f 100644 --- a/dummy/flrig.c +++ b/dummy/flrig.c @@ -234,6 +234,9 @@ static int check_vfo(vfo_t vfo) static char *xml_build(char *cmd, char *value, char *xmlbuf, int xmlbuflen) { char xml[4096]; // we shouldn't need more the 4096 bytes for this + char tmp[32]; + char *header; + int n; // We want at least a 4K buf to play with if (xmlbuflen < 4096) @@ -242,10 +245,10 @@ static char *xml_build(char *cmd, char *value, char *xmlbuf, int xmlbuflen) return NULL; } - char *header = + header = "POST /RPC2 HTTP/1.1\r\n" "User-Agent: XMLRPC++ 0.8\r\n" "Host: 127.0.0.1:12345\r\n" "Content-type: text/xml\r\n"; - int n = snprintf(xmlbuf, xmlbuflen, "%s", header); + n = snprintf(xmlbuf, xmlbuflen, "%s", header); if (n != strlen(header)) { @@ -272,7 +275,6 @@ static char *xml_build(char *cmd, char *value, char *xmlbuf, int xmlbuflen) strncat(xml, "\r\n", sizeof(xml) - 1); strncat(xmlbuf, "Content-length: ", xmlbuflen - 1); - char tmp[32]; snprintf(tmp, sizeof(tmp), "%d\r\n\r\n", (int)strlen(xml)); strncat(xmlbuf, tmp, xmlbuflen - 1); strncat(xmlbuf, xml, xmlbuflen - 1); @@ -347,6 +349,8 @@ static char *xml_parse2(char *xml, char *value, int valueLen) */ static char *xml_parse(char *xml, char *value, int value_len) { + char *next; + char *pxml; /* first off we should have an OK on the 1st line */ if (strstr(xml, " 200 OK") == NULL) { @@ -356,14 +360,14 @@ static char *xml_parse(char *xml, char *value, int value_len) rig_debug(RIG_DEBUG_TRACE, "%s XML:\n%s\n", __func__, xml); // find the xml skipping the other stuff above it - char *pxml = strstr(xml, ""; + struct rig_state *rs = &rig->state; rig_debug(RIG_DEBUG_TRACE, "%s\n", __func__); - struct rig_state *rs = &rig->state; rs->rigport.timeout = 1000; // 2 second read string timeout - int retry = 5; - char *delims = "\n"; + retry = 5; + delims = "\n"; xml[0] = 0; do @@ -491,11 +497,10 @@ static int write_transaction(RIG *rig, char *xml, int xml_len) */ static int flrig_init(RIG *rig) { + struct flrig_priv_data *priv = (struct flrig_priv_data *)malloc(sizeof(struct flrig_priv_data)); rig_debug(RIG_DEBUG_TRACE, "%s version %s\n", __func__, BACKEND_VER); - struct flrig_priv_data *priv = (struct flrig_priv_data *)malloc(sizeof( - struct flrig_priv_data)); if (!priv) { @@ -585,18 +590,21 @@ static rmode_t modeMapGetHamlib(const char *modeFLRig) static void modeMapAdd(rmode_t *modes, rmode_t mode_hamlib, char *mode_flrig) { int i; + int len1; + rig_debug(RIG_DEBUG_TRACE, "%s:mode_flrig=%s\n", __func__, mode_flrig); // if we already have it just return // We get ERROR if the mode is not known so non-ERROR is OK if (modeMapGetHamlib(mode_flrig) != RIG_MODE_NONE) { return; } - int len1 = strlen(mode_flrig) + 3; /* bytes needed for allocating */ + len1 = strlen(mode_flrig) + 3; /* bytes needed for allocating */ for (i = 0; modeMap[i].mode_hamlib != 0; ++i) { if (modeMap[i].mode_hamlib == mode_hamlib) { + int len2; *modes |= modeMap[i].mode_hamlib; /* we will pipe delimit all the entries for easier matching */ @@ -613,7 +621,7 @@ static void modeMapAdd(rmode_t *modes, rmode_t mode_hamlib, char *mode_flrig) } } - int len2 = strlen(modeMap[i].mode_flrig); /* current len w/o null */ + len2 = strlen(modeMap[i].mode_flrig); /* current len w/o null */ modeMap[i].mode_flrig = realloc(modeMap[i].mode_flrig, strlen(modeMap[i].mode_flrig) + len1); @@ -636,13 +644,16 @@ static int flrig_open(RIG *rig) { int retval; char xml[MAXXMLLEN]; + char *pxml; char value[MAXXMLLEN]; + rmode_t modes; + char *p; + char *pr; + struct flrig_priv_data *priv = (struct flrig_priv_data *) rig->state.priv; rig_debug(RIG_DEBUG_TRACE, "%s version %s\n", __func__, BACKEND_VER); - struct flrig_priv_data *priv = (struct flrig_priv_data *) rig->state.priv; - - char *pxml = xml_build("rig.get_xcvr", NULL, xml, sizeof(xml)); + pxml = xml_build("rig.get_xcvr", NULL, xml, sizeof(xml)); retval = write_transaction(rig, pxml, strlen(pxml)); if (retval < 0) @@ -727,9 +738,8 @@ static int flrig_open(RIG *rig) read_transaction(rig, xml, sizeof(xml)); xml_parse(xml, value, sizeof(value)); rig_debug(RIG_DEBUG_TRACE, "%s: modes=%s\n", __func__, value); - rmode_t modes = 0; - char *p; - char *pr = value; + modes = 0; + pr = value; /* The following modes in FLRig are not implemented yet A1A @@ -877,10 +887,14 @@ static int flrig_cleanup(RIG *rig) */ static int flrig_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) { + int retries = 10; + char xml[MAXXMLLEN]; + char value[MAXCMDLEN]; + struct flrig_priv_data *priv = (struct flrig_priv_data *) rig->state.priv; + rig_debug(RIG_DEBUG_TRACE, "%s: vfo=%s\n", __func__, rig_strvfo(vfo)); - struct flrig_priv_data *priv = (struct flrig_priv_data *) rig->state.priv; if (check_vfo(vfo) == FALSE) { @@ -896,13 +910,10 @@ static int flrig_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) __func__, rig_strvfo(vfo)); } - int retries = 10; - char xml[MAXXMLLEN]; - char value[MAXCMDLEN]; - do { char *pxml; + int retval; if (vfo == RIG_VFO_A) { @@ -913,7 +924,7 @@ static int flrig_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) pxml = xml_build("rig.get_vfoB", NULL, xml, sizeof(xml)); } - int retval = write_transaction(rig, pxml, strlen(pxml)); + retval = write_transaction(rig, pxml, strlen(pxml)); if (retval < 0) { @@ -963,12 +974,14 @@ static int flrig_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) static int flrig_set_freq(RIG *rig, vfo_t vfo, freq_t freq) { int retval; + char value[MAXXMLLEN]; + char xml[MAXXMLLEN]; + char *pxml; + struct flrig_priv_data *priv = (struct flrig_priv_data *) rig->state.priv; rig_debug(RIG_DEBUG_TRACE, "%s: vfo=%s freq=%.0f\n", __func__, rig_strvfo(vfo), freq); - struct flrig_priv_data *priv = (struct flrig_priv_data *) rig->state.priv; - if (check_vfo(vfo) == FALSE) { rig_debug(RIG_DEBUG_ERR, "%s: unsupported VFO %s\n", @@ -985,11 +998,8 @@ static int flrig_set_freq(RIG *rig, vfo_t vfo, freq_t freq) vfo = RIG_VFO_B; // if split always TX on VFOB } - char value[MAXXMLLEN]; sprintf(value, "%.0f", freq); - char xml[MAXXMLLEN]; - char *pxml; if (vfo == RIG_VFO_B) { @@ -1032,10 +1042,13 @@ static int flrig_set_freq(RIG *rig, vfo_t vfo, freq_t freq) static int flrig_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) { int retval; + char xml[MAXXMLLEN]; + char *pxml; + char cmd_buf[MAXCMDLEN]; + struct flrig_priv_data *priv = (struct flrig_priv_data *) rig->state.priv; rig_debug(RIG_DEBUG_TRACE, "%s: ptt=%d\n", __func__, ptt); - struct flrig_priv_data *priv = (struct flrig_priv_data *) rig->state.priv; if (check_vfo(vfo) == FALSE) { @@ -1044,12 +1057,10 @@ static int flrig_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) return -RIG_EINVAL; } - char cmd_buf[MAXCMDLEN]; sprintf(cmd_buf, "%d", ptt); - char xml[MAXXMLLEN]; - char *pxml = xml_build("rig.set_ptt", cmd_buf, xml, sizeof(xml)); + pxml = xml_build("rig.set_ptt", cmd_buf, xml, sizeof(xml)); retval = write_transaction(rig, pxml, strlen(pxml)); if (retval < 0) @@ -1071,14 +1082,16 @@ static int flrig_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) static int flrig_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt) { int retval; + char value[MAXCMDLEN]; + char xml[MAXXMLLEN]; + char *pxml; + struct flrig_priv_data *priv = (struct flrig_priv_data *) rig->state.priv; rig_debug(RIG_DEBUG_TRACE, "%s: vfo=%s\n", __func__, rig_strvfo(vfo)); - struct flrig_priv_data *priv = (struct flrig_priv_data *) rig->state.priv; - char xml[MAXXMLLEN]; - char *pxml = xml_build("rig.get_ptt", NULL, xml, sizeof(xml)); + pxml = xml_build("rig.get_ptt", NULL, xml, sizeof(xml)); retval = write_transaction(rig, pxml, strlen(pxml)); @@ -1088,7 +1101,6 @@ static int flrig_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt) } read_transaction(rig, xml, sizeof(xml)); - char value[MAXCMDLEN]; xml_parse(xml, value, sizeof(value)); *ptt = atoi(value); rig_debug(RIG_DEBUG_TRACE, "%s: '%s'\n", __func__, value); @@ -1106,11 +1118,11 @@ static int flrig_set_split_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) { int retval; + struct flrig_priv_data *priv = (struct flrig_priv_data *) rig->state.priv; + rig_debug(RIG_DEBUG_TRACE, "%s: vfo=%s mode=%s width=%d\n", __func__, rig_strvfo(vfo), rig_strrmode(mode), (int)width); - struct flrig_priv_data *priv = (struct flrig_priv_data *) rig->state.priv; - switch (vfo) { case RIG_VFO_CURR: @@ -1147,11 +1159,19 @@ static int flrig_set_split_mode(RIG *rig, vfo_t vfo, rmode_t mode, static int flrig_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) { int retval; + int needBW; + int vfoSwitched; + char xml[MAXXMLLEN]; + char *pxml = NULL; + char cmd_buf[MAXCMDLEN]; + char *p; + char *pttmode; + char *ttmode; + struct flrig_priv_data *priv = (struct flrig_priv_data *) rig->state.priv; rig_debug(RIG_DEBUG_TRACE, "%s: vfo=%s mode=%s width=%d\n", __func__, rig_strvfo(vfo), rig_strrmode(mode), (int)width); - struct flrig_priv_data *priv = (struct flrig_priv_data *) rig->state.priv; // if ptt is on do not set mode if (priv->ptt) @@ -1181,7 +1201,7 @@ static int flrig_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) // Switch to VFOB if appropriate since we can't set mode directly // MDB - int vfoSwitched = 0; + vfoSwitched = 0; rig_debug(RIG_DEBUG_TRACE, "%s: curr_vfo = %s\n", __func__, rig_strvfo(priv->curr_vfo)); @@ -1206,22 +1226,20 @@ static int flrig_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) } // Set the mode - char *ttmode = strdup(modeMapGetFLRig(mode)); + ttmode = strdup(modeMapGetFLRig(mode)); rig_debug(RIG_DEBUG_TRACE, "%s: got ttmode = %s\n", __func__, ttmode == NULL ? "NULL" : ttmode); - char *pttmode = ttmode; + pttmode = ttmode; if (ttmode[0] == '|') { pttmode = &ttmode[1]; } // remove first pipe symbol - char *p = strchr(pttmode, '|'); + p = strchr(pttmode, '|'); if (p) { *p = 0; } // remove any other pipe - char cmd_buf[MAXCMDLEN]; sprintf(cmd_buf, "%s", pttmode); free(ttmode); - char xml[MAXXMLLEN]; - char *pxml = NULL; + pxml = NULL; if (!priv->has_get_modeA) { @@ -1253,7 +1271,7 @@ static int flrig_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) rig_debug(RIG_DEBUG_TRACE, "%s: response=%s\n", __func__, xml); // Determine if we need to update the bandwidth - int needBW = 0; + needBW = 0; if (vfo == RIG_VFO_A) { @@ -1336,12 +1354,17 @@ static int flrig_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) static int flrig_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) { int retval; + int vfoSwitched; + char value[MAXCMDLEN]; + char xml[MAXXMLLEN]; + char *pxml; + char *cmdp; + vfo_t curr_vfo; + struct flrig_priv_data *priv = (struct flrig_priv_data *) rig->state.priv; rig_debug(RIG_DEBUG_TRACE, "%s: vfo=%s\n", __func__, rig_strvfo(vfo)); - struct flrig_priv_data *priv = (struct flrig_priv_data *) rig->state.priv; - if (check_vfo(vfo) == FALSE) { rig_debug(RIG_DEBUG_ERR, "%s: unsupported VFO %s\n", @@ -1349,7 +1372,7 @@ static int flrig_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) return -RIG_EINVAL; } - vfo_t curr_vfo = priv->curr_vfo; + curr_vfo = priv->curr_vfo; if (vfo == RIG_VFO_CURR) { @@ -1369,7 +1392,7 @@ static int flrig_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) } // Switch to VFOB if appropriate - int vfoSwitched = 0; + vfoSwitched = 0; if (priv->has_get_modeA == 0 && vfo == RIG_VFO_B && curr_vfo != RIG_VFO_B) { @@ -1388,8 +1411,7 @@ static int flrig_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) } } - char xml[MAXXMLLEN]; - char *cmdp = "rig.get_mode"; /* default to old way */ + cmdp = "rig.get_mode"; /* default to old way */ if (priv->has_get_modeA) /* change to new way if we can */ { @@ -1402,7 +1424,7 @@ static int flrig_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) if (vfo == RIG_VFO_B) { cmdp = "rig.get_modeB"; } } - char *pxml = xml_build(cmdp, NULL, xml, sizeof(xml)); + pxml = xml_build(cmdp, NULL, xml, sizeof(xml)); retval = write_transaction(rig, pxml, strlen(pxml)); if (retval < 0) @@ -1411,7 +1433,6 @@ static int flrig_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) } read_transaction(rig, xml, sizeof(xml)); - char value[MAXCMDLEN]; xml_parse(xml, value, sizeof(value)); retval = modeMapGetHamlib(value); @@ -1502,12 +1523,15 @@ static int flrig_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) static int flrig_set_vfo(RIG *rig, vfo_t vfo) { int retval; + char value[MAXCMDLEN]; + char xml[MAXXMLLEN]; + char *pxml; + struct rig_state *rs = &rig->state; + struct flrig_priv_data *priv = (struct flrig_priv_data *) rig->state.priv; rig_debug(RIG_DEBUG_TRACE, "%s: vfo=%s\n", __func__, rig_strvfo(vfo)); - struct rig_state *rs = &rig->state; - struct flrig_priv_data *priv = (struct flrig_priv_data *) rig->state.priv; if (check_vfo(vfo) == FALSE) { @@ -1527,11 +1551,9 @@ static int flrig_set_vfo(RIG *rig, vfo_t vfo) vfo = priv->curr_vfo; } - char value[MAXCMDLEN]; - char xml[MAXXMLLEN]; sprintf(value, "%s", vfo == RIG_VFO_A ? "A" : "B"); - char *pxml = xml_build("rig.set_AB", value, xml, sizeof(xml)); + pxml = xml_build("rig.set_AB", value, xml, sizeof(xml)); retval = write_transaction(rig, pxml, strlen(pxml)); if (retval < 0) @@ -1570,13 +1592,15 @@ static int flrig_set_vfo(RIG *rig, vfo_t vfo) static int flrig_get_vfo(RIG *rig, vfo_t *vfo) { int retval; + char value[MAXCMDLEN]; + char xml[MAXXMLLEN]; + char *pxml; + struct flrig_priv_data *priv = (struct flrig_priv_data *) rig->state.priv; rig_debug(RIG_DEBUG_TRACE, "%s\n", __func__); - struct flrig_priv_data *priv = (struct flrig_priv_data *) rig->state.priv; - char xml[MAXXMLLEN]; - char *pxml = xml_build("rig.get_AB", NULL, xml, sizeof(xml)); + pxml = xml_build("rig.get_AB", NULL, xml, sizeof(xml)); retval = write_transaction(rig, pxml, strlen(pxml)); if (retval < 0) @@ -1585,7 +1609,6 @@ static int flrig_get_vfo(RIG *rig, vfo_t *vfo) } read_transaction(rig, xml, sizeof(xml)); - char value[MAXCMDLEN]; xml_parse(xml, value, sizeof(value)); rig_debug(RIG_DEBUG_TRACE, "%s: vfo value=%s\n", __func__, value); @@ -1626,12 +1649,15 @@ static int flrig_get_vfo(RIG *rig, vfo_t *vfo) static int flrig_set_split_freq(RIG *rig, vfo_t vfo, freq_t tx_freq) { int retval; + char xml[MAXXMLLEN]; + char *pxml; + char value[MAXCMDLEN]; + freq_t qtx_freq; + struct flrig_priv_data *priv = (struct flrig_priv_data *) rig->state.priv; rig_debug(RIG_DEBUG_TRACE, "%s: vfo=%s freq=%.1f\n", __func__, rig_strvfo(vfo), tx_freq); - struct flrig_priv_data *priv = (struct flrig_priv_data *) rig->state.priv; - if (check_vfo(vfo) == FALSE) { rig_debug(RIG_DEBUG_ERR, "%s: unsupported VFO %s\n", @@ -1640,19 +1666,16 @@ static int flrig_set_split_freq(RIG *rig, vfo_t vfo, freq_t tx_freq) } // we always split on VFOB so if no change just return - freq_t qtx_freq; retval = flrig_get_freq(rig, RIG_VFO_B, &qtx_freq); if (retval != RIG_OK) { return retval; } if (tx_freq == qtx_freq) { return RIG_OK; } - char xml[MAXXMLLEN]; - char value[MAXCMDLEN]; sprintf(value, "%.6f", tx_freq); - char *pxml = xml_build("rig.set_vfoB", value, xml, sizeof(xml)); + pxml = xml_build("rig.set_vfoB", value, xml, sizeof(xml)); retval = write_transaction(rig, pxml, strlen(pxml)); if (retval < 0) @@ -1673,12 +1696,13 @@ static int flrig_set_split_freq(RIG *rig, vfo_t vfo, freq_t tx_freq) */ static int flrig_get_split_freq(RIG *rig, vfo_t vfo, freq_t *tx_freq) { + int retval; + struct flrig_priv_data *priv = (struct flrig_priv_data *) rig->state.priv; + rig_debug(RIG_DEBUG_TRACE, "%s: vfo=%s\n", __func__, rig_strvfo(vfo)); - struct flrig_priv_data *priv = (struct flrig_priv_data *) rig->state.priv; - - int retval = flrig_get_freq(rig, RIG_VFO_B, tx_freq); + retval = flrig_get_freq(rig, RIG_VFO_B, tx_freq); priv->curr_freqB = *tx_freq; return retval; } @@ -1690,19 +1714,22 @@ static int flrig_get_split_freq(RIG *rig, vfo_t vfo, freq_t *tx_freq) static int flrig_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, vfo_t tx_vfo) { int retval; + vfo_t qtx_vfo; + split_t qsplit; + char xml[MAXXMLLEN]; + char value[MAXCMDLEN]; + struct flrig_priv_data *priv = (struct flrig_priv_data *) rig->state.priv; + char *pxml; rig_debug(RIG_DEBUG_TRACE, "%s: tx_vfo=%s\n", __func__, rig_strvfo(tx_vfo)); - struct flrig_priv_data *priv = (struct flrig_priv_data *) rig->state.priv; if (tx_vfo == RIG_VFO_SUB || tx_vfo == RIG_VFO_TX) { tx_vfo = RIG_VFO_B; } - vfo_t qtx_vfo; - split_t qsplit; retval = flrig_get_split_vfo(rig, RIG_VFO_A, &qsplit, &qtx_vfo); if (retval != RIG_OK) { return retval; } @@ -1715,11 +1742,9 @@ static int flrig_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, vfo_t tx_vfo) return RIG_OK; // just return OK and ignore this } - char xml[MAXXMLLEN]; - char value[MAXCMDLEN]; sprintf(value, "%d", split); - char *pxml = xml_build("rig.set_split", value, xml, sizeof(xml)); + pxml = xml_build("rig.set_split", value, xml, sizeof(xml)); retval = write_transaction(rig, pxml, strlen(pxml)); if (retval < 0) @@ -1742,12 +1767,14 @@ static int flrig_get_split_vfo(RIG *rig, vfo_t vfo, split_t *split, vfo_t *tx_vfo) { int retval; + char value[MAXCMDLEN]; + char xml[MAXXMLLEN]; + struct flrig_priv_data *priv = (struct flrig_priv_data *) rig->state.priv; + char *pxml; rig_debug(RIG_DEBUG_TRACE, "%s\n", __func__); - struct flrig_priv_data *priv = (struct flrig_priv_data *) rig->state.priv; - char xml[MAXXMLLEN]; - char *pxml = xml_build("rig.get_split", NULL, xml, sizeof(xml)); + pxml = xml_build("rig.get_split", NULL, xml, sizeof(xml)); retval = write_transaction(rig, pxml, strlen(pxml)); if (retval < 0) @@ -1755,7 +1782,6 @@ static int flrig_get_split_vfo(RIG *rig, vfo_t vfo, split_t *split, return retval; } - char value[MAXCMDLEN]; read_transaction(rig, xml, sizeof(xml)); xml_parse(xml, value, sizeof(value)); @@ -1775,10 +1801,12 @@ static int flrig_set_split_freq_mode(RIG *rig, vfo_t vfo, freq_t freq, rmode_t mode, pbwidth_t width) { int retval; + rmode_t qmode; + pbwidth_t qwidth; + struct flrig_priv_data *priv = (struct flrig_priv_data *) rig->state.priv; rig_debug(RIG_DEBUG_TRACE, "%s\n", __func__); - struct flrig_priv_data *priv = (struct flrig_priv_data *) rig->state.priv; if (vfo != RIG_VFO_CURR && vfo != RIG_VFO_TX) { @@ -1800,8 +1828,6 @@ static int flrig_set_split_freq_mode(RIG *rig, vfo_t vfo, freq_t freq, } // Make VFOB mode match VFOA mode, keep VFOB width - rmode_t qmode; - pbwidth_t qwidth; retval = flrig_get_mode(rig, RIG_VFO_B, &qmode, &qwidth); if (retval != RIG_OK) { return retval; } diff --git a/dummy/netrigctl.c b/dummy/netrigctl.c index 3642b08e8..84bdf8410 100644 --- a/dummy/netrigctl.c +++ b/dummy/netrigctl.c @@ -106,6 +106,8 @@ static int netrigctl_transaction(RIG *rig, char *cmd, int len, char *buf) */ static int netrigctl_vfostr(RIG *rig, char *vfostr, int len, vfo_t vfo) { + struct netrigctl_priv_data *priv; + if (len < 5) { rig_debug(RIG_DEBUG_ERR, "%s: len must be >=5, len=%d\n", __func__, len); @@ -114,7 +116,6 @@ static int netrigctl_vfostr(RIG *rig, char *vfostr, int len, vfo_t vfo) vfostr[0] = 0; - struct netrigctl_priv_data *priv; priv = (struct netrigctl_priv_data *)rig->state.priv; if (vfo == RIG_VFO_CURR) @@ -132,13 +133,14 @@ static int netrigctl_vfostr(RIG *rig, char *vfostr, int len, vfo_t vfo) static int netrigctl_init(RIG *rig) { + struct netrigctl_priv_data *priv = (struct netrigctl_priv_data *)malloc(sizeof( + struct netrigctl_priv_data)); + if (!rig || !rig->caps) { return -RIG_EINVAL; } - struct netrigctl_priv_data *priv = (struct netrigctl_priv_data *)malloc(sizeof( - struct netrigctl_priv_data)); if (!priv) @@ -177,11 +179,11 @@ static int netrigctl_open(RIG *rig) int prot_ver; char cmd[CMD_MAX]; char buf[BUF_MAX]; + struct netrigctl_priv_data *priv; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - struct netrigctl_priv_data *priv; priv = (struct netrigctl_priv_data *)rig->state.priv; len = sprintf(cmd, "\\chk_vfo\n"); @@ -519,10 +521,10 @@ static int netrigctl_set_freq(RIG *rig, vfo_t vfo, freq_t freq) int ret, len; char cmd[CMD_MAX]; char buf[BUF_MAX]; + char vfostr[6] = ""; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - char vfostr[6] = ""; ret = netrigctl_vfostr(rig, vfostr, sizeof(vfostr), vfo); if (ret != RIG_OK) { return ret; } @@ -546,10 +548,10 @@ static int netrigctl_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) int ret, len; char cmd[CMD_MAX]; char buf[BUF_MAX]; + char vfostr[6] = ""; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - char vfostr[6] = ""; ret = netrigctl_vfostr(rig, vfostr, sizeof(vfostr), vfo); if (ret != RIG_OK) { return ret; } @@ -575,10 +577,10 @@ static int netrigctl_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, int ret, len; char cmd[CMD_MAX]; char buf[BUF_MAX]; + char vfostr[6] = ""; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - char vfostr[6] = ""; ret = netrigctl_vfostr(rig, vfostr, sizeof(vfostr), vfo); if (ret != RIG_OK) { return ret; } @@ -605,10 +607,10 @@ static int netrigctl_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, int ret, len; char cmd[CMD_MAX]; char buf[BUF_MAX]; + char vfostr[6] = ""; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - char vfostr[6] = ""; ret = netrigctl_vfostr(rig, vfostr, sizeof(vfostr), vfo); if (ret != RIG_OK) { return ret; } @@ -644,10 +646,10 @@ static int netrigctl_set_vfo(RIG *rig, vfo_t vfo) int ret, len; char cmd[CMD_MAX]; char buf[BUF_MAX]; + char vfostr[6] = ""; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - char vfostr[6] = ""; ret = netrigctl_vfostr(rig, vfostr, sizeof(vfostr), RIG_VFO_A); if (ret != RIG_OK) { return ret; } @@ -672,13 +674,13 @@ static int netrigctl_get_vfo(RIG *rig, vfo_t *vfo) int ret, len; char cmd[CMD_MAX]; char buf[BUF_MAX]; + char vfostr[6] = ""; + struct netrigctl_priv_data *priv; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - struct netrigctl_priv_data *priv; priv = (struct netrigctl_priv_data *)rig->state.priv; - char vfostr[6] = ""; ret = netrigctl_vfostr(rig, vfostr, sizeof(vfostr), RIG_VFO_A); if (ret != RIG_OK) { return ret; } @@ -709,10 +711,10 @@ static int netrigctl_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) int ret, len; char cmd[CMD_MAX]; char buf[BUF_MAX]; + char vfostr[6] = ""; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - char vfostr[6] = ""; ret = netrigctl_vfostr(rig, vfostr, sizeof(vfostr), RIG_VFO_A); if (ret != RIG_OK) { return ret; } @@ -737,10 +739,10 @@ static int netrigctl_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt) int ret, len; char cmd[CMD_MAX]; char buf[BUF_MAX]; + char vfostr[6] = ""; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - char vfostr[6] = ""; ret = netrigctl_vfostr(rig, vfostr, sizeof(vfostr), RIG_VFO_A); if (ret != RIG_OK) { return ret; } @@ -764,10 +766,10 @@ static int netrigctl_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd) int ret, len; char cmd[CMD_MAX]; char buf[BUF_MAX]; + char vfostr[6] = ""; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - char vfostr[6] = ""; ret = netrigctl_vfostr(rig, vfostr, sizeof(vfostr), RIG_VFO_A); if (ret != RIG_OK) { return ret; } @@ -793,10 +795,10 @@ static int netrigctl_set_rptr_shift(RIG *rig, vfo_t vfo, int ret, len; char cmd[CMD_MAX]; char buf[BUF_MAX]; + char vfostr[6] = ""; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - char vfostr[6] = ""; ret = netrigctl_vfostr(rig, vfostr, sizeof(vfostr), RIG_VFO_A); if (ret != RIG_OK) { return ret; } @@ -822,10 +824,10 @@ static int netrigctl_get_rptr_shift(RIG *rig, vfo_t vfo, int ret, len; char cmd[CMD_MAX]; char buf[BUF_MAX]; + char vfostr[6] = ""; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - char vfostr[6] = ""; ret = netrigctl_vfostr(rig, vfostr, sizeof(vfostr), RIG_VFO_A); if (ret != RIG_OK) { return ret; } @@ -852,10 +854,10 @@ static int netrigctl_set_rptr_offs(RIG *rig, vfo_t vfo, shortfreq_t rptr_offs) int ret, len; char cmd[CMD_MAX]; char buf[BUF_MAX]; + char vfostr[6] = ""; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - char vfostr[6] = ""; ret = netrigctl_vfostr(rig, vfostr, sizeof(vfostr), RIG_VFO_A); if (ret != RIG_OK) { return ret; } @@ -880,10 +882,10 @@ static int netrigctl_get_rptr_offs(RIG *rig, vfo_t vfo, shortfreq_t *rptr_offs) int ret, len; char cmd[CMD_MAX]; char buf[BUF_MAX]; + char vfostr[6] = ""; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - char vfostr[6] = ""; ret = netrigctl_vfostr(rig, vfostr, sizeof(vfostr), RIG_VFO_A); if (ret != RIG_OK) { return ret; } @@ -908,10 +910,10 @@ static int netrigctl_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone) int ret, len; char cmd[CMD_MAX]; char buf[BUF_MAX]; + char vfostr[6] = ""; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - char vfostr[6] = ""; ret = netrigctl_vfostr(rig, vfostr, sizeof(vfostr), RIG_VFO_A); if (ret != RIG_OK) { return ret; } @@ -936,10 +938,10 @@ static int netrigctl_get_ctcss_tone(RIG *rig, vfo_t vfo, tone_t *tone) int ret, len; char cmd[CMD_MAX]; char buf[BUF_MAX]; + char vfostr[6] = ""; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - char vfostr[6] = ""; ret = netrigctl_vfostr(rig, vfostr, sizeof(vfostr), RIG_VFO_A); if (ret != RIG_OK) { return ret; } @@ -964,10 +966,10 @@ static int netrigctl_set_dcs_code(RIG *rig, vfo_t vfo, tone_t code) int ret, len; char cmd[CMD_MAX]; char buf[BUF_MAX]; + char vfostr[6] = ""; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - char vfostr[6] = ""; ret = netrigctl_vfostr(rig, vfostr, sizeof(vfostr), RIG_VFO_A); if (ret != RIG_OK) { return ret; } @@ -992,10 +994,10 @@ static int netrigctl_get_dcs_code(RIG *rig, vfo_t vfo, tone_t *code) int ret, len; char cmd[CMD_MAX]; char buf[BUF_MAX]; + char vfostr[6] = ""; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - char vfostr[6] = ""; ret = netrigctl_vfostr(rig, vfostr, sizeof(vfostr), RIG_VFO_A); if (ret != RIG_OK) { return ret; } @@ -1020,10 +1022,10 @@ static int netrigctl_set_ctcss_sql(RIG *rig, vfo_t vfo, tone_t tone) int ret, len; char cmd[CMD_MAX]; char buf[BUF_MAX]; + char vfostr[6] = ""; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - char vfostr[6] = ""; ret = netrigctl_vfostr(rig, vfostr, sizeof(vfostr), RIG_VFO_A); if (ret != RIG_OK) { return ret; } @@ -1048,10 +1050,10 @@ static int netrigctl_get_ctcss_sql(RIG *rig, vfo_t vfo, tone_t *tone) int ret, len; char cmd[CMD_MAX]; char buf[BUF_MAX]; + char vfostr[6] = ""; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - char vfostr[6] = ""; ret = netrigctl_vfostr(rig, vfostr, sizeof(vfostr), RIG_VFO_A); if (ret != RIG_OK) { return ret; } @@ -1076,10 +1078,10 @@ static int netrigctl_set_dcs_sql(RIG *rig, vfo_t vfo, unsigned int code) int ret, len; char cmd[CMD_MAX]; char buf[BUF_MAX]; + char vfostr[6] = ""; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - char vfostr[6] = ""; ret = netrigctl_vfostr(rig, vfostr, sizeof(vfostr), RIG_VFO_A); if (ret != RIG_OK) { return ret; } @@ -1103,10 +1105,10 @@ static int netrigctl_get_dcs_sql(RIG *rig, vfo_t vfo, unsigned int *code) int ret, len; char cmd[CMD_MAX]; char buf[BUF_MAX]; + char vfostr[6] = ""; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - char vfostr[6] = ""; ret = netrigctl_vfostr(rig, vfostr, sizeof(vfostr), RIG_VFO_A); if (ret != RIG_OK) { return ret; } @@ -1131,10 +1133,10 @@ static int netrigctl_set_split_freq(RIG *rig, vfo_t vfo, freq_t tx_freq) int ret, len; char cmd[CMD_MAX]; char buf[BUF_MAX]; + char vfostr[6] = ""; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - char vfostr[6] = ""; ret = netrigctl_vfostr(rig, vfostr, sizeof(vfostr), RIG_VFO_A); if (ret != RIG_OK) { return ret; } @@ -1159,10 +1161,10 @@ static int netrigctl_get_split_freq(RIG *rig, vfo_t vfo, freq_t *tx_freq) int ret, len; char cmd[CMD_MAX]; char buf[BUF_MAX]; + char vfostr[6] = ""; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - char vfostr[6] = ""; ret = netrigctl_vfostr(rig, vfostr, sizeof(vfostr), RIG_VFO_A); if (ret != RIG_OK) { return ret; } @@ -1187,10 +1189,10 @@ static int netrigctl_set_split_mode(RIG *rig, vfo_t vfo, rmode_t tx_mode, int ret, len; char cmd[CMD_MAX]; char buf[BUF_MAX]; + char vfostr[6] = ""; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - char vfostr[6] = ""; ret = netrigctl_vfostr(rig, vfostr, sizeof(vfostr), RIG_VFO_A); if (ret != RIG_OK) { return ret; } @@ -1216,10 +1218,10 @@ static int netrigctl_get_split_mode(RIG *rig, vfo_t vfo, rmode_t *tx_mode, int ret, len; char cmd[CMD_MAX]; char buf[BUF_MAX]; + char vfostr[6] = ""; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - char vfostr[6] = ""; ret = netrigctl_vfostr(rig, vfostr, sizeof(vfostr), RIG_VFO_A); if (ret != RIG_OK) { return ret; } @@ -1255,10 +1257,10 @@ static int netrigctl_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, int ret, len; char cmd[CMD_MAX]; char buf[BUF_MAX]; + char vfostr[6] = ""; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - char vfostr[6] = ""; ret = netrigctl_vfostr(rig, vfostr, sizeof(vfostr), RIG_VFO_A); if (ret != RIG_OK) { return ret; } @@ -1284,10 +1286,10 @@ static int netrigctl_get_split_vfo(RIG *rig, vfo_t vfo, split_t *split, int ret, len; char cmd[CMD_MAX]; char buf[BUF_MAX]; + char vfostr[6] = ""; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - char vfostr[6] = ""; ret = netrigctl_vfostr(rig, vfostr, sizeof(vfostr), RIG_VFO_A); if (ret != RIG_OK) { return ret; } @@ -1323,10 +1325,10 @@ static int netrigctl_set_rit(RIG *rig, vfo_t vfo, shortfreq_t rit) int ret, len; char cmd[CMD_MAX]; char buf[BUF_MAX]; + char vfostr[6] = ""; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - char vfostr[6] = ""; ret = netrigctl_vfostr(rig, vfostr, sizeof(vfostr), vfo); if (ret != RIG_OK) { return ret; } @@ -1351,10 +1353,10 @@ static int netrigctl_get_rit(RIG *rig, vfo_t vfo, shortfreq_t *rit) int ret, len; char cmd[CMD_MAX]; char buf[BUF_MAX]; + char vfostr[6] = ""; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - char vfostr[6] = ""; ret = netrigctl_vfostr(rig, vfostr, sizeof(vfostr), vfo); if (ret != RIG_OK) { return ret; } @@ -1379,10 +1381,10 @@ static int netrigctl_set_xit(RIG *rig, vfo_t vfo, shortfreq_t xit) int ret, len; char cmd[CMD_MAX]; char buf[BUF_MAX]; + char vfostr[6] = ""; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - char vfostr[6] = ""; ret = netrigctl_vfostr(rig, vfostr, sizeof(vfostr), vfo); if (ret != RIG_OK) { return ret; } @@ -1407,10 +1409,10 @@ static int netrigctl_get_xit(RIG *rig, vfo_t vfo, shortfreq_t *xit) int ret, len; char cmd[CMD_MAX]; char buf[BUF_MAX]; + char vfostr[6] = ""; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - char vfostr[6] = ""; ret = netrigctl_vfostr(rig, vfostr, sizeof(vfostr), vfo); if (ret != RIG_OK) { return ret; } @@ -1435,10 +1437,10 @@ static int netrigctl_set_ts(RIG *rig, vfo_t vfo, shortfreq_t ts) int ret, len; char cmd[CMD_MAX]; char buf[BUF_MAX]; + char vfostr[6] = ""; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - char vfostr[6] = ""; ret = netrigctl_vfostr(rig, vfostr, sizeof(vfostr), RIG_VFO_A); if (ret != RIG_OK) { return ret; } @@ -1463,10 +1465,10 @@ static int netrigctl_get_ts(RIG *rig, vfo_t vfo, shortfreq_t *ts) int ret, len; char cmd[CMD_MAX]; char buf[BUF_MAX]; + char vfostr[6] = ""; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - char vfostr[6] = ""; ret = netrigctl_vfostr(rig, vfostr, sizeof(vfostr), RIG_VFO_A); if (ret != RIG_OK) { return ret; } @@ -1491,10 +1493,10 @@ static int netrigctl_set_func(RIG *rig, vfo_t vfo, setting_t func, int status) int ret, len; char cmd[CMD_MAX]; char buf[BUF_MAX]; + char vfostr[6] = ""; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - char vfostr[6] = ""; ret = netrigctl_vfostr(rig, vfostr, sizeof(vfostr), vfo); if (ret != RIG_OK) { return ret; } @@ -1519,10 +1521,10 @@ static int netrigctl_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status) int ret, len; char cmd[CMD_MAX]; char buf[BUF_MAX]; + char vfostr[6] = ""; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - char vfostr[6] = ""; ret = netrigctl_vfostr(rig, vfostr, sizeof(vfostr), vfo); if (ret != RIG_OK) { return ret; } @@ -1549,6 +1551,7 @@ static int netrigctl_set_level(RIG *rig, vfo_t vfo, setting_t level, char cmd[CMD_MAX]; char buf[BUF_MAX]; char lstr[32]; + char vfostr[6] = ""; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -1561,7 +1564,6 @@ static int netrigctl_set_level(RIG *rig, vfo_t vfo, setting_t level, sprintf(lstr, "%d", val.i); } - char vfostr[6] = ""; ret = netrigctl_vfostr(rig, vfostr, sizeof(vfostr), vfo); if (ret != RIG_OK) { return ret; } @@ -1589,10 +1591,10 @@ static int netrigctl_get_level(RIG *rig, vfo_t vfo, setting_t level, int ret, len; char cmd[CMD_MAX]; char buf[BUF_MAX]; + char vfostr[6] = ""; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - char vfostr[6] = ""; ret = netrigctl_vfostr(rig, vfostr, sizeof(vfostr), vfo); if (ret != RIG_OK) { return ret; } @@ -1733,10 +1735,10 @@ static int netrigctl_set_ant(RIG *rig, vfo_t vfo, ant_t ant) int ret, len; char cmd[CMD_MAX]; char buf[BUF_MAX]; + char vfostr[6] = ""; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - char vfostr[6] = ""; ret = netrigctl_vfostr(rig, vfostr, sizeof(vfostr), vfo); if (ret != RIG_OK) { return ret; } @@ -1761,10 +1763,10 @@ static int netrigctl_get_ant(RIG *rig, vfo_t vfo, ant_t *ant) int ret, len; char cmd[CMD_MAX]; char buf[BUF_MAX]; + char vfostr[6] = ""; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - char vfostr[6] = ""; ret = netrigctl_vfostr(rig, vfostr, sizeof(vfostr), vfo); if (ret != RIG_OK) { return ret; } @@ -1812,10 +1814,10 @@ static int netrigctl_set_mem(RIG *rig, vfo_t vfo, int ch) int ret, len; char cmd[CMD_MAX]; char buf[BUF_MAX]; + char vfostr[6] = ""; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - char vfostr[6] = ""; ret = netrigctl_vfostr(rig, vfostr, sizeof(vfostr), vfo); if (ret != RIG_OK) { return ret; } @@ -1840,10 +1842,10 @@ static int netrigctl_get_mem(RIG *rig, vfo_t vfo, int *ch) int ret, len; char cmd[CMD_MAX]; char buf[BUF_MAX]; + char vfostr[6] = ""; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - char vfostr[6] = ""; ret = netrigctl_vfostr(rig, vfostr, sizeof(vfostr), vfo); if (ret != RIG_OK) { return ret; } diff --git a/dummy/trxmanager.c b/dummy/trxmanager.c index 8e2bbd868..df8670cf6 100644 --- a/dummy/trxmanager.c +++ b/dummy/trxmanager.c @@ -236,13 +236,14 @@ static int vfo_curr(RIG *rig, vfo_t vfo) */ static int read_transaction(RIG *rig, char *response, int response_len) { + struct rig_state *rs = &rig->state; + char *delims = "\n"; + int len; + rig_debug(RIG_DEBUG_TRACE, "%s\n", __func__); - struct rig_state *rs = &rig->state; - - char *delims = "\n"; - int len = read_string(&rs->rigport, response, response_len, delims, - strlen(delims)); + len = read_string(&rs->rigport, response, response_len, delims, + strlen(delims)); if (len <= 0) { @@ -259,12 +260,11 @@ static int read_transaction(RIG *rig, char *response, int response_len) */ static int trxmanager_init(RIG *rig) { - - rig_debug(RIG_DEBUG_TRACE, "%s version %s\n", __func__, BACKEND_VER); - struct trxmanager_priv_data *priv = (struct trxmanager_priv_data *)malloc( sizeof(struct trxmanager_priv_data)); + rig_debug(RIG_DEBUG_TRACE, "%s version %s\n", __func__, BACKEND_VER); + if (!priv) { return -RIG_ENOMEM; @@ -297,14 +297,14 @@ static int trxmanager_init(RIG *rig) static int trxmanager_open(RIG *rig) { int retval; + char *cmd; char response[MAXCMDLEN] = ""; - - rig_debug(RIG_DEBUG_VERBOSE, "%s version %s\n", __func__, BACKEND_VER); - struct rig_state *rs = &rig->state; struct trxmanager_priv_data *priv = (struct trxmanager_priv_data *) rig->state.priv; + rig_debug(RIG_DEBUG_VERBOSE, "%s version %s\n", __func__, BACKEND_VER); + rs->rigport.timeout = 10000; // long timeout for antenna switching/tuning retval = read_transaction(rig, response, sizeof(response)); @@ -325,7 +325,7 @@ static int trxmanager_open(RIG *rig) rig_debug(RIG_DEBUG_VERBOSE, "%s connected to %s\n", __func__, priv->info); // Turn off active messages - char *cmd = "AI0;"; + cmd = "AI0;"; retval = write_block(&rs->rigport, cmd, strlen(cmd)); if (retval < 0) @@ -404,14 +404,17 @@ static int trxmanager_cleanup(RIG *rig) static int trxmanager_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) { int retval; - - rig_debug(RIG_DEBUG_TRACE, "%s: vfo=%s\n", __func__, - rig_strvfo(vfo)); - + int n; + char vfoab; + char cmd[MAXCMDLEN]; + char response[MAXCMDLEN] = ""; struct rig_state *rs = &rig->state; struct trxmanager_priv_data *priv = (struct trxmanager_priv_data *) rig->state.priv; + rig_debug(RIG_DEBUG_TRACE, "%s: vfo=%s\n", __func__, + rig_strvfo(vfo)); + if (check_vfo(vfo) == FALSE) { rig_debug(RIG_DEBUG_ERR, "%s: unsupported VFO %s\n", @@ -432,9 +435,7 @@ static int trxmanager_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) __func__, rig_strvfo(vfo)); } - char cmd[MAXCMDLEN]; - char response[MAXCMDLEN] = ""; - char vfoab = vfo == RIG_VFO_A ? 'R' : 'T'; + vfoab = vfo == RIG_VFO_A ? 'R' : 'T'; snprintf(cmd, sizeof(cmd), "X%c;", vfoab); retval = write_block(&rs->rigport, cmd, strlen(cmd)); @@ -451,7 +452,7 @@ static int trxmanager_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) } *freq = 0; - int n = sscanf(&response[2], "%lg", freq); + n = sscanf(&response[2], "%lg", freq); if (n != 1) { @@ -474,14 +475,17 @@ static int trxmanager_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) static int trxmanager_set_freq(RIG *rig, vfo_t vfo, freq_t freq) { int retval; - - rig_debug(RIG_DEBUG_TRACE, "%s: vfo=%s freq=%.1f\n", __func__, - rig_strvfo(vfo), freq); - + char vfoab; + char cmd[MAXCMDLEN]; + char response[MAXCMDLEN] = ""; struct rig_state *rs = &rig->state; struct trxmanager_priv_data *priv = (struct trxmanager_priv_data *) rig->state.priv; + + rig_debug(RIG_DEBUG_TRACE, "%s: vfo=%s freq=%.1f\n", __func__, + rig_strvfo(vfo), freq); + if (check_vfo(vfo) == FALSE) { rig_debug(RIG_DEBUG_ERR, "%s: unsupported VFO %s\n", @@ -501,9 +505,7 @@ static int trxmanager_set_freq(RIG *rig, vfo_t vfo, freq_t freq) vfo = RIG_VFO_B; // if split always TX on VFOB } - char cmd[MAXCMDLEN]; - char response[MAXCMDLEN] = ""; - char vfoab = vfo == RIG_VFO_A ? 'A' : 'B'; + vfoab = vfo == RIG_VFO_A ? 'A' : 'B'; snprintf(cmd, sizeof(cmd), "F%c%011lu;", vfoab, (unsigned long)freq); retval = write_block(&rs->rigport, cmd, strlen(cmd)); @@ -530,11 +532,12 @@ static int trxmanager_set_freq(RIG *rig, vfo_t vfo, freq_t freq) static int trxmanager_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) { int retval; + char cmd[MAXCMDLEN]; + char response[MAXCMDLEN] = ""; + struct rig_state *rs = &rig->state; rig_debug(RIG_DEBUG_TRACE, "%s: ptt=%d\n", __func__, ptt); - struct rig_state *rs = &rig->state; - if (check_vfo(vfo) == FALSE) { rig_debug(RIG_DEBUG_ERR, "%s: unsupported VFO %s\n", @@ -542,9 +545,6 @@ static int trxmanager_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) return -RIG_EINVAL; } - char cmd[MAXCMDLEN]; - char response[MAXCMDLEN] = ""; - snprintf(cmd, sizeof(cmd), "%s;", ptt == 1 ? "TX" : "RX"); retval = write_block(&rs->rigport, cmd, strlen(cmd)); @@ -576,14 +576,14 @@ static int trxmanager_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) static int trxmanager_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt) { int retval; + char cptt; + char cmd[MAXCMDLEN]; + char response[MAXCMDLEN] = ""; + struct rig_state *rs = &rig->state; rig_debug(RIG_DEBUG_TRACE, "%s: vfo=%s\n", __func__, rig_strvfo(vfo)); - struct rig_state *rs = &rig->state; - - char cmd[MAXCMDLEN]; - char response[MAXCMDLEN] = ""; snprintf(cmd, sizeof(cmd), "IF;"); retval = write_block(&rs->rigport, cmd, strlen(cmd)); @@ -607,7 +607,7 @@ static int trxmanager_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt) rig_debug(RIG_DEBUG_VERBOSE, "%s: IF response len=%d\n", __func__, (int)strlen(response)); - char cptt = response[28]; + cptt = response[28]; *ptt = cptt == '0' ? 0 : 1; return RIG_OK; @@ -635,12 +635,14 @@ static int trxmanager_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) { int retval; + char ttmode; + char cmd[MAXCMDLEN]; + char response[MAXCMDLEN] = ""; + struct rig_state *rs = &rig->state; rig_debug(RIG_DEBUG_TRACE, "%s: vfo=%s mode=%s width=%d\n", __func__, rig_strvfo(vfo), rig_strrmode(mode), (int)width); - struct rig_state *rs = &rig->state; - if (check_vfo(vfo) == FALSE) { rig_debug(RIG_DEBUG_ERR, "%s: unsupported VFO %s\n", @@ -648,7 +650,7 @@ static int trxmanager_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, return -RIG_EINVAL; } - char ttmode = FLRIG_MODE_USB; + ttmode = FLRIG_MODE_USB; switch (mode) { @@ -707,8 +709,6 @@ static int trxmanager_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, } - char cmd[MAXCMDLEN]; - char response[MAXCMDLEN] = ""; snprintf(cmd, sizeof(cmd), "MD%c;", ttmode); retval = write_block(&rs->rigport, cmd, strlen(cmd)); @@ -740,14 +740,18 @@ static int trxmanager_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) { int retval; - - rig_debug(RIG_DEBUG_TRACE, "%s: vfo=%s\n", __func__, - rig_strvfo(vfo)); - + int n; + long iwidth = 0; + char tmode; + char cmd[MAXCMDLEN]; + char response[MAXCMDLEN] = ""; struct rig_state *rs = &rig->state; struct trxmanager_priv_data *priv = (struct trxmanager_priv_data *) rig->state.priv; + rig_debug(RIG_DEBUG_TRACE, "%s: vfo=%s\n", __func__, + rig_strvfo(vfo)); + if (check_vfo(vfo) == FALSE) { rig_debug(RIG_DEBUG_ERR, "%s: unsupported VFO %s\n", @@ -768,8 +772,6 @@ static int trxmanager_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, rig_debug(RIG_DEBUG_TRACE, "%s: using vfo=%s\n", __func__, rig_strvfo(vfo)); - char cmd[MAXCMDLEN]; - char response[MAXCMDLEN] = ""; snprintf(cmd, sizeof(cmd), "MD;"); retval = write_block(&rs->rigport, cmd, strlen(cmd)); @@ -785,8 +787,7 @@ static int trxmanager_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, rig_debug(RIG_DEBUG_ERR, "%s read_transaction failed\n", __func__); } - char tmode; - int n = sscanf(response, "MD%c;", &tmode); + n = sscanf(response, "MD%c;", &tmode); if (n != 1 || strlen(response) != 6) { @@ -865,7 +866,6 @@ static int trxmanager_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, return -RIG_EPROTO; } - long iwidth = 0; n = sscanf(response, "BW%ld;", &iwidth); if (n != 1) @@ -883,14 +883,16 @@ static int trxmanager_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, static int trxmanager_set_vfo(RIG *rig, vfo_t vfo) { int retval; - - rig_debug(RIG_DEBUG_TRACE, "%s: vfo=%s\n", __func__, - rig_strvfo(vfo)); - + char cmd[MAXCMDLEN]; + char response[MAXCMDLEN] = ""; struct rig_state *rs = &rig->state; struct trxmanager_priv_data *priv = (struct trxmanager_priv_data *) rig->state.priv; + + rig_debug(RIG_DEBUG_TRACE, "%s: vfo=%s\n", __func__, + rig_strvfo(vfo)); + if (check_vfo(vfo) == FALSE) { rig_debug(RIG_DEBUG_ERR, "%s: unsupported VFO %s\n", @@ -909,8 +911,6 @@ static int trxmanager_set_vfo(RIG *rig, vfo_t vfo) vfo = priv->vfo_curr; } - char cmd[MAXCMDLEN]; - char response[MAXCMDLEN] = ""; snprintf(cmd, sizeof(cmd), "FN%d;", vfo == RIG_VFO_A ? 0 : 1); retval = write_block(&rs->rigport, cmd, strlen(cmd)); @@ -936,13 +936,14 @@ static int trxmanager_get_vfo(RIG *rig, vfo_t *vfo) // TRXManager does not swap vfos // So we maintain our own internal state during set_vfo // This keeps the hamlib interface consistent with other rigs + struct trxmanager_priv_data *priv = (struct trxmanager_priv_data *) + rig->state.priv; + char vfoab; + rig_debug(RIG_DEBUG_TRACE, "%s\n", __func__); - struct trxmanager_priv_data *priv = (struct trxmanager_priv_data *) - rig->state.priv; - - char vfoab = priv->vfo_curr; + vfoab = priv->vfo_curr; switch (vfoab) { @@ -981,12 +982,13 @@ static int trxmanager_get_vfo(RIG *rig, vfo_t *vfo) static int trxmanager_set_split_freq(RIG *rig, vfo_t vfo, freq_t tx_freq) { int retval; + char cmd[MAXCMDLEN]; + char response[MAXCMDLEN] = ""; + struct rig_state *rs = &rig->state; rig_debug(RIG_DEBUG_TRACE, "%s: vfo=%s freq=%.1f\n", __func__, rig_strvfo(vfo), tx_freq); - struct rig_state *rs = &rig->state; - if (check_vfo(vfo) == FALSE) { rig_debug(RIG_DEBUG_ERR, "%s: unsupported VFO %s\n", @@ -994,8 +996,6 @@ static int trxmanager_set_split_freq(RIG *rig, vfo_t vfo, freq_t tx_freq) return -RIG_EINVAL; } - char cmd[MAXCMDLEN]; - char response[MAXCMDLEN] = ""; snprintf(cmd, sizeof(cmd), "XT%011lu;", (unsigned long) tx_freq); retval = write_block(&rs->rigport, cmd, strlen(cmd)); @@ -1021,9 +1021,10 @@ static int trxmanager_set_split_freq(RIG *rig, vfo_t vfo, freq_t tx_freq) */ static int trxmanager_get_split_freq(RIG *rig, vfo_t vfo, freq_t *tx_freq) { + int retval; rig_debug(RIG_DEBUG_TRACE, "%s: vfo=%s\n", __func__, rig_strvfo(vfo)); - int retval = trxmanager_get_freq(rig, RIG_VFO_B, tx_freq); + retval = trxmanager_get_freq(rig, RIG_VFO_B, tx_freq); return retval; } @@ -1035,12 +1036,15 @@ static int trxmanager_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, vfo_t tx_vfo) { int retval; + char cmd[MAXCMDLEN]; + char response[MAXCMDLEN] = ""; + split_t tsplit; + vfo_t ttx_vfo; + struct rig_state *rs = &rig->state; rig_debug(RIG_DEBUG_TRACE, "%s: tx_vfo=%s\n", __func__, rig_strvfo(tx_vfo)); - struct rig_state *rs = &rig->state; - if (tx_vfo == RIG_VFO_SUB || tx_vfo == RIG_VFO_TX) { tx_vfo = RIG_VFO_B; @@ -1056,8 +1060,6 @@ static int trxmanager_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, } #endif - split_t tsplit; - vfo_t ttx_vfo; retval = trxmanager_get_split_vfo(rig, vfo, &tsplit, &ttx_vfo); if (retval < 0) @@ -1067,8 +1069,6 @@ static int trxmanager_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, if (tsplit == split) { return RIG_OK; } // don't need to change it - char cmd[MAXCMDLEN]; - char response[MAXCMDLEN] = ""; snprintf(cmd, sizeof(cmd), "SP%c;", split ? '1' : '0'); retval = write_block(&rs->rigport, cmd, strlen(cmd)); @@ -1102,14 +1102,15 @@ static int trxmanager_get_split_vfo(RIG *rig, vfo_t vfo, split_t *split, vfo_t *tx_vfo) { int retval; - - rig_debug(RIG_DEBUG_TRACE, "%s\n", __func__); + int tsplit = 0; + int n; + char cmd[MAXCMDLEN]; + char response[MAXCMDLEN] = ""; struct rig_state *rs = &rig->state; struct trxmanager_priv_data *priv = (struct trxmanager_priv_data *) rig->state.priv; - char cmd[MAXCMDLEN]; - char response[MAXCMDLEN] = ""; + rig_debug(RIG_DEBUG_TRACE, "%s\n", __func__); snprintf(cmd, sizeof(cmd), "SP;"); retval = write_block(&rs->rigport, cmd, strlen(cmd)); @@ -1127,8 +1128,7 @@ static int trxmanager_get_split_vfo(RIG *rig, vfo_t vfo, split_t *split, } *tx_vfo = RIG_VFO_B; - int tsplit = 0; - int n = sscanf(response, "SP%d", &tsplit); + n = sscanf(response, "SP%d", &tsplit); if (n == 0) { @@ -1149,13 +1149,14 @@ static int trxmanager_set_split_freq_mode(RIG *rig, vfo_t vfo, freq_t freq, rmode_t mode, pbwidth_t width) { int retval; - - rig_debug(RIG_DEBUG_TRACE, "%s\n", __func__); - + char cmd[MAXCMDLEN]; + char response[MAXCMDLEN] = ""; struct rig_state *rs = &rig->state; struct trxmanager_priv_data *priv = (struct trxmanager_priv_data *) rig->state.priv; + rig_debug(RIG_DEBUG_TRACE, "%s\n", __func__); + if (vfo != RIG_VFO_CURR && vfo != RIG_VFO_TX) { return -RIG_ENTARGET; @@ -1163,8 +1164,6 @@ static int trxmanager_set_split_freq_mode(RIG *rig, vfo_t vfo, freq_t freq, // assume split is on B // - char cmd[MAXCMDLEN]; - char response[MAXCMDLEN] = ""; snprintf(cmd, sizeof(cmd), "XT%011lu;", (unsigned long)freq); retval = write_block(&rs->rigport, cmd, strlen(cmd)); @@ -1182,8 +1181,9 @@ static int trxmanager_set_split_freq_mode(RIG *rig, vfo_t vfo, freq_t freq, if (strlen(response) != 16 || strstr(response, cmd) == NULL) { + FILE *fp; rig_debug(RIG_DEBUG_ERR, "%s invalid response='%s'\n", __func__, response); - FILE *fp = fopen("debug.txt", "w+"); + fp = fopen("debug.txt", "w+"); fprintf(fp, "XT response=%s\n", response); fclose(fp); return -RIG_EPROTO; diff --git a/elad/elad.c b/elad/elad.c index 29abb3c44..648e42004 100644 --- a/elad/elad.c +++ b/elad/elad.c @@ -168,33 +168,26 @@ const struct confparams elad_cfg_params[] = */ int elad_transaction(RIG *rig, const char *cmdstr, char *data, size_t datasize) { + struct elad_priv_data *priv = rig->state.priv; + struct elad_priv_caps *caps = elad_caps(rig); + struct rig_state *rs; + int retval; + char cmdtrm[2]; /* Default Command/Reply termination char */ + char *cmd; + int len; + int retry_read = 0; + char buffer[ELAD_MAX_BUF_LEN]; /* use our own buffer since verification may need a longer buffer than the user supplied one */ rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || (!cmdstr && !datasize) || (datasize && !data)) + if ((!cmdstr && !datasize) || (datasize && !data)) { return -RIG_EINVAL; } - struct elad_priv_data *priv = rig->state.priv; - - struct elad_priv_caps *caps = elad_caps(rig); - - struct rig_state *rs; - - int retval; - - char cmdtrm[2]; /* Default Command/Reply termination char */ - - char *cmd; - - int len; - - int retry_read = 0; - rs = &rig->state; rs->hold_decode = 1; @@ -455,16 +448,11 @@ transaction_quit: int elad_safe_transaction(RIG *rig, const char *cmd, char *buf, size_t buf_size, size_t expected) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig || !cmd) - { - return -RIG_EINVAL; - } - int err; int retry = 0; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + if (expected == 0) { buf_size = 0; @@ -472,6 +460,7 @@ int elad_safe_transaction(RIG *rig, const char *cmd, char *buf, do { + size_t length; err = elad_transaction(rig, cmd, buf, buf_size); if (err != RIG_OK) /* return immediately on error as any @@ -480,7 +469,7 @@ int elad_safe_transaction(RIG *rig, const char *cmd, char *buf, return err; } - size_t length = strlen(buf); + length = strlen(buf); if (length != expected) /* worth retrying as some rigs occasionally send short results */ @@ -531,17 +520,11 @@ char rmode2elad(rmode_t mode, const rmode_t mode_table[]) int elad_init(RIG *rig) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - struct elad_priv_data *priv; - struct elad_priv_caps *caps = elad_caps(rig); + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + priv = malloc(sizeof(struct elad_priv_data)); if (priv == NULL) @@ -577,11 +560,6 @@ int elad_cleanup(RIG *rig) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - { - return -RIG_EINVAL; - } - free(rig->state.priv); rig->state.priv = NULL; @@ -590,23 +568,16 @@ int elad_cleanup(RIG *rig) int elad_open(RIG *rig) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - struct elad_priv_data *priv = rig->state.priv; - int err, i; - char *idptr; - char id[ELAD_MAX_BUF_LEN]; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + if (RIG_MODEL_TS590S == rig->caps->rig_model) { + char *dot_pos; /* we need the firmware version for these rigs to deal with f/w defects */ static char fw_version[7]; @@ -621,7 +592,7 @@ int elad_open(RIG *rig) /* store the data after the "FV" which should be a f/w version string of the form n.n e.g. 1.07 */ priv->fw_rev = &fw_version[2]; - char *dot_pos = strchr(fw_version, '.'); + dot_pos = strchr(fw_version, '.'); if (dot_pos) { @@ -737,12 +708,10 @@ int elad_open(RIG *rig) int elad_close(RIG *rig) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) { return -RIG_EINVAL; } - struct elad_priv_data *priv = rig->state.priv; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + if (!no_restore_ai && priv->trn_state >= 0) { /* restore AI state */ @@ -764,11 +733,6 @@ int elad_get_id(RIG *rig, char *buf) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - { - return -RIG_EINVAL; - } - return elad_transaction(rig, "ID", buf, ELAD_MAX_BUF_LEN); } @@ -779,17 +743,11 @@ int elad_get_id(RIG *rig, char *buf) */ static int elad_get_if(RIG *rig) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - struct elad_priv_data *priv = rig->state.priv; - struct elad_priv_caps *caps = elad_caps(rig); + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + return elad_safe_transaction(rig, "IF", priv->info, ELAD_MAX_BUF_LEN, caps->if_len); } @@ -802,15 +760,13 @@ static int elad_get_if(RIG *rig) */ int elad_set_vfo(RIG *rig, vfo_t vfo) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - + char cmdbuf[6]; + int retval; + char vfo_function; struct elad_priv_data *priv = rig->state.priv; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + /* Emulations do not need to set VFO since VFOB is a copy of VFOA * except for frequency. And we can change freq without changing VFOS * This prevents a 1.8 second delay in PowerSDR when switching VFOs @@ -818,10 +774,6 @@ int elad_set_vfo(RIG *rig, vfo_t vfo) */ if (priv->is_emulation && priv->curr_mode > 0) { return RIG_OK; } - char cmdbuf[6]; - int retval; - char vfo_function; - switch (vfo) { case RIG_VFO_A: @@ -905,16 +857,11 @@ int elad_set_vfo(RIG *rig, vfo_t vfo) */ int elad_set_vfo_main_sub(RIG *rig, vfo_t vfo) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - char cmdbuf[6]; char vfo_function; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + switch (vfo) { case RIG_VFO_MAIN: @@ -949,11 +896,6 @@ int elad_get_vfo_main_sub(RIG *rig, vfo_t *vfo) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !vfo) - { - return -RIG_EINVAL; - } - if (RIG_OK == (rc = elad_safe_transaction(rig, "CB", buf, sizeof(buf), 3))) { *vfo = buf[2] == '1' ? RIG_VFO_SUB : RIG_VFO_MAIN; @@ -969,21 +911,13 @@ int elad_get_vfo_main_sub(RIG *rig, vfo_t *vfo) */ int elad_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, vfo_t txvfo) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - struct elad_priv_data *priv = rig->state.priv; - char cmdbuf[6]; - int retval; - unsigned char vfo_function; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + if (RIG_MODEL_TS990S == rig->caps->rig_model) { if (split) @@ -1087,19 +1021,12 @@ int elad_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, vfo_t txvfo) */ int elad_set_split(RIG *rig, vfo_t vfo, split_t split, vfo_t txvfo) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - struct elad_priv_data *priv = rig->state.priv; - char cmdbuf[6]; - int retval; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + snprintf(cmdbuf, sizeof(cmdbuf), "SP%c", RIG_SPLIT_ON == split ? '1' : '0'); retval = elad_transaction(rig, cmdbuf, NULL, 0); @@ -1122,16 +1049,17 @@ int elad_set_split(RIG *rig, vfo_t vfo, split_t split, vfo_t txvfo) */ int elad_get_split_vfo_if(RIG *rig, vfo_t rxvfo, split_t *split, vfo_t *txvfo) { + struct elad_priv_data *priv = rig->state.priv; + int retval; + int transmitting; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !split || !txvfo) + if (!split || !txvfo) { return -RIG_EINVAL; } - struct elad_priv_data *priv = rig->state.priv; - - int retval; if (RIG_MODEL_TS990S == rig->caps->rig_model) { @@ -1182,7 +1110,7 @@ int elad_get_split_vfo_if(RIG *rig, vfo_t rxvfo, split_t *split, vfo_t *txvfo) /* find where is the txvfo.. */ /* Elecraft info[30] does not track split VFO when transmitting */ - int transmitting = '1' == priv->info[28] + transmitting = '1' == priv->info[28] && RIG_MODEL_K2 != rig->caps->rig_model && RIG_MODEL_K3 != rig->caps->rig_model; @@ -1219,15 +1147,11 @@ int elad_get_split_vfo_if(RIG *rig, vfo_t rxvfo, split_t *split, vfo_t *txvfo) */ int elad_get_vfo_if(RIG *rig, vfo_t *vfo) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig || !vfo) - { - return -RIG_EINVAL; - } - int retval; struct elad_priv_data *priv = rig->state.priv; + int split_and_transmitting; + + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); retval = elad_get_if(rig); @@ -1237,7 +1161,7 @@ int elad_get_vfo_if(RIG *rig, vfo_t *vfo) } /* Elecraft info[30] does not track split VFO when transmitting */ - int split_and_transmitting = + split_and_transmitting = '1' == priv->info[28] /* transmitting */ && '1' == priv->info[32] /* split */ && RIG_MODEL_K2 != rig->caps->rig_model @@ -1272,17 +1196,14 @@ int elad_get_vfo_if(RIG *rig, vfo_t *vfo) */ int elad_set_freq(RIG *rig, vfo_t vfo, freq_t freq) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - char freqbuf[16]; unsigned char vfo_letter = '\0'; vfo_t tvfo; int err; + struct elad_priv_data *priv = rig->state.priv; + + + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); tvfo = (vfo == RIG_VFO_CURR || vfo == RIG_VFO_VFO) ? rig->state.current_vfo : vfo; @@ -1320,8 +1241,6 @@ int elad_set_freq(RIG *rig, vfo_t vfo, freq_t freq) err = elad_transaction(rig, freqbuf, NULL, 0); - struct elad_priv_data *priv = rig->state.priv; - if (RIG_OK == err && RIG_MODEL_TS590S == rig->caps->rig_model && priv->fw_rev_uint <= 107 && ('A' == vfo_letter || 'B' == vfo_letter)) { @@ -1367,19 +1286,17 @@ int elad_set_freq(RIG *rig, vfo_t vfo, freq_t freq) int elad_get_freq_if(RIG *rig, vfo_t vfo, freq_t *freq) { + struct elad_priv_data *priv = rig->state.priv; + char freqbuf[50]; + int retval; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !freq) + if (!freq) { return -RIG_EINVAL; } - struct elad_priv_data *priv = rig->state.priv; - - char freqbuf[50]; - - int retval; - retval = elad_get_if(rig); if (retval != RIG_OK) @@ -1399,19 +1316,19 @@ int elad_get_freq_if(RIG *rig, vfo_t vfo, freq_t *freq) */ int elad_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig || !freq) - { - return -RIG_EINVAL; - } - char freqbuf[50]; char cmdbuf[4]; int retval; unsigned char vfo_letter = '\0'; vfo_t tvfo; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + + if (!freq) + { + return -RIG_EINVAL; + } + tvfo = (vfo == RIG_VFO_CURR || vfo == RIG_VFO_VFO) ? rig->state.current_vfo : vfo; @@ -1467,17 +1384,12 @@ int elad_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) int elad_get_rit(RIG *rig, vfo_t vfo, shortfreq_t *rit) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig || !rit) - { - return -RIG_EINVAL; - } - int retval; char buf[6]; struct elad_priv_data *priv = rig->state.priv; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + retval = elad_get_if(rig); if (retval != RIG_OK) @@ -1498,16 +1410,11 @@ int elad_get_rit(RIG *rig, vfo_t vfo, shortfreq_t *rit) */ int elad_set_rit(RIG *rig, vfo_t vfo, shortfreq_t rit) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - char buf[4]; int retval, i; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + if (rit == 0) { return elad_transaction(rig, "RC", NULL, 0); @@ -1537,7 +1444,7 @@ int elad_get_xit(RIG *rig, vfo_t vfo, shortfreq_t *rit) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !rit) + if (!rit) { return -RIG_EINVAL; } @@ -1549,11 +1456,6 @@ int elad_set_xit(RIG *rig, vfo_t vfo, shortfreq_t rit) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - { - return -RIG_EINVAL; - } - return elad_set_rit(rig, vfo, rit); } @@ -1561,11 +1463,6 @@ int elad_scan(RIG *rig, vfo_t vfo, scan_t scan, int ch) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - { - return -RIG_EINVAL; - } - if (RIG_MODEL_TS990S == rig->caps->rig_model) { return elad_transaction(rig, scan == RIG_SCAN_STOP ? "SC00" : "SC01", NULL, 0); @@ -1589,15 +1486,10 @@ int elad_scan(RIG *rig, vfo_t vfo, scan_t scan, int ch) /* XXX revise */ static int elad_set_filter(RIG *rig, pbwidth_t width) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - char *cmd; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + if (width <= Hz(250)) { cmd = "FL010009"; @@ -1627,25 +1519,15 @@ static int elad_set_filter(RIG *rig, pbwidth_t width) */ int elad_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - struct elad_priv_data *priv = rig->state.priv; - struct elad_priv_caps *caps = elad_caps(rig); - char buf[6]; - char kmode; - int err; - char data_mode = '0'; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + if (RIG_MODEL_TS590S == rig->caps->rig_model || RIG_MODEL_TS590SG == rig->caps->rig_model) { @@ -1776,16 +1658,16 @@ int elad_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) static int elad_get_filter(RIG *rig, pbwidth_t *width) { + int err, f, f1, f2; + char buf[10]; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !width) + if (!width) { return -RIG_EINVAL; } - int err, f, f1, f2; - char buf[10]; - err = elad_safe_transaction(rig, "FL", buf, sizeof(buf), 8); if (err != RIG_OK) @@ -1839,25 +1721,21 @@ static int elad_get_filter(RIG *rig, pbwidth_t *width) */ int elad_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) { + struct elad_priv_data *priv = rig->state.priv; + struct elad_priv_caps *caps = elad_caps(rig); + char cmd[4]; + char modebuf[10]; + int offs; + int retval; + int kmode; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !mode || !width) + if (!mode || !width) { return -RIG_EINVAL; } - struct elad_priv_data *priv = rig->state.priv; - - struct elad_priv_caps *caps = elad_caps(rig); - - char cmd[4]; - - char modebuf[10]; - - int offs; - - int retval; - /* for emulation do not read mode from VFOB as it is copy of VFOA */ /* we avoid the VFO swapping most of the time this way */ /* only need to get it if it has to be initialized */ @@ -1905,8 +1783,6 @@ int elad_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) return retval; } - int kmode; - if (modebuf[offs] <= '9') { kmode = modebuf[offs] - '0'; @@ -1962,17 +1838,17 @@ int elad_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) /* This is used when the radio does not support MD; for mode reading */ int elad_get_mode_if(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig || !mode || !width) - { - return -RIG_EINVAL; - } - int err; struct elad_priv_caps *caps = elad_caps(rig); struct elad_priv_data *priv = rig->state.priv; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + + if (!mode || !width) + { + return -RIG_EINVAL; + } + err = elad_get_if(rig); if (err != RIG_OK) @@ -1999,16 +1875,11 @@ int elad_get_mode_if(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) int elad_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - char levelbuf[16]; int i, elad_val; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + if (RIG_LEVEL_IS_FLOAT(level)) { elad_val = val.f * 255; @@ -2151,18 +2022,18 @@ int elad_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) int get_elad_level(RIG *rig, const char *cmd, float *f) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig || !cmd || !f) - { - return -RIG_EINVAL; - } - char lvlbuf[10]; int retval; int lvl; int len = strlen(cmd); + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + + if ( !cmd || !f) + { + return -RIG_EINVAL; + } + retval = elad_safe_transaction(rig, cmd, lvlbuf, 10, len + 3); if (retval != RIG_OK) @@ -2182,19 +2053,19 @@ int get_elad_level(RIG *rig, const char *cmd, float *f) */ int elad_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig || !val) - { - return -RIG_EINVAL; - } - char lvlbuf[ELAD_MAX_BUF_LEN]; char *cmd; int retval; int lvl; int i, ret, agclevel, len; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + + if (!val) + { + return -RIG_EINVAL; + } + switch (level) { case RIG_LEVEL_RAWSTR: @@ -2434,15 +2305,10 @@ int elad_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) int elad_set_func(RIG *rig, vfo_t vfo, setting_t func, int status) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - char buf[6]; /* longest cmd is GTxxx */ + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + switch (func) { case RIG_FUNC_NB: @@ -2515,16 +2381,16 @@ int elad_set_func(RIG *rig, vfo_t vfo, setting_t func, int status) */ int get_elad_func(RIG *rig, const char *cmd, int *status) { + int retval; + char buf[10]; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !cmd || !status) + if (!cmd || !status) { return -RIG_EINVAL; } - int retval; - char buf[10]; - retval = elad_safe_transaction(rig, cmd, buf, 10, 3); if (retval != RIG_OK) @@ -2542,16 +2408,16 @@ int get_elad_func(RIG *rig, const char *cmd, int *status) */ int elad_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status) { + char fctbuf[20]; + int retval; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !status) + if (!status) { return -RIG_EINVAL; } - char fctbuf[20]; - int retval; - switch (func) { case RIG_FUNC_FAGC: @@ -2616,17 +2482,12 @@ int elad_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status) */ int elad_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - const struct rig_caps *caps; char tonebuf[16]; int i; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + caps = rig->caps; /* TODO: replace 200 by something like RIGTONEMAX */ @@ -2651,17 +2512,12 @@ int elad_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone) int elad_set_ctcss_tone_tn(RIG *rig, vfo_t vfo, tone_t tone) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - const struct rig_caps *caps = rig->caps; char buf[16]; int i; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + /* XXX 40 is a fixed constant */ for (i = 0; caps->ctcss_list[i] != 0; i++) { @@ -2717,23 +2573,14 @@ int elad_set_ctcss_tone_tn(RIG *rig, vfo_t vfo, tone_t tone) */ int elad_get_ctcss_tone(RIG *rig, vfo_t vfo, tone_t *tone) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig || !tone) - { - return -RIG_EINVAL; - } - struct elad_priv_data *priv = rig->state.priv; - const struct rig_caps *caps; - char tonebuf[3]; - int i, retval; - unsigned int tone_idx; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + caps = rig->caps; if (RIG_MODEL_TS990S == caps->rig_model) @@ -2804,17 +2651,12 @@ int elad_get_ctcss_tone(RIG *rig, vfo_t vfo, tone_t *tone) int elad_set_ctcss_sql(RIG *rig, vfo_t vfo, tone_t tone) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - const struct rig_caps *caps = rig->caps; char buf[16]; int i; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + for (i = 0; caps->ctcss_list[i] != 0; i++) { if (tone == caps->ctcss_list[i]) @@ -2865,13 +2707,6 @@ int elad_set_ctcss_sql(RIG *rig, vfo_t vfo, tone_t tone) int elad_get_ctcss_sql(RIG *rig, vfo_t vfo, tone_t *tone) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig || !tone) - { - return -RIG_EINVAL; - } - const struct rig_caps *caps; char cmd[4]; char tonebuf[6]; @@ -2879,6 +2714,8 @@ int elad_get_ctcss_sql(RIG *rig, vfo_t vfo, tone_t *tone) int i, retval; unsigned int tone_idx; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + caps = rig->caps; if (RIG_MODEL_TS990S == rig->caps->rig_model) @@ -2951,16 +2788,11 @@ int elad_get_ctcss_sql(RIG *rig, vfo_t vfo, tone_t *tone) */ int elad_set_ant(RIG *rig, vfo_t vfo, ant_t ant) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - char cmd[8]; char a; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + switch (ant) { case RIG_ANT_1: a = '1'; break; @@ -3012,15 +2844,10 @@ int elad_set_ant(RIG *rig, vfo_t vfo, ant_t ant) int elad_set_ant_no_ack(RIG *rig, vfo_t vfo, ant_t ant) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - const char *cmd; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + switch (ant) { case RIG_ANT_1: @@ -3051,17 +2878,12 @@ int elad_set_ant_no_ack(RIG *rig, vfo_t vfo, ant_t ant) */ int elad_get_ant(RIG *rig, vfo_t vfo, ant_t *ant) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig || !ant) - { - return -RIG_EINVAL; - } - char ackbuf[8]; int offs; int retval; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + if (RIG_MODEL_TS990S == rig->caps->rig_model) { retval = elad_safe_transaction(rig, "AN0", ackbuf, sizeof(ackbuf), 7); @@ -3095,17 +2917,11 @@ int elad_get_ant(RIG *rig, vfo_t vfo, ant_t *ant) */ int elad_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig || !ptt) - { - return -RIG_EINVAL; - } - struct elad_priv_data *priv = rig->state.priv; - int retval; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + retval = elad_get_if(rig); if (retval != RIG_OK) @@ -3125,11 +2941,6 @@ int elad_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - { - return -RIG_EINVAL; - } - switch (ptt) { case RIG_PTT_ON: ptt_cmd = "TX"; break; @@ -3149,16 +2960,11 @@ int elad_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) int elad_set_ptt_safe(RIG *rig, vfo_t vfo, ptt_t ptt) { char busybuf[10]; - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - int err; ptt_t current_ptt; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + err = elad_get_ptt(rig, vfo, ¤t_ptt); if (err != RIG_OK) @@ -3181,15 +2987,12 @@ int elad_set_ptt_safe(RIG *rig, vfo_t vfo, ptt_t ptt) */ int elad_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig || !dcd) - { - return -RIG_EINVAL; - } - char busybuf[10]; int retval; + int offs = 2; + + + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); retval = elad_safe_transaction(rig, "BY", busybuf, 10, 3); @@ -3198,8 +3001,6 @@ int elad_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd) return retval; } - int offs = 2; - if (RIG_MODEL_TS990S == rig->caps->rig_model && RIG_VFO_SUB == vfo) { offs = 3; @@ -3217,11 +3018,6 @@ int elad_set_trn(RIG *rig, int trn) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - { - return -RIG_EINVAL; - } - if (RIG_MODEL_TS990S == rig->caps->rig_model) { return elad_transaction(rig, (trn == RIG_TRN_RIG) ? "AI2" : "AI0", NULL, 0); @@ -3237,9 +3033,12 @@ int elad_set_trn(RIG *rig, int trn) */ int elad_get_trn(RIG *rig, int *trn) { + char trnbuf[6]; + int retval; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !trn) + if (!trn) { return -RIG_EINVAL; } @@ -3254,9 +3053,6 @@ int elad_get_trn(RIG *rig, int *trn) return -RIG_ENAVAIL; } - char trnbuf[6]; - int retval; - retval = elad_safe_transaction(rig, "AI", trnbuf, 6, 3); if (retval != RIG_OK) @@ -3276,11 +3072,6 @@ int elad_set_powerstat(RIG *rig, powerstat_t status) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - { - return -RIG_EINVAL; - } - return elad_transaction(rig, (status == RIG_POWER_ON) ? "PS1" : "PS0", NULL, 0); } @@ -3289,16 +3080,16 @@ int elad_set_powerstat(RIG *rig, powerstat_t status) */ int elad_get_powerstat(RIG *rig, powerstat_t *status) { + char pwrbuf[6]; + int retval; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !status) + if (!status) { return -RIG_EINVAL; } - char pwrbuf[6]; - int retval; - retval = elad_safe_transaction(rig, "PS", pwrbuf, 6, 3); if (retval != RIG_OK) @@ -3316,16 +3107,11 @@ int elad_get_powerstat(RIG *rig, powerstat_t *status) */ int elad_reset(RIG *rig, reset_t reset) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - char rstbuf[6]; char rst; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + if (RIG_MODEL_TS990S == rig->caps->rig_model) { switch (reset) @@ -3370,22 +3156,18 @@ int elad_reset(RIG *rig, reset_t reset) */ int elad_send_morse(RIG *rig, vfo_t vfo, const char *msg) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig || !msg) - { - return -RIG_EINVAL; - } - char morsebuf[40], m2[30]; int msg_len, retval, i; const char *p; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + p = msg; msg_len = strlen(msg); while (msg_len > 0) { + int buff_len; /* * Check with "KY" if char buffer is available. * if not, sleep. @@ -3410,7 +3192,7 @@ int elad_send_morse(RIG *rig, vfo_t vfo, const char *msg) else { return -RIG_EINVAL; } } - int buff_len = msg_len > 24 ? 24 : msg_len; + buff_len = msg_len > 24 ? 24 : msg_len; strncpy(m2, p, 24); m2[24] = '\0'; @@ -3458,11 +3240,6 @@ int elad_vfo_op(RIG *rig, vfo_t vfo, vfo_op_t op) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - { - return -RIG_EINVAL; - } - switch (op) { case RIG_OP_UP: @@ -3489,15 +3266,10 @@ int elad_vfo_op(RIG *rig, vfo_t vfo, vfo_op_t op) */ int elad_set_mem(RIG *rig, vfo_t vfo, int ch) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - char buf[7]; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + if (RIG_MODEL_TS990S == rig->caps->rig_model) { char c; @@ -3543,18 +3315,13 @@ int elad_set_mem(RIG *rig, vfo_t vfo, int ch) */ int elad_get_mem(RIG *rig, vfo_t vfo, int *ch) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig || !ch) - { - return -RIG_EINVAL; - } - char cmd[4]; char membuf[10]; int offs; int retval; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + if (RIG_MODEL_TS990S == rig->caps->rig_model) { char c; @@ -3606,17 +3373,12 @@ int elad_get_mem(RIG *rig, vfo_t vfo, int *ch) int elad_get_mem_if(RIG *rig, vfo_t vfo, int *ch) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig || !ch) - { - return -RIG_EINVAL; - } - int err; char buf[4]; struct elad_priv_data *priv = rig->state.priv; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + err = elad_get_if(rig); if (err != RIG_OK) @@ -3634,20 +3396,15 @@ int elad_get_mem_if(RIG *rig, vfo_t vfo, int *ch) int elad_get_channel(RIG *rig, channel_t *chan) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig || !chan) - { - return -RIG_EINVAL; - } - int err; char buf[26]; char cmd[8]; + char bank = ' '; struct elad_priv_caps *caps = elad_caps(rig); + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + /* put channel num in the command string */ - char bank = ' '; if (rig->caps->rig_model == RIG_MODEL_TS940) { @@ -3746,20 +3503,20 @@ int elad_get_channel(RIG *rig, channel_t *chan) int elad_set_channel(RIG *rig, const channel_t *chan) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig || !chan) - { - return -RIG_EINVAL; - } - char buf[128]; char mode, tx_mode = 0; int err; int tone = 0; - + char bank = ' '; struct elad_priv_caps *caps = elad_caps(rig); + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + + if (!chan) + { + return -RIG_EINVAL; + } + mode = rmode2elad(chan->mode, caps->mode_table); if (mode < 0) @@ -3800,8 +3557,6 @@ int elad_set_channel(RIG *rig, const channel_t *chan) } } - char bank = ' '; - if (rig->caps->rig_model == RIG_MODEL_TS940) { bank = '0' + chan->bank_num; @@ -3839,15 +3594,10 @@ int elad_set_channel(RIG *rig, const channel_t *chan) int elad_set_ext_parm(RIG *rig, token_t token, value_t val) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - char buf[4]; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + switch (token) { case TOK_VOICE: @@ -3871,16 +3621,11 @@ int elad_set_ext_parm(RIG *rig, token_t token, value_t val) int elad_get_ext_parm(RIG *rig, token_t token, value_t *val) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig || !val) - { - return -RIG_EINVAL; - } - int err; struct elad_priv_data *priv = rig->state.priv; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + switch (token) { case TOK_FINE: @@ -3918,16 +3663,11 @@ int elad_get_ext_parm(RIG *rig, token_t token, value_t *val) */ const char *elad_get_info(RIG *rig) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return "*rig == NULL"; - } - char firmbuf[10]; int retval; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + retval = elad_safe_transaction(rig, "TY", firmbuf, 10, 5); if (retval != RIG_OK) @@ -3959,14 +3699,14 @@ const char *elad_get_info(RIG *rig) */ DECLARE_PROBERIG_BACKEND(elad) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - char idbuf[IDBUFSZ]; int id_len = -1, i, k_id; int retval = -1; int rates[] = { 115200, 57600, 38400, 19200, 9600, 4800, 1200, 0 }; /* possible baud rates */ int rates_idx; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + if (!port) { return RIG_MODEL_NONE; diff --git a/elad/fdm_duo.c b/elad/fdm_duo.c index 8ca6ec429..ea3e9a316 100644 --- a/elad/fdm_duo.c +++ b/elad/fdm_duo.c @@ -49,6 +49,7 @@ elad_fdm_duo_get_info(RIG *rig) { char firmbuf[50]; int retval; + size_t firm_len; retval = elad_transaction(rig, "TY", firmbuf, sizeof(firmbuf)); @@ -57,7 +58,7 @@ elad_fdm_duo_get_info(RIG *rig) return NULL; } - size_t firm_len = strlen(firmbuf); + firm_len = strlen(firmbuf); if (firm_len != 5) { diff --git a/icmarine/icmarine.c b/icmarine/icmarine.c index 0e24dbb1a..160d4013e 100644 --- a/icmarine/icmarine.c +++ b/icmarine/icmarine.c @@ -245,6 +245,7 @@ int icmarine_transaction(RIG *rig, const char *cmd, const char *param, char cmdbuf[BUFSZ + 1]; char respbuf[BUFSZ + 1]; char *p; + char *strip; int cmd_len = 0; unsigned csum = 0; @@ -321,7 +322,7 @@ int icmarine_transaction(RIG *rig, const char *cmd, const char *param, } /* strip from *checksum and after */ - char *strip = strrchr(respbuf, '*'); + strip = strrchr(respbuf, '*'); if (strip) { @@ -572,9 +573,11 @@ int icmarine_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) */ int icmarine_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) { + int retval; + rig_debug(RIG_DEBUG_TRACE, "%s:\n", __func__); - int retval = icmarine_transaction(rig, CMD_PTT, + retval = icmarine_transaction(rig, CMD_PTT, ptt == RIG_PTT_ON ? "TX" : "RX", NULL); if (retval != RIG_OK) diff --git a/icom/optoscan.c b/icom/optoscan.c index 6c74fe18d..0f05d6aec 100644 --- a/icom/optoscan.c +++ b/icom/optoscan.c @@ -502,6 +502,9 @@ int optoscan_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) if (level != RIG_LEVEL_AF) { int lvl_cn, lvl_sc; /* Command Number, Subcommand */ + unsigned char lvlbuf[MAXFRAMELEN]; + int cmdhead; + switch (level) { case RIG_LEVEL_RAWSTR: @@ -514,7 +517,6 @@ int optoscan_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) return -RIG_EINVAL; } - unsigned char lvlbuf[MAXFRAMELEN]; retval = icom_transaction(rig, lvl_cn, lvl_sc, NULL, 0, lvlbuf, &lvl_len); @@ -526,7 +528,7 @@ int optoscan_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) /* * strbuf should contain Cn,Sc,Data area */ - int cmdhead = (lvl_sc == -1) ? 1 : 2; + cmdhead = (lvl_sc == -1) ? 1 : 2; lvl_len -= cmdhead; if (lvlbuf[0] != ACK && lvlbuf[0] != lvl_cn) diff --git a/ioptron/rot_ioptron.c b/ioptron/rot_ioptron.c index 0b34fe33f..e451adacb 100644 --- a/ioptron/rot_ioptron.c +++ b/ioptron/rot_ioptron.c @@ -275,9 +275,9 @@ ioptron_get_info(ROT *rot) { static char info[16]; char str[6]; + int retval; rig_debug(RIG_DEBUG_TRACE, "%s called\n", __func__); - int retval; retval = ioptron_transaction(rot, ":MountInfo#", str, sizeof(str)); diff --git a/jrc/jrc.c b/jrc/jrc.c index 4b330f06b..83aa8c0c4 100644 --- a/jrc/jrc.c +++ b/jrc/jrc.c @@ -1404,9 +1404,11 @@ int jrc_set_chan(RIG *rig, const channel_t *chan) struct jrc_priv_caps *priv = (struct jrc_priv_caps *)rig->caps->priv; char cmdbuf[BUFSZ]; int retval, cmd_len; + rmode_t mode; + pbwidth_t width; + channel_t current; /* read first to get current values */ - channel_t current; current.channel_num = chan->channel_num; if ((retval = jrc_get_chan(rig, ¤t)) != RIG_OK) { return retval; } @@ -1418,8 +1420,8 @@ int jrc_set_chan(RIG *rig, const channel_t *chan) cmdbuf[4] = '1'; } - rmode_t mode = chan->mode; - pbwidth_t width = chan->width; + mode = chan->mode; + width = chan->width; if (RIG_MODE_NONE == mode) { mode = current.mode; } @@ -1512,6 +1514,8 @@ int jrc_get_chan(RIG *rig, channel_t *chan) if (mem_len != 6) { + char freqbuf[BUFSZ]; + if (membuf[4] == '1') { chan->levels[rig_setting2idx(RIG_LEVEL_ATT)].i = 20; @@ -1520,7 +1524,6 @@ int jrc_get_chan(RIG *rig, channel_t *chan) jrc2rig_mode(rig, membuf[6], membuf[5], &chan->mode, &chan->width); - char freqbuf[BUFSZ]; strncpy(freqbuf, membuf + 7, priv->max_freq_len); freqbuf[priv->max_freq_len] = 0x00; chan->freq = strtol(freqbuf, NULL, 10); diff --git a/kenwood/elecraft.c b/kenwood/elecraft.c index 027241091..46fa3821a 100644 --- a/kenwood/elecraft.c +++ b/kenwood/elecraft.c @@ -93,11 +93,13 @@ int elecraft_get_firmware_revision_level(RIG *rig, const char *cmd, int elecraft_open(RIG *rig) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called, rig version=%s\n", __func__, - rig->caps->version); - int err; char id[KENWOOD_MAX_BUF_LEN]; + struct kenwood_priv_data *priv = rig->state.priv; + + + rig_debug(RIG_DEBUG_VERBOSE, "%s called, rig version=%s\n", __func__, + rig->caps->version); /* Actual read extension levels from radio. * @@ -106,8 +108,6 @@ int elecraft_open(RIG *rig) * elecraft_get_extension_level() private function during elecraft_open() * and thereafter shall be treated as READ ONLY! */ - struct kenwood_priv_data *priv = rig->state.priv; - /* As k3_fw_rev is declared static, it is persistent so the structure * can point to it. This way was chosen to allow the compiler to * calculate the size of the array to resolve a bug found by gcc 4.8.x @@ -245,16 +245,16 @@ int elecraft_open(RIG *rig) int verify_kenwood_id(RIG *rig, char *id) { + int err; + char *idptr; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !id) + if (!id) { return -RIG_EINVAL; } - int err; - char *idptr; - /* Check for an Elecraft K2|K3 which returns "017" */ err = kenwood_get_id(rig, id); @@ -297,17 +297,17 @@ int verify_kenwood_id(RIG *rig, char *id) int elecraft_get_extension_level(RIG *rig, const char *cmd, int *ext_level) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig || !ext_level) - { - return -RIG_EINVAL; - } - int err, i; char buf[KENWOOD_MAX_BUF_LEN]; char *bufptr; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + + if (!ext_level) + { + return -RIG_EINVAL; + } + err = kenwood_safe_transaction(rig, cmd, buf, KENWOOD_MAX_BUF_LEN, 3); if (err != RIG_OK) @@ -342,17 +342,17 @@ int elecraft_get_extension_level(RIG *rig, const char *cmd, int *ext_level) int elecraft_get_firmware_revision_level(RIG *rig, const char *cmd, char *fw_rev, size_t fw_rev_sz) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig || !fw_rev) - { - return -RIG_EINVAL; - } - int err; char *bufptr; char buf[KENWOOD_MAX_BUF_LEN]; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + + if (!fw_rev) + { + return -RIG_EINVAL; + } + /* Get the actual firmware revision number. */ err = kenwood_transaction(rig, cmd, buf, sizeof(buf)); diff --git a/kenwood/flex.c b/kenwood/flex.c index 10701c8ac..f2ffd2586 100644 --- a/kenwood/flex.c +++ b/kenwood/flex.c @@ -34,16 +34,16 @@ int verify_flexradio_id(RIG *rig, char *id) { + int err; + char *idptr; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !id) + if (!id) { return -RIG_EINVAL; } - int err; - char *idptr; - /* Check for a Flex 6700 which returns "904" */ err = kenwood_get_id(rig, id); @@ -110,19 +110,12 @@ int verify_flexradio_id(RIG *rig, char *id) int flexradio_open(RIG *rig) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - struct kenwood_priv_data *priv = rig->state.priv; - int err; - char id[FLEXRADIO_MAX_BUF_LEN]; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + //struct flexradio_priv_data *priv = rig->state.priv; /* Use check for "ID017;" to verify rig is reachable */ diff --git a/kenwood/flex6xxx.c b/kenwood/flex6xxx.c index f5b013838..fe0aaee22 100644 --- a/kenwood/flex6xxx.c +++ b/kenwood/flex6xxx.c @@ -94,21 +94,18 @@ static int dsp_bw_dig[DSP_BW_NUM] = static int flex6k_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) { + struct kenwood_priv_caps *caps = kenwood_caps(rig); + char modebuf[10]; + int index; + int retval; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !mode || !width) + if (!mode || !width) { return -RIG_EINVAL; } - struct kenwood_priv_caps *caps = kenwood_caps(rig); - - char modebuf[10]; - - int index; - - int retval; - retval = kenwood_safe_transaction(rig, "MD", modebuf, 6, 3); if (retval != RIG_OK) @@ -243,23 +240,14 @@ static int flex6k_find_width(rmode_t mode, pbwidth_t width, int *ridx) static int flex6k_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - struct kenwood_priv_caps *caps = kenwood_caps(rig); - char buf[10]; - char kmode; - int idx; - int err; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + kmode = rmode2kenwood(mode, caps->mode_table); if (kmode < 0) diff --git a/kenwood/k2.c b/kenwood/k2.c index 3dc074bdc..b3028b08b 100644 --- a/kenwood/k2.c +++ b/kenwood/k2.c @@ -256,16 +256,11 @@ const struct rig_caps k2_caps = */ int k2_open(RIG *rig) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - int err; struct kenwood_priv_data *priv = rig->state.priv; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + err = elecraft_open(rig); if (err != RIG_OK) @@ -292,12 +287,6 @@ int k2_open(RIG *rig) int k2_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } int err; char f; @@ -305,6 +294,8 @@ int k2_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) struct kenwood_priv_data *priv = rig->state.priv; shortfreq_t freq = 0; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + /* Select the filter array per mode. */ switch (mode) { @@ -391,6 +382,8 @@ int k2_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) if (width != RIG_PASSBAND_NOCHANGE) { + char fcmd[16]; + err = kenwood_transaction(rig, "K22", NULL, 0); if (err != RIG_OK) @@ -399,7 +392,6 @@ int k2_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) } /* Construct the filter command and set the radio mode and width*/ - char fcmd[16]; snprintf(fcmd, 8, "FW0000%c", f); /* Set the filter slot */ @@ -430,19 +422,19 @@ int k2_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) int k2_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig || !mode || !width) - { - return -RIG_EINVAL; - } - int err; char buf[KENWOOD_MAX_BUF_LEN]; char tmp[16]; char *bufptr; pbwidth_t temp_w; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + + if (!mode || !width) + { + return -RIG_EINVAL; + } + err = kenwood_get_mode(rig, vfo, mode, &temp_w); if (err != RIG_OK) @@ -496,17 +488,17 @@ int k2_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) */ int k2_get_ext_level(RIG *rig, vfo_t vfo, token_t token, value_t *val) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig || !val) - { - return -RIG_EINVAL; - } - char buf[KENWOOD_MAX_BUF_LEN]; int err; const struct confparams *cfp; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + + if (!val) + { + return -RIG_EINVAL; + } + cfp = rig_ext_lookup_tok(rig, token); switch (token) @@ -549,19 +541,19 @@ int k2_get_ext_level(RIG *rig, vfo_t vfo, token_t token, value_t *val) */ int k2_probe_mdfw(RIG *rig, struct kenwood_priv_data *priv) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig || !priv) - { - return -RIG_EINVAL; - } - int err, i, c; char buf[KENWOOD_MAX_BUF_LEN]; char mode[16]; char fw[16]; char cmd[16]; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + + if (!priv) + { + return -RIG_EINVAL; + } + /* The K2 extension level has been stored by elecraft_open(). Now set rig * to K22 for detailed query of mode and filter width values... */ @@ -683,15 +675,15 @@ int k2_probe_mdfw(RIG *rig, struct kenwood_priv_data *priv) /* Restore mode, filter, and ext_lvl to original values */ int k2_mdfw_rest(RIG *rig, const char *mode, const char *fw) { + int err; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !mode || !fw) + if (!mode || !fw) { return -RIG_EINVAL; } - int err; - if (strlen(mode) != 3 || strlen(fw) != 7) { return -RIG_EINVAL; @@ -725,19 +717,19 @@ int k2_mdfw_rest(RIG *rig, const char *mode, const char *fw) /* Populate k2_filt_lst_s structure for each mode */ int k2_pop_fw_lst(RIG *rig, const char *cmd) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig || !cmd) - { - return -RIG_EINVAL; - } - int err, f; char fcmd[16]; char buf[KENWOOD_MAX_BUF_LEN]; char tmp[16]; struct k2_filt_lst_s *flt; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + + if (!cmd) + { + return -RIG_EINVAL; + } + /* Store filter data in the correct structure depending on mode */ if (strcmp(cmd, "MD1") == 0) { @@ -766,6 +758,8 @@ int k2_pop_fw_lst(RIG *rig, const char *cmd) for (f = 1; f < 5; f++) { + char *bufptr = buf; + snprintf(fcmd, 8, "FW0000%d", f); err = kenwood_transaction(rig, fcmd, NULL, 0); @@ -787,8 +781,6 @@ int k2_pop_fw_lst(RIG *rig, const char *cmd) * f = crystal filter slot number--1-4 * a = audio filter slot number--0-2 */ - char *bufptr = buf; - strncpy(tmp, bufptr + 2, 4); tmp[4] = '\0'; flt->filt_list[f - 1].width = atoi(tmp); diff --git a/kenwood/k3.c b/kenwood/k3.c index 75a4424d7..040356244 100644 --- a/kenwood/k3.c +++ b/kenwood/k3.c @@ -783,18 +783,18 @@ const struct rig_caps kx2_caps = int k3_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig || !mode || !width) - { - return -RIG_EINVAL; - } - char buf[KENWOOD_MAX_BUF_LEN]; int err; rmode_t temp_m; pbwidth_t temp_w; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + + if (!mode || !width) + { + return -RIG_EINVAL; + } + err = kenwood_get_mode(rig, vfo, &temp_m, &temp_w); if (err != RIG_OK) @@ -903,16 +903,11 @@ int k3_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) int k3_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - int err; char cmd_m[4]; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + switch (mode) { case RIG_MODE_PKTLSB: @@ -947,6 +942,7 @@ int k3_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) if (width != RIG_PASSBAND_NOCHANGE) { + char cmd_s[64]; /* and set the requested bandwidth. On my K3, the bandwidth is rounded * down to the nearest 50 Hz, i.e. sending BW0239; will cause the bandwidth * to be set to 2.350 kHz. As the width must be divided by 10, 10 Hz values @@ -979,7 +975,6 @@ int k3_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) width = pb_wid; } - char cmd_s[64]; snprintf(cmd_s, sizeof(cmd_s), "BW%04ld", width / 10); err = kenwood_transaction(rig, cmd_s, NULL, 0); @@ -1015,15 +1010,10 @@ int k3_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) int k3_set_vfo(RIG *rig, vfo_t vfo) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - int err; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + switch (vfo) { case RIG_VFO_B: @@ -1058,15 +1048,10 @@ int k3_set_vfo(RIG *rig, vfo_t vfo) */ int k3_set_ext_level(RIG *rig, vfo_t vfo, token_t token, value_t val) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - char buf[10]; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + switch (token) { case TOK_RIT_CLR: @@ -1112,16 +1097,16 @@ int k3_set_ext_level(RIG *rig, vfo_t vfo, token_t token, value_t val) */ int k3_get_ext_level(RIG *rig, vfo_t vfo, token_t token, value_t *val) { + char buf[KENWOOD_MAX_BUF_LEN]; + int err; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !val) + if (!val) { return -RIG_EINVAL; } - char buf[KENWOOD_MAX_BUF_LEN]; - int err; - switch (token) { case TOK_IF_FREQ: @@ -1180,14 +1165,9 @@ int k3_get_ext_level(RIG *rig, vfo_t vfo, token_t token, value_t *val) */ int k3_set_rit(RIG *rig, vfo_t vfo, shortfreq_t rit) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - int err; - if (!rig) - { - return -RIG_EINVAL; - } + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); err = set_rit_xit(rig, rit); @@ -1206,14 +1186,9 @@ int k3_set_rit(RIG *rig, vfo_t vfo, shortfreq_t rit) */ int k3_set_xit(RIG *rig, vfo_t vfo, shortfreq_t rit) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - int err; - if (!rig) - { - return -RIG_EINVAL; - } + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); err = set_rit_xit(rig, rit); @@ -1231,16 +1206,14 @@ int k3_set_xit(RIG *rig, vfo_t vfo, shortfreq_t rit) */ int k3_set_split_mode(RIG *rig, vfo_t vfo, rmode_t tx_mode, pbwidth_t tx_width) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - + struct kenwood_priv_caps *caps = kenwood_caps(rig); + char buf[32]; + char kmode; int err; char cmd_m[4]; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + switch (tx_mode) { case RIG_MODE_PKTLSB: @@ -1283,10 +1256,6 @@ int k3_set_split_mode(RIG *rig, vfo_t vfo, rmode_t tx_mode, pbwidth_t tx_width) #endif - struct kenwood_priv_caps *caps = kenwood_caps(rig); - char buf[32]; - char kmode; - kmode = rmode2kenwood(tx_mode, caps->mode_table); if (kmode < 0) @@ -1306,6 +1275,7 @@ int k3_set_split_mode(RIG *rig, vfo_t vfo, rmode_t tx_mode, pbwidth_t tx_width) if (tx_width != RIG_PASSBAND_NOCHANGE) { + char cmd_s[32]; /* and set the requested bandwidth. On my K3, the bandwidth is rounded * down to the nearest 50 Hz, i.e. sending BW0239; will cause the bandwidth * to be set to 2.350 kHz. As the width must be divided by 10, 10 Hz values @@ -1338,7 +1308,6 @@ int k3_set_split_mode(RIG *rig, vfo_t vfo, rmode_t tx_mode, pbwidth_t tx_width) tx_width = pb_wid; } - char cmd_s[32]; snprintf(cmd_s, sizeof(cmd_s), "BW$%04ld", tx_width / 10); err = kenwood_transaction(rig, cmd_s, NULL, 0); @@ -1358,19 +1327,18 @@ int k3_set_split_mode(RIG *rig, vfo_t vfo, rmode_t tx_mode, pbwidth_t tx_width) int k3_get_split_mode(RIG *rig, vfo_t vfo, rmode_t *tx_mode, pbwidth_t *tx_width) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig || !tx_mode || !tx_width) - { - return -RIG_EINVAL; - } - char buf[KENWOOD_MAX_BUF_LEN]; int err; rmode_t temp_m; - struct kenwood_priv_caps *caps = kenwood_caps(rig); + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + + if (!tx_mode || !tx_width) + { + return -RIG_EINVAL; + } + err = kenwood_safe_transaction(rig, "MD$", buf, KENWOOD_MAX_BUF_LEN, 4); if (err != RIG_OK) @@ -1460,16 +1428,11 @@ int k3_get_split_mode(RIG *rig, vfo_t vfo, rmode_t *tx_mode, int k3_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - char levelbuf[16]; int kenwood_val; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + if (RIG_LEVEL_IS_FLOAT(level)) { kenwood_val = val.f * 255; @@ -1571,18 +1534,18 @@ int k3_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) */ int k3_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig || !val) - { - return -RIG_EINVAL; - } - char lvlbuf[50]; int retval; int lvl; struct kenwood_priv_data *priv = rig->state.priv; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + + if (!val) + { + return -RIG_EINVAL; + } + switch (level) { float firmware_have; @@ -1867,15 +1830,10 @@ int kx3_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) int k3_set_func(RIG *rig, vfo_t vfo, setting_t func, int status) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - char buf[10]; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + switch (func) { case RIG_FUNC_APF: @@ -1906,7 +1864,7 @@ int k3_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !status) + if (!status) { return -RIG_EINVAL; } @@ -1942,14 +1900,9 @@ int k3_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status) */ int set_rit_xit(RIG *rig, shortfreq_t rit) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - int err; - if (!rig) - { - return -RIG_EINVAL; - } + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); if (rit == 0) { @@ -1990,18 +1943,12 @@ int set_rit_xit(RIG *rig, shortfreq_t rit) int k3_set_nb_level(RIG *rig, float dsp_nb, float if_nb) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - char lvlbuf[16]; - int dsp_nb_raw = 0; int if_nb_raw = 0; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + if (dsp_nb >= 0) { dsp_nb_raw = (int)(dsp_nb * 21.0f); @@ -2044,19 +1991,13 @@ int k3_set_nb_level(RIG *rig, float dsp_nb, float if_nb) int k3_get_nb_level(RIG *rig, float *dsp_nb, float *if_nb) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - char lvlbuf[16]; int retval; - int dsp_nb_raw; int if_nb_raw; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + retval = kenwood_safe_transaction(rig, "NL", lvlbuf, sizeof(lvlbuf), 6); if (retval != RIG_OK) @@ -2082,20 +2023,14 @@ int k3_get_nb_level(RIG *rig, float *dsp_nb, float *if_nb) int k3_get_bar_graph_level(RIG *rig, float *smeter, float *pwr, float *alc, int *mode_tx) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - char lvlbuf[16]; int retval; - int tm_raw; int bg_raw; char mode; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + // Determine transmit metering mode: 0 = RF POWER, 1 = ALC retval = get_kenwood_func(rig, "TM", &tm_raw); @@ -2185,18 +2120,12 @@ int k3_get_bar_graph_level(RIG *rig, float *smeter, float *pwr, float *alc, int kx3_get_bar_graph_level(RIG *rig, float *level) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - char lvlbuf[16]; int retval; - int bg_raw; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + retval = kenwood_safe_transaction(rig, "BG", lvlbuf, sizeof(lvlbuf), 4); if (retval != RIG_OK) diff --git a/kenwood/kenwood.c b/kenwood/kenwood.c index 320fa2a77..f9ee2a435 100644 --- a/kenwood/kenwood.c +++ b/kenwood/kenwood.c @@ -222,33 +222,25 @@ const struct confparams kenwood_cfg_params[] = int kenwood_transaction(RIG *rig, const char *cmdstr, char *data, size_t datasize) { - char buffer[KENWOOD_MAX_BUF_LEN]; /* use our own buffer since + char buffer[KENWOOD_MAX_BUF_LEN]; /* use our own buffer since verification may need a longer buffer than the user supplied one */ + char cmdtrm[2]; /* Default Command/Reply termination char */ + int retval; + char *cmd; + int len; + int retry_read = 0; + struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_caps *caps = kenwood_caps(rig); + struct rig_state *rs; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || (!cmdstr && !datasize) || (datasize && !data)) + if ((!cmdstr && !datasize) || (datasize && !data)) { return -RIG_EINVAL; } - struct kenwood_priv_data *priv = rig->state.priv; - - struct kenwood_priv_caps *caps = kenwood_caps(rig); - - struct rig_state *rs; - - int retval; - - char cmdtrm[2]; /* Default Command/Reply termination char */ - - char *cmd; - - int len; - - int retry_read = 0; - rs = &rig->state; rs->hold_decode = 1; @@ -508,16 +500,16 @@ transaction_quit: int kenwood_safe_transaction(RIG *rig, const char *cmd, char *buf, size_t buf_size, size_t expected) { + int err; + int retry = 0; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !cmd) + if (!cmd) { return -RIG_EINVAL; } - int err; - int retry = 0; - memset(buf, 0, buf_size); if (expected == 0) @@ -527,6 +519,7 @@ int kenwood_safe_transaction(RIG *rig, const char *cmd, char *buf, do { + size_t length; err = kenwood_transaction(rig, cmd, buf, buf_size); if (err != RIG_OK) /* return immediately on error as any @@ -535,7 +528,7 @@ int kenwood_safe_transaction(RIG *rig, const char *cmd, char *buf, return err; } - size_t length = strlen(buf); + length = strlen(buf); if (length != expected) /* worth retrying as some rigs occasionally send short results */ @@ -586,17 +579,11 @@ char rmode2kenwood(rmode_t mode, const rmode_t mode_table[]) int kenwood_init(RIG *rig) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called, version %s\n", __func__, BACKEND_VER); - - if (!rig) - { - return -RIG_EINVAL; - } - struct kenwood_priv_data *priv; - struct kenwood_priv_caps *caps = kenwood_caps(rig); + rig_debug(RIG_DEBUG_VERBOSE, "%s called, version %s\n", __func__, BACKEND_VER); + priv = malloc(sizeof(struct kenwood_priv_data)); if (priv == NULL) @@ -632,11 +619,6 @@ int kenwood_cleanup(RIG *rig) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - { - return -RIG_EINVAL; - } - free(rig->state.priv); rig->state.priv = NULL; @@ -645,25 +627,18 @@ int kenwood_cleanup(RIG *rig) int kenwood_open(RIG *rig) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - struct kenwood_priv_data *priv = rig->state.priv; - int err, i; - char *idptr; - char id[KENWOOD_MAX_BUF_LEN]; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + if (RIG_MODEL_TS590S == rig->caps->rig_model) { /* we need the firmware version for these rigs to deal with f/w defects */ static char fw_version[7]; + char *dot_pos; err = kenwood_transaction(rig, "FV", fw_version, sizeof(fw_version)); @@ -676,7 +651,7 @@ int kenwood_open(RIG *rig) /* store the data after the "FV" which should be a f/w version string of the form n.n e.g. 1.07 */ priv->fw_rev = &fw_version[2]; - char *dot_pos = strchr(fw_version, '.'); + dot_pos = strchr(fw_version, '.'); if (dot_pos) { @@ -765,6 +740,9 @@ int kenwood_open(RIG *rig) if (kenwood_id_string_list[i].model == rig->caps->rig_model) { + int retval; + split_t split; + vfo_t tx_vfo; /* get current AI state so it can be restored */ kenwood_get_trn(rig, &priv->trn_state); /* ignore errors */ /* Currently we cannot cope with AI mode so turn it off in @@ -772,9 +750,7 @@ int kenwood_open(RIG *rig) kenwood_set_trn(rig, RIG_TRN_OFF); /* ignore status in case it's not supported */ // call get_split to fill in current split and tx_vfo status - split_t split; - vfo_t tx_vfo; - int retval = kenwood_get_split_vfo_if(rig, RIG_VFO_A, &split, &tx_vfo); + retval = kenwood_get_split_vfo_if(rig, RIG_VFO_A, &split, &tx_vfo); if (retval != RIG_OK) { @@ -805,12 +781,10 @@ int kenwood_open(RIG *rig) int kenwood_close(RIG *rig) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) { return -RIG_EINVAL; } - struct kenwood_priv_data *priv = rig->state.priv; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + if (!no_restore_ai && priv->trn_state >= 0) { /* restore AI state */ @@ -832,11 +806,6 @@ int kenwood_get_id(RIG *rig, char *buf) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - { - return -RIG_EINVAL; - } - return kenwood_transaction(rig, "ID", buf, KENWOOD_MAX_BUF_LEN); } @@ -847,17 +816,11 @@ int kenwood_get_id(RIG *rig, char *buf) */ static int kenwood_get_if(RIG *rig) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - struct kenwood_priv_data *priv = rig->state.priv; - struct kenwood_priv_caps *caps = kenwood_caps(rig); + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + return kenwood_safe_transaction(rig, "IF", priv->info, KENWOOD_MAX_BUF_LEN, caps->if_len); } @@ -870,14 +833,13 @@ static int kenwood_get_if(RIG *rig) */ int kenwood_set_vfo(RIG *rig, vfo_t vfo) { + char cmdbuf[6]; + int retval; + char vfo_function; + struct kenwood_priv_data *priv = rig->state.priv; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - { - return -RIG_EINVAL; - } - - struct kenwood_priv_data *priv = rig->state.priv; /* Emulations do not need to set VFO since VFOB is a copy of VFOA * except for frequency. And we can change freq without changing VFOS @@ -886,10 +848,6 @@ int kenwood_set_vfo(RIG *rig, vfo_t vfo) */ if (priv->is_emulation && priv->curr_mode > 0) { return RIG_OK; } - char cmdbuf[6]; - int retval; - char vfo_function; - switch (vfo) { case RIG_VFO_A: @@ -974,16 +932,11 @@ int kenwood_set_vfo(RIG *rig, vfo_t vfo) */ int kenwood_set_vfo_main_sub(RIG *rig, vfo_t vfo) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - char cmdbuf[6]; char vfo_function; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + switch (vfo) { case RIG_VFO_MAIN: @@ -1018,7 +971,7 @@ int kenwood_get_vfo_main_sub(RIG *rig, vfo_t *vfo) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !vfo) + if (!vfo) { return -RIG_EINVAL; } @@ -1038,21 +991,13 @@ int kenwood_get_vfo_main_sub(RIG *rig, vfo_t *vfo) */ int kenwood_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, vfo_t txvfo) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - struct kenwood_priv_data *priv = rig->state.priv; - char cmdbuf[6]; - int retval; - unsigned char vfo_function; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + if (RIG_MODEL_TS990S == rig->caps->rig_model) { if (split) @@ -1159,19 +1104,12 @@ int kenwood_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, vfo_t txvfo) */ int kenwood_set_split(RIG *rig, vfo_t vfo, split_t split, vfo_t txvfo) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - struct kenwood_priv_data *priv = rig->state.priv; - char cmdbuf[6]; - int retval; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + snprintf(cmdbuf, sizeof(cmdbuf), "SP%c", RIG_SPLIT_ON == split ? '1' : '0'); retval = kenwood_transaction(rig, cmdbuf, NULL, 0); @@ -1198,17 +1136,18 @@ int kenwood_set_split(RIG *rig, vfo_t vfo, split_t split, vfo_t txvfo) int kenwood_get_split_vfo_if(RIG *rig, vfo_t rxvfo, split_t *split, vfo_t *txvfo) { + int transmitting; + int retval; + struct kenwood_priv_data *priv = rig->state.priv; + + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !split || !txvfo) + if (!split || !txvfo) { return -RIG_EINVAL; } - struct kenwood_priv_data *priv = rig->state.priv; - - int retval; - if (RIG_MODEL_TS990S == rig->caps->rig_model) { char buf[4]; @@ -1261,7 +1200,7 @@ int kenwood_get_split_vfo_if(RIG *rig, vfo_t rxvfo, split_t *split, /* find where is the txvfo.. */ /* Elecraft info[30] does not track split VFO when transmitting */ - int transmitting = '1' == priv->info[28] + transmitting = '1' == priv->info[28] && RIG_MODEL_K2 != rig->caps->rig_model && RIG_MODEL_K3 != rig->caps->rig_model; @@ -1302,16 +1241,17 @@ int kenwood_get_split_vfo_if(RIG *rig, vfo_t rxvfo, split_t *split, */ int kenwood_get_vfo_if(RIG *rig, vfo_t *vfo) { + int retval; + int split_and_transmitting; + struct kenwood_priv_data *priv = rig->state.priv; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !vfo) + if (!vfo) { return -RIG_EINVAL; } - int retval; - struct kenwood_priv_data *priv = rig->state.priv; - retval = kenwood_get_if(rig); if (retval != RIG_OK) @@ -1320,7 +1260,7 @@ int kenwood_get_vfo_if(RIG *rig, vfo_t *vfo) } /* Elecraft info[30] does not track split VFO when transmitting */ - int split_and_transmitting = + split_and_transmitting = '1' == priv->info[28] /* transmitting */ && '1' == priv->info[32] /* split */ && RIG_MODEL_K2 != rig->caps->rig_model @@ -1358,20 +1298,14 @@ int kenwood_get_vfo_if(RIG *rig, vfo_t *vfo) */ int kenwood_set_freq(RIG *rig, vfo_t vfo, freq_t freq) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - char freqbuf[16]; unsigned char vfo_letter = '\0'; vfo_t tvfo; int err; - struct kenwood_priv_data *priv = rig->state.priv; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + tvfo = (vfo == RIG_VFO_CURR || vfo == RIG_VFO_VFO) ? rig->state.current_vfo : vfo; @@ -1464,19 +1398,17 @@ int kenwood_set_freq(RIG *rig, vfo_t vfo, freq_t freq) int kenwood_get_freq_if(RIG *rig, vfo_t vfo, freq_t *freq) { + struct kenwood_priv_data *priv = rig->state.priv; + char freqbuf[50]; + int retval; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !freq) + if (!freq) { return -RIG_EINVAL; } - struct kenwood_priv_data *priv = rig->state.priv; - - char freqbuf[50]; - - int retval; - retval = kenwood_get_if(rig); if (retval != RIG_OK) @@ -1496,18 +1428,19 @@ int kenwood_get_freq_if(RIG *rig, vfo_t vfo, freq_t *freq) */ int kenwood_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig || !freq) - { - return -RIG_EINVAL; - } - char freqbuf[50]; char cmdbuf[4]; int retval; unsigned char vfo_letter = '\0'; vfo_t tvfo; + struct kenwood_priv_data *priv = rig->state.priv; + + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + + if (!freq) + { + return -RIG_EINVAL; + } tvfo = (vfo == RIG_VFO_CURR || vfo == RIG_VFO_VFO) ? rig->state.current_vfo : vfo; @@ -1520,8 +1453,6 @@ int kenwood_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) if (RIG_OK != retval) { return retval; } } - struct kenwood_priv_data *priv = rig->state.priv; - /* memory frequency cannot be read with an Fx command, use IF */ if (tvfo == RIG_VFO_MEM) { @@ -1572,17 +1503,17 @@ int kenwood_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) int kenwood_get_rit(RIG *rig, vfo_t vfo, shortfreq_t *rit) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig || !rit) - { - return -RIG_EINVAL; - } - int retval; char buf[6]; struct kenwood_priv_data *priv = rig->state.priv; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + + if (!rit) + { + return -RIG_EINVAL; + } + retval = kenwood_get_if(rig); if (retval != RIG_OK) @@ -1603,16 +1534,11 @@ int kenwood_get_rit(RIG *rig, vfo_t vfo, shortfreq_t *rit) */ int kenwood_set_rit(RIG *rig, vfo_t vfo, shortfreq_t rit) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - char buf[4]; int retval, i; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + if (rit == 0) { return kenwood_transaction(rig, "RC", NULL, 0); @@ -1642,11 +1568,6 @@ int kenwood_get_xit(RIG *rig, vfo_t vfo, shortfreq_t *rit) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !rit) - { - return -RIG_EINVAL; - } - return kenwood_get_rit(rig, vfo, rit); } @@ -1654,11 +1575,6 @@ int kenwood_set_xit(RIG *rig, vfo_t vfo, shortfreq_t rit) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - { - return -RIG_EINVAL; - } - return kenwood_set_rit(rig, vfo, rit); } @@ -1666,11 +1582,6 @@ int kenwood_scan(RIG *rig, vfo_t vfo, scan_t scan, int ch) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - { - return -RIG_EINVAL; - } - if (RIG_MODEL_TS990S == rig->caps->rig_model) { return kenwood_transaction(rig, scan == RIG_SCAN_STOP ? "SC00" : "SC01", NULL, @@ -1695,15 +1606,10 @@ int kenwood_scan(RIG *rig, vfo_t vfo, scan_t scan, int ch) /* XXX revise */ static int kenwood_set_filter(RIG *rig, pbwidth_t width) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - char *cmd; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + if (width <= Hz(250)) { cmd = "FL010009"; @@ -1733,24 +1639,16 @@ static int kenwood_set_filter(RIG *rig, pbwidth_t width) */ int kenwood_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - + char c; + char kmode; + char buf[6]; + char data_mode = '0'; + int err; struct kenwood_priv_data *priv = rig->state.priv; - struct kenwood_priv_caps *caps = kenwood_caps(rig); - char buf[6]; - char kmode; - - int err; - - char data_mode = '0'; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); if (RIG_MODEL_TS590S == rig->caps->rig_model || RIG_MODEL_TS590SG == rig->caps->rig_model) @@ -1795,8 +1693,6 @@ int kenwood_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) return -RIG_EINVAL; } - char c; - if (kmode <= 9) { c = '0' + kmode; @@ -1883,16 +1779,16 @@ int kenwood_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) static int kenwood_get_filter(RIG *rig, pbwidth_t *width) { + int err, f, f1, f2; + char buf[10]; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !width) + if (!width) { return -RIG_EINVAL; } - int err, f, f1, f2; - char buf[10]; - err = kenwood_safe_transaction(rig, "FL", buf, sizeof(buf), 8); if (err != RIG_OK) @@ -1946,25 +1842,22 @@ static int kenwood_get_filter(RIG *rig, pbwidth_t *width) */ int kenwood_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) { + char cmd[4]; + char modebuf[10]; + int offs; + int retval; + int kmode; + + struct kenwood_priv_data *priv = rig->state.priv; + struct kenwood_priv_caps *caps = kenwood_caps(rig); + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !mode || !width) + if (!mode || !width) { return -RIG_EINVAL; } - struct kenwood_priv_data *priv = rig->state.priv; - - struct kenwood_priv_caps *caps = kenwood_caps(rig); - - char cmd[4]; - - char modebuf[10]; - - int offs; - - int retval; - /* for emulation do not read mode from VFOB as it is copy of VFOA */ /* we avoid the VFO swapping most of the time this way */ /* only need to get it if it has to be initialized */ @@ -2012,8 +1905,6 @@ int kenwood_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) return retval; } - int kmode; - if (modebuf[offs] <= '9') { kmode = modebuf[offs] - '0'; @@ -2069,17 +1960,17 @@ int kenwood_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) /* This is used when the radio does not support MD; for mode reading */ int kenwood_get_mode_if(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig || !mode || !width) - { - return -RIG_EINVAL; - } - int err; struct kenwood_priv_caps *caps = kenwood_caps(rig); struct kenwood_priv_data *priv = rig->state.priv; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + + if (!mode || !width) + { + return -RIG_EINVAL; + } + err = kenwood_get_if(rig); if (err != RIG_OK) @@ -2106,16 +1997,11 @@ int kenwood_get_mode_if(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) int kenwood_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - char levelbuf[16]; int i, kenwood_val; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + if (RIG_LEVEL_IS_FLOAT(level)) { kenwood_val = val.f * 255; @@ -2260,18 +2146,18 @@ int kenwood_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) int get_kenwood_level(RIG *rig, const char *cmd, float *f) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig || !cmd || !f) - { - return -RIG_EINVAL; - } - char lvlbuf[10]; int retval; int lvl; int len = strlen(cmd); + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + + if (!cmd || !f) + { + return -RIG_EINVAL; + } + retval = kenwood_safe_transaction(rig, cmd, lvlbuf, 10, len + 3); if (retval != RIG_OK) @@ -2291,19 +2177,19 @@ int get_kenwood_level(RIG *rig, const char *cmd, float *f) */ int kenwood_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig || !val) - { - return -RIG_EINVAL; - } - char lvlbuf[KENWOOD_MAX_BUF_LEN]; char *cmd; int retval; int lvl; int i, ret, agclevel, len; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + + if (!val) + { + return -RIG_EINVAL; + } + switch (level) { case RIG_LEVEL_RAWSTR: @@ -2544,14 +2430,8 @@ int kenwood_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) int kenwood_set_func(RIG *rig, vfo_t vfo, setting_t func, int status) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - char buf[10]; /* longest cmd is GTxxx */ + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); switch (func) { @@ -2675,18 +2555,17 @@ int kenwood_set_func(RIG *rig, vfo_t vfo, setting_t func, int status) */ int get_kenwood_func(RIG *rig, const char *cmd, int *status) { + int retval; + char buf[10]; + int offset = 2; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !cmd || !status) + if (!cmd || !status) { return -RIG_EINVAL; } - int retval; - char buf[10]; - - int offset = 2; - if (strlen(cmd) == 3) { offset = 3; } // some commands are 3 letters retval = kenwood_safe_transaction(rig, cmd, buf, sizeof(buf), offset + 1); @@ -2707,16 +2586,16 @@ int get_kenwood_func(RIG *rig, const char *cmd, int *status) int kenwood_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status) { char *cmd; + char fctbuf[20]; + int retval; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !status) + if (!status) { return -RIG_EINVAL; } - char fctbuf[20]; - int retval; - switch (func) { case RIG_FUNC_FAGC: @@ -2809,17 +2688,12 @@ int kenwood_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status) */ int kenwood_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - const struct rig_caps *caps; char tonebuf[16]; int i; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + caps = rig->caps; for (i = 0; caps->ctcss_list[i] != 0; i++) @@ -2843,17 +2717,12 @@ int kenwood_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone) int kenwood_set_ctcss_tone_tn(RIG *rig, vfo_t vfo, tone_t tone) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - const struct rig_caps *caps = rig->caps; char buf[6]; int i; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + for (i = 0; caps->ctcss_list[i] != 0; i++) { if (tone == caps->ctcss_list[i]) @@ -2908,23 +2777,19 @@ int kenwood_set_ctcss_tone_tn(RIG *rig, vfo_t vfo, tone_t tone) */ int kenwood_get_ctcss_tone(RIG *rig, vfo_t vfo, tone_t *tone) { + struct kenwood_priv_data *priv = rig->state.priv; + const struct rig_caps *caps; + char tonebuf[3]; + int i, retval; + unsigned int tone_idx; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !tone) + if (!tone) { return -RIG_EINVAL; } - struct kenwood_priv_data *priv = rig->state.priv; - - const struct rig_caps *caps; - - char tonebuf[3]; - - int i, retval; - - unsigned int tone_idx; - caps = rig->caps; if (RIG_MODEL_TS990S == caps->rig_model) @@ -2995,17 +2860,12 @@ int kenwood_get_ctcss_tone(RIG *rig, vfo_t vfo, tone_t *tone) int kenwood_set_ctcss_sql(RIG *rig, vfo_t vfo, tone_t tone) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - const struct rig_caps *caps = rig->caps; char buf[6]; int i; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + for (i = 0; caps->ctcss_list[i] != 0; i++) { if (tone == caps->ctcss_list[i]) @@ -3056,13 +2916,6 @@ int kenwood_set_ctcss_sql(RIG *rig, vfo_t vfo, tone_t tone) int kenwood_get_ctcss_sql(RIG *rig, vfo_t vfo, tone_t *tone) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig || !tone) - { - return -RIG_EINVAL; - } - const struct rig_caps *caps; char cmd[4]; char tonebuf[6]; @@ -3070,6 +2923,13 @@ int kenwood_get_ctcss_sql(RIG *rig, vfo_t vfo, tone_t *tone) int i, retval; unsigned int tone_idx; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + + if (!tone) + { + return -RIG_EINVAL; + } + caps = rig->caps; if (RIG_MODEL_TS990S == rig->caps->rig_model) @@ -3142,16 +3002,11 @@ int kenwood_get_ctcss_sql(RIG *rig, vfo_t vfo, tone_t *tone) */ int kenwood_set_ant(RIG *rig, vfo_t vfo, ant_t ant) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - char cmd[8]; char a; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + switch (ant) { case RIG_ANT_1: a = '1'; break; @@ -3203,15 +3058,10 @@ int kenwood_set_ant(RIG *rig, vfo_t vfo, ant_t ant) int kenwood_set_ant_no_ack(RIG *rig, vfo_t vfo, ant_t ant) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - const char *cmd; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + switch (ant) { case RIG_ANT_1: @@ -3242,17 +3092,17 @@ int kenwood_set_ant_no_ack(RIG *rig, vfo_t vfo, ant_t ant) */ int kenwood_get_ant(RIG *rig, vfo_t vfo, ant_t *ant) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig || !ant) - { - return -RIG_EINVAL; - } - char ackbuf[8]; int offs; int retval; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + + if (!ant) + { + return -RIG_EINVAL; + } + if (RIG_MODEL_TS990S == rig->caps->rig_model) { retval = kenwood_safe_transaction(rig, "AN0", ackbuf, sizeof(ackbuf), 7); @@ -3286,17 +3136,16 @@ int kenwood_get_ant(RIG *rig, vfo_t vfo, ant_t *ant) */ int kenwood_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt) { + struct kenwood_priv_data *priv = rig->state.priv; + int retval; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !ptt) + if (!ptt) { return -RIG_EINVAL; } - struct kenwood_priv_data *priv = rig->state.priv; - - int retval; - retval = kenwood_get_if(rig); if (retval != RIG_OK) @@ -3315,11 +3164,6 @@ int kenwood_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - { - return -RIG_EINVAL; - } - switch (ptt) { case RIG_PTT_ON: ptt_cmd = "TX"; break; @@ -3356,16 +3200,11 @@ int kenwood_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) int kenwood_set_ptt_safe(RIG *rig, vfo_t vfo, ptt_t ptt) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - int err; ptt_t current_ptt; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + err = kenwood_get_ptt(rig, vfo, ¤t_ptt); if (err != RIG_OK) @@ -3388,16 +3227,17 @@ int kenwood_set_ptt_safe(RIG *rig, vfo_t vfo, ptt_t ptt) */ int kenwood_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd) { + char busybuf[10]; + int retval; + int offs = 2; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !dcd) + if (!dcd) { return -RIG_EINVAL; } - char busybuf[10]; - int retval; - retval = kenwood_safe_transaction(rig, "BY", busybuf, 10, 3); if (retval != RIG_OK) @@ -3405,8 +3245,6 @@ int kenwood_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd) return retval; } - int offs = 2; - if (RIG_MODEL_TS990S == rig->caps->rig_model && RIG_VFO_SUB == vfo) { offs = 3; @@ -3424,11 +3262,6 @@ int kenwood_set_trn(RIG *rig, int trn) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - { - return -RIG_EINVAL; - } - switch (rig->caps->rig_model) { case RIG_MODEL_TS990S: @@ -3451,9 +3284,12 @@ int kenwood_set_trn(RIG *rig, int trn) */ int kenwood_get_trn(RIG *rig, int *trn) { + char trnbuf[6]; + int retval; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !trn) + if (!trn) { return -RIG_EINVAL; } @@ -3468,9 +3304,6 @@ int kenwood_get_trn(RIG *rig, int *trn) return -RIG_ENAVAIL; } - char trnbuf[6]; - int retval; - if (rig->caps->rig_model == RIG_MODEL_THD74) { retval = kenwood_safe_transaction(rig, "AI", trnbuf, 6, 4); @@ -3502,25 +3335,18 @@ int kenwood_get_trn(RIG *rig, int *trn) */ int kenwood_set_powerstat(RIG *rig, powerstat_t status) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called status=%d\n", __func__, status); - - if (!rig) - { - return -RIG_EINVAL; - } - - int retval = kenwood_transaction(rig, (status == RIG_POWER_ON) ? "PS1" : "PS0", - NULL, 0); - + int retval = kenwood_transaction(rig, (status == RIG_POWER_ON) ? "PS1" : "PS0", NULL, 0); int i = 0; int retry = 3 / rig->state.rigport.retry; + rig_debug(RIG_DEBUG_VERBOSE, "%s called status=%d\n", __func__, status); + if (status == RIG_POWER_ON) // wait for wakeup only { for (i = 0; i < retry; ++i) // up to 10 seconds { - sleep(1); freq_t freq; + sleep(1); retval = rig_get_freq(rig, RIG_VFO_A, &freq); if (retval == RIG_OK) { return retval; } @@ -3546,16 +3372,16 @@ int kenwood_set_powerstat(RIG *rig, powerstat_t status) */ int kenwood_get_powerstat(RIG *rig, powerstat_t *status) { + char pwrbuf[6]; + int retval; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !status) + if (!status) { return -RIG_EINVAL; } - char pwrbuf[6]; - int retval; - retval = kenwood_safe_transaction(rig, "PS", pwrbuf, 6, 3); if (retval != RIG_OK) @@ -3573,16 +3399,11 @@ int kenwood_get_powerstat(RIG *rig, powerstat_t *status) */ int kenwood_reset(RIG *rig, reset_t reset) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - char rstbuf[6]; char rst; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + if (RIG_MODEL_TS990S == rig->caps->rig_model) { switch (reset) @@ -3627,22 +3448,23 @@ int kenwood_reset(RIG *rig, reset_t reset) */ int kenwood_send_morse(RIG *rig, vfo_t vfo, const char *msg) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig || !msg) - { - return -RIG_EINVAL; - } - char morsebuf[40], m2[30]; int msg_len, retval, i; const char *p; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + + if (!msg) + { + return -RIG_EINVAL; + } + p = msg; msg_len = strlen(msg); while (msg_len > 0) { + int buff_len; /* * Check with "KY" if char buffer is available. * if not, sleep. @@ -3667,7 +3489,7 @@ int kenwood_send_morse(RIG *rig, vfo_t vfo, const char *msg) else { return -RIG_EINVAL; } } - int buff_len = msg_len > 24 ? 24 : msg_len; + buff_len = msg_len > 24 ? 24 : msg_len; strncpy(m2, p, 24); m2[24] = '\0'; @@ -3718,11 +3540,6 @@ int kenwood_vfo_op(RIG *rig, vfo_t vfo, vfo_op_t op) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - { - return -RIG_EINVAL; - } - switch (op) { case RIG_OP_UP: @@ -3749,15 +3566,10 @@ int kenwood_vfo_op(RIG *rig, vfo_t vfo, vfo_op_t op) */ int kenwood_set_mem(RIG *rig, vfo_t vfo, int ch) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - char buf[7]; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + if (RIG_MODEL_TS990S == rig->caps->rig_model) { char c; @@ -3803,18 +3615,18 @@ int kenwood_set_mem(RIG *rig, vfo_t vfo, int ch) */ int kenwood_get_mem(RIG *rig, vfo_t vfo, int *ch) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig || !ch) - { - return -RIG_EINVAL; - } - char cmd[4]; char membuf[10]; int offs; int retval; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + + if (!ch) + { + return -RIG_EINVAL; + } + if (RIG_MODEL_TS990S == rig->caps->rig_model) { char c; @@ -3866,17 +3678,17 @@ int kenwood_get_mem(RIG *rig, vfo_t vfo, int *ch) int kenwood_get_mem_if(RIG *rig, vfo_t vfo, int *ch) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig || !ch) - { - return -RIG_EINVAL; - } - int err; char buf[4]; struct kenwood_priv_data *priv = rig->state.priv; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + + if (!ch) + { + return -RIG_EINVAL; + } + err = kenwood_get_if(rig); if (err != RIG_OK) @@ -3894,20 +3706,20 @@ int kenwood_get_mem_if(RIG *rig, vfo_t vfo, int *ch) int kenwood_get_channel(RIG *rig, channel_t *chan) { + int err; + char buf[26]; + char cmd[8]; + char bank = ' '; + struct kenwood_priv_caps *caps = kenwood_caps(rig); + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !chan) + if (!chan) { return -RIG_EINVAL; } - int err; - char buf[26]; - char cmd[8]; - struct kenwood_priv_caps *caps = kenwood_caps(rig); - /* put channel num in the command string */ - char bank = ' '; if (rig->caps->rig_model == RIG_MODEL_TS940) { @@ -4006,20 +3818,20 @@ int kenwood_get_channel(RIG *rig, channel_t *chan) int kenwood_set_channel(RIG *rig, const channel_t *chan) { + char buf[128]; + char mode, tx_mode = 0; + char bank = ' '; + int err; + int tone = 0; + struct kenwood_priv_caps *caps = kenwood_caps(rig); + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !chan) + if (!chan) { return -RIG_EINVAL; } - char buf[128]; - char mode, tx_mode = 0; - int err; - int tone = 0; - - struct kenwood_priv_caps *caps = kenwood_caps(rig); - mode = rmode2kenwood(chan->mode, caps->mode_table); if (mode < 0) @@ -4060,8 +3872,6 @@ int kenwood_set_channel(RIG *rig, const channel_t *chan) } } - char bank = ' '; - if (rig->caps->rig_model == RIG_MODEL_TS940) { bank = '0' + chan->bank_num; @@ -4099,15 +3909,10 @@ int kenwood_set_channel(RIG *rig, const channel_t *chan) int kenwood_set_ext_parm(RIG *rig, token_t token, value_t val) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - char buf[4]; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + switch (token) { case TOK_VOICE: @@ -4131,16 +3936,16 @@ int kenwood_set_ext_parm(RIG *rig, token_t token, value_t val) int kenwood_get_ext_parm(RIG *rig, token_t token, value_t *val) { + int err; + struct kenwood_priv_data *priv = rig->state.priv; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !val) + if (!val) { return -RIG_EINVAL; } - int err; - struct kenwood_priv_data *priv = rig->state.priv; - switch (token) { case TOK_FINE: @@ -4178,6 +3983,9 @@ int kenwood_get_ext_parm(RIG *rig, token_t token, value_t *val) */ const char *kenwood_get_info(RIG *rig) { + char firmbuf[10]; + int retval; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); if (!rig) @@ -4185,9 +3993,6 @@ const char *kenwood_get_info(RIG *rig) return "*rig == NULL"; } - char firmbuf[10]; - int retval; - retval = kenwood_safe_transaction(rig, "TY", firmbuf, 10, 5); if (retval != RIG_OK) @@ -4219,14 +4024,14 @@ const char *kenwood_get_info(RIG *rig) */ DECLARE_PROBERIG_BACKEND(kenwood) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - char idbuf[IDBUFSZ]; int id_len = -1, i, k_id; int retval = -1; int rates[] = { 115200, 57600, 38400, 19200, 9600, 4800, 1200, 0 }; /* possible baud rates */ int rates_idx; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + if (!port) { return RIG_MODEL_NONE; diff --git a/kenwood/pihpsdr.c b/kenwood/pihpsdr.c index 85b4f0c89..67b8995bd 100644 --- a/kenwood/pihpsdr.c +++ b/kenwood/pihpsdr.c @@ -337,18 +337,20 @@ const struct rig_caps pihpsdr_caps = int pihspdr_get_channel(RIG *rig, channel_t *chan) { + int err; + int tmp; + char buf[52]; + char cmd[8]; + size_t length; + struct kenwood_priv_caps *caps = kenwood_caps(rig); + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !chan || chan->vfo != RIG_VFO_MEM) + if (!chan || chan->vfo != RIG_VFO_MEM) { return -RIG_EINVAL; } - int err; - char buf[52]; - char cmd[8]; - struct kenwood_priv_caps *caps = kenwood_caps(rig); - /* put channel num in the command string */ sprintf(cmd, "MR0%03d;", chan->channel_num); @@ -359,7 +361,7 @@ int pihspdr_get_channel(RIG *rig, channel_t *chan) return err; } - size_t length = strlen(buf); + length = strlen(buf); memset(chan, 0x00, sizeof(channel_t)); chan->vfo = RIG_VFO_MEM; @@ -384,7 +386,6 @@ int pihspdr_get_channel(RIG *rig, channel_t *chan) Tuning step depends on this number and the mode, just save it for now */ buf[ 40 ] = '\0'; - int tmp; tmp = atoi(&buf[ 38]); /* Offset frequency */ buf[ 38 ] = '\0'; @@ -563,22 +564,20 @@ int pihspdr_get_channel(RIG *rig, channel_t *chan) } int pihspdr_set_channel(RIG *rig, const channel_t *chan) -{ - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig || !chan) - { - return -RIG_EINVAL; - } - +{ + char sqltype; + char shift; char buf[128]; char mode, tx_mode = 0; int err; int tone = 0; - - + int tstep; + short code; + short dcscode; struct kenwood_priv_caps *caps = kenwood_caps(rig); + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + mode = rmode2kenwood(chan->mode, caps->mode_table); if (mode < 0) @@ -601,7 +600,7 @@ int pihspdr_set_channel(RIG *rig, const channel_t *chan) } /* find tone */ - char sqltype = '0'; + sqltype = '0'; if (chan->ctcss_tone) { @@ -622,7 +621,7 @@ int pihspdr_set_channel(RIG *rig, const channel_t *chan) } /* find CTCSS code */ - short code = 0; + code = 0; if (chan->ctcss_sql) { @@ -643,7 +642,7 @@ int pihspdr_set_channel(RIG *rig, const channel_t *chan) } /* find DCS code */ - short dcscode = 0; + dcscode = 0; if (chan->dcs_code) { @@ -663,7 +662,7 @@ int pihspdr_set_channel(RIG *rig, const channel_t *chan) dcscode = 0; } - char shift = '0'; + shift = '0'; if (chan->rptr_shift == RIG_RPT_SHIFT_PLUS) { @@ -675,7 +674,7 @@ int pihspdr_set_channel(RIG *rig, const channel_t *chan) shift = '2'; } - int tstep = 0; + tstep = 0; if ((chan->mode == RIG_MODE_AM) || (chan->mode == RIG_MODE_FM)) { @@ -770,16 +769,11 @@ int pihspdr_set_channel(RIG *rig, const channel_t *chan) int pihpsdr_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - char levelbuf[16]; int i, kenwood_val; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + if (RIG_LEVEL_IS_FLOAT(level)) { kenwood_val = val.f * 255; @@ -1331,15 +1325,10 @@ int pihpsdr_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) to not use the TS-2000 backend open function */ int pihpsdr_open(RIG *rig) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - char id[KENWOOD_MAX_BUF_LEN]; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + /* get id in buffer, will be null terminated */ kenwood_get_id(rig, id); diff --git a/kenwood/th.c b/kenwood/th.c index fb06e6159..5a328f5fd 100644 --- a/kenwood/th.c +++ b/kenwood/th.c @@ -52,6 +52,7 @@ th_decode_event(RIG *rig) { char asyncbuf[128]; int retval; + int async_len; rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); @@ -64,7 +65,7 @@ th_decode_event(RIG *rig) rig_debug(RIG_DEBUG_TRACE, "%s: Decoding message\n", __func__); - size_t async_len = strlen(asyncbuf); + async_len = strlen(asyncbuf); if (async_len > 3 && asyncbuf[0] == 'B' && asyncbuf[1] == 'U' && asyncbuf[2] == 'F') @@ -435,6 +436,7 @@ th_set_vfo(RIG *rig, vfo_t vfo) /* set band */ if (vfo != RIG_VFO_MEM) { + int retval; switch (vfo) { @@ -453,7 +455,7 @@ th_set_vfo(RIG *rig, vfo_t vfo) return kenwood_wrong_vfo(__func__, vfo); } - int retval = kenwood_simple_transaction(rig, cmd, 5); + retval = kenwood_simple_transaction(rig, cmd, 5); if (retval != RIG_OK) { @@ -507,6 +509,7 @@ th_get_vfo_char(RIG *rig, vfo_t *vfo, char *vfoch) { char cmdbuf[10], buf[10], vfoc; int retval; + size_t length; rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); @@ -519,7 +522,7 @@ th_get_vfo_char(RIG *rig, vfo_t *vfo, char *vfoch) return retval; } - size_t length = strlen(buf); + length = strlen(buf); switch (length) { @@ -1695,6 +1698,7 @@ th_get_info(RIG *rig) { static char firmbuf[50]; int retval; + size_t firm_len; rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); @@ -1705,7 +1709,7 @@ th_get_info(RIG *rig) return NULL; } - size_t firm_len = strlen(firmbuf); + firm_len = strlen(firmbuf); if (firm_len < 3) { @@ -2191,6 +2195,7 @@ int th_get_channel(RIG *rig, channel_t *chan) /* If not set already by special channels.. */ if (chan->channel_desc[0] == '\0') { + size_t ack_len; if (chan_caps[1].type == RIG_MTYPE_PRIO) { sprintf(membuf, "MNA %sI-%01d", mr_extra, channel_num); @@ -2208,7 +2213,7 @@ int th_get_channel(RIG *rig, channel_t *chan) return retval; } - size_t ack_len = strlen(ackbuf); + ack_len = strlen(ackbuf); if (ack_len > rig->caps->chan_desc_sz) { @@ -2428,6 +2433,7 @@ int th_set_channel(RIG *rig, const channel_t *chan) if (chan_caps->mem_caps.flags && chan_caps->mem_caps.dcs_sql) { + int mode; if (!priv->mode_table) { @@ -2436,7 +2442,7 @@ int th_set_channel(RIG *rig, const channel_t *chan) return -RIG_ENIMPL; } - int mode = rmode2kenwood(chan->mode, priv->mode_table); + mode = rmode2kenwood(chan->mode, priv->mode_table); if (mode == -1) { diff --git a/kenwood/thd72.c b/kenwood/thd72.c index 2cae19cd5..2870a637e 100644 --- a/kenwood/thd72.c +++ b/kenwood/thd72.c @@ -196,19 +196,20 @@ static int thd72_set_vfo(RIG *rig, vfo_t vfo) static int thd72_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) { + int retval; char vfobuf[16]; struct kenwood_priv_data *priv = rig->state.priv; - rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); - char vfonum = '0'; + rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); + if (vfo == RIG_VFO_B || priv->split) { vfonum = '1'; } sprintf(vfobuf, "BC %c", vfonum); - int retval = kenwood_transaction(rig, vfobuf, NULL, 0); + retval = kenwood_transaction(rig, vfobuf, NULL, 0); if (retval != RIG_OK) { @@ -222,6 +223,7 @@ static int thd72_get_vfo(RIG *rig, vfo_t *vfo) { int retval; char c, buf[10]; + size_t length; rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); @@ -232,7 +234,7 @@ static int thd72_get_vfo(RIG *rig, vfo_t *vfo) return retval; } - size_t length = strlen(buf); + length = strlen(buf); if (length == 4) { @@ -431,6 +433,8 @@ static int thd72_set_freq_item(RIG *rig, vfo_t vfo, int item, int val) static int thd72_set_freq(RIG *rig, vfo_t vfo, freq_t freq) { int retval; + int tsindex; + shortfreq_t ts; char buf[64], fbuf[11]; rig_debug(RIG_DEBUG_TRACE, "%s: called, vfo=%s, freq=%f\n", __func__, @@ -444,11 +448,11 @@ static int thd72_set_freq(RIG *rig, vfo_t vfo, freq_t freq) return retval; } - int tsindex = buf[16] - '0'; + tsindex = buf[16] - '0'; if (buf[16] >= 'A') { tsindex = buf[16] - 'A' + 10; } - shortfreq_t ts = thd72tuningstep[tsindex]; + ts = thd72tuningstep[tsindex]; rig_debug(RIG_DEBUG_VERBOSE, "%s: tsindex=%d, stepsize=%d\n", __func__, tsindex, (int)ts); freq = roundl(freq / ts) * ts; @@ -461,6 +465,8 @@ static int thd72_set_freq(RIG *rig, vfo_t vfo, freq_t freq) static int thd72_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) { int retval; + int tsindex; + shortfreq_t ts; char buf[64]; rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); @@ -472,8 +478,8 @@ static int thd72_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) return retval; } - int tsindex = buf[16] - '0'; - shortfreq_t ts = thd72tuningstep[tsindex]; + tsindex = buf[16] - '0'; + ts = thd72tuningstep[tsindex]; rig_debug(RIG_DEBUG_VERBOSE, "%s: tsindex=%d, stepsize=%d\n", __func__, tsindex, (int)ts); sscanf(buf + 5, "%"SCNfreq, freq); @@ -1360,6 +1366,7 @@ static int thd72_get_channel(RIG *rig, channel_t *chan) if (chan->vfo == RIG_VFO_MEM) /* memory channel */ { + int len; char cmd[16]; sprintf(cmd, "ME %03d", chan->channel_num); retval = kenwood_transaction(rig, cmd, buf, sizeof(buf)); @@ -1384,7 +1391,7 @@ static int thd72_get_channel(RIG *rig, channel_t *chan) return retval; } - int len = strlen(buf); + len = strlen(buf); memcpy(chan->channel_desc, buf + 7, len - 7); } else /* current channel */ diff --git a/kenwood/thd74.c b/kenwood/thd74.c index 8b12077f8..76f0e97c9 100644 --- a/kenwood/thd74.c +++ b/kenwood/thd74.c @@ -202,6 +202,7 @@ static int thd74_get_vfo(RIG *rig, vfo_t *vfo) { int retval; char c, buf[10]; + size_t length; rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); @@ -212,7 +213,7 @@ static int thd74_get_vfo(RIG *rig, vfo_t *vfo) return retval; } - size_t length = strlen(buf); + length = strlen(buf); if (length == 4) { @@ -863,11 +864,6 @@ int thd74_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - { - return -RIG_EINVAL; - } - switch (ptt) { case RIG_PTT_ON: @@ -1286,6 +1282,7 @@ static int thd74_get_channel(RIG *rig, channel_t *chan) if (chan->vfo == RIG_VFO_MEM) /* memory channel */ { + int len; char cmd[16]; sprintf(cmd, "ME %03d", chan->channel_num); retval = kenwood_transaction(rig, cmd, buf, sizeof(buf)); @@ -1310,7 +1307,7 @@ static int thd74_get_channel(RIG *rig, channel_t *chan) return retval; } - int len = strlen(buf); + len = strlen(buf); memcpy(chan->channel_desc, buf + 7, len - 7); } else /* current channel */ diff --git a/kenwood/thg71.c b/kenwood/thg71.c index 0f07458b0..e70b2f4db 100644 --- a/kenwood/thg71.c +++ b/kenwood/thg71.c @@ -508,9 +508,10 @@ int thg71_open(RIG *rig) for (i = 0; i < FRQRANGESIZ; i++) { freq_range_t frng; + char *stru; strl = strtok(NULL, ","); - char *stru = strtok(NULL, ","); + stru = strtok(NULL, ","); if (strl == NULL && stru == NULL) { diff --git a/kenwood/ts2000.c b/kenwood/ts2000.c index 9ef77eca1..db1c43e22 100644 --- a/kenwood/ts2000.c +++ b/kenwood/ts2000.c @@ -370,6 +370,13 @@ const struct rig_caps ts2000_caps = int ts2000_get_channel(RIG *rig, channel_t *chan) { + int err; + int tmp; + size_t length; + char buf[52]; + char cmd[8]; + struct kenwood_priv_caps *caps = kenwood_caps(rig); + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); if (!rig || !chan || chan->vfo != RIG_VFO_MEM) @@ -377,11 +384,6 @@ int ts2000_get_channel(RIG *rig, channel_t *chan) return -RIG_EINVAL; } - int err; - char buf[52]; - char cmd[8]; - struct kenwood_priv_caps *caps = kenwood_caps(rig); - /* put channel num in the command string */ sprintf(cmd, "MR0%03d;", chan->channel_num); @@ -392,7 +394,7 @@ int ts2000_get_channel(RIG *rig, channel_t *chan) return err; } - size_t length = strlen(buf); + length = strlen(buf); memset(chan, 0x00, sizeof(channel_t)); chan->vfo = RIG_VFO_MEM; @@ -417,7 +419,6 @@ int ts2000_get_channel(RIG *rig, channel_t *chan) Tuning step depends on this number and the mode, just save it for now */ buf[ 40 ] = '\0'; - int tmp; tmp = atoi(&buf[ 38]); /* Offset frequency */ buf[ 38 ] = '\0'; @@ -597,21 +598,25 @@ int ts2000_get_channel(RIG *rig, channel_t *chan) int ts2000_set_channel(RIG *rig, const channel_t *chan) { + char sqltype = '0'; + char buf[128]; + char mode, tx_mode = 0; + char shift = '0'; + short dcscode = 0; + short code = 0; + int tstep = 0; + int err; + int tone = 0; + struct kenwood_priv_caps *caps = kenwood_caps(rig); + + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !chan) + if (!chan) { return -RIG_EINVAL; } - char buf[128]; - char mode, tx_mode = 0; - int err; - int tone = 0; - - - struct kenwood_priv_caps *caps = kenwood_caps(rig); - mode = rmode2kenwood(chan->mode, caps->mode_table); if (mode < 0) @@ -634,7 +639,6 @@ int ts2000_set_channel(RIG *rig, const channel_t *chan) } /* find tone */ - char sqltype = '0'; if (chan->ctcss_tone) { @@ -655,7 +659,6 @@ int ts2000_set_channel(RIG *rig, const channel_t *chan) } /* find CTCSS code */ - short code = 0; if (chan->ctcss_sql) { @@ -676,7 +679,6 @@ int ts2000_set_channel(RIG *rig, const channel_t *chan) } /* find DCS code */ - short dcscode = 0; if (chan->dcs_code) { @@ -696,8 +698,6 @@ int ts2000_set_channel(RIG *rig, const channel_t *chan) dcscode = 0; } - char shift = '0'; - if (chan->rptr_shift == RIG_RPT_SHIFT_PLUS) { shift = '1'; @@ -708,7 +708,6 @@ int ts2000_set_channel(RIG *rig, const channel_t *chan) shift = '2'; } - int tstep = 0; if ((chan->mode == RIG_MODE_AM) || (chan->mode == RIG_MODE_FM)) { diff --git a/kenwood/ts480.c b/kenwood/ts480.c index 0be8216ce..932184ceb 100644 --- a/kenwood/ts480.c +++ b/kenwood/ts480.c @@ -52,6 +52,7 @@ kenwood_ts480_get_info(RIG *rig) { char firmbuf[50]; int retval; + size_t firm_len; retval = kenwood_transaction(rig, "TY", firmbuf, sizeof(firmbuf)); @@ -60,7 +61,7 @@ kenwood_ts480_get_info(RIG *rig) return NULL; } - size_t firm_len = strlen(firmbuf); + firm_len = strlen(firmbuf); if (firm_len != 5) { diff --git a/kenwood/ts570.c b/kenwood/ts570.c index da44fdcc4..502532955 100644 --- a/kenwood/ts570.c +++ b/kenwood/ts570.c @@ -763,6 +763,7 @@ int ts570_get_xit(RIG *rig, vfo_t vfo, shortfreq_t *rit) { char infobuf[50]; int retval; + size_t info_len; retval = kenwood_transaction(rig, "IF", infobuf, sizeof(infobuf)); @@ -771,7 +772,7 @@ int ts570_get_xit(RIG *rig, vfo_t vfo, shortfreq_t *rit) return retval; } - size_t info_len = strlen(infobuf); + info_len = strlen(infobuf); if (info_len != 37 || infobuf[1] != 'F') { diff --git a/kenwood/ts590.c b/kenwood/ts590.c index af2149e5f..16b9a0782 100644 --- a/kenwood/ts590.c +++ b/kenwood/ts590.c @@ -435,16 +435,11 @@ const struct rig_caps ts590sg_caps = */ const char *ts590_get_info(RIG *rig) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return "*rig == NULL"; - } - char firmbuf[10]; int retval; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + retval = kenwood_safe_transaction(rig, "TY", firmbuf, 10, 6); if (retval != RIG_OK) diff --git a/kenwood/xg3.c b/kenwood/xg3.c index b9064d0a9..1c914df57 100644 --- a/kenwood/xg3.c +++ b/kenwood/xg3.c @@ -171,11 +171,11 @@ const struct rig_caps xg3_caps = */ int xg3_init(RIG *rig) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - struct xg3_priv_data *priv; int i; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + priv = (struct xg3_priv_data *)malloc(sizeof(struct xg3_priv_data)); if (!priv) @@ -212,14 +212,10 @@ int xg3_init(RIG *rig) */ int xg3_open(RIG *rig) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - int err; + ptt_t ptt; + + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); err = elecraft_open(rig); @@ -228,7 +224,6 @@ int xg3_open(RIG *rig) return err; } - ptt_t ptt; xg3_get_ptt(rig, RIG_VFO_A, &ptt); // set our PTT status return RIG_OK; @@ -237,15 +232,10 @@ int xg3_open(RIG *rig) int xg3_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - char levelbuf[16]; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + switch (level) { case RIG_LEVEL_RFPOWER: @@ -272,18 +262,13 @@ int xg3_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) */ int xg3_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig || !val) - { - return -RIG_EINVAL; - } - char cmdbuf[32], replybuf[32]; int retval; size_t replysize = sizeof(replybuf); struct rig_state *rs = &rig->state; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + switch (level) { case RIG_LEVEL_RFPOWER: @@ -344,10 +329,10 @@ int xg3_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) */ int xg3_get_vfo(RIG *rig, vfo_t *vfo) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - struct xg3_priv_data *priv = (struct xg3_priv_data *)rig->state.priv; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + if (!vfo) { return -RIG_EINVAL; @@ -362,10 +347,10 @@ int xg3_get_vfo(RIG *rig, vfo_t *vfo) */ int xg3_set_vfo(RIG *rig, vfo_t vfo) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - struct xg3_priv_data *priv = (struct xg3_priv_data *)rig->state.priv; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + if (!vfo) { return -RIG_EINVAL; @@ -384,17 +369,12 @@ int xg3_set_vfo(RIG *rig, vfo_t vfo) */ int xg3_set_freq(RIG *rig, vfo_t vfo, freq_t freq) { + int err; vfo_t tvfo; + char cmdbuf[20]; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - { - return -RIG_EINVAL; - } - - char cmdbuf[20]; - tvfo = (vfo == RIG_VFO_CURR || vfo == RIG_VFO_VFO) ? rig->state.current_vfo : vfo; @@ -422,7 +402,7 @@ int xg3_set_freq(RIG *rig, vfo_t vfo, freq_t freq) sprintf(cmdbuf, "F,%011ld", (long)freq); } - int err = kenwood_transaction(rig, cmdbuf, NULL, 0); + err = kenwood_transaction(rig, cmdbuf, NULL, 0); return err; } @@ -432,21 +412,21 @@ int xg3_set_freq(RIG *rig, vfo_t vfo, freq_t freq) */ int xg3_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - struct rig_state *rs; - - if (!rig || !freq) - { - return -RIG_EINVAL; - } - char freqbuf[50]; int freqsize = sizeof(freqbuf); char cmdbuf[16]; int retval; + int offset; vfo_t tvfo; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + + if (!freq) + { + return -RIG_EINVAL; + } + tvfo = (vfo == RIG_VFO_CURR || vfo == RIG_VFO_VFO) ? rig->state.current_vfo : vfo; rs = &rig->state; @@ -491,7 +471,7 @@ int xg3_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) return retval; } - int offset = tvfo == RIG_VFO_A ? 2 : 5; + offset = tvfo == RIG_VFO_A ? 2 : 5; sscanf(freqbuf + offset, "%" SCNfreq, freq); @@ -503,10 +483,10 @@ int xg3_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) */ int xg3_set_powerstat(RIG *rig, powerstat_t status) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - struct xg3_priv_data *priv = (struct xg3_priv_data *)rig->state.priv; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + if (status == RIG_POWER_OFF) { const char *cmd = "X"; @@ -525,24 +505,20 @@ int xg3_set_powerstat(RIG *rig, powerstat_t status) */ int xg3_get_powerstat(RIG *rig, powerstat_t *status) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - const char *cmd = "G"; // any command to test will do + char reply[32]; int retval = kenwood_transaction(rig, cmd, NULL, 0); + struct rig_state *rs = &rig->state; + struct xg3_priv_data *priv = (struct xg3_priv_data *)rig->state.priv; + + retval = read_string(&rs->rigport, reply, sizeof(reply), ";", 1); + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); if (retval != RIG_OK) { return retval; } - struct rig_state *rs = &rig->state; - - struct xg3_priv_data *priv = (struct xg3_priv_data *)rig->state.priv; - - char reply[32]; - - retval = read_string(&rs->rigport, reply, sizeof(reply), ";", 1); - if (retval != RIG_OK) { *status = RIG_POWER_OFF; // Error indicates power is off @@ -563,11 +539,11 @@ int xg3_get_powerstat(RIG *rig, powerstat_t *status) */ int xg3_set_mem(RIG *rig, vfo_t vfo, int ch) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - char cmdbuf[32]; int retval; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + if (ch < 0 || ch > 11) { rig_debug(RIG_DEBUG_VERBOSE, "%s invalid channel#%02d\n", __func__, ch); @@ -592,13 +568,13 @@ int xg3_set_mem(RIG *rig, vfo_t vfo, int ch) */ int xg3_get_mem(RIG *rig, vfo_t vfo, int *ch) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - char cmdbuf[32]; char reply[32]; int retval; - struct rig_state *rs = &rig->state; + + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + sprintf(cmdbuf, "C;"); retval = kenwood_transaction(rig, cmdbuf, NULL, 0); @@ -624,12 +600,11 @@ int xg3_get_mem(RIG *rig, vfo_t vfo, int *ch) */ int xg3_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - struct xg3_priv_data *priv = (struct xg3_priv_data *)rig->state.priv; - int retval; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + retval = kenwood_simple_transaction(rig, (ptt == RIG_PTT_ON) ? "O,01" : "O,00", 0); @@ -646,18 +621,17 @@ int xg3_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) */ int xg3_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - + char pttbuf[6]; + int retval; struct xg3_priv_data *priv = (struct xg3_priv_data *)rig->state.priv; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + if (!ptt) { return -RIG_EINVAL; } - char pttbuf[6]; - int retval; - retval = kenwood_safe_transaction(rig, "O", pttbuf, 6, 4); if (retval != RIG_OK) @@ -676,12 +650,12 @@ int xg3_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt) */ int xg3_set_parm(RIG *rig, setting_t parm, value_t val) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - int ival; char cmdbuf[16]; int retval = -RIG_EINVAL; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + switch (parm) { case RIG_PARM_BACKLIGHT: @@ -705,12 +679,12 @@ int xg3_set_parm(RIG *rig, setting_t parm, value_t val) */ int xg3_get_parm(RIG *rig, setting_t parm, value_t *val) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - int ival; char replybuf[6]; int retval = -RIG_EINVAL; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + switch (parm) { case RIG_PARM_BACKLIGHT: diff --git a/kit/rs_hfiq.c b/kit/rs_hfiq.c index bb19afd6f..aa96ad37b 100644 --- a/kit/rs_hfiq.c +++ b/kit/rs_hfiq.c @@ -149,11 +149,12 @@ static int rshfiq_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) { char cmdstr[15]; char stopset[2]; - stopset[0] = '\r'; - stopset[1] = '\n'; int retval; serial_flush(&rig->state.rigport); + stopset[0] = '\r'; + stopset[1] = '\n'; + snprintf(cmdstr, sizeof(cmdstr), "*f?\r"); rig_debug(RIG_DEBUG_TRACE, "%s: cmdstr = %s\n", __func__, cmdstr); @@ -186,11 +187,12 @@ static int rshfiq_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) static int rshfiq_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) { char cmdstr[5]; + int retval; + cmdstr[0] = '*'; cmdstr[1] = 'x'; cmdstr[3] = '\r'; cmdstr[4] = 0; - int retval; if (ptt == RIG_PTT_ON) { diff --git a/kit/si570avrusb.c b/kit/si570avrusb.c index 461066a6f..f6c8779a9 100644 --- a/kit/si570avrusb.c +++ b/kit/si570avrusb.c @@ -981,7 +981,7 @@ static int setBPF(RIG *rig, int enable) if (nBytes > 2) { - + int i; int retval = libusb_control_transfer(udh, REQUEST_TYPE_IN, REQUEST_FILTERS, enable, (nBytes / 2) - 1, (unsigned char *) FilterCrossOver, sizeof(FilterCrossOver), @@ -995,8 +995,6 @@ static int setBPF(RIG *rig, int enable) rig_debug(RIG_DEBUG_TRACE, "%s: Filter Bank 1:\n", __func__); - int i; - for (i = 0; i < (nBytes / 2) - 1; i++) { rig_debug(RIG_DEBUG_TRACE, " CrossOver[%d] = %f\n", diff --git a/m2/rc2800.c b/m2/rc2800.c index 8d905300c..aca931e34 100644 --- a/m2/rc2800.c +++ b/m2/rc2800.c @@ -69,11 +69,11 @@ static int rc2800_parse(char *s, char *device, float *value) { int msgtype = 0, errcode = 0; + int len; rig_debug(RIG_DEBUG_TRACE, "%s: device return->%s", __func__, s); - int len = strlen(s); - + len = strlen(s); if (len == 0) { return -RIG_EPROTO; diff --git a/meade/meade.c b/meade/meade.c index 155939f6e..22012c185 100644 --- a/meade/meade.c +++ b/meade/meade.c @@ -320,6 +320,7 @@ static int meade_get_position(ROT *rot, azimuth_t *az, elevation_t *el) char eom; size_t return_str_size; int az_degrees, az_minutes, az_seconds, el_degrees, el_minutes, el_seconds; + int n; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -327,7 +328,7 @@ static int meade_get_position(ROT *rot, azimuth_t *az, elevation_t *el) rig_debug(RIG_DEBUG_VERBOSE, "%s: returned '%s'\n", __func__, return_str); // GZ returns DDD*MM# or DDD*MM'SS# // GA returns sDD*MM# or sDD*MM'SS# - int n = sscanf(return_str, "%d%*c%d:%d#%d%*c%d:%d%c", &az_degrees, &az_minutes, + n = sscanf(return_str, "%d%*c%d:%d#%d%*c%d:%d%c", &az_degrees, &az_minutes, &az_seconds, &el_degrees, &el_minutes, &el_seconds, &eom); if (n != 7 || eom != '#') @@ -432,10 +433,10 @@ static int meade_move(ROT *rot, int direction, int speed) static const char *meade_get_info(ROT *rot) { + static char buf[256]; // this is not thread-safe but not important either struct meade_priv_data *priv = (struct meade_priv_data *)rot->state.priv; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - static char buf[256]; // this is not thread-safe but not important either sprintf(buf, "Meade telescope rotator with LX200 protocol.\nModel: %s", priv->product_name); return buf; diff --git a/prosistel/prosistel.c b/prosistel/prosistel.c index e9ea6b80e..e4e803297 100644 --- a/prosistel/prosistel.c +++ b/prosistel/prosistel.c @@ -198,6 +198,7 @@ static int prosistel_rot_get_position(ROT *rot, azimuth_t *az, elevation_t *el) char data[20]; float posval; int retval; + int n; num_sprintf(cmdstr, STX"A?"CR); retval = prosistel_transaction(rot, cmdstr, data, sizeof(data)); @@ -209,7 +210,7 @@ static int prosistel_rot_get_position(ROT *rot, azimuth_t *az, elevation_t *el) // Example response of 100 azimuth // 02 41 2c 3f 2c 31 30 30 30 2c 52 0d .A,?,1000,R. - int n = sscanf(data, "%*cA,?,%f,%*c.", &posval); + n = sscanf(data, "%*cA,?,%f,%*c.", &posval); if (n != 1) { diff --git a/rs/gp2000.c b/rs/gp2000.c index 2a93ad594..45212d641 100644 --- a/rs/gp2000.c +++ b/rs/gp2000.c @@ -233,6 +233,10 @@ gp2000_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) { char buf[RESPSZ]; int buf_len, retval; + int nmode; + char *pmode = "UNKNOWN"; + int n = sscanf(buf, "%*cI%d", &nmode); + rig_debug(RIG_DEBUG_VERBOSE, "%s: vfo=%s\n", __func__, rig_strvfo(vfo)); @@ -246,10 +250,6 @@ gp2000_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) return retval; } - int nmode; - char *pmode = "UNKNOWN"; - int n = sscanf(buf, "%*cI%d", &nmode); - if (n != 1) { return -RIG_EPROTO; @@ -450,6 +450,12 @@ gp2000_get_info(RIG *rig) { static char infobuf[128]; int info_len, retval; + int addr = -1; + char type[32] = "unk type"; + char rigid[32] = "unk rigid"; + char sernum[32] = "unk sernum"; + char *p; + rig_debug(RIG_DEBUG_VERBOSE, "%s\n", __func__); @@ -463,13 +469,7 @@ gp2000_get_info(RIG *rig) return NULL; } - int addr = -1; - char type[32] = "unk type"; - char rigid[32] = "unk rigid"; - char sernum[32] = "unk sernum"; - - char *p = strtok(infobuf, ","); - + p = strtok(infobuf, ","); while (p) { switch (p[0]) diff --git a/src/cm108.c b/src/cm108.c index efe373d71..a57fe671c 100644 --- a/src/cm108.c +++ b/src/cm108.c @@ -80,6 +80,9 @@ int cm108_open(hamlib_port_t *port) { int fd; +#ifdef HAVE_LINUX_HIDRAW_H + struct hidraw_devinfo hiddevinfo; +#endif rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -102,13 +105,10 @@ int cm108_open(hamlib_port_t *port) #ifdef HAVE_LINUX_HIDRAW_H // CM108 detection copied from Thomas Sailer's soundmodem code - rig_debug(RIG_DEBUG_VERBOSE, "%s: checking for cm108 (or compatible) device\n", __func__); - struct hidraw_devinfo hiddevinfo; - if (!ioctl(fd, HIDIOCGRAWINFO, &hiddevinfo) && ((hiddevinfo.vendor == 0x0d8c // CM108/108B/109/119/119A @@ -163,6 +163,18 @@ int cm108_close(hamlib_port_t *port) */ int cm108_ptt_set(hamlib_port_t *p, ptt_t pttx) { + ssize_t nw; + char out_rep[] = + { + 0x00, // report number + // HID output report + 0x00, + (pttx == RIG_PTT_ON) ? (1 << p->parm.cm108.ptt_bitnum) : 0, // set GPIO + 1 << p->parm.cm108.ptt_bitnum, // Data direction register (1=output) + 0x00 + }; + + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); // For a CM108 USB audio device PTT is wired up to one of the GPIO @@ -192,18 +204,6 @@ 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[] = - { - 0x00, // report number - // HID output report - 0x00, - (pttx == RIG_PTT_ON) ? (1 << p->parm.cm108.ptt_bitnum) : 0, // set GPIO - 1 << p->parm.cm108.ptt_bitnum, // Data direction register (1=output) - 0x00 - }; - - ssize_t nw; - if (p->fd == -1) { return -RIG_EINVAL; diff --git a/src/debug.c b/src/debug.c index 74746e553..aafdc009c 100644 --- a/src/debug.c +++ b/src/debug.c @@ -84,6 +84,7 @@ void dump_hex(const unsigned char ptr[], size_t size) for (i = 0; i < size; ++i) { + char c; if (i % DUMP_HEX_WIDTH == 0) { /* new line */ @@ -91,7 +92,7 @@ void dump_hex(const unsigned char ptr[], size_t size) memset(line + 4, ' ', sizeof(line) - 4 - 1); } - char c = ptr[i]; + c = ptr[i]; /* hex print */ sprintf(line + 8 + 3 * (i % DUMP_HEX_WIDTH), "%02x", c); @@ -141,6 +142,7 @@ void HAMLIB_API rig_set_debug_time_stamp(int flag) char *date_strget(char *buf, int buflen) { + char tmp[16]; time_t mytime; struct tm *mytm; struct timeval tv; @@ -148,7 +150,6 @@ char *date_strget(char *buf, int buflen) mytm = gmtime(&mytime); gettimeofday(&tv, NULL); strftime(buf, buflen, "%Y-%m-%d:%H:%M:%S.", mytm); - char tmp[16]; sprintf(tmp, "%06ld", (long)tv.tv_usec); strcat(buf, tmp); return buf; diff --git a/src/gpio.c b/src/gpio.c index 7c01322b6..700777739 100644 --- a/src/gpio.c +++ b/src/gpio.c @@ -34,6 +34,7 @@ int gpio_open(hamlib_port_t *port, int output, int on_value) char pathname[FILPATHLEN * 2]; FILE *fexp, *fdir; int fd; + char *dir; port->parm.gpio.on_value = on_value; @@ -69,7 +70,7 @@ int gpio_open(hamlib_port_t *port, int output, int on_value) return -RIG_EIO; } - char *dir = output ? "out" : "in"; + dir = output ? "out" : "in"; rig_debug(RIG_DEBUG_VERBOSE, "Setting direction of GPIO%s to %s\n", port->pathname, dir); fprintf(fdir, "%s\n", dir); diff --git a/src/iofunc.c b/src/iofunc.c index bda352b52..884f46daa 100644 --- a/src/iofunc.c +++ b/src/iofunc.c @@ -561,13 +561,15 @@ int HAMLIB_API read_block(hamlib_port_t *p, char *rxbuffer, size_t count) while (count > 0) { + int retval; + int rd_count; tv = tv_timeout; /* select may have updated it */ FD_ZERO(&rfds); FD_SET(p->fd, &rfds); efds = rfds; - int retval = port_select(p, p->fd + 1, &rfds, NULL, &efds, &tv); + retval = port_select(p, p->fd + 1, &rfds, NULL, &efds, &tv); if (retval == 0) { @@ -612,7 +614,7 @@ int HAMLIB_API read_block(hamlib_port_t *p, char *rxbuffer, size_t count) * grab bytes from the rig * The file descriptor must have been set up non blocking. */ - int rd_count = port_read(p, rxbuffer + total_count, count); + rd_count = port_read(p, rxbuffer + total_count, count); if (rd_count < 0) { @@ -695,13 +697,15 @@ int HAMLIB_API read_string(hamlib_port_t *p, while (total_count < rxmax - 1) { + int rd_count; + int retval; tv = tv_timeout; /* select may have updated it */ FD_ZERO(&rfds); FD_SET(p->fd, &rfds); efds = rfds; - int retval = port_select(p, p->fd + 1, &rfds, NULL, &efds, &tv); + retval = port_select(p, p->fd + 1, &rfds, NULL, &efds, &tv); if (retval == 0) { @@ -751,7 +755,7 @@ int HAMLIB_API read_string(hamlib_port_t *p, * read 1 character from the rig, (check if in stop set) * The file descriptor must have been set up non blocking. */ - int rd_count = port_read(p, &rxbuffer[total_count], 1); + rd_count = port_read(p, &rxbuffer[total_count], 1); /* if we get 0 bytes or an error something is wrong */ if (rd_count <= 0) diff --git a/src/mem.c b/src/mem.c index 5831ba2b4..b2360166b 100644 --- a/src/mem.c +++ b/src/mem.c @@ -956,6 +956,7 @@ int get_chan_all_cb_generic(RIG *rig, chan_cb_t chan_cb, rig_ptr_t arg) for (i = 0; !RIG_IS_CHAN_END(chan_list[i]) && i < CHANLSTSIZ; i++) { + int retval; /* * setting chan to NULL means the application @@ -963,7 +964,7 @@ int get_chan_all_cb_generic(RIG *rig, chan_cb_t chan_cb, rig_ptr_t arg) * future data for channel channel_num */ chan = NULL; - int retval = chan_cb(rig, &chan, chan_list[i].startc, chan_list, arg); + retval = chan_cb(rig, &chan, chan_list[i].startc, chan_list, arg); if (retval != RIG_OK) { @@ -1590,7 +1591,7 @@ const chan_t *HAMLIB_API rig_lookup_mem_caps(RIG *rig, int ch) for (i = 0; i < CHANLSTSIZ && !RIG_IS_CHAN_END(chan_list[i]); i++) { - + int j; unsigned char *p1, *p2; p1 = (unsigned char *)&chan_list_all.mem_caps; p2 = (unsigned char *)&chan_list[i].mem_caps; @@ -1598,7 +1599,6 @@ 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 */ - int j; for (j = 0; j < sizeof(channel_cap_t); j++) { p1[j] |= p2[j]; diff --git a/src/microham.c b/src/microham.c index ce3161bfd..3ae0201e9 100644 --- a/src/microham.c +++ b/src/microham.c @@ -477,11 +477,11 @@ static void parseFrame(unsigned char *frame) if ((frame[0] & 0x08) == 0 && incontrol) { + int i; // end of a control sequence controlstring[numcontrolbytes++] = byte; DEBUG("%10d:FromControl:", TIME); - int i; for (i = 0; i < numcontrolbytes; i++) { DEBUG(" %02x", controlstring[i]); } DEBUG(".\n"); @@ -534,6 +534,8 @@ static void writeRadio(unsigned char *bytes, int len) for (i = 0; i < len; i++) { + int ret; + seq[0] = 0x28; seq[1] = 0x80 | bytes[i]; seq[2] = 0x80; @@ -549,7 +551,6 @@ static void writeRadio(unsigned char *bytes, int len) seq[0] |= 0x04; } - int ret; if ((ret = write(uh_device_fd, seq, 4)) < 4) { MYERROR("WriteRadio failed with %d\n", ret); @@ -620,6 +621,8 @@ static void writeWkey(unsigned char *bytes, int len) for (i = 0; i < len; i++) { + int ret; + seq[ 0] = 0x08; seq[ 1] = 0x80; seq[ 2] = 0x80; @@ -643,7 +646,6 @@ static void writeWkey(unsigned char *bytes, int len) seq[ 8] |= 0x01; } - int ret; if ((ret = write(uh_device_fd, seq, 12)) < 12) { MYERROR("WriteWINKEY failed with %d\n", ret); @@ -680,6 +682,8 @@ static void writeControl(unsigned char *data, int len) for (i = 0; i < len; i++) { + int ret; + // encode statusbyte in first frame seq[0] = 0x08; seq[1] = 0x80; @@ -705,7 +709,6 @@ static void writeControl(unsigned char *data, int len) seq[4] |= 0x01; } - int ret; if ((ret = write(uh_device_fd, seq, 8)) < 8) { MYERROR("WriteControl failed, ret=%d\n", ret); @@ -761,6 +764,8 @@ static void *read_device(void *p) // terminates if the device is closed. for (;;) { + int ret; + int maxdev; // // setting uh_is_initialized to zero in the main thread // tells this one that it is all over now @@ -792,7 +797,7 @@ static void *read_device(void *p) FD_SET(uh_wkey_pair[0], &fds); // determine max of these fd's for use in select() - int maxdev = uh_device_fd; + maxdev = uh_device_fd; if (uh_radio_pair[0] > maxdev) { @@ -811,7 +816,7 @@ static void *read_device(void *p) tv.tv_usec = 100000; tv.tv_sec = 0; - int ret = select(maxdev + 1, &fds, NULL, NULL, &tv); + ret = select(maxdev + 1, &fds, NULL, NULL, &tv); // // select returned error, or nothing has arrived: diff --git a/src/network.c b/src/network.c index 192a48ad3..9aba3ba6f 100644 --- a/src/network.c +++ b/src/network.c @@ -229,6 +229,7 @@ int network_open(hamlib_port_t *rp, int default_port) do { + char msg[1024]; fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol); if (fd < 0) @@ -243,7 +244,6 @@ int network_open(hamlib_port_t *rp, int default_port) break; } - char msg[1024]; snprintf(msg, sizeof(msg), "connect to %s failed, (trying next interface)", rp->pathname); handle_error(RIG_DEBUG_WARN, msg); diff --git a/src/parallel.c b/src/parallel.c index 5b93dab75..26abcc50e 100644 --- a/src/parallel.c +++ b/src/parallel.c @@ -128,8 +128,6 @@ int par_open(hamlib_port_t *port) { int fd; - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - #ifdef HAVE_LINUX_PPDEV_H int mode; #endif @@ -138,6 +136,8 @@ int par_open(hamlib_port_t *port) HANDLE handle; #endif + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + if (!port->pathname[0]) { return -RIG_EINVAL; @@ -240,20 +240,24 @@ int par_close(hamlib_port_t *port) */ int HAMLIB_API par_write_data(hamlib_port_t *port, unsigned char data) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - #ifdef HAVE_LINUX_PPDEV_H int status; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + status = ioctl(port->fd, PPWDATA, &data); return status == 0 ? RIG_OK : -RIG_EIO; #elif defined(HAVE_DEV_PPBUS_PPI_H) int status; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + status = ioctl(port->fd, PPISDATA, &data); return status == 0 ? RIG_OK : -RIG_EIO; #elif defined(__WIN64__) || defined(__WIN32__) unsigned int dummy = 0; intptr_t handle; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + handle = _get_osfhandle(port->fd); @@ -281,14 +285,16 @@ int HAMLIB_API par_write_data(hamlib_port_t *port, unsigned char data) */ int HAMLIB_API par_read_data(hamlib_port_t *port, unsigned char *data) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - #ifdef HAVE_LINUX_PPDEV_H int status; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + status = ioctl(port->fd, PPRDATA, data); return status == 0 ? RIG_OK : -RIG_EIO; #elif defined(HAVE_DEV_PPBUS_PPI_H) int status; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + status = ioctl(port->fd, PPIGDATA, &data); return status == 0 ? RIG_OK : -RIG_EIO; #elif defined(__WIN64__) || defined(__WIN32__) @@ -297,6 +303,8 @@ int HAMLIB_API par_read_data(hamlib_port_t *port, unsigned char *data) intptr_t handle; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + handle = _get_osfhandle(port->fd); if (handle != (intptr_t)INVALID_HANDLE_VALUE) @@ -333,13 +341,13 @@ int HAMLIB_API par_read_data(hamlib_port_t *port, unsigned char *data) */ int HAMLIB_API par_write_control(hamlib_port_t *port, unsigned char control) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - #ifdef HAVE_LINUX_PPDEV_H int status; unsigned char ctrl = control ^ CP_ACTIVE_LOW_BITS; status = ioctl(port->fd, PPWCONTROL, &ctrl); + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + if (status < 0) { rig_debug(RIG_DEBUG_ERR, @@ -352,6 +360,8 @@ int HAMLIB_API par_write_control(hamlib_port_t *port, unsigned char control) #elif defined(HAVE_DEV_PPBUS_PPI_H) int status; unsigned char ctrl = control ^ CP_ACTIVE_LOW_BITS; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + status = ioctl(port->fd, PPISCTRL, &ctrl); return status == 0 ? RIG_OK : -RIG_EIO; #elif defined(__WIN64__) || defined(__WIN32__) @@ -364,6 +374,8 @@ int HAMLIB_API par_write_control(hamlib_port_t *port, unsigned char control) | C1284_NSELECTIN); intptr_t handle; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + if (ctr & 0x20) { rig_debug(RIG_DEBUG_WARN, @@ -409,11 +421,12 @@ int HAMLIB_API par_write_control(hamlib_port_t *port, unsigned char control) */ int HAMLIB_API par_read_control(hamlib_port_t *port, unsigned char *control) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); #ifdef HAVE_LINUX_PPDEV_H int status; unsigned char ctrl; + + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); status = ioctl(port->fd, PPRCONTROL, &ctrl); if (status < 0) @@ -429,6 +442,8 @@ int HAMLIB_API par_read_control(hamlib_port_t *port, unsigned char *control) #elif defined(HAVE_DEV_PPBUS_PPI_H) int status; unsigned char ctrl; + + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); status = ioctl(port->fd, PPIGCTRL, &ctrl); *control = ctrl ^ CP_ACTIVE_LOW_BITS; return status == 0 ? RIG_OK : -RIG_EIO; @@ -438,6 +453,7 @@ int HAMLIB_API par_read_control(hamlib_port_t *port, unsigned char *control) intptr_t handle; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); handle = _get_osfhandle(port->fd); if (handle != (intptr_t)INVALID_HANDLE_VALUE) @@ -476,12 +492,12 @@ int HAMLIB_API par_read_control(hamlib_port_t *port, unsigned char *control) */ int HAMLIB_API par_read_status(hamlib_port_t *port, unsigned char *status) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); #ifdef HAVE_LINUX_PPDEV_H int ret; unsigned char sta; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); ret = ioctl(port->fd, PPRSTATUS, &sta); *status = sta ^ SP_ACTIVE_LOW_BITS; return ret == 0 ? RIG_OK : -RIG_EIO; @@ -490,6 +506,7 @@ int HAMLIB_API par_read_status(hamlib_port_t *port, unsigned char *status) int ret; unsigned char sta; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); ret = ioctl(port->fd, PPIGSTATUS, &sta); *status = sta ^ SP_ACTIVE_LOW_BITS; return ret == 0 ? RIG_OK : -RIG_EIO; @@ -500,6 +517,7 @@ int HAMLIB_API par_read_status(hamlib_port_t *port, unsigned char *status) intptr_t handle; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); handle = _get_osfhandle(port->fd); if (handle != (intptr_t)INVALID_HANDLE_VALUE) diff --git a/src/rig.c b/src/rig.c index dc2bb3928..3f6d07093 100644 --- a/src/rig.c +++ b/src/rig.c @@ -1094,6 +1094,7 @@ int HAMLIB_API rig_set_freq(RIG *rig, vfo_t vfo, freq_t freq) const struct rig_caps *caps; int retcode; vfo_t curr_vfo; + int rc2; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -1142,7 +1143,7 @@ int HAMLIB_API rig_set_freq(RIG *rig, vfo_t vfo, freq_t freq) retcode = caps->set_freq(rig, vfo, freq); /* try and revert even if we had an error above */ - int rc2 = caps->set_vfo(rig, curr_vfo); + rc2 = caps->set_vfo(rig, curr_vfo); if (RIG_OK == retcode) { @@ -1205,6 +1206,7 @@ int HAMLIB_API rig_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) } else { + int rc2; if (!caps->set_vfo) { return -RIG_ENAVAIL; @@ -1220,7 +1222,7 @@ int HAMLIB_API rig_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) retcode = caps->get_freq(rig, vfo, freq); /* try and revert even if we had an error above */ - int rc2 = caps->set_vfo(rig, curr_vfo); + rc2 = caps->set_vfo(rig, curr_vfo); if (RIG_OK == retcode) { @@ -1297,6 +1299,7 @@ int HAMLIB_API rig_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) } else { + int rc2; if (!caps->set_vfo) { @@ -1313,7 +1316,7 @@ int HAMLIB_API rig_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) retcode = caps->set_mode(rig, vfo, mode, width); /* try and revert even if we had an error above */ - int rc2 = caps->set_vfo(rig, curr_vfo); + rc2 = caps->set_vfo(rig, curr_vfo); /* return the first error code */ if (RIG_OK == retcode) @@ -1383,6 +1386,7 @@ int HAMLIB_API rig_get_mode(RIG *rig, } else { + int rc2; if (!caps->set_vfo) { @@ -1399,7 +1403,7 @@ int HAMLIB_API rig_get_mode(RIG *rig, retcode = caps->get_mode(rig, vfo, mode, width); /* try and revert even if we had an error above */ - int rc2 = caps->set_vfo(rig, curr_vfo); + rc2 = caps->set_vfo(rig, curr_vfo); if (RIG_OK == retcode) { @@ -1720,9 +1724,10 @@ int HAMLIB_API rig_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) if (retcode == RIG_OK) { + int rc2; retcode = caps->set_ptt(rig, vfo, ptt); /* try and revert even if we had an error above */ - int rc2 = caps->set_vfo(rig, curr_vfo); + rc2 = caps->set_vfo(rig, curr_vfo); /* return the first error code */ if (RIG_OK == retcode) diff --git a/src/rotator.c b/src/rotator.c index 4817be3c8..29300f063 100644 --- a/src/rotator.c +++ b/src/rotator.c @@ -627,6 +627,7 @@ int HAMLIB_API rot_get_position(ROT *rot, { const struct rot_caps *caps; const struct rot_state *rs; + int retval; rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -643,7 +644,7 @@ int HAMLIB_API rot_get_position(ROT *rot, return -RIG_ENAVAIL; } - int retval = caps->get_position(rot, azimuth, elevation); + retval = caps->get_position(rot, azimuth, elevation); if (retval != RIG_OK) { return retval; } diff --git a/src/usb_port.c b/src/usb_port.c index 8dfc7a7c9..55ec409cd 100644 --- a/src/usb_port.c +++ b/src/usb_port.c @@ -376,10 +376,11 @@ int usb_port_open(hamlib_port_t *port) */ int usb_port_close(hamlib_port_t *port) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); libusb_device_handle *udh = port->handle; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + libusb_release_interface(udh, port->parm.usb.iface); libusb_close(udh); diff --git a/tentec/jupiter.c b/tentec/jupiter.c index 614c51095..40189d267 100644 --- a/tentec/jupiter.c +++ b/tentec/jupiter.c @@ -506,8 +506,18 @@ int tt538_get_split_vfo(RIG *rig, vfo_t vfo, split_t *split, vfo_t *tx_vfo) int tt538_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) { int cmd_len, resp_len, retval; + int rpb; unsigned char cmdbuf[16], respbuf[32]; char ttmode; + /* Find bandwidth according to response from table. */ + static int pbwidth[39] = + { + 8000, 6000, 5700, 5400, 5100, 4800, 4500, 4200, + 3900, 3600, 3300, 3000, 2850, 2700, 2550, 2400, + 2250, 2100, 1950, 1800, 1650, 1500, 1350, 1200, + 1050, 900, 750, 675, 600, 525, 450, 375, + 330, 300, 260, 225, 180, 165, 150 + }; /* Query mode */ cmd_len = sprintf((char *) cmdbuf, "?M" EOM); @@ -580,16 +590,7 @@ int tt538_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) return -RIG_EPROTO; } - /* Find bandwidth according to response from table. */ - static int pbwidth[39] = - { - 8000, 6000, 5700, 5400, 5100, 4800, 4500, 4200, - 3900, 3600, 3300, 3000, 2850, 2700, 2550, 2400, - 2250, 2100, 1950, 1800, 1650, 1500, 1350, 1200, - 1050, 900, 750, 675, 600, 525, 450, 375, - 330, 300, 260, 225, 180, 165, 150 - }; - int rpb = respbuf[1]; + rpb = respbuf[1]; if (rpb >= 0 && rpb <= 38) { diff --git a/tentec/omnivii.c b/tentec/omnivii.c index 417872ff4..250d80b9f 100644 --- a/tentec/omnivii.c +++ b/tentec/omnivii.c @@ -378,6 +378,7 @@ static char which_vfo(const RIG *rig, vfo_t vfo) int tt588_get_vfo(RIG *rig, vfo_t *vfo) { static int getinfo = TRUE; + struct tt588_priv_data *priv = (struct tt588_priv_data *) rig->state.priv; if (getinfo) // this is the first call to this package so we do this here { @@ -385,8 +386,6 @@ int tt588_get_vfo(RIG *rig, vfo_t *vfo) tt588_get_info(rig); } - struct tt588_priv_data *priv = (struct tt588_priv_data *) rig->state.priv; - *vfo = priv->vfo_curr; if (check_vfo(*vfo) == FALSE) @@ -601,11 +600,11 @@ int tt588_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) int cmd_len, resp_len, retval; unsigned char cmdbuf[16], respbuf[32]; char ttmode; + struct tt588_priv_data *priv = (struct tt588_priv_data *) rig->state.priv; + rig_debug(RIG_DEBUG_VERBOSE, "%s: vfo=%s\n", __func__, rig_strvfo(vfo)); - struct tt588_priv_data *priv = (struct tt588_priv_data *) rig->state.priv; - if (check_vfo(vfo) == FALSE) { rig_debug(RIG_DEBUG_ERR, "%s: unsupported VFO %s\n", __func__, rig_strvfo(vfo)); @@ -981,10 +980,11 @@ int tt588_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) { // transmit reply example S<0x8f><0x01> 0x0f=15 watts, 0x01 // it appears 0x01 refelected = 0W since 0 means not read yet + int strength; int reflected = (int)lvlbuf[2]; reflected = reflected > 0 ? reflected - 1 : 0; // computer transmit power - int strength = (int)(lvlbuf[1] & 0x7f) - reflected; + strength = (int)(lvlbuf[1] & 0x7f) - reflected; rig_debug(RIG_DEBUG_TRACE, "%s: strength fwd=%d, rev=%d\n", __func__, strength, reflected); diff --git a/tentec/orion.c b/tentec/orion.c index c5d4f6ff1..241c14d40 100644 --- a/tentec/orion.c +++ b/tentec/orion.c @@ -129,9 +129,10 @@ static int tt565_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, /* Allow transaction re-tries according to capabilities. */ for (itry = 0; itry < rig->caps->retry; itry++) { + int retval; rs = &rig->state; serial_flush(&rs->rigport); /* discard pending i/p */ - int retval = write_block(&rs->rigport, cmd, cmd_len); + retval = write_block(&rs->rigport, cmd, cmd_len); if (retval != RIG_OK) { @@ -1332,8 +1333,9 @@ int tt565_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) } else /* look at main rx info */ { + char *raw_field2; raw_field = lvlbuf + 4; - char *raw_field2 = strchr(raw_field, 'S'); /* position may vary */ + raw_field2 = strchr(raw_field, 'S'); /* position may vary */ if (raw_field2) { *raw_field2 = '\0'; } /* valid string */ } diff --git a/tentec/rx331.c b/tentec/rx331.c index 9e109247c..f0aa52ed3 100644 --- a/tentec/rx331.c +++ b/tentec/rx331.c @@ -247,6 +247,7 @@ static int rx331_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int rig_id; int retval; char str[BUFSZ]; + char fmt[16]; struct rig_state *rs; struct rx331_priv_data *priv = (struct rx331_priv_data *)rig->state.priv; @@ -275,7 +276,6 @@ static int rx331_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, return retval; } - char fmt[16]; snprintf(fmt,sizeof(fmt)-1,"%%i%%%ds",BUFSZ); sscanf(data + 1, fmt, &rig_id, data); diff --git a/tests/ampctl.c b/tests/ampctl.c index a65a94133..52ddc875c 100644 --- a/tests/ampctl.c +++ b/tests/ampctl.c @@ -371,6 +371,7 @@ int main(int argc, char *argv[]) if (rd_hist || sv_hist) { + int hist_path_size; if (!(hist_dir = getenv("AMPCTL_HIST_DIR"))) { hist_dir = getenv("HOME"); @@ -383,7 +384,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Warning: %s is not a directory!\n", hist_dir); } - int hist_path_size = sizeof(char) * (strlen(hist_dir) + strlen(hist_file) + 1); + hist_path_size = sizeof(char) * (strlen(hist_dir) + strlen(hist_file) + 1); hist_path = (char *)calloc(hist_path_size, sizeof(char)); snprintf(hist_path, hist_path_size, "%s%s", hist_dir, hist_file); diff --git a/tests/ampctl_parse.c b/tests/ampctl_parse.c index 4c63a593d..0ee8e91ff 100644 --- a/tests/ampctl_parse.c +++ b/tests/ampctl_parse.c @@ -1049,8 +1049,8 @@ int ampctl_parse(AMP *my_amp, FILE *fin, FILE *fout, char *argv[], int argc) } else { - x = 0; char pmptstr[(strlen(cmd_entry->arg1) + 3)]; + x = 0; strcpy(pmptstr, cmd_entry->arg1); strcat(pmptstr, ": "); @@ -1107,8 +1107,8 @@ int ampctl_parse(AMP *my_amp, FILE *fin, FILE *fout, char *argv[], int argc) } else { - x = 0; char pmptstr[(strlen(cmd_entry->arg1) + 3)]; + x = 0; strcpy(pmptstr, cmd_entry->arg1); strcat(pmptstr, ": "); @@ -1168,8 +1168,8 @@ int ampctl_parse(AMP *my_amp, FILE *fin, FILE *fout, char *argv[], int argc) } else { - x = 0; char pmptstr[(strlen(cmd_entry->arg2) + 3)]; + x = 0; strcpy(pmptstr, cmd_entry->arg2); strcat(pmptstr, ": "); @@ -1229,8 +1229,8 @@ int ampctl_parse(AMP *my_amp, FILE *fin, FILE *fout, char *argv[], int argc) } else { - x = 0; char pmptstr[(strlen(cmd_entry->arg3) + 3)]; + x = 0; strcpy(pmptstr, cmd_entry->arg3); strcat(pmptstr, ": "); @@ -1290,8 +1290,8 @@ int ampctl_parse(AMP *my_amp, FILE *fin, FILE *fout, char *argv[], int argc) } else { - x = 0; char pmptstr[(strlen(cmd_entry->arg4) + 3)]; + x = 0; strcpy(pmptstr, cmd_entry->arg4); strcat(pmptstr, ": "); diff --git a/tests/ampctld.c b/tests/ampctld.c index 86b724edd..a094b974e 100644 --- a/tests/ampctld.c +++ b/tests/ampctld.c @@ -176,6 +176,9 @@ int main(int argc, char *argv[]) pthread_attr_t attr; #endif struct handle_data *arg; +#if HAVE_SIGACTION + struct sigaction act; +#endif while (1) { @@ -498,7 +501,6 @@ int main(int argc, char *argv[]) that will consequently fail with EPIPE. All child threads will inherit this disposition which is what we want. */ #if HAVE_SIGACTION - struct sigaction act; memset(&act, 0, sizeof act); act.sa_handler = SIG_IGN; act.sa_flags = SA_RESTART; diff --git a/tests/memcsv.c b/tests/memcsv.c index 202a69829..d0ce5a0dd 100644 --- a/tests/memcsv.c +++ b/tests/memcsv.c @@ -271,6 +271,7 @@ static char *mystrtok(char *s, char delim) { static size_t pos = 0, length = 0; static char *str = 0; + size_t i, ent_pos; if (s != NULL) { @@ -287,7 +288,7 @@ static char *mystrtok(char *s, char delim) return NULL; } - size_t i, ent_pos = pos; + ent_pos = pos; for (i = pos; i < length;) { @@ -729,6 +730,7 @@ int set_channel_data(RIG *rig, { int i, j, n; + const channel_cap_t *mem_caps; memset(chan, 0, sizeof(channel_t)); chan->vfo = RIG_VFO_CURR; @@ -754,7 +756,7 @@ int set_channel_data(RIG *rig, printf("Requested channel number %d, list number %d\n", n, j); - const channel_cap_t *mem_caps = &rig->state.chan_list[j].mem_caps; + mem_caps = &rig->state.chan_list[j].mem_caps; if (mem_caps->bank_num) { diff --git a/tests/rigctl.c b/tests/rigctl.c index b2f892a6f..ec4eb03de 100644 --- a/tests/rigctl.c +++ b/tests/rigctl.c @@ -157,6 +157,7 @@ int main(int argc, char *argv[]) char send_cmd_term = '\r'; /* send_cmd termination char */ int ext_resp = 0; char resp_sep = '\n'; + int i; while (1) { @@ -513,7 +514,7 @@ int main(int argc, char *argv[]) exit(0); } - int i=0; + i=0; do { // we'll try 5 times and sleep 200ms between tries retcode = rig_open(my_rig); if (retcode != RIG_OK) { @@ -581,6 +582,7 @@ int main(int argc, char *argv[]) if (rd_hist || sv_hist) { + int hist_path_size; if (!(hist_dir = getenv("RIGCTL_HIST_DIR"))) { hist_dir = getenv("HOME"); @@ -592,7 +594,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Warning: %s is not a directory!\n", hist_dir); } - int hist_path_size = sizeof(char) * (strlen(hist_dir) + strlen(hist_file) + 1); + hist_path_size = sizeof(char) * (strlen(hist_dir) + strlen(hist_file) + 1); hist_path = (char *)calloc(hist_path_size, sizeof(char)); snprintf(hist_path, hist_path_size, "%s%s", hist_dir, hist_file); diff --git a/tests/rigctl_parse.c b/tests/rigctl_parse.c index 766ba7dbd..02d11ba58 100644 --- a/tests/rigctl_parse.c +++ b/tests/rigctl_parse.c @@ -1259,8 +1259,8 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc, } else { - x = 0; char pmptstr[(strlen(cmd_entry->arg1) + 3)]; + x = 0; strcpy(pmptstr, cmd_entry->arg1); strcat(pmptstr, ": "); @@ -1322,8 +1322,8 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc, } else { - x = 0; char pmptstr[(strlen(cmd_entry->arg1) + 3)]; + x = 0; strcpy(pmptstr, cmd_entry->arg1); strcat(pmptstr, ": "); @@ -1388,8 +1388,8 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc, } else { - x = 0; char pmptstr[(strlen(cmd_entry->arg2) + 3)]; + x = 0; strcpy(pmptstr, cmd_entry->arg2); strcat(pmptstr, ": "); @@ -1454,8 +1454,8 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc, } else { - x = 0; char pmptstr[(strlen(cmd_entry->arg3) + 3)]; + x = 0; strcpy(pmptstr, cmd_entry->arg3); strcat(pmptstr, ": "); @@ -1641,12 +1641,12 @@ void usage_rig(FILE *fout) for (i = 0; test_list[i].cmd != 0; i++) { + int nbspaces = 18; fprintf(fout, "%c: %-16s(", isprint(test_list[i].cmd) ? test_list[i].cmd : '?', test_list[i].name); - int nbspaces = 18; if (test_list[i].arg1 && (test_list[i].flags & ARG_IN1)) { @@ -1797,6 +1797,8 @@ int set_conf(RIG *my_rig, char *conf_parms) while (p && *p != '\0') { + int ret; + /* FIXME: left hand value of = cannot be null */ char *q = strchr(p, '='); @@ -1813,7 +1815,7 @@ int set_conf(RIG *my_rig, char *conf_parms) *n++ = '\0'; } - int ret = rig_set_conf(my_rig, rig_token_lookup(my_rig, p), q); + ret = rig_set_conf(my_rig, rig_token_lookup(my_rig, p), q); if (ret != RIG_OK) { diff --git a/tests/rigctlcom.c b/tests/rigctlcom.c index 3583333d8..f391cea2d 100644 --- a/tests/rigctlcom.c +++ b/tests/rigctlcom.c @@ -206,6 +206,7 @@ int main(int argc, char *argv[]) int serial_rate2 = 115200; /* virtual com port default speed */ char *civaddr = NULL; /* NULL means no need to set conf */ char conf_parms[MAXCONFLEN] = ""; + int status; printf("rigctlcom Version 1.1\n"); @@ -574,7 +575,7 @@ int main(int argc, char *argv[]) my_com.parm.serial.parity = RIG_PARITY_NONE; my_com.parm.serial.handshake = RIG_HANDSHAKE_NONE; - int status = port_open(&my_com); + status = port_open(&my_com); if (status != RIG_OK) { @@ -794,6 +795,8 @@ static int handle_ts2000(void *arg) else if (strcmp(arg, "FA;") == 0) { freq_t freq = 0; + char response[32]; + int retval = rig_get_freq(my_rig, RIG_VFO_A, &freq); if (retval != RIG_OK) @@ -803,13 +806,12 @@ static int handle_ts2000(void *arg) return retval; } - char response[32]; - snprintf(response, sizeof(response), "FA%011"PRIll";", (uint64_t)freq); return write_block2((void *)__func__, &my_com, response, strlen(response)); } else if (strcmp(arg, "FB;") == 0) { + char response[32]; freq_t freq = 0; int retval = rig_get_freq(my_rig, RIG_VFO_B, &freq); @@ -820,8 +822,6 @@ static int handle_ts2000(void *arg) return retval; } - char response[32]; - snprintf(response, sizeof(response), "FB%011"PRIll";", (uint64_t)freq); return write_block2((void *)__func__, &my_com, response, strlen(response)); } @@ -864,8 +864,10 @@ static int handle_ts2000(void *arg) } else if (strcmp(arg, "FR;") == 0) { + char response[32]; vfo_t vfo; int retval = rig_get_vfo(my_rig, &vfo); + int nvfo = 0; if (retval != RIG_OK) { @@ -874,7 +876,6 @@ static int handle_ts2000(void *arg) return retval; } - int nvfo = 0; if (vfo == RIG_VFO_A) { nvfo = 0; } else if (vfo == RIG_VFO_B) { nvfo = 1; } @@ -884,7 +885,6 @@ static int handle_ts2000(void *arg) return retval; } - char response[32]; snprintf(response, sizeof(response), "FR%c;", nvfo + '0'); return write_block2((void *)__func__, &my_com, response, strlen(response)); @@ -892,8 +892,10 @@ static int handle_ts2000(void *arg) } else if (strcmp(arg, "FT;") == 0) { + char response[32]; vfo_t vfo, vfo_curr = RIG_VFO_A; split_t split; + int nvfo = 0; int retval = rig_get_split_vfo(my_rig, vfo_curr, &split, &vfo); if (retval != RIG_OK) @@ -903,7 +905,6 @@ static int handle_ts2000(void *arg) return retval; } - int nvfo = 0; if (vfo == RIG_VFO_A) { nvfo = 0; } else if (vfo == RIG_VFO_B) { nvfo = 1; } @@ -913,7 +914,6 @@ static int handle_ts2000(void *arg) return retval; } - char response[32]; snprintf(response, sizeof(response), "FT%c;", nvfo + '0'); return write_block2((void *)__func__, &my_com, response, strlen(response)); @@ -921,6 +921,7 @@ static int handle_ts2000(void *arg) } else if (strcmp(arg, "TN;") == 0) { + char response[32]; tone_t val; int retval = rig_get_ctcss_tone(my_rig, RIG_VFO_CURR, &val); @@ -931,16 +932,17 @@ static int handle_ts2000(void *arg) return retval; } - char response[32]; snprintf(response, sizeof(response), "TN%02d;", val); return write_block2((void *)__func__, &my_com, response, strlen(response)); } else if (strncmp(arg, "TN", 2) == 0) { + tone_t val; int ival = 0; + int retval; sscanf(arg, "TN%d", &ival); - tone_t val = ival; - int retval = rig_set_ctcss_tone(my_rig, RIG_VFO_CURR, val); + val = ival; + retval = rig_set_ctcss_tone(my_rig, RIG_VFO_CURR, val); if (retval != RIG_OK) { @@ -952,8 +954,10 @@ static int handle_ts2000(void *arg) } else if (strcmp(arg, "PA;") == 0) { + char response[32]; int valA; int retval = rig_get_func(my_rig, RIG_VFO_A, RIG_FUNC_AIP, &valA); + int valB; if (retval != RIG_OK) { @@ -969,7 +973,6 @@ static int handle_ts2000(void *arg) return retval; } - int valB; retval = rig_get_func(my_rig, RIG_VFO_B, RIG_FUNC_AIP, &valB); if (retval != RIG_OK) @@ -979,7 +982,6 @@ static int handle_ts2000(void *arg) return retval; } - char response[32]; snprintf(response, sizeof(response), "PA%c%c;", valA + '0', valB + '0'); return write_block2((void *)__func__, &my_com, response, strlen(response)); } @@ -987,6 +989,7 @@ static int handle_ts2000(void *arg) { int valA = 0; int valB = 0; + int retval; int n = sscanf(arg, "PA%1d%1d", &valA, &valB); if (n != 2) @@ -995,7 +998,7 @@ static int handle_ts2000(void *arg) (char *)arg); } - int retval = rig_set_func(my_rig, RIG_VFO_A, RIG_FUNC_AIP, valA); + retval = rig_set_func(my_rig, RIG_VFO_A, RIG_FUNC_AIP, valA); if (retval != RIG_OK) { @@ -1017,6 +1020,7 @@ static int handle_ts2000(void *arg) } else if (strcmp(arg, "XT;") == 0) { + char response[32]; int val; int retval = rig_get_func(my_rig, RIG_VFO_CURR, RIG_FUNC_XIT, &val); @@ -1034,15 +1038,15 @@ static int handle_ts2000(void *arg) return retval; } - char response[32]; snprintf(response, sizeof(response), "XT%c;", val + '0'); return write_block2((void *)__func__, &my_com, response, strlen(response)); } else if (strncmp(arg, "XT", 2) == 0) { int val = 0; + int retval; sscanf(arg, "XT%d", &val); - int retval = rig_set_func(my_rig, RIG_VFO_CURR, RIG_FUNC_XIT, val); + retval = rig_set_func(my_rig, RIG_VFO_CURR, RIG_FUNC_XIT, val); if (retval != RIG_OK) { @@ -1060,6 +1064,7 @@ static int handle_ts2000(void *arg) } else if (strcmp(arg, "NR;") == 0) { + char response[32]; int val; int retval = rig_get_func(my_rig, RIG_VFO_CURR, RIG_FUNC_NR, &val); @@ -1076,15 +1081,15 @@ static int handle_ts2000(void *arg) return retval; } - char response[32]; snprintf(response, sizeof(response), "NR%c;", val + '0'); return write_block2((void *)__func__, &my_com, response, strlen(response)); } else if (strncmp(arg, "NR", 2) == 0) { int val = 0; + int retval; sscanf(arg, "NR%d", &val); - int retval = rig_set_func(my_rig, RIG_VFO_CURR, RIG_FUNC_NR, val); + retval = rig_set_func(my_rig, RIG_VFO_CURR, RIG_FUNC_NR, val); if (retval != RIG_OK) { @@ -1101,6 +1106,7 @@ static int handle_ts2000(void *arg) } else if (strcmp(arg, "NB;") == 0) { + char response[32]; int val; int retval = rig_get_func(my_rig, RIG_VFO_CURR, RIG_FUNC_NB, &val); @@ -1118,15 +1124,14 @@ static int handle_ts2000(void *arg) return retval; } - char response[32]; snprintf(response, sizeof(response), "NB%c;", val + '0'); return write_block2((void *)__func__, &my_com, response, strlen(response)); } else if (strncmp(arg, "NB", 2) == 0) { int val = 0; - sscanf(arg, "NB%d", &val); int retval = rig_set_func(my_rig, RIG_VFO_CURR, RIG_FUNC_NB, val); + sscanf(arg, "NB%d", &val); if (retval != RIG_OK) { @@ -1146,6 +1151,8 @@ static int handle_ts2000(void *arg) { value_t val; int retval = rig_get_level(my_rig, RIG_VFO_CURR, RIG_LEVEL_AF, &val); + char response[32]; + int level; if (retval != RIG_OK) { @@ -1161,8 +1168,7 @@ static int handle_ts2000(void *arg) return retval; } - char response[32]; - int level = val.f * 255; + level = val.f * 255; snprintf(response, sizeof(response), "AG0%03d;", level); return write_block2((void *)__func__, &my_com, response, strlen(response)); } @@ -1170,6 +1176,8 @@ static int handle_ts2000(void *arg) { int level = 0; int n = sscanf(arg, "AG%d", &level); + int retval; + value_t val; if (n != 1) { @@ -1178,9 +1186,8 @@ static int handle_ts2000(void *arg) return -RIG_EPROTO; } - value_t val; val.f = level / 255.0; - int retval = rig_set_level(my_rig, RIG_VFO_CURR, RIG_LEVEL_AF, val); + retval = rig_set_level(my_rig, RIG_VFO_CURR, RIG_LEVEL_AF, val); if (retval != RIG_OK) { @@ -1192,8 +1199,10 @@ static int handle_ts2000(void *arg) } else if (strcmp(arg, "PR;") == 0) { + char response[32]; value_t val; int retval = rig_get_level(my_rig, RIG_VFO_CURR, RIG_LEVEL_COMP, &val); + int speechLevel; if (retval != RIG_OK) { @@ -1209,15 +1218,16 @@ static int handle_ts2000(void *arg) return retval; } - char response[32]; - int speechLevel = val.f * 255; + speechLevel = val.f * 255; snprintf(response, sizeof(response), "PR%03d;", speechLevel); return write_block2((void *)__func__, &my_com, response, strlen(response)); } else if (strncmp(arg, "PR", 2) == 0) { + value_t val; int speechLevel = 0; int n = sscanf(arg, "PR%d", &speechLevel); + int retval; if (n != 1) { @@ -1226,9 +1236,8 @@ static int handle_ts2000(void *arg) return -RIG_EPROTO; } - value_t val; val.f = speechLevel / 255.0; - int retval = rig_set_level(my_rig, RIG_VFO_CURR, RIG_LEVEL_COMP, val); + retval = rig_set_level(my_rig, RIG_VFO_CURR, RIG_LEVEL_COMP, val); if (retval != RIG_OK) { @@ -1248,6 +1257,8 @@ static int handle_ts2000(void *arg) { value_t val; int retval = rig_get_level(my_rig, RIG_VFO_CURR, RIG_LEVEL_AGC, &val); + char response[32]; + int agcLevel; if (retval != RIG_OK) { @@ -1263,8 +1274,7 @@ static int handle_ts2000(void *arg) return retval; } - char response[32]; - int agcLevel = val.f * 255; + agcLevel = val.f * 255; snprintf(response, sizeof(response), "GT%03d;", agcLevel); return write_block2((void *)__func__, &my_com, response, strlen(response)); } @@ -1272,6 +1282,8 @@ static int handle_ts2000(void *arg) { int agcLevel = 0; int n = sscanf(arg, "GT%d", &agcLevel); + int retval; + value_t val; if (n != 1) { @@ -1280,9 +1292,8 @@ static int handle_ts2000(void *arg) return -RIG_EPROTO; } - value_t val; val.f = agcLevel / 255.0; - int retval = rig_set_level(my_rig, RIG_VFO_CURR, RIG_LEVEL_AGC, val); + retval = rig_set_level(my_rig, RIG_VFO_CURR, RIG_LEVEL_AGC, val); if (retval != RIG_OK) { @@ -1294,8 +1305,10 @@ static int handle_ts2000(void *arg) } else if (strcmp(arg, "SQ;") == 0) { + char response[32]; value_t val; int retval = rig_get_level(my_rig, RIG_VFO_CURR, RIG_LEVEL_SQL, &val); + int sqlev; if (retval != RIG_OK) { @@ -1311,8 +1324,7 @@ static int handle_ts2000(void *arg) return retval; } - char response[32]; - int sqlev = val.f * 255; + sqlev = val.f * 255; snprintf(response, sizeof(response), "SQ%03d;", sqlev); return write_block2((void *)__func__, &my_com, response, strlen(response)); } @@ -1320,6 +1332,8 @@ static int handle_ts2000(void *arg) { int sqlev = 0; int n = sscanf(arg, "SQ%d", &sqlev); + int retval; + value_t val; if (n != 1) { @@ -1328,9 +1342,8 @@ static int handle_ts2000(void *arg) return -RIG_EPROTO; } - value_t val; val.f = sqlev / 255.0; - int retval = rig_set_level(my_rig, RIG_VFO_CURR, RIG_LEVEL_SQL, val); + retval = rig_set_level(my_rig, RIG_VFO_CURR, RIG_LEVEL_SQL, val); if (retval != RIG_OK) { @@ -1350,6 +1363,7 @@ static int handle_ts2000(void *arg) { vfo_t vfo, vfo_curr = RIG_VFO_A; split_t split; + char response[32]; int retval = rig_get_split_vfo(my_rig, vfo_curr, &split, &vfo); if (retval != RIG_OK) @@ -1359,7 +1373,6 @@ static int handle_ts2000(void *arg) return retval; } - char response[32]; snprintf(response, sizeof(response), "DC%c;", split + '0'); return write_block2((void *)__func__, &my_com, response, strlen(response)); @@ -1370,6 +1383,8 @@ static int handle_ts2000(void *arg) vfo_t vfo_curr = RIG_VFO_A; split_t split; int isplit; + int retval; + char response[32]; // Expecting DCnn -- but we dont' care about the control param int n = sscanf(arg, "DC%d", &isplit); @@ -1380,7 +1395,7 @@ static int handle_ts2000(void *arg) } split = isplit; - int retval = rig_set_split_vfo(my_rig, vfo_curr, split, RIG_VFO_SUB); + retval = rig_set_split_vfo(my_rig, vfo_curr, split, RIG_VFO_SUB); if (retval != RIG_OK) { @@ -1389,7 +1404,6 @@ static int handle_ts2000(void *arg) return retval; } - char response[32]; snprintf(response, sizeof(response), "DC%c;", split + '0'); return write_block2((void *)__func__, &my_com, response, strlen(response)); @@ -1419,6 +1433,7 @@ static int handle_ts2000(void *arg) } else if (strncmp(arg, "MD", 2) == 0) { + char response[32]; mode_t mode = 0; int imode = 0; @@ -1447,8 +1462,6 @@ static int handle_ts2000(void *arg) case 9: mode = RIG_MODE_RTTYR; break; } - char response[32]; - snprintf(response, sizeof(response), "MD%c;", mode + '0'); return write_block2((void *)__func__, &my_com, response, strlen(response)); } diff --git a/tests/rigctld.c b/tests/rigctld.c index 91590acfc..2fa03cc30 100644 --- a/tests/rigctld.c +++ b/tests/rigctld.c @@ -248,6 +248,9 @@ int main(int argc, char *argv[]) int reuseaddr = 1; char host[NI_MAXHOST]; char serv[NI_MAXSERV]; +#if HAVE_SIGACTION + struct sigaction act; +#endif #ifdef HAVE_PTHREAD pthread_t thread; @@ -723,7 +726,6 @@ int main(int argc, char *argv[]) } #if HAVE_SIGACTION - struct sigaction act; #ifdef SIGPIPE /* Ignore SIGPIPE as we will handle it at the write()/send() calls @@ -781,6 +783,9 @@ int main(int argc, char *argv[]) */ do { + fd_set set; + struct timeval timeout; + arg = malloc(sizeof(struct handle_data)); if (!arg) @@ -790,8 +795,6 @@ int main(int argc, char *argv[]) } /* use select to allow for periodic checks for CTRL+C */ - fd_set set; - struct timeval timeout; FD_ZERO(&set); FD_SET(sock_listen, &set); timeout.tv_sec = 5; diff --git a/tests/rigmem.c b/tests/rigmem.c index 5c26646ca..1382f442c 100644 --- a/tests/rigmem.c +++ b/tests/rigmem.c @@ -427,6 +427,8 @@ int set_conf(RIG *rig, char *conf_parms) while (p && *p != '\0') { + int ret; + /* FIXME: left hand value of = cannot be null */ char *q = strchr(p, '='); @@ -443,7 +445,7 @@ int set_conf(RIG *rig, char *conf_parms) *n++ = '\0'; } - int ret = rig_set_conf(rig, rig_token_lookup(rig, p), q); + ret = rig_set_conf(rig, rig_token_lookup(rig, p), q); if (ret != RIG_OK) { diff --git a/tests/rotctl.c b/tests/rotctl.c index 099b6c996..43b4456b1 100644 --- a/tests/rotctl.c +++ b/tests/rotctl.c @@ -393,6 +393,7 @@ int main(int argc, char *argv[]) if (rd_hist || sv_hist) { + int hist_path_size; if (!(hist_dir = getenv("ROTCTL_HIST_DIR"))) { hist_dir = getenv("HOME"); @@ -405,7 +406,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Warning: %s is not a directory!\n", hist_dir); } - int hist_path_size = sizeof(char) * (strlen(hist_dir) + strlen(hist_file) + 1); + hist_path_size = sizeof(char) * (strlen(hist_dir) + strlen(hist_file) + 1); hist_path = (char *)calloc(hist_path_size, sizeof(char)); snprintf(hist_path, hist_path_size, "%s%s", hist_dir, hist_file); diff --git a/tests/rotctl_parse.c b/tests/rotctl_parse.c index 6af9b7192..08bdcb1fe 100644 --- a/tests/rotctl_parse.c +++ b/tests/rotctl_parse.c @@ -1076,8 +1076,8 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc, } else { - x = 0; char pmptstr[(strlen(cmd_entry->arg1) + 3)]; + x = 0; strcpy(pmptstr, cmd_entry->arg1); strcat(pmptstr, ": "); @@ -1134,8 +1134,8 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc, } else { - x = 0; char pmptstr[(strlen(cmd_entry->arg1) + 3)]; + x = 0; strcpy(pmptstr, cmd_entry->arg1); strcat(pmptstr, ": "); @@ -1195,8 +1195,8 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc, } else { - x = 0; char pmptstr[(strlen(cmd_entry->arg2) + 3)]; + x = 0; strcpy(pmptstr, cmd_entry->arg2); strcat(pmptstr, ": "); @@ -1256,8 +1256,8 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc, } else { - x = 0; char pmptstr[(strlen(cmd_entry->arg3) + 3)]; + x = 0; strcpy(pmptstr, cmd_entry->arg3); strcat(pmptstr, ": "); @@ -1317,8 +1317,8 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc, } else { - x = 0; char pmptstr[(strlen(cmd_entry->arg4) + 3)]; + x = 0; strcpy(pmptstr, cmd_entry->arg4); strcat(pmptstr, ": "); @@ -1798,6 +1798,8 @@ declare_proto_rot(move) /* 'C' */ declare_proto_rot(inter_set_conf) { + char buf[256]; + rot_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); if (!arg2 || arg2[0] == '\0') @@ -1807,7 +1809,6 @@ declare_proto_rot(inter_set_conf) return -RIG_EINVAL; } - char buf[256]; sprintf(buf, "%s=%s", arg1, arg2); return set_conf(rot, buf); } diff --git a/tests/rotctld.c b/tests/rotctld.c index 36971a82c..84e2e00ba 100644 --- a/tests/rotctld.c +++ b/tests/rotctld.c @@ -175,6 +175,9 @@ int main(int argc, char *argv[]) pthread_attr_t attr; #endif struct handle_data *arg; +#if HAVE_SIGACTION + struct sigaction act; +#endif while (1) { @@ -512,7 +515,6 @@ int main(int argc, char *argv[]) that will consequently fail with EPIPE. All child threads will inherit this disposition which is what we want. */ #if HAVE_SIGACTION - struct sigaction act; memset(&act, 0, sizeof act); act.sa_handler = SIG_IGN; act.sa_flags = SA_RESTART; diff --git a/yaesu/ft1000d.c b/yaesu/ft1000d.c index c07a05ff1..9916603bd 100644 --- a/yaesu/ft1000d.c +++ b/yaesu/ft1000d.c @@ -3191,6 +3191,7 @@ int ft1000d_get_update_data(RIG *rig, unsigned char ci, unsigned short ch) int n; int err; int rl; + int retry; char temp[5]; char *p; @@ -3206,7 +3207,7 @@ int ft1000d_get_update_data(RIG *rig, unsigned char ci, unsigned short ch) priv = (struct ft1000d_priv_data *)rig->state.priv; rig_s = &rig->state; - int retry = rig_s->rigport.retry; + retry = rig_s->rigport.retry; do { diff --git a/yaesu/ft817.c b/yaesu/ft817.c index 52b1b5574..ad69e2924 100644 --- a/yaesu/ft817.c +++ b/yaesu/ft817.c @@ -1285,11 +1285,12 @@ int ft817_vfo_op(RIG *rig, vfo_t vfo, vfo_op_t op) { switch (op) { + int n; case RIG_OP_TOGGLE: rig_force_cache_timeout(&((struct ft817_priv_data *) rig->state.priv)->fm_status_tv); - int n = ft817_send_cmd(rig, FT817_NATIVE_CAT_SET_VFOAB); + n = ft817_send_cmd(rig, FT817_NATIVE_CAT_SET_VFOAB); usleep(100 * 1000); // rig needs a little time to do this return n; diff --git a/yaesu/ft891.c b/yaesu/ft891.c index bf598f4ad..189c594f6 100644 --- a/yaesu/ft891.c +++ b/yaesu/ft891.c @@ -519,9 +519,10 @@ int ft891_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) int ft891_init(RIG *rig) { + int ret; rig_debug(RIG_DEBUG_VERBOSE, "%s called, version %s\n", __func__, rig->caps->version); - int ret = newcat_init(rig); + ret = newcat_init(rig); if (ret != RIG_OK) { return ret; } diff --git a/yaesu/ft900.c b/yaesu/ft900.c index c08693398..444814261 100644 --- a/yaesu/ft900.c +++ b/yaesu/ft900.c @@ -1505,6 +1505,7 @@ static int ft900_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) struct ft900_priv_data *priv; unsigned char *p; int err; + cal_table_t cal = FT900_STR_CAL_SMETER; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -1520,6 +1521,7 @@ static int ft900_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) switch (level) { + case RIG_LEVEL_STRENGTH: err = ft900_get_update_data(rig, FT900_NATIVE_READ_METER, FT900_STATUS_FLAGS_LENGTH); @@ -1544,8 +1546,6 @@ static int ft900_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) * is life when mapping non-linear S-meters to a linear scale. * */ - cal_table_t cal = FT900_STR_CAL_SMETER; - if (priv->ptt) { cal = (cal_table_t)FT900_STR_CAL_POWER; diff --git a/yaesu/ft991.c b/yaesu/ft991.c index b4476be1e..6c3aa4bc6 100644 --- a/yaesu/ft991.c +++ b/yaesu/ft991.c @@ -368,10 +368,12 @@ int ft991_set_split_mode(RIG *rig, vfo_t vfo, rmode_t tx_mode, int ft991_init(RIG *rig) { + int ret; + rig_debug(RIG_DEBUG_VERBOSE, "%s called, version %s\n", __func__, rig->caps->version); - int ret = newcat_init(rig); + ret = newcat_init(rig); if (ret != RIG_OK) { return ret; } rig->state.current_vfo = RIG_VFO_A; diff --git a/yaesu/newcat.c b/yaesu/newcat.c index bf7da7a9c..5cb51e42b 100644 --- a/yaesu/newcat.c +++ b/yaesu/newcat.c @@ -287,11 +287,6 @@ int newcat_init(RIG *rig) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - { - return -RIG_EINVAL; - } - priv = (struct newcat_priv_data *) calloc(1, sizeof(struct newcat_priv_data)); if (!priv) /* whoops! memory shortage! */ @@ -329,11 +324,6 @@ int newcat_cleanup(RIG *rig) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - { - return -RIG_EINVAL; - } - if (rig->state.priv) { free(rig->state.priv); @@ -354,18 +344,11 @@ int newcat_cleanup(RIG *rig) int newcat_open(RIG *rig) { + struct newcat_priv_data *priv = rig->state.priv; + struct rig_state *rig_s = &rig->state; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - { - return -RIG_EINVAL; - } - - struct newcat_priv_data *priv = rig->state.priv; - - struct rig_state *rig_s = &rig->state; - rig_debug(RIG_DEBUG_TRACE, "%s: write_delay = %i msec\n", __func__, rig_s->rigport.write_delay); @@ -397,15 +380,10 @@ int newcat_open(RIG *rig) int newcat_close(RIG *rig) { - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - - if (!rig) - { - return -RIG_EINVAL; - } - struct newcat_priv_data *priv = rig->state.priv; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + if (!no_restore_ai && priv->trn_state >= 0) { /* restore AI state */ @@ -426,12 +404,6 @@ int newcat_close(RIG *rig) int newcat_set_conf(RIG *rig, token_t token, const char *val) { - - if (rig == NULL) - { - return -RIG_EARG; - } - int ret = RIG_OK; struct newcat_priv_data *priv; @@ -444,9 +416,9 @@ int newcat_set_conf(RIG *rig, token_t token, const char *val) switch (token) { - case TOK_FAST_SET_CMD: ; char *end; long value; + case TOK_FAST_SET_CMD: ; //using strtol because atoi can lead to undefined behaviour value = strtol(val, &end, 10); @@ -482,12 +454,6 @@ int newcat_set_conf(RIG *rig, token_t token, const char *val) int newcat_get_conf(RIG *rig, token_t token, char *val) { - - if (rig == NULL) - { - return -RIG_EARG; - } - int ret = RIG_OK; struct newcat_priv_data *priv; @@ -530,10 +496,12 @@ int newcat_get_conf(RIG *rig, token_t token, char *val) int newcat_set_freq(RIG *rig, vfo_t vfo, freq_t freq) { + char c; + char target_vfo; + int err; const struct rig_caps *caps; struct newcat_priv_data *priv; - char c; - int err; + int special_60m = 0; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -572,7 +540,6 @@ int newcat_set_freq(RIG *rig, vfo_t vfo, freq_t freq) /* vfo should now be modified to a valid VFO constant. */ /* DX3000/DX5000 can only do VFO_MEM on 60M */ /* So we will not change freq in that case */ - int special_60m = 0; special_60m = newcat_is_rig(rig, RIG_MODEL_FTDX3000); /* duplicate the following line to add more rigs */ special_60m |= newcat_is_rig(rig, RIG_MODEL_FTDX5000); @@ -602,7 +569,7 @@ int newcat_set_freq(RIG *rig, vfo_t vfo, freq_t freq) return -RIG_ENIMPL; /* Only VFO_A or VFO_B are valid */ } - char target_vfo = 'A' == c ? '0' : '1'; + target_vfo = 'A' == c ? '0' : '1'; if (RIG_MODEL_FT450 == caps->rig_model) { @@ -1160,7 +1127,7 @@ int newcat_get_vfo(RIG *rig, vfo_t *vfo) vfo_t vfo_mode; char const *command = "VS"; - if (!rig || !vfo) + if (!vfo) { return -RIG_EINVAL; } @@ -1628,6 +1595,7 @@ int newcat_get_rit(RIG *rig, vfo_t vfo, shortfreq_t *rit) char *retval; char rit_on; int err; + int offset = 0; if (!newcat_valid_command(rig, "IF")) { @@ -1650,7 +1618,6 @@ int newcat_get_rit(RIG *rig, vfo_t vfo, shortfreq_t *rit) // e.g. FT450 has 27 byte IF response, FT991 has 28 byte if response (one more byte for P2 VFO A Freq) // so we now check to ensure we know the length of the response - int offset = 0; switch (strlen(priv->ret_data)) { @@ -1726,6 +1693,7 @@ int newcat_get_xit(RIG *rig, vfo_t vfo, shortfreq_t *xit) char *retval; char xit_on; int err; + int offset = 0; if (!newcat_valid_command(rig, "IF")) { @@ -1748,7 +1716,6 @@ int newcat_get_xit(RIG *rig, vfo_t vfo, shortfreq_t *xit) // e.g. FT450 has 27 byte IF response, FT991 has 28 byte if response (one more byte for P2 VFO A Freq) // so we now check to ensure we know the length of the response - int offset = 0; switch (strlen(priv->ret_data)) { @@ -2557,11 +2524,6 @@ int newcat_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - { - return -RIG_EINVAL; - } - /* Set Main or SUB vfo */ err = newcat_set_vfo_from_alias(rig, &vfo); @@ -3086,11 +3048,6 @@ int newcat_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - { - return -RIG_EINVAL; - } - /* Set Main or SUB vfo */ err = newcat_set_vfo_from_alias(rig, &vfo); @@ -3548,11 +3505,6 @@ int newcat_set_func(RIG *rig, vfo_t vfo, setting_t func, int status) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - { - return -RIG_EINVAL; - } - /* Set Main or SUB vfo */ err = newcat_set_vfo_from_alias(rig, &vfo); @@ -3724,11 +3676,6 @@ int newcat_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - { - return -RIG_EINVAL; - } - switch (func) { case RIG_FUNC_ANF: @@ -4126,11 +4073,6 @@ int newcat_vfo_op(RIG *rig, vfo_t vfo, vfo_op_t op) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - { - return -RIG_EINVAL; - } - /* Set Main or SUB vfo */ err = newcat_set_vfo_from_alias(rig, &vfo); @@ -4665,11 +4607,6 @@ const char *newcat_get_info(RIG *rig) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - { - return NULL; - } - /* Build the command string */ snprintf(priv->cmd_str, sizeof(priv->cmd_str), "ID;"); @@ -4717,12 +4654,6 @@ ncboolean newcat_valid_command(RIG *rig, char const *const command) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rig_debug(RIG_DEBUG_TRACE, "%s %s\n", __func__, command); - if (!rig) - { - rig_debug(RIG_DEBUG_ERR, "%s: Rig argument is invalid\n", __func__); - return FALSE; - } - caps = rig->caps; if (!caps) @@ -6046,6 +5977,7 @@ int newcat_get_vfo_mode(RIG *rig, vfo_t *vfo_mode) { struct newcat_priv_data *priv = (struct newcat_priv_data *)rig->state.priv; int err; + int offset = 0; char command[] = "IF"; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -6066,8 +5998,6 @@ int newcat_get_vfo_mode(RIG *rig, vfo_t *vfo_mode) /* vfo, mem, P7 ************************** */ // e.g. FT450 has 27 byte IF response, FT991 has 28 byte if response (one more byte for P2 VFO A Freq) // so we now check to ensure we know the length of the response - int offset = 0; - switch (strlen(priv->ret_data)) { case 27: offset = 21; priv->width_frequency = 8; break; From 78f3fbdecd25401b15ae0d01ed448919983235df Mon Sep 17 00:00:00 2001 From: Michael Black Date: Mon, 9 Dec 2019 17:33:54 -0600 Subject: [PATCH 077/205] Fix arm compilation warnings --- kenwood/kenwood.c | 4 ++-- kenwood/th.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/kenwood/kenwood.c b/kenwood/kenwood.c index f9ee2a435..7bf9794fb 100644 --- a/kenwood/kenwood.c +++ b/kenwood/kenwood.c @@ -2718,7 +2718,7 @@ int kenwood_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone) int kenwood_set_ctcss_tone_tn(RIG *rig, vfo_t vfo, tone_t tone) { const struct rig_caps *caps = rig->caps; - char buf[6]; + char buf[16]; int i; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -2861,7 +2861,7 @@ int kenwood_get_ctcss_tone(RIG *rig, vfo_t vfo, tone_t *tone) int kenwood_set_ctcss_sql(RIG *rig, vfo_t vfo, tone_t tone) { const struct rig_caps *caps = rig->caps; - char buf[6]; + char buf[16]; int i; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); diff --git a/kenwood/th.c b/kenwood/th.c index 5a328f5fd..6bafeb541 100644 --- a/kenwood/th.c +++ b/kenwood/th.c @@ -2245,7 +2245,7 @@ static int find_tone_index(const tone_t *tone_list, tone_t tone) /* --------------------------------------------------------------------- */ int th_set_channel(RIG *rig, const channel_t *chan) { - char membuf[150]; + char membuf[256]; int retval; char req[64]; char lockoutstr[8]; @@ -2453,7 +2453,7 @@ int th_set_channel(RIG *rig, const channel_t *chan) /* Step can be hexa */ retval = snprintf(membuf, sizeof(membuf), - "%s,%011"PRIll",%X,%d,%d,%d,%d,%d,%02d,%02d,%03d,%09"PRIll",%d%s", + "%8s,%011"PRIll",%X,%d,%d,%d,%d,%d,%02d,%02d,%03d,%09"PRIll",%d%10s", req, (int64_t)chan->freq, step, shift, rev, tone, ctcss, dcs, tonefq, ctcssfq, dcscode, (int64_t)labs((long)(chan->rptr_offs)), mode, lockoutstr From 3a3d66d52d3b0de24feedfb0416bd6f8a31cd8b1 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Mon, 9 Dec 2019 22:45:37 -0600 Subject: [PATCH 078/205] Now compiles with -std=c99 and no c99 warnings --- adat/adat.c | 1 + aor/ar3030.c | 1 + barrett/barrett.c | 2 ++ dummy/dummy.c | 1 + dummy/flrig.c | 2 ++ elad/elad.c | 1 + icom/optoscan.c | 1 + kenwood/kenwood.c | 1 + pcr/pcr.c | 1 + tentec/orion.c | 1 + 10 files changed, 12 insertions(+) diff --git a/adat/adat.c b/adat/adat.c index f6e8d8ea9..b6e50e613 100644 --- a/adat/adat.c +++ b/adat/adat.c @@ -21,6 +21,7 @@ // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +#define _XOPEN_SOURCE 500 #ifdef HAVE_CONFIG_H # include "config.h" diff --git a/aor/ar3030.c b/aor/ar3030.c index bc03c253c..a3d3bd18a 100644 --- a/aor/ar3030.c +++ b/aor/ar3030.c @@ -18,6 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ +#define _XOPEN_SOURCE 500 #ifdef HAVE_CONFIG_H #include "config.h" diff --git a/barrett/barrett.c b/barrett/barrett.c index a0c39c145..69459fa71 100644 --- a/barrett/barrett.c +++ b/barrett/barrett.c @@ -18,6 +18,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ +#define _XOPEN_SOURCE 500 + #ifdef HAVE_CONFIG_H # include "config.h" #endif diff --git a/dummy/dummy.c b/dummy/dummy.c index f42b0b0af..f46fb3c25 100644 --- a/dummy/dummy.c +++ b/dummy/dummy.c @@ -19,6 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ +#define _XOPEN_SOURCE 500 #ifdef HAVE_CONFIG_H #include "config.h" diff --git a/dummy/flrig.c b/dummy/flrig.c index 2b84d460f..d7ee4d5b5 100644 --- a/dummy/flrig.c +++ b/dummy/flrig.c @@ -19,6 +19,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ +#define _XOPEN_SOURCE 500 + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/elad/elad.c b/elad/elad.c index 648e42004..01f56a26a 100644 --- a/elad/elad.c +++ b/elad/elad.c @@ -21,6 +21,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ +#define _XOPEN_SOURCE 500 #ifdef HAVE_CONFIG_H #include "config.h" diff --git a/icom/optoscan.c b/icom/optoscan.c index 0f05d6aec..d733286a6 100644 --- a/icom/optoscan.c +++ b/icom/optoscan.c @@ -18,6 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ +#define _XOPEN_SOURCE 500 #ifdef HAVE_CONFIG_H #include "config.h" diff --git a/kenwood/kenwood.c b/kenwood/kenwood.c index 7bf9794fb..f2fd87935 100644 --- a/kenwood/kenwood.c +++ b/kenwood/kenwood.c @@ -20,6 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ +#define _XOPEN_SOURCE 500 #ifdef HAVE_CONFIG_H #include "config.h" diff --git a/pcr/pcr.c b/pcr/pcr.c index f4422aa8a..299be8b74 100644 --- a/pcr/pcr.c +++ b/pcr/pcr.c @@ -28,6 +28,7 @@ * (403) PCR1500 fw 2.0, proto 2.0 (usb) by KM3T * */ +#define _XOPEN_SOURCE 500 #ifdef HAVE_CONFIG_H #include "config.h" diff --git a/tentec/orion.c b/tentec/orion.c index 241c14d40..c652d13ea 100644 --- a/tentec/orion.c +++ b/tentec/orion.c @@ -65,6 +65,7 @@ * This backend supports the Ten-Tec Orion (565) and Orion II (566) transceivers. * \n This backend tested mostly with firmware versions 1.372 and 2.062a */ +#define _XOPEN_SOURCE 500 #ifdef HAVE_CONFIG_H #include "config.h" From 2fce78ac87db112417d1535f25b3cba3511a22d6 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Mon, 9 Dec 2019 22:59:32 -0600 Subject: [PATCH 079/205] Fix c90 warnings on ic746.c --- icom/ic746.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/icom/ic746.c b/icom/ic746.c index eb69e1363..a035c84b0 100644 --- a/icom/ic746.c +++ b/icom/ic746.c @@ -971,6 +971,9 @@ int ic746pro_get_channel(RIG *rig, channel_t *chan) /* do this only if not a blank channel */ if (chan_len != 1) { + int band; + int sc; + unsigned char databuf[32]; membuf = (mem_buf_t *)(chanbuf + 4); @@ -991,14 +994,12 @@ int ic746pro_get_channel(RIG *rig, channel_t *chan) /* offset is default for the band & is not stored in channel memory. The following retrieves the system default for the band */ - int band = (int) chan->freq / 1000000; /* hf, 2m or 6 m */ + band = (int) chan->freq / 1000000; /* hf, 2m or 6 m */ - int sc; if (band < 50) { sc = S_MEM_HF_DUP_OFST; } else if (band < 108) { sc = S_MEM_6M_DUP_OFST; } else { sc = S_MEM_2M_DUP_OFST; } - unsigned char databuf[32]; retval = icom_transaction(rig, C_CTL_MEM, sc, NULL, 0, databuf, &data_len); From 9eae7615790205e8457b64a0033b28e5d26b4e27 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Mon, 9 Dec 2019 23:37:14 -0600 Subject: [PATCH 080/205] Added 'W' command for reading a fixed number of bytes So we can now do this...write once to see how many bytes you get back Rig command: w \0xfe\0xfe\0x58\0xe0\0x03\0xfd Cmd:\0xFE\0xFE\0x58\0xE0\0x03\0xFD\0xFE\0xFE\0xE0\0x58\0x03\0x00\0x00\0x09\0x14\0x00\0xFD 17 Then use 'W' to write the command with the # of bytes to expect -- no timeout this way Rig command: W \0xfe\0xfe\0x58\0xe0\0x03\0xfd 17 Cmd:\0xFE\0xFE\0x58\0xE0\0x03\0xFD\0xFE\0xFE\0xE0\0x58\0x03\0x00\0x00\0x09\0x14\0x00\0xFD 17 --- tests/rigctl_parse.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/rigctl_parse.c b/tests/rigctl_parse.c index 02d11ba58..66f0f5384 100644 --- a/tests/rigctl_parse.c +++ b/tests/rigctl_parse.c @@ -311,6 +311,7 @@ static struct test_table test_list[] = { 0x8a, "recv_dtmf", ACTION(recv_dtmf), ARG_OUT, "Digits" }, { '*', "reset", ACTION(reset), ARG_IN, "Reset" }, { 'w', "send_cmd", ACTION(send_cmd), ARG_IN1 | ARG_IN_LINE | ARG_OUT2 | ARG_NOVFO, "Cmd", "Reply" }, + { 'W', "send_cmd_rx", ACTION(send_cmd), ARG_IN | ARG_OUT2 | ARG_NOVFO,"Cmd","NBytes"}, { 'b', "send_morse", ACTION(send_morse), ARG_IN | ARG_IN_LINE, "Morse" }, { 0x8b, "get_dcd", ACTION(get_dcd), ARG_OUT, "DCD" }, { '2', "power2mW", ACTION(power2mW), ARG_IN1 | ARG_IN2 | ARG_IN3 | ARG_OUT1 | ARG_NOVFO, "Power [0.0..1.0]", "Frequency", "Mode", "Power mW" }, @@ -4011,7 +4012,7 @@ declare_proto_rig(get_powerstat) * Special debugging purpose send command display reply until there's a * timeout. * - * 'w' + * 'w' and 'W' */ declare_proto_rig(send_cmd) { @@ -4023,6 +4024,7 @@ declare_proto_rig(send_cmd) char buf[BUFSZ]; char eom_buf[4] = { 0xa, 0xd, 0, 0 }; int binary = 0; + int rxbytes = BUFSZ; rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); @@ -4094,8 +4096,10 @@ declare_proto_rig(send_cmd) do { + if (arg2) sscanf(arg2, "%d", &rxbytes); + if (rxbytes > 0) ++rxbytes; // need length + 1 for end of string /* Assumes CR or LF is end of line char for all ASCII protocols. */ - retval = read_string(&rs->rigport, buf, BUFSZ, eom_buf, strlen(eom_buf)); + retval = read_string(&rs->rigport, buf, rxbytes, eom_buf, strlen(eom_buf)); if (retval < 0) { From 1806496538b5ddf41f08f3f8e8e421577ef279be Mon Sep 17 00:00:00 2001 From: Michael Black Date: Mon, 9 Dec 2019 23:45:18 -0600 Subject: [PATCH 081/205] Update rigctl.1 to include W command --- doc/man1/rigctl.1 | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/doc/man1/rigctl.1 b/doc/man1/rigctl.1 index 636b282db..f324f7845 100644 --- a/doc/man1/rigctl.1 +++ b/doc/man1/rigctl.1 @@ -1071,6 +1071,25 @@ option above, will terminate each command string sent to the radio. This character should not be a part of the input string. . .TP +.BR W ", " send_cmd_rx " \(aq" \fICmd\fP \(aq +Send a raw command string to the radio and expect a number of bytes returned. +.IP +This is useful for testing and troubleshooting radio commands and responses when +developing a backend. If the # of bytes requested is <= the number actually returnead no timeout will occur. +.IP +The command argument can have no spaces in it. +For binary protocols enter values as \\0xAA\\0xBB. Expect a +.RI \(aq Reply \(aq +from the radio which will likely be a binary block or an ASCII string +depending on the radio's protocol (see your radio's computer control +documentation). +.IP +The command terminator, set by the +.B send-cmd-term +option above, will terminate each command string sent to the radio. This +character should not be a part of the input string. +. +.TP .BR pause " \(aq" \fISeconds\fP \(aq Pause for the given whole (integer) number of .RI \(aq Seconds \(aq From ae13db1ce516419ecca281c8e70eada81107cf47 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Tue, 10 Dec 2019 10:41:21 -0600 Subject: [PATCH 082/205] Fix c90 warnings on icom.c --- icom/icom.c | 66 +++++++++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/icom/icom.c b/icom/icom.c index a4e06fa20..bffae8171 100644 --- a/icom/icom.c +++ b/icom/icom.c @@ -571,13 +571,12 @@ int icom_rig_open(RIG *rig) unsigned char ackbuf[MAXFRAMELEN]; int ack_len = sizeof(ackbuf); int retval = RIG_OK; - - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - struct rig_state *rs = &rig->state; struct icom_priv_data *priv = (struct icom_priv_data *)rs->priv; struct icom_priv_caps *priv_caps = (struct icom_priv_caps *) rig->caps->priv; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + if (priv_caps->serial_USB_echo_check) { @@ -615,6 +614,7 @@ int icom_set_freq(RIG *rig, vfo_t vfo, freq_t freq) struct rig_state *rs; unsigned char freqbuf[MAXFRAMELEN], ackbuf[MAXFRAMELEN]; int freq_len, ack_len = sizeof(ackbuf), retval; + int cmd, subcmd; rig_debug(RIG_DEBUG_VERBOSE, "%s called %s=%"PRIfreq"\n", __func__, rig_strvfo(vfo), freq); @@ -676,8 +676,8 @@ int icom_set_freq(RIG *rig, vfo_t vfo, freq_t freq) */ to_bcd(freqbuf, freq, freq_len * 2); - int cmd = C_SET_FREQ; - int subcmd = -1; + cmd = C_SET_FREQ; + subcmd = -1; retval = icom_transaction(rig, cmd, subcmd, freqbuf, freq_len, ackbuf, &ack_len); @@ -707,14 +707,14 @@ int icom_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) struct rig_state *rs; unsigned char freqbuf[MAXFRAMELEN]; int freq_len, retval; + int cmd, subcmd; rig_debug(RIG_DEBUG_VERBOSE, "%s called for %s\n", __func__, rig_strvfo(vfo)); rs = &rig->state; priv = (struct icom_priv_data *)rs->priv; - // Newer Icoms can read main/sub frequency - int cmd = C_RD_FREQ; - int subcmd = -1; + cmd = C_RD_FREQ; + subcmd = -1; // Pick the appropriate VFO when VFO_TX is requested if (vfo == RIG_VFO_TX) @@ -1439,6 +1439,8 @@ int icom_set_vfo(RIG *rig, vfo_t vfo) { unsigned char ackbuf[MAXFRAMELEN]; int ack_len = sizeof(ackbuf), icvfo, retval; + struct rig_state *rs = &rig->state; + struct icom_priv_data *priv = (struct icom_priv_data *)rs->priv; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -1447,10 +1449,6 @@ int icom_set_vfo(RIG *rig, vfo_t vfo) return RIG_OK; } - struct rig_state *rs = &rig->state; - - struct icom_priv_data *priv = (struct icom_priv_data *)rs->priv; - if ((vfo == RIG_VFO_A || vfo == RIG_VFO_B) && !VFO_HAS_A_B) { rig_debug(RIG_DEBUG_ERR, "%s: Rig does not have VFO A/B?\n", __func__); @@ -1589,13 +1587,12 @@ int icom_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) int lvl_cn, lvl_sc; /* Command Number, Subcommand */ int icom_val; int i, retval; + const struct icom_priv_caps *priv_caps = + (const struct icom_priv_caps *) rig->caps->priv; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rs = &rig->state; - const struct icom_priv_caps *priv_caps = - (const struct icom_priv_caps *) rig->caps->priv; - /* * So far, levels of float type are in [0.0..1.0] range */ @@ -1933,13 +1930,12 @@ int icom_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) int icom_val; int cmdhead; int retval; + const struct icom_priv_caps *priv_caps = + (const struct icom_priv_caps *) rig->caps->priv; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rs = &rig->state; - const struct icom_priv_caps *priv_caps = - (const struct icom_priv_caps *) rig->caps->priv; - lvl2_len = 0; switch (level) @@ -2736,12 +2732,13 @@ int icom_get_rptr_shift(RIG *rig, vfo_t vfo, rptr_shift_t *rptr_shift) */ int icom_set_rptr_offs(RIG *rig, vfo_t vfo, shortfreq_t rptr_offs) { - const struct icom_priv_caps *priv_caps; - priv_caps = (const struct icom_priv_caps *)rig->caps->priv; - int offs_len = (priv_caps->offs_len) ? priv_caps->offs_len : OFFS_LEN; - + int offs_len; unsigned char offsbuf[MAXFRAMELEN], ackbuf[MAXFRAMELEN]; int ack_len = sizeof(ackbuf), retval; + const struct icom_priv_caps *priv_caps; + + priv_caps = (const struct icom_priv_caps *)rig->caps->priv; + offs_len = (priv_caps->offs_len) ? priv_caps->offs_len : OFFS_LEN; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); /* @@ -2774,12 +2771,13 @@ int icom_set_rptr_offs(RIG *rig, vfo_t vfo, shortfreq_t rptr_offs) */ int icom_get_rptr_offs(RIG *rig, vfo_t vfo, shortfreq_t *rptr_offs) { - const struct icom_priv_caps *priv_caps; - priv_caps = (const struct icom_priv_caps *)rig->caps->priv; - int offs_len = (priv_caps->offs_len) ? priv_caps->offs_len : OFFS_LEN; - + int offs_len; unsigned char offsbuf[MAXFRAMELEN]; int buf_len, retval; + const struct icom_priv_caps *priv_caps; + + priv_caps = (const struct icom_priv_caps *)rig->caps->priv; + offs_len = (priv_caps->offs_len) ? priv_caps->offs_len : OFFS_LEN; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); retval = icom_transaction(rig, C_RD_OFFS, -1, NULL, 0, @@ -4411,6 +4409,8 @@ int icom_set_powerstat(RIG *rig, powerstat_t status) int pwr_sc; unsigned char fe_buf[200]; // for FE's to power up int fe_len = 0; + int i; + int retry; rig_debug(RIG_DEBUG_VERBOSE, "%s called status=%d\n", __func__, (int)status); @@ -4440,15 +4440,15 @@ int icom_set_powerstat(RIG *rig, powerstat_t status) retval = icom_transaction(rig, C_SET_PWR, pwr_sc, NULL, 0, ackbuf, &ack_len); rig_debug(RIG_DEBUG_VERBOSE, "%s #2 called retval=%d\n", __func__, retval); - int i = 0; - int retry = 3 / rig->state.rigport.retry; + i = 0; + retry = 3 / rig->state.rigport.retry; if (status == RIG_POWER_ON) // wait for wakeup only { for (i = 0; i < retry; ++i) // up to 10 attempts { - sleep(1); freq_t freq = 0; + sleep(1); // Use get_freq as all rigs should repond to this retval = rig_get_freq(rig, RIG_VFO_A, &freq); @@ -4885,9 +4885,10 @@ int icom_send_morse(RIG *rig, vfo_t vfo, const char *msg) { unsigned char ackbuf[MAXFRAMELEN]; int ack_len = sizeof(ackbuf), retval; + int len; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - int len = strlen(msg); + len = strlen(msg); if (len > 30) { len = 30; } @@ -5261,6 +5262,7 @@ int icom_get_custom_parm_time(RIG *rig, int parmbuflen, unsigned char *parmbuf, unsigned char resbuf[MAXFRAMELEN]; int reslen = sizeof(resbuf); int retval; + int hour,min; retval = icom_get_raw_buf(rig, C_CTL_MEM, S_MEM_PARM, parmbuflen, parmbuf, &reslen, resbuf); @@ -5270,8 +5272,8 @@ int icom_get_custom_parm_time(RIG *rig, int parmbuflen, unsigned char *parmbuf, return retval; } - int hour = from_bcd_be(resbuf, 2); - int min = from_bcd_be(resbuf + 1, 2); + hour = from_bcd_be(resbuf, 2); + min = from_bcd_be(resbuf + 1, 2); *seconds = (hour * 3600) + (min * 60); return RIG_OK; From 3220c37ff2a714d4bd8166aeab2751f69e7a52fd Mon Sep 17 00:00:00 2001 From: Michael Black Date: Tue, 10 Dec 2019 14:50:24 -0600 Subject: [PATCH 083/205] Change XOPEN to 600 --- adat/adat.c | 2 +- aor/ar3030.c | 2 +- barrett/barrett.c | 2 +- dummy/dummy.c | 2 +- elad/elad.c | 2 +- icom/optoscan.c | 2 +- kenwood/kenwood.c | 2 +- pcr/pcr.c | 2 +- tentec/orion.c | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/adat/adat.c b/adat/adat.c index b6e50e613..35607eb51 100644 --- a/adat/adat.c +++ b/adat/adat.c @@ -21,7 +21,7 @@ // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -#define _XOPEN_SOURCE 500 +#define _XOPEN_SOURCE 600 #ifdef HAVE_CONFIG_H # include "config.h" diff --git a/aor/ar3030.c b/aor/ar3030.c index a3d3bd18a..76c4f3c8d 100644 --- a/aor/ar3030.c +++ b/aor/ar3030.c @@ -18,7 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ -#define _XOPEN_SOURCE 500 +#define _XOPEN_SOURCE 600 #ifdef HAVE_CONFIG_H #include "config.h" diff --git a/barrett/barrett.c b/barrett/barrett.c index 69459fa71..6ec06adf4 100644 --- a/barrett/barrett.c +++ b/barrett/barrett.c @@ -18,7 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ -#define _XOPEN_SOURCE 500 +#define _XOPEN_SOURCE 600 #ifdef HAVE_CONFIG_H # include "config.h" diff --git a/dummy/dummy.c b/dummy/dummy.c index f46fb3c25..ddd48bbba 100644 --- a/dummy/dummy.c +++ b/dummy/dummy.c @@ -19,7 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ -#define _XOPEN_SOURCE 500 +#define _XOPEN_SOURCE 600 #ifdef HAVE_CONFIG_H #include "config.h" diff --git a/elad/elad.c b/elad/elad.c index 01f56a26a..0d4b43a9f 100644 --- a/elad/elad.c +++ b/elad/elad.c @@ -21,7 +21,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ -#define _XOPEN_SOURCE 500 +#define _XOPEN_SOURCE 600 #ifdef HAVE_CONFIG_H #include "config.h" diff --git a/icom/optoscan.c b/icom/optoscan.c index d733286a6..3ce568f8c 100644 --- a/icom/optoscan.c +++ b/icom/optoscan.c @@ -18,7 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ -#define _XOPEN_SOURCE 500 +#define _XOPEN_SOURCE 600 #ifdef HAVE_CONFIG_H #include "config.h" diff --git a/kenwood/kenwood.c b/kenwood/kenwood.c index f2fd87935..bc3d70169 100644 --- a/kenwood/kenwood.c +++ b/kenwood/kenwood.c @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ -#define _XOPEN_SOURCE 500 +#define _XOPEN_SOURCE 600 #ifdef HAVE_CONFIG_H #include "config.h" diff --git a/pcr/pcr.c b/pcr/pcr.c index 299be8b74..8a3d08a53 100644 --- a/pcr/pcr.c +++ b/pcr/pcr.c @@ -28,7 +28,7 @@ * (403) PCR1500 fw 2.0, proto 2.0 (usb) by KM3T * */ -#define _XOPEN_SOURCE 500 +#define _XOPEN_SOURCE 600 #ifdef HAVE_CONFIG_H #include "config.h" diff --git a/tentec/orion.c b/tentec/orion.c index c652d13ea..77430e24d 100644 --- a/tentec/orion.c +++ b/tentec/orion.c @@ -65,7 +65,7 @@ * This backend supports the Ten-Tec Orion (565) and Orion II (566) transceivers. * \n This backend tested mostly with firmware versions 1.372 and 2.062a */ -#define _XOPEN_SOURCE 500 +#define _XOPEN_SOURCE 600 #ifdef HAVE_CONFIG_H #include "config.h" From 444fcfa575b50a0d0cba411d6f3e92e516f5f3b9 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Tue, 10 Dec 2019 15:54:12 -0600 Subject: [PATCH 084/205] Replace XOPEN with AC_USE_SYSTEM_EXTENSIONS --- adat/adat.c | 2 -- aor/ar3030.c | 2 -- barrett/barrett.c | 2 -- configure.ac | 4 +++- dummy/dummy.c | 2 -- dummy/flrig.c | 2 -- elad/elad.c | 2 -- icom/optoscan.c | 2 -- kenwood/kenwood.c | 2 -- pcr/pcr.c | 2 -- tentec/orion.c | 2 -- 11 files changed, 3 insertions(+), 21 deletions(-) diff --git a/adat/adat.c b/adat/adat.c index 35607eb51..bc02794f2 100644 --- a/adat/adat.c +++ b/adat/adat.c @@ -21,8 +21,6 @@ // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -#define _XOPEN_SOURCE 600 - #ifdef HAVE_CONFIG_H # include "config.h" #endif diff --git a/aor/ar3030.c b/aor/ar3030.c index 76c4f3c8d..1570db05f 100644 --- a/aor/ar3030.c +++ b/aor/ar3030.c @@ -18,8 +18,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ -#define _XOPEN_SOURCE 600 - #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/barrett/barrett.c b/barrett/barrett.c index 6ec06adf4..a0c39c145 100644 --- a/barrett/barrett.c +++ b/barrett/barrett.c @@ -18,8 +18,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ -#define _XOPEN_SOURCE 600 - #ifdef HAVE_CONFIG_H # include "config.h" #endif diff --git a/configure.ac b/configure.ac index e252ad6d8..7646bf2d9 100644 --- a/configure.ac +++ b/configure.ac @@ -27,6 +27,8 @@ AC_CONFIG_HEADERS([include/config.h]) dnl Place build system provided programs in this directory. AC_CONFIG_AUX_DIR([build-aux]) +AC_USE_SYSTEM_EXTENSIONS + ## ------------------------ ## ## Automake Initialisation. ## @@ -299,6 +301,7 @@ AS_CASE(["$host_os"], dnl Check if C99 struct initializers are supported AC_MSG_CHECKING([whether C99 struct/array initializers are supported]) + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[struct{char a;int b;}s[8]={[3]={.b=5}};]])], [AC_MSG_RESULT(yes)], @@ -307,7 +310,6 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], "Have you considered GCC lately?."]) ]) - dnl Check for libusb, treat LIBUSB_LIBS and LIBUSB_CFLAGS as precious variables AC_MSG_CHECKING([whether to build USB dependent backends]) AC_ARG_WITH([libusb], diff --git a/dummy/dummy.c b/dummy/dummy.c index ddd48bbba..0b2072e9a 100644 --- a/dummy/dummy.c +++ b/dummy/dummy.c @@ -19,8 +19,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ -#define _XOPEN_SOURCE 600 - #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/dummy/flrig.c b/dummy/flrig.c index d7ee4d5b5..2b84d460f 100644 --- a/dummy/flrig.c +++ b/dummy/flrig.c @@ -19,8 +19,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ -#define _XOPEN_SOURCE 500 - #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/elad/elad.c b/elad/elad.c index 0d4b43a9f..95aaef41e 100644 --- a/elad/elad.c +++ b/elad/elad.c @@ -21,8 +21,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ -#define _XOPEN_SOURCE 600 - #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/icom/optoscan.c b/icom/optoscan.c index 3ce568f8c..af1db8b92 100644 --- a/icom/optoscan.c +++ b/icom/optoscan.c @@ -18,8 +18,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ -#define _XOPEN_SOURCE 600 - #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/kenwood/kenwood.c b/kenwood/kenwood.c index bc3d70169..4629c2ee0 100644 --- a/kenwood/kenwood.c +++ b/kenwood/kenwood.c @@ -20,8 +20,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ -#define _XOPEN_SOURCE 600 - #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/pcr/pcr.c b/pcr/pcr.c index 8a3d08a53..cf9555799 100644 --- a/pcr/pcr.c +++ b/pcr/pcr.c @@ -28,8 +28,6 @@ * (403) PCR1500 fw 2.0, proto 2.0 (usb) by KM3T * */ -#define _XOPEN_SOURCE 600 - #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/tentec/orion.c b/tentec/orion.c index 77430e24d..30060f997 100644 --- a/tentec/orion.c +++ b/tentec/orion.c @@ -65,8 +65,6 @@ * This backend supports the Ten-Tec Orion (565) and Orion II (566) transceivers. * \n This backend tested mostly with firmware versions 1.372 and 2.062a */ -#define _XOPEN_SOURCE 600 - #ifdef HAVE_CONFIG_H #include "config.h" #endif From b3c6b9d70777b26428215c2945afaf1bb78b005b Mon Sep 17 00:00:00 2001 From: Michael Black Date: Thu, 12 Dec 2019 09:13:30 -0600 Subject: [PATCH 085/205] Add rig_strrmodes function and fix flrig to print mode list correctly --- dummy/flrig.c | 10 +++++++--- include/hamlib/rig.h | 1 + src/misc.c | 39 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/dummy/flrig.c b/dummy/flrig.c index 2b84d460f..cae3bdfcc 100644 --- a/dummy/flrig.c +++ b/dummy/flrig.c @@ -841,10 +841,14 @@ static int flrig_open(RIG *rig) } rig->state.mode_list = modes; - rig_debug(RIG_DEBUG_VERBOSE, "%s: hamlib modes=%s\n", __func__, - rig_strrmode(modes)); + + retval = rig_strrmodes(modes, value, sizeof(value)); + if (retval != RIG_OK) { // we might get TRUNC but we can still print the debug + rig_debug(RIG_DEBUG_VERBOSE, "%s: %s\n", __func__, rigerror(retval)); + } + rig_debug(RIG_DEBUG_VERBOSE, "%s: hamlib modes=%s\n", __func__, value); - return RIG_OK; + return retval; } /* diff --git a/include/hamlib/rig.h b/include/hamlib/rig.h index 856b6e2ce..dc8d675fa 100644 --- a/include/hamlib/rig.h +++ b/include/hamlib/rig.h @@ -2410,6 +2410,7 @@ rig_probe HAMLIB_PARAMS((hamlib_port_t *p)); /* Misc calls */ extern HAMLIB_EXPORT(const char *) rig_strrmode(rmode_t mode); +extern HAMLIB_EXPORT(int) rig_strrmodes(rmode_t modes, char *buf, int buflen); extern HAMLIB_EXPORT(const char *) rig_strvfo(vfo_t vfo); extern HAMLIB_EXPORT(const char *) rig_strfunc(setting_t); extern HAMLIB_EXPORT(const char *) rig_strlevel(setting_t); diff --git a/src/misc.c b/src/misc.c index af33c55b0..84aa4fdf5 100644 --- a/src/misc.c +++ b/src/misc.c @@ -383,7 +383,7 @@ const char *HAMLIB_API rig_strrmode(rmode_t mode) { int i; - // only enable it needed for debugging -- too verbose otherwise + // only enable if needed for debugging -- too verbose otherwise //rig_debug(RIG_DEBUG_TRACE, "%s called mode=0x%"PRXll"\n", __func__, mode); if (mode == RIG_MODE_NONE) @@ -402,6 +402,43 @@ const char *HAMLIB_API rig_strrmode(rmode_t mode) return ""; } +/** + * \brief Convert RIG_MODE or'd value to alpha string of all modes + * \param modes RIG_MODE or'd value + * \param buf char* of result buffer + * \param buflen length of buffer + * \return rig status -- RIG_ETRUNC if buffer not big enough + * + * \sa rmode_t + */ +const int HAMLIB_API rig_strrmodes(rmode_t modes, char *buf, int buflen) +{ + int i; + + // only enable if needed for debugging -- too verbose otherwise + //rig_debug(RIG_DEBUG_TRACE, "%s called mode=0x%"PRXll"\n", __func__, mode); + + if (modes == RIG_MODE_NONE) + { + snprintf(buf,buflen,"NONE"); + return RIG_OK; + } + + for (i = 0 ; mode_str[i].str[0] != '\0'; i++) + { + if (modes & mode_str[i].mode) + { + char modebuf[16]; + if (strlen(buf)==0) snprintf(modebuf, sizeof(modebuf), "%s", mode_str[i].str); + else snprintf(modebuf, sizeof(modebuf)," %s", mode_str[i].str); + strncat(buf, modebuf, buflen-strlen(buf)-1); + if (strlen(buf) > buflen-10) return -RIG_ETRUNC; + } + } + + return RIG_OK; +} + static struct { From 5e44f6637e106568fd54debc4953e5de3a0be4b9 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Thu, 12 Dec 2019 09:47:24 -0600 Subject: [PATCH 086/205] Fix mingw compile error on rig_strrmodes --- src/misc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/misc.c b/src/misc.c index 84aa4fdf5..bf8e3fc75 100644 --- a/src/misc.c +++ b/src/misc.c @@ -411,7 +411,7 @@ const char *HAMLIB_API rig_strrmode(rmode_t mode) * * \sa rmode_t */ -const int HAMLIB_API rig_strrmodes(rmode_t modes, char *buf, int buflen) +int HAMLIB_API rig_strrmodes(rmode_t modes, char *buf, int buflen) { int i; From e91df87a8f866beb51ff4752c4c84df7d0524a2e Mon Sep 17 00:00:00 2001 From: Michael Black Date: Thu, 12 Dec 2019 10:14:42 -0600 Subject: [PATCH 087/205] Fix hex_dump..was printing negative values --- src/debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/debug.c b/src/debug.c index aafdc009c..10dec74fc 100644 --- a/src/debug.c +++ b/src/debug.c @@ -84,7 +84,7 @@ void dump_hex(const unsigned char ptr[], size_t size) for (i = 0; i < size; ++i) { - char c; + unsigned char c; if (i % DUMP_HEX_WIDTH == 0) { /* new line */ From f9bed84d8e3b7c868545eb6bd266344236d7c849 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Thu, 12 Dec 2019 22:29:13 -0600 Subject: [PATCH 088/205] Got the w and W commands working much better ICOM test via rigctl Rig command: w \0xfe\0xfe\0x58\0xe0\0x03\0xfd Reply:\0xFE\0xFE\0x58\0xE0\0x03\0xFD\0xFE\0xFE\0xE0\0x58\0x03\0x00\0x50\0x09\0x14\0x00\0xFD 17 Rig command: W \0xfe\0xfe\0x58\0xe0\0x03\0xfd 17 Reply:\0xFE\0xFE\0x58\0xE0\0x03\0xFD\0xFE\0xFE\0xE0\0x58\0x03\0x00\0x50\0x09\0x14\0x00\0xFD 17 Rig command: w FA; send_cmd: error = Invalid parameter Rig command: W FA; 14 send_cmd_rx: error = Invalid parameter ICOM test via rigctld Rig command: w \0xfe\0xfe\0x58\0xe0\0x03\0xfd Reply:\0xFE\0xFE\0x58\0xE0\0x03\0xFD\0xFE\0xFE\0xE0\0x58\0x03\0x00\0x50\0x09\0x14\0x00\0xFD 17 Rig command: W \0xfe\0xfe\0x58\0xe0\0x03\0xfd 17 Reply:\0xFE\0xFE\0x58\0xE0\0x03\0xFD\0xFE\0xFE\0xE0\0x58\0x03\0x00\0x50\0x09\0x14\0x00\0xFD 17 Rig command: w FA; Reply:RPRT -1 Rig command: W FA; 14 Reply:RPRT -1 Kenwood test via rigctl Rig command: w FA; Reply:FA00014074000; Rig command: W FA; 14 Reply:FA00014074000; Rig command: w \0x46\0x41\0x3b Reply:FA00014074000; Rig command: W \0x46\0x41\0x3b 14 Reply:FA00014074000; Kenwood test via rigctld Rig command: w FA; Reply:FA00014074000; Rig command: W FA; 14 Reply:FA00014074000; Rig command: w \0x46\0x41\0x3b Reply:FA00014074000; Rig command: W \0x46\0x41\0x3b 14 Reply:FA00014074000; --- tests/rigctl_parse.c | 177 +++++++++++++++++++++++++++++++++---------- 1 file changed, 138 insertions(+), 39 deletions(-) diff --git a/tests/rigctl_parse.c b/tests/rigctl_parse.c index 66f0f5384..728d084a9 100644 --- a/tests/rigctl_parse.c +++ b/tests/rigctl_parse.c @@ -311,7 +311,7 @@ static struct test_table test_list[] = { 0x8a, "recv_dtmf", ACTION(recv_dtmf), ARG_OUT, "Digits" }, { '*', "reset", ACTION(reset), ARG_IN, "Reset" }, { 'w', "send_cmd", ACTION(send_cmd), ARG_IN1 | ARG_IN_LINE | ARG_OUT2 | ARG_NOVFO, "Cmd", "Reply" }, - { 'W', "send_cmd_rx", ACTION(send_cmd), ARG_IN | ARG_OUT2 | ARG_NOVFO,"Cmd","NBytes"}, + { 'W', "send_cmd_rx", ACTION(send_cmd), ARG_IN | ARG_OUT2 | ARG_NOVFO, "Cmd", "Reply"}, { 'b', "send_morse", ACTION(send_morse), ARG_IN | ARG_IN_LINE, "Morse" }, { 0x8b, "get_dcd", ACTION(get_dcd), ARG_OUT, "DCD" }, { '2', "power2mW", ACTION(power2mW), ARG_IN1 | ARG_IN2 | ARG_IN3 | ARG_OUT1 | ARG_NOVFO, "Power [0.0..1.0]", "Frequency", "Mode", "Power mW" }, @@ -615,6 +615,7 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc, if (!(interactive && prompt && have_rl)) { static int last_was_ret = 1; + if (interactive) { if (prompt) @@ -807,19 +808,19 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc, } } + rig_debug(RIG_DEBUG_TRACE, "%s: debug1\n", __func__); + if ((cmd_entry->flags & ARG_IN_LINE) && (cmd_entry->flags & ARG_IN1) && cmd_entry->arg1) { + rig_debug(RIG_DEBUG_TRACE, "%s: debug2\n", __func__); if (interactive) { char *nl; + rig_debug(RIG_DEBUG_TRACE, "%s: debug2a\n", __func__); - if (prompt) - { - fprintf_flush(fout, "%s: ", cmd_entry->arg1); - } if (fgets(arg1, MAXARGSZ, fin) == NULL) { @@ -828,6 +829,13 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc, if (arg1[0] == 0xa) { + rig_debug(RIG_DEBUG_TRACE, "%s: debug2b\n", __func__); + + if (prompt) + { + fprintf_flush(fout, "%s: ", cmd_entry->arg1); + } + if (fgets(arg1, MAXARGSZ, fin) == NULL) { return -1; @@ -870,18 +878,22 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc, } else if ((cmd_entry->flags & ARG_IN1) && cmd_entry->arg1) { + rig_debug(RIG_DEBUG_TRACE, "%s: debug3\n", __func__); + if (interactive) { - if (prompt) - { - fprintf_flush(fout, "%s: ", cmd_entry->arg1); - } + rig_debug(RIG_DEBUG_TRACE, "%s: debug4\n", __func__); if (scanfc(fin, "%s", arg1) < 1) { return -1; } + if (prompt && *arg1 == 0x0a) + { + fprintf_flush(fout, "%s: ", cmd_entry->arg1); + } + p1 = arg1; } else @@ -903,19 +915,29 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc, } } + rig_debug(RIG_DEBUG_TRACE, "%s: debug5\n", __func__); + if (p1 && p1[0] != '?' && (cmd_entry->flags & ARG_IN2) && cmd_entry->arg2) { + rig_debug(RIG_DEBUG_TRACE, "%s: debug6\n", __func__); if (interactive) { + rig_debug(RIG_DEBUG_TRACE, "%s: debug7\n", __func__); + +#ifdef XXREMOVEDXX + if (prompt) { + rig_debug(RIG_DEBUG_TRACE, "%s: debug8\n", __func__); fprintf_flush(fout, "%s: ", cmd_entry->arg2); } +#endif + if (scanfc(fin, "%s", arg2) < 1) { return -1; @@ -925,6 +947,7 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc, } else { + rig_debug(RIG_DEBUG_TRACE, "%s: debug9\n", __func__); retcode = next_word(arg2, argc, argv, 0); if (EOF == retcode) @@ -942,16 +965,22 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc, } } + rig_debug(RIG_DEBUG_TRACE, "%s: debug10\n", __func__); + if (p1 && p1[0] != '?' && (cmd_entry->flags & ARG_IN3) && cmd_entry->arg3) { + rig_debug(RIG_DEBUG_TRACE, "%s: debug11\n", __func__); if (interactive) { + rig_debug(RIG_DEBUG_TRACE, "%s: debug12\n", __func__); + if (prompt) { + rig_debug(RIG_DEBUG_TRACE, "%s: debug13\n", __func__); fprintf_flush(fout, "%s: ", cmd_entry->arg3); } @@ -964,6 +993,7 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc, } else { + rig_debug(RIG_DEBUG_TRACE, "%s: debug14\n", __func__); retcode = next_word(arg3, argc, argv, 0); if (EOF == retcode) @@ -984,6 +1014,7 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc, } #ifdef HAVE_LIBREADLINE + rig_debug(RIG_DEBUG_TRACE, "%s: debug15\n", __func__); if (interactive && prompt && have_rl) { @@ -2161,7 +2192,7 @@ declare_proto_rig(set_rptr_offs) { unsigned long rptr_offs; - CHKSCN1ARG(sscanf(arg1, "%ld", &rptr_offs)); + CHKSCN1ARG(sscanf(arg1, "%lu", &rptr_offs)); return rig_set_rptr_offs(rig, vfo, rptr_offs); } @@ -2195,7 +2226,7 @@ declare_proto_rig(set_ctcss_tone) { tone_t tone; - CHKSCN1ARG(sscanf(arg1, "%d", &tone)); + CHKSCN1ARG(sscanf(arg1, "%u", &tone)); return rig_set_ctcss_tone(rig, vfo, tone); } @@ -2229,7 +2260,7 @@ declare_proto_rig(set_dcs_code) { tone_t code; - CHKSCN1ARG(sscanf(arg1, "%d", &code)); + CHKSCN1ARG(sscanf(arg1, "%u", &code)); return rig_set_dcs_code(rig, vfo, code); } @@ -2263,7 +2294,7 @@ declare_proto_rig(set_ctcss_sql) { tone_t tone; - CHKSCN1ARG(sscanf(arg1, "%d", &tone)); + CHKSCN1ARG(sscanf(arg1, "%u", &tone)); return rig_set_ctcss_sql(rig, vfo, tone); } @@ -2297,7 +2328,7 @@ declare_proto_rig(set_dcs_sql) { tone_t code; - CHKSCN1ARG(sscanf(arg1, "%d", &code)); + CHKSCN1ARG(sscanf(arg1, "%u", &code)); return rig_set_dcs_sql(rig, vfo, code); } @@ -2544,7 +2575,7 @@ declare_proto_rig(set_ts) { unsigned long ts; - CHKSCN1ARG(sscanf(arg1, "%ld", &ts)); + CHKSCN1ARG(sscanf(arg1, "%lu", &ts)); return rig_set_ts(rig, vfo, ts); } @@ -2613,7 +2644,7 @@ declare_proto_rig(mW2power) rmode_t mode; unsigned int mwp; - CHKSCN1ARG(sscanf(arg1, "%i", &mwp)); + CHKSCN1ARG(sscanf(arg1, "%u", &mwp)); CHKSCN1ARG(sscanf(arg2, "%"SCNfreq, &freq)); mode = rig_parse_mode(arg3); @@ -4007,6 +4038,17 @@ declare_proto_rig(get_powerstat) return status; } +static int hasbinary(char *s) +{ + int i; + + for (i = 0; s[i] != 0; ++i) + { + if (!isascii(s[i])) { return 1; } + } + + return 0; +} /* * Special debugging purpose send command display reply until there's a @@ -4021,7 +4063,7 @@ declare_proto_rig(send_cmd) int backend_num, cmd_len; #define BUFSZ 128 char bufcmd[BUFSZ]; - char buf[BUFSZ]; + unsigned char buf[BUFSZ]; char eom_buf[4] = { 0xa, 0xd, 0, 0 }; int binary = 0; int rxbytes = BUFSZ; @@ -4033,15 +4075,37 @@ declare_proto_rig(send_cmd) */ backend_num = RIG_BACKEND_NUM(rig->caps->rig_model); + rig_debug(RIG_DEBUG_TRACE, "%s: backend_num=%d\n", __func__, backend_num); + + // need to move the eom_buf to rig-specifc backends + // we'll let KENWOOD backends use the ; char in the rigctl commands + if (backend_num == RIG_KENWOOD) + { + rig_debug(RIG_DEBUG_TRACE, "%s: KENWOOD\n", __func__); + eom_buf[0] = 0; + send_cmd_term = 0; + } + + rig_debug(RIG_DEBUG_TRACE, "%s: arg1=%s\n", __func__, arg1); + if (send_cmd_term == -1 || backend_num == RIG_YAESU || backend_num == RIG_ICOM || backend_num == RIG_KACHINA - || backend_num == RIG_MICROTUNE) + || backend_num == RIG_MICROTUNE + || (strstr(arg1, "\\0x") && (rig->caps->rig_model != RIG_MODEL_NETRIGCTL)) + ) { const char *p = arg1, *pp = NULL; int i; + rig_debug(RIG_DEBUG_TRACE, "%s: send_cmd_term==-1, arg1=%s\n", __func__, arg1); + + if (strstr(arg1, "\\0x") == NULL) + { + rig_debug(RIG_DEBUG_ERR, "%s: expecting binary hex string here\n", __func__); + return -RIG_EINVAL; + } for (i = 0; i < BUFSZ - 1 && p != pp; i++) { @@ -4057,16 +4121,32 @@ declare_proto_rig(send_cmd) } else if (rig->caps->rig_model == RIG_MODEL_NETRIGCTL) { - rig_debug(RIG_DEBUG_VERBOSE, "%s: we're using netrigctl\n", __func__); - snprintf(bufcmd, sizeof(bufcmd), "w %s\n", arg1); + rig_debug(RIG_DEBUG_TRACE, "%s: we're netrigctl#2\n", __func__); + + //snprintf(bufcmd, sizeof(bufcmd), "%s %s\n", cmd->cmd, arg1); + if (cmd->cmd == 'w') + { + snprintf(bufcmd, sizeof(bufcmd), "%c %s\n", cmd->cmd, arg1); + } + else + { + int nbytes = 0; + sscanf(arg2, "%d", &nbytes); + snprintf(bufcmd, sizeof(bufcmd), "%c %s %d\n", cmd->cmd, arg1, nbytes); + } + cmd_len = strlen(bufcmd); + rig_debug(RIG_DEBUG_VERBOSE, "%s: cmd=%s, len=%d\n", __func__, bufcmd, cmd_len); } else { + char tmpbuf[64]; /* text protocol */ strncpy(bufcmd, arg1, BUFSZ); + strtok(bufcmd, "\0xa\0xd"); bufcmd[BUFSZ - 2] = '\0'; cmd_len = strlen(bufcmd); + rig_debug(RIG_DEBUG_TRACE, "%s: bufcmd=%s\n", __func__, bufcmd); /* Automatic termination char */ if (send_cmd_term != 0) @@ -4075,13 +4155,21 @@ declare_proto_rig(send_cmd) } eom_buf[2] = send_cmd_term; + + snprintf(tmpbuf, sizeof(tmpbuf), "0x%02x 0x%02x 0x%02x", eom_buf[0], eom_buf[1], + eom_buf[2]); + + rig_debug(RIG_DEBUG_TRACE, "%s: text protocol, send_cmd_term=%s\n", __func__, + tmpbuf); } rs = &rig->state; serial_flush(&rs->rigport); - retval = write_block(&rs->rigport, bufcmd, cmd_len); + rig_debug(RIG_DEBUG_TRACE, "%s: rigport=%d, bufcmd=%s, cmd_len=%d\n", __func__, + rs->rigport.fd, hasbinary(bufcmd) ? "BINARY" : bufcmd, cmd_len); + retval = write_block(&rs->rigport, (char *)bufcmd, cmd_len); if (retval != RIG_OK) { @@ -4090,19 +4178,33 @@ declare_proto_rig(send_cmd) if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { - fwrite(cmd->arg1, 1, strlen(cmd->arg1), fout); /* i.e. "Frequency" */ + rig_debug(RIG_DEBUG_TRACE, "%s: debug Cmd\n", __func__); + fwrite(cmd->arg2, 1, strlen(cmd->arg2), fout); /* i.e. "Frequency" */ fwrite(":", 1, 1, fout); /* i.e. "Frequency" */ } do { - if (arg2) sscanf(arg2, "%d", &rxbytes); - if (rxbytes > 0) ++rxbytes; // need length + 1 for end of string + if (arg2) { sscanf(arg2, "%d", &rxbytes); } + + if (rxbytes > 0) + { + ++rxbytes; // need length + 1 for end of string + + if (cmd->cmd == 'W') { rxbytes *= 5; } + + eom_buf[0] = 0; + } + /* Assumes CR or LF is end of line char for all ASCII protocols. */ - retval = read_string(&rs->rigport, buf, rxbytes, eom_buf, strlen(eom_buf)); + retval = read_string(&rs->rigport, (char *)buf, rxbytes, eom_buf, + strlen(eom_buf)); if (retval < 0) { + rig_debug(RIG_DEBUG_ERR, "%s: read_string error %s\n", __func__, + rigerror(retval)); + break; } @@ -4118,31 +4220,28 @@ declare_proto_rig(send_cmd) if (rig->caps->rig_model != RIG_MODEL_NETRIGCTL) { // see if we have binary being returned - int i; - - for (i = 0; i < retval; ++i) - { - if (!isprint(buf[i])) - { - binary = 1; - break; - } - } + binary = hasbinary((char *)buf); } if (binary) // convert our buf to a hex representaion { int i; - char hex[64]; + char hex[8]; + char *hexbuf = calloc(retval, 5); rig_debug(RIG_DEBUG_VERBOSE, "%s: sending binary\n", __func__); + hexbuf[0] = 0; for (i = 0; i < retval; ++i) { snprintf(hex, sizeof(hex), "\\0x%02X", (unsigned char)buf[i]); - fprintf(fout, "%s", hex); + strncat(hexbuf, hex, strlen(hex)); + //fprintf(fout, "%s", hex); } - fprintf(fout, " %d\n", retval); + rig_debug(RIG_DEBUG_TRACE, "%s: binary=%s, retval=%d\n", __func__, hexbuf, + retval); + fprintf(fout, "%s %d\n", hexbuf, retval); + free(hexbuf); return RIG_OK; } else @@ -4151,7 +4250,7 @@ declare_proto_rig(send_cmd) fprintf(fout, "%s\n", buf); } } - while (retval > 0); + while (retval > 0 && rxbytes == BUFSZ); // we use fwrite in case of any nulls in binary return if (binary) { fwrite(buf, 1, retval, fout); } From f53763602ee6b9f9f4df4f8f4b9fb3f98042b521 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Thu, 12 Dec 2019 23:25:43 -0600 Subject: [PATCH 089/205] Fix TS590 get_level --- kenwood/kenwood.h | 16 ++++++++++++++++ kenwood/ts590.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/kenwood/kenwood.h b/kenwood/kenwood.h index d002b97ed..960e83f9b 100644 --- a/kenwood/kenwood.h +++ b/kenwood/kenwood.h @@ -62,6 +62,22 @@ extern const struct confparams kenwood_cfg_params[]; #define MD_CWR '7' #define MD_FSKR '9' +/* S-meter calibration tables */ +/* This one for the TS590 no doubt applies elsewhere */ +#define TS590_SM_CAL { 10, \ + { \ + { 0, -54 }, \ + { 3, -48 }, \ + { 6, -36 }, \ + { 9, -24 }, \ + { 12, -12 }, \ + { 15, 0 }, \ + { 20, 20 }, \ + { 25, 40 }, \ + { 30, 60 }, \ + } } + + struct kenwood_priv_caps { char cmdtrm; /* Command termination chars (ken=';' or th='\r') */ diff --git a/kenwood/ts590.c b/kenwood/ts590.c index 16b9a0782..3929ae8cf 100644 --- a/kenwood/ts590.c +++ b/kenwood/ts590.c @@ -29,6 +29,7 @@ #include "hamlib/rig.h" #include "idx_builtin.h" #include "kenwood.h" +#include "cal.h" /* Function declarations */ @@ -90,7 +91,7 @@ const struct rig_caps ts590_caps = .rig_model = RIG_MODEL_TS590S, .model_name = "TS-590S", .mfg_name = "Kenwood", - .version = BACKEND_VER ".2", + .version = BACKEND_VER ".3", .copyright = "LGPL", .status = RIG_STATUS_STABLE, .rig_type = RIG_TYPE_TRANSCEIVER, @@ -471,6 +472,14 @@ int ts590_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) switch (level) { + case RIG_LEVEL_KEYSPD: + case RIG_LEVEL_AGC: + case RIG_LEVEL_SQL: + case RIG_LEVEL_CWPITCH: + case RIG_LEVEL_RFPOWER: + case RIG_LEVEL_RF: + return kenwood_get_level(rig, vfo, level, val); + case RIG_LEVEL_AF: return get_kenwood_level(rig, "AG0", &val->f); @@ -558,6 +567,38 @@ int ts590_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) sscanf(lvlbuf + 3, "%d", &val->i); return retval; - default: return rig_get_level(rig, vfo, level, val); + case RIG_LEVEL_RAWSTR: + case RIG_LEVEL_STRENGTH: + retval = kenwood_transaction(rig, "SM0", lvlbuf, sizeof(lvlbuf)); + + if (retval != RIG_OK) + { + return retval; + } + + lvl_len = strlen(lvlbuf); + + if (((lvl_len != 7)) || lvlbuf[1] != 'M') + { + /* TS-590 returns 8 bytes for S meter level */ + rig_debug(RIG_DEBUG_ERR, "%s: wrong answer len=%d\n", __func__, (int)lvl_len); + return -RIG_ERJCTED; + } + + /* Frontend expects: -54 = S0, 0 = S9 */ + sscanf(lvlbuf + 3, "%d", &val->i); + + /* TS-590 main receiver returns values from 0 - 30 */ + /* Indicates # of dots on meter */ + /* so first 15 are S0-S9 and last 15 are 20/40/60 */ + if (level == RIG_LEVEL_STRENGTH) + { + cal_table_t str_cal = TS590_SM_CAL; + val->i = (int) rig_raw2val(val->i, &str_cal); + } + + return retval; + + default: return -RIG_EINVAL; } } From 7b0d4e754fc1bd19ebc8691003d1946744cb4f7d Mon Sep 17 00:00:00 2001 From: Michael Black Date: Fri, 13 Dec 2019 08:25:06 -0600 Subject: [PATCH 090/205] Add bootstrap note to INSTALL --- INSTALL | 2 ++ 1 file changed, 2 insertions(+) diff --git a/INSTALL b/INSTALL index e1aef7302..f8203c10d 100644 --- a/INSTALL +++ b/INSTALL @@ -17,6 +17,8 @@ main directory and do the following: $ ./configure + Note: if ./configure does not exist you must run ./bootstrap first + If you are planning to install the package into your home directory or to a location other than `/usr/local' then add the flag `--prefix=PATH' to `configure'. For example, if your home directory From 72476c21bec7bb0c934c0d46d3218a698382c6d0 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Fri, 13 Dec 2019 23:28:49 -0600 Subject: [PATCH 091/205] Added set_powerstat 1 to kenwood_init -- any reason not to do this? Do we ever want to start rigctl or rigctld on a non-powered rig? Maybe should do this on all rigs? TS590S rigctl could not start with power off as firmware version is needed. And many other things require the rig to be up when rigctl is started. We won't let set_powerstat fail the startup just in case. --- kenwood/kenwood.c | 3 +++ kenwood/kenwood.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/kenwood/kenwood.c b/kenwood/kenwood.c index 4629c2ee0..711999e05 100644 --- a/kenwood/kenwood.c +++ b/kenwood/kenwood.c @@ -611,6 +611,9 @@ int kenwood_init(RIG *rig) rig_debug(RIG_DEBUG_TRACE, "%s: if_len = %d\n", __func__, caps->if_len); + // Ensure power is on -- any reason not to do this? + rig_set_powerstat(rig,1); + return RIG_OK; } diff --git a/kenwood/kenwood.h b/kenwood/kenwood.h index 960e83f9b..08d3bff16 100644 --- a/kenwood/kenwood.h +++ b/kenwood/kenwood.h @@ -27,7 +27,7 @@ #include #include "token.h" -#define BACKEND_VER "1.4" +#define BACKEND_VER "1.5" #define EOM_KEN ';' #define EOM_TH '\r' From dede1e5ac1e374365c6a5894011dc2348f6d5379 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Fri, 13 Dec 2019 23:36:17 -0600 Subject: [PATCH 092/205] Remove bootstrap reference in INSTALL --- INSTALL | 2 -- 1 file changed, 2 deletions(-) diff --git a/INSTALL b/INSTALL index f8203c10d..e1aef7302 100644 --- a/INSTALL +++ b/INSTALL @@ -17,8 +17,6 @@ main directory and do the following: $ ./configure - Note: if ./configure does not exist you must run ./bootstrap first - If you are planning to install the package into your home directory or to a location other than `/usr/local' then add the flag `--prefix=PATH' to `configure'. For example, if your home directory From 2e74b4fa6ba0aa2d8a9d97f5575cc4a266477e02 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sat, 14 Dec 2019 08:25:34 -0600 Subject: [PATCH 093/205] Move set_powerstat to kenwood_open and add kenwood_open to ts950.c --- kenwood/kenwood.c | 7 ++++--- kenwood/ts950.c | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/kenwood/kenwood.c b/kenwood/kenwood.c index 711999e05..c1f6e8812 100644 --- a/kenwood/kenwood.c +++ b/kenwood/kenwood.c @@ -611,9 +611,6 @@ int kenwood_init(RIG *rig) rig_debug(RIG_DEBUG_TRACE, "%s: if_len = %d\n", __func__, caps->if_len); - // Ensure power is on -- any reason not to do this? - rig_set_powerstat(rig,1); - return RIG_OK; } @@ -636,6 +633,10 @@ int kenwood_open(RIG *rig) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + // Ensure rig is on + rig_set_powerstat(rig,1); + + if (RIG_MODEL_TS590S == rig->caps->rig_model) { /* we need the firmware version for these rigs to deal with f/w defects */ diff --git a/kenwood/ts950.c b/kenwood/ts950.c index 9ffebf765..b109ee66b 100644 --- a/kenwood/ts950.c +++ b/kenwood/ts950.c @@ -162,6 +162,7 @@ const struct rig_caps ts950sdx_caps = .priv = (void *)& ts950_priv_caps, .rig_init = kenwood_init, + .rig_open = kenwood_open, .rig_cleanup = kenwood_cleanup, .set_freq = kenwood_set_freq, .get_freq = kenwood_get_freq, From 8ff9a682ccfd8b996a31ce485ed09c0be7b2bd4a Mon Sep 17 00:00:00 2001 From: Michael Black Date: Mon, 16 Dec 2019 10:51:36 -0600 Subject: [PATCH 094/205] Add set_powerstat to icom.c and debug msg to rig.c --- icom/icom.c | 3 +++ src/rig.c | 1 + 2 files changed, 4 insertions(+) diff --git a/icom/icom.c b/icom/icom.c index bffae8171..c82da7a9b 100644 --- a/icom/icom.c +++ b/icom/icom.c @@ -533,6 +533,7 @@ int icom_init(RIG *rig) priv->tx_vfo = RIG_VFO_NONE; priv->rx_vfo = RIG_VFO_NONE; priv->curr_vfo = RIG_VFO_NONE; + rig_debug(RIG_DEBUG_TRACE, "%s: done\n", __func__); return RIG_OK; @@ -577,6 +578,8 @@ int icom_rig_open(RIG *rig) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + rig_set_powerstat(rig,1); + if (priv_caps->serial_USB_echo_check) { diff --git a/src/rig.c b/src/rig.c index 3f6d07093..195c9fd8c 100644 --- a/src/rig.c +++ b/src/rig.c @@ -3828,6 +3828,7 @@ int HAMLIB_API rig_set_powerstat(RIG *rig, powerstat_t status) if (rig->caps->set_powerstat == NULL) { + rig_debug(RIG_DEBUG_WARN, "%s set_powerstat not implemented\n", __func__); return -RIG_ENAVAIL; } From ff969113fa258c652a1e991586715128ee60af40 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Mon, 16 Dec 2019 11:26:23 -0600 Subject: [PATCH 095/205] Fix RIG_VFO_B in ic821h --- icom/ic821h.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/icom/ic821h.c b/icom/ic821h.c index bbcf7ff69..be7c8e15c 100644 --- a/icom/ic821h.c +++ b/icom/ic821h.c @@ -32,7 +32,7 @@ #define IC821H_MODES (RIG_MODE_SSB|RIG_MODE_CW|RIG_MODE_FM) -#define IC821H_VFO_ALL (RIG_VFO_A|RIG_VFO_C|RIG_VFO_MEM|RIG_VFO_MAIN|RIG_VFO_SUB) +#define IC821H_VFO_ALL (RIG_VFO_A|RIG_VFO_B|RIG_VFO_MEM|RIG_VFO_MAIN|RIG_VFO_SUB) /* FIXME: What about MAIN/SUB mode? And satellite mode? */ #define IC821H_VFO_OPS (RIG_OP_FROM_VFO|RIG_OP_TO_VFO|RIG_OP_CPY|RIG_OP_MCL) @@ -59,9 +59,9 @@ const struct rig_caps ic821h_caps = .rig_model = RIG_MODEL_IC821H, .model_name = "IC-821H", .mfg_name = "Icom", - .version = BACKEND_VER ".1", + .version = BACKEND_VER ".2", .copyright = "LGPL", - .status = RIG_STATUS_ALPHA, + .status = RIG_STATUS_BETA, .rig_type = RIG_TYPE_TRANSCEIVER, .ptt_type = RIG_PTT_NONE, .dcd_type = RIG_DCD_NONE, From 935baaad2454baa46e36ffa72c7f88930fc4b281 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Mon, 16 Dec 2019 11:55:09 -0600 Subject: [PATCH 096/205] Fix powerstat 1 for 115,200 on ic7300 (and perhaps others) --- icom/icom.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/icom/icom.c b/icom/icom.c index c82da7a9b..a339166c9 100644 --- a/icom/icom.c +++ b/icom/icom.c @@ -4410,7 +4410,10 @@ int icom_set_powerstat(RIG *rig, powerstat_t status) unsigned char ackbuf[200]; int ack_len = sizeof(ackbuf), retval; int pwr_sc; - unsigned char fe_buf[200]; // for FE's to power up + // 175 0xfe's are workign for 38,400 but not 57,600 + // so we'll do up to 175*3 for 115,200 + int fe_max = 175*3; + unsigned char fe_buf[fe_max]; // for FE's to power up int fe_len = 0; int i; int retry; @@ -4424,7 +4427,7 @@ int icom_set_powerstat(RIG *rig, powerstat_t status) // ic7300 manual says ~150 for 115,200 // we'll just send 175 to be sure for all speeds - for (fe_len = 0; fe_len < 175; ++fe_len) + for (fe_len = 0; fe_len < fe_max; ++fe_len) { fe_buf[fe_len] = 0xfe; } @@ -4438,13 +4441,13 @@ int icom_set_powerstat(RIG *rig, powerstat_t status) // we can ignore this retval // sending more than enough 0xfe's to wake up the rs232 - icom_transaction(rig, 0xfe, 0xfe, fe_buf, fe_len, ackbuf, &ack_len); + icom_transaction(rig, 0xfe, 0xfe, fe_buf, fe_max, ackbuf, &ack_len); retval = icom_transaction(rig, C_SET_PWR, pwr_sc, NULL, 0, ackbuf, &ack_len); rig_debug(RIG_DEBUG_VERBOSE, "%s #2 called retval=%d\n", __func__, retval); i = 0; - retry = 3 / rig->state.rigport.retry; + retry = 10; if (status == RIG_POWER_ON) // wait for wakeup only { From 014da04095ffa8c4242b4af3a0b469f8bc79cf32 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Tue, 17 Dec 2019 07:51:45 -0600 Subject: [PATCH 097/205] Fix cppcheck static warning in barrett.c --- barrett/barrett.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/barrett/barrett.c b/barrett/barrett.c index a0c39c145..b45ca7b3e 100644 --- a/barrett/barrett.c +++ b/barrett/barrett.c @@ -335,23 +335,22 @@ int barrett_transaction(RIG *rig, char *cmd, int expected, char **result) int barrett_init(RIG *rig) { - struct barrett_priv_data *priv = (struct barrett_priv_data *)calloc(1, sizeof(struct barrett_priv_data)); rig_debug(RIG_DEBUG_VERBOSE, "%s version %s\n", __func__, rig->caps->version); + rig->state.priv = (struct barrett_priv_data *)calloc(1, + sizeof(struct barrett_priv_data)); - if (!rig || !rig->caps) + if (!rig->caps) { return -RIG_EINVAL; } - if (!priv) + if (!rig->state.priv) { return -RIG_ENOMEM; } - rig->state.priv = (void *)priv; - return RIG_OK; } @@ -616,9 +615,9 @@ int barrett_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) */ int barrett_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) { - char *result=NULL; + char *result = NULL; int retval; - + rig_debug(RIG_DEBUG_VERBOSE, "%s: vfo=%s\n", __func__, rig_strvfo(vfo)); retval = barrett_transaction(rig, "IB", 0, &result); @@ -749,8 +748,9 @@ int barrett_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) switch (level) { - int strength; - int n; + int strength; + int n; + case RIG_LEVEL_STRENGTH: retval = barrett_transaction(rig, "IAL", 0, &response); From eac8077c6099f9f9d99ec41a54f381318697d291 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Tue, 17 Dec 2019 08:08:39 -0600 Subject: [PATCH 098/205] Fix possible buf overrun in rigctl_parse.c --- tests/rigctl_parse.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/rigctl_parse.c b/tests/rigctl_parse.c index 728d084a9..df993a678 100644 --- a/tests/rigctl_parse.c +++ b/tests/rigctl_parse.c @@ -4227,13 +4227,24 @@ declare_proto_rig(send_cmd) { int i; char hex[8]; - char *hexbuf = calloc(retval, 5); - rig_debug(RIG_DEBUG_VERBOSE, "%s: sending binary\n", __func__); + int hexbufbytes = retval * 6; + char *hexbuf = calloc(hexbufbytes, 1); + rig_debug(RIG_DEBUG_VERBOSE, "%s: sending binary, hexbuf size=%d\n", __func__, + hexbufbytes); hexbuf[0] = 0; for (i = 0; i < retval; ++i) { snprintf(hex, sizeof(hex), "\\0x%02X", (unsigned char)buf[i]); + + if ((strlen(hexbuf) + strlen(hex) + 1) >= hexbufbytes) + { + hexbufbytes *= 2; + rig_debug(RIG_DEBUG_TRACE, "%s: doubling hexbuf size to %d\n", __func__, + hexbufbytes); + hexbuf = realloc(hexbuf, hexbufbytes); + } + strncat(hexbuf, hex, strlen(hex)); //fprintf(fout, "%s", hex); } From 20fa6d50ca7d62bb087dd316cf89497ecb2933f8 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Tue, 17 Dec 2019 08:09:07 -0600 Subject: [PATCH 099/205] Fix set_powerstat in icom.c --- icom/icom.c | 79 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 51 insertions(+), 28 deletions(-) diff --git a/icom/icom.c b/icom/icom.c index a339166c9..6572b4ff3 100644 --- a/icom/icom.c +++ b/icom/icom.c @@ -578,7 +578,7 @@ int icom_rig_open(RIG *rig) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - rig_set_powerstat(rig,1); + rig_set_powerstat(rig, 1); if (priv_caps->serial_USB_echo_check) { @@ -736,6 +736,7 @@ int icom_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) } retval = set_vfo_curr(rig, vfo, priv->curr_vfo); + if (retval != RIG_OK) { return retval; } // Pick the appropriate VFO when VFO_RX is requested @@ -1021,6 +1022,7 @@ int icom_set_dsp_flt(RIG *rig, rmode_t mode, pbwidth_t width) if (!rig_get_func(rig, RIG_VFO_CURR, RIG_FUNC_RF, &rfstatus) && (rfstatus)) { int i; + for (i = 0; i < RTTY_FIL_NB; i++) { if (rtty_fil[i] == width) @@ -3184,9 +3186,13 @@ int icom_set_split_freq_mode(RIG *rig, vfo_t vfo, freq_t tx_freq, } } - rig_debug(RIG_DEBUG_VERBOSE,"%s: before get_split_vfos rx_vfo=%s tx_vfo=%s\n", __func__, rig_strvfo(priv->rx_vfo), rig_strvfo(priv->tx_vfo)); + rig_debug(RIG_DEBUG_VERBOSE, "%s: before get_split_vfos rx_vfo=%s tx_vfo=%s\n", + __func__, rig_strvfo(priv->rx_vfo), rig_strvfo(priv->tx_vfo)); + if (RIG_OK != (rc = icom_get_split_vfos(rig, &rx_vfo, &tx_vfo))) { return rc; } - rig_debug(RIG_DEBUG_VERBOSE,"%s: after get_split_vfos rx_vfo=%s tx_vfo=%s\n", __func__, rig_strvfo(priv->rx_vfo), rig_strvfo(priv->tx_vfo)); + + rig_debug(RIG_DEBUG_VERBOSE, "%s: after get_split_vfos rx_vfo=%s tx_vfo=%s\n", + __func__, rig_strvfo(priv->rx_vfo), rig_strvfo(priv->tx_vfo)); if (RIG_OK != (rc = icom_set_vfo(rig, tx_vfo))) { return rc; } @@ -3340,7 +3346,9 @@ int icom_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, vfo_t tx_vfo) priv->rx_vfo = vfo; priv->tx_vfo = tx_vfo; priv->split_on = RIG_SPLIT_ON == split; - rig_debug(RIG_DEBUG_VERBOSE, "%s: vfo=%s rx_vfo=%s tx_vfo=%s split=%d\n", __func__, rig_strvfo(vfo), rig_strvfo(priv->rx_vfo), rig_strvfo(priv->tx_vfo), split); + rig_debug(RIG_DEBUG_VERBOSE, "%s: vfo=%s rx_vfo=%s tx_vfo=%s split=%d\n", + __func__, rig_strvfo(vfo), rig_strvfo(priv->rx_vfo), rig_strvfo(priv->tx_vfo), + split); return RIG_OK; } @@ -3392,9 +3400,12 @@ int icom_get_split_vfo(RIG *rig, vfo_t vfo, split_t *split, vfo_t *tx_vfo) rig_debug(RIG_DEBUG_ERR, "%s: unsupported split %d", __func__, splitbuf[1]); return -RIG_EPROTO; } + *tx_vfo = priv->tx_vfo; priv->split_on = RIG_SPLIT_ON == *split; - rig_debug(RIG_DEBUG_VERBOSE, "%s: vfo=%s rx_vfo=%s tx_vfo=%s split=%d\n", __func__, rig_strvfo(vfo), rig_strvfo(priv->rx_vfo), rig_strvfo(priv->tx_vfo), *split); + rig_debug(RIG_DEBUG_VERBOSE, "%s: vfo=%s rx_vfo=%s tx_vfo=%s split=%d\n", + __func__, rig_strvfo(vfo), rig_strvfo(priv->rx_vfo), rig_strvfo(priv->tx_vfo), + *split); return RIG_OK; } @@ -3675,11 +3686,16 @@ int icom_set_func(RIG *rig, vfo_t vfo, setting_t func, int status) case RIG_FUNC_DSQL: fct_cn = C_CTL_FUNC; fct_sc = S_FUNC_DSSQL; - if (status <= 2) { + + if (status <= 2) + { fctbuf[0] = status; - } else { + } + else + { fctbuf[0] = 0; } + break; case RIG_FUNC_AFLT: @@ -4023,6 +4039,7 @@ int icom_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone) if (caps->ctcss_list) { int i; + for (i = 0; caps->ctcss_list[i] != 0; i++) { if (caps->ctcss_list[i] == tone) @@ -4408,52 +4425,56 @@ int icom_get_dcs_sql(RIG *rig, vfo_t vfo, tone_t *code) int icom_set_powerstat(RIG *rig, powerstat_t status) { unsigned char ackbuf[200]; - int ack_len = sizeof(ackbuf), retval; + int ack_len = sizeof(ackbuf), retval = RIG_OK; int pwr_sc; - // 175 0xfe's are workign for 38,400 but not 57,600 - // so we'll do up to 175*3 for 115,200 - int fe_max = 175*3; + // so we'll do up to 175 for 115,200 + int fe_max = 175; unsigned char fe_buf[fe_max]; // for FE's to power up - int fe_len = 0; int i; int retry; + struct rig_state *rs = &rig->state; rig_debug(RIG_DEBUG_VERBOSE, "%s called status=%d\n", __func__, (int)status); switch (status) { case RIG_POWER_ON: - pwr_sc = S_PWR_ON; + sleep(1); // let serial bus idle for a while + rig_debug(RIG_DEBUG_TRACE, "%s: PWR_ON failed, trying 0xfe's\n", __func__); // ic7300 manual says ~150 for 115,200 - // we'll just send 175 to be sure for all speeds - for (fe_len = 0; fe_len < fe_max; ++fe_len) - { - fe_buf[fe_len] = 0xfe; - } + // we'll just send a few more to be sure for all speeds + memset(fe_buf, 0xfe, fe_max); + // sending more than enough 0xfe's to wake up the rs232 + retval = write_block(&rs->rigport, (char *) fe_buf, fe_max); + + usleep(100 * 1000); + // we'll try 0x18 0x01 now -- should work on STBY rigs too + pwr_sc = S_PWR_ON; + fe_buf[0] = 0; + retry = rs->rigport.retry; + rs->rigport.retry = 0; + retval = icom_transaction(rig, C_SET_PWR, pwr_sc, NULL, 0, ackbuf, &ack_len); + rs->rigport.retry = retry; break; default: pwr_sc = S_PWR_OFF; fe_buf[0] = 0; + retry = rs->rigport.retry; + rs->rigport.retry = 0; + retval = icom_transaction(rig, C_SET_PWR, pwr_sc, NULL, 0, ackbuf, &ack_len); + rs->rigport.retry = retry; } - // we can ignore this retval - // sending more than enough 0xfe's to wake up the rs232 - icom_transaction(rig, 0xfe, 0xfe, fe_buf, fe_max, ackbuf, &ack_len); - - retval = icom_transaction(rig, C_SET_PWR, pwr_sc, NULL, 0, ackbuf, &ack_len); - rig_debug(RIG_DEBUG_VERBOSE, "%s #2 called retval=%d\n", __func__, retval); - - i = 0; retry = 10; if (status == RIG_POWER_ON) // wait for wakeup only { for (i = 0; i < retry; ++i) // up to 10 attempts { - freq_t freq = 0; + freq_t freq; sleep(1); // Use get_freq as all rigs should repond to this retval = rig_get_freq(rig, RIG_VFO_A, &freq); @@ -4473,6 +4494,8 @@ int icom_set_powerstat(RIG *rig, powerstat_t status) if (retval != RIG_OK) { + rig_debug(RIG_DEBUG_TRACE, "%s: retval != RIG_OK, =%s\n", __func__, + rigerror(retval)); return retval; } @@ -5268,7 +5291,7 @@ int icom_get_custom_parm_time(RIG *rig, int parmbuflen, unsigned char *parmbuf, unsigned char resbuf[MAXFRAMELEN]; int reslen = sizeof(resbuf); int retval; - int hour,min; + int hour, min; retval = icom_get_raw_buf(rig, C_CTL_MEM, S_MEM_PARM, parmbuflen, parmbuf, &reslen, resbuf); From e6aee45b59c6aa73e1e1bc966431faee6831095a Mon Sep 17 00:00:00 2001 From: Michael Black Date: Tue, 17 Dec 2019 08:23:19 -0600 Subject: [PATCH 100/205] Add icom_rig_open to ic7300.c and ic785x.c --- icom/ic7300.c | 2 +- icom/ic785x.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/icom/ic7300.c b/icom/ic7300.c index 70d085975..bcbed2d9a 100644 --- a/icom/ic7300.c +++ b/icom/ic7300.c @@ -346,7 +346,7 @@ const struct rig_caps ic7300_caps = .priv = (void *)& IC7300_priv_caps, .rig_init = icom_init, .rig_cleanup = icom_cleanup, - .rig_open = NULL, + .rig_open = icom_rig_open, .rig_close = NULL, .set_freq = icom_set_freq, diff --git a/icom/ic785x.c b/icom/ic785x.c index be6583c73..1600b7e68 100644 --- a/icom/ic785x.c +++ b/icom/ic785x.c @@ -279,7 +279,7 @@ const struct rig_caps ic785x_caps = .priv = (void *)& ic785x_priv_caps, .rig_init = icom_init, .rig_cleanup = icom_cleanup, - .rig_open = NULL, + .rig_open = icom_rig_open, .rig_close = NULL, .set_freq = icom_set_freq, From 67896f1913d88c372f4cfa4654c3c332078c219c Mon Sep 17 00:00:00 2001 From: Michael Black Date: Tue, 17 Dec 2019 23:44:51 -0600 Subject: [PATCH 101/205] Add rig_get_func SATMODE to icom.c and set rx/tx vfo to Main/Sub if satmode!=0 --- icom/icom.c | 24 ++++++++++++++++++++++++ icom/icom.h | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/icom/icom.c b/icom/icom.c index 6572b4ff3..207860fad 100644 --- a/icom/icom.c +++ b/icom/icom.c @@ -492,6 +492,7 @@ int icom_init(RIG *rig) struct icom_priv_data *priv; const struct icom_priv_caps *priv_caps; const struct rig_caps *caps; + int satmode; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -533,6 +534,12 @@ int icom_init(RIG *rig) priv->tx_vfo = RIG_VFO_NONE; priv->rx_vfo = RIG_VFO_NONE; priv->curr_vfo = RIG_VFO_NONE; + rig_get_func(rig, RIG_VFO_CURR, RIG_FUNC_SATMODE, &satmode); + rig_debug(RIG_DEBUG_VERBOSE, "%s: satmode=%d\n", __func__, satmode); + if (satmode) { + priv->rx_vfo = RIG_VFO_MAIN; + priv->tx_vfo = RIG_VFO_SUB; + } rig_debug(RIG_DEBUG_TRACE, "%s: done\n", __func__); @@ -3914,6 +3921,23 @@ int icom_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status) fct_sc = S_DUAL; break; + case RIG_FUNC_SATMODE: + if (rig->caps->rig_model == RIG_MODEL_IC910) + { + // Is the 910 the only one that uses this command? + fct_cn = C_CTL_MEM; + fct_sc = S_MEM_SATMODE910; + } + else + { + fct_cn = C_CTL_FUNC; + fct_sc = S_MEM_SATMODE; + } + + break; + + + default: rig_debug(RIG_DEBUG_ERR, "%s: unsupported get_func %s\n", __func__, rig_strfunc(func)); diff --git a/icom/icom.h b/icom/icom.h index 628b59574..16a50b4b2 100644 --- a/icom/icom.h +++ b/icom/icom.h @@ -30,7 +30,7 @@ #include #endif -#define BACKEND_VER "0.18" +#define BACKEND_VER "0.18a" /* * defines used by comp_cal_str in rig.c From e24d8f77bd350deb83524917ecebef250991f39c Mon Sep 17 00:00:00 2001 From: Michael Black Date: Wed, 18 Dec 2019 06:14:31 -0600 Subject: [PATCH 102/205] Have icoms check freq to see is power needs to be turned on --- icom/icom.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/icom/icom.c b/icom/icom.c index 207860fad..e8f7a624c 100644 --- a/icom/icom.c +++ b/icom/icom.c @@ -492,11 +492,12 @@ int icom_init(RIG *rig) struct icom_priv_data *priv; const struct icom_priv_caps *priv_caps; const struct rig_caps *caps; + int retval; int satmode; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig || !rig->caps) + if (!rig->caps) { return -RIG_EINVAL; } @@ -535,8 +536,10 @@ int icom_init(RIG *rig) priv->rx_vfo = RIG_VFO_NONE; priv->curr_vfo = RIG_VFO_NONE; rig_get_func(rig, RIG_VFO_CURR, RIG_FUNC_SATMODE, &satmode); - rig_debug(RIG_DEBUG_VERBOSE, "%s: satmode=%d\n", __func__, satmode); - if (satmode) { + retval = rig_debug(RIG_DEBUG_VERBOSE, "%s: satmode=%d\n", __func__, satmode); + + if (retval == RIG_OK && satmode) + { priv->rx_vfo = RIG_VFO_MAIN; priv->tx_vfo = RIG_VFO_SUB; } @@ -579,13 +582,17 @@ int icom_rig_open(RIG *rig) unsigned char ackbuf[MAXFRAMELEN]; int ack_len = sizeof(ackbuf); int retval = RIG_OK; + freq_t freq; struct rig_state *rs = &rig->state; struct icom_priv_data *priv = (struct icom_priv_data *)rs->priv; struct icom_priv_caps *priv_caps = (struct icom_priv_caps *) rig->caps->priv; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - rig_set_powerstat(rig, 1); + // if we can't get freq we may need to turn power on + retval = rig_get_freq(vfo, RIG_VFO_CURR, &freq); + + if (retval == RIG_ETIMEOUT) { rig_set_powerstat(rig, 1); } if (priv_caps->serial_USB_echo_check) { From bda8b623df8d8bd26d8fcc3b2d005f8572fa11b1 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Wed, 18 Dec 2019 06:31:47 -0600 Subject: [PATCH 103/205] Fix icom.c compile error --- icom/icom.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/icom/icom.c b/icom/icom.c index e8f7a624c..c7a13d7c1 100644 --- a/icom/icom.c +++ b/icom/icom.c @@ -535,8 +535,8 @@ int icom_init(RIG *rig) priv->tx_vfo = RIG_VFO_NONE; priv->rx_vfo = RIG_VFO_NONE; priv->curr_vfo = RIG_VFO_NONE; - rig_get_func(rig, RIG_VFO_CURR, RIG_FUNC_SATMODE, &satmode); - retval = rig_debug(RIG_DEBUG_VERBOSE, "%s: satmode=%d\n", __func__, satmode); + retval = rig_get_func(rig, RIG_VFO_CURR, RIG_FUNC_SATMODE, &satmode); + rig_debug(RIG_DEBUG_VERBOSE, "%s: satmode=%d\n", __func__, satmode); if (retval == RIG_OK && satmode) { @@ -590,7 +590,7 @@ int icom_rig_open(RIG *rig) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); // if we can't get freq we may need to turn power on - retval = rig_get_freq(vfo, RIG_VFO_CURR, &freq); + retval = rig_get_freq(rig, RIG_VFO_CURR, &freq); if (retval == RIG_ETIMEOUT) { rig_set_powerstat(rig, 1); } From a052ea40035e5d577cd11ac3d3af11518773df56 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Wed, 18 Dec 2019 10:41:00 -0600 Subject: [PATCH 104/205] Fix FLRig to expire VFOB cache when VFOA mode is set --- dummy/flrig.c | 4 ++++ dummy/flrig.h | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/dummy/flrig.c b/dummy/flrig.c index cae3bdfcc..27d56f32f 100644 --- a/dummy/flrig.c +++ b/dummy/flrig.c @@ -1257,6 +1257,10 @@ static int flrig_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) { cmd = "rig.set_modeB"; } + else + { // we make VFO_B mode unknown so it expires the cache + priv->curr_modeB = RIG_MODE_NONE; + } pxml = xml_build(cmd, cmd_buf, xml, sizeof(xml)); } diff --git a/dummy/flrig.h b/dummy/flrig.h index 673b3988c..8cbf1b71f 100644 --- a/dummy/flrig.h +++ b/dummy/flrig.h @@ -28,7 +28,7 @@ #include #endif -#define BACKEND_VER "1.11" +#define BACKEND_VER "1.12" #define EOM "\r" #define TRUE 1 From b672e8917cb1c77705dbf42cbfa1802018b4af5e Mon Sep 17 00:00:00 2001 From: Michael Black Date: Wed, 18 Dec 2019 13:07:20 -0600 Subject: [PATCH 105/205] Add debug to icom.c --- icom/icom.c | 1 + 1 file changed, 1 insertion(+) diff --git a/icom/icom.c b/icom/icom.c index c7a13d7c1..94853df63 100644 --- a/icom/icom.c +++ b/icom/icom.c @@ -591,6 +591,7 @@ int icom_rig_open(RIG *rig) // if we can't get freq we may need to turn power on retval = rig_get_freq(rig, RIG_VFO_CURR, &freq); + rig_debug(RIG_DEBUG_VERBOSE, "%s get_freq retval=%s\n", __func__, rigerror(retval)); if (retval == RIG_ETIMEOUT) { rig_set_powerstat(rig, 1); } From 3bf263aae6b2165b4ae20df23a79eb88482cc4b4 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Wed, 18 Dec 2019 14:53:05 -0600 Subject: [PATCH 106/205] Add ERJECTED as possible error when Icom rig in standby --- icom/icom.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/icom/icom.c b/icom/icom.c index 94853df63..3226f1c2d 100644 --- a/icom/icom.c +++ b/icom/icom.c @@ -593,7 +593,7 @@ int icom_rig_open(RIG *rig) retval = rig_get_freq(rig, RIG_VFO_CURR, &freq); rig_debug(RIG_DEBUG_VERBOSE, "%s get_freq retval=%s\n", __func__, rigerror(retval)); - if (retval == RIG_ETIMEOUT) { rig_set_powerstat(rig, 1); } + if (retval == RIG_ETIMEOUT || retval == RIG_ERJCTED) { rig_set_powerstat(rig, 1); } if (priv_caps->serial_USB_echo_check) { From 6e05851d78fd1940821b77b1b6463b1cfedaef73 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Wed, 18 Dec 2019 15:53:03 -0600 Subject: [PATCH 107/205] Promote ft840 to stable --- yaesu/ft840.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yaesu/ft840.c b/yaesu/ft840.c index 6f0798db9..08f77d9ae 100644 --- a/yaesu/ft840.c +++ b/yaesu/ft840.c @@ -220,7 +220,7 @@ const struct rig_caps ft840_caps = .mfg_name = "Yaesu", .version = "0.1", .copyright = "LGPL", - .status = RIG_STATUS_UNTESTED, + .status = RIG_STATUS_STABLE, .rig_type = RIG_TYPE_TRANSCEIVER, .ptt_type = RIG_PTT_RIG, .dcd_type = RIG_DCD_NONE, From ba7d3645fc005d91d27ca2406bd34a2ac31eda5e Mon Sep 17 00:00:00 2001 From: Michael Black Date: Wed, 18 Dec 2019 17:19:55 -0600 Subject: [PATCH 108/205] Fix cppcheck warning in adat.c --- adat/adat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adat/adat.c b/adat/adat.c index bc02794f2..8f9b6da00 100644 --- a/adat/adat.c +++ b/adat/adat.c @@ -3144,7 +3144,7 @@ int adat_set_mode(RIG *pRig, vfo_t vfo, rmode_t mode, pbwidth_t width) adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; pPriv->nRIGMode = mode; - nRC = adat_vfo_rnr2anr(vfo, &(pPriv->nCurrentVFO)); + adat_vfo_rnr2anr(vfo, &(pPriv->nCurrentVFO)); if (width != RIG_PASSBAND_NOCHANGE) { From efb6edcb5209d295097699d8bac9bd26fb50181a Mon Sep 17 00:00:00 2001 From: Michael Black Date: Wed, 18 Dec 2019 17:22:15 -0600 Subject: [PATCH 109/205] Fix cppcheck warning in kpa.c --- amplifiers/elecraft/kpa.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/amplifiers/elecraft/kpa.c b/amplifiers/elecraft/kpa.c index e21ab813c..308a63cb9 100644 --- a/amplifiers/elecraft/kpa.c +++ b/amplifiers/elecraft/kpa.c @@ -133,7 +133,6 @@ int kpa_transaction(AMP *amp, const char *cmd, char *response, int response_len) if (response) // if response expected get it { - int len; responsebuf[0] = 0; len = read_string(&rs->ampport, responsebuf, KPABUFSZ, ";", 1); @@ -153,7 +152,6 @@ int kpa_transaction(AMP *amp, const char *cmd, char *response, int response_len) do { - int len; char c = ';'; rig_debug(RIG_DEBUG_VERBOSE, "%s waiting for ;\n", __func__); err = write_block(&rs->ampport, &c, 1); @@ -273,8 +271,6 @@ int kpa_get_level(AMP *amp, setting_t level, value_t *val) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!amp) { return -RIG_EINVAL; } - // get the current antenna selected cmd = "^AE;"; retval = kpa_transaction(amp, cmd, responsebuf, sizeof(responsebuf)); From 83856e679d4a09d34e5305c5da45b0c1098c53c7 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Wed, 18 Dec 2019 17:28:23 -0600 Subject: [PATCH 110/205] Fix cppcheck warning in ar7030p.c --- aor/ar7030p.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/aor/ar7030p.c b/aor/ar7030p.c index 0cc715fa8..c1e4fa8ce 100644 --- a/aor/ar7030p.c +++ b/aor/ar7030p.c @@ -514,6 +514,13 @@ static int ar7030p_set_freq(RIG *rig, vfo_t vfo, freq_t freq) rc = -RIG_EINVAL; } + // this RIG_OK check added to clear cppcheck warnings + // not sure if it's needed but seem like RIG_OK should be expected + // if this debug prints out when things are working need to reexamine + if (rc != RIG_OK) { + rig_debug(RIG_DEBUG_ERR, "%s: unexpected error?? %s\n", __func__, rigerror(rc)); + } + rc = execRoutine(rig, SET_ALL); if (rc == RIG_OK) { rc = lockRx(rig, LOCK_0); } @@ -564,6 +571,13 @@ static int ar7030p_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) break; } + // this RIG_OK check added to clear cppcheck warnings + // not sure if it's needed but seem like RIG_OK should be expected + // if this debug prints out when things are working need to reexamine + if (rc != RIG_OK) { + rig_debug(RIG_DEBUG_ERR, "%s: unexpected error?? %s\n", __func__, rigerror(rc)); + } + rc = lockRx(rig, LOCK_0); } @@ -631,6 +645,13 @@ static int ar7030p_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, } } + // this RIG_OK check added to clear cppcheck warnings + // not sure if it's needed but seem like RIG_OK should be expected + // if this debug prints out when things are working need to reexamine + if (rc != RIG_OK) { + rig_debug(RIG_DEBUG_ERR, "%s: unexpected error?? %s\n", __func__, rigerror(rc)); + } + rc = lockRx(rig, LOCK_0); } @@ -968,6 +989,13 @@ static int ar7030p_set_level(RIG *rig, vfo_t vfo, setting_t level, break; } + // this RIG_OK check added to clear cppcheck warnings + // not sure if it's needed but seem like RIG_OK should be expected + // if this debug prints out when things are working need to reexamine + if (rc != RIG_OK) { + rig_debug(RIG_DEBUG_ERR, "%s: unexpected error?? %s\n", __func__, rigerror(rc)); + } + rc = lockRx(rig, LOCK_0); } From e61ce986c8c6bad7f45d1888283ff031d7b253f5 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Wed, 18 Dec 2019 17:35:35 -0600 Subject: [PATCH 111/205] Fix cppcheck warnings in ar7030a_utilsp.c --- aor/ar7030p_utils.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/aor/ar7030p_utils.c b/aor/ar7030p_utils.c index 0cb535d19..7e138ffa5 100644 --- a/aor/ar7030p_utils.c +++ b/aor/ar7030p_utils.c @@ -428,7 +428,7 @@ int execRoutine(RIG *rig, enum ROUTINE_e rtn) */ static int setAddr(RIG *rig, enum PAGE_e page, unsigned int addr) { - int rc = RIG_OK; + int rc; unsigned char v; assert(NULL != rig); @@ -528,7 +528,7 @@ static int setAddr(RIG *rig, enum PAGE_e page, unsigned int addr) */ int writeByte(RIG *rig, enum PAGE_e page, unsigned int addr, unsigned char x) { - int rc = -RIG_EIO; + int rc; unsigned char hi = SRH((x & 0xf0) >> 4); unsigned char lo = WRD(x & 0x0f); @@ -568,7 +568,7 @@ int writeByte(RIG *rig, enum PAGE_e page, unsigned int addr, unsigned char x) */ int writeShort(RIG *rig, enum PAGE_e page, unsigned int addr, unsigned short x) { - int rc = -RIG_EIO; + int rc; unsigned char v = (unsigned char)((x & 0xff00) >> 8); rc = writeByte(rig, page, addr, v); @@ -595,7 +595,7 @@ int writeShort(RIG *rig, enum PAGE_e page, unsigned int addr, unsigned short x) */ int write3Bytes(RIG *rig, enum PAGE_e page, unsigned int addr, unsigned int x) { - int rc = -RIG_EIO; + int rc; unsigned char v = (unsigned char)((x & 0xff0000) >> 16); rc = writeByte(rig, page, addr, v); @@ -630,7 +630,7 @@ int write3Bytes(RIG *rig, enum PAGE_e page, unsigned int addr, unsigned int x) */ int writeInt(RIG *rig, enum PAGE_e page, unsigned int addr, unsigned int x) { - int rc = -RIG_EIO; + int rc; unsigned char v = (unsigned char)((x & 0xff000000) >> 24); rc = writeByte(rig, page, addr, v); @@ -836,7 +836,7 @@ int readInt(RIG *rig, enum PAGE_e page, unsigned int addr, unsigned int *x) */ int readSignal(RIG *rig, unsigned char *x) { - int rc = -RIG_EIO; + int rc; assert(NULL != rig); assert(NULL != x); @@ -1479,7 +1479,7 @@ int pageSize(const enum PAGE_e page) */ int sendIRCode(RIG *rig, enum IR_CODE_e code) { - int rc = -RIG_EIO; + int rc; unsigned char v = (unsigned char) code; assert(NULL != rig); From 530a1dca16e9b92e65fe3c9cb4f323d1771f9e8d Mon Sep 17 00:00:00 2001 From: Michael Black Date: Wed, 18 Dec 2019 22:32:03 -0600 Subject: [PATCH 112/205] Fix cppcheck warnings in barrett.c --- barrett/barrett.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/barrett/barrett.c b/barrett/barrett.c index b45ca7b3e..257b6c5ef 100644 --- a/barrett/barrett.c +++ b/barrett/barrett.c @@ -337,15 +337,10 @@ int barrett_init(RIG *rig) { rig_debug(RIG_DEBUG_VERBOSE, "%s version %s\n", __func__, rig->caps->version); + // cppcheck claims leak here but it's freed in cleanup rig->state.priv = (struct barrett_priv_data *)calloc(1, sizeof(struct barrett_priv_data)); - if (!rig->caps) - { - return -RIG_EINVAL; - } - - if (!rig->state.priv) { return -RIG_ENOMEM; From 7d0805628a0d5972edd92fb28bfbeccf5f226486 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Wed, 18 Dec 2019 22:33:06 -0600 Subject: [PATCH 113/205] Fix cppcheck warnings in flrig.c --- dummy/flrig.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/dummy/flrig.c b/dummy/flrig.c index 27d56f32f..e75bfc0d7 100644 --- a/dummy/flrig.c +++ b/dummy/flrig.c @@ -351,6 +351,7 @@ static char *xml_parse(char *xml, char *value, int value_len) { char *next; char *pxml; + /* first off we should have an OK on the 1st line */ if (strstr(xml, " 200 OK") == NULL) { @@ -497,7 +498,8 @@ static int write_transaction(RIG *rig, char *xml, int xml_len) */ static int flrig_init(RIG *rig) { - struct flrig_priv_data *priv = (struct flrig_priv_data *)malloc(sizeof(struct flrig_priv_data)); + struct flrig_priv_data *priv = (struct flrig_priv_data *)malloc(sizeof( + struct flrig_priv_data)); rig_debug(RIG_DEBUG_TRACE, "%s version %s\n", __func__, BACKEND_VER); @@ -669,6 +671,9 @@ static int flrig_open(RIG *rig) /* see if get_modeA is available */ pxml = xml_build("rig.get_modeA", NULL, xml, sizeof(xml)); retval = write_transaction(rig, pxml, strlen(pxml)); + + if (retval != RIG_OK) { return retval; } + read_transaction(rig, xml, sizeof(xml)); xml_parse(xml, value, sizeof(value)); @@ -841,11 +846,14 @@ static int flrig_open(RIG *rig) } rig->state.mode_list = modes; - + retval = rig_strrmodes(modes, value, sizeof(value)); - if (retval != RIG_OK) { // we might get TRUNC but we can still print the debug - rig_debug(RIG_DEBUG_VERBOSE, "%s: %s\n", __func__, rigerror(retval)); + + if (retval != RIG_OK) // we might get TRUNC but we can still print the debug + { + rig_debug(RIG_DEBUG_VERBOSE, "%s: %s\n", __func__, rigerror(retval)); } + rig_debug(RIG_DEBUG_VERBOSE, "%s: hamlib modes=%s\n", __func__, value); return retval; @@ -1257,9 +1265,10 @@ static int flrig_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) { cmd = "rig.set_modeB"; } - else - { // we make VFO_B mode unknown so it expires the cache - priv->curr_modeB = RIG_MODE_NONE; + else + { + // we make VFO_B mode unknown so it expires the cache + priv->curr_modeB = RIG_MODE_NONE; } pxml = xml_build(cmd, cmd_buf, xml, sizeof(xml)); From eec16fa625348f54aa8edc703d93d0802c15caec Mon Sep 17 00:00:00 2001 From: Michael Black Date: Wed, 18 Dec 2019 22:34:37 -0600 Subject: [PATCH 114/205] Fix cppcheck warnings in netrigctl.c --- dummy/netrigctl.c | 1 + 1 file changed, 1 insertion(+) diff --git a/dummy/netrigctl.c b/dummy/netrigctl.c index 84bdf8410..241a66401 100644 --- a/dummy/netrigctl.c +++ b/dummy/netrigctl.c @@ -133,6 +133,7 @@ static int netrigctl_vfostr(RIG *rig, char *vfostr, int len, vfo_t vfo) static int netrigctl_init(RIG *rig) { + // cppcheck says leak here but it's freed in cleanup struct netrigctl_priv_data *priv = (struct netrigctl_priv_data *)malloc(sizeof( struct netrigctl_priv_data)); From c339dfdbe41ea5a19dd8ad7ca378840f5e963d2e Mon Sep 17 00:00:00 2001 From: Michael Black Date: Wed, 18 Dec 2019 22:35:39 -0600 Subject: [PATCH 115/205] Fix cppcheck warnings in elad.c --- elad/elad.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elad/elad.c b/elad/elad.c index 95aaef41e..0b939f3da 100644 --- a/elad/elad.c +++ b/elad/elad.c @@ -2028,7 +2028,7 @@ int get_elad_level(RIG *rig, const char *cmd, float *f) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if ( !cmd || !f) + if ( !f ) { return -RIG_EINVAL; } From a936dc5e59618f007ba6544d28420a49e0b3a4f1 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Wed, 18 Dec 2019 22:49:06 -0600 Subject: [PATCH 116/205] Fix cppcheck warnings in icom.c --- icom/icom.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/icom/icom.c b/icom/icom.c index 3226f1c2d..88c9893e9 100644 --- a/icom/icom.c +++ b/icom/icom.c @@ -591,27 +591,28 @@ int icom_rig_open(RIG *rig) // if we can't get freq we may need to turn power on retval = rig_get_freq(rig, RIG_VFO_CURR, &freq); - rig_debug(RIG_DEBUG_VERBOSE, "%s get_freq retval=%s\n", __func__, rigerror(retval)); + rig_debug(RIG_DEBUG_VERBOSE, "%s get_freq retval=%s\n", __func__, + rigerror(retval)); if (retval == RIG_ETIMEOUT || retval == RIG_ERJCTED) { rig_set_powerstat(rig, 1); } if (priv_caps->serial_USB_echo_check) { - priv->serial_USB_echo_off = 0; retval = icom_transaction(rig, C_RD_TRXID, 0x00, NULL, 0, ackbuf, &ack_len); if (retval == RIG_OK) { + priv->serial_USB_echo_off = 0; rig_debug(RIG_DEBUG_VERBOSE, "%s: USB echo on detected\n", __func__); return RIG_OK; } - priv->serial_USB_echo_off = 1; retval = icom_transaction(rig, C_RD_TRXID, 0x00, NULL, 0, ackbuf, &ack_len); if (retval == RIG_OK) { + priv->serial_USB_echo_off = 1; rig_debug(RIG_DEBUG_VERBOSE, "%s: USB echo off detected\n", __func__); return RIG_OK; } @@ -4547,8 +4548,8 @@ int icom_set_powerstat(RIG *rig, powerstat_t status) */ int icom_get_powerstat(RIG *rig, powerstat_t *status) { - unsigned char cmdbuf[MAXFRAMELEN], ackbuf[MAXFRAMELEN]; - int cmd_len, ack_len = sizeof(ackbuf), retval; + unsigned char ackbuf[MAXFRAMELEN]; + int ack_len = sizeof(ackbuf), retval; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -4557,7 +4558,8 @@ int icom_get_powerstat(RIG *rig, powerstat_t *status) { /* getting the mode doesn't work if a memory is blank */ /* so use one of the more innculous 'set mode' commands instead */ - cmd_len = 1; + int cmd_len = 1; + unsigned char cmdbuf[MAXFRAMELEN]; cmdbuf[0] = S_PRM_TIME; retval = icom_transaction(rig, C_CTL_MEM, S_MEM_MODE_SLCT, cmdbuf, cmd_len, ackbuf, &ack_len); @@ -5050,9 +5052,9 @@ int icom_decode_event(RIG *rig) __func__); } - if (frm_len < 0) + if (frm_len < 1) { - return frm_len; + return 0; } switch (buf[frm_len - 1]) @@ -5343,8 +5345,8 @@ int icom_get_custom_parm_time(RIG *rig, int parmbuflen, unsigned char *parmbuf, // Sets rig vfo && priv->curr_vfo to default VFOA, or current vfo, or the vfo requested static int set_vfo_curr(RIG *rig, vfo_t vfo, vfo_t curr_vfo) { - struct icom_priv_data *priv = (struct icom_priv_data *)rig->state.priv; int retval; + struct icom_priv_data *priv = (struct icom_priv_data *)rig->state.priv; rig_debug(RIG_DEBUG_TRACE, "%s: vfo=%s, curr_vfo=%s\n", __func__, rig_strvfo(vfo), rig_strvfo(curr_vfo)); @@ -5381,9 +5383,10 @@ static int set_vfo_curr(RIG *rig, vfo_t vfo, vfo_t curr_vfo) rig_debug(RIG_DEBUG_TRACE, "%s: setting new vfo=%s\n", __func__, rig_strvfo(vfo)); retval = rig_set_vfo(rig, vfo); - priv->curr_vfo = vfo; if (retval != RIG_OK) { return retval; } + + priv->curr_vfo = vfo; } return RIG_OK; From f6b55762dfbd4f0a2f832a84ac008dcc073a55d0 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Wed, 18 Dec 2019 22:50:58 -0600 Subject: [PATCH 117/205] Fix cppcheck warnings in k2.c --- kenwood/k2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kenwood/k2.c b/kenwood/k2.c index b3028b08b..f4aa40e56 100644 --- a/kenwood/k2.c +++ b/kenwood/k2.c @@ -343,7 +343,7 @@ int k2_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) width = rig_passband_normal(rig, mode); } - if (width > flt->filt_list[0].width || ((flt->filt_list[0].width >= width) + if ((width > flt->filt_list[0].width) || ((flt->filt_list[0].width >= width) && (width > flt->filt_list[1].width))) { width = flt->filt_list[0].width; From 41da2b38f8b14cc79721eb87bfd797e366fe125b Mon Sep 17 00:00:00 2001 From: Michael Black Date: Wed, 18 Dec 2019 22:51:37 -0600 Subject: [PATCH 118/205] Fix cppcheck warnings in kenwood.c --- kenwood/kenwood.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kenwood/kenwood.c b/kenwood/kenwood.c index c1f6e8812..ba00cb67c 100644 --- a/kenwood/kenwood.c +++ b/kenwood/kenwood.c @@ -2156,7 +2156,7 @@ int get_kenwood_level(RIG *rig, const char *cmd, float *f) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!cmd || !f) + if (!f) { return -RIG_EINVAL; } From 8c976ea10e6ba4f7d7708e6882ea0705f8c31c2a Mon Sep 17 00:00:00 2001 From: Michael Black Date: Wed, 18 Dec 2019 22:54:30 -0600 Subject: [PATCH 119/205] Fix cppcheck warnings in th.c --- kenwood/th.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kenwood/th.c b/kenwood/th.c index 6bafeb541..9c80bd3f4 100644 --- a/kenwood/th.c +++ b/kenwood/th.c @@ -1175,7 +1175,7 @@ th_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) return retval; } - retval = sscanf(ackbuf, "SM %d,%d", &v, &l); + retval = sscanf(ackbuf, "SM %d,%u", &v, &l); if (retval != 2 || l < rig->caps->level_gran[LVL_RAWSTR].min.i || l > rig->caps->level_gran[LVL_RAWSTR].max.i) @@ -1244,9 +1244,9 @@ th_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) return retval; } - retval = sscanf(ackbuf, "PC %d,%d", &v, &l); + retval = sscanf(ackbuf, "PC %d,%u", &v, &l); - if (retval != 2 || l < 0 || l > 3) + if ((retval != 2) || l > 3) { rig_debug(RIG_DEBUG_ERR, "%s: Unexpected reply '%s'\n", __func__, ackbuf); return -RIG_ERJCTED; @@ -2452,7 +2452,7 @@ int th_set_channel(RIG *rig, const channel_t *chan) } /* Step can be hexa */ - retval = snprintf(membuf, sizeof(membuf), + snprintf(membuf, sizeof(membuf), "%8s,%011"PRIll",%X,%d,%d,%d,%d,%d,%02d,%02d,%03d,%09"PRIll",%d%10s", req, (int64_t)chan->freq, step, shift, rev, tone, ctcss, dcs, tonefq, ctcssfq, dcscode, From becc661ed7b54e29c948789cef0b16b21c098da0 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Wed, 18 Dec 2019 22:55:44 -0600 Subject: [PATCH 120/205] Fix cppcheck warnings in tmd710.c --- kenwood/tmd710.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kenwood/tmd710.c b/kenwood/tmd710.c index a796f0f0f..28d7d0a64 100644 --- a/kenwood/tmd710.c +++ b/kenwood/tmd710.c @@ -2138,9 +2138,9 @@ int tmd710_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) return retval; } - retval = sscanf(ackbuf, "PC %d,%d", &v, &l); + retval = sscanf(ackbuf, "PC %d,%u", &v, &l); - if (retval != 2 || l < 0 || l > 2) + if (retval != 2 || l > 2) { rig_debug(RIG_DEBUG_ERR, "%s: Unexpected reply '%s'\n", __func__, ackbuf); return -RIG_ERJCTED; @@ -2165,7 +2165,7 @@ int tmd710_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) retval = sscanf(ackbuf, "SQ %X", &l); - if (retval != 1 || l < TMD710_SQL_MIN || l > TMD710_SQL_MAX) + if (retval != 1 || l > TMD710_SQL_MAX) { rig_debug(RIG_DEBUG_ERR, "%s: Unexpected reply '%s'\n", __func__, ackbuf); return -RIG_ERJCTED; From f187fd86cd7f26369cd8b90907ba45fd50cc2e8f Mon Sep 17 00:00:00 2001 From: Michael Black Date: Wed, 18 Dec 2019 22:57:21 -0600 Subject: [PATCH 121/205] Fix cppcheck warnings in xg3.c --- kenwood/xg3.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/kenwood/xg3.c b/kenwood/xg3.c index 1c914df57..a233063f2 100644 --- a/kenwood/xg3.c +++ b/kenwood/xg3.c @@ -107,7 +107,7 @@ const struct rig_caps xg3_caps = .rig_model = RIG_MODEL_XG3, .model_name = "XG3", .mfg_name = "Elecraft", - .version = "20150101", + .version = "20191218", .copyright = "LGPL", .status = RIG_STATUS_BETA, .rig_type = RIG_TYPE_TRANSCEIVER, @@ -514,11 +514,6 @@ int xg3_get_powerstat(RIG *rig, powerstat_t *status) retval = read_string(&rs->rigport, reply, sizeof(reply), ";", 1); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (retval != RIG_OK) - { - return retval; - } - if (retval != RIG_OK) { *status = RIG_POWER_OFF; // Error indicates power is off From 69b8b1dfa72cad9381633c83e9d91de4868c4f92 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Wed, 18 Dec 2019 22:59:59 -0600 Subject: [PATCH 122/205] Fix cppcheck warnings in xi570avrusb.c --- kit/si570avrusb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kit/si570avrusb.c b/kit/si570avrusb.c index f6c8779a9..25a9efabc 100644 --- a/kit/si570avrusb.c +++ b/kit/si570avrusb.c @@ -987,7 +987,7 @@ static int setBPF(RIG *rig, int enable) (unsigned char *) FilterCrossOver, sizeof(FilterCrossOver), rig->state.rigport.timeout); - if (retval < 0) + if (retval < 1) { return -RIG_EIO; } From e2e3d5a606fabaa1cd3f2e94a3a9276461dc871b Mon Sep 17 00:00:00 2001 From: Michael Black Date: Wed, 18 Dec 2019 23:00:34 -0600 Subject: [PATCH 123/205] Fix cppcheck warnings in xi570avrusb.c --- kit/si570avrusb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kit/si570avrusb.c b/kit/si570avrusb.c index 25a9efabc..8cd65cfba 100644 --- a/kit/si570avrusb.c +++ b/kit/si570avrusb.c @@ -904,7 +904,7 @@ int si570xxxusb_set_conf(RIG *rig, token_t token, const char *val) return -RIG_EINVAL; } - if (i2c_addr < 0 || i2c_addr >= (1 << 9)) + if (i2c_addr >= (1 << 9)) { return -RIG_EINVAL; } From 63548891f2e0dd9a1b5789cf0ceaa2e0c2fb95b4 Mon Sep 17 00:00:00 2001 From: Kosta Arvanitis Date: Thu, 19 Dec 2019 05:55:43 +0000 Subject: [PATCH 124/205] Allow IC-7410 to send cw messages --- icom/ic7410.c | 1 + 1 file changed, 1 insertion(+) diff --git a/icom/ic7410.c b/icom/ic7410.c index 5a67ddc1a..2930dd8f0 100644 --- a/icom/ic7410.c +++ b/icom/ic7410.c @@ -268,6 +268,7 @@ const struct rig_caps ic7410_caps = .get_split_mode = icom_get_split_mode, .set_split_vfo = icom_set_split_vfo, .get_split_vfo = icom_mem_get_split_vfo, + .send_morse = icom_send_morse, }; From 34e4279a784fbbdb7e5cfbe1c1ab539e6cf18c33 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Thu, 19 Dec 2019 07:46:03 -0600 Subject: [PATCH 125/205] Handling more errors on icom powerstat --- icom/icom.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/icom/icom.c b/icom/icom.c index 88c9893e9..443eaae1a 100644 --- a/icom/icom.c +++ b/icom/icom.c @@ -594,7 +594,9 @@ int icom_rig_open(RIG *rig) rig_debug(RIG_DEBUG_VERBOSE, "%s get_freq retval=%s\n", __func__, rigerror(retval)); - if (retval == RIG_ETIMEOUT || retval == RIG_ERJCTED) { rig_set_powerstat(rig, 1); } + if (retval == RIG_ETIMEOUT || retval == RIG_ERJCTED || retval == RIG_BUSERROR) { retval = rig_set_powerstat(rig, 1); } + + if (retval != RIG_OK) { rig_debug(RIG_DEBUG_WARN, "%s: unexpected retval here\n", __func__); } if (priv_caps->serial_USB_echo_check) { @@ -607,6 +609,10 @@ int icom_rig_open(RIG *rig) rig_debug(RIG_DEBUG_VERBOSE, "%s: USB echo on detected\n", __func__); return RIG_OK; } + else + { + return retval; + } retval = icom_transaction(rig, C_RD_TRXID, 0x00, NULL, 0, ackbuf, &ack_len); @@ -616,10 +622,14 @@ int icom_rig_open(RIG *rig) rig_debug(RIG_DEBUG_VERBOSE, "%s: USB echo off detected\n", __func__); return RIG_OK; } + else + { + return retval; + } } priv->serial_USB_echo_off = 0; - return retval; + return RIG_OK; } From 7dc98d3b79fd5ebf13d85cfe99fc027b4c6e43bd Mon Sep 17 00:00:00 2001 From: Michael Black Date: Thu, 19 Dec 2019 08:11:37 -0600 Subject: [PATCH 126/205] Fix cppcheck warning in getopt.c removing alloca --- lib/getopt.c | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/lib/getopt.c b/lib/getopt.c index fecab52a9..b448525dd 100644 --- a/lib/getopt.c +++ b/lib/getopt.c @@ -22,26 +22,10 @@ */ /* NOTE!!! AIX requires this to be the first thing in the file. Do not put ANYTHING before it! */ -#if !defined (__GNUC__) && defined (_AIX) -#pragma alloca -#endif - #ifdef HAVE_CONFIG_H #include "config.h" #endif -#ifdef __GNUC__ -#define alloca __builtin_alloca -#else /* not __GNUC__ */ -#if defined (HAVE_ALLOCA_H) || (defined(sparc) && (defined(sun) || (!defined(USG) && !defined(SVR4) && !defined(__svr4__)))) -#include -#else -#ifndef _AIX -char *alloca(); -#endif -#endif /* alloca.h */ -#endif /* not __GNUC__ */ - #if !__STDC__ && !defined(const) && IN_GCC #define const #endif @@ -67,12 +51,9 @@ char *alloca(); /* This needs to come after some library #include to get __GNU_LIBRARY__ defined. */ #ifdef __GNU_LIBRARY__ -#undef alloca /* Don't include stdlib.h for non-GNU C libraries because some of them contain conflicting prototypes for getopt. */ #include -#else /* Not GNU C library. */ -#define __alloca alloca #endif /* GNU C library. */ /* If GETOPT_COMPAT is defined, `+' as well as `--' can introduce a @@ -244,7 +225,7 @@ exchange(argv) char **argv; { int nonopts_size = (last_nonopt - first_nonopt) * sizeof(char *); - char **temp = (char **) __alloca(nonopts_size); + char **temp = (char **) malloc(nonopts_size); /* Interchange the two blocks of data in ARGV. */ @@ -259,6 +240,7 @@ char **argv; first_nonopt += (optind - last_nonopt); last_nonopt = optind; + free(temp); } /* Scan elements of ARGV (whose length is ARGC) for option characters @@ -326,8 +308,6 @@ const struct option *longopts; int *longind; int long_only; { - int option_index; - optarg = 0; /* Initialize the internal data when the first call is made. @@ -474,6 +454,7 @@ int long_only; int ambig = 0; const struct option *pfound = NULL; int indfound; + int option_index; while (*s && *s != '=') { From 3d98d3862c1d42cf2da00f34ad82e1a06a72962e Mon Sep 17 00:00:00 2001 From: Michael Black Date: Thu, 19 Dec 2019 08:13:34 -0600 Subject: [PATCH 127/205] Fix cppcheck warning in getopt.c --- lib/getopt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/getopt.c b/lib/getopt.c index b448525dd..33d313897 100644 --- a/lib/getopt.c +++ b/lib/getopt.c @@ -721,11 +721,11 @@ main(argc, argv) int argc; char **argv; { - int c; - int digit_optind = 0; - while (1) { + int c; + int digit_optind = 0; + int this_option_optind = optind ? optind : 1; c = getopt(argc, argv, "abc:d:0123456789"); From 7bc8ac0c35016012bb1e28dd465e550f0be4febe Mon Sep 17 00:00:00 2001 From: Michael Black Date: Thu, 19 Dec 2019 08:14:26 -0600 Subject: [PATCH 128/205] Fix cppcheck warning in getopt_long.c --- lib/getopt_long.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/getopt_long.c b/lib/getopt_long.c index 19491fafb..e42782f27 100644 --- a/lib/getopt_long.c +++ b/lib/getopt_long.c @@ -91,11 +91,11 @@ main(argc, argv) int argc; char **argv; { - int c; - int digit_optind = 0; - while (1) { + int c; + int digit_optind = 0; + int this_option_optind = optind ? optind : 1; int option_index = 0; static struct option long_options[] = From 1685a67b2ca012ebffe2513c9dc3f7f9b4b91866 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Thu, 19 Dec 2019 08:18:29 -0600 Subject: [PATCH 129/205] Fix cppcheck warnings in prm80.c --- prm80/prm80.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prm80/prm80.c b/prm80/prm80.c index d7c29c440..a3a99f397 100644 --- a/prm80/prm80.c +++ b/prm80/prm80.c @@ -355,7 +355,7 @@ int prm80_set_channel(RIG *rig, const channel_t *chan) /* [T] = Set current channel state. (Mode-Chan-Chanstate-Sql-Vol-Lock-RX freq-TX freq) ? */ /* Example: 1240080AFF0033F02D40 ? */ statebuf_len = sprintf(statebuf, "T%02X%02X%02X%02X%02X%02X%04X%04X", - (chan->mode == RIG_MODE_FM) ? 0x12 : 0x12, + 0x12, chan->channel_num, (chan->flags & RIG_CHFLAG_SKIP) ? 0x08 : 0, /* TODO: tx shift */ (unsigned)(chan->levels[LVL_SQL].f * 15), From ddc8ff0c65dae97cb36854f228cd41f886fd8234 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Thu, 19 Dec 2019 08:39:07 -0600 Subject: [PATCH 130/205] Fix cppcheck warnings in prosistel.c --- prosistel/prosistel.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/prosistel/prosistel.c b/prosistel/prosistel.c index e4e803297..c715ff7f0 100644 --- a/prosistel/prosistel.c +++ b/prosistel/prosistel.c @@ -49,7 +49,6 @@ struct prosistel_rot_priv_data azimuth_t az; elevation_t el; - struct timeval tv; /* time last az/el update */ azimuth_t target_az; elevation_t target_el; }; @@ -125,7 +124,7 @@ transaction_write: data[3]); retval = RIG_OK; } - else + else if (cmdstr) { rig_debug(RIG_DEBUG_VERBOSE, "%s Error Command issued: %c doesn't match reply %c\n", __func__, cmdstr[2], From c71bb35ab1c9371c0dbed0c94b648f595d06009b Mon Sep 17 00:00:00 2001 From: Michael Black Date: Thu, 19 Dec 2019 08:47:40 -0600 Subject: [PATCH 131/205] Fix cppcheck warnings in parallel.c --- src/parallel.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/parallel.c b/src/parallel.c index 26abcc50e..f40144480 100644 --- a/src/parallel.c +++ b/src/parallel.c @@ -126,9 +126,8 @@ */ int par_open(hamlib_port_t *port) { - int fd; - #ifdef HAVE_LINUX_PPDEV_H + int fd; int mode; #endif From 8baeb4d5cf63437736827e3cf57bc340a75d8e22 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Thu, 19 Dec 2019 08:48:02 -0600 Subject: [PATCH 132/205] Fix cppcheck warnings in cm108.c --- src/cm108.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/cm108.c b/src/cm108.c index a57fe671c..169cbc4b3 100644 --- a/src/cm108.c +++ b/src/cm108.c @@ -77,7 +77,7 @@ * \param port * \return file descriptor */ -int cm108_open(hamlib_port_t *port) +int cm108_open(hamlib_port_t *p) { int fd; #ifdef HAVE_LINUX_HIDRAW_H @@ -86,19 +86,19 @@ int cm108_open(hamlib_port_t *port) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!port->pathname[0]) + if (!p->pathname[0]) { return -RIG_EINVAL; } - fd = open(port->pathname, O_RDWR); + fd = open(p->pathname, O_RDWR); if (fd < 0) { rig_debug(RIG_DEBUG_ERR, "%s: opening device \"%s\": %s\n", __func__, - port->pathname, + p->pathname, strerror(errno)); return -RIG_EIO; } @@ -138,7 +138,7 @@ int cm108_open(hamlib_port_t *port) #endif - port->fd = fd; + p->fd = fd; return fd; } @@ -147,11 +147,11 @@ int cm108_open(hamlib_port_t *port) * \brief Close CM108 HID port * \param port */ -int cm108_close(hamlib_port_t *port) +int cm108_close(hamlib_port_t *p) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - return close(port->fd); + return close(p->fd); } @@ -174,7 +174,6 @@ int cm108_ptt_set(hamlib_port_t *p, ptt_t pttx) 0x00 }; - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); // For a CM108 USB audio device PTT is wired up to one of the GPIO @@ -186,6 +185,7 @@ int cm108_ptt_set(hamlib_port_t *p, ptt_t pttx) switch (p->type.ptt) { + case RIG_PTT_CM108: { From 00d578074ec65db1747ad5f0443b5268f548b12b Mon Sep 17 00:00:00 2001 From: Michael Black Date: Thu, 19 Dec 2019 09:38:50 -0600 Subject: [PATCH 133/205] Remove Recommend statment from rigctl.c --- tests/rigctl.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/rigctl.c b/tests/rigctl.c index ec4eb03de..dd3a7ae59 100644 --- a/tests/rigctl.c +++ b/tests/rigctl.c @@ -558,10 +558,6 @@ int main(int argc, char *argv[]) fprintf(stderr, "vfo mode doesn't make sense for any rig other than rig#2\n"); fprintf(stderr, "But we'll let you run this way if you want\n"); } - else if (!vfo_mode && my_rig->caps->rig_model == RIG_MODEL_NETRIGCTL) - { - fprintf(stderr, "Recommend using --vfo switch for rigctl with rigctld\n"); - } } rig_debug(RIG_DEBUG_VERBOSE, From eb1929800310036d7109a96d0f97becd9e22ae8a Mon Sep 17 00:00:00 2001 From: Michael Black Date: Thu, 19 Dec 2019 09:40:14 -0600 Subject: [PATCH 134/205] Fix cppcheck warning in register.h --- src/register.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/register.h b/src/register.h index 0d15dc3b8..7407ffc8a 100644 --- a/src/register.h +++ b/src/register.h @@ -25,6 +25,7 @@ #include #include #include +#include #ifdef __cplusplus #define EXTERN_C extern "C" From 2fe051e76444a5cb5e724df2aac3960bc0351f96 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Thu, 19 Dec 2019 09:50:47 -0600 Subject: [PATCH 135/205] Fix compile warning on ar7030p_utils.c --- aor/ar7030p_utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aor/ar7030p_utils.c b/aor/ar7030p_utils.c index 7e138ffa5..16ef54532 100644 --- a/aor/ar7030p_utils.c +++ b/aor/ar7030p_utils.c @@ -428,7 +428,7 @@ int execRoutine(RIG *rig, enum ROUTINE_e rtn) */ static int setAddr(RIG *rig, enum PAGE_e page, unsigned int addr) { - int rc; + int rc=RIG_OK; unsigned char v; assert(NULL != rig); From 1715bcf42299dd71819118b63d44a1a9c75a3ba5 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Thu, 19 Dec 2019 09:55:57 -0600 Subject: [PATCH 136/205] Fix compilation error on parallel.c --- src/parallel.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/parallel.c b/src/parallel.c index f40144480..a592f2601 100644 --- a/src/parallel.c +++ b/src/parallel.c @@ -126,10 +126,8 @@ */ int par_open(hamlib_port_t *port) { -#ifdef HAVE_LINUX_PPDEV_H int fd; int mode; -#endif #if defined (__WIN64__) || defined(__WIN32__) HANDLE handle; From 73c3412156e3bf1eaaadb96d190752c9c7db6be2 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Thu, 19 Dec 2019 10:33:06 -0600 Subject: [PATCH 137/205] Fix icom debug msg for powerstat --- icom/icom.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/icom/icom.c b/icom/icom.c index 443eaae1a..67bf347bc 100644 --- a/icom/icom.c +++ b/icom/icom.c @@ -594,9 +594,10 @@ int icom_rig_open(RIG *rig) rig_debug(RIG_DEBUG_VERBOSE, "%s get_freq retval=%s\n", __func__, rigerror(retval)); - if (retval == RIG_ETIMEOUT || retval == RIG_ERJCTED || retval == RIG_BUSERROR) { retval = rig_set_powerstat(rig, 1); } - - if (retval != RIG_OK) { rig_debug(RIG_DEBUG_WARN, "%s: unexpected retval here\n", __func__); } + if (retval == RIG_ETIMEOUT || retval == RIG_ERJCTED || retval == RIG_BUSERROR) { + retval = rig_set_powerstat(rig, 1); + if (retval != RIG_OK) { rig_debug(RIG_DEBUG_WARN, "%s: unexpected retval here %s\n", __func__, rigerror(retval)); } + } if (priv_caps->serial_USB_echo_check) { From ef5d2b783848ceebf287fd11200698db9ac49cb7 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Thu, 19 Dec 2019 10:57:17 -0600 Subject: [PATCH 138/205] Fix cppcheck warnings in rig.c --- src/rig.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rig.c b/src/rig.c index 195c9fd8c..a36faa9ef 100644 --- a/src/rig.c +++ b/src/rig.c @@ -1094,7 +1094,6 @@ int HAMLIB_API rig_set_freq(RIG *rig, vfo_t vfo, freq_t freq) const struct rig_caps *caps; int retcode; vfo_t curr_vfo; - int rc2; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -1128,6 +1127,7 @@ int HAMLIB_API rig_set_freq(RIG *rig, vfo_t vfo, freq_t freq) } else { + int rc2; if (!caps->set_vfo) { return -RIG_ENTARGET; From 0bae216af321d36ef57340603d6ae7e515573bf8 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Thu, 19 Dec 2019 11:50:30 -0600 Subject: [PATCH 139/205] Fix cppcheck warnings in ampctl_parse.c --- tests/ampctl_parse.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/ampctl_parse.c b/tests/ampctl_parse.c index 0ee8e91ff..a86a4def2 100644 --- a/tests/ampctl_parse.c +++ b/tests/ampctl_parse.c @@ -1457,12 +1457,13 @@ void version() void usage_amp(FILE *fout) { - int i, nbspaces; + int i; fprintf(fout, "Commands (some may not be available for this amplifier):\n"); for (i = 0; test_list[i].cmd != 0; i++) { + int nbspaces; fprintf(fout, "%c: %-12s(", isprint(test_list[i].cmd) ? test_list[i].cmd : '?', @@ -1599,13 +1600,14 @@ void list_models() int set_conf(AMP *my_amp, char *conf_parms) { - char *p, *q, *n; - int ret; + char *p, *n; p = conf_parms; while (p && *p != '\0') { + char *q; + int ret; /* FIXME: left hand value of = cannot be null */ q = strchr(p, '='); From 776e21017b6bf75ed6a9202dac1024d8faeffa71 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Thu, 19 Dec 2019 11:51:28 -0600 Subject: [PATCH 140/205] Add rx_range example --- tests/example.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/tests/example.c b/tests/example.c index 9ac890029..b6f212ca4 100644 --- a/tests/example.c +++ b/tests/example.c @@ -3,7 +3,7 @@ * Edit to specify your rig model and serial port, and baud rate * before compiling. * To compile: - * gcc -L/usr/local/lib -o example example.c -lhamlib + * gcc -I../src -I../include -g -o example example.c sprintflst.c -lhamlib * if hamlib is installed in /usr/local/... * */ @@ -12,6 +12,7 @@ #include #include #include +#include "sprintflst.h" int main() @@ -30,7 +31,7 @@ int main() rig_set_debug(RIG_DEBUG_ERR); // errors only /* Instantiate a rig */ - my_rig = rig_init(RIG_MODEL_TT565); // your rig model. + my_rig = rig_init(RIG_MODEL_DUMMY); // your rig model. /* Set up serial port, baud rate */ rig_file = "/dev/ttyUSB0"; // your serial device @@ -63,11 +64,13 @@ int main() /* Main VFO frequency */ status = rig_get_freq(my_rig, RIG_VFO_CURR, &freq); + if (status != RIG_OK) printf("Get freq failed?? Err=%s\n", rigerror(status)); printf("VFO freq. = %.1f Hz\n", freq); /* Current mode */ status = rig_get_mode(my_rig, RIG_VFO_CURR, &mode, &width); + if (status != RIG_OK) printf("Get mode failed?? Err=%s\n", rigerror(status)); switch (mode) { @@ -141,4 +144,16 @@ int main() if (status != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s: error rig_get_level: %s\n", __func__, rigerror(status)); } printf("LEVEL_STRENGTH returns %d\n", strength.i); + + const freq_range_t *range = rig_get_range(&my_rig->state.rx_range_list[0],14074000,RIG_MODE_USB); + + if (status != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s: error rig_get_ragne: %s\n", __func__, rigerror(status)); } + if (range) { + char vfolist[256]; + sprintf_vfo(vfolist,my_rig->state.vfo_list); + printf("Range start=%"PRIfreq", end=%"PRIfreq", low_power=%d, high_power=%d, vfos=%s\n",range->startf, range->endf, range->low_power, range->high_power, vfolist); + } + else { + printf("Not rx range list found\n"); + } }; From d81d60dfc1807a2bfa7e2f8772119eb664e803f4 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Thu, 19 Dec 2019 11:55:14 -0600 Subject: [PATCH 141/205] Fix cppcheck warnings in rigctl_parse.c --- tests/rigctl_parse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/rigctl_parse.c b/tests/rigctl_parse.c index df993a678..e5a878e92 100644 --- a/tests/rigctl_parse.c +++ b/tests/rigctl_parse.c @@ -614,10 +614,10 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc, /* cmd, internal, rigctld */ if (!(interactive && prompt && have_rl)) { - static int last_was_ret = 1; if (interactive) { + static int last_was_ret = 1; if (prompt) { fprintf_flush(fout, "\nRig command: "); From 9882448494687e087e260c37ae2ff514014bf7a5 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Thu, 19 Dec 2019 11:59:12 -0600 Subject: [PATCH 142/205] Fix cppcheck warnings in rigctlcom.c --- tests/rigctlcom.c | 48 +++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/tests/rigctlcom.c b/tests/rigctlcom.c index f391cea2d..b23724787 100644 --- a/tests/rigctlcom.c +++ b/tests/rigctlcom.c @@ -966,8 +966,8 @@ static int handle_ts2000(void *arg) if (retval == -RIG_ENIMPL || retval == -RIG_ENAVAIL) { - char *response = "?;"; - return write_block2((void *)__func__, &my_com, response, strlen(response)); + char *responsetmp = "?;"; + return write_block2((void *)__func__, &my_com, responsetmp, strlen(responsetmp)); } return retval; @@ -1031,8 +1031,8 @@ static int handle_ts2000(void *arg) if (retval == -RIG_ENIMPL || retval == -RIG_ENAVAIL) { - char *response = "?;"; - return write_block2((void *)__func__, &my_com, response, strlen(response)); + char *responsetmp = "?;"; + return write_block2((void *)__func__, &my_com, responsetmp, strlen(responsetmp)); } return retval; @@ -1074,8 +1074,8 @@ static int handle_ts2000(void *arg) if (retval == -RIG_ENIMPL || retval == -RIG_ENAVAIL) { - char *response = "?;"; - return write_block2((void *)__func__, &my_com, response, strlen(response)); + char *responsetmp = "?;"; + return write_block2((void *)__func__, &my_com, responsetmp, strlen(responsetmp)); } return retval; @@ -1097,8 +1097,8 @@ static int handle_ts2000(void *arg) if (retval == -RIG_ENIMPL || retval == -RIG_ENAVAIL) { - char *response = "?;"; - return write_block2((void *)__func__, &my_com, response, strlen(response)); + char *responsetmp = "?;"; + return write_block2((void *)__func__, &my_com, responsetmp, strlen(responsetmp)); } } @@ -1117,8 +1117,8 @@ static int handle_ts2000(void *arg) if (retval == -RIG_ENIMPL || retval == -RIG_ENAVAIL) { - char *response = "?;"; - return write_block2((void *)__func__, &my_com, response, strlen(response)); + char *responsetmp = "?;"; + return write_block2((void *)__func__, &my_com, responsetmp, strlen(responsetmp)); } return retval; @@ -1140,8 +1140,8 @@ static int handle_ts2000(void *arg) if (retval == -RIG_ENIMPL || retval == -RIG_ENAVAIL) { - char *response = "?;"; - return write_block2((void *)__func__, &my_com, response, strlen(response)); + char *responsetmp = "?;"; + return write_block2((void *)__func__, &my_com, responsetmp, strlen(responsetmp)); } } @@ -1161,8 +1161,8 @@ static int handle_ts2000(void *arg) if (retval == -RIG_ENIMPL || retval == -RIG_ENAVAIL) { - char *response = "?;"; - return write_block2((void *)__func__, &my_com, response, strlen(response)); + char *responsetmp = "?;"; + return write_block2((void *)__func__, &my_com, responsetmp, strlen(responsetmp)); } return retval; @@ -1211,8 +1211,8 @@ static int handle_ts2000(void *arg) if (retval == -RIG_ENIMPL || retval == -RIG_ENAVAIL) { - char *response = "?;"; - return write_block2((void *)__func__, &my_com, response, strlen(response)); + char *responsetmp = "?;"; + return write_block2((void *)__func__, &my_com, responsetmp, strlen(responsetmp)); } return retval; @@ -1247,8 +1247,8 @@ static int handle_ts2000(void *arg) if (retval == -RIG_ENIMPL || retval == -RIG_ENAVAIL) { - char *response = "?;"; - return write_block2((void *)__func__, &my_com, response, strlen(response)); + char *responsetmp = "?;"; + return write_block2((void *)__func__, &my_com, responsetmp, strlen(responsetmp)); } return retval; @@ -1267,8 +1267,8 @@ static int handle_ts2000(void *arg) if (retval == -RIG_ENIMPL || retval == -RIG_ENAVAIL) { - char *response = "?;"; - return write_block2((void *)__func__, &my_com, response, strlen(response)); + char *responsetmp = "?;"; + return write_block2((void *)__func__, &my_com, responsetmp, strlen(responsetmp)); } return retval; @@ -1317,8 +1317,8 @@ static int handle_ts2000(void *arg) if (retval == -RIG_ENIMPL || retval == -RIG_ENAVAIL) { - char *response = "?;"; - return write_block2((void *)__func__, &my_com, response, strlen(response)); + char *responsetmp = "?;"; + return write_block2((void *)__func__, &my_com, responsetmp, strlen(responsetmp)); } return retval; @@ -1352,8 +1352,8 @@ static int handle_ts2000(void *arg) if (retval == -RIG_ENIMPL || retval == -RIG_ENAVAIL) { - char *response = "?;"; - return write_block2((void *)__func__, &my_com, response, strlen(response)); + char *responsetmp = "?;"; + return write_block2((void *)__func__, &my_com, responsetmp, strlen(responsetmp)); } } From dd1184c9e565e99dea82eeb87dec0bf38580cb76 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Thu, 19 Dec 2019 12:07:28 -0600 Subject: [PATCH 143/205] Another attempt to get icom powerstat working --- icom/icom.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/icom/icom.c b/icom/icom.c index 67bf347bc..7ba3caa6d 100644 --- a/icom/icom.c +++ b/icom/icom.c @@ -594,7 +594,8 @@ int icom_rig_open(RIG *rig) rig_debug(RIG_DEBUG_VERBOSE, "%s get_freq retval=%s\n", __func__, rigerror(retval)); - if (retval == RIG_ETIMEOUT || retval == RIG_ERJCTED || retval == RIG_BUSERROR) { +// if (retval == RIG_ETIMEOUT || retval == RIG_ERJCTED || retval == RIG_BUSERROR) { + if (retval != RIG_OK) { // maybe we need powerr on? retval = rig_set_powerstat(rig, 1); if (retval != RIG_OK) { rig_debug(RIG_DEBUG_WARN, "%s: unexpected retval here %s\n", __func__, rigerror(retval)); } } From 285d73966b15cee8fe97d574026be37576a64880 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Thu, 19 Dec 2019 12:33:29 -0600 Subject: [PATCH 144/205] icom powerstat debug added --- icom/icom.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/icom/icom.c b/icom/icom.c index 7ba3caa6d..deacb2033 100644 --- a/icom/icom.c +++ b/icom/icom.c @@ -594,9 +594,11 @@ int icom_rig_open(RIG *rig) rig_debug(RIG_DEBUG_VERBOSE, "%s get_freq retval=%s\n", __func__, rigerror(retval)); -// if (retval == RIG_ETIMEOUT || retval == RIG_ERJCTED || retval == RIG_BUSERROR) { - if (retval != RIG_OK) { // maybe we need powerr on? - retval = rig_set_powerstat(rig, 1); +// if (retval == RIG_ETIMEOUT || retval == RIG_ERJCTED || retval == RIG_BUSERROR) { + if (retval != RIG_OK) // maybe we need powerr on? + { + retval = rig_set_powerstat(rig, 1); + if (retval != RIG_OK) { rig_debug(RIG_DEBUG_WARN, "%s: unexpected retval here %s\n", __func__, rigerror(retval)); } } @@ -4525,6 +4527,7 @@ int icom_set_powerstat(RIG *rig, powerstat_t status) retval = rig_get_freq(rig, RIG_VFO_A, &freq); if (retval == RIG_OK) { return retval; } + else { rig_debug(RIG_DEBUG_TRACE, "%s: get_freq err=%s\n", __func__, rigerror(retval));} rig_debug(RIG_DEBUG_TRACE, "%s: Wait %d of %d for get_powerstat\n", __func__, i + 1, retry); From c108284c55e7a11e638c919a6c972c077999380a Mon Sep 17 00:00:00 2001 From: Michael Black Date: Thu, 19 Dec 2019 12:41:06 -0600 Subject: [PATCH 145/205] Fix powerstat loop for icom --- icom/icom.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/icom/icom.c b/icom/icom.c index deacb2033..c03c5e2df 100644 --- a/icom/icom.c +++ b/icom/icom.c @@ -4524,7 +4524,7 @@ int icom_set_powerstat(RIG *rig, powerstat_t status) freq_t freq; sleep(1); // Use get_freq as all rigs should repond to this - retval = rig_get_freq(rig, RIG_VFO_A, &freq); + retval = rig_get_freq(rig, RIG_VFO_CURR, &freq); if (retval == RIG_OK) { return retval; } else { rig_debug(RIG_DEBUG_TRACE, "%s: get_freq err=%s\n", __func__, rigerror(retval));} From 2ff1f47da8bd1369e5e2c3179065af1200352d26 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Thu, 19 Dec 2019 14:42:23 -0600 Subject: [PATCH 146/205] Fix clang warning in icom.c --- icom/icom.c | 1 + 1 file changed, 1 insertion(+) diff --git a/icom/icom.c b/icom/icom.c index c03c5e2df..4989975b4 100644 --- a/icom/icom.c +++ b/icom/icom.c @@ -4515,6 +4515,7 @@ int icom_set_powerstat(RIG *rig, powerstat_t status) rs->rigport.retry = retry; } + i = 0; retry = 10; if (status == RIG_POWER_ON) // wait for wakeup only From 4b442dba945bce44b0fcb55342f0a4529cb34ae0 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Thu, 19 Dec 2019 14:45:48 -0600 Subject: [PATCH 147/205] Fix clang warning in rigctl_parse.c --- tests/rigctl_parse.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/rigctl_parse.c b/tests/rigctl_parse.c index e5a878e92..bc74c1e03 100644 --- a/tests/rigctl_parse.c +++ b/tests/rigctl_parse.c @@ -4142,7 +4142,7 @@ declare_proto_rig(send_cmd) { char tmpbuf[64]; /* text protocol */ - strncpy(bufcmd, arg1, BUFSZ); + strncpy(bufcmd, arg1, BUFSZ-1); strtok(bufcmd, "\0xa\0xd"); bufcmd[BUFSZ - 2] = '\0'; cmd_len = strlen(bufcmd); @@ -4245,8 +4245,7 @@ declare_proto_rig(send_cmd) hexbuf = realloc(hexbuf, hexbufbytes); } - strncat(hexbuf, hex, strlen(hex)); - //fprintf(fout, "%s", hex); + strncat(hexbuf, hex, hexbufbytes-1); } rig_debug(RIG_DEBUG_TRACE, "%s: binary=%s, retval=%d\n", __func__, hexbuf, From bfe28e803228b49b8bfe61816ccf1c42ecefdb2f Mon Sep 17 00:00:00 2001 From: Michael Black Date: Thu, 19 Dec 2019 17:09:18 -0600 Subject: [PATCH 148/205] Fix fd leak with fsockout --- tests/rigctld.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/rigctld.c b/tests/rigctld.c index 2fa03cc30..41ebe44d3 100644 --- a/tests/rigctld.c +++ b/tests/rigctld.c @@ -212,7 +212,7 @@ static void handle_error(enum rig_debug_level_e lvl, const char *msg) (LPTSTR)&lpMsgBuf, 0, NULL)) { - rig_debug(lvl, "%s: Network error %d: %s\n", msg, e, (char*)lpMsgBuf); + rig_debug(lvl, "%s: Network error %d: %s\n", msg, e, (char *)lpMsgBuf); LocalFree(lpMsgBuf); } else @@ -979,6 +979,7 @@ void *handle_socket(void *arg) if (retcode == 1) { + rig_close(my_rig); retcode = rig_open(my_rig); } } @@ -1031,10 +1032,13 @@ void *handle_socket(void *arg) host, serv); - fclose(fsockin); -#ifndef __MINGW32__ - fclose(fsockout); -#endif + retcode = fclose(fsockin); + + if (retcode != 0) { rig_debug(RIG_DEBUG_ERR, "%s: fclose(fsockin) %s\n", __func__, strerror(retcode)); } + + retcode = fclose(fsockout); + + if (retcode != 0) { rig_debug(RIG_DEBUG_ERR, "%s: fclose(fsockout) %s\n", __func__, strerror(retcode)); } handle_exit: #ifdef __MINGW32__ From 2703423b72d9d8f5ac4bef87ae784680fa096f94 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Thu, 19 Dec 2019 18:03:02 -0600 Subject: [PATCH 149/205] Think I got the fd socket leak on windows fixed now --- tests/rigctld.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/rigctld.c b/tests/rigctld.c index 41ebe44d3..22163aa5c 100644 --- a/tests/rigctld.c +++ b/tests/rigctld.c @@ -1036,12 +1036,16 @@ void *handle_socket(void *arg) if (retcode != 0) { rig_debug(RIG_DEBUG_ERR, "%s: fclose(fsockin) %s\n", __func__, strerror(retcode)); } +#ifndef __MINGW32__ + rig_debug(RIG_DEBUG_ERR,"%s: fclose(fsockout)\n", __func__); retcode = fclose(fsockout); if (retcode != 0) { rig_debug(RIG_DEBUG_ERR, "%s: fclose(fsockout) %s\n", __func__, strerror(retcode)); } +#endif handle_exit: #ifdef __MINGW32__ + shutdown(handle_data_arg->sock, 2) closesocket(handle_data_arg->sock); #else close(handle_data_arg->sock); From 1dbd633d5a49e952461357ce4d51e88c5a0c8205 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Thu, 19 Dec 2019 18:05:23 -0600 Subject: [PATCH 150/205] Missed semicolon --- tests/rigctld.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/rigctld.c b/tests/rigctld.c index 22163aa5c..5d1ef374d 100644 --- a/tests/rigctld.c +++ b/tests/rigctld.c @@ -1045,7 +1045,7 @@ void *handle_socket(void *arg) handle_exit: #ifdef __MINGW32__ - shutdown(handle_data_arg->sock, 2) + shutdown(handle_data_arg->sock, 2); closesocket(handle_data_arg->sock); #else close(handle_data_arg->sock); From a401d3ac78f52ba9bf6c04d976af311554de9085 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Fri, 20 Dec 2019 11:22:09 -0600 Subject: [PATCH 151/205] Fix memory leak in rigctld and cleanup debug --- tests/rigctl_parse.c | 18 +++++++++++------- tests/rigctld.c | 43 ++++++++++++++++++++++--------------------- 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/tests/rigctl_parse.c b/tests/rigctl_parse.c index bc74c1e03..0fcb0af95 100644 --- a/tests/rigctl_parse.c +++ b/tests/rigctl_parse.c @@ -473,6 +473,7 @@ static int scanfc(FILE *fin, const char *format, void *p) { do { + *(char *)p = 0; int ret = fscanf(fin, format, p); if (ret < 0) @@ -482,11 +483,13 @@ static int scanfc(FILE *fin, const char *format, void *p) continue; } - rig_debug(RIG_DEBUG_ERR, "fscanf: %s\n", strerror(errno)); - rig_debug(RIG_DEBUG_ERR, - "fscanf: parsing '%s' with '%s'\n", - (char *)p, - format); + if (!feof(fin)) + { + rig_debug(RIG_DEBUG_ERR, + "fscanf: parsing '%s' with '%s'\n", + (char *)p, + format); + } } return ret; @@ -618,6 +621,7 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc, if (interactive) { static int last_was_ret = 1; + if (prompt) { fprintf_flush(fout, "\nRig command: "); @@ -4142,7 +4146,7 @@ declare_proto_rig(send_cmd) { char tmpbuf[64]; /* text protocol */ - strncpy(bufcmd, arg1, BUFSZ-1); + strncpy(bufcmd, arg1, BUFSZ - 1); strtok(bufcmd, "\0xa\0xd"); bufcmd[BUFSZ - 2] = '\0'; cmd_len = strlen(bufcmd); @@ -4245,7 +4249,7 @@ declare_proto_rig(send_cmd) hexbuf = realloc(hexbuf, hexbufbytes); } - strncat(hexbuf, hex, hexbufbytes-1); + strncat(hexbuf, hex, hexbufbytes - 1); } rig_debug(RIG_DEBUG_TRACE, "%s: binary=%s, retval=%d\n", __func__, hexbuf, diff --git a/tests/rigctld.c b/tests/rigctld.c index 5d1ef374d..8d5dc2962 100644 --- a/tests/rigctld.c +++ b/tests/rigctld.c @@ -585,7 +585,7 @@ int main(int argc, char *argv[]) exit(2); } - if (verbose > 0) + if (verbose > RIG_DEBUG_ERR) { printf("Opened rig model %d, '%s'\n", my_rig->caps->rig_model, @@ -597,7 +597,7 @@ int main(int argc, char *argv[]) rig_close(my_rig); /* we will reopen for clients */ - if (verbose > 0) + if (verbose > RIG_DEBUG_ERR) { printf("Closed rig model %d, '%s - will reopen for clients'\n", my_rig->caps->rig_model, @@ -721,7 +721,7 @@ int main(int argc, char *argv[]) if (listen(sock_listen, 4) < 0) { - handle_error(RIG_DEBUG_ERR, "listeningn"); + handle_error(RIG_DEBUG_ERR, "listening"); exit(1); } @@ -895,8 +895,8 @@ int main(int argc, char *argv[]) void *handle_socket(void *arg) { struct handle_data *handle_data_arg = (struct handle_data *)arg; - FILE *fsockin; - FILE *fsockout; + FILE *fsockin = NULL; + FILE *fsockout = NULL; int retcode = RIG_OK; char host[NI_MAXHOST]; char serv[NI_MAXSERV]; @@ -945,7 +945,7 @@ void *handle_socket(void *arg) { retcode = rig_open(my_rig); - if (RIG_OK == retcode && verbose > 0) + if (RIG_OK == retcode && verbose > RIG_DEBUG_ERR) { printf("Opened rig model %d, '%s'\n", my_rig->caps->rig_model, @@ -957,7 +957,7 @@ void *handle_socket(void *arg) #else retcode = rig_open(my_rig); - if (RIG_OK == retcode && verbose > 0) + if (RIG_OK == retcode && verbose > RIG_DEBUG_ERR) { printf("Opened rig model %d, '%s'\n", my_rig->caps->rig_model, @@ -979,7 +979,6 @@ void *handle_socket(void *arg) if (retcode == 1) { - rig_close(my_rig); retcode = rig_open(my_rig); } } @@ -993,7 +992,7 @@ void *handle_socket(void *arg) { rig_close(my_rig); - if (verbose > 0) + if (verbose > RIG_DEBUG_ERR) { printf("Closed rig model %d, '%s - no clients, will reopen for new clients'\n", my_rig->caps->rig_model, @@ -1005,7 +1004,7 @@ void *handle_socket(void *arg) #else rig_close(my_rig); - if (verbose > 0) + if (verbose > RIG_DEBUG_ERR) { printf("Closed rig model %d, '%s - will reopen for new clients'\n", my_rig->caps->rig_model, @@ -1032,24 +1031,26 @@ void *handle_socket(void *arg) host, serv); - retcode = fclose(fsockin); +handle_exit: + +// for MINGW we close the handle before fclose +#ifdef __MINGW32__ + retcode = closesocket(handle_data_arg->sock); if (retcode != 0) { rig_debug(RIG_DEBUG_ERR, "%s: fclose(fsockin) %s\n", __func__, strerror(retcode)); } +#endif + fclose(fsockin); + fclose(fsockout); + +// for everybody else we close the handle after fclose #ifndef __MINGW32__ - rig_debug(RIG_DEBUG_ERR,"%s: fclose(fsockout)\n", __func__); - retcode = fclose(fsockout); + retcode = close(handle_data_arg->sock); + + if (retcode != 0) { rig_debug(RIG_DEBUG_ERR, "%s: close(handle_data_arg->sock) %s\n", __func__, strerror(retcode)); } - if (retcode != 0) { rig_debug(RIG_DEBUG_ERR, "%s: fclose(fsockout) %s\n", __func__, strerror(retcode)); } #endif -handle_exit: -#ifdef __MINGW32__ - shutdown(handle_data_arg->sock, 2); - closesocket(handle_data_arg->sock); -#else - close(handle_data_arg->sock); -#endif free(arg); #ifdef HAVE_PTHREAD From 343d6b48a04a268900e58b4d1f96b9555be4a73c Mon Sep 17 00:00:00 2001 From: Michael Black Date: Fri, 20 Dec 2019 16:49:17 -0600 Subject: [PATCH 152/205] Fix newcat.c get_mode MD=1=LSB, MD=2=USB --- yaesu/newcat.c | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/yaesu/newcat.c b/yaesu/newcat.c index 5cb51e42b..e56fe2b66 100644 --- a/yaesu/newcat.c +++ b/yaesu/newcat.c @@ -418,6 +418,7 @@ int newcat_set_conf(RIG *rig, token_t token, const char *val) { char *end; long value; + case TOK_FAST_SET_CMD: ; //using strtol because atoi can lead to undefined behaviour value = strtol(val, &end, 10); @@ -875,29 +876,11 @@ int newcat_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) switch (c) { case '1': - - /* Why is the FT891 backwards with LSB/USB?? Oh well... */ - if (newcat_is_rig(rig, RIG_MODEL_FT891)) - { - *mode = RIG_MODE_LSB; - } - else /* every other Yaesu */ - { - *mode = RIG_MODE_USB; - } - + *mode = RIG_MODE_LSB; break; case '2': - if (newcat_is_rig(rig, RIG_MODEL_FT891)) - { - *mode = RIG_MODE_USB; - } - else /* every other Yaesu */ - { - *mode = RIG_MODE_LSB; - } - + *mode = RIG_MODE_USB; break; case '3': From 0f2a5814f766ea6c798a21bf2e4efdfbc3d934e8 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Fri, 20 Dec 2019 22:46:44 -0600 Subject: [PATCH 153/205] Fix cppcheck warnings in cnctrk.c --- cnctrk/cnctrk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cnctrk/cnctrk.c b/cnctrk/cnctrk.c index af525208d..eae599f7e 100644 --- a/cnctrk/cnctrk.c +++ b/cnctrk/cnctrk.c @@ -51,7 +51,7 @@ cnctrk_set_position(ROT *rot, azimuth_t az, elevation_t el) } sprintf(axcmd, "/usr/bin/axis-remote --mdi 'G00 X %6.2f Y %6.2f' \n", az, el); - return retval = system(axcmd); + return system(axcmd); } From 1e6de6cdb2bdaee837e862c0a52a2b8f8251760b Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 22 Dec 2019 08:15:25 -0600 Subject: [PATCH 154/205] Fix barrett strtok to be thread safe --- barrett/barrett.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/barrett/barrett.c b/barrett/barrett.c index 257b6c5ef..2239549a4 100644 --- a/barrett/barrett.c +++ b/barrett/barrett.c @@ -60,7 +60,7 @@ static int barrett_set_split_freq(RIG *rig, vfo_t vfo, freq_t tx_freq); static int barrett_set_split_vfo(RIG *rig, vfo_t rxvfo, split_t split, vfo_t txvfo); -static int barrett_get_split_vfo(RIG *rig, vfo_t vfo, split_t *split, +static int barrett_get_split_vfo(RIG *rig, vfo_t rxvfo, split_t *split, vfo_t *txvfo); static int barrett_get_level(RIG *rig, vfo_t vfo, setting_t level, @@ -317,7 +317,8 @@ int barrett_transaction(RIG *rig, char *cmd, int expected, char **result) // Several commands can return multiline strings and we'll leave them alone if (n == 1) { - strtok(*result, "\r"); + char *dummy; + strtok_r(*result, "\r", &dummy); } dump_hex((const unsigned char *)*result, strlen(*result)); From 73319f68b39f48191b88bd795b327a4d80c882b1 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 22 Dec 2019 08:31:53 -0600 Subject: [PATCH 155/205] Make icom.c try power on when can't get freq during open --- icom/icom.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/icom/icom.c b/icom/icom.c index 4989975b4..a24969b4f 100644 --- a/icom/icom.c +++ b/icom/icom.c @@ -594,8 +594,7 @@ int icom_rig_open(RIG *rig) rig_debug(RIG_DEBUG_VERBOSE, "%s get_freq retval=%s\n", __func__, rigerror(retval)); -// if (retval == RIG_ETIMEOUT || retval == RIG_ERJCTED || retval == RIG_BUSERROR) { - if (retval != RIG_OK) // maybe we need powerr on? + if (retval != RIG_OK) // maybe we need power on? { retval = rig_set_powerstat(rig, 1); From ed339b1c2b4f92784d92bf9cbba289573efe54bf Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 22 Dec 2019 11:17:22 -0600 Subject: [PATCH 156/205] Add sleep and usleep macros so all sleeps use nanosleep --- icom/optoscan.c | 1 - include/hamlib/rig.h | 14 ++++++++++++++ src/usb_port.c | 7 +++---- winradio/winradio.c | 1 - 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/icom/optoscan.c b/icom/optoscan.c index af1db8b92..c24da430c 100644 --- a/icom/optoscan.c +++ b/icom/optoscan.c @@ -27,7 +27,6 @@ #include /* String function definitions */ #include /* UNIX standard function definitions */ #include -#include #include "hamlib/rig.h" #include "serial.h" diff --git a/include/hamlib/rig.h b/include/hamlib/rig.h index dc8d675fa..995d15c10 100644 --- a/include/hamlib/rig.h +++ b/include/hamlib/rig.h @@ -92,6 +92,20 @@ #define CONSTANT_64BIT_FLAG(BIT) (1ull << (BIT)) #endif +#include +#undef sleep +#undef usleep +#if 1 +#define usleep(n) \ + do { \ + struct timespec t;\ + t.tv_sec=0;\ + t.tv_nsec = n*1000ul;\ + nanosleep(&t,NULL);\ + } while(0) +#define sleep(n) do { struct timespec t;t.tv_sec=0;t.tv_nsec = n*1000000000ul;nanosleep(&t,NULL);} while(0) +#endif + __BEGIN_DECLS extern HAMLIB_EXPORT_VAR(const char) hamlib_version[]; diff --git a/src/usb_port.c b/src/usb_port.c index 55ec409cd..4d2fac222 100644 --- a/src/usb_port.c +++ b/src/usb_port.c @@ -35,8 +35,6 @@ # include "config.h" #endif -#include - /* * Compile only if libusb is available */ @@ -46,10 +44,11 @@ #include #include /* Standard input/output definitions */ #include /* String function definitions */ -#include /* UNIX standard function definitions */ +#include #include #include -#include + +#include #ifdef HAVE_LIBUSB_H # include diff --git a/winradio/winradio.c b/winradio/winradio.c index 6bc1248eb..5822f9071 100644 --- a/winradio/winradio.c +++ b/winradio/winradio.c @@ -24,7 +24,6 @@ #include #include /* String function definitions */ -#include /* UNIX standard function definitions */ #ifdef HAVE_SYS_IOCTL_H #include #endif From b07833c889c135bc202843e409d5c76f192f8f66 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 22 Dec 2019 11:30:30 -0600 Subject: [PATCH 157/205] Pretty up sleep macros --- include/hamlib/rig.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/include/hamlib/rig.h b/include/hamlib/rig.h index 995d15c10..b03b38553 100644 --- a/include/hamlib/rig.h +++ b/include/hamlib/rig.h @@ -95,16 +95,20 @@ #include #undef sleep #undef usleep -#if 1 -#define usleep(n) \ - do { \ +#define usleep(n)\ + do {\ struct timespec t;\ t.tv_sec=0;\ t.tv_nsec = n*1000ul;\ nanosleep(&t,NULL);\ } while(0) -#define sleep(n) do { struct timespec t;t.tv_sec=0;t.tv_nsec = n*1000000000ul;nanosleep(&t,NULL);} while(0) -#endif +#define sleep(n)\ + do {\ + struct timespec t;\ + t.tv_sec=0;\ + t.tv_nsec = n*1000000000ul;\ + nanosleep(&t,NULL);\ + } while(0) __BEGIN_DECLS From e7e9943e8b9fd4c96c16787332b97d91b42691ad Mon Sep 17 00:00:00 2001 From: Michael Black Date: Sun, 22 Dec 2019 22:23:57 -0600 Subject: [PATCH 158/205] Add set_powerstat 1 to Yaesu rig_open --- yaesu/newcat.c | 3 +++ yaesu/newcat.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/yaesu/newcat.c b/yaesu/newcat.c index e56fe2b66..3aae3597e 100644 --- a/yaesu/newcat.c +++ b/yaesu/newcat.c @@ -355,6 +355,9 @@ int newcat_open(RIG *rig) rig_debug(RIG_DEBUG_TRACE, "%s: post_write_delay = %i msec\n", __func__, rig_s->rigport.post_write_delay); + /* Ensure rig is powered on */ + rig_set_powerstat(rig, 1); + /* get current AI state so it can be restored */ priv->trn_state = -1; diff --git a/yaesu/newcat.h b/yaesu/newcat.h index ee29d4709..8fcf77bf3 100644 --- a/yaesu/newcat.h +++ b/yaesu/newcat.h @@ -50,7 +50,7 @@ typedef char ncboolean; /* shared function version */ -#define NEWCAT_VER "0.24" +#define NEWCAT_VER "0.25" /* Hopefully large enough for future use, 128 chars plus '\0' */ #define NEWCAT_DATA_LEN 129 From 8d02ba0da175fc4f03726485da734ec3d9748ef0 Mon Sep 17 00:00:00 2001 From: Chris Ruvolo Date: Sun, 22 Dec 2019 23:35:43 -0500 Subject: [PATCH 159/205] TS-690: deal with optional tone board using TS-450 logic --- kenwood/ts450s.c | 2 +- kenwood/ts690.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/kenwood/ts450s.c b/kenwood/ts450s.c index 2dd365d7f..3bcd5a00e 100644 --- a/kenwood/ts450s.c +++ b/kenwood/ts450s.c @@ -77,7 +77,7 @@ static const struct confparams ts450_ext_parms[] = { RIG_CONF_END, NULL, } }; -static int ts450_open(RIG *rig) +int ts450_open(RIG *rig) { int err; int maxtries; diff --git a/kenwood/ts690.c b/kenwood/ts690.c index aecc5ccaa..d4c2f1284 100644 --- a/kenwood/ts690.c +++ b/kenwood/ts690.c @@ -29,6 +29,7 @@ #include "bandplan.h" #include "kenwood.h" +extern int ts450_open(RIG *rig); #define TS690_ALL_MODES (RIG_MODE_AM|RIG_MODE_FM|RIG_MODE_RTTY|RIG_MODE_CW|RIG_MODE_RTTYR|RIG_MODE_CWR|RIG_MODE_SSB) #define TS690_OTHER_TX_MODES (RIG_MODE_CW|RIG_MODE_SSB|RIG_MODE_FM|RIG_MODE_RTTY|RIG_MODE_RTTYR|RIG_MODE_CWR) @@ -166,7 +167,7 @@ const struct rig_caps ts690s_caps = .rig_init = kenwood_init, .rig_cleanup = kenwood_cleanup, - .rig_open = kenwood_open, + .rig_open = ts450_open, .rig_close = kenwood_close, .set_freq = kenwood_set_freq, .get_freq = kenwood_get_freq, From d5939b6e8f6b2a18cd150cde21d38bc1a417a993 Mon Sep 17 00:00:00 2001 From: Chris Ruvolo Date: Sun, 22 Dec 2019 23:41:36 -0500 Subject: [PATCH 160/205] TS-690 does not implement the PC command to get/set output power level --- kenwood/ts690.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kenwood/ts690.c b/kenwood/ts690.c index d4c2f1284..0e9773459 100644 --- a/kenwood/ts690.c +++ b/kenwood/ts690.c @@ -97,7 +97,7 @@ const struct rig_caps ts690s_caps = .has_get_func = TS690_FUNC_ALL, .has_set_func = TS690_FUNC_ALL, - .has_get_level = TS690_LEVEL_ALL | RIG_LEVEL_RFPOWER, + .has_get_level = TS690_LEVEL_ALL, .has_set_level = RIG_LEVEL_SET(TS690_LEVEL_ALL), .has_get_parm = TS690_PARMS, .has_set_parm = RIG_LEVEL_SET(TS690_PARMS), /* FIXME: parms */ From e57576422c443a35e11fe557003071785be4eda6 Mon Sep 17 00:00:00 2001 From: Chris Ruvolo Date: Sun, 22 Dec 2019 23:44:17 -0500 Subject: [PATCH 161/205] TS-690 does not implement the GT command to get/set AGC rate --- kenwood/ts690.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kenwood/ts690.c b/kenwood/ts690.c index 0e9773459..311a1d1ef 100644 --- a/kenwood/ts690.c +++ b/kenwood/ts690.c @@ -38,7 +38,7 @@ extern int ts450_open(RIG *rig); /* FIXME: TBC */ #define TS690_FUNC_ALL (RIG_FUNC_LOCK|RIG_FUNC_AIP|RIG_FUNC_TONE) -#define TS690_LEVEL_ALL (RIG_LEVEL_STRENGTH|RIG_LEVEL_AGC|RIG_LEVEL_METER|RIG_LEVEL_SWR|RIG_LEVEL_ALC) +#define TS690_LEVEL_ALL (RIG_LEVEL_STRENGTH|RIG_LEVEL_METER|RIG_LEVEL_SWR|RIG_LEVEL_ALC) #define TS690_PARMS (RIG_PARM_ANN) /* optional */ From 7771cab7da1ec965dc21da41f60031ff4cbbb735 Mon Sep 17 00:00:00 2001 From: Chris Ruvolo Date: Sun, 22 Dec 2019 23:54:27 -0500 Subject: [PATCH 162/205] TS-690: bump version --- kenwood/ts690.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kenwood/ts690.c b/kenwood/ts690.c index 311a1d1ef..b7b3bfdbf 100644 --- a/kenwood/ts690.c +++ b/kenwood/ts690.c @@ -77,7 +77,7 @@ const struct rig_caps ts690s_caps = .rig_model = RIG_MODEL_TS690S, .model_name = "TS-690S", .mfg_name = "Kenwood", - .version = BACKEND_VER ".1", + .version = BACKEND_VER ".2", .copyright = "LGPL", .status = RIG_STATUS_BETA, .rig_type = RIG_TYPE_TRANSCEIVER, From 475012771bf77c7316b50ceeb2274e052410c1ff Mon Sep 17 00:00:00 2001 From: Michael Black Date: Mon, 23 Dec 2019 23:11:36 -0600 Subject: [PATCH 163/205] Fix cppcheck warning in rigsmtr.c --- tests/rigsmtr.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/rigsmtr.c b/tests/rigsmtr.c index 804abcc95..2de0ec95c 100644 --- a/tests/rigsmtr.c +++ b/tests/rigsmtr.c @@ -467,7 +467,7 @@ int set_conf_rig(RIG *rig, char *conf_parms) int set_conf_rot(ROT *rot, char *conf_parms) { - char *p, *q, *n; + char *p, *q, *n = NULL; int ret; p = conf_parms; @@ -480,13 +480,13 @@ int set_conf_rot(ROT *rot, char *conf_parms) if (q) { *q++ = '\0'; - } - n = strchr(q, ','); + n = strchr(q, ','); - if (n) - { - *n++ = '\0'; + if (n) + { + *n++ = '\0'; + } } ret = rot_set_conf(rot, rot_token_lookup(rot, p), q); From 17fb84044f2862c3e048024bb8974c4a27fdff42 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Mon, 23 Dec 2019 23:13:40 -0600 Subject: [PATCH 164/205] Fix cppcheck warning in rigsmtr.c --- tests/rigsmtr.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/tests/rigsmtr.c b/tests/rigsmtr.c index 2de0ec95c..82242a86b 100644 --- a/tests/rigsmtr.c +++ b/tests/rigsmtr.c @@ -428,27 +428,28 @@ void usage() int set_conf_rig(RIG *rig, char *conf_parms) { - char *p, *q, *n; + char *p; int ret; p = conf_parms; while (p && *p != '\0') { + char *q, *n = NULL; /* FIXME: left hand value of = cannot be null */ q = strchr(p, '='); if (!q) { return RIG_EINVAL; - } - *q++ = '\0'; - n = strchr(q, ','); + *q++ = '\0'; + n = strchr(q, ','); - if (n) - { - *n++ = '\0'; + if (n) + { + *n++ = '\0'; + } } ret = rig_set_conf(rig, rig_token_lookup(rig, p), q); @@ -467,13 +468,14 @@ int set_conf_rig(RIG *rig, char *conf_parms) int set_conf_rot(ROT *rot, char *conf_parms) { - char *p, *q, *n = NULL; - int ret; + char *p; p = conf_parms; while (p && *p != '\0') { + char *q, *n = NULL; + int ret; /* FIXME: left hand value of = cannot be null */ q = strchr(p, '='); From bd2149bd8aa7f7ff247308f2667f6d3958101877 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Mon, 23 Dec 2019 23:14:55 -0600 Subject: [PATCH 165/205] Fix cppcheck warning in rotctl.c --- tests/rotctl.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/rotctl.c b/tests/rotctl.c index 43b4456b1..ba45b5fc4 100644 --- a/tests/rotctl.c +++ b/tests/rotctl.c @@ -113,9 +113,6 @@ static struct option long_options[] = static const int have_rl = 1; #endif -double az_offset; -double el_offset; - int main(int argc, char *argv[]) { ROT *my_rot; /* handle to rot (instance) */ From 9b9a6c55f5aa68a1768f4997d2ff5ea9a93a4c7c Mon Sep 17 00:00:00 2001 From: Michael Black Date: Mon, 23 Dec 2019 23:36:14 -0600 Subject: [PATCH 166/205] Fix cppcheck warning in testrig.c --- tests/testrig.c | 64 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 5 deletions(-) diff --git a/tests/testrig.c b/tests/testrig.c index d92a83e14..678583220 100644 --- a/tests/testrig.c +++ b/tests/testrig.c @@ -131,12 +131,18 @@ int main(int argc, char *argv[]) printf("\nSetting 10m FM Narrow...\n"); retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 29620000); /* 10m */ + + if (retcode != RIG_OK) + { + printf("rig_set_freq: error = %s \n", rigerror(retcode)); + } + retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_FM, rig_passband_narrow(my_rig, RIG_MODE_FM)); if (retcode != RIG_OK) { - printf("rig_set_freq: error = %s \n", rigerror(retcode)); + printf("rig_set_mode: error = %s \n", rigerror(retcode)); } rig_get_freq(my_rig, RIG_VFO_CURR, &freq); @@ -154,6 +160,12 @@ int main(int argc, char *argv[]) printf("Setting 15m USB...\n"); retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 21235175); /* 15m */ + + if (retcode != RIG_OK) + { + printf("rig_set_freq: error = %s \n", rigerror(retcode)); + } + retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_USB, @@ -161,7 +173,7 @@ int main(int argc, char *argv[]) if (retcode != RIG_OK) { - printf("rig_set_freq: error = %s \n", rigerror(retcode)); + printf("rig_set_mode: error = %s \n", rigerror(retcode)); } rig_get_freq(my_rig, RIG_VFO_CURR, &freq); @@ -176,6 +188,12 @@ int main(int argc, char *argv[]) printf("Setting 40m LSB...\n"); retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 7250100); /* 40m */ + + if (retcode != RIG_OK) + { + printf("rig_set_freq: error = %s \n", rigerror(retcode)); + } + retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_LSB, @@ -183,7 +201,7 @@ int main(int argc, char *argv[]) if (retcode != RIG_OK) { - printf("rig_set_freq: error = %s \n", rigerror(retcode)); + printf("rig_set_mode: error = %s \n", rigerror(retcode)); } rig_get_freq(my_rig, RIG_VFO_CURR, &freq); @@ -200,6 +218,12 @@ int main(int argc, char *argv[]) printf("Setting 80m AM Narrow...\n"); retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 3885000); /* 80m */ + + if (retcode != RIG_OK) + { + printf("rig_set_freq: error = %s \n", rigerror(retcode)); + } + retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_AM, @@ -207,7 +231,7 @@ int main(int argc, char *argv[]) if (retcode != RIG_OK) { - printf("rig_set_freq: error = %s \n", rigerror(retcode)); + printf("rig_set_mode: error = %s \n", rigerror(retcode)); } rig_get_freq(my_rig, RIG_VFO_CURR, &freq); @@ -225,6 +249,12 @@ int main(int argc, char *argv[]) printf("Setting 160m CW...\n"); retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 1875000); /* 160m */ + + if (retcode != RIG_OK) + { + printf("rig_set_freq: error = %s \n", rigerror(retcode)); + } + retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_CW, @@ -232,7 +262,7 @@ int main(int argc, char *argv[]) if (retcode != RIG_OK) { - printf("rig_set_freq: error = %s \n", rigerror(retcode)); + printf("rig_set_mode: error = %s \n", rigerror(retcode)); } rig_get_freq(my_rig, RIG_VFO_CURR, &freq); @@ -274,6 +304,12 @@ int main(int argc, char *argv[]) printf("Setting Medium Wave AM...\n"); retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 770000); /* KAAM */ + + if (retcode != RIG_OK) + { + printf("rig_set_freq: error = %s \n", rigerror(retcode)); + } + retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_AM, @@ -299,6 +335,12 @@ int main(int argc, char *argv[]) printf("Setting 20m on VFO A with two functions...\n"); retcode = rig_set_vfo(my_rig, RIG_VFO_A); + + if (retcode != RIG_OK) + { + printf("rig_set_vfo: error = %s \n", rigerror(retcode)); + } + retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 14250375); /* cq de vk3fcs */ if (retcode != RIG_OK) @@ -424,24 +466,36 @@ int main(int argc, char *argv[]) if (rig_has_set_func(my_rig, RIG_FUNC_RIT)) { retcode = rig_set_func(my_rig, RIG_VFO_CURR, RIG_FUNC_RIT, 1); + + if (retcode != RIG_OK) { printf("rig_set_func RIT error: %s\n", rigerror(retcode)); } + printf("rig_set_func: Setting RIT ON\n"); } if (rig_has_get_func(my_rig, RIG_FUNC_RIT)) { retcode = rig_get_func(my_rig, RIG_VFO_CURR, RIG_FUNC_RIT, &rit); + + if (retcode != RIG_OK) { printf("rig_get_func RIT error: %s\n", rigerror(retcode)); } + printf("rig_get_func: RIT: %d\n", rit); } if (rig_has_set_func(my_rig, RIG_FUNC_XIT)) { retcode = rig_set_func(my_rig, RIG_VFO_CURR, RIG_FUNC_XIT, 1); + + if (retcode != RIG_OK) { printf("rig_set_func XIT error: %s\n", rigerror(retcode)); } + printf("rig_set_func: Setting XIT ON\n"); } if (rig_has_get_func(my_rig, RIG_FUNC_XIT)) { retcode = rig_get_func(my_rig, RIG_VFO_CURR, RIG_FUNC_XIT, &xit); + + if (retcode != RIG_OK) { printf("rig_get_func XIT error: %s\n", rigerror(retcode)); } + printf("rig_get_func: XIT: %d\n", xit); } From f1b3525888a92f1b8d508f9ae74f95510c564e07 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Mon, 23 Dec 2019 23:37:37 -0600 Subject: [PATCH 167/205] Fix cppcheck warning in peekpoke.c --- ts7400/include/peekpoke.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ts7400/include/peekpoke.c b/ts7400/include/peekpoke.c index 419362ee8..b5e6c3441 100644 --- a/ts7400/include/peekpoke.c +++ b/ts7400/include/peekpoke.c @@ -61,7 +61,6 @@ int main(int argc, char **argv) off_t addr, page; int fd, bits, dowrite = 0, doread = 1; unsigned char *start; - unsigned char *chardat, charval; unsigned short *shortdat, shortval; unsigned int *intdat, intval; @@ -110,6 +109,7 @@ int main(int argc, char **argv) if (bits == 8) { + unsigned char *chardat, charval; charval = (unsigned char)intval; chardat = start + (addr & 0xfff); From 4c7c6c671fb8bf9c056d60cf78622a38770acae4 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Mon, 23 Dec 2019 23:42:51 -0600 Subject: [PATCH 168/205] Fix cppcheck warning in readADC.c --- ts7400/include/readADC.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ts7400/include/readADC.c b/ts7400/include/readADC.c index ca67d38ea..f22188c2a 100644 --- a/ts7400/include/readADC.c +++ b/ts7400/include/readADC.c @@ -441,8 +441,7 @@ int test_ADC(int calibration[NUM_CHANNELS][2]) int main(void) { int calibration[NUM_CHANNELS][2]; - int stored_calibration[NUM_CHANNELS][2]; - int ret_val, state; + int ret_val; int devmem = open("/dev/mem", O_RDWR | O_SYNC); assert(devmem != -1); @@ -465,6 +464,8 @@ int main(void) if (test_ADC(calibration)) { + int state; + int stored_calibration[NUM_CHANNELS][2]; printf("ADC tested ok(data sheet values)\n"); state = read_calibration(stored_calibration); From bc9be4961ef2c7acf8e4edf560490ca07599d3c5 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Mon, 23 Dec 2019 23:43:41 -0600 Subject: [PATCH 169/205] Fix cppcheck warning in test7400ADC.c --- ts7400/include/test7400ADC.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ts7400/include/test7400ADC.c b/ts7400/include/test7400ADC.c index 76ee67584..dddfffa0f 100644 --- a/ts7400/include/test7400ADC.c +++ b/ts7400/include/test7400ADC.c @@ -432,8 +432,7 @@ int test_ADC(int calibration[NUM_CHANNELS][2]) int main(void) { int calibration[NUM_CHANNELS][2]; - int stored_calibration[NUM_CHANNELS][2]; - int ret_val, state; + int ret_val; int devmem = open("/dev/mem", O_RDWR | O_SYNC); assert(devmem != -1); @@ -455,6 +454,8 @@ int main(void) if (test_ADC(calibration)) { + int state; + int stored_calibration[NUM_CHANNELS][2]; printf("ADC tested ok(data sheet values)\n"); state = read_calibration(stored_calibration); From 13bde4c6fc6734e112f95645f04e7b4225102acd Mon Sep 17 00:00:00 2001 From: Michael Black Date: Mon, 23 Dec 2019 23:45:34 -0600 Subject: [PATCH 170/205] Fix cppcheck warning in v4l.c --- tuner/v4l.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tuner/v4l.c b/tuner/v4l.c index 5abfd6384..d4f222e88 100644 --- a/tuner/v4l.c +++ b/tuner/v4l.c @@ -165,13 +165,14 @@ int v4l_init(RIG *rig) int v4l_open(RIG *rig) { - int ret, i; + int i; struct video_tuner vt; struct rig_state *rs = &rig->state; - double fact; for (i = 0; i < 8; i++) { + int ret; + double fact; vt.tuner = i; ret = ioctl(rig->state.rigport.fd, VIDIOCGTUNER, &vt); From e33ef63d5fe6ac3c9ba351173e0ef212877c2d17 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Mon, 23 Dec 2019 23:46:00 -0600 Subject: [PATCH 171/205] Fix cppcheck warning in v4l2.c --- tuner/v4l2.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tuner/v4l2.c b/tuner/v4l2.c index 0d1c9efd6..21f5b6b9d 100644 --- a/tuner/v4l2.c +++ b/tuner/v4l2.c @@ -165,13 +165,14 @@ int v4l2_init(RIG *rig) int v4l2_open(RIG *rig) { - int ret, i; + int i; struct v4l2_tuner vt; struct rig_state *rs = &rig->state; - double fact; for (i = 0; i < 8; i++) { + int ret; + double fact; vt.index = i; ret = ioctl(rig->state.rigport.fd, VIDIOC_G_TUNER, &vt); From 3d8dedb321ff110303851c145361d443a21e0117 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Mon, 23 Dec 2019 23:49:56 -0600 Subject: [PATCH 172/205] Fix cppcheck warning in uniden.c --- uniden/uniden.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uniden/uniden.c b/uniden/uniden.c index d55949d02..fd7965dd4 100644 --- a/uniden/uniden.c +++ b/uniden/uniden.c @@ -229,7 +229,7 @@ transaction_write: #endif /* Special case for SQuelch */ - if (!memcmp(cmdstr, "SQ", 2) && (replystr[0] == '-' || replystr[0] == '+')) + if (replystr && !memcmp(cmdstr, "SQ", 2) && (replystr[0] == '-' || replystr[0] == '+')) { retval = RIG_OK; goto transaction_quit; From dba6301ae070522b09e07aa259013057b98f8f68 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Tue, 24 Dec 2019 09:37:26 -0600 Subject: [PATCH 173/205] Fix cppcheck warning in ft980.c --- yaesu/ft980.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/yaesu/ft980.c b/yaesu/ft980.c index 2a99049e6..5a3720946 100644 --- a/yaesu/ft980.c +++ b/yaesu/ft980.c @@ -713,7 +713,7 @@ int ft980_open(RIG *rig) { unsigned char echo_back[YAESU_CMD_LENGTH]; struct ft980_priv_data *priv; - int retval, retry_count1 = 0; + int retry_count1 = 0; rig_debug(RIG_DEBUG_TRACE, "%s called\n", __func__); @@ -731,6 +731,7 @@ int ft980_open(RIG *rig) /* send Ext Cntl ON: Activate CAT */ do { + int retval; int retry_count2 = 0; do @@ -753,12 +754,13 @@ int ft980_close(RIG *rig) { unsigned char echo_back[YAESU_CMD_LENGTH]; struct ft980_priv_data *priv = (struct ft980_priv_data *)rig->state.priv; - int retval, retry_count1 = 0; + int retry_count1 = 0; rig_debug(RIG_DEBUG_TRACE, "%s called\n", __func__); do { + int retval; int retry_count2 = 0; do From 86c94d513d265226cb172b49dbc9b1125e21e108 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Tue, 24 Dec 2019 09:52:19 -0600 Subject: [PATCH 174/205] Fix cppcheck warning in ft857.c --- yaesu/ft857.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/yaesu/ft857.c b/yaesu/ft857.c index a74cdde07..67bb7b7b5 100644 --- a/yaesu/ft857.c +++ b/yaesu/ft857.c @@ -571,18 +571,19 @@ int ft857_set_vfo(RIG *rig, vfo_t vfo) int ft857_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) { struct ft857_priv_data *p = (struct ft857_priv_data *) rig->state.priv; - int n; if (vfo != RIG_VFO_CURR) { return -RIG_ENTARGET; } - if (check_cache_timeout(&p->fm_status_tv)) + if (check_cache_timeout(&p->fm_status_tv)) { + int n; if ((n = ft857_get_status(rig, FT857_NATIVE_CAT_GET_FREQ_MODE_STATUS)) < 0) { return n; } + } *freq = from_bcd_be(p->fm_status, 8) * 10; @@ -661,18 +662,19 @@ static void get_mode(RIG *rig, struct ft857_priv_data *priv, rmode_t *mode, int ft857_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) { struct ft857_priv_data *p = (struct ft857_priv_data *) rig->state.priv; - int n; if (vfo != RIG_VFO_CURR) { return -RIG_ENTARGET; } - if (check_cache_timeout(&p->fm_status_tv)) + if (check_cache_timeout(&p->fm_status_tv)) { + int n; if ((n = ft857_get_status(rig, FT857_NATIVE_CAT_GET_FREQ_MODE_STATUS)) < 0) { return n; } + } get_mode(rig, p, mode, width); @@ -747,18 +749,19 @@ int ft857_get_split_vfo(RIG *rig, vfo_t vfo, split_t *split, vfo_t *tx_vfo) int ft857_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt) { struct ft857_priv_data *p = (struct ft857_priv_data *) rig->state.priv; - int n; - if (vfo != RIG_VFO_CURR) { return -RIG_ENTARGET; } - if (check_cache_timeout(&p->tx_status_tv)) + if (check_cache_timeout(&p->tx_status_tv)) { + int n; + if ((n = ft857_get_status(rig, FT857_NATIVE_CAT_GET_TX_STATUS)) < 0) { return n; } + } *ptt = ((p->tx_status & 0x80) == 0); @@ -768,13 +771,14 @@ int ft857_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt) static int ft857_get_pometer_level(RIG *rig, value_t *val) { struct ft857_priv_data *p = (struct ft857_priv_data *) rig->state.priv; - int n; - if (check_cache_timeout(&p->tx_status_tv)) + if (check_cache_timeout(&p->tx_status_tv)) { + int n; if ((n = ft857_get_status(rig, FT857_NATIVE_CAT_GET_TX_STATUS)) < 0) { return n; } + } /* Valid only if PTT is on */ if ((p->tx_status & 0x80) == 0) @@ -836,18 +840,19 @@ int ft857_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) int ft857_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd) { struct ft857_priv_data *p = (struct ft857_priv_data *) rig->state.priv; - int n; if (vfo != RIG_VFO_CURR) { return -RIG_ENTARGET; } - if (check_cache_timeout(&p->rx_status_tv)) + if (check_cache_timeout(&p->rx_status_tv)) { + int n; if ((n = ft857_get_status(rig, FT857_NATIVE_CAT_GET_RX_STATUS)) < 0) { return n; } + } /* TODO: consider bit 6 too ??? (CTCSS/DCS code match) */ if (p->rx_status & 0x80) From c048616d0ec6073d06dcacb48f85a92e22fe1c5d Mon Sep 17 00:00:00 2001 From: Michael Black Date: Tue, 24 Dec 2019 09:54:48 -0600 Subject: [PATCH 175/205] Fix cppcheck warning in ft897.c --- yaesu/ft897.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/yaesu/ft897.c b/yaesu/ft897.c index dcd40d925..182629c3f 100644 --- a/yaesu/ft897.c +++ b/yaesu/ft897.c @@ -524,18 +524,19 @@ int ft897_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) int ft897_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) { struct ft897_priv_data *p = (struct ft897_priv_data *) rig->state.priv; - int n; if (vfo != RIG_VFO_CURR) { return -RIG_ENTARGET; } - if (check_cache_timeout(&p->fm_status_tv)) + if (check_cache_timeout(&p->fm_status_tv)) { + int n; if ((n = ft897_get_status(rig, FT897_NATIVE_CAT_GET_FREQ_MODE_STATUS)) < 0) { return n; } + } switch (p->fm_status[4] & 0x7f) { @@ -629,13 +630,14 @@ int ft897_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt) static int ft897_get_pometer_level(RIG *rig, value_t *val) { struct ft897_priv_data *p = (struct ft897_priv_data *) rig->state.priv; - int n; - if (check_cache_timeout(&p->tx_status_tv)) + if (check_cache_timeout(&p->tx_status_tv)) { + int n; if ((n = ft897_get_status(rig, FT897_NATIVE_CAT_GET_TX_STATUS)) < 0) { return n; } + } /* Valid only if PTT is on */ if ((p->tx_status & 0x80) == 0) @@ -653,13 +655,14 @@ static int ft897_get_pometer_level(RIG *rig, value_t *val) static int ft897_get_swr_level(RIG *rig, value_t *val) { struct ft897_priv_data *p = (struct ft897_priv_data *) rig->state.priv; - int n; - if (check_cache_timeout(&p->tx_status_tv)) + if (check_cache_timeout(&p->tx_status_tv)) { + int n; if ((n = ft897_get_status(rig, FT897_NATIVE_CAT_GET_TX_STATUS)) < 0) { return n; } + } /* Valid only if PTT is on */ if ((p->tx_status & 0x80) == 0) @@ -695,13 +698,14 @@ static int ft897_get_smeter_level(RIG *rig, value_t *val) static int ft897_get_rawstr_level(RIG *rig, value_t *val) { struct ft897_priv_data *p = (struct ft897_priv_data *) rig->state.priv; - int n; - if (check_cache_timeout(&p->rx_status_tv)) + if (check_cache_timeout(&p->rx_status_tv)) { + int n; if ((n = ft897_get_status(rig, FT897_NATIVE_CAT_GET_RX_STATUS)) < 0) { return n; } + } val->i = p->rx_status & 0x0F; @@ -739,18 +743,19 @@ int ft897_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) int ft897_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd) { struct ft897_priv_data *p = (struct ft897_priv_data *) rig->state.priv; - int n; if (vfo != RIG_VFO_CURR) { return -RIG_ENTARGET; } - if (check_cache_timeout(&p->rx_status_tv)) + if (check_cache_timeout(&p->rx_status_tv)) { + int n; if ((n = ft897_get_status(rig, FT897_NATIVE_CAT_GET_RX_STATUS)) < 0) { return n; } + } /* TODO: consider bit 6 too ??? (CTCSS/DCS code match) */ if (p->rx_status & 0x80) From 817a61644cc0feb2c984de0f2e086976ab53619d Mon Sep 17 00:00:00 2001 From: Michael Black Date: Tue, 24 Dec 2019 09:55:27 -0600 Subject: [PATCH 176/205] Fix boolean error in ft990.c --- yaesu/ft990.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yaesu/ft990.c b/yaesu/ft990.c index fc99cabd1..d946842f9 100644 --- a/yaesu/ft990.c +++ b/yaesu/ft990.c @@ -2684,7 +2684,7 @@ int ft990_get_channel(RIG *rig, channel_t *chan) priv = (struct ft990_priv_data *) rig->state.priv; - if (chan->channel_num < 0 && chan->channel_num > 90) + if (chan->channel_num < 0 || chan->channel_num > 90) { return -RIG_EINVAL; } From 6fc999cb0119404a21f96cfc1aa56652c4f3d838 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Tue, 24 Dec 2019 09:56:12 -0600 Subject: [PATCH 177/205] Fix cppcheck warning in ft897.c --- yaesu/ft897.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/yaesu/ft897.c b/yaesu/ft897.c index 182629c3f..7c1bd0af8 100644 --- a/yaesu/ft897.c +++ b/yaesu/ft897.c @@ -530,8 +530,10 @@ int ft897_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) return -RIG_ENTARGET; } - if (check_cache_timeout(&p->fm_status_tv)) { + if (check_cache_timeout(&p->fm_status_tv)) + { int n; + if ((n = ft897_get_status(rig, FT897_NATIVE_CAT_GET_FREQ_MODE_STATUS)) < 0) { return n; @@ -631,8 +633,10 @@ static int ft897_get_pometer_level(RIG *rig, value_t *val) { struct ft897_priv_data *p = (struct ft897_priv_data *) rig->state.priv; - if (check_cache_timeout(&p->tx_status_tv)) { + if (check_cache_timeout(&p->tx_status_tv)) + { int n; + if ((n = ft897_get_status(rig, FT897_NATIVE_CAT_GET_TX_STATUS)) < 0) { return n; @@ -656,8 +660,10 @@ static int ft897_get_swr_level(RIG *rig, value_t *val) { struct ft897_priv_data *p = (struct ft897_priv_data *) rig->state.priv; - if (check_cache_timeout(&p->tx_status_tv)) { + if (check_cache_timeout(&p->tx_status_tv)) + { int n; + if ((n = ft897_get_status(rig, FT897_NATIVE_CAT_GET_TX_STATUS)) < 0) { return n; @@ -667,7 +673,7 @@ static int ft897_get_swr_level(RIG *rig, value_t *val) /* Valid only if PTT is on */ if ((p->tx_status & 0x80) == 0) { - val->f = p->tx_status & 0x40 ? 30.0 : 1.0; /* or infinity? */ + val->f = (p->tx_status & 0x40) ? 30.0 : 1.0; /* or infinity? */ } else { @@ -699,8 +705,10 @@ static int ft897_get_rawstr_level(RIG *rig, value_t *val) { struct ft897_priv_data *p = (struct ft897_priv_data *) rig->state.priv; - if (check_cache_timeout(&p->rx_status_tv)) { + if (check_cache_timeout(&p->rx_status_tv)) + { int n; + if ((n = ft897_get_status(rig, FT897_NATIVE_CAT_GET_RX_STATUS)) < 0) { return n; @@ -749,8 +757,10 @@ int ft897_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd) return -RIG_ENTARGET; } - if (check_cache_timeout(&p->rx_status_tv)) { + if (check_cache_timeout(&p->rx_status_tv)) + { int n; + if ((n = ft897_get_status(rig, FT897_NATIVE_CAT_GET_RX_STATUS)) < 0) { return n; From 15bf76d85a3e9735331e435deadcce16ae13d9b4 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Tue, 24 Dec 2019 09:57:45 -0600 Subject: [PATCH 178/205] Fix cppcheck warning in vx1700.c --- yaesu/vx1700.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yaesu/vx1700.c b/yaesu/vx1700.c index d15fb585b..cbca5860b 100644 --- a/yaesu/vx1700.c +++ b/yaesu/vx1700.c @@ -1013,8 +1013,7 @@ static int vx1700_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) static int vx1700_set_mem(RIG *rig, vfo_t vfo, int ch) { struct vx1700_priv_data *priv = (struct vx1700_priv_data *)rig->state.priv; - struct rig_state *state = &rig->state; - int ret; + struct rig_state *state = &rig->state; if (! vx1700_channel_is_ok(ch)) { return -RIG_EINVAL; } @@ -1022,6 +1021,7 @@ static int vx1700_set_mem(RIG *rig, vfo_t vfo, int ch) if (vfo == RIG_VFO_MEM) { + int ret; ret = vx1700_do_dynamic_cmd(rig, VX1700_NATIVE_RECALL_MEM, ch, 0, 0, 0); if (ret == RIG_OK) { priv->ch = ch; } @@ -1038,12 +1038,12 @@ static int vx1700_get_mem(RIG *rig, vfo_t vfo, int *ch) struct vx1700_priv_data *priv = (struct vx1700_priv_data *)rig->state.priv; struct rig_state *state = &rig->state; unsigned char channel = 0; - int ret; if (vfo == RIG_VFO_CURR) { vfo = state->current_vfo; } if (vfo == RIG_VFO_MEM) { + int ret; ret = vx1700_read_mem_channel_number(rig, &channel); if (ret != RIG_OK) { return ret; } From f61e9551de956efe221f9fb051420b86ea3acdd3 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Tue, 24 Dec 2019 10:00:45 -0600 Subject: [PATCH 179/205] Fix cppcheck warning in newcat.c --- yaesu/newcat.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/yaesu/newcat.c b/yaesu/newcat.c index 3aae3597e..82197f3e2 100644 --- a/yaesu/newcat.c +++ b/yaesu/newcat.c @@ -3954,6 +3954,11 @@ int newcat_set_mem(RIG *rig, vfo_t vfo, int ch) valid_chan.channel_num = ch; err = newcat_get_channel(rig, &valid_chan); + if (err < 0) + { + return err; + } + if (valid_chan.freq <= 1.0) { mem_caps = NULL; @@ -4634,7 +4639,6 @@ ncboolean newcat_valid_command(RIG *rig, char const *const command) ncboolean is_ft3000; ncboolean is_ft101; int search_high; - int search_index; int search_low; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -4685,6 +4689,7 @@ ncboolean newcat_valid_command(RIG *rig, char const *const command) while (search_low <= search_high) { int search_test; + int search_index; search_index = (search_low + search_high) / 2; search_test = strcmp(valid_commands[search_index].command, command); From 063e0e396db27ad4425082ed01ff86ecf56e6d89 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Tue, 24 Dec 2019 10:02:47 -0600 Subject: [PATCH 180/205] Fix cppcheck warning in ft817.c --- yaesu/ft817.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/yaesu/ft817.c b/yaesu/ft817.c index ad69e2924..7f946a705 100644 --- a/yaesu/ft817.c +++ b/yaesu/ft817.c @@ -522,18 +522,19 @@ int ft817_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) int ft817_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) { struct ft817_priv_data *p = (struct ft817_priv_data *) rig->state.priv; - int n; if (vfo != RIG_VFO_CURR) { return -RIG_ENTARGET; } - if (check_cache_timeout(&p->fm_status_tv)) + if (check_cache_timeout(&p->fm_status_tv)) { + int n; if ((n = ft817_get_status(rig, FT817_NATIVE_CAT_GET_FREQ_MODE_STATUS)) < 0) { return n; } + } switch (p->fm_status[4] & 0x7f) { @@ -640,18 +641,19 @@ int ft817_get_split_vfo(RIG *rig, vfo_t vfo, split_t *split, vfo_t *tx_vfo) int ft817_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt) { struct ft817_priv_data *p = (struct ft817_priv_data *) rig->state.priv; - int n; if (vfo != RIG_VFO_CURR) { return -RIG_ENTARGET; } - if (check_cache_timeout(&p->tx_status_tv)) + if (check_cache_timeout(&p->tx_status_tv)) { + int n; if ((n = ft817_get_status(rig, FT817_NATIVE_CAT_GET_TX_STATUS)) < 0) { return n; } + } *ptt = ((p->tx_status & 0x80) == 0); @@ -661,13 +663,14 @@ int ft817_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt) static int ft817_get_pometer_level(RIG *rig, value_t *val) { struct ft817_priv_data *p = (struct ft817_priv_data *) rig->state.priv; - int n; - if (check_cache_timeout(&p->tx_status_tv)) + if (check_cache_timeout(&p->tx_status_tv)) { + int n; if ((n = ft817_get_status(rig, FT817_NATIVE_CAT_GET_TX_STATUS)) < 0) { return n; } + } /* Valid only if PTT is on. FT-817 returns the number of bars in the lowest 4 bits @@ -730,13 +733,14 @@ static int ft817_get_smeter_level(RIG *rig, value_t *val) static int ft817_get_raw_smeter_level(RIG *rig, value_t *val) { struct ft817_priv_data *p = (struct ft817_priv_data *) rig->state.priv; - int n; - if (check_cache_timeout(&p->rx_status_tv)) + if (check_cache_timeout(&p->rx_status_tv)) { + int n; if ((n = ft817_get_status(rig, FT817_NATIVE_CAT_GET_RX_STATUS)) < 0) { return n; } + } val->i = p->rx_status & 0x0F; @@ -777,18 +781,19 @@ int ft817_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) int ft817_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd) { struct ft817_priv_data *p = (struct ft817_priv_data *) rig->state.priv; - int n; if (vfo != RIG_VFO_CURR) { return -RIG_ENTARGET; } - if (check_cache_timeout(&p->rx_status_tv)) + if (check_cache_timeout(&p->rx_status_tv)) { + int n; if ((n = ft817_get_status(rig, FT817_NATIVE_CAT_GET_RX_STATUS)) < 0) { return n; } + } /* TODO: consider bit 6 too ??? (CTCSS/DCS code match) */ if (p->rx_status & 0x80) @@ -955,7 +960,7 @@ int ft817_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) int ft817_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) { - int index, n; + int index; ptt_t ptt_response = -1; int retries = rig->state.rigport.retry; @@ -983,6 +988,7 @@ int ft817_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) do { + int n; n = ft817_send_cmd(rig, index); rig_force_cache_timeout( From e458d5bf2c5379d1a9b710414dfbc74dfc71fc71 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Tue, 24 Dec 2019 10:07:48 -0600 Subject: [PATCH 181/205] Fix cppcheck warning in ft757gx.c --- yaesu/ft767gx.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/yaesu/ft767gx.c b/yaesu/ft767gx.c index 495337d10..64b545339 100644 --- a/yaesu/ft767gx.c +++ b/yaesu/ft767gx.c @@ -263,7 +263,7 @@ const struct rig_caps ft767gx_caps = .rig_model = RIG_MODEL_FT767, .model_name = "FT-767GX", .mfg_name = "Yaesu", - .version = "1.0", + .version = "1.1", .copyright = "LGPL", .status = RIG_STATUS_STABLE, .rig_type = RIG_TYPE_TRANSCEIVER, @@ -730,7 +730,7 @@ int ft767_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt) return retval; } - *ptt = priv->update_data[STATUS_FLAGS] & 0x01 ? RIG_PTT_ON : RIG_PTT_OFF; + *ptt = (priv->update_data[STATUS_FLAGS] & 0x01) ? RIG_PTT_ON : RIG_PTT_OFF; return RIG_OK; } @@ -1480,6 +1480,10 @@ int ft767_send_block_and_ack(RIG *rig, unsigned char *cmd, size_t length) retval = read_block(&rig->state.rigport, (char *) cmd_echo_buf, YAESU_CMD_LENGTH); + if (retval < 0) { + rig_debug(RIG_DEBUG_ERR, "%s: read_block failed: %s\n", __func__, rigerror(retval)); + return retval; + } /* see if it matches the command we sent */ if (memcmp(cmd_echo_buf, cmd, YAESU_CMD_LENGTH)) @@ -1559,7 +1563,6 @@ int ft767_get_update_data(RIG *rig) int ft767_set_split(RIG *rig, unsigned int split) { - unsigned char cmd[YAESU_CMD_LENGTH] = { 0x00, 0x00, 0x00, SUBCMD_SPLIT, CMD_MULTICMD}; struct ft767_priv_data *priv = (struct ft767_priv_data *)rig->state.priv; int retval; unsigned int curr_split; @@ -1583,6 +1586,7 @@ int ft767_set_split(RIG *rig, unsigned int split) if (curr_split ^ split) { + unsigned char cmd[YAESU_CMD_LENGTH] = { 0x00, 0x00, 0x00, SUBCMD_SPLIT, CMD_MULTICMD}; retval = ft767_send_block_and_ack(rig, cmd, YAESU_CMD_LENGTH); if (retval < 0) From a48dc0c0900cc0898679e44b4b5a9ce0245e282e Mon Sep 17 00:00:00 2001 From: Michael Black Date: Tue, 24 Dec 2019 10:09:59 -0600 Subject: [PATCH 182/205] Fix cppcheck warnings in ft757gx.c --- yaesu/ft767gx.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/yaesu/ft767gx.c b/yaesu/ft767gx.c index 64b545339..c646f4f4e 100644 --- a/yaesu/ft767gx.c +++ b/yaesu/ft767gx.c @@ -1154,11 +1154,6 @@ int ft767_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, vfo_t tx_vfo) unsigned char curr_split; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (!rig) - { - return -RIG_EINVAL; - } - rig_debug(RIG_DEBUG_TRACE, "%s: passed vfo = 0x%02x\n", __func__, vfo); rig_debug(RIG_DEBUG_TRACE, "%s: passed tx_vfo = 0x%02x\n", __func__, tx_vfo); rig_debug(RIG_DEBUG_TRACE, "%s: passed split = 0x%02x\n", __func__, split); From 90e5115c95efba8de56490c6d732795f86291b8e Mon Sep 17 00:00:00 2001 From: Michael Black Date: Tue, 24 Dec 2019 10:11:27 -0600 Subject: [PATCH 183/205] Fix cppcheck warnings in ft747.c --- yaesu/ft747.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yaesu/ft747.c b/yaesu/ft747.c index 53fb588ae..505860bd7 100644 --- a/yaesu/ft747.c +++ b/yaesu/ft747.c @@ -858,8 +858,6 @@ static int ft747_get_update_data(RIG *rig) hamlib_port_t *rigport; struct ft747_priv_data *p; char last_byte; - int port_timeout; - int ret; p = (struct ft747_priv_data *)rig->state.priv; rigport = &rig->state.rigport; @@ -871,6 +869,8 @@ static int ft747_get_update_data(RIG *rig) if (!rig->state.transmit) /* rig doesn't respond in Tx mode */ { + int ret; + int port_timeout; serial_flush(rigport); /* send UPDATE comand to fetch data*/ From ee0914ec9d03a67b71581e6c798e8f49fa0c9023 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Tue, 24 Dec 2019 12:51:24 -0600 Subject: [PATCH 184/205] Fix cppcheck warnings in ft600.c --- yaesu/ft600.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yaesu/ft600.c b/yaesu/ft600.c index 41eda2690..2372bb091 100644 --- a/yaesu/ft600.c +++ b/yaesu/ft600.c @@ -462,7 +462,7 @@ int ft600_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) return -RIG_EINVAL; } - if (!width) + if (width == NULL) { *width = RIG_PASSBAND_NORMAL; } @@ -512,7 +512,6 @@ int ft600_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) int ft600_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) { unsigned char cmd_index; /* index of sequence to send */ - unsigned char p_cmd[YAESU_CMD_LENGTH]; int ret; rig_debug(RIG_DEBUG_VERBOSE, "%s: generic mode = %s, width %d\n", __func__, @@ -557,6 +556,7 @@ int ft600_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) if (mode != RIG_MODE_FM && mode != RIG_MODE_WFM && width <= kHz(6)) { + unsigned char p_cmd[YAESU_CMD_LENGTH]; p_cmd[0] = 0x00; p_cmd[1] = 0x00; p_cmd[2] = 0x00; From 55585261eb3156acbea121a1d0396fde6d8c129c Mon Sep 17 00:00:00 2001 From: Michael Black Date: Tue, 24 Dec 2019 12:52:12 -0600 Subject: [PATCH 185/205] Fix boolean logic error in ft1000d.c --- yaesu/ft1000d.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yaesu/ft1000d.c b/yaesu/ft1000d.c index 9916603bd..b8ad455a4 100644 --- a/yaesu/ft1000d.c +++ b/yaesu/ft1000d.c @@ -2735,7 +2735,7 @@ int ft1000d_get_channel(RIG *rig, channel_t *chan) priv = (struct ft1000d_priv_data *) rig->state.priv; - if (chan->channel_num < 0 && chan->channel_num > 90) + if (chan->channel_num < 0 || chan->channel_num > 90) { return -RIG_EINVAL; } From a71e7611fcebeab25b6f62c4bd9184390579b94e Mon Sep 17 00:00:00 2001 From: Michael Black Date: Tue, 24 Dec 2019 12:53:12 -0600 Subject: [PATCH 186/205] Fix cppcheck warnings in ft100.c --- yaesu/ft100.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yaesu/ft100.c b/yaesu/ft100.c index a5012aed1..289051574 100644 --- a/yaesu/ft100.c +++ b/yaesu/ft100.c @@ -529,7 +529,6 @@ int ft100_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) int ft100_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) { unsigned char cmd_index; /* index of sequence to send */ - unsigned char p_cmd[YAESU_CMD_LENGTH]; int ret; rig_debug(RIG_DEBUG_VERBOSE, "%s: generic mode = %s, width %d\n", __func__, @@ -586,6 +585,7 @@ int ft100_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) if (mode != RIG_MODE_FM && mode != RIG_MODE_WFM && width <= kHz(6)) { + unsigned char p_cmd[YAESU_CMD_LENGTH]; p_cmd[0] = 0x00; p_cmd[1] = 0x00; p_cmd[2] = 0x00; @@ -852,7 +852,6 @@ int ft100_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) { int ret; - float f; FT100_METER_INFO ft100_meter; if (!rig) { return -RIG_EINVAL; } @@ -895,6 +894,7 @@ int ft100_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) } else { + float f; f = sqrt((float)ft100_meter.tx_rev_power / (float)ft100_meter.tx_fwd_power); val->f = (1 + f) / (1 - f); } From 73e6ae44bd3cd81b1921f8048255c5106ac69464 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Tue, 24 Dec 2019 12:53:58 -0600 Subject: [PATCH 187/205] Fix cppcheck warnings in wj.c --- wj/wj.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wj/wj.c b/wj/wj.c index 7ce5ee99c..3c70060ef 100644 --- a/wj/wj.c +++ b/wj/wj.c @@ -290,7 +290,7 @@ int wj_get_conf(RIG *rig, token_t token, char *val) switch (token) { case TOK_RIGID: - sprintf(val, "%d", priv->receiver_id); + sprintf(val, "%u", priv->receiver_id); break; default: From 4f05f09eeda10bd21231ce0fe74a541b64cc827a Mon Sep 17 00:00:00 2001 From: Michael Black Date: Tue, 24 Dec 2019 12:55:01 -0600 Subject: [PATCH 188/205] Fix potential segfault in g313-posix.c --- winradio/g313-posix.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/winradio/g313-posix.c b/winradio/g313-posix.c index 7fd910b7c..ba230d3ee 100644 --- a/winradio/g313-posix.c +++ b/winradio/g313-posix.c @@ -115,14 +115,14 @@ int g313_init(RIG *rig) priv = (struct g313_priv_data *)malloc(sizeof(struct g313_priv_data)); - memset(priv, 0, sizeof(struct g313_priv_data)); - if (!priv) { /* whoops! memory shortage! */ return -RIG_ENOMEM; } + memset(priv, 0, sizeof(struct g313_priv_data)); + priv->hWRAPI = g313_init_api(); if (priv->hWRAPI) From 24eaeecfdfa1eacd11b64e927db75376ea9ecee8 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Tue, 24 Dec 2019 15:01:08 -0600 Subject: [PATCH 189/205] Fix sleep macros and newcat.c set_powerstat --- include/hamlib/rig.h | 10 ++++++---- yaesu/newcat.c | 14 ++++++-------- yaesu/newcat.h | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/include/hamlib/rig.h b/include/hamlib/rig.h index b03b38553..cb256f060 100644 --- a/include/hamlib/rig.h +++ b/include/hamlib/rig.h @@ -97,16 +97,18 @@ #undef usleep #define usleep(n)\ do {\ + unsigned long sec = n/1000000ul;\ + unsigned long nsec = n*1000ul - (sec * 1000000000ul);\ struct timespec t;\ - t.tv_sec=0;\ - t.tv_nsec = n*1000ul;\ + t.tv_sec=sec;\ + t.tv_nsec = nsec;\ nanosleep(&t,NULL);\ } while(0) #define sleep(n)\ do {\ struct timespec t;\ - t.tv_sec=0;\ - t.tv_nsec = n*1000000000ul;\ + t.tv_sec=n;\ + t.tv_nsec = 0;\ nanosleep(&t,NULL);\ } while(0) diff --git a/yaesu/newcat.c b/yaesu/newcat.c index 82197f3e2..ed5167132 100644 --- a/yaesu/newcat.c +++ b/yaesu/newcat.c @@ -2260,6 +2260,10 @@ int newcat_set_powerstat(RIG *rig, powerstat_t status) { case RIG_POWER_ON: ps = '1'; + // when powering on need a dummy byte to wake it up + // then sleep from 1 to 2 seconds so we'll do 1.5 secs + write_block(&state->rigport, "\n", 1); + usleep(1500000); break; case RIG_POWER_OFF: @@ -2273,15 +2277,9 @@ int newcat_set_powerstat(RIG *rig, powerstat_t status) snprintf(priv->cmd_str, sizeof(priv->cmd_str), "PS%c%c", ps, cat_term); - if (RIG_OK != (err = write_block(&state->rigport, priv->cmd_str, - strlen(priv->cmd_str)))) - { - return err; - } + err = write_block(&state->rigport, priv->cmd_str, strlen(priv->cmd_str)); - // delay 1.5 seconds - usleep(1500000); - return write_block(&state->rigport, priv->cmd_str, strlen(priv->cmd_str)); + return err; } diff --git a/yaesu/newcat.h b/yaesu/newcat.h index 8fcf77bf3..60b2a5983 100644 --- a/yaesu/newcat.h +++ b/yaesu/newcat.h @@ -50,7 +50,7 @@ typedef char ncboolean; /* shared function version */ -#define NEWCAT_VER "0.25" +#define NEWCAT_VER "0.26" /* Hopefully large enough for future use, 128 chars plus '\0' */ #define NEWCAT_DATA_LEN 129 From 9012049a374356881a95851ee05308fefa42696a Mon Sep 17 00:00:00 2001 From: Michael Black Date: Tue, 24 Dec 2019 15:11:41 -0600 Subject: [PATCH 190/205] Fix cppcheck warnings in ampctl_parse.c --- tests/ampctl_parse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ampctl_parse.c b/tests/ampctl_parse.c index a86a4def2..8104e7ab7 100644 --- a/tests/ampctl_parse.c +++ b/tests/ampctl_parse.c @@ -227,7 +227,7 @@ struct test_table *find_cmd_entry(int cmd) */ struct mod_lst { - int id; /* caps->amp_model This is the hash key */ + unsigned int id; /* caps->amp_model This is the hash key */ char mfg_name[32]; /* caps->mfg_name */ char model_name[32]; /* caps->model_name */ char version[32]; /* caps->version */ From 57952c59278a56e440a4411187728275ba42908c Mon Sep 17 00:00:00 2001 From: Michael Black Date: Tue, 24 Dec 2019 15:12:05 -0600 Subject: [PATCH 191/205] Fix cppcheck warnings in rotctl_parse.c --- tests/rotctl_parse.c | 49 +++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/tests/rotctl_parse.c b/tests/rotctl_parse.c index 08bdcb1fe..f042ee411 100644 --- a/tests/rotctl_parse.c +++ b/tests/rotctl_parse.c @@ -359,7 +359,7 @@ char parse_arg(const char *arg) { int i; - for (i = 0; i < MAXNBOPT && test_list[i].cmd != 0; i++) + for (i = 0; test_list[i].cmd != 0; i++) { if (!strncmp(arg, test_list[i].name, MAXNAMSIZ)) { @@ -376,10 +376,10 @@ char parse_arg(const char *arg) */ static int scanfc(FILE *fin, const char *format, void *p) { - int ret; - do { + int ret; + ret = fscanf(fin, format, p); if (ret < 0) @@ -519,13 +519,14 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc, char arg4[MAXARGSZ + 1], *p4 = NULL; char *p5 = NULL; char *p6 = NULL; - static int last_was_ret = 1; /* cmd, internal, rotctld */ if (!(interactive && prompt && have_rl)) { if (interactive) { + static int last_was_ret = 1; + if (prompt) { fprintf_flush(fout, "\nRotator command: "); @@ -1084,22 +1085,21 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc, rp_getline(pmptstr); + if (input_line == NULL) + { + fprintf_flush(fout, "\n"); + return 1; + } /* Blank line entered */ - if (!(strcmp(input_line, ""))) + else if (!(strcmp(input_line, ""))) { fprintf(fout, "? for help, q to quit.\n"); fflush(fout); return 0; } - - if (input_line) - { - parsed_input[x] = input_line; - } else { - fprintf_flush(fout, "\n"); - return 1; + parsed_input[x] = input_line; } } @@ -1448,8 +1448,9 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc, } else { - if (cmd_entry != NULL && cmd_entry->name != NULL) { - fprintf(fout, "%s: error = %s\n", cmd_entry->name, rigerror(retcode)); + if (cmd_entry != NULL && cmd_entry->name != NULL) + { + fprintf(fout, "%s: error = %s\n", cmd_entry->name, rigerror(retcode)); } } } @@ -1490,12 +1491,13 @@ void version() void usage_rot(FILE *fout) { - int i, nbspaces; + int i; fprintf(fout, "Commands (some may not be available for this rotator):\n"); for (i = 0; test_list[i].cmd != 0; i++) { + int nbspaces; fprintf(fout, "%c: %-12s(", isprint(test_list[i].cmd) ? test_list[i].cmd : '?', @@ -1631,28 +1633,29 @@ void list_models() int set_conf(ROT *my_rot, char *conf_parms) { - char *p, *q, *n; - int ret; + char *p; rot_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); p = conf_parms; while (p && *p != '\0') { + int ret; + char *q, *n = NULL; /* FIXME: left hand value of = cannot be null */ q = strchr(p, '='); if (!q) { return RIG_EINVAL; - } - *q++ = '\0'; - n = strchr(q, ','); + *q++ = '\0'; + n = strchr(q, ','); - if (n) - { - *n++ = '\0'; + if (n) + { + *n++ = '\0'; + } } rig_debug(RIG_DEBUG_TRACE, "%s: token=%s, val=%s\n", __func__, p, q); From 2fca5f49b86d9d2a7c2565fe91398a4ea9c23751 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Tue, 24 Dec 2019 15:21:06 -0600 Subject: [PATCH 192/205] Remove hl_sleep.h as no longer needed --- adat/adat.c | 17 ----------------- include/Makefile.am | 2 +- include/hl_sleep.h | 41 ----------------------------------------- tentec/paragon.c | 17 ----------------- tentec/tt550.c | 18 ------------------ tests/ampctl_parse.c | 18 ------------------ tests/rigctl_parse.c | 17 ----------------- tests/testrig.c | 17 ----------------- tests/testtrn.c | 17 ----------------- 9 files changed, 1 insertion(+), 163 deletions(-) delete mode 100644 include/hl_sleep.h diff --git a/adat/adat.c b/adat/adat.c index 8f9b6da00..6b22cc7dc 100644 --- a/adat/adat.c +++ b/adat/adat.c @@ -48,23 +48,6 @@ #include "register.h" #include "num_stdio.h" -/* HAVE_SSLEEP is defined when Windows Sleep is found - * HAVE_SLEEP is defined when POSIX sleep is found - * _WIN32 is defined when compiling with MinGW - * - * When cross-compiling from POSIX to Windows using MinGW, HAVE_SLEEP - * will often be defined by configure although it is not supported by - * MinGW. So substitute the sleep definition below in such a case and - * when compiling on Windows using MinGW where HAVE_SLEEP will be - * undefined. - * - * FIXME: Needs better handling for all versions of MinGW. - * - */ -#if (defined(HAVE_SSLEEP) || defined(_WIN32)) && (!defined(HAVE_SLEEP)) -# include "hl_sleep.h" -#endif - // --------------------------------------------------------------------------- // ADAT INCLUDES // --------------------------------------------------------------------------- diff --git a/include/Makefile.am b/include/Makefile.am index 8f54fb88b..fddf48f66 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1,4 +1,4 @@ -noinst_HEADERS = config.h bandplan.h num_stdio.h hl_sleep.h +noinst_HEADERS = config.h bandplan.h num_stdio.h nobase_include_HEADERS = hamlib/rig.h hamlib/riglist.h hamlib/rig_dll.h \ hamlib/rotator.h hamlib/rotlist.h hamlib/rigclass.h \ diff --git a/include/hl_sleep.h b/include/hl_sleep.h deleted file mode 100644 index 3782a8f6f..000000000 --- a/include/hl_sleep.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Hamlib Interface - Replacement sleep() declaration for Windows - * Copyright (C) 2013 The Hamlib Group - * - * - * 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 - * - */ - -/* Define missing sleep() prototype */ -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef HAVE_WINBASE_H -#include -#include -#endif - -/* TODO: what about SleepEx? */ -static inline unsigned int sleep(unsigned int nb_sec) -{ - Sleep(nb_sec * 1000); - return 0; -} - -#ifdef __cplusplus -} -#endif diff --git a/tentec/paragon.c b/tentec/paragon.c index 305853016..f81960fbb 100644 --- a/tentec/paragon.c +++ b/tentec/paragon.c @@ -36,23 +36,6 @@ #include "misc.h" #include "num_stdio.h" -/* HAVE_SSLEEP is defined when Windows Sleep is found - * HAVE_SLEEP is defined when POSIX sleep is found - * _WIN32 is defined when compiling with MinGW - * - * When cross-compiling from POSIX to Windows using MinGW, HAVE_SLEEP - * will often be defined by configure although it is not supported by - * MinGW. So substitute the sleep definition below in such a case and - * when compiling on Windows using MinGW where HAVE_SLEEP will be - * undefined. - * - * FIXME: Needs better handling for all versions of MinGW. - * - */ -#if (defined(HAVE_SSLEEP) || defined(_WIN32)) && (!defined(HAVE_SLEEP)) -#include "hl_sleep.h" -#endif - struct tt585_priv_data { unsigned char status_data[30]; diff --git a/tentec/tt550.c b/tentec/tt550.c index 15a6943ca..2c8e71760 100644 --- a/tentec/tt550.c +++ b/tentec/tt550.c @@ -39,24 +39,6 @@ #include "tt550.h" -/* HAVE_SSLEEP is defined when Windows Sleep is found - * HAVE_SLEEP is defined when POSIX sleep is found - * _WIN32 is defined when compiling with MinGW - * - * When cross-compiling from POSIX to Windows using MinGW, HAVE_SLEEP - * will often be defined by configure although it is not supported by - * MinGW. So substitute the sleep definition below in such a case and - * when compiling on Windows using MinGW where HAVE_SLEEP will be - * undefined. - * - * FIXME: Needs better handling for all versions of MinGW. - * - */ -#if (defined(HAVE_SSLEEP) || defined(_WIN32)) && (!defined(HAVE_SLEEP)) -#include "hl_sleep.h" -#endif - - /* * Filter table for 550 reciver support */ diff --git a/tests/ampctl_parse.c b/tests/ampctl_parse.c index 8104e7ab7..57099e569 100644 --- a/tests/ampctl_parse.c +++ b/tests/ampctl_parse.c @@ -66,24 +66,6 @@ extern int read_history(); #include "misc.h" #include "sprintflst.h" - -/* HAVE_SSLEEP is defined when Windows Sleep is found - * HAVE_SLEEP is defined when POSIX sleep is found - * _WIN32 is defined when compiling with MinGW - * - * When cross-compiling from POSIX to Windows using MinGW, HAVE_SLEEP - * will often be defined by configure although it is not supported by - * MinGW. So substitute the sleep definition below in such a case and - * when compiling on Windows using MinGW where HAVE_SLEEP will be - * undefined. - * - * FIXME: Needs better handling for all versions of MinGW. - * - */ -#if (defined(HAVE_SSLEEP) || defined(_WIN32)) && (!defined(HAVE_SLEEP)) -# include "hl_sleep.h" -#endif - #include "ampctl_parse.h" /* Hash table implementation See: http://uthash.sourceforge.net/ */ diff --git a/tests/rigctl_parse.c b/tests/rigctl_parse.c index 0fcb0af95..891d2fd72 100644 --- a/tests/rigctl_parse.c +++ b/tests/rigctl_parse.c @@ -68,23 +68,6 @@ extern int read_history(); #include "serial.h" #include "sprintflst.h" -/* HAVE_SSLEEP is defined when Windows Sleep is found - * HAVE_SLEEP is defined when POSIX sleep is found - * _WIN32 is defined when compiling with MinGW - * - * When cross-compiling from POSIX to Windows using MinGW, HAVE_SLEEP - * will often be defined by configure although it is not supported by - * MinGW. So substitute the sleep definition below in such a case and - * when compiling on Windows using MinGW where HAVE_SLEEP will be - * undefined. - * - * FIXME: Needs better handling for all versions of MinGW. - * - */ -#if (defined(HAVE_SSLEEP) || defined(_WIN32)) && (!defined(HAVE_SLEEP)) -# include "hl_sleep.h" -#endif - #include "rigctl_parse.h" /* Hash table implementation See: http://uthash.sourceforge.net/ */ diff --git a/tests/testrig.c b/tests/testrig.c index 678583220..a1c123787 100644 --- a/tests/testrig.c +++ b/tests/testrig.c @@ -15,23 +15,6 @@ # include "config.h" #endif -/* HAVE_SSLEEP is defined when Windows Sleep is found - * HAVE_SLEEP is defined when POSIX sleep is found - * _WIN32 is defined when compiling with MinGW - * - * When cross-compiling from POSIX to Windows using MinGW, HAVE_SLEEP - * will often be defined by configure although it is not supported by - * MinGW. So substitute the sleep definition below in such a case and - * when compiling on Windows using MinGW where HAVE_SLEEP will be - * undefined. - * - * FIXME: Needs better handling for all versions of MinGW. - * - */ -#if (defined(HAVE_SSLEEP) || defined(_WIN32)) && (!defined(HAVE_SLEEP)) -# include "hl_sleep.h" -#endif - #define SERIAL_PORT "/dev/ttyS0" diff --git a/tests/testtrn.c b/tests/testtrn.c index 2d8dc9ae0..5e96a0b5e 100644 --- a/tests/testtrn.c +++ b/tests/testtrn.c @@ -13,23 +13,6 @@ # include "config.h" #endif -/* HAVE_SSLEEP is defined when Windows Sleep is found - * HAVE_SLEEP is defined when POSIX sleep is found - * _WIN32 is defined when compiling with MinGW - * - * When cross-compiling from POSIX to Windows using MinGW, HAVE_SLEEP - * will often be defined by configure although it is not supported by - * MinGW. So substitute the sleep definition below in such a case and - * when compiling on Windows using MinGW where HAVE_SLEEP will be - * undefined. - * - * FIXME: Needs better handling for all versions of MinGW. - * - */ -#if (defined(HAVE_SSLEEP) || defined(_WIN32)) && (!defined(HAVE_SLEEP)) -# include "hl_sleep.h" -#endif - #define SERIAL_PORT "/dev/ttyS0" From 4dbe66193c21f083490b76c85f574b3a9ae119c3 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Tue, 24 Dec 2019 15:24:01 -0600 Subject: [PATCH 193/205] fix cppcheck warnings in sprintflst.c --- tests/sprintflst.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/sprintflst.c b/tests/sprintflst.c index d7e69494d..6e81640cd 100644 --- a/tests/sprintflst.c +++ b/tests/sprintflst.c @@ -44,7 +44,6 @@ int sprintf_vfo(char *str, vfo_t vfo) { int i, len = 0; - const char *sv; *str = '\0'; @@ -55,6 +54,7 @@ int sprintf_vfo(char *str, vfo_t vfo) for (i = 0; i < 32; i++) { + const char *sv; sv = rig_strvfo(vfo & RIG_VFO_N(i)); if (sv && sv[0]) From 72e934b67e11993c70ad53bfa572b2e05f775fda Mon Sep 17 00:00:00 2001 From: Michael Black Date: Tue, 24 Dec 2019 15:35:37 -0600 Subject: [PATCH 194/205] Fix mingw32 compilation of usb_port.c --- src/usb_port.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/usb_port.c b/src/usb_port.c index 4d2fac222..f0c259212 100644 --- a/src/usb_port.c +++ b/src/usb_port.c @@ -35,10 +35,6 @@ # include "config.h" #endif -/* - * Compile only if libusb is available - */ -#if defined(HAVE_LIBUSB) && (defined(HAVE_LIBUSB_H) || defined(HAVE_LIBUSB_1_0_LIBUSB_H)) #include @@ -58,6 +54,10 @@ #include "usb_port.h" +/* + * Compile only if libusb is available + */ +#if defined(HAVE_LIBUSB) && (defined(HAVE_LIBUSB_H) || defined(HAVE_LIBUSB_1_0_LIBUSB_H)) /** * \brief Find and open USB device From 520066e3e73b0e85363c009f8225e82e6ee95902 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Tue, 24 Dec 2019 15:41:57 -0600 Subject: [PATCH 195/205] Fix cppcheck warnings in rigctlcom.c --- tests/rigctlcom.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/rigctlcom.c b/tests/rigctlcom.c index b23724787..0cd6d4c8b 100644 --- a/tests/rigctlcom.c +++ b/tests/rigctlcom.c @@ -713,8 +713,8 @@ static int handle_ts2000(void *arg) int p13 = 0; // P13 Tone dummy value for now int p14 = 0; // P14 Tone Freq dummy value for now int p15 = 0; // P15 Shift status dummy value for now - char response[64]; int retval = rig_get_freq(my_rig, RIG_VFO_A, &freq); + char response[64]; if (retval != RIG_OK) { From 6fe29ad942852478fc4f8bf5af7102ddfe899608 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Tue, 24 Dec 2019 15:47:06 -0600 Subject: [PATCH 196/205] Fix cppcheck warnings in rig.c --- src/rig.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/rig.c b/src/rig.c index a36faa9ef..3d7ab0b9e 100644 --- a/src/rig.c +++ b/src/rig.c @@ -4400,7 +4400,8 @@ const freq_range_t *HAMLIB_API rig_get_range(const freq_range_t range_list[], if (freq >= range_list[i].startf && freq <= range_list[i].endf && (range_list[i].modes & mode)) { - return &range_list[i]; + const freq_range_t *f = &range_list[i]; + return f; } } From 4e5e53324874873e4c70104f8c004521c4964b22 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Tue, 24 Dec 2019 15:48:36 -0600 Subject: [PATCH 197/205] Fix cppcheck warnings --- tests/rigctl.c | 2 + tests/rigctld.c | 1095 ------------------------------------------ tests/rotctl_parse.c | 6 +- 3 files changed, 6 insertions(+), 1097 deletions(-) delete mode 100644 tests/rigctld.c diff --git a/tests/rigctl.c b/tests/rigctl.c index dd3a7ae59..f64ec7e52 100644 --- a/tests/rigctl.c +++ b/tests/rigctl.c @@ -121,6 +121,8 @@ static struct option long_options[] = /* variable for readline support */ #ifdef HAVE_LIBREADLINE static const int have_rl = 1; +#else +static const int have_rl = 0; #endif diff --git a/tests/rigctld.c b/tests/rigctld.c deleted file mode 100644 index 8d5dc2962..000000000 --- a/tests/rigctld.c +++ /dev/null @@ -1,1095 +0,0 @@ -/* - * rigctld.c - (C) Stephane Fillod 2000-2011 - * (C) Nate Bargmann 2008,2010,2011,2012,2013 - * (C) The Hamlib Group 2012 - * - * This program test/control a radio using Hamlib. - * It takes commands from network connection. - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#ifdef WIN32 -#define WIN32_LEAN_AND_MEAN -#include -#endif - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include /* See NOTES */ - -#ifdef HAVE_NETINET_IN_H -# include -#endif - -#ifdef HAVE_ARPA_INET_H -# include -#endif - -#ifdef HAVE_SYS_SOCKET_H -# include -#elif HAVE_WS2TCPIP_H -# include -# include -# if defined(HAVE_WSPIAPI_H) -# include -# endif -#endif - -#ifdef HAVE_NETDB_H -# include -#endif - -#ifdef HAVE_PTHREAD -# include -#endif - -#include -#include "misc.h" -#include "iofunc.h" -#include "serial.h" -#include "sprintflst.h" - -#include "rigctl_parse.h" - - -/* - * Reminder: when adding long options, - * keep up to date SHORT_OPTIONS, usage()'s output and man page. thanks. - * NB: do NOT use -W since it's reserved by POSIX. - * TODO: add an option to read from a file - */ -#define SHORT_OPTIONS "m:r:p:d:P:D:s:c:T:t:C:lLuovhVZ" -static struct option long_options[] = -{ - {"model", 1, 0, 'm'}, - {"rig-file", 1, 0, 'r'}, - {"ptt-file", 1, 0, 'p'}, - {"dcd-file", 1, 0, 'd'}, - {"ptt-type", 1, 0, 'P'}, - {"dcd-type", 1, 0, 'D'}, - {"serial-speed", 1, 0, 's'}, - {"civaddr", 1, 0, 'c'}, - {"listen-addr", 1, 0, 'T'}, - {"port", 1, 0, 't'}, - {"set-conf", 1, 0, 'C'}, - {"list", 0, 0, 'l'}, - {"show-conf", 0, 0, 'L'}, - {"dump-caps", 0, 0, 'u'}, - {"vfo", 0, 0, 'o'}, - {"verbose", 0, 0, 'v'}, - {"help", 0, 0, 'h'}, - {"version", 0, 0, 'V'}, - {"debug-time-stamps", 0, 0, 'Z'}, - {0, 0, 0, 0} -}; - - -struct handle_data -{ - RIG *rig; - int sock; - struct sockaddr_storage cli_addr; - socklen_t clilen; - int vfo_mode; -}; - - -void *handle_socket(void *arg); -void usage(void); - - -#ifdef HAVE_PTHREAD -static unsigned client_count; -#endif - -static RIG *my_rig; /* handle to rig (instance) */ -static int verbose; - -#ifdef HAVE_SIG_ATOMIC_T -static sig_atomic_t volatile ctrl_c; -#else -static int volatile ctrl_c; -#endif - -const char *portno = "4532"; -const char *src_addr = NULL; /* INADDR_ANY */ - -#define MAXCONFLEN 128 - -static void sync_callback(int lock) -{ -#ifdef HAVE_PTHREAD - static pthread_mutex_t client_lock = PTHREAD_MUTEX_INITIALIZER; - - if (lock) - { - pthread_mutex_lock(&client_lock); - rig_debug(RIG_DEBUG_VERBOSE, "%s: client lock engaged\n", __func__); - } - else - { - rig_debug(RIG_DEBUG_VERBOSE, "%s: client lock disengaged\n", __func__); - pthread_mutex_unlock(&client_lock); - } - -#endif -} - -#ifdef WIN32 -static BOOL WINAPI CtrlHandler(DWORD fdwCtrlType) -{ - rig_debug(RIG_DEBUG_VERBOSE, "%s: called\n", __func__); - - switch (fdwCtrlType) - { - case CTRL_C_EVENT: - case CTRL_CLOSE_EVENT: - ctrl_c = 1; - return TRUE; - - default: - return FALSE; - } -} -#else -static void signal_handler(int sig) -{ - switch (sig) - { - case SIGINT: - ctrl_c = 1; - break; - - default: - /* do nothing */ - break; - } -} -#endif - -static void handle_error(enum rig_debug_level_e lvl, const char *msg) -{ - int e; -#ifdef __MINGW32__ - LPVOID lpMsgBuf; - - lpMsgBuf = (LPVOID)"Unknown error"; - e = WSAGetLastError(); - - if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER - | FORMAT_MESSAGE_FROM_SYSTEM - | FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, e, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - // Default language - (LPTSTR)&lpMsgBuf, 0, NULL)) - { - - rig_debug(lvl, "%s: Network error %d: %s\n", msg, e, (char *)lpMsgBuf); - LocalFree(lpMsgBuf); - } - else - { - rig_debug(lvl, "%s: Network error %d\n", msg, e); - } - -#else - e = errno; - rig_debug(lvl, "%s: Network error %d: %s\n", msg, e, strerror(e)); -#endif -} - - -int main(int argc, char *argv[]) -{ - rig_model_t my_model = RIG_MODEL_DUMMY; - - int retcode; /* generic return code from functions */ - - int show_conf = 0; - int dump_caps_opt = 0; - const char *rig_file = NULL, *ptt_file = NULL, *dcd_file = NULL; - ptt_type_t ptt_type = RIG_PTT_NONE; - dcd_type_t dcd_type = RIG_DCD_NONE; - int serial_rate = 0; - char *civaddr = NULL; /* NULL means no need to set conf */ - char conf_parms[MAXCONFLEN] = ""; - - struct addrinfo hints, *result, *saved_result; - int sock_listen; - int sockopt; - int reuseaddr = 1; - char host[NI_MAXHOST]; - char serv[NI_MAXSERV]; -#if HAVE_SIGACTION - struct sigaction act; -#endif - -#ifdef HAVE_PTHREAD - pthread_t thread; - pthread_attr_t attr; -#endif - struct handle_data *arg; - int vfo_mode = 0; /* vfo_mode=0 means target VFO is current VFO */ - - while (1) - { - int c; - int option_index = 0; - - c = getopt_long(argc, - argv, - SHORT_OPTIONS, - long_options, - &option_index); - - if (c == -1) - { - break; - } - - switch (c) - { - case 'h': - usage(); - exit(0); - - case 'V': - version(); - exit(0); - - case 'm': - if (!optarg) - { - usage(); /* wrong arg count */ - exit(1); - } - - my_model = atoi(optarg); - break; - - case 'r': - if (!optarg) - { - usage(); /* wrong arg count */ - exit(1); - } - - rig_file = optarg; - break; - - case 'p': - if (!optarg) - { - usage(); /* wrong arg count */ - exit(1); - } - - ptt_file = optarg; - break; - - case 'd': - if (!optarg) - { - usage(); /* wrong arg count */ - exit(1); - } - - dcd_file = optarg; - break; - - case 'P': - if (!optarg) - { - usage(); /* wrong arg count */ - exit(1); - } - - if (!strcmp(optarg, "RIG")) - { - ptt_type = RIG_PTT_RIG; - } - else if (!strcmp(optarg, "DTR")) - { - ptt_type = RIG_PTT_SERIAL_DTR; - } - else if (!strcmp(optarg, "RTS")) - { - ptt_type = RIG_PTT_SERIAL_RTS; - } - else if (!strcmp(optarg, "PARALLEL")) - { - ptt_type = RIG_PTT_PARALLEL; - } - else if (!strcmp(optarg, "CM108")) - { - ptt_type = RIG_PTT_CM108; - } - else if (!strcmp(optarg, "NONE")) - { - ptt_type = RIG_PTT_NONE; - } - else - { - ptt_type = atoi(optarg); - } - - break; - - case 'D': - if (!optarg) - { - usage(); /* wrong arg count */ - exit(1); - } - - if (!strcmp(optarg, "RIG")) - { - dcd_type = RIG_DCD_RIG; - } - else if (!strcmp(optarg, "DSR")) - { - dcd_type = RIG_DCD_SERIAL_DSR; - } - else if (!strcmp(optarg, "CTS")) - { - dcd_type = RIG_DCD_SERIAL_CTS; - } - else if (!strcmp(optarg, "CD")) - { - dcd_type = RIG_DCD_SERIAL_CAR; - } - else if (!strcmp(optarg, "PARALLEL")) - { - dcd_type = RIG_DCD_PARALLEL; - } - else if (!strcmp(optarg, "NONE")) - { - dcd_type = RIG_DCD_NONE; - } - else - { - dcd_type = atoi(optarg); - } - - break; - - case 'c': - if (!optarg) - { - usage(); /* wrong arg count */ - exit(1); - } - - civaddr = optarg; - break; - - case 's': - if (!optarg) - { - usage(); /* wrong arg count */ - exit(1); - } - - serial_rate = atoi(optarg); - break; - - case 'C': - if (!optarg) - { - usage(); /* wrong arg count */ - exit(1); - } - - if (*conf_parms != '\0') - { - strcat(conf_parms, ","); - } - - strncat(conf_parms, optarg, MAXCONFLEN - strlen(conf_parms)); - break; - - case 't': - if (!optarg) - { - usage(); /* wrong arg count */ - exit(1); - } - - portno = optarg; - break; - - case 'T': - if (!optarg) - { - usage(); /* wrong arg count */ - exit(1); - } - - src_addr = optarg; - break; - - case 'o': - vfo_mode++; - break; - - case 'v': - verbose++; - break; - - case 'L': - show_conf++; - break; - - case 'l': - list_models(); - exit(0); - - case 'u': - dump_caps_opt++; - break; - - case 'Z': - rig_set_debug_time_stamp(1); - break; - - default: - usage(); /* unknown option? */ - exit(1); - } - } - - if (!vfo_mode) - { - printf("Recommend using --vfo switch for rigctld\n"); - printf("rigctl and netrigctl will automatically detect vfo mode\n"); - } - - rig_set_debug(verbose); - - rig_debug(RIG_DEBUG_VERBOSE, "rigctld, %s\n", hamlib_version); - rig_debug(RIG_DEBUG_VERBOSE, "%s", - "Report bugs to \n\n"); - - my_rig = rig_init(my_model); - - if (!my_rig) - { - fprintf(stderr, - "Unknown rig num %d, or initialization error.\n", - my_model); - - fprintf(stderr, "Please check with --list option.\n"); - exit(2); - } - - retcode = set_conf(my_rig, conf_parms); - - if (retcode != RIG_OK) - { - fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode)); - exit(2); - } - - if (rig_file) - { - strncpy(my_rig->state.rigport.pathname, rig_file, FILPATHLEN - 1); - } - - /* - * ex: RIG_PTT_PARALLEL and /dev/parport0 - */ - if (ptt_type != RIG_PTT_NONE) - { - my_rig->state.pttport.type.ptt = ptt_type; - } - - if (dcd_type != RIG_DCD_NONE) - { - my_rig->state.dcdport.type.dcd = dcd_type; - } - - if (ptt_file) - { - strncpy(my_rig->state.pttport.pathname, ptt_file, FILPATHLEN - 1); - } - - if (dcd_file) - { - strncpy(my_rig->state.dcdport.pathname, dcd_file, FILPATHLEN - 1); - } - - /* FIXME: bound checking and port type == serial */ - if (serial_rate != 0) - { - my_rig->state.rigport.parm.serial.rate = serial_rate; - } - - if (civaddr) - { - rig_set_conf(my_rig, rig_token_lookup(my_rig, "civaddr"), civaddr); - } - - /* - * print out conf parameters - */ - if (show_conf) - { - rig_token_foreach(my_rig, print_conf_list, (rig_ptr_t)my_rig); - } - - /* - * print out conf parameters, and exits immediately - * We may be interested only in only caps, and rig_open may fail. - */ - if (dump_caps_opt) - { - dumpcaps(my_rig, stdout); - rig_cleanup(my_rig); /* if you care about memory */ - exit(0); - } - - /* open and close rig connection to check early for issues */ - retcode = rig_open(my_rig); - - if (retcode != RIG_OK) - { - fprintf(stderr, "rig_open: error = %s \n", rigerror(retcode)); - exit(2); - } - - if (verbose > RIG_DEBUG_ERR) - { - printf("Opened rig model %d, '%s'\n", - my_rig->caps->rig_model, - my_rig->caps->model_name); - } - - rig_debug(RIG_DEBUG_VERBOSE, "Backend version: %s, Status: %s\n", - my_rig->caps->version, rig_strstatus(my_rig->caps->status)); - - rig_close(my_rig); /* we will reopen for clients */ - - if (verbose > RIG_DEBUG_ERR) - { - printf("Closed rig model %d, '%s - will reopen for clients'\n", - my_rig->caps->rig_model, - my_rig->caps->model_name); - } - -#ifdef __MINGW32__ -# ifndef SO_OPENTYPE -# define SO_OPENTYPE 0x7008 -# endif -# ifndef SO_SYNCHRONOUS_NONALERT -# define SO_SYNCHRONOUS_NONALERT 0x20 -# endif -# ifndef INVALID_SOCKET -# define INVALID_SOCKET -1 -# endif - - WSADATA wsadata; - - if (WSAStartup(MAKEWORD(1, 1), &wsadata) == SOCKET_ERROR) - { - fprintf(stderr, "WSAStartup socket error\n"); - exit(1); - } - - sockopt = SO_SYNCHRONOUS_NONALERT; - setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE, (char *)&sockopt, - sizeof(sockopt)); -#endif - - /* - * Prepare listening socket - */ - memset(&hints, 0, sizeof(struct addrinfo)); - hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */ - hints.ai_socktype = SOCK_STREAM;/* TCP socket */ - hints.ai_flags = AI_PASSIVE; /* For wildcard IP address */ - hints.ai_protocol = 0; /* Any protocol */ - - retcode = getaddrinfo(src_addr, portno, &hints, &result); - - if (retcode != 0) - { - fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(retcode)); - exit(2); - } - - saved_result = result; - - do - { - sock_listen = socket(result->ai_family, - result->ai_socktype, - result->ai_protocol); - - if (sock_listen < 0) - { - handle_error(RIG_DEBUG_ERR, "socket"); - freeaddrinfo(saved_result); /* No longer needed */ - exit(2); - } - - if (setsockopt(sock_listen, - SOL_SOCKET, - SO_REUSEADDR, - (char *)&reuseaddr, - sizeof(reuseaddr)) - < 0) - { - - handle_error(RIG_DEBUG_ERR, "setsockopt"); - freeaddrinfo(saved_result); /* No longer needed */ - exit(1); - } - -#ifdef IPV6_V6ONLY - - if (AF_INET6 == result->ai_family) - { - /* allow IPv4 mapped to IPv6 clients Windows and BSD default - this to 1 (i.e. disallowed) and we prefer it off */ - sockopt = 0; - - if (setsockopt(sock_listen, - IPPROTO_IPV6, - IPV6_V6ONLY, - (char *)&sockopt, - sizeof(sockopt)) - < 0) - { - - handle_error(RIG_DEBUG_ERR, "setsockopt"); - freeaddrinfo(saved_result); /* No longer needed */ - exit(1); - } - } - -#endif - - if (0 == bind(sock_listen, result->ai_addr, result->ai_addrlen)) - { - break; - } - - handle_error(RIG_DEBUG_WARN, "binding failed (trying next interface)"); -#ifdef __MINGW32__ - closesocket(sock_listen); -#else - close(sock_listen); -#endif - } - while ((result = result->ai_next) != NULL); - - freeaddrinfo(saved_result); /* No longer needed */ - - if (NULL == result) - { - rig_debug(RIG_DEBUG_ERR, "%s: bind error - no available interface\n", __func__); - exit(1); - } - - if (listen(sock_listen, 4) < 0) - { - handle_error(RIG_DEBUG_ERR, "listening"); - exit(1); - } - -#if HAVE_SIGACTION - -#ifdef SIGPIPE - /* Ignore SIGPIPE as we will handle it at the write()/send() calls - that will consequently fail with EPIPE. All child threads will - inherit this disposition which is what we want. */ - memset(&act, 0, sizeof act); - act.sa_handler = SIG_IGN; - act.sa_flags = SA_RESTART; - - if (sigaction(SIGPIPE, &act, NULL)) - { - handle_error(RIG_DEBUG_ERR, "sigaction SIGPIPE"); - } - -#endif - -#ifdef SIGINT - memset(&act, 0, sizeof act); - act.sa_handler = signal_handler; - - if (sigaction(SIGINT, &act, NULL)) - { - handle_error(RIG_DEBUG_ERR, "sigaction SIGINT"); - } - -#endif -#elif defined (WIN32) - - if (!SetConsoleCtrlHandler(CtrlHandler, TRUE)) - { - handle_error(RIG_DEBUG_ERR, "SetConsoleCtrlHandler"); - } - -#elif HAVE_SIGNAL -#ifdef SIGPIPE - - if (SIG_ERR == signal(SIGPIPE, SIG_IGN)) - { - handle_error(RIG_DEBUG_ERR, "signal SIGPIPE"); - } - -#endif -#ifdef SIGINT - - if (SIG_ERR == signal(SIGINT, signal_handler)) - { - handle_error(RIG_DEBUG_ERR, "signal SIGINT"); - } - -#endif -#endif - - /* - * main loop accepting connections - */ - do - { - fd_set set; - struct timeval timeout; - - arg = malloc(sizeof(struct handle_data)); - - if (!arg) - { - rig_debug(RIG_DEBUG_ERR, "malloc: %s\n", strerror(errno)); - exit(1); - } - - /* use select to allow for periodic checks for CTRL+C */ - FD_ZERO(&set); - FD_SET(sock_listen, &set); - timeout.tv_sec = 5; - timeout.tv_usec = 0; - retcode = select(sock_listen + 1, &set, NULL, NULL, &timeout); - - if (-1 == retcode) - { - rig_debug(RIG_DEBUG_ERR, "%s: select\n", __func__); - } - else if (!retcode) - { - if (ctrl_c) - { - break; - } - } - else - { - arg->rig = my_rig; - arg->clilen = sizeof(arg->cli_addr); - arg->vfo_mode = vfo_mode; - arg->sock = accept(sock_listen, - (struct sockaddr *)&arg->cli_addr, - &arg->clilen); - - if (arg->sock < 0) - { - handle_error(RIG_DEBUG_ERR, "accept"); - break; - } - - if ((retcode = getnameinfo((struct sockaddr const *)&arg->cli_addr, - arg->clilen, - host, - sizeof(host), - serv, - sizeof(serv), - NI_NOFQDN)) - < 0) - { - rig_debug(RIG_DEBUG_WARN, - "Peer lookup error: %s", - gai_strerror(retcode)); - } - - rig_debug(RIG_DEBUG_VERBOSE, - "Connection opened from %s:%s\n", - host, - serv); - -#ifdef HAVE_PTHREAD - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - - retcode = pthread_create(&thread, &attr, handle_socket, arg); - - if (retcode != 0) - { - rig_debug(RIG_DEBUG_ERR, "pthread_create: %s\n", strerror(retcode)); - break; - } - -#else - handle_socket(arg); -#endif - } - } - while (retcode == 0 && !ctrl_c); - -#ifdef HAVE_PTHREAD - /* allow threads to finish current action */ - sync_callback(1); - - if (client_count) - { - rig_debug(RIG_DEBUG_WARN, "%d outstanding client(s)\n", client_count); - } - - rig_close(my_rig); - sync_callback(0); -#else - rig_close(my_rig); /* close port */ -#endif - rig_cleanup(my_rig); /* if you care about memory */ - -#ifdef __MINGW32__ - WSACleanup(); -#endif - - return 0; -} - - -/* - * This is the function run by the threads - */ -void *handle_socket(void *arg) -{ - struct handle_data *handle_data_arg = (struct handle_data *)arg; - FILE *fsockin = NULL; - FILE *fsockout = NULL; - int retcode = RIG_OK; - char host[NI_MAXHOST]; - char serv[NI_MAXSERV]; - char send_cmd_term = '\r'; /* send_cmd termination char */ - int ext_resp = 0; - char resp_sep = '\n'; - -#ifdef __MINGW32__ - int sock_osfhandle = _open_osfhandle(handle_data_arg->sock, _O_RDONLY); - - if (sock_osfhandle == -1) - { - rig_debug(RIG_DEBUG_ERR, "_open_osfhandle error: %s\n", strerror(errno)); - goto handle_exit; - } - - fsockin = _fdopen(sock_osfhandle, "rb"); -#else - fsockin = fdopen(handle_data_arg->sock, "rb"); -#endif - - if (!fsockin) - { - rig_debug(RIG_DEBUG_ERR, "fdopen in: %s\n", strerror(errno)); - goto handle_exit; - } - -#ifdef __MINGW32__ - fsockout = _fdopen(sock_osfhandle, "wb"); -#else - fsockout = fdopen(handle_data_arg->sock, "wb"); -#endif - - if (!fsockout) - { - rig_debug(RIG_DEBUG_ERR, "fdopen out: %s\n", strerror(errno)); - fclose(fsockin); - - goto handle_exit; - } - -#ifdef HAVE_PTHREAD - sync_callback(1); - - if (!client_count++) - { - retcode = rig_open(my_rig); - - if (RIG_OK == retcode && verbose > RIG_DEBUG_ERR) - { - printf("Opened rig model %d, '%s'\n", - my_rig->caps->rig_model, - my_rig->caps->model_name); - } - } - - sync_callback(0); -#else - retcode = rig_open(my_rig); - - if (RIG_OK == retcode && verbose > RIG_DEBUG_ERR) - { - printf("Opened rig model %d, '%s'\n", - my_rig->caps->rig_model, - my_rig->caps->model_name); - } - -#endif - - do - { - retcode = rigctl_parse(handle_data_arg->rig, fsockin, fsockout, NULL, 0, - sync_callback, - 1, 0, handle_data_arg->vfo_mode, send_cmd_term, &ext_resp, &resp_sep); - - if (ferror(fsockin) || ferror(fsockout)) - { - retcode = 1; - } - - if (retcode == 1) - { - retcode = rig_open(my_rig); - } - } - while (retcode == 0 || retcode == 2 || retcode == -RIG_ENAVAIL); - -#ifdef HAVE_PTHREAD - sync_callback(1); - - /* Release rig if there are no clients */ - if (!--client_count) - { - rig_close(my_rig); - - if (verbose > RIG_DEBUG_ERR) - { - printf("Closed rig model %d, '%s - no clients, will reopen for new clients'\n", - my_rig->caps->rig_model, - my_rig->caps->model_name); - } - } - - sync_callback(0); -#else - rig_close(my_rig); - - if (verbose > RIG_DEBUG_ERR) - { - printf("Closed rig model %d, '%s - will reopen for new clients'\n", - my_rig->caps->rig_model, - my_rig->caps->model_name); - } - -#endif - - if ((retcode = getnameinfo((struct sockaddr const *)&handle_data_arg->cli_addr, - handle_data_arg->clilen, - host, - sizeof(host), - serv, - sizeof(serv), - NI_NOFQDN)) - < 0) - { - - rig_debug(RIG_DEBUG_WARN, "Peer lookup error: %s", gai_strerror(retcode)); - } - - rig_debug(RIG_DEBUG_VERBOSE, - "Connection closed from %s:%s\n", - host, - serv); - -handle_exit: - -// for MINGW we close the handle before fclose -#ifdef __MINGW32__ - retcode = closesocket(handle_data_arg->sock); - - if (retcode != 0) { rig_debug(RIG_DEBUG_ERR, "%s: fclose(fsockin) %s\n", __func__, strerror(retcode)); } - -#endif - fclose(fsockin); - fclose(fsockout); - -// for everybody else we close the handle after fclose -#ifndef __MINGW32__ - retcode = close(handle_data_arg->sock); - - if (retcode != 0) { rig_debug(RIG_DEBUG_ERR, "%s: close(handle_data_arg->sock) %s\n", __func__, strerror(retcode)); } - -#endif - - free(arg); - -#ifdef HAVE_PTHREAD - pthread_exit(NULL); -#endif - return NULL; -} - - -void usage(void) -{ - printf("Usage: rigctld [OPTION]...\n" - "Daemon serving COMMANDs to a connected radio transceiver or receiver.\n\n"); - - - printf( - " -m, --model=ID select radio model number. See model list\n" - " -r, --rig-file=DEVICE set device of the radio to operate on\n" - " -p, --ptt-file=DEVICE set device of the PTT device to operate on\n" - " -d, --dcd-file=DEVICE set device of the DCD device to operate on\n" - " -P, --ptt-type=TYPE set type of the PTT device to operate on\n" - " -D, --dcd-type=TYPE set type of the DCD device to operate on\n" - " -s, --serial-speed=BAUD set serial speed of the serial port\n" - " -c, --civaddr=ID set CI-V address, decimal (for Icom rigs only)\n" - " -t, --port=NUM set TCP listening port, default %s\n" - " -T, --listen-addr=IPADDR set listening IP address, default ANY\n" - " -C, --set-conf=PARM=VAL set config parameters\n" - " -L, --show-conf list all config parameters\n" - " -l, --list list all model numbers and exit\n" - " -u, --dump-caps dump capabilities and exit\n" - " -o, --vfo do not default to VFO_CURR, require extra vfo arg\n" - " -v, --verbose set verbose mode, cumulative (-v to -vvvvv)\n" - " -Z, --debug-time-stamps enable time stamps for debug messages\n" - " -h, --help display this help and exit\n" - " -V, --version output version information and exit\n\n", - portno); - - usage_rig(stdout); - - printf("\nReport bugs to .\n"); - -} diff --git a/tests/rotctl_parse.c b/tests/rotctl_parse.c index f042ee411..20aea85ee 100644 --- a/tests/rotctl_parse.c +++ b/tests/rotctl_parse.c @@ -1448,9 +1448,11 @@ int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc, } else { - if (cmd_entry != NULL && cmd_entry->name != NULL) + if (cmd_entry != NULL) { - fprintf(fout, "%s: error = %s\n", cmd_entry->name, rigerror(retcode)); + if (cmd_entry->name != NULL) { + fprintf(fout, "%s: error = %s\n", cmd_entry->name, rigerror(retcode)); + } } } } From 310d7efe0d11d1a6699b7201f00d95ccef3bf7bf Mon Sep 17 00:00:00 2001 From: Michael Black Date: Tue, 24 Dec 2019 23:15:09 -0600 Subject: [PATCH 198/205] Fix cppcheck warnings in adat.c --- adat/adat.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/adat/adat.c b/adat/adat.c index 6b22cc7dc..25a1b68ad 100644 --- a/adat/adat.c +++ b/adat/adat.c @@ -2572,6 +2572,11 @@ int adat_transaction(RIG *pRig, nRC = adat_receive(pRig, acBuf); } + if (pPriv->pcResult != NULL) + { + free(pPriv->pcResult); + } + pPriv->pcResult = strdup(acBuf); } } @@ -3515,6 +3520,7 @@ int adat_set_conf(RIG *pRig, token_t token, const char *val) switch (token) { case TOKEN_ADAT_PRODUCT_NAME: + if (pPriv->pcProductName != NULL) free(pPriv->pcProductName); pPriv->pcProductName = strdup(val); break; From c5a6dccc27944785e7f889f08692220446542ff0 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Tue, 24 Dec 2019 23:17:52 -0600 Subject: [PATCH 199/205] Fix cppcheck warning in kpa.h --- amplifiers/elecraft/kpa.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/amplifiers/elecraft/kpa.h b/amplifiers/elecraft/kpa.h index e8e7a1689..c4169ea93 100644 --- a/amplifiers/elecraft/kpa.h +++ b/amplifiers/elecraft/kpa.h @@ -47,7 +47,7 @@ struct kpa_priv_data int kpa_init(AMP *amp); int kpa_reset(AMP *amp, amp_reset_t reset); int kpa_flush_buffer(AMP *amp); -int kpa_transaction(AMP *amp, const char *cmd, char *reponse, int reponse_len); +int kpa_transaction(AMP *amp, const char *cmd, char *response, int response_len); const char *kpa_get_info (AMP *amp); int kpa_get_freq (AMP *amp, freq_t *freq); int kpa_set_freq (AMP *amp, freq_t freq); From 5ce7169cbf32f5b80a1eb824ac1ed15ff1fc423a Mon Sep 17 00:00:00 2001 From: Michael Black Date: Tue, 24 Dec 2019 23:25:08 -0600 Subject: [PATCH 200/205] Fix cppcheck warning in ar7030p_utils.c --- aor/ar7030p_utils.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/aor/ar7030p_utils.c b/aor/ar7030p_utils.c index 16ef54532..8b66e7197 100644 --- a/aor/ar7030p_utils.c +++ b/aor/ar7030p_utils.c @@ -458,14 +458,10 @@ static int setAddr(RIG *rig, enum PAGE_e page, unsigned int addr) { v = SRH((0x0f0 & addr) >> 4); - if (0 == write_block(&rig->state.rigport, (char *) &v, 1)) + rc = write_block(&rig->state.rigport, (char *) &v, 1); + if (rc != RIG_OK) { - rc = RIG_OK; - } - else - { - rc = -RIG_EIO; - return rc; + return -RIG_EIO; } v = ADR((0x00f & addr)); From 59194c975ab1a714efa2a80f1bdcd8be7262651f Mon Sep 17 00:00:00 2001 From: Michael Black Date: Tue, 24 Dec 2019 23:26:48 -0600 Subject: [PATCH 201/205] Fix cppcheck warning in ars.c --- ars/ars.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ars/ars.c b/ars/ars.c index dc58ba8c6..5af7f9eca 100644 --- a/ars/ars.c +++ b/ars/ars.c @@ -437,7 +437,7 @@ static void *handle_set_position(void *arg) if (!priv->set_pos_active) { /* TODO: replace polling period by cond var */ - usleep(100 * 1000); + usleep(100 * 1000 - 1); continue; } From 7c1ef0f6ca6f745e6c7e79fabe16d5394162c2fe Mon Sep 17 00:00:00 2001 From: Michael Black Date: Tue, 24 Dec 2019 23:28:19 -0600 Subject: [PATCH 202/205] Fix cppcheck warning in alinco.c --- alinco/alinco.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/alinco/alinco.c b/alinco/alinco.c index b6996183b..5175e1200 100644 --- a/alinco/alinco.c +++ b/alinco/alinco.c @@ -815,6 +815,7 @@ int alinco_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) return alinco_transaction(rig, cmdbuf, cmd_len, NULL, NULL); case RIG_LEVEL_CWPITCH: + lvl = 4; if (val.i < 426) { lvl = 5; @@ -867,10 +868,6 @@ int alinco_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) { lvl = 4; } - else - { - lvl = 4; - } cmd_len = sprintf(cmdbuf, AL CMD_SDATA "M%02d" EOM, lvl); From c8eaf13a3d346e6dbab9c3c5d43b6b25ffa2fb48 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Wed, 25 Dec 2019 07:58:19 -0600 Subject: [PATCH 203/205] Readding rigctld.c accidental removal --- tests/rigctld.c | 1095 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1095 insertions(+) create mode 100644 tests/rigctld.c diff --git a/tests/rigctld.c b/tests/rigctld.c new file mode 100644 index 000000000..8d5dc2962 --- /dev/null +++ b/tests/rigctld.c @@ -0,0 +1,1095 @@ +/* + * rigctld.c - (C) Stephane Fillod 2000-2011 + * (C) Nate Bargmann 2008,2010,2011,2012,2013 + * (C) The Hamlib Group 2012 + * + * This program test/control a radio using Hamlib. + * It takes commands from network connection. + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#ifdef WIN32 +#define WIN32_LEAN_AND_MEAN +#include +#endif + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include /* See NOTES */ + +#ifdef HAVE_NETINET_IN_H +# include +#endif + +#ifdef HAVE_ARPA_INET_H +# include +#endif + +#ifdef HAVE_SYS_SOCKET_H +# include +#elif HAVE_WS2TCPIP_H +# include +# include +# if defined(HAVE_WSPIAPI_H) +# include +# endif +#endif + +#ifdef HAVE_NETDB_H +# include +#endif + +#ifdef HAVE_PTHREAD +# include +#endif + +#include +#include "misc.h" +#include "iofunc.h" +#include "serial.h" +#include "sprintflst.h" + +#include "rigctl_parse.h" + + +/* + * Reminder: when adding long options, + * keep up to date SHORT_OPTIONS, usage()'s output and man page. thanks. + * NB: do NOT use -W since it's reserved by POSIX. + * TODO: add an option to read from a file + */ +#define SHORT_OPTIONS "m:r:p:d:P:D:s:c:T:t:C:lLuovhVZ" +static struct option long_options[] = +{ + {"model", 1, 0, 'm'}, + {"rig-file", 1, 0, 'r'}, + {"ptt-file", 1, 0, 'p'}, + {"dcd-file", 1, 0, 'd'}, + {"ptt-type", 1, 0, 'P'}, + {"dcd-type", 1, 0, 'D'}, + {"serial-speed", 1, 0, 's'}, + {"civaddr", 1, 0, 'c'}, + {"listen-addr", 1, 0, 'T'}, + {"port", 1, 0, 't'}, + {"set-conf", 1, 0, 'C'}, + {"list", 0, 0, 'l'}, + {"show-conf", 0, 0, 'L'}, + {"dump-caps", 0, 0, 'u'}, + {"vfo", 0, 0, 'o'}, + {"verbose", 0, 0, 'v'}, + {"help", 0, 0, 'h'}, + {"version", 0, 0, 'V'}, + {"debug-time-stamps", 0, 0, 'Z'}, + {0, 0, 0, 0} +}; + + +struct handle_data +{ + RIG *rig; + int sock; + struct sockaddr_storage cli_addr; + socklen_t clilen; + int vfo_mode; +}; + + +void *handle_socket(void *arg); +void usage(void); + + +#ifdef HAVE_PTHREAD +static unsigned client_count; +#endif + +static RIG *my_rig; /* handle to rig (instance) */ +static int verbose; + +#ifdef HAVE_SIG_ATOMIC_T +static sig_atomic_t volatile ctrl_c; +#else +static int volatile ctrl_c; +#endif + +const char *portno = "4532"; +const char *src_addr = NULL; /* INADDR_ANY */ + +#define MAXCONFLEN 128 + +static void sync_callback(int lock) +{ +#ifdef HAVE_PTHREAD + static pthread_mutex_t client_lock = PTHREAD_MUTEX_INITIALIZER; + + if (lock) + { + pthread_mutex_lock(&client_lock); + rig_debug(RIG_DEBUG_VERBOSE, "%s: client lock engaged\n", __func__); + } + else + { + rig_debug(RIG_DEBUG_VERBOSE, "%s: client lock disengaged\n", __func__); + pthread_mutex_unlock(&client_lock); + } + +#endif +} + +#ifdef WIN32 +static BOOL WINAPI CtrlHandler(DWORD fdwCtrlType) +{ + rig_debug(RIG_DEBUG_VERBOSE, "%s: called\n", __func__); + + switch (fdwCtrlType) + { + case CTRL_C_EVENT: + case CTRL_CLOSE_EVENT: + ctrl_c = 1; + return TRUE; + + default: + return FALSE; + } +} +#else +static void signal_handler(int sig) +{ + switch (sig) + { + case SIGINT: + ctrl_c = 1; + break; + + default: + /* do nothing */ + break; + } +} +#endif + +static void handle_error(enum rig_debug_level_e lvl, const char *msg) +{ + int e; +#ifdef __MINGW32__ + LPVOID lpMsgBuf; + + lpMsgBuf = (LPVOID)"Unknown error"; + e = WSAGetLastError(); + + if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER + | FORMAT_MESSAGE_FROM_SYSTEM + | FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, e, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + // Default language + (LPTSTR)&lpMsgBuf, 0, NULL)) + { + + rig_debug(lvl, "%s: Network error %d: %s\n", msg, e, (char *)lpMsgBuf); + LocalFree(lpMsgBuf); + } + else + { + rig_debug(lvl, "%s: Network error %d\n", msg, e); + } + +#else + e = errno; + rig_debug(lvl, "%s: Network error %d: %s\n", msg, e, strerror(e)); +#endif +} + + +int main(int argc, char *argv[]) +{ + rig_model_t my_model = RIG_MODEL_DUMMY; + + int retcode; /* generic return code from functions */ + + int show_conf = 0; + int dump_caps_opt = 0; + const char *rig_file = NULL, *ptt_file = NULL, *dcd_file = NULL; + ptt_type_t ptt_type = RIG_PTT_NONE; + dcd_type_t dcd_type = RIG_DCD_NONE; + int serial_rate = 0; + char *civaddr = NULL; /* NULL means no need to set conf */ + char conf_parms[MAXCONFLEN] = ""; + + struct addrinfo hints, *result, *saved_result; + int sock_listen; + int sockopt; + int reuseaddr = 1; + char host[NI_MAXHOST]; + char serv[NI_MAXSERV]; +#if HAVE_SIGACTION + struct sigaction act; +#endif + +#ifdef HAVE_PTHREAD + pthread_t thread; + pthread_attr_t attr; +#endif + struct handle_data *arg; + int vfo_mode = 0; /* vfo_mode=0 means target VFO is current VFO */ + + while (1) + { + int c; + int option_index = 0; + + c = getopt_long(argc, + argv, + SHORT_OPTIONS, + long_options, + &option_index); + + if (c == -1) + { + break; + } + + switch (c) + { + case 'h': + usage(); + exit(0); + + case 'V': + version(); + exit(0); + + case 'm': + if (!optarg) + { + usage(); /* wrong arg count */ + exit(1); + } + + my_model = atoi(optarg); + break; + + case 'r': + if (!optarg) + { + usage(); /* wrong arg count */ + exit(1); + } + + rig_file = optarg; + break; + + case 'p': + if (!optarg) + { + usage(); /* wrong arg count */ + exit(1); + } + + ptt_file = optarg; + break; + + case 'd': + if (!optarg) + { + usage(); /* wrong arg count */ + exit(1); + } + + dcd_file = optarg; + break; + + case 'P': + if (!optarg) + { + usage(); /* wrong arg count */ + exit(1); + } + + if (!strcmp(optarg, "RIG")) + { + ptt_type = RIG_PTT_RIG; + } + else if (!strcmp(optarg, "DTR")) + { + ptt_type = RIG_PTT_SERIAL_DTR; + } + else if (!strcmp(optarg, "RTS")) + { + ptt_type = RIG_PTT_SERIAL_RTS; + } + else if (!strcmp(optarg, "PARALLEL")) + { + ptt_type = RIG_PTT_PARALLEL; + } + else if (!strcmp(optarg, "CM108")) + { + ptt_type = RIG_PTT_CM108; + } + else if (!strcmp(optarg, "NONE")) + { + ptt_type = RIG_PTT_NONE; + } + else + { + ptt_type = atoi(optarg); + } + + break; + + case 'D': + if (!optarg) + { + usage(); /* wrong arg count */ + exit(1); + } + + if (!strcmp(optarg, "RIG")) + { + dcd_type = RIG_DCD_RIG; + } + else if (!strcmp(optarg, "DSR")) + { + dcd_type = RIG_DCD_SERIAL_DSR; + } + else if (!strcmp(optarg, "CTS")) + { + dcd_type = RIG_DCD_SERIAL_CTS; + } + else if (!strcmp(optarg, "CD")) + { + dcd_type = RIG_DCD_SERIAL_CAR; + } + else if (!strcmp(optarg, "PARALLEL")) + { + dcd_type = RIG_DCD_PARALLEL; + } + else if (!strcmp(optarg, "NONE")) + { + dcd_type = RIG_DCD_NONE; + } + else + { + dcd_type = atoi(optarg); + } + + break; + + case 'c': + if (!optarg) + { + usage(); /* wrong arg count */ + exit(1); + } + + civaddr = optarg; + break; + + case 's': + if (!optarg) + { + usage(); /* wrong arg count */ + exit(1); + } + + serial_rate = atoi(optarg); + break; + + case 'C': + if (!optarg) + { + usage(); /* wrong arg count */ + exit(1); + } + + if (*conf_parms != '\0') + { + strcat(conf_parms, ","); + } + + strncat(conf_parms, optarg, MAXCONFLEN - strlen(conf_parms)); + break; + + case 't': + if (!optarg) + { + usage(); /* wrong arg count */ + exit(1); + } + + portno = optarg; + break; + + case 'T': + if (!optarg) + { + usage(); /* wrong arg count */ + exit(1); + } + + src_addr = optarg; + break; + + case 'o': + vfo_mode++; + break; + + case 'v': + verbose++; + break; + + case 'L': + show_conf++; + break; + + case 'l': + list_models(); + exit(0); + + case 'u': + dump_caps_opt++; + break; + + case 'Z': + rig_set_debug_time_stamp(1); + break; + + default: + usage(); /* unknown option? */ + exit(1); + } + } + + if (!vfo_mode) + { + printf("Recommend using --vfo switch for rigctld\n"); + printf("rigctl and netrigctl will automatically detect vfo mode\n"); + } + + rig_set_debug(verbose); + + rig_debug(RIG_DEBUG_VERBOSE, "rigctld, %s\n", hamlib_version); + rig_debug(RIG_DEBUG_VERBOSE, "%s", + "Report bugs to \n\n"); + + my_rig = rig_init(my_model); + + if (!my_rig) + { + fprintf(stderr, + "Unknown rig num %d, or initialization error.\n", + my_model); + + fprintf(stderr, "Please check with --list option.\n"); + exit(2); + } + + retcode = set_conf(my_rig, conf_parms); + + if (retcode != RIG_OK) + { + fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode)); + exit(2); + } + + if (rig_file) + { + strncpy(my_rig->state.rigport.pathname, rig_file, FILPATHLEN - 1); + } + + /* + * ex: RIG_PTT_PARALLEL and /dev/parport0 + */ + if (ptt_type != RIG_PTT_NONE) + { + my_rig->state.pttport.type.ptt = ptt_type; + } + + if (dcd_type != RIG_DCD_NONE) + { + my_rig->state.dcdport.type.dcd = dcd_type; + } + + if (ptt_file) + { + strncpy(my_rig->state.pttport.pathname, ptt_file, FILPATHLEN - 1); + } + + if (dcd_file) + { + strncpy(my_rig->state.dcdport.pathname, dcd_file, FILPATHLEN - 1); + } + + /* FIXME: bound checking and port type == serial */ + if (serial_rate != 0) + { + my_rig->state.rigport.parm.serial.rate = serial_rate; + } + + if (civaddr) + { + rig_set_conf(my_rig, rig_token_lookup(my_rig, "civaddr"), civaddr); + } + + /* + * print out conf parameters + */ + if (show_conf) + { + rig_token_foreach(my_rig, print_conf_list, (rig_ptr_t)my_rig); + } + + /* + * print out conf parameters, and exits immediately + * We may be interested only in only caps, and rig_open may fail. + */ + if (dump_caps_opt) + { + dumpcaps(my_rig, stdout); + rig_cleanup(my_rig); /* if you care about memory */ + exit(0); + } + + /* open and close rig connection to check early for issues */ + retcode = rig_open(my_rig); + + if (retcode != RIG_OK) + { + fprintf(stderr, "rig_open: error = %s \n", rigerror(retcode)); + exit(2); + } + + if (verbose > RIG_DEBUG_ERR) + { + printf("Opened rig model %d, '%s'\n", + my_rig->caps->rig_model, + my_rig->caps->model_name); + } + + rig_debug(RIG_DEBUG_VERBOSE, "Backend version: %s, Status: %s\n", + my_rig->caps->version, rig_strstatus(my_rig->caps->status)); + + rig_close(my_rig); /* we will reopen for clients */ + + if (verbose > RIG_DEBUG_ERR) + { + printf("Closed rig model %d, '%s - will reopen for clients'\n", + my_rig->caps->rig_model, + my_rig->caps->model_name); + } + +#ifdef __MINGW32__ +# ifndef SO_OPENTYPE +# define SO_OPENTYPE 0x7008 +# endif +# ifndef SO_SYNCHRONOUS_NONALERT +# define SO_SYNCHRONOUS_NONALERT 0x20 +# endif +# ifndef INVALID_SOCKET +# define INVALID_SOCKET -1 +# endif + + WSADATA wsadata; + + if (WSAStartup(MAKEWORD(1, 1), &wsadata) == SOCKET_ERROR) + { + fprintf(stderr, "WSAStartup socket error\n"); + exit(1); + } + + sockopt = SO_SYNCHRONOUS_NONALERT; + setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE, (char *)&sockopt, + sizeof(sockopt)); +#endif + + /* + * Prepare listening socket + */ + memset(&hints, 0, sizeof(struct addrinfo)); + hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */ + hints.ai_socktype = SOCK_STREAM;/* TCP socket */ + hints.ai_flags = AI_PASSIVE; /* For wildcard IP address */ + hints.ai_protocol = 0; /* Any protocol */ + + retcode = getaddrinfo(src_addr, portno, &hints, &result); + + if (retcode != 0) + { + fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(retcode)); + exit(2); + } + + saved_result = result; + + do + { + sock_listen = socket(result->ai_family, + result->ai_socktype, + result->ai_protocol); + + if (sock_listen < 0) + { + handle_error(RIG_DEBUG_ERR, "socket"); + freeaddrinfo(saved_result); /* No longer needed */ + exit(2); + } + + if (setsockopt(sock_listen, + SOL_SOCKET, + SO_REUSEADDR, + (char *)&reuseaddr, + sizeof(reuseaddr)) + < 0) + { + + handle_error(RIG_DEBUG_ERR, "setsockopt"); + freeaddrinfo(saved_result); /* No longer needed */ + exit(1); + } + +#ifdef IPV6_V6ONLY + + if (AF_INET6 == result->ai_family) + { + /* allow IPv4 mapped to IPv6 clients Windows and BSD default + this to 1 (i.e. disallowed) and we prefer it off */ + sockopt = 0; + + if (setsockopt(sock_listen, + IPPROTO_IPV6, + IPV6_V6ONLY, + (char *)&sockopt, + sizeof(sockopt)) + < 0) + { + + handle_error(RIG_DEBUG_ERR, "setsockopt"); + freeaddrinfo(saved_result); /* No longer needed */ + exit(1); + } + } + +#endif + + if (0 == bind(sock_listen, result->ai_addr, result->ai_addrlen)) + { + break; + } + + handle_error(RIG_DEBUG_WARN, "binding failed (trying next interface)"); +#ifdef __MINGW32__ + closesocket(sock_listen); +#else + close(sock_listen); +#endif + } + while ((result = result->ai_next) != NULL); + + freeaddrinfo(saved_result); /* No longer needed */ + + if (NULL == result) + { + rig_debug(RIG_DEBUG_ERR, "%s: bind error - no available interface\n", __func__); + exit(1); + } + + if (listen(sock_listen, 4) < 0) + { + handle_error(RIG_DEBUG_ERR, "listening"); + exit(1); + } + +#if HAVE_SIGACTION + +#ifdef SIGPIPE + /* Ignore SIGPIPE as we will handle it at the write()/send() calls + that will consequently fail with EPIPE. All child threads will + inherit this disposition which is what we want. */ + memset(&act, 0, sizeof act); + act.sa_handler = SIG_IGN; + act.sa_flags = SA_RESTART; + + if (sigaction(SIGPIPE, &act, NULL)) + { + handle_error(RIG_DEBUG_ERR, "sigaction SIGPIPE"); + } + +#endif + +#ifdef SIGINT + memset(&act, 0, sizeof act); + act.sa_handler = signal_handler; + + if (sigaction(SIGINT, &act, NULL)) + { + handle_error(RIG_DEBUG_ERR, "sigaction SIGINT"); + } + +#endif +#elif defined (WIN32) + + if (!SetConsoleCtrlHandler(CtrlHandler, TRUE)) + { + handle_error(RIG_DEBUG_ERR, "SetConsoleCtrlHandler"); + } + +#elif HAVE_SIGNAL +#ifdef SIGPIPE + + if (SIG_ERR == signal(SIGPIPE, SIG_IGN)) + { + handle_error(RIG_DEBUG_ERR, "signal SIGPIPE"); + } + +#endif +#ifdef SIGINT + + if (SIG_ERR == signal(SIGINT, signal_handler)) + { + handle_error(RIG_DEBUG_ERR, "signal SIGINT"); + } + +#endif +#endif + + /* + * main loop accepting connections + */ + do + { + fd_set set; + struct timeval timeout; + + arg = malloc(sizeof(struct handle_data)); + + if (!arg) + { + rig_debug(RIG_DEBUG_ERR, "malloc: %s\n", strerror(errno)); + exit(1); + } + + /* use select to allow for periodic checks for CTRL+C */ + FD_ZERO(&set); + FD_SET(sock_listen, &set); + timeout.tv_sec = 5; + timeout.tv_usec = 0; + retcode = select(sock_listen + 1, &set, NULL, NULL, &timeout); + + if (-1 == retcode) + { + rig_debug(RIG_DEBUG_ERR, "%s: select\n", __func__); + } + else if (!retcode) + { + if (ctrl_c) + { + break; + } + } + else + { + arg->rig = my_rig; + arg->clilen = sizeof(arg->cli_addr); + arg->vfo_mode = vfo_mode; + arg->sock = accept(sock_listen, + (struct sockaddr *)&arg->cli_addr, + &arg->clilen); + + if (arg->sock < 0) + { + handle_error(RIG_DEBUG_ERR, "accept"); + break; + } + + if ((retcode = getnameinfo((struct sockaddr const *)&arg->cli_addr, + arg->clilen, + host, + sizeof(host), + serv, + sizeof(serv), + NI_NOFQDN)) + < 0) + { + rig_debug(RIG_DEBUG_WARN, + "Peer lookup error: %s", + gai_strerror(retcode)); + } + + rig_debug(RIG_DEBUG_VERBOSE, + "Connection opened from %s:%s\n", + host, + serv); + +#ifdef HAVE_PTHREAD + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + + retcode = pthread_create(&thread, &attr, handle_socket, arg); + + if (retcode != 0) + { + rig_debug(RIG_DEBUG_ERR, "pthread_create: %s\n", strerror(retcode)); + break; + } + +#else + handle_socket(arg); +#endif + } + } + while (retcode == 0 && !ctrl_c); + +#ifdef HAVE_PTHREAD + /* allow threads to finish current action */ + sync_callback(1); + + if (client_count) + { + rig_debug(RIG_DEBUG_WARN, "%d outstanding client(s)\n", client_count); + } + + rig_close(my_rig); + sync_callback(0); +#else + rig_close(my_rig); /* close port */ +#endif + rig_cleanup(my_rig); /* if you care about memory */ + +#ifdef __MINGW32__ + WSACleanup(); +#endif + + return 0; +} + + +/* + * This is the function run by the threads + */ +void *handle_socket(void *arg) +{ + struct handle_data *handle_data_arg = (struct handle_data *)arg; + FILE *fsockin = NULL; + FILE *fsockout = NULL; + int retcode = RIG_OK; + char host[NI_MAXHOST]; + char serv[NI_MAXSERV]; + char send_cmd_term = '\r'; /* send_cmd termination char */ + int ext_resp = 0; + char resp_sep = '\n'; + +#ifdef __MINGW32__ + int sock_osfhandle = _open_osfhandle(handle_data_arg->sock, _O_RDONLY); + + if (sock_osfhandle == -1) + { + rig_debug(RIG_DEBUG_ERR, "_open_osfhandle error: %s\n", strerror(errno)); + goto handle_exit; + } + + fsockin = _fdopen(sock_osfhandle, "rb"); +#else + fsockin = fdopen(handle_data_arg->sock, "rb"); +#endif + + if (!fsockin) + { + rig_debug(RIG_DEBUG_ERR, "fdopen in: %s\n", strerror(errno)); + goto handle_exit; + } + +#ifdef __MINGW32__ + fsockout = _fdopen(sock_osfhandle, "wb"); +#else + fsockout = fdopen(handle_data_arg->sock, "wb"); +#endif + + if (!fsockout) + { + rig_debug(RIG_DEBUG_ERR, "fdopen out: %s\n", strerror(errno)); + fclose(fsockin); + + goto handle_exit; + } + +#ifdef HAVE_PTHREAD + sync_callback(1); + + if (!client_count++) + { + retcode = rig_open(my_rig); + + if (RIG_OK == retcode && verbose > RIG_DEBUG_ERR) + { + printf("Opened rig model %d, '%s'\n", + my_rig->caps->rig_model, + my_rig->caps->model_name); + } + } + + sync_callback(0); +#else + retcode = rig_open(my_rig); + + if (RIG_OK == retcode && verbose > RIG_DEBUG_ERR) + { + printf("Opened rig model %d, '%s'\n", + my_rig->caps->rig_model, + my_rig->caps->model_name); + } + +#endif + + do + { + retcode = rigctl_parse(handle_data_arg->rig, fsockin, fsockout, NULL, 0, + sync_callback, + 1, 0, handle_data_arg->vfo_mode, send_cmd_term, &ext_resp, &resp_sep); + + if (ferror(fsockin) || ferror(fsockout)) + { + retcode = 1; + } + + if (retcode == 1) + { + retcode = rig_open(my_rig); + } + } + while (retcode == 0 || retcode == 2 || retcode == -RIG_ENAVAIL); + +#ifdef HAVE_PTHREAD + sync_callback(1); + + /* Release rig if there are no clients */ + if (!--client_count) + { + rig_close(my_rig); + + if (verbose > RIG_DEBUG_ERR) + { + printf("Closed rig model %d, '%s - no clients, will reopen for new clients'\n", + my_rig->caps->rig_model, + my_rig->caps->model_name); + } + } + + sync_callback(0); +#else + rig_close(my_rig); + + if (verbose > RIG_DEBUG_ERR) + { + printf("Closed rig model %d, '%s - will reopen for new clients'\n", + my_rig->caps->rig_model, + my_rig->caps->model_name); + } + +#endif + + if ((retcode = getnameinfo((struct sockaddr const *)&handle_data_arg->cli_addr, + handle_data_arg->clilen, + host, + sizeof(host), + serv, + sizeof(serv), + NI_NOFQDN)) + < 0) + { + + rig_debug(RIG_DEBUG_WARN, "Peer lookup error: %s", gai_strerror(retcode)); + } + + rig_debug(RIG_DEBUG_VERBOSE, + "Connection closed from %s:%s\n", + host, + serv); + +handle_exit: + +// for MINGW we close the handle before fclose +#ifdef __MINGW32__ + retcode = closesocket(handle_data_arg->sock); + + if (retcode != 0) { rig_debug(RIG_DEBUG_ERR, "%s: fclose(fsockin) %s\n", __func__, strerror(retcode)); } + +#endif + fclose(fsockin); + fclose(fsockout); + +// for everybody else we close the handle after fclose +#ifndef __MINGW32__ + retcode = close(handle_data_arg->sock); + + if (retcode != 0) { rig_debug(RIG_DEBUG_ERR, "%s: close(handle_data_arg->sock) %s\n", __func__, strerror(retcode)); } + +#endif + + free(arg); + +#ifdef HAVE_PTHREAD + pthread_exit(NULL); +#endif + return NULL; +} + + +void usage(void) +{ + printf("Usage: rigctld [OPTION]...\n" + "Daemon serving COMMANDs to a connected radio transceiver or receiver.\n\n"); + + + printf( + " -m, --model=ID select radio model number. See model list\n" + " -r, --rig-file=DEVICE set device of the radio to operate on\n" + " -p, --ptt-file=DEVICE set device of the PTT device to operate on\n" + " -d, --dcd-file=DEVICE set device of the DCD device to operate on\n" + " -P, --ptt-type=TYPE set type of the PTT device to operate on\n" + " -D, --dcd-type=TYPE set type of the DCD device to operate on\n" + " -s, --serial-speed=BAUD set serial speed of the serial port\n" + " -c, --civaddr=ID set CI-V address, decimal (for Icom rigs only)\n" + " -t, --port=NUM set TCP listening port, default %s\n" + " -T, --listen-addr=IPADDR set listening IP address, default ANY\n" + " -C, --set-conf=PARM=VAL set config parameters\n" + " -L, --show-conf list all config parameters\n" + " -l, --list list all model numbers and exit\n" + " -u, --dump-caps dump capabilities and exit\n" + " -o, --vfo do not default to VFO_CURR, require extra vfo arg\n" + " -v, --verbose set verbose mode, cumulative (-v to -vvvvv)\n" + " -Z, --debug-time-stamps enable time stamps for debug messages\n" + " -h, --help display this help and exit\n" + " -V, --version output version information and exit\n\n", + portno); + + usage_rig(stdout); + + printf("\nReport bugs to .\n"); + +} From d7e9bfd35c16629cea31000b1bfd4e86632ffc10 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Mon, 30 Dec 2019 22:24:19 -0600 Subject: [PATCH 204/205] Fix mingw warning on parallel.c --- src/parallel.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/parallel.c b/src/parallel.c index a592f2601..b6c2272c7 100644 --- a/src/parallel.c +++ b/src/parallel.c @@ -127,7 +127,9 @@ int par_open(hamlib_port_t *port) { int fd; +#ifdef HAVE_LINUX_PPDEV_H int mode; +#endif #if defined (__WIN64__) || defined(__WIN32__) HANDLE handle; From fb51f4f902b2af00e493ad04a994f01a4f538909 Mon Sep 17 00:00:00 2001 From: Michael Black Date: Fri, 3 Jan 2020 12:18:27 -0600 Subject: [PATCH 205/205] Fix compile warnings in rigctl.c and rigctl_parse.c --- tests/rigctl.c | 12 ++---------- tests/rigctl_parse.c | 4 +++- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/tests/rigctl.c b/tests/rigctl.c index f64ec7e52..1b5246869 100644 --- a/tests/rigctl.c +++ b/tests/rigctl.c @@ -118,14 +118,6 @@ static struct option long_options[] = #define MAXCONFLEN 128 -/* variable for readline support */ -#ifdef HAVE_LIBREADLINE -static const int have_rl = 1; -#else -static const int have_rl = 0; -#endif - - int main(int argc, char *argv[]) { RIG *my_rig; /* handle to rig (instance) */ @@ -571,7 +563,7 @@ int main(int argc, char *argv[]) #ifdef HAVE_LIBREADLINE - if (interactive && prompt && have_rl) + if (interactive && prompt) { rl_readline_name = "rigctl"; @@ -628,7 +620,7 @@ int main(int argc, char *argv[]) #ifdef HAVE_LIBREADLINE - if (interactive && prompt && have_rl) + if (interactive && prompt) { #ifdef HAVE_READLINE_HISTORY diff --git a/tests/rigctl_parse.c b/tests/rigctl_parse.c index 891d2fd72..606368401 100644 --- a/tests/rigctl_parse.c +++ b/tests/rigctl_parse.c @@ -456,8 +456,10 @@ static int scanfc(FILE *fin, const char *format, void *p) { do { + int ret; *(char *)p = 0; - int ret = fscanf(fin, format, p); + + ret = fscanf(fin, format, p); if (ret < 0) {