Add rig_strrmodes function and fix flrig to print mode list correctly

This commit is contained in:
Michael Black 2019-12-12 09:13:30 -06:00
parent 011efe0452
commit b3c6b9d707
No known key found for this signature in database
GPG Key ID: 6599353EC683404D
3 changed files with 46 additions and 4 deletions

View File

@ -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;
}
/*

View File

@ -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);

View File

@ -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
{