diff --git a/module/radio/BackEnd/BackEnd_Mock.cpp b/module/radio/BackEnd/BackEnd_Mock.cpp index 81964be..9834124 100644 --- a/module/radio/BackEnd/BackEnd_Mock.cpp +++ b/module/radio/BackEnd/BackEnd_Mock.cpp @@ -7,27 +7,43 @@ #include "RadioWidget.h" #include "SweepFrequencyWidget.h" #include +#include #include +#include +#include #include #include #include #include "export.h" namespace { +enum class Trace_Mode { + Random, + Sine +}; struct Mock_Config { bool performance{}; - int interval_ms = 10; + int interval_ms = 16; int batch_count = 1; + Trace_Mode trace_mode = Trace_Mode::Random; }; int read_env_int(const char* name, int fallback) { bool ok = false; int value = qEnvironmentVariableIntValue(name, &ok); return ok ? value : fallback; } +Trace_Mode read_trace_mode() { + QByteArray value = qgetenv("RADIO_MOCK_TRACE_MODE").trimmed().toLower(); + return value == "sine" ? Trace_Mode::Sine : Trace_Mode::Random; +} +const char* trace_mode_text(Trace_Mode mode) { + return mode == Trace_Mode::Sine ? "sine" : "random"; +} Mock_Config read_mock_config() { Mock_Config config; - config.performance = read_env_int("RADIO_MOCK_PERF_MODE", 1) != 0; - config.interval_ms = std::max(1, read_env_int("RADIO_MOCK_INTERVAL_MS", config.performance ? 1 : 10)); + config.performance = read_env_int("RADIO_MOCK_PERF_MODE", 0) != 0; + config.interval_ms = std::max(1, read_env_int("RADIO_MOCK_INTERVAL_MS", config.performance ? 1 : 16)); config.batch_count = std::max(1, read_env_int("RADIO_MOCK_BATCH_COUNT", config.performance ? 4 : 1)); + config.trace_mode = read_trace_mode(); return config; } std::pmr::vector make_random_data(renderive::Range range, int size, renderive::Memory_Domain domain) { @@ -43,11 +59,21 @@ double make_random_value(renderive::Range range) { std::swap(range.origin, range.target); return renderive::get_data(range); } +double make_trace_value(renderive::Range range, Trace_Mode mode) { + if (mode == Trace_Mode::Random) + return make_random_value(range); + if (range.origin > range.target) + std::swap(range.origin, range.target); + static std::uint64_t sine_index = 0; + const double phase = static_cast(sine_index++) * 0.08; + const double amplitude = range.length() * 0.40; + return range.center() + std::sin(phase) * amplitude; +} renderive::Time_Of_Day current_render_time() { const QTime now = QTime::currentTime(); return {now.isValid() ? now.msecsSinceStartOfDay() : -1}; } -void push_radio_data(Radio_Widget* rw) { +void push_radio_data(Radio_Widget* rw, Trace_Mode trace_mode) { if (!rw || !rw->spectrogram_line || !rw->water_fall || !rw->time_power || !rw->audio_spectrogram_plot || !rw->progress_bar1 || !rw->progress_bar2) return; { @@ -64,7 +90,7 @@ void push_radio_data(Radio_Widget* rw) { { renderive::Range r = rw->time_power->value_axis()->coord_range(); renderive::Range nr = {r.center() - r.length() / 4, r.center() + r.length() / 4}; - rw->time_power->append_sample(current_render_time(), make_random_value(nr)); + rw->time_power->append_sample(current_render_time(), make_trace_value(nr, trace_mode)); } { auto r = rw->audio_spectrogram_plot->power_axis()->coord_range(); @@ -73,7 +99,7 @@ void push_radio_data(Radio_Widget* rw) { } rw->progress_bar2->setValue(make_random_value({1, 5})); } -void push_radio_data_perf(Radio_Widget* rw) { +void push_radio_data_perf(Radio_Widget* rw, Trace_Mode trace_mode) { if (!rw || !rw->spectrogram_line || !rw->water_fall || !rw->time_power || !rw->audio_spectrogram_plot || !rw->progress_bar1 || !rw->progress_bar2) return; { @@ -87,7 +113,7 @@ void push_radio_data_perf(Radio_Widget* rw) { rw->water_fall->append_row(current_render_time(), make_random_data({0, 160}, 1024, renderive::Memory_Domain::Waterfall)); } { - rw->time_power->append_sample(current_render_time(), make_random_value({-6000, 6000})); + rw->time_power->append_sample(current_render_time(), make_trace_value({-6000, 6000}, trace_mode)); } { rw->audio_spectrogram_plot->update_samples(make_random_data({-6000, 6000}, 512, renderive::Memory_Domain::Spectrum)); @@ -157,6 +183,10 @@ Back_End::Back_End() { function_map["特别增加"] = Qt::Key_PageUp; function_map["特别减小"] = Qt::Key_PageDown; Mock_Config config = read_mock_config(); + qInfo() << "Radio mock perf:" << config.performance + << "interval_ms:" << config.interval_ms + << "batch_count:" << config.batch_count + << "trace_mode:" << trace_mode_text(config.trace_mode); std::uint64_t start_generation = mock_generation; QTimer::singleShot(0, this, [this, config, start_generation]() { if (start_generation != mock_generation) @@ -170,7 +200,7 @@ Back_End::Back_End() { for (int i = 0; i < config.batch_count; ++i) { if (!rw) return; - config.performance ? push_radio_data_perf(rw.data()) : push_radio_data(rw.data()); + config.performance ? push_radio_data_perf(rw.data(), config.trace_mode) : push_radio_data(rw.data(), config.trace_mode); } }); mock_timer->start(config.interval_ms); diff --git a/module/radio/BackEnd/RadioWidget.cpp b/module/radio/BackEnd/RadioWidget.cpp index 0256b56..546e874 100644 --- a/module/radio/BackEnd/RadioWidget.cpp +++ b/module/radio/BackEnd/RadioWidget.cpp @@ -17,7 +17,7 @@ static renderive::Range frequent_range = {-12000, 12000}; static bool radio_mock_perf_mode() { bool ok = false; int value = qEnvironmentVariableIntValue("RADIO_MOCK_PERF_MODE", &ok); - return ok ? value != 0 : true; + return ok ? value != 0 : false; } static bool radio_show_performance_overlay() { bool ok = false; @@ -25,9 +25,7 @@ static bool radio_show_performance_overlay() { return ok ? value != 0 : false; } static void configure_radio_plot_perf(renderive::Latency_Eager_Plot* plot) { - if (!radio_mock_perf_mode()) - return; - plot->set_max_render_fps(1000); + plot->set_max_render_fps(radio_mock_perf_mode() ? 1000 : 60); } static renderive::Performance_Overlay_Options radio_performance_options() { renderive::Performance_Overlay_Options options;