Rtty tx and rx (#2977)

This commit is contained in:
Totoo
2026-02-16 14:34:55 +01:00
committed by GitHub
parent 95eafeb812
commit 794daf5257
21 changed files with 1809 additions and 1 deletions
+104
View File
@@ -0,0 +1,104 @@
#include "baudot.hpp"
#include <cctype>
namespace ui::external_app::rtty_rx {
constexpr uint8_t CODE_FIGS = 0x1B;
constexpr uint8_t CODE_LTRS = 0x1F;
constexpr uint8_t CODE_SPACE = 0x04;
char BaudotCoder::get_char_mapping(bool is_figures, uint8_t index) const {
if (index >= 32) return 0; // Safety check
if (is_figures) {
// ITA2 FIGURES Table
const char figures[32] = {
0, '3', '\n', '-', ' ', '\'', '8', '7',
'\r', '$', '4', '\a', ',', '!', ':', '(',
'5', '+', ')', '2', '#', '6', '0', '1',
'9', '?', '&', 0, '.', '/', '=', 0};
return figures[index];
} else {
// ITA2 LETTERS Table
const char letters[32] = {
0, 'E', '\n', 'A', ' ', 'S', 'I', 'U',
'\r', 'D', 'R', 'J', 'N', 'F', 'C', 'K',
'T', 'Z', 'L', 'W', 'H', 'Y', 'P', 'Q',
'O', 'B', 'G', 0, 'M', 'X', 'V', 0};
return letters[index];
}
}
// --- DECODE ---
char BaudotCoder::decode(uint8_t baudotCode) {
uint8_t code = baudotCode & 0x1F;
if (code == CODE_FIGS) {
shiftState = FIGURES;
return 0;
}
if (code == CODE_LTRS) {
shiftState = LETTERS;
return 0;
}
if (usos_enabled && shiftState == FIGURES && code == CODE_SPACE) {
shiftState = LETTERS;
return ' ';
}
return get_char_mapping((shiftState == FIGURES), code);
}
void BaudotCoder::encode(const std::string& src, uint8_t* dest, uint16_t* dest_length, uint16_t dest_max_size) {
uint16_t idx = 0;
for (char c : src) {
if (idx >= dest_max_size) break;
char upper_c = std::toupper(c);
uint8_t code = 0;
bool found = false;
bool target_is_figures = false;
if (upper_c == ' ') {
code = CODE_SPACE;
found = true;
} else {
for (int i = 1; i < 32; i++) {
if (get_char_mapping(false, i) == upper_c) {
code = i;
found = true;
target_is_figures = false;
break;
}
}
if (!found) {
for (int i = 1; i < 32; i++) {
if (get_char_mapping(true, i) == upper_c) {
code = i;
found = true;
target_is_figures = true;
break;
}
}
}
}
if (found) {
if (target_is_figures && shiftState != FIGURES) {
if (idx + 1 >= dest_max_size) break;
dest[idx++] = CODE_FIGS;
shiftState = FIGURES;
} else if (!target_is_figures && shiftState != LETTERS && code != CODE_SPACE) {
if (idx + 1 >= dest_max_size) break;
dest[idx++] = CODE_LTRS;
shiftState = LETTERS;
}
dest[idx++] = code;
}
}
if (dest_length) {
*dest_length = idx;
}
}
} // namespace ui::external_app::rtty_rx
+28
View File
@@ -0,0 +1,28 @@
#ifndef BAUDOT_HPP
#define BAUDOT_HPP
#include <cstdint>
#include <string>
namespace ui::external_app::rtty_rx {
class BaudotCoder {
public:
enum ShiftState { LETTERS,
FIGURES };
BaudotCoder()
: shiftState(LETTERS) {}
char decode(uint8_t baudotCode);
void encode(const std::string& src, uint8_t* dest, uint16_t* dest_length, uint16_t dest_max_size);
void set_usos(bool enable) { usos_enabled = enable; } // shift == set to letters too
private:
ShiftState shiftState;
bool usos_enabled = true;
char get_char_mapping(bool is_figures, uint8_t index) const;
};
} // namespace ui::external_app::rtty_rx
#endif // BAUDOT_HPP
+83
View File
@@ -0,0 +1,83 @@
/*
* Copyright (C) 2026 HTotoo
*
* 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.hpp"
#include "ui_rtty_rx.hpp"
#include "ui_navigation.hpp"
#include "external_app.hpp"
namespace ui::external_app::rtty_rx {
void initialize_app(ui::NavigationView& nav) {
nav.push<RttyRxView>();
}
} // namespace ui::external_app::rtty_rx
extern "C" {
__attribute__((section(".external_app.app_rtty_rx.application_information"), used)) application_information_t _application_information_rtty_rx = {
/*.memory_location = */ (uint8_t*)0x00000000,
/*.externalAppEntry = */ ui::external_app::rtty_rx::initialize_app,
/*.header_version = */ CURRENT_HEADER_VERSION,
/*.app_version = */ VERSION_MD5,
/*.app_name = */ "RTTY",
/*.bitmap_data = */ {
0x00,
0x00,
0xFE,
0x1F,
0xFE,
0x3F,
0x0E,
0x78,
0x0E,
0x70,
0x0E,
0x70,
0x0E,
0x70,
0x0E,
0x78,
0xFE,
0x3F,
0xFE,
0x1F,
0x8E,
0x07,
0x0E,
0x0F,
0x0E,
0x1E,
0x0E,
0x3C,
0x0E,
0x78,
0x00,
0x00,
},
/*.icon_color = */ ui::Color::orange().v,
/*.menu_location = */ app_location_t::RX,
/*.desired_menu_position = */ -1,
/*.m4_app_tag = portapack::spi_flash::image_tag_rttyrx */ {'P', 'R', 'T', 'R'},
/*.m4_app_offset = */ 0x00000000, // will be filled at compile time
};
}
+96
View File
@@ -0,0 +1,96 @@
/*
* Copyright (C) 2026 HTotoo
*
* 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_rtty_rx.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 ui;
// todo add timeout, so add newline and time when new data arrives after a time.
namespace ui::external_app::rtty_rx {
void RttyRxView::focus() {
field_frequency.focus();
}
RttyRxView::RttyRxView(NavigationView& nav)
: nav_{nav} {
baseband::run_prepared_image(portapack::memory::map::m4_code.base());
add_children({
&rssi,
&field_rf_amp,
&field_lna,
&field_vga,
&field_volume,
&field_frequency,
&labels,
&options_baud,
&console,
});
field_frequency.set_step(100);
audio::set_rate(audio::Rate::Hz_24000);
audio::output::start();
receiver_model.set_hidden_offset(0);
receiver_model.set_sampling_rate(3072000); // set the needed baseband SR.
receiver_model.set_baseband_bandwidth(1750000); // set the front-end RF BW filter.
receiver_model.enable();
console.enable_scrolling(false);
options_baud.on_change = [this](size_t, int32_t value) {
baseband::set_rtty_config(value, 170);
baud_conf = value;
};
options_baud.set_by_value(baud_conf);
if (baud_conf == 0) { // to trigger it when not changed
baseband::set_rtty_config(0, 170);
}
}
void RttyRxView::got_message(std::string msg) {
console.write(msg);
}
RttyRxView::~RttyRxView() {
receiver_model.set_hidden_offset(0);
receiver_model.disable();
baseband::shutdown();
audio::output::stop();
}
void RttyRxView::on_data(const RTTYDataMessage* message) {
std::string msg = "";
for (size_t i = 0; i < message->data_len; i++) {
const auto c = baudot_decoder.decode(message->data[i]);
if (c != 0)
msg += c;
}
got_message(msg);
}
} // namespace ui::external_app::rtty_rx
+109
View File
@@ -0,0 +1,109 @@
/*
* Copyright (C) 2026 HTotoo
*
* 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_RTTY_RX_H__
#define __UI_RTTY_RX_H__
#include "ui.hpp"
#include "ui_language.hpp"
#include "ui_navigation.hpp"
#include "ui_receiver.hpp"
#include "ui_freq_field.hpp"
#include "app_settings.hpp"
#include "radio_state.hpp"
#include "log_file.hpp"
#include "utility.hpp"
#include "ui_fileman.hpp"
#include "file_path.hpp"
#include "baudot.hpp"
using namespace ui;
namespace ui::external_app::rtty_rx {
class RttyRxView : public View {
public:
RttyRxView(NavigationView& nav);
~RttyRxView();
void focus() override;
std::string title() const override { return "RTTY"; };
private:
NavigationView& nav_;
RxRadioState radio_state_{};
uint32_t baud_conf = 0;
app_settings::SettingsManager settings_{
"rx_rtty",
app_settings::Mode::RX,
{
{"baud_conf"sv, &baud_conf},
}};
RxFrequencyField field_frequency{
{UI_POS_X(0), UI_POS_Y(0)},
nav_};
RFAmpField field_rf_amp{
{UI_POS_X(13), UI_POS_Y(0)}};
LNAGainField field_lna{
{UI_POS_X(15), UI_POS_Y(0)}};
VGAGainField field_vga{
{UI_POS_X(18), UI_POS_Y(0)}};
RSSI rssi{
{UI_POS_X(21), UI_POS_Y(0), UI_POS_WIDTH_REMAINING(24), 4}};
AudioVolumeField field_volume{{UI_POS_X_RIGHT(2), UI_POS_Y(0)}};
Labels labels{
{{UI_POS_X(0), UI_POS_Y(1)}, "Baud:", Theme::getInstance()->fg_light->foreground}};
OptionsField options_baud{
{UI_POS_X(7), UI_POS_Y(1)},
5,
{{"Auto", 0},
{"45", 4500},
{"45.45", 4545},
{"50", 5000},
{"75", 7500},
{"100", 10000},
{"110", 11000},
{"150", 15000},
{"200", 20000}}};
Console console{
{UI_POS_X(0), UI_POS_Y(2), UI_POS_MAXWIDTH, UI_POS_HEIGHT_REMAINING(3)}};
BaudotCoder baudot_decoder{};
void on_data(const RTTYDataMessage* message);
void got_message(std::string msg);
MessageHandlerRegistration message_handler_data{
Message::ID::RTTYData,
[this](Message* const p) {
const auto message = static_cast<const RTTYDataMessage*>(p);
this->on_data(message);
}};
};
} // namespace ui::external_app::rtty_rx
#endif /*__UI_RTTY_RX_H__*/