mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-12-23 14:29:23 -05:00
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:
parent
2b7962fa7c
commit
adabbfbef1
@ -75,7 +75,7 @@ void RecentEntriesTable<BleRecentEntries>::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<BLETxView>(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:";
|
||||
|
@ -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"};
|
||||
|
@ -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 {
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user