From d95bda65cefd57ed00d1ae6932f87e4123782716 Mon Sep 17 00:00:00 2001 From: Erwin Ried <1091420+eried@users.noreply.github.com> Date: Mon, 20 Apr 2020 06:45:28 +0200 Subject: [PATCH] Nrf24l01 demodulation (#338) * NRF demodulation * Update ui_navigation.cpp --- firmware/application/CMakeLists.txt | 1 + firmware/application/apps/ui_nrf_rx.cpp | 165 ++++++++++++++ firmware/application/apps/ui_nrf_rx.hpp | 107 +++++++++ firmware/application/baseband_api.cpp | 10 + firmware/application/baseband_api.hpp | 1 + firmware/application/bitmap.hpp | 22 ++ firmware/application/ui_navigation.cpp | 2 + firmware/baseband/CMakeLists.txt | 6 + firmware/baseband/proc_nrfrx.cpp | 286 ++++++++++++++++++++++++ firmware/baseband/proc_nrfrx.hpp | 96 ++++++++ firmware/common/message.hpp | 22 ++ firmware/common/spi_image.hpp | 1 + 12 files changed, 719 insertions(+) create mode 100644 firmware/application/apps/ui_nrf_rx.cpp create mode 100644 firmware/application/apps/ui_nrf_rx.hpp create mode 100644 firmware/baseband/proc_nrfrx.cpp create mode 100644 firmware/baseband/proc_nrfrx.hpp diff --git a/firmware/application/CMakeLists.txt b/firmware/application/CMakeLists.txt index 91fec2fa..851e021d 100644 --- a/firmware/application/CMakeLists.txt +++ b/firmware/application/CMakeLists.txt @@ -217,6 +217,7 @@ set(CPPSRC apps/ui_adsb_rx.cpp apps/ui_adsb_tx.cpp apps/ui_afsk_rx.cpp + apps/ui_nrf_rx.cpp apps/ui_aprs_tx.cpp apps/ui_bht_tx.cpp apps/ui_coasterp.cpp diff --git a/firmware/application/apps/ui_nrf_rx.cpp b/firmware/application/apps/ui_nrf_rx.cpp new file mode 100644 index 00000000..32982ae6 --- /dev/null +++ b/firmware/application/apps/ui_nrf_rx.cpp @@ -0,0 +1,165 @@ +/* + * Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc. + * Copyright (C) 2017 Furrtek + * Copyright (C) 2020 Shao + * + * 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. + */ + +#include "ui_nrf_rx.hpp" +#include "ui_modemsetup.hpp" + +#include "modems.hpp" +#include "audio.hpp" +#include "rtc_time.hpp" +#include "baseband_api.hpp" +#include "string_format.hpp" +#include "portapack_persistent_memory.hpp" + +using namespace portapack; +using namespace modems; + +namespace ui { + +void NRFRxView::focus() { + field_frequency.focus(); +} + +void NRFRxView::update_freq(rf::Frequency f) { + receiver_model.set_tuning_frequency(f); +} + +NRFRxView::NRFRxView(NavigationView& nav) { + baseband::run_image(portapack::spi_flash::image_tag_nrf_rx); + + add_children({ + &rssi, + &channel, + &field_rf_amp, + &field_lna, + &field_vga, + &field_frequency, + &text_debug, + &button_modem_setup, + &record_view, + &console + }); + + // DEBUG + record_view.on_error = [&nav](std::string message) { + nav.display_modal("Error", message); + }; + record_view.set_sampling_rate(24000); + + // Auto-configure modem for LCR RX (will be removed later) + update_freq(2480000000); + auto def_bell202 = &modem_defs[0]; + persistent_memory::set_modem_baudrate(def_bell202->baudrate); + serial_format_t serial_format; + serial_format.data_bits = 7; + serial_format.parity = EVEN; + serial_format.stop_bits = 1; + serial_format.bit_order = LSB_FIRST; + persistent_memory::set_serial_format(serial_format); + + field_frequency.set_value(receiver_model.tuning_frequency()); + field_frequency.set_step(100); + field_frequency.on_change = [this](rf::Frequency f) { + update_freq(f); + }; + field_frequency.on_edit = [this, &nav]() { + auto new_view = nav.push(receiver_model.tuning_frequency()); + new_view->on_changed = [this](rf::Frequency f) { + update_freq(f); + field_frequency.set_value(f); + }; + }; + + button_modem_setup.on_select = [&nav](Button&) { + nav.push(); + }; + + + // Auto-configure modem for LCR RX (will be removed later) + baseband::set_nrf(persistent_memory::modem_baudrate(), 8, 0, false); + + audio::set_rate(audio::Rate::Hz_24000); + audio::output::start(); + + receiver_model.set_sampling_rate(4000000); + receiver_model.set_baseband_bandwidth(4000000); + receiver_model.set_modulation(ReceiverModel::Mode::WidebandFMAudio); + receiver_model.enable(); +} + +void NRFRxView::on_data(uint32_t value, bool is_data) { + //std::string str_console = "\x1B"; + std::string str_console = ""; + if (is_data) { + // Colorize differently after message splits + //str_console += (char)((console_color & 3) + 9); + + //value &= 0xFF; // ABCDEFGH + //value = ((value & 0xF0) >> 4) | ((value & 0x0F) << 4); // EFGHABCD + //value = ((value & 0xCC) >> 2) | ((value & 0x33) << 2); // GHEFCDAB + //value = ((value & 0xAA) >> 1) | ((value & 0x55) << 1); // HGFEDCBA + //value &= 0x7F; // Ignore parity, which is the MSB now + + //if ((value >= 32) && (value < 127)) { + // str_console += (char)value; // Printable + //} + + //str_console += (char)'A'; + //str_console += (char)value; + //str_console += "[" + to_string_hex(value, 2) + "]"; + str_console += " " + to_string_hex(value, 2) ; + console.write(str_console); + + + + /*if ((value != 0x7F) && (prev_value == 0x7F)) { + // Message split + console.writeln(""); + console_color++; + + + }*/ + //prev_value = value; + } else { + // Baudrate estimation + //text_debug.set("~" + to_string_dec_uint(value)); + if (value == 'A') + {console.write("addr:");} + else if (value == 'B') + {console.write(" data:");} + else if (value == 'C') + { + console.writeln(""); + console.writeln(""); + } + //console.writeln(""); + } +} + +NRFRxView::~NRFRxView() { + audio::output::stop(); + receiver_model.disable(); + baseband::shutdown(); +} + +} /* namespace ui */ diff --git a/firmware/application/apps/ui_nrf_rx.hpp b/firmware/application/apps/ui_nrf_rx.hpp new file mode 100644 index 00000000..4f72b25b --- /dev/null +++ b/firmware/application/apps/ui_nrf_rx.hpp @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc. + * Copyright (C) 2017 Furrtek + * Copyright (C) 2020 Shao + * + * 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 __UI_NRF_RX_H__ +#define __UI_NRF_RX_H__ + +#include "ui.hpp" +#include "ui_navigation.hpp" +#include "ui_receiver.hpp" +#include "ui_record_view.hpp" // DEBUG + +#include "utility.hpp" + +namespace ui { + +class NRFRxView : public View { +public: + NRFRxView(NavigationView& nav); + ~NRFRxView(); + + void focus() override; + + std::string title() const override { return "NRF RX"; }; + +private: + void on_data(uint32_t value, bool is_data); + + uint8_t console_color { 0 }; + uint32_t prev_value { 0 }; + std::string str_log { "" }; + + RFAmpField field_rf_amp { + { 13 * 8, 0 * 16 } + }; + LNAGainField field_lna { + { 15 * 8, 0 * 16 } + }; + VGAGainField field_vga { + { 18 * 8, 0 * 16 } + }; + RSSI rssi { + { 21 * 8, 0, 6 * 8, 4 }, + }; + Channel channel { + { 21 * 8, 5, 6 * 8, 4 }, + }; + + FrequencyField field_frequency { + { 0 * 8, 0 * 16 }, + }; + + Text text_debug { + { 0 * 8, 1 * 16, 10 * 8, 16 }, + "DEBUG" + }; + + + Button button_modem_setup { + { 12 * 8, 1 * 16, 96, 24 }, + "Modem setup" + }; + + // DEBUG + RecordView record_view { + { 0 * 8, 3 * 16, 30 * 8, 1 * 16 }, + u"AFS_????", RecordView::FileType::WAV, 4096, 4 + }; + + Console console { + { 0, 4 * 16, 240, 240 } + }; + + void update_freq(rf::Frequency f); + //void on_data_afsk(const AFSKDataMessage& message); + + MessageHandlerRegistration message_handler_packet { + Message::ID::AFSKData, + [this](Message* const p) { + const auto message = static_cast(p); + this->on_data(message->value, message->is_data); + } + }; +}; + +} /* namespace ui */ + +#endif/*__UI_NRF_RX_H__*/ diff --git a/firmware/application/baseband_api.cpp b/firmware/application/baseband_api.cpp index beb95371..be969ac8 100644 --- a/firmware/application/baseband_api.cpp +++ b/firmware/application/baseband_api.cpp @@ -130,6 +130,16 @@ void set_afsk(const uint32_t baudrate, const uint32_t word_length, const uint32_ send_message(&message); } +void set_nrf(const uint32_t baudrate, const uint32_t word_length, const uint32_t trigger_value, const bool trigger_word) { + const NRFRxConfigureMessage message { + baudrate, + word_length, + trigger_value, + trigger_word + }; + send_message(&message); +} + void set_afsk_data(const uint32_t afsk_samples_per_bit, const uint32_t afsk_phase_inc_mark, const uint32_t afsk_phase_inc_space, const uint8_t afsk_repeat, const uint32_t afsk_bw, const uint8_t symbol_count) { const AFSKTxConfigureMessage message { diff --git a/firmware/application/baseband_api.hpp b/firmware/application/baseband_api.hpp index 8562a90c..30ad6084 100644 --- a/firmware/application/baseband_api.hpp +++ b/firmware/application/baseband_api.hpp @@ -68,6 +68,7 @@ void set_afsk_data(const uint32_t afsk_samples_per_bit, const uint32_t afsk_phas const uint8_t afsk_repeat, const uint32_t afsk_bw, const uint8_t symbol_count); void kill_afsk(); void set_afsk(const uint32_t baudrate, const uint32_t word_length, const uint32_t trigger_value, const bool trigger_word); +void set_nrf(const uint32_t baudrate, const uint32_t word_length, const uint32_t trigger_value, const bool trigger_word); void set_ook_data(const uint32_t stream_length, const uint32_t samples_per_bit, const uint8_t repeat, const uint32_t pause_symbols); void set_fsk_data(const uint32_t stream_length, const uint32_t samples_per_bit, const uint32_t shift, diff --git a/firmware/application/bitmap.hpp b/firmware/application/bitmap.hpp index a4950deb..0d11ceab 100644 --- a/firmware/application/bitmap.hpp +++ b/firmware/application/bitmap.hpp @@ -1503,6 +1503,28 @@ static constexpr Bitmap bitmap_icon_replay { { 16, 16 }, bitmap_icon_replay_data }; +static constexpr uint8_t bitmap_icon_nrf_data[] = { + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, + 0x07, 0xE0, + 0x05, 0x20, + 0xCC, 0x33, + 0xF4, 0x2F, + 0xE6, 0x67, + 0xE2, 0x47, + 0x36, 0x5C, + 0x0E, 0xE0, + 0x06, 0x60, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, +}; +static constexpr Bitmap bitmap_icon_nrf { + { 16, 16 }, bitmap_icon_nrf_data +}; + static constexpr uint8_t bitmap_sig_sine_data[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, diff --git a/firmware/application/ui_navigation.cpp b/firmware/application/ui_navigation.cpp index 4c574c63..8e000fbf 100644 --- a/firmware/application/ui_navigation.cpp +++ b/firmware/application/ui_navigation.cpp @@ -34,6 +34,7 @@ #include "ui_adsb_rx.hpp" #include "ui_adsb_tx.hpp" #include "ui_afsk_rx.hpp" +#include "ui_nrf_rx.hpp" #include "ui_aprs_tx.hpp" #include "ui_bht_tx.hpp" #include "ui_coasterp.hpp" @@ -347,6 +348,7 @@ ReceiversMenuView::ReceiversMenuView(NavigationView& nav) { { "ACARS", ui::Color::yellow(), &bitmap_icon_adsb, [&nav](){ nav.push(); }, }, { "AIS Boats", ui::Color::green(), &bitmap_icon_ais, [&nav](){ nav.push(); } }, { "AFSK", ui::Color::yellow(), &bitmap_icon_receivers, [&nav](){ nav.push(); } }, + { "NRF", ui::Color::yellow(), &bitmap_icon_nrf, [&nav](){ nav.push(); } }, { "Audio", ui::Color::green(), &bitmap_icon_speaker, [&nav](){ nav.push(); } }, { "ERT Meter", ui::Color::green(), &bitmap_icon_ert, [&nav](){ nav.push(); } }, { "POCSAG", ui::Color::green(), &bitmap_icon_pocsag, [&nav](){ nav.push(); } }, diff --git a/firmware/baseband/CMakeLists.txt b/firmware/baseband/CMakeLists.txt index fd70a03a..0d1000b8 100644 --- a/firmware/baseband/CMakeLists.txt +++ b/firmware/baseband/CMakeLists.txt @@ -311,6 +311,12 @@ set(MODE_CPPSRC proc_afskrx.cpp ) DeclareTargets(PAFR afskrx) +### NRF RX + +set(MODE_CPPSRC + proc_nrfrx.cpp +) +DeclareTargets(PNRR nrfrx) ### AIS diff --git a/firmware/baseband/proc_nrfrx.cpp b/firmware/baseband/proc_nrfrx.cpp new file mode 100644 index 00000000..277bc7f3 --- /dev/null +++ b/firmware/baseband/proc_nrfrx.cpp @@ -0,0 +1,286 @@ +/* + * Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc. + * Copyright (C) 2016 Furrtek + * Copyright (C) 2020 Shao + * + * 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. + */ + +#include "proc_nrfrx.hpp" +#include "portapack_shared_memory.hpp" + +#include "event_m4.hpp" + +void NRFRxProcessor::execute(const buffer_c8_t& buffer) { + if (!configured) return; + + // FM demodulation + + const auto decim_0_out = decim_0.execute(buffer, dst_buffer); + feed_channel_stats(decim_0_out); + + auto audio_oversampled = demod.execute(decim_0_out, work_audio_buffer); + // Audio signal processing + for (size_t c = 0; c < audio_oversampled.count; c++) { + int result; + int g_srate = 4; //4 for 250KPS + //int g_srate = 1; //1 for 1MPS, not working yet + int32_t current_sample = audio_oversampled.p[c]; //if I directly use this, some results can pass crc but not correct. + rb_head++; + rb_head=(rb_head)%RB_SIZE; + + rb_buf[rb_head] = current_sample; + + skipSamples = skipSamples - 1; + + + if (skipSamples<1) + { + + + int32_t threshold_tmp=0; + for (int c=0;c<8*g_srate;c++) + { + threshold_tmp = threshold_tmp + (int32_t)rb_buf[(rb_head+c)%RB_SIZE]; + } + + g_threshold = (int32_t)threshold_tmp/(8*g_srate); + + int transitions=0; + if (rb_buf[(rb_head + 9*g_srate)%RB_SIZE] > g_threshold) + { + for (int c=0;c<8;c++) + { + if (rb_buf[(rb_head + c*g_srate)%RB_SIZE] > rb_buf[(rb_head + (c+1)*g_srate)%RB_SIZE]) + transitions = transitions + 1; + } + } + else + { + for (int c=0;c<8;c++) + { + if (rb_buf[(rb_head + c*g_srate)%RB_SIZE] < rb_buf[(rb_head + (c+1)*g_srate)%RB_SIZE]) + transitions = transitions + 1; + } + } + + bool packet_detected=false; + //if ( transitions==4 && abs(g_threshold)<15500) + if ( transitions==4 && abs(g_threshold)<15500) + { + int packet_length = 0; + uint8_t tmp_buf[10]; + uint8_t packet_data[500]; + uint8_t packet_packed[50]; + uint16_t pcf; + uint32_t packet_crc; + uint32_t calced_crc; + uint64_t packet_addr_l; + + /* extract address */ + packet_addr_l=0; + + for (int t=0;t<5;t++) + { + bool current_bit; + uint8_t byte=0; + for (int c=0;c<8;c++) + { + if (rb_buf[(rb_head+(1*8+t*8+c)*g_srate)%RB_SIZE] > g_threshold) + current_bit = true; + else + current_bit = false; + byte |= current_bit << (7-c); + } + tmp_buf[t]=byte; + } + + for (int t=0;t<5;t++) packet_addr_l|=((uint64_t)tmp_buf[t])<<(4-t)*8; + + //channel_number = 26; + + + /* extract pcf */ + for (int t=0;t<2;t++) + { + bool current_bit; + uint8_t byte=0; + for (int c=0;c<8;c++) + { + if (rb_buf[(rb_head+(6*8+t*8+c)*g_srate)%RB_SIZE] > g_threshold) + current_bit = true; + else + current_bit = false; + byte |= current_bit << (7-c); + } + tmp_buf[t]=byte; + } + + pcf = tmp_buf[0]<<8 | tmp_buf[1]; + pcf >>=7; + + /* extract packet length, avoid excessive length packets */ + if(packet_length == 0) + packet_length=(int)pcf>>3; + if (packet_length>32) + packet_detected = false; + + /* extract data */ + for (int t=0;t g_threshold) + current_bit = true; + else + current_bit = false; + byte |= current_bit << (7-c); + } + packet_data[t]=byte; + } + + /* Prepare packed bit stream for CRC calculation */ + uint64_t packet_header=packet_addr_l; + packet_header<<=9; + packet_header|=pcf; + for (int c=0;c<7;c++){ + packet_packed[c]=(packet_header>>((6-c)*8))&0xFF; + } + + for (int c=0;c 0; i >>= 1) + { + bit = crc & 0x8000; + if (cc & i) + { + bit = !bit; + } + crc <<= 1; + if (bit) + { + crc ^= 0x1021; + } + } + crc &= 0xffff; + } + calced_crc = (uint16_t)(crc & 0xffff); + + /* extract crc */ + for (int t=0;t<2;t++) + { + bool current_bit; + uint8_t byte=0; + for (int c=0;c<8;c++) + { + if (rb_buf[(rb_head+((6+packet_length)*8+9+t*8+c)*g_srate)%RB_SIZE] > g_threshold) + current_bit = true; + else + current_bit = false; + byte |= current_bit << (7-c); + } + tmp_buf[t]=byte; + } + packet_crc = tmp_buf[0]<<8 | tmp_buf[1]; + + /* NRF24L01+ packet found, dump information */ + //if (packet_addr_l==0xE7E7E7E7) + if (packet_crc==calced_crc) + { + data_message.is_data = false; + data_message.value = 'A'; + shared_memory.application_queue.push(data_message); + + data_message.is_data = true; + data_message.value = packet_addr_l; + shared_memory.application_queue.push(data_message); + + for (int c=0;c<7;c++) + { + data_message.is_data = true; + data_message.value = packet_addr_l >> 8; + shared_memory.application_queue.push(data_message); + } + /*data_message.is_data = true; + data_message.value = packet_addr_l; + shared_memory.application_queue.push(data_message); + + data_message.is_data = true; + data_message.value = packet_addr_l >> 8; + shared_memory.application_queue.push(data_message);*/ + + data_message.is_data = false; + data_message.value = 'B'; + shared_memory.application_queue.push(data_message); + + for (int c=0;cid == Message::ID::NRFRxConfigure) + configure(*reinterpret_cast(message)); +} + +void NRFRxProcessor::configure(const NRFRxConfigureMessage& message) { + decim_0.configure(taps_200k_wfm_decim_0.taps, 33554432); + decim_1.configure(taps_200k_wfm_decim_1.taps, 131072); + demod.configure(audio_fs, 5000); + + configured = true; +} + +int main() { + EventDispatcher event_dispatcher { std::make_unique() }; + event_dispatcher.run(); + return 0; +} diff --git a/firmware/baseband/proc_nrfrx.hpp b/firmware/baseband/proc_nrfrx.hpp new file mode 100644 index 00000000..bfd9e348 --- /dev/null +++ b/firmware/baseband/proc_nrfrx.hpp @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc. + * Copyright (C) 2016 Furrtek + * Copyright (C) 2020 Shao + * + * 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 __PROC_NRFRX_H__ +#define __PROC_NRFRX_H__ + +#include "baseband_processor.hpp" +#include "baseband_thread.hpp" +#include "rssi_thread.hpp" + +#include "dsp_decimate.hpp" +#include "dsp_demodulate.hpp" + +#include "audio_output.hpp" + +#include "fifo.hpp" +#include "message.hpp" + +class NRFRxProcessor : public BasebandProcessor { +public: + void execute(const buffer_c8_t& buffer) override; + + void on_message(const Message* const message) override; + +private: + static constexpr size_t baseband_fs = 4000000; + static constexpr size_t audio_fs = baseband_fs / 8 / 8 / 2; + + BasebandThread baseband_thread { baseband_fs, this, NORMALPRIO + 20, baseband::Direction::Receive }; + RSSIThread rssi_thread { NORMALPRIO + 10 }; + + std::array dst { }; + const buffer_c16_t dst_buffer { + dst.data(), + dst.size() + }; + + std::array spectrum { }; + const buffer_c16_t spectrum_buffer { + spectrum.data(), + spectrum.size() + }; + + const buffer_s16_t work_audio_buffer { + (int16_t*)dst.data(), + sizeof(dst) / sizeof(int16_t) + }; + + + // Array size ok down to 375 bauds (24000 / 375) + std::array delay_line { 0 }; + std::array rb_buf { 0 }; + + /*dsp::decimate::FIRC8xR16x24FS4Decim8 decim_0 { }; + dsp::decimate::FIRC16xR16x32Decim8 decim_1 { }; + dsp::decimate::FIRAndDecimateComplex channel_filter { };*/ + dsp::decimate::FIRC8xR16x24FS4Decim4 decim_0 { }; + dsp::decimate::FIRC16xR16x16Decim2 decim_1 { }; + + dsp::demodulate::FM demod { }; + int rb_head {-1}; + int32_t g_threshold {0}; + //uint8_t g_srate {8}; + uint8_t channel_number {38}; + int skipSamples {1000}; + int RB_SIZE {1000}; + + bool configured { false }; + + + void configure(const NRFRxConfigureMessage& message); + + AFSKDataMessage data_message { false, 0 }; +}; + +#endif/*__PROC_NRFRX_H__*/ diff --git a/firmware/common/message.hpp b/firmware/common/message.hpp index dfcc49ce..e1a507d1 100644 --- a/firmware/common/message.hpp +++ b/firmware/common/message.hpp @@ -78,6 +78,7 @@ public: AFSKRxConfigure = 22, StatusRefresh = 23, SamplerateConfig = 24, + NRFRxConfigure = 26, TXProgress = 30, Retune = 31, @@ -722,6 +723,27 @@ public: const bool trigger_word; }; + +class NRFRxConfigureMessage : public Message { +public: + constexpr NRFRxConfigureMessage( + const uint32_t baudrate, + const uint32_t word_length, + const uint32_t trigger_value, + const bool trigger_word + ) : Message { ID::NRFRxConfigure }, + baudrate(baudrate), + word_length(word_length), + trigger_value(trigger_value), + trigger_word(trigger_word) + { + } + + const uint32_t baudrate; + const uint32_t word_length; + const uint32_t trigger_value; + const bool trigger_word; +}; class PitchRSSIConfigureMessage : public Message { public: constexpr PitchRSSIConfigureMessage( diff --git a/firmware/common/spi_image.hpp b/firmware/common/spi_image.hpp index fd2c7b7d..ce2522c6 100644 --- a/firmware/common/spi_image.hpp +++ b/firmware/common/spi_image.hpp @@ -68,6 +68,7 @@ private: constexpr image_tag_t image_tag_acars { 'P', 'A', 'C', 'A' }; constexpr image_tag_t image_tag_adsb_rx { 'P', 'A', 'D', 'R' }; constexpr image_tag_t image_tag_afsk_rx { 'P', 'A', 'F', 'R' }; +constexpr image_tag_t image_tag_nrf_rx { 'P', 'N', 'R', 'R' }; constexpr image_tag_t image_tag_ais { 'P', 'A', 'I', 'S' }; constexpr image_tag_t image_tag_am_audio { 'P', 'A', 'M', 'A' }; constexpr image_tag_t image_tag_capture { 'P', 'C', 'A', 'P' };