-
Notifications
You must be signed in to change notification settings - Fork 707
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
127 additions
and
66 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
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 |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* BLEBeacon.cpp | ||
* | ||
* Created on: Jan 4, 2018 | ||
* Author: kolban | ||
*/ | ||
#include "sdkconfig.h" | ||
#if defined(CONFIG_BT_ENABLED) | ||
#include <string.h> | ||
#include <esp_log.h> | ||
#include "BLEBeacon.h" | ||
|
||
#define ENDIAN_CHANGE_U16(x) ((((x)&0xFF00)>>8) + (((x)&0xFF)<<8)) | ||
|
||
static const char LOG_TAG[] = "BLEBeacon"; | ||
|
||
BLEBeacon::BLEBeacon() { | ||
m_beaconData.manufacturerId = 0x4c00; | ||
m_beaconData.subType = 0x02; | ||
m_beaconData.subTypeLength = 0x15; | ||
m_beaconData.major = 0; | ||
m_beaconData.minor = 0; | ||
m_beaconData.signalPower = 0; | ||
memset(m_beaconData.proximityUUID, 0, sizeof(m_beaconData.proximityUUID)); | ||
} // BLEBeacon | ||
|
||
std::string BLEBeacon::getData() { | ||
return std::string((char*)&m_beaconData, sizeof(m_beaconData)); | ||
} // getData | ||
|
||
uint16_t BLEBeacon::getMajor() { | ||
return m_beaconData.major; | ||
} | ||
|
||
uint16_t BLEBeacon::getManufacturerId() { | ||
return m_beaconData.manufacturerId; | ||
} | ||
|
||
uint16_t BLEBeacon::getMinor() { | ||
return m_beaconData.minor; | ||
} | ||
|
||
BLEUUID BLEBeacon::getProximityUUID() { | ||
return BLEUUID(m_beaconData.proximityUUID, 16, false); | ||
} | ||
|
||
int8_t BLEBeacon::getSignalPower() { | ||
return m_beaconData.signalPower; | ||
} | ||
|
||
/** | ||
* Set the raw data for the beacon record. | ||
*/ | ||
void BLEBeacon::setData(std::string data) { | ||
if (data.length() != sizeof(m_beaconData)) { | ||
ESP_LOGE(LOG_TAG, "Unable to set the data ... length passed in was %d and expected %d", data.length(), sizeof(m_beaconData)); | ||
return; | ||
} | ||
memcpy(&m_beaconData, data.data(), sizeof(m_beaconData)); | ||
} // setData | ||
|
||
void BLEBeacon::setMajor(uint16_t major) { | ||
m_beaconData.major = ENDIAN_CHANGE_U16(major); | ||
} // setMajor | ||
|
||
void BLEBeacon::setManufacturerId(uint16_t manufacturerId) { | ||
m_beaconData.manufacturerId = ENDIAN_CHANGE_U16(manufacturerId); | ||
} // setManufacturerId | ||
|
||
void BLEBeacon::setMinor(uint16_t minor) { | ||
m_beaconData.minor = ENDIAN_CHANGE_U16(minor); | ||
} // setMinior | ||
|
||
void BLEBeacon::setProximityUUID(BLEUUID uuid) { | ||
uuid = uuid.to128(); | ||
memcpy(m_beaconData.proximityUUID, uuid.getNative()->uuid.uuid128, 16); | ||
} // setProximityUUID | ||
|
||
void BLEBeacon::setSignalPower(int8_t signalPower) { | ||
m_beaconData.signalPower = signalPower; | ||
} // setSignalPower | ||
|
||
|
||
#endif |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* BLEBeacon2.h | ||
* | ||
* Created on: Jan 4, 2018 | ||
* Author: kolban | ||
*/ | ||
|
||
#ifndef COMPONENTS_CPP_UTILS_BLEBEACON_H_ | ||
#define COMPONENTS_CPP_UTILS_BLEBEACON_H_ | ||
#include "BLEUUID.h" | ||
/** | ||
* @brief Representation of a beacon. | ||
* See: | ||
* * https://en.wikipedia.org/wiki/IBeacon | ||
*/ | ||
class BLEBeacon { | ||
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: | ||
BLEBeacon(); | ||
std::string getData(); | ||
uint16_t getMajor(); | ||
uint16_t getMinor(); | ||
uint16_t getManufacturerId(); | ||
BLEUUID getProximityUUID(); | ||
int8_t getSignalPower(); | ||
void setData(std::string data); | ||
void setMajor(uint16_t major); | ||
void setMinor(uint16_t minor); | ||
void setManufacturerId(uint16_t manufacturerId); | ||
void setProximityUUID(BLEUUID uuid); | ||
void setSignalPower(int8_t signalPower); | ||
}; // BLEBeacon | ||
|
||
#endif /* COMPONENTS_CPP_UTILS_BLEBEACON_H_ */ |