From 7710b2d1fac387ff5d513acfe4fadee7174cf2ac Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Wed, 6 Jan 2016 12:10:30 -0800 Subject: [PATCH] ChannelSpectrumConfig message subsumes FIFONotify. Separate channel spectrum config from spectrum data. This will permit sending config info only when necessary. Use type information of ChannelSpectrum to statically define number of FFT bins elsewhere. TODO: Posting configuration message way too often. Fixing that is the next step. --- firmware/application/ui_spectrum.cpp | 29 ++++++++---------- firmware/application/ui_spectrum.hpp | 4 +-- firmware/baseband/spectrum_collector.cpp | 18 ++++++----- firmware/baseband/spectrum_collector.hpp | 1 + firmware/common/message.hpp | 39 +++++++++++++----------- 5 files changed, 49 insertions(+), 42 deletions(-) diff --git a/firmware/application/ui_spectrum.cpp b/firmware/application/ui_spectrum.cpp index afb43e94..0cdfedbe 100644 --- a/firmware/application/ui_spectrum.cpp +++ b/firmware/application/ui_spectrum.cpp @@ -40,11 +40,9 @@ void FrequencyScale::on_show() { clear(); } -void FrequencyScale::set_spectrum_sampling_rate(const uint32_t new_sampling_rate, const size_t new_spectrum_bins) { - if( (spectrum_sampling_rate != new_sampling_rate) || - (spectrum_bins != new_spectrum_bins) ) { +void FrequencyScale::set_spectrum_sampling_rate(const uint32_t new_sampling_rate) { + if( (spectrum_sampling_rate != new_sampling_rate) ) { spectrum_sampling_rate = new_sampling_rate; - spectrum_bins = new_spectrum_bins; set_dirty(); } } @@ -66,7 +64,7 @@ void FrequencyScale::paint(Painter& painter) { clear_background(painter, r); - if( !spectrum_sampling_rate || !spectrum_bins ) { + if( !spectrum_sampling_rate ) { // Can't draw without non-zero scale. return; } @@ -77,7 +75,6 @@ void FrequencyScale::paint(Painter& painter) { void FrequencyScale::clear() { spectrum_sampling_rate = 0; - spectrum_bins = 0; set_dirty(); } @@ -237,14 +234,19 @@ WaterfallWidget::WaterfallWidget() { } void WaterfallWidget::on_show() { - context().message_map().register_handler(Message::ID::FIFONotify, + context().message_map().register_handler(Message::ID::ChannelSpectrumConfig, [this](const Message* const p) { - const auto message = reinterpret_cast(p); - this->fifo = reinterpret_cast(message->fifo); + const auto message = *reinterpret_cast(p); + frequency_scale.set_spectrum_sampling_rate(message.sampling_rate); + frequency_scale.set_channel_filter( + message.channel_filter_pass_frequency, + message.channel_filter_stop_frequency + ); + this->fifo = message.fifo; } ); context().message_map().register_handler(Message::ID::DisplayFrameSync, - [this](const Message* const p) { + [this](const Message* const) { if( this->fifo ) { ChannelSpectrum channel_spectrum; while( fifo->out(channel_spectrum) ) { @@ -257,7 +259,7 @@ void WaterfallWidget::on_show() { void WaterfallWidget::on_hide() { context().message_map().unregister_handler(Message::ID::DisplayFrameSync); - context().message_map().unregister_handler(Message::ID::FIFONotify); + context().message_map().unregister_handler(Message::ID::ChannelSpectrumConfig); } void WaterfallWidget::set_parent_rect(const Rect new_parent_rect) { @@ -279,11 +281,6 @@ void WaterfallWidget::paint(Painter& painter) { void WaterfallWidget::on_channel_spectrum(const ChannelSpectrum& spectrum) { waterfall_view.on_channel_spectrum(spectrum); - frequency_scale.set_spectrum_sampling_rate(spectrum.sampling_rate, spectrum.db_count); - frequency_scale.set_channel_filter( - spectrum.channel_filter_pass_frequency, - spectrum.channel_filter_stop_frequency - ); } } /* namespace spectrum */ diff --git a/firmware/application/ui_spectrum.hpp b/firmware/application/ui_spectrum.hpp index 2d166bbf..cfce3c8f 100644 --- a/firmware/application/ui_spectrum.hpp +++ b/firmware/application/ui_spectrum.hpp @@ -37,7 +37,7 @@ class FrequencyScale : public Widget { public: void on_show() override; - void set_spectrum_sampling_rate(const uint32_t new_sampling_rate, const size_t new_spectrum_bins); + void set_spectrum_sampling_rate(const uint32_t new_sampling_rate); void set_channel_filter(const uint32_t pass_frequency, const uint32_t stop_frequency); void paint(Painter& painter) override; @@ -46,7 +46,7 @@ private: static constexpr Dim filter_band_height = 4; uint32_t spectrum_sampling_rate { 0 }; - size_t spectrum_bins { 0 }; + const size_t spectrum_bins = std::tuple_size::value; uint32_t channel_filter_pass_frequency { 0 }; uint32_t channel_filter_stop_frequency { 0 }; diff --git a/firmware/baseband/spectrum_collector.cpp b/firmware/baseband/spectrum_collector.cpp index 37660df6..ca3fc1dd 100644 --- a/firmware/baseband/spectrum_collector.cpp +++ b/firmware/baseband/spectrum_collector.cpp @@ -48,6 +48,7 @@ void SpectrumCollector::feed( // Called from baseband processing thread. channel_filter_pass_frequency = filter_pass_frequency; channel_filter_stop_frequency = filter_stop_frequency; + post_configuration_message(); channel_spectrum_decimator.feed( channel, [this](const buffer_c16_t& data) { @@ -66,6 +67,16 @@ void SpectrumCollector::post_message(const buffer_c16_t& data) { } } +void SpectrumCollector::post_configuration_message() { + ChannelSpectrumConfigMessage message { + channel_spectrum_sampling_rate, + channel_filter_pass_frequency, + channel_filter_stop_frequency, + &fifo + }; + shared_memory.application_queue.push(message); +} + void SpectrumCollector::update() { // Called from idle thread (after EVT_MASK_SPECTRUM is flagged) if( channel_spectrum_request_update ) { @@ -85,13 +96,6 @@ void SpectrumCollector::update() { spectrum.db[i] = std::max(0U, std::min(255U, v)); } - /* TODO: Rename .db -> .magnitude, or something more (less!) accurate. */ - spectrum.db_count = spectrum.db.size(); - spectrum.sampling_rate = channel_spectrum_sampling_rate; - spectrum.channel_filter_pass_frequency = channel_filter_pass_frequency; - spectrum.channel_filter_stop_frequency = channel_filter_stop_frequency; fifo.in(spectrum); - FIFONotifyMessage message { &fifo }; - shared_memory.application_queue.push(message); } } diff --git a/firmware/baseband/spectrum_collector.hpp b/firmware/baseband/spectrum_collector.hpp index 3e591022..164937a4 100644 --- a/firmware/baseband/spectrum_collector.hpp +++ b/firmware/baseband/spectrum_collector.hpp @@ -60,6 +60,7 @@ private: uint32_t channel_filter_stop_frequency { 0 }; void post_message(const buffer_c16_t& data); + void post_configuration_message(); }; #endif/*__SPECTRUM_COLLECTOR_H__*/ diff --git a/firmware/common/message.hpp b/firmware/common/message.hpp index 3f3b6f8c..6885ddb9 100644 --- a/firmware/common/message.hpp +++ b/firmware/common/message.hpp @@ -56,7 +56,7 @@ public: NBFMConfigure = 11, WFMConfigure = 12, AMConfigure = 13, - FIFONotify = 14, + ChannelSpectrumConfig = 14, MAX }; @@ -211,14 +211,31 @@ public: struct ChannelSpectrum { std::array db { { 0 } }; - size_t db_count { 256 }; - uint32_t sampling_rate { 0 }; - uint32_t channel_filter_pass_frequency { 0 }; - uint32_t channel_filter_stop_frequency { 0 }; }; using ChannelSpectrumFIFO = FIFO; +class ChannelSpectrumConfigMessage : public Message { +public: + constexpr ChannelSpectrumConfigMessage( + uint32_t sampling_rate, + uint32_t channel_filter_pass_frequency, + uint32_t channel_filter_stop_frequency, + ChannelSpectrumFIFO* fifo + ) : Message { ID::ChannelSpectrumConfig }, + sampling_rate { sampling_rate }, + channel_filter_pass_frequency { channel_filter_pass_frequency }, + channel_filter_stop_frequency { channel_filter_stop_frequency }, + fifo { fifo } + { + } + + uint32_t sampling_rate { 0 }; + uint32_t channel_filter_pass_frequency { 0 }; + uint32_t channel_filter_stop_frequency { 0 }; + ChannelSpectrumFIFO* fifo { nullptr }; +}; + class AISPacketMessage : public Message { public: constexpr AISPacketMessage( @@ -335,18 +352,6 @@ public: const fir_taps_real<32> channel_filter; }; -class FIFONotifyMessage : public Message { -public: - constexpr FIFONotifyMessage( - void* const fifo - ) : Message { ID::FIFONotify }, - fifo { fifo } - { - } - - void* const fifo; -}; - class MessageHandlerMap { public: using MessageHandler = std::function;