Minor temporary patch to allow DFU packet callback
Fork of BLE_API by
Diff: services/URIBeacon2Service.h
- Revision:
- 151:cb5df770f05b
- Parent:
- 150:aa2d70369df0
- Child:
- 152:fc0bb2ba916b
diff -r aa2d70369df0 -r cb5df770f05b services/URIBeacon2Service.h --- a/services/URIBeacon2Service.h Fri Nov 28 14:11:20 2014 +0000 +++ b/services/URIBeacon2Service.h Fri Nov 28 14:11:20 2014 +0000 @@ -22,39 +22,39 @@ class URIBeacon2Service { public: // ee0c2080-8786-40ba-ab96-99b91ac981d8 - URIBeacon2Service(BLEDevice &ble_, const char *urldata) : ble(ble_), payloadIndex(0), payload() { + URIBeacon2Service(BLEDevice &ble_, const char *urldata, uint8_t flags = 0, uint8_t power = 0) : ble(ble_), payloadIndex(0), serviceDataPayload() { const uint8_t BEACON_UUID[] = {0xD8, 0xFE}; - payload[payloadIndex++] = BEACON_UUID[0]; - payload[payloadIndex++] = BEACON_UUID[1]; - payload[payloadIndex++] = 0x00; /* flags */ - payload[payloadIndex++] = 0x20; /* power */ + serviceDataPayload[payloadIndex++] = BEACON_UUID[0]; + serviceDataPayload[payloadIndex++] = BEACON_UUID[1]; + serviceDataPayload[payloadIndex++] = flags; + serviceDataPayload[payloadIndex++] = power; size_t sizeofURLData = strlen(urldata); - size_t encodedBytes = encodeURIData(urldata, sizeofURLData); + size_t encodedBytes = encodeServiceData(urldata, sizeofURLData); ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, BEACON_UUID, sizeof(BEACON_UUID)); - ble.accumulateAdvertisingPayload(GapAdvertisingData::SERVICE_DATA, payload, encodedBytes + 4); + ble.accumulateAdvertisingPayload(GapAdvertisingData::SERVICE_DATA, serviceDataPayload, encodedBytes + 4); } - void dumpEncoded() { + void dumpEncodedSeviceData() const { printf("encoded: '"); for (unsigned i = 0; i < payloadIndex; i++) { - printf(" %02x", payload[i]); + printf(" %02x", serviceDataPayload[i]); } printf("'\r\n"); } private: - size_t encodeURIData(const char *urldata, size_t sizeofURLData) { + size_t encodeServiceData(const char *urldata, size_t sizeofURLData) { if (sizeofURLData == 0) { return 0; } - return encodePrefix(urldata, sizeofURLData) + copyURLCheckingForSuffixes(urldata, sizeofURLData); + return encodeURISchemePrefix(urldata, sizeofURLData) + encodeURI(urldata, sizeofURLData); } - size_t encodePrefix(const char *&urldata, size_t &sizeofURLData) { + size_t encodeURISchemePrefix(const char *&urldata, size_t &sizeofURLData) { const char *prefixes[] = { "http://www.", "https://www.", @@ -68,7 +68,7 @@ for (unsigned i = 0; i < NUM_PREFIXES; i++) { size_t prefixLen = strlen(prefixes[i]); if (strncmp(urldata, prefixes[i], prefixLen) == 0) { - payload[payloadIndex++] = i; + serviceDataPayload[payloadIndex++] = i; encodedBytes = 1; urldata += prefixLen; @@ -80,7 +80,7 @@ return encodedBytes; } - size_t copyURLCheckingForSuffixes(const char *urldata, size_t sizeofURLData) { + size_t encodeURI(const char *urldata, size_t sizeofURLData) { const char *suffixes[] = { ".com/", ".org/", @@ -110,7 +110,7 @@ } if (strncmp(urldata, suffixes[i], suffixLen) == 0) { - payload[payloadIndex++] = i; + serviceDataPayload[payloadIndex++] = i; ++encodedBytes; urldata += suffixLen; sizeofURLData -= suffixLen; @@ -119,7 +119,7 @@ } /* This is the default case where we've got an ordinary character which doesn't match a suffix. */ if (i == NUM_SUFFIXES) { - payload[payloadIndex++] = *urldata; + serviceDataPayload[payloadIndex++] = *urldata; ++encodedBytes; ++urldata; --sizeofURLData; @@ -155,7 +155,7 @@ BLEDevice &ble; size_t payloadIndex; - uint8_t payload[MAX_SIZEOF_PAYLOAD]; + uint8_t serviceDataPayload[MAX_SIZEOF_PAYLOAD]; // uint8_t batteryLevel; // GattCharacteristic batteryLevelCharacteristic; };