Skip to content

Commit

Permalink
Control Channel Retune Handling (#954)
Browse files Browse the repository at this point in the history
* Do not count TDUs as CC messages.

* Only count TSBK and MBTs for control channel message rate.

* Differentiate bween invalid CC messages and link control messages.
  • Loading branch information
tadscottsmith authored May 3, 2024
1 parent 12a019c commit a3eda60
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 80 deletions.
170 changes: 92 additions & 78 deletions trunk-recorder/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,86 @@ void handle_call_update(TrunkMessage message, System *sys) {
}
}

System *find_system(int sys_num) {
System *sys_match = NULL;

for (std::vector<System *>::iterator it = systems.begin(); it != systems.end(); ++it) {
System *sys = (System *)*it;

if (sys->get_sys_num() == sys_num) {
sys_match = sys;
break;
}
}

if (sys_match == NULL) {
BOOST_LOG_TRIVIAL(info) << "Sys is null";
}
return sys_match;
}

void retune_system(System *sys) {
System_impl *system = (System_impl *)sys;
bool source_found = false;
Source *current_source = system->get_source();
double control_channel_freq = system->get_next_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)) {
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
// For Loop
if (system->get_system_type() == "smartnet") {
system->smartnet_trunking->tune_freq(control_channel_freq);
system->smartnet_trunking->reset();
} else if (system->get_system_type() == "p25") {
system->p25_trunking->tune_freq(control_channel_freq);
} else {
BOOST_LOG_TRIVIAL(error) << "\t - Unknown system type for Retune";
}
} else {
for (vector<Source *>::iterator src_it = sources.begin(); src_it != sources.end(); src_it++) {
Source *source = *src_it;

if ((source->get_min_hz() <= control_channel_freq) &&
(source->get_max_hz() >= control_channel_freq)) {
source_found = true;
BOOST_LOG_TRIVIAL(info) << "\t - System Source " << source->get_num() << " - Min Freq: " << format_freq(source->get_min_hz()) << " Max Freq: " << format_freq(source->get_max_hz());

if (system->get_system_type() == "smartnet") {
system->set_source(source);
// We must lock the flow graph in order to disconnect and reconnect blocks
tb->lock();
tb->disconnect(current_source->get_src_block(), 0, system->smartnet_trunking, 0);
system->smartnet_trunking = make_smartnet_trunking(control_channel_freq, source->get_center(), source->get_rate(), system->get_msg_queue(), system->get_sys_num());
tb->connect(source->get_src_block(), 0, system->smartnet_trunking, 0);
tb->unlock();
system->smartnet_trunking->reset();
} else if (system->get_system_type() == "p25") {
system->set_source(source);
// We must lock the flow graph in order to disconnect and reconnect blocks
tb->lock();
tb->disconnect(current_source->get_src_block(), 0, system->p25_trunking, 0);
system->p25_trunking = make_p25_trunking(control_channel_freq, source->get_center(), source->get_rate(), system->get_msg_queue(), system->get_qpsk_mod(), system->get_sys_num());
tb->connect(source->get_src_block(), 0, system->p25_trunking, 0);
tb->unlock();
} else {
BOOST_LOG_TRIVIAL(error) << "\t - Unkown system type for Retune";
}

// break out of the For Loop
break;
}
}
}
if (!source_found) {
BOOST_LOG_TRIVIAL(error) << "\t - Unable to retune System control channel, freq not covered by any source.";
}
}

void handle_message(std::vector<TrunkMessage> messages, System *sys) {
for (std::vector<TrunkMessage>::iterator it = messages.begin(); it != messages.end(); it++) {
TrunkMessage message = *it;
Expand Down Expand Up @@ -727,90 +807,24 @@ void handle_message(std::vector<TrunkMessage> messages, System *sys) {
unit_answer_request(sys, message.source, message.talkgroup);
break;

case UNKNOWN:
case INVALID_CC_MESSAGE:
{
//Do not count messages that aren't valid TSBK or MBTs.
int msg_count = sys->get_message_count();
if(msg_count > 1){
sys->set_message_count(msg_count - 1);
}
}
break;
}
}
}

System *find_system(int sys_num) {
System *sys_match = NULL;

for (std::vector<System *>::iterator it = systems.begin(); it != systems.end(); ++it) {
System *sys = (System *)*it;

if (sys->get_sys_num() == sys_num) {
sys_match = sys;
case TDULC:
retune_system(sys);
break;
}
}

if (sys_match == NULL) {
BOOST_LOG_TRIVIAL(info) << "Sys is null";
}
return sys_match;
}

