diff --git a/firmware/application/Makefile b/firmware/application/Makefile index 697660c89..05a2fd5e6 100755 --- a/firmware/application/Makefile +++ b/firmware/application/Makefile @@ -179,6 +179,7 @@ CPPSRC = main.cpp \ ../common/tpms_packet.cpp \ ert_app.cpp \ ../common/ert_packet.cpp \ + capture_app.cpp \ sd_card.cpp \ file.cpp \ log_file.cpp \ diff --git a/firmware/application/capture_app.cpp b/firmware/application/capture_app.cpp new file mode 100644 index 000000000..d08a277eb --- /dev/null +++ b/firmware/application/capture_app.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2016 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. + */ + +#include "capture_app.hpp" + +#include "baseband_api.hpp" + +#include "utility.hpp" + +namespace ui { + +CaptureAppView::CaptureAppView(NavigationView&) { + capture_thread = std::make_unique("baseband.c16"); + + radio::enable({ + tuning_frequency(), + sampling_rate, + baseband_bandwidth, + rf::Direction::Receive, + false, 16, 16, + 1, + }); + + baseband::start({ + .mode = 7, + .sampling_rate = sampling_rate, + .decimation_factor = 1, + }); +} + +CaptureAppView::~CaptureAppView() { + baseband::stop(); + radio::disable(); +} + +uint32_t CaptureAppView::target_frequency() const { + return initial_target_frequency; +} + +uint32_t CaptureAppView::tuning_frequency() const { + return target_frequency() - (sampling_rate / 4); +} + +} /* namespace ui */ diff --git a/firmware/application/capture_app.hpp b/firmware/application/capture_app.hpp new file mode 100644 index 000000000..fe043ff94 --- /dev/null +++ b/firmware/application/capture_app.hpp @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2016 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 __CAPTURE_APP_HPP__ +#define __CAPTURE_APP_HPP__ + +#include "ui_widget.hpp" +#include "ui_navigation.hpp" + +#include "audio_thread.hpp" + +#include +#include + +namespace ui { + +class CaptureAppView : public View { +public: + CaptureAppView(NavigationView& nav); + ~CaptureAppView(); + + std::string title() const override { return "Capture"; }; + +private: + static constexpr uint32_t initial_target_frequency = 91500000; + static constexpr uint32_t sampling_rate = 2457600; + static constexpr uint32_t baseband_bandwidth = 1750000; + + std::unique_ptr capture_thread; + + uint32_t target_frequency() const; + uint32_t tuning_frequency() const; +}; + +} /* namespace ui */ + +#endif/*__CAPTURE_APP_HPP__*/ diff --git a/firmware/application/ui_navigation.cpp b/firmware/application/ui_navigation.cpp index ee7258017..2b245dd63 100644 --- a/firmware/application/ui_navigation.cpp +++ b/firmware/application/ui_navigation.cpp @@ -31,6 +31,7 @@ #include "ais_app.hpp" #include "ert_app.hpp" #include "tpms_app.hpp" +#include "capture_app.hpp" #include "core_control.hpp" @@ -168,7 +169,7 @@ ReceiverMenuView::ReceiverMenuView(NavigationView& nav) { SystemMenuView::SystemMenuView(NavigationView& nav) { add_items<7>({ { { "Receiver", [&nav](){ nav.push(); } }, - { "Capture", [&nav](){ nav.push(); } }, + { "Capture", [&nav](){ nav.push(); } }, { "Analyze", [&nav](){ nav.push(); } }, { "Setup", [&nav](){ nav.push(); } }, { "About", [&nav](){ nav.push(); } }, diff --git a/firmware/baseband/Makefile b/firmware/baseband/Makefile index fedacf9cd..5881ff660 100755 --- a/firmware/baseband/Makefile +++ b/firmware/baseband/Makefile @@ -145,6 +145,7 @@ CPPSRC = main.cpp \ proc_wideband_spectrum.cpp \ proc_tpms.cpp \ proc_ert.cpp \ + proc_capture.cpp \ dsp_squelch.cpp \ clock_recovery.cpp \ packet_builder.cpp \ diff --git a/firmware/baseband/baseband_thread.cpp b/firmware/baseband/baseband_thread.cpp index 2065979df..88d77ef09 100644 --- a/firmware/baseband/baseband_thread.cpp +++ b/firmware/baseband/baseband_thread.cpp @@ -38,6 +38,7 @@ #include "proc_wideband_spectrum.hpp" #include "proc_tpms.hpp" #include "proc_ert.hpp" +#include "proc_capture.hpp" #include "portapack_shared_memory.hpp" @@ -130,6 +131,7 @@ BasebandProcessor* BasebandThread::create_processor(const int32_t mode) { case 4: return new WidebandSpectrum(); case 5: return new TPMSProcessor(); case 6: return new ERTProcessor(); + case 7: return new CaptureProcessor(); default: return nullptr; } } diff --git a/firmware/baseband/proc_capture.cpp b/firmware/baseband/proc_capture.cpp new file mode 100644 index 000000000..fcbbd647b --- /dev/null +++ b/firmware/baseband/proc_capture.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2016 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. + */ + +#include "proc_capture.hpp" + +#include "dsp_fir_taps.hpp" + +#include "utility.hpp" + +CaptureProcessor::CaptureProcessor() { + decim_0.configure(taps_200k_decim_0.taps, 33554432); + decim_1.configure(taps_200k_decim_1.taps, 131072); + + stream = std::make_unique(15); +} + +void CaptureProcessor::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; + + if( stream ) { + const size_t bytes_to_write = sizeof(*decimator_out.p) * decimator_out.count; + const auto result = stream->write(decimator_out.p, bytes_to_write); + } +} diff --git a/firmware/baseband/proc_capture.hpp b/firmware/baseband/proc_capture.hpp new file mode 100644 index 000000000..9e77a8ce2 --- /dev/null +++ b/firmware/baseband/proc_capture.hpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2016 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 __PROC_CAPTURE_HPP__ +#define __PROC_CAPTURE_HPP__ + +#include "baseband_processor.hpp" +#include "dsp_decimate.hpp" + +#include "stream_input.hpp" + +#include +#include + +class CaptureProcessor : public BasebandProcessor { +public: + CaptureProcessor(); + + void execute(const buffer_c8_t& buffer) override; + +private: + std::array dst; + const buffer_c16_t dst_buffer { + dst.data(), + dst.size() + }; + + dsp::decimate::FIRC8xR16x24FS4Decim4 decim_0; + dsp::decimate::FIRC16xR16x16Decim2 decim_1; + + std::unique_ptr stream; +}; + +#endif/*__PROC_CAPTURE_HPP__*/