From adabbfbef1b9e54e39c7bd0d3650f29b5d944579 Mon Sep 17 00:00:00 2001 From: Netro <146584182+iNetro@users.noreply.github.com> Date: Mon, 6 Nov 2023 05:16:01 -0500 Subject: [PATCH] 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 --- firmware/application/apps/ble_rx_app.cpp | 26 ++++++++++++++++++++---- firmware/application/apps/ble_rx_app.hpp | 5 +++++ firmware/application/apps/ble_tx_app.cpp | 17 ++++++++++++++-- firmware/application/apps/ble_tx_app.hpp | 16 ++++++++------- firmware/application/string_format.cpp | 4 ++-- firmware/application/string_format.hpp | 2 +- 6 files changed, 54 insertions(+), 16 deletions(-) diff --git a/firmware/application/apps/ble_rx_app.cpp b/firmware/application/apps/ble_rx_app.cpp index 3d64ce05..5d050214 100644 --- a/firmware/application/apps/ble_rx_app.cpp +++ b/firmware/application/apps/ble_rx_app.cpp @@ -75,7 +75,7 @@ void RecentEntriesTable::draw( line = truncate(line, 17); } } 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. @@ -100,15 +100,21 @@ BleRecentEntryDetailView::BleRecentEntryDetailView(NavigationView& nav, const Bl : nav_{nav}, entry_{entry} { add_children({&button_done, + &button_send, &label_mac_address, &text_mac_address, &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&) { nav_.pop(); }; + + button_send.on_select = [this](const ui::Button&) { + nav_.set_on_pop([this]() { launch_bletx(entry_); }); + nav_.pop(); + }; } void BleRecentEntryDetailView::update_data() { @@ -180,7 +186,7 @@ void BleRecentEntryDetailView::paint(Painter& painter) { if (number_data_lines > 1) { 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]); } } @@ -193,6 +199,18 @@ void BleRecentEntryDetailView::set_entry(const BleRecentEntry& entry) { 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(bleTxPacket); +} + static std::uint64_t get_freq_by_channel_number(uint8_t channel_number) { uint64_t freq_hz; @@ -390,7 +408,7 @@ void BLERxView::on_data(BlePacketData* packet) { str_console += "\n"; 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 += "Data:"; diff --git a/firmware/application/apps/ble_rx_app.hpp b/firmware/application/apps/ble_rx_app.hpp index da5c0670..f30faa28 100644 --- a/firmware/application/apps/ble_rx_app.hpp +++ b/firmware/application/apps/ble_rx_app.hpp @@ -118,6 +118,7 @@ class BleRecentEntryDetailView : public View { private: NavigationView& nav_; BleRecentEntry entry_{}; + void launch_bletx(BleRecentEntry packetEntry); static constexpr uint8_t total_data_lines{5}; @@ -134,6 +135,10 @@ class BleRecentEntryDetailView : public View { {{10 * 8, 2 * 16}, "Value", Color::light_grey()}, }; + Button button_send{ + {19, 224, 96, 24}, + "Send"}; + Button button_done{ {125, 224, 96, 24}, "Done"}; diff --git a/firmware/application/apps/ble_tx_app.cpp b/firmware/application/apps/ble_tx_app.cpp index 19286213..34b24de1 100644 --- a/firmware/application/apps/ble_tx_app.cpp +++ b/firmware/application/apps/ble_tx_app.cpp @@ -189,7 +189,7 @@ void BLETxView::start() { File data_file; auto error = data_file.open(file_path); - if (error) { + if (error && !file_override) { file_error(); check_loop.set_value(false); return; @@ -309,6 +309,8 @@ BLETxView::BLETxView(NavigationView& nav) }; 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.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) { file_path = fs::path(u"/") + new_file_path; num_packets = 0; @@ -357,7 +370,7 @@ void BLETxView::on_file_changed(const fs::path& new_file_path) { // Verify Data. 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)); } else { diff --git a/firmware/application/apps/ble_tx_app.hpp b/firmware/application/apps/ble_tx_app.hpp index 761d425d..90e140d3 100644 --- a/firmware/application/apps/ble_tx_app.hpp +++ b/firmware/application/apps/ble_tx_app.hpp @@ -55,9 +55,17 @@ class BLELoggerTx { namespace ui { +struct BLETxPacket { + char macAddress[13]; + char advertisementData[63]; + char packetCount[11]; + uint32_t packet_count; +}; + class BLETxView : public View { public: BLETxView(NavigationView& nav); + BLETxView(NavigationView& nav, BLETxPacket packet); ~BLETxView(); 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"; }; - struct BLETxPacket { - char macAddress[13]; - char advertisementData[63]; - char packetCount[11]; - uint32_t packet_count; - }; - private: void on_data(uint32_t value, bool is_data); void on_tx_progress(const bool done); @@ -112,6 +113,7 @@ class BLETxView : public View { uint32_t num_packets{0}; uint32_t current_packet{0}; bool random_mac = false; + bool file_override = false; enum PKT_TYPE { INVALID_TYPE, diff --git a/firmware/application/string_format.cpp b/firmware/application/string_format.cpp index 74e1097c..d64c6fa1 100644 --- a/firmware/application/string_format.cpp +++ b/firmware/application/string_format.cpp @@ -311,13 +311,13 @@ std::string to_string_file_size(uint32_t file_size) { 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; string += to_string_hex(macAddress[0], 2); 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; diff --git a/firmware/application/string_format.hpp b/firmware/application/string_format.hpp index 3ab566b9..ad0c105f 100644 --- a/firmware/application/string_format.hpp +++ b/firmware/application/string_format.hpp @@ -77,7 +77,7 @@ std::string to_string_FAT_timestamp(const FATTimestamp& timestamp); std::string to_string_file_size(uint32_t file_size); // 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); /* Scales 'n' to be a value less than 1000. 'base_unit' is the index of the unit from