Skip to content

Commit

Permalink
add service to remotely change device mode
Browse files Browse the repository at this point in the history
  • Loading branch information
corruptbear committed Jun 22, 2024
1 parent 0c6a757 commit 32da276
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions software/firmware/src/app/app_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ typedef enum { BATTERY_EMPTY = 3500, BATTERY_CRITICAL = 3680, BATTERY_NOMINAL =
#define BLE_MAINTENANCE_EXPERIMENT_CHAR 0x2e,0x5d,0x5e,0x39,0x31,0x52,0x45,0x0c,0x90,0xee,0x3f,0xa2,0x61,0x31,0x8c,0xd6
#define BLE_MAINTENANCE_COMMAND_CHAR 0x2e,0x5d,0x5e,0x39,0x31,0x52,0x45,0x0c,0x90,0xee,0x3f,0xa2,0x62,0x31,0x8c,0xd6
#define BLE_MAINTENANCE_DATA_CHAR 0x2e,0x5d,0x5e,0x39,0x31,0x52,0x45,0x0c,0x90,0xee,0x3f,0xa2,0x63,0x31,0x8c,0xd6
#define BLE_MODE_SWITCH_CHAR 0x2e,0x5d,0x5e,0x39,0x31,0x52,0x45,0x0c,0x90,0xee,0x3f,0xa2,0x64,0x31,0x8c,0xd6


// Ranging Protocol Configuration --------------------------------------------------------------------------------------
Expand Down
10 changes: 10 additions & 0 deletions software/firmware/src/tasks/app_task_ranging.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,16 @@ void app_activate_find_my_tottag(uint32_t seconds_to_activate)
app_maintenance_activate_find_my_tottag(seconds_to_activate);
}

void app_switch_mode(uint8_t command)
{
if (command==1)
{ //enable data downloading from ranging mode
//disable storage writing
storage_disable(true);
storage_enter_maintenance_mode();
}
}

void AppTaskRanging(void *uid)
{
// Store the UID and application task handle
Expand Down
1 change: 1 addition & 0 deletions software/firmware/src/tasks/app_tasks.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ typedef struct __attribute__ ((__packed__))
// Application Task Public Functions
void app_notify(app_notification_t notification, bool from_isr);
void app_activate_find_my_tottag(uint32_t seconds_to_activate);
void app_switch_mode(uint8_t command);
uint32_t app_get_experiment_time(int32_t offset);
uint32_t app_experiment_time_to_rtc_time(uint32_t experiment_time);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ uint8_t handleLiveStatsWrite(dmConnId_t connId, uint16_t handle, uint8_t operati
app_activate_find_my_tottag(*(uint32_t*)pValue);
else if (handle == TIMESTAMP_HANDLE)
rtc_set_time_from_timestamp(*(uint32_t*)pValue);
#ifdef _REMOTE_MODE_SWITCH_ENABLED
else if (handle == APP_MODE_SWITCH_HANDLE)
app_switch_mode(*(uint8_t*)pValue);
#endif
return ATT_SUCCESS;
}

Expand Down
36 changes: 36 additions & 0 deletions software/firmware/src/tasks/bluetooth/live_stats_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ static const uint16_t findMyTottagDurationLen = sizeof(findMyTottagDuration);
static const uint8_t findMyTottagDesc[] = "FindMyTottagRequest";
static const uint16_t findMyTottagDescLen = sizeof(findMyTottagDesc);

#ifdef _REMOTE_MODE_SWITCH_ENABLED
static const uint8_t modeSwitchChUuid[] = { BLE_MODE_SWITCH_CHAR };
static const uint8_t modeSwitchChar[] = { ATT_PROP_WRITE, UINT16_TO_BYTES(APP_MODE_SWITCH_HANDLE), BLE_MODE_SWITCH_CHAR };
static const uint16_t modeSwitchCharLen = sizeof(modeSwitchChar);
static uint32_t operationMode = 0;
static const uint16_t operationModeLen = sizeof(operationMode);
static const uint8_t modeSwitchDesc[] = "AppModeSwitch";
static const uint16_t modeSwitchDescLen = sizeof(modeSwitchDesc);
#endif

static const uint8_t rangingChUuid[] = { BLE_LIVE_STATS_RANGING_CHAR };
static const uint8_t rangesChar[] = { ATT_PROP_NOTIFY, UINT16_TO_BYTES(RANGES_HANDLE), BLE_LIVE_STATS_RANGING_CHAR };
static const uint16_t rangesCharLen = sizeof(rangesChar);
Expand Down Expand Up @@ -137,6 +147,32 @@ static const attsAttr_t liveStatsList[] =
0,
ATTS_PERMIT_READ
},
#ifdef _REMOTE_MODE_SWITCH_ENABLED
{
attChUuid,
(uint8_t*)modeSwitchChar,
(uint16_t*)&modeSwitchCharLen,
sizeof(modeSwitchChar),
0,
ATTS_PERMIT_READ
},
{
modeSwitchChUuid,
(uint8_t*)&operationMode,
(uint16_t*)&operationModeLen,
sizeof(operationMode),
(ATTS_SET_UUID_128 | ATTS_SET_WRITE_CBACK),
ATTS_PERMIT_WRITE
},
{
attChUserDescUuid,
(uint8_t*)modeSwitchDesc,
(uint16_t*)&modeSwitchDescLen,
sizeof(modeSwitchDesc),
0,
ATTS_PERMIT_READ
},
#endif
{
attChUuid,
(uint8_t*)rangesChar,
Expand Down
5 changes: 5 additions & 0 deletions software/firmware/src/tasks/bluetooth/live_stats_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ enum
FIND_MY_TOTTAG_CHAR_HANDLE, // FindMyTottag characteristic
FIND_MY_TOTTAG_HANDLE, // FindMyTottag value
FIND_MY_TOTTAG_DESC_HANDLE, // FindMyTottag description
#ifdef _REMOTE_MODE_SWITCH_ENABLED
APP_MODE_SWITCH_CHAR_HANDLE, // Mode switch characteristic
APP_MODE_SWITCH_HANDLE, // Mode switch value
APP_MODE_SWITCH_DESC_HANDLE, // Mode switch description
#endif
RANGES_CHAR_HANDLE, // Current ranges characteristic
RANGES_HANDLE, // Current ranges
RANGES_DESC_HANDLE, // Current ranges description
Expand Down
1 change: 1 addition & 0 deletions software/firmware/src/tasks/ranging_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ void ranging_begin(schedule_role_t role)
xTaskNotify(ranging_task_handle, role, eSetValueWithOverwrite);
}


bool ranging_active(void)
{
// Return whether actively ranging
Expand Down

0 comments on commit 32da276

Please sign in to comment.