mirror of
https://github.com/meshtastic/firmware.git
synced 2025-04-27 18:31:37 +00:00
Nimble WIP - make notify work
This commit is contained in:
parent
66b147fb31
commit
78ff9a8116
@ -4,8 +4,7 @@ You probably don't care about this section - skip to the next one.
|
||||
|
||||
Nimble tasks:
|
||||
|
||||
- make notify work
|
||||
- test with app
|
||||
- ble bonding is not being kept?
|
||||
- restart advertising after client disconnects (confirm this works if client goes out of range)
|
||||
- make sleep work
|
||||
- check BLE handle stability
|
||||
|
@ -332,15 +332,21 @@ BLEServer *serve = initBLE(, , getDeviceName(), HW_VENDOR, optstr(APP_VERSION),
|
||||
#include "services/gap/ble_svc_gap.h"
|
||||
#include "services/gatt/ble_svc_gatt.h"
|
||||
|
||||
static bool pinShowing;
|
||||
|
||||
static void startCb(uint32_t pin)
|
||||
{
|
||||
pinShowing = true;
|
||||
powerFSM.trigger(EVENT_BLUETOOTH_PAIR);
|
||||
screen.startBluetoothPinScreen(pin);
|
||||
};
|
||||
|
||||
static void stopCb()
|
||||
{
|
||||
screen.stopBluetoothPinScreen();
|
||||
if (pinShowing) {
|
||||
pinShowing = false;
|
||||
screen.stopBluetoothPinScreen();
|
||||
}
|
||||
};
|
||||
|
||||
static uint8_t own_addr_type;
|
||||
@ -349,6 +355,12 @@ static uint8_t own_addr_type;
|
||||
// proccess at once
|
||||
static uint8_t trBytes[max(FromRadio_size, ToRadio_size)];
|
||||
|
||||
static uint16_t fromNumValHandle;
|
||||
static uint32_t fromNum;
|
||||
|
||||
/// We only allow one BLE connection at a time
|
||||
static int16_t curConnectionHandle = -1;
|
||||
|
||||
class BluetoothPhoneAPI : public PhoneAPI
|
||||
{
|
||||
/**
|
||||
@ -358,8 +370,14 @@ class BluetoothPhoneAPI : public PhoneAPI
|
||||
{
|
||||
PhoneAPI::onNowHasData(fromRadioNum);
|
||||
|
||||
DEBUG_MSG("BLE notify fromNum\n");
|
||||
// fromNum.notify32(fromRadioNum);
|
||||
fromNum = fromRadioNum;
|
||||
if (curConnectionHandle >= 0 && fromNumValHandle) {
|
||||
DEBUG_MSG("BLE notify fromNum\n");
|
||||
auto res = ble_gattc_notify(curConnectionHandle, fromNumValHandle);
|
||||
assert(res == 0);
|
||||
} else {
|
||||
DEBUG_MSG("No BLE notify\n");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -396,8 +414,6 @@ int fromradio_callback(uint16_t conn_handle, uint16_t attr_handle, struct ble_ga
|
||||
|
||||
int fromnum_callback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt, void *arg)
|
||||
{
|
||||
static uint32_t fromNum = 0;
|
||||
|
||||
DEBUG_MSG("BLE fromNum called\n");
|
||||
auto rc = os_mbuf_append(ctxt->om, &fromNum,
|
||||
sizeof(fromNum)); // FIXME - once we report real numbers we will need to consider endianness
|
||||
@ -491,6 +507,7 @@ static int bleprph_gap_event(struct ble_gap_event *event, void *arg)
|
||||
rc = ble_gap_conn_find(event->connect.conn_handle, &desc);
|
||||
assert(rc == 0);
|
||||
print_conn_desc(&desc);
|
||||
curConnectionHandle = event->connect.conn_handle;
|
||||
}
|
||||
DEBUG_MSG("\n");
|
||||
|
||||
@ -505,6 +522,8 @@ static int bleprph_gap_event(struct ble_gap_event *event, void *arg)
|
||||
print_conn_desc(&event->disconnect.conn);
|
||||
DEBUG_MSG("\n");
|
||||
|
||||
curConnectionHandle = -1;
|
||||
|
||||
/* Connection terminated; resume advertising. */
|
||||
advertise();
|
||||
return 0;
|
||||
@ -710,6 +729,11 @@ void gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg)
|
||||
DEBUG_MSG("registering characteristic %s with "
|
||||
"def_handle=%d val_handle=%d\n",
|
||||
ble_uuid_to_str(ctxt->chr.chr_def->uuid, buf), ctxt->chr.def_handle, ctxt->chr.val_handle);
|
||||
|
||||
if (ctxt->chr.chr_def->uuid == &fromnum_uuid.u) {
|
||||
fromNumValHandle = ctxt->chr.val_handle;
|
||||
DEBUG_MSG("FromNum handle %d\n", fromNumValHandle);
|
||||
}
|
||||
break;
|
||||
|
||||
case BLE_GATT_REGISTER_OP_DSC:
|
||||
|
@ -19,7 +19,7 @@ static const ble_uuid128_t toradio_uuid =
|
||||
static const ble_uuid128_t fromradio_uuid =
|
||||
BLE_UUID128_INIT(0xd5, 0x54, 0xe4, 0xc5, 0x25, 0xc5, 0x31, 0xa5, 0x55, 0x4a, 0x02, 0xee, 0xc2, 0xbc, 0xa2, 0x8b);
|
||||
|
||||
static const ble_uuid128_t fromnum_uuid =
|
||||
const ble_uuid128_t fromnum_uuid =
|
||||
BLE_UUID128_INIT(0x53, 0x44, 0xe3, 0x47, 0x75, 0xaa, 0x70, 0xa6, 0x66, 0x4f, 0x00, 0xa8, 0x8c, 0xa1, 0x9d, 0xed);
|
||||
|
||||
const struct ble_gatt_svc_def gatt_svr_svcs[] = {
|
||||
|
@ -18,7 +18,7 @@ int fromnum_callback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt
|
||||
|
||||
extern const struct ble_gatt_svc_def gatt_svr_svcs[];
|
||||
|
||||
extern const ble_uuid128_t mesh_service_uuid;
|
||||
extern const ble_uuid128_t mesh_service_uuid, fromnum_uuid;
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user