2023-11-01 06:46:41 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
|
|
|
* Copyright (C) 2017 Furrtek
|
|
|
|
* Copyright (C) 2023 TJ Baginski
|
|
|
|
*
|
|
|
|
* 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 "ble_tx_app.hpp"
|
2023-11-03 03:08:49 -04:00
|
|
|
#include "ble_rx_app.hpp"
|
2023-11-01 06:46:41 -04:00
|
|
|
|
|
|
|
#include "ui_fileman.hpp"
|
|
|
|
#include "ui_modemsetup.hpp"
|
|
|
|
|
|
|
|
#include "audio.hpp"
|
|
|
|
#include "baseband_api.hpp"
|
|
|
|
#include "io_file.hpp"
|
|
|
|
#include "modems.hpp"
|
|
|
|
#include "portapack_persistent_memory.hpp"
|
|
|
|
#include "rtc_time.hpp"
|
|
|
|
#include "string_format.hpp"
|
2024-03-25 03:44:49 -04:00
|
|
|
#include "file_path.hpp"
|
2023-11-01 06:46:41 -04:00
|
|
|
|
|
|
|
using namespace portapack;
|
|
|
|
using namespace modems;
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
|
|
|
|
void BLELoggerTx::log_raw_data(const std::string& data) {
|
|
|
|
log_file.write_entry(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasValidHexPairs(const std::string& str, int totalPairs) {
|
|
|
|
int validPairs = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < totalPairs * 2; i += 2) {
|
|
|
|
char c1 = str[i];
|
|
|
|
char c2 = str[i + 1];
|
|
|
|
|
|
|
|
if (!(std::isxdigit(c1) && std::isxdigit(c2))) {
|
|
|
|
return false; // Return false if any pair is invalid.
|
|
|
|
}
|
|
|
|
|
|
|
|
validPairs++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (validPairs == totalPairs);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> splitIntoStrings(const char* input) {
|
|
|
|
std::vector<std::string> result;
|
|
|
|
int length = std::strlen(input);
|
|
|
|
int start = 0;
|
|
|
|
|
|
|
|
while (start < length) {
|
|
|
|
int remaining = length - start;
|
2023-12-02 02:05:29 -05:00
|
|
|
int chunkSize = (remaining > 29) ? 29 : remaining;
|
2023-11-01 06:46:41 -04:00
|
|
|
result.push_back(std::string(input + start, chunkSize));
|
|
|
|
start += chunkSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t stringToUint32(const std::string& str) {
|
|
|
|
size_t pos = 0;
|
|
|
|
uint32_t result = 0;
|
|
|
|
|
|
|
|
while (pos < str.size() && std::isdigit(str[pos])) {
|
|
|
|
int digit = str[pos] - '0';
|
|
|
|
|
|
|
|
// Check for overflow before adding the next digit
|
|
|
|
if (result > (UINT32_MAX - digit) / 10) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = result * 10 + digit;
|
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::uint64_t get_freq_by_channel_number(uint8_t channel_number) {
|
|
|
|
uint64_t freq_hz;
|
|
|
|
|
|
|
|
switch (channel_number) {
|
|
|
|
case 37:
|
|
|
|
freq_hz = 2'402'000'000ull;
|
|
|
|
break;
|
|
|
|
case 38:
|
|
|
|
freq_hz = 2'426'000'000ull;
|
|
|
|
break;
|
|
|
|
case 39:
|
|
|
|
freq_hz = 2'480'000'000ull;
|
|
|
|
break;
|
|
|
|
case 0 ... 10:
|
|
|
|
freq_hz = 2'404'000'000ull + channel_number * 2'000'000ull;
|
|
|
|
break;
|
|
|
|
case 11 ... 36:
|
|
|
|
freq_hz = 2'428'000'000ull + (channel_number - 11) * 2'000'000ull;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
freq_hz = UINT64_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
return freq_hz;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
|
|
|
|
void BLETxView::focus() {
|
2023-11-02 14:47:34 -04:00
|
|
|
button_open.focus();
|
2023-11-01 06:46:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool BLETxView::is_active() const {
|
|
|
|
return (bool)is_running;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BLETxView::file_error() {
|
|
|
|
nav_.display_modal("Error", "File read error.");
|
|
|
|
}
|
|
|
|
|
2023-11-06 13:09:26 -05:00
|
|
|
bool BLETxView::saveFile(const std::filesystem::path& path) {
|
|
|
|
File f;
|
|
|
|
auto error = f.create(path);
|
|
|
|
if (error)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < num_packets; i++) {
|
|
|
|
std::string macAddressStr = packets[i].macAddress;
|
|
|
|
std::string advertisementDataStr = packets[i].advertisementData;
|
|
|
|
std::string packetCountStr = packets[i].packetCount;
|
|
|
|
|
|
|
|
std::string packetString = macAddressStr + ' ' + advertisementDataStr + ' ' + packetCountStr;
|
|
|
|
|
|
|
|
// Are we on the last line?
|
|
|
|
if (i != num_packets - 1) {
|
|
|
|
packetString += '\n';
|
|
|
|
}
|
|
|
|
|
|
|
|
f.write(packetString.c_str(), packetString.length());
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-11-01 06:46:41 -04:00
|
|
|
void BLETxView::toggle() {
|
|
|
|
if (is_active()) {
|
|
|
|
stop();
|
|
|
|
} else {
|
|
|
|
start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BLETxView::start() {
|
2023-11-27 15:59:29 -05:00
|
|
|
baseband::run_image(portapack::spi_flash::image_tag_btle_tx);
|
|
|
|
transmitter_model.enable();
|
|
|
|
|
2023-11-02 12:32:29 -04:00
|
|
|
// Generate new random Mac Address.
|
|
|
|
generateRandomMacAddress(randomMac);
|
|
|
|
|
2023-11-16 08:46:45 -05:00
|
|
|
// If this is our first run, check file.
|
2023-11-01 06:46:41 -04:00
|
|
|
if (!is_active()) {
|
|
|
|
File data_file;
|
|
|
|
|
|
|
|
auto error = data_file.open(file_path);
|
2023-11-06 05:16:01 -05:00
|
|
|
if (error && !file_override) {
|
2023-11-01 06:46:41 -04:00
|
|
|
file_error();
|
|
|
|
check_loop.set_value(false);
|
|
|
|
return;
|
|
|
|
}
|
2023-11-16 08:46:45 -05:00
|
|
|
|
|
|
|
button_play.set_bitmap(&bitmap_stop);
|
|
|
|
is_running = true;
|
2023-11-01 06:46:41 -04:00
|
|
|
}
|
|
|
|
|
2023-11-28 15:11:07 -05:00
|
|
|
char advertisementData[63] = {0};
|
|
|
|
strcpy(advertisementData, packets[current_packet].advertisementData);
|
|
|
|
|
2023-11-30 15:57:22 -05:00
|
|
|
// TODO: Make this a checkbox.
|
|
|
|
if (!markedBytes.empty()) {
|
|
|
|
for (size_t i = 0; i < strlen(advertisementData); i++) {
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
auto it = std::find(markedBytes.begin(), markedBytes.end(), i);
|
2023-11-28 15:11:07 -05:00
|
|
|
|
2023-11-30 15:57:22 -05:00
|
|
|
if (it != markedBytes.end()) {
|
|
|
|
found = true;
|
|
|
|
}
|
2023-11-28 15:11:07 -05:00
|
|
|
|
2023-11-30 15:57:22 -05:00
|
|
|
if (found) {
|
2023-12-02 02:05:29 -05:00
|
|
|
uint8_t hexDigit;
|
|
|
|
switch (marked_data_sequence.selected_index_value()) {
|
|
|
|
case 0:
|
|
|
|
hexDigit = marked_counter++;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
hexDigit = marked_counter--;
|
|
|
|
break;
|
|
|
|
case 2: {
|
|
|
|
uint8_t min = 0x00;
|
|
|
|
uint8_t max = 0x0F;
|
|
|
|
|
|
|
|
hexDigit = min + std::rand() % (max - min + 1);
|
|
|
|
} break;
|
|
|
|
default:
|
2023-12-03 02:19:04 -05:00
|
|
|
hexDigit = 0;
|
2023-12-02 02:05:29 -05:00
|
|
|
break;
|
|
|
|
}
|
2023-11-28 15:11:07 -05:00
|
|
|
|
2023-12-02 02:05:29 -05:00
|
|
|
advertisementData[i] = uint_to_char(hexDigit, 16);
|
2023-11-28 15:11:07 -05:00
|
|
|
|
2023-12-02 02:05:29 -05:00
|
|
|
// Bounding to Hex.
|
|
|
|
if (marked_counter == 16) {
|
|
|
|
marked_counter = 0;
|
|
|
|
} else if (marked_counter == 255) {
|
|
|
|
marked_counter = 15;
|
|
|
|
}
|
2023-11-28 15:11:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-27 15:59:29 -05:00
|
|
|
// Setup next packet configuration.
|
2023-11-16 08:46:45 -05:00
|
|
|
progressbar.set_max(packets[current_packet].packet_count);
|
2023-11-28 15:11:07 -05:00
|
|
|
baseband::set_btletx(channel_number, random_mac ? randomMac : packets[current_packet].macAddress, advertisementData, pduType);
|
2023-11-01 06:46:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void BLETxView::stop() {
|
|
|
|
transmitter_model.disable();
|
2023-11-27 15:59:29 -05:00
|
|
|
baseband::shutdown();
|
|
|
|
|
2023-11-01 06:46:41 -04:00
|
|
|
progressbar.set_value(0);
|
|
|
|
button_play.set_bitmap(&bitmap_play);
|
|
|
|
check_loop.set_value(false);
|
2023-11-02 12:32:29 -04:00
|
|
|
|
2023-11-11 14:46:51 -05:00
|
|
|
update_current_packet(packets[0], 0);
|
2023-11-02 12:32:29 -04:00
|
|
|
|
2023-11-01 06:46:41 -04:00
|
|
|
is_running = false;
|
|
|
|
}
|
|
|
|
|
2023-11-27 15:59:29 -05:00
|
|
|
void BLETxView::reset() {
|
|
|
|
transmitter_model.disable();
|
|
|
|
baseband::shutdown();
|
|
|
|
|
|
|
|
start();
|
|
|
|
}
|
|
|
|
|
2023-11-16 08:46:45 -05:00
|
|
|
// called each 1/60th of second, so 6 = 100ms
|
|
|
|
void BLETxView::on_timer() {
|
2023-11-28 12:18:15 -05:00
|
|
|
if (++timer_count == timer_period) {
|
|
|
|
timer_count = 0;
|
2023-11-16 08:46:45 -05:00
|
|
|
|
2023-11-27 15:59:29 -05:00
|
|
|
if (is_active()) {
|
2023-11-02 12:32:29 -04:00
|
|
|
// Reached end of current packet repeats.
|
|
|
|
if (packet_counter == 0) {
|
|
|
|
// Done sending all packets.
|
|
|
|
if (current_packet == (num_packets - 1)) {
|
2023-11-27 15:59:29 -05:00
|
|
|
current_packet = 0;
|
|
|
|
|
2023-11-02 14:47:34 -04:00
|
|
|
// If looping, restart from beginning.
|
|
|
|
if (check_loop.value()) {
|
2023-11-27 15:59:29 -05:00
|
|
|
update_current_packet(packets[current_packet], current_packet);
|
|
|
|
reset();
|
2023-11-02 14:47:34 -04:00
|
|
|
} else {
|
|
|
|
stop();
|
|
|
|
}
|
2023-11-02 12:32:29 -04:00
|
|
|
} else {
|
|
|
|
current_packet++;
|
2023-11-11 14:46:51 -05:00
|
|
|
update_current_packet(packets[current_packet], current_packet);
|
2023-11-27 15:59:29 -05:00
|
|
|
reset();
|
2023-11-02 12:32:29 -04:00
|
|
|
}
|
2023-11-16 08:46:45 -05:00
|
|
|
} else {
|
2023-11-27 15:59:29 -05:00
|
|
|
reset();
|
2023-11-01 06:46:41 -04:00
|
|
|
}
|
2023-11-16 08:46:45 -05:00
|
|
|
}
|
|
|
|
}
|
2023-11-28 12:18:15 -05:00
|
|
|
|
|
|
|
if (++auto_channel_counter == auto_channel_period) {
|
|
|
|
auto_channel_counter = 0;
|
|
|
|
|
|
|
|
if (auto_channel) {
|
|
|
|
int min = 37;
|
|
|
|
int max = 39;
|
|
|
|
|
|
|
|
channel_number = min + std::rand() % (max - min + 1);
|
|
|
|
|
|
|
|
field_frequency.set_value(get_freq_by_channel_number(channel_number));
|
|
|
|
}
|
|
|
|
}
|
2023-11-16 08:46:45 -05:00
|
|
|
}
|
2023-11-01 06:46:41 -04:00
|
|
|
|
2023-11-16 08:46:45 -05:00
|
|
|
void BLETxView::on_tx_progress(const bool done) {
|
|
|
|
if (done) {
|
|
|
|
if (is_active()) {
|
2023-11-27 15:59:29 -05:00
|
|
|
if ((packet_counter % 10) == 0) {
|
|
|
|
text_packets_sent.set(to_string_dec_uint(packet_counter));
|
|
|
|
}
|
|
|
|
|
|
|
|
packet_counter--;
|
|
|
|
progressbar.set_value(packets[current_packet].packet_count - packet_counter);
|
2023-11-02 14:47:34 -04:00
|
|
|
}
|
2023-11-01 06:46:41 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BLETxView::BLETxView(NavigationView& nav)
|
|
|
|
: nav_{nav} {
|
|
|
|
add_children({&button_open,
|
|
|
|
&text_filename,
|
|
|
|
&progressbar,
|
2023-11-02 12:32:29 -04:00
|
|
|
&check_rand_mac,
|
2023-11-01 06:46:41 -04:00
|
|
|
&field_frequency,
|
|
|
|
&tx_view, // now it handles previous rfgain, rfamp.
|
|
|
|
&check_loop,
|
|
|
|
&button_play,
|
|
|
|
&label_speed,
|
|
|
|
&options_speed,
|
|
|
|
&options_channel,
|
2023-11-01 18:24:55 -04:00
|
|
|
&options_adv_type,
|
2023-12-02 02:05:29 -05:00
|
|
|
&label_marked_data,
|
|
|
|
&marked_data_sequence,
|
2023-11-02 12:32:29 -04:00
|
|
|
&label_packet_index,
|
|
|
|
&text_packet_index,
|
2023-11-01 06:46:41 -04:00
|
|
|
&label_packets_sent,
|
|
|
|
&text_packets_sent,
|
|
|
|
&label_mac_address,
|
|
|
|
&text_mac_address,
|
|
|
|
&label_data_packet,
|
2023-11-30 15:57:22 -05:00
|
|
|
&dataEditView,
|
2023-12-02 02:05:29 -05:00
|
|
|
&button_clear_marked,
|
2023-11-06 13:09:26 -05:00
|
|
|
&button_save_packet,
|
2023-11-30 15:57:22 -05:00
|
|
|
&button_switch});
|
2023-11-01 06:46:41 -04:00
|
|
|
|
|
|
|
field_frequency.set_step(0);
|
|
|
|
|
2023-11-06 13:09:26 -05:00
|
|
|
ensure_directory(packet_save_path);
|
|
|
|
|
2023-11-01 06:46:41 -04:00
|
|
|
button_play.on_select = [this](ImageButton&) {
|
|
|
|
this->toggle();
|
|
|
|
};
|
|
|
|
|
|
|
|
options_channel.on_change = [this](size_t, int32_t i) {
|
2023-11-16 08:46:45 -05:00
|
|
|
// If we selected Auto don't do anything and Auto will handle changing.
|
|
|
|
if (i == 40) {
|
|
|
|
auto_channel = true;
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
auto_channel = false;
|
|
|
|
}
|
|
|
|
|
2023-11-01 06:46:41 -04:00
|
|
|
field_frequency.set_value(get_freq_by_channel_number(i));
|
|
|
|
channel_number = i;
|
|
|
|
};
|
|
|
|
|
|
|
|
options_speed.on_change = [this](size_t, int32_t i) {
|
|
|
|
timer_period = i;
|
2023-11-28 12:18:15 -05:00
|
|
|
timer_count = 0;
|
2023-11-01 06:46:41 -04:00
|
|
|
};
|
|
|
|
|
2023-11-01 18:24:55 -04:00
|
|
|
options_adv_type.on_change = [this](size_t, int32_t i) {
|
|
|
|
pduType = (PKT_TYPE)i;
|
|
|
|
};
|
|
|
|
|
2023-11-01 06:46:41 -04:00
|
|
|
options_speed.set_selected_index(0);
|
2023-11-06 05:16:01 -05:00
|
|
|
options_channel.set_selected_index(0);
|
|
|
|
options_adv_type.set_selected_index(0);
|
2023-11-01 06:46:41 -04:00
|
|
|
|
2023-11-02 12:32:29 -04:00
|
|
|
check_rand_mac.set_value(false);
|
|
|
|
check_rand_mac.on_select = [this](Checkbox&, bool v) {
|
|
|
|
random_mac = v;
|
|
|
|
};
|
|
|
|
|
2023-11-11 14:46:51 -05:00
|
|
|
button_open.on_select = [this](Button&) {
|
|
|
|
auto open_view = nav_.push<FileLoadView>(".TXT");
|
2023-11-01 06:46:41 -04:00
|
|
|
open_view->on_changed = [this](std::filesystem::path new_file_path) {
|
|
|
|
on_file_changed(new_file_path);
|
2023-11-04 03:29:48 -04:00
|
|
|
|
|
|
|
nav_.set_on_pop([this]() { button_play.focus(); });
|
2023-11-01 06:46:41 -04:00
|
|
|
};
|
|
|
|
};
|
2023-11-03 03:08:49 -04:00
|
|
|
|
2023-11-06 13:09:26 -05:00
|
|
|
button_save_packet.on_select = [this, &nav](Button&) {
|
|
|
|
packetFileBuffer = "";
|
|
|
|
text_prompt(
|
|
|
|
nav,
|
|
|
|
packetFileBuffer,
|
|
|
|
64,
|
|
|
|
[this](std::string& buffer) {
|
|
|
|
on_save_file(buffer);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2023-11-11 14:46:51 -05:00
|
|
|
button_switch.on_select = [&nav](Button&) {
|
|
|
|
nav.replace<BLERxView>();
|
2023-11-03 03:08:49 -04:00
|
|
|
};
|
2023-11-30 15:57:22 -05:00
|
|
|
|
|
|
|
dataEditView.on_select = [this] {
|
|
|
|
// Save last selected cursor.
|
|
|
|
cursor_pos.line = dataEditView.line();
|
|
|
|
cursor_pos.col = dataEditView.col();
|
|
|
|
|
2023-12-02 02:05:29 -05:00
|
|
|
// Reject setting newline at index 29.
|
|
|
|
if (cursor_pos.col != 29) {
|
|
|
|
uint16_t dataBytePos = (cursor_pos.line * 29) + cursor_pos.col;
|
2023-11-30 15:57:22 -05:00
|
|
|
|
2023-12-02 02:05:29 -05:00
|
|
|
auto it = std::find(markedBytes.begin(), markedBytes.end(), dataBytePos);
|
2023-11-30 15:57:22 -05:00
|
|
|
|
2023-12-02 02:05:29 -05:00
|
|
|
if (it != markedBytes.end()) {
|
|
|
|
markedBytes.erase(it);
|
|
|
|
} else {
|
|
|
|
markedBytes.push_back(dataBytePos);
|
|
|
|
}
|
2023-11-30 15:57:22 -05:00
|
|
|
|
2023-12-02 02:05:29 -05:00
|
|
|
dataEditView.cursor_mark_selected();
|
|
|
|
}
|
|
|
|
};
|
2023-11-30 15:57:22 -05:00
|
|
|
|
2023-12-02 02:05:29 -05:00
|
|
|
button_clear_marked.on_select = [this](Button&) {
|
|
|
|
marked_counter = 0;
|
|
|
|
markedBytes.clear();
|
|
|
|
dataEditView.cursor_clear_marked();
|
2023-11-30 15:57:22 -05:00
|
|
|
};
|
2023-11-01 06:46:41 -04:00
|
|
|
}
|
|
|
|
|
2023-11-06 05:16:01 -05:00
|
|
|
BLETxView::BLETxView(
|
|
|
|
NavigationView& nav,
|
|
|
|
BLETxPacket packet)
|
|
|
|
: BLETxView(nav) {
|
|
|
|
packets[0] = packet;
|
2023-11-11 14:46:51 -05:00
|
|
|
|
|
|
|
update_current_packet(packets[0], 0);
|
2023-11-06 05:16:01 -05:00
|
|
|
|
|
|
|
num_packets = 1;
|
|
|
|
file_override = true;
|
|
|
|
}
|
|
|
|
|
2023-11-01 06:46:41 -04:00
|
|
|
void BLETxView::on_file_changed(const fs::path& new_file_path) {
|
2024-03-26 12:32:24 -04:00
|
|
|
file_path = new_file_path;
|
2023-11-03 03:08:49 -04:00
|
|
|
num_packets = 0;
|
2023-11-01 06:46:41 -04:00
|
|
|
|
|
|
|
{ // Get the size of the data file.
|
|
|
|
File data_file;
|
|
|
|
auto error = data_file.open(file_path);
|
|
|
|
if (error) {
|
|
|
|
file_error();
|
|
|
|
file_path = "";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-11-02 12:32:29 -04:00
|
|
|
do {
|
|
|
|
readUntil(data_file, packets[num_packets].macAddress, mac_address_size_str, ' ');
|
|
|
|
readUntil(data_file, packets[num_packets].advertisementData, max_packet_size_str, ' ');
|
|
|
|
readUntil(data_file, packets[num_packets].packetCount, max_packet_repeat_str, '\n');
|
2023-11-01 06:46:41 -04:00
|
|
|
|
2023-11-02 12:32:29 -04:00
|
|
|
uint64_t macAddressSize = strlen(packets[num_packets].macAddress);
|
|
|
|
uint64_t advertisementDataSize = strlen(packets[num_packets].advertisementData);
|
|
|
|
uint64_t packetCountSize = strlen(packets[num_packets].packetCount);
|
2023-11-01 06:46:41 -04:00
|
|
|
|
2023-11-02 12:32:29 -04:00
|
|
|
packets[num_packets].packet_count = stringToUint32(packets[num_packets].packetCount);
|
2023-11-01 06:46:41 -04:00
|
|
|
|
2023-11-02 12:32:29 -04:00
|
|
|
// Verify Data.
|
|
|
|
if ((macAddressSize == mac_address_size_str) && (advertisementDataSize < max_packet_size_str) && (packetCountSize < max_packet_repeat_str) &&
|
2023-11-16 15:28:22 -05:00
|
|
|
hasValidHexPairs(packets[num_packets].macAddress, macAddressSize / 2) && hasValidHexPairs(packets[num_packets].advertisementData, advertisementDataSize / 2) && (packets[num_packets].packet_count >= 1) && (packets[num_packets].packet_count < max_packet_repeat_count)) {
|
2023-11-02 12:32:29 -04:00
|
|
|
text_filename.set(truncate(file_path.filename().string(), 12));
|
2023-11-01 06:46:41 -04:00
|
|
|
|
2023-11-02 12:32:29 -04:00
|
|
|
} else {
|
|
|
|
// Did not find any packets.
|
|
|
|
if (num_packets == 0) {
|
|
|
|
file_path = "";
|
|
|
|
return;
|
|
|
|
}
|
2023-11-01 06:46:41 -04:00
|
|
|
|
2023-11-02 12:32:29 -04:00
|
|
|
break;
|
|
|
|
}
|
2023-11-01 06:46:41 -04:00
|
|
|
|
2023-11-02 12:32:29 -04:00
|
|
|
num_packets++;
|
2023-11-01 06:46:41 -04:00
|
|
|
|
2023-11-02 12:32:29 -04:00
|
|
|
} while (num_packets < max_num_packets);
|
2023-11-01 06:46:41 -04:00
|
|
|
|
2023-11-11 14:46:51 -05:00
|
|
|
update_current_packet(packets[0], 0);
|
2023-11-01 06:46:41 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-06 13:09:26 -05:00
|
|
|
void BLETxView::on_save_file(const std::string value) {
|
|
|
|
auto folder = packet_save_path.parent_path();
|
|
|
|
auto ext = packet_save_path.extension();
|
|
|
|
auto new_path = folder / value + ext;
|
|
|
|
|
|
|
|
saveFile(new_path);
|
|
|
|
}
|
|
|
|
|
2023-11-01 06:46:41 -04:00
|
|
|
void BLETxView::on_data(uint32_t value, bool is_data) {
|
|
|
|
std::string str_console = "";
|
|
|
|
|
|
|
|
if (is_data) {
|
|
|
|
str_console += (char)(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-11 14:46:51 -05:00
|
|
|
void BLETxView::update_current_packet(BLETxPacket packet, uint32_t currentIndex) {
|
2023-11-02 12:32:29 -04:00
|
|
|
std::string formattedMacAddress = to_string_formatted_mac_address(packet.macAddress);
|
|
|
|
|
|
|
|
std::vector<std::string> strings = splitIntoStrings(packet.advertisementData);
|
|
|
|
|
|
|
|
text_packet_index.set(to_string_dec_uint(current_packet));
|
|
|
|
|
|
|
|
text_packets_sent.set(to_string_dec_uint(packet.packet_count));
|
|
|
|
|
|
|
|
text_mac_address.set(formattedMacAddress);
|
|
|
|
|
2023-11-29 12:54:17 -05:00
|
|
|
packet_counter = packet.packet_count;
|
|
|
|
current_packet = currentIndex;
|
|
|
|
|
|
|
|
dataFile.create(dataTempFilePath);
|
2023-11-02 12:32:29 -04:00
|
|
|
|
|
|
|
for (const std::string& str : strings) {
|
2023-11-29 12:54:17 -05:00
|
|
|
dataFile.write(str.c_str(), str.size());
|
|
|
|
dataFile.write("\n", 1);
|
|
|
|
;
|
2023-11-02 12:32:29 -04:00
|
|
|
}
|
2023-11-11 14:46:51 -05:00
|
|
|
|
2023-11-29 12:54:17 -05:00
|
|
|
dataFile.~File();
|
|
|
|
|
|
|
|
auto result = FileWrapper::open(dataTempFilePath);
|
|
|
|
|
|
|
|
if (!result)
|
|
|
|
return;
|
|
|
|
|
|
|
|
dataFileWrapper = *std::move(result);
|
|
|
|
|
|
|
|
dataEditView.set_font_zoom(true);
|
|
|
|
dataEditView.set_file(*dataFileWrapper);
|
2023-11-30 15:57:22 -05:00
|
|
|
dataEditView.redraw(true, true);
|
2023-11-02 12:32:29 -04:00
|
|
|
}
|
|
|
|
|
2023-11-01 06:46:41 -04:00
|
|
|
void BLETxView::set_parent_rect(const Rect new_parent_rect) {
|
|
|
|
View::set_parent_rect(new_parent_rect);
|
2023-11-03 03:08:49 -04:00
|
|
|
const Rect content_rect{0, header_height, new_parent_rect.width(), new_parent_rect.height() - header_height - switch_button_height};
|
2023-11-29 12:54:17 -05:00
|
|
|
dataEditView.set_parent_rect(content_rect);
|
2023-11-01 06:46:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
BLETxView::~BLETxView() {
|
2023-11-29 12:54:17 -05:00
|
|
|
delete_file(dataTempFilePath);
|
2023-11-01 06:46:41 -04:00
|
|
|
transmitter_model.disable();
|
|
|
|
baseband::shutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace ui */
|