-
-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* General code cleanup * The internal data struct type `BeaconData` is now public and can be used by the application. * `NimBLEBeacon::setData` now takes `const NimBLEBeacon::BeaconData&` instead of `std::string`. * Added overload for `NimBLEBeacon::setData` that takes a pointer to raw `uint8_t` data and length`. * `NimBLEBeacon::getData` now returns `const NimBLEBeacon::BeaconData&` instead of `std::string`.
- Loading branch information
Showing
2 changed files
with
72 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,61 @@ | ||
/* | ||
* NimBLEBeacon2.h | ||
* NimBLEBeacon.h | ||
* | ||
* Created: on March 15 2020 | ||
* Author H2zero | ||
* | ||
* Originally: | ||
* | ||
* BLEBeacon2.h | ||
* BLEBeacon.h | ||
* | ||
* Created on: Jan 4, 2018 | ||
* Author: kolban | ||
*/ | ||
|
||
#ifndef MAIN_NIMBLEBEACON_H_ | ||
#define MAIN_NIMBLEBEACON_H_ | ||
#ifndef NIMBLE_CPP_BEACON_H_ | ||
#define NIMBLE_CPP_BEACON_H_ | ||
|
||
#include "nimconfig.h" | ||
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_BROADCASTER) | ||
|
||
class NimBLEUUID; | ||
|
||
# include <cstdint> | ||
|
||
#include "NimBLEUUID.h" | ||
/** | ||
* @brief Representation of a beacon. | ||
* See: | ||
* * https://en.wikipedia.org/wiki/IBeacon | ||
*/ | ||
class NimBLEBeacon { | ||
private: | ||
struct { | ||
uint16_t manufacturerId; | ||
uint8_t subType; | ||
uint8_t subTypeLength; | ||
uint8_t proximityUUID[16]; | ||
uint16_t major; | ||
uint16_t minor; | ||
int8_t signalPower; | ||
} __attribute__((packed)) m_beaconData; | ||
public: | ||
NimBLEBeacon(); | ||
std::string getData(); | ||
uint16_t getMajor(); | ||
uint16_t getMinor(); | ||
uint16_t getManufacturerId(); | ||
NimBLEUUID getProximityUUID(); | ||
int8_t getSignalPower(); | ||
void setData(const std::string &data); | ||
void setMajor(uint16_t major); | ||
void setMinor(uint16_t minor); | ||
void setManufacturerId(uint16_t manufacturerId); | ||
void setProximityUUID(const NimBLEUUID &uuid); | ||
void setSignalPower(int8_t signalPower); | ||
public: | ||
struct BeaconData { | ||
uint16_t manufacturerId{0x4c00}; | ||
uint8_t subType{0x02}; | ||
uint8_t subTypeLength{0x15}; | ||
uint8_t proximityUUID[16]{}; | ||
uint16_t major{}; | ||
uint16_t minor{}; | ||
int8_t signalPower{}; | ||
} __attribute__((packed)); | ||
|
||
const BeaconData& getData(); | ||
uint16_t getMajor(); | ||
uint16_t getMinor(); | ||
uint16_t getManufacturerId(); | ||
NimBLEUUID getProximityUUID(); | ||
int8_t getSignalPower(); | ||
void setData(const uint8_t* data, uint8_t length); | ||
void setData(const BeaconData& data); | ||
void setMajor(uint16_t major); | ||
void setMinor(uint16_t minor); | ||
void setManufacturerId(uint16_t manufacturerId); | ||
void setProximityUUID(const NimBLEUUID& uuid); | ||
void setSignalPower(int8_t signalPower); | ||
|
||
private: | ||
BeaconData m_beaconData; | ||
}; // NimBLEBeacon | ||
|
||
#endif /* MAIN_NIMBLEBEACON_H_ */ | ||
#endif // NIMBLE_CPP_BEACON_H_ | ||
#endif // CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_PERIPHERAL |