From 731517595f7f936d8adebe46304f3d9143ff7b13 Mon Sep 17 00:00:00 2001 From: Luke Berndt Date: Sat, 9 Mar 2024 10:13:04 -0500 Subject: [PATCH] Optional Per Talkgroup Squelch --- trunk-recorder/call_conventional.cc | 7 ++++++- trunk-recorder/call_conventional.h | 5 ++++- trunk-recorder/recorders/analog_recorder.cc | 3 ++- trunk-recorder/recorders/dmr_recorder_impl.cc | 3 ++- trunk-recorder/recorders/p25_recorder_impl.cc | 7 +++++-- .../recorders/sigmf_recorder_impl.cc | 10 +++++++-- trunk-recorder/setup_systems.cc | 9 ++++++-- trunk-recorder/talkgroup.cc | 13 ++++++++++-- trunk-recorder/talkgroup.h | 4 +++- trunk-recorder/talkgroups.cc | 21 +++++++++++++++---- 10 files changed, 65 insertions(+), 17 deletions(-) diff --git a/trunk-recorder/call_conventional.cc b/trunk-recorder/call_conventional.cc index 08b753c9c..3c8db38b1 100644 --- a/trunk-recorder/call_conventional.cc +++ b/trunk-recorder/call_conventional.cc @@ -4,7 +4,8 @@ #include "recorders/recorder.h" #include -Call_conventional::Call_conventional(long t, double f, System *s, Config c) : Call_impl(t, f, s, c) { +Call_conventional::Call_conventional(long t, double f, System *s, Config c, double squelch_db) : Call_impl(t, f, s, c) { + this->squelch_db = squelch_db; } void Call_conventional::restart_call() { @@ -39,3 +40,7 @@ void Call_conventional::set_recorder(Recorder *r) { void Call_conventional::recording_started() { start_time = time(NULL); } + +double Call_conventional::get_squelch_db() { + return squelch_db; +} \ No newline at end of file diff --git a/trunk-recorder/call_conventional.h b/trunk-recorder/call_conventional.h index c54e26554..625db94d6 100644 --- a/trunk-recorder/call_conventional.h +++ b/trunk-recorder/call_conventional.h @@ -10,12 +10,15 @@ class Recorder; class Call_conventional : public Call_impl { public: - Call_conventional(long t, double f, System *s, Config c); + Call_conventional(long t, double f, System *s, Config c, double squelch_db); time_t get_start_time(); bool is_conventional() { return true; } void restart_call(); void set_recorder(Recorder *r); void recording_started(); + double get_squelch_db(); +private: + double squelch_db; }; #endif diff --git a/trunk-recorder/recorders/analog_recorder.cc b/trunk-recorder/recorders/analog_recorder.cc index d94458604..9511be547 100644 --- a/trunk-recorder/recorders/analog_recorder.cc +++ b/trunk-recorder/recorders/analog_recorder.cc @@ -350,7 +350,8 @@ bool analog_recorder::start(Call *call) { talkgroup = call->get_talkgroup(); chan_freq = call->get_freq(); - squelch_db = system->get_squelch_db(); + Call_conventional *conventional_call = dynamic_cast(call); + squelch_db = conventional_call->get_squelch_db(); prefilter->set_squelch_db(squelch_db); BOOST_LOG_TRIVIAL(info) << "[" << call->get_short_name() << "]\t\033[0;34m" << call->get_call_num() << "C\033[0m\tTG: " << this->call->get_talkgroup_display() << "\tFreq: " << format_freq(chan_freq) << "\t\u001b[32mStarting Analog Recorder Num [" << rec_num << "]\u001b[0m \tSquelch: " << squelch_db; diff --git a/trunk-recorder/recorders/dmr_recorder_impl.cc b/trunk-recorder/recorders/dmr_recorder_impl.cc index e7fbfd3b1..46d4713a8 100644 --- a/trunk-recorder/recorders/dmr_recorder_impl.cc +++ b/trunk-recorder/recorders/dmr_recorder_impl.cc @@ -259,7 +259,8 @@ bool dmr_recorder_impl::start(Call *call) { chan_freq = call->get_freq(); this->call = call; - squelch_db = system->get_squelch_db(); + Call_conventional *conventional_call = dynamic_cast(call); + squelch_db = conventional_call->get_squelch_db(); prefilter->set_squelch_db(squelch_db); BOOST_LOG_TRIVIAL(info) << "[" << call->get_short_name() << "]\t\033[0;34m" << call->get_call_num() << "C\033[0m\tTG: " << this->call->get_talkgroup_display() << "\tFreq: " << format_freq(chan_freq) << "\t\u001b[32mStarting DMR Recorder Num [" << rec_num << "]\u001b[0m\tTDMA: " << call->get_phase2_tdma() << "\tSlot: " << call->get_tdma_slot(); diff --git a/trunk-recorder/recorders/p25_recorder_impl.cc b/trunk-recorder/recorders/p25_recorder_impl.cc index dc83ba9b9..d5b2a94ea 100644 --- a/trunk-recorder/recorders/p25_recorder_impl.cc +++ b/trunk-recorder/recorders/p25_recorder_impl.cc @@ -317,8 +317,11 @@ bool p25_recorder_impl::start(Call *call) { chan_freq = call->get_freq(); this->call = call; - squelch_db = system->get_squelch_db(); - prefilter->set_squelch_db(squelch_db); + if (conventional) { + Call_conventional *conventional_call = dynamic_cast(call); + squelch_db = conventional_call->get_squelch_db(); + prefilter->set_squelch_db(squelch_db); + } BOOST_LOG_TRIVIAL(info) << "[" << call->get_short_name() << "]\t\033[0;34m" << call->get_call_num() << "C\033[0m\tTG: " << this->call->get_talkgroup_display() << "\tFreq: " << format_freq(chan_freq) << "\t\u001b[32mStarting P25 Recorder Num [" << rec_num << "]\u001b[0m\tTDMA: " << call->get_phase2_tdma() << "\tSlot: " << call->get_tdma_slot() << "\tQPSK: " << qpsk_mod; diff --git a/trunk-recorder/recorders/sigmf_recorder_impl.cc b/trunk-recorder/recorders/sigmf_recorder_impl.cc index b0f1d5e7f..4242e2063 100644 --- a/trunk-recorder/recorders/sigmf_recorder_impl.cc +++ b/trunk-recorder/recorders/sigmf_recorder_impl.cc @@ -134,10 +134,16 @@ bool sigmf_recorder_impl::start(Call *call) { System *system = call->get_system(); talkgroup = call->get_talkgroup(); freq = call->get_freq(); - squelch_db = system->get_squelch_db(); - prefilter->set_squelch_db(squelch_db); + + if (conventional) { + Call_conventional *conventional_call = dynamic_cast(call); + squelch_db = conventional_call->get_squelch_db(); + prefilter->set_squelch_db(squelch_db); + } + int offset_amount = (center - freq); prefilter->tune_offset(offset_amount); + //freq_xlat->set_center_freq(-offset_amount); BOOST_LOG_TRIVIAL(info) << "[" << call->get_short_name() << "]\t\033[0;34m" << call->get_call_num() << "C\033[0m\tTG: " << this->call->get_talkgroup_display() << "\tFreq: " << format_freq(freq) << "\t\u001b[32mStarting SigMF Recorder Num [" << rec_num << "]\u001b[0m"; diff --git a/trunk-recorder/setup_systems.cc b/trunk-recorder/setup_systems.cc index 1e7497adc..e945d8f1d 100644 --- a/trunk-recorder/setup_systems.cc +++ b/trunk-recorder/setup_systems.cc @@ -21,10 +21,15 @@ bool setup_conventional_channel(System *system, double frequency, long channel_i if (system->has_channel_file()) { Talkgroup *tg = system->find_talkgroup_by_freq(frequency); tone_freq = tg->tone; - call = new Call_conventional(tg->number, tg->freq, system, config); + if (tg->squelch_db != 999) { + call = new Call_conventional(tg->number, tg->freq, system, config, tg->squelch_db); + } else { + call = new Call_conventional(tg->number, tg->freq, system, config, system->get_squelch_db()); + } + call->set_talkgroup_tag(tg->alpha_tag); } else { - call = new Call_conventional(channel_index, frequency, system, config); + call = new Call_conventional(channel_index, frequency, system, config, system->get_squelch_db()); } BOOST_LOG_TRIVIAL(info) << "[" << system->get_short_name() << "]\tMonitoring " << system->get_system_type() << " channel: " << format_freq(frequency) << " Talkgroup: " << channel_index; if (system->get_system_type() == "conventional") { diff --git a/trunk-recorder/talkgroup.cc b/trunk-recorder/talkgroup.cc index afee663ec..bdd03ad8f 100644 --- a/trunk-recorder/talkgroup.cc +++ b/trunk-recorder/talkgroup.cc @@ -10,12 +10,17 @@ Talkgroup::Talkgroup(int sys_num, long num, std::string mode, std::string alpha_ this->group = group; this->priority = priority; this->active = false; + this->preferredNAC = preferredNAC; + + // This talkgroup is for a Trunked system and freq and tone are not used this->freq = 0; this->tone = 0; - this->preferredNAC = preferredNAC; + this->squelch_db = 999; + this->signal_detection = false; + } -Talkgroup::Talkgroup(int sys_num, long num, double freq, double tone, std::string alpha_tag, std::string description, std::string tag, std::string group) { +Talkgroup::Talkgroup(int sys_num, long num, double freq, double tone, std::string alpha_tag, std::string description, std::string tag, std::string group, double squelch_db, bool signal_detection) { this->sys_num = sys_num; this->number = num; this->mode = "Z"; @@ -26,6 +31,10 @@ Talkgroup::Talkgroup(int sys_num, long num, double freq, double tone, std::strin this->active = false; this->freq = freq; this->tone = tone; + this->squelch_db = squelch_db; + this->signal_detection = signal_detection; + + // This talkgroup is for a Conventional system and priority and preferredNAC are not used this->priority = 0; this->preferredNAC = 0; } diff --git a/trunk-recorder/talkgroup.h b/trunk-recorder/talkgroup.h index 82dec567c..0dbcce4a2 100644 --- a/trunk-recorder/talkgroup.h +++ b/trunk-recorder/talkgroup.h @@ -16,6 +16,8 @@ class Talkgroup { std::string group; int priority; int sys_num; + double squelch_db; + bool signal_detection; // For Conventional @@ -23,7 +25,7 @@ class Talkgroup { double tone; Talkgroup(int sys_num, long num, std::string mode, std::string alpha_tag, std::string description, std::string tag, std::string group, int priority, unsigned long preferredNAC); - Talkgroup(int sys_num, long num, double freq, double tone, std::string alpha_tag, std::string description, std::string tag, std::string group); + Talkgroup(int sys_num, long num, double freq, double tone, std::string alpha_tag, std::string description, std::string tag, std::string group, double squelch_db, bool signal_detection); bool is_active(); int get_priority(); diff --git a/trunk-recorder/talkgroups.cc b/trunk-recorder/talkgroups.cc index eb9edc0c2..8e6725e76 100644 --- a/trunk-recorder/talkgroups.cc +++ b/trunk-recorder/talkgroups.cc @@ -125,14 +125,14 @@ void Talkgroups::load_channels(int sys_num, std::string filename) { format.trim({' ', '\t'}); CSVReader reader(filename, format); std::vector headers = reader.get_col_names(); - std::vector defined_headers = {"TG Number", "Tone", "Frequency", "Alpha Tag", "Description", "Category", "Tag", "Enable", "Comment"}; + std::vector defined_headers = {"TG Number", "Tone", "Frequency", "Alpha Tag", "Description", "Category", "Tag", "Enable", "Comment", "Signal Detection", "Squelch"}; if (headers[0] != "TG Number") { BOOST_LOG_TRIVIAL(error) << "Column Headers are required for Channel CSV files"; BOOST_LOG_TRIVIAL(error) << "The first column must be 'TG Number'"; BOOST_LOG_TRIVIAL(error) << "Required columns are: 'TG Number', 'Tone', 'Frequency',"; - BOOST_LOG_TRIVIAL(error) << "Optional columns are: 'Alpha Tag', 'Description', 'Category', 'Tag', 'Enable', 'Comment'"; + BOOST_LOG_TRIVIAL(error) << "Optional columns are: 'Alpha Tag', 'Description', 'Category', 'Tag', 'Enable', 'Comment', 'Signal Detection', 'Squelch'"; exit(0); } else { BOOST_LOG_TRIVIAL(info) << "Found Columns: " << internals::format_row(reader.get_col_names(), ", "); @@ -142,7 +142,7 @@ void Talkgroups::load_channels(int sys_num, std::string filename) { if (find(defined_headers.begin(), defined_headers.end(), headers[i]) == defined_headers.end()) { BOOST_LOG_TRIVIAL(error) << "Unknown column header: " << headers[i]; BOOST_LOG_TRIVIAL(error) << "Required columns are: 'TG Number', 'Tone', 'Frequency',"; - BOOST_LOG_TRIVIAL(error) << "Optional columns are: 'Alpha Tag', 'Description', 'Category', 'Tag', 'Enable', 'Comment'"; + BOOST_LOG_TRIVIAL(error) << "Optional columns are: 'Alpha Tag', 'Description', 'Category', 'Tag', 'Enable', 'Comment', 'Signal Detection', 'Squelch'"; exit(0); } } @@ -155,6 +155,8 @@ void Talkgroups::load_channels(int sys_num, std::string filename) { std::string description = ""; std::string tag = ""; std::string group = ""; + double squelch_db = 999; + bool signal_detection = true; double freq = 0; double tone = 0; bool enable = true; @@ -194,13 +196,24 @@ void Talkgroups::load_channels(int sys_num, std::string filename) { } } + if ((reader.index_of("Squelch") >= 0) && row["Squelch"].is_num()) { + squelch_db = row["Squelch"].get(); + } + + if ((reader.index_of("Signal Detection") >= 0) && row["Signal Detection"].is_str()) { + if (boost::iequals(row["Signal Detection"].get(), "false")) { + signal_detection = false; + } + } + + if ((reader.index_of("Enable") >= 0) && row["Enable"].is_str()) { if (boost::iequals(row["Enable"].get(), "false")) { enable = false; } } if (enable) { - tg = new Talkgroup(sys_num, tg_number, freq, tone, alpha_tag, description, tag, group); + tg = new Talkgroup(sys_num, tg_number, freq, tone, alpha_tag, description, tag, group, squelch_db, signal_detection); talkgroups.push_back(tg); lines_pushed++; }