51 lines
1.7 KiB
C++
51 lines
1.7 KiB
C++
#include <Arduino.h>
|
|
#include <NimBLEBeacon.h>
|
|
#include <NimBLEDevice.h>
|
|
|
|
#define ENDIAN_CHANGE_U16(x) ((((x)&0xFF00) >> 8) + (((x)&0xFF) << 8))
|
|
#define Sprintf(f, ...) ({ char* s; asprintf(&s, f, __VA_ARGS__); String r = s; free(s); r; })
|
|
//define SDateTimef(f) ({ struct tm firstSeenTm; gmtime_r(&f, &firstSeenTm); Sprintf("%d/%d/%d %d:%.2d:%.2d", firstSeenTm.tm_mon, firstSeenTm.tm_mday, 1900 + firstSeenTm.tm_year, firstSeenTm.tm_hour, firstSeenTm.tm_min, firstSeenTm.tm_sec); })
|
|
#define SMacf(f) ({ auto nativeAddress = f.getNative(); Sprintf("%02x%02x%02x%02x%02x%02x", nativeAddress[5], nativeAddress[4], nativeAddress[3], nativeAddress[2], nativeAddress[1], nativeAddress[0]); })
|
|
|
|
#ifdef TX_DEFAULT
|
|
static const int defaultTxPower = TX_DEFAULT;
|
|
#else
|
|
static const int defaultTxPower = -59;
|
|
#endif
|
|
|
|
static const uint16_t beaconUUID = 0xFEAA;
|
|
static const uint16_t tileUUID = 0xFEED;
|
|
static const uint16_t exposureUUID = 0xFD6F;
|
|
|
|
static int median_of_3(int a, int b, int c)
|
|
{
|
|
int the_max = max(max(a, b), c);
|
|
int the_min = min(min(a, b), c);
|
|
// unnecessarily clever code
|
|
int the_median = the_max ^ the_min ^ a ^ b ^ c;
|
|
return (the_median);
|
|
}
|
|
|
|
static String getProximityUUIDString(BLEBeacon beacon)
|
|
{
|
|
std::string serviceData = beacon.getProximityUUID().toString().c_str();
|
|
int serviceDataLength = serviceData.length();
|
|
String returnedString = "";
|
|
int i = serviceDataLength;
|
|
while (i > 0)
|
|
{
|
|
if (serviceData[i - 1] == '-')
|
|
{
|
|
i--;
|
|
}
|
|
char a = serviceData[i - 1];
|
|
char b = serviceData[i - 2];
|
|
returnedString += b;
|
|
returnedString += a;
|
|
|
|
i -= 2;
|
|
}
|
|
|
|
return returnedString;
|
|
}
|