Skip to content

Commit

Permalink
Channel csv fix (#862)
Browse files Browse the repository at this point in the history
* Fix channel CSV parsing, allow for freqs in MHz

* Update docs

* Change system IDs to ints to fix JSON type error

---------

Co-authored-by: Eric Tendian <erictendian@gmail.com>
  • Loading branch information
robotastic and EricTendian authored Nov 12, 2023
1 parent 0135d74 commit 6bd1c98
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion docs/CONFIGURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ This file allows for you to specify additional information about conventional ch
| Column Name | Required | Value |
|-------------|----------|-------|
| TG Number | ✔️ | The Talkgroup Number formatted as a decimal number. This has to be the first column |
| Frequency | ✔️ | The frequency in Hz for the channel |
| Frequency | ✔️ | The frequency in MHz or Hz for the channel (decimal point must be used for MHz) |
| Tone | ✔️ | The Tone for the talkgroup. This value is not used. *Tone based squelch is currently not supported.* |
| Alpha Tag | | A 16 character description that is intended as a shortened display on radio displays |
| Category | | The category for the Talkgroup |
Expand Down
14 changes: 7 additions & 7 deletions plugins/broadcastify_uploader/broadcastify_uploader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ class Broadcastify_Uploader : public Plugin_Api {
return "";
}

std::string get_system_id(std::string short_name) {
int get_system_id(std::string short_name) {
for (std::vector<Broadcastify_System_Key>::iterator it = data.keys.begin(); it != data.keys.end(); ++it) {
Broadcastify_System_Key key = *it;
if (key.short_name == short_name) {
return std::to_string(key.system_id); // Convert int to string for return
return key.system_id; // Convert int to string for return
}
}
return "";
return 0;
}

static size_t write_callback(void *contents, size_t size, size_t nmemb, void *userp) {
Expand Down Expand Up @@ -122,9 +122,9 @@ class Broadcastify_Uploader : public Plugin_Api {
std::string response_buffer;

std::string api_key = get_api_key(call_info.short_name);
std::string system_id = get_system_id(call_info.short_name);
int system_id = get_system_id(call_info.short_name);

if ((api_key.size() ==0) || (system_id.size() ==0)) {
if ((api_key.size() == 0) || (system_id == 0)) {
return 0;
}

Expand Down Expand Up @@ -157,7 +157,7 @@ class Broadcastify_Uploader : public Plugin_Api {
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "systemId",
CURLFORM_COPYCONTENTS, system_id.c_str(),
CURLFORM_COPYCONTENTS, std::to_string(system_id).c_str(),
CURLFORM_END);

curl_formadd(&formpost,
Expand Down Expand Up @@ -293,7 +293,7 @@ class Broadcastify_Uploader : public Plugin_Api {
BOOST_LOG_TRIVIAL(info) << "[" << call_info.short_name << "]\tTG: " << call_info.talkgroup << "\tFreq: " << format_freq(call_info.freq) << "\tBroadcastify Upload REJECTED: " << message;
return 0;
}

if (code != "0") {
BOOST_LOG_TRIVIAL(error) << "[" << call_info.short_name << "]\tTG: " << call_info.talkgroup << "\tFreq: " << format_freq(call_info.freq) << "\tBroadcastify Metadata Upload Error: " << message;
return 1;
Expand Down
14 changes: 7 additions & 7 deletions plugins/rdioscanner_uploader/rdioscanner_uploader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Rdio_Scanner_Uploader : public Plugin_Api {
if (api_key.size() == 0) {
return 0;
}

std::ostringstream freq;
std::string freq_string;
freq << std::fixed << std::setprecision(0);
Expand Down Expand Up @@ -106,7 +106,7 @@ class Rdio_Scanner_Uploader : public Plugin_Api {

if (call_info.patched_talkgroups.size()>1){
for (unsigned long i = 0; i < call_info.patched_talkgroups.size(); i++) {
if (i!=0) {
if (i!=0) {
patch_list << ",";
}
patch_list << (int)call_info.patched_talkgroups[i];
Expand All @@ -125,8 +125,8 @@ class Rdio_Scanner_Uploader : public Plugin_Api {

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 << ", \"errorCount\": " << std::setprecision(0) <<call_info.transmission_error_list[i].error_count << ", \"spikeCount\": " << call_info.transmission_error_list[i].spike_count << "}";
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 << ", \"errorCount\": " << std::setprecision(0) <<call_info.transmission_error_list[i].error_count << ", \"spikeCount\": " << call_info.transmission_error_list[i].spike_count << "}";

if (i < (call_info.transmission_error_list.size() - 1)) {
freq_list << ", ";
} else {
Expand Down Expand Up @@ -399,10 +399,10 @@ class Rdio_Scanner_Uploader : public Plugin_Api {
if (!regex_match(this->data.server.c_str(), what, ex)) {
BOOST_LOG_TRIVIAL(error) << "Unable to parse Rdio Scanner Server URL\n";
return 1;
}
}

// Gets the API key for each system, if defined
for (json element : config_data["systems"]) {
for (json element : config_data["systems"]) {
bool rdioscanner_exists = element.contains("apiKey");
if (rdioscanner_exists) {
Rdio_Scanner_System sys;
Expand All @@ -423,7 +423,7 @@ class Rdio_Scanner_Uploader : public Plugin_Api {
return 0;
}


/*
int start() { return 0; }
int stop() { return 0; }
Expand Down
10 changes: 7 additions & 3 deletions trunk-recorder/talkgroups.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ void Talkgroups::load_channels(int sys_num, std::string filename) {
std::vector<std::string> headers = reader.get_col_names();
std::vector<std::string> defined_headers = {"TG Number", "Tone", "Frequency", "Alpha Tag", "Description", "Category", "Tag", "Enable", "Comment"};

if (headers[0] != "Decimal") {
if (headers[0] != "TG Number") {

BOOST_LOG_TRIVIAL(error) << "Column Headers are required for Channel CSV files";
BOOST_LOG_TRIVIAL(error) << "The first column must be 'Decimal'";
BOOST_LOG_TRIVIAL(error) << "The first column must be 'TG Number'";
BOOST_LOG_TRIVIAL(error) << "Required columns are: 'TG Number', 'Tone', 'Frequency',";
BOOST_LOG_TRIVIAL(error) << "Optional columns are: 'Alpha Tag', 'Description', 'Category', 'Tag', 'Enable', 'Comment'";
exit(0);
Expand Down Expand Up @@ -188,8 +188,12 @@ void Talkgroups::load_channels(int sys_num, std::string filename) {
tone = row["Tone"].get<double>();
}

if ((reader.index_of("Frequency") >= 0) && row["Frequency"].is_float()) {
if ((reader.index_of("Frequency") >= 0) && row["Frequency"].is_num()) {
freq = row["Frequency"].get<double>();
// If this is a float under 1000, it must be in MHz so convert to Hz
if (row["Frequency"].is_float() && freq < 1000.0) {
freq = freq * 1e+6;
}
}

if ((reader.index_of("Enable") >= 0) && row["Enable"].is_str()) {
Expand Down

0 comments on commit 6bd1c98

Please sign in to comment.