From d820ee9dbfbd12bc030e6576cc8eea6655cbffbb Mon Sep 17 00:00:00 2001 From: Mike Black W9MDB Date: Wed, 24 Nov 2021 13:02:39 -0600 Subject: [PATCH] Add expected_len to read_string function for potential serial I/O speedup https://github.com/Hamlib/Hamlib/issues/850 --- amplifiers/elecraft/kpa.c | 8 +++--- rigs/adat/adat.c | 4 +-- rigs/alinco/dx77.c | 6 ++-- rigs/alinco/dxsr8.c | 4 +-- rigs/aor/aor.c | 4 +-- rigs/aor/ar3000.c | 2 +- rigs/aor/ar3030.c | 2 +- rigs/aor/sr2200.c | 2 +- rigs/barrett/barrett.c | 2 +- rigs/dorji/dra818.c | 4 +-- rigs/drake/drake.c | 4 +-- rigs/dummy/flrig.c | 2 +- rigs/dummy/netampctl.c | 6 ++-- rigs/dummy/netrigctl.c | 50 +++++++++++++++++----------------- rigs/dummy/netrotctl.c | 14 +++++----- rigs/dummy/trxmanager.c | 2 +- rigs/elad/elad.c | 6 ++-- rigs/icmarine/icmarine.c | 2 +- rigs/icom/frame.c | 2 +- rigs/jrc/jrc.c | 4 +-- rigs/kachina/kachina.c | 6 ++-- rigs/kenwood/elecraft.c | 2 +- rigs/kenwood/ic10.c | 4 +-- rigs/kenwood/kenwood.c | 10 +++---- rigs/kenwood/ts480.c | 2 +- rigs/kenwood/xg3.c | 8 +++--- rigs/kit/rs_hfiq.c | 8 +++--- rigs/lowe/lowe.c | 4 +-- rigs/prm80/prm80.c | 14 +++++----- rigs/racal/ra37xx.c | 2 +- rigs/racal/racal.c | 2 +- rigs/rft/rft.c | 2 +- rigs/rs/gp2000.c | 2 +- rigs/rs/rs.c | 2 +- rigs/skanti/skanti.c | 4 +-- rigs/tentec/omnivii.c | 4 +-- rigs/tentec/orion.c | 4 +-- rigs/tentec/rx331.c | 2 +- rigs/tentec/rx340.c | 2 +- rigs/tentec/tentec.c | 2 +- rigs/tentec/tt550.c | 4 +-- rigs/uniden/uniden.c | 4 +-- rigs/uniden/uniden_digital.c | 2 +- rigs/yaesu/newcat.c | 8 +++--- rotators/celestron/celestron.c | 2 +- rotators/easycomm/easycomm.c | 2 +- rotators/ether6/ether6.c | 2 +- rotators/gs232a/gs232.c | 2 +- rotators/gs232a/gs232a.c | 2 +- rotators/gs232a/gs232b.c | 2 +- rotators/ioptron/rot_ioptron.c | 2 +- rotators/m2/rc2800.c | 4 +-- rotators/meade/meade.c | 2 +- rotators/prosistel/prosistel.c | 2 +- rotators/radant/radant.c | 2 +- rotators/rotorez/rotorez.c | 2 +- rotators/satel/satel.c | 16 +++++------ src/iofunc.c | 3 +- src/iofunc.h | 3 +- src/serial.c | 2 +- tests/ampctl_parse.c | 2 +- tests/rigctl_parse.c | 2 +- tests/rigctlcom.c | 3 +- tests/rotctl_parse.c | 2 +- 64 files changed, 148 insertions(+), 145 deletions(-) diff --git a/amplifiers/elecraft/kpa.c b/amplifiers/elecraft/kpa.c index 8e0dd32cd..9e1672d7c 100644 --- a/amplifiers/elecraft/kpa.c +++ b/amplifiers/elecraft/kpa.c @@ -126,7 +126,7 @@ int kpa_transaction(AMP *amp, const char *cmd, char *response, int response_len) if (err != RIG_OK) { return err; } - len = read_string(&rs->ampport, response, response_len, ";", 1, 0); + len = read_string(&rs->ampport, response, response_len, ";", 1, 0, 1); if (len < 0) { return len; } } @@ -140,7 +140,7 @@ int kpa_transaction(AMP *amp, const char *cmd, char *response, int response_len) if (response) // if response expected get it { response[0] = 0; - len = read_string(&rs->ampport, response, response_len, ";", 1, 0); + len = read_string(&rs->ampport, response, response_len, ";", 1, 0, 1); if (len < 0) { @@ -166,7 +166,7 @@ int kpa_transaction(AMP *amp, const char *cmd, char *response, int response_len) if (err != RIG_OK) { return err; } - len = read_string(&rs->ampport, responsebuf, KPABUFSZ, ";", 1, 0); + len = read_string(&rs->ampport, responsebuf, KPABUFSZ, ";", 1, 0, 1); if (len < 0) { return len; } } @@ -369,7 +369,7 @@ int kpa_get_level(AMP *amp, setting_t level, value_t *val) // do { - retval = read_string(&rs->ampport, responsebuf, sizeof(responsebuf), ";", 1, 0); + retval = read_string(&rs->ampport, responsebuf, sizeof(responsebuf), ";", 1, 0, 1); if (retval != RIG_OK) { return retval; } diff --git a/rigs/adat/adat.c b/rigs/adat/adat.c index 53dbae641..b38c4a846 100644 --- a/rigs/adat/adat.c +++ b/rigs/adat/adat.c @@ -1294,7 +1294,7 @@ int adat_receive(RIG *pRig, "*** ADAT: %d %s (%s:%d): ENTRY. Params: pRig = %p\n", gFnLevel, __func__, __FILE__, __LINE__, pRig); - nRC = read_string(&pRigState->rigport, pcData, ADAT_RESPSZ, ADAT_EOL, 1, 0); + nRC = read_string(&pRigState->rigport, pcData, ADAT_RESPSZ, ADAT_EOL, 1, 0, 1); if (nRC > 0) { @@ -3726,7 +3726,7 @@ DECLARE_PROBERIG_BACKEND(adat) nRC = write_block(port, ADAT_CMD_DEF_STRING_GET_ID_CODE, strlen(ADAT_CMD_DEF_STRING_GET_ID_CODE)); - nRead = read_string(port, acBuf, ADAT_RESPSZ, ADAT_EOM, 1, 0); + nRead = read_string(port, acBuf, ADAT_RESPSZ, ADAT_EOM, 1, 0, 1); close(port->fd); if ((nRC != RIG_OK || nRead < 0)) diff --git a/rigs/alinco/dx77.c b/rigs/alinco/dx77.c index 134e6eabc..d6f8234fc 100644 --- a/rigs/alinco/dx77.c +++ b/rigs/alinco/dx77.c @@ -321,7 +321,7 @@ int dx77_transaction(RIG *rig, * Transceiver sends an echo of cmd followed by a CR/LF * TODO: check whether cmd and echobuf match (optional) */ - retval = read_string(&rs->rigport, echobuf, BUFSZ, LF, strlen(LF), 0); + retval = read_string(&rs->rigport, echobuf, BUFSZ, LF, strlen(LF), 0, 1); if (retval < 0) { @@ -337,7 +337,7 @@ int dx77_transaction(RIG *rig, /* no data expected, check for OK returned */ if (data == NULL) { - retval = read_string(&rs->rigport, echobuf, BUFSZ, LF, strlen(LF), 0); + retval = read_string(&rs->rigport, echobuf, BUFSZ, LF, strlen(LF), 0, 1); if (retval < 0) { @@ -358,7 +358,7 @@ int dx77_transaction(RIG *rig, } } - retval = read_string(&rs->rigport, data, BUFSZ, LF, strlen(LF), 0); + retval = read_string(&rs->rigport, data, BUFSZ, LF, strlen(LF), 0, 1); if (retval < 0) { diff --git a/rigs/alinco/dxsr8.c b/rigs/alinco/dxsr8.c index 02f33b9d9..030bb7193 100644 --- a/rigs/alinco/dxsr8.c +++ b/rigs/alinco/dxsr8.c @@ -264,7 +264,7 @@ int dxsr8_transaction(RIG *rig, * Transceiver sends an echo of cmd followed by a CR/LF * TODO: check whether cmd and echobuf match (optional) */ - retval = read_string(&rs->rigport, replybuf, BUFSZ, LF, strlen(LF), 0); + retval = read_string(&rs->rigport, replybuf, BUFSZ, LF, strlen(LF), 0, 1); if (retval < 0) { @@ -272,7 +272,7 @@ int dxsr8_transaction(RIG *rig, } - retval = read_string(&rs->rigport, replybuf, BUFSZ, LF, strlen(LF), 0); + retval = read_string(&rs->rigport, replybuf, BUFSZ, LF, strlen(LF), 0, 1); if (retval < 0) { diff --git a/rigs/aor/aor.c b/rigs/aor/aor.c index 799816429..f6a3ca5ba 100644 --- a/rigs/aor/aor.c +++ b/rigs/aor/aor.c @@ -102,7 +102,7 @@ static int aor_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, /* * Do wait for a reply */ - retval = read_string(&rs->rigport, data, BUFSZ, EOM, strlen(EOM), 0); + retval = read_string(&rs->rigport, data, BUFSZ, EOM, strlen(EOM), 0, 1); if (retval < 0) { @@ -1428,7 +1428,7 @@ int aor_get_chan_all_cb(RIG *rig, vfo_t vfo, chan_cb_t chan_cb, rig_ptr_t arg) /* * get next line */ - retval = read_string(&rig->state.rigport, chanbuf, BUFSZ, EOM, strlen(EOM), 0); + retval = read_string(&rig->state.rigport, chanbuf, BUFSZ, EOM, strlen(EOM), 0, 1); if (retval < 0) { diff --git a/rigs/aor/ar3000.c b/rigs/aor/ar3000.c index f5cb8cf02..4a52d2574 100644 --- a/rigs/aor/ar3000.c +++ b/rigs/aor/ar3000.c @@ -211,7 +211,7 @@ static int ar3k_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, return RIG_OK; } - retval = read_string(&rs->rigport, data, BUFSZ, EOM, strlen(EOM), 0); + retval = read_string(&rs->rigport, data, BUFSZ, EOM, strlen(EOM), 0, 1); if (retval == -RIG_ETIMEOUT) { diff --git a/rigs/aor/ar3030.c b/rigs/aor/ar3030.c index 88a7c7d73..ad03b94cb 100644 --- a/rigs/aor/ar3030.c +++ b/rigs/aor/ar3030.c @@ -247,7 +247,7 @@ static int ar3030_transaction(RIG *rig, const char *cmd, int cmd_len, if (data) { /* expecting 0x0d0x0a on all commands so wait for the 0x0a */ - retval = read_string(&rs->rigport, data, BUFSZ, "\x0a", 1, 0); + retval = read_string(&rs->rigport, data, BUFSZ, "\x0a", 1, 0, 1); if (retval == -RIG_ETIMEOUT) { diff --git a/rigs/aor/sr2200.c b/rigs/aor/sr2200.c index 72519b689..7cb051837 100644 --- a/rigs/aor/sr2200.c +++ b/rigs/aor/sr2200.c @@ -307,7 +307,7 @@ static int sr2200_transaction(RIG *rig, const char *cmd, int cmd_len, /* * Do wait for a reply */ - retval = read_string(&rs->rigport, data, BUFSZ, EOM, strlen(EOM), 0); + retval = read_string(&rs->rigport, data, BUFSZ, EOM, strlen(EOM), 0, 1); if (retval < 0) { diff --git a/rigs/barrett/barrett.c b/rigs/barrett/barrett.c index a266f0f8b..572e5f097 100644 --- a/rigs/barrett/barrett.c +++ b/rigs/barrett/barrett.c @@ -244,7 +244,7 @@ int barrett_transaction(RIG *rig, char *cmd, int expected, char **result) { // response format is 0x11,data...,0x0d,0x0a,0x13 retval = read_string(&rs->rigport, priv->ret_data, sizeof(priv->ret_data), - "\x11", 1, 0); + "\x11", 1, 0, 1); rig_debug(RIG_DEBUG_VERBOSE, "%s: resultlen=%d\n", __func__, (int)strlen(priv->ret_data)); diff --git a/rigs/dorji/dra818.c b/rigs/dorji/dra818.c index 79d0ee783..851f325ee 100644 --- a/rigs/dorji/dra818.c +++ b/rigs/dorji/dra818.c @@ -60,7 +60,7 @@ struct dra818_priv static int dra818_response(RIG *rig, const char *expected) { char response[80]; - int r = read_string(&rig->state.rigport, response, sizeof(response), "\n", 1, 0); + int r = read_string(&rig->state.rigport, response, sizeof(response), "\n", 1, 0, 1); if (r != strlen(expected)) { @@ -294,7 +294,7 @@ int dra818_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd) (int)(priv->rx_freq / 1000000), (int)((priv->rx_freq % 1000000) / 100)); write_block(&rig->state.rigport, cmd, strlen(cmd)); - r = read_string(&rig->state.rigport, response, sizeof(response), "\n", 1, 0); + r = read_string(&rig->state.rigport, response, sizeof(response), "\n", 1, 0, 1); if (r != 5) { diff --git a/rigs/drake/drake.c b/rigs/drake/drake.c index 3cc2b0f0b..fad3265de 100644 --- a/rigs/drake/drake.c +++ b/rigs/drake/drake.c @@ -84,7 +84,7 @@ int drake_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, return 0; } - retval = read_string(&rs->rigport, data, BUFSZ, LF, 1, 0); + retval = read_string(&rs->rigport, data, BUFSZ, LF, 1, 0, 1); if (retval == -RIG_ETIMEOUT) { @@ -1252,7 +1252,7 @@ DECLARE_PROBERIG_BACKEND(drake) } retval = write_block(port, "ID" EOM, 3); - id_len = read_string(port, idbuf, BUFSZ, LF, 1, 0); + id_len = read_string(port, idbuf, BUFSZ, LF, 1, 0, 1); close(port->fd); diff --git a/rigs/dummy/flrig.c b/rigs/dummy/flrig.c index 534b41951..2a1563140 100644 --- a/rigs/dummy/flrig.c +++ b/rigs/dummy/flrig.c @@ -456,7 +456,7 @@ static int read_transaction(RIG *rig, char *xml, int xml_len) } int len = read_string(&rs->rigport, tmp_buf, sizeof(tmp_buf), delims, - strlen(delims), 0); + strlen(delims), 0, 1); rig_debug(RIG_DEBUG_TRACE, "%s: string='%s'\n", __func__, tmp_buf); // if our first response we should see the HTTP header diff --git a/rigs/dummy/netampctl.c b/rigs/dummy/netampctl.c index 5334b9543..91a872897 100644 --- a/rigs/dummy/netampctl.c +++ b/rigs/dummy/netampctl.c @@ -52,7 +52,7 @@ static int netampctl_transaction(AMP *amp, char *cmd, int len, char *buf) return ret; } - ret = read_string(&->state.ampport, buf, BUF_MAX, "\n", sizeof("\n"), 0); + ret = read_string(&->state.ampport, buf, BUF_MAX, "\n", sizeof("\n"), 0, 1); if (ret < 0) { @@ -95,7 +95,7 @@ static int netampctl_open(AMP *amp) return -RIG_EPROTO; } - ret = read_string(&->state.ampport, buf, BUF_MAX, "\n", sizeof("\n"), 0); + ret = read_string(&->state.ampport, buf, BUF_MAX, "\n", sizeof("\n"), 0, 1); if (ret <= 0) { @@ -104,7 +104,7 @@ static int netampctl_open(AMP *amp) do { - ret = read_string(&->state.ampport, buf, BUF_MAX, "\n", sizeof("\n"), 0); + ret = read_string(&->state.ampport, buf, BUF_MAX, "\n", sizeof("\n"), 0, 1); if (ret > 0) { diff --git a/rigs/dummy/netrigctl.c b/rigs/dummy/netrigctl.c index 8502f4311..7108b821f 100644 --- a/rigs/dummy/netrigctl.c +++ b/rigs/dummy/netrigctl.c @@ -79,7 +79,7 @@ static int netrigctl_transaction(RIG *rig, char *cmd, int len, char *buf) return ret; } - ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0); + ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0, 1); if (ret < 0) { @@ -312,14 +312,14 @@ static int netrigctl_open(RIG *rig) return -RIG_EPROTO; } - ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0); + ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0, 1); if (ret <= 0) { return (ret < 0) ? ret : -RIG_EPROTO; } - ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0); + ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0, 1); if (ret <= 0) { @@ -330,7 +330,7 @@ static int netrigctl_open(RIG *rig) for (i = 0; i < HAMLIB_FRQRANGESIZ; i++) { - ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0); + ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0, 1); if (ret <= 0) { @@ -360,7 +360,7 @@ static int netrigctl_open(RIG *rig) for (i = 0; i < HAMLIB_FRQRANGESIZ; i++) { - ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0); + ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0, 1); if (ret <= 0) { @@ -402,7 +402,7 @@ static int netrigctl_open(RIG *rig) for (i = 0; i < HAMLIB_TSLSTSIZ; i++) { - ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0); + ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0, 1); if (ret <= 0) { @@ -426,7 +426,7 @@ static int netrigctl_open(RIG *rig) for (i = 0; i < HAMLIB_FLTLSTSIZ; i++) { - ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0); + ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0, 1); if (ret <= 0) { @@ -453,7 +453,7 @@ static int netrigctl_open(RIG *rig) chan_t chan_list[HAMLIB_CHANLSTSIZ]; /*!< Channel list, zero ended */ #endif - ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0); + ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0, 1); if (ret <= 0) { @@ -462,7 +462,7 @@ static int netrigctl_open(RIG *rig) rig->caps->max_rit = rs->max_rit = atol(buf); - ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0); + ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0, 1); if (ret <= 0) { @@ -471,7 +471,7 @@ static int netrigctl_open(RIG *rig) rig->caps->max_xit = rs->max_xit = atol(buf); - ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0); + ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0, 1); if (ret <= 0) { @@ -480,7 +480,7 @@ static int netrigctl_open(RIG *rig) rig->caps->max_ifshift = rs->max_ifshift = atol(buf); - ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0); + ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0, 1); if (ret <= 0) { @@ -489,7 +489,7 @@ static int netrigctl_open(RIG *rig) rs->announces = atoi(buf); - ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0); + ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0, 1); if (ret <= 0) { @@ -516,7 +516,7 @@ static int netrigctl_open(RIG *rig) rig->caps->preamp[ret] = rs->preamp[ret] = RIG_DBLST_END; - ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0); + ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0, 1); if (ret <= 0) { @@ -543,7 +543,7 @@ static int netrigctl_open(RIG *rig) rig->caps->attenuator[ret] = rs->attenuator[ret] = RIG_DBLST_END; - ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0); + ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0, 1); if (ret <= 0) { @@ -552,7 +552,7 @@ static int netrigctl_open(RIG *rig) rig->caps->has_get_func = rs->has_get_func = strtoll(buf, NULL, 0); - ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0); + ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0, 1); if (ret <= 0) { @@ -561,7 +561,7 @@ static int netrigctl_open(RIG *rig) rig->caps->has_set_func = rs->has_set_func = strtoll(buf, NULL, 0); - ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0); + ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0, 1); if (ret <= 0) { @@ -583,7 +583,7 @@ static int netrigctl_open(RIG *rig) #endif - ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0); + ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0, 1); if (ret <= 0) { @@ -592,7 +592,7 @@ static int netrigctl_open(RIG *rig) rig->caps->has_set_level = rs->has_set_level = strtoll(buf, NULL, 0); - ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0); + ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0, 1); if (ret <= 0) { @@ -601,7 +601,7 @@ static int netrigctl_open(RIG *rig) rs->has_get_parm = strtoll(buf, NULL, 0); - ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0); + ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0, 1); if (ret <= 0) { @@ -641,7 +641,7 @@ static int netrigctl_open(RIG *rig) do { char setting[32], value[1024]; - ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0); + ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0, 1); strtok(buf, "\r\n"); // chop the EOL if (ret <= 0) @@ -892,7 +892,7 @@ static int netrigctl_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) CHKSCN1ARG(num_sscanf(buf, "%"SCNfreq, freq)); #if 0 // implement set_freq VFO later if it can be detected - ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0); + ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0, 1); if (ret <= 0) { @@ -963,7 +963,7 @@ static int netrigctl_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, *mode = rig_parse_mode(buf); - ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0); + ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0, 1); if (ret <= 0) { @@ -1576,7 +1576,7 @@ static int netrigctl_get_split_mode(RIG *rig, vfo_t vfo, rmode_t *tx_mode, *tx_mode = rig_parse_mode(buf); - ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0); + ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0, 1); if (ret <= 0) { @@ -1642,7 +1642,7 @@ static int netrigctl_get_split_vfo(RIG *rig, vfo_t vfo, split_t *split, *split = atoi(buf); - ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0); + ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0, 1); if (ret <= 0) { @@ -2164,7 +2164,7 @@ static int netrigctl_get_ant(RIG *rig, vfo_t vfo, ant_t ant, value_t *option, ret); } - ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0); + ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1, 0, 1); if (ret <= 0) { diff --git a/rigs/dummy/netrotctl.c b/rigs/dummy/netrotctl.c index deecdfe27..45883b421 100644 --- a/rigs/dummy/netrotctl.c +++ b/rigs/dummy/netrotctl.c @@ -57,7 +57,7 @@ static int netrotctl_transaction(ROT *rot, char *cmd, int len, char *buf) return ret; } - ret = read_string(&rot->state.rotport, buf, BUF_MAX, "\n", sizeof("\n"), 0); + ret = read_string(&rot->state.rotport, buf, BUF_MAX, "\n", sizeof("\n"), 0, 1); if (ret < 0) { @@ -100,14 +100,14 @@ static int netrotctl_open(ROT *rot) return -RIG_EPROTO; } - ret = read_string(&rot->state.rotport, buf, BUF_MAX, "\n", sizeof("\n"), 0); + ret = read_string(&rot->state.rotport, buf, BUF_MAX, "\n", sizeof("\n"), 0, 1); if (ret <= 0) { return (ret < 0) ? ret : -RIG_EPROTO; } - ret = read_string(&rot->state.rotport, buf, BUF_MAX, "\n", sizeof("\n"), 0); + ret = read_string(&rot->state.rotport, buf, BUF_MAX, "\n", sizeof("\n"), 0, 1); if (ret <= 0) { @@ -116,7 +116,7 @@ static int netrotctl_open(ROT *rot) rs->min_az = atof(buf); - ret = read_string(&rot->state.rotport, buf, BUF_MAX, "\n", sizeof("\n"), 0); + ret = read_string(&rot->state.rotport, buf, BUF_MAX, "\n", sizeof("\n"), 0, 1); if (ret <= 0) { @@ -125,7 +125,7 @@ static int netrotctl_open(ROT *rot) rs->max_az = atof(buf); - ret = read_string(&rot->state.rotport, buf, BUF_MAX, "\n", sizeof("\n"), 0); + ret = read_string(&rot->state.rotport, buf, BUF_MAX, "\n", sizeof("\n"), 0, 1); if (ret <= 0) { @@ -134,7 +134,7 @@ static int netrotctl_open(ROT *rot) rs->min_el = atof(buf); - ret = read_string(&rot->state.rotport, buf, BUF_MAX, "\n", sizeof("\n"), 0); + ret = read_string(&rot->state.rotport, buf, BUF_MAX, "\n", sizeof("\n"), 0, 1); if (ret <= 0) { @@ -198,7 +198,7 @@ static int netrotctl_get_position(ROT *rot, azimuth_t *az, elevation_t *el) *az = atof(buf); - ret = read_string(&rot->state.rotport, buf, BUF_MAX, "\n", sizeof("\n"), 0); + ret = read_string(&rot->state.rotport, buf, BUF_MAX, "\n", sizeof("\n"), 0, 1); if (ret <= 0) { diff --git a/rigs/dummy/trxmanager.c b/rigs/dummy/trxmanager.c index 5d5192d32..2476870ff 100644 --- a/rigs/dummy/trxmanager.c +++ b/rigs/dummy/trxmanager.c @@ -243,7 +243,7 @@ static int read_transaction(RIG *rig, char *response, int response_len) rig_debug(RIG_DEBUG_TRACE, "%s\n", __func__); len = read_string(&rs->rigport, response, response_len, delims, - strlen(delims), 0); + strlen(delims), 0, 1); if (len <= 0) { diff --git a/rigs/elad/elad.c b/rigs/elad/elad.c index 346c96909..aba415af5 100644 --- a/rigs/elad/elad.c +++ b/rigs/elad/elad.c @@ -253,7 +253,7 @@ transaction_read: /* allow one extra byte for terminator we don't return */ len = min(datasize ? datasize + 1 : strlen(priv->verify_cmd) + 13, ELAD_MAX_BUF_LEN); - retval = read_string(&rs->rigport, buffer, len, cmdtrm, strlen(cmdtrm), 0); + retval = read_string(&rs->rigport, buffer, len, cmdtrm, strlen(cmdtrm), 0, 1); if (retval < 0) { @@ -3739,7 +3739,7 @@ DECLARE_PROBERIG_BACKEND(elad) } retval = write_block(port, "ID;", 3); - id_len = read_string(port, idbuf, IDBUFSZ, ";\r", 2, 0); + id_len = read_string(port, idbuf, IDBUFSZ, ";\r", 2, 0, 1); close(port->fd); if (retval != RIG_OK || id_len < 0) @@ -3800,7 +3800,7 @@ DECLARE_PROBERIG_BACKEND(elad) } retval = write_block(port, "K2;", 3); - id_len = read_string(port, idbuf, IDBUFSZ, ";\r", 2, 0); + id_len = read_string(port, idbuf, IDBUFSZ, ";\r", 2, 0, 1); close(port->fd); if (retval != RIG_OK) diff --git a/rigs/icmarine/icmarine.c b/rigs/icmarine/icmarine.c index 5fc194f47..5e99e681f 100644 --- a/rigs/icmarine/icmarine.c +++ b/rigs/icmarine/icmarine.c @@ -288,7 +288,7 @@ int icmarine_transaction(RIG *rig, const char *cmd, const char *param, /* * Transceiver sends an echo of cmd followed by a CR/LF */ - retval = read_string(&rs->rigport, respbuf, BUFSZ, LF, strlen(LF), 0); + retval = read_string(&rs->rigport, respbuf, BUFSZ, LF, strlen(LF), 0, 1); if (retval < 0) { diff --git a/rigs/icom/frame.c b/rigs/icom/frame.c index 964277a13..a57f8fd76 100644 --- a/rigs/icom/frame.c +++ b/rigs/icom/frame.c @@ -490,7 +490,7 @@ int read_icom_frame(hamlib_port_t *p, unsigned char rxbuffer[], do { int i = read_string(p, rx_ptr, MAXFRAMELEN - read, - icom_block_end, icom_block_end_length, 0); + icom_block_end, icom_block_end_length, 0, 1); if (i < 0 && i != RIG_BUSBUSY) /* die on errors */ { diff --git a/rigs/jrc/jrc.c b/rigs/jrc/jrc.c index 61e429f71..a02aa9c56 100644 --- a/rigs/jrc/jrc.c +++ b/rigs/jrc/jrc.c @@ -93,7 +93,7 @@ static int jrc_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, return 0; } - retval = read_string(&rs->rigport, data, BUFSZ, EOM, strlen(EOM), 0); + retval = read_string(&rs->rigport, data, BUFSZ, EOM, strlen(EOM), 0, 1); Unhold_Decode(rig); @@ -1632,7 +1632,7 @@ int jrc_decode_event(RIG *rig) //#define SETUP_STATUS_LEN 17 //count = read_string(&rs->rigport, buf, SETUP_STATUS_LEN, "", 0); - count = read_string(&rs->rigport, buf, priv->info_len, "", 0, 0); + count = read_string(&rs->rigport, buf, priv->info_len, "", 0, 0, 1); if (count < 0) { diff --git a/rigs/kachina/kachina.c b/rigs/kachina/kachina.c index df1aecba0..138c26006 100644 --- a/rigs/kachina/kachina.c +++ b/rigs/kachina/kachina.c @@ -93,7 +93,7 @@ static int kachina_transaction(RIG *rig, unsigned char cmd1, unsigned char cmd2) return retval; } - count = read_string(&rs->rigport, (char *) buf4, 1, "", 0, 0); + count = read_string(&rs->rigport, (char *) buf4, 1, "", 0, 0, 1); if (count != 1) { @@ -128,7 +128,7 @@ static int kachina_trans_n(RIG *rig, unsigned char cmd1, const char *data, return retval; } - count = read_string(&rs->rigport, (char *) buf, 1, "", 0, 0); + count = read_string(&rs->rigport, (char *) buf, 1, "", 0, 0, 1); if (count != 1) { @@ -273,7 +273,7 @@ int kachina_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) rig_flush(&rig->state.rigport); count = read_string(&rig->state.rigport, (char *) buf, 31, rcv_signal_range, - 128, 0); + 128, 0, 1); if (count < 1) { diff --git a/rigs/kenwood/elecraft.c b/rigs/kenwood/elecraft.c index ad2a6e06c..016b4dec2 100644 --- a/rigs/kenwood/elecraft.c +++ b/rigs/kenwood/elecraft.c @@ -135,7 +135,7 @@ int elecraft_open(RIG *rig) return err; } - err = read_string(&rs->rigport, buf, sizeof(buf), ";", 1, 0); + err = read_string(&rs->rigport, buf, sizeof(buf), ";", 1, 0, 1); if (err < 0) { diff --git a/rigs/kenwood/ic10.c b/rigs/kenwood/ic10.c index c393e3f6a..7053249ae 100644 --- a/rigs/kenwood/ic10.c +++ b/rigs/kenwood/ic10.c @@ -110,7 +110,7 @@ transaction: } // this should be the ID response - retval = read_string(&rs->rigport, buffer, sizeof(buffer), ";", 1, 0); + retval = read_string(&rs->rigport, buffer, sizeof(buffer), ";", 1, 0, 1); // might be ?; too if (buffer[0] == '?' && retry_cmd++ < rs->rigport.retry) @@ -129,7 +129,7 @@ transaction: return RIG_OK; } - retval = read_string(&rs->rigport, data, 50, ";", 1, 0); + retval = read_string(&rs->rigport, data, 50, ";", 1, 0, 1); if (retval == -RIG_ETIMEOUT) { diff --git a/rigs/kenwood/kenwood.c b/rigs/kenwood/kenwood.c index cd544b446..1000bffc8 100644 --- a/rigs/kenwood/kenwood.c +++ b/rigs/kenwood/kenwood.c @@ -369,7 +369,7 @@ transaction_read: /* allow room for most any response */ len = min(datasize ? datasize + 1 : strlen(priv->verify_cmd) + 48, KENWOOD_MAX_BUF_LEN); - retval = read_string(&rs->rigport, buffer, len, cmdtrm_str, strlen(cmdtrm_str), 0); + retval = read_string(&rs->rigport, buffer, len, cmdtrm_str, strlen(cmdtrm_str), 0, 1); rig_debug(RIG_DEBUG_TRACE, "%s: read_string(len=%d)='%s'\n", __func__, (int)strlen(buffer), buffer); @@ -2601,7 +2601,7 @@ static int kenwood_get_micgain_minmax(RIG *rig, int *micgain_now, if (retval != RIG_OK) { RETURNFUNC(retval); } - retval = read_string(&rs->rigport, levelbuf, sizeof(levelbuf), NULL, 0, 0); + retval = read_string(&rs->rigport, levelbuf, sizeof(levelbuf), NULL, 0, 0, 1); rig_debug(RIG_DEBUG_TRACE, "%s: retval=%d\n", __func__, retval); @@ -2700,7 +2700,7 @@ static int kenwood_get_power_minmax(RIG *rig, int *power_now, int *power_min, if (retval != RIG_OK) { RETURNFUNC(retval); } - retval = read_string(&rs->rigport, levelbuf, sizeof(levelbuf), NULL, 0, 0); + retval = read_string(&rs->rigport, levelbuf, sizeof(levelbuf), NULL, 0, 0, 1); rig_debug(RIG_DEBUG_TRACE, "%s: retval=%d\n", __func__, retval); @@ -5367,7 +5367,7 @@ DECLARE_PROBERIG_BACKEND(kenwood) } retval = write_block(port, "ID;", 3); - id_len = read_string(port, idbuf, IDBUFSZ, ";\r", 2, 0); + id_len = read_string(port, idbuf, IDBUFSZ, ";\r", 2, 0, 1); close(port->fd); if (retval != RIG_OK || id_len < 0) @@ -5434,7 +5434,7 @@ DECLARE_PROBERIG_BACKEND(kenwood) } retval = write_block(port, "K2;", 3); - id_len = read_string(port, idbuf, IDBUFSZ, ";\r", 2, 0); + id_len = read_string(port, idbuf, IDBUFSZ, ";\r", 2, 0, 1); close(port->fd); if (retval != RIG_OK) diff --git a/rigs/kenwood/ts480.c b/rigs/kenwood/ts480.c index 190b72f03..029123ce7 100644 --- a/rigs/kenwood/ts480.c +++ b/rigs/kenwood/ts480.c @@ -442,7 +442,7 @@ static int ts480_read_meters(RIG *rig, int *swr, int *comp, int *alc) // TS-480 returns values for all meters at the same time, for example: RM10000;RM20000;RM30000; - retval = read_string(&rs->rigport, ackbuf, expected_len + 1, NULL, 0, 0); + retval = read_string(&rs->rigport, ackbuf, expected_len + 1, NULL, 0, 0, 1); rig_debug(RIG_DEBUG_TRACE, "%s: read_string retval=%d\n", __func__, retval); diff --git a/rigs/kenwood/xg3.c b/rigs/kenwood/xg3.c index 54b136344..1251378c0 100644 --- a/rigs/kenwood/xg3.c +++ b/rigs/kenwood/xg3.c @@ -285,7 +285,7 @@ int xg3_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) return retval; } - retval = read_string(&rs->rigport, replybuf, replysize, ";", 1, 0); + retval = read_string(&rs->rigport, replybuf, replysize, ";", 1, 0, 1); if (retval < 0) { @@ -462,7 +462,7 @@ int xg3_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) return retval; } - retval = read_string(&rs->rigport, freqbuf, freqsize, ";", 1, 0); + retval = read_string(&rs->rigport, freqbuf, freqsize, ";", 1, 0, 1); if (retval < 0) { @@ -514,7 +514,7 @@ int xg3_get_powerstat(RIG *rig, powerstat_t *status) if (retval == RIG_OK) { char reply[32]; - retval = read_string(&rs->rigport, reply, sizeof(reply), ";", 1, 0); + retval = read_string(&rs->rigport, reply, sizeof(reply), ";", 1, 0, 1); *status = RIG_POWER_ON; priv->powerstat = RIG_POWER_ON; } @@ -578,7 +578,7 @@ int xg3_get_mem(RIG *rig, vfo_t vfo, int *ch) return retval; } - retval = read_string(&rs->rigport, reply, sizeof(reply), ";", 1, 0); + retval = read_string(&rs->rigport, reply, sizeof(reply), ";", 1, 0, 1); if (retval < 0) { diff --git a/rigs/kit/rs_hfiq.c b/rigs/kit/rs_hfiq.c index 92b1b59d5..3618cd0a4 100644 --- a/rigs/kit/rs_hfiq.c +++ b/rigs/kit/rs_hfiq.c @@ -102,7 +102,7 @@ static int rshfiq_open(RIG *rig) return retval; } - retval = read_string(&rig->state.rigport, versionstr, 20, stopset, 2, 0); + retval = read_string(&rig->state.rigport, versionstr, 20, stopset, 2, 0, 1); } if (retval <= 0) @@ -191,7 +191,7 @@ static int rshfiq_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) return retval; } - retval = read_string(&rig->state.rigport, cmdstr, 9, stopset, 2, 0); + retval = read_string(&rig->state.rigport, cmdstr, 9, stopset, 2, 0, 1); if (retval <= 0) { @@ -276,7 +276,7 @@ static int rshfiq_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) stopset[0] = '\r'; stopset[1] = '\n'; - retval = read_string(&rig->state.rigport, cmdstr, 9, stopset, 2, 0); + retval = read_string(&rig->state.rigport, cmdstr, 9, stopset, 2, 0, 1); rig_debug(RIG_DEBUG_TRACE, "RIG_LEVEL_RFPOWER_METER reply=%s\n", cmdstr); @@ -314,7 +314,7 @@ static int rshfiq_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) stopset[0] = '\r'; stopset[1] = '\n'; - retval = read_string(&rig->state.rigport, cmdstr, 9, stopset, 2, 0); + retval = read_string(&rig->state.rigport, cmdstr, 9, stopset, 2, 0, 1); rig_debug(RIG_DEBUG_TRACE, "RIG_LEVEL_TEMP_METER reply=%s\n", cmdstr); diff --git a/rigs/lowe/lowe.c b/rigs/lowe/lowe.c index ad561b1ab..a9d14478e 100644 --- a/rigs/lowe/lowe.c +++ b/rigs/lowe/lowe.c @@ -79,7 +79,7 @@ int lowe_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, return 0; } - retval = read_string(&rs->rigport, data, BUFSZ, CR, 1, 0); + retval = read_string(&rs->rigport, data, BUFSZ, CR, 1, 0, 1); if (retval == -RIG_ETIMEOUT) { @@ -342,7 +342,7 @@ DECLARE_PROBERIG_BACKEND(lowe) } retval = write_block(port, "TYP?" EOM, 4); - id_len = read_string(port, idbuf, BUFSZ, CR, 2, 0); + id_len = read_string(port, idbuf, BUFSZ, CR, 2, 0, 1); close(port->fd); diff --git a/rigs/prm80/prm80.c b/rigs/prm80/prm80.c index 6da02693e..5ba68be6d 100644 --- a/rigs/prm80/prm80.c +++ b/rigs/prm80/prm80.c @@ -170,7 +170,7 @@ static int read_prompt_and_send(hamlib_port_t *rigport, buflen = (data_len == NULL) ? sizeof(buf) : *data_len; - retval = read_string(rigport, data, buflen, delimiter, 1, 0); + retval = read_string(rigport, data, buflen, delimiter, 1, 0, 1); if (retval < 0) { @@ -230,7 +230,7 @@ static int prm80_wait_for_prompt(hamlib_port_t *rigport) int retval; // Read up to the '>' prompt and discard content. - retval = read_string(rigport, buf, sizeof(buf), ">", 1, 0); + retval = read_string(rigport, buf, sizeof(buf), ">", 1, 0, 1); if (retval < 0) { @@ -910,7 +910,7 @@ int prm80_set_channel(RIG *rig, vfo_t vfo, const channel_t *chan) if (ret == 3 && buf[2] == 'T') { // Read the question - ret = read_string(&rs->rigport, buf, sizeof(buf), "?", 1, 0); + ret = read_string(&rs->rigport, buf, sizeof(buf), "?", 1, 0, 1); if (ret < 0) { @@ -1126,7 +1126,7 @@ static int prm80_get_rawstr_RAM(RIG *rig, value_t *val) } // Read CRLF - ret = read_string(&rs->rigport, buf, BUFSZ, "\n", 1, 0); + ret = read_string(&rs->rigport, buf, BUFSZ, "\n", 1, 0, 1); if (ret < 0) { @@ -1142,7 +1142,7 @@ static int prm80_get_rawstr_RAM(RIG *rig, value_t *val) for (i = 0; i < (RSSI_HOLD_ADDR / 16) + 1; i++) { - ret = read_string(&rs->rigport, buf, BUFSZ, "\n", 1, 0); + ret = read_string(&rs->rigport, buf, BUFSZ, "\n", 1, 0, 1); if (ret < 0) { @@ -1158,7 +1158,7 @@ static int prm80_get_rawstr_RAM(RIG *rig, value_t *val) // discard the remaining content of RAM print for (i = 0; i < (16 - RSSI_HOLD_ADDR / 16) - 1; i++) { - read_string(&rs->rigport, buf, BUFSZ, "\n", 1, 0); + read_string(&rs->rigport, buf, BUFSZ, "\n", 1, 0, 1); } prm80_wait_for_prompt(&rs->rigport); @@ -1281,7 +1281,7 @@ const char *prm80_get_info(RIG *rig) return NULL; } - ret = read_string(&rs->rigport, s_buf, BUFSZ, ">", 1, 0); + ret = read_string(&rs->rigport, s_buf, BUFSZ, ">", 1, 0, 1); if (ret < 0) { diff --git a/rigs/racal/ra37xx.c b/rigs/racal/ra37xx.c index bee3c6e66..353ba2d5a 100644 --- a/rigs/racal/ra37xx.c +++ b/rigs/racal/ra37xx.c @@ -122,7 +122,7 @@ static int ra37xx_one_transaction(RIG *rig, const char *cmd, char *data, do { - retval = read_string(&rs->rigport, respbuf, BUFSZ, EOM, strlen(EOM), 0); + retval = read_string(&rs->rigport, respbuf, BUFSZ, EOM, strlen(EOM), 0, 1); if (retval < 0) { diff --git a/rigs/racal/racal.c b/rigs/racal/racal.c index dc6dad86b..cc3b5050b 100644 --- a/rigs/racal/racal.c +++ b/rigs/racal/racal.c @@ -100,7 +100,7 @@ static int racal_transaction(RIG *rig, const char *cmd, char *data, return retval; } - retval = read_string(&rs->rigport, data, BUFSZ, EOM, strlen(EOM), 0); + retval = read_string(&rs->rigport, data, BUFSZ, EOM, strlen(EOM), 0, 1); if (retval <= 0) { diff --git a/rigs/rft/rft.c b/rigs/rft/rft.c index 7b544b8fb..d5960f7e6 100644 --- a/rigs/rft/rft.c +++ b/rigs/rft/rft.c @@ -71,7 +71,7 @@ int rft_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, return 0; } - retval = read_string(&rs->rigport, data, BUFSZ, CR, 1, 0); + retval = read_string(&rs->rigport, data, BUFSZ, CR, 1, 0, 1); if (retval == -RIG_ETIMEOUT) { diff --git a/rigs/rs/gp2000.c b/rigs/rs/gp2000.c index 6455fa0a9..d0c80c52e 100644 --- a/rigs/rs/gp2000.c +++ b/rigs/rs/gp2000.c @@ -89,7 +89,7 @@ gp2000_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, return RIG_OK; } - retval = read_string(&rs->rigport, data, RESPSZ, CR, 1, 0); + retval = read_string(&rs->rigport, data, RESPSZ, CR, 1, 0, 1); if (retval < 0) { diff --git a/rigs/rs/rs.c b/rigs/rs/rs.c index bde748edb..b60056eb1 100644 --- a/rigs/rs/rs.c +++ b/rigs/rs/rs.c @@ -80,7 +80,7 @@ int rs_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, return RIG_OK; } - retval = read_string(&rs->rigport, data, BUFSZ, CR, 1, 0); + retval = read_string(&rs->rigport, data, BUFSZ, CR, 1, 0, 1); if (retval < 0) { diff --git a/rigs/skanti/skanti.c b/rigs/skanti/skanti.c index 8ad178985..347900aef 100644 --- a/rigs/skanti/skanti.c +++ b/rigs/skanti/skanti.c @@ -88,7 +88,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), 0); + retval = read_string(&rs->rigport, retbuf, BUFSZ, PROMPT, strlen(PROMPT), 0, 1); if (retval < 0) { @@ -107,7 +107,7 @@ static int skanti_transaction(RIG *rig, const char *cmd, int cmd_len, } } - retval = read_string(&rs->rigport, data, BUFSZ, LF, strlen(LF), 0); + retval = read_string(&rs->rigport, data, BUFSZ, LF, strlen(LF), 0, 1); if (retval == -RIG_ETIMEOUT) { diff --git a/rigs/tentec/omnivii.c b/rigs/tentec/omnivii.c index 34192a637..3f5ff8d3e 100644 --- a/rigs/tentec/omnivii.c +++ b/rigs/tentec/omnivii.c @@ -288,7 +288,7 @@ static int tt588_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, if (data) { - retval = read_string(&rs->rigport, data, (*data_len) + 1, term, strlen(term), 0); + retval = read_string(&rs->rigport, data, (*data_len) + 1, term, strlen(term), 0, 1); if (retval != -RIG_ETIMEOUT) { @@ -310,7 +310,7 @@ static int tt588_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, write_block(&rs->rigport, "XX" EOM, 3); // we wont' worry about the response here retval = read_string(&rs->rigport, xxbuf, sizeof(xxbuf), "", - 0, 0); // this should timeout + 0, 0, 1); // this should timeout if (retval != RIG_OK) { diff --git a/rigs/tentec/orion.c b/rigs/tentec/orion.c index 823477bc4..b1aebe475 100644 --- a/rigs/tentec/orion.c +++ b/rigs/tentec/orion.c @@ -156,7 +156,7 @@ static int tt565_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, #endif *data_len = data_len_init; /* restore orig. buffer length */ *data_len = read_string(&rs->rigport, data, *data_len, - EOM, strlen(EOM), 0); + EOM, strlen(EOM), 0, 1); if (!strncmp(data, "Z!", 2)) // command unrecognized?? { @@ -197,7 +197,7 @@ static int tt565_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, passcount, itry); *data_len = data_len_init; /* restore orig. buffer length */ read_string(&rs->rigport, data, *data_len, - EOM, strlen(EOM), 0); // purge the input stream... + EOM, strlen(EOM), 0, 1); // purge the input stream... continue; // now go retry the full command } } diff --git a/rigs/tentec/rx331.c b/rigs/tentec/rx331.c index f9737100b..9e6e84b8d 100644 --- a/rigs/tentec/rx331.c +++ b/rigs/tentec/rx331.c @@ -269,7 +269,7 @@ static int rx331_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, return RIG_OK; } - retval = read_string(&rs->rigport, data, BUFSZ, EOM, 1, 0); + retval = read_string(&rs->rigport, data, BUFSZ, EOM, 1, 0, 1); if (retval < 0) { diff --git a/rigs/tentec/rx340.c b/rigs/tentec/rx340.c index 8a8245a41..1edcf642a 100644 --- a/rigs/tentec/rx340.c +++ b/rigs/tentec/rx340.c @@ -219,7 +219,7 @@ static int rx340_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, return RIG_OK; } - retval = read_string(&rs->rigport, data, BUFSZ, EOM, 1, 0); + retval = read_string(&rs->rigport, data, BUFSZ, EOM, 1, 0, 1); if (retval < 0) { diff --git a/rigs/tentec/tentec.c b/rigs/tentec/tentec.c index 2c022a952..00a4ee9f3 100644 --- a/rigs/tentec/tentec.c +++ b/rigs/tentec/tentec.c @@ -85,7 +85,7 @@ int tentec_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, return 0; } - retval = read_string(&rs->rigport, data, *data_len, NULL, 0, 0); + retval = read_string(&rs->rigport, data, *data_len, NULL, 0, 0, 1); if (retval == -RIG_ETIMEOUT) { diff --git a/rigs/tentec/tt550.c b/rigs/tentec/tt550.c index 6fdea17ff..a7718da5f 100644 --- a/rigs/tentec/tt550.c +++ b/rigs/tentec/tt550.c @@ -103,7 +103,7 @@ tt550_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, return 0; } - retval = read_string(&rs->rigport, data, *data_len, NULL, 0, 0); + retval = read_string(&rs->rigport, data, *data_len, NULL, 0, 0, 1); if (retval == -RIG_ETIMEOUT) { @@ -1699,7 +1699,7 @@ tt550_decode_event(RIG *rig) priv = (struct tt550_priv_data *) rs->priv; - data_len = read_string(&rs->rigport, (char *) buf, MAXFRAMELEN, "\n\r", 2, 0); + data_len = read_string(&rs->rigport, (char *) buf, MAXFRAMELEN, "\n\r", 2, 0, 1); if (data_len == -RIG_ETIMEOUT) diff --git a/rigs/uniden/uniden.c b/rigs/uniden/uniden.c index c0399802d..16e0db003 100644 --- a/rigs/uniden/uniden.c +++ b/rigs/uniden/uniden.c @@ -156,7 +156,7 @@ transaction_write: } memset(data, 0, *datasize); - retval = read_string(&rs->rigport, data, *datasize, EOM, strlen(EOM), 0); + retval = read_string(&rs->rigport, data, *datasize, EOM, strlen(EOM), 0, 1); if (retval < 0) { @@ -838,7 +838,7 @@ DECLARE_PROBERIG_BACKEND(uniden) } retval = write_block(port, "SI"EOM, 3); - id_len = read_string(port, idbuf, IDBUFSZ, EOM, 1, 0); + id_len = read_string(port, idbuf, IDBUFSZ, EOM, 1, 0, 1); close(port->fd); if (retval != RIG_OK || id_len < 0) diff --git a/rigs/uniden/uniden_digital.c b/rigs/uniden/uniden_digital.c index 8e2fe3761..1e91fa6f1 100644 --- a/rigs/uniden/uniden_digital.c +++ b/rigs/uniden/uniden_digital.c @@ -138,7 +138,7 @@ transaction_write: } memset(data, 0, *datasize); - retval = read_string(&rs->rigport, data, *datasize, EOM, strlen(EOM), 0); + retval = read_string(&rs->rigport, data, *datasize, EOM, strlen(EOM), 0, 1); if (retval < 0) { diff --git a/rigs/yaesu/newcat.c b/rigs/yaesu/newcat.c index 87090d94c..6a6f55e22 100644 --- a/rigs/yaesu/newcat.c +++ b/rigs/yaesu/newcat.c @@ -9851,7 +9851,7 @@ int newcat_get_cmd(RIG *rig) /* read the reply */ if ((rc = read_string(&state->rigport, priv->ret_data, sizeof(priv->ret_data), - &cat_term, sizeof(cat_term), 0)) <= 0) + &cat_term, sizeof(cat_term), 0, 1)) <= 0) { continue; /* usually a timeout - retry */ } @@ -10051,7 +10051,7 @@ int newcat_set_cmd_validate(RIG *rig) if (strlen(valcmd) == 0) { RETURNFUNC(RIG_OK); } bytes = read_string(&state->rigport, priv->ret_data, sizeof(priv->ret_data), - &cat_term, sizeof(cat_term), 0); + &cat_term, sizeof(cat_term), 0, 1); // FA and FB success is now verified in rig.c with a followup query // so no validation is needed @@ -10179,7 +10179,7 @@ int newcat_set_cmd(RIG *rig) /* read the reply */ if ((rc = read_string(&state->rigport, priv->ret_data, sizeof(priv->ret_data), - &cat_term, sizeof(cat_term), 0)) <= 0) + &cat_term, sizeof(cat_term), 0, 1)) <= 0) { continue; /* usually a timeout - retry */ } @@ -10249,7 +10249,7 @@ int newcat_set_cmd(RIG *rig) /* read/flush the verify command reply which should still be there */ if ((rc = read_string(&state->rigport, priv->ret_data, sizeof(priv->ret_data), - &cat_term, sizeof(cat_term), 0)) > 0) + &cat_term, sizeof(cat_term), 0, 1)) > 0) { rig_debug(RIG_DEBUG_TRACE, "%s: read count = %d, ret_data = %s\n", __func__, rc, priv->ret_data); diff --git a/rotators/celestron/celestron.c b/rotators/celestron/celestron.c index 390006e7a..056c4ad51 100644 --- a/rotators/celestron/celestron.c +++ b/rotators/celestron/celestron.c @@ -92,7 +92,7 @@ transaction_write: /* the answer */ memset(data, 0, data_len); - retval = read_string(&rs->rotport, data, data_len, ACK, strlen(ACK), 0); + retval = read_string(&rs->rotport, data, data_len, ACK, strlen(ACK), 0, 1); if (retval < 0) { diff --git a/rotators/easycomm/easycomm.c b/rotators/easycomm/easycomm.c index 8facdefd8..e524e69b3 100644 --- a/rotators/easycomm/easycomm.c +++ b/rotators/easycomm/easycomm.c @@ -79,7 +79,7 @@ easycomm_transaction(ROT *rot, const char *cmdstr, char *data, size_t data_len) return RIG_OK; /* don't want a reply */ } - retval = read_string(&rs->rotport, data, data_len, "\n", 1, 0); + retval = read_string(&rs->rotport, data, data_len, "\n", 1, 0, 1); if (retval < 0) { diff --git a/rotators/ether6/ether6.c b/rotators/ether6/ether6.c index 77583f462..93af20b7b 100644 --- a/rotators/ether6/ether6.c +++ b/rotators/ether6/ether6.c @@ -60,7 +60,7 @@ static int ether_transaction(ROT *rot, char *cmd, int len, char *buf) return ret; } - ret = read_string(&rot->state.rotport, buf, BUF_MAX, "\n", sizeof("\n"), 0); + ret = read_string(&rot->state.rotport, buf, BUF_MAX, "\n", sizeof("\n"), 0, 1); rig_debug(RIG_DEBUG_VERBOSE, "function %s(2): ret=%d || receive=%s\n", __func__, ret, buf); diff --git a/rotators/gs232a/gs232.c b/rotators/gs232a/gs232.c index 8cd946ce3..88a486def 100644 --- a/rotators/gs232a/gs232.c +++ b/rotators/gs232a/gs232.c @@ -94,7 +94,7 @@ transaction_write: memset(data, 0, data_len); retval = read_string(&rs->rotport, data, data_len, REPLY_EOM, - strlen(REPLY_EOM), 0); + strlen(REPLY_EOM), 0, 1); if (retval < 0) { diff --git a/rotators/gs232a/gs232a.c b/rotators/gs232a/gs232a.c index 6def6bb32..783184007 100644 --- a/rotators/gs232a/gs232a.c +++ b/rotators/gs232a/gs232a.c @@ -104,7 +104,7 @@ transaction_write: { memset(data, 0, data_len); retval = read_string(&rs->rotport, data, data_len, REPLY_EOM, - strlen(REPLY_EOM), 0); + strlen(REPLY_EOM), 0, 1); if (strncmp(data, "\r\n", 2) == 0 || strchr(data, '>')) diff --git a/rotators/gs232a/gs232b.c b/rotators/gs232a/gs232b.c index 38002c88e..b8ecf6b7e 100644 --- a/rotators/gs232a/gs232b.c +++ b/rotators/gs232a/gs232b.c @@ -104,7 +104,7 @@ transaction_write: memset(data, 0, data_len); retval = read_string(&rs->rotport, data, data_len, REPLY_EOM, - strlen(REPLY_EOM), 0); + strlen(REPLY_EOM), 0, 1); if (strncmp(data, "\r\n", 2) == 0 || strchr(data, '>')) { diff --git a/rotators/ioptron/rot_ioptron.c b/rotators/ioptron/rot_ioptron.c index d28c3f0ba..12fa96f12 100644 --- a/rotators/ioptron/rot_ioptron.c +++ b/rotators/ioptron/rot_ioptron.c @@ -108,7 +108,7 @@ transaction_write: /** the answer */ memset(data, 0, data_len); - retval = read_string(&rs->rotport, data, data_len, ACK, strlen(ACK), 0); + retval = read_string(&rs->rotport, data, data_len, ACK, strlen(ACK), 0, 1); if (retval < 0) { diff --git a/rotators/m2/rc2800.c b/rotators/m2/rc2800.c index 9f82705d9..ea39f8f49 100644 --- a/rotators/m2/rc2800.c +++ b/rotators/m2/rc2800.c @@ -204,13 +204,13 @@ transaction_write: /* then comes the answer */ memset(data, 0, data_len); - retval = read_string(&rs->rotport, data, data_len, CR, strlen(CR), 0); + retval = read_string(&rs->rotport, data, data_len, CR, strlen(CR), 0, 1); // some models seem to echo -- so we'll check and read again if echoed if (cmdstr && strcmp(data, cmdstr) == 0) { memset(data, 0, data_len); - retval = read_string(&rs->rotport, data, data_len, CR, strlen(CR), 0); + retval = read_string(&rs->rotport, data, data_len, CR, strlen(CR), 0, 1); } if (retval < 0) diff --git a/rotators/meade/meade.c b/rotators/meade/meade.c index ab740b4f3..c05dc1c90 100644 --- a/rotators/meade/meade.c +++ b/rotators/meade/meade.c @@ -129,7 +129,7 @@ transaction: if (data != NULL) { return_value = read_string(&rs->rotport, data, expected_return_length + 1, - "\r\n", strlen("\r\n"), 0); + "\r\n", strlen("\r\n"), 0, 1); if (return_value > 0) { diff --git a/rotators/prosistel/prosistel.c b/rotators/prosistel/prosistel.c index 02bd414c6..74bbac099 100644 --- a/rotators/prosistel/prosistel.c +++ b/rotators/prosistel/prosistel.c @@ -98,7 +98,7 @@ transaction_write: } // Remember to check for STXA,G,R or STXA,?,XXX,R 10 bytes - retval = read_string(&rs->rotport, data, 20, CR, strlen(CR), 0); + retval = read_string(&rs->rotport, data, 20, CR, strlen(CR), 0, 1); if (retval < 0) { diff --git a/rotators/radant/radant.c b/rotators/radant/radant.c index ca7e4bc2d..c37ec48b2 100644 --- a/rotators/radant/radant.c +++ b/rotators/radant/radant.c @@ -79,7 +79,7 @@ radant_transaction(ROT *rot, const char *cmdstr, char *data, size_t data_len) return RIG_OK; /* don't want a reply */ } - retval = read_string(&rs->rotport, data, data_len, "\n", 1, 0); + retval = read_string(&rs->rotport, data, data_len, "\n", 1, 0, 1); if (retval < 0) { diff --git a/rotators/rotorez/rotorez.c b/rotators/rotorez/rotorez.c index 5de52b704..5666d920a 100644 --- a/rotators/rotorez/rotorez.c +++ b/rotators/rotorez/rotorez.c @@ -763,7 +763,7 @@ static int rt21_rot_get_position(ROT *rot, azimuth_t *azimuth, rs = &rot->state; - err = read_string(&rs->rotport, az, RT21_AZ_LEN + 1, ";", strlen(";"), 0); + err = read_string(&rs->rotport, az, RT21_AZ_LEN + 1, ";", strlen(";"), 0, 1); if (err < 0) /* read_string returns negative on error. */ { diff --git a/rotators/satel/satel.c b/rotators/satel/satel.c index fdd009050..d5231c960 100644 --- a/rotators/satel/satel.c +++ b/rotators/satel/satel.c @@ -137,7 +137,7 @@ static int satel_cmd(ROT *rot, char *cmd, int cmdlen, char *res, int reslen) if (reslen > 0 && res != NULL) { - ret = read_string(&rs->rotport, res, reslen, "\n", 1, 0); + ret = read_string(&rs->rotport, res, reslen, "\n", 1, 0, 1); if (ret < 0) { @@ -163,7 +163,7 @@ static int satel_read_status(ROT *rot, satel_stat_t *stat) // read motion state - ret = read_string(&rs->rotport, resbuf, BUF_SIZE, "\n", 1, 0); + ret = read_string(&rs->rotport, resbuf, BUF_SIZE, "\n", 1, 0, 1); if (ret < 0) { @@ -173,7 +173,7 @@ static int satel_read_status(ROT *rot, satel_stat_t *stat) stat->motion_enabled = strcmp(resbuf, "Motion ENABLED") == 0 ? true : false; // XXX skip mode - ret = read_string(&rs->rotport, resbuf, BUF_SIZE, "\n", 1, 0); + ret = read_string(&rs->rotport, resbuf, BUF_SIZE, "\n", 1, 0, 1); if (ret < 0) { @@ -181,7 +181,7 @@ static int satel_read_status(ROT *rot, satel_stat_t *stat) } // XXX skip time - ret = read_string(&rs->rotport, resbuf, BUF_SIZE, "\n", 1, 0); + ret = read_string(&rs->rotport, resbuf, BUF_SIZE, "\n", 1, 0, 1); if (ret < 0) { @@ -189,7 +189,7 @@ static int satel_read_status(ROT *rot, satel_stat_t *stat) } // read azimuth line - ret = read_string(&rs->rotport, resbuf, BUF_SIZE, "\n", 1, 0); + ret = read_string(&rs->rotport, resbuf, BUF_SIZE, "\n", 1, 0, 1); if (ret < 0) { @@ -201,7 +201,7 @@ static int satel_read_status(ROT *rot, satel_stat_t *stat) stat->az = (int)strtof(p, NULL); // read elevation line - ret = read_string(&rs->rotport, resbuf, BUF_SIZE, "\n", 1, 0); + ret = read_string(&rs->rotport, resbuf, BUF_SIZE, "\n", 1, 0, 1); if (ret < 0) { @@ -213,7 +213,7 @@ static int satel_read_status(ROT *rot, satel_stat_t *stat) stat->el = (int)strtof(p, NULL); // skip blank line - ret = read_string(&rs->rotport, resbuf, BUF_SIZE, "\n", 1, 0); + ret = read_string(&rs->rotport, resbuf, BUF_SIZE, "\n", 1, 0, 1); if (ret < 0) { @@ -221,7 +221,7 @@ static int satel_read_status(ROT *rot, satel_stat_t *stat) } // XXX skip stored position count - ret = read_string(&rs->rotport, resbuf, BUF_SIZE, "\n", 1, 0); + ret = read_string(&rs->rotport, resbuf, BUF_SIZE, "\n", 1, 0, 1); if (ret < 0) { diff --git a/src/iofunc.c b/src/iofunc.c index 232bc3fb0..d4b6ebf35 100644 --- a/src/iofunc.c +++ b/src/iofunc.c @@ -672,7 +672,8 @@ int HAMLIB_API read_string(hamlib_port_t *p, size_t rxmax, const char *stopset, int stopset_len, - int flush_flag) + int flush_flag, + int expected_len) { fd_set rfds, efds; struct timeval tv, tv_timeout, start_time, end_time, elapsed_time; diff --git a/src/iofunc.h b/src/iofunc.h index 8055acfa8..02e5f503c 100644 --- a/src/iofunc.h +++ b/src/iofunc.h @@ -43,6 +43,7 @@ extern HAMLIB_EXPORT(int) read_string(hamlib_port_t *p, size_t rxmax, const char *stopset, int stopset_len, - int flush_flag); + int flush_flag, + int expected_len); #endif /* _IOFUNC_H */ diff --git a/src/serial.c b/src/serial.c index 959b546a9..d9607d762 100644 --- a/src/serial.c +++ b/src/serial.c @@ -678,7 +678,7 @@ int HAMLIB_API serial_flush(hamlib_port_t *p) // we pass an empty stopset so read_string can determine // the appropriate stopset for async data char stopset[1]; - len = read_string(p, (char*)buf, sizeof(buf)-1, stopset, 0, 1); + len = read_string(p, (char*)buf, sizeof(buf)-1, stopset, 0, 1, 1); if (len > 0) { int i, binary=0; diff --git a/tests/ampctl_parse.c b/tests/ampctl_parse.c index db8d0c55e..f0052cf21 100644 --- a/tests/ampctl_parse.c +++ b/tests/ampctl_parse.c @@ -1957,7 +1957,7 @@ declare_proto_amp(send_cmd) * assumes CR or LF is end of line char * for all ascii protocols */ - retval = read_string(&rs->ampport, buf, BUFSZ, eom_buf, strlen(eom_buf), 0); + retval = read_string(&rs->ampport, buf, BUFSZ, eom_buf, strlen(eom_buf), 0, 1); if (retval < 0) { diff --git a/tests/rigctl_parse.c b/tests/rigctl_parse.c index 24f53fd02..04f32d6f0 100644 --- a/tests/rigctl_parse.c +++ b/tests/rigctl_parse.c @@ -4959,7 +4959,7 @@ declare_proto_rig(send_cmd) /* Assumes CR or LF is end of line char for all ASCII protocols. */ retval = read_string(&rs->rigport, (char *)buf, rxbytes, eom_buf, - strlen(eom_buf), 0); + strlen(eom_buf), 0, 1); if (retval < 0) { diff --git a/tests/rigctlcom.c b/tests/rigctlcom.c index 5a3a5119a..fdfff6c5f 100644 --- a/tests/rigctlcom.c +++ b/tests/rigctlcom.c @@ -626,7 +626,8 @@ int main(int argc, char *argv[]) sizeof(ts2000), stop_set, strlen(stop_set), - 0); + 0, + 1); rig_debug(RIG_DEBUG_TRACE, "%s: status=%d\n", __func__, status); diff --git a/tests/rotctl_parse.c b/tests/rotctl_parse.c index b9e5e3069..eff5c7c3c 100644 --- a/tests/rotctl_parse.c +++ b/tests/rotctl_parse.c @@ -2499,7 +2499,7 @@ declare_proto_rot(send_cmd) * assumes CR or LF is end of line char * for all ascii protocols */ - retval = read_string(&rs->rotport, buf, BUFSZ, eom_buf, strlen(eom_buf), 0); + retval = read_string(&rs->rotport, buf, BUFSZ, eom_buf, strlen(eom_buf), 0, 1); if (retval < 0) {