uint32_t sd_ble_gap_scan_start(adapter_t *adapter, ble_gap_scan_params_t const *const p_scan_params,
                               ble_data_t const *p_adv_report_buffer)
{
    encode_function_t encode_function = [&](uint8_t *buffer, uint32_t *length) -> uint32_t {
        const auto err_code =
            ble_gap_scan_start_req_enc(p_scan_params, p_adv_report_buffer, buffer, length);

#if defined(NRF_SD_BLE_API_VERSION) && NRF_SD_BLE_API_VERSION > 5
        app_ble_gap_scan_data_set(p_adv_report_buffer->p_data);
#endif

        return err_code;
    };

    decode_function_t decode_function = [&](uint8_t *buffer, uint32_t length,
                                            uint32_t *result) -> uint32_t {
        const auto err_code = ble_gap_scan_start_rsp_dec(buffer, length, result);

        if (err_code != NRF_SUCCESS)
        {
            app_ble_gap_scan_data_unset(true);
        }

        return err_code;
    };

    return gap_encode_decode(adapter, encode_function, decode_function);
}
Ejemplo n.º 2
0
/**@brief Command response callback function for @ref sd_ble_gap_scan_start BLE command.
 *
 * Callback for decoding the output parameters and the command response return code.
 *
 * @param[in] p_buffer  Pointer to begin of command response buffer.
 * @param[in] length    Length of data in bytes.
 *
 * @return Decoded command response return code.
 */
static uint32_t gap_scan_start_rsp_dec(const uint8_t * p_buffer, uint16_t length)
{
    uint32_t result_code = 0;

    const uint32_t err_code = ble_gap_scan_start_rsp_dec(p_buffer,
                                                         length,
                                                         &result_code);

    //@note: Should never fail.
    APP_ERROR_CHECK(err_code);

    return result_code;
}