From 43b1d209e5ed91c8b709c4a300a0323fd25c85ca Mon Sep 17 00:00:00 2001 From: Netro Date: Thu, 9 Nov 2023 14:12:43 -0500 Subject: [PATCH 01/19] Showing highest dB first --- firmware/application/apps/ble_rx_app.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firmware/application/apps/ble_rx_app.cpp b/firmware/application/apps/ble_rx_app.cpp index f538d1fed..609baf325 100644 --- a/firmware/application/apps/ble_rx_app.cpp +++ b/firmware/application/apps/ble_rx_app.cpp @@ -542,9 +542,9 @@ void BLERxView::updateEntry(const BlePacketData* packet, BleRecentEntry& entry) break; case 2: sortEntriesBy( - recent, [](const BleRecentEntry& entry) { return entry.dbValue; }, true); + recent, [](const BleRecentEntry& entry) { return entry.dbValue; }, false); sortEntriesBy( - filterEntries, [](const BleRecentEntry& entry) { return entry.dbValue; }, true); + filterEntries, [](const BleRecentEntry& entry) { return entry.dbValue; }, false); break; case 3: sortEntriesBy( From b96834e84607b5b321bd1f9d10bed6a7e211f900 Mon Sep 17 00:00:00 2001 From: Netro Date: Thu, 9 Nov 2023 14:47:17 -0500 Subject: [PATCH 02/19] Including namestring in search --- firmware/application/apps/ble_rx_app.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/application/apps/ble_rx_app.cpp b/firmware/application/apps/ble_rx_app.cpp index 609baf325..f8345a69e 100644 --- a/firmware/application/apps/ble_rx_app.cpp +++ b/firmware/application/apps/ble_rx_app.cpp @@ -442,7 +442,7 @@ void BLERxView::on_switch_table(const std::string value) { if (!value.empty()) { removeEntriesWithoutKey(recent, filterEntries, [&value](const BleRecentEntry& entry) { - return entry.dataString.find(value) == std::string::npos; + return (entry.dataString.find(value) == std::string::npos) && (entry.nameString.find(value) == std::string::npos); }); recent_entries_view.set_dirty(); From 0bf0a5d95cdf5e1e70ef65155799d18701229563 Mon Sep 17 00:00:00 2001 From: TJ Baginski Date: Thu, 9 Nov 2023 19:58:00 -0500 Subject: [PATCH 03/19] Using replace seems to work better. --- firmware/application/apps/ble_rx_app.cpp | 3 +-- firmware/application/apps/ble_tx_app.cpp | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/firmware/application/apps/ble_rx_app.cpp b/firmware/application/apps/ble_rx_app.cpp index f8345a69e..799d4ac3f 100644 --- a/firmware/application/apps/ble_rx_app.cpp +++ b/firmware/application/apps/ble_rx_app.cpp @@ -285,7 +285,7 @@ BLERxView::BLERxView(NavigationView& nav) }; button_switch.on_select = [this, &nav](Button&) { - nav_.set_on_pop([this]() { nav_.push(); }); + nav_.set_on_pop([this]() { nav_.replace(); }); nav_.pop(); }; @@ -428,7 +428,6 @@ void BLERxView::on_data(BlePacketData* packet) { // Start of Packet stuffing. // Masking off the top 2 bytes to avoid invalid keys. auto& entry = ::on_packet(recent, macAddressEncoded & 0xFFFFFFFFFFFF); - truncate_entries(recent, 32); updateEntry(packet, entry); // Log at End of Packet. diff --git a/firmware/application/apps/ble_tx_app.cpp b/firmware/application/apps/ble_tx_app.cpp index 5aa1ef077..0f9c404e2 100644 --- a/firmware/application/apps/ble_tx_app.cpp +++ b/firmware/application/apps/ble_tx_app.cpp @@ -365,7 +365,7 @@ BLETxView::BLETxView(NavigationView& nav) }; button_switch.on_select = [this, &nav](Button&) { - nav_.set_on_pop([this]() { nav_.push(); }); + nav_.set_on_pop([this]() { nav_.replace(); }); nav_.pop(); }; } From 5bda0fb67e927fe001d5e8526c46618df3312d80 Mon Sep 17 00:00:00 2001 From: TJ Baginski Date: Thu, 9 Nov 2023 20:34:35 -0500 Subject: [PATCH 04/19] bletx cleanup --- firmware/application/apps/ble_tx_app.cpp | 29 ++++++++++-------------- firmware/application/apps/ble_tx_app.hpp | 4 ++-- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/firmware/application/apps/ble_tx_app.cpp b/firmware/application/apps/ble_tx_app.cpp index 0f9c404e2..0522ab24d 100644 --- a/firmware/application/apps/ble_tx_app.cpp +++ b/firmware/application/apps/ble_tx_app.cpp @@ -219,11 +219,10 @@ void BLETxView::start() { return; } else { // Send first or single packet. - packet_counter = packets[current_packet].packet_count; - progressbar.set_max(packets[current_packet].packet_count); + progressbar.set_max(packets[0].packet_count); button_play.set_bitmap(&bitmap_stop); - baseband::set_btletx(channel_number, random_mac ? randomMac : packets[current_packet].macAddress, packets[current_packet].advertisementData, pduType); + baseband::set_btletx(channel_number, random_mac ? randomMac : packets[0].macAddress, packets[0].advertisementData, pduType); transmitter_model.enable(); is_running = true; @@ -238,7 +237,6 @@ void BLETxView::start() { } packet_counter--; - progressbar.set_value(packets[current_packet].packet_count - packet_counter); } @@ -248,10 +246,7 @@ void BLETxView::stop() { button_play.set_bitmap(&bitmap_play); check_loop.set_value(false); - current_packet = 0; - text_packets_sent.set(to_string_dec_uint(packets[0].packet_count)); - packet_counter = packets[0].packet_count; - update_packet_display(packets[0]); + update_current_packet(packets[0], 0); is_running = false; } @@ -265,16 +260,13 @@ void BLETxView::on_tx_progress(const bool done) { if (current_packet == (num_packets - 1)) { // If looping, restart from beginning. if (check_loop.value()) { - current_packet = 0; - packet_counter = packets[current_packet].packet_count; - update_packet_display(packets[current_packet]); + update_current_packet(packets[current_packet], 0); } else { stop(); } } else { current_packet++; - packet_counter = packets[current_packet].packet_count; - update_packet_display(packets[current_packet]); + update_current_packet(packets[current_packet], current_packet); } } else { if ((timer_count % timer_period) == 0) { @@ -375,7 +367,8 @@ BLETxView::BLETxView( BLETxPacket packet) : BLETxView(nav) { packets[0] = packet; - update_packet_display(packets[0]); + + update_current_packet(packets[0], 0); num_packets = 1; file_override = true; @@ -404,7 +397,6 @@ void BLETxView::on_file_changed(const fs::path& new_file_path) { uint64_t packetCountSize = strlen(packets[num_packets].packetCount); packets[num_packets].packet_count = stringToUint32(packets[num_packets].packetCount); - packet_counter = packets[num_packets].packet_count; // Verify Data. if ((macAddressSize == mac_address_size_str) && (advertisementDataSize < max_packet_size_str) && (packetCountSize < max_packet_repeat_str) && @@ -425,7 +417,7 @@ void BLETxView::on_file_changed(const fs::path& new_file_path) { } while (num_packets < max_num_packets); - update_packet_display(packets[0]); + update_current_packet(packets[0], 0); } } @@ -447,7 +439,7 @@ void BLETxView::on_data(uint32_t value, bool is_data) { console.write(str_console); } -void BLETxView::update_packet_display(BLETxPacket packet) { +void BLETxView::update_current_packet(BLETxPacket packet, uint32_t currentIndex) { std::string formattedMacAddress = to_string_formatted_mac_address(packet.macAddress); std::vector strings = splitIntoStrings(packet.advertisementData); @@ -463,6 +455,9 @@ void BLETxView::update_packet_display(BLETxPacket packet) { for (const std::string& str : strings) { console.writeln(str); } + + packet_counter = packet.packet_count; + current_packet = currentIndex; } void BLETxView::set_parent_rect(const Rect new_parent_rect) { diff --git a/firmware/application/apps/ble_tx_app.hpp b/firmware/application/apps/ble_tx_app.hpp index 75612fb82..63d7b66aa 100644 --- a/firmware/application/apps/ble_tx_app.hpp +++ b/firmware/application/apps/ble_tx_app.hpp @@ -85,10 +85,10 @@ class BLETxView : public View { private: void on_data(uint32_t value, bool is_data); - void on_tx_progress(const bool done); void on_file_changed(const std::filesystem::path& new_file_path); - void update_packet_display(BLETxPacket packet); void on_save_file(const std::string value); + void on_tx_progress(const bool done); + void update_current_packet(BLETxPacket packet, uint32_t currentIndex); NavigationView& nav_; TxRadioState radio_state_{ From 0eb7c3bc169d97339ffa1ea69b8b57e439d5cead Mon Sep 17 00:00:00 2001 From: TJ Baginski Date: Thu, 9 Nov 2023 22:09:51 -0500 Subject: [PATCH 05/19] More cleanup --- firmware/application/apps/ble_rx_app.cpp | 136 ++++++++++------------- firmware/application/apps/ble_rx_app.hpp | 1 + firmware/application/recent_entries.hpp | 2 +- 3 files changed, 59 insertions(+), 80 deletions(-) diff --git a/firmware/application/apps/ble_rx_app.cpp b/firmware/application/apps/ble_rx_app.cpp index 799d4ac3f..4c0d7d939 100644 --- a/firmware/application/apps/ble_rx_app.cpp +++ b/firmware/application/apps/ble_rx_app.cpp @@ -308,44 +308,8 @@ BLERxView::BLERxView(NavigationView& nav) baseband::set_btlerx(channel_number); }; - options_sort.on_change = [this](size_t, int32_t i) { - switch (i) { - case 0: - sortEntriesBy( - recent, [](const BleRecentEntry& entry) { return entry.macAddress; }, true); - sortEntriesBy( - filterEntries, [](const BleRecentEntry& entry) { return entry.macAddress; }, true); - break; - case 1: - sortEntriesBy( - recent, [](const BleRecentEntry& entry) { return entry.numHits; }, false); - sortEntriesBy( - filterEntries, [](const BleRecentEntry& entry) { return entry.numHits; }, false); - break; - case 2: - sortEntriesBy( - recent, [](const BleRecentEntry& entry) { return entry.dbValue; }, true); - sortEntriesBy( - filterEntries, [](const BleRecentEntry& entry) { return entry.dbValue; }, true); - break; - case 3: - sortEntriesBy( - recent, [](const BleRecentEntry& entry) { return entry.timestamp; }, false); - sortEntriesBy( - filterEntries, [](const BleRecentEntry& entry) { return entry.timestamp; }, false); - break; - case 4: - sortEntriesBy( - recent, [](const BleRecentEntry& entry) { return entry.nameString; }, true); - sortEntriesBy( - filterEntries, [](const BleRecentEntry& entry) { return entry.nameString; }, true); - break; - default: - break; - } - - recent_entries_view.set_dirty(); - recent_entries_filter_view.set_dirty(); + options_sort.on_change = [this](size_t, int32_t index) { + handle_entries_sort(index); }; options_channel.set_selected_index(0, true); @@ -430,6 +394,15 @@ void BLERxView::on_data(BlePacketData* packet) { auto& entry = ::on_packet(recent, macAddressEncoded & 0xFFFFFFFFFFFF); updateEntry(packet, entry); + //Add entries if they meet the criteria. + if ((entry.dataString.find(filter) != std::string::npos) || (entry.nameString.find(filter) != std::string::npos)) + { + auto& filteredEntry = ::on_packet(filterEntries, macAddressEncoded & 0xFFFFFFFFFFFF); + updateEntry(packet, filteredEntry); + } + + handle_entries_sort(options_sort.selected_index()); + // Log at End of Packet. if (logger && logging) { logger->log_raw_data(str_console); @@ -437,21 +410,63 @@ void BLERxView::on_data(BlePacketData* packet) { } void BLERxView::on_switch_table(const std::string value) { - filter = value; - if (!value.empty()) { - removeEntriesWithoutKey(recent, filterEntries, [&value](const BleRecentEntry& entry) { + //New filter? Reset list from recent entries. + if (filter != value) + { + filterEntries = BleRecentEntries {}; + resetFilteredEntries(recent, filterEntries, [&value](const BleRecentEntry& entry) { return (entry.dataString.find(value) == std::string::npos) && (entry.nameString.find(value) == std::string::npos); }); + } - recent_entries_view.set_dirty(); + filter = value; + if (!value.empty()) { recent_entries_filter_view.hidden(false); recent_entries_view.hidden(true); } else { recent_entries_view.hidden(false); recent_entries_filter_view.hidden(true); } +} + +void BLERxView::handle_entries_sort(uint8_t index) +{ + switch (index) { + case 0: + sortEntriesBy( + recent, [](const BleRecentEntry& entry) { return entry.macAddress; }, true); + sortEntriesBy( + filterEntries, [](const BleRecentEntry& entry) { return entry.macAddress; }, true); + break; + case 1: + sortEntriesBy( + recent, [](const BleRecentEntry& entry) { return entry.numHits; }, false); + sortEntriesBy( + filterEntries, [](const BleRecentEntry& entry) { return entry.numHits; }, false); + break; + case 2: + sortEntriesBy( + recent, [](const BleRecentEntry& entry) { return entry.dbValue; }, false); + sortEntriesBy( + filterEntries, [](const BleRecentEntry& entry) { return entry.dbValue; }, false); + break; + case 3: + sortEntriesBy( + recent, [](const BleRecentEntry& entry) { return entry.timestamp; }, false); + sortEntriesBy( + filterEntries, [](const BleRecentEntry& entry) { return entry.timestamp; }, false); + break; + case 4: + sortEntriesBy( + recent, [](const BleRecentEntry& entry) { return entry.nameString; }, true); + sortEntriesBy( + filterEntries, [](const BleRecentEntry& entry) { return entry.nameString; }, true); + break; + default: + break; + } recent_entries_view.set_dirty(); recent_entries_filter_view.set_dirty(); @@ -526,43 +541,6 @@ void BLERxView::updateEntry(const BlePacketData* packet, BleRecentEntry& entry) } } - switch (options_sort.selected_index()) { - case 0: - sortEntriesBy( - recent, [](const BleRecentEntry& entry) { return entry.macAddress; }, true); - sortEntriesBy( - filterEntries, [](const BleRecentEntry& entry) { return entry.macAddress; }, true); - break; - case 1: - sortEntriesBy( - recent, [](const BleRecentEntry& entry) { return entry.numHits; }, false); - sortEntriesBy( - filterEntries, [](const BleRecentEntry& entry) { return entry.numHits; }, false); - break; - case 2: - sortEntriesBy( - recent, [](const BleRecentEntry& entry) { return entry.dbValue; }, false); - sortEntriesBy( - filterEntries, [](const BleRecentEntry& entry) { return entry.dbValue; }, false); - break; - case 3: - sortEntriesBy( - recent, [](const BleRecentEntry& entry) { return entry.timestamp; }, false); - sortEntriesBy( - filterEntries, [](const BleRecentEntry& entry) { return entry.timestamp; }, false); - break; - case 4: - sortEntriesBy( - recent, [](const BleRecentEntry& entry) { return entry.nameString; }, true); - sortEntriesBy( - filterEntries, [](const BleRecentEntry& entry) { return entry.nameString; }, true); - break; - default: - break; - } - - on_switch_table(filter); - // TODO: Crude hack, should be a more formal listener arrangement... if (entry.key() == recent_entry_detail_view.entry().key()) { recent_entry_detail_view.set_entry(entry); diff --git a/firmware/application/apps/ble_rx_app.hpp b/firmware/application/apps/ble_rx_app.hpp index f30faa28a..90cdcabf8 100644 --- a/firmware/application/apps/ble_rx_app.hpp +++ b/firmware/application/apps/ble_rx_app.hpp @@ -168,6 +168,7 @@ class BLERxView : public View { private: void on_data(BlePacketData* packetData); void on_switch_table(const std::string value); + void handle_entries_sort(uint8_t index); void updateEntry(const BlePacketData* packet, BleRecentEntry& entry); NavigationView& nav_; diff --git a/firmware/application/recent_entries.hpp b/firmware/application/recent_entries.hpp index 0338d216f..e6cb435a0 100644 --- a/firmware/application/recent_entries.hpp +++ b/firmware/application/recent_entries.hpp @@ -96,7 +96,7 @@ void sortEntriesBy(ContainerType& entries, KeySelector keySelector, SortOrder as } template -void removeEntriesWithoutKey(ContainerType& entries, ContainerType& filteredEntries, KeySelector keySelector) { +void resetFilteredEntries(ContainerType& entries, ContainerType& filteredEntries, KeySelector keySelector) { // Clear the filteredEntries container filteredEntries.clear(); From a23fe6af5dbecba06b3af642657d21278fe6101a Mon Sep 17 00:00:00 2001 From: TJ Baginski Date: Thu, 9 Nov 2023 22:10:23 -0500 Subject: [PATCH 06/19] clang formatting. --- firmware/application/apps/ble_rx_app.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/firmware/application/apps/ble_rx_app.cpp b/firmware/application/apps/ble_rx_app.cpp index 4c0d7d939..95084ca5d 100644 --- a/firmware/application/apps/ble_rx_app.cpp +++ b/firmware/application/apps/ble_rx_app.cpp @@ -394,9 +394,8 @@ void BLERxView::on_data(BlePacketData* packet) { auto& entry = ::on_packet(recent, macAddressEncoded & 0xFFFFFFFFFFFF); updateEntry(packet, entry); - //Add entries if they meet the criteria. - if ((entry.dataString.find(filter) != std::string::npos) || (entry.nameString.find(filter) != std::string::npos)) - { + // Add entries if they meet the criteria. + if ((entry.dataString.find(filter) != std::string::npos) || (entry.nameString.find(filter) != std::string::npos)) { auto& filteredEntry = ::on_packet(filterEntries, macAddressEncoded & 0xFFFFFFFFFFFF); updateEntry(packet, filteredEntry); } @@ -410,11 +409,9 @@ void BLERxView::on_data(BlePacketData* packet) { } void BLERxView::on_switch_table(const std::string value) { - - //New filter? Reset list from recent entries. - if (filter != value) - { - filterEntries = BleRecentEntries {}; + // New filter? Reset list from recent entries. + if (filter != value) { + filterEntries = BleRecentEntries{}; resetFilteredEntries(recent, filterEntries, [&value](const BleRecentEntry& entry) { return (entry.dataString.find(value) == std::string::npos) && (entry.nameString.find(value) == std::string::npos); }); @@ -431,8 +428,7 @@ void BLERxView::on_switch_table(const std::string value) { } } -void BLERxView::handle_entries_sort(uint8_t index) -{ +void BLERxView::handle_entries_sort(uint8_t index) { switch (index) { case 0: sortEntriesBy( From 29d605c23dfb36a3a05566d5d4c9be89edd096e7 Mon Sep 17 00:00:00 2001 From: TJ Baginski Date: Thu, 9 Nov 2023 22:41:03 -0500 Subject: [PATCH 07/19] removing pop --- firmware/application/apps/ble_rx_app.cpp | 6 ++---- firmware/application/apps/ble_tx_app.cpp | 3 +-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/firmware/application/apps/ble_rx_app.cpp b/firmware/application/apps/ble_rx_app.cpp index 95084ca5d..e49fcdd04 100644 --- a/firmware/application/apps/ble_rx_app.cpp +++ b/firmware/application/apps/ble_rx_app.cpp @@ -112,8 +112,7 @@ BleRecentEntryDetailView::BleRecentEntryDetailView(NavigationView& nav, const Bl }; button_send.on_select = [this](const ui::Button&) { - nav_.set_on_pop([this]() { launch_bletx(entry_); }); - nav_.pop(); + launch_bletx(entry_); }; } @@ -285,8 +284,7 @@ BLERxView::BLERxView(NavigationView& nav) }; button_switch.on_select = [this, &nav](Button&) { - nav_.set_on_pop([this]() { nav_.replace(); }); - nav_.pop(); + nav_.replace(); }; field_frequency.set_step(0); diff --git a/firmware/application/apps/ble_tx_app.cpp b/firmware/application/apps/ble_tx_app.cpp index 0522ab24d..bb75c69d9 100644 --- a/firmware/application/apps/ble_tx_app.cpp +++ b/firmware/application/apps/ble_tx_app.cpp @@ -357,8 +357,7 @@ BLETxView::BLETxView(NavigationView& nav) }; button_switch.on_select = [this, &nav](Button&) { - nav_.set_on_pop([this]() { nav_.replace(); }); - nav_.pop(); + nav_.replace(); }; } From 56a68e557931ff67fa76a9d98fb96dd7a18d2926 Mon Sep 17 00:00:00 2001 From: TJ Baginski Date: Thu, 9 Nov 2023 22:49:55 -0500 Subject: [PATCH 08/19] pop is needed on this view. --- firmware/application/apps/ble_rx_app.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/firmware/application/apps/ble_rx_app.cpp b/firmware/application/apps/ble_rx_app.cpp index e49fcdd04..aee5f5fa9 100644 --- a/firmware/application/apps/ble_rx_app.cpp +++ b/firmware/application/apps/ble_rx_app.cpp @@ -112,7 +112,8 @@ BleRecentEntryDetailView::BleRecentEntryDetailView(NavigationView& nav, const Bl }; button_send.on_select = [this](const ui::Button&) { - launch_bletx(entry_); + nav_.set_on_pop([this]() { launch_bletx(entry_); }); + nav_.pop(); }; } From 0fba4a958604a55291c18aa334c964d73c3fd4ec Mon Sep 17 00:00:00 2001 From: TJ Baginski Date: Fri, 10 Nov 2023 00:32:28 -0500 Subject: [PATCH 09/19] cleanup switching --- firmware/application/apps/ble_rx_app.cpp | 25 ++++++++++-------------- firmware/application/apps/ble_rx_app.hpp | 6 +++--- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/firmware/application/apps/ble_rx_app.cpp b/firmware/application/apps/ble_rx_app.cpp index aee5f5fa9..de5be6f00 100644 --- a/firmware/application/apps/ble_rx_app.cpp +++ b/firmware/application/apps/ble_rx_app.cpp @@ -22,7 +22,6 @@ */ #include "ble_rx_app.hpp" -#include "ble_tx_app.hpp" #include "ui_modemsetup.hpp" @@ -65,6 +64,7 @@ void RecentEntriesTable::draw( Painter& painter, const Style& style) { std::string line{}; + line.reserve(30); if (!entry.nameString.empty()) { line = entry.nameString; @@ -112,7 +112,10 @@ BleRecentEntryDetailView::BleRecentEntryDetailView(NavigationView& nav, const Bl }; button_send.on_select = [this](const ui::Button&) { - nav_.set_on_pop([this]() { launch_bletx(entry_); }); + auto packetToSend = build_packet(); + nav_.set_on_pop([packetToSend, this]() { + nav_.replace(packetToSend); + }); nav_.pop(); }; } @@ -199,18 +202,18 @@ void BleRecentEntryDetailView::set_entry(const BleRecentEntry& entry) { set_dirty(); } -void BleRecentEntryDetailView::launch_bletx(BleRecentEntry packetEntry) { +BLETxPacket BleRecentEntryDetailView::build_packet() { BLETxPacket bleTxPacket; memset(&bleTxPacket, 0, sizeof(BLETxPacket)); - std::string macAddressStr = to_string_mac_address(packetEntry.packetData.macAddress, 6, true); + std::string macAddressStr = to_string_mac_address(entry_.packetData.macAddress, 6, true); strncpy(bleTxPacket.macAddress, macAddressStr.c_str(), 12); - strncpy(bleTxPacket.advertisementData, packetEntry.dataString.c_str(), packetEntry.packetData.dataLen * 2); + strncpy(bleTxPacket.advertisementData, entry_.dataString.c_str(), entry_.packetData.dataLen * 2); strncpy(bleTxPacket.packetCount, "50", 3); bleTxPacket.packet_count = 50; - nav_.replace(bleTxPacket); + return bleTxPacket; } static std::uint64_t get_freq_by_channel_number(uint8_t channel_number) { @@ -260,10 +263,8 @@ BLERxView::BLERxView(NavigationView& nav) &button_filter, &button_switch, &recent_entries_view, - &recent_entries_filter_view, - &recent_entry_detail_view}); + &recent_entries_filter_view}); - recent_entry_detail_view.hidden(true); recent_entries_filter_view.hidden(true); recent_entries_view.on_select = [this](const BleRecentEntry& entry) { @@ -471,7 +472,6 @@ void BLERxView::set_parent_rect(const Rect new_parent_rect) { View::set_parent_rect(new_parent_rect); const Rect content_rect{0, header_height, new_parent_rect.width(), new_parent_rect.height() - header_height - switch_button_height}; recent_entries_view.set_parent_rect(content_rect); - recent_entry_detail_view.set_parent_rect(content_rect); recent_entries_filter_view.set_parent_rect(content_rect); } @@ -535,11 +535,6 @@ void BLERxView::updateEntry(const BlePacketData* packet, BleRecentEntry& entry) stringFound = true; } } - - // TODO: Crude hack, should be a more formal listener arrangement... - if (entry.key() == recent_entry_detail_view.entry().key()) { - recent_entry_detail_view.set_entry(entry); - } } } /* namespace ui */ diff --git a/firmware/application/apps/ble_rx_app.hpp b/firmware/application/apps/ble_rx_app.hpp index 90cdcabf8..85b0a88a2 100644 --- a/firmware/application/apps/ble_rx_app.hpp +++ b/firmware/application/apps/ble_rx_app.hpp @@ -24,6 +24,8 @@ #ifndef __BLE_RX_APP_H__ #define __BLE_RX_APP_H__ +#include "ble_tx_app.hpp" + #include "ui.hpp" #include "ui_navigation.hpp" #include "ui_receiver.hpp" @@ -118,7 +120,7 @@ class BleRecentEntryDetailView : public View { private: NavigationView& nav_; BleRecentEntry entry_{}; - void launch_bletx(BleRecentEntry packetEntry); + BLETxPacket build_packet(); static constexpr uint8_t total_data_lines{5}; @@ -259,10 +261,8 @@ class BLERxView : public View { {"dB", 4}, }}; - BleRecentEntry entry_{}; BleRecentEntriesView recent_entries_view{columns, recent}; BleRecentEntriesView recent_entries_filter_view{columns, filterEntries}; - BleRecentEntryDetailView recent_entry_detail_view{nav_, entry_}; MessageHandlerRegistration message_handler_packet{ Message::ID::BlePacket, From f93b0791599446b39bf94985be254820a9da37c3 Mon Sep 17 00:00:00 2001 From: TJ Baginski Date: Fri, 10 Nov 2023 00:57:28 -0500 Subject: [PATCH 10/19] reduce to 1 entry list --- firmware/application/apps/ble_rx_app.cpp | 40 ++++-------------------- firmware/application/apps/ble_rx_app.hpp | 1 - firmware/application/recent_entries.hpp | 8 ++--- 3 files changed, 9 insertions(+), 40 deletions(-) diff --git a/firmware/application/apps/ble_rx_app.cpp b/firmware/application/apps/ble_rx_app.cpp index de5be6f00..c7a343991 100644 --- a/firmware/application/apps/ble_rx_app.cpp +++ b/firmware/application/apps/ble_rx_app.cpp @@ -262,19 +262,12 @@ BLERxView::BLERxView(NavigationView& nav) &options_sort, &button_filter, &button_switch, - &recent_entries_view, - &recent_entries_filter_view}); - - recent_entries_filter_view.hidden(true); + &recent_entries_view}); recent_entries_view.on_select = [this](const BleRecentEntry& entry) { nav_.push(entry); }; - recent_entries_filter_view.on_select = [this](const BleRecentEntry& entry) { - nav_.push(entry); - }; - button_filter.on_select = [this, &nav](Button&) { text_prompt( nav, @@ -395,10 +388,10 @@ void BLERxView::on_data(BlePacketData* packet) { updateEntry(packet, entry); // Add entries if they meet the criteria. - if ((entry.dataString.find(filter) != std::string::npos) || (entry.nameString.find(filter) != std::string::npos)) { - auto& filteredEntry = ::on_packet(filterEntries, macAddressEncoded & 0xFFFFFFFFFFFF); - updateEntry(packet, filteredEntry); - } + auto value = filter; + resetFilteredEntries(recent, [&value](const BleRecentEntry& entry) { + return (entry.dataString.find(value) == std::string::npos) && (entry.nameString.find(value) == std::string::npos); + }); handle_entries_sort(options_sort.selected_index()); @@ -411,21 +404,12 @@ void BLERxView::on_data(BlePacketData* packet) { void BLERxView::on_switch_table(const std::string value) { // New filter? Reset list from recent entries. if (filter != value) { - filterEntries = BleRecentEntries{}; - resetFilteredEntries(recent, filterEntries, [&value](const BleRecentEntry& entry) { + resetFilteredEntries(recent, [&value](const BleRecentEntry& entry) { return (entry.dataString.find(value) == std::string::npos) && (entry.nameString.find(value) == std::string::npos); }); } filter = value; - - if (!value.empty()) { - recent_entries_filter_view.hidden(false); - recent_entries_view.hidden(true); - } else { - recent_entries_view.hidden(false); - recent_entries_filter_view.hidden(true); - } } void BLERxView::handle_entries_sort(uint8_t index) { @@ -433,46 +417,34 @@ void BLERxView::handle_entries_sort(uint8_t index) { case 0: sortEntriesBy( recent, [](const BleRecentEntry& entry) { return entry.macAddress; }, true); - sortEntriesBy( - filterEntries, [](const BleRecentEntry& entry) { return entry.macAddress; }, true); break; case 1: sortEntriesBy( recent, [](const BleRecentEntry& entry) { return entry.numHits; }, false); - sortEntriesBy( - filterEntries, [](const BleRecentEntry& entry) { return entry.numHits; }, false); break; case 2: sortEntriesBy( recent, [](const BleRecentEntry& entry) { return entry.dbValue; }, false); - sortEntriesBy( - filterEntries, [](const BleRecentEntry& entry) { return entry.dbValue; }, false); break; case 3: sortEntriesBy( recent, [](const BleRecentEntry& entry) { return entry.timestamp; }, false); - sortEntriesBy( - filterEntries, [](const BleRecentEntry& entry) { return entry.timestamp; }, false); break; case 4: sortEntriesBy( recent, [](const BleRecentEntry& entry) { return entry.nameString; }, true); - sortEntriesBy( - filterEntries, [](const BleRecentEntry& entry) { return entry.nameString; }, true); break; default: break; } recent_entries_view.set_dirty(); - recent_entries_filter_view.set_dirty(); } void BLERxView::set_parent_rect(const Rect new_parent_rect) { View::set_parent_rect(new_parent_rect); const Rect content_rect{0, header_height, new_parent_rect.width(), new_parent_rect.height() - header_height - switch_button_height}; recent_entries_view.set_parent_rect(content_rect); - recent_entries_filter_view.set_parent_rect(content_rect); } BLERxView::~BLERxView() { diff --git a/firmware/application/apps/ble_rx_app.hpp b/firmware/application/apps/ble_rx_app.hpp index 85b0a88a2..f51dc4179 100644 --- a/firmware/application/apps/ble_rx_app.hpp +++ b/firmware/application/apps/ble_rx_app.hpp @@ -262,7 +262,6 @@ class BLERxView : public View { }}; BleRecentEntriesView recent_entries_view{columns, recent}; - BleRecentEntriesView recent_entries_filter_view{columns, filterEntries}; MessageHandlerRegistration message_handler_packet{ Message::ID::BlePacket, diff --git a/firmware/application/recent_entries.hpp b/firmware/application/recent_entries.hpp index e6cb435a0..8c1133b62 100644 --- a/firmware/application/recent_entries.hpp +++ b/firmware/application/recent_entries.hpp @@ -96,14 +96,12 @@ void sortEntriesBy(ContainerType& entries, KeySelector keySelector, SortOrder as } template -void resetFilteredEntries(ContainerType& entries, ContainerType& filteredEntries, KeySelector keySelector) { +void resetFilteredEntries(ContainerType& entries, KeySelector keySelector) { // Clear the filteredEntries container - filteredEntries.clear(); - auto it = entries.begin(); while (it != entries.end()) { - if (!keySelector(*it)) { - filteredEntries.emplace_back(*it); // Add a new entry to filteredEntries + if (keySelector(*it)) { + entries.erase(it); // Add a new entry to filteredEntries } ++it; // Move to the next element, outside of the if block } From 3b0a838ba88631371470466f113a5564a16b4df5 Mon Sep 17 00:00:00 2001 From: Netro Date: Fri, 10 Nov 2023 13:04:26 -0500 Subject: [PATCH 11/19] Setting to use the name of BLE with a toggle checkbox. --- firmware/application/apps/ble_rx_app.cpp | 12 +++++++++++- firmware/application/apps/ble_rx_app.hpp | 12 ++++++++++-- firmware/application/recent_entries.hpp | 11 +++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/firmware/application/apps/ble_rx_app.cpp b/firmware/application/apps/ble_rx_app.cpp index c7a343991..0b5db80eb 100644 --- a/firmware/application/apps/ble_rx_app.cpp +++ b/firmware/application/apps/ble_rx_app.cpp @@ -66,7 +66,7 @@ void RecentEntriesTable::draw( std::string line{}; line.reserve(30); - if (!entry.nameString.empty()) { + if (!entry.nameString.empty() && entry.include_name) { line = entry.nameString; if (line.length() < 17) { @@ -258,6 +258,7 @@ BLERxView::BLERxView(NavigationView& nav) &options_channel, &field_frequency, &check_log, + &check_name, &label_sort, &options_sort, &button_filter, @@ -294,6 +295,14 @@ BLERxView::BLERxView(NavigationView& nav) logger->append(LOG_ROOT_DIR "/BLELOG_" + to_string_timestamp(rtc_time::now()) + ".TXT"); }; + check_name.set_value(true); + + check_name.on_select = [this](Checkbox&, bool v) { + + setAllMembersToValue(recent, &BleRecentEntry::include_name, v); + recent_entries_view.set_dirty(); + }; + options_channel.on_change = [this](size_t, int32_t i) { field_frequency.set_value(get_freq_by_channel_number(i)); channel_number = i; @@ -483,6 +492,7 @@ void BLERxView::updateEntry(const BlePacketData* packet, BleRecentEntry& entry) } entry.nameString = ""; + entry.include_name = check_name.value(); uint8_t currentByte = 0; uint8_t length = 0; diff --git a/firmware/application/apps/ble_rx_app.hpp b/firmware/application/apps/ble_rx_app.hpp index f51dc4179..6fb57d1f0 100644 --- a/firmware/application/apps/ble_rx_app.hpp +++ b/firmware/application/apps/ble_rx_app.hpp @@ -81,6 +81,7 @@ struct BleRecentEntry { std::string timestamp; std::string dataString; std::string nameString; + bool include_name; uint16_t numHits; BleRecentEntry() @@ -95,6 +96,7 @@ struct BleRecentEntry { timestamp{}, dataString{}, nameString{}, + include_name{}, numHits{} { } @@ -231,15 +233,21 @@ class BLERxView : public View { {"Name", 4}}}; Button button_filter{ - {12 * 8, 3 * 8, 4 * 8, 16}, + {11 * 8, 3 * 8, 4 * 8, 16}, "Filter"}; Checkbox check_log{ - {20 * 8, 3 * 8}, + {17 * 8, 3 * 8}, 3, "Log", true}; + Checkbox check_name{ + {23 * 8, 3 * 8}, + 3, + "Name", + true}; + Console console{ {0, 4 * 16, 240, 240}}; diff --git a/firmware/application/recent_entries.hpp b/firmware/application/recent_entries.hpp index 8c1133b62..cf6de68b6 100644 --- a/firmware/application/recent_entries.hpp +++ b/firmware/application/recent_entries.hpp @@ -107,6 +107,17 @@ void resetFilteredEntries(ContainerType& entries, KeySelector keySelector) { } } +template +void setAllMembersToValue(ContainerType& entries, MemberPtr memberPtr, const KeyValue& keyValue) { + for (auto& entry : entries) { + // Check if the member specified by memberPtr is equal to keyValue + if (entry.*memberPtr != keyValue) { + // Update the member with keyValue + entry.*memberPtr = keyValue; + } + } +} + namespace ui { using RecentEntriesColumn = std::pair; From 747e641c3aeb4a8ec6e922b00672b6b70a0231d3 Mon Sep 17 00:00:00 2001 From: Netro Date: Fri, 10 Nov 2023 13:05:14 -0500 Subject: [PATCH 12/19] formatting. --- firmware/application/apps/ble_rx_app.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/firmware/application/apps/ble_rx_app.cpp b/firmware/application/apps/ble_rx_app.cpp index 0b5db80eb..41e379b9d 100644 --- a/firmware/application/apps/ble_rx_app.cpp +++ b/firmware/application/apps/ble_rx_app.cpp @@ -298,7 +298,6 @@ BLERxView::BLERxView(NavigationView& nav) check_name.set_value(true); check_name.on_select = [this](Checkbox&, bool v) { - setAllMembersToValue(recent, &BleRecentEntry::include_name, v); recent_entries_view.set_dirty(); }; From c56852f78808355dd9dd9de19cefd2c9484093f6 Mon Sep 17 00:00:00 2001 From: Netro Date: Fri, 10 Nov 2023 14:42:50 -0500 Subject: [PATCH 13/19] Cleanup, but unsure if this fixes the Guru switching views. --- firmware/application/apps/ble_rx_app.cpp | 16 ++++++++-------- firmware/application/apps/ble_tx_app.cpp | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/firmware/application/apps/ble_rx_app.cpp b/firmware/application/apps/ble_rx_app.cpp index 41e379b9d..cff2fa68e 100644 --- a/firmware/application/apps/ble_rx_app.cpp +++ b/firmware/application/apps/ble_rx_app.cpp @@ -107,16 +107,16 @@ BleRecentEntryDetailView::BleRecentEntryDetailView(NavigationView& nav, const Bl text_mac_address.set(to_string_mac_address(entry.packetData.macAddress, 6, false)); - button_done.on_select = [this](const ui::Button&) { - nav_.pop(); + button_done.on_select = [&nav](const ui::Button&) { + nav.pop(); }; - button_send.on_select = [this](const ui::Button&) { + button_send.on_select = [this, &nav](const ui::Button&) { auto packetToSend = build_packet(); - nav_.set_on_pop([packetToSend, this]() { - nav_.replace(packetToSend); + nav.set_on_pop([packetToSend, &nav]() { + nav.replace(packetToSend); }); - nav_.pop(); + nav.pop(); }; } @@ -279,8 +279,8 @@ BLERxView::BLERxView(NavigationView& nav) }); }; - button_switch.on_select = [this, &nav](Button&) { - nav_.replace(); + button_switch.on_select = [&nav](Button&) { + nav.replace(); }; field_frequency.set_step(0); diff --git a/firmware/application/apps/ble_tx_app.cpp b/firmware/application/apps/ble_tx_app.cpp index bb75c69d9..7ca2dec9b 100644 --- a/firmware/application/apps/ble_tx_app.cpp +++ b/firmware/application/apps/ble_tx_app.cpp @@ -338,10 +338,10 @@ BLETxView::BLETxView(NavigationView& nav) button_open.on_select = [this, &nav](Button&) { auto open_view = nav.push(".TXT"); - open_view->on_changed = [this](std::filesystem::path new_file_path) { + open_view->on_changed = [this, &nav](std::filesystem::path new_file_path) { on_file_changed(new_file_path); - nav_.set_on_pop([this]() { button_play.focus(); }); + nav.set_on_pop([this]() { button_play.focus(); }); }; }; @@ -357,7 +357,7 @@ BLETxView::BLETxView(NavigationView& nav) }; button_switch.on_select = [this, &nav](Button&) { - nav_.replace(); + nav.replace(); }; } From 7ede8c32c351dfc750f78ea5eacbc8a539640b6d Mon Sep 17 00:00:00 2001 From: Netro Date: Fri, 10 Nov 2023 15:33:29 -0500 Subject: [PATCH 14/19] Cleanup --- firmware/application/apps/ble_rx_app.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firmware/application/apps/ble_rx_app.cpp b/firmware/application/apps/ble_rx_app.cpp index cff2fa68e..d8177cb5e 100644 --- a/firmware/application/apps/ble_rx_app.cpp +++ b/firmware/application/apps/ble_rx_app.cpp @@ -269,9 +269,9 @@ BLERxView::BLERxView(NavigationView& nav) nav_.push(entry); }; - button_filter.on_select = [this, &nav](Button&) { + button_filter.on_select = [this](Button&) { text_prompt( - nav, + nav_, filterBuffer, 64, [this](std::string& buffer) { From 05b84d8dcada9637f11c2f7f7083844adc4c32a2 Mon Sep 17 00:00:00 2001 From: Netro Date: Fri, 10 Nov 2023 15:49:48 -0500 Subject: [PATCH 15/19] Removed &nav reference. --- firmware/application/apps/ble_tx_app.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/firmware/application/apps/ble_tx_app.cpp b/firmware/application/apps/ble_tx_app.cpp index 7ca2dec9b..ce232ad45 100644 --- a/firmware/application/apps/ble_tx_app.cpp +++ b/firmware/application/apps/ble_tx_app.cpp @@ -336,12 +336,12 @@ BLETxView::BLETxView(NavigationView& nav) random_mac = v; }; - button_open.on_select = [this, &nav](Button&) { - auto open_view = nav.push(".TXT"); - open_view->on_changed = [this, &nav](std::filesystem::path new_file_path) { + button_open.on_select = [this](Button&) { + auto open_view = nav_.push(".TXT"); + open_view->on_changed = [this](std::filesystem::path new_file_path) { on_file_changed(new_file_path); - nav.set_on_pop([this]() { button_play.focus(); }); + nav_.set_on_pop([this]() { button_play.focus(); }); }; }; From fb0d6ca917eecaf3475fad119d8b6bccf5e9eb00 Mon Sep 17 00:00:00 2001 From: Netro Date: Fri, 10 Nov 2023 15:50:37 -0500 Subject: [PATCH 16/19] removing this --- firmware/application/apps/ble_tx_app.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/application/apps/ble_tx_app.cpp b/firmware/application/apps/ble_tx_app.cpp index ce232ad45..7627e7964 100644 --- a/firmware/application/apps/ble_tx_app.cpp +++ b/firmware/application/apps/ble_tx_app.cpp @@ -356,7 +356,7 @@ BLETxView::BLETxView(NavigationView& nav) }); }; - button_switch.on_select = [this, &nav](Button&) { + button_switch.on_select = [&nav](Button&) { nav.replace(); }; } From 57d02c31677b4e0b6c7be8b0c84f6804f004871a Mon Sep 17 00:00:00 2001 From: Netro Date: Fri, 10 Nov 2023 15:55:15 -0500 Subject: [PATCH 17/19] Removing const --- firmware/application/apps/ble_rx_app.cpp | 2 +- firmware/application/apps/ble_rx_app.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/firmware/application/apps/ble_rx_app.cpp b/firmware/application/apps/ble_rx_app.cpp index d8177cb5e..03c0b9c19 100644 --- a/firmware/application/apps/ble_rx_app.cpp +++ b/firmware/application/apps/ble_rx_app.cpp @@ -409,7 +409,7 @@ void BLERxView::on_data(BlePacketData* packet) { } } -void BLERxView::on_switch_table(const std::string value) { +void BLERxView::on_switch_table(std::string value) { // New filter? Reset list from recent entries. if (filter != value) { resetFilteredEntries(recent, [&value](const BleRecentEntry& entry) { diff --git a/firmware/application/apps/ble_rx_app.hpp b/firmware/application/apps/ble_rx_app.hpp index 6fb57d1f0..1599d4847 100644 --- a/firmware/application/apps/ble_rx_app.hpp +++ b/firmware/application/apps/ble_rx_app.hpp @@ -171,7 +171,7 @@ class BLERxView : public View { private: void on_data(BlePacketData* packetData); - void on_switch_table(const std::string value); + void on_switch_table(std::string value); void handle_entries_sort(uint8_t index); void updateEntry(const BlePacketData* packet, BleRecentEntry& entry); From 4087c4756560963a8fc4c7c0e66f59bbc15c7a3f Mon Sep 17 00:00:00 2001 From: TJ Baginski Date: Sat, 11 Nov 2023 11:51:35 -0500 Subject: [PATCH 18/19] Fixed issue with memory being run out when switching from a previous app --- firmware/application/apps/ble_tx_app.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/application/apps/ble_tx_app.hpp b/firmware/application/apps/ble_tx_app.hpp index 63d7b66aa..c102a9aac 100644 --- a/firmware/application/apps/ble_tx_app.hpp +++ b/firmware/application/apps/ble_tx_app.hpp @@ -152,7 +152,7 @@ class BLETxView : public View { static constexpr uint8_t max_packet_size_str{62}; static constexpr uint8_t max_packet_repeat_str{10}; static constexpr uint32_t max_packet_repeat_count{UINT32_MAX}; - static constexpr uint32_t max_num_packets{256}; + static constexpr uint32_t max_num_packets{32}; BLETxPacket packets[max_num_packets]; From e5d0ec35c705928201fa5ee2a5afea125b998cbf Mon Sep 17 00:00:00 2001 From: TJ Baginski Date: Sat, 11 Nov 2023 12:18:31 -0500 Subject: [PATCH 19/19] Fixed not setting updated progressbar for each new packet. --- firmware/application/apps/ble_tx_app.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/firmware/application/apps/ble_tx_app.cpp b/firmware/application/apps/ble_tx_app.cpp index 7627e7964..199cffb0c 100644 --- a/firmware/application/apps/ble_tx_app.cpp +++ b/firmware/application/apps/ble_tx_app.cpp @@ -229,6 +229,7 @@ void BLETxView::start() { } } else { // Send next packet. + progressbar.set_max(packets[current_packet].packet_count); baseband::set_btletx(channel_number, random_mac ? randomMac : packets[current_packet].macAddress, packets[current_packet].advertisementData, pduType); }