This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

bool pds_peer_id_is_allocated return false

/**@brief Function for finding out whether a peer ID is in use.
 *
 * @param[in]  peer_id  The peer ID to inquire about.
 *
 * @retval  true   peer_id is in use.
 * @retval  false  peer_id is free, or the module is not initialized.
 */
bool pds_peer_id_is_allocated(pm_peer_id_t peer_id);

Hi All,

someone can be explain me what means "peer_id is free"? This function sometimes return false and cause an assert of my application, but i don't understand why.

  • Hello annapalu

    When the peer manager stores data about a connected peer it allocates a 16 bit ID number for that peer. The pds_peer_id_is_allocated function takes a peer ID number as argument, and checks if that specific ID is in use by any previously stored peer. If the ID number is in use it will return a "true". If it is not in use, it will return a "false", meaning the ID is free to be used.

    The function will also return a false if the module is not initialized, but since you say it only returns false sometimes, I assume the module is correctly initialized.

    Best regards

    Jørn Frøysa

  • Hi Jorn,

    thanks for the answer. Yes the reason that sometimes give me a false is because is free.

    So, there is something not clear. Why the function

        ret_code_t pdb_write_buf_get(pm_peer_id_t       peer_id,
                                 pm_peer_data_id_t  data_id,
                                 uint32_t           n_bufs,
                                 pm_peer_data_t   * p_peer_data)
    {
        VERIFY_MODULE_INITIALIZED();
        VERIFY_PARAM_NOT_NULL(p_peer_data);
        VERIFY_DATA_ID_WRITE_BUF(data_id);
        if (   (n_bufs == 0)
            || (n_bufs > N_WRITE_BUFFERS)
            || !pds_peer_id_is_allocated(peer_id))
        {
            return NRF_ERROR_INVALID_PARAM;
        }
    

    why this function is id is free return INVALID_PARAMETER?

  • From what I can see the NRF_ERROR_INVALID_PARAM can be caused by either the VERIFY_DATA_ID_WRITE_BUF macro, from the description "Macro for verifying that the data ID is among the values eligible for using the write buffer.", or if the if statement fails. If the peer ID is valid it should not fail. Have you checked if the macro might be the source of the error?

  • hi Jorn, yes is the if statement that fail, in particular the check pds_peer_id_is_allocated(peer_id) that return true;

  • Apologies, I read the if statement wrong in my previous post. The pds_peer_id_is_allocated then returns a false as the if statement arguement is inverted. This means the peer_id value is not in use, which means the function cannot retrieve a pointer to it. You will need to trace the peer_id to see where gets its value, as it seems to be passing an ID that is not in use.

Related