mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-12-24 14:59:24 -05:00
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.
This commit is contained in:
parent
ba33cc737d
commit
7710b2d1fa
@ -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<const FIFONotifyMessage*>(p);
|
||||
this->fifo = reinterpret_cast<ChannelSpectrumFIFO*>(message->fifo);
|
||||
const auto message = *reinterpret_cast<const ChannelSpectrumConfigMessage*>(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 */
|
||||
|
@ -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<decltype(ChannelSpectrum::db)>::value;
|
||||
uint32_t channel_filter_pass_frequency { 0 };
|
||||
uint32_t channel_filter_stop_frequency { 0 };
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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__*/
|
||||
|
@ -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<uint8_t, 256> 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<ChannelSpectrum, 2>;
|
||||
|
||||
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<void(Message* const p)>;
|
||||
|
Loading…
Reference in New Issue
Block a user