Skip to content

Commit a3eda60

Browse files
Control Channel Retune Handling (#954)
* 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.
1 parent 12a019c commit a3eda60

File tree

3 files changed

+103
-80
lines changed

3 files changed

+103
-80
lines changed

trunk-recorder/main.cc

Lines changed: 92 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,86 @@ void handle_call_update(TrunkMessage message, System *sys) {
649649
}
650650
}
651651

652+
System *find_system(int sys_num) {
653+
System *sys_match = NULL;
654+
655+
for (std::vector<System *>::iterator it = systems.begin(); it != systems.end(); ++it) {
656+
System *sys = (System *)*it;
657+
658+
if (sys->get_sys_num() == sys_num) {
659+
sys_match = sys;
660+
break;
661+
}
662+
}
663+
664+
if (sys_match == NULL) {
665+
BOOST_LOG_TRIVIAL(info) << "Sys is null";
666+
}
667+
return sys_match;
668+
}
669+
670+
void retune_system(System *sys) {
671+
System_impl *system = (System_impl *)sys;
672+
bool source_found = false;
673+
Source *current_source = system->get_source();
674+
double control_channel_freq = system->get_next_control_channel();
675+
676+
BOOST_LOG_TRIVIAL(error) << "[" << system->get_short_name() << "] Retuning to Control Channel: " << format_freq(control_channel_freq);
677+
678+
if ((current_source->get_min_hz() <= control_channel_freq) &&
679+
(current_source->get_max_hz() >= control_channel_freq)) {
680+
source_found = true;
681+
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());
682+
// The source can cover the System's control channel, break out of the
683+
// For Loop
684+
if (system->get_system_type() == "smartnet") {
685+
system->smartnet_trunking->tune_freq(control_channel_freq);
686+
system->smartnet_trunking->reset();
687+
} else if (system->get_system_type() == "p25") {
688+
system->p25_trunking->tune_freq(control_channel_freq);
689+
} else {
690+
BOOST_LOG_TRIVIAL(error) << "\t - Unknown system type for Retune";
691+
}
692+
} else {
693+
for (vector<Source *>::iterator src_it = sources.begin(); src_it != sources.end(); src_it++) {
694+
Source *source = *src_it;
695+
696+
if ((source->get_min_hz() <= control_channel_freq) &&
697+
(source->get_max_hz() >= control_channel_freq)) {
698+
source_found = true;
699+
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());
700+
701+
if (system->get_system_type() == "smartnet") {
702+
system->set_source(source);
703+
// We must lock the flow graph in order to disconnect and reconnect blocks
704+
tb->lock();
705+
tb->disconnect(current_source->get_src_block(), 0, system->smartnet_trunking, 0);
706+
system->smartnet_trunking = make_smartnet_trunking(control_channel_freq, source->get_center(), source->get_rate(), system->get_msg_queue(), system->get_sys_num());
707+
tb->connect(source->get_src_block(), 0, system->smartnet_trunking, 0);
708+
tb->unlock();
709+
system->smartnet_trunking->reset();
710+
} else if (system->get_system_type() == "p25") {
711+
system->set_source(source);
712+
// We must lock the flow graph in order to disconnect and reconnect blocks
713+
tb->lock();
714+
tb->disconnect(current_source->get_src_block(), 0, system->p25_trunking, 0);
715+
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());
716+
tb->connect(source->get_src_block(), 0, system->p25_trunking, 0);
717+
tb->unlock();
718+
} else {
719+
BOOST_LOG_TRIVIAL(error) << "\t - Unkown system type for Retune";
720+
}
721+
722+
// break out of the For Loop
723+
break;
724+
}
725+
}
726+
}
727+
if (!source_found) {
728+
BOOST_LOG_TRIVIAL(error) << "\t - Unable to retune System control channel, freq not covered by any source.";
729+
}
730+
}
731+
652732
void handle_message(std::vector<TrunkMessage> messages, System *sys) {
653733
for (std::vector<TrunkMessage>::iterator it = messages.begin(); it != messages.end(); it++) {
654734
TrunkMessage message = *it;
@@ -727,90 +807,24 @@ void handle_message(std::vector<TrunkMessage> messages, System *sys) {
727807
unit_answer_request(sys, message.source, message.talkgroup);
728808
break;
729809

730-
case UNKNOWN:
810+
case INVALID_CC_MESSAGE:
811+
{
812+
//Do not count messages that aren't valid TSBK or MBTs.
813+
int msg_count = sys->get_message_count();
814+
if(msg_count > 1){
815+
sys->set_message_count(msg_count - 1);
816+
}
817+
}
731818
break;
732-
}
733-
}
734-
}
735-
736-
System *find_system(int sys_num) {
737-
System *sys_match = NULL;
738-
739-
for (std::vector<System *>::iterator it = systems.begin(); it != systems.end(); ++it) {
740-
System *sys = (System *)*it;
741819

742-
if (sys->get_sys_num() == sys_num) {
743-
sys_match = sys;
820+
case TDULC:
821+
retune_system(sys);
744822
break;
745-
}
746-
}
747-
748-
if (sys_match == NULL) {
749-
BOOST_LOG_TRIVIAL(info) << "Sys is null";
750-
}
751-
return sys_match;
752-
}
753823

