mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2025-07-04 11:02:57 +00:00
Avoid throwing in Tlm_CRC_Stats destructor (fix bugprone-exception-escape check). More consistent private member naming.
This commit is contained in:
parent
f09da3ded6
commit
eb255dec9e
@ -23,21 +23,21 @@
|
|||||||
#include <utility> // for std::move
|
#include <utility> // for std::move
|
||||||
|
|
||||||
|
|
||||||
void Tlm_CRC_Stats::initialize(std::string dump_crc_stats_filename_)
|
void Tlm_CRC_Stats::initialize(std::string dump_crc_stats_filename)
|
||||||
{
|
{
|
||||||
d_dump_crc_stats_filename = std::move(dump_crc_stats_filename_);
|
d_dump_crc_stats_filename = std::move(dump_crc_stats_filename);
|
||||||
|
|
||||||
enable_crc_stats = true;
|
d_enable_crc_stats = true;
|
||||||
num_crc_ok = 0;
|
d_num_crc_ok = 0;
|
||||||
num_crc_not_ok = 0;
|
d_num_crc_not_ok = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Tlm_CRC_Stats::set_channel(int32_t channel_)
|
bool Tlm_CRC_Stats::set_channel(int32_t channel)
|
||||||
{
|
{
|
||||||
std::string dump_path;
|
std::string dump_path;
|
||||||
|
|
||||||
channel = channel_;
|
d_channel = channel;
|
||||||
|
|
||||||
// Get path
|
// Get path
|
||||||
if (d_dump_crc_stats_filename.find_last_of('/') != std::string::npos)
|
if (d_dump_crc_stats_filename.find_last_of('/') != std::string::npos)
|
||||||
@ -57,7 +57,7 @@ bool Tlm_CRC_Stats::set_channel(int32_t channel_)
|
|||||||
}
|
}
|
||||||
|
|
||||||
d_dump_crc_stats_filename.append("_ch");
|
d_dump_crc_stats_filename.append("_ch");
|
||||||
d_dump_crc_stats_filename.append(std::to_string(channel));
|
d_dump_crc_stats_filename.append(std::to_string(d_channel));
|
||||||
d_dump_crc_stats_filename.append(".txt");
|
d_dump_crc_stats_filename.append(".txt");
|
||||||
d_dump_crc_stats_filename = dump_path + fs::path::preferred_separator + d_dump_crc_stats_filename;
|
d_dump_crc_stats_filename = dump_path + fs::path::preferred_separator + d_dump_crc_stats_filename;
|
||||||
|
|
||||||
@ -65,17 +65,17 @@ bool Tlm_CRC_Stats::set_channel(int32_t channel_)
|
|||||||
if (!gnss_sdr_create_directory(dump_path))
|
if (!gnss_sdr_create_directory(dump_path))
|
||||||
{
|
{
|
||||||
std::cerr << "GNSS-SDR cannot create telemetry CRC stats dump file for the Telemetry block. The telemetry CRC statistics has been disabled. Wrong permissions?\n";
|
std::cerr << "GNSS-SDR cannot create telemetry CRC stats dump file for the Telemetry block. The telemetry CRC statistics has been disabled. Wrong permissions?\n";
|
||||||
enable_crc_stats = false;
|
d_enable_crc_stats = false;
|
||||||
}
|
}
|
||||||
d_dump_file.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
d_dump_file.exceptions(std::ofstream::failbit | std::ofstream::badbit);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
d_dump_file.open(d_dump_crc_stats_filename.c_str(), std::ios::out);
|
d_dump_file.open(d_dump_crc_stats_filename.c_str(), std::ios::out);
|
||||||
}
|
}
|
||||||
catch (const std::ifstream::failure &e)
|
catch (const std::ofstream::failure &e)
|
||||||
{
|
{
|
||||||
LOG(WARNING) << "Exception opening telemetry CRC stats dump file " << e.what();
|
LOG(WARNING) << "Exception opening telemetry CRC stats dump file " << e.what();
|
||||||
enable_crc_stats = false;
|
d_enable_crc_stats = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -86,61 +86,69 @@ void Tlm_CRC_Stats::update_CRC_stats(bool CRC)
|
|||||||
{
|
{
|
||||||
if (CRC)
|
if (CRC)
|
||||||
{
|
{
|
||||||
num_crc_ok++;
|
d_num_crc_ok++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
num_crc_not_ok++;
|
d_num_crc_not_ok++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Tlm_CRC_Stats::~Tlm_CRC_Stats()
|
Tlm_CRC_Stats::~Tlm_CRC_Stats()
|
||||||
{
|
{
|
||||||
uint32_t num_crc_tests = num_crc_ok + num_crc_not_ok;
|
const uint32_t num_crc_tests = d_num_crc_ok + d_num_crc_not_ok;
|
||||||
float success_rate = 0.0;
|
float success_rate = 0.0;
|
||||||
|
|
||||||
if (num_crc_tests > 0)
|
if (num_crc_tests > 0)
|
||||||
{
|
{
|
||||||
success_rate = static_cast<float>(num_crc_ok) / static_cast<float>(num_crc_tests);
|
success_rate = static_cast<float>(d_num_crc_ok) / static_cast<float>(num_crc_tests);
|
||||||
}
|
}
|
||||||
std::string txt_num_crc_tests("Num CRC Tests");
|
try
|
||||||
uint32_t align_num_crc_tests = txt_num_crc_tests.length();
|
|
||||||
std::string txt_success_tests(" | Successful Tests");
|
|
||||||
uint32_t align_success_tests = txt_success_tests.length();
|
|
||||||
std::string txt_success_rate(" | Success rate");
|
|
||||||
uint32_t align_success_rate = txt_success_rate.length();
|
|
||||||
std::string txt_delimiter(" |");
|
|
||||||
uint32_t align_delimiter = txt_delimiter.length();
|
|
||||||
if (enable_crc_stats)
|
|
||||||
{
|
{
|
||||||
// write results to the telemetry CRC statistics output file
|
const std::string txt_num_crc_tests("Num CRC Tests");
|
||||||
try
|
const auto align_num_crc_tests = txt_num_crc_tests.length();
|
||||||
{
|
const std::string txt_success_tests(" | Successful Tests");
|
||||||
d_dump_file << txt_num_crc_tests << txt_success_tests << txt_success_rate << std::endl;
|
const auto align_success_tests = txt_success_tests.length();
|
||||||
d_dump_file << std::setw(align_num_crc_tests) << num_crc_tests << txt_delimiter << std::setw(align_success_tests - align_delimiter) << num_crc_ok << txt_delimiter << std::setw(align_success_rate - align_delimiter) << std::setprecision(4) << success_rate << std::endl;
|
const std::string txt_success_rate(" | Success rate");
|
||||||
}
|
const auto align_success_rate = txt_success_rate.length();
|
||||||
catch (const std::exception &ex)
|
const std::string txt_delimiter(" |");
|
||||||
{
|
const auto align_delimiter = txt_delimiter.length();
|
||||||
DLOG(INFO) << "Telemetry CRC stats cannot write on the output file " << d_dump_crc_stats_filename.c_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto pos = d_dump_file.tellp();
|
if (d_enable_crc_stats && d_dump_file.is_open())
|
||||||
try
|
|
||||||
{
|
{
|
||||||
d_dump_file.close();
|
// write results to the telemetry CRC statistics output file
|
||||||
}
|
try
|
||||||
catch (const std::exception &ex)
|
|
||||||
{
|
|
||||||
LOG(WARNING) << "Exception in destructor closing the telemetry CRC stats dump file " << ex.what();
|
|
||||||
}
|
|
||||||
if (pos == 0)
|
|
||||||
{
|
|
||||||
errorlib::error_code ec;
|
|
||||||
if (!fs::remove(fs::path(d_dump_crc_stats_filename), ec))
|
|
||||||
{
|
{
|
||||||
std::cerr << "Problem removing telemetry CRC stats temporary file " << d_dump_crc_stats_filename << '\n';
|
d_dump_file << txt_num_crc_tests << txt_success_tests << txt_success_rate << std::endl;
|
||||||
|
d_dump_file << std::setw(align_num_crc_tests) << num_crc_tests << txt_delimiter << std::setw(align_success_tests - align_delimiter) << d_num_crc_ok << txt_delimiter << std::setw(align_success_rate - align_delimiter) << std::setprecision(4) << success_rate << std::endl;
|
||||||
|
}
|
||||||
|
catch (const std::exception &ex)
|
||||||
|
{
|
||||||
|
DLOG(INFO) << "Telemetry CRC stats cannot write on the output file " << d_dump_crc_stats_filename.c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto pos = d_dump_file.tellp();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
d_dump_file.close();
|
||||||
|
}
|
||||||
|
catch (const std::exception &ex)
|
||||||
|
{
|
||||||
|
LOG(WARNING) << "Exception in destructor closing the telemetry CRC stats dump file " << ex.what();
|
||||||
|
}
|
||||||
|
if (pos == 0)
|
||||||
|
{
|
||||||
|
errorlib::error_code ec;
|
||||||
|
if (!fs::remove(fs::path(d_dump_crc_stats_filename), ec))
|
||||||
|
{
|
||||||
|
std::cerr << "Problem removing telemetry CRC stats temporary file " << d_dump_crc_stats_filename << '\n';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (const std::exception &e)
|
||||||
|
{
|
||||||
|
std::cerr << "Problem in Tlm_CRC_Stats destructor: " << e.what() << '\n';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,12 +39,12 @@ public:
|
|||||||
/*!
|
/*!
|
||||||
* \brief Initialize the telemetry CRC statistics
|
* \brief Initialize the telemetry CRC statistics
|
||||||
*/
|
*/
|
||||||
void initialize(std::string dump_crc_stats_filename_);
|
void initialize(std::string dump_crc_stats_filename);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Initialize the channel number and output file
|
* \brief Initialize the channel number and output file
|
||||||
*/
|
*/
|
||||||
bool set_channel(int32_t channel_);
|
bool set_channel(int32_t channel);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Update the CRC statistics
|
* \brief Update the CRC statistics
|
||||||
@ -54,10 +54,10 @@ public:
|
|||||||
private:
|
private:
|
||||||
std::ofstream d_dump_file;
|
std::ofstream d_dump_file;
|
||||||
std::string d_dump_crc_stats_filename;
|
std::string d_dump_crc_stats_filename;
|
||||||
uint32_t num_crc_ok{0};
|
uint32_t d_num_crc_ok{0};
|
||||||
uint32_t num_crc_not_ok{0};
|
uint32_t d_num_crc_not_ok{0};
|
||||||
int32_t channel{0};
|
int32_t d_channel{0};
|
||||||
bool enable_crc_stats{false};
|
bool d_enable_crc_stats{false};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user