Kenji Arai / Mbed 2 deprecated BLE_EddystoneBeacon_w_ACC_TY51822

Dependencies:   BLE_API LIS3DH mbed nRF51822 BMC050 nRF51_LowPwr nRF51_Vdd

Fork of BLE_EddystoneBeacon_Service by Bluetooth Low Energy

Revision:
10:b5d19bcf23cf
Parent:
7:e9800c45e065
Child:
11:73ea4ef7f5a4
--- a/ZipBeaconConfigService.h	Thu Jul 02 08:42:21 2015 +0000
+++ b/ZipBeaconConfigService.h	Fri Jul 17 19:02:54 2015 +0000
@@ -62,6 +62,12 @@
 
     static const int URI_DATA_MAX = 18;
     typedef uint8_t  UriData_t[URI_DATA_MAX];
+    
+    static const int UID_NAMESPACEID_SIZE = 10;
+    typedef uint8_t  UIDNamespaceID_t[UUID_NAMESPACEID_SIZE];
+    
+    static const int UID_INSTANCEID_SIZE = 6;
+    typedef uint8_t  UIDInstanceID_t[UUID_INSTANCEID_SIZE];
 
     static const uint8_t FRAME_TYPE_UID = 0x00;
     static const uint8_t FRAME_TYPE_URL = 0x10;
@@ -75,6 +81,9 @@
         PowerLevels_t advPowerLevels; // Current value of AdvertisedPowerLevels
         uint8_t       txPowerMode;    // Firmware power levels used with setTxPower()
         uint16_t      beaconPeriod;
+        uint8_t       tlmVersion;     // version of TLM packet
+        UUIDNamespaceID_t uidNamespaceID; // UUID type, Namespace ID, 10B
+        UUIDInstanceID_t  uidInstanceID;  // UUID type, Instance ID,  6B
     };
 
     /**
@@ -116,7 +125,7 @@
         beaconPeriodChar(UUID_BEACON_PERIOD_CHAR, &params.beaconPeriod),
         resetChar(UUID_RESET_CHAR, &resetFlag) {
 
-        encodeURI(defaultURIDataIn, defaultUriData, defaultUriDataLength);
+        encodeURI(defaultURIDataIn, defaultUriData, defaultUriDataLength); // encode URL to URL Formatting
         if (defaultUriDataLength > URI_DATA_MAX) {
             return;
         }
@@ -165,7 +174,7 @@
      * afterwards. */
     void setupZipBeaconConfigAdvertisements()
     {
-        const char DEVICE_NAME[] = "zipBeacon Config";
+        const char DEVICE_NAME[] = "eddystone Config";
 
         ble.clearAdvertisingPayload();
 
@@ -189,6 +198,54 @@
         ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
         ble.setAdvertisingInterval(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(ADVERTISING_INTERVAL_MSEC));
     }
+    
+    /*
+    *  Set Eddystone UID Frame information. 
+    *  @param[in] power   TX Power in dB measured at 0 meters from the device. Range of -100 to +20 dB.
+    *  @param namespaceID 10B namespace ID
+    *  @param instanceID  6B instance ID
+    *  @param RFU         2B of RFU, initialized to 0x0000 and not broadcast, included for future reference. 
+    *
+    */
+    void setUIDFrameData(int8_t power, UIDNamespaceID_t namespaceID, UIDInstanceID_t instanceID, uint8_t RFU[2] = [0x00,0x00])
+    {
+        defaultUidNamespaceID = namespaceID;
+        defaultUidInstanceID = instanceID;
+        uidRFU = (uint16_t)RFU;
+        return;
+    }
+    
+    /*
+    *  Set Eddystone URL Frame information. 
+    *  @param[in] power   TX Power in dB measured at 0 meters from the device.
+    *  @param url         URL to encode 
+    *  @return            false on success, true on failure.
+    */
+    bool setURLFrameData(int8_t power, const char * url)
+    {
+        encodeURI(defaultURIDataIn, defaultUriData, defaultUriDataLength); // encode URL to URL Formatting
+        if (defaultUriDataLength > URI_DATA_MAX) {
+            return true; // error, URL is too big
+        }
+        
+    }
+    
+    /*
+    *  Set Eddystone TLM Frame information. 
+    *  @param[in] Version    of the TLM beacon data format
+    *  @param batteryVoltage in milivolts
+    *  @param beaconTemp     in 8.8 floating point notation
+    *
+    */
+    void setTLMFrameData(uint8_t version, uint16_t batteryVoltage, uint16_t beaconTemp, uint32_t pduCount = 0, uint32_t timeSinceBoot = 0)
+    {
+        TlmVersion = version;
+        TlmBatteryVoltage = batteryVoltage;
+        TlmBeaconTemp = beaconTemp;
+        TlmPduCount = pduCount; // reset
+        TlmTimeSinceBoot = timeSinceBoot; // reset
+        return;        
+    }
 
     /* Helper function to switch to the non-connectible normal mode for ZipBeacon. This gets called after a timeout. */
     void setupZipBeaconAdvertisements()
@@ -296,6 +353,8 @@
         memcpy(params.advPowerLevels, defaultAdvPowerLevels, sizeof(PowerLevels_t));
         params.txPowerMode      = TX_POWER_MODE_LOW;
         params.beaconPeriod     = 1000;
+        memcpy(params.uidNamespaceID, defaultUidNamespaceID, UID_NAMESPACEID_SIZE);
+        memcpy(params.uidInstanceID,  defaultUidInstanceID,  UID_INSTANCEID_SIZE);
         updateCharacteristicValues();
     }
 
@@ -379,16 +438,26 @@
         }
     }
 
-    BLEDevice     &ble;
-    Params_t      &params;
+    BLEDevice           &ble;
+    Params_t            &params;
+    // Default value that is restored on reset
+    size_t              defaultUriDataLength;
+    UriData_t           defaultUriData;
+    UIDNamespaceID_t    defaultUidNamespaceID;
+    UIDInstanceID_t     defaultUidInstanceID;
+    uint16_t            uidRFU;
     // Default value that is restored on reset
-    size_t        defaultUriDataLength;
-    UriData_t     defaultUriData;
-    // Default value that is restored on reset
-    PowerLevels_t &defaultAdvPowerLevels;
-    uint8_t       lockedState;
-    bool          initSucceeded;
-    uint8_t       resetFlag;
+    PowerLevels_t       &defaultAdvPowerLevels;
+    uint8_t             lockedState;
+    bool                initSucceeded;
+    uint8_t             resetFlag;
+    
+    // Private Variables for Telemetry Data
+    uint8_t             TlmVersion;
+    uint16_t            TlmBatteryVoltage;
+    uint16_t            TlmBeaconTemp;
+    uint32_t            TlmPduCount;
+    uint32_t            TlmTimeSinceBoot;
 
     ReadOnlyGattCharacteristic<uint8_t>        lockedStateChar;
     WriteOnlyGattCharacteristic<Lock_t>        lockChar;