diff --git a/dummy/flrig.c b/dummy/flrig.c index 2b84d460f..cae3bdfcc 100644 --- a/dummy/flrig.c +++ b/dummy/flrig.c @@ -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; } /* diff --git a/include/hamlib/rig.h b/include/hamlib/rig.h index 856b6e2ce..dc8d675fa 100644 --- a/include/hamlib/rig.h +++ b/include/hamlib/rig.h @@ -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); diff --git a/src/misc.c b/src/misc.c index af33c55b0..84aa4fdf5 100644 --- a/src/misc.c +++ b/src/misc.c @@ -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 {