Skip to content

Commit

Permalink
feat: ADV scanner
Browse files Browse the repository at this point in the history
  • Loading branch information
JahazielLem committed Oct 25, 2024
1 parent 07e14ef commit 13d7e14
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
21 changes: 21 additions & 0 deletions firmware/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,25 @@ The build files will be in the `build_files.zip` file. Now you can create a rele
| 0x20000 | minino.bin |
```bash
python -m esptool --chip esp32c6 -b 460800 --before default_reset --after hard_reset write_flash --flash_mode dio --flash_size 8MB --flash_freq 80m 0x0 bootloader.bin 0x8000 partition-table.bin 0x20000 minino.bin
```



## BLE

### ADV Filters
```
BLE_SCAN_FILTER_ALLOW_ALL = 0x0, /*!< Accept all :
1. advertisement packets except directed advertising packets not addressed to this device (default). */
BLE_SCAN_FILTER_ALLOW_ONLY_WLST = 0x1, /*!< Accept only :
1. advertisement packets from devices where the advertiser’s address is in the White list.
2. Directed advertising packets which are not addressed for this device shall be ignored. */
BLE_SCAN_FILTER_ALLOW_UND_RPA_DIR = 0x2, /*!< Accept all :
1. undirected advertisement packets, and
2. directed advertising packets where the initiator address is a resolvable private address, and
3. directed advertising packets addressed to this device. */
BLE_SCAN_FILTER_ALLOW_WLIST_RPA_DIR = 0x3, /*!< Accept all :
1. advertisement packets from devices where the advertiser’s address is in the White list, and
2. directed advertising packets where the initiator address is a resolvable private address, and
3. directed advertising packets addressed to this device.*/
```
8 changes: 7 additions & 1 deletion firmware/components/ble_scann/ble_scann.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ static bluetooth_adv_scanner_cb_t display_records_cb = NULL;
static int ble_scan_duration = 0;
static bool ble_scanner_active = false;
static esp_ble_scan_filter_t ble_scan_filter = BLE_SCAN_FILTER_ALLOW_ALL;
static esp_ble_scan_type_t ble_scan_type = BLE_SCAN_TYPE_ACTIVE;
static void task_scanner_timer();
static void handle_bt_gapc_events(esp_gap_ble_cb_event_t event_type,
esp_ble_gap_cb_param_t* param);
Expand All @@ -18,6 +19,10 @@ void set_filter_type(uint8_t filter_type) {
ble_scan_filter = filter_type;
}

void set_scan_type(uint8_t scan_type) {
ble_scan_type = scan_type;
}

void ble_scanner_begin() {
// #if !defined(CONFIG_TRACKERS_SCANNER_DEBUG)
// esp_log_level_set(TAG_BLE_CLIENT_MODULE, ESP_LOG_NONE);
Expand All @@ -30,6 +35,7 @@ void ble_scanner_begin() {
.notify_descr_uuid = bt_gattc_set_default_ble_notify_descr_uuid(),
.ble_scan_params = bt_gattc_set_default_ble_scan_params()};
scan_params.ble_scan_params.scan_filter_policy = ble_scan_filter;
scan_params.ble_scan_params.scan_type = ble_scan_type;
bt_gattc_set_ble_scan_params(&scan_params);
bt_client_event_cb_t event_cb = {.handler_gattc_cb = NULL,
.handler_gapc_cb = handle_bt_gapc_events};
Expand Down Expand Up @@ -79,7 +85,7 @@ static void task_scanner_timer() {
ESP_LOGI(TAG_BLE_CLIENT_MODULE, "Trackers task stopped");
ble_scanner_stop();
}
// ble_scan_duration++;
ble_scan_duration++;
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
Expand Down
1 change: 1 addition & 0 deletions firmware/components/ble_scann/ble_scann.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,5 @@ void ble_scanner_stop();
*/
bool ble_scanner_is_active();
void set_filter_type(uint8_t filter_type);
void set_scan_type(uint8_t scan_type);
#endif // BLE_SCANNER_H
18 changes: 17 additions & 1 deletion firmware/main/apps/ble/adv_scanner/adv_scan_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ static void adv_scanner_module_reset_menu() {

static void adv_filter_selection(uint8_t selection) {
set_filter_type(selection);
adv_scanner_module_reset_menu();
}

static void adv_type_selection(uint8_t selection) {
set_scan_type(selection);
adv_scanner_module_reset_menu();
}

void adv_scanner_display_filter() {
Expand All @@ -30,6 +36,15 @@ void adv_scanner_display_filter() {
general_submenu(adv_menu_filter);
}

void adv_scanner_display_type() {
general_submenu_menu_t adv_menu_type;
adv_menu_type.options = scan_type_items;
adv_menu_type.options_count = 2;
adv_menu_type.select_cb = adv_type_selection;
adv_menu_type.exit_cb = adv_scanner_module_reset_menu;
general_submenu(adv_menu_type);
}

static void adv_scanner_module_cb_event(uint8_t button_name,
uint8_t button_event) {
if (button_event != BUTTON_PRESS_DOWN) {
Expand All @@ -46,9 +61,10 @@ static void adv_scanner_module_cb_event(uint8_t button_name,
break;
case BUTTON_RIGHT:
if (current_item == SCAN_TYPE) {
adv_scanner_display_type();
} else if (current_item == SCAN_FILTER) {
adv_scanner_display_filter();
} else if (current_item == SCAN_START) {
ESP_LOGI(TAG_BLE_CLIENT_MODULE, "Scan start");
ble_scanner_register_cb(adv_scanner_display_record);
ble_scanner_begin();
}
Expand Down

0 comments on commit 13d7e14

Please sign in to comment.