Skip to content

Commit

Permalink
lib: location: Ignore timeout if another event processing ongoing
Browse files Browse the repository at this point in the history
It's possible that we get GNSS fix and when we are sending an event
about it to the application, location request timeout expires.
When an event is indicated to the location library core,
a check is made whether an event processing is already ongoing.
And if there is, new event is ignored.

Signed-off-by: Tommi Rantanen <[email protected]>
  • Loading branch information
trantanen authored and nordicjm committed Sep 29, 2023
1 parent 7e80dfb commit edbfa18
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
5 changes: 5 additions & 0 deletions include/modem/location.h
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,11 @@ struct location_config {
* Default value is 300000 (5 minutes). It is applied when
* @ref location_config_defaults_set function is called and can be changed
* at build time with CONFIG_LOCATION_REQUEST_DEFAULT_TIMEOUT configuration.
*
* This is intended to be a safety timer preventing location request from getting stuck
* in any of its phases, because parts of the method-specific functionality are not
* covered by method-specific timeouts. You should use a rather large value that
* can be one minute or more larger than the sum of method-specific timeouts.
*/
int32_t timeout;

Expand Down
16 changes: 10 additions & 6 deletions lib/location/location_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -777,9 +777,15 @@ void location_core_event_cb(const struct location_data *location)
loc_req_info.current_event_data.location = *location;
}

k_work_submit_to_queue(
location_core_work_queue_get(),
&location_event_cb_work);
if (k_work_busy_get(&location_event_cb_work) == 0) {
/* If work item is idle, schedule it */
k_work_submit_to_queue(
location_core_work_queue_get(),
&location_event_cb_work);
} else {
LOG_INF("Event is already scheduled so ignoring event %d",
loc_req_info.current_event_data.id);
}
}

struct k_work_q *location_core_work_queue_get(void)
Expand Down Expand Up @@ -821,9 +827,7 @@ static void location_core_timeout_work_fn(struct k_work *work)
loc_req_info.current_event_data.id = LOCATION_EVT_TIMEOUT;
loc_req_info.execute_fallback = false;

k_work_submit_to_queue(
location_core_work_queue_get(),
&location_event_cb_work);
location_core_event_cb(NULL);
}

void location_core_timer_start(int32_t timeout)
Expand Down

0 comments on commit edbfa18

Please sign in to comment.