diff --git a/rigs/icom/icom.c b/rigs/icom/icom.c index 5799704b6..4ce338c2e 100644 --- a/rigs/icom/icom.c +++ b/rigs/icom/icom.c @@ -1324,14 +1324,7 @@ int icom_set_freq(RIG *rig, vfo_t vfo, freq_t freq) RETURNFUNC2(retval); } - if (ICOM_IS_ID5100 || ICOM_IS_ID4100 || ICOM_IS_ID31 || ICOM_IS_ID51) - { - freq_len = 5; - } - else - { - freq_len = priv->civ_731_mode ? 4 : 5; - } + freq_len = priv->civ_731_mode ? 4 : 5; /* * to_bcd requires nibble len diff --git a/rigs/icom/icom.h b/rigs/icom/icom.h index 03574dc3f..254d89f96 100644 --- a/rigs/icom/icom.h +++ b/rigs/icom/icom.h @@ -31,7 +31,7 @@ #include #endif -#define BACKEND_VER "20230103" +#define BACKEND_VER "20230104" #define ICOM_IS_ID31 rig_is_model(rig, RIG_MODEL_ID31) #define ICOM_IS_ID51 rig_is_model(rig, RIG_MODEL_ID51) diff --git a/rigs/icom/id5100.c b/rigs/icom/id5100.c index 2448ff8fb..7e32e4b47 100644 --- a/rigs/icom/id5100.c +++ b/rigs/icom/id5100.c @@ -26,6 +26,8 @@ #include "hamlib/rig.h" #include "idx_builtin.h" #include "icom.h" +#include "icom_defs.h" +#include "frame.h" /* * Specs and protocol details comes from the chapter 13 of ID-5100_Full-Inst_Manual.pdf @@ -39,7 +41,7 @@ * - Single/dual watch (RIG_LEVEL_BALANCE) */ -#define ID5100_MODES (RIG_MODE_FM|RIG_MODE_DSTAR) +#define ID5100_MODES (RIG_MODE_AM|RIG_MODE_AMN|RIG_MODE_FM|RIG_MODE_FMN|RIG_MODE_DSTAR) #define ID5100_ALL_RX_MODES (RIG_MODE_AM|ID5100_MODES) #define ID5100_VFO_ALL (RIG_VFO_MAIN|RIG_VFO_SUB) @@ -70,7 +72,61 @@ */ #define ID5100_STR_CAL UNKNOWN_IC_STR_CAL +int id5100_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) +{ + int retval; + unsigned char modebuf; + unsigned char ackbuf[MAXFRAMELEN]; + int icmode = 2; + int ack_len = sizeof(ackbuf); + switch (mode) + { + case RIG_MODE_AM: icmode = 2; modebuf = 1; break; + + case RIG_MODE_AMN: icmode = 2; modebuf = 2; break; + + case RIG_MODE_FM: icmode = 5; modebuf = 1; break; + + case RIG_MODE_FMN: icmode = 5; modebuf = 2; break; + + case RIG_MODE_DSTAR: icmode = 17; modebuf = 1; break; + + default: + rig_debug(RIG_DEBUG_ERR, "%s: Unknown mode=%s\n", __func__, rig_strrmode(mode)); + return -RIG_EINVAL; + } + + retval = icom_transaction(rig, C_SET_MODE, icmode, &modebuf, 1, ackbuf, + &ack_len); + + return retval; +} + +int id5100_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) +{ + int retval; + int mode_len; + unsigned char modebuf[4]; + + retval = icom_transaction(rig, C_RD_MODE, -1, NULL, 0, modebuf, &mode_len); + + if (retval != RIG_OK) + { + return retval; + } + + switch (modebuf[1]) + { + case 2: *mode = modebuf[3] == 1 ? RIG_MODE_AM : RIG_MODE_AMN; break; + + case 5: *mode = modebuf[3] == 1 ? RIG_MODE_FM : RIG_MODE_FMN; break; + + case 17: *mode = RIG_MODE_DSTAR; break; + } + + return RIG_OK; +} /* */ @@ -102,7 +158,7 @@ const struct rig_caps id5100_caps = .write_delay = 0, .post_write_delay = 0, .timeout = 1000, - .retry = 3, + .retry = 0, .has_get_func = ID5100_FUNC_ALL, .has_set_func = ID5100_FUNC_ALL, .has_get_level = ID5100_LEVEL_ALL, @@ -184,8 +240,8 @@ const struct rig_caps id5100_caps = .set_freq = icom_set_freq, .get_freq = icom_get_freq, - .set_mode = icom_set_mode, - .get_mode = icom_get_mode, + .set_mode = id5100_set_mode, + .get_mode = id5100_get_mode, .set_vfo = icom_set_vfo, .set_powerstat = icom_set_powerstat,