Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -424,3 +424,14 @@ if (GR_IIO_FOUND)
endif()

install(TARGETS trunk-recorder RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

include(CTest)
if(BUILD_TESTING)
add_executable(control_channel_source_affinity_tests
tests/control_channel_source_affinity_tests.cc
)
target_include_directories(control_channel_source_affinity_tests PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
)
add_test(NAME control_channel_source_affinity_tests COMMAND control_channel_source_affinity_tests)
endif()
1 change: 1 addition & 0 deletions docs/CONFIGURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ During the status display, each source will report the running average as well a
| lcnTable | | | object; `{ "1": 463112500, "2": 463612500, ... }` | *For `"dmr"` systems.* Explicit map from DMR Logical Channel Number to RF frequency in Hz. Provide this if you know the LCN-to-freq assignment for the site. If you don't, supply `channels` instead and the decoder will auto-map. |
| channels (DMR) | | | array of numbers;<br />`[463112500, 463162500, 463612500]` | *For `"dmr"` systems, alternative to `lcnTable`.* List of candidate voice channel frequencies. The parser claims them on a first-come basis: the first unknown LCN seen in a grant gets the first unused freq, the next unknown LCN gets the next freq, etc. Useful when you have a band-scan list but don't know which LCN is which. The order you list freqs in is the order they'll be claimed — if a recorder lands on the wrong physical channel, reorder this list and the next session will be correct. You may supply both `lcnTable` and `channels`: `lcnTable` entries win, and `channels` is the pool for everything else. |
| control_channels | ✓ | | array of numbers;<br />[496537500, 496437500] | *For trunked systems* The control channel frequencies for the system, in Hz. The frequencies will automatically be cycled through if the system moves to an alternate channel. |
| sourceAffinity | | false | **true** / **false** | *For trunked systems.* Keep the control-channel decoder on the source selected at startup. A control channel outside that source's frequency range is skipped instead of rebuilding the decoder on another source. Voice recorder source selection is unaffected. Enable only when the assigned source covers every control channel the system must use. |
| channels | ✓ | | array of numbers;<br />[166725000, 166925000, 167075000, 166850000] | *For conventional systems* The channel frequencies, in Hz, used for the system. The channels get assigned a virtual talkgroup number based upon their position in the array. Squelch levels need to be specified for the Source(s) being used. |
| channelFile | ✓ | | string | *For conventional systems* The filename for a CSV file that provides information about the conventional channels. The format for the file is described below. Squelch levels need to be specified for the Source(s) being used. *Use channels or channelFile, not both*. |
| modulation | | "qpsk" | **"qpsk"** or **"fsk4"** | The type of digital modulation that the system uses. You do not need to specify this with **conventionalDMR** systems. |
Expand Down
15 changes: 15 additions & 0 deletions tests/control_channel_source_affinity_tests.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "trunk-recorder/systems/control_channel_source_affinity.h"

#include <cassert>

int main() {
assert(control_channel_retune_source_action(false, true) ==
ControlChannelRetuneSourceAction::RetuneOnCurrentSource);
assert(control_channel_retune_source_action(true, true) ==
ControlChannelRetuneSourceAction::RetuneOnCurrentSource);
assert(control_channel_retune_source_action(false, false) ==
ControlChannelRetuneSourceAction::SearchOtherSources);
assert(control_channel_retune_source_action(true, false) ==
ControlChannelRetuneSourceAction::BlockCrossSourceRetune);
return 0;
}
2 changes: 2 additions & 0 deletions trunk-recorder/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ bool load_config(string config_file, Config &config, gr::top_block_sptr &tb, std

system->set_system_type(element["type"]);
BOOST_LOG_TRIVIAL(info) << "System Type: " << system->get_system_type();
system->set_source_affinity(element.value("sourceAffinity", false));
BOOST_LOG_TRIVIAL(info) << "Control Channel Source Affinity: " << system->get_source_affinity();

// If it is a conventional System
if ((system->get_system_type() == "conventional") || (system->get_system_type() == "conventionalP25") || (system->get_system_type() == "conventionalDMR") || (system->get_system_type() == "conventionalSIGMF")) {
Expand Down
25 changes: 21 additions & 4 deletions trunk-recorder/monitor_systems.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "monitor_systems.h"
#include "recorders/p25_recorder.h"
#include "systems/control_channel_source_affinity.h"
#include "systems/dmr_parser.h"
#include <chrono>
#include <boost/log/sinks/text_file_backend.hpp>
Expand Down Expand Up @@ -704,13 +705,20 @@ void handle_message(std::vector<TrunkMessage> messages, System *sys, Config &con
void retune_system(System *sys, gr::top_block_sptr &tb, std::vector<Source *> &sources) {
System_impl *system = (System_impl *)sys;
bool source_found = false;
bool source_affinity_blocked = false;
Source *current_source = system->get_source();
double control_channel_freq = system->get_next_control_channel();
bool current_source_covers_control_channel =
(current_source->get_min_hz() <= control_channel_freq) &&
(current_source->get_max_hz() >= control_channel_freq);
ControlChannelRetuneSourceAction source_action =
control_channel_retune_source_action(
system->get_source_affinity(),
current_source_covers_control_channel);

BOOST_LOG_TRIVIAL(error) << "[" << system->get_short_name() << "] Retuning to Control Channel: " << format_freq(control_channel_freq);

if ((current_source->get_min_hz() <= control_channel_freq) &&
(current_source->get_max_hz() >= control_channel_freq)) {
if (source_action == ControlChannelRetuneSourceAction::RetuneOnCurrentSource) {
source_found = true;
BOOST_LOG_TRIVIAL(info) << "\t - System Source " << current_source->get_num() << " - Min Freq: " << format_freq(current_source->get_min_hz()) << " Max Freq: " << format_freq(current_source->get_max_hz());
// The source can cover the System's control channel, break out of the
Expand All @@ -727,6 +735,15 @@ void retune_system(System *sys, gr::top_block_sptr &tb, std::vector<Source *> &s
} else {
BOOST_LOG_TRIVIAL(error) << "\t - Unknown system type for Retune";
}
} else if (source_action == ControlChannelRetuneSourceAction::BlockCrossSourceRetune) {
source_affinity_blocked = true;
BOOST_LOG_TRIVIAL(warning)
<< "\t - Source affinity blocked cross-source control-channel retune for "
<< system->get_short_name() << ": requested "
<< format_freq(control_channel_freq) << " is outside assigned Source "
<< current_source->get_num() << " ("
<< format_freq(current_source->get_min_hz()) << " - "
<< format_freq(current_source->get_max_hz()) << ").";
} else {
for (vector<Source *>::iterator src_it = sources.begin(); src_it != sources.end(); src_it++) {
Source *source = *src_it;
Expand Down Expand Up @@ -776,9 +793,9 @@ void retune_system(System *sys, gr::top_block_sptr &tb, std::vector<Source *> &s
}
}
}
if (!source_found) {
if (!source_found && !source_affinity_blocked) {
BOOST_LOG_TRIVIAL(error) << "\t - Unable to retune System control channel, freq not covered by any source.";
} else {
} else if (source_found) {
if ((system->get_source()->get_autotune_source()) && (system->get_system_type() == "p25")) {
// If control channel source has autotune enabled, perform adjustments after retune completes
// Don't store measurements since the control channel recorder just started
Expand Down
22 changes: 22 additions & 0 deletions trunk-recorder/systems/control_channel_source_affinity.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef CONTROL_CHANNEL_SOURCE_AFFINITY_H
#define CONTROL_CHANNEL_SOURCE_AFFINITY_H

enum class ControlChannelRetuneSourceAction {
RetuneOnCurrentSource,
SearchOtherSources,
BlockCrossSourceRetune,
};

constexpr ControlChannelRetuneSourceAction control_channel_retune_source_action(
bool source_affinity_enabled,
bool current_source_covers_control_channel) {
if (current_source_covers_control_channel) {
return ControlChannelRetuneSourceAction::RetuneOnCurrentSource;
}

return source_affinity_enabled
? ControlChannelRetuneSourceAction::BlockCrossSourceRetune
: ControlChannelRetuneSourceAction::SearchOtherSources;
}

#endif
4 changes: 3 additions & 1 deletion trunk-recorder/systems/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ class System {
virtual std::string get_unit_tags_file() = 0;
virtual Source *get_source() = 0;
virtual void set_source(Source *) = 0;
virtual bool get_source_affinity() = 0;
virtual void set_source_affinity(bool) = 0;
virtual Talkgroup *find_talkgroup(long tg) = 0;
virtual Talkgroup *find_talkgroup_by_freq(double freq) = 0;
virtual std::string find_unit_tag(long unitID) = 0;
Expand Down Expand Up @@ -266,4 +268,4 @@ class System {
virtual void set_dmr_variant(const std::string &v) = 0;
virtual std::string get_dmr_variant() = 0;
};
#endif
#endif
11 changes: 10 additions & 1 deletion trunk-recorder/systems/system_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ System_impl::System_impl(int sys_num) {
retune_attempts = 0;
message_count = 0;
decode_rate = 0;
source_affinity = false;
dmr_rest_lcn = -1;
dmr_variant = "";
msg_queue = gr::msg_queue::make(100);
Expand Down Expand Up @@ -500,6 +501,14 @@ void System_impl::set_source(Source *s) {
this->source = s;
}

bool System_impl::get_source_affinity() {
return source_affinity;
}

void System_impl::set_source_affinity(bool enabled) {
source_affinity = enabled;
}

Talkgroup *System_impl::find_talkgroup(long tg_number) {
return talkgroups->find_talkgroup(sys_num, tg_number);
}
Expand Down Expand Up @@ -963,4 +972,4 @@ void System_impl::set_dmr_variant(const std::string &v) {

std::string System_impl::get_dmr_variant() {
return dmr_variant;
}
}
3 changes: 3 additions & 0 deletions trunk-recorder/systems/system_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class System_impl : public System {
std::string audio_bitrate;
bool conversation_mode;
bool qpsk_mod;
bool source_affinity;
double squelch_db;
float tau;
double analog_levels;
Expand Down Expand Up @@ -242,6 +243,8 @@ class System_impl : public System {
std::string get_unit_tags_file() override;
Source *get_source() override;
void set_source(Source *) override;
bool get_source_affinity() override;
void set_source_affinity(bool) override;
Talkgroup *find_talkgroup(long tg) override;
Talkgroup *find_talkgroup_by_freq(double freq) override;
std::string find_unit_tag(long unitID) override;
Expand Down