2015-10-14 10:59:32 -07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
|
|
|
*
|
|
|
|
* This file is part of PortaPack.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ui_baseband_stats_view.hpp"
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include "hackrf_hal.hpp"
|
|
|
|
using namespace hackrf::one;
|
|
|
|
|
2015-12-02 13:38:17 -08:00
|
|
|
#include "string_format.hpp"
|
|
|
|
|
2015-10-14 10:59:32 -07:00
|
|
|
namespace ui {
|
|
|
|
|
|
|
|
/* BasebandStatsView *****************************************************/
|
|
|
|
|
|
|
|
BasebandStatsView::BasebandStatsView() {
|
2023-05-19 08:16:05 +12:00
|
|
|
add_children({
|
|
|
|
&text_stats,
|
|
|
|
});
|
2015-10-14 10:59:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static std::string ticks_to_percent_string(const uint32_t ticks) {
|
2023-05-19 08:16:05 +12:00
|
|
|
constexpr size_t decimal_digits = 1;
|
|
|
|
constexpr size_t decimal_factor = decimal_digits * 10;
|
|
|
|
|
|
|
|
const uint32_t percent_x10 = ticks / (base_m4_clk_f / (100 * decimal_factor));
|
|
|
|
const uint32_t percent_x10_clipped = std::min(percent_x10, static_cast<uint32_t>(100 * decimal_factor) - 1);
|
|
|
|
return to_string_dec_uint(percent_x10_clipped / decimal_factor, 2) + "." +
|
|
|
|
to_string_dec_uint(percent_x10_clipped % decimal_factor, decimal_digits, '0');
|
2015-10-14 10:59:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void BasebandStatsView::on_statistics_update(const BasebandStatistics& statistics) {
|
2023-05-19 08:16:05 +12:00
|
|
|
std::string message = ticks_to_percent_string(statistics.idle_ticks) + " " + ticks_to_percent_string(statistics.main_ticks) + " " + ticks_to_percent_string(statistics.rssi_ticks) + " " + ticks_to_percent_string(statistics.baseband_ticks);
|
2015-10-14 10:59:32 -07:00
|
|
|
|
2023-05-19 08:16:05 +12:00
|
|
|
text_stats.set(message);
|
2015-10-14 10:59:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace ui */
|