void retune_system(System *sys) {
System_impl *system = (System_impl *)sys;
bool source_found = false;
Source *current_source = system->get_source();
double control_channel_freq = system->get_next_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)) {
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
// For Loop
if (system->get_system_type() == "smartnet") {
system->smartnet_trunking->tune_freq(control_channel_freq);
system->smartnet_trunking->reset();
} else if (system->get_system_type() == "p25") {
system->p25_trunking->tune_freq(control_channel_freq);
} else {
BOOST_LOG_TRIVIAL(error) << "\t - Unknown system type for Retune";
}
} else {
for (vector<Source *>::iterator src_it = sources.begin(); src_it != sources.end(); src_it++) {
Source *source = *src_it;

if ((source->get_min_hz() <= control_channel_freq) &&
(source->get_max_hz() >= control_channel_freq)) {
source_found = true;
BOOST_LOG_TRIVIAL(info) << "\t - System Source " << source->get_num() << " - Min Freq: " << format_freq(source->get_min_hz()) << " Max Freq: " << format_freq(source->get_max_hz());

if (system->get_system_type() == "smartnet") {
system->set_source(source);
// We must lock the flow graph in order to disconnect and reconnect blocks
tb->lock();
tb->disconnect(current_source->get_src_block(), 0, system->smartnet_trunking, 0);
system->smartnet_trunking = make_smartnet_trunking(control_channel_freq, source->get_center(), source->get_rate(), system->get_msg_queue(), system->get_sys_num());
tb->connect(source->get_src_block(), 0, system->smartnet_trunking, 0);
tb->unlock();
system->smartnet_trunking->reset();
} else if (system->get_system_type() == "p25") {
system->set_source(source);
// We must lock the flow graph in order to disconnect and reconnect blocks
tb->lock();
tb->disconnect(current_source->get_src_block(), 0, system->p25_trunking, 0);
system->p25_trunking = make_p25_trunking(control_channel_freq, source->get_center(), source->get_rate(), system->get_msg_queue(), system->get_qpsk_mod(), system->get_sys_num());
tb->connect(source->get_src_block(), 0, system->p25_trunking, 0);
tb->unlock();
} else {
BOOST_LOG_TRIVIAL(error) << "\t - Unkown system type for Retune";
}

// break out of the For Loop
break;
}
case UNKNOWN:
break;
}
}
if (!source_found) {
BOOST_LOG_TRIVIAL(error) << "\t - Unable to retune System control channel, freq not covered by any source.";
}
}

void check_message_count(float timeDiff) {
Expand Down
11 changes: 9 additions & 2 deletions trunk-recorder/systems/p25_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,7 @@ std::vector<TrunkMessage> P25Parser::parse_message(gr::message::sptr msg, System
return messages;
} else if (type < 0) {
BOOST_LOG_TRIVIAL(debug) << "unknown message type " << type;
message.message_type = INVALID_CC_MESSAGE;
messages.push_back(message);
return messages;
}
Expand All @@ -979,6 +980,7 @@ std::vector<TrunkMessage> P25Parser::parse_message(gr::message::sptr msg, System

if (s.length() < 2) {
BOOST_LOG_TRIVIAL(error) << "P25 Parse error, s: " << s << " s0: " << static_cast<int>(s0) << " s1: " << static_cast<int>(s1) << " shift: " << shift << " nac: " << nac << " type: " << type << " Len: " << s.length();
message.message_type = INVALID_CC_MESSAGE;
messages.push_back(message);
return messages;
}
Expand All @@ -995,8 +997,7 @@ std::vector<TrunkMessage> P25Parser::parse_message(gr::message::sptr msg, System
// //" at %f state %d len %d" %(nac, type, time.time(), self.state, len(s))
if ((type != 7) && (type != 12)) // and nac not in self.trunked_systems:
{
BOOST_LOG_TRIVIAL(debug) << std::hex << "NON TBSK: nac " << nac << std::dec << " type " << type << " size " << msg->to_string().length() << " mesg len: " << msg->length();

BOOST_LOG_TRIVIAL(debug) << std::hex << "NON TSBK: nac " << nac << std::dec << " type " << type << " size " << msg->to_string().length() << " mesg len: " << msg->length();
/*
if not self.configs:
# TODO: allow whitelist/blacklist rather than blind automatic-add
Expand Down Expand Up @@ -1071,7 +1072,13 @@ std::vector<TrunkMessage> P25Parser::parse_message(gr::message::sptr msg, System
return decode_mbt_data(opcode, header, mbt_data, link_id, nac, sys_num);
// self.trunked_systems[nac].decode_mbt_data(opcode, header << 16, mbt_data
// << 32)
} else if (type == 15)
{
//TDU with Link Contol. Link Control words should not be seen on an active Control Channel.
BOOST_LOG_TRIVIAL(debug) << "P25 Parser: TDULC on control channel. Retuning to next control channel.";
message.message_type = TDULC;
}

messages.push_back(message);
return messages;
}
Expand Down
2 changes: 2 additions & 0 deletions trunk-recorder/systems/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ enum MessageType {
UU_ANS_REQ = 13,
UU_V_GRANT = 14,
UU_V_UPDATE = 15,
INVALID_CC_MESSAGE = 16,
TDULC = 17,
UNKNOWN = 99
};

Expand Down

0 comments on commit a3eda60

Please sign in to comment.