2015-07-08 11:39:24 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
|
|
|
*
|
|
|
|
* This file is part of PortaPack.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __MESSAGE_H__
|
|
|
|
#define __MESSAGE_H__
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include <cstddef>
|
|
|
|
#include <array>
|
|
|
|
#include <functional>
|
|
|
|
|
2015-12-08 18:15:51 -05:00
|
|
|
#include "baseband_packet.hpp"
|
2015-12-08 19:19:27 -05:00
|
|
|
#include "ert_packet.hpp"
|
2016-01-03 15:46:21 -05:00
|
|
|
#include "dsp_fir_taps.hpp"
|
2016-01-06 14:34:41 -05:00
|
|
|
#include "fifo.hpp"
|
2015-12-07 15:35:05 -05:00
|
|
|
|
2015-07-08 11:39:24 -04:00
|
|
|
#include "utility.hpp"
|
|
|
|
|
2015-11-09 14:57:25 -05:00
|
|
|
#include "ch.h"
|
|
|
|
|
2015-07-08 11:39:24 -04:00
|
|
|
class Message {
|
|
|
|
public:
|
2015-08-20 16:13:12 -04:00
|
|
|
static constexpr size_t MAX_SIZE = 276;
|
|
|
|
|
|
|
|
enum class ID : uint32_t {
|
2015-07-08 11:39:24 -04:00
|
|
|
/* Assign consecutive IDs. IDs are used to index array. */
|
|
|
|
RSSIStatistics = 0,
|
|
|
|
BasebandStatistics = 1,
|
|
|
|
ChannelStatistics = 2,
|
2016-01-06 14:36:57 -05:00
|
|
|
DisplayFrameSync = 3,
|
2015-07-08 11:39:24 -04:00
|
|
|
AudioStatistics = 4,
|
|
|
|
BasebandConfiguration = 5,
|
2015-11-10 18:19:56 -05:00
|
|
|
TPMSPacket = 6,
|
2015-08-20 21:03:49 -04:00
|
|
|
Shutdown = 8,
|
2015-11-10 17:07:07 -05:00
|
|
|
AISPacket = 7,
|
2015-12-01 14:24:48 -05:00
|
|
|
ERTPacket = 9,
|
2016-01-03 15:05:47 -05:00
|
|
|
UpdateSpectrum = 10,
|
2016-01-03 15:46:21 -05:00
|
|
|
NBFMConfigure = 11,
|
2016-01-03 16:38:55 -05:00
|
|
|
WFMConfigure = 12,
|
2016-01-03 17:31:39 -05:00
|
|
|
AMConfigure = 13,
|
2016-01-06 15:10:30 -05:00
|
|
|
ChannelSpectrumConfig = 14,
|
2015-07-08 11:39:24 -04:00
|
|
|
MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
constexpr Message(
|
|
|
|
ID id
|
2015-08-20 16:13:12 -04:00
|
|
|
) : id { id }
|
2015-07-08 11:39:24 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
const ID id;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct RSSIStatistics {
|
|
|
|
uint32_t accumulator { 0 };
|
|
|
|
uint32_t min { 0 };
|
|
|
|
uint32_t max { 0 };
|
|
|
|
uint32_t count { 0 };
|
|
|
|
};
|
|
|
|
|
|
|
|
class RSSIStatisticsMessage : public Message {
|
|
|
|
public:
|
|
|
|
constexpr RSSIStatisticsMessage(
|
2015-11-11 12:35:28 -05:00
|
|
|
const RSSIStatistics& statistics
|
|
|
|
) : Message { ID::RSSIStatistics },
|
|
|
|
statistics { statistics }
|
2015-07-08 11:39:24 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
RSSIStatistics statistics;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct BasebandStatistics {
|
|
|
|
uint32_t idle_ticks { 0 };
|
2015-10-14 13:44:20 -04:00
|
|
|
uint32_t main_ticks { 0 };
|
|
|
|
uint32_t rssi_ticks { 0 };
|
2015-07-08 11:39:24 -04:00
|
|
|
uint32_t baseband_ticks { 0 };
|
|
|
|
bool saturation { false };
|
|
|
|
};
|
|
|
|
|
|
|
|
class BasebandStatisticsMessage : public Message {
|
|
|
|
public:
|
|
|
|
constexpr BasebandStatisticsMessage(
|
2015-11-11 12:35:28 -05:00
|
|
|
const BasebandStatistics& statistics
|
|
|
|
) : Message { ID::BasebandStatistics },
|
|
|
|
statistics { statistics }
|
2015-07-08 11:39:24 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
BasebandStatistics statistics;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ChannelStatistics {
|
|
|
|
int32_t max_db;
|
|
|
|
size_t count;
|
|
|
|
|
|
|
|
constexpr ChannelStatistics(
|
2015-11-11 12:16:20 -05:00
|
|
|
int32_t max_db = -120,
|
|
|
|
size_t count = 0
|
2015-07-08 11:39:24 -04:00
|
|
|
) : max_db { max_db },
|
|
|
|
count { count }
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class ChannelStatisticsMessage : public Message {
|
|
|
|
public:
|
|
|
|
constexpr ChannelStatisticsMessage(
|
2015-12-10 15:25:11 -05:00
|
|
|
const ChannelStatistics& statistics
|
|
|
|
) : Message { ID::ChannelStatistics },
|
|
|
|
statistics { statistics }
|
2015-07-08 11:39:24 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ChannelStatistics statistics;
|
|
|
|
};
|
|
|
|
|
2016-01-06 14:36:57 -05:00
|
|
|
class DisplayFrameSyncMessage : public Message {
|
|
|
|
public:
|
|
|
|
constexpr DisplayFrameSyncMessage(
|
|
|
|
) : Message { ID::DisplayFrameSync }
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-07-08 11:39:24 -04:00
|
|
|
struct AudioStatistics {
|
|
|
|
int32_t rms_db;
|
|
|
|
int32_t max_db;
|
|
|
|
size_t count;
|
|
|
|
|
|
|
|
constexpr AudioStatistics(
|
|
|
|
) : rms_db { -120 },
|
|
|
|
max_db { -120 },
|
|
|
|
count { 0 }
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
constexpr AudioStatistics(
|
|
|
|
int32_t rms_db,
|
|
|
|
int32_t max_db,
|
|
|
|
size_t count
|
|
|
|
) : rms_db { rms_db },
|
|
|
|
max_db { max_db },
|
|
|
|
count { count }
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class AudioStatisticsMessage : public Message {
|
|
|
|
public:
|
|
|
|
constexpr AudioStatisticsMessage(
|
2015-12-10 15:25:11 -05:00
|
|
|
const AudioStatistics& statistics
|
2015-07-08 11:39:24 -04:00
|
|
|
) : Message { ID::AudioStatistics },
|
2015-12-10 15:25:11 -05:00
|
|
|
statistics { statistics }
|
2015-07-08 11:39:24 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioStatistics statistics;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct BasebandConfiguration {
|
|
|
|
int32_t mode;
|
|
|
|
uint32_t sampling_rate;
|
|
|
|
size_t decimation_factor;
|
2015-11-11 13:30:35 -05:00
|
|
|
|
|
|
|
constexpr BasebandConfiguration(
|
2015-12-10 17:40:34 -05:00
|
|
|
int32_t mode,
|
|
|
|
uint32_t sampling_rate,
|
2015-11-11 13:30:35 -05:00
|
|
|
size_t decimation_factor = 1
|
|
|
|
) : mode { mode },
|
|
|
|
sampling_rate { sampling_rate },
|
|
|
|
decimation_factor { decimation_factor }
|
|
|
|
{
|
|
|
|
}
|
2015-12-10 17:40:34 -05:00
|
|
|
|
|
|
|
constexpr BasebandConfiguration(
|
|
|
|
) : BasebandConfiguration { -1, 0, 1 }
|
|
|
|
{
|
|
|
|
}
|
2015-07-08 11:39:24 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
class BasebandConfigurationMessage : public Message {
|
|
|
|
public:
|
|
|
|
constexpr BasebandConfigurationMessage(
|
2015-12-10 18:13:07 -05:00
|
|
|
const BasebandConfiguration& configuration
|
2015-07-08 11:39:24 -04:00
|
|
|
) : Message { ID::BasebandConfiguration },
|
2015-12-10 18:13:07 -05:00
|
|
|
configuration { configuration }
|
2015-07-08 11:39:24 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
BasebandConfiguration configuration;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ChannelSpectrum {
|
2015-08-20 16:13:12 -04:00
|
|
|
std::array<uint8_t, 256> db { { 0 } };
|
2016-01-06 15:10:30 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
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 }
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-07-18 01:55:18 -04:00
|
|
|
uint32_t sampling_rate { 0 };
|
2015-07-18 02:16:09 -04:00
|
|
|
uint32_t channel_filter_pass_frequency { 0 };
|
|
|
|
uint32_t channel_filter_stop_frequency { 0 };
|
2016-01-06 15:10:30 -05:00
|
|
|
ChannelSpectrumFIFO* fifo { nullptr };
|
2015-07-08 11:39:24 -04:00
|
|
|
};
|
|
|
|
|
2015-11-10 17:07:07 -05:00
|
|
|
class AISPacketMessage : public Message {
|
2015-07-08 11:39:24 -04:00
|
|
|
public:
|
2015-11-11 12:16:20 -05:00
|
|
|
constexpr AISPacketMessage(
|
2015-12-10 18:13:07 -05:00
|
|
|
const baseband::Packet& packet
|
|
|
|
) : Message { ID::AISPacket },
|
|
|
|
packet { packet }
|
2015-07-08 11:39:24 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-12-08 18:15:51 -05:00
|
|
|
baseband::Packet packet;
|
2015-11-10 18:19:56 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
class TPMSPacketMessage : public Message {
|
|
|
|
public:
|
2015-11-11 12:16:20 -05:00
|
|
|
constexpr TPMSPacketMessage(
|
2015-12-10 18:13:07 -05:00
|
|
|
const baseband::Packet& packet
|
|
|
|
) : Message { ID::TPMSPacket },
|
|
|
|
packet { packet }
|
2015-11-10 18:19:56 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-12-08 18:15:51 -05:00
|
|
|
baseband::Packet packet;
|
2015-11-10 18:19:56 -05:00
|
|
|
};
|
|
|
|
|
2015-08-20 21:03:49 -04:00
|
|
|
class ShutdownMessage : public Message {
|
|
|
|
public:
|
|
|
|
constexpr ShutdownMessage(
|
|
|
|
) : Message { ID::Shutdown }
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-12-08 18:15:51 -05:00
|
|
|
class ERTPacketMessage : public Message {
|
|
|
|
public:
|
|
|
|
constexpr ERTPacketMessage(
|
2015-12-10 18:13:07 -05:00
|
|
|
const ert::Packet::Type type,
|
|
|
|
const baseband::Packet& packet
|
|
|
|
) : Message { ID::ERTPacket },
|
|
|
|
type { type },
|
|
|
|
packet { packet }
|
2015-12-08 18:15:51 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-12-10 18:13:07 -05:00
|
|
|
ert::Packet::Type type;
|
2015-12-01 14:24:48 -05:00
|
|
|
|
2015-12-08 18:15:51 -05:00
|
|
|
baseband::Packet packet;
|
2015-12-01 14:24:48 -05:00
|
|
|
};
|
|
|
|
|
2016-01-03 15:05:47 -05:00
|
|
|
class UpdateSpectrumMessage : public Message {
|
|
|
|
public:
|
|
|
|
constexpr UpdateSpectrumMessage(
|
|
|
|
) : Message { ID::UpdateSpectrum }
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-01-03 15:46:21 -05:00
|
|
|
class NBFMConfigureMessage : public Message {
|
|
|
|
public:
|
|
|
|
constexpr NBFMConfigureMessage(
|
2016-01-03 19:21:17 -05:00
|
|
|
const fir_taps_real<24> decim_0_filter,
|
|
|
|
const fir_taps_real<32> decim_1_filter,
|
|
|
|
const fir_taps_real<32> channel_filter,
|
2016-01-03 15:46:21 -05:00
|
|
|
const size_t deviation
|
|
|
|
) : Message { ID::NBFMConfigure },
|
2016-01-03 19:28:09 -05:00
|
|
|
decim_0_filter(decim_0_filter),
|
|
|
|
decim_1_filter(decim_1_filter),
|
|
|
|
channel_filter(channel_filter),
|
2016-01-03 15:46:21 -05:00
|
|
|
deviation { deviation }
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
const fir_taps_real<24> decim_0_filter;
|
|
|
|
const fir_taps_real<32> decim_1_filter;
|
|
|
|
const fir_taps_real<32> channel_filter;
|
|
|
|
const size_t deviation;
|
|
|
|
};
|
|
|
|
|
2016-01-03 16:38:55 -05:00
|
|
|
class WFMConfigureMessage : public Message {
|
|
|
|
public:
|
|
|
|
constexpr WFMConfigureMessage(
|
2016-01-03 19:21:17 -05:00
|
|
|
const fir_taps_real<24> decim_0_filter,
|
|
|
|
const fir_taps_real<16> decim_1_filter,
|
|
|
|
const fir_taps_real<64> audio_filter,
|
2016-01-03 16:38:55 -05:00
|
|
|
const size_t deviation
|
|
|
|
) : Message { ID::WFMConfigure },
|
2016-01-03 19:28:09 -05:00
|
|
|
decim_0_filter(decim_0_filter),
|
|
|
|
decim_1_filter(decim_1_filter),
|
|
|
|
audio_filter(audio_filter),
|
2016-01-03 16:38:55 -05:00
|
|
|
deviation { deviation }
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
const fir_taps_real<24> decim_0_filter;
|
|
|
|
const fir_taps_real<16> decim_1_filter;
|
|
|
|
const fir_taps_real<64> audio_filter;
|
|
|
|
const size_t deviation;
|
|
|
|
};
|
|
|
|
|
2016-01-03 17:31:39 -05:00
|
|
|
class AMConfigureMessage : public Message {
|
|
|
|
public:
|
|
|
|
constexpr AMConfigureMessage(
|
2016-01-03 19:21:17 -05:00
|
|
|
const fir_taps_real<24> decim_0_filter,
|
|
|
|
const fir_taps_real<32> decim_1_filter,
|
|
|
|
const fir_taps_real<32> channel_filter
|
2016-01-03 17:31:39 -05:00
|
|
|
) : Message { ID::AMConfigure },
|
2016-01-03 19:28:09 -05:00
|
|
|
decim_0_filter(decim_0_filter),
|
|
|
|
decim_1_filter(decim_1_filter),
|
|
|
|
channel_filter(channel_filter)
|
2016-01-03 17:31:39 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
const fir_taps_real<24> decim_0_filter;
|
|
|
|
const fir_taps_real<32> decim_1_filter;
|
|
|
|
const fir_taps_real<32> channel_filter;
|
|
|
|
};
|
|
|
|
|
2015-07-08 11:39:24 -04:00
|
|
|
class MessageHandlerMap {
|
|
|
|
public:
|
2015-09-26 14:48:30 -04:00
|
|
|
using MessageHandler = std::function<void(Message* const p)>;
|
2015-07-08 11:39:24 -04:00
|
|
|
|
2015-08-14 20:31:23 -04:00
|
|
|
void register_handler(const Message::ID id, MessageHandler&& handler) {
|
2015-11-09 14:57:25 -05:00
|
|
|
if( map_[toUType(id)] != nullptr ) {
|
|
|
|
chDbgPanic("MsgDblReg");
|
|
|
|
}
|
2015-08-14 20:31:23 -04:00
|
|
|
map_[toUType(id)] = std::move(handler);
|
2015-07-08 11:39:24 -04:00
|
|
|
}
|
|
|
|
|
2015-08-14 20:31:23 -04:00
|
|
|
void unregister_handler(const Message::ID id) {
|
|
|
|
map_[toUType(id)] = nullptr;
|
|
|
|
}
|
|
|
|
|
2015-09-26 14:48:30 -04:00
|
|
|
void send(Message* const message) {
|
2015-08-20 16:13:12 -04:00
|
|
|
if( message->id < Message::ID::MAX ) {
|
|
|
|
auto& fn = map_[toUType(message->id)];
|
|
|
|
if( fn ) {
|
|
|
|
fn(message);
|
|
|
|
}
|
2015-08-14 20:31:23 -04:00
|
|
|
}
|
2015-07-08 11:39:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
using MapType = std::array<MessageHandler, toUType(Message::ID::MAX)>;
|
|
|
|
MapType map_;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif/*__MESSAGE_H__*/
|