GAP Observer Exported Functions

group Observer_Exported_Functions

Functions

T_GAP_CAUSE le_scan_set_param(T_LE_SCAN_PARAM_TYPE param, uint8_t len, void *p_value)

Set a scan parameter.

This function can be called with a scan parameter type T_LE_SCAN_PARAM_TYPE and it will set the scan parameter. The ‘p_value’ field must point to an appropriate data type that meets the requirements for the corresponding parameter type. (For example: if required data length for parameter type is 2 octets, p_value should be cast to a pointer of uint16_t.)

Example usage

void test(void)
{
    uint8_t scan_mode = GAP_SCAN_MODE_ACTIVE;
    uint16_t scan_interval = DEFAULT_SCAN_INTERVAL;
    uint16_t scan_window = DEFAULT_SCAN_WINDOW;
    uint8_t scan_filter_policy = GAP_SCAN_FILTER_ANY;
    uint8_t scan_filter_duplicate = GAP_SCAN_FILTER_DUPLICATE_ENABLE;

    le_scan_set_param(GAP_PARAM_SCAN_MODE, sizeof(scan_mode), &scan_mode);
    le_scan_set_param(GAP_PARAM_SCAN_INTERVAL, sizeof(scan_interval), &scan_interval);
    le_scan_set_param(GAP_PARAM_SCAN_WINDOW, sizeof(scan_window), &scan_window);
    le_scan_set_param(GAP_PARAM_SCAN_FILTER_POLICY, sizeof(scan_filter_policy),
                     &scan_filter_policy);
    le_scan_set_param(GAP_PARAM_SCAN_FILTER_DUPLICATES, sizeof(scan_filter_duplicate),
                     &scan_filter_duplicate);
}
Parameters:
  • param[in] Scan parameter type T_LE_SCAN_PARAM_TYPE.

  • len[in] Length of data to write.

  • p_value[in] Pointer to data to write.

Return values:
  • GAP_CAUSE_SUCCESS – Operation success.

  • Others – Operation failure.

Returns:

Operation result.

T_GAP_CAUSE le_scan_get_param(T_LE_SCAN_PARAM_TYPE param, void *p_value)

Get a scan parameter.

This function can be called with a scan parameter type T_LE_SCAN_PARAM_TYPE and it will get the scan parameter. The ‘p_value’ field must point to an appropriate data type that meets the requirements for the corresponding parameter type. (For example: if required data length for parameter type is 2 octets, p_value should be cast to a pointer of uint16_t.)

Example usage

void test(void)
{
    uint16_t scan_interval;
    le_scan_get_param(GAP_PARAM_SCAN_INTERVAL, &scan_interval);
}
Parameters:
  • param[in] Scan parameter type T_LE_SCAN_PARAM_TYPE.

  • p_value[inout] Pointer to location to get the parameter value.

Return values:
  • GAP_CAUSE_SUCCESS – Operation success.

  • Others – Operation failure.

Returns:

Operation result.

T_GAP_CAUSE le_scan_start(void)

Start scan.

If sending request operation is successful, the starting result will be returned in one of the following ways:

If the device is in the scanning state GAP_SCAN_STATE_SCANNING, the advertising data or scan response data will be returned by the callback registered by le_register_app_cb with msg type GAP_MSG_LE_SCAN_INFO.

Applications can only call this API after Bluetooth Host is ready.

Explanation: If Bluetooth Host is ready, the application will be notified by message GAP_MSG_LE_DEV_STATE_CHANGE with new_state about gap_init_state which is configured as GAP_INIT_STATE_STACK_READY.

Example usage

void test(void)
{
    le_scan_start();
}

void app_handle_dev_state_evt(T_GAP_DEV_STATE new_state, uint16_t cause)
{
    APP_PRINT_INFO5("app_handle_dev_state_evt: init state %d scan state %d adv state %d conn state %d cause 0x%x",
                   new_state.gap_init_state,
                   new_state.gap_scan_state, new_state.gap_adv_state, new_state.gap_conn_state, cause);

    if (gap_dev_state.gap_scan_state != new_state.gap_scan_state)
    {
        if (new_state.gap_scan_state == GAP_SCAN_STATE_IDLE)
        {
            APP_PRINT_INFO0("GAP scan stop");
            data_uart_print("GAP scan stop\r\n");
        }
        else if (new_state.gap_scan_state == GAP_SCAN_STATE_SCANNING)
        {
            APP_PRINT_INFO0("GAP scan start");
            data_uart_print("GAP scan start\r\n");
        }
    }
}
//Received advertising or scan rsp data will be handled in app_gap_callback
T_APP_RESULT app_gap_callback(uint8_t cb_type, void *p_cb_data)
{
    T_APP_RESULT result = APP_RESULT_SUCCESS;
    T_LE_CB_DATA cb_data;
    memcpy(&cb_data, p_cb_data, sizeof(T_LE_CB_DATA));
    APP_PRINT_TRACE1("app_gap_callback: cb_type %d", cb_type);
    switch (cb_type)
    {
    case GAP_MSG_LE_SCAN_INFO:
        APP_PRINT_INFO5("GAP_MSG_LE_SCAN_INFO:adv_type 0x%x, bd_addr %s, remote_addr_type %d, RSSI %d, data_len %d",
                       cb_data.p_le_scan_info->adv_type,
                       TRACE_BDADDR(cb_data.p_le_scan_info->bd_addr),
                       cb_data.p_le_scan_info->remote_addr_type,
                       cb_data.p_le_scan_info->rssi,
                       cb_data.p_le_scan_info->data_len);
        break;
    }
}
Return values:
  • GAP_CAUSE_SUCCESS – Sending request operation is successful.

  • Others – Sending request operation is failed.

Returns:

The result of sending request.

T_GAP_CAUSE le_scan_stop(void)

Stop scan.

If sending request operation is successful, the stopping result will be returned in one of the following ways:

Applications can only call this API after Bluetooth Host is ready.

Explanation: If Bluetooth Host is ready, the application will be notified by message GAP_MSG_LE_DEV_STATE_CHANGE with new_state about gap_init_state which is configured as GAP_INIT_STATE_STACK_READY.

Example usage

void test(void)
{
    le_scan_stop();
}
void app_handle_dev_state_evt(T_GAP_DEV_STATE new_state, uint16_t cause)
{
    APP_PRINT_INFO5("app_handle_dev_state_evt: init state %d scan state %d adv state %d conn state %d cause 0x%x",
                   new_state.gap_init_state,
                   new_state.gap_scan_state, new_state.gap_adv_state, new_state.gap_conn_state, cause);

    if (gap_dev_state.gap_scan_state != new_state.gap_scan_state)
    {
        if (new_state.gap_scan_state == GAP_SCAN_STATE_IDLE)
        {
            APP_PRINT_INFO0("GAP scan stop");
            data_uart_print("GAP scan stop\r\n");
        }
        else if (new_state.gap_scan_state == GAP_SCAN_STATE_SCANNING)
        {
            APP_PRINT_INFO0("GAP scan start");
            data_uart_print("GAP scan start\r\n");
        }
    }
}
Return values:
  • GAP_CAUSE_SUCCESS – Sending request operation is successful.

  • Others – Sending request operation is failed.

Returns:

The result of sending request.