2016-08-23 08:45:33 +02:00
|
|
|
/*
|
|
|
|
* 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 "pocsag_app.hpp"
|
|
|
|
|
|
|
|
#include "baseband_api.hpp"
|
2016-08-23 11:27:10 +02:00
|
|
|
#include "portapack_persistent_memory.hpp"
|
2017-04-18 21:29:55 +01:00
|
|
|
|
2016-08-23 08:45:33 +02:00
|
|
|
using namespace portapack;
|
2017-02-05 20:57:20 +00:00
|
|
|
using namespace pocsag;
|
2016-08-23 08:45:33 +02:00
|
|
|
|
|
|
|
#include "string_format.hpp"
|
|
|
|
#include "utility.hpp"
|
2021-10-10 09:15:42 +01:00
|
|
|
#include "audio.hpp"
|
2016-08-23 08:45:33 +02:00
|
|
|
|
2017-04-18 21:29:55 +01:00
|
|
|
void POCSAGLogger::log_raw_data(const pocsag::POCSAGPacket& packet, const uint32_t frequency) {
|
|
|
|
std::string entry = "Raw: F:" + to_string_dec_uint(frequency) + "Hz " +
|
2021-10-21 17:14:08 +01:00
|
|
|
to_string_dec_uint(packet.bitrate()) + " Codewords:";
|
2016-08-25 16:20:19 +02:00
|
|
|
|
|
|
|
// Raw hex dump of all the codewords
|
2016-08-23 08:45:33 +02:00
|
|
|
for (size_t c = 0; c < 16; c++)
|
|
|
|
entry += to_string_hex(packet[c], 8) + " ";
|
|
|
|
|
|
|
|
log_file.write_entry(packet.timestamp(), entry);
|
|
|
|
}
|
|
|
|
|
2017-04-18 21:29:55 +01:00
|
|
|
void POCSAGLogger::log_decoded(
|
2016-08-24 14:44:57 +02:00
|
|
|
const pocsag::POCSAGPacket& packet,
|
2016-08-25 16:20:19 +02:00
|
|
|
const std::string text) {
|
2016-08-24 14:44:57 +02:00
|
|
|
|
2016-08-25 16:20:19 +02:00
|
|
|
log_file.write_entry(packet.timestamp(), text);
|
2016-08-23 14:35:14 +02:00
|
|
|
}
|
|
|
|
|
2016-08-23 08:45:33 +02:00
|
|
|
namespace ui {
|
|
|
|
|
2016-08-23 11:27:10 +02:00
|
|
|
void POCSAGAppView::update_freq(rf::Frequency f) {
|
|
|
|
set_target_frequency(f);
|
2017-04-18 21:29:55 +01:00
|
|
|
portapack::persistent_memory::set_tuned_frequency(f); // Maybe not ?
|
2016-08-23 11:27:10 +02:00
|
|
|
}
|
|
|
|
|
2016-08-23 08:45:33 +02:00
|
|
|
POCSAGAppView::POCSAGAppView(NavigationView& nav) {
|
2017-04-21 06:22:31 +01:00
|
|
|
uint32_t ignore_address;
|
2017-02-06 20:32:33 +00:00
|
|
|
|
2016-08-23 08:45:33 +02:00
|
|
|
baseband::run_image(portapack::spi_flash::image_tag_pocsag);
|
|
|
|
|
2017-01-16 03:45:44 +00:00
|
|
|
add_children({
|
2016-08-23 08:45:33 +02:00
|
|
|
&rssi,
|
|
|
|
&channel,
|
2021-10-10 09:15:42 +01:00
|
|
|
&audio,
|
2016-08-23 08:45:33 +02:00
|
|
|
&field_rf_amp,
|
|
|
|
&field_lna,
|
|
|
|
&field_vga,
|
2017-07-20 16:48:59 +01:00
|
|
|
&field_frequency,
|
2017-01-16 13:36:28 +00:00
|
|
|
&check_log,
|
2021-10-10 09:15:42 +01:00
|
|
|
&field_volume,
|
2017-04-18 21:29:55 +01:00
|
|
|
&check_ignore,
|
|
|
|
&sym_ignore,
|
2016-08-23 08:45:33 +02:00
|
|
|
&console
|
2017-01-16 03:45:44 +00:00
|
|
|
});
|
2017-01-16 13:36:28 +00:00
|
|
|
|
2023-03-05 19:50:56 +00:00
|
|
|
// Set on_change before initialising the field
|
|
|
|
field_frequency.on_change = [this](rf::Frequency f) {
|
|
|
|
update_freq(f);
|
|
|
|
};
|
|
|
|
|
2022-04-15 08:43:44 -04:00
|
|
|
// load app settings
|
|
|
|
auto rc = settings.load("rx_pocsag", &app_settings);
|
|
|
|
if(rc == SETTINGS_OK) {
|
|
|
|
field_lna.set_value(app_settings.lna);
|
|
|
|
field_vga.set_value(app_settings.vga);
|
|
|
|
field_rf_amp.set_value(app_settings.rx_amp);
|
|
|
|
field_frequency.set_value(app_settings.rx_frequency);
|
|
|
|
}
|
|
|
|
else field_frequency.set_value(receiver_model.tuning_frequency());
|
|
|
|
|
2022-05-13 09:04:53 -04:00
|
|
|
receiver_model.set_modulation(ReceiverModel::Mode::NarrowbandFMAudio);
|
|
|
|
|
2017-02-06 20:32:33 +00:00
|
|
|
receiver_model.set_sampling_rate(3072000);
|
|
|
|
receiver_model.set_baseband_bandwidth(1750000);
|
|
|
|
receiver_model.enable();
|
|
|
|
|
2017-07-20 16:48:59 +01:00
|
|
|
field_frequency.set_step(receiver_model.frequency_step());
|
|
|
|
field_frequency.on_edit = [this, &nav]() {
|
|
|
|
// TODO: Provide separate modal method/scheme?
|
|
|
|
auto new_view = nav.push<FrequencyKeypadView>(receiver_model.tuning_frequency());
|
|
|
|
new_view->on_changed = [this](rf::Frequency f) {
|
|
|
|
update_freq(f);
|
|
|
|
field_frequency.set_value(f);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-01-16 13:36:28 +00:00
|
|
|
check_log.set_value(logging);
|
2017-01-17 14:27:37 +00:00
|
|
|
check_log.on_select = [this](Checkbox&, bool v) {
|
|
|
|
logging = v;
|
2017-01-16 13:36:28 +00:00
|
|
|
};
|
|
|
|
|
2021-10-10 09:15:42 +01:00
|
|
|
field_volume.set_value((receiver_model.headphone_volume() - audio::headphone::volume_range().max).decibel() + 99);
|
|
|
|
field_volume.on_change = [this](int32_t v) {
|
|
|
|
this->on_headphone_volume_changed(v);
|
|
|
|
};
|
|
|
|
|
2017-04-18 21:29:55 +01:00
|
|
|
check_ignore.set_value(ignore);
|
|
|
|
check_ignore.on_select = [this](Checkbox&, bool v) {
|
|
|
|
ignore = v;
|
|
|
|
};
|
2017-04-21 06:22:31 +01:00
|
|
|
|
|
|
|
ignore_address = persistent_memory::pocsag_ignore_address();
|
|
|
|
for (size_t c = 0; c < 7; c++) {
|
|
|
|
sym_ignore.set_sym(6 - c, ignore_address % 10);
|
|
|
|
ignore_address /= 10;
|
|
|
|
}
|
2016-08-23 08:45:33 +02:00
|
|
|
|
|
|
|
logger = std::make_unique<POCSAGLogger>();
|
2017-04-18 21:29:55 +01:00
|
|
|
if (logger)
|
2023-05-12 11:08:07 -07:00
|
|
|
logger->append(LOG_ROOT_DIR "/POCSAG.TXT");
|
2021-10-10 09:15:42 +01:00
|
|
|
|
|
|
|
audio::output::start();
|
|
|
|
audio::output::unmute();
|
|
|
|
|
2021-10-22 18:11:50 +01:00
|
|
|
baseband::set_pocsag();
|
2016-08-23 08:45:33 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 16:48:59 +01:00
|
|
|
POCSAGAppView::~POCSAGAppView() {
|
2022-04-15 08:43:44 -04:00
|
|
|
|
|
|
|
// save app settings
|
|
|
|
app_settings.rx_frequency = field_frequency.value();
|
|
|
|
settings.save("rx_pocsag", &app_settings);
|
|
|
|
|
2021-10-10 09:15:42 +01:00
|
|
|
audio::output::stop();
|
|
|
|
|
2017-04-21 06:22:31 +01:00
|
|
|
// Save ignored address
|
|
|
|
persistent_memory::set_pocsag_ignore_address(sym_ignore.value_dec_u32());
|
|
|
|
|
2017-02-05 20:57:20 +00:00
|
|
|
receiver_model.disable();
|
2016-08-23 08:45:33 +02:00
|
|
|
baseband::shutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
void POCSAGAppView::focus() {
|
2017-07-20 16:48:59 +01:00
|
|
|
field_frequency.focus();
|
2016-08-23 08:45:33 +02:00
|
|
|
}
|
|
|
|
|
2021-10-10 09:15:42 +01:00
|
|
|
void POCSAGAppView::on_headphone_volume_changed(int32_t v) {
|
|
|
|
const auto new_volume = volume_t::decibel(v - 99) + audio::headphone::volume_range().max;
|
|
|
|
receiver_model.set_headphone_volume(new_volume);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-05 20:57:20 +00:00
|
|
|
// Useless ?
|
2016-08-23 08:45:33 +02:00
|
|
|
void POCSAGAppView::set_parent_rect(const Rect new_parent_rect) {
|
|
|
|
View::set_parent_rect(new_parent_rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
void POCSAGAppView::on_packet(const POCSAGPacketMessage * message) {
|
2016-08-23 11:27:10 +02:00
|
|
|
std::string alphanum_text = "";
|
2016-08-23 08:45:33 +02:00
|
|
|
|
2017-04-18 21:29:55 +01:00
|
|
|
if (message->packet.flag() != NORMAL)
|
2018-05-15 23:35:30 +01:00
|
|
|
console.writeln("\n\x1B\x0CRC ERROR: " + pocsag::flag_str(message->packet.flag()));
|
2017-04-18 21:29:55 +01:00
|
|
|
else {
|
|
|
|
pocsag_decode_batch(message->packet, &pocsag_state);
|
|
|
|
|
2017-04-19 22:05:16 +01:00
|
|
|
if ((ignore) && (pocsag_state.address == sym_ignore.value_dec_u32())) {
|
2017-04-18 21:29:55 +01:00
|
|
|
// Ignore (inform, but no log)
|
2017-04-19 22:05:16 +01:00
|
|
|
//console.write("\n\x1B\x03" + to_string_time(message->packet.timestamp()) +
|
|
|
|
// " Ignored address " + to_string_dec_uint(pocsag_state.address));
|
2017-04-18 21:29:55 +01:00
|
|
|
return;
|
|
|
|
}
|
2021-10-10 09:15:42 +01:00
|
|
|
// Too many errors for reliable decode
|
|
|
|
if ((ignore) && (pocsag_state.errors >= 3)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-23 08:45:33 +02:00
|
|
|
|
2016-08-25 16:20:19 +02:00
|
|
|
std::string console_info;
|
2021-10-21 17:14:08 +01:00
|
|
|
const uint32_t roundVal = 50;
|
|
|
|
const uint32_t bitrate = roundVal * ((message->packet.bitrate() + (roundVal/2))/roundVal);
|
2017-08-17 12:56:47 +01:00
|
|
|
console_info = "\n" + to_string_datetime(message->packet.timestamp(), HM);
|
2021-10-21 17:14:08 +01:00
|
|
|
console_info += " " + to_string_dec_uint(bitrate);
|
2017-02-06 20:32:33 +00:00
|
|
|
console_info += " ADDR:" + to_string_dec_uint(pocsag_state.address);
|
|
|
|
console_info += " F" + to_string_dec_uint(pocsag_state.function);
|
2017-03-05 15:37:56 +00:00
|
|
|
|
2017-04-18 21:29:55 +01:00
|
|
|
// Store last received address for POCSAG TX
|
2017-04-21 06:22:31 +01:00
|
|
|
persistent_memory::set_pocsag_last_address(pocsag_state.address);
|
2017-02-06 20:32:33 +00:00
|
|
|
|
2017-02-05 20:57:20 +00:00
|
|
|
if (pocsag_state.out_type == ADDRESS) {
|
|
|
|
// Address only
|
2016-08-25 16:20:19 +02:00
|
|
|
|
2017-04-18 21:29:55 +01:00
|
|
|
console.write(console_info);
|
2016-08-25 16:20:19 +02:00
|
|
|
|
2017-04-18 21:29:55 +01:00
|
|
|
if (logger && logging) {
|
|
|
|
logger->log_decoded(message->packet, to_string_dec_uint(pocsag_state.address) +
|
|
|
|
" F" + to_string_dec_uint(pocsag_state.function) +
|
|
|
|
" Address only");
|
|
|
|
}
|
2016-08-25 16:20:19 +02:00
|
|
|
|
2017-02-05 20:57:20 +00:00
|
|
|
last_address = pocsag_state.address;
|
|
|
|
} else if (pocsag_state.out_type == MESSAGE) {
|
|
|
|
if (pocsag_state.address != last_address) {
|
|
|
|
// New message
|
|
|
|
console.writeln(console_info);
|
2017-04-18 21:29:55 +01:00
|
|
|
console.write(pocsag_state.output);
|
2017-02-05 20:57:20 +00:00
|
|
|
|
|
|
|
last_address = pocsag_state.address;
|
|
|
|
} else {
|
|
|
|
// Message continues...
|
2017-04-18 21:29:55 +01:00
|
|
|
console.write(pocsag_state.output);
|
2017-02-05 20:57:20 +00:00
|
|
|
}
|
2017-04-18 21:29:55 +01:00
|
|
|
|
|
|
|
if (logger && logging)
|
|
|
|
logger->log_decoded(message->packet, to_string_dec_uint(pocsag_state.address) +
|
|
|
|
" F" + to_string_dec_uint(pocsag_state.function) +
|
|
|
|
" Alpha: " + pocsag_state.output);
|
2017-02-06 20:32:33 +00:00
|
|
|
}
|
2016-08-23 11:27:10 +02:00
|
|
|
}
|
2017-04-18 21:29:55 +01:00
|
|
|
|
|
|
|
// Log raw data whatever it contains
|
|
|
|
if (logger && logging)
|
|
|
|
logger->log_raw_data(message->packet, target_frequency());
|
2016-08-23 08:45:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void POCSAGAppView::set_target_frequency(const uint32_t new_value) {
|
|
|
|
target_frequency_ = new_value;
|
2017-02-05 20:57:20 +00:00
|
|
|
receiver_model.set_tuning_frequency(new_value);
|
2016-08-23 08:45:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t POCSAGAppView::target_frequency() const {
|
|
|
|
return target_frequency_;
|
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace ui */
|