Button initiated config service
Dependencies: BLE_API_EddystoneConfigService_2 mbed nRF51822
Fork of BLE_EddystoneBeaconConfigService_3 by
Diff: EddystoneConfigService.h
- Revision:
- 45:1827e4f496a7
- Parent:
- 44:0e27ee7800b8
- Child:
- 46:46bb40f60816
--- a/EddystoneConfigService.h Fri Sep 11 19:38:12 2015 +0000 +++ b/EddystoneConfigService.h Fri Sep 11 21:48:41 2015 +0000 @@ -126,7 +126,7 @@ PowerLevels_t &defaultAdvPowerLevelsIn) : ble(bleIn), params(paramsIn), // Initialize URL Data - defaultUriDataLength(), + defaultUriDataLength(0), defaultUriData(), defaultUidNamespaceID(), // Initialize UID Data defaultUidInstanceID(), @@ -231,11 +231,13 @@ */ void setDefaultURIFrameData(const char * uriIn,uint32_t advPeriod = 1000){ DBG("Setting Default URI Data"); - // Set URL Frame - encodeURI(uriIn, defaultUriData, defaultUriDataLength); // encode URL to URL Formatting - if (defaultUriDataLength > URI_DATA_MAX) { - return; - } +// // Set URL Frame +// EddystoneService::encodeURL(uriIn, defaultUriData, defaultUriDataLength); // encode URL to URL Formatting +// if (defaultUriDataLength > URI_DATA_MAX) { +// return; +// } + memcpy(defaultUriData,uriIn,URI_DATA_MAX); +// defaultUriData = (UriData_t *)uriIn; defaultUriAdvPeriod = advPeriod; urlIsSet = true; // flag to add this to eddystone service when config is done } @@ -334,7 +336,8 @@ INFO("Device Unlocked"); } else if (handle == uriDataChar.getValueHandle()) { params.uriDataLength = writeParams->len; - memcpy(params.uriData, writeParams->data, params.uriDataLength); + memset(params.uriData,0x00,URI_DATA_MAX); // clear URI string + memcpy(params.uriData, writeParams->data, params.uriDataLength); // set URI string params.uriEnabled = true; INFO("URI = %s, URILen = %d", writeParams->data, writeParams->len); } else if (handle == flagsChar.getValueHandle()) { @@ -529,76 +532,6 @@ ReadWriteGattCharacteristic<uint16_t> beaconPeriodChar; WriteOnlyGattCharacteristic<uint8_t> resetChar; -public: - /* - * Encode a human-readable URI into the binary format defined by URIBeacon spec (https://github.com/google/uribeacon/tree/master/specification). - */ - static void encodeURI(const char *uriDataIn, UriData_t uriDataOut, uint8_t &sizeofURIDataOut) { - const char *prefixes[] = { - "http://www.", - "https://www.", - "http://", - "https://", - }; - const uint8_t NUM_PREFIXES = sizeof(prefixes) / sizeof(char *); - const char *suffixes[] = { - ".com/", - ".org/", - ".edu/", - ".net/", - ".info/", - ".biz/", - ".gov/", - ".com", - ".org", - ".edu", - ".net", - ".info", - ".biz", - ".gov" - }; - const uint8_t NUM_SUFFIXES = sizeof(suffixes) / sizeof(char *); - - sizeofURIDataOut = 0; - memset(uriDataOut, 0, sizeof(UriData_t)); - - if ((uriDataIn == NULL) || (strlen(uriDataIn) == 0)) { - return; - } - - /* - * handle prefix - */ - for (unsigned i = 0; i < NUM_PREFIXES; i++) { - uint8_t prefixLen = strlen(prefixes[i]); - if (strncmp(uriDataIn, prefixes[i], prefixLen) == 0) { - uriDataOut[sizeofURIDataOut++] = i; - uriDataIn += prefixLen; - break; - } - } - - /* - * handle suffixes - */ - while (*uriDataIn && (sizeofURIDataOut < URI_DATA_MAX)) { - /* check for suffix match */ - unsigned i; - for (i = 0; i < NUM_SUFFIXES; i++) { - uint8_t suffixLen = strlen(suffixes[i]); - if (strncmp(uriDataIn, suffixes[i], suffixLen) == 0) { - uriDataOut[sizeofURIDataOut++] = i; - uriDataIn += suffixLen; - break; /* from the for loop for checking against suffixes */ - } - } - /* This is the default case where we've got an ordinary character which doesn't match a suffix. */ - if (i == NUM_SUFFIXES) { - uriDataOut[sizeofURIDataOut++] = *uriDataIn; - ++uriDataIn; - } - } - } }; #endif // SERVICES_EDDYSTONEBEACONCONFIGSERVICE_H_