From b3036159b513d1a0bbe3c456b23c1ed4f93df5c4 Mon Sep 17 00:00:00 2001 From: Luke Berndt Date: Sat, 8 Jul 2023 09:30:54 -0400 Subject: [PATCH] Cleaned up some files --- trunk-recorder/gr_blocks/transmission_sink.cc | 110 ++++---- trunk-recorder/gr_blocks/transmission_sink.h | 7 +- trunk-recorder/main.cc | 260 +++++++----------- 3 files changed, 157 insertions(+), 220 deletions(-) diff --git a/trunk-recorder/gr_blocks/transmission_sink.cc b/trunk-recorder/gr_blocks/transmission_sink.cc index 1453ea84b..431701d7c 100644 --- a/trunk-recorder/gr_blocks/transmission_sink.cc +++ b/trunk-recorder/gr_blocks/transmission_sink.cc @@ -23,8 +23,8 @@ #include "transmission_sink.h" #include "../../trunk-recorder/call.h" -#include #include +#include #include #include #include @@ -62,11 +62,11 @@ transmission_sink::transmission_sink(int n_channels, unsigned int sample_rate, i : sync_block("transmission_sink", io_signature::make(1, n_channels, sizeof(int16_t)), io_signature::make(0, 0, 0)), - d_sample_rate(sample_rate), + d_sample_rate(sample_rate), d_nchans(n_channels), - d_current_call(NULL), + d_current_call(NULL), d_fp(0) { - + if ((bits_per_sample != 8) && (bits_per_sample != 16)) { throw std::runtime_error("Invalid bits per sample (supports 8 and 16)"); } @@ -77,15 +77,12 @@ transmission_sink::transmission_sink(int n_channels, unsigned int sample_rate, i state = AVAILABLE; } - -// static int rec_counter=0; void transmission_sink::create_filename() { time_t work_start_time = d_start_time; std::stringstream temp_path_stream; tm *ltm = localtime(&work_start_time); // Found some good advice on Streams and Strings here: https://blog.sensecodons.com/2013/04/dont-let-stdstringstreamstrcstr-happen.html - //temp_path_stream << d_current_call_temp_dir << "/" << d_current_call_short_name << "/" << 1900 + ltm->tm_year << "/" << 1 + ltm->tm_mon << "/" << ltm->tm_mday; - + temp_path_stream << d_current_call_temp_dir << "/" << d_current_call_short_name; std::string temp_path_string = temp_path_stream.str(); boost::filesystem::create_directories(temp_path_string); @@ -120,7 +117,6 @@ bool transmission_sink::start_recording(Call *call) { } d_current_call = call; d_current_call_num = call->get_call_num(); - d_current_call_recorder_num = 0; // call->get_recorder()->get_num(); d_current_call_freq = call->get_freq(); d_current_call_talkgroup = call->get_talkgroup(); d_current_call_talkgroup_display = call->get_talkgroup_display(); @@ -134,8 +130,7 @@ bool transmission_sink::start_recording(Call *call) { d_prior_transmission_length = 0; d_error_count = 0; d_spike_count = 0; - d_last_write_time = std::chrono::steady_clock::now(); // we want to make sure the call doesn't get cleaned up before data starts coming in. - + d_last_write_time = std::chrono::steady_clock::now(); // we want to make sure the call doesn't get cleaned up before data starts coming in. this->clear_transmission_list(); d_conventional = call->is_conventional(); @@ -182,9 +177,9 @@ bool transmission_sink::open_internal(const char *filename) { BOOST_LOG_TRIVIAL(error) << "wav open failed" << std::endl; return false; } - if(std::setvbuf(d_fp, nullptr, _IOFBF, 1000000) != 0) { - BOOST_LOG_TRIVIAL(error) << "setvbuf failed"; // POSIX version sets errno - } + if (std::setvbuf(d_fp, nullptr, _IOFBF, 1000000) != 0) { + BOOST_LOG_TRIVIAL(error) << "setvbuf failed"; // POSIX version sets errno + } d_sample_count = 0; if (!wavheader_write(d_fp, d_sample_rate, d_nchans, d_bytes_per_sample)) { @@ -209,7 +204,7 @@ bool transmission_sink::open_internal(const char *filename) { void transmission_sink::set_source(long src) { if (curr_src_id == -1) { - + BOOST_LOG_TRIVIAL(info) << "[" << d_current_call_short_name << "]\t\033[0;34m" << d_current_call_num << "C\033[0m\tTG: " << d_current_call_talkgroup_display << "\tFreq: " << format_freq(d_current_call_freq) << "\tUnit ID set via Control Channel, ext: " << src << "\tcurrent: " << curr_src_id << "\t samples: " << d_sample_count; curr_src_id = src; @@ -310,10 +305,9 @@ int transmission_sink::work(int noutput_items, gr_vector_const_void_star &input_ // It is possible the P25 Frame Assembler passes a TDU after the call has timed out. // In this case, the termination tag will be transferred on a blank sample and can safely be ignored. - if(noutput_items == 1){ + if (noutput_items == 1) { BOOST_LOG_TRIVIAL(trace) << "[" << d_current_call_short_name << "]\t\033[0;34m" << d_current_call_num << "C\033[0m\tTG: " << d_current_call_talkgroup_display << "\tFreq: " << format_freq(d_current_call_freq) << "\tDropping " << noutput_items << " samples - current_call is null\t Rec State: " << format_state(this->state) << "\tSince close: " << its_been; - } - else{ + } else { BOOST_LOG_TRIVIAL(error) << "[" << d_current_call_short_name << "]\t\033[0;34m" << d_current_call_num << "C\033[0m\tTG: " << d_current_call_talkgroup_display << "\tFreq: " << format_freq(d_current_call_freq) << "\tDropping " << noutput_items << " samples - current_call is null\t Rec State: " << format_state(this->state) << "\tSince close: " << its_been; } @@ -350,19 +344,19 @@ int transmission_sink::work(int noutput_items, gr_vector_const_void_star &input_ long grp_id = pmt::to_long(tags[i].value); if ((state == RECORDING) || (state == IDLE)) { - if(d_current_call_talkgroup_encoded != grp_id) { + if (d_current_call_talkgroup_encoded != grp_id) { if (!d_conventional) { BOOST_LOG_TRIVIAL(info) << "[" << d_current_call_short_name << "]\t\033[0;34m" << d_current_call_num << "C\033[0m\tTG: " << d_current_call_talkgroup_display << "\tFreq: " << format_freq(d_current_call_freq) << "\tGROUP MISMATCH - Recorder TG: " << d_current_call_talkgroup_encoded << " Received TG: " << grp_id << " Recorder state: " << format_state(state) << " incoming: " << noutput_items; - if (d_sample_count > 0) { - BOOST_LOG_TRIVIAL(info) << "[" << d_current_call_short_name << "]\t\033[0;34m" << d_current_call_num << "C\033[0m\tTG: " << d_current_call_talkgroup_display << "\tFreq: " << format_freq(d_current_call_freq) << "\tEnding Transmission and IGNORING Rest - count: " << d_sample_count; - end_transmission(); - } + if (d_sample_count > 0) { + BOOST_LOG_TRIVIAL(info) << "[" << d_current_call_short_name << "]\t\033[0;34m" << d_current_call_num << "C\033[0m\tTG: " << d_current_call_talkgroup_display << "\tFreq: " << format_freq(d_current_call_freq) << "\tEnding Transmission and IGNORING Rest - count: " << d_sample_count; + end_transmission(); + } state = IGNORE; } else { BOOST_LOG_TRIVIAL(info) << "[" << d_current_call_short_name << "]\t\033[0;34m" << d_current_call_num << "C\033[0m\tTG: " << d_current_call_talkgroup_display << "\tFreq: " << format_freq(d_current_call_freq) << "\tGroup Mismatch - Recorder Received TG: " << grp_id << " Recorder state: " << format_state(state) << " incoming samples: " << noutput_items; } } - } + } } if (pmt::eq(src_id_key, tags[i].key)) { long src_id = pmt::to_long(tags[i].value); @@ -471,14 +465,14 @@ int transmission_sink::dowork(int noutput_items, gr_vector_const_void_star &inpu return noutput_items; } - if (state == IGNORE ) { - BOOST_LOG_TRIVIAL(trace) << "[" << d_current_call_short_name << "]\t\033[0;34m" << d_current_call_num << "C\033[0m\tTG: " << d_current_call_talkgroup_display << "\tFreq: " << format_freq(d_current_call_freq) << "\tResetting state from IGNORE to IDLE: " << noutput_items; - state = IDLE; + if (state == IGNORE) { + BOOST_LOG_TRIVIAL(trace) << "[" << d_current_call_short_name << "]\t\033[0;34m" << d_current_call_num << "C\033[0m\tTG: " << d_current_call_talkgroup_display << "\tFreq: " << format_freq(d_current_call_freq) << "\tResetting state from IGNORE to IDLE: " << noutput_items; + state = IDLE; } if (d_sample_count > 0) { BOOST_LOG_TRIVIAL(trace) << "[" << d_current_call_short_name << "]\t\033[0;34m" << d_current_call_num << "C\033[0m\tTG: " << d_current_call_talkgroup_display << "\tFreq: " << format_freq(d_current_call_freq) << "\tTERMINATING! - count: " << d_sample_count; end_transmission(); - + if (noutput_items > 1) { BOOST_LOG_TRIVIAL(trace) << "[" << d_current_call_short_name << "]\t\033[0;34m" << d_current_call_num << "C\033[0m\tTG: " << d_current_call_talkgroup_display << "\tFreq: " << format_freq(d_current_call_freq) << "\tTERM - there were some items to output: " << noutput_items; } @@ -489,43 +483,41 @@ int transmission_sink::dowork(int noutput_items, gr_vector_const_void_star &inpu return noutput_items; } - if (state == IGNORE ) { + if (state == IGNORE) { BOOST_LOG_TRIVIAL(trace) << "[" << d_current_call_short_name << "]\t\033[0;34m" << d_current_call_num << "C\033[0m\tTG: " << d_current_call_talkgroup_display << "\tFreq: " << format_freq(d_current_call_freq) << "\tIGNORE missing count: " << noutput_items; - return noutput_items; + return noutput_items; } if (state == IDLE) { - //BOOST_LOG_TRIVIAL(info) << "[" << d_current_call_short_name << "]\t\033[0;34m" << d_current_call_num << "C\033[0m\tTG: " << d_current_call_talkgroup_display << "\tFreq: " << format_freq(d_current_call_freq) << "\tIDLE but haven't seen Group ID yet, missing count: " << noutput_items; - //return noutput_items; - if (d_fp) { - // if we are already recording a file for this call, close it before starting a new one. - BOOST_LOG_TRIVIAL(info) << "WAV - Weird! we have an existing FP, but STATE was IDLE: " << current_filename << std::endl; + // BOOST_LOG_TRIVIAL(info) << "[" << d_current_call_short_name << "]\t\033[0;34m" << d_current_call_num << "C\033[0m\tTG: " << d_current_call_talkgroup_display << "\tFreq: " << format_freq(d_current_call_freq) << "\tIDLE but haven't seen Group ID yet, missing count: " << noutput_items; + // return noutput_items; + if (d_fp) { + // if we are already recording a file for this call, close it before starting a new one. + BOOST_LOG_TRIVIAL(info) << "WAV - Weird! we have an existing FP, but STATE was IDLE: " << current_filename << std::endl; - close_wav(false); - } + close_wav(false); + } - time_t current_time = time(NULL); - if (current_time == d_start_time) { - d_start_time = current_time + 1; - } else { - d_start_time = current_time; - } + time_t current_time = time(NULL); + if (current_time == d_start_time) { + d_start_time = current_time + 1; + } else { + d_start_time = current_time; + } - // create a new filename, based on the current time and source. - create_filename(); - if (!open_internal(current_filename)) { - BOOST_LOG_TRIVIAL(error) << "can't open file"; - return noutput_items; - } + // create a new filename, based on the current time and source. + create_filename(); + if (!open_internal(current_filename)) { + BOOST_LOG_TRIVIAL(error) << "can't open file"; + return noutput_items; + } - BOOST_LOG_TRIVIAL(trace) << "[" << d_current_call_short_name << "]\t\033[0;34m" << d_current_call_num << "C\033[0m\tTG: " << d_current_call_talkgroup_display << "\tFreq: " << format_freq(d_current_call_freq) << "\tStarting new Transmission \tSrc ID: " << curr_src_id; + BOOST_LOG_TRIVIAL(trace) << "[" << d_current_call_short_name << "]\t\033[0;34m" << d_current_call_num << "C\033[0m\tTG: " << d_current_call_talkgroup_display << "\tFreq: " << format_freq(d_current_call_freq) << "\tStarting new Transmission \tSrc ID: " << curr_src_id; - // curr_src_id = d_current_call->get_current_source_id(); - state = RECORDING; - + // curr_src_id = d_current_call->get_current_source_id(); + state = RECORDING; } - if (!d_fp) // drop output on the floor { BOOST_LOG_TRIVIAL(error) << "Wav - Dropping items, no fp or Current Call: " << noutput_items << " Filename: " << current_filename << " Current sample count: " << d_sample_count << std::endl; @@ -551,8 +543,8 @@ int transmission_sink::dowork(int noutput_items, gr_vector_const_void_star &inpu } } - d_stop_time = time(NULL); - d_last_write_time = std::chrono::steady_clock::now(); + d_stop_time = time(NULL); + d_last_write_time = std::chrono::steady_clock::now(); if (nwritten < noutput_items) { BOOST_LOG_TRIVIAL(error) << "[" << d_current_call_short_name << "]\t\033[0;34m" << d_current_call_num << "C\033[0m\tTG: " << d_current_call_talkgroup_display << "\tFreq: " << format_freq(d_current_call_freq) << "\tFailed to Write! Wrote: " << nwritten << " of " << noutput_items; @@ -590,13 +582,7 @@ double transmission_sink::total_length_in_seconds() { } double transmission_sink::length_in_seconds() { - // std::cout << "Filename: "<< current_filename << "Sample #: " << - // d_sample_count << " rate: " << d_sample_rate << " bytes: " << - // d_bytes_per_sample << "\n"; return (double)d_sample_count / (double)d_sample_rate; - - // return (double) ( d_sample_count * d_bytes_per_sample_new * 8) / (double) - // d_sample_rate; } void transmission_sink::do_update() {} diff --git a/trunk-recorder/gr_blocks/transmission_sink.h b/trunk-recorder/gr_blocks/transmission_sink.h index 72ebfef53..31f68e02a 100644 --- a/trunk-recorder/gr_blocks/transmission_sink.h +++ b/trunk-recorder/gr_blocks/transmission_sink.h @@ -52,7 +52,7 @@ class BLOCKS_API transmission_sink : virtual public sync_block { bool d_termination_flag; time_t d_start_time; time_t d_stop_time; - std::chrono::time_point d_last_write_time; + std::chrono::time_point d_last_write_time; long d_spike_count; long d_error_count; long curr_src_id; @@ -60,7 +60,6 @@ class BLOCKS_API transmission_sink : virtual public sync_block { char current_filename[255]; Call *d_current_call; long d_current_call_num; - long d_current_call_recorder_num; std::string d_current_call_short_name; std::string d_current_call_temp_dir; double d_current_call_freq; @@ -69,7 +68,6 @@ class BLOCKS_API transmission_sink : virtual public sync_block { long d_current_call_talkgroup_encoded; std::string d_current_call_talkgroup_display; - protected: unsigned d_sample_count; int d_bytes_per_sample; @@ -144,8 +142,7 @@ class BLOCKS_API transmission_sink : virtual public sync_block { State get_state(); time_t get_start_time(); time_t get_stop_time(); - std::chrono::time_point get_last_write_time(); - + std::chrono::time_point get_last_write_time(); }; } /* namespace blocks */ diff --git a/trunk-recorder/main.cc b/trunk-recorder/main.cc index 78ce1eb65..5d5f44b2a 100644 --- a/trunk-recorder/main.cc +++ b/trunk-recorder/main.cc @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -36,7 +37,6 @@ #include #include #include -#include #include "./global_structs.h" #include "recorder_globals.h" @@ -83,7 +83,6 @@ std::vector calls; gr::top_block_sptr tb; - volatile sig_atomic_t exit_flag = 0; int exit_code = EXIT_SUCCESS; SmartnetParser *smartnet_parser; @@ -185,7 +184,7 @@ bool load_config(string config_file) { BOOST_LOG_TRIVIAL(info) << "Using Config file: " << config_file << "\n"; BOOST_LOG_TRIVIAL(info) << PROJECT_NAME << ": " - << "Version: " << PROJECT_VER << "\n"; + << "Version: " << PROJECT_VER << "\n"; BOOST_LOG_TRIVIAL(info) << "Log to File: " << config.log_file; BOOST_LOG_TRIVIAL(info) << "Log Directory: " << config.log_dir; @@ -242,7 +241,6 @@ bool load_config(string config_file) { BOOST_LOG_TRIVIAL(info) << "New Call from UPDATE Messages" << config.new_call_from_update; std::string frequency_format_string = pt.get("frequencyFormat", "mhz"); - if (boost::iequals(frequency_format_string, "mhz")) { frequency_format = 1; } else if (boost::iequals(frequency_format_string, "hz")) { @@ -320,7 +318,7 @@ bool load_config(string config_file) { system->add_control_channel(control_channel); } std::vector control_channels = system->get_control_channels(); - for(unsigned int i = 0; i < control_channels.size(); i++) { + for (unsigned int i = 0; i < control_channels.size(); i++) { BOOST_LOG_TRIVIAL(info) << " " << format_freq(control_channels[i]); } system->set_talkgroups_file(node.second.get("talkgroupsFile", "")); @@ -411,10 +409,9 @@ bool load_config(string config_file) { system->set_xor_mask(sys_id, wacn, nac); system->set_bandplan(node.second.get("bandplan", "800_standard")); system->set_bandfreq(800); // Default to 800 - + if (boost::starts_with(system->get_bandplan(), "400")) { system->set_bandfreq(400); - } system->set_bandplan_base(node.second.get("bandplanBase", 0.0)); system->set_bandplan_high(node.second.get("bandplanHigh", 0.0)); @@ -879,7 +876,6 @@ void print_status() { } } - BOOST_LOG_TRIVIAL(info) << "Recorders: "; for (vector::iterator it = sources.begin(); it != sources.end(); it++) { @@ -887,14 +883,14 @@ void print_status() { source->print_recorders(); } - BOOST_LOG_TRIVIAL(info) << "Control Channel Decode Rates: "; - for (std::vector::iterator it = systems.begin(); it != systems.end(); ++it) { + BOOST_LOG_TRIVIAL(info) << "Control Channel Decode Rates: "; + for (std::vector::iterator it = systems.begin(); it != systems.end(); ++it) { System_impl *sys = (System_impl *)*it; - if ((sys->get_system_type() != "conventional") && (sys->get_system_type() != "conventionalP25") && (sys->get_system_type() != "conventionalDMR")) { - BOOST_LOG_TRIVIAL(info) << "[" << sys->get_short_name() << "] " << sys->get_decode_rate() << " msg/sec"; - } - } + if ((sys->get_system_type() != "conventional") && (sys->get_system_type() != "conventionalP25") && (sys->get_system_type() != "conventionalDMR")) { + BOOST_LOG_TRIVIAL(info) << "[" << sys->get_short_name() << "] " << sys->get_decode_rate() << " msg/sec"; + } + } } void manage_calls() { @@ -912,58 +908,36 @@ void manage_calls() { // Handle Trunked Calls if ((state == MONITORING) && (call->since_last_update() > config.call_timeout)) { - ended_call = true; - it = calls.erase(it); - delete call; - continue; + ended_call = true; + it = calls.erase(it); + delete call; + continue; } - if (state == RECORDING) { + if (state == RECORDING) { Recorder *recorder = call->get_recorder(); // Stop the call if: // - there hasn't been an UPDATE for it on the Control Channel in X seconds AND the recorder hasn't written anything in X seconds - // OR - // - the recorder has been stopped - // actually, we don't want to remove a recorder as soon as it is stopped because we want to drain everything from the gnuradio flowgraph - if ((recorder->since_last_write() > config.call_timeout) && (call->since_last_update() > config.call_timeout)) { - BOOST_LOG_TRIVIAL(trace) << "[" << call->get_short_name() << "]\t\033[0;34m" << call->get_call_num() << "C\033[0m\tTG: " << call->get_talkgroup_display() << "\tFreq: " << format_freq(call->get_freq()) << "\t\u001b[36m Stopping Call because of Recorder \u001b[0m Rec last write: " << recorder->since_last_write() << " State: " << format_state(recorder->get_state()); - call->conclude_call(); - // The State of the Recorders has changed, so lets send an update - ended_call = true; - if (recorder != NULL) { - plugman_setup_recorder(recorder); - } - it = calls.erase(it); - delete call; - continue; - } else { - //BOOST_LOG_TRIVIAL(info) << "[" << call->get_short_name() << "]\t\033[0;34m" << call->get_call_num() << "C\033[0m\tTG: " << call->get_talkgroup_display() << "\tFreq: " << format_freq(call->get_freq()) << "\t\u001b[36m Still good!! \u001b[0m Rec last write: " << recorder->since_last_write() << " State: " << format_state(recorder->get_state()); + if ((recorder->since_last_write() > config.call_timeout) && (call->since_last_update() > config.call_timeout)) { + BOOST_LOG_TRIVIAL(trace) << "[" << call->get_short_name() << "]\t\033[0;34m" << call->get_call_num() << "C\033[0m\tTG: " << call->get_talkgroup_display() << "\tFreq: " << format_freq(call->get_freq()) << "\t\u001b[36m Stopping Call because of Recorder \u001b[0m Rec last write: " << recorder->since_last_write() << " State: " << format_state(recorder->get_state()); + call->conclude_call(); + // The State of the Recorders has changed, so lets send an update + ended_call = true; + if (recorder != NULL) { + plugman_setup_recorder(recorder); + } + it = calls.erase(it); + delete call; + continue; } } else if (call->since_last_update() > config.call_timeout) { - Recorder *recorder = call->get_recorder(); - // BOOST_LOG_TRIVIAL(info) << "Recorder state: " << recorder->get_state(); - BOOST_LOG_TRIVIAL(trace) << "[" << call->get_short_name() << "]\t\033[0;34m" << call->get_call_num() << "C\033[0m\tTG: " << call->get_talkgroup_display() << "\tFreq: " << format_freq(call->get_freq()) << "\t\u001b[36m Call UPDATEs has been inactive for more than " << config.call_timeout << " Sec \u001b[0m Rec last write: " << recorder->since_last_write() << " State: " << format_state(recorder->get_state()); - - // since the Call state is INACTIVE and the Recorder has been going on for a while, we can now - // - /* - call->conclude_call(); - // The State of the Recorders has changed, so lets send an update - ended_call = true; + Recorder *recorder = call->get_recorder(); - if (recorder != NULL) { - plugman_setup_recorder(recorder); - } - it = calls.erase(it); - delete call; - continue;*/ + BOOST_LOG_TRIVIAL(trace) << "[" << call->get_short_name() << "]\t\033[0;34m" << call->get_call_num() << "C\033[0m\tTG: " << call->get_talkgroup_display() << "\tFreq: " << format_freq(call->get_freq()) << "\t\u001b[36m Call UPDATEs has been inactive for more than " << config.call_timeout << " Sec \u001b[0m Rec last write: " << recorder->since_last_write() << " State: " << format_state(recorder->get_state()); } - - ++it; - // if rx is active } // foreach loggers if (ended_call) { @@ -1021,12 +995,12 @@ void handle_call_grant(TrunkMessage message, System *sys, bool grant_message) { going until it gets a termination flag. */ - //BOOST_LOG_TRIVIAL(info) << "TG: " << message.talkgroup << " sys num: " << message.sys_num << " freq: " << message.freq << " TDMA Slot" << message.tdma_slot << " TDMA: " << message.phase2_tdma; + // BOOST_LOG_TRIVIAL(info) << "TG: " << message.talkgroup << " sys num: " << message.sys_num << " freq: " << message.freq << " TDMA Slot" << message.tdma_slot << " TDMA: " << message.phase2_tdma; unsigned long message_preferredNAC = 0; Talkgroup *message_talkgroup = sys->find_talkgroup(message.talkgroup); if (message_talkgroup) { - message_preferredNAC = message_talkgroup->get_preferredNAC(); + message_preferredNAC = message_talkgroup->get_preferredNAC(); } for (vector::iterator it = calls.begin(); it != calls.end();) { @@ -1034,56 +1008,53 @@ void handle_call_grant(TrunkMessage message, System *sys, bool grant_message) { /* This is for Multi-Site support */ if (call->get_talkgroup() == message.talkgroup) { - if ((call->get_phase2_tdma() == message.phase2_tdma) && (call->get_tdma_slot() == message.tdma_slot) ) { - if (call->get_sys_num() != message.sys_num) { - if (call->get_system()->get_multiSite() && sys->get_multiSite()) { - if (call->get_system()->get_wacn() == sys->get_wacn()) { - // Default mode to match WACN and NAC and use a preferred NAC; - if (call->get_system()->get_nac() != sys->get_nac() && (call->get_system()->get_multiSiteSystemName() == "")) { - if (call->get_state() == RECORDING) { - - duplicate_grant = true; - original_call = call; - - unsigned long call_preferredNAC = 0; - Talkgroup *call_talkgroup = call->get_system()->find_talkgroup(message.talkgroup); - if (call_talkgroup) { - call_preferredNAC = call_talkgroup->get_preferredNAC(); - - } + if ((call->get_phase2_tdma() == message.phase2_tdma) && (call->get_tdma_slot() == message.tdma_slot)) { + if (call->get_sys_num() != message.sys_num) { + if (call->get_system()->get_multiSite() && sys->get_multiSite()) { + if (call->get_system()->get_wacn() == sys->get_wacn()) { + // Default mode to match WACN and NAC and use a preferred NAC; + if (call->get_system()->get_nac() != sys->get_nac() && (call->get_system()->get_multiSiteSystemName() == "")) { + if (call->get_state() == RECORDING) { + + duplicate_grant = true; + original_call = call; + + unsigned long call_preferredNAC = 0; + Talkgroup *call_talkgroup = call->get_system()->find_talkgroup(message.talkgroup); + if (call_talkgroup) { + call_preferredNAC = call_talkgroup->get_preferredNAC(); + } - if ((call_preferredNAC != call->get_system()->get_nac() ) && (message_preferredNAC == sys->get_nac())) { - superseding_grant = true; + if ((call_preferredNAC != call->get_system()->get_nac()) && (message_preferredNAC == sys->get_nac())) { + superseding_grant = true; + } } - } - } - // If a multiSiteSystemName has been manually entered; - // We already know that Call's system number does not match the message system number. - // In this case, we check that the multiSiteSystemName is present, and that the Call and System multiSiteSystemNames are the same. - else if ((call->get_system()->get_multiSiteSystemName() != "") && (call->get_system()->get_multiSiteSystemName() == sys->get_multiSiteSystemName())) { - if (call->get_state() == RECORDING) { - - duplicate_grant = true; - original_call = call; - - unsigned long call_preferredNAC = 0; - Talkgroup *call_talkgroup = call->get_system()->find_talkgroup(message.talkgroup); - if (call_talkgroup) { - call_preferredNAC = call_talkgroup->get_preferredNAC(); - } + // If a multiSiteSystemName has been manually entered; + // We already know that Call's system number does not match the message system number. + // In this case, we check that the multiSiteSystemName is present, and that the Call and System multiSiteSystemNames are the same. + else if ((call->get_system()->get_multiSiteSystemName() != "") && (call->get_system()->get_multiSiteSystemName() == sys->get_multiSiteSystemName())) { + if (call->get_state() == RECORDING) { + + duplicate_grant = true; + original_call = call; + + unsigned long call_preferredNAC = 0; + Talkgroup *call_talkgroup = call->get_system()->find_talkgroup(message.talkgroup); + if (call_talkgroup) { + call_preferredNAC = call_talkgroup->get_preferredNAC(); + } - if((call->get_system()->get_multiSiteSystemNumber() != 0 ) && (sys->get_multiSiteSystemNumber() != 0 )) - { - if ((call_preferredNAC != call->get_system()->get_multiSiteSystemNumber()) && (message_preferredNAC == sys->get_multiSiteSystemNumber())) { - superseding_grant = true; + if ((call->get_system()->get_multiSiteSystemNumber() != 0) && (sys->get_multiSiteSystemNumber() != 0)) { + if ((call_preferredNAC != call->get_system()->get_multiSiteSystemNumber()) && (message_preferredNAC == sys->get_multiSiteSystemNumber())) { + superseding_grant = true; + } } } } } } } - } } } @@ -1104,11 +1075,6 @@ void handle_call_grant(TrunkMessage message, System *sys, bool grant_message) { recorder_state = format_state(recorder->get_state()); } BOOST_LOG_TRIVIAL(trace) << "[" << call->get_short_name() << "]\t\033[0;34m" << call->get_call_num() << "C\033[0m\tTG: " << call->get_talkgroup_display() << "\tFreq: " << format_freq(call->get_freq()) << "\t\u001b[36mShould be Stopping RECORDING call, Recorder State: " << recorder_state << " RX overlapping TG message Freq, TG:" << message.talkgroup << "\u001b[0m"; -/* - call->conclude_call(); - it = calls.erase(it); - delete call; - continue;*/ } it++; @@ -1125,34 +1091,30 @@ void handle_call_grant(TrunkMessage message, System *sys, bool grant_message) { call->set_talkgroup_tag("-"); } - - if(superseding_grant) { + if (superseding_grant) { BOOST_LOG_TRIVIAL(info) << "[" << call->get_short_name() << "]\t\033[0;34m" << call->get_call_num() << "C\033[0m\tTG: " << original_call->get_talkgroup_display() << "\tFreq: " << format_freq(call->get_freq()) << "\t\u001b[36mSuperseding Grant. Original Call NAC: " << original_call->get_system()->get_nac() << " Grant Message NAC: " << sys->get_nac() << "\t State: " << format_state(original_call->get_state()) << "\u001b[0m"; // Attempt to start a new call on the preferred NAC. recording_started = start_recorder(call, message, sys); - - if(recording_started) { + + if (recording_started) { // Clean up the original call. original_call->set_state(MONITORING); original_call->set_monitoring_state(SUPERSEDED); original_call->conclude_call(); - } - else{ + } else { BOOST_LOG_TRIVIAL(info) << "[" << call->get_short_name() << "]\t\033[0;34m" << call->get_call_num() << "C\033[0m\tTG: " << original_call->get_talkgroup_display() << "\tFreq: " << format_freq(call->get_freq()) << "\t\u001b[36mCould not start Superseding recorder. Continuing original call: " << original_call->get_call_num() << "C\u001b[0m"; } - } - else if (duplicate_grant) { + } else if (duplicate_grant) { call->set_state(MONITORING); call->set_monitoring_state(DUPLICATE); BOOST_LOG_TRIVIAL(info) << "[" << call->get_short_name() << "]\t\033[0;34m" << call->get_call_num() << "C\033[0m\tTG: " << original_call->get_talkgroup_display() << "\tFreq: " << format_freq(call->get_freq()) << "\t\u001b[36mDuplicate Grant. Original Call NAC: " << original_call->get_system()->get_nac() << " Grant Message NAC: " << sys->get_nac() << " Source: " << message.source << " Call: " << original_call->get_call_num() << "C State: " << format_state(original_call->get_state()) << "\u001b[0m"; - } - else { + } else { recording_started = start_recorder(call, message, sys); if (recording_started && !grant_message) { BOOST_LOG_TRIVIAL(info) << "[" << call->get_short_name() << "]\t\033[0;34m" << call->get_call_num() << "C\033[0m\tTG: " << call->get_talkgroup_display() << "\tFreq: " << format_freq(call->get_freq()) << "\t\u001b[36mThis was an UPDATE\u001b[0m"; } - } + } calls.push_back(call); plugman_call_start(call); plugman_calls_active(calls); @@ -1370,7 +1332,8 @@ void check_message_count(float timeDiff) { if (config.control_retune_limit > 0) { sys->retune_attempts++; if (sys->retune_attempts > config.control_retune_limit) { - BOOST_LOG_TRIVIAL(error) << "[" << sys->get_short_name() << "]\t" << "Control channel retune limit exceeded after " << sys->retune_attempts << " tries - Terminating trunk recorder"; + BOOST_LOG_TRIVIAL(error) << "[" << sys->get_short_name() << "]\t" + << "Control channel retune limit exceeded after " << sys->retune_attempts << " tries - Terminating trunk recorder"; exit_flag = 1; exit_code = EXIT_FAILURE; return; @@ -1382,7 +1345,6 @@ void check_message_count(float timeDiff) { BOOST_LOG_TRIVIAL(error) << "[" << sys->get_short_name() << "]\tThere is only one control channel defined"; } - } else { sys->retune_attempts = 0; } @@ -1432,50 +1394,45 @@ void monitor_messages() { plugman_poll_one(); + for (vector::iterator sys_it = systems.begin(); sys_it != systems.end(); sys_it++) { + System_impl *system = (System_impl *)*sys_it; -for (vector::iterator sys_it = systems.begin(); sys_it != systems.end(); sys_it++) { - System_impl *system = (System_impl *)*sys_it; + if ((system->get_system_type() == "p25") || (system->get_system_type() == "smartnet")) { + msg.reset(); + msg = system->get_msg_queue()->delete_head_nowait(); + while (msg != 0) { + system->set_message_count(system->get_message_count() + 1); + if (system->get_system_type() == "smartnet") { + trunk_messages = smartnet_parser->parse_message(msg->to_string(), system); + handle_message(trunk_messages, system); + plugman_trunk_message(trunk_messages, system); + } - if ((system->get_system_type() == "p25") || (system->get_system_type() == "smartnet") ) { - msg.reset(); - msg = system->get_msg_queue()->delete_head_nowait(); - while (msg != 0) { - system->set_message_count(system->get_message_count() + 1); - - if (system->get_system_type() == "smartnet") { - trunk_messages = smartnet_parser->parse_message(msg->to_string(), system); - handle_message(trunk_messages, system); - plugman_trunk_message(trunk_messages, system); - } + if (system->get_system_type() == "p25") { + trunk_messages = p25_parser->parse_message(msg, system); + handle_message(trunk_messages, system); + plugman_trunk_message(trunk_messages, system); + } - if (system->get_system_type() == "p25") { - trunk_messages = p25_parser->parse_message(msg, system); - handle_message(trunk_messages, system); - plugman_trunk_message(trunk_messages, system); - } - + if (msg->type() == -1) { + BOOST_LOG_TRIVIAL(error) << "[" << system->get_short_name() << "]\t process_data_unit timeout"; + } - if (msg->type() == -1) { - BOOST_LOG_TRIVIAL(error) << "[" << system->get_short_name() << "]\t process_data_unit timeout"; + msg.reset(); + msg = system->get_msg_queue()->delete_head_nowait(); + } } - - msg.reset(); - msg = system->get_msg_queue()->delete_head_nowait(); - } } -} - current_time = time(NULL); + current_time = time(NULL); - if ((current_time - management_timestamp) >= 1.0) { - manage_calls(); - Call_Concluder::manage_call_data_workers(); - management_timestamp = current_time; - } + if ((current_time - management_timestamp) >= 1.0) { + manage_calls(); + Call_Concluder::manage_call_data_workers(); + management_timestamp = current_time; + } - boost::this_thread::sleep(boost::posix_time::milliseconds(10)); - // usleep(1000 * 10); - + boost::this_thread::sleep(boost::posix_time::milliseconds(10)); float decode_rate_check_time_diff = current_time - last_decode_rate_check; @@ -1668,9 +1625,6 @@ int main(int argc, char **argv) { boost::log::core::get()->add_global_attribute("Scope", boost::log::attributes::named_scope()); boost::log::core::get()->set_filter(boost::log::trivial::severity >= boost::log::trivial::info); - // boost::log::sinks->imbue(std::locale("C")); - // std::locale::global(std::locale("C")); - boost::program_options::options_description desc("Options"); desc.add_options()("help,h", "Help screen")("config,c", boost::program_options::value()->default_value("./config.json"), "Config File")("version,v", "Version Information"); @@ -1691,7 +1645,7 @@ int main(int argc, char **argv) { string config_file = vm["config"].as(); tb = gr::make_top_block("Trunking"); - + smartnet_parser = new SmartnetParser(); // this has to eventually be generic; p25_parser = new P25Parser();