whipcalc parsing, bug fixes (#1174)

* whipcalc parsing, bug fixes
This commit is contained in:
Kyle Reed 2023-06-20 11:22:58 -07:00 committed by GitHub
parent 63b0093321
commit 909f37f89b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 63 additions and 71 deletions

View File

@ -378,14 +378,26 @@ SearchView::SearchView(
field_frequency_min.set_value(receiver_model.target_frequency() - 1000000);
field_frequency_min.set_step(100000);
field_frequency_min.updated = [this](rf::Frequency) {
on_range_changed();
field_frequency_min.on_change = [this](rf::Frequency) {
this->on_range_changed();
};
field_frequency_min.on_edit = [this, &nav]() {
auto new_view = nav.push<FrequencyKeypadView>(receiver_model.target_frequency() - 1000000);
new_view->on_changed = [this](rf::Frequency f) {
this->field_frequency_min.set_value(f);
};
};
field_frequency_max.set_value(receiver_model.target_frequency() + 1000000);
field_frequency_max.set_step(100000);
field_frequency_max.updated = [this](rf::Frequency) {
on_range_changed();
field_frequency_max.on_change = [this](rf::Frequency) {
this->on_range_changed();
};
field_frequency_max.on_edit = [this, &nav]() {
auto new_view = nav.push<FrequencyKeypadView>(receiver_model.target_frequency() + 1000000);
new_view->on_changed = [this](rf::Frequency f) {
this->field_frequency_max.set_value(f);
};
};
field_lna.set_value(receiver_model.lna());

View File

@ -26,7 +26,6 @@
#include "spectrum_color_lut.hpp"
#include "ui_receiver.hpp"
#include "ui_freq_field.hpp"
#include "ui_styles.hpp"
#include "recent_entries.hpp"
@ -147,14 +146,10 @@ class SearchView : public View {
{{1 * 8, 25 * 8}, "Accuracy +/-4.9kHz", Color::light_grey()},
{{26 * 8, 25 * 8}, "MHz", Color::light_grey()}};
RxFrequencyField field_frequency_min{
{1 * 8, 1 * 16},
nav_,
false};
RxFrequencyField field_frequency_max{
{11 * 8, 1 * 16},
nav_,
false};
FrequencyField field_frequency_min{
{1 * 8, 1 * 16}};
FrequencyField field_frequency_max{
{11 * 8, 1 * 16}};
LNAGainField field_lna{
{22 * 8, 1 * 16}};
VGAGainField field_vga{

View File

@ -23,8 +23,10 @@
#include "ui_whipcalc.hpp"
#include "ch.h"
#include "portapack.hpp"
#include "convert.hpp"
#include "event_m0.hpp"
#include "file_reader.hpp"
#include "portapack.hpp"
#include <cstring>
@ -113,28 +115,12 @@ WhipCalcView::WhipCalcView(NavigationView& nav)
&console,
&button_exit});
File antennas_file;
auto error = antennas_file.open("WHIPCALC/ANTENNAS.TXT");
if (!error.is_valid()) {
std::string line;
char one_char[1];
for (size_t pointer = 0; pointer < antennas_file.size(); pointer++) {
antennas_file.seek(pointer);
antennas_file.read(one_char, 1);
if ((int)one_char[0] >= ' ')
line += one_char[0]; // Add it to the textline
else if (one_char[0] == '\n') { // New Line
txtline_process(line); // make sense of this textline
line.clear(); // Ready for next textline
}
}
if (line.length() > 0)
txtline_process(line); // Last line had no newline at end ?
}
// Try loading antennas from file.
load_antenna_db();
if (!antenna_db.size())
add_default_antenna();
// antennas_on_memory.set(to_string_dec_int(antenna_db.size(),0) + " antennas"); //tell user
options_type.set_selected_index(2); // Quarter wave
@ -151,40 +137,42 @@ WhipCalcView::WhipCalcView(NavigationView& nav)
nav.pop();
};
field_frequency.set_value(transmitter_model.target_frequency());
update_result();
}
void ui::WhipCalcView::txtline_process(std::string& line) {
if (line.find("#") != std::string::npos)
return; // Line is just a comment
void WhipCalcView::load_antenna_db() {
File antennas_file;
auto error = antennas_file.open("/WHIPCALC/ANTENNAS.TXT");
char separator = ',';
size_t previous = 0;
uint16_t value = 0;
antenna_entry new_antenna;
size_t current = line.find(separator);
if (error)
return;
while (current != std::string::npos) {
if (!previous)
new_antenna.label.assign(line, 0, current); // antenna label
else {
value = std::stoi(line.substr(previous, current - previous));
if (!value) return; // No element length? abort antenna
new_antenna.elements.push_back(value); // Store this new element
auto reader = FileLineReader(antennas_file);
for (const auto& line : reader) {
if (line.length() == 0 || line[0] == '#')
continue; // Empty or comment line.
auto cols = split_string(line, ',');
if (cols.size() < 2)
continue; // Line doesn't have enough columns.
antenna_entry new_antenna{
std::string{cols[0]}};
// Add antenna elements.
for (auto i = 1ul; i < cols.size(); ++i) {
uint16_t length = 0;
if (parse_int(cols[i], length)) {
new_antenna.elements.push_back(length);
}
}
previous = current + 1;
current = line.find(separator, previous); // Search for next space delimiter
if (!new_antenna.elements.empty())
antenna_db.push_back(std::move(new_antenna));
}
if (!previous) return; // Not even a label ? drop this antenna!
value = std::stoi(line.substr(previous, current - previous)); // Last element
if (!value) return;
new_antenna.elements.push_back(value);
antenna_db.push_back(new_antenna); // Add this antenna
}
void ui::WhipCalcView::add_default_antenna() {
void WhipCalcView::add_default_antenna() {
antenna_db.push_back({"ANT500", {185, 315, 450, 586, 724, 862}}); // store a default ant500
}
} // namespace ui

View File

@ -51,8 +51,7 @@ class WhipCalcView : public View {
NavigationView& nav_;
std::vector<antenna_entry> antenna_db{};
void update_result();
uint16_t string_to_number(std::string);
void txtline_process(std::string&);
void load_antenna_db();
void add_default_antenna();
Labels labels{
@ -63,8 +62,7 @@ class WhipCalcView : public View {
TxFrequencyField field_frequency{
{13 * 8, 1 * 16},
nav_,
false};
nav_};
OptionsField options_type{
{13 * 8, 2 * 16},

View File

@ -49,9 +49,8 @@ Optional<File::Error> write_metadata_file(const fs::path& path, capture_metadata
if (error)
return error;
// TODO: Why does this divide by 8? Leaving as is for back-compat, but it's odd.
error = f.write_line(std::string{sample_rate_name} + "=" +
to_string_dec_uint(metadata.sample_rate / 8));
to_string_dec_uint(metadata.sample_rate));
if (error)
return error;

View File

@ -40,15 +40,14 @@ class BoundFrequencyField : public FrequencyField {
public:
decltype(FrequencyField::on_change) updated{};
BoundFrequencyField(Point parent_pos, NavigationView& nav, bool update_model = true)
BoundFrequencyField(Point parent_pos, NavigationView& nav)
: FrequencyField(parent_pos) {
// NB: There is no frequency_step on the tx_model.
set_step(portapack::receiver_model.frequency_step());
set_value(model->target_frequency());
on_change = [this, update_model](rf::Frequency f) {
if (update_model)
model->set_target_frequency(f);
on_change = [this](rf::Frequency f) {
model->set_target_frequency(f);
if (updated)
updated(f);
};

View File

@ -197,7 +197,8 @@ void RecordView::start() {
case FileType::RawS16: {
const auto metadata_file_error =
write_metadata_file(get_metadata_path(base_path),
{receiver_model.target_frequency(), sampling_rate});
{receiver_model.target_frequency(), sampling_rate / 8});
// Not sure why sample_rate is div. 8, but stored value matches rate settings.
if (metadata_file_error.is_valid()) {
handle_error(metadata_file_error.value());
return;
@ -266,7 +267,7 @@ void RecordView::update_status_display() {
if (sampling_rate) {
const auto space_info = std::filesystem::space(u"");
const uint32_t bytes_per_second = file_type == FileType::WAV ? (sampling_rate * 2) : (sampling_rate / 8 * 4);
const uint32_t bytes_per_second = file_type == FileType::WAV ? (sampling_rate * 2) : (sampling_rate / 8 * 4); // TODO: Why 8/4??
const uint32_t available_seconds = space_info.free / bytes_per_second;
const uint32_t seconds = available_seconds % 60;
const uint32_t available_minutes = available_seconds / 60;