123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- #ifndef BLE_SC_CTRLPT_H__
- #define BLE_SC_CTRLPT_H__
- #include <stdint.h>
- #include <stdbool.h>
- #include "ble.h"
- #include "ble_srv_common.h"
- #include "ble_sensor_location.h"
- #ifdef __cplusplus
- extern "C" {
- #endif
- #define BLE_SC_CTRLPT_MAX_LEN 19
- #define BLE_SC_CTRLPT_MIN_LEN 1
- typedef struct ble_sc_ctrlpt_s ble_sc_ctrlpt_t;
- typedef enum
- {
- BLE_SC_CTRLPT_EVT_UPDATE_LOCATION,
- BLE_SC_CTRLPT_EVT_SET_CUMUL_VALUE,
- BLE_SC_CTRLPT_EVT_START_CALIBRATION,
- } ble_sc_ctrlpt_evt_type_t;
- typedef struct
- {
- ble_sc_ctrlpt_evt_type_t evt_type;
- union
- {
- ble_sensor_location_t update_location;
- uint32_t cumulative_value;
- }params;
- } ble_sc_ctrlpt_evt_t;
- typedef enum {
- BLE_SCPT_SET_CUMULATIVE_VALUE = 0x01,
- BLE_SCPT_START_AUTOMATIC_CALIBRATION = 0x02,
- BLE_SCPT_UPDATE_SENSOR_LOCATION = 0x03,
- BLE_SCPT_REQUEST_SUPPORTED_SENSOR_LOCATIONS = 0x04,
- BLE_SCPT_RESPONSE_CODE = 0x10,
- } ble_scpt_operator_t;
- typedef enum {
- BLE_SCPT_SUCCESS = 0x01,
- BLE_SCPT_OP_CODE_NOT_SUPPORTED = 0x02,
- BLE_SCPT_INVALID_PARAMETER = 0x03,
- BLE_SCPT_OPERATION_FAILED = 0x04,
- } ble_scpt_response_t;
- typedef enum {
- BLE_SCPT_NO_PROC_IN_PROGRESS = 0x00,
- BLE_SCPT_AUTOMATIC_CALIB_IN_PROGRESS = 0x01,
- BLE_SCPT_INDICATION_PENDING = 0x02,
- BLE_SCPT_IND_CONFIRM_PENDING = 0x03,
- }ble_scpt_procedure_status_t;
- typedef ble_scpt_response_t (*ble_sc_ctrlpt_evt_handler_t) (ble_sc_ctrlpt_t * p_sc_ctrlpt,
- ble_sc_ctrlpt_evt_t * p_evt);
- typedef struct{
- ble_scpt_operator_t opcode;
- uint32_t cumulative_value;
- ble_sensor_location_t location;
- }ble_sc_ctrlpt_val_t;
- typedef struct{
- ble_scpt_operator_t opcode;
- ble_scpt_response_t status;
- ble_sensor_location_t location_list[BLE_NB_MAX_SENSOR_LOCATIONS];
- }ble_sc_ctrlpt_rsp_t;
- #define BLE_SRV_SC_CTRLPT_SENSOR_LOCATIONS_OP_SUPPORTED 0x01
- #define BLE_SRV_SC_CTRLPT_CUM_VAL_OP_SUPPORTED 0x02
- #define BLE_SRV_SC_CTRLPT_START_CALIB_OP_SUPPORTED 0x04
- typedef struct
- {
- security_req_t sc_ctrlpt_cccd_wr_sec;
- security_req_t sc_ctrlpt_wr_sec;
- uint8_t supported_functions;
- uint16_t service_handle;
- ble_sc_ctrlpt_evt_handler_t evt_handler;
- ble_sensor_location_t *list_supported_locations;
- uint8_t size_list_supported_locations;
- uint16_t sensor_location_handle;
- ble_srv_error_handler_t error_handler;
- } ble_cs_ctrlpt_init_t;
- typedef struct
- {
- ble_scpt_response_t status;
- uint8_t len;
- uint8_t encoded_ctrl_rsp[BLE_SC_CTRLPT_MAX_LEN];
- }ble_sc_ctrlpt_resp_t;
- struct ble_sc_ctrlpt_s
- {
- uint8_t supported_functions;
- uint16_t service_handle;
- ble_gatts_char_handles_t sc_ctrlpt_handles;
- uint16_t conn_handle;
- ble_sensor_location_t list_supported_locations[BLE_NB_MAX_SENSOR_LOCATIONS];
- uint8_t size_list_supported_locations;
- ble_sc_ctrlpt_evt_handler_t evt_handler;
- uint16_t sensor_location_handle;
- ble_scpt_procedure_status_t procedure_status;
- ble_srv_error_handler_t error_handler;
- ble_sc_ctrlpt_resp_t response;
- };
- #define SCPT_OPCODE_POS 0
- #define SCPT_PARAMETER_POS 1
- #define SCPT_RESPONSE_REQUEST_OPCODE_POS 1
- #define SCPT_RESPONSE_CODE_POS 2
- #define SCPT_RESPONSE_PARAMETER 3
- #define SCPT_MIN_RESPONSE_SIZE 3
- #define SCPT_MAX_RESPONSE_SIZE (SCPT_MIN_RESPONSE_SIZE + NB_MAX_SENSOR_LOCATIONS)
- uint32_t ble_sc_ctrlpt_init(ble_sc_ctrlpt_t * p_sc_ctrlpt,
- ble_cs_ctrlpt_init_t const * p_sc_ctrlpt_init);
- uint32_t ble_sc_ctrlpt_rsp_send(ble_sc_ctrlpt_t * p_sc_ctrlpt, ble_scpt_response_t response_status);
- void ble_sc_ctrlpt_on_ble_evt(ble_sc_ctrlpt_t * p_sc_ctrlpt, ble_evt_t const * p_ble_evt);
- #ifdef __cplusplus
- }
- #endif
- #endif
|