BLE RX: Making auto channel timer independent of packet events. (#1608)

This commit is contained in:
Netro 2023-11-28 12:18:15 -05:00 committed by GitHub
parent 175e5e2e8c
commit a6ed6e3099
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 27 deletions

View File

@ -657,16 +657,6 @@ bool BLERxView::saveFile(const std::filesystem::path& path) {
}
void BLERxView::on_data(BlePacketData* packet) {
if (auto_channel) {
int min = 37;
int max = 39;
int randomChannel = min + std::rand() % (max - min + 1);
field_frequency.set_value(get_freq_by_channel_number(randomChannel));
baseband::set_btlerx(randomChannel);
}
std::string str_console = "";
if (!logging) {
@ -726,6 +716,23 @@ void BLERxView::on_filter_change(std::string value) {
filter = value;
}
// called each 1/60th of second, so 6 = 100ms
void BLERxView::on_timer() {
if (++timer_count == timer_period) {
timer_count = 0;
if (auto_channel) {
int min = 37;
int max = 39;
int randomChannel = min + std::rand() % (max - min + 1);
field_frequency.set_value(get_freq_by_channel_number(randomChannel));
baseband::set_btlerx(randomChannel);
}
}
}
void BLERxView::handle_entries_sort(uint8_t index) {
switch (index) {
case 0:

View File

@ -195,6 +195,7 @@ class BLERxView : public View {
bool saveFile(const std::filesystem::path& path);
void on_data(BlePacketData* packetData);
void on_filter_change(std::string value);
void on_timer();
void handle_entries_sort(uint8_t index);
void updateEntry(const BlePacketData* packet, BleRecentEntry& entry, ADV_PDU_TYPE pdu_type);
@ -212,6 +213,9 @@ class BLERxView : public View {
uint8_t channel_number = 37;
bool auto_channel = false;
int16_t timer_count{0};
int16_t timer_period{6}; // 100ms
std::string filterBuffer{};
std::string filter{};
std::string listFileBuffer{};
@ -313,6 +317,12 @@ class BLERxView : public View {
const auto message = static_cast<const BLEPacketMessage*>(p);
this->on_data(message->packet);
}};
MessageHandlerRegistration message_handler_frame_sync{
Message::ID::DisplayFrameSync,
[this](const Message* const) {
this->on_timer();
}};
};
} /* namespace ui */

View File

@ -170,17 +170,6 @@ void BLETxView::start() {
baseband::run_image(portapack::spi_flash::image_tag_btle_tx);
transmitter_model.enable();
int randomChannel = channel_number;
if (auto_channel) {
int min = 37;
int max = 39;
randomChannel = min + std::rand() % (max - min + 1);
field_frequency.set_value(get_freq_by_channel_number(randomChannel));
}
// Generate new random Mac Address.
generateRandomMacAddress(randomMac);
@ -201,7 +190,7 @@ void BLETxView::start() {
// Setup next packet configuration.
progressbar.set_max(packets[current_packet].packet_count);
baseband::set_btletx(randomChannel, random_mac ? randomMac : packets[current_packet].macAddress, packets[current_packet].advertisementData, pduType);
baseband::set_btletx(channel_number, random_mac ? randomMac : packets[current_packet].macAddress, packets[current_packet].advertisementData, pduType);
}
void BLETxView::stop() {
@ -226,8 +215,8 @@ void BLETxView::reset() {
// called each 1/60th of second, so 6 = 100ms
void BLETxView::on_timer() {
if (++mscounter == timer_period) {
mscounter = 0;
if (++timer_count == timer_period) {
timer_count = 0;
if (is_active()) {
// Reached end of current packet repeats.
@ -253,6 +242,19 @@ void BLETxView::on_timer() {
}
}
}
if (++auto_channel_counter == auto_channel_period) {
auto_channel_counter = 0;
if (auto_channel) {
int min = 37;
int max = 39;
channel_number = min + std::rand() % (max - min + 1);
field_frequency.set_value(get_freq_by_channel_number(channel_number));
}
}
}
void BLETxView::on_tx_progress(const bool done) {
@ -316,7 +318,7 @@ BLETxView::BLETxView(NavigationView& nav)
options_speed.on_change = [this](size_t, int32_t i) {
timer_period = i;
mscounter = 0;
timer_count = 0;
};
options_adv_type.on_change = [this](size_t, int32_t i) {

View File

@ -143,8 +143,12 @@ class BLETxView : public View {
char randomMac[13] = "010203040506";
bool is_running = false;
uint64_t timer_count{0};
int16_t timer_count{0};
int16_t timer_period{1};
int16_t auto_channel_counter = 0;
int16_t auto_channel_period{6};
bool repeatLoop = false;
uint32_t packet_counter{0};
uint32_t num_packets{0};
@ -157,7 +161,6 @@ class BLETxView : public View {
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{32};
int16_t mscounter = 0;
BLETxPacket packets[max_num_packets];