mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-10-01 01:26:06 -04:00
Morse TX bugfix: bad CW symbols, FM not stopping
Corrected fox hunt transmitter #s Moved widgets a bit Setting up proc_tones with 0 message length stops it
This commit is contained in:
parent
0ba05fea5e
commit
2022fe137c
@ -38,12 +38,44 @@ using namespace hackrf::one;
|
||||
|
||||
namespace ui {
|
||||
|
||||
static WORKING_AREA(ookthread_wa, 256);
|
||||
|
||||
static msg_t ookthread_fn(void * arg) {
|
||||
uint32_t v = 0, delay = 0;
|
||||
size_t i = 0;
|
||||
uint8_t * message_symbols = shared_memory.bb_data.tones_data.message;
|
||||
uint8_t symbol;
|
||||
MorseView * arg_c = (MorseView*)arg;
|
||||
|
||||
chRegSetThreadName("ookthread");
|
||||
|
||||
for (i = 0; i < arg_c->symbol_count; i++) {
|
||||
if (chThdShouldTerminate()) break;
|
||||
|
||||
symbol = message_symbols[i];
|
||||
|
||||
v = (symbol < 2) ? 1 : 0; // TX on for dot or dash, off for pause
|
||||
delay = morse_symbols[symbol];
|
||||
|
||||
gpio_tx.write(v);
|
||||
arg_c->on_tx_progress(i, false);
|
||||
|
||||
chThdSleepMilliseconds(delay * arg_c->time_unit_ms);
|
||||
}
|
||||
|
||||
gpio_tx.write(0); // Ensure TX is off
|
||||
arg_c->on_tx_progress(0, true);
|
||||
chThdExit(0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MorseView::on_set_text(NavigationView& nav) {
|
||||
textentry(nav, buffer, 28);
|
||||
}
|
||||
|
||||
void MorseView::focus() {
|
||||
tx_view.focus();
|
||||
button_message.focus();
|
||||
}
|
||||
|
||||
MorseView::~MorseView() {
|
||||
@ -57,44 +89,12 @@ void MorseView::paint(Painter&) {
|
||||
update_tx_duration();
|
||||
}
|
||||
|
||||
static WORKING_AREA(ookthread_wa, 256);
|
||||
|
||||
static msg_t ookthread_fn(void * arg) {
|
||||
uint32_t v = 0, delay = 0;
|
||||
size_t i = 0;
|
||||
uint8_t * message = shared_memory.bb_data.tones_data.message;
|
||||
uint8_t symbol;
|
||||
MorseView * arg_c = (MorseView*)arg;
|
||||
|
||||
chRegSetThreadName("ookthread");
|
||||
for (i = 0; i < arg_c->symbol_count; i++) {
|
||||
if (chThdShouldTerminate()) break;
|
||||
|
||||
symbol = message[i];
|
||||
|
||||
v = (symbol < 2) ? 1 : 0;
|
||||
delay = morse_symbols[v];
|
||||
|
||||
gpio_tx.write(v);
|
||||
arg_c->on_tx_progress(i, false);
|
||||
|
||||
chThdSleepMilliseconds(delay * arg_c->time_unit_ms);
|
||||
}
|
||||
|
||||
gpio_tx.write(0);
|
||||
arg_c->on_tx_progress(0, true);
|
||||
chThdExit(0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool MorseView::start_tx() {
|
||||
// Re-generate message, just in case
|
||||
time_unit_ms = field_time_unit.value();
|
||||
symbol_count = morse_encode(message, time_unit_ms, field_tone.value(), &time_units);
|
||||
update_tx_duration();
|
||||
|
||||
if (!symbol_count) {
|
||||
nav_.display_modal("Error", "Message too long.", INFO, nullptr);
|
||||
nav_.display_modal("Error", "Message too long,\nmust be < 256 symbols.", INFO, nullptr);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -107,9 +107,9 @@ bool MorseView::start_tx() {
|
||||
transmitter_model.set_baseband_bandwidth(1750000);
|
||||
transmitter_model.enable();
|
||||
|
||||
if (options_modulation.selected_index() == 0) {
|
||||
if (modulation == CW) {
|
||||
ookthread = chThdCreateStatic(ookthread_wa, sizeof(ookthread_wa), NORMALPRIO + 10, ookthread_fn, this);
|
||||
} else {
|
||||
} else if (modulation == FM) {
|
||||
baseband::set_tones_data(transmitter_model.bandwidth(), 0, symbol_count, false, false);
|
||||
}
|
||||
|
||||
@ -126,7 +126,7 @@ void MorseView::update_tx_duration() {
|
||||
duration_ms = time_units * time_unit_ms;
|
||||
text_tx_duration.set(to_string_dec_uint(duration_ms / 1000) + "." + to_string_dec_uint((duration_ms / 100) % 10, 1) + "s ");
|
||||
} else {
|
||||
text_tx_duration.set("-");
|
||||
text_tx_duration.set("-"); // Error
|
||||
}
|
||||
}
|
||||
|
||||
@ -139,6 +139,13 @@ void MorseView::on_tx_progress(const int progress, const bool done) {
|
||||
progressbar.set_value(progress);
|
||||
}
|
||||
|
||||
void MorseView::set_foxhunt(size_t i) {
|
||||
message = foxhunt_codes[i];
|
||||
strncpy(buffer, message.c_str(), sizeof(buffer));
|
||||
text_message.set(message);
|
||||
update_tx_duration();
|
||||
}
|
||||
|
||||
MorseView::MorseView(
|
||||
NavigationView& nav
|
||||
) : nav_ (nav)
|
||||
@ -159,22 +166,25 @@ MorseView::MorseView(
|
||||
&tx_view
|
||||
});
|
||||
|
||||
field_time_unit.set_value(50); // 50ms
|
||||
field_tone.set_value(700); // 700Hz
|
||||
options_modulation.set_selected_index(0); // CW
|
||||
// Default settings
|
||||
field_time_unit.set_value(50); // 50ms unit
|
||||
field_tone.set_value(700); // 700Hz FM tone
|
||||
options_modulation.set_selected_index(0); // CW mode
|
||||
|
||||
checkbox_foxhunt.on_select = [this](Checkbox&, bool v) {
|
||||
if (v) {
|
||||
message = foxhunt_codes[options_foxhunt.selected_index_value()];
|
||||
strncpy(buffer, message.c_str(), sizeof(buffer));
|
||||
text_message.set(message);
|
||||
update_tx_duration();
|
||||
}
|
||||
checkbox_foxhunt.on_select = [this](Checkbox&, bool value) {
|
||||
foxhunt_mode = value;
|
||||
|
||||
if (foxhunt_mode)
|
||||
set_foxhunt(options_foxhunt.selected_index_value());
|
||||
};
|
||||
|
||||
options_foxhunt.on_change = [this](size_t, int32_t) {
|
||||
if (checkbox_foxhunt.value())
|
||||
update_tx_duration();
|
||||
options_foxhunt.on_change = [this](size_t i, int32_t) {
|
||||
if (foxhunt_mode)
|
||||
set_foxhunt(i);
|
||||
};
|
||||
|
||||
options_modulation.on_change = [this](size_t i, int32_t) {
|
||||
modulation = (modulation_t)i;
|
||||
};
|
||||
|
||||
field_time_unit.on_change = [this](int32_t) {
|
||||
@ -198,7 +208,9 @@ MorseView::MorseView(
|
||||
};
|
||||
|
||||
tx_view.on_stop = [this]() {
|
||||
chThdTerminate(ookthread);
|
||||
if (ookthread) chThdTerminate(ookthread);
|
||||
transmitter_model.disable();
|
||||
baseband::set_tones_data(0, 0, 0, false, false);
|
||||
tx_view.set_transmitting(false);
|
||||
};
|
||||
}
|
||||
|
@ -65,18 +65,25 @@ private:
|
||||
std::string message { };
|
||||
uint32_t time_units { 0 };
|
||||
|
||||
enum modulation_t {
|
||||
CW = 0,
|
||||
FM = 1
|
||||
};
|
||||
modulation_t modulation { CW };
|
||||
|
||||
bool start_tx();
|
||||
void update_tx_duration();
|
||||
void on_set_text(NavigationView& nav);
|
||||
void set_foxhunt(size_t i);
|
||||
|
||||
size_t modulation { 0 };
|
||||
Thread * ookthread { };
|
||||
Thread * ookthread { nullptr };
|
||||
bool foxhunt_mode { false };
|
||||
|
||||
Labels labels {
|
||||
{ { 4 * 8, 6 * 8 }, "Time unit: ms", Color::light_grey() },
|
||||
{ { 4 * 8, 8 * 8 }, "Tone: Hz", Color::light_grey() },
|
||||
{ { 4 * 8, 10 * 8 }, "Modulation:", Color::light_grey() },
|
||||
{ { 1 * 8, 14 * 8 }, "TX will last", Color::light_grey() }
|
||||
{ { 1 * 8, 25 * 8 }, "TX will last", Color::light_grey() }
|
||||
};
|
||||
|
||||
Checkbox checkbox_foxhunt {
|
||||
@ -88,17 +95,17 @@ private:
|
||||
{ 17 * 8, 16 + 4 },
|
||||
7,
|
||||
{
|
||||
{ "0 (MOE)", 0 },
|
||||
{ "1 (MOI)", 1 },
|
||||
{ "2 (MOS)", 2 },
|
||||
{ "3 (MOH)", 3 },
|
||||
{ "4 (MO5)", 4 },
|
||||
{ "5 (MON)", 5 },
|
||||
{ "6 (MOD)", 6 },
|
||||
{ "7 (MOB)", 7 },
|
||||
{ "8 (MO6)", 8 },
|
||||
{ "9 (MO) ", 9 },
|
||||
{ "10 (S) ", 10 }
|
||||
{ "1 (MOE)", 0 },
|
||||
{ "2 (MOI)", 1 },
|
||||
{ "3 (MOS)", 2 },
|
||||
{ "4 (MOH)", 3 },
|
||||
{ "5 (MO5)", 4 },
|
||||
{ "6 (MON)", 5 },
|
||||
{ "7 (MOD)", 6 },
|
||||
{ "8 (MOB)", 7 },
|
||||
{ "9 (MO6)", 8 },
|
||||
{ "X (MO) ", 9 },
|
||||
{ "T (S) ", 10 }
|
||||
}
|
||||
};
|
||||
|
||||
@ -128,17 +135,17 @@ private:
|
||||
};
|
||||
|
||||
Text text_tx_duration {
|
||||
{ 14 * 8, 14 * 8, 4 * 8, 16 },
|
||||
{ 14 * 8, 25 * 8, 4 * 8, 16 },
|
||||
"-"
|
||||
};
|
||||
|
||||
Text text_message {
|
||||
{ 1 * 8, 18 * 8, 28 * 8, 16 },
|
||||
{ 1 * 8, 15 * 8, 28 * 8, 16 },
|
||||
""
|
||||
};
|
||||
|
||||
Button button_message {
|
||||
{ 1 * 8, 20 * 8, 12 * 8, 28 },
|
||||
{ 1 * 8, 17 * 8, 12 * 8, 28 },
|
||||
"Set message"
|
||||
};
|
||||
|
||||
|
@ -122,28 +122,35 @@ void TonesProcessor::execute(const buffer_c8_t& buffer) {
|
||||
void TonesProcessor::on_message(const Message* const p) {
|
||||
const auto message = *reinterpret_cast<const TonesConfigureMessage*>(p);
|
||||
if (message.id == Message::ID::TonesConfigure) {
|
||||
silence_count = message.pre_silence; // In samples
|
||||
for (uint8_t c = 0; c < 32; c++) {
|
||||
tone_deltas[c] = shared_memory.bb_data.tones_data.tone_defs[c].delta;
|
||||
tone_durations[c] = shared_memory.bb_data.tones_data.tone_defs[c].duration;
|
||||
}
|
||||
message_length = message.tone_count;
|
||||
fm_delta = message.fm_delta * (0xFFFFFFFFULL / 1536000) * 2;
|
||||
audio_out = message.audio_out;
|
||||
dual_tone = message.dual_tone;
|
||||
|
||||
if (audio_out) audio_output.configure(false);
|
||||
|
||||
txdone_message.done = false;
|
||||
txdone_message.progress = 0;
|
||||
|
||||
digit_pos = 0;
|
||||
sample_count = 0;
|
||||
tone_a_phase = 0;
|
||||
tone_b_phase = 0;
|
||||
as = 0;
|
||||
|
||||
configured = true;
|
||||
if (message_length) {
|
||||
silence_count = message.pre_silence; // In samples
|
||||
for (uint8_t c = 0; c < 32; c++) {
|
||||
tone_deltas[c] = shared_memory.bb_data.tones_data.tone_defs[c].delta;
|
||||
tone_durations[c] = shared_memory.bb_data.tones_data.tone_defs[c].duration;
|
||||
}
|
||||
fm_delta = message.fm_delta * (0xFFFFFFFFULL / 1536000) * 2;
|
||||
audio_out = message.audio_out;
|
||||
dual_tone = message.dual_tone;
|
||||
|
||||
if (audio_out) audio_output.configure(false);
|
||||
|
||||
txdone_message.done = false;
|
||||
txdone_message.progress = 0;
|
||||
|
||||
digit_pos = 0;
|
||||
sample_count = 0;
|
||||
tone_a_phase = 0;
|
||||
tone_b_phase = 0;
|
||||
as = 0;
|
||||
|
||||
configured = true;
|
||||
} else {
|
||||
configured = false;
|
||||
txdone_message.done = true;
|
||||
shared_memory.application_queue.push(txdone_message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ size_t morse_encode(std::string& message, const uint32_t time_unit_ms,
|
||||
|
||||
i = 0;
|
||||
for (char& ch : message) {
|
||||
if (i > 256) return 0;
|
||||
if (i > 256) return 0; // Message too long
|
||||
|
||||
if ((ch >= 'a') && (ch <= 'z')) // Make uppercase
|
||||
ch -= 32;
|
||||
|
Loading…
Reference in New Issue
Block a user