2015-08-28 14:50:42 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
2016-05-27 19:59:13 -04: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 "ui_rds.hpp"
|
|
|
|
|
|
|
|
#include "portapack.hpp"
|
2016-07-26 21:03:40 -04:00
|
|
|
#include "baseband_api.hpp"
|
2022-08-27 11:47:24 -04:00
|
|
|
#include "cpld_update.hpp"
|
2015-08-28 14:50:42 -04:00
|
|
|
#include "portapack_shared_memory.hpp"
|
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
|
2016-02-04 04:27:53 -05:00
|
|
|
using namespace portapack;
|
2016-12-05 06:56:41 -05:00
|
|
|
using namespace rds;
|
2015-08-28 14:50:42 -04:00
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
|
2017-08-16 05:02:57 -04:00
|
|
|
RDSPSNView::RDSPSNView(
|
|
|
|
NavigationView& nav,
|
|
|
|
Rect parent_rect
|
|
|
|
) : OptionTabView(parent_rect)
|
|
|
|
{
|
|
|
|
set_type("PSN");
|
|
|
|
|
|
|
|
add_children({
|
|
|
|
&labels,
|
|
|
|
&text_psn,
|
|
|
|
&button_set,
|
|
|
|
&check_mono_stereo,
|
|
|
|
&check_TA,
|
|
|
|
&check_MS
|
|
|
|
});
|
|
|
|
|
|
|
|
set_enabled(true);
|
|
|
|
|
|
|
|
check_TA.set_value(true);
|
|
|
|
|
|
|
|
check_mono_stereo.on_select = [this](Checkbox&, bool value) {
|
|
|
|
mono_stereo = value;
|
|
|
|
};
|
|
|
|
check_TA.on_select = [this](Checkbox&, bool value) {
|
|
|
|
TA = value;
|
|
|
|
};
|
|
|
|
check_MS.on_select = [this](Checkbox&, bool value) {
|
|
|
|
MS = value;
|
|
|
|
};
|
|
|
|
|
|
|
|
button_set.on_select = [this, &nav](Button&) {
|
|
|
|
text_prompt(
|
|
|
|
nav,
|
2019-05-04 19:43:36 -04:00
|
|
|
PSN,
|
2017-08-16 05:02:57 -04:00
|
|
|
8,
|
2019-05-04 19:43:36 -04:00
|
|
|
[this](std::string& s) {
|
|
|
|
text_psn.set(s);
|
2017-08-16 05:02:57 -04:00
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
RDSRadioTextView::RDSRadioTextView(
|
|
|
|
NavigationView& nav,
|
|
|
|
Rect parent_rect
|
|
|
|
) : OptionTabView(parent_rect)
|
|
|
|
{
|
|
|
|
set_type("Radiotext");
|
|
|
|
|
|
|
|
add_children({
|
|
|
|
&labels,
|
|
|
|
&button_set,
|
|
|
|
&text_radiotext
|
|
|
|
});
|
|
|
|
|
|
|
|
button_set.on_select = [this, &nav](Button&){
|
|
|
|
text_prompt(
|
|
|
|
nav,
|
2019-05-04 19:43:36 -04:00
|
|
|
radiotext,
|
2017-08-16 05:02:57 -04:00
|
|
|
28,
|
2019-05-04 19:43:36 -04:00
|
|
|
[this](std::string& s) {
|
|
|
|
text_radiotext.set(s);
|
2017-08-16 05:02:57 -04:00
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
2015-08-28 14:50:42 -04:00
|
|
|
}
|
|
|
|
|
2017-08-16 05:02:57 -04:00
|
|
|
RDSDateTimeView::RDSDateTimeView(
|
|
|
|
Rect parent_rect
|
|
|
|
) : OptionTabView(parent_rect)
|
|
|
|
{
|
|
|
|
set_type("date & time");
|
|
|
|
|
|
|
|
add_children({
|
|
|
|
&labels
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
RDSAudioView::RDSAudioView(
|
|
|
|
Rect parent_rect
|
|
|
|
) : OptionTabView(parent_rect)
|
|
|
|
{
|
|
|
|
set_type("audio");
|
|
|
|
|
|
|
|
add_children({
|
|
|
|
&labels
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
RDSThread::RDSThread(
|
|
|
|
std::vector<RDSGroup>** frames
|
|
|
|
) : frames_ { std::move(frames) }
|
|
|
|
{
|
|
|
|
thread = chThdCreateFromHeap(NULL, 1024, NORMALPRIO + 10, RDSThread::static_fn, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
RDSThread::~RDSThread() {
|
|
|
|
if( thread ) {
|
|
|
|
chThdTerminate(thread);
|
|
|
|
chThdWait(thread);
|
|
|
|
thread = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
msg_t RDSThread::static_fn(void* arg) {
|
|
|
|
auto obj = static_cast<RDSThread*>(arg);
|
|
|
|
obj->run();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RDSThread::run() {
|
|
|
|
std::vector<RDSGroup>* frame_ptr;
|
|
|
|
size_t block_count, c;
|
|
|
|
uint32_t * tx_data_u32 = (uint32_t*)shared_memory.bb_data.data;
|
|
|
|
uint32_t frame_index = 0;
|
|
|
|
|
|
|
|
while( !chThdShouldTerminate() ) {
|
|
|
|
|
|
|
|
do {
|
|
|
|
frame_ptr = frames_[frame_index];
|
|
|
|
|
|
|
|
if (frame_index == 2) {
|
|
|
|
frame_index = 0;
|
|
|
|
} else {
|
|
|
|
frame_index++;
|
|
|
|
}
|
|
|
|
} while(!(block_count = frame_ptr->size() * 4));
|
|
|
|
|
|
|
|
for (c = 0; c < block_count; c++)
|
|
|
|
tx_data_u32[c] = frame_ptr->at(c >> 2).block[c & 3];
|
|
|
|
|
|
|
|
baseband::set_rds_data(block_count * 26);
|
|
|
|
|
|
|
|
chThdSleepMilliseconds(1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RDSView::focus() {
|
|
|
|
tab_view.focus();
|
2016-05-27 19:59:13 -04:00
|
|
|
}
|
|
|
|
|
2016-12-05 06:56:41 -05:00
|
|
|
RDSView::~RDSView() {
|
2022-05-13 08:38:04 -04:00
|
|
|
// save app settings
|
|
|
|
app_settings.tx_frequency = transmitter_model.tuning_frequency();
|
|
|
|
settings.save("tx_rds", &app_settings);
|
|
|
|
|
2016-12-05 06:56:41 -05:00
|
|
|
transmitter_model.disable();
|
2022-08-27 11:47:24 -04:00
|
|
|
hackrf::cpld::load_sram_no_verify(); // to leave all RX ok, without ghost signal problem at the exit.
|
|
|
|
baseband::shutdown(); // better this function at the end, not load_sram() that sometimes produces hang up.
|
2016-05-29 06:06:47 -04:00
|
|
|
}
|
2015-08-28 14:50:42 -04:00
|
|
|
|
2016-12-05 06:56:41 -05:00
|
|
|
void RDSView::start_tx() {
|
2017-08-16 05:02:57 -04:00
|
|
|
rds_flags.PI_code = sym_pi_code.value_hex_u64();
|
|
|
|
rds_flags.PTY = options_pty.selected_index_value();
|
|
|
|
rds_flags.DI = view_PSN.mono_stereo ? 1 : 0;
|
|
|
|
rds_flags.TP = check_TP.value();
|
|
|
|
rds_flags.TA = view_PSN.TA;
|
|
|
|
rds_flags.MS = view_PSN.MS;
|
|
|
|
|
|
|
|
if (view_PSN.is_enabled())
|
|
|
|
gen_PSN(frame_psn, view_PSN.PSN, &rds_flags);
|
|
|
|
else
|
|
|
|
frame_psn.clear();
|
|
|
|
|
|
|
|
if (view_radiotext.is_enabled())
|
|
|
|
gen_RadioText(frame_radiotext, view_radiotext.radiotext, 0, &rds_flags);
|
|
|
|
else
|
|
|
|
frame_radiotext.clear();
|
|
|
|
|
|
|
|
// DEBUG
|
|
|
|
if (view_datetime.is_enabled())
|
|
|
|
gen_ClockTime(frame_datetime, &rds_flags, 2016, 12, 1, 9, 23, 2);
|
|
|
|
else
|
|
|
|
frame_datetime.clear();
|
|
|
|
|
2017-01-15 22:45:44 -05:00
|
|
|
transmitter_model.set_sampling_rate(2280000U);
|
2016-12-05 06:56:41 -05:00
|
|
|
transmitter_model.set_baseband_bandwidth(1750000);
|
|
|
|
transmitter_model.enable();
|
|
|
|
|
2017-08-16 05:02:57 -04:00
|
|
|
tx_thread = std::make_unique<RDSThread>(frames);
|
2015-08-28 14:50:42 -04:00
|
|
|
}
|
|
|
|
|
2017-08-16 05:02:57 -04:00
|
|
|
RDSView::RDSView(
|
|
|
|
NavigationView& nav
|
|
|
|
) : nav_ { nav }
|
|
|
|
{
|
2016-07-26 21:03:40 -04:00
|
|
|
baseband::run_image(portapack::spi_flash::image_tag_rds);
|
2016-05-29 06:06:47 -04:00
|
|
|
|
2017-01-15 22:45:44 -05:00
|
|
|
add_children({
|
2017-08-16 05:02:57 -04:00
|
|
|
&tab_view,
|
2017-02-13 00:35:13 -05:00
|
|
|
&labels,
|
2016-12-09 12:21:47 -05:00
|
|
|
&sym_pi_code,
|
2017-08-16 05:02:57 -04:00
|
|
|
&check_TP,
|
|
|
|
&options_pty,
|
|
|
|
&view_PSN,
|
|
|
|
&view_radiotext,
|
|
|
|
&view_datetime,
|
|
|
|
&view_audio,
|
2017-02-07 17:12:20 -05:00
|
|
|
&tx_view,
|
2017-01-15 22:45:44 -05:00
|
|
|
});
|
2022-05-13 08:38:04 -04:00
|
|
|
|
|
|
|
// load app settings
|
|
|
|
auto rc = settings.load("tx_rds", &app_settings);
|
|
|
|
if(rc == SETTINGS_OK) {
|
|
|
|
transmitter_model.set_rf_amp(app_settings.tx_amp);
|
|
|
|
transmitter_model.set_channel_bandwidth(app_settings.channel_bandwidth);
|
|
|
|
transmitter_model.set_tuning_frequency(app_settings.tx_frequency);
|
|
|
|
transmitter_model.set_tx_gain(app_settings.tx_gain);
|
|
|
|
}
|
2017-08-16 05:02:57 -04:00
|
|
|
check_TP.set_value(true);
|
|
|
|
|
|
|
|
sym_pi_code.set_sym(0, 0xF);
|
|
|
|
sym_pi_code.set_sym(1, 0x3);
|
|
|
|
sym_pi_code.set_sym(2, 0xE);
|
|
|
|
sym_pi_code.set_sym(3, 0x0);
|
|
|
|
sym_pi_code.on_change = [this]() {
|
|
|
|
rds_flags.PI_code = sym_pi_code.value_hex_u64();
|
|
|
|
};
|
|
|
|
|
|
|
|
options_pty.set_selected_index(0); // None
|
|
|
|
|
2017-02-07 17:12:20 -05:00
|
|
|
tx_view.on_edit_frequency = [this, &nav]() {
|
|
|
|
auto new_view = nav.push<FrequencyKeypadView>(receiver_model.tuning_frequency());
|
2016-05-27 19:59:13 -04:00
|
|
|
new_view->on_changed = [this](rf::Frequency f) {
|
2017-02-07 17:12:20 -05:00
|
|
|
receiver_model.set_tuning_frequency(f);
|
2016-05-27 19:59:13 -04:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-02-07 17:12:20 -05:00
|
|
|
tx_view.on_start = [this]() {
|
2017-08-16 05:02:57 -04:00
|
|
|
start_tx();
|
2017-02-07 17:12:20 -05:00
|
|
|
tx_view.set_transmitting(true);
|
|
|
|
txing = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
tx_view.on_stop = [this]() {
|
2018-01-09 16:12:19 -05:00
|
|
|
// Kill tx_thread here ?
|
2017-02-07 17:12:20 -05:00
|
|
|
tx_view.set_transmitting(false);
|
|
|
|
transmitter_model.disable();
|
|
|
|
txing = false;
|
|
|
|
};
|
2015-08-28 14:50:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace ui */
|