Transmit ChannelSpectrum data through separate FIFO.

Allows handling of data during LCD "vertical retrace", independent of other baseband->application messages. A bit kludgy still...
This commit is contained in:
Jared Boone 2016-01-06 11:34:41 -08:00
parent 2cd28fcc0c
commit aaa1bc3a09
4 changed files with 37 additions and 21 deletions

View File

@ -237,15 +237,20 @@ WaterfallWidget::WaterfallWidget() {
}
void WaterfallWidget::on_show() {
context().message_map().register_handler(Message::ID::ChannelSpectrum,
context().message_map().register_handler(Message::ID::FIFONotify,
[this](const Message* const p) {
this->on_channel_spectrum(reinterpret_cast<const ChannelSpectrumMessage*>(p)->spectrum);
const auto message = reinterpret_cast<const FIFONotifyMessage*>(p);
auto fifo = reinterpret_cast<ChannelSpectrumFIFO*>(message->fifo);
ChannelSpectrum channel_spectrum;
if( fifo->out(channel_spectrum) ) {
this->on_channel_spectrum(channel_spectrum);
}
}
);
}
void WaterfallWidget::on_hide() {
context().message_map().unregister_handler(Message::ID::ChannelSpectrum);
context().message_map().unregister_handler(Message::ID::FIFONotify);
}
void WaterfallWidget::set_parent_rect(const Rect new_parent_rect) {

View File

@ -73,8 +73,8 @@ void SpectrumCollector::update() {
channel_spectrum_request_update = false;
fft_c_preswapped(channel_spectrum);
ChannelSpectrumMessage spectrum_message;
for(size_t i=0; i<spectrum_message.spectrum.db.size(); i++) {
ChannelSpectrum spectrum;
for(size_t i=0; i<spectrum.db.size(); i++) {
// Three point Hamming window.
const auto corrected_sample = channel_spectrum[i] * 0.54f
+ (channel_spectrum[(i-1) & 0xff] + channel_spectrum[(i+1) & 0xff]) * -0.23f;
@ -82,14 +82,16 @@ void SpectrumCollector::update() {
const float db = complex16_mag_squared_to_dbv_norm(mag2);
constexpr float mag_scale = 5.0f;
const unsigned int v = (db * mag_scale) + 255.0f;
spectrum_message.spectrum.db[i] = std::max(0U, std::min(255U, v));
spectrum.db[i] = std::max(0U, std::min(255U, v));
}
/* TODO: Rename .db -> .magnitude, or something more (less!) accurate. */
spectrum_message.spectrum.db_count = spectrum_message.spectrum.db.size();
spectrum_message.spectrum.sampling_rate = channel_spectrum_sampling_rate;
spectrum_message.spectrum.channel_filter_pass_frequency = channel_filter_pass_frequency;
spectrum_message.spectrum.channel_filter_stop_frequency = channel_filter_stop_frequency;
shared_memory.application_queue.push(spectrum_message);
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);
}
}

View File

@ -30,6 +30,8 @@
#include <cstdint>
#include <array>
#include "message.hpp"
class SpectrumCollector {
public:
constexpr SpectrumCollector(
@ -49,6 +51,7 @@ public:
private:
BlockDecimator<256> channel_spectrum_decimator;
ChannelSpectrumFIFO fifo;
volatile bool channel_spectrum_request_update { false };
std::array<std::complex<float>, 256> channel_spectrum;

View File

@ -30,6 +30,7 @@
#include "baseband_packet.hpp"
#include "ert_packet.hpp"
#include "dsp_fir_taps.hpp"
#include "fifo.hpp"
#include "utility.hpp"
@ -44,7 +45,7 @@ public:
RSSIStatistics = 0,
BasebandStatistics = 1,
ChannelStatistics = 2,
ChannelSpectrum = 3,
AudioStatistics = 4,
BasebandConfiguration = 5,
TPMSPacket = 6,
@ -55,6 +56,7 @@ public:
NBFMConfigure = 11,
WFMConfigure = 12,
AMConfigure = 13,
FIFONotify = 14,
MAX
};
@ -207,15 +209,7 @@ struct ChannelSpectrum {
uint32_t channel_filter_stop_frequency { 0 };
};
class ChannelSpectrumMessage : public Message {
public:
constexpr ChannelSpectrumMessage(
) : Message { ID::ChannelSpectrum }
{
}
ChannelSpectrum spectrum;
};
using ChannelSpectrumFIFO = FIFO<ChannelSpectrum, 2>;
class AISPacketMessage : public Message {
public:
@ -333,6 +327,18 @@ 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)>;