Skip to content

Commit

Permalink
- make UriBeacon extend BLEPeripheral
Browse files Browse the repository at this point in the history
  • Loading branch information
sandeepmistry committed Jun 4, 2015
1 parent ef8ede4 commit cc0a3ab
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 32 deletions.
34 changes: 9 additions & 25 deletions URIBeacon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,27 @@ static const char* URI_BEACON_SUFFIX_SUBSTITUTIONS[] = {
};

URIBeacon::URIBeacon(unsigned char req, unsigned char rdy, unsigned char rst) :
_blePeripheral(req, rdy, rst),
BLEPeripheral(req, rdy, rst),
_bleService("fed8"),
_bleCharacteristic("fed9", BLERead | BLEBroadcast, MAX_SERVICE_DATA_SIZE)
{
// this->_blePeripheral.setLocalName(uri);
// this->_blePeripheral.setLocalName("uri-beacon");
// this->setLocalName(uri);
// this->setLocalName("uri-beacon");

this->_blePeripheral.setAdvertisedServiceUuid(this->_bleService.uuid());
this->setAdvertisedServiceUuid(this->_bleService.uuid());

this->_blePeripheral.setConnectable(false);
this->setConnectable(false);

this->_blePeripheral.addAttribute(this->_bleService);
this->_blePeripheral.addAttribute(this->_bleCharacteristic);
this->addAttribute(this->_bleService);
this->addAttribute(this->_bleCharacteristic);
}

void URIBeacon::begin(unsigned char flags, unsigned char power, const char* uri) {
this->_flags = flags;
this->_power = power;
this->setURI(uri);

this->_blePeripheral.begin();
BLEPeripheral::begin();

this->_bleCharacteristic.broadcast();
}
Expand All @@ -67,22 +67,6 @@ void URIBeacon::setURI(const char* uri) {
this->_bleCharacteristic.setValue(serviceData, 2 + compressedURIlength);
}

void URIBeacon::setLocalName(const char *localName) {
this->_blePeripheral.setLocalName(localName);
}

void URIBeacon::setConnectable(bool connectable) {
this->_blePeripheral.setConnectable(connectable);
}

void URIBeacon::addAttribute(BLELocalAttribute& attribute) {
this->_blePeripheral.addAttribute(attribute);
}

void URIBeacon::setEventHandler(BLEPeripheralEvent event, BLEPeripheralEventHandler eventHandler) {
this->_blePeripheral.setEventHandler(event, eventHandler);
}

unsigned char URIBeacon::compressURI(const char* uri, char *compressedUri, unsigned char compressedUriSize) {
String uriString = uri;

Expand Down Expand Up @@ -111,5 +95,5 @@ unsigned char URIBeacon::compressURI(const char* uri, char *compressedUri, unsig
}

void URIBeacon::loop() {
this->_blePeripheral.poll();
this->poll();
}
8 changes: 1 addition & 7 deletions URIBeacon.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "BLEPeripheral.h"

class URIBeacon
class URIBeacon : public BLEPeripheral
{
public:
URIBeacon(unsigned char req, unsigned char rdy, unsigned char rst);
Expand All @@ -13,18 +13,12 @@ class URIBeacon

void setURI(const char* uri);

void setLocalName(const char *localName);
void setConnectable(bool connectable);
void addAttribute(BLELocalAttribute& attribute);
void setEventHandler(BLEPeripheralEvent event, BLEPeripheralEventHandler eventHandler);

private:
unsigned char compressURI(const char* uri, char *compressedUri, unsigned char compressedUriSize);

unsigned char _flags;
unsigned char _power;

BLEPeripheral _blePeripheral;
BLEService _bleService;
BLECharacteristic _bleCharacteristic;
};
Expand Down

0 comments on commit cc0a3ab

Please sign in to comment.