Proximity Monitor Profile declarations.
Copyright (c) 2017-2019 Microchip Technology Inc. and its subsidiaries.
#include "ble_manager.h"
Macros | |
#define | DBG_LOG_PTS ALL_UNUSED |
#define | DISCOVER_SUCCESS (10) |
#define | PXP_ASCII_TO_DECIMAL_VALUE ('0') |
#define | PXP_CONNECT_REQ_INTERVAL (20) |
#define | PXP_HIGH_ALERT_RANGE (-90) |
#define | PXP_LOW_ALERT_RANGE (-70) |
#define | PXP_RSSI_UPDATE_INTERVAL (0x10) |
Typedefs | |
typedef void(* | hw_timer_start_func_cb_t )(uint32_t) |
typedef void(* | hw_timer_stop_func_cb_t )(void) |
typedef ble_device_ll_state_t(* | peripheral_state_cb_t )(void) |
Enumerations | |
enum | AD_TYPE { AD_TYPE_FLAGS = 01, AD_TYPE_COMPLETE_LIST_UUID = 0x03, AD_TYPE_COMPLETE_LOCAL_NAME = 0x09 } |
enum | PXP_DEV { PXP_DEV_UNCONNECTED, PXP_DEV_CONNECTING, PXP_DEV_CONNECTED } |
Functions | |
at_ble_status_t | pxp_disconnect_event_handler (void *params) |
peer device connection terminated More... | |
at_ble_status_t | pxp_monitor_characteristic_found_handler (void *params) |
Handles all Discovered characteristics of a given handler in a connected device. More... | |
at_ble_status_t | pxp_monitor_characteristic_read_response (void *params) |
Handles the read response from the peer/connected device. More... | |
at_ble_status_t | pxp_monitor_connect_request (at_ble_scan_info_t *scan_buffer, uint8_t index) |
Connect to a peer device. More... | |
at_ble_status_t | pxp_monitor_connected_state_handler (void *params) |
Connected event state handle after connection request to peer device. More... | |
at_ble_status_t | pxp_monitor_discovery_complete_handler (void *params) |
Discover all Characteristics supported for Proximity Service of a connected device and handles discovery complete Search will go from start_handle to end_handle, whenever a characteristic is found After search and discovery completes will initialize the alert level and read the tx power value as defined AT_BLE_CHARACTERISTIC_FOUND event is sent and AT_BLE_DISCOVERY_COMPLETE is sent at end of discover operation. More... | |
at_ble_status_t | pxp_monitor_encryption_change_handler (void *params) |
void | pxp_monitor_init (void *param) |
at_ble_status_t | pxp_monitor_pair_done_handler (void *params) |
at_ble_status_t | pxp_monitor_scan_data_handler (void *params) |
Search for a given AD type in a buffer, received from advertising packets. More... | |
at_ble_status_t | pxp_monitor_service_discover (at_ble_handle_t) |
Discover all services. More... | |
at_ble_status_t | pxp_monitor_service_found_handler (void *params) |
Discover the Proximity services. More... | |
at_ble_status_t | pxp_monitor_start_scan (void) |
void | register_hw_timer_start_func_cb (hw_timer_start_func_cb_t timer_start_fn) |
Registers callback for hardware timer start. More... | |
void | register_hw_timer_stop_func_cb (hw_timer_stop_func_cb_t timer_stop_fn) |
Registers callback for hardware timer stop. More... | |
void | register_peripheral_state_cb (peripheral_state_cb_t peripheral_state_cb) |
#define DBG_LOG_PTS ALL_UNUSED |
#define DISCOVER_SUCCESS (10) |
#define PXP_ASCII_TO_DECIMAL_VALUE ('0') |
Referenced by pxp_monitor_scan_data_handler().
#define PXP_CONNECT_REQ_INTERVAL (20) |
Referenced by pxp_monitor_connect_request(), and pxp_monitor_start_scan().
#define PXP_HIGH_ALERT_RANGE (-90) |
Referenced by pxp_monitor_init(), and rssi_update().
#define PXP_LOW_ALERT_RANGE (-70) |
Referenced by pxp_monitor_init(), and rssi_update().
#define PXP_RSSI_UPDATE_INTERVAL (0x10) |
Referenced by pxp_monitor_app_timer_event(), and pxp_monitor_characteristic_read_response().
typedef void(* hw_timer_start_func_cb_t)(uint32_t) |
typedef void(* hw_timer_stop_func_cb_t)(void) |
typedef ble_device_ll_state_t(* peripheral_state_cb_t)(void) |
enum AD_TYPE |
enum PXP_DEV |
at_ble_status_t pxp_disconnect_event_handler | ( | void * | params | ) |
peer device connection terminated
handler for disconnect notification try to send connect request for previously connect device.
[in] | available | disconnect handler of peer and reason for disconnection |
References AT_BLE_FAILURE, ble_check_disconnected_iscentral(), ble_device_current_state, CENTRAL_SCANNING_STATE, at_ble_disconnected_t::handle, PERIPHERAL_ADVERTISING_STATE, pxp_connect_request_flag, PXP_DEV_UNCONNECTED, and pxp_monitor_start_scan().
at_ble_status_t pxp_monitor_characteristic_found_handler | ( | void * | params | ) |
Handles all Discovered characteristics of a given handler in a connected device.
Compare the characteristics UUID with proximity services whenever a characteristics is found if compare stores the characteristics handler of respective service
[in] | characteristic_found | Discovered characteristics params of a connected device |
References ALERT_LEVEL_CHAR_UUID, AT_BLE_FAILURE, AT_BLE_SUCCESS, ble_check_iscentral(), gatt_txps_char_handler::char_handle, gatt_lls_char_handler::char_handle, gatt_ias_char_handler::char_handle, at_ble_characteristic_found_t::char_handle, at_ble_characteristic_found_t::char_uuid, at_ble_characteristic_found_t::conn_handle, DBG_LOG_PTS, gatt_lls_char_handler::end_handle, at_ble_characteristic_found_t::properties, gatt_lls_char_handler::start_handle, TX_POWER_LEVEL_CHAR_UUID, at_ble_uuid_t::uuid, and at_ble_characteristic_found_t::value_handle.
at_ble_status_t pxp_monitor_characteristic_read_response | ( | void * | params | ) |
Handles the read response from the peer/connected device.
if any read request send, response back event is handle. compare the read response characteristics with available service. and data is handle to the respective service.
References AT_BLE_FAILURE, AT_BLE_SUCCESS, ble_check_iscentral(), at_ble_characteristic_read_response_t::conn_handle, DBG_LOG_DEV, hw_timer_start_func_cb, lls_alert_read_response(), PXP_RSSI_UPDATE_INTERVAL, and txps_power_read_response().
at_ble_status_t pxp_monitor_connect_request | ( | at_ble_scan_info_t * | scan_buffer, |
uint8_t | index | ||
) |
Connect to a peer device.
Connecting to a peer device, implicitly starting the necessary scan operation then connecting if a device in the peers list is found.
[in] | scan_buffer | a list of peers that the device will connect to one of them |
[in] | index | index of elements in peers, to initiate the connection |
References AT_BLE_FAILURE, AT_BLE_SUCCESS, DBG_LOG, gap_dev_connect(), hw_timer_start_func_cb, PXP_CONNECT_REQ_INTERVAL, pxp_connect_request_flag, and PXP_DEV_CONNECTING.
Referenced by pxp_monitor_scan_data_handler().
at_ble_status_t pxp_monitor_connected_state_handler | ( | void * | params | ) |
Connected event state handle after connection request to peer device.
After connecting to the peer device start the GATT primary discovery
[in] | at_ble_connected_t | parameters of the established connection |
After connecting to the peer device start the GATT primary discovery
[in] | conn_params | parameters of the established connection |
References ble_check_iscentral(), at_ble_connected_t::conn_status, at_ble_connected_t::handle, pxp_connect_request_flag, and PXP_DEV_CONNECTED.
at_ble_status_t pxp_monitor_discovery_complete_handler | ( | void * | params | ) |
Discover all Characteristics supported for Proximity Service of a connected device and handles discovery complete Search will go from start_handle to end_handle, whenever a characteristic is found After search and discovery completes will initialize the alert level and read the tx power value as defined AT_BLE_CHARACTERISTIC_FOUND event is sent and AT_BLE_DISCOVERY_COMPLETE is sent at end of discover operation.
[in] | discover_status | discovery status on each |
[in] | start_handle | start of the searched range |
[in] | end_handle | end of the searched range |
[in] | discover_status | discovery status of each handle |
References at_ble_characteristic_discover_all(), at_ble_disconnect(), AT_BLE_FAILURE, AT_BLE_INVALID_PARAM, AT_BLE_INVALID_STATE, AT_BLE_SUCCESS, AT_BLE_TERMINATED_BY_USER, ble_check_iscentral(), gatt_txps_char_handler::char_discovery, gatt_lls_char_handler::char_discovery, gatt_ias_char_handler::char_discovery, gatt_txps_char_handler::char_handle, gatt_lls_char_handler::char_handle, at_ble_cmd_complete_event_t::conn_handle, DBG_LOG, DBG_LOG_DEV, DISCOVER_SUCCESS, gatt_txps_char_handler::end_handle, gatt_lls_char_handler::end_handle, gatt_ias_char_handler::end_handle, LLS_ALERT_LEVEL, lls_alert_level_write(), at_ble_cmd_complete_event_t::operation, gatt_txps_char_handler::start_handle, gatt_lls_char_handler::start_handle, gatt_ias_char_handler::start_handle, at_ble_cmd_complete_event_t::status, and txps_power_read().
at_ble_status_t pxp_monitor_encryption_change_handler | ( | void * | params | ) |
References AT_BLE_FAILURE, AT_BLE_SUCCESS, ble_check_iscentral(), ble_check_ispheripheral(), ble_device_current_state, CENTRAL_SCANNING_STATE, at_ble_encryption_status_changed_t::handle, hw_timer_stop_func_cb, PERIPHERAL_ADVERTISING_STATE, pxp_connect_request_flag, PXP_DEV_CONNECTED, PXP_DEV_UNCONNECTED, pxp_monitor_service_discover(), pxp_monitor_start_scan(), and at_ble_encryption_status_changed_t::status.
void pxp_monitor_init | ( | void * | param | ) |
References BLE_GAP_EVENT_TYPE, BLE_GATT_CLIENT_EVENT_TYPE, ble_mgr_events_callback_handler(), gatt_txps_char_handler::char_data, gatt_lls_char_handler::char_data, gatt_ias_char_handler::char_data, DBG_LOG, ias_char_data, lls_char_data, PXP_HIGH_ALERT_RANGE, PXP_LOW_ALERT_RANGE, REGISTER_CALL_BACK, tx_power_char_data, and UNUSED.
Referenced by main().
at_ble_status_t pxp_monitor_pair_done_handler | ( | void * | params | ) |
References AT_BLE_FAILURE, AT_BLE_SUCCESS, ble_check_iscentral(), ble_check_ispheripheral(), ble_device_current_state, CENTRAL_SCANNING_STATE, at_ble_pair_done_t::handle, hw_timer_stop_func_cb, PERIPHERAL_ADVERTISING_STATE, pxp_connect_request_flag, PXP_DEV_CONNECTED, PXP_DEV_UNCONNECTED, pxp_monitor_service_discover(), pxp_monitor_start_scan(), and at_ble_pair_done_t::status.
at_ble_status_t pxp_monitor_scan_data_handler | ( | void * | params | ) |
Search for a given AD type in a buffer, received from advertising packets.
starts search form the buffer, need to provide required search params
[in] | scan_buffer | where all received advertising packet are stored |
[in] | scanned_dev_count | elements in scan_buffer |
Search for a given AD type in a buffer, received from advertising packets.
[in] | scan_buffer | where all received advertising packet are stored |
[in] | scanned_dev_count | elements in scan_buffer |
References AD_TYPE_COMPLETE_LIST_UUID, at_ble_addr_t::addr, ALL_UNUSED, AT_BLE_ADV_TYPE_DIRECTED, AT_BLE_ADV_TYPE_UNDIRECTED, AT_BLE_FAILURE, at_ble_scan_stop(), AT_BLE_SUCCESS, AT_BLE_UUID_16, DBG_LOG, DBG_LOG_CONT, at_ble_scan_info_t::dev_addr, gap_dev_scan(), LINK_LOSS_SERVICE_UUID, MAX_SCAN_DEVICE, PXP_ASCII_TO_DECIMAL_VALUE, pxp_monitor_connect_request(), pxp_supp_scan_index, scan_index, scan_info_parse(), scan_response_count, at_ble_uuid_t::type, and at_ble_uuid_t::uuid.
at_ble_status_t pxp_monitor_service_discover | ( | at_ble_handle_t | handle | ) |
Discover all services.
[in] | connection | handle. |
[in] | connection | handle. |
References at_ble_primary_service_discover_all(), AT_BLE_SUCCESS, DBG_LOG, DBG_LOG_DEV, GATT_DISCOVERY_ENDING_HANDLE, and GATT_DISCOVERY_STARTING_HANDLE.
Referenced by pxp_monitor_app_button_event(), pxp_monitor_encryption_change_handler(), and pxp_monitor_pair_done_handler().
at_ble_status_t pxp_monitor_service_found_handler | ( | void * | params | ) |
Discover the Proximity services.
Search will go from start_handle to end_handle, whenever a service is found and compare with proximity services and stores the respective handlers PXP_MONITOR_CONNECTED_STATE_HANDLER event i.
[in] | at_ble_primary_service_found_t | Primary service parameter |
Search will go from start_handle to end_handle, whenever a service is found and compare with proximity services and stores the respective handlers PXP_MONITOR_CONNECTED_STATE_HANDLER event i.
[in] | at_ble_primary_service_found_t | Primary service parameter |
References AT_BLE_FAILURE, AT_BLE_INVALID_PARAM, AT_BLE_SUCCESS, AT_BLE_UUID_16, ble_check_iscentral(), gatt_txps_char_handler::char_discovery, gatt_lls_char_handler::char_discovery, gatt_ias_char_handler::char_discovery, at_ble_primary_service_found_t::conn_handle, DBG_LOG, DBG_LOG_PTS, DISCOVER_SUCCESS, gatt_txps_char_handler::end_handle, gatt_lls_char_handler::end_handle, gatt_ias_char_handler::end_handle, at_ble_primary_service_found_t::end_handle, IMMEDIATE_ALERT_SERVICE_UUID, LINK_LOSS_SERVICE_UUID, at_ble_primary_service_found_t::service_uuid, gatt_txps_char_handler::start_handle, gatt_lls_char_handler::start_handle, gatt_ias_char_handler::start_handle, at_ble_primary_service_found_t::start_handle, TX_POWER_SERVICE_UUID, at_ble_uuid_t::type, and at_ble_uuid_t::uuid.
at_ble_status_t pxp_monitor_start_scan | ( | void | ) |
References AT_BLE_FAILURE, at_ble_scan_stop(), AT_BLE_SUCCESS, ble_event_task(), DBG_LOG, gap_dev_connect(), gap_dev_scan(), getchar_timeout(), hw_timer_start_func_cb, hw_timer_stop_func_cb, NULL, PERIPHERAL_ADVERTISING_STATE, peripheral_state_callback, PXP_CONNECT_REQ_INTERVAL, pxp_connect_request_flag, PXP_DEV_CONNECTING, and SYSTEM_RunTasks().
Referenced by pxp_disconnect_event_handler(), pxp_monitor_encryption_change_handler(), and pxp_monitor_pair_done_handler().
void register_hw_timer_start_func_cb | ( | hw_timer_start_func_cb_t | timer_start_fn | ) |
Registers callback for hardware timer start.
[in] | Callback | for hardware timer start function. |
References hw_timer_start_func_cb.
Referenced by main().
void register_hw_timer_stop_func_cb | ( | hw_timer_stop_func_cb_t | timer_stop_fn | ) |
Registers callback for hardware timer stop.
[in] | Callback | for hardware timer stop function. |
References hw_timer_stop_func_cb.
Referenced by main().
void register_peripheral_state_cb | ( | peripheral_state_cb_t | peripheral_state_cb | ) |
References peripheral_state_callback.