
Button initiated config service
Dependencies: BLE_API_EddystoneConfigService_2 mbed nRF51822
Fork of BLE_EddystoneBeaconConfigService_3 by
Revision 11:73ea4ef7f5a4, committed 2015-07-17
- Comitter:
- mbedAustin
- Date:
- Fri Jul 17 21:06:30 2015 +0000
- Parent:
- 10:b5d19bcf23cf
- Child:
- 12:ced5e837c511
- Commit message:
- Added functions to construct each frame type from the subsidiary data.
Changed in this revision
ZipBeaconConfigService.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/ZipBeaconConfigService.h Fri Jul 17 19:02:54 2015 +0000 +++ b/ZipBeaconConfigService.h Fri Jul 17 21:06:30 2015 +0000 @@ -60,18 +60,23 @@ typedef uint8_t Lock_t[16]; /* 128 bits */ typedef int8_t PowerLevels_t[NUM_POWER_MODES]; + static const int URI_DATA_MAX = 18; typedef uint8_t UriData_t[URI_DATA_MAX]; + // UID Frame Type subfields static const int UID_NAMESPACEID_SIZE = 10; - typedef uint8_t UIDNamespaceID_t[UUID_NAMESPACEID_SIZE]; - + typedef uint8_t UIDNamespaceID_t[UID_NAMESPACEID_SIZE]; static const int UID_INSTANCEID_SIZE = 6; - typedef uint8_t UIDInstanceID_t[UUID_INSTANCEID_SIZE]; + typedef uint8_t UIDInstanceID_t[UID_INSTANCEID_SIZE]; + // Eddystone Frame Type ID static const uint8_t FRAME_TYPE_UID = 0x00; static const uint8_t FRAME_TYPE_URL = 0x10; static const uint8_t FRAME_TYPE_TLM = 0x20; + + static const uint8_t FRAME_SIZE_TLM = 14; // TLM frame is a constant 14Bytes + static const uint8_t FRAME_SIZE_UID = 20; // includes RFU bytes struct Params_t { Lock_t lock; @@ -82,8 +87,8 @@ 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 + UIDNamespaceID_t uidNamespaceID; // UUID type, Namespace ID, 10B + UIDInstanceID_t uidInstanceID; // UUID type, Instance ID, 6B }; /** @@ -207,12 +212,40 @@ * @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]) + void setUIDFrameData(int8_t power, UIDNamespaceID_t namespaceID, UIDInstanceID_t instanceID, uint16_t RFU = 0x00) + { + defaultUidPower = power; + memcpy(defaultUidNamespaceID, namespaceID, UID_NAMESPACEID_SIZE); + memcpy(defaultUidInstanceID, instanceID, UID_INSTANCEID_SIZE); + uidRFU = (uint16_t)RFU; // this is probably bad form, but it doesnt really matter yet. + return; + } + + /* + * Construct UID frame from private variables + * @param[in/out] Data pointer to array to store constructed frame in + * @param[in] maxSize number of bytes left in array, effectively how much emtpy space is available to write to + * @return number of bytes used. negative number indicates error message. + */ + int constructUIDFrame(uint8_t * Data, uint8_t maxSize) { - defaultUidNamespaceID = namespaceID; - defaultUidInstanceID = instanceID; - uidRFU = (uint16_t)RFU; - return; + if(maxSize < FRAME_SIZE_UID){ + return -1; // not enough space to encode UIDframe in advertising packet. + } + int index = 0; + Data[index++] = FRAME_TYPE_UID; // 1B Type + Data[index++] = defaultUidPower; // 1B Power @ 0meter + for(int x = 0; x < UID_NAMESPACEID_SIZE; x++){ // 10B Namespce ID + Data[index++] = defaultUidNamespaceID[x]; + } + for(int x = 0; x< UID_INSTANCEID_SIZE; x++){ // 6B Instance ID + Data[index++] = defaultUidInstanceID[x]; + } + if(0x00 != uidRFU){ // 2B RFU, include if non-zero, otherwise ignore + Data[index++] = (uint8_t)(uidRFU >> 8); + Data[index++] = (uint8_t)uidRFU; + } + return index; } /* @@ -223,11 +256,32 @@ */ bool setURLFrameData(int8_t power, const char * url) { - encodeURI(defaultURIDataIn, defaultUriData, defaultUriDataLength); // encode URL to URL Formatting + defaultUrlPower = power; + encodeURI(url, defaultUriData, defaultUriDataLength); // encode URL to URL Formatting if (defaultUriDataLength > URI_DATA_MAX) { return true; // error, URL is too big } - + return false; + } + + /* + * Construct URL frame from private variables + * @param[in/out] Data pointer to array to store constructed frame in + * @param[in] maxSize number of bytes left in array, effectively how much emtpy space is available to write to + * @return number of bytes used. negative number indicates error message. + */ + int constructURLFrame(uint8_t * Data, uint8_t maxSize) + { + if(maxSize < (2 + defaultUriDataLength)){ + return -1; // not enough space to encode URL frame in advertising packet. + } + int index = 0; + Data[index++] = FRAME_TYPE_URL; // 1B Type + Data[index++] = defaultUrlPower; // 1B TX Power + for(int x = 0; x < defaultUriDataLength; x++){ // 18B of URL Prefix + encoded URL + Data[index++] = defaultUriData[x]; + } + return index; } /* @@ -246,6 +300,36 @@ TlmTimeSinceBoot = timeSinceBoot; // reset return; } + + /* + * Construct TLM frame from private variables + * @param[in/out] Data pointer to array to store constructed frame in + * @param[in] maxSize number of bytes left in array, effectively how much emtpy space is available to write to + * @return number of bytes used. negative number indicates error message. + */ + int constructTLMFrame(uint8_t * Data, uint8_t maxSize) + { + if(maxSize < FRAME_SIZE_TLM){ // error, not enough space to add TLM frame. 14B, every time + return -1; + } + int index = 0; + Data[index++] = FRAME_TYPE_TLM; // Eddystone frame type = Telemetry + Data[index++] = TlmVersion; // TLM Version Number + Data[index++] = (uint8_t)(TlmBatteryVoltage>>0); // Battery Voltage[0] + Data[index++] = (uint8_t)(TlmBatteryVoltage>>8); // Battery Voltage[1] + Data[index++] = (uint8_t)(TlmBeaconTemp>>0); // Beacon Temp[0] + Data[index++] = (uint8_t)(TlmBeaconTemp>>8); // Beacon Temp[1] + Data[index++] = (uint8_t)(TlmPduCount>>0); // PDU Count [0] + Data[index++] = (uint8_t)(TlmPduCount>>8); // PDU Count [1] + Data[index++] = (uint8_t)(TlmPduCount>>16); // PDU Count [2] + Data[index++] = (uint8_t)(TlmPduCount>>24); // PDU Count [3] + Data[index++] = (uint8_t)(TlmTimeSinceBoot>>0); // Time Since Boot [0] + Data[index++] = (uint8_t)(TlmTimeSinceBoot>>8); // Time Since Boot [1] + Data[index++] = (uint8_t)(TlmTimeSinceBoot>>16); // Time Since Boot [2] + Data[index++] = (uint8_t)(TlmTimeSinceBoot>>24); // Time Since Boot [3] + + return index; + } /* Helper function to switch to the non-connectible normal mode for ZipBeacon. This gets called after a timeout. */ void setupZipBeaconAdvertisements() @@ -445,6 +529,8 @@ UriData_t defaultUriData; UIDNamespaceID_t defaultUidNamespaceID; UIDInstanceID_t defaultUidInstanceID; + int8_t defaultUidPower; + int8_t defaultUrlPower; uint16_t uidRFU; // Default value that is restored on reset PowerLevels_t &defaultAdvPowerLevels;