From 4e8ba3d6f31f70f3cd373d99a69f5c334440528a Mon Sep 17 00:00:00 2001 From: "Ekki Plicht (DF4OR)" Date: Wed, 19 Dec 2018 17:11:20 +0100 Subject: [PATCH] Patch for Icom DCS code handling * Change magic numbers in icom_set|get_ctcss|dcs_sql|code functions to constants defined in src/tones.h * fix a minor bug in icom_get_dcs_code (now ignoring polarity instead of reporting invalid DCS code when sending reverse pol. DCS code) * introduce DCS codes to IC-R8600 rig backend 73, Ekki, DF4OR --- icom/icom.c | 21 +++++++++++++-------- icom/icr8600.c | 2 ++ src/tones.h | 6 ++++++ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/icom/icom.c b/icom/icom.c index 69580a9ae..3ebbe5b2c 100644 --- a/icom/icom.c +++ b/icom/icom.c @@ -2959,7 +2959,7 @@ int icom_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone) caps = rig->caps; if (caps->ctcss_list) { - for (i = 0; caps->ctcss_list[i] != 0 && i<52; i++) { + for (i = 0; caps->ctcss_list[i] != 0 && ictcss_list[i] == tone) break; } @@ -3018,7 +3018,7 @@ int icom_get_ctcss_tone(RIG *rig, vfo_t vfo, tone_t *tone) if (!caps->ctcss_list) return RIG_OK; /* check this tone exists. That's better than nothing. */ - for (i = 0; caps->ctcss_list[i] != 0 && i<52; i++) { + for (i = 0; caps->ctcss_list[i] != 0 && ictcss_list[i] == *tone) return RIG_OK; } @@ -3042,7 +3042,7 @@ int icom_set_ctcss_sql(RIG *rig, vfo_t vfo, tone_t tone) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); caps = rig->caps; - for (i = 0; caps->ctcss_list[i] != 0 && i<52; i++) { + for (i = 0; caps->ctcss_list[i] != 0 && ictcss_list[i] == tone) break; } @@ -3097,7 +3097,7 @@ int icom_get_ctcss_sql(RIG *rig, vfo_t vfo, tone_t *tone) *tone = from_bcd_be(tonebuf+2, tone_len*2); /* check this tone exists. That's better than nothing. */ - for (i = 0; caps->ctcss_list[i] != 0 && i<52; i++) { + for (i = 0; caps->ctcss_list[i] != 0 && ictcss_list[i] == *tone) return RIG_OK; } @@ -3121,13 +3121,14 @@ int icom_set_dcs_code(RIG *rig, vfo_t vfo, tone_t code) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); caps = rig->caps; - for (i = 0; caps->dcs_list[i] != 0 && i<104; i++) { + for (i = 0; caps->dcs_list[i] != 0 && idcs_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); @@ -3171,11 +3172,15 @@ int icom_get_dcs_code(RIG *rig, vfo_t vfo, tone_t *code) return -RIG_ERJCTED; } - code_len -= 2; - *code = from_bcd_be(codebuf+2, code_len*2); + /* 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<104; i++) { + for (i = 0; caps->dcs_list[i] != 0 && idcs_list[i] == *code) return RIG_OK; } diff --git a/icom/icr8600.c b/icom/icr8600.c index 9ecb31755..4224c31b8 100644 --- a/icom/icr8600.c +++ b/icom/icr8600.c @@ -265,6 +265,8 @@ const struct rig_caps icr8600_caps = { .get_powerstat = icom_get_powerstat, .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_channel = icr8600_set_channel, .get_channel = icr8600_get_channel, diff --git a/src/tones.h b/src/tones.h index 2a78752f9..852554330 100644 --- a/src/tones.h +++ b/src/tones.h @@ -42,6 +42,8 @@ static const tone_t static_full_ctcss_list[] = FULL_CTCSS_LIST }; +#define FULL_CTCSS_LIST_COUNT 52 + /* * 50 CTCSS sub-audible tones, from 67.0Hz to 254.1Hz @@ -63,6 +65,8 @@ static const tone_t static_common_ctcss_list[] = COMMON_CTCSS_LIST }; +#define COMMON_CTCSS_LIST_COUNT 50 + /* * 104 DCS codes @@ -84,6 +88,7 @@ static const tone_t static_common_dcs_list[] = COMMON_DCS_LIST }; +#define COMMON_DCS_LIST_COUNT 104 /* * 106 DCS codes @@ -105,6 +110,7 @@ static const tone_t static_full_dcs_list[] = FULL_DCS_LIST }; +#define FULL_DCS_LIST_COUNT 106 /* * These arrays cannot be shared on Win32 systems,