Skip to content

Commit

Permalink
Remove BLE-specific role status functions
Browse files Browse the repository at this point in the history
  • Loading branch information
hedgecrw committed Jan 11, 2024
1 parent 3f4bbe5 commit 5069e71
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 17 deletions.
1 change: 0 additions & 1 deletion software/firmware/src/peripherals/include/bluetooth.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ void bluetooth_set_uninitialized(void);
void bluetooth_register_discovery_callback(ble_discovery_callback_t callback);
uint8_t bluetooth_get_current_ranging_role(void);
void bluetooth_set_current_ranging_role(uint8_t ranging_role);
bool bluetooth_is_changing_roles(void);
void bluetooth_write_range_results(const uint8_t *results, uint16_t results_length);
void bluetooth_start_advertising(void);
void bluetooth_stop_advertising(void);
Expand Down
20 changes: 6 additions & 14 deletions software/firmware/src/peripherals/src/bluetooth.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
// Static Global Variables ---------------------------------------------------------------------------------------------

static volatile uint16_t connection_mtu;
static volatile bool is_scanning, is_advertising, is_changing_roles, is_connected, ranges_requested;
static volatile bool data_requested, expected_scanning, expected_advertising, is_initialized, first_initialization;
static volatile bool is_scanning, is_advertising, is_connected, ranges_requested, data_requested;
static volatile bool expected_scanning, expected_advertising, is_initialized, first_initialization;
static volatile uint8_t adv_data_conn[HCI_ADV_DATA_LEN], scan_data_conn[HCI_ADV_DATA_LEN], current_ranging_role[3];
static const char adv_local_name[] = { 'T', 'o', 't', 'T', 'a', 'g' };
static const uint8_t adv_data_flags[] = { DM_FLAG_LE_GENERAL_DISC | DM_FLAG_LE_BREDR_NOT_SUP };
Expand Down Expand Up @@ -126,7 +126,7 @@ static void deviceManagerCallback(dmEvt_t *pDmEvt)
print("TotTag BLE: deviceManagerCallback: Received DM_RESET_CMPL_IND\n");
if (first_initialization)
AttsCalculateDbHash();
is_advertising = is_scanning = is_changing_roles = first_initialization = false;
is_advertising = is_scanning = first_initialization = false;
is_initialized = true;
if (expected_advertising)
bluetooth_start_advertising();
Expand All @@ -149,8 +149,6 @@ static void deviceManagerCallback(dmEvt_t *pDmEvt)
is_advertising = (pDmEvt->hdr.status == HCI_SUCCESS);
if (!is_advertising)
bluetooth_start_advertising();
else
is_changing_roles = false;
break;
case DM_ADV_STOP_IND:
print("TotTag BLE: deviceManagerCallback: Received DM_ADV_STOP_IND\n");
Expand Down Expand Up @@ -240,7 +238,7 @@ void bluetooth_init(uint8_t* uid)
const uint8_t ranging_role[] = { BLUETOOTH_COMPANY_ID, 0x00 };
memcpy((uint8_t*)current_ranging_role, ranging_role, sizeof(ranging_role));
data_requested = expected_scanning = expected_advertising = is_initialized = false;
is_scanning = is_advertising = is_changing_roles = is_connected = ranges_requested = false;
is_scanning = is_advertising = is_connected = ranges_requested = false;
first_initialization = true;
discovery_callback = NULL;

Expand Down Expand Up @@ -351,20 +349,14 @@ uint8_t bluetooth_get_current_ranging_role(void)
void bluetooth_set_current_ranging_role(uint8_t ranging_role)
{
// Update the current device ranging role in the BLE advertisements
is_changing_roles = is_advertising;
is_advertising = false;
current_ranging_role[2] = ranging_role;
#ifndef _TEST_RANGING_TASK
AppAdvSetAdValue(APP_ADV_DATA_CONNECTABLE, DM_ADV_TYPE_MANUFACTURER, sizeof(current_ranging_role), (uint8_t*)current_ranging_role);
AppAdvStop();
#endif
}

bool bluetooth_is_changing_roles(void)
{
// Return whether the advertised role is being updated
return is_changing_roles;
}

void bluetooth_write_range_results(const uint8_t *results, uint16_t results_length)
{
// Update the current set of ranging data
Expand All @@ -387,7 +379,7 @@ void bluetooth_start_advertising(void)
void bluetooth_stop_advertising(void)
{
// Attempt to stop advertising
expected_advertising = is_changing_roles = false;
expected_advertising = false;
if (is_initialized && is_advertising)
{
print("TotTag BLE: Stopping advertising...\n");
Expand Down
4 changes: 2 additions & 2 deletions software/firmware/src/tasks/app_task_ranging.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ static void verify_app_configuration(void)
if (current_role != bluetooth_get_current_ranging_role())
{
bluetooth_set_current_ranging_role(current_role);
for (uint32_t i = 0; bluetooth_is_changing_roles() && (i < BLE_ADV_TIMEOUT_MS); i += 10)
for (uint32_t i = 0; !bluetooth_is_advertising() && (i < BLE_ADV_TIMEOUT_MS); i += 10)
vTaskDelay(pdMS_TO_TICKS(10));
if (bluetooth_is_changing_roles())
if (!bluetooth_is_advertising())
{
bluetooth_reset();
for (int i = 0; !bluetooth_is_advertising() && (i < BLE_INIT_TIMEOUT_MS); i += 100)
Expand Down

0 comments on commit 5069e71

Please sign in to comment.