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.
Dependents: LinkNode_SimpleChatwithSerial
Fork of BLE_API by
Diff: ble/services/EddystoneService.h
- Revision:
- 890:f3144091ae19
- Parent:
- 885:1164aa1735ca
- Child:
- 906:8ddab3271c2f
diff -r 958c04685226 -r f3144091ae19 ble/services/EddystoneService.h
--- a/ble/services/EddystoneService.h Thu Nov 26 12:52:00 2015 +0000
+++ b/ble/services/EddystoneService.h Thu Nov 26 12:52:00 2015 +0000
@@ -101,9 +101,9 @@
void setUIDFrameData(int8_t power,
UIDNamespaceID_t namespaceID,
UIDInstanceID_t instanceID,
- float uidAdvPeriodIn,
+ uint32_t uidAdvPeriodIn,
uint16_t RFU = 0x0000) {
- if (0.0f == uidAdvPeriodIn) {
+ if (0 == uidAdvPeriodIn) {
uidIsSet = false;
return;
}
@@ -170,45 +170,21 @@
* @param[in] urlAdvPeriodIn How long to advertise the URL frame (measured in # of adv periods)
* @return false on success, true on failure.
*/
- bool setURLFrameData(int8_t power, const char *urlIn, float urlAdvPeriodIn) {
- if (0.0f == urlAdvPeriodIn) {
+ bool setURLFrameData(int8_t power, const char *urlIn, uint32_t urlAdvPeriodIn) {
+ if (0 == urlAdvPeriodIn) {
urlIsSet = false;
return false;
}
+ defaultUrlPower = power;
encodeURL(urlIn, defaultUriData, defaultUriDataLength); // encode URL to URL Formatting
if (defaultUriDataLength > URI_DATA_MAX) {
return true; // error, URL is too big
}
- defaultUrlPower = power;
urlAdvPeriod = urlAdvPeriodIn;
urlIsSet = true;
return false;
}
- /**
- * Set Eddystone URL Frame information.
- * @param[in] power TX Power in dB measured at 0 meters from the device.
- * @param[in] encodedUrlIn Encoded URL
- * @param[in] encodedUrlInLength Length of the encoded URL
- * @param[in] urlAdvPeriodIn How long to advertise the URL frame (measured in # of adv periods)
- * @return false on success, true on failure.
- */
- bool setURLFrameEncodedData(int8_t power, const char *encodedUrlIn, uint8_t encodedUrlInLength, float urlAdvPeriodIn) {
- if (0.0f == urlAdvPeriodIn) {
- urlIsSet = false;
- return false;
- }
- memcpy(defaultUriData, encodedUrlIn, encodedUrlInLength);
- if (defaultUriDataLength > URI_DATA_MAX) {
- return true; // error, URL is too big
- }
- defaultUrlPower = power;
- defaultUriDataLength = encodedUrlInLength;
- urlAdvPeriod = urlAdvPeriodIn;
- urlIsSet = true;
- return false;
- }
-
/*
* Construct URL frame from private variables
* @param[in/out] Data pointer to array to store constructed frame in
@@ -235,12 +211,12 @@
*
*/
void setTLMFrameData(uint8_t version = 0,
- float advPeriod = 60.0f,
+ uint32_t advPeriod = 60,
uint16_t batteryVoltage = 0,
- uint16_t beaconTemp = 0x8000,
+ uint16_t beaconTemp = 0,
uint32_t pduCount = 0,
uint32_t timeSinceBoot = 0) {
- if (0.0f == advPeriod) {
+ if (0 == advPeriod) {
tlmIsSet = false;
return;
}
@@ -260,10 +236,6 @@
* @return number of bytes used. negative number indicates error message.
*/
int constructTLMFrame(uint8_t *Data, uint8_t maxSize) {
- uint32_t now = timeSinceBootTimer.read_ms();
- TlmTimeSinceBoot += (now - lastBootTimerRead) / 100;
- lastBootTimerRead = now;
-
int index = 0;
Data[index++] = FRAME_TYPE_TLM; // Eddystone frame type = Telemetry
Data[index++] = TlmVersion; // TLM Version Number
@@ -320,6 +292,14 @@
}
/*
+ * callback function, called every 0.1s, incriments the TimeSinceBoot field in the TLM frame
+ * @return nothing
+ */
+ void tsbCallback(void) {
+ TlmTimeSinceBoot++;
+ }
+
+ /*
* Update advertising data
* @return true on success, false on failure
*/
@@ -507,7 +487,7 @@
// Initialize Frame transition, start with URL to pass eddystone validator app on first try
if (urlIsSet) {
frameIndex = url;
- urlTicker.attach(this, &EddystoneService::urlCallback, (float) advPeriodus / 1000.0f);
+ urlTicker.attach(this, &EddystoneService::urlCallback, urlAdvPeriod);
DBG("attached urlCallback every %d seconds", urlAdvPeriod);
}
if (uidIsSet) {
@@ -520,8 +500,7 @@
// Make double sure the PDUCount and TimeSinceBoot fields are set to zero at reset
updateTlmPduCount(0);
updateTlmTimeSinceBoot(0);
- lastBootTimerRead = 0;
- timeSinceBootTimer.start();
+ timeSinceBootTick.attach(this, &EddystoneService::tsbCallback, 0.1); // incriment the TimeSinceBoot ticker every 0.1s
tlmTicker.attach(this, &EddystoneService::tlmCallback, TlmAdvPeriod);
DBG("attached tlmCallback every %d seconds", TlmAdvPeriod);
}
@@ -540,8 +519,7 @@
BLEDevice &ble;
uint16_t advPeriodus;
uint8_t txPower;
- Timer timeSinceBootTimer;
- volatile uint32_t lastBootTimerRead;
+ Ticker timeSinceBootTick; // counter that counts time since boot
volatile bool advLock;
volatile FrameTypes frameIndex;
Timeout stopAdv;
@@ -552,7 +530,7 @@
UriData_t defaultUriData;
int8_t defaultUrlPower;
bool urlIsSet; // flag that enables / disable URI Frames
- float urlAdvPeriod; // how long the url frame will be advertised for
+ uint32_t urlAdvPeriod; // how long the url frame will be advertised for
Ticker urlTicker;
// UID Frame Variables
@@ -561,7 +539,7 @@
int8_t defaultUidPower;
uint16_t uidRFU;
bool uidIsSet; // flag that enables / disable UID Frames
- float uidAdvPeriod; // how long the uid frame will be advertised for
+ uint32_t uidAdvPeriod; // how long the uid frame will be advertised for
Ticker uidTicker;
// TLM Frame Variables
@@ -571,7 +549,7 @@
volatile uint32_t TlmPduCount;
volatile uint32_t TlmTimeSinceBoot;
bool tlmIsSet; // flag that enables / disables TLM frames
- float TlmAdvPeriod; // number of minutes between adv frames
+ uint32_t TlmAdvPeriod; // number of minutes between adv frames
Ticker tlmTicker;
public:
