Improve error prone implementation of CTCSS to TG map
Was using float as index into map which can lead to problems when rounding errors are present. Now using uint16_t instead.
This commit is contained in:
parent
fb70af791b
commit
6217a41389
|
|
@ -674,7 +674,9 @@ bool Logic::initialize(void)
|
|||
}
|
||||
if (rx().addToneDetector(it->first, bw, 10, 1000))
|
||||
{
|
||||
m_ctcss_to_tg[it->first] = it->second;
|
||||
uint16_t uint_fq = static_cast<uint16_t>(round(10.0f*it->first));
|
||||
uint32_t tg = it->second;
|
||||
m_ctcss_to_tg[uint_fq] = tg;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -1673,7 +1675,8 @@ void Logic::publishStateEvent(const string &event_name, const string &msg)
|
|||
void Logic::detectedTone(float fq)
|
||||
{
|
||||
//cout << name() << ": " << fq << " Hz tone call detected" << endl;
|
||||
std::map<float, uint32_t>::const_iterator it = m_ctcss_to_tg.find(fq);
|
||||
uint16_t uint_fq = static_cast<uint16_t>(round(10.0f*fq));
|
||||
std::map<uint16_t, uint32_t>::const_iterator it = m_ctcss_to_tg.find(uint_fq);
|
||||
if (it != m_ctcss_to_tg.end())
|
||||
{
|
||||
uint32_t tg = it->second;
|
||||
|
|
|
|||
|
|
@ -282,7 +282,7 @@ class Logic : public LogicBase
|
|||
DtmfDigitHandler *dtmf_digit_handler;
|
||||
Async::Pty *state_pty;
|
||||
Async::Pty *dtmf_ctrl_pty;
|
||||
std::map<float, uint32_t> m_ctcss_to_tg;
|
||||
std::map<uint16_t, uint32_t> m_ctcss_to_tg;
|
||||
|
||||
void loadModules(void);
|
||||
void loadModule(const std::string& module_name);
|
||||
|
|
|
|||
Loading…
Reference in New Issue