diff --git a/icom/icom.c b/icom/icom.c index 11ad13842..fb5330d4d 100644 --- a/icom/icom.c +++ b/icom/icom.c @@ -4267,6 +4267,105 @@ int icom_get_dcs_code(RIG *rig, vfo_t vfo, tone_t *code) return -RIG_EPROTO; } +/* + * icom_set_dcs_sql + * Assumes rig!=NULL, rig->state.priv!=NULL + */ +int icom_set_dcs_sql(RIG *rig, vfo_t vfo, tone_t code) +{ + const struct rig_caps *caps; + unsigned char codebuf[MAXFRAMELEN], ackbuf[MAXFRAMELEN]; + int code_len, ack_len = sizeof(ackbuf), retval; + int i; + + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + caps = rig->caps; + + for (i = 0; caps->dcs_list[i] != 0 && i < COMMON_DCS_LIST_COUNT; i++) + { + if (caps->dcs_list[i] == code) + { + break; + } + } + + if (caps->dcs_list[i] != code) + { + return -RIG_EINVAL; + } + + /* DCS Polarity ignored, by setting code_len to 3 it's forced to 0 (= Tx:norm, Rx:norm). */ + code_len = 3; + to_bcd_be(codebuf, code, code_len * 2); + + retval = icom_transaction(rig, C_SET_TONE, S_TONE_DTCS, + codebuf, code_len, ackbuf, &ack_len); + + if (retval != RIG_OK) + { + return retval; + } + + if (ack_len != 1 || ackbuf[0] != ACK) + { + rig_debug(RIG_DEBUG_ERR, "%s: ack NG (%#.2x), len=%d\n", __func__, ackbuf[0], + ack_len); + return -RIG_ERJCTED; + } + + return RIG_OK; +} + +/* + * icom_get_dcs_sql + * Assumes rig!=NULL, rig->state.priv!=NULL + */ +int icom_get_dcs_sql(RIG *rig, vfo_t vfo, tone_t *code) +{ + const struct rig_caps *caps; + unsigned char codebuf[MAXFRAMELEN]; + int code_len, retval; + int i; + + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + caps = rig->caps; + + retval = icom_transaction(rig, C_SET_TONE, S_TONE_DTCS, NULL, 0, + codebuf, &code_len); + + if (retval != RIG_OK) + { + return retval; + } + + /* cn,sc,data*3 */ + if (code_len != 5) + { + rig_debug(RIG_DEBUG_ERR, "%s: ack NG (%#.2x), len=%d\n", __func__, codebuf[0], + code_len); + return -RIG_ERJCTED; + } + + /* buf is cn,sc, polarity, code_lo, code_hi, so code bytes start at 3, len is 2 + polarity is not decoded yet, hard to do without breaking ABI + */ + + code_len -= 3; + *code = from_bcd_be(codebuf + 3, code_len * 2); + + /* check this code exists. That's better than nothing. */ + for (i = 0; caps->dcs_list[i] != 0 && i < COMMON_DCS_LIST_COUNT; i++) + { + if (caps->dcs_list[i] == *code) + { + return RIG_OK; + } + } + + rig_debug(RIG_DEBUG_ERR, "%s: DTCS NG (%#.2x)\n", __func__, codebuf[2]); + return -RIG_EPROTO; +} + /* * icom_set_powerstat * Assumes rig!=NULL, rig->state.priv!=NULL diff --git a/icom/icom.h b/icom/icom.h index 49445b32b..2911c832d 100644 --- a/icom/icom.h +++ b/icom/icom.h @@ -213,6 +213,8 @@ int icom_set_ctcss_sql(RIG *rig, vfo_t vfo, tone_t tone); int icom_get_ctcss_sql(RIG *rig, vfo_t vfo, tone_t *tone); int icom_set_dcs_code(RIG *rig, vfo_t vfo, tone_t code); int icom_get_dcs_code(RIG *rig, vfo_t vfo, tone_t *code); +int icom_set_dcs_sql(RIG *rig, vfo_t vfo, tone_t code); +int icom_get_dcs_sql(RIG *rig, vfo_t vfo, tone_t *code); int icom_set_bank(RIG *rig, vfo_t vfo, int bank); int icom_set_mem(RIG *rig, vfo_t vfo, int ch); int icom_vfo_op(RIG *rig, vfo_t vfo, vfo_op_t op); diff --git a/icom/icr30.c b/icom/icr30.c index b184825a5..373ba4645 100644 --- a/icom/icr30.c +++ b/icom/icr30.c @@ -227,6 +227,6 @@ const struct rig_caps icr30_caps = .get_dcd = icom_get_dcd, .set_ctcss_sql = icom_set_ctcss_sql, .get_ctcss_sql = icom_get_ctcss_sql, - .set_dcs_code = icom_set_dcs_code, - .get_dcs_code = icom_get_dcs_code, + .set_dcs_sql = icom_set_dcs_sql, + .get_dcs_sql = icom_get_dcs_sql, }; diff --git a/icom/icr6.c b/icom/icr6.c index 0282260b1..fe0476ea1 100644 --- a/icom/icr6.c +++ b/icom/icr6.c @@ -168,6 +168,6 @@ const struct rig_caps icr6_caps = .get_dcd = icom_get_dcd, .set_ctcss_sql = icom_set_ctcss_sql, .get_ctcss_sql = icom_get_ctcss_sql, - .set_dcs_code = icom_set_dcs_code, - .get_dcs_code = icom_get_dcs_code, + .set_dcs_sql = icom_set_dcs_sql, + .get_dcs_sql = icom_get_dcs_sql, }; diff --git a/icom/icr8600.c b/icom/icr8600.c index 96a0242f9..c3cc2297c 100644 --- a/icom/icr8600.c +++ b/icom/icr8600.c @@ -230,8 +230,8 @@ const struct rig_caps icr8600_caps = .get_ts = icom_get_ts, .set_ctcss_sql = icom_set_ctcss_sql, .get_ctcss_sql = icom_get_ctcss_sql, - .set_dcs_code = icom_set_dcs_code, - .get_dcs_code = icom_get_dcs_code, + .set_dcs_sql = icom_set_dcs_sql, + .get_dcs_sql = icom_get_dcs_sql, }; diff --git a/icom/icr9500.c b/icom/icr9500.c index 1770f3410..e814f8d53 100644 --- a/icom/icr9500.c +++ b/icom/icr9500.c @@ -192,8 +192,8 @@ const struct rig_caps icr9500_caps = .get_rptr_offs = icom_get_rptr_offs, .set_ctcss_sql = icom_set_ctcss_sql, .get_ctcss_sql = icom_get_ctcss_sql, - .set_dcs_sql = icom_set_dcs_code, - .get_dcs_sql = icom_get_dcs_code, + .set_dcs_sql = icom_set_dcs_sql, + .get_dcs_sql = icom_get_dcs_sql, .set_ts = icom_set_ts, .get_ts = icom_get_ts, diff --git a/src/tones.c b/src/tones.c index 526d3c481..857bfc68d 100644 --- a/src/tones.c +++ b/src/tones.c @@ -82,7 +82,7 @@ const tone_t full_dcs_list[] = { FULL_DCS_LIST }; * \param tone The tone to set to * * Sets the current Continuous Tone Controlled Squelch System (CTCSS) - * sub-audible tone frequency. + * sub-audible tone frequency for the transmitter only. * \note the \a tone integer is NOT in Hz, but in tenth of Hz! This way, * if you want to set a subaudible tone of 88.5 Hz for example, * then pass 885 to this function. @@ -152,7 +152,7 @@ int HAMLIB_API rig_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone) * \param tone The location where to store the current tone * * Retrieves the current Continuous Tone Controlled Squelch System (CTCSS) - * sub-audible tone frequency. + * sub-audible tone frequency for the transmitter only. * \note the \a *tone integer is NOT in Hz, but in tenth of Hz! This way, * if the function rig_get_ctcss_tone() returns a subaudible tone of 885 * for example, then the real tone is 88.5 Hz.