Skip to content

Commit

Permalink
connect to any adv data
Browse files Browse the repository at this point in the history
  • Loading branch information
vChavezB committed Apr 12, 2024
1 parent 52de0d8 commit cda00c8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ build*
test/renode/logs/*
test/renode/*.html
test/renode/*.xml
test/renode/snapshots
1 change: 1 addition & 0 deletions samples/uptime/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ CONFIG_LIB_CPLUSPLUS=y
CONFIG_STD_CPP17=y
CONFIG_NEWLIB_LIBC=y
CONFIG_BLE_UTILS=y
CONFIG_BT_ASSERT=n
6 changes: 4 additions & 2 deletions test/renode/load.resc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ emulation CreateBLEMedium "wireless"

mach add "central"
machine LoadPlatformDescription @platforms/cpus/nrf52840.repl

connector Connect sysbus.radio wireless

showAnalyzer uart0

Expand All @@ -21,4 +21,6 @@ mach set "central"
sysbus LoadELF $ORIGIN/uptime_central/build/zephyr/zephyr.elf

mach set "peripheral"
sysbus LoadELF $ORIGIN/../../samples/uptime/build/zephyr/zephyr.elf
sysbus LoadELF $ORIGIN/../../samples/uptime/build/zephyr/zephyr.elf

start
44 changes: 23 additions & 21 deletions test/renode/uptime_central/src/discovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,32 @@ static uint8_t service_discover_cb(bt_conn *conn,
return BT_GATT_ITER_STOP;
}



static bool adv_data_cb(bt_data *data, void *user_data)
{
auto addr = static_cast<bt_addr_le_t*>(user_data);
int i;
int err = bt_le_scan_stop();
if (err) {
LOG_INF("Stop LE scan failed (err %d)", err);
return true;
}

LOG_INF("Connecting..");
err = bt_conn_le_create(addr, &conn_create_param,
&conn_default_param, &default_conn);
if (err) {
LOG_ERR("Create conn failed (err %d)", err);
start_scan();
}
return false;

/*
TODO wait for upcoming changes with uuid advertisement
until then do not compare uuid in adv data
*/
/*
switch (data->type) {
case BT_DATA_UUID128_SOME:
case BT_DATA_UUID128_ALL:
Expand All @@ -151,39 +172,20 @@ static bool adv_data_cb(bt_data *data, void *user_data)
for (i = 0; i < data->data_len; i += BT_UUID_SIZE_128) {
int err;

/*
TODO wait for upcoming changes with uuid advertisement
until then do not compare uuid in adv data
*/
/*
bt_uuid_128 adv_uuid ={ .uuid = { BT_UUID_TYPE_128 }};
memcpy(adv_uuid.val, data->data+i, BT_UUID_SIZE_128);
const int uuid_match = bt_uuid_cmp(&adv_uuid.uuid, &uptime::uuid::svc_base.uuid);
if (uuid_match != 0) {
continue;
}
LOG_INF("Matched Uptime adv. UUID");
*/
err = bt_le_scan_stop();
if (err) {
LOG_INF("Stop LE scan failed (err %d)", err);
continue;
}

LOG_INF("Connecting..");
err = bt_conn_le_create(addr, &conn_create_param,
&conn_default_param, &default_conn);
if (err) {
LOG_ERR("Create conn failed (err %d)", err);
start_scan();
}

return false;
}
}
return true;
*/
}

static void device_found_cb(const bt_addr_le_t *addr, int8_t rssi, uint8_t type,
Expand Down

0 comments on commit cda00c8

Please sign in to comment.