From d821afc60d7d1afd2529fda0e983d6d77546cb4b Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Sun, 10 Jan 2016 10:42:20 -0800 Subject: [PATCH] Spectrum streaming control, spectrum attributes back in each frame. TODO: This feels kinda complex, and there's some repeated Processor code that needs to be refactored into a base class. --- firmware/application/ui_spectrum.cpp | 23 ++++++++++++++---- firmware/baseband/proc_am_audio.cpp | 12 ++++++++++ firmware/baseband/proc_am_audio.hpp | 2 ++ firmware/baseband/proc_nfm_audio.cpp | 12 ++++++++++ firmware/baseband/proc_nfm_audio.hpp | 2 ++ firmware/baseband/proc_wfm_audio.cpp | 12 ++++++++++ firmware/baseband/proc_wfm_audio.hpp | 2 ++ firmware/baseband/spectrum_collector.cpp | 30 +++++++++++++----------- firmware/baseband/spectrum_collector.hpp | 5 +++- firmware/common/message.hpp | 30 +++++++++++++++++------- 10 files changed, 101 insertions(+), 29 deletions(-) diff --git a/firmware/application/ui_spectrum.cpp b/firmware/application/ui_spectrum.cpp index 0cdfedbe..74838210 100644 --- a/firmware/application/ui_spectrum.cpp +++ b/firmware/application/ui_spectrum.cpp @@ -24,6 +24,7 @@ #include "spectrum_color_lut.hpp" #include "portapack.hpp" +#include "portapack_shared_memory.hpp" using namespace portapack; #include "string_format.hpp" @@ -237,11 +238,6 @@ void WaterfallWidget::on_show() { context().message_map().register_handler(Message::ID::ChannelSpectrumConfig, [this](const Message* const p) { 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; } ); @@ -255,9 +251,21 @@ void WaterfallWidget::on_show() { } } ); + + shared_memory.baseband_queue.push_and_wait( + SpectrumStreamingConfigMessage { + SpectrumStreamingConfigMessage::Mode::Running + } + ); } void WaterfallWidget::on_hide() { + shared_memory.baseband_queue.push_and_wait( + SpectrumStreamingConfigMessage { + SpectrumStreamingConfigMessage::Mode::Stopped + } + ); + context().message_map().unregister_handler(Message::ID::DisplayFrameSync); context().message_map().unregister_handler(Message::ID::ChannelSpectrumConfig); } @@ -281,6 +289,11 @@ 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); + frequency_scale.set_channel_filter( + spectrum.channel_filter_pass_frequency, + spectrum.channel_filter_stop_frequency + ); } } /* namespace spectrum */ diff --git a/firmware/baseband/proc_am_audio.cpp b/firmware/baseband/proc_am_audio.cpp index dd51c746..561cefbe 100644 --- a/firmware/baseband/proc_am_audio.cpp +++ b/firmware/baseband/proc_am_audio.cpp @@ -53,6 +53,10 @@ void NarrowbandAMAudio::on_message(const Message* const message) { configure(*reinterpret_cast(message)); break; + case Message::ID::SpectrumStreamingConfig: + streaming_config(*reinterpret_cast(message)); + break; + default: break; } @@ -82,3 +86,11 @@ void NarrowbandAMAudio::configure(const AMConfigureMessage& message) { configured = true; } + +void NarrowbandAMAudio::streaming_config(const SpectrumStreamingConfigMessage& message) { + if( message.mode == SpectrumStreamingConfigMessage::Mode::Running ) { + channel_spectrum.start(); + } else { + channel_spectrum.stop(); + } +} diff --git a/firmware/baseband/proc_am_audio.hpp b/firmware/baseband/proc_am_audio.hpp index 46fbbee5..9c819c67 100644 --- a/firmware/baseband/proc_am_audio.hpp +++ b/firmware/baseband/proc_am_audio.hpp @@ -64,6 +64,8 @@ private: bool configured { false }; void configure(const AMConfigureMessage& message); + + void streaming_config(const SpectrumStreamingConfigMessage& message); }; #endif/*__PROC_AM_AUDIO_H__*/ diff --git a/firmware/baseband/proc_nfm_audio.cpp b/firmware/baseband/proc_nfm_audio.cpp index 749d754b..093d92b4 100644 --- a/firmware/baseband/proc_nfm_audio.cpp +++ b/firmware/baseband/proc_nfm_audio.cpp @@ -66,6 +66,10 @@ void NarrowbandFMAudio::on_message(const Message* const message) { configure(*reinterpret_cast(message)); break; + case Message::ID::SpectrumStreamingConfig: + streaming_config(*reinterpret_cast(message)); + break; + default: break; } @@ -99,3 +103,11 @@ void NarrowbandFMAudio::configure(const NBFMConfigureMessage& message) { configured = true; } + +void NarrowbandFMAudio::streaming_config(const SpectrumStreamingConfigMessage& message) { + if( message.mode == SpectrumStreamingConfigMessage::Mode::Running ) { + channel_spectrum.start(); + } else { + channel_spectrum.stop(); + } +} diff --git a/firmware/baseband/proc_nfm_audio.hpp b/firmware/baseband/proc_nfm_audio.hpp index a4c65576..79fabbd8 100644 --- a/firmware/baseband/proc_nfm_audio.hpp +++ b/firmware/baseband/proc_nfm_audio.hpp @@ -66,6 +66,8 @@ private: bool configured { false }; void configure(const NBFMConfigureMessage& message); + + void streaming_config(const SpectrumStreamingConfigMessage& message); }; #endif/*__PROC_NFM_AUDIO_H__*/ diff --git a/firmware/baseband/proc_wfm_audio.cpp b/firmware/baseband/proc_wfm_audio.cpp index 5ad961d8..d903462e 100644 --- a/firmware/baseband/proc_wfm_audio.cpp +++ b/firmware/baseband/proc_wfm_audio.cpp @@ -84,6 +84,10 @@ void WidebandFMAudio::on_message(const Message* const message) { configure(*reinterpret_cast(message)); break; + case Message::ID::SpectrumStreamingConfig: + streaming_config(*reinterpret_cast(message)); + break; + default: break; } @@ -117,3 +121,11 @@ void WidebandFMAudio::configure(const WFMConfigureMessage& message) { configured = true; } + +void WidebandFMAudio::streaming_config(const SpectrumStreamingConfigMessage& message) { + if( message.mode == SpectrumStreamingConfigMessage::Mode::Running ) { + channel_spectrum.start(); + } else { + channel_spectrum.stop(); + } +} diff --git a/firmware/baseband/proc_wfm_audio.hpp b/firmware/baseband/proc_wfm_audio.hpp index 4b137493..ee4a38f4 100644 --- a/firmware/baseband/proc_wfm_audio.hpp +++ b/firmware/baseband/proc_wfm_audio.hpp @@ -67,6 +67,8 @@ private: bool configured { false }; void configure(const WFMConfigureMessage& message); + + void streaming_config(const SpectrumStreamingConfigMessage& message); }; #endif/*__PROC_WFM_AUDIO_H__*/ diff --git a/firmware/baseband/spectrum_collector.cpp b/firmware/baseband/spectrum_collector.cpp index ca3fc1dd..7a70b69e 100644 --- a/firmware/baseband/spectrum_collector.cpp +++ b/firmware/baseband/spectrum_collector.cpp @@ -29,6 +29,16 @@ #include +void SpectrumCollector::start() { + streaming = true; + ChannelSpectrumConfigMessage message { &fifo }; + shared_memory.application_queue.push(message); +} + +void SpectrumCollector::stop() { + streaming = false; +} + void SpectrumCollector::set_decimation_factor( const size_t decimation_factor ) { @@ -48,7 +58,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) { @@ -59,7 +69,7 @@ void SpectrumCollector::feed( void SpectrumCollector::post_message(const buffer_c16_t& data) { // Called from baseband processing thread. - if( !channel_spectrum_request_update ) { + if( streaming && !channel_spectrum_request_update ) { fft_swap(data, channel_spectrum); channel_spectrum_sampling_rate = data.sampling_rate; channel_spectrum_request_update = true; @@ -67,24 +77,17 @@ 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 ) { + if( streaming && channel_spectrum_request_update ) { /* Decimated buffer is full. Compute spectrum. */ channel_spectrum_request_update = false; fft_c_preswapped(channel_spectrum); ChannelSpectrum spectrum; + 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; for(size_t i=0; i, 256> channel_spectrum; uint32_t channel_spectrum_sampling_rate { 0 }; uint32_t channel_filter_pass_frequency { 0 }; 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 6885ddb9..66eebbc5 100644 --- a/firmware/common/message.hpp +++ b/firmware/common/message.hpp @@ -57,6 +57,7 @@ public: WFMConfigure = 12, AMConfigure = 13, ChannelSpectrumConfig = 14, + SpectrumStreamingConfig = 15, MAX }; @@ -209,8 +210,28 @@ public: BasebandConfiguration configuration; }; +class SpectrumStreamingConfigMessage : public Message { +public: + enum class Mode : uint32_t { + Stopped = 0, + Running = 1, + }; + + constexpr SpectrumStreamingConfigMessage( + Mode mode + ) : Message { ID::SpectrumStreamingConfig }, + mode { mode } + { + } + + Mode mode { Mode::Stopped }; +}; + struct ChannelSpectrum { std::array db { { 0 } }; + uint32_t sampling_rate { 0 }; + uint32_t channel_filter_pass_frequency { 0 }; + uint32_t channel_filter_stop_frequency { 0 }; }; using ChannelSpectrumFIFO = FIFO; @@ -218,21 +239,12 @@ 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 }; };