754-
void retune_system(System *sys) {
755-
System_impl *system = (System_impl *)sys;
756-
bool source_found = false;
757-
Source *current_source = system->get_source();
758-
double control_channel_freq = system->get_next_control_channel();
759-
760-
BOOST_LOG_TRIVIAL(error) << "[" << system->get_short_name() << "] Retuning to Control Channel: " << format_freq(control_channel_freq);
761-
762-
if ((current_source->get_min_hz() <= control_channel_freq) &&
763-
(current_source->get_max_hz() >= control_channel_freq)) {
764-
source_found = true;
765-
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());
766-
// The source can cover the System's control channel, break out of the
767-
// For Loop
768-
if (system->get_system_type() == "smartnet") {
769-
system->smartnet_trunking->tune_freq(control_channel_freq);
770-
system->smartnet_trunking->reset();
771-
} else if (system->get_system_type() == "p25") {
772-
system->p25_trunking->tune_freq(control_channel_freq);
773-
} else {
774-
BOOST_LOG_TRIVIAL(error) << "\t - Unknown system type for Retune";
775-
}
776-
} else {
777-
for (vector<Source *>::iterator src_it = sources.begin(); src_it != sources.end(); src_it++) {
778-
Source *source = *src_it;
779-
780-
if ((source->get_min_hz() <= control_channel_freq) &&
781-
(source->get_max_hz() >= control_channel_freq)) {
782-
source_found = true;
783-
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());
784-
785-
if (system->get_system_type() == "smartnet") {
786-
system->set_source(source);
787-
// We must lock the flow graph in order to disconnect and reconnect blocks
788-
tb->lock();
789-
tb->disconnect(current_source->get_src_block(), 0, system->smartnet_trunking, 0);
790-
system->smartnet_trunking = make_smartnet_trunking(control_channel_freq, source->get_center(), source->get_rate(), system->get_msg_queue(), system->get_sys_num());
791-
tb->connect(source->get_src_block(), 0, system->smartnet_trunking, 0);
792-
tb->unlock();
793-
system->smartnet_trunking->reset();
794-
} else if (system->get_system_type() == "p25") {
795-
system->set_source(source);
796-
// We must lock the flow graph in order to disconnect and reconnect blocks
797-
tb->lock();
798-
tb->disconnect(current_source->get_src_block(), 0, system->p25_trunking, 0);
799-
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());
800-
tb->connect(source->get_src_block(), 0, system->p25_trunking, 0);
801-
tb->unlock();
802-
} else {
803-
BOOST_LOG_TRIVIAL(error) << "\t - Unkown system type for Retune";
804-
}
805-
806-
// break out of the For Loop
807-
break;
808-
}
824+
case UNKNOWN:
825+
break;
809826
}
810827
}
811-
if (!source_found) {
812-
BOOST_LOG_TRIVIAL(error) << "\t - Unable to retune System control channel, freq not covered by any source.";
813-
}
814828
}
815829

816830
void check_message_count(float timeDiff) {

trunk-recorder/systems/p25_parser.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,7 @@ std::vector<TrunkMessage> P25Parser::parse_message(gr::message::sptr msg, System
964964
return messages;
965965
} else if (type < 0) {
966966
BOOST_LOG_TRIVIAL(debug) << "unknown message type " << type;
967+
message.message_type = INVALID_CC_MESSAGE;
967968
messages.push_back(message);
968969
return messages;
969970
}
@@ -979,6 +980,7 @@ std::vector<TrunkMessage> P25Parser::parse_message(gr::message::sptr msg, System
979980

980981
if (s.length() < 2) {
981982
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();
983+
message.message_type = INVALID_CC_MESSAGE;
982984
messages.push_back(message);
983985
return messages;
984986
}
@@ -995,8 +997,7 @@ std::vector<TrunkMessage> P25Parser::parse_message(gr::message::sptr msg, System
995997
// //" at %f state %d len %d" %(nac, type, time.time(), self.state, len(s))
996998
if ((type != 7) && (type != 12)) // and nac not in self.trunked_systems:
997999
{
998-
BOOST_LOG_TRIVIAL(debug) << std::hex << "NON TBSK: nac " << nac << std::dec << " type " << type << " size " << msg->to_string().length() << " mesg len: " << msg->length();
999-
1000+
BOOST_LOG_TRIVIAL(debug) << std::hex << "NON TSBK: nac " << nac << std::dec << " type " << type << " size " << msg->to_string().length() << " mesg len: " << msg->length();
10001001
/*
10011002
if not self.configs:
10021003
# TODO: allow whitelist/blacklist rather than blind automatic-add
@@ -1071,7 +1072,13 @@ std::vector<TrunkMessage> P25Parser::parse_message(gr::message::sptr msg, System
10711072
return decode_mbt_data(opcode, header, mbt_data, link_id, nac, sys_num);
10721073
// self.trunked_systems[nac].decode_mbt_data(opcode, header << 16, mbt_data
10731074
// << 32)
1075+
} else if (type == 15)
1076+
{
1077+
//TDU with Link Contol. Link Control words should not be seen on an active Control Channel.
1078+
BOOST_LOG_TRIVIAL(debug) << "P25 Parser: TDULC on control channel. Retuning to next control channel.";
1079+
message.message_type = TDULC;
10741080
}
1081+
10751082
messages.push_back(message);
10761083
return messages;
10771084
}

trunk-recorder/systems/parser.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ enum MessageType {
2020
UU_ANS_REQ = 13,
2121
UU_V_GRANT = 14,
2222
UU_V_UPDATE = 15,
23+
INVALID_CC_MESSAGE = 16,
24+
TDULC = 17,
2325
UNKNOWN = 99
2426
};
2527

0 commit comments

Comments
 (0)