2015-11-12 19:19:05 -05:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
2016-12-01 00:58:47 -05:00
|
|
|
* Copyright (C) 2016 Furrtek
|
2015-11-12 19:19:05 -05:00
|
|
|
*
|
|
|
|
* 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_jammer.hpp"
|
|
|
|
#include "ui_receiver.hpp"
|
|
|
|
|
2016-07-26 21:03:40 -04:00
|
|
|
#include "baseband_api.hpp"
|
2016-02-04 04:27:53 -05:00
|
|
|
#include "string_format.hpp"
|
2015-11-12 19:19:05 -05:00
|
|
|
|
|
|
|
#include "portapack_shared_memory.hpp"
|
|
|
|
#include "portapack_persistent_memory.hpp"
|
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2016-02-04 04:27:53 -05:00
|
|
|
using namespace portapack;
|
2017-02-13 00:35:13 -05:00
|
|
|
using namespace jammer;
|
2015-11-12 19:19:05 -05:00
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
|
|
|
|
void JammerView::focus() {
|
|
|
|
options_preset.focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
JammerView::~JammerView() {
|
2016-12-01 00:58:47 -05:00
|
|
|
transmitter_model.disable();
|
2016-07-26 21:03:40 -04:00
|
|
|
baseband::shutdown();
|
2015-11-12 19:19:05 -05:00
|
|
|
}
|
|
|
|
|
2017-01-29 03:29:16 -05:00
|
|
|
void JammerView::update_range(const uint32_t n) {
|
|
|
|
std::string label;
|
|
|
|
jammer_range_t * range_ptr;
|
|
|
|
rf::Frequency center, bw_khz;
|
|
|
|
|
|
|
|
range_ptr = &frequency_range[n];
|
|
|
|
|
|
|
|
center = (range_ptr->min + range_ptr->max) / 2;
|
|
|
|
bw_khz = abs(range_ptr->max - range_ptr->min) / 1000;
|
|
|
|
|
|
|
|
auto center_mhz = to_string_dec_int(center / 1000000, 4);
|
|
|
|
auto center_hz100 = to_string_dec_int((center / 1000) % 1000, 3, '0');
|
2015-11-12 19:19:05 -05:00
|
|
|
|
2017-01-29 03:29:16 -05:00
|
|
|
label = "C:" + center_mhz + "." + center_hz100 + "M W:";
|
|
|
|
|
|
|
|
if (bw_khz < 1000) {
|
|
|
|
label += to_string_dec_int(bw_khz, 3) + "kHz";
|
|
|
|
} else {
|
|
|
|
bw_khz /= 1000;
|
|
|
|
label += to_string_dec_int(bw_khz, 3) + "MHz";
|
|
|
|
}
|
|
|
|
|
|
|
|
while (label.length() < 23)
|
|
|
|
label += " ";
|
|
|
|
|
|
|
|
texts_info[n].set(label);
|
|
|
|
}
|
2015-11-12 19:19:05 -05:00
|
|
|
|
2017-02-03 01:26:42 -05:00
|
|
|
void JammerView::update_button(const uint32_t id) {
|
2017-01-29 03:29:16 -05:00
|
|
|
std::string label;
|
|
|
|
rf::Frequency f;
|
2016-12-06 07:31:38 -05:00
|
|
|
|
2017-02-03 01:26:42 -05:00
|
|
|
if (id & 1)
|
|
|
|
f = frequency_range[id / 2].max;
|
2017-01-29 03:29:16 -05:00
|
|
|
else
|
2017-02-03 01:26:42 -05:00
|
|
|
f = frequency_range[id / 2].min;
|
2017-01-29 03:29:16 -05:00
|
|
|
|
|
|
|
auto f_mhz = to_string_dec_int(f / 1000000, 4);
|
|
|
|
auto f_hz100 = to_string_dec_int((f / 1000) % 1000, 3, '0');
|
2015-11-12 19:19:05 -05:00
|
|
|
|
2017-01-29 03:29:16 -05:00
|
|
|
label = f_mhz + "." + f_hz100 + "M";
|
|
|
|
|
2017-02-03 01:26:42 -05:00
|
|
|
buttons_freq[id].set_text(label);
|
2015-11-12 19:19:05 -05:00
|
|
|
}
|
|
|
|
|
2017-01-17 03:42:35 -05:00
|
|
|
void JammerView::on_retune(const rf::Frequency freq, const uint32_t range) {
|
|
|
|
if (freq) {
|
2016-12-05 06:56:41 -05:00
|
|
|
transmitter_model.set_tuning_frequency(freq);
|
2017-02-02 04:29:14 -05:00
|
|
|
text_range_number.set(to_string_dec_uint(range, 2));
|
2017-01-17 03:42:35 -05:00
|
|
|
}
|
2016-07-26 21:03:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
JammerView::JammerView(NavigationView& nav) {
|
2016-12-05 06:56:41 -05:00
|
|
|
size_t n;
|
|
|
|
|
2016-07-26 21:03:40 -04:00
|
|
|
baseband::run_image(portapack::spi_flash::image_tag_jammer);
|
2015-11-13 21:44:49 -05:00
|
|
|
|
2015-11-12 19:19:05 -05:00
|
|
|
static constexpr Style style_val {
|
|
|
|
.font = font::fixed_8x16,
|
2017-01-17 03:42:35 -05:00
|
|
|
.background = Color::black(),
|
|
|
|
.foreground = Color::green(),
|
2015-11-12 19:19:05 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
static constexpr Style style_cancel {
|
|
|
|
.font = font::fixed_8x16,
|
2017-01-17 03:42:35 -05:00
|
|
|
.background = Color::black(),
|
|
|
|
.foreground = Color::red(),
|
2015-11-12 19:19:05 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
static constexpr Style style_info {
|
|
|
|
.font = font::fixed_8x16,
|
|
|
|
.background = Color::black(),
|
|
|
|
.foreground = Color::grey(),
|
|
|
|
};
|
|
|
|
|
2017-01-17 09:27:37 -05:00
|
|
|
JammerChannel * jammer_channels = (JammerChannel*)shared_memory.bb_data.data;
|
2016-12-05 06:56:41 -05:00
|
|
|
|
2017-01-15 22:45:44 -05:00
|
|
|
add_children({
|
2017-02-13 00:35:13 -05:00
|
|
|
&labels,
|
2017-01-29 03:29:16 -05:00
|
|
|
&options_type,
|
2017-01-17 03:42:35 -05:00
|
|
|
&text_range_number,
|
2017-01-29 03:29:16 -05:00
|
|
|
&text_range_total,
|
|
|
|
&options_speed,
|
2015-11-12 19:19:05 -05:00
|
|
|
&options_preset,
|
|
|
|
&options_hop,
|
2017-02-13 00:35:13 -05:00
|
|
|
&button_transmit
|
2017-01-15 22:45:44 -05:00
|
|
|
});
|
2015-11-12 19:19:05 -05:00
|
|
|
|
2016-12-05 06:56:41 -05:00
|
|
|
const auto button_freq_fn = [this, &nav](Button& button) {
|
|
|
|
rf::Frequency * value_ptr;
|
2017-02-03 01:26:42 -05:00
|
|
|
uint32_t id = button.id;
|
2016-12-05 06:56:41 -05:00
|
|
|
|
2017-02-03 01:26:42 -05:00
|
|
|
if (id & 1)
|
|
|
|
value_ptr = &frequency_range[id >> 1].max;
|
2016-12-05 06:56:41 -05:00
|
|
|
else
|
2017-02-03 01:26:42 -05:00
|
|
|
value_ptr = &frequency_range[id >> 1].min;
|
2017-01-17 02:00:42 -05:00
|
|
|
|
2016-12-05 06:56:41 -05:00
|
|
|
auto new_view = nav.push<FrequencyKeypadView>(*value_ptr);
|
2017-02-03 01:26:42 -05:00
|
|
|
new_view->on_changed = [this, value_ptr, id](rf::Frequency f) {
|
2016-12-05 06:56:41 -05:00
|
|
|
*value_ptr = f;
|
2017-02-03 01:26:42 -05:00
|
|
|
update_button(id);
|
|
|
|
update_range(id >> 1);
|
2016-12-05 06:56:41 -05:00
|
|
|
};
|
2017-02-03 01:26:42 -05:00
|
|
|
|
|
|
|
update_button(id);
|
2016-12-05 06:56:41 -05:00
|
|
|
};
|
|
|
|
|
2017-01-17 09:27:37 -05:00
|
|
|
const auto checkbox_fn = [this](Checkbox& checkbox, bool v) {
|
|
|
|
frequency_range[checkbox.id].enabled = v;
|
|
|
|
};
|
|
|
|
|
2016-12-05 06:56:41 -05:00
|
|
|
n = 0;
|
|
|
|
for (auto& button : buttons_freq) {
|
|
|
|
button.on_select = button_freq_fn;
|
|
|
|
button.set_parent_rect({
|
|
|
|
static_cast<Coord>(13 * 8),
|
2017-01-29 03:29:16 -05:00
|
|
|
static_cast<Coord>(76 + ((n >> 1) * 58) + (20 * (n & 1))),
|
|
|
|
96, 20
|
2016-12-05 06:56:41 -05:00
|
|
|
});
|
|
|
|
button.id = n;
|
|
|
|
add_child(&button);
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
|
2017-01-17 09:27:37 -05:00
|
|
|
n = 0;
|
|
|
|
for (auto& checkbox : checkboxes) {
|
|
|
|
checkbox.on_select = checkbox_fn;
|
|
|
|
checkbox.set_parent_rect({
|
|
|
|
static_cast<Coord>(8),
|
2017-01-29 03:29:16 -05:00
|
|
|
static_cast<Coord>(86 + (n * 58)),
|
2017-01-17 09:27:37 -05:00
|
|
|
24, 24
|
|
|
|
});
|
|
|
|
checkbox.id = n;
|
|
|
|
checkbox.set_text("Range " + to_string_dec_uint(n + 1));
|
|
|
|
add_child(&checkbox);
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
|
|
|
|
n = 0;
|
|
|
|
for (auto& text : texts_info) {
|
|
|
|
text.set_parent_rect({
|
|
|
|
static_cast<Coord>(3 * 8),
|
2017-01-29 03:29:16 -05:00
|
|
|
static_cast<Coord>(116 + (n * 58)),
|
2017-01-17 09:27:37 -05:00
|
|
|
25 * 8, 16
|
|
|
|
});
|
|
|
|
text.set_style(&style_info);
|
|
|
|
add_child(&text);
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
|
2017-01-17 02:00:42 -05:00
|
|
|
options_preset.on_change = [this](size_t, OptionsField::value_t v) {
|
2017-01-29 03:29:16 -05:00
|
|
|
const jammer_range_t * preset_ptr;
|
|
|
|
uint32_t c;
|
|
|
|
|
|
|
|
for (c = 0; c < 3; c++) {
|
|
|
|
preset_ptr = &range_presets[v][c];
|
|
|
|
|
|
|
|
frequency_range[c].min = preset_ptr->min;
|
|
|
|
frequency_range[c].max = preset_ptr->max;
|
|
|
|
checkboxes[c].set_value(preset_ptr->enabled);
|
|
|
|
update_button(c * 2);
|
|
|
|
update_button(c * 2 + 1);
|
|
|
|
update_range(c);
|
2015-11-12 19:19:05 -05:00
|
|
|
}
|
2016-12-06 07:31:38 -05:00
|
|
|
|
2015-11-12 19:19:05 -05:00
|
|
|
};
|
|
|
|
|
2017-02-13 00:35:13 -05:00
|
|
|
options_type.set_selected_index(2); // Sweep
|
|
|
|
options_speed.set_selected_index(3); // 10kHz
|
2017-01-29 03:29:16 -05:00
|
|
|
options_preset.set_selected_index(8); // ISM 868
|
|
|
|
options_hop.set_selected_index(1); // 50ms
|
|
|
|
button_transmit.set_style(&style_val);
|
2016-12-05 06:56:41 -05:00
|
|
|
|
2017-01-17 09:27:37 -05:00
|
|
|
button_transmit.on_select = [this, &nav, jammer_channels](Button&) {
|
2017-01-29 03:29:16 -05:00
|
|
|
uint32_t c, i = 0;
|
2017-01-17 09:27:37 -05:00
|
|
|
size_t num_channels;
|
2017-01-17 03:42:35 -05:00
|
|
|
rf::Frequency start_freq, range_bw, range_bw_sub, ch_width;
|
2016-12-05 06:56:41 -05:00
|
|
|
bool out_of_ranges = false;
|
2015-11-13 21:44:49 -05:00
|
|
|
|
2017-01-29 03:29:16 -05:00
|
|
|
if (jamming) {
|
|
|
|
button_transmit.set_style(&style_val);
|
|
|
|
button_transmit.set_text("START");
|
|
|
|
transmitter_model.disable();
|
|
|
|
radio::disable();
|
2017-02-13 00:35:13 -05:00
|
|
|
baseband::set_jammer(false, JammerType::TYPE_FSK, 0);
|
2017-01-29 03:29:16 -05:00
|
|
|
jamming = false;
|
|
|
|
} else {
|
2017-01-17 03:42:35 -05:00
|
|
|
|
2017-01-29 03:29:16 -05:00
|
|
|
// Disable all ranges by default
|
2017-02-02 04:29:14 -05:00
|
|
|
for (c = 0; c < JAMMER_MAX_CH; c++)
|
2017-01-29 03:29:16 -05:00
|
|
|
jammer_channels[c].enabled = false;
|
|
|
|
|
2017-02-02 04:29:14 -05:00
|
|
|
// Generate jamming "channels", maximum: JAMMER_MAX_CH
|
2017-01-29 03:29:16 -05:00
|
|
|
// Convert ranges min/max to center/bw
|
|
|
|
for (size_t r = 0; r < 3; r++) {
|
2017-01-17 03:42:35 -05:00
|
|
|
|
2017-01-29 03:29:16 -05:00
|
|
|
if (frequency_range[r].enabled) {
|
|
|
|
range_bw = abs(frequency_range[r].max - frequency_range[r].min);
|
|
|
|
|
|
|
|
// Sort
|
|
|
|
if (frequency_range[r].min < frequency_range[r].max)
|
|
|
|
start_freq = frequency_range[r].min;
|
|
|
|
else
|
|
|
|
start_freq = frequency_range[r].max;
|
|
|
|
|
|
|
|
if (range_bw >= JAMMER_CH_WIDTH) {
|
|
|
|
num_channels = 0;
|
|
|
|
range_bw_sub = range_bw;
|
|
|
|
do {
|
|
|
|
range_bw_sub -= JAMMER_CH_WIDTH;
|
|
|
|
num_channels++;
|
|
|
|
} while (range_bw_sub >= JAMMER_CH_WIDTH);
|
|
|
|
ch_width = range_bw / num_channels;
|
|
|
|
for (c = 0; c < num_channels; c++) {
|
2017-02-02 04:29:14 -05:00
|
|
|
if (i >= JAMMER_MAX_CH) {
|
2017-01-29 03:29:16 -05:00
|
|
|
out_of_ranges = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
jammer_channels[i].enabled = true;
|
2017-02-02 04:29:14 -05:00
|
|
|
jammer_channels[i].width = (ch_width * 0xFFFFFFULL) / 1536000;
|
2017-01-29 03:29:16 -05:00
|
|
|
jammer_channels[i].center = start_freq + (ch_width / 2) + (ch_width * c);
|
2017-02-02 04:29:14 -05:00
|
|
|
jammer_channels[i].duration = 30720 * options_hop.selected_index_value();
|
2017-01-29 03:29:16 -05:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
} else {
|
2017-02-02 04:29:14 -05:00
|
|
|
if (i >= JAMMER_MAX_CH) {
|
2017-01-17 03:42:35 -05:00
|
|
|
out_of_ranges = true;
|
2017-01-29 03:29:16 -05:00
|
|
|
} else {
|
|
|
|
jammer_channels[i].enabled = true;
|
2017-02-02 04:29:14 -05:00
|
|
|
jammer_channels[i].width = (range_bw * 0xFFFFFFULL) / 1536000;
|
2017-01-29 03:29:16 -05:00
|
|
|
jammer_channels[i].center = start_freq + (range_bw / 2);
|
2017-02-02 04:29:14 -05:00
|
|
|
jammer_channels[i].duration = 30720 * options_hop.selected_index_value();
|
2017-01-29 03:29:16 -05:00
|
|
|
i++;
|
2017-01-17 03:42:35 -05:00
|
|
|
}
|
2016-12-05 06:56:41 -05:00
|
|
|
}
|
|
|
|
}
|
2015-11-13 21:44:49 -05:00
|
|
|
}
|
2017-01-29 03:29:16 -05:00
|
|
|
|
|
|
|
if (!out_of_ranges) {
|
2017-02-02 04:29:14 -05:00
|
|
|
text_range_total.set("/" + to_string_dec_uint(i, 2));
|
2017-01-29 03:29:16 -05:00
|
|
|
|
2017-01-17 03:42:35 -05:00
|
|
|
jamming = true;
|
|
|
|
button_transmit.set_style(&style_cancel);
|
|
|
|
button_transmit.set_text("STOP");
|
|
|
|
|
2017-02-02 04:29:14 -05:00
|
|
|
transmitter_model.set_sampling_rate(3072000U);
|
2017-01-17 03:42:35 -05:00
|
|
|
transmitter_model.set_rf_amp(true);
|
2017-02-02 04:29:14 -05:00
|
|
|
transmitter_model.set_baseband_bandwidth(3500000U);
|
2017-01-17 09:27:37 -05:00
|
|
|
transmitter_model.set_tx_gain(47);
|
2017-01-17 03:42:35 -05:00
|
|
|
transmitter_model.enable();
|
2017-01-17 09:27:37 -05:00
|
|
|
|
2017-02-13 00:35:13 -05:00
|
|
|
baseband::set_jammer(true, (JammerType)options_type.selected_index(), options_speed.selected_index_value());
|
2017-01-29 03:29:16 -05:00
|
|
|
} else {
|
2017-02-13 00:35:13 -05:00
|
|
|
nav.display_modal("Error", "Jamming bandwidth too large.\nMust be less than 24MHz.");
|
2016-07-25 10:21:27 -04:00
|
|
|
}
|
2015-11-12 19:19:05 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace ui */
|