diff --git a/openrtx/include/core/cps.h b/openrtx/include/core/cps.h index 76e06d0d..b24bedc2 100644 --- a/openrtx/include/core/cps.h +++ b/openrtx/include/core/cps.h @@ -40,19 +40,69 @@ ******************************************************************************/ /** - * Data structure containing the tone information for analog FM channels. - * This is just a lookup table for the CTCSS frequencies and is not actually - * present in the codeplug binary data. + * Enumeration type for CTCSS frequencies. */ -#define MAX_TONE_INDEX 50 -static const uint16_t ctcss_tone[MAX_TONE_INDEX] = +enum CTCSSfreq { - 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 + CTCSS_67_0 = 0, + CTCSS_69_3, + CTCSS_71_9, + CTCSS_74_4, + CTCSS_77_0, + CTCSS_79_7, + CTCSS_82_5, + CTCSS_85_4, + CTCSS_88_5, + CTCSS_91_5, + CTCSS_94_8, + CTCSS_97_4, + CTCSS_100_0, + CTCSS_103_5, + CTCSS_107_2, + CTCSS_110_9, + CTCSS_114_8, + CTCSS_118_8, + CTCSS_123_0, + CTCSS_127_3, + CTCSS_131_8, + CTCSS_136_5, + CTCSS_141_3, + CTCSS_146_2, + CTCSS_151_4, + CTCSS_156_7, + CTCSS_159_8, + CTCSS_162_2, + CTCSS_165_5, + CTCSS_167_9, + CTCSS_171_3, + CTCSS_173_8, + CTCSS_177_3, + CTCSS_179_9, + CTCSS_183_5, + CTCSS_186_2, + CTCSS_189_9, + CTCSS_192_8, + CTCSS_196_6, + CTCSS_199_5, + CTCSS_203_5, + CTCSS_206_5, + CTCSS_210_7, + CTCSS_218_1, + CTCSS_225_7, + CTCSS_229_1, + CTCSS_233_6, + CTCSS_241_8, + CTCSS_250_3, + CTCSS_254_1, + + CTCSS_FREQ_NUM }; +/** + * CTCSS tone table for fast index-to-frequency conversion + */ +extern const uint16_t ctcss_tone[]; + /** * Data structure defining an analog-specific channel information such as tones. */ diff --git a/openrtx/include/core/utils.h b/openrtx/include/core/utils.h index 6c438dc4..08dee873 100644 --- a/openrtx/include/core/utils.h +++ b/openrtx/include/core/utils.h @@ -74,6 +74,14 @@ void stripTrailingZeroes(char *str); */ uint8_t rssiToSlevel(const rssi_t rssi); +/** + * Retrieve the CTCSS tone index given its frequency in tenths of Hz. + * + * @param freq: CTCSS frequency + * @return tone index or 255 if the tone has not been found + */ +uint8_t ctcssFreqToIndex(const uint16_t freq); + #ifdef __cplusplus } #endif diff --git a/openrtx/src/core/cps.c b/openrtx/src/core/cps.c index e5c42f5b..c5e8cecc 100644 --- a/openrtx/src/core/cps.c +++ b/openrtx/src/core/cps.c @@ -21,6 +21,14 @@ #include #include +const uint16_t ctcss_tone[CTCSS_FREQ_NUM] = +{ + 670, 693, 719, 744, 770, 797, 825, 854, 885, 915, 948, 974, 1000, 1035, + 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 +}; + channel_t cps_getDefaultChannel() { channel_t channel; diff --git a/openrtx/src/core/utils.c b/openrtx/src/core/utils.c index decdf10c..468d1281 100644 --- a/openrtx/src/core/utils.c +++ b/openrtx/src/core/utils.c @@ -21,6 +21,7 @@ #include #include #include +#include uint8_t interpCalParameter(const freq_t freq, const freq_t *calPoints, const uint8_t *param, const uint8_t elems) @@ -94,3 +95,14 @@ uint8_t rssiToSlevel(const rssi_t rssi) // For S1 - S9 use 6dB increase per S-Point return (uint8_t)(127 + rssi) / 6; } + +uint8_t ctcssFreqToIndex(const uint16_t freq) +{ + for(uint8_t idx = 0; idx < CTCSS_FREQ_NUM; idx += 1) + { + if(ctcss_tone[idx] == freq) + return idx; + } + + return 255; +} diff --git a/openrtx/src/ui/default/ui.c b/openrtx/src/ui/default/ui.c index 66a62db6..816fb49d 100644 --- a/openrtx/src/ui/default/ui.c +++ b/openrtx/src/ui/default/ui.c @@ -916,14 +916,14 @@ static void _ui_fsm_menuMacro(kbd_msg_t msg, bool *sync_rtx) { if(state.channel.fm.txTone == 0) { - state.channel.fm.txTone = MAX_TONE_INDEX-1; + state.channel.fm.txTone = CTCSS_FREQ_NUM-1; } else { state.channel.fm.txTone--; } - state.channel.fm.txTone %= MAX_TONE_INDEX; + state.channel.fm.txTone %= CTCSS_FREQ_NUM; state.channel.fm.rxTone = state.channel.fm.txTone; *sync_rtx = true; vp_announceCTCSS(state.channel.fm.rxToneEn, @@ -938,7 +938,7 @@ static void _ui_fsm_menuMacro(kbd_msg_t msg, bool *sync_rtx) if(state.channel.mode == OPMODE_FM) { state.channel.fm.txTone++; - state.channel.fm.txTone %= MAX_TONE_INDEX; + state.channel.fm.txTone %= CTCSS_FREQ_NUM; state.channel.fm.rxTone = state.channel.fm.txTone; *sync_rtx = true; vp_announceCTCSS(state.channel.fm.rxToneEn, diff --git a/platform/drivers/CPS/cps_io_native_GDx.c b/platform/drivers/CPS/cps_io_native_GDx.c index dee5d919..6e54073b 100644 --- a/platform/drivers/CPS/cps_io_native_GDx.c +++ b/platform/drivers/CPS/cps_io_native_GDx.c @@ -154,7 +154,7 @@ int cps_readChannel(channel_t *channel, uint16_t pos) // TODO: Implement binary search to speed up this lookup if((rx_css != 0) && (rx_css != 0xFFFF)) { - for(int i = 0; i < MAX_TONE_INDEX; i++) + for(int i = 0; i < CTCSS_FREQ_NUM; i++) { if(ctcss_tone[i] == ((uint16_t) bcdToBin(rx_css))) { @@ -167,7 +167,7 @@ int cps_readChannel(channel_t *channel, uint16_t pos) if((tx_css != 0) && (tx_css != 0xFFFF)) { - for(int i = 0; i < MAX_TONE_INDEX; i++) + for(int i = 0; i < CTCSS_FREQ_NUM; i++) { if(ctcss_tone[i] == ((uint16_t) bcdToBin(tx_css))) { diff --git a/platform/drivers/CPS/cps_io_native_MD3x0.c b/platform/drivers/CPS/cps_io_native_MD3x0.c index feaa870e..7b4e93f8 100644 --- a/platform/drivers/CPS/cps_io_native_MD3x0.c +++ b/platform/drivers/CPS/cps_io_native_MD3x0.c @@ -107,7 +107,7 @@ int cps_readChannel(channel_t *channel, uint16_t pos) // TODO: Implement binary search to speed up this lookup if((rx_css != 0) && (rx_css != 0xFFFF)) { - for(int i = 0; i < MAX_TONE_INDEX; i++) + for(int i = 0; i < CTCSS_FREQ_NUM; i++) { if(ctcss_tone[i] == ((uint16_t) bcdToBin(rx_css))) { @@ -120,7 +120,7 @@ int cps_readChannel(channel_t *channel, uint16_t pos) if((tx_css != 0) && (tx_css != 0xFFFF)) { - for(int i = 0; i < MAX_TONE_INDEX; i++) + for(int i = 0; i < CTCSS_FREQ_NUM; i++) { if(ctcss_tone[i] == ((uint16_t) bcdToBin(tx_css))) { diff --git a/platform/drivers/CPS/cps_io_native_MD9600.c b/platform/drivers/CPS/cps_io_native_MD9600.c index 6a80ea75..912dd8aa 100644 --- a/platform/drivers/CPS/cps_io_native_MD9600.c +++ b/platform/drivers/CPS/cps_io_native_MD9600.c @@ -96,7 +96,7 @@ static int _readChannelAtAddress(channel_t *channel, uint32_t addr) // TODO: Implement binary search to speed up this lookup if((rx_css != 0) && (rx_css != 0xFFFF)) { - for(int i = 0; i < MAX_TONE_INDEX; i++) + for(int i = 0; i < CTCSS_FREQ_NUM; i++) { if(ctcss_tone[i] == ((uint16_t) bcdToBin(rx_css))) { @@ -109,7 +109,7 @@ static int _readChannelAtAddress(channel_t *channel, uint32_t addr) if((tx_css != 0) && (tx_css != 0xFFFF)) { - for(int i = 0; i < MAX_TONE_INDEX; i++) + for(int i = 0; i < CTCSS_FREQ_NUM; i++) { if(ctcss_tone[i] == ((uint16_t) bcdToBin(tx_css))) { diff --git a/platform/drivers/CPS/cps_io_native_MDUV3x0.c b/platform/drivers/CPS/cps_io_native_MDUV3x0.c index 1cf7d2cc..6150ba9d 100644 --- a/platform/drivers/CPS/cps_io_native_MDUV3x0.c +++ b/platform/drivers/CPS/cps_io_native_MDUV3x0.c @@ -95,7 +95,7 @@ static int _readChannelAtAddress(channel_t *channel, uint32_t addr) // TODO: Implement binary search to speed up this lookup if((rx_css != 0) && (rx_css != 0xFFFF)) { - for(int i = 0; i < MAX_TONE_INDEX; i++) + for(int i = 0; i < CTCSS_FREQ_NUM; i++) { if(ctcss_tone[i] == ((uint16_t) bcdToBin(rx_css))) { @@ -108,7 +108,7 @@ static int _readChannelAtAddress(channel_t *channel, uint32_t addr) if((tx_css != 0) && (tx_css != 0xFFFF)) { - for(int i = 0; i < MAX_TONE_INDEX; i++) + for(int i = 0; i < CTCSS_FREQ_NUM; i++) { if(ctcss_tone[i] == ((uint16_t) bcdToBin(tx_css))) {