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 連線關閉時不會產生對 Weave 的呼叫,則必須使用 err = BLE_ERROR_APP_CLOSED_CONNECTION 呼叫 HandleConnectionError,以免這個 WeaveConnection 及其終點物件外洩。
HandleSubscribeComplete
bool HandleSubscribeComplete( BLE_CONNECTION_OBJECT connObj, const WeaveBleUUID *svcId, const WeaveBleUUID *charId )
GATT 訂閱要求成功時呼叫。
每當有人要求取消訂閱 GATT 的 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 引數的擁有權。這份合約讓平台不必知道 Weave 重視哪些特徵,也能將 BLE 事件傳送給 Weave。
對任何 Weave 服務特徵碼建立 GATT 訂閱時,平台必須呼叫這個函式。
如果這個函式傳回 true,系統就會接受 BLE 連線,並將其包裝在 WeaveConnection 物件中。如果 Weave 接受 BLE 連線,在取消訂閱或基礎 BLE 連線關閉時,平台「必須」通知 Weave,或與相關聯的 WeaveConnection 一律不會關閉或釋出。