2015-08-28 14:50:42 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
2016-12-09 12:21:47 -05:00
|
|
|
* Copyright (C) 2016 Furrtek
|
2015-08-28 14:50:42 -04:00
|
|
|
*
|
|
|
|
* 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 "transmitter_model.hpp"
|
|
|
|
|
2016-04-28 08:59:14 -04:00
|
|
|
#include "baseband_api.hpp"
|
|
|
|
|
2015-08-28 14:50:42 -04:00
|
|
|
#include "portapack_persistent_memory.hpp"
|
2016-12-09 12:21:47 -05:00
|
|
|
#include "hackrf_gpio.hpp"
|
2018-02-22 02:04:19 -05:00
|
|
|
#include "portapack.hpp"
|
2017-01-15 22:45:44 -05:00
|
|
|
#include "rtc_time.hpp"
|
2016-12-09 12:21:47 -05:00
|
|
|
#include "event_m0.hpp"
|
2016-04-28 08:59:14 -04:00
|
|
|
#include "radio.hpp"
|
|
|
|
#include "audio.hpp"
|
|
|
|
|
2023-06-11 14:47:13 -04:00
|
|
|
using namespace hackrf::one;
|
|
|
|
using namespace portapack;
|
|
|
|
|
|
|
|
rf::Frequency TransmitterModel::target_frequency() const {
|
|
|
|
return persistent_memory::target_frequency();
|
2015-08-28 14:50:42 -04:00
|
|
|
}
|
|
|
|
|
2023-06-11 14:47:13 -04:00
|
|
|
void TransmitterModel::set_target_frequency(rf::Frequency f) {
|
|
|
|
persistent_memory::set_target_frequency(f);
|
2023-05-18 16:16:05 -04:00
|
|
|
update_tuning_frequency();
|
2015-08-28 14:50:42 -04:00
|
|
|
}
|
|
|
|
|
2018-02-22 02:04:19 -05:00
|
|
|
void TransmitterModel::set_antenna_bias() {
|
2023-05-18 16:16:05 -04:00
|
|
|
update_antenna_bias();
|
2018-02-22 02:04:19 -05:00
|
|
|
}
|
|
|
|
|
2015-08-28 14:50:42 -04:00
|
|
|
bool TransmitterModel::rf_amp() const {
|
2023-05-18 16:16:05 -04:00
|
|
|
return rf_amp_;
|
2015-08-28 14:50:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void TransmitterModel::set_rf_amp(bool enabled) {
|
2023-05-18 16:16:05 -04:00
|
|
|
rf_amp_ = enabled;
|
|
|
|
update_rf_amp();
|
2015-08-28 14:50:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t TransmitterModel::lna() const {
|
2023-05-18 16:16:05 -04:00
|
|
|
return lna_gain_db_;
|
2015-08-28 14:50:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void TransmitterModel::set_lna(int32_t v_db) {
|
2023-05-18 16:16:05 -04:00
|
|
|
lna_gain_db_ = v_db;
|
|
|
|
update_lna();
|
2015-08-28 14:50:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t TransmitterModel::baseband_bandwidth() const {
|
2023-05-18 16:16:05 -04:00
|
|
|
return baseband_bandwidth_;
|
2015-08-28 14:50:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void TransmitterModel::set_baseband_bandwidth(uint32_t v) {
|
2023-05-18 16:16:05 -04:00
|
|
|
baseband_bandwidth_ = v;
|
|
|
|
update_baseband_bandwidth();
|
2015-08-28 14:50:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t TransmitterModel::vga() const {
|
2023-05-18 16:16:05 -04:00
|
|
|
return vga_gain_db_;
|
2015-08-28 14:50:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void TransmitterModel::set_vga(int32_t v_db) {
|
2023-05-18 16:16:05 -04:00
|
|
|
vga_gain_db_ = v_db;
|
|
|
|
update_vga();
|
2015-08-28 14:50:42 -04:00
|
|
|
}
|
|
|
|
|
2017-08-12 14:28:57 -04:00
|
|
|
uint32_t TransmitterModel::channel_bandwidth() const {
|
2023-05-18 16:16:05 -04:00
|
|
|
return channel_bandwidth_;
|
2017-01-30 08:10:30 -05:00
|
|
|
}
|
|
|
|
|
2017-08-12 14:28:57 -04:00
|
|
|
void TransmitterModel::set_channel_bandwidth(uint32_t v) {
|
2023-05-18 16:16:05 -04:00
|
|
|
channel_bandwidth_ = v;
|
2017-01-30 08:10:30 -05:00
|
|
|
}
|
|
|
|
|
2015-08-28 14:50:42 -04:00
|
|
|
uint32_t TransmitterModel::sampling_rate() const {
|
2023-05-18 16:16:05 -04:00
|
|
|
return sampling_rate_;
|
2015-08-28 14:50:42 -04:00
|
|
|
}
|
|
|
|
|
2017-01-15 22:45:44 -05:00
|
|
|
void TransmitterModel::set_sampling_rate(uint32_t v) {
|
2023-05-18 16:16:05 -04:00
|
|
|
sampling_rate_ = v;
|
|
|
|
update_sampling_rate();
|
2016-07-26 21:03:40 -04:00
|
|
|
}
|
|
|
|
|
2017-01-30 08:10:30 -05:00
|
|
|
int32_t TransmitterModel::tx_gain() const {
|
2023-05-18 16:16:05 -04:00
|
|
|
return tx_gain_db_;
|
2017-01-30 08:10:30 -05:00
|
|
|
}
|
|
|
|
|
2017-01-17 09:27:37 -05:00
|
|
|
void TransmitterModel::set_tx_gain(int32_t v_db) {
|
2023-05-18 16:16:05 -04:00
|
|
|
tx_gain_db_ = v_db;
|
|
|
|
update_tx_gain();
|
2017-01-17 09:27:37 -05:00
|
|
|
}
|
|
|
|
|
2016-12-09 12:21:47 -05:00
|
|
|
void TransmitterModel::on_tick_second() {
|
2023-05-18 16:16:05 -04:00
|
|
|
if (portapack::persistent_memory::stealth_mode())
|
|
|
|
led_tx.toggle();
|
2016-12-09 12:21:47 -05:00
|
|
|
}
|
|
|
|
|
2015-08-28 14:50:42 -04:00
|
|
|
void TransmitterModel::enable() {
|
2023-05-18 16:16:05 -04:00
|
|
|
enabled_ = true;
|
|
|
|
radio::set_direction(rf::Direction::Transmit);
|
|
|
|
update_tuning_frequency();
|
|
|
|
update_antenna_bias();
|
|
|
|
update_rf_amp();
|
|
|
|
update_lna();
|
|
|
|
update_vga();
|
|
|
|
update_baseband_bandwidth();
|
|
|
|
update_sampling_rate();
|
2023-05-24 00:22:30 -04:00
|
|
|
update_tx_gain();
|
2023-05-18 16:16:05 -04:00
|
|
|
|
|
|
|
led_tx.on();
|
|
|
|
signal_token_tick_second = rtc_time::signal_tick_second += [this]() {
|
|
|
|
this->on_tick_second();
|
|
|
|
};
|
2023-06-11 14:47:13 -04:00
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
if (portapack::persistent_memory::stealth_mode()) {
|
|
|
|
DisplaySleepMessage message;
|
|
|
|
EventDispatcher::send_message(message);
|
|
|
|
}
|
2015-08-28 14:50:42 -04:00
|
|
|
}
|
|
|
|
|
2016-02-04 04:27:53 -05:00
|
|
|
void TransmitterModel::disable() {
|
2023-05-18 16:16:05 -04:00
|
|
|
enabled_ = false;
|
2016-02-04 04:27:53 -05:00
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
radio::disable();
|
|
|
|
|
|
|
|
rtc_time::signal_tick_second -= signal_token_tick_second;
|
|
|
|
led_tx.off();
|
2015-08-28 14:50:42 -04:00
|
|
|
}
|
|
|
|
|
2023-06-17 10:54:52 -04:00
|
|
|
void TransmitterModel::set_configuration_without_update(
|
|
|
|
uint32_t baseband_bandwidth,
|
|
|
|
uint32_t sampling_rate) {
|
|
|
|
baseband_bandwidth_ = baseband_bandwidth;
|
|
|
|
sampling_rate_ = sampling_rate;
|
|
|
|
}
|
|
|
|
|
2023-06-11 14:47:13 -04:00
|
|
|
void TransmitterModel::configure_from_app_settings(
|
|
|
|
const app_settings::AppSettings& settings) {
|
|
|
|
baseband_bandwidth_ = settings.baseband_bandwidth;
|
|
|
|
channel_bandwidth_ = settings.channel_bandwidth;
|
|
|
|
tx_gain_db_ = settings.tx_gain;
|
|
|
|
rf_amp_ = settings.tx_amp;
|
|
|
|
|
|
|
|
// TODO: Do these make sense for TX?
|
|
|
|
lna_gain_db_ = settings.lna;
|
|
|
|
vga_gain_db_ = settings.vga;
|
|
|
|
sampling_rate_ = settings.sampling_rate;
|
|
|
|
}
|
|
|
|
|
2015-08-28 14:50:42 -04:00
|
|
|
void TransmitterModel::update_tuning_frequency() {
|
2023-06-12 13:40:32 -04:00
|
|
|
radio::set_tuning_frequency(target_frequency());
|
2015-08-28 14:50:42 -04:00
|
|
|
}
|
|
|
|
|
2018-02-22 02:04:19 -05:00
|
|
|
void TransmitterModel::update_antenna_bias() {
|
2023-05-18 16:16:05 -04:00
|
|
|
if (enabled_)
|
|
|
|
radio::set_antenna_bias(portapack::get_antenna_bias());
|
2018-02-22 02:04:19 -05:00
|
|
|
}
|
|
|
|
|
2015-08-28 14:50:42 -04:00
|
|
|
void TransmitterModel::update_rf_amp() {
|
2023-05-18 16:16:05 -04:00
|
|
|
radio::set_rf_amp(rf_amp_);
|
2015-08-28 14:50:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void TransmitterModel::update_lna() {
|
2023-05-18 16:16:05 -04:00
|
|
|
radio::set_lna_gain(lna_gain_db_);
|
2015-08-28 14:50:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void TransmitterModel::update_baseband_bandwidth() {
|
2023-05-18 16:16:05 -04:00
|
|
|
radio::set_baseband_filter_bandwidth(baseband_bandwidth_);
|
2015-08-28 14:50:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void TransmitterModel::update_vga() {
|
2023-05-18 16:16:05 -04:00
|
|
|
radio::set_vga_gain(vga_gain_db_);
|
2015-08-28 14:50:42 -04:00
|
|
|
}
|
|
|
|
|
2017-01-15 22:45:44 -05:00
|
|
|
void TransmitterModel::update_tx_gain() {
|
2023-05-18 16:16:05 -04:00
|
|
|
radio::set_tx_gain(tx_gain_db_);
|
2016-01-05 05:47:46 -05:00
|
|
|
}
|
|
|
|
|
2017-01-15 22:45:44 -05:00
|
|
|
void TransmitterModel::update_sampling_rate() {
|
2023-05-18 16:16:05 -04:00
|
|
|
// TODO: Move more low-level radio control stuff to M4. It'll enable tighter
|
|
|
|
// synchronization for things like wideband (sweeping) spectrum analysis, and
|
|
|
|
// protocols that need quick RX/TX turn-around.
|
|
|
|
|
|
|
|
// Disabling baseband while changing sampling rates seems like a good idea...
|
|
|
|
|
|
|
|
radio::set_baseband_rate(sampling_rate());
|
|
|
|
update_tuning_frequency();
|
2015-08-28 14:50:42 -04:00
|
|
|
}
|