diff --git a/software/firmware/launchConfigs/TestFull.launch b/software/firmware/launchConfigs/TestFull.launch
index ef325b1c..4ecc747e 100644
--- a/software/firmware/launchConfigs/TestFull.launch
+++ b/software/firmware/launchConfigs/TestFull.launch
@@ -78,6 +78,6 @@
-
+
diff --git a/software/firmware/src/peripherals/src/bluetooth.c b/software/firmware/src/peripherals/src/bluetooth.c
index baa51aca..92b95491 100644
--- a/software/firmware/src/peripherals/src/bluetooth.c
+++ b/software/firmware/src/peripherals/src/bluetooth.c
@@ -309,8 +309,10 @@ void bluetooth_set_current_ranging_role(uint8_t ranging_role)
{
// Update the current device ranging role in the BLE advertisements
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
}
void bluetooth_write_range_results(const uint8_t *results, uint16_t results_length)
diff --git a/software/firmware/src/tasks/app_task_maintenance.c b/software/firmware/src/tasks/app_task_maintenance.c
index 639b7f29..de5e8dd1 100644
--- a/software/firmware/src/tasks/app_task_maintenance.c
+++ b/software/firmware/src/tasks/app_task_maintenance.c
@@ -63,8 +63,10 @@ void AppTaskMaintenance(void *uid)
app_task_handle = xTaskGetCurrentTaskHandle();
uint32_t notification_bits = 0;
- // Register handler for battery status changes
+ // Register handler for battery status changes and verify correct mode of operation
battery_register_event_callback(battery_event_handler);
+ if (!battery_monitor_is_plugged_in())
+ storage_flush_and_shutdown();
// Wait until the BLE stack has been fully initialized
while (!bluetooth_is_initialized())
diff --git a/software/firmware/src/tasks/app_task_ranging.c b/software/firmware/src/tasks/app_task_ranging.c
index 2651a5c4..9fccd6e8 100644
--- a/software/firmware/src/tasks/app_task_ranging.c
+++ b/software/firmware/src/tasks/app_task_ranging.c
@@ -192,6 +192,8 @@ void AppTaskRanging(void *uid)
battery_register_event_callback(battery_event_handler);
imu_register_motion_change_callback(motion_change_handler);
bluetooth_register_discovery_callback(ble_discovery_handler);
+ if (battery_monitor_is_plugged_in())
+ storage_flush_and_shutdown();
// Retrieve current experiment details from non-volatile storage
experiment_details_t current_experiment;
@@ -201,12 +203,12 @@ void AppTaskRanging(void *uid)
devices_found = false;
while (!bluetooth_is_initialized())
vTaskDelay(1);
- bluetooth_set_current_ranging_role(ROLE_IDLE);
// Update the BLE address whitelist
bluetooth_clear_whitelist();
for (uint8_t i = 0; i < current_experiment.num_devices; ++i)
bluetooth_add_device_to_whitelist(current_experiment.uids[i]);
+ bluetooth_set_current_ranging_role(ROLE_IDLE);
// Loop forever, sleeping until an application notification is received
while (true)
diff --git a/software/firmware/src/tasks/app_tasks.h b/software/firmware/src/tasks/app_tasks.h
index 2b12ad3a..9d823b24 100644
--- a/software/firmware/src/tasks/app_tasks.h
+++ b/software/firmware/src/tasks/app_tasks.h
@@ -8,7 +8,7 @@
// Task Type Definitions -----------------------------------------------------------------------------------------------
-typedef enum { ROLE_IDLE = 0, ROLE_MASTER, ROLE_PARTICIPANT, ROLE_ASLEEP } schedule_role_t;
+typedef enum { ROLE_IDLE = 10, ROLE_MASTER, ROLE_PARTICIPANT, ROLE_ASLEEP } schedule_role_t;
typedef enum {
APP_NOTIFY_VERIFY_CONFIGURATION = 0b00000001,
diff --git a/software/firmware/src/tasks/ranging_task.c b/software/firmware/src/tasks/ranging_task.c
index a3cf6909..1cff2d1e 100644
--- a/software/firmware/src/tasks/ranging_task.c
+++ b/software/firmware/src/tasks/ranging_task.c
@@ -1,7 +1,7 @@
// Header Inclusions ---------------------------------------------------------------------------------------------------
#include "app_tasks.h"
-#include "bluetooth.h"
+#include "logging.h"
#include "rtc.h"
#include "scheduler.h"
@@ -41,9 +41,9 @@ void RangingTask(void *uid)
// Sleep until time to start ranging with the indicated role
if ((xTaskNotifyWait(pdFALSE, 0xffffffff, &desired_role_bits, portMAX_DELAY) == pdTRUE) && uid)
{
- bluetooth_set_current_ranging_role(desired_role_bits);
+ print("TotTag Ranging: Starting ranging task as %s\n", (desired_role_bits == ROLE_MASTER) ? "MASTER" : "PARTICIPANT");
scheduler_run((schedule_role_t)desired_role_bits, rtc_get_timestamp());
- bluetooth_set_current_ranging_role(ROLE_IDLE);
+ print("TotTag Ranging: Ranging task has stopped!\n");
}
// Notify the application that network connectivity has been lost