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 {
|
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) {
|
void MorseView::on_set_text(NavigationView& nav) {
|
||||||
textentry(nav, buffer, 28);
|
textentry(nav, buffer, 28);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MorseView::focus() {
|
void MorseView::focus() {
|
||||||
tx_view.focus();
|
button_message.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
MorseView::~MorseView() {
|
MorseView::~MorseView() {
|
||||||
@ -57,44 +89,12 @@ void MorseView::paint(Painter&) {
|
|||||||
update_tx_duration();
|
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() {
|
bool MorseView::start_tx() {
|
||||||
// Re-generate message, just in case
|
// Re-generate message, just in case
|
||||||
time_unit_ms = field_time_unit.value();
|
update_tx_duration();
|
||||||
symbol_count = morse_encode(message, time_unit_ms, field_tone.value(), &time_units);
|
|
||||||
|
|
||||||
if (!symbol_count) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,9 +107,9 @@ bool MorseView::start_tx() {
|
|||||||
transmitter_model.set_baseband_bandwidth(1750000);
|
transmitter_model.set_baseband_bandwidth(1750000);
|
||||||
transmitter_model.enable();
|
transmitter_model.enable();
|
||||||
|
|
||||||
if (options_modulation.selected_index() == 0) {
|
if (modulation == CW) {
|
||||||
ookthread = chThdCreateStatic(ookthread_wa, sizeof(ookthread_wa), NORMALPRIO + 10, ookthread_fn, this);
|
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);
|
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;
|
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 ");
|
text_tx_duration.set(to_string_dec_uint(duration_ms / 1000) + "." + to_string_dec_uint((duration_ms / 100) % 10, 1) + "s ");
|
||||||
} else {
|
} 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);
|
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(
|
MorseView::MorseView(
|
||||||
NavigationView& nav
|
NavigationView& nav
|
||||||
) : nav_ (nav)
|
) : nav_ (nav)
|
||||||
@ -159,22 +166,25 @@ MorseView::MorseView(
|
|||||||
&tx_view
|
&tx_view
|
||||||
});
|
});
|
||||||
|
|
||||||
field_time_unit.set_value(50); // 50ms
|
// Default settings
|
||||||
field_tone.set_value(700); // 700Hz
|
field_time_unit.set_value(50); // 50ms unit
|
||||||
options_modulation.set_selected_index(0); // CW
|
field_tone.set_value(700); // 700Hz FM tone
|
||||||
|
options_modulation.set_selected_index(0); // CW mode
|
||||||
|
|
||||||
checkbox_foxhunt.on_select = [this](Checkbox&, bool v) {
|
checkbox_foxhunt.on_select = [this](Checkbox&, bool value) {
|
||||||
if (v) {
|
foxhunt_mode = value;
|
||||||
message = foxhunt_codes[options_foxhunt.selected_index_value()];
|
|
||||||
strncpy(buffer, message.c_str(), sizeof(buffer));
|
if (foxhunt_mode)
|
||||||
text_message.set(message);
|
set_foxhunt(options_foxhunt.selected_index_value());
|
||||||
update_tx_duration();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
options_foxhunt.on_change = [this](size_t, int32_t) {
|
options_foxhunt.on_change = [this](size_t i, int32_t) {
|
||||||
if (checkbox_foxhunt.value())
|
if (foxhunt_mode)
|
||||||
update_tx_duration();
|
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) {
|
field_time_unit.on_change = [this](int32_t) {
|
||||||
@ -198,7 +208,9 @@ MorseView::MorseView(
|
|||||||
};
|
};
|
||||||
|
|
||||||
tx_view.on_stop = [this]() {
|
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);
|
tx_view.set_transmitting(false);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -65,18 +65,25 @@ private:
|
|||||||
std::string message { };
|
std::string message { };
|
||||||
uint32_t time_units { 0 };
|
uint32_t time_units { 0 };
|
||||||
|
|
||||||
|
enum modulation_t {
|
||||||
|
CW = 0,
|
||||||
|
FM = 1
|
||||||
|
};
|
||||||
|
modulation_t modulation { CW };
|
||||||
|
|
||||||
bool start_tx();
|
bool start_tx();
|
||||||
void update_tx_duration();
|
void update_tx_duration();
|
||||||
void on_set_text(NavigationView& nav);
|
void on_set_text(NavigationView& nav);
|
||||||
|
void set_foxhunt(size_t i);
|
||||||
|
|
||||||
size_t modulation { 0 };
|
Thread * ookthread { nullptr };
|
||||||
Thread * ookthread { };
|
bool foxhunt_mode { false };
|
||||||
|
|
||||||
Labels labels {
|
Labels labels {
|
||||||
{ { 4 * 8, 6 * 8 }, "Time unit: ms", Color::light_grey() },
|
{ { 4 * 8, 6 * 8 }, "Time unit: ms", Color::light_grey() },
|
||||||
{ { 4 * 8, 8 * 8 }, "Tone: Hz", Color::light_grey() },
|
{ { 4 * 8, 8 * 8 }, "Tone: Hz", Color::light_grey() },
|
||||||
{ { 4 * 8, 10 * 8 }, "Modulation:", 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 {
|
Checkbox checkbox_foxhunt {
|
||||||
@ -88,17 +95,17 @@ private:
|
|||||||
{ 17 * 8, 16 + 4 },
|
{ 17 * 8, 16 + 4 },
|
||||||
7,
|
7,
|
||||||
{
|
{
|
||||||
{ "0 (MOE)", 0 },
|
{ "1 (MOE)", 0 },
|
||||||
{ "1 (MOI)", 1 },
|
{ "2 (MOI)", 1 },
|
||||||
{ "2 (MOS)", 2 },
|
{ "3 (MOS)", 2 },
|
||||||
{ "3 (MOH)", 3 },
|
{ "4 (MOH)", 3 },
|
||||||
{ "4 (MO5)", 4 },
|
{ "5 (MO5)", 4 },
|
||||||
{ "5 (MON)", 5 },
|
{ "6 (MON)", 5 },
|
||||||
{ "6 (MOD)", 6 },
|
{ "7 (MOD)", 6 },
|
||||||
{ "7 (MOB)", 7 },
|
{ "8 (MOB)", 7 },
|
||||||
{ "8 (MO6)", 8 },
|
{ "9 (MO6)", 8 },
|
||||||
{ "9 (MO) ", 9 },
|
{ "X (MO) ", 9 },
|
||||||
{ "10 (S) ", 10 }
|
{ "T (S) ", 10 }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -128,17 +135,17 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
Text text_tx_duration {
|
Text text_tx_duration {
|
||||||
{ 14 * 8, 14 * 8, 4 * 8, 16 },
|
{ 14 * 8, 25 * 8, 4 * 8, 16 },
|
||||||
"-"
|
"-"
|
||||||
};
|
};
|
||||||
|
|
||||||
Text text_message {
|
Text text_message {
|
||||||
{ 1 * 8, 18 * 8, 28 * 8, 16 },
|
{ 1 * 8, 15 * 8, 28 * 8, 16 },
|
||||||
""
|
""
|
||||||
};
|
};
|
||||||
|
|
||||||
Button button_message {
|
Button button_message {
|
||||||
{ 1 * 8, 20 * 8, 12 * 8, 28 },
|
{ 1 * 8, 17 * 8, 12 * 8, 28 },
|
||||||
"Set message"
|
"Set message"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -122,12 +122,14 @@ void TonesProcessor::execute(const buffer_c8_t& buffer) {
|
|||||||
void TonesProcessor::on_message(const Message* const p) {
|
void TonesProcessor::on_message(const Message* const p) {
|
||||||
const auto message = *reinterpret_cast<const TonesConfigureMessage*>(p);
|
const auto message = *reinterpret_cast<const TonesConfigureMessage*>(p);
|
||||||
if (message.id == Message::ID::TonesConfigure) {
|
if (message.id == Message::ID::TonesConfigure) {
|
||||||
|
message_length = message.tone_count;
|
||||||
|
|
||||||
|
if (message_length) {
|
||||||
silence_count = message.pre_silence; // In samples
|
silence_count = message.pre_silence; // In samples
|
||||||
for (uint8_t c = 0; c < 32; c++) {
|
for (uint8_t c = 0; c < 32; c++) {
|
||||||
tone_deltas[c] = shared_memory.bb_data.tones_data.tone_defs[c].delta;
|
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;
|
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;
|
fm_delta = message.fm_delta * (0xFFFFFFFFULL / 1536000) * 2;
|
||||||
audio_out = message.audio_out;
|
audio_out = message.audio_out;
|
||||||
dual_tone = message.dual_tone;
|
dual_tone = message.dual_tone;
|
||||||
@ -144,6 +146,11 @@ void TonesProcessor::on_message(const Message* const p) {
|
|||||||
as = 0;
|
as = 0;
|
||||||
|
|
||||||
configured = true;
|
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;
|
i = 0;
|
||||||
for (char& ch : message) {
|
for (char& ch : message) {
|
||||||
if (i > 256) return 0;
|
if (i > 256) return 0; // Message too long
|
||||||
|
|
||||||
if ((ch >= 'a') && (ch <= 'z')) // Make uppercase
|
if ((ch >= 'a') && (ch <= 'z')) // Make uppercase
|
||||||
ch -= 32;
|
ch -= 32;
|
||||||
|
Loading…
Reference in New Issue
Block a user