Simplified LCR code a bit

Split modem into modem and serializer
Frequency string formatter
This commit is contained in:
furrtek 2017-04-24 18:15:57 +01:00
parent 90feadd9f5
commit 8c680ff893
18 changed files with 198 additions and 125 deletions

View file

@ -21,8 +21,7 @@
*/
#include "ui_lcr.hpp"
#include "ui_afsksetup.hpp"
#include "ui_debug.hpp"
#include "ui_modemsetup.hpp"
#include "modems.hpp"
#include "lcr.hpp"
@ -35,7 +34,6 @@
#include <stdio.h>
using namespace portapack;
using namespace modems;
namespace ui {
@ -74,8 +72,8 @@ void LCRView::paint(Painter& painter) {
button_setrgsb.set_text(rgsb);
// Recap: freq @ bps
final_str = to_string_dec_int(persistent_memory::tuned_frequency() / 1000, 6);
// Recap: frequency @ baudrate
final_str = to_string_short_freq(persistent_memory::tuned_frequency(), 3);
final_str += '@';
final_str += to_string_dec_int(persistent_memory::modem_baudrate(), 4);
final_str += "bps ";
@ -99,13 +97,13 @@ void LCRView::update_progress() {
text_status.set(" "); // Clear
progress_str = to_string_dec_uint(repeat_index) + "/" + to_string_dec_uint(persistent_memory::modem_repeat());
progress_str += " " + to_string_dec_uint(scan_index + 1) + "/" + to_string_dec_uint(scan_count);
if (tx_mode == SINGLE) {
progress_str = to_string_dec_uint(repeat_index) + "/" + to_string_dec_uint(persistent_memory::modem_repeat());
text_status.set(progress_str);
progress.set_value(repeat_index);
} else if (tx_mode == SCAN) {
progress_str = to_string_dec_uint(repeat_index) + "/" + to_string_dec_uint(persistent_memory::modem_repeat());
progress_str += " " + to_string_dec_uint(scan_index + 1) + "/" + to_string_dec_uint(scan_count);
text_status.set(progress_str);
progress.set_value(scan_progress);
} else {
@ -115,34 +113,30 @@ void LCRView::update_progress() {
}
void LCRView::on_txdone(int n) {
if (n > 0) {
if (n) {
// Repeating...
repeat_index = n + 1;
if (tx_mode == SCAN) {
if (tx_mode == SCAN)
scan_progress++;
update_progress();
} else {
update_progress();
}
} else {
// Done transmitting
if ((tx_mode == SCAN) && (scan_index < (scan_count - 1))) {
transmitter_model.disable();
// Next address
scan_index++;
rgsb = scan_list[options_scanlist.selected_index()].addresses[scan_index];
scan_progress++;
repeat_index = 1;
update_progress();
start_tx(true);
} else {
transmitter_model.disable();
tx_mode = IDLE;
update_progress();
button_scan.set_style(&style_val);
button_scan.set_text("SCAN");
}
}
}
update_progress();
}
void LCRView::start_tx(const bool scan) {
@ -157,13 +151,15 @@ void LCRView::start_tx(const bool scan) {
scan_progress = 1;
repeat_index = 1;
tx_mode = SCAN;
rgsb = scan_list[options_scanlist.selected_index()].addresses[0];
progress.set_max(scan_count * repeats);
update_progress();
}
rgsb = scan_list[options_scanlist.selected_index()].addresses[scan_index];
} else {
tx_mode = SINGLE;
repeat_index = 1;
scan_count = 1;
scan_index = 0;
progress.set_max(repeats);
update_progress();
}
@ -177,7 +173,7 @@ void LCRView::start_tx(const bool scan) {
transmitter_model.set_baseband_bandwidth(1750000);
transmitter_model.enable();
memcpy(shared_memory.bb_data.data, lcr_message_data, 300);
memcpy(shared_memory.bb_data.data, lcr_message_data, sizeof(lcr_message_data));
baseband::set_afsk_data(
1536000 / persistent_memory::modem_baudrate(),
@ -185,7 +181,7 @@ void LCRView::start_tx(const bool scan) {
persistent_memory::afsk_space_freq(),
repeats,
persistent_memory::modem_bw(),
modems::symbol_count()
serializer::symbol_count()
);
}
@ -201,15 +197,14 @@ LCRView::LCRView(NavigationView& nav) {
rgsb = scan_list[0].addresses[0];
add_children({
&labels,
&text_recap,
&options_ec,
&button_setrgsb,
&button_txsetup,
&text_status,
&progress,
&button_lcrdebug,
&button_transmit,
&text_scanlist,
&options_scanlist,
&button_scan,
&button_clear
@ -222,13 +217,12 @@ LCRView::LCRView(NavigationView& nav) {
};
size_t n = 0;
for(auto& button : buttons) {
for (auto& button : buttons) {
button.on_select = button_setam_fn;
button.id = n;
label = "AM " + to_string_dec_uint(n + 1, 1);;
button.set_text(label);
button.set_text("AM " + to_string_dec_uint(n + 1, 1));
button.set_parent_rect({
static_cast<Coord>(48),
static_cast<Coord>(40),
static_cast<Coord>(n * 32 + 64),
48, 24
});
@ -237,9 +231,9 @@ LCRView::LCRView(NavigationView& nav) {
}
n = 0;
for(auto& checkbox : checkboxes) {
for (auto& checkbox : checkboxes) {
checkbox.set_parent_rect({
static_cast<Coord>(16),
static_cast<Coord>(8),
static_cast<Coord>(n * 32 + 64),
48, 24
});
@ -249,11 +243,11 @@ LCRView::LCRView(NavigationView& nav) {
}
n = 0;
for(auto& rectangle : rectangles) {
for (auto& rectangle : rectangles) {
rectangle.set_parent_rect({
static_cast<Coord>(104 - 2),
static_cast<Coord>(98),
static_cast<Coord>(n * 32 + 68 - 2),
56 + 4, 16 + 4
64, 20
});
rectangle.set_color(ui::Color::grey());
rectangle.set_outline(true);
@ -273,15 +267,12 @@ LCRView::LCRView(NavigationView& nav) {
};
button_txsetup.on_select = [&nav](Button&) {
nav.push<AFSKSetupView>();
};
button_lcrdebug.on_select = [this, &nav](Button&) {
nav.push<DebugLCRView>(lcr::generate_message(rgsb, parse_litterals(), options_ec.selected_index()));
nav.push<ModemSetupView>();
};
button_transmit.on_select = [this](Button&) {
if (tx_mode == IDLE) start_tx(false);
if (tx_mode == IDLE)
start_tx(false);
};
button_scan.on_select = [this](Button&) {
@ -303,7 +294,7 @@ LCRView::LCRView(NavigationView& nav) {
};
button_clear.on_select = [this, &nav](Button&) {
uint8_t n;
size_t n;
if (tx_mode == IDLE) {
options_ec.set_selected_index(0); // Auto