Skip to content

Commit

Permalink
Merge pull request #794 from robotastic/freq-list
Browse files Browse the repository at this point in the history
OpenMHz Uploader update
  • Loading branch information
robotastic authored Apr 7, 2023
2 parents 9d9def8 + 570c761 commit 7bb5742
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 38 deletions.
52 changes: 24 additions & 28 deletions plugins/openmhz_uploader/openmhz_uploader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ class Openmhz_Uploader : public Plugin_Api {
freq << std::fixed << std::setprecision(0);
freq << call_info.freq;

std::ostringstream error_count;
std::string error_count_string;
error_count << std::fixed << std::setprecision(0);
error_count << call_info.error_count;

std::ostringstream spike_count;
std::string spike_count_string;
spike_count << std::fixed << std::setprecision(0);
spike_count << call_info.spike_count;

std::ostringstream call_length;
std::string call_length_string;
call_length << std::fixed << std::setprecision(0);
Expand All @@ -77,28 +87,6 @@ class Openmhz_Uploader : public Plugin_Api {
source_list << "]";
}


std::ostringstream freq_list;
std::string freq_list_string;
freq_list << std::fixed << std::setprecision(2);
freq_list << "[";

if (call_info.transmission_error_list.size() != 0) {
for (std::size_t i = 0; i < call_info.transmission_error_list.size(); i++) {
freq_list << "{\"freq\": " << std::fixed << std::setprecision(0) << call_info.freq << ", \"time\": " << call_info.transmission_error_list[i].time << ", \"pos\": " << std::fixed << std::setprecision(2) << call_info.transmission_error_list[i].position << ", \"len\": " << call_info.transmission_error_list[i].total_len << ", \"error_count\": \"" << std::setprecision(0) <<call_info.transmission_error_list[i].error_count << "\", \"spike_count\": \"" << call_info.transmission_error_list[i].spike_count << "\"}";

if (i < (call_info.transmission_error_list.size() - 1)) {
freq_list << ", ";
} else {
freq_list << "]";
}
}
}else {
freq_list << "]";
}



char formattedTalkgroup[62];
snprintf(formattedTalkgroup, 61, "%c[%dm%10ld%c[0m", 0x1B, 35, call_info.talkgroup, 0x1B);
std::string talkgroup_display = boost::lexical_cast<std::string>(formattedTalkgroup);
Expand All @@ -108,9 +96,10 @@ class Openmhz_Uploader : public Plugin_Api {
int still_running = 0;
std::string response_buffer;
freq_string = freq.str();
error_count_string = error_count.str();
spike_count_string = spike_count.str();

source_list_string = source_list.str();
freq_list_string = freq_list.str();
call_length_string = call_length.str();

struct curl_httppost *formpost = NULL;
Expand All @@ -132,6 +121,18 @@ class Openmhz_Uploader : public Plugin_Api {
CURLFORM_COPYCONTENTS, freq_string.c_str(),
CURLFORM_END);

curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "error_count",
CURLFORM_COPYCONTENTS, error_count_string.c_str(),
CURLFORM_END);

curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "spike_count",
CURLFORM_COPYCONTENTS, spike_count_string.c_str(),
CURLFORM_END);

curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "start_time",
Expand Down Expand Up @@ -173,11 +174,6 @@ class Openmhz_Uploader : public Plugin_Api {
CURLFORM_COPYNAME, "source_list",
CURLFORM_COPYCONTENTS, source_list_string.c_str(),
CURLFORM_END);
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "freq_list",
CURLFORM_COPYCONTENTS, freq_list_string.c_str(),
CURLFORM_END);

curl = curl_easy_init();
multi_handle = curl_multi_init();
Expand Down
4 changes: 4 additions & 0 deletions trunk-recorder/call_concluder/call_concluder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ Call_Data_t Call_Concluder::create_call_data(Call *call, System *sys, Config con
call_info.status = INITIAL;
call_info.process_call_time = time(0);
call_info.retry_attempt = 0;
call_info.error_count = 0;
call_info.spike_count = 0;
call_info.freq = call->get_freq();
call_info.encrypted = call->get_encrypted();
call_info.emergency = call->get_emergency();
Expand Down Expand Up @@ -291,6 +293,8 @@ Call_Data_t Call_Concluder::create_call_data(Call *call, System *sys, Config con
std::string tag = sys->find_unit_tag(t.source);
Call_Source call_source = {t.source, t.start_time, total_length, false, "", tag};
Call_Error call_error = {t.start_time, total_length, t.length, t.error_count, t.spike_count};
call_info.error_count = call_info.error_count + t.error_count;
call_info.spike_count = call_info.spike_count + t.spike_count;
call_info.transmission_source_list.push_back(call_source);
call_info.transmission_error_list.push_back(call_error);

Expand Down
31 changes: 21 additions & 10 deletions trunk-recorder/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <time.h>
#include <unistd.h>
#include <utility>
#include <cmath>

#include "./global_structs.h"
#include "recorder_globals.h"
Expand Down Expand Up @@ -837,6 +838,15 @@ void print_status() {
Source *source = *it;
source->print_recorders();
}

BOOST_LOG_TRIVIAL(info) << "Control Channel Decode Rates: ";
for (std::vector<System *>::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";
}
}
}

