mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-10-21 15:18:48 +00:00
Fixed LCR transmit and AFSK baseband module
This commit is contained in:
@@ -32,7 +32,6 @@
|
||||
#include "hackrf_gpio.hpp"
|
||||
#include "portapack.hpp"
|
||||
#include "event_m0.hpp"
|
||||
#include "radio.hpp"
|
||||
|
||||
#include "string_format.hpp"
|
||||
|
||||
@@ -52,16 +51,19 @@ void LCRView::focus() {
|
||||
}
|
||||
|
||||
LCRView::~LCRView() {
|
||||
radio::disable();
|
||||
transmitter_model.disable();
|
||||
baseband::shutdown();
|
||||
}
|
||||
|
||||
void LCRView::make_frame() {
|
||||
void LCRView::generate_message() {
|
||||
// Modem sync and SOM
|
||||
const char lcr_init[8] = { 127, 127, 127, 127, 127, 127, 127, 15 };
|
||||
// Eclairage (Auto, Jour, Nuit)
|
||||
const char ec_lut[3][2] = { { 'A', 0x00 },
|
||||
{ 'J', 0x00 },
|
||||
{ 'N', 0x00 }
|
||||
};
|
||||
char eom[3] = { 3, 0, 0 }; // EOM and space for checksum
|
||||
uint8_t i, pm;
|
||||
{ 'N', 0x00 } };
|
||||
char eom[3] = { 3, 0, 0 }; // EOM and space for checksum
|
||||
uint8_t i, pm, bit;
|
||||
uint16_t dp;
|
||||
uint8_t cp, pp, cur_byte, new_byte;
|
||||
|
||||
@@ -74,63 +76,56 @@ void LCRView::make_frame() {
|
||||
}
|
||||
}
|
||||
|
||||
// Make LCR frame
|
||||
memset(lcrframe, 0, 256);
|
||||
lcrframe[0] = 127; // Modem sync
|
||||
lcrframe[1] = 127;
|
||||
lcrframe[2] = 127;
|
||||
lcrframe[3] = 127;
|
||||
lcrframe[4] = 127;
|
||||
lcrframe[5] = 127;
|
||||
lcrframe[6] = 127;
|
||||
lcrframe[7] = 15; // SOM
|
||||
// Compose LCR message
|
||||
memset(lcr_message, 0, 256);
|
||||
memcpy(lcr_message, lcr_init, 8);
|
||||
|
||||
strcat(lcrframe, rgsb);
|
||||
strcat(lcrframe, "PA ");
|
||||
strcat(lcr_message, rgsb); // Address
|
||||
strcat(lcr_message, "PA ");
|
||||
|
||||
if (checkbox_am_a.value() == true) {
|
||||
strcat(lcrframe, "AM=1 AF=\"");
|
||||
strcat(lcrframe, litteral[0]);
|
||||
strcat(lcrframe, "\" CL=0 ");
|
||||
strcat(lcr_message, "AM=1 AF=\"");
|
||||
strcat(lcr_message, litteral[0]);
|
||||
strcat(lcr_message, "\" CL=0 ");
|
||||
}
|
||||
if (checkbox_am_b.value() == true) {
|
||||
strcat(lcrframe, "AM=2 AF=\"");
|
||||
strcat(lcrframe, litteral[1]);
|
||||
strcat(lcrframe, "\" CL=0 ");
|
||||
strcat(lcr_message, "AM=2 AF=\"");
|
||||
strcat(lcr_message, litteral[1]);
|
||||
strcat(lcr_message, "\" CL=0 ");
|
||||
}
|
||||
if (checkbox_am_c.value() == true) {
|
||||
strcat(lcrframe, "AM=3 AF=\"");
|
||||
strcat(lcrframe, litteral[2]);
|
||||
strcat(lcrframe, "\" CL=0 ");
|
||||
strcat(lcr_message, "AM=3 AF=\"");
|
||||
strcat(lcr_message, litteral[2]);
|
||||
strcat(lcr_message, "\" CL=0 ");
|
||||
}
|
||||
if (checkbox_am_d.value() == true) {
|
||||
strcat(lcrframe, "AM=4 AF=\"");
|
||||
strcat(lcrframe, litteral[3]);
|
||||
strcat(lcrframe, "\" CL=0 ");
|
||||
strcat(lcr_message, "AM=4 AF=\"");
|
||||
strcat(lcr_message, litteral[3]);
|
||||
strcat(lcr_message, "\" CL=0 ");
|
||||
}
|
||||
if (checkbox_am_e.value() == true) {
|
||||
strcat(lcrframe, "AM=5 AF=\"");
|
||||
strcat(lcrframe, litteral[4]);
|
||||
strcat(lcrframe, "\" CL=0 ");
|
||||
strcat(lcr_message, "AM=5 AF=\"");
|
||||
strcat(lcr_message, litteral[4]);
|
||||
strcat(lcr_message, "\" CL=0 ");
|
||||
}
|
||||
strcat(lcrframe, "EC=");
|
||||
strcat(lcrframe, ec_lut[options_ec.selected_index()]);
|
||||
strcat(lcrframe, " SAB=0");
|
||||
strcat(lcr_message, "EC=");
|
||||
strcat(lcr_message, ec_lut[options_ec.selected_index()]);
|
||||
strcat(lcr_message, " SAB=0");
|
||||
|
||||
memcpy(lcrstring, lcrframe, 256);
|
||||
memcpy(lcr_string, lcr_message, 256);
|
||||
|
||||
// Checksum
|
||||
checksum = 0;
|
||||
i = 7; // Skip modem sync
|
||||
while (lcrframe[i]) {
|
||||
checksum ^= lcrframe[i];
|
||||
while (lcr_message[i]) {
|
||||
checksum ^= lcr_message[i];
|
||||
i++;
|
||||
}
|
||||
checksum ^= eom[0]; // EOM char
|
||||
checksum &= 0x7F;
|
||||
checksum &= 0x7F; // Trim
|
||||
eom[1] = checksum;
|
||||
|
||||
strcat(lcrframe, eom);
|
||||
strcat(lcr_message, eom);
|
||||
|
||||
//if (persistent_memory::afsk_config() & 2)
|
||||
pm = 0; // Even parity
|
||||
@@ -138,30 +133,31 @@ void LCRView::make_frame() {
|
||||
// pm = 1; // Odd parity
|
||||
|
||||
if (!(persistent_memory::afsk_config() & 8)) {
|
||||
// Clear format
|
||||
for (dp = 0; dp < strlen(lcrframe); dp++) {
|
||||
// Normal format
|
||||
for (dp = 0; dp < strlen(lcr_message); dp++) {
|
||||
pp = pm;
|
||||
new_byte = 0;
|
||||
cur_byte = lcrframe[dp];
|
||||
cur_byte = lcr_message[dp];
|
||||
for (cp = 0; cp < 7; cp++) {
|
||||
if ((cur_byte >> cp) & 1) pp++;
|
||||
new_byte |= (((cur_byte >> cp) & 1) << (7 - cp));
|
||||
bit = (cur_byte >> cp) & 1;
|
||||
pp += bit;
|
||||
new_byte |= (bit << (7 - cp));
|
||||
}
|
||||
lcrframe_f[dp] = new_byte | (pp & 1);
|
||||
lcr_message_data[dp] = new_byte | (pp & 1);
|
||||
}
|
||||
lcrframe_f[dp] = 0;
|
||||
lcr_message_data[dp] = 0;
|
||||
} else {
|
||||
// Alt format
|
||||
for (dp = 0; dp < strlen(lcrframe); dp++) {
|
||||
for (dp = 0; dp < strlen(lcr_message); dp++) {
|
||||
pp = pm;
|
||||
cur_byte = alt_lookup[lcrframe[dp]];
|
||||
cur_byte = alt_lookup[(uint8_t)lcr_message[dp] & 0x7F];
|
||||
for (cp = 0; cp < 8; cp++) {
|
||||
if ((cur_byte >> cp) & 1) pp++;
|
||||
}
|
||||
lcrframe_f[dp * 2] = cur_byte;
|
||||
lcrframe_f[(dp * 2) + 1] = pp & 1;
|
||||
lcr_message_data[dp * 2] = cur_byte;
|
||||
lcr_message_data[(dp * 2) + 1] = pp & 1;
|
||||
}
|
||||
lcrframe_f[dp * 2] = 0;
|
||||
lcr_message_data[dp * 2] = 0;
|
||||
}
|
||||
|
||||
//if (persistent_memory::afsk_config() & 1) {
|
||||
@@ -169,13 +165,13 @@ void LCRView::make_frame() {
|
||||
// See above
|
||||
/*} else {
|
||||
// MSB first
|
||||
for (dp=0;dp<strlen(lcrframe);dp++) {
|
||||
for (dp=0;dp<strlen(lcr_message);dp++) {
|
||||
pp = pm;
|
||||
cur_byte = lcrframe[dp];
|
||||
cur_byte = lcr_message[dp];
|
||||
for (cp=0;cp<7;cp++) {
|
||||
if ((cur_byte>>cp)&1) pp++;
|
||||
}
|
||||
lcrframe_f[dp] = (cur_byte<<1)|(pp&1);
|
||||
lcr_message_data[dp] = (cur_byte<<1)|(pp&1);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
@@ -206,14 +202,17 @@ void LCRView::paint(Painter& painter) {
|
||||
|
||||
button_setrgsb.set_text(rgsb);
|
||||
|
||||
// Recap: tx freq @ bps / ALT
|
||||
// Recap: freq @ bps / ALT
|
||||
auto fstr = to_string_dec_int(portapack::persistent_memory::tuned_frequency() / 1000, 6);
|
||||
auto bstr = to_string_dec_int(portapack::persistent_memory::afsk_bitrate(), 4);
|
||||
strcpy(finalstr, fstr.c_str());
|
||||
strcat(finalstr, "@");
|
||||
strcat(finalstr, bstr.c_str());
|
||||
strcat(finalstr, "bps");
|
||||
if (portapack::persistent_memory::afsk_config() & 8) strcat(finalstr, " ALT");
|
||||
if (portapack::persistent_memory::afsk_config() & 8)
|
||||
strcat(finalstr, " ALT");
|
||||
else
|
||||
strcat(finalstr, " NRM");
|
||||
text_recap.set(finalstr);
|
||||
}
|
||||
|
||||
@@ -226,9 +225,8 @@ void LCRView::on_txdone(int n) {
|
||||
strcat(str, rgsb);
|
||||
text_status.set(str);
|
||||
progress.set_value(0);
|
||||
radio::disable();
|
||||
txing = false;
|
||||
scanning = false;
|
||||
transmitter_model.disable();
|
||||
tx_mode = IDLE;
|
||||
abort_scan = false;
|
||||
button_scan.set_style(&style_val);
|
||||
button_scan.set_text("SCAN");
|
||||
@@ -236,8 +234,8 @@ void LCRView::on_txdone(int n) {
|
||||
}
|
||||
|
||||
if (n > 0) {
|
||||
if (scanning) {
|
||||
scan_progress += 0.555f;
|
||||
if (tx_mode == SCAN) {
|
||||
scan_progress += 0.555f; // 100/(37*5)
|
||||
progress.set_value(scan_progress);
|
||||
} else {
|
||||
text_status.set(" ");
|
||||
@@ -247,71 +245,52 @@ void LCRView::on_txdone(int n) {
|
||||
progress.set_value((6 - n) * 20);
|
||||
}
|
||||
} else {
|
||||
if (scanning && (scan_index < 36)) {
|
||||
radio::disable();
|
||||
if ((tx_mode == SCAN) && (scan_index < LCR_SCAN_COUNT)) {
|
||||
transmitter_model.disable();
|
||||
|
||||
// Next address
|
||||
strcpy(rgsb, RGSB_list[scan_index]);
|
||||
make_frame();
|
||||
|
||||
memset(shared_memory.radio_data, 0, 256);
|
||||
memcpy(shared_memory.radio_data, lcrframe_f, 256);
|
||||
shared_memory.afsk_transmit_done = false;
|
||||
shared_memory.afsk_repeat = 5;
|
||||
generate_message();
|
||||
|
||||
text_status.set(" ");
|
||||
strcpy(str, to_string_dec_int(scan_index).c_str());
|
||||
strcat(str, "/36");
|
||||
strcat(str, "/");
|
||||
strcat(str, to_string_dec_uint(LCR_SCAN_COUNT).c_str());
|
||||
text_status.set(str);
|
||||
scan_progress += 0.694f;
|
||||
progress.set_value(scan_progress);
|
||||
|
||||
scan_index++;
|
||||
radio::disable();
|
||||
// start_tx ?
|
||||
} else {
|
||||
text_status.set("Ready ");
|
||||
progress.set_value(0);
|
||||
radio::disable();
|
||||
txing = false;
|
||||
scanning = false;
|
||||
transmitter_model.disable();
|
||||
tx_mode = IDLE;
|
||||
button_scan.set_style(&style_val);
|
||||
button_scan.set_text("SCAN");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LCRView::start_tx() {
|
||||
void LCRView::start_tx(const bool scan) {
|
||||
char str[16];
|
||||
bool afsk_alt_format;
|
||||
|
||||
if (scanning) {
|
||||
if (scan) {
|
||||
tx_mode = SCAN;
|
||||
scan_index = 0;
|
||||
strcpy(rgsb, RGSB_list[0]);
|
||||
} else {
|
||||
tx_mode = SINGLE;
|
||||
}
|
||||
|
||||
make_frame();
|
||||
|
||||
lcr_radio_config.tuning_frequency = portapack::persistent_memory::tuned_frequency();
|
||||
|
||||
shared_memory.afsk_samples_per_bit = 228000 / portapack::persistent_memory::afsk_bitrate();
|
||||
shared_memory.afsk_phase_inc_mark = portapack::persistent_memory::afsk_mark_freq() * (0x40000 * 256) / 2280;
|
||||
shared_memory.afsk_phase_inc_space = portapack::persistent_memory::afsk_space_freq() * (0x40000 * 256) / 2280;
|
||||
generate_message();
|
||||
|
||||
if (portapack::persistent_memory::afsk_config() & 8)
|
||||
shared_memory.afsk_alt_format = true;
|
||||
else
|
||||
shared_memory.afsk_alt_format = false;
|
||||
|
||||
shared_memory.afsk_fmmod = portapack::persistent_memory::afsk_bw() * 8;
|
||||
|
||||
memset(shared_memory.radio_data, 0, 256);
|
||||
memcpy(shared_memory.radio_data, lcrframe_f, 256);
|
||||
|
||||
shared_memory.afsk_transmit_done = false;
|
||||
shared_memory.afsk_repeat = 5; //(portapack::persistent_memory::afsk_config() >> 8) & 0xFF;
|
||||
|
||||
if (scanning) {
|
||||
if (tx_mode == SCAN) {
|
||||
text_status.set(" ");
|
||||
strcat(str, "1/36");
|
||||
strcpy(str, "1/");
|
||||
strcat(str, to_string_dec_uint(LCR_SCAN_COUNT).c_str());
|
||||
text_status.set(str);
|
||||
progress.set_value(1);
|
||||
scan_index++;
|
||||
@@ -321,19 +300,42 @@ void LCRView::start_tx() {
|
||||
text_status.set(str);
|
||||
progress.set_value(20);
|
||||
}
|
||||
|
||||
if (portapack::persistent_memory::afsk_config() & 8)
|
||||
afsk_alt_format = true;
|
||||
else
|
||||
afsk_alt_format = false;
|
||||
|
||||
txing = true;
|
||||
radio::enable(lcr_radio_config);
|
||||
transmitter_model.set_tuning_frequency(portapack::persistent_memory::tuned_frequency());
|
||||
transmitter_model.set_baseband_configuration({
|
||||
.mode = 0,
|
||||
.sampling_rate = 2280000U,
|
||||
.decimation_factor = 1,
|
||||
});
|
||||
transmitter_model.set_rf_amp(true);
|
||||
transmitter_model.set_lna(40);
|
||||
transmitter_model.set_vga(40);
|
||||
transmitter_model.set_baseband_bandwidth(1750000);
|
||||
transmitter_model.enable();
|
||||
|
||||
baseband::set_afsk_data(
|
||||
lcr_message_data,
|
||||
228000 / portapack::persistent_memory::afsk_bitrate(),
|
||||
portapack::persistent_memory::afsk_mark_freq() * (0x40000 * 256) / 2280,
|
||||
portapack::persistent_memory::afsk_space_freq() * (0x40000 * 256) / 2280,
|
||||
5,
|
||||
portapack::persistent_memory::afsk_bw() * 115, // See proc_fsk_lcr.cpp
|
||||
afsk_alt_format
|
||||
);
|
||||
}
|
||||
|
||||
LCRView::LCRView(NavigationView& nav) {
|
||||
baseband::run_image(portapack::spi_flash::image_tag_lcr);
|
||||
baseband::run_image(portapack::spi_flash::image_tag_afsk);
|
||||
|
||||
memset(litteral, 0, 5 * 8);
|
||||
memset(rgsb, 0, 5);
|
||||
|
||||
strcpy(rgsb, RGSB_list[0]);
|
||||
button_setrgsb.set_text(rgsb);
|
||||
|
||||
add_children({ {
|
||||
&text_recap,
|
||||
@@ -358,7 +360,9 @@ LCRView::LCRView(NavigationView& nav) {
|
||||
&button_clear
|
||||
} });
|
||||
|
||||
options_ec.set_selected_index(0);
|
||||
button_setrgsb.set_text(rgsb);
|
||||
|
||||
options_ec.set_selected_index(0); // Auto
|
||||
|
||||
checkbox_am_a.set_value(true);
|
||||
checkbox_am_b.set_value(false);
|
||||
@@ -394,29 +398,27 @@ LCRView::LCRView(NavigationView& nav) {
|
||||
};
|
||||
|
||||
button_lcrdebug.on_select = [this,&nav](Button&) {
|
||||
make_frame();
|
||||
nav.push<DebugLCRView>(lcrstring, checksum);
|
||||
generate_message();
|
||||
nav.push<DebugLCRView>(lcr_string, checksum);
|
||||
};
|
||||
|
||||
button_transmit.on_select = [this](Button&) {
|
||||
if (txing == false) start_tx();
|
||||
if (tx_mode == IDLE) start_tx(false);
|
||||
};
|
||||
|
||||
button_scan.on_select = [this](Button&) {
|
||||
if (txing == false) {
|
||||
scanning = true;
|
||||
if (tx_mode == IDLE) {
|
||||
scan_progress = 0;
|
||||
button_scan.set_style(&style_cancel);
|
||||
button_scan.set_text("ABORT");
|
||||
start_tx();
|
||||
start_tx(true);
|
||||
} else {
|
||||
abort_scan = true;
|
||||
}
|
||||
};
|
||||
|
||||
button_clear.on_select = [this, &nav](Button&) {
|
||||
if (txing == false) {
|
||||
scanning = false;
|
||||
if (tx_mode == IDLE) {
|
||||
memset(litteral, 0, 5 * 8);
|
||||
options_ec.set_selected_index(0);
|
||||
checkbox_am_a.set_value(true);
|
||||
@@ -425,7 +427,7 @@ LCRView::LCRView(NavigationView& nav) {
|
||||
checkbox_am_d.set_value(true);
|
||||
checkbox_am_e.set_value(true);
|
||||
set_dirty();
|
||||
start_tx();
|
||||
start_tx(false);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user