Add D13 definition

Dependents:   Program3_BLEHeartRate Program3_BLEHeartRate

Fork of X_NUCLEO_IDB0XA1 by ST

Revision:
242:058b2e731adc
Parent:
212:8b5ff0f0186f
Parent:
238:b6454c839f42
Child:
252:0c2cb16a7166
--- a/x-nucleo-idb0xa1/BlueNRGGap.h	Fri Mar 18 12:10:20 2016 +0100
+++ b/x-nucleo-idb0xa1/BlueNRGGap.h	Mon Jun 20 14:59:06 2016 +0200
@@ -45,25 +45,29 @@
 #define BLE_CONN_HANDLE_INVALID 0x0
 #define BDADDR_SIZE 6
 
-#define BLUENRG_GAP_ADV_INTERVAL_MIN (0)
-#define BLUENRG_GAP_ADV_INTERVAL_MAX (0)
-#define BLE_GAP_ADV_NONCON_INTERVAL_MIN (0)
+#define BLUENRG_GAP_ADV_INTERVAL_MIN (0x0020)
+#define BLUENRG_GAP_ADV_INTERVAL_MAX (0x4000)
+#define BLUENRG_GAP_ADV_NONCON_INTERVAL_MIN (0x00A0)
 
 // Scanning and Connection Params used by Central for creating connection
-#define LIMITED_DISCOVERY_PROCEDURE 0x01
-#define GENERAL_DISCOVERY_PROCEDURE 0x02
+#define GAP_OBSERVATION_PROC (0x80)
 
-#define SCAN_P         (0x4000)
-#define SCAN_L         (0x4000)
-#define SUPERV_TIMEOUT (600)
+#define SCAN_P         (0x0010)
+#define SCAN_L         (0x0010)
+#define SUPERV_TIMEOUT (0xC80)
 #define CONN_P(x)      ((int)((x)/1.25f))
 #define CONN_L(x)      ((int)((x)/0.625f))
-#define CONN_P1        (CONN_P(50))//(CONN_P(1000))
-#define CONN_P2        (CONN_P(50))//(CONN_P(1000))
-#define CONN_L1        (CONN_L(5)) 
-#define CONN_L2        (CONN_L(5))
+#define CONN_P1        ((int)(_advParams.getInterval()+5)/1.25f)//(0x4C)//(0x6C)
+#define CONN_P2        ((int)(_advParams.getInterval()+5)/1.25f)//(0x4C)//(0x6C)
+#define CONN_L1        (0x0008)
+#define CONN_L2        (0x0008)
+#define GUARD_INT      5 //msec
+#define MIN_INT_CONN   0x0006 //=>7.5msec
+#define MAX_INT_CONN   0x0C80 //=>4000msec
+#define DEF_INT_CONN   0x0140 //=>400msec (default value for connection interval)
 
-#define UUID_BUFFER_SIZE 17 //Either 8*2(16-bit UUIDs) or 4*4(32-bit UUIDs) or 1*16(128-bit UUIDs) +1
+#define LOCAL_NAME_MAX_SIZE 9 //8 + 1(AD_DATA_TYPE)
+#define UUID_BUFFER_SIZE 17 //Either 8*2(16-bit UUIDs) or 4*4(32-bit UUIDs) or 1*16(128-bit UUIDs) +1(AD_DATA_TYPE)
 #define ADV_DATA_MAX_SIZE 31
 
 /**************************************************************************/
@@ -80,15 +84,6 @@
         return m_instance;
     }
 
