BLE Rx improvements. (#1550)

* Added parsing for ble name added focus for ble tx play button.
* Added sort by name
* Fixed issue where we were pushing too early before pop was finished.
* Fix ordering
* Fix field location.
* truncating entries to stop memory overflow
* Added Number of Hits.
* Limiting number of hits to uint16_t, as any higher would overflow screen
* Limiting number of hits to uint16_t due to possible screen overflow.
* Stop creating a log every time app starts. Cluttering log folder.
This commit is contained in:
Netro 2023-11-04 03:29:48 -04:00 committed by GitHub
parent 1639348b94
commit b178462e47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 128 additions and 46 deletions

View File

@ -64,17 +64,33 @@ void RecentEntriesTable<BleRecentEntries>::draw(
const Rect& target_rect, const Rect& target_rect,
Painter& painter, Painter& painter,
const Style& style) { const Style& style) {
std::string line = to_string_mac_address(entry.packetData.macAddress, 6); std::string line{};
// Handle spacing for negative sign. if (!entry.nameString.empty()) {
uint8_t db_spacing = entry.dbValue > 0 ? 7 : 6; line = entry.nameString;
// Pushing single digit values down right justified. if (line.length() < 17) {
if (entry.dbValue > 9 || entry.dbValue < -9) { line += pad_string_with_spaces(17 - line.length());
db_spacing--; } else {
line = truncate(line, 17);
}
} else {
line = to_string_mac_address(entry.packetData.macAddress, 6);
} }
line += pad_string_with_spaces(db_spacing) + to_string_dec_int(entry.dbValue); // Pushing single digit values down right justified.
std::string hitsStr = to_string_dec_int(entry.numHits);
int hitsDigits = hitsStr.length();
uint8_t hits_spacing = 8 - hitsDigits;
// Pushing single digit values down right justified.
std::string dbStr = to_string_dec_int(entry.dbValue);
int dbDigits = dbStr.length();
uint8_t db_spacing = 5 - dbDigits;
line += pad_string_with_spaces(hits_spacing) + hitsStr;
line += pad_string_with_spaces(db_spacing) + dbStr;
line.resize(target_rect.width() / 8, ' '); line.resize(target_rect.width() / 8, ' ');
painter.draw_string(target_rect.location(), style, line); painter.draw_string(target_rect.location(), style, line);
@ -84,8 +100,12 @@ BleRecentEntryDetailView::BleRecentEntryDetailView(NavigationView& nav, const Bl
: nav_{nav}, : nav_{nav},
entry_{entry} { entry_{entry} {
add_children({&button_done, add_children({&button_done,
&label_mac_address,
&text_mac_address,
&labels}); &labels});
text_mac_address.set(to_string_mac_address(entry.packetData.macAddress, 6));
button_done.on_select = [this](const ui::Button&) { button_done.on_select = [this](const ui::Button&) {
nav_.pop(); nav_.pop();
}; };
@ -118,7 +138,7 @@ void BleRecentEntryDetailView::paint(Painter& painter) {
const auto s = style(); const auto s = style();
const auto rect = screen_rect(); const auto rect = screen_rect();
auto field_rect = Rect{rect.left(), rect.top() + 16, rect.width(), 16}; auto field_rect = Rect{rect.left(), rect.top() + 48, rect.width(), 16};
uint8_t type[total_data_lines]; uint8_t type[total_data_lines];
uint8_t length[total_data_lines]; uint8_t length[total_data_lines];
@ -217,7 +237,7 @@ BLERxView::BLERxView(NavigationView& nav)
&check_log, &check_log,
&label_sort, &label_sort,
&options_sort, &options_sort,
&button_message, &button_filter,
&button_switch, &button_switch,
&recent_entries_view, &recent_entries_view,
&recent_entries_filter_view, &recent_entries_filter_view,
@ -234,7 +254,7 @@ BLERxView::BLERxView(NavigationView& nav)
nav_.push<BleRecentEntryDetailView>(entry); nav_.push<BleRecentEntryDetailView>(entry);
}; };
button_message.on_select = [this, &nav](Button&) { button_filter.on_select = [this, &nav](Button&) {
text_prompt( text_prompt(
nav, nav,
filterBuffer, filterBuffer,
@ -245,8 +265,8 @@ BLERxView::BLERxView(NavigationView& nav)
}; };
button_switch.on_select = [this, &nav](Button&) { button_switch.on_select = [this, &nav](Button&) {
nav.pop(); nav_.set_on_pop([this]() { nav_.push<BLETxView>(); });
nav.push<BLETxView>(); nav_.pop();
}; };
field_frequency.set_step(0); field_frequency.set_step(0);
@ -256,6 +276,9 @@ BLERxView::BLERxView(NavigationView& nav)
check_log.on_select = [this](Checkbox&, bool v) { check_log.on_select = [this](Checkbox&, bool v) {
str_log = ""; str_log = "";
logging = v; logging = v;
if (logger && logging)
logger->append(LOG_ROOT_DIR "/BLELOG_" + to_string_timestamp(rtc_time::now()) + ".TXT");
}; };
options_channel.on_change = [this](size_t, int32_t i) { options_channel.on_change = [this](size_t, int32_t i) {
@ -274,17 +297,29 @@ BLERxView::BLERxView(NavigationView& nav)
filterEntries, [](const BleRecentEntry& entry) { return entry.macAddress; }, true); filterEntries, [](const BleRecentEntry& entry) { return entry.macAddress; }, true);
break; break;
case 1: case 1:
sortEntriesBy(
recent, [](const BleRecentEntry& entry) { return entry.numHits; }, false);
sortEntriesBy(
filterEntries, [](const BleRecentEntry& entry) { return entry.numHits; }, false);
break;
case 2:
sortEntriesBy( sortEntriesBy(
recent, [](const BleRecentEntry& entry) { return entry.dbValue; }, true); recent, [](const BleRecentEntry& entry) { return entry.dbValue; }, true);
sortEntriesBy( sortEntriesBy(
filterEntries, [](const BleRecentEntry& entry) { return entry.dbValue; }, true); filterEntries, [](const BleRecentEntry& entry) { return entry.dbValue; }, true);
break; break;
case 2: case 3:
sortEntriesBy( sortEntriesBy(
recent, [](const BleRecentEntry& entry) { return entry.timestamp; }, false); recent, [](const BleRecentEntry& entry) { return entry.timestamp; }, false);
sortEntriesBy( sortEntriesBy(
filterEntries, [](const BleRecentEntry& entry) { return entry.timestamp; }, false); filterEntries, [](const BleRecentEntry& entry) { return entry.timestamp; }, false);
break; break;
case 4:
sortEntriesBy(
recent, [](const BleRecentEntry& entry) { return entry.nameString; }, true);
sortEntriesBy(
filterEntries, [](const BleRecentEntry& entry) { return entry.nameString; }, true);
break;
default: default:
break; break;
} }
@ -298,9 +333,6 @@ BLERxView::BLERxView(NavigationView& nav)
logger = std::make_unique<BLELogger>(); logger = std::make_unique<BLELogger>();
if (logger)
logger->append(LOG_ROOT_DIR "/BLELOG_" + to_string_timestamp(rtc_time::now()) + ".TXT");
// Auto-configure modem for LCR RX (will be removed later) // Auto-configure modem for LCR RX (will be removed later)
baseband::set_btlerx(channel_number); baseband::set_btlerx(channel_number);
@ -376,6 +408,7 @@ void BLERxView::on_data(BlePacketData* packet) {
// Start of Packet stuffing. // Start of Packet stuffing.
// Masking off the top 2 bytes to avoid invalid keys. // Masking off the top 2 bytes to avoid invalid keys.
auto& entry = ::on_packet(recent, macAddressEncoded & 0xFFFFFFFFFFFF); auto& entry = ::on_packet(recent, macAddressEncoded & 0xFFFFFFFFFFFF);
truncate_entries(recent, 32);
updateEntry(packet, entry); updateEntry(packet, entry);
// Log at End of Packet. // Log at End of Packet.
@ -442,11 +475,37 @@ void BLERxView::updateEntry(const BlePacketData* packet, BleRecentEntry& entry)
entry.packetData.macAddress[4] = packet->macAddress[4]; entry.packetData.macAddress[4] = packet->macAddress[4];
entry.packetData.macAddress[5] = packet->macAddress[5]; entry.packetData.macAddress[5] = packet->macAddress[5];
entry.numHits++;
for (int i = 0; i < packet->dataLen; i++) { for (int i = 0; i < packet->dataLen; i++) {
entry.packetData.data[i] = packet->data[i]; entry.packetData.data[i] = packet->data[i];
} }
// entry.update(packet); entry.nameString = "";
uint8_t currentByte = 0;
uint8_t length = 0;
uint8_t type = 0;
bool stringFound = false;
for (currentByte = 0; (currentByte < entry.packetData.dataLen);) {
length = entry.packetData.data[currentByte++];
type = entry.packetData.data[currentByte++];
// Subtract 1 because type is part of the length.
for (int i = 0; i < length - 1; i++) {
if (((type == 0x08) || (type == 0x09)) && !stringFound) {
entry.nameString += (char)entry.packetData.data[currentByte];
}
currentByte++;
}
if (!entry.nameString.empty()) {
stringFound = true;
}
}
switch (options_sort.selected_index()) { switch (options_sort.selected_index()) {
case 0: case 0:
@ -456,17 +515,29 @@ void BLERxView::updateEntry(const BlePacketData* packet, BleRecentEntry& entry)
filterEntries, [](const BleRecentEntry& entry) { return entry.macAddress; }, true); filterEntries, [](const BleRecentEntry& entry) { return entry.macAddress; }, true);
break; break;
case 1: case 1:
sortEntriesBy(
recent, [](const BleRecentEntry& entry) { return entry.numHits; }, false);
sortEntriesBy(
filterEntries, [](const BleRecentEntry& entry) { return entry.numHits; }, false);
break;
case 2:
sortEntriesBy( sortEntriesBy(
recent, [](const BleRecentEntry& entry) { return entry.dbValue; }, true); recent, [](const BleRecentEntry& entry) { return entry.dbValue; }, true);
sortEntriesBy( sortEntriesBy(
filterEntries, [](const BleRecentEntry& entry) { return entry.dbValue; }, true); filterEntries, [](const BleRecentEntry& entry) { return entry.dbValue; }, true);
break; break;
case 2: case 3:
sortEntriesBy( sortEntriesBy(
recent, [](const BleRecentEntry& entry) { return entry.timestamp; }, false); recent, [](const BleRecentEntry& entry) { return entry.timestamp; }, false);
sortEntriesBy( sortEntriesBy(
filterEntries, [](const BleRecentEntry& entry) { return entry.timestamp; }, false); filterEntries, [](const BleRecentEntry& entry) { return entry.timestamp; }, false);
break; break;
case 4:
sortEntriesBy(
recent, [](const BleRecentEntry& entry) { return entry.nameString; }, true);
sortEntriesBy(
filterEntries, [](const BleRecentEntry& entry) { return entry.nameString; }, true);
break;
default: default:
break; break;
} }

View File

@ -78,6 +78,8 @@ struct BleRecentEntry {
BlePacketData packetData; BlePacketData packetData;
std::string timestamp; std::string timestamp;
std::string dataString; std::string dataString;
std::string nameString;
uint16_t numHits;
BleRecentEntry() BleRecentEntry()
: BleRecentEntry{0} { : BleRecentEntry{0} {
@ -89,7 +91,9 @@ struct BleRecentEntry {
dbValue{}, dbValue{},
packetData{}, packetData{},
timestamp{}, timestamp{},
dataString{} { dataString{},
nameString{},
numHits{} {
} }
Key key() const { Key key() const {
@ -117,10 +121,17 @@ class BleRecentEntryDetailView : public View {
static constexpr uint8_t total_data_lines{5}; static constexpr uint8_t total_data_lines{5};
Labels label_mac_address{
{{0 * 8, 0 * 16}, "Mac Address:", Color::light_grey()}};
Text text_mac_address{
{12 * 8, 0 * 16, 17 * 8, 16},
"-"};
Labels labels{ Labels labels{
{{0 * 8, 0 * 16}, "Len", Color::light_grey()}, {{0 * 8, 2 * 16}, "Len", Color::light_grey()},
{{5 * 8, 0 * 16}, "Type", Color::light_grey()}, {{5 * 8, 2 * 16}, "Type", Color::light_grey()},
{{10 * 8, 0 * 16}, "Value", Color::light_grey()}, {{10 * 8, 2 * 16}, "Value", Color::light_grey()},
}; };
Button button_done{ Button button_done{
@ -199,26 +210,28 @@ class BLERxView : public View {
Channel channel{ Channel channel{
{24 * 8, 5, 6 * 8, 4}}; {24 * 8, 5, 6 * 8, 4}};
Labels label_sort{
{{0 * 8, 3 * 8}, "Sort:", Color::light_grey()}};
OptionsField options_sort{
{5 * 8, 3 * 8},
4,
{{"MAC", 0},
{"Hits", 1},
{"dB", 2},
{"Time", 3},
{"Name", 4}}};
Button button_filter{
{12 * 8, 3 * 8, 4 * 8, 16},
"Filter"};
Checkbox check_log{ Checkbox check_log{
{0 * 8, 3 * 8}, {20 * 8, 3 * 8},
3, 3,
"Log", "Log",
true}; true};
Labels label_sort{
{{6 * 8, 3 * 8}, "Sort:", Color::light_grey()}};
OptionsField options_sort{
{12 * 8, 3 * 8},
6,
{{"MAC", 0},
{"dB", 1},
{"Recent", 2}}};
Button button_message{
{22 * 8, 3 * 8, 4 * 8, 16},
"Filter"};
Console console{ Console console{
{0, 4 * 16, 240, 240}}; {0, 4 * 16, 240, 240}};
@ -231,17 +244,13 @@ class BLERxView : public View {
std::unique_ptr<BLELogger> logger{}; std::unique_ptr<BLELogger> logger{};
// const RecentEntriesColumns columns{{{"Source", 9},
// {"Loc", 6},
// {"Hits", 4},
// {"Time", 8}}};
BleRecentEntries recent{}; BleRecentEntries recent{};
BleRecentEntries filterEntries{}; BleRecentEntries filterEntries{};
const RecentEntriesColumns columns{{ const RecentEntriesColumns columns{{
{"Mac Address", 20}, {"Mac Address", 17},
{"dB", 20}, {"Hits", 7},
{"dB", 4},
}}; }};
BleRecentEntry entry_{}; BleRecentEntry entry_{};

View File

@ -319,12 +319,14 @@ BLETxView::BLETxView(NavigationView& nav)
auto open_view = nav.push<FileLoadView>(".TXT"); auto open_view = nav.push<FileLoadView>(".TXT");
open_view->on_changed = [this](std::filesystem::path new_file_path) { open_view->on_changed = [this](std::filesystem::path new_file_path) {
on_file_changed(new_file_path); on_file_changed(new_file_path);
nav_.set_on_pop([this]() { button_play.focus(); });
}; };
}; };
button_switch.on_select = [this, &nav](Button&) { button_switch.on_select = [this, &nav](Button&) {
nav.pop(); nav_.set_on_pop([this]() { nav_.push<BLERxView>(); });
nav.push<BLERxView>(); nav_.pop();
}; };
} }