nl:: Ble:: BleLayer
#include <src/ble/BleLayer.h>
此类提供了一个接口,可供单个线程通过 BleLayer 平台接口函数将数据驱动到堆栈上行,或者通过与 BLEEndPoint 相关联的 WeaveConnection 对象使数据下行。
摘要
您可以通过以下两种方式将 WeaveConnection(由 WeaveMessageLayer 定义)与 BLE 连接相关联:
首先,应用可以被动接收传入的 BLE 连接,并通过相应的平台接口函数将此接收生成的特定于平台的 BLE_CONNECTION_OBJECT 移交给 BleLayer。这会使 BleLayer 将 BLE_CONNECTION_OBJECT 封装在 BLEEndPoint 中,并通知 WeaveMessageLayer 已收到新的 BLE 连接。然后,消息层将新的 BLEEndPoint 对象封装在 WeaveConnection 中,并通过消息层的 OnConnectionReceived 回调将此对象传递给应用。
其次,应用可以主动建立传出的 BLE 连接,例如通过连接到 BLE 外围设备。然后,它通过 WeaveMessageLayer 创建一个新的 WeaveConnection,为此连接分配一个身份验证类型,并通过 WeaveConnection::ConnectBle 将其绑定到用于新的 BLE 连接的 BLE_CONNECTION_OBJECT。然后,此函数会建立 WeaveConnection 的身份验证类型成员变量指定的安全会话类型。
继承
直接已知的子类:nl::Weave::DeviceLayer::Internal::BLEManagerImpl
nl::Weave::DeviceLayer::Internal::BLEManagerImpl
nl::Weave::DeviceLayer::Internal::BLEManagerImpl
构造函数和析构函数 |
|
---|---|
BleLayer(void)
|
公共类型 |
|
---|---|
@14
|
枚举 |
BleConnectionReceivedFunct)(BLEEndPoint *newEndPoint)
|
typedefvoid(*
|
公共属性 |
|
---|---|
OnWeaveBleConnectReceived
|
BleConnectionReceivedFunct
|
mAppState
|
void *
|
mState
|
enum nl::Ble::BleLayer::@14
[只读] 当前状态
|
公共类型
14 岁
@14
BleConnectionReceivedFunct
void(* BleConnectionReceivedFunct)(BLEEndPoint *newEndPoint)
公共属性
OnWeaveBleConnectReceived
BleConnectionReceivedFunct OnWeaveBleConnectReceived
mAppState
void * mAppState
mState
enum nl::Ble::BleLayer::@14 mState
[只读] 当前状态
公共函数
BleLayer
BleLayer( void )
HandleConnectionError
void HandleConnectionError( BLE_CONNECTION_OBJECT connObj, BLE_ERROR err )
HandleIndicationConfirmation
bool HandleIndicationConfirmation( BLE_CONNECTION_OBJECT connObj, const WeaveBleUUID *svcId, const WeaveBleUUID *charId )
在标准 GATT 指示收到正面的收据确认时调用。
HandleIndicationReceived
bool HandleIndicationReceived( BLE_CONNECTION_OBJECT connObj, const WeaveBleUUID *svcId, const WeaveBleUUID *charId, PacketBuffer *pBuf )
在收到 GATT 指示时调用。
HandleReadReceived
bool HandleReadReceived( BLE_CONNECTION_OBJECT connObj, BLE_READ_REQUEST_CONTEXT requestContext, const WeaveBleUUID *svcId, const WeaveBleUUID *charId )
在收到 GATT 读取请求时调用。
当 BleLayer 通过 BleAdapter 执行的任何先前操作失败时(例如特征写入请求或订阅尝试),或者 BLE 连接关闭时,平台必须调用此函数。
在大多数情况下,这将提示 Weave 关闭关联的 WeaveConnection,并通知该平台其放弃了底层 BLE 连接。
注意:如果应用显式关闭与关联 WeaveConnection 的 BLE 连接,以使 BLE 连接关闭不会生成对 Weave 的上调用,则必须使用 err = BLE_ERROR_APP_CLOSED_CONNECTION 调用 HandleConnectionError,以防止此 WeaveConnection 及其端点对象泄漏。
HandleSubscribeComplete
bool HandleSubscribeComplete( BLE_CONNECTION_OBJECT connObj, const WeaveBleUUID *svcId, const WeaveBleUUID *charId )
在 GATT 订阅请求成功时调用。
当针对任何 Weave 服务特性请求 GATT 退订时(即取消了具有 Weave 服务特征的现有 GATT 订阅),平台必须调用此函数。
HandleSubscribeReceived
bool HandleSubscribeReceived( BLE_CONNECTION_OBJECT connObj, const WeaveBleUUID *svcId, const WeaveBleUUID *charId )
HandleUnsubscribeComplete
bool HandleUnsubscribeComplete( BLE_CONNECTION_OBJECT connObj, const WeaveBleUUID *svcId, const WeaveBleUUID *charId )
在 GATT 退订请求成功时调用该方法。
HandleUnsubscribeReceived
bool HandleUnsubscribeReceived( BLE_CONNECTION_OBJECT connObj, const WeaveBleUUID *svcId, const WeaveBleUUID *charId )
HandleWriteConfirmation
bool HandleWriteConfirmation( BLE_CONNECTION_OBJECT connObj, const WeaveBleUUID *svcId, const WeaveBleUUID *charId )
在未完成的 GATT 写入请求收到收到肯定的确认消息时调用。
HandleWriteReceived
bool HandleWriteReceived( BLE_CONNECTION_OBJECT connObj, const WeaveBleUUID *svcId, const WeaveBleUUID *charId, PacketBuffer *pBuf )
在收到 GATT 写入请求时调用。
Init
BLE_ERROR Init( BlePlatformDelegate *platformDelegate, BleApplicationDelegate *appDelegate, Weave::System::Layer *systemLayer )
NewBleEndPoint
BLE_ERROR NewBleEndPoint( BLEEndPoint **retEndPoint, BLE_CONNECTION_OBJECT connObj, BleRole role, bool autoClose )
ScheduleWork
nl::Weave::System::Error ScheduleWork( nl::Weave::System::Layer::TimerCompleteFunct aComplete, void *aAppState )
平台接口功能:
调用规范:Weave 拥有通过这些函数收到的 PacketBuffers,并释放它们或将所有权向上传递至堆栈。
除了每次调用之外,无法保证 UUID 参数的生命周期。
“true”返回值表示 Weave 堆栈已成功处理相应的消息或状态指示。“false”表示 Weave 堆栈失败或选择不处理此问题。如果设置为“false”,Weave 堆栈不会释放或获得任何 PacketBuffer 参数。此协定允许平台将 BLE 事件传递给 Weave,而无需知道 Weave 关注哪些特性。
当已针对任何 Weave 服务特性建立 GATT 订阅后,平台必须调用此函数。
如果此函数返回 true,则表示 Weave 已接受 BLE 连接,并将其封装在 WeaveConnection 对象中。如果 Weave 接受 BLE 连接,且订阅被取消或底层 BLE 连接已关闭,或者关联的 WeaveConnection 永远不会被关闭或释放,那么平台必须通知 Weave。