From 17b238f3a8a06ef10c7f9cebd435f7e82ec8464c Mon Sep 17 00:00:00 2001 From: furrtek Date: Mon, 30 Oct 2017 02:00:39 +0100 Subject: [PATCH] Added "test app" as a draft zone for... stuff Added second signature for M2K2 radiosonde --- firmware/application/CMakeLists.txt | 2 + firmware/application/ui_navigation.cpp | 2 + firmware/application/ui_test.cpp | 123 +++++++++++++++++++++++++ firmware/application/ui_test.hpp | 106 +++++++++++++++++++++ firmware/baseband/CMakeLists.txt | 7 ++ firmware/baseband/proc_test.cpp | 55 +++++++++++ firmware/baseband/proc_test.hpp | 86 +++++++++++++++++ firmware/common/message.hpp | 13 +++ firmware/common/sonde_packet.cpp | 2 +- firmware/common/spi_image.hpp | 1 + firmware/common/test_packet.cpp | 52 +++++++++++ firmware/common/test_packet.hpp | 74 +++++++++++++++ 12 files changed, 522 insertions(+), 1 deletion(-) create mode 100644 firmware/application/ui_test.cpp create mode 100644 firmware/application/ui_test.hpp create mode 100644 firmware/baseband/proc_test.cpp create mode 100644 firmware/baseband/proc_test.hpp create mode 100644 firmware/common/test_packet.cpp create mode 100644 firmware/common/test_packet.hpp diff --git a/firmware/application/CMakeLists.txt b/firmware/application/CMakeLists.txt index 63f4f969..d53b8c22 100644 --- a/firmware/application/CMakeLists.txt +++ b/firmware/application/CMakeLists.txt @@ -209,6 +209,7 @@ set(CPPSRC ui_spectrum.cpp ui_sstvtx.cpp ui_tabview.cpp + ui_test.cpp ui_textentry.cpp ui_touch_calibration.cpp ui_touchtunes.cpp @@ -229,6 +230,7 @@ set(CPPSRC ${COMMON}/adsb_frame.cpp ${COMMON}/adsb.cpp ${COMMON}/sonde_packet.cpp + ${COMMON}/test_packet.cpp ais_app.cpp tpms_app.cpp pocsag_app.cpp diff --git a/firmware/application/ui_navigation.cpp b/firmware/application/ui_navigation.cpp index 8abdb841..04cb114d 100644 --- a/firmware/application/ui_navigation.cpp +++ b/firmware/application/ui_navigation.cpp @@ -58,6 +58,7 @@ #include "ui_sonde.hpp" #include "ui_soundboard.hpp" #include "ui_sstvtx.hpp" +#include "ui_test.hpp" #include "ui_touchtunes.hpp" #include "ui_view_wav.hpp" #include "ui_whipcalc.hpp" @@ -335,6 +336,7 @@ TransmittersMenuView::TransmittersMenuView(NavigationView& nav) { UtilitiesMenuView::UtilitiesMenuView(NavigationView& nav) { add_items({ + { "Test app", ui::Color::grey(), nullptr, [&nav](){ nav.push(); } }, { "Frequency manager", ui::Color::green(), &bitmap_icon_freqman, [&nav](){ nav.push(); } }, { "File manager", ui::Color::yellow(), &bitmap_icon_file, [&nav](){ nav.push(); } }, { "Whip antenna length", ui::Color::yellow(), nullptr, [&nav](){ nav.push(); } }, diff --git a/firmware/application/ui_test.cpp b/firmware/application/ui_test.cpp new file mode 100644 index 00000000..6268a1db --- /dev/null +++ b/firmware/application/ui_test.cpp @@ -0,0 +1,123 @@ +/* + * Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc. + * Copyright (C) 2017 Furrtek + * + * 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_test.hpp" +#include "baseband_api.hpp" + +#include "portapack.hpp" +using namespace portapack; + +#include "string_format.hpp" + +namespace ui { + +TestView::TestView(NavigationView& nav) { + baseband::run_image(portapack::spi_flash::image_tag_test); + + add_children({ + &labels, + &field_frequency, + &field_rf_amp, + &field_lna, + &field_vga, + &rssi, + &text_debug_a, + &text_debug_b + }); + + field_frequency.set_value(target_frequency_); + field_frequency.set_step(10000); + field_frequency.on_change = [this](rf::Frequency f) { + set_target_frequency(f); + field_frequency.set_value(f); + }; + field_frequency.on_edit = [this, &nav]() { + // TODO: Provide separate modal method/scheme? + auto new_view = nav.push(receiver_model.tuning_frequency()); + new_view->on_changed = [this](rf::Frequency f) { + set_target_frequency(f); + field_frequency.set_value(f); + }; + }; + + radio::enable({ + tuning_frequency(), + sampling_rate, + baseband_bandwidth, + rf::Direction::Receive, + receiver_model.rf_amp(), + static_cast(receiver_model.lna()), + static_cast(receiver_model.vga()), + }); +} + +TestView::~TestView() { + radio::disable(); + baseband::shutdown(); +} + +void TestView::focus() { + field_vga.focus(); +} + +void TestView::on_packet(const testapp::Packet& packet) { + const auto hex_formatted = packet.symbols_formatted(); + auto v = packet.value(); + + packet_count++; + uint32_t diff = ((v - 1) - prev_v); + if (diff < 20) + packets_lost += diff; + prev_v = v; + + text_debug_a.set(hex_formatted.data.substr(0, 30)); + + text_debug_b.set(to_string_dec_uint((packets_lost * 1000) / packet_count) + " per 1000"); + + display.draw_pixel(Point(cur_x, 4 * 16 + (256 - packet.alt())), Color::white()); + + cur_x++; + if (cur_x >= 240) { + display.fill_rectangle(Rect(0, 4 * 16, 240, 256), Color::black()); + cur_x = 0; + } + + //radio::disable(); + + /*text_serial.set(packet.serial_number()); + text_voltage.set(unit_auto_scale(packet.battery_voltage(), 2, 3) + "V"); + + altitude = packet.GPS_altitude(); + latitude = packet.GPS_latitude(); + longitude = packet.GPS_longitude();*/ +} + +void TestView::set_target_frequency(const uint32_t new_value) { + target_frequency_ = new_value; + radio::set_tuning_frequency(tuning_frequency()); +} + +uint32_t TestView::tuning_frequency() const { + return target_frequency_ - (sampling_rate / 4); +} + +} /* namespace ui */ diff --git a/firmware/application/ui_test.hpp b/firmware/application/ui_test.hpp new file mode 100644 index 00000000..58bddc82 --- /dev/null +++ b/firmware/application/ui_test.hpp @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc. + * Copyright (C) 2017 Furrtek + * + * 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_TEST_H__ +#define __UI_TEST_H__ + +#include "ui_navigation.hpp" +#include "ui_receiver.hpp" +#include "ui_rssi.hpp" + +#include "event_m0.hpp" + +#include "test_packet.hpp" + +#include +#include + +namespace ui { + +class TestView : public View { +public: + static constexpr uint32_t sampling_rate = 2457600; + static constexpr uint32_t baseband_bandwidth = 1750000; + + TestView(NavigationView& nav); + ~TestView(); + + void focus() override; + + std::string title() const override { return "Test app"; }; + +private: + uint32_t target_frequency_ { 439255000 }; + Coord cur_x { 0 }; + uint32_t packet_count { 0 }; + uint32_t packets_lost { 0 }; + uint32_t prev_v { 0 }; + + Labels labels { + { { 0 * 8, 1 * 16 }, "Data:", Color::light_grey() } + }; + + FrequencyField field_frequency { + { 0 * 8, 0 * 8 }, + }; + 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 }, + }; + + Text text_debug_a { + { 0 * 8, 2 * 16, 30 * 8, 16 }, + "..." + }; + Text text_debug_b { + { 0 * 8, 3 * 16, 30 * 8, 16 }, + "..." + }; + + MessageHandlerRegistration message_handler_packet { + Message::ID::TestAppPacket, + [this](Message* const p) { + const auto message = static_cast(p); + const testapp::Packet packet { message->packet }; + this->on_packet(packet); + } + }; + + void on_packet(const testapp::Packet& packet); + void set_target_frequency(const uint32_t new_value); + uint32_t tuning_frequency() const; +}; + +} /* namespace ui */ + +#endif/*__UI_TEST_H__*/ diff --git a/firmware/baseband/CMakeLists.txt b/firmware/baseband/CMakeLists.txt index 206e1bb7..7346f89f 100644 --- a/firmware/baseband/CMakeLists.txt +++ b/firmware/baseband/CMakeLists.txt @@ -422,6 +422,13 @@ set(MODE_CPPSRC ) DeclareTargets(PSTX sstvtx) +### Test + +set(MODE_CPPSRC + proc_test.cpp +) +DeclareTargets(PTST test) + ### Tones set(MODE_CPPSRC diff --git a/firmware/baseband/proc_test.cpp b/firmware/baseband/proc_test.cpp new file mode 100644 index 00000000..d31da2ac --- /dev/null +++ b/firmware/baseband/proc_test.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc. + * Copyright (C) 2017 Furrtek + * + * 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_test.hpp" + +#include "dsp_fir_taps.hpp" + +#include "event_m4.hpp" + +TestProcessor::TestProcessor() { + decim_0.configure(taps_11k0_decim_0.taps, 33554432); + decim_1.configure(taps_11k0_decim_1.taps, 131072); +} + +void TestProcessor::execute(const buffer_c8_t& buffer) { + /* 2.4576MHz, 2048 samples */ + + const auto decim_0_out = decim_0.execute(buffer, dst_buffer); + const auto decim_1_out = decim_1.execute(decim_0_out, dst_buffer); + const auto decimator_out = decim_1_out; + + /* 38.4kHz, 32 samples */ + feed_channel_stats(decimator_out); + + for(size_t i=0; i() }; + event_dispatcher.run(); + return 0; +} diff --git a/firmware/baseband/proc_test.hpp b/firmware/baseband/proc_test.hpp new file mode 100644 index 00000000..dcdcd4a9 --- /dev/null +++ b/firmware/baseband/proc_test.hpp @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc. + * Copyright (C) 2017 Furrtek + * + * 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_TEST_H__ +#define __PROC_TEST_H__ + +#include "baseband_processor.hpp" +#include "baseband_thread.hpp" +#include "rssi_thread.hpp" +#include "proc_ais.hpp" + +#include "channel_decimator.hpp" +#include "matched_filter.hpp" + +#include "clock_recovery.hpp" +#include "symbol_coding.hpp" +#include "packet_builder.hpp" +#include "baseband_packet.hpp" + +#include "message.hpp" +#include "portapack_shared_memory.hpp" + +#include +#include +#include + +class TestProcessor : public BasebandProcessor { +public: + TestProcessor(); + + void execute(const buffer_c8_t& buffer) override; + +private: + static constexpr size_t baseband_fs = 2457600; + + 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() + }; + + dsp::decimate::FIRC8xR16x24FS4Decim8 decim_0 { }; + dsp::decimate::FIRC16xR16x32Decim8 decim_1 { }; + dsp::matched_filter::MatchedFilter mf { baseband::ais::square_taps_38k4_1t_p, 2 }; + + clock_recovery::ClockRecovery clock_recovery_fsk_9600 { + 19200, 9600, { 0.00555f }, + [this](const float raw_symbol) { + const uint_fast8_t sliced_symbol = (raw_symbol >= 0.0f) ? 1 : 0; + this->packet_builder_fsk_9600_CC1101.execute(sliced_symbol); + } + }; + PacketBuilder packet_builder_fsk_9600_CC1101 { + { 0b01010110010110100101101001101010, 32, 1 }, // Manchester 0x1337 + { }, + { 10 * 8 }, + [this](const baseband::Packet& packet) { + const TestAppPacketMessage message { packet }; + shared_memory.application_queue.push(message); + } + }; +}; + +#endif/*__PROC_TEST_H__*/ diff --git a/firmware/common/message.hpp b/firmware/common/message.hpp index ab23d14d..3fb4e898 100644 --- a/firmware/common/message.hpp +++ b/firmware/common/message.hpp @@ -97,6 +97,7 @@ public: POCSAGPacket = 50, ADSBFrame = 51, AFSKData = 52, + TestAppPacket = 53, RequestSignal = 60, FIFOData = 61, @@ -390,6 +391,18 @@ public: baseband::Packet packet; }; +class TestAppPacketMessage : public Message { +public: + constexpr TestAppPacketMessage( + const baseband::Packet& packet + ) : Message { ID::TestAppPacket }, + packet { packet } + { + } + + baseband::Packet packet; +}; + class UpdateSpectrumMessage : public Message { public: constexpr UpdateSpectrumMessage( diff --git a/firmware/common/sonde_packet.cpp b/firmware/common/sonde_packet.cpp index 088d8777..5eba330c 100644 --- a/firmware/common/sonde_packet.cpp +++ b/firmware/common/sonde_packet.cpp @@ -62,7 +62,7 @@ std::string Packet::signature() const { if (header == 0x649F20) return "M10"; - else if (header == 0x648F20) + else if ((header == 0x648F20) || (header == 0x648F23)) return "M2K2"; else return "0x" + symbols_formatted().data.substr(0, 6); diff --git a/firmware/common/spi_image.hpp b/firmware/common/spi_image.hpp index 036b3fd1..51ea0679 100644 --- a/firmware/common/spi_image.hpp +++ b/firmware/common/spi_image.hpp @@ -75,6 +75,7 @@ constexpr image_tag_t image_tag_sonde { 'P', 'S', 'O', 'N' }; constexpr image_tag_t image_tag_tpms { 'P', 'T', 'P', 'M' }; constexpr image_tag_t image_tag_wfm_audio { 'P', 'W', 'F', 'M' }; constexpr image_tag_t image_tag_wideband_spectrum { 'P', 'S', 'P', 'E' }; +constexpr image_tag_t image_tag_test { 'P', 'T', 'S', 'T' }; constexpr image_tag_t image_tag_adsb_tx { 'P', 'A', 'D', 'T' }; constexpr image_tag_t image_tag_afsk { 'P', 'A', 'F', 'T' }; diff --git a/firmware/common/test_packet.cpp b/firmware/common/test_packet.cpp new file mode 100644 index 00000000..86c2fb8a --- /dev/null +++ b/firmware/common/test_packet.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc. + * Copyright (C) 2017 Furrtek + * + * 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 "test_packet.hpp" +#include "string_format.hpp" + +namespace testapp { + +size_t Packet::length() const { + return decoder_.symbols_count(); +} + +bool Packet::is_valid() const { + return true; +} + +Timestamp Packet::received_at() const { + return packet_.timestamp(); +} + +FormattedSymbols Packet::symbols_formatted() const { + return format_symbols(decoder_); +} + +uint32_t Packet::value() const { + return reader_.read(3 * 8, 8); +} + +uint32_t Packet::alt() const { + return reader_.read(1 * 8, 12) - 0xC00; +} + +} /* namespace testapp */ diff --git a/firmware/common/test_packet.hpp b/firmware/common/test_packet.hpp new file mode 100644 index 00000000..d4b23d7d --- /dev/null +++ b/firmware/common/test_packet.hpp @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc. + * Copyright (C) 2017 Furrtek + * + * 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 __TEST_PACKET_H__ +#define __TEST_PACKET_H__ + +#include +#include + +#include "field_reader.hpp" +#include "baseband_packet.hpp" +#include "manchester.hpp" + +namespace testapp { + +class Packet { +public: + Packet( + const baseband::Packet& packet + ) : packet_ { packet }, + decoder_ { packet_ }, + reader_ { decoder_ } + { + } + + size_t length() const; + + bool is_valid() const; + + Timestamp received_at() const; + + uint32_t value() const; + uint32_t alt() const; + /*std::string serial_number() const; + uint32_t GPS_altitude() const; + float GPS_latitude() const; + float GPS_longitude() const; + std::string signature() const; + uint32_t battery_voltage() const;*/ + + FormattedSymbols symbols_formatted() const; + + //bool crc_ok() const; + +private: + using Reader = FieldReader; + + const baseband::Packet packet_; + const ManchesterDecoder decoder_; + const Reader reader_; +}; + +} /* namespace testapp */ + +#endif/*__TEST_PACKET_H__*/