CVS Spam v0.2 (#2357)

* Make the CVS Spam app

CHAOS.C16 is over 100mb and send to JLynx to be included in the sdcard ZIP file.

* indentation

* C16 files are perfect. Disregard any previous files for sdcard/CVSFILES. CHAOS now randomizes files to save space.

---------

Co-authored-by: sommermorgentraum <24917424+zxkmm@users.noreply.github.com>
This commit is contained in:
RocketGod 2024-11-13 23:06:52 -08:00 committed by GitHub
parent 4641dcb449
commit c8f236a708
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
112 changed files with 53 additions and 35 deletions

View file

@ -8,6 +8,7 @@
#include "metadata_file.hpp"
#include "oversample.hpp"
#include "io_convert.hpp"
#include "lfsr_random.hpp"
using namespace portapack;
@ -80,7 +81,7 @@ void CVSSpamView::start_tx(const uint32_t id) {
return;
}
const uint32_t sample_rate = 500000;
const uint32_t sample_rate = 250000;
current_file = cvsfiles_dir / file_list[id].filename();
@ -149,36 +150,36 @@ void CVSSpamView::start_tx(const uint32_t id) {
});
}
void CVSSpamView::start_chaos_tx() {
void CVSSpamView::start_random_tx() {
if (is_active()) {
stop_tx();
return;
}
const std::filesystem::path chaos_file_path = cvsfiles_dir / "chaos.c16";
const uint32_t sample_rate = 500000;
File capture_file;
auto open_error = capture_file.open(chaos_file_path);
if (open_error) {
file_error(chaos_file_path,
"Cannot open CHAOS.C16.\n"
"Initial file check failed.\n"
"Path: " +
cvsfiles_dir.string() +
"\n"
"Error: " +
std::to_string(static_cast<uint32_t>(open_error)));
if (file_list.empty()) {
nav_.display_modal("Error", "No files found!");
return;
}
auto metadata_path = get_metadata_path(chaos_file_path);
lfsr_v = lfsr_iterate(lfsr_v);
size_t random_index = lfsr_v % file_list.size();
const uint32_t sample_rate = 250000;
current_file = cvsfiles_dir / file_list[random_index].filename();
File capture_file;
auto open_error = capture_file.open(current_file);
if (open_error) {
file_error(current_file, "Cannot open file.\nInitial check failed.");
return;
}
auto metadata_path = get_metadata_path(current_file);
auto metadata = read_metadata_file(metadata_path);
if (!metadata) {
metadata = capture_metadata{transmitter_model.target_frequency(), sample_rate};
}
auto file_size = capture_file.size();
capture_file.close();
replay_thread.reset();
@ -188,18 +189,8 @@ void CVSSpamView::start_chaos_tx() {
baseband::set_sample_rate(metadata->sample_rate, get_oversample_rate(metadata->sample_rate));
auto reader = std::make_unique<FileConvertReader>();
if (auto error = reader->open(chaos_file_path)) {
file_error(chaos_file_path,
"Cannot read CHAOS.C16.\n"
"Check file format/perms.\n"
"Rate: " +
to_string_dec_uint(metadata->sample_rate) +
"\n"
"Size: " +
to_string_dec_uint(file_size) +
"\n"
"Error: " +
std::to_string(static_cast<uint32_t>(error)));
if (auto error = reader->open(current_file)) {
file_error(current_file, "Cannot read file data.");
return;
}
@ -241,9 +232,9 @@ bool CVSSpamView::is_active() const {
void CVSSpamView::stop_tx() {
replay_thread.reset();
transmitter_model.disable();
audio::output::stop();
ready_signal = false;
thread_sync_complete = false;
chaos_mode = false;
progressbar.set_value(0);
chThdSleepMilliseconds(50);
}
@ -295,7 +286,13 @@ CVSSpamView::CVSSpamView(NavigationView& nav)
};
button_chaos.on_select = [this](Button&) {
start_chaos_tx();
if (is_active()) {
chaos_mode = false;
stop_tx();
} else {
chaos_mode = true;
start_random_tx();
}
};
button_stop.on_select = [this](Button&) {

View file

@ -11,7 +11,6 @@
#include "baseband_api.hpp"
#include "ui_language.hpp"
#include "file_path.hpp"
#include "audio.hpp"
using namespace portapack;
@ -29,6 +28,9 @@ class CVSSpamView : public View {
static constexpr size_t read_size = 0x4000;
static constexpr size_t buffer_count = 3;
lfsr_word_t lfsr_v = 1;
bool chaos_mode{false};
NavigationView& nav_;
std::unique_ptr<ReplayThread> replay_thread{};
bool ready_signal{false};
@ -40,7 +42,7 @@ class CVSSpamView : public View {
void file_error(const std::filesystem::path& path, const std::string& error_details);
void refresh_list();
void start_tx(const uint32_t id);
void start_chaos_tx();
void start_random_tx();
void on_tx_progress(const uint32_t progress);
uint32_t page = 1;
@ -102,12 +104,31 @@ class CVSSpamView : public View {
[this](const Message* const p) {
const auto message = *reinterpret_cast<const ReplayThreadDoneMessage*>(p);
if (message.return_code == ReplayThread::END_OF_FILE) {
if (is_active()) {
if (chaos_mode) {
replay_thread.reset();
transmitter_model.disable();
ready_signal = false;
lfsr_v = lfsr_iterate(lfsr_v);
size_t random_index = lfsr_v % file_list.size();
menu_view.set_highlighted(random_index);
chThdSleepMilliseconds(100);
start_tx(random_index);
} else {
thread_sync_complete = true;
stop_tx();
}
} else if (message.return_code == ReplayThread::READ_ERROR) {
file_error(file_list[menu_view.highlighted_index()], "Read error during playback");
if (chaos_mode) {
replay_thread.reset();
transmitter_model.disable();
ready_signal = false;
lfsr_v = lfsr_iterate(lfsr_v);
size_t random_index = lfsr_v % file_list.size();
menu_view.set_highlighted(random_index);
chThdSleepMilliseconds(100);
start_tx(random_index);
}
}
}};
};