MCPcopy Create free account
hub / github.com/Hamlib/Hamlib / read_string_generic

Function read_string_generic

src/iofunc.c:1316–1525  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1314}
1315
1316static int read_string_generic(hamlib_port_t *p,
1317 unsigned char *rxbuffer,
1318 size_t rxmax,
1319 const char *stopset,
1320 int stopset_len,
1321 int flush_flag,
1322 int expected_len,
1323 int direct)
1324{
1325 struct timeval start_time, end_time, elapsed_time;
1326 int total_count = 0;
1327 int i = 0;
1328 static int minlen = 1; // dynamic minimum length of rig response data
1329
1330 if (p != NULL && !p->asyncio && !direct)
1331 {
1332 return -RIG_EINTERNAL;
1333 }
1334
1335 rig_debug(RIG_DEBUG_CACHE, "%s called, rxmax=%d direct=%d, expected_len=%d\n",
1336 __func__,
1337 (int)rxmax, direct, expected_len);
1338
1339 if (!p || !rxbuffer)
1340 {
1341 rig_debug(RIG_DEBUG_ERR, "%s: error p=%p, rxbuffer=%p\n", __func__, p,
1342 rxbuffer);
1343 return -RIG_EINVAL;
1344 }
1345
1346 if (rxmax < 1)
1347 {
1348 rig_debug(RIG_DEBUG_ERR, "%s: error rxmax=%ld\n", __func__, (long)rxmax);
1349 return 0;
1350 }
1351
1352 /* Store the time of the read loop start */
1353 gettimeofday(&start_time, NULL);
1354
1355 memset(rxbuffer, 0, rxmax);
1356
1357 short timeout_retries = p->timeout_retry;
1358
1359 while (total_count < rxmax - 1) // allow 1 byte for end-of-string
1360 {
1361 ssize_t rd_count = 0;
1362 int result;
1363 result = port_wait_for_data(p, direct);
1364
1365 if (result == -RIG_ETIMEOUT)
1366 {
1367 if (timeout_retries > 0)
1368 {
1369 timeout_retries--;
1370 rig_debug(RIG_DEBUG_CACHE, "%s(%d): retrying read timeout %d/%d timeout=%d\n",
1371 __func__, __LINE__,
1372 p->timeout_retry - timeout_retries, p->timeout_retry, p->timeout);
1373 hl_usleep(10 * 1000);

Callers 2

read_stringFunction · 0.85
read_string_directFunction · 0.85

Calls 6

rig_debugFunction · 0.85
gettimeofdayFunction · 0.85
port_wait_for_dataFunction · 0.85
hl_usleepFunction · 0.85
dump_hexFunction · 0.85
port_read_genericFunction · 0.85

Tested by

no test coverage detected