From 8f7e26b5c11941406c5c3789faa98bb853c9f0b3 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Wed, 14 Oct 2015 10:59:32 -0700 Subject: [PATCH] Break out BasebandStatsView, add main, RSSI threads. --- firmware/application/Makefile | 1 + .../application/ui_baseband_stats_view.cpp | 73 +++++++++++++++++++ .../application/ui_baseband_stats_view.hpp | 48 ++++++++++++ firmware/application/ui_debug.cpp | 37 ---------- firmware/application/ui_debug.hpp | 21 ------ 5 files changed, 122 insertions(+), 58 deletions(-) create mode 100644 firmware/application/ui_baseband_stats_view.cpp create mode 100644 firmware/application/ui_baseband_stats_view.hpp diff --git a/firmware/application/Makefile b/firmware/application/Makefile index b212639c0..e875d25d4 100755 --- a/firmware/application/Makefile +++ b/firmware/application/Makefile @@ -161,6 +161,7 @@ CPPSRC = main.cpp \ ui_font_fixed_8x16.cpp \ ui_setup.cpp \ ui_debug.cpp \ + ui_baseband_stats_view.cpp \ ui_console.cpp \ ui_receiver.cpp \ ui_spectrum.cpp \ diff --git a/firmware/application/ui_baseband_stats_view.cpp b/firmware/application/ui_baseband_stats_view.cpp new file mode 100644 index 000000000..2e54b67ba --- /dev/null +++ b/firmware/application/ui_baseband_stats_view.cpp @@ -0,0 +1,73 @@ +/* + * 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 +#include + +#include "hackrf_hal.hpp" +using namespace hackrf::one; + +namespace ui { + +/* BasebandStatsView *****************************************************/ + +BasebandStatsView::BasebandStatsView() { + add_children({ { + &text_stats, + } }); +} + +void BasebandStatsView::on_show() { + context().message_map.register_handler(Message::ID::BasebandStatistics, + [this](const Message* const p) { + this->on_statistics_update(static_cast(p)->statistics); + } + ); +} + +void BasebandStatsView::on_hide() { + context().message_map.unregister_handler(Message::ID::BasebandStatistics); +} + + +static std::string ticks_to_percent_string(const uint32_t ticks) { + 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(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'); +} + +void BasebandStatsView::on_statistics_update(const BasebandStatistics& statistics) { + 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); + + text_stats.set(message); +} + +} /* namespace ui */ diff --git a/firmware/application/ui_baseband_stats_view.hpp b/firmware/application/ui_baseband_stats_view.hpp new file mode 100644 index 000000000..700266183 --- /dev/null +++ b/firmware/application/ui_baseband_stats_view.hpp @@ -0,0 +1,48 @@ +/* + * 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. + */ + +#ifndef __UI_BASEBAND_STATS_VIEW_H__ +#define __UI_BASEBAND_STATS_VIEW_H__ + +#include "ui_widget.hpp" +#include "message.hpp" + +namespace ui { + +class BasebandStatsView : public View { +public: + BasebandStatsView(); + + void on_show() override; + void on_hide() override; + +private: + Text text_stats { + { 0 * 8, 0, (4 * 4 + 3) * 8, 1 * 16 }, + "", + }; + + void on_statistics_update(const BasebandStatistics& statistics); +}; + +} /* namespace ui */ + +#endif/*__UI_BASEBAND_STATS_VIEW_H__*/ diff --git a/firmware/application/ui_debug.cpp b/firmware/application/ui_debug.cpp index d337a7068..28d99abf3 100644 --- a/firmware/application/ui_debug.cpp +++ b/firmware/application/ui_debug.cpp @@ -25,45 +25,8 @@ #include "radio.hpp" -#include "hackrf_hal.hpp" -using namespace hackrf::one; - namespace ui { -/* BasebandStatsView *****************************************************/ - -BasebandStatsView::BasebandStatsView() { - add_children({ { - &text_used, - &text_idle, - } }); -} - -void BasebandStatsView::on_show() { - context().message_map.register_handler(Message::ID::BasebandStatistics, - [this](const Message* const p) { - this->on_statistics_update(static_cast(p)->statistics); - } - ); -} - -void BasebandStatsView::on_hide() { - context().message_map.unregister_handler(Message::ID::BasebandStatistics); -} - - -static std::string ticks_to_percent_string(const uint32_t ticks) { - const uint32_t percent_x100 = ticks / (base_m4_clk_f / 10000); - return - to_string_dec_uint(percent_x100 / 100, 3) + "." + - to_string_dec_uint(percent_x100 % 100, 2, '0') + "%"; -} - -void BasebandStatsView::on_statistics_update(const BasebandStatistics& statistics) { - text_used.set(ticks_to_percent_string(statistics.baseband_ticks)); - text_idle.set(ticks_to_percent_string(statistics.idle_ticks)); -} - DebugMemoryView::DebugMemoryView(NavigationView& nav) { add_children({ { &text_title, diff --git a/firmware/application/ui_debug.hpp b/firmware/application/ui_debug.hpp index 3f92fa6d3..92fa0c47b 100644 --- a/firmware/application/ui_debug.hpp +++ b/firmware/application/ui_debug.hpp @@ -32,27 +32,6 @@ namespace ui { -class BasebandStatsView : public View { -public: - BasebandStatsView(); - - void on_show() override; - void on_hide() override; - -private: - Text text_used { - { 0, 0, 7 * 8, 1 * 16 }, - "", - }; - - Text text_idle { - { 8 * 8, 0, 7 * 8, 1 * 16 }, - "", - }; - - void on_statistics_update(const BasebandStatistics& statistics); -}; - class DebugMemoryView : public View { public: DebugMemoryView(NavigationView& nav);