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"
|
|
|
|
|
2017-02-05 15:57:20 -05:00
|
|
|
#include "audio.hpp"
|
2016-08-23 02:45:33 -04:00
|
|
|
#include "portapack.hpp"
|
2016-08-23 05:27:10 -04:00
|
|
|
#include "portapack_persistent_memory.hpp"
|
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
|
|
|
|
2017-02-05 15:57:20 -05:00
|
|
|
#include "pocsag.hpp"
|
2016-08-23 02:45:33 -04:00
|
|
|
#include "string_format.hpp"
|
|
|
|
|
|
|
|
#include "utility.hpp"
|
|
|
|
|
2016-08-23 05:27:10 -04:00
|
|
|
void POCSAGLogger::on_packet(const pocsag::POCSAGPacket& packet, const uint32_t frequency) {
|
2017-02-06 15:32:33 -05:00
|
|
|
std::string entry = to_string_dec_uint(frequency) + "Hz " + pocsag::bitrate_str(packet.bitrate()) + " RAW: ";
|
2016-08-25 10:20:19 -04:00
|
|
|
|
|
|
|
// Raw hex dump of all the codewords
|
2016-08-23 02:45:33 -04:00
|
|
|
for (size_t c = 0; c < 16; c++)
|
|
|
|
entry += to_string_hex(packet[c], 8) + " ";
|
|
|
|
|
|
|
|
log_file.write_entry(packet.timestamp(), entry);
|
|
|
|
}
|
|
|
|
|
2016-08-24 08:44:57 -04:00
|
|
|
void POCSAGLogger::on_decoded(
|
|
|
|
const pocsag::POCSAGPacket& packet,
|
2016-08-25 10:20:19 -04:00
|
|
|
const std::string text) {
|
2016-08-24 08:44:57 -04:00
|
|
|
|
2016-08-25 10:20:19 -04:00
|
|
|
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 {
|
|
|
|
|
2016-08-23 05:27:10 -04:00
|
|
|
void POCSAGAppView::update_freq(rf::Frequency f) {
|
2017-02-06 15:32:33 -05:00
|
|
|
options_freq.set_selected_index(0); // "Entered"
|
2016-08-23 05:27:10 -04:00
|
|
|
set_target_frequency(f);
|
|
|
|
|
|
|
|
portapack::persistent_memory::set_tuned_frequency(f); // Maybe not ?
|
|
|
|
|
2016-08-23 08:35:14 -04:00
|
|
|
auto mhz = to_string_dec_int(f / 1000000, 4);
|
2016-08-23 05:27:10 -04:00
|
|
|
auto hz100 = to_string_dec_int((f / 100) % 10000, 4, '0');
|
|
|
|
|
2017-02-06 15:32:33 -05:00
|
|
|
this->button_setfreq.set_text(mhz + "." + hz100);
|
2016-08-23 05:27:10 -04:00
|
|
|
}
|
|
|
|
|
2016-08-23 02:45:33 -04:00
|
|
|
POCSAGAppView::POCSAGAppView(NavigationView& nav) {
|
2017-02-06 15:32:33 -05:00
|
|
|
|
2016-08-23 02:45:33 -04:00
|
|
|
baseband::run_image(portapack::spi_flash::image_tag_pocsag);
|
|
|
|
|
2017-01-15 22:45:44 -05:00
|
|
|
add_children({
|
2016-08-23 02:45:33 -04:00
|
|
|
&rssi,
|
|
|
|
&channel,
|
2016-08-23 05:27:10 -04:00
|
|
|
&options_freq,
|
2016-08-23 02:45:33 -04:00
|
|
|
&field_rf_amp,
|
|
|
|
&field_lna,
|
|
|
|
&field_vga,
|
2017-01-16 08:36:28 -05:00
|
|
|
&button_setfreq,
|
|
|
|
&options_bitrate,
|
|
|
|
&check_log,
|
2016-08-23 02:45:33 -04:00
|
|
|
&console
|
2017-01-15 22:45:44 -05:00
|
|
|
});
|
2017-01-16 08:36:28 -05:00
|
|
|
|
2017-02-06 15:32:33 -05:00
|
|
|
receiver_model.set_sampling_rate(3072000);
|
|
|
|
receiver_model.set_baseband_bandwidth(1750000);
|
|
|
|
receiver_model.enable();
|
|
|
|
|
2017-01-16 08:36:28 -05:00
|
|
|
check_log.set_value(logging);
|
2017-01-17 09:27:37 -05:00
|
|
|
check_log.on_select = [this](Checkbox&, bool v) {
|
|
|
|
logging = v;
|
2017-01-16 08:36:28 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
options_bitrate.on_change = [this](size_t, OptionsField::value_t v) {
|
|
|
|
this->on_bitrate_changed(v);
|
|
|
|
};
|
2017-02-06 15:32:33 -05:00
|
|
|
options_bitrate.set_selected_index(1); // 1200bps
|
2016-08-23 02:45:33 -04:00
|
|
|
|
2016-08-23 05:27:10 -04:00
|
|
|
options_freq.on_change = [this](size_t, OptionsField::value_t v) {
|
2016-08-23 02:45:33 -04:00
|
|
|
this->on_band_changed(v);
|
|
|
|
};
|
2016-08-23 05:27:10 -04:00
|
|
|
options_freq.set_by_value(target_frequency());
|
|
|
|
|
|
|
|
button_setfreq.on_select = [this,&nav](Button&) {
|
|
|
|
auto new_view = nav.push<FrequencyKeypadView>(target_frequency_);
|
|
|
|
new_view->on_changed = [this](rf::Frequency f) {
|
|
|
|
update_freq(f);
|
|
|
|
};
|
|
|
|
};
|
2016-08-23 02:45:33 -04:00
|
|
|
|
|
|
|
logger = std::make_unique<POCSAGLogger>();
|
2016-08-25 10:20:19 -04:00
|
|
|
if (logger) logger->append("pocsag.txt");
|
2016-08-23 02:45:33 -04:00
|
|
|
|
2017-02-06 15:32:33 -05:00
|
|
|
/*const auto new_volume = volume_t::decibel(60 - 99) + audio::headphone::volume_range().max;
|
2017-02-05 15:57:20 -05:00
|
|
|
receiver_model.set_headphone_volume(new_volume);
|
2017-02-06 15:32:33 -05:00
|
|
|
audio::output::start();*/
|
2016-08-23 02:45:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
POCSAGAppView::~POCSAGAppView() {
|
2017-02-06 15:32:33 -05:00
|
|
|
//audio::output::stop();
|
2017-02-05 15:57:20 -05:00
|
|
|
receiver_model.disable();
|
2016-08-23 02:45:33 -04:00
|
|
|
baseband::shutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
void POCSAGAppView::focus() {
|
2016-08-23 05:27:10 -04:00
|
|
|
options_freq.focus();
|
2016-08-23 02:45:33 -04:00
|
|
|
}
|
|
|
|
|
2017-02-05 15:57:20 -05:00
|
|
|
// Useless ?
|
2016-08-23 02:45:33 -04: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 05:27:10 -04:00
|
|
|
std::string alphanum_text = "";
|
2016-08-23 02:45:33 -04:00
|
|
|
|
2017-02-06 15:32:33 -05:00
|
|
|
// Log raw data whatever it contains
|
|
|
|
if (logger && logging)
|
|
|
|
logger->on_packet(message->packet, target_frequency());
|
2017-02-05 15:57:20 -05:00
|
|
|
|
|
|
|
if (message->packet.flag() != NORMAL) {
|
|
|
|
console.writeln(
|
|
|
|
"RX ERROR: " + pocsag::flag_str(message->packet.flag()) +
|
|
|
|
" Codewords: " + to_string_dec_uint(message->packet[0])
|
|
|
|
);
|
2016-08-23 02:45:33 -04:00
|
|
|
}
|
2016-08-24 08:44:57 -04:00
|
|
|
|
2017-02-06 15:32:33 -05:00
|
|
|
bool result = pocsag_decode_batch(message->packet, &pocsag_state);
|
2016-08-23 02:45:33 -04:00
|
|
|
|
2017-02-05 15:57:20 -05:00
|
|
|
if (result) {
|
2016-08-25 10:20:19 -04:00
|
|
|
std::string console_info;
|
|
|
|
|
2017-02-06 15:32:33 -05:00
|
|
|
console_info = to_string_time(message->packet.timestamp()) + " ";
|
2017-04-14 05:54:35 -04:00
|
|
|
console_info += "B:" + pocsag::bitrate_str(message->packet.bitrate()); // "B:" caractere add for more visibility
|
2017-02-06 15:32:33 -05:00
|
|
|
console_info += " ADDR:" + to_string_dec_uint(pocsag_state.address);
|
|
|
|
console_info += " F" + to_string_dec_uint(pocsag_state.function);
|
2017-03-05 10:37:56 -05:00
|
|
|
|
|
|
|
portapack::persistent_memory::set_pocsag_address(pocsag_state.address);
|
2017-02-06 15:32:33 -05:00
|
|
|
|
2017-02-05 15:57:20 -05:00
|
|
|
if (pocsag_state.out_type == ADDRESS) {
|
|
|
|
// Address only
|
2016-08-25 10:20:19 -04:00
|
|
|
|
|
|
|
console.writeln(console_info);
|
|
|
|
|
2017-02-06 15:32:33 -05:00
|
|
|
if (logger && logging)
|
|
|
|
logger->on_decoded(message->packet, console_info);
|
2016-08-25 10:20:19 -04:00
|
|
|
|
2017-02-05 15:57:20 -05: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.writeln("Alpha:" + pocsag_state.output);
|
|
|
|
|
2017-02-06 15:32:33 -05:00
|
|
|
if (logger && logging) {
|
|
|
|
logger->on_decoded(message->packet, console_info);
|
|
|
|
logger->on_decoded(message->packet, pocsag_state.output);
|
|
|
|
}
|
2017-02-05 15:57:20 -05:00
|
|
|
|
|
|
|
last_address = pocsag_state.address;
|
|
|
|
} else {
|
|
|
|
// Message continues...
|
2017-02-06 15:32:33 -05:00
|
|
|
console.writeln(pocsag_state.output);
|
|
|
|
|
|
|
|
if (logger && logging)
|
|
|
|
logger->on_decoded(message->packet, pocsag_state.output);
|
2017-02-05 15:57:20 -05:00
|
|
|
}
|
2017-02-06 15:32:33 -05:00
|
|
|
}
|
2016-08-23 05:27:10 -04:00
|
|
|
}
|
2016-08-23 02:45:33 -04:00
|
|
|
}
|
|
|
|
|
2017-01-16 08:36:28 -05:00
|
|
|
void POCSAGAppView::on_bitrate_changed(const uint32_t new_bitrate) {
|
2017-02-07 14:54:18 -05:00
|
|
|
baseband::set_pocsag(pocsag_bitrates[new_bitrate]);
|
2017-01-16 08:36:28 -05:00
|
|
|
}
|
|
|
|
|
2016-08-23 02:45:33 -04:00
|
|
|
void POCSAGAppView::on_band_changed(const uint32_t new_band_frequency) {
|
2016-08-23 05:27:10 -04:00
|
|
|
if (new_band_frequency) set_target_frequency(new_band_frequency);
|
2016-08-23 02:45:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void POCSAGAppView::set_target_frequency(const uint32_t new_value) {
|
|
|
|
target_frequency_ = new_value;
|
2017-02-05 15:57:20 -05:00
|
|
|
receiver_model.set_tuning_frequency(new_value);
|
2016-08-23 02:45:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t POCSAGAppView::target_frequency() const {
|
|
|
|
return target_frequency_;
|
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace ui */
|