2016-08-02 22:53:51 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
|
|
|
* Copyright (C) 2016 Furrtek
|
|
|
|
*
|
|
|
|
* This file is part of PortaPack.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ui_encoders.hpp"
|
|
|
|
|
|
|
|
#include "baseband_api.hpp"
|
|
|
|
#include "string_format.hpp"
|
|
|
|
|
|
|
|
#include "portapack_persistent_memory.hpp"
|
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
#include <stdio.h>
|
2016-08-03 02:53:50 -04:00
|
|
|
#include <math.h>
|
2016-08-02 22:53:51 -04:00
|
|
|
|
|
|
|
using namespace portapack;
|
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
|
|
|
|
void EncodersView::focus() {
|
2016-09-26 21:06:14 -04:00
|
|
|
options_enctype.focus();
|
2016-08-02 22:53:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
EncodersView::~EncodersView() {
|
|
|
|
transmitter_model.disable();
|
|
|
|
baseband::shutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EncodersView::generate_frame() {
|
2016-08-06 02:49:45 -04:00
|
|
|
size_t i;
|
2016-08-02 22:53:51 -04:00
|
|
|
|
2016-08-06 02:49:45 -04:00
|
|
|
debug_text.clear();
|
2016-08-03 02:53:50 -04:00
|
|
|
|
2016-08-02 22:53:51 -04:00
|
|
|
i = 0;
|
2016-08-06 06:55:39 -04:00
|
|
|
for (auto c : encoder_def->word_format) {
|
|
|
|
if (c == 'S')
|
2016-08-06 02:49:45 -04:00
|
|
|
debug_text += encoder_def->sync;
|
2016-08-06 06:55:39 -04:00
|
|
|
else
|
2017-03-13 00:09:21 -04:00
|
|
|
debug_text += encoder_def->bit_format[symfield_word.get_sym(i++)];
|
2016-08-02 22:53:51 -04:00
|
|
|
}
|
|
|
|
|
2016-08-06 06:55:39 -04:00
|
|
|
draw_waveform();
|
2016-08-02 22:53:51 -04:00
|
|
|
}
|
|
|
|
|
2016-08-06 02:49:45 -04:00
|
|
|
void EncodersView::draw_waveform() {
|
2017-01-17 02:00:42 -05:00
|
|
|
uint32_t n, length;
|
2017-01-08 21:45:29 -05:00
|
|
|
|
|
|
|
length = debug_text.length();
|
2016-08-02 22:53:51 -04:00
|
|
|
|
2017-01-08 21:45:29 -05:00
|
|
|
for (n = 0; n < length; n++) {
|
|
|
|
if (debug_text[n] == '0')
|
2017-01-17 02:00:42 -05:00
|
|
|
waveform_buffer[n] = 0;
|
2016-08-02 22:53:51 -04:00
|
|
|
else
|
2017-01-17 02:00:42 -05:00
|
|
|
waveform_buffer[n] = 1;
|
2016-08-02 22:53:51 -04:00
|
|
|
}
|
2017-01-08 21:45:29 -05:00
|
|
|
|
2017-01-17 02:00:42 -05:00
|
|
|
waveform.set_length(length);
|
2017-01-08 21:45:29 -05:00
|
|
|
waveform.set_dirty();
|
2016-08-06 02:49:45 -04:00
|
|
|
}
|
|
|
|
|
2016-08-02 22:53:51 -04:00
|
|
|
void EncodersView::update_progress() {
|
2016-08-03 02:53:50 -04:00
|
|
|
char str[16];
|
2016-08-02 22:53:51 -04:00
|
|
|
|
2016-08-06 02:49:45 -04:00
|
|
|
// text_status.set(" ");
|
2016-08-02 22:53:51 -04:00
|
|
|
|
2016-08-06 02:49:45 -04:00
|
|
|
if (tx_mode == SINGLE) {
|
2016-08-02 22:53:51 -04:00
|
|
|
strcpy(str, to_string_dec_uint(repeat_index).c_str());
|
|
|
|
strcat(str, "/");
|
2016-08-03 02:53:50 -04:00
|
|
|
strcat(str, to_string_dec_uint(encoder_def->repeat_min).c_str());
|
2016-08-02 22:53:51 -04:00
|
|
|
text_status.set(str);
|
|
|
|
progress.set_value(repeat_index);
|
2016-08-03 02:53:50 -04:00
|
|
|
/*} else if (tx_mode == SCAN) {
|
2016-08-02 22:53:51 -04:00
|
|
|
strcpy(str, to_string_dec_uint(repeat_index).c_str());
|
|
|
|
strcat(str, "/");
|
|
|
|
strcat(str, to_string_dec_uint(portapack::persistent_memory::afsk_repeats()).c_str());
|
|
|
|
strcat(str, " ");
|
|
|
|
strcat(str, to_string_dec_uint(scan_index + 1).c_str());
|
|
|
|
strcat(str, "/");
|
|
|
|
strcat(str, to_string_dec_uint(scan_count).c_str());
|
|
|
|
text_status.set(str);
|
2016-08-06 02:49:45 -04:00
|
|
|
progress.set_value(scan_progress);*/
|
2016-08-02 22:53:51 -04:00
|
|
|
} else {
|
|
|
|
text_status.set("Ready");
|
|
|
|
progress.set_value(0);
|
2016-08-06 02:49:45 -04:00
|
|
|
}
|
2016-08-02 22:53:51 -04:00
|
|
|
}
|
|
|
|
|
2017-01-08 16:52:54 -05:00
|
|
|
void EncodersView::on_txdone(int n, const bool txdone) {
|
2016-08-03 02:53:50 -04:00
|
|
|
//char str[16];
|
2016-08-02 22:53:51 -04:00
|
|
|
|
2017-01-08 16:52:54 -05:00
|
|
|
if (!txdone) {
|
2016-08-02 22:53:51 -04:00
|
|
|
// Repeating...
|
|
|
|
repeat_index = n + 1;
|
2016-08-03 02:53:50 -04:00
|
|
|
/*if (tx_mode == SCAN) {
|
2016-08-02 22:53:51 -04:00
|
|
|
scan_progress++;
|
|
|
|
update_progress();
|
2016-08-03 02:53:50 -04:00
|
|
|
} else {*/
|
2016-08-02 22:53:51 -04:00
|
|
|
update_progress();
|
2016-08-03 02:53:50 -04:00
|
|
|
//}
|
2016-08-02 22:53:51 -04:00
|
|
|
} else {
|
|
|
|
// Done transmitting
|
2016-08-03 02:53:50 -04:00
|
|
|
/*if ((tx_mode == SCAN) && (scan_index < (scan_count - 1))) {
|
2016-08-02 22:53:51 -04:00
|
|
|
transmitter_model.disable();
|
|
|
|
if (abort_scan) {
|
|
|
|
// Kill scan process
|
|
|
|
strcpy(str, "Abort @");
|
|
|
|
strcat(str, rgsb);
|
|
|
|
text_status.set(str);
|
|
|
|
progress.set_value(0);
|
|
|
|
tx_mode = IDLE;
|
|
|
|
abort_scan = false;
|
|
|
|
button_scan.set_style(&style_val);
|
|
|
|
button_scan.set_text("SCAN");
|
|
|
|
} else {
|
|
|
|
// Next address
|
|
|
|
scan_index++;
|
|
|
|
strcpy(rgsb, &scan_list[options_scanlist.selected_index()].addresses[scan_index * 5]);
|
|
|
|
scan_progress++;
|
|
|
|
repeat_index = 1;
|
|
|
|
update_progress();
|
|
|
|
start_tx(true);
|
|
|
|
}
|
2016-08-03 02:53:50 -04:00
|
|
|
} else {*/
|
2016-08-02 22:53:51 -04:00
|
|
|
transmitter_model.disable();
|
|
|
|
tx_mode = IDLE;
|
2016-08-03 02:53:50 -04:00
|
|
|
text_status.set("Done");
|
|
|
|
progress.set_value(0);
|
2017-02-07 17:12:20 -05:00
|
|
|
tx_view.set_transmitting(false);
|
2016-08-03 02:53:50 -04:00
|
|
|
//}
|
|
|
|
}
|
2016-08-02 22:53:51 -04:00
|
|
|
}
|
|
|
|
|
2017-01-08 21:45:29 -05:00
|
|
|
void EncodersView::on_tuning_frequency_changed(rf::Frequency f) {
|
|
|
|
transmitter_model.set_tuning_frequency(f);
|
|
|
|
}
|
|
|
|
|
2016-08-02 22:53:51 -04:00
|
|
|
void EncodersView::start_tx(const bool scan) {
|
2016-09-26 21:06:14 -04:00
|
|
|
char ook_bitstream[256];
|
2016-08-03 02:53:50 -04:00
|
|
|
uint32_t ook_bitstream_length;
|
2017-02-07 17:12:20 -05:00
|
|
|
(void)scan;
|
2016-08-03 02:53:50 -04:00
|
|
|
|
2016-08-02 22:53:51 -04:00
|
|
|
/*if (scan) {
|
|
|
|
if (tx_mode != SCAN) {
|
|
|
|
scan_index = 0;
|
|
|
|
scan_count = scan_list[options_scanlist.selected_index()].count;
|
|
|
|
scan_progress = 1;
|
|
|
|
repeat_index = 1;
|
|
|
|
tx_mode = SCAN;
|
|
|
|
strcpy(rgsb, &scan_list[options_scanlist.selected_index()].addresses[0]);
|
|
|
|
progress.set_max(scan_count * afsk_repeats);
|
|
|
|
update_progress();
|
|
|
|
}
|
2016-08-03 02:53:50 -04:00
|
|
|
} else {*/
|
2016-08-02 22:53:51 -04:00
|
|
|
tx_mode = SINGLE;
|
|
|
|
repeat_index = 1;
|
2016-08-03 02:53:50 -04:00
|
|
|
progress.set_max(encoder_def->repeat_min);
|
2016-08-02 22:53:51 -04:00
|
|
|
update_progress();
|
2016-08-03 02:53:50 -04:00
|
|
|
//}
|
2016-08-02 22:53:51 -04:00
|
|
|
|
|
|
|
generate_frame();
|
2016-08-03 02:53:50 -04:00
|
|
|
|
|
|
|
// Clear bitstream
|
2016-09-26 21:06:14 -04:00
|
|
|
memset(ook_bitstream, 0, 256);
|
2016-08-03 02:53:50 -04:00
|
|
|
|
|
|
|
size_t n = 0;
|
|
|
|
for (auto c : debug_text) {
|
|
|
|
if (c != '0')
|
|
|
|
ook_bitstream[n >> 3] |= (1 << (7 - (n & 7)));
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
|
2016-09-26 21:06:14 -04:00
|
|
|
ook_bitstream_length = n;
|
2016-08-02 22:53:51 -04:00
|
|
|
|
2017-01-15 22:45:44 -05:00
|
|
|
transmitter_model.set_sampling_rate(2280000U);
|
2016-08-02 22:53:51 -04:00
|
|
|
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();
|
|
|
|
|
2016-12-09 12:21:47 -05:00
|
|
|
memcpy(shared_memory.bb_data.data, ook_bitstream, 256);
|
2016-08-06 02:49:45 -04:00
|
|
|
|
2016-08-03 02:53:50 -04:00
|
|
|
baseband::set_ook_data(
|
|
|
|
ook_bitstream_length,
|
|
|
|
// 2280000/2 = 1140000Hz = 0,877192982us
|
2016-09-26 21:06:14 -04:00
|
|
|
// numberfield_clk.value() / encoder_def->clk_per_fragment
|
2016-08-03 02:53:50 -04:00
|
|
|
// 455000 / 12 = 37917Hz = 26,37339452us
|
2016-09-26 21:06:14 -04:00
|
|
|
228000 / ((numberfield_clk.value() * 1000) / encoder_def->clk_per_fragment),
|
2016-08-06 02:49:45 -04:00
|
|
|
encoder_def->repeat_min,
|
|
|
|
encoder_def->pause_symbols
|
2016-08-03 02:53:50 -04:00
|
|
|
);
|
2016-08-02 22:53:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void EncodersView::on_type_change(size_t index) {
|
2016-09-26 21:06:14 -04:00
|
|
|
std::string word_format, format_string = "";
|
|
|
|
size_t word_length;
|
|
|
|
char symbol_type;
|
2016-08-06 02:49:45 -04:00
|
|
|
//size_t address_length;
|
2016-08-03 02:53:50 -04:00
|
|
|
|
2016-08-02 22:53:51 -04:00
|
|
|
enc_type = index;
|
2016-08-06 02:49:45 -04:00
|
|
|
|
2016-08-02 22:53:51 -04:00
|
|
|
encoder_def = &encoder_defs[enc_type];
|
2016-08-06 02:49:45 -04:00
|
|
|
|
2016-12-09 12:21:47 -05:00
|
|
|
numberfield_clk.set_value(encoder_def->default_speed / 1000);
|
2016-08-02 22:53:51 -04:00
|
|
|
|
2016-09-26 21:06:14 -04:00
|
|
|
// SymField setup
|
|
|
|
word_length = encoder_def->word_length;
|
|
|
|
symfield_word.set_length(word_length);
|
|
|
|
size_t n = 0, i = 0;
|
|
|
|
while (n < word_length) {
|
|
|
|
symbol_type = encoder_def->word_format.at(i++);
|
|
|
|
if (symbol_type == 'A') {
|
|
|
|
symfield_word.set_symbol_list(n++, encoder_def->address_symbols);
|
|
|
|
format_string += 'A';
|
|
|
|
} else if (symbol_type == 'D') {
|
|
|
|
symfield_word.set_symbol_list(n++, encoder_def->data_symbols);
|
|
|
|
format_string += 'D';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ugly :( Pad to erase
|
|
|
|
while (format_string.length() < 24)
|
|
|
|
format_string += ' ';
|
|
|
|
|
|
|
|
text_format.set(format_string);
|
2016-08-03 02:53:50 -04:00
|
|
|
|
2016-08-02 22:53:51 -04:00
|
|
|
generate_frame();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EncodersView::on_show() {
|
2016-09-26 21:06:14 -04:00
|
|
|
// TODO: Remove ?
|
2016-08-02 22:53:51 -04:00
|
|
|
options_enctype.set_selected_index(enc_type);
|
|
|
|
on_type_change(enc_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
EncodersView::EncodersView(NavigationView& nav) {
|
2016-08-06 02:49:45 -04:00
|
|
|
using name_t = std::string;
|
|
|
|
using value_t = int32_t;
|
|
|
|
using option_t = std::pair<name_t, value_t>;
|
|
|
|
using options_t = std::vector<option_t>;
|
|
|
|
options_t enc_options;
|
|
|
|
size_t i;
|
|
|
|
|
2016-08-03 02:53:50 -04:00
|
|
|
baseband::run_image(portapack::spi_flash::image_tag_ook);
|
|
|
|
|
2016-09-26 21:06:14 -04:00
|
|
|
// Default encoder def
|
2016-08-03 02:53:50 -04:00
|
|
|
encoder_def = &encoder_defs[0];
|
2016-08-02 22:53:51 -04:00
|
|
|
|
2017-01-15 22:45:44 -05:00
|
|
|
add_children({
|
2017-02-13 00:35:13 -05:00
|
|
|
&labels,
|
2016-08-02 22:53:51 -04:00
|
|
|
&options_enctype,
|
|
|
|
&numberfield_clk,
|
|
|
|
&numberfield_bitduration,
|
|
|
|
&numberfield_wordduration,
|
2016-09-26 21:06:14 -04:00
|
|
|
&symfield_word,
|
|
|
|
&text_format,
|
2016-08-06 02:49:45 -04:00
|
|
|
//&text_format_a, // DEBUG
|
|
|
|
//&text_format_d, // DEBUG
|
2017-01-08 21:45:29 -05:00
|
|
|
&waveform,
|
2016-08-02 22:53:51 -04:00
|
|
|
&text_status,
|
|
|
|
&progress,
|
2017-02-07 17:12:20 -05:00
|
|
|
&tx_view
|
2017-01-15 22:45:44 -05:00
|
|
|
});
|
2016-08-02 22:53:51 -04:00
|
|
|
|
2016-09-26 21:06:14 -04:00
|
|
|
// Load encoder types
|
2016-08-06 02:49:45 -04:00
|
|
|
for (i = 0; i < ENC_TYPES_COUNT; i++)
|
|
|
|
enc_options.emplace_back(std::make_pair(encoder_defs[i].name, i));
|
|
|
|
|
2016-09-26 21:06:14 -04:00
|
|
|
options_enctype.on_change = [this](size_t index, int32_t value) {
|
|
|
|
(void)value;
|
|
|
|
this->on_type_change(index);
|
|
|
|
};
|
|
|
|
|
2016-08-06 02:49:45 -04:00
|
|
|
options_enctype.set_options(enc_options);
|
|
|
|
options_enctype.set_selected_index(0);
|
|
|
|
|
2016-09-26 21:06:14 -04:00
|
|
|
symfield_word.on_change = [this]() {
|
2016-08-06 02:49:45 -04:00
|
|
|
this->generate_frame();
|
|
|
|
};
|
|
|
|
|
2016-09-26 21:06:14 -04:00
|
|
|
// Selecting input clock changes symbol and word duration
|
2016-08-02 22:53:51 -04:00
|
|
|
numberfield_clk.on_change = [this](int32_t value) {
|
2016-09-26 21:06:14 -04:00
|
|
|
//int32_t new_value = 1000000 / (((float)value * 1000) / encoder_def->clk_per_symbol);
|
|
|
|
// value is in kHz, new_value is in us
|
|
|
|
int32_t new_value = 1000000 / ((value * 1000) / encoder_def->clk_per_symbol);
|
2016-08-02 22:53:51 -04:00
|
|
|
if (new_value != numberfield_bitduration.value()) {
|
|
|
|
numberfield_bitduration.set_value(new_value, false);
|
|
|
|
numberfield_wordduration.set_value(new_value * encoder_def->word_length, false);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-09-26 21:06:14 -04:00
|
|
|
// Selecting symbol duration changes input clock and word duration
|
2016-08-02 22:53:51 -04:00
|
|
|
numberfield_bitduration.on_change = [this](int32_t value) {
|
2016-09-26 21:06:14 -04:00
|
|
|
int32_t new_value = 1000000 / (((float)value * 1000) / encoder_def->clk_per_symbol);
|
2016-08-02 22:53:51 -04:00
|
|
|
if (new_value != numberfield_clk.value()) {
|
|
|
|
numberfield_clk.set_value(new_value, false);
|
|
|
|
numberfield_wordduration.set_value(value * encoder_def->word_length, false);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-09-26 21:06:14 -04:00
|
|
|
// Selecting word duration changes input clock and symbol duration
|
2016-08-02 22:53:51 -04:00
|
|
|
numberfield_wordduration.on_change = [this](int32_t value) {
|
|
|
|
int32_t new_value = value / encoder_def->word_length;
|
|
|
|
if (new_value != numberfield_bitduration.value()) {
|
|
|
|
numberfield_bitduration.set_value(new_value, false);
|
2016-09-26 21:06:14 -04:00
|
|
|
numberfield_clk.set_value(1000000 / (((float)new_value * 1000) / encoder_def->clk_per_symbol), false);
|
2016-08-02 22:53:51 -04:00
|
|
|
}
|
|
|
|
};
|
2017-02-07 17:12:20 -05:00
|
|
|
|
|
|
|
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) {
|
|
|
|
receiver_model.set_tuning_frequency(f);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
tx_view.on_start = [this]() {
|
|
|
|
tx_view.set_transmitting(true);
|
|
|
|
start_tx(false);
|
|
|
|
};
|
|
|
|
|
|
|
|
tx_view.on_stop = [this]() {
|
|
|
|
tx_view.set_transmitting(false);
|
2016-08-02 22:53:51 -04:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace ui */
|