Send on select (#1557)

* fixed bug not fully displaying rx packet
* added sending selected packet
* setting packet count to 100 as 1 is too aggressive for speed > 2
* setting limit to 50 as 50 does not bog down UI at speed 5.
* fix tx channel getting out of sync with freq
This commit is contained in:
Netro 2023-11-06 05:16:01 -05:00 committed by GitHub
parent 2b7962fa7c
commit adabbfbef1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 54 additions and 16 deletions

View File

@ -75,7 +75,7 @@ void RecentEntriesTable<BleRecentEntries>::draw(
line = truncate(line, 17); line = truncate(line, 17);
} }
} else { } else {
line = to_string_mac_address(entry.packetData.macAddress, 6); line = to_string_mac_address(entry.packetData.macAddress, 6, false);
} }
// Pushing single digit values down right justified. // Pushing single digit values down right justified.
@ -100,15 +100,21 @@ BleRecentEntryDetailView::BleRecentEntryDetailView(NavigationView& nav, const Bl
: nav_{nav}, : nav_{nav},
entry_{entry} { entry_{entry} {
add_children({&button_done, add_children({&button_done,
&button_send,
&label_mac_address, &label_mac_address,
&text_mac_address, &text_mac_address,
&labels}); &labels});
text_mac_address.set(to_string_mac_address(entry.packetData.macAddress, 6)); text_mac_address.set(to_string_mac_address(entry.packetData.macAddress, 6, false));
button_done.on_select = [this](const ui::Button&) { button_done.on_select = [this](const ui::Button&) {
nav_.pop(); nav_.pop();
}; };
button_send.on_select = [this](const ui::Button&) {
nav_.set_on_pop([this]() { launch_bletx(entry_); });
nav_.pop();
};
} }
void BleRecentEntryDetailView::update_data() { void BleRecentEntryDetailView::update_data() {
@ -180,7 +186,7 @@ void BleRecentEntryDetailView::paint(Painter& painter) {
if (number_data_lines > 1) { if (number_data_lines > 1) {
for (k = 1; k < number_data_lines; k++) { for (k = 1; k < number_data_lines; k++) {
if (data_strings[k].empty()) { if (!data_strings[k].empty()) {
field_rect = draw_field(painter, field_rect, s, "", pad_string_with_spaces(5) + data_strings[k]); field_rect = draw_field(painter, field_rect, s, "", pad_string_with_spaces(5) + data_strings[k]);
} }
} }
@ -193,6 +199,18 @@ void BleRecentEntryDetailView::set_entry(const BleRecentEntry& entry) {
set_dirty(); set_dirty();
} }
void BleRecentEntryDetailView::launch_bletx(BleRecentEntry packetEntry) {
BLETxPacket bleTxPacket;
std::string macAddressStr = to_string_mac_address(packetEntry.packetData.macAddress, 6, true);
strncpy(bleTxPacket.macAddress, macAddressStr.c_str(), 13);
strncpy(bleTxPacket.advertisementData, packetEntry.dataString.c_str(), (packetEntry.packetData.dataLen * 2) + 1);
bleTxPacket.packet_count = 50;
nav_.replace<BLETxView>(bleTxPacket);
}
static std::uint64_t get_freq_by_channel_number(uint8_t channel_number) { static std::uint64_t get_freq_by_channel_number(uint8_t channel_number) {
uint64_t freq_hz; uint64_t freq_hz;
@ -390,7 +408,7 @@ void BLERxView::on_data(BlePacketData* packet) {
str_console += "\n"; str_console += "\n";
str_console += "Mac:"; str_console += "Mac:";
str_console += to_string_mac_address(packet->macAddress, 6); str_console += to_string_mac_address(packet->macAddress, 6, false);
str_console += "\n"; str_console += "\n";
str_console += "Data:"; str_console += "Data:";

View File

@ -118,6 +118,7 @@ class BleRecentEntryDetailView : public View {
private: private:
NavigationView& nav_; NavigationView& nav_;
BleRecentEntry entry_{}; BleRecentEntry entry_{};
void launch_bletx(BleRecentEntry packetEntry);
static constexpr uint8_t total_data_lines{5}; static constexpr uint8_t total_data_lines{5};
@ -134,6 +135,10 @@ class BleRecentEntryDetailView : public View {
{{10 * 8, 2 * 16}, "Value", Color::light_grey()}, {{10 * 8, 2 * 16}, "Value", Color::light_grey()},
}; };
Button button_send{
{19, 224, 96, 24},
"Send"};
Button button_done{ Button button_done{
{125, 224, 96, 24}, {125, 224, 96, 24},
"Done"}; "Done"};

View File

@ -189,7 +189,7 @@ void BLETxView::start() {
File data_file; File data_file;
auto error = data_file.open(file_path); auto error = data_file.open(file_path);
if (error) { if (error && !file_override) {
file_error(); file_error();
check_loop.set_value(false); check_loop.set_value(false);
return; return;
@ -309,6 +309,8 @@ BLETxView::BLETxView(NavigationView& nav)
}; };
options_speed.set_selected_index(0); options_speed.set_selected_index(0);
options_channel.set_selected_index(0);
options_adv_type.set_selected_index(0);
check_rand_mac.set_value(false); check_rand_mac.set_value(false);
check_rand_mac.on_select = [this](Checkbox&, bool v) { check_rand_mac.on_select = [this](Checkbox&, bool v) {
@ -330,6 +332,17 @@ BLETxView::BLETxView(NavigationView& nav)
}; };
} }
BLETxView::BLETxView(
NavigationView& nav,
BLETxPacket packet)
: BLETxView(nav) {
packets[0] = packet;
update_packet_display(packets[0]);
num_packets = 1;
file_override = true;
}
void BLETxView::on_file_changed(const fs::path& new_file_path) { void BLETxView::on_file_changed(const fs::path& new_file_path) {
file_path = fs::path(u"/") + new_file_path; file_path = fs::path(u"/") + new_file_path;
num_packets = 0; num_packets = 0;
@ -357,7 +370,7 @@ void BLETxView::on_file_changed(const fs::path& new_file_path) {
// Verify Data. // Verify Data.
if ((macAddressSize == mac_address_size_str) && (advertisementDataSize < max_packet_size_str) && (packetCountSize < max_packet_repeat_str) && if ((macAddressSize == mac_address_size_str) && (advertisementDataSize < max_packet_size_str) && (packetCountSize < max_packet_repeat_str) &&
hasValidHexPairs(packets[num_packets].macAddress, macAddressSize / 2) && hasValidHexPairs(packets[num_packets].advertisementData, advertisementDataSize / 2) && (packets[num_packets].packet_count > 0) && (packets[num_packets].packet_count < max_packet_repeat_count)) { hasValidHexPairs(packets[num_packets].macAddress, macAddressSize / 2) && hasValidHexPairs(packets[num_packets].advertisementData, advertisementDataSize / 2) && (packets[num_packets].packet_count >= 50) && (packets[num_packets].packet_count < max_packet_repeat_count)) {
text_filename.set(truncate(file_path.filename().string(), 12)); text_filename.set(truncate(file_path.filename().string(), 12));
} else { } else {

View File

@ -55,9 +55,17 @@ class BLELoggerTx {
namespace ui { namespace ui {
struct BLETxPacket {
char macAddress[13];
char advertisementData[63];
char packetCount[11];
uint32_t packet_count;
};
class BLETxView : public View { class BLETxView : public View {
public: public:
BLETxView(NavigationView& nav); BLETxView(NavigationView& nav);
BLETxView(NavigationView& nav, BLETxPacket packet);
~BLETxView(); ~BLETxView();
void set_parent_rect(const Rect new_parent_rect) override; void set_parent_rect(const Rect new_parent_rect) override;
@ -74,13 +82,6 @@ class BLETxView : public View {
std::string title() const override { return "BLE TX"; }; std::string title() const override { return "BLE TX"; };
struct BLETxPacket {
char macAddress[13];
char advertisementData[63];
char packetCount[11];
uint32_t packet_count;
};
private: private:
void on_data(uint32_t value, bool is_data); void on_data(uint32_t value, bool is_data);
void on_tx_progress(const bool done); void on_tx_progress(const bool done);
@ -112,6 +113,7 @@ class BLETxView : public View {
uint32_t num_packets{0}; uint32_t num_packets{0};
uint32_t current_packet{0}; uint32_t current_packet{0};
bool random_mac = false; bool random_mac = false;
bool file_override = false;
enum PKT_TYPE { enum PKT_TYPE {
INVALID_TYPE, INVALID_TYPE,

View File

@ -311,13 +311,13 @@ std::string to_string_file_size(uint32_t file_size) {
return to_string_dec_uint(file_size) + suffix[suffix_index]; return to_string_dec_uint(file_size) + suffix[suffix_index];
} }
std::string to_string_mac_address(const uint8_t* macAddress, uint8_t length) { std::string to_string_mac_address(const uint8_t* macAddress, uint8_t length, bool noColon) {
std::string string; std::string string;
string += to_string_hex(macAddress[0], 2); string += to_string_hex(macAddress[0], 2);
for (int i = 1; i < length; i++) { for (int i = 1; i < length; i++) {
string += ":" + to_string_hex(macAddress[i], 2); string += noColon ? to_string_hex(macAddress[i], 2) : ":" + to_string_hex(macAddress[i], 2);
} }
return string; return string;

View File

@ -77,7 +77,7 @@ std::string to_string_FAT_timestamp(const FATTimestamp& timestamp);
std::string to_string_file_size(uint32_t file_size); std::string to_string_file_size(uint32_t file_size);
// Converts Mac Address to string. // Converts Mac Address to string.
std::string to_string_mac_address(const uint8_t* macAddress, uint8_t length); std::string to_string_mac_address(const uint8_t* macAddress, uint8_t length, bool noColon);
std::string to_string_formatted_mac_address(const char* macAddress); std::string to_string_formatted_mac_address(const char* macAddress);
/* Scales 'n' to be a value less than 1000. 'base_unit' is the index of the unit from /* Scales 'n' to be a value less than 1000. 'base_unit' is the index of the unit from