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

how to use dm_device_delete

Hi all! I want to allow only 1 device to bond at a time. If another device bonding, I want to delete the previously bonded one. I tried to use dm_device_delete_all() in DM_EVT_SECURITY_SETUP_COMPLETE event, but it delete the current device too. I want to use dm_device_delete to delete the previous one, but I haven't p_handle for the previously bonded device. Is there any api function to get all bonded device handle, or something similar?

Thanks!!!

Parents
  • You can create a new function something like this in the device_manager_xxx.c

    dm_application_instance_t is only used for sanity checking, you can ignore that

    ret_code_t dm_device_delete_all_except this(dm_application_instance_t const * p_app_handle,
                                                                       dm_handle_t const * p_dm_handle)
    {
        VERIFY_MODULE_INITIALIZED();
        NULL_PARAM_CHECK(p_app_handle);
        NULL_PARAM_CHECK(p_dm_handle);
        VERIFY_APP_REGISTERED((*p_app_handle));
        VERIFY_DEVICE_INSTANCE(p_dm_handle->device_id);
    
        DM_MUTEX_LOCK();
    
        uint32_t err_code = NRF_SUCCESS;
    
        DM_TRC("[DM]: >> dm_device_delete_all_except_this\r\n");
    
        for (uint32_t index = 0; index < DEVICE_MANAGER_MAX_BONDS; index++)
        {
            if ((m_peer_table[index].id_bitmap != UNASSIGNED) && (p_dm_handle->device_id != index))
            {
                err_code = device_instance_free(index);
            }
        }
    
        DM_TRC("[DM]: << dm_device_delete_all_except_this\r\n");
    
        DM_MUTEX_UNLOCK();
    
        return err_code;
    }
    

    And then in the device_manager_evt_handler that is registered in your application, you can call this function when you get DM_EVT_SECURITY_SETUP_COMPLETE

Reply
  • You can create a new function something like this in the device_manager_xxx.c

    dm_application_instance_t is only used for sanity checking, you can ignore that

    ret_code_t dm_device_delete_all_except this(dm_application_instance_t const * p_app_handle,
                                                                       dm_handle_t const * p_dm_handle)
    {
        VERIFY_MODULE_INITIALIZED();
        NULL_PARAM_CHECK(p_app_handle);
        NULL_PARAM_CHECK(p_dm_handle);
        VERIFY_APP_REGISTERED((*p_app_handle));
        VERIFY_DEVICE_INSTANCE(p_dm_handle->device_id);
    
        DM_MUTEX_LOCK();
    
        uint32_t err_code = NRF_SUCCESS;
    
        DM_TRC("[DM]: >> dm_device_delete_all_except_this\r\n");
    
        for (uint32_t index = 0; index < DEVICE_MANAGER_MAX_BONDS; index++)
        {
            if ((m_peer_table[index].id_bitmap != UNASSIGNED) && (p_dm_handle->device_id != index))
            {
                err_code = device_instance_free(index);
            }
        }
    
        DM_TRC("[DM]: << dm_device_delete_all_except_this\r\n");
    
        DM_MUTEX_UNLOCK();
    
        return err_code;
    }
    

    And then in the device_manager_evt_handler that is registered in your application, you can call this function when you get DM_EVT_SECURITY_SETUP_COMPLETE

Children
  • Thanks, it works with a little modification:

    ret_code_t dm_device_delete_all_except_this(dm_application_instance_t const * p_app_handle,
                                                                   dm_handle_t const * p_dm_handle)
    {
        VERIFY_MODULE_INITIALIZED();
        NULL_PARAM_CHECK(p_app_handle);
        NULL_PARAM_CHECK(p_dm_handle);
        VERIFY_APP_REGISTERED((*p_app_handle));
        VERIFY_DEVICE_INSTANCE(p_dm_handle->device_id);
    
        DM_MUTEX_LOCK();
    
        uint32_t err_code = NRF_SUCCESS;
    
        DM_TRC("[DM]: >> dm_device_delete_all_except_this\r\n");
    
        for (uint32_t index = 0; index < DEVICE_MANAGER_MAX_BONDS; index++)
        {
            if ((m_peer_table[index].id_bitmap != UNASSIGNED) && (p_dm_handle->device_id != index))
            {
                err_code = device_instance_free(index);
            }
        }
    
        DM_TRC("[DM]: << dm_device_delete_all_except_this\r\n");
    
        DM_MUTEX_UNLOCK();
    
        return err_code;
    }
    
  • Just used dm_app_instance to sanity checking. This should work perfectly

Related