-    // <<<ANDREA>>>
-    /*
-    enum AdvType_t {
-        ADV_IND           = GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED,//Gap::ADV_IND,
-        ADV_DIRECT_IND    = GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED,//Gap::ADV_DIRECT_IND,
-        ADV_SCAN_IND      = GapAdvertisingParams::ADV_SCANNABLE_UNDIRECTED,//Gap::ADV_SCAN_IND,
-        ADV_NONCONN_IND   = GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED//Gap::ADV_NONCONN_IND
-    };
-    */
     enum Reason_t {
         DEVICE_FOUND,
         DISCOVERY_COMPLETE
@@ -101,9 +96,9 @@
     virtual ble_error_t startAdvertising(const GapAdvertisingParams &);
     virtual ble_error_t stopAdvertising(void);
     virtual ble_error_t stopScan();
-    virtual uint16_t    getMinAdvertisingInterval(void) const;
-    virtual uint16_t    getMinNonConnectableAdvertisingInterval(void) const;
-    virtual uint16_t    getMaxAdvertisingInterval(void) const;
+    virtual uint16_t    getMinAdvertisingInterval(void) const {return GapAdvertisingParams::ADVERTISEMENT_DURATION_UNITS_TO_MS(BLUENRG_GAP_ADV_INTERVAL_MIN);}
+    virtual uint16_t    getMinNonConnectableAdvertisingInterval(void) const {return GapAdvertisingParams::ADVERTISEMENT_DURATION_UNITS_TO_MS(BLUENRG_GAP_ADV_NONCON_INTERVAL_MIN);}
+    virtual uint16_t    getMaxAdvertisingInterval(void) const {return GapAdvertisingParams::ADVERTISEMENT_DURATION_UNITS_TO_MS(BLUENRG_GAP_ADV_INTERVAL_MAX);}
     virtual ble_error_t disconnect(DisconnectionReason_t reason);
     virtual ble_error_t disconnect(Handle_t connectionHandle, DisconnectionReason_t reason);
     virtual ble_error_t getPreferredConnectionParams(ConnectionParams_t *params);
@@ -114,19 +109,25 @@
     virtual ble_error_t getDeviceName(uint8_t *deviceName, unsigned *lengthP);
     virtual ble_error_t setAppearance(GapAdvertisingData::Appearance appearance);
     virtual ble_error_t getAppearance(GapAdvertisingData::Appearance *appearanceP);
-    
+
+    virtual ble_error_t setScanningPolicyMode(ScanningPolicyMode_t mode);
+    virtual ble_error_t setAdvertisingPolicyMode(AdvertisingPolicyMode_t mode);
+    virtual AdvertisingPolicyMode_t getAdvertisingPolicyMode(void) const;
+    virtual ScanningPolicyMode_t getScanningPolicyMode(void) const;
+
     virtual ble_error_t setTxPower(int8_t txPower);
     virtual void        getPermittedTxPowerValues(const int8_t **, size_t *);
-    // <<<ANDREA>>>
+
     virtual ble_error_t connect(const Address_t peerAddr,
                                 Gap::AddressType_t peerAddrType,
                                 const ConnectionParams_t *connectionParams,
                                 const GapScanningParams *scanParams);
-    
+
+    virtual ble_error_t reset(void);
 
     void                Discovery_CB(Reason_t reason,
                                      uint8_t adv_type,
-                                     uint8_t *addr_type,
+                                     uint8_t addr_type,
                                      uint8_t *addr,
                                      uint8_t *data_length,
                                      uint8_t *data,
@@ -156,16 +157,15 @@
     uint16_t m_connectionHandle;
     AddressType_t addr_type;
     Address_t _peerAddr;
+    AddressType_t _peerAddrType;
     uint8_t bdaddr[BDADDR_SIZE];
     bool _scanning;
     bool _connecting;
     bool isSetAddress;
-    bool btle_reinited;
-    uint8_t *DeviceName;
     uint8_t deviceAppearance[2];
 
-    uint8_t *local_name;
     uint8_t local_name_length;
+    uint8_t local_name[LOCAL_NAME_MAX_SIZE];
 
     uint8_t servUuidlength;
     uint8_t servUuidData[UUID_BUFFER_SIZE];
@@ -176,12 +176,38 @@
     Timeout advTimeout;
     bool AdvToFlag;
 
+    const uint8_t *scan_response_payload;
+    uint8_t scan_rsp_length;
+
+    static uint16_t SCAN_DURATION_UNITS_TO_MSEC(uint16_t duration) {
+        return (duration * 625) / 1000;
+    }
+
+    uint16_t scanInterval;
+    uint16_t scanWindow;
+    uint16_t advInterval;
+    uint16_t conn_min_interval;
+    uint16_t conn_max_interval;
+    void setAdvParameters(void);
+    void setConnectionParameters(void);
+
+    Gap::AdvertisingPolicyMode_t advertisingPolicyMode;
+    Gap::ScanningPolicyMode_t scanningPolicyMode;
+
+    Whitelist_t whitelistAddresses;
+
+    ble_error_t updateAdvertisingData(void);
+
     BlueNRGGap() {
         m_connectionHandle = BLE_CONN_HANDLE_INVALID;
-        addr_type = BLEProtocol::AddressType::PUBLIC;
+        addr_type = BLEProtocol::AddressType::RANDOM_STATIC;
+
+        /* Set the whitelist policy filter modes to IGNORE_WHITELIST */
+        advertisingPolicyMode = Gap::ADV_POLICY_IGNORE_WHITELIST;
+        scanningPolicyMode    = Gap::SCAN_POLICY_IGNORE_WHITELIST;
+
         isSetAddress = false;
-        btle_reinited = false;
-        DeviceName = NULL;     
+        memset(deviceAppearance, 0, sizeof(deviceAppearance));
     }
 
     BlueNRGGap(BlueNRGGap const &);