Skip to content

Commit

Permalink
Differentiate bween invalid CC messages and link control messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
tadscottsmith committed Apr 29, 2024
1 parent 9b83072 commit 247b578
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 88 deletions.
176 changes: 90 additions & 86 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 @@ -728,99 +808,23 @@ void handle_message(std::vector<TrunkMessage> messages, System *sys) {
break;

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);
{
//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;

case UNKNOWN:
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
9 changes: 7 additions & 2 deletions trunk-recorder/systems/p25_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -997,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();
message.message_type = INVALID_CC_MESSAGE;
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 @@ -1073,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
1 change: 1 addition & 0 deletions trunk-recorder/systems/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ enum MessageType {
UU_V_GRANT = 14,
UU_V_UPDATE = 15,
INVALID_CC_MESSAGE = 16,
TDULC = 17,
UNKNOWN = 99
};

Expand Down

0 comments on commit 247b578

Please sign in to comment.