CPS: added enumeration type for CTCSS tone index

This commit is contained in:
Silvano Seva 2025-03-01 18:55:47 +01:00
parent 4f791a8f09
commit 1099f0f7a3
9 changed files with 98 additions and 20 deletions

View File

@ -40,19 +40,69 @@
******************************************************************************/ ******************************************************************************/
/** /**
* Data structure containing the tone information for analog FM channels. * Enumeration type for CTCSS frequencies.
* This is just a lookup table for the CTCSS frequencies and is not actually
* present in the codeplug binary data.
*/ */
#define MAX_TONE_INDEX 50 enum CTCSSfreq
static const uint16_t ctcss_tone[MAX_TONE_INDEX] =
{ {
670, 693, 719, 744, 770, 797, 825, 854, 885, 915, 948, 974, 1000, 1034, CTCSS_67_0 = 0,
1072, 1109, 1148, 1188, 1230, 1273, 1318, 1365, 1413, 1462, 1514, 1567, CTCSS_69_3,
1598, 1622, 1655, 1679, 1713, 1738, 1773, 1799, 1835, 1862, 1899, 1928, CTCSS_71_9,
1966, 1995, 2035, 2065, 2107, 2181, 2257, 2291, 2336, 2418, 2503, 2541 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. * Data structure defining an analog-specific channel information such as tones.
*/ */

View File

@ -74,6 +74,14 @@ void stripTrailingZeroes(char *str);
*/ */
uint8_t rssiToSlevel(const rssi_t rssi); 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 #ifdef __cplusplus
} }
#endif #endif

View File

@ -21,6 +21,14 @@
#include <interfaces/platform.h> #include <interfaces/platform.h>
#include <cps.h> #include <cps.h>
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 cps_getDefaultChannel()
{ {
channel_t channel; channel_t channel;

View File

@ -21,6 +21,7 @@
#include <utils.h> #include <utils.h>
#include <stdio.h> #include <stdio.h>
#include <math.h> #include <math.h>
#include <cps.h>
uint8_t interpCalParameter(const freq_t freq, const freq_t *calPoints, uint8_t interpCalParameter(const freq_t freq, const freq_t *calPoints,
const uint8_t *param, const uint8_t elems) 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 // For S1 - S9 use 6dB increase per S-Point
return (uint8_t)(127 + rssi) / 6; 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;
}

View File

@ -916,14 +916,14 @@ static void _ui_fsm_menuMacro(kbd_msg_t msg, bool *sync_rtx)
{ {
if(state.channel.fm.txTone == 0) if(state.channel.fm.txTone == 0)
{ {
state.channel.fm.txTone = MAX_TONE_INDEX-1; state.channel.fm.txTone = CTCSS_FREQ_NUM-1;
} }
else else
{ {
state.channel.fm.txTone--; 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; state.channel.fm.rxTone = state.channel.fm.txTone;
*sync_rtx = true; *sync_rtx = true;
vp_announceCTCSS(state.channel.fm.rxToneEn, 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) if(state.channel.mode == OPMODE_FM)
{ {
state.channel.fm.txTone++; 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; state.channel.fm.rxTone = state.channel.fm.txTone;
*sync_rtx = true; *sync_rtx = true;
vp_announceCTCSS(state.channel.fm.rxToneEn, vp_announceCTCSS(state.channel.fm.rxToneEn,

View File

@ -154,7 +154,7 @@ int cps_readChannel(channel_t *channel, uint16_t pos)
// TODO: Implement binary search to speed up this lookup // TODO: Implement binary search to speed up this lookup
if((rx_css != 0) && (rx_css != 0xFFFF)) 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))) 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)) 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))) if(ctcss_tone[i] == ((uint16_t) bcdToBin(tx_css)))
{ {

View File

@ -107,7 +107,7 @@ int cps_readChannel(channel_t *channel, uint16_t pos)
// TODO: Implement binary search to speed up this lookup // TODO: Implement binary search to speed up this lookup
if((rx_css != 0) && (rx_css != 0xFFFF)) 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))) 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)) 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))) if(ctcss_tone[i] == ((uint16_t) bcdToBin(tx_css)))
{ {

View File

@ -96,7 +96,7 @@ static int _readChannelAtAddress(channel_t *channel, uint32_t addr)
// TODO: Implement binary search to speed up this lookup // TODO: Implement binary search to speed up this lookup
if((rx_css != 0) && (rx_css != 0xFFFF)) 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))) 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)) 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))) if(ctcss_tone[i] == ((uint16_t) bcdToBin(tx_css)))
{ {

View File

@ -95,7 +95,7 @@ static int _readChannelAtAddress(channel_t *channel, uint32_t addr)
// TODO: Implement binary search to speed up this lookup // TODO: Implement binary search to speed up this lookup
if((rx_css != 0) && (rx_css != 0xFFFF)) 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))) 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)) 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))) if(ctcss_tone[i] == ((uint16_t) bcdToBin(tx_css)))
{ {