Let kenwood serial read remove non-printable chars from responses

Should help it be a bit more robust against bad serial data like this
https://github.com/Hamlib/Hamlib/issues/1652
pull/1662/head
Michael Black W9MDB 2025-01-07 07:52:08 -06:00
rodzic b2b8586c93
commit d1e0e3f204
2 zmienionych plików z 22 dodań i 1 usunięć

Wyświetl plik

@ -231,6 +231,23 @@ struct confparams kenwood_cfg_params[] =
{ RIG_CONF_END, NULL, }
};
int remove_nonprint(char *s)
{
int i, j = 0;
if (s == NULL) return 0;
for (i = 0; s[i] != '\0'; ++i)
{
if (isprint((unsigned char)s[i]))
{
s[j++] = s[i]; // Copy printable character
}
}
s[j] = '\0'; // Null-terminate the string
return j; // Return the new length of the string
}
/**
* kenwood_transaction
@ -424,6 +441,10 @@ transaction_read:
rig_debug(RIG_DEBUG_TRACE, "%s: read_string len=%d '%s'\n", __func__,
(int)strlen(buffer), buffer);
// this fixes the case when some corrupt data is returned
// let's us be a little more robust about funky serial data
remove_nonprint(buffer);
if (retval < 0)
{
rig_debug(RIG_DEBUG_WARN,

Wyświetl plik

@ -28,7 +28,7 @@
#include "token.h"
#include "idx_builtin.h"
#define BACKEND_VER "20241022"
#define BACKEND_VER "20250107"
#define EOM_KEN ';'
#define EOM_TH '\r'