Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BLE_API LIS3DH mbed nRF51822 BMC050 nRF51_LowPwr nRF51_Vdd
Fork of BLE_EddystoneBeacon_Service by
Revision 17:0458759c40e4, committed 2015-07-22
- Comitter:
- mbedAustin
- Date:
- Wed Jul 22 21:28:09 2015 +0000
- Parent:
- 16:a7d07ea94b31
- Child:
- 18:91c36071aafb
- Commit message:
- [[Debug]] Compiling, hardfaulting when attempting to dynamically switch frames.
Changed in this revision
| ZipBeaconConfigService.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/ZipBeaconConfigService.h Wed Jul 22 18:01:20 2015 +0000
+++ b/ZipBeaconConfigService.h Wed Jul 22 21:28:09 2015 +0000
@@ -39,7 +39,7 @@
static const uint8_t BEACON_EDDYSTONE[] = {0xAA, 0xFE};
//Debug is disabled by default
-#if 0
+#if 1
#define DBG(x, ...) printf("[EddyStone: DBG]"x" \t[%s,%d]\r\n", ##__VA_ARGS__,__FILE__,__LINE__);
#define WARN(x, ...) printf("[EddyStone: WARN]"x" \t[%s,%d]\r\n", ##__VA_ARGS__,__FILE__,__LINE__);
#define ERR(x, ...) printf("[EddyStone: ERR]"x" \t[%s,%d]\r\n", ##__VA_ARGS__,__FILE__,__LINE__);
@@ -242,9 +242,7 @@
* @return number of bytes used. negative number indicates error message.
*/
int constructUIDFrame(uint8_t * Data, uint8_t maxSize) {
- 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
@@ -258,6 +256,7 @@
Data[index++] = (uint8_t)(uidRFU >> 8);
Data[index++] = (uint8_t)uidRFU;
}
+ DBG("construcUIDFrame %d, %d",maxSize,index);
return index;
}
@@ -283,15 +282,13 @@
* @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++] = params.txPowerMode; // 1B TX Power
for(int x = 0; x < defaultUriDataLength; x++) { // 18B of URL Prefix + encoded URL
Data[index++] = defaultUriData[x];
}
+ DBG("constructURLFrame: %d, %d",maxSize,index);
return index;
}
@@ -318,9 +315,6 @@
* @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
@@ -336,7 +330,7 @@
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]
-
+ DBG("constructURLFrame: %d, %d",maxSize,index);
return index;
}
@@ -394,22 +388,17 @@
*/
bool updateAdvPacket(uint8_t serviceData[], unsigned serviceDataLen) {
// Fields from the Service
- DBG("Updating Adv Data: %d", serviceDataLen);
-
+ DBG("Updating AdvFrame: %d", serviceDataLen);
+ printf("\r\n");
+ for(int x = 0; x<serviceDataLen; x++) {
+ printf("%2.2x:",serviceData[x]);
+ }
+ printf("\r\n");
ble.clearAdvertisingPayload();
ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, BEACON_EDDYSTONE, sizeof(BEACON_EDDYSTONE));
ble.accumulateAdvertisingPayload(GapAdvertisingData::SERVICE_DATA, serviceData, serviceDataLen);
- // attach callback to count number of sent packets
-
-// printf("\r\n");
-// for(int x = 0; x<serviceDataLen; x++) {
-// printf("%2.2x:",serviceData[x]);
-// }
-// printf("\r\n");
-
- ble.gap().startAdvertising();
return true;
}
@@ -419,26 +408,25 @@
*
*/
void radioNotificationCallback(bool radioActive) {
- DBG("RadioNotificationCallback : %d, %d",radioActive,frameIndex);
+ DBG("RadioNotificationCallback : %d, %d, %d",radioActive,frameIndex,TlmPduCount);
// Update Time and PDUCount
// True just before an frame is sent, fale just after a frame is sent
- if(radioActive) {
+
+ TlmPduCount++;
+ frameIndex = frameIndex % EDDYSTONE_MAX_FRAMETYPE;
+ uint8_t serviceData[SERVICE_DATA_MAX];
+ unsigned serviceDataLen = 0;
+ //hard code in the eddystone UUID
+ serviceData[serviceDataLen++] = BEACON_EDDYSTONE[0];
+ serviceData[serviceDataLen++] = BEACON_EDDYSTONE[1];
+ if(!radioActive) {
// Do Nothing
} else {
- static bool switchFlag;
- TlmPduCount++;
- frameIndex = frameIndex % EDDYSTONE_MAX_FRAMETYPE;
- uint8_t serviceData[SERVICE_DATA_MAX];
- unsigned serviceDataLen = 0;
- //hard code in the eddystone UUID
- serviceData[serviceDataLen++] = BEACON_EDDYSTONE[0];
- serviceData[serviceDataLen++] = BEACON_EDDYSTONE[1];
-
// state machine to control which packet is being sent
switch(frameIndex) {
case 0:
- DBG("\tconstructing TLM Frame: ");
- serviceDataLen += constructTLMFrame(serviceData+serviceDataLen,SERVICE_DATA_MAX);
+ serviceDataLen += constructTLMFrame(serviceData+serviceDataLen,20);
+ DBG("\tconstructing TLM Frame: len= %d",serviceDataLen);
updateAdvPacket(serviceData,serviceDataLen);
frameIndex++;
switchFlag = true;
@@ -446,8 +434,8 @@
case 1:
// switch out packets
if(switchFlag) {
- DBG("\tconstructing URL Frame: ");
- serviceDataLen += constructURLFrame(serviceData+serviceDataLen,SERVICE_DATA_MAX);
+ serviceDataLen += constructURLFrame(serviceData+serviceDataLen,20);
+ DBG("\tconstructing URL Frame: len = %d ",serviceDataLen);
updateAdvPacket(serviceData,serviceDataLen);
switchFlag = false;
} else {
@@ -460,8 +448,8 @@
case 2:
// switch out packets
if(switchFlag) {
- DBG("\tconstructing UID Frame: ");
- serviceDataLen += constructUIDFrame(serviceData+serviceDataLen,SERVICE_DATA_MAX);
+ serviceDataLen += constructUIDFrame(serviceData+serviceDataLen,20);
+ DBG("\tconstructing UID Frame: len=%d",serviceDataLen);
updateAdvPacket(serviceData,serviceDataLen);
switchFlag = false;
} else {
@@ -491,8 +479,10 @@
uint8_t flags = params.flags;
// Initialize Frame transition
- frameIndex = 0;
+ frameIndex = 2;
uidRFU = 0;
+ switchFlag = true;
+
/* Reinitialize the BLE stack. This will clear away the existing services and advertising state. */
ble.shutdown();
@@ -500,30 +490,22 @@
ble.setTxPower(params.advPowerLevels[params.txPowerMode]);
ble.setAdvertisingType(GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED);
ble.setAdvertisingInterval(beaconPeriod);
- ble.gap().onRadioNotification(this,&ZipBeaconConfigService::radioNotificationCallback);
extern void saveURIBeaconConfigParams(const Params_t *paramsP); /* forward declaration; necessary to avoid a circular dependency. */
saveURIBeaconConfigParams(¶ms);
- setTLMFrameData(0x00,22,33,0,0); // Initialize TLM Data, for testing, remove for release
- updateTlmPduCount(0);
- updateTlmTimeSinceBoot(0);
+ setTLMFrameData(0x00,0x2222,0x3333,0x01,0x02); // Initialize TLM Data, for testing, remove for release
+ updateTlmPduCount(0x11);
+ updateTlmTimeSinceBoot(0x22);
// Construct TLM Frame in initial advertising.
serviceData[serviceDataLen++] = BEACON_EDDYSTONE[0];
serviceData[serviceDataLen++] = BEACON_EDDYSTONE[1];
- serviceDataLen += constructTLMFrame(serviceData+serviceDataLen,SERVICE_DATA_MAX);
+ serviceDataLen += constructURLFrame(serviceData+serviceDataLen,SERVICE_DATA_MAX);
updateAdvPacket(serviceData, serviceDataLen);
-// serviceData[serviceDataLen++] = FRAME_TYPE_URL | flags;
-// serviceData[serviceDataLen++] = advPowerLevels[txPowerMode];
-// for (unsigned j = 0; j < uriDataLength; j++) {
-// serviceData[serviceDataLen++] = uriData[j];
-// }
-
-
- //callbackTick.attach(this,&ZipBeaconConfigService::radioNotificationCallback, 0.1); // switch services every 2 seconds
+ ble.gap().startAdvertising();
+ ble.gap().onRadioNotification(this,&ZipBeaconConfigService::radioNotificationCallback);
timeSinceBootTick.attach(this,&ZipBeaconConfigService::tsbCallback,0.1); // incriment the TimeSinceBoot ticker every 0.1s
- //callbackTick.attach(stupidWrapperFn,2.0);
}
private:
@@ -697,6 +679,7 @@
uint8_t lockedState;
bool initSucceeded;
uint8_t resetFlag;
+ bool switchFlag;
// Private Variables for Telemetry Data
uint8_t TlmVersion;
