From adc48efb19a703184e148fd63c85a1fbfb824fd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Izzo?= Date: Tue, 5 Jan 2021 11:11:33 +0100 Subject: [PATCH] Implement CTCSS available tones array Now the CTCSS tones are taken from an array and indexed from that array. A macro that sets the tone has been implemented. --- openrtx/include/cps.h | 16 ++++++++++++---- openrtx/src/state.c | 4 ++-- openrtx/src/threads.c | 4 ++-- openrtx/src/ui.c | 11 +++++++++-- platform/drivers/NVM/nvmem_MD3x0.c | 27 +++++++++++++++++++++++++-- platform/drivers/NVM/nvmem_MDUV3x0.c | 27 +++++++++++++++++++++++++-- 6 files changed, 75 insertions(+), 14 deletions(-) diff --git a/openrtx/include/cps.h b/openrtx/include/cps.h index b06f6ab7..b912669b 100644 --- a/openrtx/include/cps.h +++ b/openrtx/include/cps.h @@ -41,12 +41,20 @@ enum admit_t * Data structure containing all and only the information for analog FM channels, * like CTC/DCS tones. */ +#define MAX_TONE_INDEX 50 +static const uint16_t ctcss_tone[MAX_TONE_INDEX] = { + 670, 693, 719, 744, 770, 797, 825, 854, 885, 915, 948, 974, 1000, 1034, + 1072, 1109, 1148, 1188, 1230, 1273, 1318, 1365, 1413, 1462, 1514, 1567, + 1598, 1622, 1655, 1679, 1713, 1738, 1773, 1799, 1835, 1862, 1899, 1928, + 1966, 1995, 2035, 2065, 2107, 2181, 2257, 2291, 2336, 2418, 2503, 2541 +}; + typedef struct { - uint16_t rxToneEn : 1, /**< RX CTC/DCS tone enable */ - rxTone : 15; /**< RX CTC/DCS tone, squelch opens on match */ - uint16_t txToneEn : 1, /**< TX CTC/DCS tone enable */ - txTone : 15; /**< TX CTC/DCS tonem sent alongside voidce */ + uint8_t rxToneEn : 1, /**< RX CTC/DCS tone enable */ + rxTone : 7; /**< RX CTC/DCS tone index, squelch opens on match */ + uint8_t txToneEn : 1, /**< TX CTC/DCS tone enable */ + txTone : 7; /**< TX CTC/DCS tone index, sent alongside voice */ } fmInfo_t; /** diff --git a/openrtx/src/state.c b/openrtx/src/state.c index 71c9d97b..4e1e2f4a 100644 --- a/openrtx/src/state.c +++ b/openrtx/src/state.c @@ -44,9 +44,9 @@ void state_init() state.channel.rx_frequency = 430000000; state.channel.tx_frequency = 430000000; state.channel.fm.rxToneEn = 0; - state.channel.fm.rxTone = 719; + state.channel.fm.rxTone = 2; // 71.9Hz state.channel.fm.txToneEn = 1; - state.channel.fm.txTone = 719; + state.channel.fm.txTone = 2; // 71.9Hz state.rtxStatus = RTX_OFF; state.sqlLevel = 3; diff --git a/openrtx/src/threads.c b/openrtx/src/threads.c index 5904d787..f083128e 100644 --- a/openrtx/src/threads.c +++ b/openrtx/src/threads.c @@ -119,9 +119,9 @@ static void ui_task(void *arg) rtx_cfg.txPower = state.channel.power; rtx_cfg.sqlLevel = state.channel.squelch; rtx_cfg.rxToneEn = state.channel.fm.rxToneEn; - rtx_cfg.rxTone = state.channel.fm.rxTone; + rtx_cfg.rxTone = ctcss_tone[state.channel.fm.rxTone]; rtx_cfg.txToneEn = state.channel.fm.txToneEn; - rtx_cfg.txTone = state.channel.fm.txTone; + rtx_cfg.txTone = ctcss_tone[state.channel.fm.txTone]; OSMutexPost(&rtx_mutex, OS_OPT_POST_NONE, &os_err); rtx_configure(&rtx_cfg); diff --git a/openrtx/src/ui.c b/openrtx/src/ui.c index 1978f41f..f4ec7d20 100644 --- a/openrtx/src/ui.c +++ b/openrtx/src/ui.c @@ -707,8 +707,9 @@ bool _ui_drawMenuMacro(state_t* last_state) { // First row gfx_print(layout.line1_left, "1", layout.top_font, TEXT_ALIGN_LEFT, yellow_fab413); - char code_str[9] = { 0 }; - snprintf(code_str, 9, " %3.1f", last_state->channel.fm.txTone/10.0f); + char code_str[11] = { 0 }; + snprintf(code_str, 11, " %6.1f", + ctcss_tone[last_state->channel.fm.txTone]/10.0f); gfx_print(layout.line1_left, code_str, layout.top_font, TEXT_ALIGN_LEFT, color_white); gfx_print(layout.line1_left, "2 ", layout.top_font, TEXT_ALIGN_CENTER, @@ -1037,6 +1038,12 @@ void ui_updateFSM(event_t event, bool *sync_rtx) uint8_t tone_flags = tone_tx_enable << 1 | tone_rx_enable; switch(input_number) { + case 1: + state.channel.fm.txTone++; + state.channel.fm.txTone %= MAX_TONE_INDEX; + state.channel.fm.rxTone = state.channel.fm.txTone; + *sync_rtx = true; + break; case 2: tone_flags++; tone_flags %= 4; diff --git a/platform/drivers/NVM/nvmem_MD3x0.c b/platform/drivers/NVM/nvmem_MD3x0.c index 2b343107..47308f4d 100644 --- a/platform/drivers/NVM/nvmem_MD3x0.c +++ b/platform/drivers/NVM/nvmem_MD3x0.c @@ -231,9 +231,32 @@ int nvm_readChannelData(channel_t *channel, uint16_t pos) if(channel->mode == FM) { channel->fm.rxToneEn = chData.ctcss_dcs_receive != 0; - channel->fm.rxTone = chData.ctcss_dcs_receive; channel->fm.txToneEn = chData.ctcss_dcs_transmit != 0; - channel->fm.txTone = chData.ctcss_dcs_transmit; + // TODO: Implement binary search to speed up this lookup + if (channel->fm.rxToneEn) + { + for(int i = 0; i < MAX_TONE_INDEX; i++) + { + if (ctcss_tone[i] == chData.ctcss_dcs_receive) + { + channel->fm.rxTone = i; + break; + } + } + + } + if (channel->fm.txToneEn) + { + for(int i = 0; i < MAX_TONE_INDEX; i++) + { + if (ctcss_tone[i] == chData.ctcss_dcs_transmit) + { + channel->fm.txTone = i; + break; + } + } + } + // TODO: Implement warning screen if tone was not found } else if(channel->mode == DMR) { diff --git a/platform/drivers/NVM/nvmem_MDUV3x0.c b/platform/drivers/NVM/nvmem_MDUV3x0.c index 3e318875..fb3e59a1 100644 --- a/platform/drivers/NVM/nvmem_MDUV3x0.c +++ b/platform/drivers/NVM/nvmem_MDUV3x0.c @@ -264,9 +264,32 @@ int nvm_readChannelData(channel_t *channel, uint16_t pos) if(channel->mode == FM) { channel->fm.rxToneEn = chData.ctcss_dcs_receive != 0; - channel->fm.rxTone = chData.ctcss_dcs_receive; channel->fm.txToneEn = chData.ctcss_dcs_transmit != 0; - channel->fm.txTone = chData.ctcss_dcs_transmit; + // TODO: Implement binary search to speed up this lookup + if (channel->fm.rxToneEn) + { + for(int i = 0; i < MAX_TONE_INDEX; i++) + { + if (ctcss_tone[i] == chData.ctcss_dcs_receive) + { + channel->fm.rxTone = i; + break; + } + } + + } + if (channel->fm.txToneEn) + { + for(int i = 0; i < MAX_TONE_INDEX; i++) + { + if (ctcss_tone[i] == chData.ctcss_dcs_transmit) + { + channel->fm.txTone = i; + break; + } + } + } + // TODO: Implement warning screen if tone was not found } else if(channel->mode == DMR) {