2017-10-05 00:38:45 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
|
|
|
* Copyright (C) 2017 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_sonde.hpp"
|
|
|
|
#include "baseband_api.hpp"
|
|
|
|
|
|
|
|
#include "portapack.hpp"
|
|
|
|
using namespace portapack;
|
|
|
|
|
|
|
|
#include "string_format.hpp"
|
|
|
|
|
2017-10-28 13:16:06 -04:00
|
|
|
void SondeLogger::on_packet(const sonde::Packet& packet) {
|
2017-10-05 00:38:45 -04:00
|
|
|
const auto formatted = packet.symbols_formatted();
|
2017-10-28 13:16:06 -04:00
|
|
|
log_file.write_entry(packet.received_at(), formatted.data);
|
|
|
|
}
|
2017-10-05 00:38:45 -04:00
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
|
|
|
|
SondeView::SondeView(NavigationView& nav) {
|
|
|
|
baseband::run_image(portapack::spi_flash::image_tag_sonde);
|
|
|
|
|
|
|
|
add_children({
|
2017-10-27 12:54:50 -04:00
|
|
|
&labels,
|
2017-10-28 13:16:06 -04:00
|
|
|
&field_frequency,
|
2017-10-05 00:38:45 -04:00
|
|
|
&field_rf_amp,
|
|
|
|
&field_lna,
|
|
|
|
&field_vga,
|
2017-10-27 12:54:50 -04:00
|
|
|
&rssi,
|
2017-10-28 13:16:06 -04:00
|
|
|
&check_log,
|
2017-10-27 12:54:50 -04:00
|
|
|
&text_signature,
|
2017-10-28 13:16:06 -04:00
|
|
|
&text_serial,
|
|
|
|
&text_voltage,
|
2017-10-27 12:54:50 -04:00
|
|
|
&geopos,
|
|
|
|
&button_see_map
|
2017-10-05 00:38:45 -04:00
|
|
|
});
|
|
|
|
|
2017-10-27 12:54:50 -04:00
|
|
|
field_frequency.set_value(target_frequency_);
|
|
|
|
field_frequency.set_step(10000);
|
2017-10-05 00:38:45 -04:00
|
|
|
field_frequency.on_change = [this](rf::Frequency f) {
|
2017-10-06 00:35:25 -04:00
|
|
|
set_target_frequency(f);
|
2017-10-05 00:38:45 -04:00
|
|
|
field_frequency.set_value(f);
|
|
|
|
};
|
|
|
|
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) {
|
2017-10-06 00:35:25 -04:00
|
|
|
set_target_frequency(f);
|
2017-10-05 00:38:45 -04:00
|
|
|
field_frequency.set_value(f);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-10-27 12:54:50 -04:00
|
|
|
geopos.set_read_only(true);
|
|
|
|
|
2017-10-28 13:16:06 -04:00
|
|
|
check_log.on_select = [this](Checkbox&, bool v) {
|
|
|
|
logging = v;
|
|
|
|
};
|
|
|
|
|
2017-10-05 00:38:45 -04:00
|
|
|
radio::enable({
|
2017-10-27 12:54:50 -04:00
|
|
|
tuning_frequency(),
|
2017-10-05 00:38:45 -04:00
|
|
|
sampling_rate,
|
|
|
|
baseband_bandwidth,
|
|
|
|
rf::Direction::Receive,
|
|
|
|
receiver_model.rf_amp(),
|
|
|
|
static_cast<int8_t>(receiver_model.lna()),
|
|
|
|
static_cast<int8_t>(receiver_model.vga()),
|
|
|
|
});
|
|
|
|
|
2017-10-27 12:54:50 -04:00
|
|
|
button_see_map.on_select = [this, &nav](Button&) {
|
|
|
|
nav.push<GeoMapView>(
|
|
|
|
"",
|
|
|
|
altitude,
|
2017-10-28 14:22:55 -04:00
|
|
|
GeoPos::alt_unit::METERS,
|
2017-10-27 12:54:50 -04:00
|
|
|
latitude,
|
|
|
|
longitude,
|
|
|
|
0);
|
|
|
|
};
|
|
|
|
|
2017-10-28 13:16:06 -04:00
|
|
|
logger = std::make_unique<SondeLogger>();
|
|
|
|
if (logger)
|
2017-10-05 00:38:45 -04:00
|
|
|
logger->append(u"sonde.txt");
|
2017-10-28 13:16:06 -04:00
|
|
|
|
2017-10-05 00:38:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
SondeView::~SondeView() {
|
|
|
|
radio::disable();
|
|
|
|
baseband::shutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SondeView::focus() {
|
|
|
|
field_vga.focus();
|
|
|
|
}
|
|
|
|
|
2017-10-27 12:54:50 -04:00
|
|
|
void SondeView::on_packet(const sonde::Packet& packet) {
|
2017-10-28 13:16:06 -04:00
|
|
|
//const auto hex_formatted = packet.symbols_formatted();
|
2017-10-06 00:35:25 -04:00
|
|
|
|
2017-11-09 21:20:44 -05:00
|
|
|
text_signature.set(packet.type_string());
|
2017-10-28 13:16:06 -04:00
|
|
|
text_serial.set(packet.serial_number());
|
2017-10-28 14:22:55 -04:00
|
|
|
text_voltage.set(unit_auto_scale(packet.battery_voltage(), 2, 3) + "V");
|
2017-10-27 12:54:50 -04:00
|
|
|
|
|
|
|
altitude = packet.GPS_altitude();
|
|
|
|
latitude = packet.GPS_latitude();
|
|
|
|
longitude = packet.GPS_longitude();
|
|
|
|
|
|
|
|
geopos.set_altitude(altitude);
|
|
|
|
geopos.set_lat(latitude);
|
|
|
|
geopos.set_lon(longitude);
|
2017-10-06 00:35:25 -04:00
|
|
|
|
2017-10-28 13:16:06 -04:00
|
|
|
if (logger && logging) {
|
2017-10-05 00:38:45 -04:00
|
|
|
logger->on_packet(packet);
|
2017-10-28 13:16:06 -04:00
|
|
|
}
|
2017-10-27 12:54:50 -04:00
|
|
|
|
2017-10-05 00:38:45 -04:00
|
|
|
/*if( packet.crc_ok() ) {
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
|
2017-10-06 00:35:25 -04:00
|
|
|
void SondeView::set_target_frequency(const uint32_t new_value) {
|
|
|
|
target_frequency_ = new_value;
|
|
|
|
radio::set_tuning_frequency(tuning_frequency());
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t SondeView::tuning_frequency() const {
|
|
|
|
return target_frequency_ - (sampling_rate / 4);
|
|
|
|
}
|
|
|
|
|
2017-10-05 00:38:45 -04:00
|
|
|
} /* namespace ui */
|