
Button initiated config service
Dependencies: BLE_API_EddystoneConfigService_2 mbed nRF51822
Fork of BLE_EddystoneBeaconConfigService_3 by
Revision 14:5a2a104a21a8, committed 2015-07-20
- Comitter:
- mbedAustin
- Date:
- Mon Jul 20 04:29:07 2015 +0000
- Parent:
- 13:91c356fa928e
- Child:
- 15:af8c24f34a9f
- Commit message:
- [[Testing Commit]]; ; Added button interrupt that will swap out the frame types.
Changed in this revision
ZipBeaconConfigService.h | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/ZipBeaconConfigService.h Fri Jul 17 21:45:03 2015 +0000 +++ b/ZipBeaconConfigService.h Mon Jul 20 04:29:07 2015 +0000 @@ -35,7 +35,7 @@ static const uint8_t UUID_TX_POWER_MODE_CHAR[] = UUID_URI_BEACON(0x20, 0x87); static const uint8_t UUID_BEACON_PERIOD_CHAR[] = UUID_URI_BEACON(0x20, 0x88); static const uint8_t UUID_RESET_CHAR[] = UUID_URI_BEACON(0x20, 0x89); -static const uint8_t BEACON_UUID[] = {0xAA, 0xFE}; +static const uint8_t BEACON_EDDYSTONE[] = {0xAA, 0xFE}; /** * @class ZipBeaconConfigService @@ -60,7 +60,9 @@ typedef uint8_t Lock_t[16]; /* 128 bits */ typedef int8_t PowerLevels_t[NUM_POWER_MODES]; - + #define EDDYSTONE_MAX_FRAMETYPE 3 + void (*frames[EDDYSTONE_MAX_FRAMETYPE])(uint8_t *, uint32_t); + uint8_t frameIndex; static const int URI_DATA_MAX = 18; typedef uint8_t UriData_t[URI_DATA_MAX]; @@ -90,7 +92,7 @@ UIDNamespaceID_t uidNamespaceID; // UUID type, Namespace ID, 10B UIDInstanceID_t uidInstanceID; // UUID type, Instance ID, 6B }; - + /** * @param[ref] ble * BLEDevice object for the underlying controller. @@ -370,12 +372,50 @@ TlmTimeSinceBoot = timeSinceBoot; return; } + + /* + * Callback from onRadioNotification(), used to update the PDUCounter and maybe other stuff eventually? + * + * + */ + void pduCountCallback(){ + // Update Time and PDUCount + TlmPduCount++; + TlmTimeSinceBoot += 10; + + // Every 1 second switch the frame types + if((TlmPduCount % 10) == 1){ + frameIndex = frameIndex % EDDYSTONE_MAX_FRAMETYPE; + uint8_t serviceData[SERVICE_DATA_MAX]; + unsigned serviceDataLen = 0; + //switch payloads + serviceData[serviceDataLen++] = BEACON_EDDYSTONE[0]; + serviceData[serviceDataLen++] = BEACON_EDDYSTONE[1]; + switch(frameIndex){ + case 0: + constructTLMFrame(serviceData+serviceDataLen,20); + break; + case 1: + constructURLFrame(serviceData+serviceDataLen,20); + break; + case 2: + constructUIDFrame(serviceData+serviceDataLen,20); + break; + } + ble.accumulateAdvertisingPayload(GapAdvertisingData::SERVICE_DATA, serviceData, serviceDataLen); + } + //TODO: add bit to keep timer / update time + frameIndex++; + return; + } /* Helper function to switch to the non-connectible normal mode for ZipBeacon. This gets called after a timeout. */ void setupZipBeaconAdvertisements() { uint8_t serviceData[SERVICE_DATA_MAX]; unsigned serviceDataLen = 0; + // Initialize Frame transition + frameIndex = 0; /* Reinitialize the BLE stack. This will clear away the existing services and advertising state. */ ble.shutdown(); @@ -397,16 +437,26 @@ ble.setAdvertisingType(GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED); ble.setAdvertisingInterval(beaconPeriod); ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); - ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, BEACON_UUID, sizeof(BEACON_UUID)); + ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, BEACON_EDDYSTONE, sizeof(BEACON_EDDYSTONE)); + + setTLMFrameData(0x00,22,33,0,0); // Initialize TLM Data, for testing, remove for release + updateTlmPduCount(0); + updateTlmTimeSinceBoot(0); + + // Construct TLM Frame in initial advertising. + serviceData[serviceDataLen++] = BEACON_EDDYSTONE[0]; + serviceData[serviceDataLen++] = BEACON_EDDYSTONE[1]; + constructTLMFrame(serviceData+serviceDataLen,20); +// serviceData[serviceDataLen++] = FRAME_TYPE_URL | flags; +// serviceData[serviceDataLen++] = advPowerLevels[txPowerMode]; +// for (unsigned j = 0; j < uriDataLength; j++) { +// serviceData[serviceDataLen++] = uriData[j]; +// } - serviceData[serviceDataLen++] = BEACON_UUID[0]; - serviceData[serviceDataLen++] = BEACON_UUID[1]; - serviceData[serviceDataLen++] = FRAME_TYPE_URL | flags; - serviceData[serviceDataLen++] = advPowerLevels[txPowerMode]; - for (unsigned j = 0; j < uriDataLength; j++) { - serviceData[serviceDataLen++] = uriData[j]; - } + // attach callback to count number of sent packets + //TODO: ble.gap().onRadioNotification(pduCountCallback); ble.accumulateAdvertisingPayload(GapAdvertisingData::SERVICE_DATA, serviceData, serviceDataLen); + //callbackTick.attach(&pduCountCallback,2.0); // switch services every 2 seconds } private: @@ -565,6 +615,7 @@ BLEDevice &ble; Params_t ¶ms; + Ticker callbackTick; // Default value that is restored on reset size_t defaultUriDataLength; UriData_t defaultUriData;
--- a/main.cpp Fri Jul 17 21:45:03 2015 +0000 +++ b/main.cpp Mon Jul 20 04:29:07 2015 +0000 @@ -23,6 +23,7 @@ BLE ble; ZipBeaconConfigService *zipBeaconConfig; +InterruptIn button(p17); /** * URIBeaconConfig service can operate in two modes: a configuration mode which @@ -36,6 +37,13 @@ static const int CONFIG_ADVERTISEMENT_TIMEOUT_SECONDS = 60; // Duration after power-on that config service is available. Ticker configAdvertisementTimeoutTicker; +// +// Have to use this to add a interrupt, because C++ is stupid. +// +void stupidWrapperFn(){ + zipBeaconConfig->pduCountCallback(); + } + /** * Stop advertising the UriBeaconConfig Service after a delay; and switch to normal URIBeacon. */ @@ -89,6 +97,7 @@ ble.gap().startAdvertising(); /* Set the whole thing in motion. After this call a GAP central can scan the zipBeaconConfig * service. This can then be switched to the normal URIBeacon functionality after a timeout. */ + button.rise(&stupidWrapperFn); while (true) { ble.waitForEvent(); }