Skip to content

Commit

Permalink
net: lib: nrf_cloud_pgps: Fix bug in prediction set update
Browse files Browse the repository at this point in the history
Fixed a bug which caused the prediction set update to fail. The
failure happened when all downloaded predictions could not be
written to flash sequentially.

NCSDK-25224

Signed-off-by: Tommi Kangas <[email protected]>
  • Loading branch information
tokangas authored and nordicjm committed Jan 18, 2024
1 parent 4d81e69 commit f5162ea
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,10 @@ Libraries for networking
* The AGNSS handling to use the AGNSS app ID string and corresponding MQTT topic instead of the older AGPS app ID string and topic.
* The :c:func:`nrf_cloud_obj_location_request_create` and :c:func:`nrf_cloud_location_request` functions to accept the :c:struct:`nrf_cloud_location_config` structure in place of the ``bool request_loc`` parameter.

* :ref:`lib_nrf_cloud_pgps` library:

* Fixed a bug in prediction set update when the :kconfig:option:`CONFIG_NRF_CLOUD_PGPS_REPLACEMENT_THRESHOLD` Kconfig option was set to non-zero value.

* :ref:`lib_nrf_provisioning` library:

* Renamed nRF Device provisioning to :ref:`lib_nrf_provisioning`.
Expand Down
14 changes: 11 additions & 3 deletions subsys/net/lib/nrf_cloud/src/nrf_cloud_pgps.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ struct pgps_index {
uint8_t cur_pnum;
bool partial_request;
bool stale_server_data;
uint32_t storage_extent;
int32_t storage_extent;
int store_block;

/* Array of memory offsets to predictions, in sorted time order.
Expand Down Expand Up @@ -1500,8 +1500,12 @@ static int consume_pgps_data(uint8_t pnum, const char *buf, size_t buf_len)

index.loading_count++;
finished = (index.loading_count == index.expected_count);
store_prediction(prediction_ptr, buf_len, (uint32_t)gps_sec,
finished || (index.storage_extent == 1));
err = store_prediction(prediction_ptr, buf_len, (uint32_t)gps_sec,
finished || (index.storage_extent == 1));
if (err) {
LOG_ERR("Error storing prediction:%d", err);
goto fail;
}
index.predictions[pnum] = npgps_block_to_pointer(index.store_block);

if (!finished) {
Expand Down Expand Up @@ -1557,6 +1561,10 @@ static int consume_pgps_data(uint8_t pnum, const char *buf, size_t buf_len)
LOG_ERR("Error opening storage again:%d", err);
goto fail;
}
} else if (index.storage_extent < 0) {
LOG_ERR("Unexpected storage extent:%d", index.storage_extent);
err = -ENOMEM;
goto fail;
}
}
} else {
Expand Down
15 changes: 9 additions & 6 deletions subsys/net/lib/nrf_cloud/src/nrf_cloud_pgps_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,18 +328,21 @@ void npgps_free_block(int block)
pool.block_used[block] = false;
}

int npgps_get_block_extent(int block)
int npgps_get_block_extent(int store_block)
{
int i;
int len = 0;
/* Start counting from 1, because the first block has already been marked as being used. */
int len = 1;

for (i = 0; i < num_blocks; i++) {
if (pool.block_used[block]) {
store_block++;
while (store_block < num_blocks) {
if (pool.block_used[store_block]) {
break;
}
block = (block + 1) % num_blocks;

len++;
store_block++;
}

return len;
}

Expand Down

0 comments on commit f5162ea

Please sign in to comment.