Skip to content

Fix Firmata crash, J-791. Peripheral discover profile failure, J-788 #391

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions libraries/CurieBLE/examples/peripheral/broadcast/broadcast.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <CurieBLE.h>

uint8_t value = 0;

BLEPeripheral peripheral;
BLEService service = BLEService("EEE0");
BLEShortCharacteristic characteristic = BLEShortCharacteristic("EEE1", BLERead | BLENotify | BLEBroadcast);

void setup() {
Serial.begin(9600);

peripheral.setLocalName("BLEBroadcast");
peripheral.setAdvertisedServiceUuid(service.uuid());

peripheral.addAttribute(service);
peripheral.addAttribute(characteristic);

characteristic.setValue(value);

peripheral.begin();
characteristic.broadcast();

Serial.println(F("BLE Broadcast Count"));
}

void loop() {
peripheral.poll();
characteristic.setValue(value);
delay(1000);
value++;
}
6 changes: 3 additions & 3 deletions libraries/CurieBLE/src/BLEPeripheral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include "BLEPeripheral.h"

static BLEPeripheralEventHandler m_eventHandlers[BLEDeviceLastEvent];
static BLEPeripheralEventHandler m_eventHandlers[BLEDeviceLastEvent] = {NULL, NULL, NULL, NULL};

void bleBackCompatiblePeripheralConnectHandler(BLEDevice central)
{
Expand Down Expand Up @@ -146,15 +146,15 @@ BLECentral BLEPeripheral::central(void)

bool BLEPeripheral::connected(void)
{
return BLE.connected();
BLEDevice centralBle = BLE.central();
return centralBle.connected();
}

void BLEPeripheral::init()
{
if (!_initCalled)
{
BLE.begin();
memset(m_eventHandlers, 0, sizeof(m_eventHandlers));
_initCalled = true;
}
}
Expand Down
17 changes: 17 additions & 0 deletions libraries/CurieBLE/src/internal/BLECallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,23 @@ uint8_t profile_service_read_rsp_process(bt_conn_t *conn,
return ret;
}

uint8_t profile_characteristic_read_rsp_process(bt_conn_t *conn,
int err,
bt_gatt_read_params_t *params,
const void *data,
uint16_t length)
{
BLEDevice bleDevice(bt_conn_get_dst(conn));
BLEServiceImp* service_imp = BLEProfileManager::instance()->getServiceBySubHandle(bleDevice, params->single.handle);

uint8_t ret = service_imp->characteristicReadRspProc(conn,
err,
params,
data,
length);
pr_debug(LOG_MODULE_BLE, "%s-%d:ret-%d", __FUNCTION__, __LINE__, ret);
return ret;
}


void bleConnectEventHandler(bt_conn_t *conn,
Expand Down
5 changes: 5 additions & 0 deletions libraries/CurieBLE/src/internal/BLECallbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ uint8_t profile_service_read_rsp_process(bt_conn_t *conn,

void ble_on_write_no_rsp_complete(struct bt_conn *conn, uint8_t err,
const void *data);
uint8_t profile_characteristic_read_rsp_process(bt_conn_t *conn,
int err,
bt_gatt_read_params_t *params,
const void *data,
uint16_t length);

#endif

34 changes: 34 additions & 0 deletions libraries/CurieBLE/src/internal/BLEProfileManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,40 @@ BLEServiceImp* BLEProfileManager::service(const BLEDevice &bledevice, int index)
return serviceImp;
}

BLEServiceImp* BLEProfileManager::getServiceBySubHandle(const BLEDevice &bledevice, uint16_t handle) const
{
BLEServiceImp* serviceImp = NULL;
uint16_t start_handle;
uint16_t end_handle;
#if 1
const BLEServiceLinkNodeHeader* serviceHeader = getServiceHeader(bledevice);
if (NULL == serviceHeader)
{
// Doesn't find the service
return NULL;
}
BLEServiceNodePtr node = serviceHeader->next;

while (node != NULL)
{
serviceImp = node->value;
start_handle = serviceImp->startHandle();
end_handle = serviceImp->endHandle();
if (handle >= start_handle && handle <= end_handle)
{
break;
}
node = node->next;
}

if (NULL == node)
{
serviceImp = NULL;
}
#endif
return serviceImp;
}

void BLEProfileManager::handleConnectedEvent(const bt_addr_le_t* deviceAddr)
{
int index = getUnusedIndex();
Expand Down
1 change: 1 addition & 0 deletions libraries/CurieBLE/src/internal/BLEProfileManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class BLEProfileManager{
BLEServiceImp* service(const BLEDevice &bledevice, const char * uuid) const;
BLEServiceImp* service(const BLEDevice &bledevice, int index) const;
BLEServiceImp* service(const BLEDevice &bledevice, const bt_uuid_t* uuid) const;
BLEServiceImp* getServiceBySubHandle(const BLEDevice &bledevice, uint16_t handle) const;
int serviceCount(const BLEDevice &bledevice) const;
int characteristicCount(const BLEDevice &bledevice) const;

Expand Down
Loading