Change iofunc.c to read FLRig more efficiently

https://github.com/Hamlib/Hamlib/issues/1394
pull/1404/head
Mike Black W9MDB 2023-10-04 17:30:02 -05:00
rodzic e0c4988e6a
commit d4cf8a04d7
4 zmienionych plików z 35 dodań i 27 usunięć

Wyświetl plik

@ -3635,7 +3635,7 @@ extern HAMLIB_EXPORT_VAR(char) debugmsgsave3[DEBUGMSGSAVE_SIZE]; // last-2 debu
// Measuring elapsed time -- local variable inside function when macro is used
#define ELAPSED1 struct timespec __begin; elapsed_ms(&__begin, HAMLIB_ELAPSED_SET);
#define ELAPSED2 rig_debug(RIG_DEBUG_TRACE, "%.*s%d:%s: elapsed=%.0lfms\n", rig->state.depth-1, spaces(), rig->state.depth, __func__, elapsed_ms(&__begin, HAMLIB_ELAPSED_GET));
#define ELAPSED2 rig_debug(RIG_DEBUG_VERBOSE, "%.*s%d:%s: elapsed=%.0lfms\n", rig->state.depth-1, spaces(), rig->state.depth, __func__, elapsed_ms(&__begin, HAMLIB_ELAPSED_GET));
// use this instead of snprintf for automatic detection of buffer limit
#define SNPRINTF(s,n,...) { snprintf(s,n,##__VA_ARGS__);if (strlen(s) > n-1) fprintf(stderr,"****** %s(%d): buffer overflow ******\n", __func__, __LINE__); }

Wyświetl plik

@ -422,7 +422,7 @@ static int read_transaction(RIG *rig, char *xml, int xml_len)
{
int retval;
int retry;
char *delims;
//char *delims;
char *terminator = "</methodResponse>";
struct rig_state *rs = &rig->state;
@ -443,8 +443,8 @@ static int read_transaction(RIG *rig, char *xml, int xml_len)
rig_debug(RIG_DEBUG_TRACE, "%s: before read_string\n", __func__);
int len = read_string(&rs->rigport, (unsigned char *) tmp_buf, sizeof(tmp_buf),
"<methodResponse>",
16, 0, 1);
"</methodResponse>",
17, 0, 1);
rig_debug(RIG_DEBUG_TRACE, "%s: string='%s'\n", __func__, tmp_buf);
// if our first response we should see the HTTP header

Wyświetl plik

@ -1339,7 +1339,7 @@ static int read_string_generic(hamlib_port_t *p,
memset(rxbuffer, 0, rxmax);
short timeout_retries = p->timeout_retry;
HAMLIB_TRACE2;
//HAMLIB_TRACE2;
while (total_count < rxmax - 1) // allow 1 byte for end-of-string
{
ssize_t rd_count = 0;
@ -1358,7 +1358,7 @@ static int read_string_generic(hamlib_port_t *p,
rig_debug(RIG_DEBUG_CACHE, "%s(%d): retrying read timeout %d/%d timeout=%d\n", __func__, __LINE__,
p->timeout_retry - timeout_retries, p->timeout_retry, p->timeout);
hl_usleep(10 * 1000);
HAMLIB_TRACE2;
//HAMLIB_TRACE2;
continue;
}
@ -1416,12 +1416,12 @@ static int read_string_generic(hamlib_port_t *p,
//rig_debug(RIG_DEBUG_ERR, "xs: avail=%d expected_len=%d, minlen=%d, direct=%d\n", __func__, avail, expected_len, minlen, direct);
#endif
#endif
HAMLIB_TRACE2;
//HAMLIB_TRACE2;
shortcut:
rd_count = port_read_generic(p, &rxbuffer[total_count],
expected_len == 1 ? 1 : minlen, direct);
HAMLIB_TRACE2;
// rig_debug(RIG_DEBUG_VERBOSE, "%s: read %d bytes tot=%d\n", __func__, (int)rd_count, total_count);
//HAMLIB_TRACE2;
// rig_debug(RIG_DEBUG_VERBOSE, "%s: read %d bytes tot=%d\nrxbuffer=%s\n", __func__, (int)rd_count, total_count, rxbuffer);
minlen -= rd_count;
if (errno == EAGAIN)
@ -1433,7 +1433,7 @@ static int read_string_generic(hamlib_port_t *p,
}
while (++i < 10 && errno == EBUSY); // 50ms should be enough
HAMLIB_TRACE2;
//HAMLIB_TRACE2;
/* if we get 0 bytes or an error something is wrong */
if (rd_count <= 0)
@ -1449,6 +1449,7 @@ static int read_string_generic(hamlib_port_t *p,
return -RIG_EIO;
}
//HAMLIB_TRACE2;
// check to see if our string startis with \...if so we need more chars
if (total_count == 0 && rxbuffer[total_count] == '\\') { rxmax = (rxmax - 1) * 5; }
@ -1456,7 +1457,27 @@ static int read_string_generic(hamlib_port_t *p,
if (total_count == rxmax) { break; }
// special read for FLRig
// rig_debug(RIG_DEBUG_TRACE, "%s: stopset=%s\n", __func__, stopset);
if (strcmp(stopset, "</methodResponse>") == 0 || timeout_retries <= 0)
{
//HAMLIB_TRACE2;
if (strstr((char*)rxbuffer, stopset))
{
//HAMLIB_TRACE2;
break;
}
else {
//HAMLIB_TRACE2;
goto shortcut;
}
}
//else
//HAMLIB_TRACE2;
//HAMLIB_TRACE2;
if (stopset && memchr(stopset, rxbuffer[total_count - 1], stopset_len))
{
if (minlen == 1) { minlen = total_count; }
@ -1482,19 +1503,6 @@ static int read_string_generic(hamlib_port_t *p,
rig_debug(RIG_DEBUG_VERBOSE,
"%s: skipping single ';' chars at beginning of reply\n", __func__);
}
// special read for FLRig
if (strcmp(stopset, "/methodResponse>") == 0 || timeout_retries <= 0)
{
if (strstr((char*)rxbuffer, stopset))
{
HAMLIB_TRACE2;
}
else {
HAMLIB_TRACE2;
goto shortcut;
}
}
/*
* Doesn't hurt anyway. But be aware, some binary protocols may have

Wyświetl plik

@ -7964,18 +7964,18 @@ static int morse_data_handler_stop(RIG *rig)
rs->morse_data_handler_priv_data;
// wait until fifo queue is flushed
HAMLIB_TRACE;
//HAMLIB_TRACE;
hl_usleep(100*1000);
HAMLIB_TRACE;
//HAMLIB_TRACE;
while(peek(rig->state.fifo_morse) >= 0)
{
HAMLIB_TRACE;
rig_debug(RIG_DEBUG_TRACE, "%s: waiting for fifo queue to flush\n", __func__);
hl_usleep(100*1000);
}
HAMLIB_TRACE;
//HAMLIB_TRACE;
hl_usleep(100*1000);
HAMLIB_TRACE;
//HAMLIB_TRACE;
if (morse_data_handler_priv != NULL)
{
if (morse_data_handler_priv->thread_id != 0)