123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291 |
- #ifndef BLE_CTS_C_H__
- #define BLE_CTS_C_H__
- #include "ble_srv_common.h"
- #include "ble_gattc.h"
- #include "ble.h"
- #include "ble_date_time.h"
- #include "ble_db_discovery.h"
- #include "nrf_ble_gq.h"
- #include "nrf_sdh_ble.h"
- #include <stdint.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- #define BLE_CTS_C_DEF(_name) \
- static ble_cts_c_t _name; \
- NRF_SDH_BLE_OBSERVER(_name ## _obs, \
- BLE_CTS_C_BLE_OBSERVER_PRIO, \
- ble_cts_c_on_ble_evt, &_name)
- #define BLE_CTS_C_ARRAY_DEF(_name, _cnt) \
- static ble_cts_c_t _name[_cnt]; \
- NRF_SDH_BLE_OBSERVERS(_name ## _obs, \
- BLE_CTS_C_BLE_OBSERVER_PRIO, \
- ble_cts_c_on_ble_evt, &_name, _cnt)
- typedef struct
- {
- ble_date_time_t date_time;
- uint8_t day_of_week;
- } day_date_time_t;
- typedef struct
- {
- day_date_time_t day_date_time;
- uint8_t fractions256;
- } exact_time_256_t;
- typedef struct
- {
- uint8_t manual_time_update : 1;
- uint8_t external_reference_time_update : 1;
- uint8_t change_of_time_zone : 1;
- uint8_t change_of_daylight_savings_time : 1;
- } adjust_reason_t;
- typedef struct
- {
- exact_time_256_t exact_time_256;
- adjust_reason_t adjust_reason;
- } current_time_char_t;
- typedef struct ble_cts_c_s ble_cts_c_t;
- typedef enum
- {
- BLE_CTS_C_EVT_DISCOVERY_COMPLETE,
- BLE_CTS_C_EVT_DISCOVERY_FAILED,
- BLE_CTS_C_EVT_DISCONN_COMPLETE,
- BLE_CTS_C_EVT_CURRENT_TIME,
- BLE_CTS_C_EVT_INVALID_TIME
- } ble_cts_c_evt_type_t;
- typedef struct
- {
- uint16_t cts_handle;
- uint16_t cts_cccd_handle;
- } ble_cts_c_handles_t;
- typedef struct
- {
- ble_cts_c_evt_type_t evt_type;
- uint16_t conn_handle;
- union
- {
- current_time_char_t current_time;
- ble_cts_c_handles_t char_handles;
- } params;
- } ble_cts_c_evt_t;
- typedef void (* ble_cts_c_evt_handler_t) (ble_cts_c_t * p_cts, ble_cts_c_evt_t * p_evt);
- struct ble_cts_c_s
- {
- ble_cts_c_evt_handler_t evt_handler;
- ble_srv_error_handler_t error_handler;
- ble_cts_c_handles_t char_handles;
- uint16_t conn_handle;
- nrf_ble_gq_t * p_gatt_queue;
- };
- typedef struct
- {
- ble_cts_c_evt_handler_t evt_handler;
- ble_srv_error_handler_t error_handler;
- nrf_ble_gq_t * p_gatt_queue;
- } ble_cts_c_init_t;
- uint32_t ble_cts_c_init(ble_cts_c_t * p_cts, const ble_cts_c_init_t * p_cts_init);
- void ble_cts_c_on_db_disc_evt(ble_cts_c_t * p_cts, ble_db_discovery_evt_t * p_evt);
- void ble_cts_c_on_ble_evt(ble_evt_t const * p_ble_evt, void * p_context);
- static __INLINE bool ble_cts_c_is_cts_discovered(const ble_cts_c_t * p_cts)
- {
- return (p_cts->char_handles.cts_handle != BLE_GATT_HANDLE_INVALID);
- }
- uint32_t ble_cts_c_current_time_read(ble_cts_c_t const * p_cts);
- uint32_t ble_cts_c_handles_assign(ble_cts_c_t * p_cts,
- const uint16_t conn_handle,
- const ble_cts_c_handles_t * p_peer_handles);
- #ifdef __cplusplus
- }
- #endif
- #endif
|