Added more SSTV modes

A bit more work done on Replay (still not enabled)
This commit is contained in:
furrtek
2017-03-23 21:28:21 +00:00
parent 6a0bcb9cca
commit 685e4c6e4b
19 changed files with 288 additions and 172 deletions
+22
View File
@@ -175,6 +175,28 @@ static constexpr Bitmap bitmap_sd_card_unknown {
{ 16, 16 }, bitmap_sd_card_unknown_data
};
static constexpr uint8_t bitmap_play_data[] = {
0x00, 0x00,
0x00, 0x00,
0x0C, 0x00,
0x3C, 0x00,
0xFC, 0x00,
0xFC, 0x03,
0xFC, 0x0F,
0xFC, 0x3F,
0xFC, 0x3F,
0xFC, 0x0F,
0xFC, 0x03,
0xFC, 0x00,
0x3C, 0x00,
0x0C, 0x00,
0x00, 0x00,
0x00, 0x00,
};
static constexpr Bitmap bitmap_play {
{ 16, 16 }, bitmap_play_data
};
static constexpr uint8_t bitmap_icon_stealth_data[] = {
0x00, 0x00,
0x00, 0x00,
+1
View File
@@ -319,6 +319,7 @@ public:
Result<Size> write(const void* const data, const Size bytes_to_write);
Result<Offset> seek(const uint64_t Offset);
Size size();
template<size_t N>
Result<Size> write(const std::array<uint8_t, N>& data) {
+1 -2
View File
@@ -23,13 +23,13 @@
// Color bitmaps generated with:
// Gimp image > indexed colors (16), then "xxd -i *.bmp"
//BUG: Length is wrong in soundboard for long files (> 1min ?)
//BUG: RDS Radiotext is not recognized in Redsea (and car radio)
//BUG: RDS doesn't stop baseband when stopping tx ?
//BUG: Check AFSK transmit end, skips last bits ?
//TEST: Imperial in whipcalc
//TODO: IQ replay
//TODO: Optimize (and group ?) CTCSS tone gen code
//TODO: Morse use prosigns
//TODO: Morse live keying mode ?
@@ -49,7 +49,6 @@ Continuous (Fox-oring)
//TODO: Script engine ?
//TODO: Close Call multiple slices (buggy)
//TODO: Finish EPAR tx
//TODO: IQ replay
//TODO: Wav visualizer
//TODO: File browser view ?
+18 -17
View File
@@ -21,6 +21,7 @@
*/
#include "replay_app.hpp"
#include "string_format.hpp"
#include "baseband_api.hpp"
@@ -32,20 +33,31 @@ using namespace portapack;
namespace ui {
ReplayAppView::ReplayAppView(NavigationView& nav) {
baseband::run_image(portapack::spi_flash::image_tag_replay);
ReplayAppView::ReplayAppView(
NavigationView& nav
) : nav_ (nav)
{
std::vector<std::filesystem::path> file_list;
// Search for files
file_list = scan_root_files(u"/", u"*.C16");
if (!file_list.size()) {
file_error = true;
return;
}
//baseband::run_image(portapack::spi_flash::image_tag_replay);
add_children({
&channel,
&field_frequency,
&field_frequency_step,
&field_rf_amp,
&field_lna,
&field_vga,
&replay_view,
&waterfall,
});
replay_view.set_file_list(file_list);
field_frequency.set_value(target_frequency());
field_frequency.set_step(receiver_model.frequency_step());
field_frequency.on_change = [this](rf::Frequency f) {
@@ -66,17 +78,6 @@ ReplayAppView::ReplayAppView(NavigationView& nav) {
this->field_frequency.set_step(v);
};
radio::enable({
target_frequency(),
sampling_rate,
baseband_bandwidth,
rf::Direction::Transmit,
receiver_model.rf_amp(),
static_cast<int8_t>(receiver_model.lna()),
static_cast<int8_t>(receiver_model.vga())
});
replay_view.set_sampling_rate(sampling_rate / 8);
replay_view.on_error = [&nav](std::string message) {
nav.display_modal("Error", message);
};
+7 -15
View File
@@ -45,9 +45,13 @@ public:
void focus() override;
std::string title() const override { return "Capture"; };
std::string title() const override { return "Replay (beta)"; };
private:
NavigationView& nav_;
bool file_error { false };
static constexpr ui::Dim header_height = 2 * 16;
static constexpr uint32_t sampling_rate = 4000000;
@@ -58,10 +62,6 @@ private:
rf::Frequency target_frequency() const;
void set_target_frequency(const rf::Frequency new_value);
Channel channel {
{ 24 * 8, 5, 6 * 8, 4 },
};
FrequencyField field_frequency {
{ 0 * 8, 0 * 16 },
};
@@ -74,20 +74,12 @@ private:
{ 16 * 8, 0 * 16 }
};
LNAGainField field_lna {
{ 18 * 8, 0 * 16 }
};
VGAGainField field_vga {
{ 21 * 8, 0 * 16 }
};
ReplayView replay_view {
{ 0 * 8, 1 * 16, 30 * 8, 1 * 16 },
"BBD_????", ReplayView::FileType::RawS16, 16384, 3
16384, 3
};
spectrum::WaterfallWidget waterfall;
spectrum::WaterfallWidget waterfall { };
};
} /* namespace ui */
+2 -2
View File
@@ -358,10 +358,10 @@ SystemMenuView::SystemMenuView(NavigationView& nav) {
{ "Play dead", ui::Color::red(), &bitmap_icon_playdead, [&nav](){ nav.push<PlayDeadView>(); } },
{ "Receivers", ui::Color::cyan(), &bitmap_icon_receivers, [&nav](){ nav.push<ReceiverMenuView>(); } },
{ "Capture", ui::Color::blue(), &bitmap_icon_capture, [&nav](){ nav.push<CaptureAppView>(); } },
{ "Replay", ui::Color::grey(), &bitmap_icon_replay, [&nav](){ nav.push<NotImplementedView>(); } },
{ "Replay", ui::Color::grey(), &bitmap_icon_replay, [&nav](){ nav.push<NotImplementedView>(); } }, // ReplayAppView
{ "Audio transmitters", ui::Color::green(), &bitmap_icon_audiotx, [&nav](){ nav.push<TransmitterAudioMenuView>(); } },
{ "Code transmitters", ui::Color::green(), &bitmap_icon_codetx, [&nav](){ nav.push<TransmitterCodedMenuView>(); } },
{ "SSTV transmitter", ui::Color::dark_orange(), &bitmap_icon_sstv, [&nav](){ nav.push<SSTVTXView>(); } },
{ "SSTV transmitter", ui::Color::dark_green(), &bitmap_icon_sstv, [&nav](){ nav.push<SSTVTXView>(); } },
{ "Close Call", ui::Color::cyan(), &bitmap_icon_closecall, [&nav](){ nav.push<CloseCallView>(); } },
{ "Jammer", ui::Color::orange(),&bitmap_icon_jammer, [&nav](){ nav.push<JammerView>(); } },
{ "Utilities", ui::Color::purple(),&bitmap_icon_utilities, [&nav](){ nav.push<UtilitiesView>(); } },
+44 -29
View File
@@ -37,28 +37,38 @@ using namespace portapack;
namespace ui {
void ReplayView::on_file_changed(const uint32_t duration) {
std::string str_duration = "";
if (duration >= 60)
str_duration = to_string_dec_uint(duration / 60) + "m";
text_duration.set(str_duration + to_string_dec_uint(duration % 60) + "s");
}
ReplayView::ReplayView(
const Rect parent_rect,
std::string filename,
const FileType file_type,
const size_t read_size,
const size_t buffer_count
) : View { parent_rect },
filename { filename },
file_type { file_type },
read_size { read_size },
buffer_count { buffer_count }
{
add_children({
&rect_background,
&button_record,
&text_replay_filename,
&text_time_seek,
&button_play,
&options_files,
&text_duration,
//&text_time_seek,
});
rect_background.set_parent_rect({ { 0, 0 }, size() });
button_record.on_select = [this](ImageButton&) {
options_files.on_change = [this](size_t, int32_t duration) {
this->on_file_changed(duration);
};
button_play.on_select = [this](ImageButton&) {
this->toggle();
};
@@ -72,21 +82,22 @@ ReplayView::~ReplayView() {
}
void ReplayView::focus() {
button_record.focus();
options_files.focus();
}
void ReplayView::set_sampling_rate(const size_t new_sampling_rate) {
if( new_sampling_rate != sampling_rate ) {
stop();
sampling_rate = new_sampling_rate;
button_record.hidden(sampling_rate == 0);
text_replay_filename.hidden(sampling_rate == 0);
text_time_seek.hidden(sampling_rate == 0);
rect_background.hidden(sampling_rate != 0);
update_status_display();
void ReplayView::set_file_list(const std::vector<std::filesystem::path>& file_list) {
File bbd_file;
uint32_t duration;
for (const auto& file : file_list) {
bbd_file.open("/" + file.string());
duration = bbd_file.size() / (2 * 2 * (sampling_rate / 8));
file_options.emplace_back(file.string().substr(0, 8), duration);
}
options_files.set_options(file_options);
options_files.set_selected_index(0); // First file
on_file_changed(file_options[0].second);
}
bool ReplayView::is_active() const {
@@ -104,17 +115,10 @@ void ReplayView::toggle() {
void ReplayView::start() {
stop();
text_replay_filename.set("");
if( sampling_rate == 0 ) {
return;
}
auto reader = std::make_unique<FileReader>();
if( reader ) {
text_replay_filename.set(filename.string());
button_record.set_bitmap(&bitmap_stop);
button_play.set_bitmap(&bitmap_stop);
replay_thread = std::make_unique<ReplayThread>(
std::move(reader),
read_size, buffer_count,
@@ -130,12 +134,23 @@ void ReplayView::start() {
}
update_status_display();
radio::enable({
460000000, //target_frequency(),
4000000, //sampling_rate,
2500000, //baseband_bandwidth,
rf::Direction::Transmit,
receiver_model.rf_amp(),
static_cast<int8_t>(receiver_model.lna()),
static_cast<int8_t>(receiver_model.vga())
});
}
void ReplayView::stop() {
if( is_active() ) {
replay_thread.reset();
button_record.set_bitmap(&bitmap_record);
radio::disable();
button_play.set_bitmap(&bitmap_play);
}
update_status_display();
+27 -24
View File
@@ -37,17 +37,10 @@ namespace ui {
class ReplayView : public View {
public:
std::function<void(std::string)> on_error;
enum FileType {
RawS16 = 2,
WAV = 3,
};
std::function<void(std::string)> on_error { };
ReplayView(
const Rect parent_rect,
std::string filename,
FileType file_type,
const size_t read_size,
const size_t buffer_count
);
@@ -55,7 +48,7 @@ public:
void focus() override;
void set_sampling_rate(const size_t new_sampling_rate);
void set_file_list(const std::vector<std::filesystem::path>& file_list);
void start();
void stop();
@@ -63,43 +56,53 @@ public:
bool is_active() const;
private:
using option_t = std::pair<std::string, int32_t>;
using options_t = std::vector<option_t>;
static constexpr uint32_t sampling_rate = 4000000;
void toggle();
void on_file_changed(const uint32_t duration);
void on_tick_second();
void update_status_display();
void handle_replay_thread_done(const File::Error error);
void handle_error(const File::Error error);
const std::filesystem::path filename;
const FileType file_type;
const size_t read_size;
const size_t buffer_count;
size_t sampling_rate { 0 };
SignalToken signal_token_tick_second;
SignalToken signal_token_tick_second { };
options_t file_options { };
Rectangle rect_background {
Color::black()
};
ImageButton button_record {
{ 4 * 8, 0 * 16, 2 * 8, 1 * 16 },
&bitmap_record,
Color::red(),
ImageButton button_play {
{ 0 * 8, 0 * 16, 2 * 8, 1 * 16 },
&bitmap_play,
Color::green(),
Color::black()
};
Text text_replay_filename {
{ 7 * 8, 0 * 16, 8 * 8, 16 },
"",
OptionsField options_files {
{ 2 * 8, 0 * 8 },
8,
{ }
};
Text text_duration {
{ 11 * 8, 0 * 8, 12 * 8, 16 },
"-"
};
Text text_time_seek {
{ 21 * 8, 0 * 16, 9 * 8, 16 },
/*Text text_time_seek {
{ 18 * 8, 0 * 16, 9 * 8, 16 },
"",
};
};*/
std::unique_ptr<ReplayThread> replay_thread;
std::unique_ptr<ReplayThread> replay_thread { };
MessageHandlerRegistration message_handler_capture_thread_error {
Message::ID::CaptureThreadDone,
+64 -32
View File
@@ -99,6 +99,7 @@ void SSTVTXView::on_tuning_frequency_changed(rf::Frequency f) {
void SSTVTXView::prepare_scanline() {
sstv_scanline scanline_buffer;
uint32_t component, pixel_idx;
uint8_t offset;
if (scanline_counter >= (256 * 3)) {
progressbar.set_value(0);
@@ -122,31 +123,33 @@ void SSTVTXView::prepare_scanline() {
// Scanline time: 88.064ms (275.2us/pixel @ 320 pixels/line)
component = scanline_counter % 3;
if ((!scanline_counter) || (component == 2)) {
if ((!scanline_counter && tx_sstv_mode->sync_on_first) || (component == tx_sstv_mode->sync_index)) {
// Sync
scanline_buffer.start_tone.frequency = SSTV_F2D(1200);
scanline_buffer.start_tone.duration = SSTV_MS2S(9);
} else
scanline_buffer.start_tone.duration = tx_sstv_mode->samples_per_sync;
scanline_buffer.gap_tone.frequency = SSTV_F2D(1500);
scanline_buffer.gap_tone.duration = tx_sstv_mode->samples_per_gap;
} else {
// Regular scanline
scanline_buffer.start_tone.duration = 0;
if (tx_sstv_mode->gaps) {
scanline_buffer.gap_tone.frequency = SSTV_F2D(1500);
scanline_buffer.gap_tone.duration = tx_sstv_mode->samples_per_gap;
}
}
scanline_buffer.gap_tone.frequency = SSTV_F2D(1500);
scanline_buffer.gap_tone.duration = SSTV_MS2S(1.5);
if (component == 0) {
if (!component) {
// Read a new line
read_boundary(pixels_buffer,
bmp_header.image_data + ((255 - (scanline_counter / 3)) * sizeof(pixels_buffer)),
sizeof(pixels_buffer));
}
offset = component_map[component];
for (uint32_t bmp_px = 0; bmp_px < 320; bmp_px++) {
pixel_idx = bmp_px * 3;
if (component == 0)
scanline_buffer.luma[bmp_px] = pixels_buffer[pixel_idx + 1]; // Green
else if (component == 1)
scanline_buffer.luma[bmp_px] = pixels_buffer[pixel_idx]; // Blue
else
scanline_buffer.luma[bmp_px] = pixels_buffer[pixel_idx + 2]; // Red
scanline_buffer.luma[bmp_px] = pixels_buffer[pixel_idx + offset];
}
baseband::set_fifo_data((int8_t *)&scanline_buffer);
@@ -155,15 +158,12 @@ void SSTVTXView::prepare_scanline() {
}
void SSTVTXView::start_tx() {
// Baseband SSTV TX code should have a 2 scanlines buffer, and ask
// for fill-up when there's 1 or less remaining. This should leave
// enough time for the code here to generate the scanline data
// before tx. See sstv.hpp:
// Scottie 2 is 320x256 px
// The baseband SSTV TX code (proc_sstv) has a 2-scanline buffer. It is preloaded before
// TX start, and asks for fill-up when a new scanline starts being read. This should
// leave enough time for the code in prepare_scanline() before it ends.
scanline_counter = 0;
prepare_scanline();
prepare_scanline(); // Preload one scanline
transmitter_model.set_sampling_rate(3072000U);
transmitter_model.set_rf_amp(true);
@@ -171,8 +171,8 @@ void SSTVTXView::start_tx() {
transmitter_model.enable();
baseband::set_sstv_data(
0b00011101, // Scottie 2, 275.2us/px
(uint32_t)(0.0002752 * 3072000.0)
tx_sstv_mode->vis_code,
tx_sstv_mode->samples_per_pixel
);
// Todo: Find a better way to prevent user from changing bitmap during tx
@@ -180,13 +180,31 @@ void SSTVTXView::start_tx() {
tx_view.focus();
}
void SSTVTXView::on_bitmap_changed(size_t index) {
void SSTVTXView::on_bitmap_changed(const size_t index) {
bmp_file.open("/sstv/" + bitmaps[index].string());
bmp_file.read(&bmp_header, sizeof(bmp_header));
progressbar.set_max(256 * 3);
set_dirty();
}
void SSTVTXView::on_mode_changed(const size_t index) {
sstv_color_seq tx_color_sequence;
tx_sstv_mode = &sstv_modes[index];
tx_color_sequence = sstv_modes[index].color_sequence;
if (tx_color_sequence == SSTV_COLOR_RGB) {
component_map[0] = 2;
component_map[1] = 1;
component_map[2] = 0;
} else if (tx_color_sequence == SSTV_COLOR_GBR) {
component_map[0] = 1;
component_map[1] = 0;
component_map[2] = 2;
}
progressbar.set_max(sstv_modes[index].lines * 3);
}
SSTVTXView::SSTVTXView(
NavigationView& nav
) : nav_ (nav)
@@ -195,7 +213,9 @@ SSTVTXView::SSTVTXView(
using option_t = std::pair<std::string, int32_t>;
using options_t = std::vector<option_t>;
options_t bitmap_options;
options_t mode_options;
uint32_t c;
// Search for valid bitmaps
file_list = scan_root_files(u"/sstv", u"*.bmp");
if (!file_list.size()) {
@@ -205,11 +225,11 @@ SSTVTXView::SSTVTXView(
for (const auto& file_name : file_list) {
if (!bmp_file.open("/sstv/" + file_name.string()).is_valid()) {
bmp_file.read(&bmp_header, sizeof(bmp_header));
if ((bmp_header.signature == 0x4D42) &&
(bmp_header.width == 320) && // Must be == 320x256 pixels for now
if ((bmp_header.signature == 0x4D42) && // "BM"
(bmp_header.width == 320) && // Must be exactly 320x256 pixels for now
(bmp_header.height == 256) &&
(bmp_header.planes == 1) &&
(bmp_header.bpp >= 24) && // 24 or 32 bpp
(bmp_header.bpp == 24) && // 24 bpp only
(bmp_header.compression == 0)) { // No compression
bitmaps.push_back(file_name);
}
@@ -227,21 +247,33 @@ SSTVTXView::SSTVTXView(
add_children({
&labels,
&options_bitmaps,
&text_mode,
&options_modes,
&progressbar,
&tx_view
});
// Populate file list
for (const auto& bitmap : bitmaps)
bitmap_options.emplace_back(bitmap.string().substr(0, 16), 0);
options_bitmaps.set_options(bitmap_options);
// Populate mode list
for (c = 0; c < SSTV_MODES_NB; c++)
mode_options.emplace_back(sstv_modes[c].name, c);
options_modes.set_options(mode_options);
options_bitmaps.on_change = [this](size_t i, int32_t) {
this->on_bitmap_changed(i);
};
options_bitmaps.set_selected_index(0);
options_bitmaps.set_selected_index(0); // First file
on_bitmap_changed(0);
options_modes.on_change = [this](size_t i, int32_t) {
this->on_mode_changed(i);
};
options_modes.set_selected_index(1); // Scottie 2
on_mode_changed(1);
tx_view.on_edit_frequency = [this, &nav]() {
auto new_view = nav.push<FrequencyKeypadView>(receiver_model.tuning_frequency());
new_view->on_changed = [this](rf::Frequency f) {
+17 -6
View File
@@ -43,6 +43,11 @@ class SSTVTXView : public View {
public:
SSTVTXView(NavigationView& nav);
~SSTVTXView();
SSTVTXView(const SSTVTXView&) = delete;
SSTVTXView(SSTVTXView&&) = delete;
SSTVTXView& operator=(const SSTVTXView&) = delete;
SSTVTXView& operator=(SSTVTXView&&) = delete;
void focus() override;
void paint(Painter&) override;
@@ -54,21 +59,26 @@ private:
sstv_scanline scanline_buffer { };
bool file_error { false };
File bmp_file { };
bmp_header_t bmp_header { };
std::vector<std::filesystem::path> bitmaps { };
bool file_error { false };
uint32_t scanline_counter { 0 };
uint8_t pixels_buffer[320 * 3]; // 320 pixels @ 24bpp
const sstv_mode * tx_sstv_mode { };
uint8_t component_map[3] { };
void read_boundary(uint8_t * buffer, uint32_t position, uint32_t length);
void on_bitmap_changed(size_t index);
void on_bitmap_changed(const size_t index);
void on_mode_changed(const size_t index);
void on_tuning_frequency_changed(rf::Frequency f);
void start_tx();
void prepare_scanline();
Labels labels {
{ { 1 * 8, 1 * 8 }, "File:", Color::light_grey() }
{ { 1 * 8, 1 * 8 }, "File:", Color::light_grey() },
{ { 1 * 8, 3 * 8 }, "Mode:", Color::light_grey() }
};
OptionsField options_bitmaps {
@@ -76,9 +86,10 @@ private:
16,
{ }
};
Text text_mode {
{ 2 * 8, 4 * 8, 16 * 8, 16 },
"Scottie 2"
OptionsField options_modes {
{ 6 * 8, 3 * 8 },
16,
{ }
};
ProgressBar progressbar {