void manage_calls() {
Expand Down Expand Up @@ -1380,7 +1390,8 @@ void check_message_count(float timeDiff) {
System_impl *sys = (System_impl *)*it;

if ((sys->get_system_type() != "conventional") && (sys->get_system_type() != "conventionalP25") && (sys->get_system_type() != "conventionalDMR")) {
float msgs_decoded_per_second = sys->message_count / timeDiff;
int msgs_decoded_per_second = std::floor(sys->message_count / timeDiff);
sys->set_decode_rate(msgs_decoded_per_second);

if (msgs_decoded_per_second < 2) {

Expand Down Expand Up @@ -1418,8 +1429,8 @@ void monitor_messages() {
int sys_num;
System *sys;

time_t lastStatusTime = time(NULL);
time_t lastMsgCountTime = time(NULL);
time_t last_status_time = time(NULL);
time_t last_decode_rate_check = time(NULL);
time_t management_timestamp = time(NULL);
time_t current_time = time(NULL);
std::vector<TrunkMessage> trunk_messages;
Expand Down Expand Up @@ -1491,11 +1502,11 @@ void monitor_messages() {

current_time = time(NULL);

float timeDiff = current_time - lastMsgCountTime;
float decode_rate_check_time_diff = current_time - last_decode_rate_check;

if (timeDiff >= 3.0) {
check_message_count(timeDiff);
lastMsgCountTime = current_time;
if (decode_rate_check_time_diff >= 3.0) {
check_message_count(decode_rate_check_time_diff);
last_decode_rate_check = current_time;
for (vector<System *>::iterator sys_it = systems.begin(); sys_it != systems.end(); sys_it++) {
System *system = *sys_it;
if (system->get_system_type() == "p25") {
Expand All @@ -1504,10 +1515,10 @@ void monitor_messages() {
}
}

float statusTimeDiff = current_time - lastStatusTime;
float print_status_time_diff = current_time - last_status_time;

if (statusTimeDiff > 200) {
lastStatusTime = current_time;
if (print_status_time_diff > 200) {
last_status_time = current_time;
print_status();
}
}
Expand Down
2 changes: 2 additions & 0 deletions trunk-recorder/systems/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ class System {
virtual int channel_count() = 0;
virtual int get_message_count() = 0;
virtual void set_message_count(int count) = 0;
virtual void set_decode_rate(int rate) = 0;
virtual int get_decode_rate() = 0;
virtual void add_channel(double channel) = 0;
virtual void add_conventional_recorder(analog_recorder_sptr rec) = 0;
virtual std::vector<analog_recorder_sptr> get_conventional_recorders() = 0;
Expand Down
10 changes: 10 additions & 0 deletions trunk-recorder/systems/system_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ System_impl::System_impl(int sys_num) {
d_tps_enabled = false;
retune_attempts = 0;
message_count = 0;
decode_rate = 0;
}

void System_impl::set_xor_mask(unsigned long sys_id, unsigned long wacn, unsigned long nac) {
Expand Down Expand Up @@ -368,6 +369,15 @@ int System_impl::get_message_count() {
void System_impl::set_message_count(int count) {
message_count = count;
}

void System_impl::set_decode_rate(int rate) {
decode_rate = rate;
}

int System_impl::get_decode_rate() {
return decode_rate;
}

void System_impl::add_control_channel(double control_channel) {
if (control_channels.size() == 0) {
control_channels.push_back(control_channel);
Expand Down
3 changes: 3 additions & 0 deletions trunk-recorder/systems/system_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class System_impl : public System {
std::string upload_script;
int bcfy_system_id;
int message_count;
int decode_rate;
int retune_attempts;
time_t last_message_time;
std::string bandplan;
Expand Down Expand Up @@ -174,6 +175,8 @@ class System_impl : public System {
int control_channel_count();
int get_message_count();
void set_message_count(int count);
int get_decode_rate();
void set_decode_rate(int rate);
void add_control_channel(double channel);
double get_next_control_channel();
double get_current_control_channel();
Expand Down

0 comments on commit 7bb5742

Please sign in to comment.