![](/media/cache/profiles/profile2.jpg.50x50_q85.jpg)
This software setup a central node of a star topology network
Dependencies: MQTT target_st_bluenrg
Fork of ble-star-mbed by
inc/BleSlaveService.h@0:1902469bdd2d, 2018-02-20 (annotated)
- Committer:
- lorevee
- Date:
- Tue Feb 20 11:21:41 2018 +0000
- Revision:
- 0:1902469bdd2d
First commit of Ble Star demo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lorevee | 0:1902469bdd2d | 1 | #ifndef __BLESLAVESERVICE_H__ |
lorevee | 0:1902469bdd2d | 2 | #define __BLESLAVESERVICE_H__ |
lorevee | 0:1902469bdd2d | 3 | |
lorevee | 0:1902469bdd2d | 4 | #include "ble/GattService.h" |
lorevee | 0:1902469bdd2d | 5 | #include "ble/GattCharacteristic.h" |
lorevee | 0:1902469bdd2d | 6 | #include <BleMasterService.h> |
lorevee | 0:1902469bdd2d | 7 | |
lorevee | 0:1902469bdd2d | 8 | /* Attribute value format of the STAR_CHAR */ |
lorevee | 0:1902469bdd2d | 9 | /* Timestamp | Node ID | Type ID | value | Type ID | value | Type ID | value | */ |
lorevee | 0:1902469bdd2d | 10 | /* 2 bytes | 2 bytes | 1 byte | x bytes | 1 byte | x bytes | 1 byte | x bytes | */ |
lorevee | 0:1902469bdd2d | 11 | #define STAR_CHAR_MAX_VALUE_LEN 20 |
lorevee | 0:1902469bdd2d | 12 | |
lorevee | 0:1902469bdd2d | 13 | #define uint8_tNAME_BLESTAR1 'B','l','e','S','t','a','r','1' |
lorevee | 0:1902469bdd2d | 14 | |
lorevee | 0:1902469bdd2d | 15 | |
lorevee | 0:1902469bdd2d | 16 | /* Store Value into a buffer in Little Endian Format */ |
lorevee | 0:1902469bdd2d | 17 | #define STORE_LE_16(buf, val) ( ((buf)[0] = (uint8_t) (val) ) , \ |
lorevee | 0:1902469bdd2d | 18 | ((buf)[1] = (uint8_t) (val>>8) ) ) |
lorevee | 0:1902469bdd2d | 19 | |
lorevee | 0:1902469bdd2d | 20 | #define STORE_LE_32(buf, val) ( ((buf)[0] = (uint8_t) (val) ) , \ |
lorevee | 0:1902469bdd2d | 21 | ((buf)[1] = (uint8_t) (val>>8) ) , \ |
lorevee | 0:1902469bdd2d | 22 | ((buf)[2] = (uint8_t) (val>>16) ) , \ |
lorevee | 0:1902469bdd2d | 23 | ((buf)[3] = (uint8_t) (val>>24) ) ) |
lorevee | 0:1902469bdd2d | 24 | |
lorevee | 0:1902469bdd2d | 25 | #define STORE_BE_32(buf, val) ( ((buf)[3] = (uint8_t) (val) ) , \ |
lorevee | 0:1902469bdd2d | 26 | ((buf)[2] = (uint8_t) (val>>8) ) , \ |
lorevee | 0:1902469bdd2d | 27 | ((buf)[1] = (uint8_t) (val>>16) ) , \ |
lorevee | 0:1902469bdd2d | 28 | ((buf)[0] = (uint8_t) (val>>24) ) ) |
lorevee | 0:1902469bdd2d | 29 | |
lorevee | 0:1902469bdd2d | 30 | |
lorevee | 0:1902469bdd2d | 31 | |
lorevee | 0:1902469bdd2d | 32 | |
lorevee | 0:1902469bdd2d | 33 | |
lorevee | 0:1902469bdd2d | 34 | typedef BLEProtocol::AddressBytes_t tBDAddr; |
lorevee | 0:1902469bdd2d | 35 | |
lorevee | 0:1902469bdd2d | 36 | /* MANUFACTURER_SPECIFIC_DATA */ |
lorevee | 0:1902469bdd2d | 37 | extern uint8_t manuf_data[6]; |
lorevee | 0:1902469bdd2d | 38 | |
lorevee | 0:1902469bdd2d | 39 | |
lorevee | 0:1902469bdd2d | 40 | |
lorevee | 0:1902469bdd2d | 41 | |
lorevee | 0:1902469bdd2d | 42 | /* BLE Slave Service exported types */ |
lorevee | 0:1902469bdd2d | 43 | typedef struct { |
lorevee | 0:1902469bdd2d | 44 | uint8_t data_length; |
lorevee | 0:1902469bdd2d | 45 | uint8_t *attribute_value; |
lorevee | 0:1902469bdd2d | 46 | tBDAddr devAddr; |
lorevee | 0:1902469bdd2d | 47 | uint16_t attribute_handle; |
lorevee | 0:1902469bdd2d | 48 | } NotificationData_t; |
lorevee | 0:1902469bdd2d | 49 | |
lorevee | 0:1902469bdd2d | 50 | typedef struct { |
lorevee | 0:1902469bdd2d | 51 | uint8_t is_discoverable; |
lorevee | 0:1902469bdd2d | 52 | uint8_t is_connected; |
lorevee | 0:1902469bdd2d | 53 | uint16_t conn_handle; |
lorevee | 0:1902469bdd2d | 54 | uint16_t star_hw_serv_handle; |
lorevee | 0:1902469bdd2d | 55 | uint16_t star_data_char_handle; |
lorevee | 0:1902469bdd2d | 56 | uint16_t star_config_char_handle; |
lorevee | 0:1902469bdd2d | 57 | uint8_t star_data_char_notify; |
lorevee | 0:1902469bdd2d | 58 | uint8_t star_config_value[3]; |
lorevee | 0:1902469bdd2d | 59 | uint8_t star_config_value_len; |
lorevee | 0:1902469bdd2d | 60 | NotificationData_t notification_data; |
lorevee | 0:1902469bdd2d | 61 | } SlaveDevice_t; |
lorevee | 0:1902469bdd2d | 62 | |
lorevee | 0:1902469bdd2d | 63 | |
lorevee | 0:1902469bdd2d | 64 | /* This struct owns the Change_Notification_Status() parameters */ |
lorevee | 0:1902469bdd2d | 65 | typedef struct { |
lorevee | 0:1902469bdd2d | 66 | uint8_t *att_data; |
lorevee | 0:1902469bdd2d | 67 | uint8_t *attr_value; |
lorevee | 0:1902469bdd2d | 68 | uint16_t conn_handle; |
lorevee | 0:1902469bdd2d | 69 | uint8_t i; |
lorevee | 0:1902469bdd2d | 70 | uint32_t feature_mask; |
lorevee | 0:1902469bdd2d | 71 | uint8_t frequency; |
lorevee | 0:1902469bdd2d | 72 | }ChangeNotificationQueue; |
lorevee | 0:1902469bdd2d | 73 | |
lorevee | 0:1902469bdd2d | 74 | |
lorevee | 0:1902469bdd2d | 75 | |
lorevee | 0:1902469bdd2d | 76 | |
lorevee | 0:1902469bdd2d | 77 | /* ---- BLE Slave Service exported functions ---- */ |
lorevee | 0:1902469bdd2d | 78 | /* Set the device as a slave in discoverable mode */ |
lorevee | 0:1902469bdd2d | 79 | void setSlaveDiscoverable (void); |
lorevee | 0:1902469bdd2d | 80 | |
lorevee | 0:1902469bdd2d | 81 | /* Stop advertising */ |
lorevee | 0:1902469bdd2d | 82 | void stopAdv (void); |
lorevee | 0:1902469bdd2d | 83 | |
lorevee | 0:1902469bdd2d | 84 | /* Sets some notification properties */ |
lorevee | 0:1902469bdd2d | 85 | void setNotificationProperty (uint16_t conn_handle, uint8_t i, uint32_t feature_mask, |
lorevee | 0:1902469bdd2d | 86 | uint8_t command, uint8_t data); |
lorevee | 0:1902469bdd2d | 87 | /* Disable all notifications */ |
lorevee | 0:1902469bdd2d | 88 | void disableAllNotifications (void); |
lorevee | 0:1902469bdd2d | 89 | |
lorevee | 0:1902469bdd2d | 90 | /* This function enables or disables the new peripheral scanning */ |
lorevee | 0:1902469bdd2d | 91 | void setNewNodesScanning (uint8_t enabled); |
lorevee | 0:1902469bdd2d | 92 | |
lorevee | 0:1902469bdd2d | 93 | /* This function forwards to the peripheral device the command coming from the Cloud */ |
lorevee | 0:1902469bdd2d | 94 | void Forward_Command_To_BlueNRG (uint8_t* data_ptr, uint8_t data_length); |
lorevee | 0:1902469bdd2d | 95 | |
lorevee | 0:1902469bdd2d | 96 | /* This function is called when an attribute gets modified */ |
lorevee | 0:1902469bdd2d | 97 | void AttributeModified_CB (const GattWriteCallbackParams* param); |
lorevee | 0:1902469bdd2d | 98 | |
lorevee | 0:1902469bdd2d | 99 | /* Notification callbacks */ |
lorevee | 0:1902469bdd2d | 100 | void onUpdatesDisabledCallback (Gap::Handle_t handle); |
lorevee | 0:1902469bdd2d | 101 | void onUpdatesEnabledCallback (GattAttribute::Handle_t handle); |
lorevee | 0:1902469bdd2d | 102 | |
lorevee | 0:1902469bdd2d | 103 | /* Retrieve the device index from the peripheral device address */ |
lorevee | 0:1902469bdd2d | 104 | uint8_t Get_Device_Index_From_Addr (uint8_t *addr); |
lorevee | 0:1902469bdd2d | 105 | |
lorevee | 0:1902469bdd2d | 106 | /* This function is called to Enable/Disable MIC/PRX/AGM/SFusion notifications */ |
lorevee | 0:1902469bdd2d | 107 | void Change_Notification_Status (uint8_t *att_data, uint8_t *attr_value, uint16_t conn_handle, uint8_t i, |
lorevee | 0:1902469bdd2d | 108 | uint32_t feature_mask, uint8_t frequency); |
lorevee | 0:1902469bdd2d | 109 | |
lorevee | 0:1902469bdd2d | 110 | /* Add all services using a vendor specific UUIDs */ |
lorevee | 0:1902469bdd2d | 111 | void addAllServices (void); |
lorevee | 0:1902469bdd2d | 112 | |
lorevee | 0:1902469bdd2d | 113 | /* Forwards to master all notifications from peripherals */ |
lorevee | 0:1902469bdd2d | 114 | //void notifyMaster (uint8_t data_length, uint8_t* attribute_value, GattCharacteristic *pCharac); |
lorevee | 0:1902469bdd2d | 115 | void notifyMaster (uint8_t data_length, uint8_t* attribute_value, uint16_t attribute_handle); |
lorevee | 0:1902469bdd2d | 116 | |
lorevee | 0:1902469bdd2d | 117 | /* Function used to call Attribute_Modified_CB outside the callback call */ |
lorevee | 0:1902469bdd2d | 118 | void createAttribute_Modified_CB_Prototype (uint16_t handle, uint8_t data_length, uint8_t *att_data); |
lorevee | 0:1902469bdd2d | 119 | |
lorevee | 0:1902469bdd2d | 120 | |
lorevee | 0:1902469bdd2d | 121 | |
lorevee | 0:1902469bdd2d | 122 | |
lorevee | 0:1902469bdd2d | 123 | |
lorevee | 0:1902469bdd2d | 124 | |
lorevee | 0:1902469bdd2d | 125 | |
lorevee | 0:1902469bdd2d | 126 | |
lorevee | 0:1902469bdd2d | 127 | |
lorevee | 0:1902469bdd2d | 128 | |
lorevee | 0:1902469bdd2d | 129 | #endif /*__BLESLAVESERVICE_H__*/ |