Files
mayhem-firmware/firmware/application/external/pocsag_tx/ui_pocsag_tx.cpp
T
Totoo 900c80549f externalize basebands, not needed, and remove too high level function (#3134)
* externalize basebands, not needed, and remove too high level function

* fix ert
2026-04-10 21:08:46 +02:00

231 lines
7.3 KiB
C++

/*
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
* Copyright (C) 2016 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_pocsag_tx.hpp"
#include "baseband_api.hpp"
#include "string_format.hpp"
#include "ui_textentry.hpp"
#include "portapack_persistent_memory.hpp"
using namespace portapack;
using namespace pocsag;
namespace ui::external_app::pocsag_tx {
#define MAX_POCSAG_LENGTH 80
void POCSAGTXView::focus() {
field_address.focus();
}
POCSAGTXView::~POCSAGTXView() {
transmitter_model.disable();
baseband::shutdown();
}
void POCSAGTXView::on_remete(const PocsagTosendMessage data) {
// check if still sending or not
size_t tmp = 0;
if (data.baud == 1200) tmp = 1;
if (data.baud == 2400) tmp = 2;
options_bitrate.set_selected_index(tmp);
tmp = 0;
options_type.set_selected_index(data.type);
if (data.function == 'B') tmp = 1;
if (data.function == 'C') tmp = 2;
if (data.function == 'D') tmp = 3;
options_function.set_selected_index(tmp);
/* 'S' = Standard (CCIR Rec. 584 polarity), 'I' = Inverted */
options_polarity.set_selected_index(data.polarity == 'S' ? 0 : 1);
field_address.set_value(data.addr);
message = (char*)data.msg;
buffer = message;
text_message.set(message);
options_bitrate.dirty();
options_type.dirty();
options_function.dirty();
options_polarity.dirty();
field_address.dirty();
text_message.dirty();
tx_view.focus();
start_tx();
}
void POCSAGTXView::on_tx_progress(const uint32_t progress, const bool done) {
if (done) {
transmitter_model.disable();
progressbar.set_value(0);
tx_view.set_transmitting(false);
} else
progressbar.set_value(progress);
}
bool POCSAGTXView::start_tx() {
uint32_t total_frames, i, codeword, bi, address;
pocsag::BitRate bitrate;
std::vector<uint32_t> codewords;
address = field_address.to_integer();
if (address > 0x1FFFFFU) {
nav_.display_modal("Bad address", "Address must be less\nthan 2097152.");
return false;
}
MessageType type = (MessageType)options_type.selected_index_value();
if (type == MessageType::NUMERIC_ONLY) {
// Check for invalid characters
const char* p = message.c_str();
bool is_valid = true;
while (*p != '\0') {
const char c = *p;
// Check if char is NOT in the allowed set
if (!((c >= '0' && c <= '9') || c == 'S' || c == 'U' ||
c == ' ' || c == '-' || c == '[' || c == ']')) {
is_valid = false;
break;
}
p++;
}
if (!is_valid) {
nav_.display_modal("Bad message", "A numeric only message must\nonly contain:\n0123456789SU][- or space.");
return false;
}
}
/*
* TX polarity inversion (CCIR Rec. 584):
*
* The FSK modulator (proc_fsk.cpp) maps bit 1 to positive deviation.
* Standard POCSAG requires bit 1 to negative deviation.
*
* "Standard" (value 0): invert codewords so that original bit 1 becomes
* bit 0 in the modulator, producing negative deviation. This is the standard.
* "Inverted" (value 1): send codewords as-is. Bit 1 produces positive deviation.
*/
bool invert_polarity = (options_polarity.selected_index_value() == 0);
pocsag_encode(type, BCH_code, options_function.selected_index_value(), message, address, codewords);
total_frames = codewords.size() / 2;
progressbar.set_max(total_frames);
// transmitter_model.set_rf_amp(true);
// transmitter_model.set_tx_gain(40);
// We left exactly same TX LPF settings as previous fw 1.7.4, TX LPF= 1M75 (min). It is fine even in max FM dev. 150khz and 2400 bauds.
transmitter_model.set_baseband_bandwidth(1'750'000); // Min TX LPF . Pocsag is NBFM , using BW channel 25khz or 12khz
transmitter_model.enable();
uint8_t* data_ptr = shared_memory.bb_data.data;
bi = 0;
for (i = 0; i < codewords.size(); i++) {
codeword = invert_polarity ? ~(codewords[i]) : codewords[i];
data_ptr[bi++] = (codeword >> 24) & 0xFF;
data_ptr[bi++] = (codeword >> 16) & 0xFF;
data_ptr[bi++] = (codeword >> 8) & 0xFF;
data_ptr[bi++] = codeword & 0xFF;
}
bitrate = pocsag_bitrates[options_bitrate.selected_index()];
baseband::set_fsk_data(
codewords.size() * 32,
2280000 / bitrate,
4500,
64);
return true;
}
void POCSAGTXView::paint(Painter&) {
message = buffer;
text_message.set(message); // the whole message, but it may not fit.
if (message.length() > 30 && message.length() <= 60) {
text_message_l2.set(message.substr(29)); // remaining to 2nd line
} else if (message.length() > 60) {
text_message_l2.set(message.substr(29, 27) + "...");
} else {
text_message_l2.set("");
}
}
void POCSAGTXView::on_set_text(NavigationView& nav) {
text_prompt(nav, buffer, MAX_POCSAG_LENGTH, ENTER_KEYBOARD_MODE_ALPHA);
}
POCSAGTXView::POCSAGTXView(
NavigationView& nav)
: nav_(nav) {
baseband::run_prepared_image(portapack::memory::map::m4_code.base());
add_children({&labels,
&options_bitrate,
&field_address,
&options_type,
&options_function,
&options_polarity,
&text_message,
&text_message_l2,
&button_message,
&progressbar,
&tx_view});
options_bitrate.set_selected_index(1); // 1200 bps
options_type.set_selected_index(2); // Alphanumeric
options_function.set_selected_index(0); // Function A
options_polarity.set_selected_index(0); // Standard (CCIR Rec. 584)
field_address.set_value(persistent_memory::pocsag_last_address());
options_type.on_change = [this](size_t, int32_t i) {
if (i == 2)
options_function.set_selected_index(3);
};
button_message.on_select = [this, &nav](Button&) {
this->on_set_text(nav);
};
tx_view.on_edit_frequency = [this, &nav]() {
auto new_view = nav.push<FrequencyKeypadView>(transmitter_model.target_frequency());
new_view->on_changed = [this](rf::Frequency f) {
transmitter_model.set_target_frequency(f);
};
};
tx_view.on_start = [this]() {
if (start_tx())
tx_view.set_transmitting(true);
};
tx_view.on_stop = [this]() {
tx_view.set_transmitting(false);
transmitter_model.disable();
};
}
} /* namespace ui::external_app::pocsag_tx */