services/data_logging: avoid repeatedly reopening a datalogging session

If CoreApp is not ready for us, we can end up in trouble and reopning a
session that will never do anything but NACK.  Give up after 20 tries.

Signed-off-by: Joshua Wise <joshua@accelerated.tech>
This commit is contained in:
Joshua Wise 2025-09-26 18:29:00 -07:00 committed by Jinchang
parent 4051c5bb97
commit 75cc979a09
1 changed files with 17 additions and 1 deletions

View File

@ -76,6 +76,14 @@ static const uint16_t ENDPOINT_ID_DATA_LOGGING = 0x1a7a;
static const uint8_t MAX_NACK_COUNT = 20; static const uint8_t MAX_NACK_COUNT = 20;
// If we don't have a PRF -- or we are in PRF, or CoreApp is confused about
// whether we have a PRF or not -- then CoreApp might decide not to talk to
// us, and will NACK our DLS open requests. Fair enough, I guess, but if
// that's what's happening, then we shouldn't waste our battery continually
// trying to reopen the session.
static const uint8_t MAX_UNEXPECTED_NACK_COUNT = 20;
static uint8_t s_unexpected_nacks = 0;
static void reschedule_ack_timeout(void); static void reschedule_ack_timeout(void);
static void update_session_state(DataLoggingSession *session, DataLoggingSessionCommState new_state, static void update_session_state(DataLoggingSession *session, DataLoggingSessionCommState new_state,
@ -373,6 +381,12 @@ static void prv_dls_endpoint_handle_nack(uint8_t session_id) {
case DataLoggingSessionCommStateOpening: case DataLoggingSessionCommStateOpening:
//Currently, these messages never get NACK'd //Currently, these messages never get NACK'd
PBL_LOG(LOG_LEVEL_ERROR, "Unexpected NACK"); PBL_LOG(LOG_LEVEL_ERROR, "Unexpected NACK");
if (s_unexpected_nacks < MAX_UNEXPECTED_NACK_COUNT) {
s_unexpected_nacks++;
if (s_unexpected_nacks == MAX_UNEXPECTED_NACK_COUNT) {
PBL_LOG(LOG_LEVEL_ERROR, "I give up; I will not try to autonomously repair sessions anymore");
}
}
break; break;
case DataLoggingSessionCommStateSending: case DataLoggingSessionCommStateSending:
//Maybe queue a resend //Maybe queue a resend
@ -391,8 +405,10 @@ static void prv_dls_endpoint_handle_nack(uint8_t session_id) {
mutex_unlock(s_endpoint_data.mutex); mutex_unlock(s_endpoint_data.mutex);
// reopen the session that was NACK'ed // reopen the session that was NACK'ed
if (s_unexpected_nacks < MAX_UNEXPECTED_NACK_COUNT) {
dls_endpoint_open_session(logging_session); dls_endpoint_open_session(logging_session);
} }
}
//! System task callback executed which reopens the next session in the list built up by report_cmd_system_task_cb //! System task callback executed which reopens the next session in the list built up by report_cmd_system_task_cb
static void prv_reopen_next_session_system_task_cb(void* data) { static void prv_reopen_next_session_system_task_cb(void* data) {