ble_hds.h 2.81 KB
#ifndef BLE_HDS_H__
#define BLE_HDS_H__

#include <stdint.h>
#include <stdbool.h>
#include "ble.h"
#include "ble_srv_common.h"


#define BLE_HDS_DEF(_name)                                                                          \
static ble_hds_t _name;                                                                             \
NRF_SDH_BLE_OBSERVER(_name ## _obs,                                                                 \
                     BLE_HRS_BLE_OBSERVER_PRIO,                                                     \
                     ble_hds_on_ble_evt, &_name)


#define HD_CUSTOM_SERVICE_UUID_BASE          {0x80, 0x80, 0x99, 0x5d, 0x95, 0xab, 0x50, 0xb6,       \
                                              0xec, 0x40, 0x67, 0x3d, 0x21, 0xe7, 0xfc, 0x91}

#define HD_CUSTOM_SERVICE_UUID               0x1400
#define HD_CUSTOM_VALUE_CHAR_UUID            0x1401
																					

typedef enum
{
    BLE_HDS_EVT_NOTIFICATION_ENABLED,                             /**< Custom value notification enabled event. */
    BLE_HDS_EVT_NOTIFICATION_DISABLED,                             /**< Custom value notification disabled event. */
    BLE_HDS_EVT_DISCONNECTED,
    BLE_HDS_EVT_CONNECTED
} ble_hds_evt_type_t;


typedef struct
{
    ble_hds_evt_type_t evt_type;                                  /**< Type of event. */
} ble_hds_evt_t;

typedef struct ble_hds_s ble_hds_t;



typedef void (*ble_hds_evt_handler_t) (ble_hds_t * p_bas, ble_hds_evt_t * p_evt);


typedef struct
{
    ble_hds_evt_handler_t         evt_handler;                    /**< Event handler to be called for handling events in the Custom Service. */
    uint8_t                       initial_custom_value;           /**< Initial custom value */
    ble_srv_cccd_security_mode_t  custom_value_char_attr_md;     /**< Initial security level for Custom characteristics attribute */
} ble_hds_init_t;


struct ble_hds_s
{
    ble_hds_evt_handler_t         evt_handler;                    /**< Event handler to be called for handling events in the Custom Service. */
    uint16_t                      service_handle;                 /**< Handle of Custom Service (as provided by the BLE stack). */
    ble_gatts_char_handles_t      custom_value_handles;           /**< Handles related to the Custom Value characteristic. */
    uint16_t                      conn_handle;                    /**< Handle of the current connection (as provided by the BLE stack, is BLE_CONN_HANDLE_INVALID if not in a connection). */
    uint8_t                       uuid_type; 
};

uint32_t ble_hds_init(ble_hds_t * p_hds, const ble_hds_init_t * p_hds_init);

void ble_hds_on_ble_evt( ble_evt_t const * p_ble_evt, void * p_context);


uint32_t ble_hds_custom_value_update(ble_hds_t * p_hds, uint8_t custom_value);

#endif // BLE_HDS_H__