2016-08-23 02:45:33 -04: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 05:27:10 -04:00
|
|
|
#include "portapack_persistent_memory.hpp"
|
2017-04-18 16:29:55 -04:00
|
|
|
|
2016-08-23 02:45:33 -04:00
|
|
|
using namespace portapack;
|
2017-02-05 15:57:20 -05:00
|
|
|
using namespace pocsag;
|
2016-08-23 02:45:33 -04:00
|
|
|
|
|
|
|
#include "string_format.hpp"
|
|
|
|
#include "utility.hpp"
|
2021-10-10 04:15:42 -04:00
|
|
|
#include "audio.hpp"
|
2016-08-23 02:45:33 -04:00
|
|
|
|
2017-04-18 16:29:55 -04:00
|
|
|
void POCSAGLogger::log_raw_data(const pocsag::POCSAGPacket& packet, const uint32_t frequency) {
|
2023-05-18 16:16:05 -04:00
|
|
|
std::string entry = "Raw: F:" + to_string_dec_uint(frequency) + "Hz " +
|
|
|
|
to_string_dec_uint(packet.bitrate()) + " Codewords:";
|
|
|
|
|
|
|
|
// Raw hex dump of all the codewords
|
|
|
|
for (size_t c = 0; c < 16; c++)
|
|
|
|
entry += to_string_hex(packet[c], 8) + " ";
|
|
|
|
|
|
|
|
log_file.write_entry(packet.timestamp(), entry);
|
2016-08-23 02:45:33 -04:00
|
|
|
}
|
|
|
|
|
2017-04-18 16:29:55 -04:00
|
|
|
void POCSAGLogger::log_decoded(
|
2023-05-18 16:16:05 -04:00
|
|
|
const pocsag::POCSAGPacket& packet,
|
|
|
|
const std::string text) {
|
|
|
|
log_file.write_entry(packet.timestamp(), text);
|
2016-08-23 08:35:14 -04:00
|
|
|
}
|
|
|
|
|
2016-08-23 02:45:33 -04:00
|
|
|
namespace ui {
|
|
|
|
|
2023-06-18 15:11:04 -04:00
|
|
|
POCSAGAppView::POCSAGAppView(NavigationView& nav)
|
|
|
|
: nav_{nav} {
|
2023-05-18 16:16:05 -04:00
|
|
|
baseband::run_image(portapack::spi_flash::image_tag_pocsag);
|
|
|
|
|
|
|
|
add_children({&rssi,
|
|
|
|
&channel,
|
|
|
|
&audio,
|
|
|
|
&field_rf_amp,
|
|
|
|
&field_lna,
|
|
|
|
&field_vga,
|
|
|
|
&field_frequency,
|
|
|
|
&check_log,
|
|
|
|
&field_volume,
|
|
|
|
&check_ignore,
|
|
|
|
&sym_ignore,
|
|
|
|
&console});
|
|
|
|
|
2023-06-14 10:54:19 -04:00
|
|
|
if (!settings_.loaded())
|
2023-06-18 15:11:04 -04:00
|
|
|
field_frequency.set_value(initial_target_frequency);
|
2023-06-14 10:54:19 -04:00
|
|
|
|
2023-08-18 15:35:41 -04:00
|
|
|
check_log.set_value(enable_logging);
|
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
receiver_model.enable();
|
|
|
|
|
2023-06-18 15:11:04 -04:00
|
|
|
// TODO: app setting instead?
|
|
|
|
uint32_t ignore_address;
|
2023-05-18 16:16:05 -04:00
|
|
|
ignore_address = persistent_memory::pocsag_ignore_address();
|
2023-06-04 15:56:46 -04:00
|
|
|
|
2023-06-18 15:11:04 -04:00
|
|
|
// TODO: is this common enough for a helper?
|
2023-05-18 16:16:05 -04:00
|
|
|
for (size_t c = 0; c < 7; c++) {
|
|
|
|
sym_ignore.set_sym(6 - c, ignore_address % 10);
|
|
|
|
ignore_address /= 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
logger = std::make_unique<POCSAGLogger>();
|
|
|
|
if (logger)
|
|
|
|
logger->append(LOG_ROOT_DIR "/POCSAG.TXT");
|
|
|
|
|
|
|
|
audio::output::start();
|
|
|
|
baseband::set_pocsag();
|
2016-08-23 02:45:33 -04:00
|
|
|
}
|
|
|
|
|
2023-06-11 14:47:13 -04:00
|
|
|
void POCSAGAppView::focus() {
|
2023-06-18 02:14:29 -04:00
|
|
|
field_frequency.focus();
|
2023-06-11 14:47:13 -04:00
|
|
|
}
|
2022-04-15 08:43:44 -04:00
|
|
|
|
2023-06-11 14:47:13 -04:00
|
|
|
POCSAGAppView::~POCSAGAppView() {
|
2023-05-18 16:16:05 -04:00
|
|
|
audio::output::stop();
|
2022-04-15 08:43:44 -04:00
|
|
|
|
2023-08-18 15:35:41 -04:00
|
|
|
// Save settings.
|
2023-05-18 16:16:05 -04:00
|
|
|
persistent_memory::set_pocsag_ignore_address(sym_ignore.value_dec_u32());
|
2023-08-18 15:35:41 -04:00
|
|
|
enable_logging = check_log.value();
|
2021-10-10 04:15:42 -04:00
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
receiver_model.disable();
|
|
|
|
baseband::shutdown();
|
2016-08-23 02:45:33 -04:00
|
|
|
}
|
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
void POCSAGAppView::on_packet(const POCSAGPacketMessage* message) {
|
|
|
|
std::string alphanum_text = "";
|
|
|
|
|
|
|
|
if (message->packet.flag() != NORMAL)
|
|
|
|
console.writeln("\n\x1B\x0CRC ERROR: " + pocsag::flag_str(message->packet.flag()));
|
|
|
|
else {
|
|
|
|
pocsag_decode_batch(message->packet, &pocsag_state);
|
|
|
|
|
2023-06-04 15:56:46 -04:00
|
|
|
if ((ignore()) && (pocsag_state.address == sym_ignore.value_dec_u32())) {
|
2023-05-18 16:16:05 -04:00
|
|
|
// Ignore (inform, but no log)
|
|
|
|
// console.write("\n\x1B\x03" + to_string_time(message->packet.timestamp()) +
|
|
|
|
// " Ignored address " + to_string_dec_uint(pocsag_state.address));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Too many errors for reliable decode
|
2023-06-04 15:56:46 -04:00
|
|
|
if ((ignore()) && (pocsag_state.errors >= 3)) {
|
2023-05-18 16:16:05 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string console_info;
|
|
|
|
const uint32_t roundVal = 50;
|
|
|
|
const uint32_t bitrate = roundVal * ((message->packet.bitrate() + (roundVal / 2)) / roundVal);
|
|
|
|
console_info = "\n" + to_string_datetime(message->packet.timestamp(), HM);
|
|
|
|
console_info += " " + to_string_dec_uint(bitrate);
|
|
|
|
console_info += " ADDR:" + to_string_dec_uint(pocsag_state.address);
|
|
|
|
console_info += " F" + to_string_dec_uint(pocsag_state.function);
|
|
|
|
|
|
|
|
// Store last received address for POCSAG TX
|
|
|
|
persistent_memory::set_pocsag_last_address(pocsag_state.address);
|
|
|
|
|
|
|
|
if (pocsag_state.out_type == ADDRESS) {
|
|
|
|
// Address only
|
|
|
|
|
|
|
|
console.write(console_info);
|
|
|
|
|
2023-06-04 15:56:46 -04:00
|
|
|
if (logger && logging()) {
|
2023-06-18 15:11:04 -04:00
|
|
|
logger->log_decoded(
|
|
|
|
message->packet, to_string_dec_uint(pocsag_state.address) +
|
|
|
|
" F" + to_string_dec_uint(pocsag_state.function) +
|
|
|
|
" Address only");
|
2023-05-18 16:16:05 -04: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);
|
|
|
|
console.write(pocsag_state.output);
|
|
|
|
|
|
|
|
last_address = pocsag_state.address;
|
|
|
|
} else {
|
|
|
|
// Message continues...
|
|
|
|
console.write(pocsag_state.output);
|
|
|
|
}
|
|
|
|
|
2023-06-04 15:56:46 -04:00
|
|
|
if (logger && logging())
|
2023-06-18 15:11:04 -04:00
|
|
|
logger->log_decoded(
|
|
|
|
message->packet, to_string_dec_uint(pocsag_state.address) +
|
|
|
|
" F" + to_string_dec_uint(pocsag_state.function) +
|
|
|
|
" Alpha: " + pocsag_state.output);
|
2023-05-18 16:16:05 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-04 15:56:46 -04:00
|
|
|
// TODO: make setting.
|
2023-05-18 16:16:05 -04:00
|
|
|
// Log raw data whatever it contains
|
2023-06-18 15:11:04 -04:00
|
|
|
/*if (logger && logging())
|
|
|
|
logger->log_raw_data(message->packet, receiver_model.target_frequency());*/
|
2016-08-23 02:45:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace ui */
|