I was working from the ANCS example and the way it stores the remote characteristics in flash. I expanded the example to add the time service, and was now storing additional data for the same peer. When connecting to a known peer, I was expecting the code to fail on first attempt, because the data in the DB should be too small (ie not holding the newly added time server characteristics). From my interpretation, the code is actually attempting to do so, but deep inside pds_peer_data_read() prevents that (more below).
From the ANCS example, this is how the DB is loaded:
case PM_EVT_BONDED_PEER_CONNECTED: { if (p_evt->peer_id != PM_PEER_ID_INVALID) { uint32_t data_len = sizeof(m_peer_srv_buf); ret = pm_peer_data_remote_db_load(p_evt->peer_id, m_peer_srv_buf, &data_len); if (ret == NRF_ERROR_NOT_FOUND) { ...snip... } else { // Check if the load was successful. ASSERT(data_len == sizeof(m_peer_srv_buf)); APP_ERROR_CHECK(ret); NRF_LOG_INFO("Remote Database loaded from flash.");
From the call pm_peer_data_remote_db_load(p_evt->peer_id, m_peer_srv_buf, &data_len);
I expected data_len to come back with the data length in the entry from flash, but it didn't. If I debug, the above call ultimately calls pds_peer_data_read()
which doesn't change data_len. And by function definition I don't think it actually could.
So data_len remains unchanged, and the
ASSERT(data_len == sizeof(m_peer_srv_buf));
will always succeed. It's a rare case, but maybe there's a bug here ?