CC2640之新增一個自定義的特性值
測試環境
協議棧版本:BLE-STACK V2.1
IAR開發環境版本:IAR for Arm 7.40
硬體裝置:Amo-SmartRF v2.0 開發板(對應TI官方的SmartRF06EB 開發板)
示例測試Demo工程:simpleBLEPeripheral工程
新增自定義特徵值
我們今天一起來了解下,如何在一個現有的profile中新增一個自定義的特徵值,而且該特徵值具有讀、寫和通知許可權。下面的講解中,我們以“simpleBLEPeripheral”工程為例,來了解如何在其現有的profile中,新增一個具有讀、寫和通知功能的特徵值char6。
首先,我們先了解下“
1.在“C:\ti\simplelink\ble_cc26xx_2_01_00_44423\Projects\ble\Profiles\SimpleProfile”目錄下找到“simpleGATTprofile.h”檔案,我們先在這個檔案中定義我們要新增的新的特徵值的一些宣告:
- #define SIMPLEPROFILE_CHAR6 5 // RW uint8 - Profile Characteristic 6 value
- #define SIMPLEPROFILE_CHAR6_UUID 0xFFF6
- // Length of Characteristic 6 in bytes
- #define SIMPLEPROFILE_CHAR6_LEN 19
- // Position of simple char6 value in attribute array
-
// char6特性在屬性表中的位置,根據實際情況而定,協議棧中的demo新增之後分別是18,19
- #define SIMPLE_MEAS6_VALUE_POS 18
- #define SIMPLE_MEAS6_CCC_POS 19
2.在“C:\ti\simplelink\ble_cc26xx_2_01_00_44423\Projects\ble\Profiles\SimpleProfile\CC26xx”目錄下找到“simpleGATTprofile.c”檔案。
(1)在該檔案全域性變數宣告UUID的地方,宣告我們新新增的特徵值的UUID:
- // Characteristic 6 UUID: 0xFFF6
- CONST uint8 simpleProfilechar6UUID[ATT_BT_UUID_SIZE] =
- {
- LO_UINT16(SIMPLEPROFILE_CHAR6_UUID), HI_UINT16(SIMPLEPROFILE_CHAR6_UUID)
- };
(2)在該檔案內部變數宣告的地方,宣告一下我們要新增的新特徵值char6的相關變數:
- // Simple Profile Characteristic 6 Properties
- static uint8 simpleProfileChar6Props = GATT_PROP_READ | GATT_PROP_WRITE_NO_RSP | GATT_PROP_NOTIFY;
- // Characteristic 6 Value
- static uint8 simpleProfileChar6[SIMPLEPROFILE_CHAR6_LEN] = { 0, 0, 0, 0, 0 };
- static uint8 simpleProfileChar6Len = 0;
- // Simple Profile Characteristic 6 Configuration Each client has its own
- // instantiation of the Client Characteristic Configuration. Reads of the
- // Client Characteristic Configuration only shows the configuration for
- // that client and writes only affect the configuration of that client.
- static gattCharCfg_t *simpleProfileChar6Config;
- // Simple Profile Characteristic 6 User Description
- static uint8 simpleProfileChar6UserDesp[17] = "Characteristic 6";
(3)在該Profile的屬性表
“static gattAttribute_t simpleProfileAttrTbl[SERVAPP_NUM_ATTR_SUPPORTED] =”
中新增char6相關配置,新增的程式碼如下:
- // 17 Characteristic 6 Declaration
- {
- { ATT_BT_UUID_SIZE, characterUUID },
- GATT_PERMIT_READ,
- 0,
- &simpleProfileChar6Props
- },
- // 18 Characteristic Value 6
- {
- { ATT_BT_UUID_SIZE, simpleProfilechar6UUID },
- GATT_PERMIT_READ | GATT_PERMIT_WRITE,
- 0,
- simpleProfileChar6
- },
- // 19 Characteristic 6 configuration
- {
- { ATT_BT_UUID_SIZE, clientCharCfgUUID },
- GATT_PERMIT_READ | GATT_PERMIT_WRITE,
- 0,
- (uint8 *)&simpleProfileChar6Config
- },
- // 20 Characteristic 6 User Description
- {
- { ATT_BT_UUID_SIZE, charUserDescUUID },
- GATT_PERMIT_READ,
- 0,
- simpleProfileChar6UserDesp
- },
上面程式碼註釋上的標號,是我自己標的,也就是屬性表陣列的下標,注意是從0開始,上述註釋的下標就跟我之前標頭檔案中定義的SIMPLE_MEAS6_VALUE_POS和SIMPLE_MEAS6_CCC_POS的值相對應。
因為增加了這4個數組成員,所以屬性表“SERVAPP_NUM_ATTR_SUPPORTED”的值需要由原來的17修改為21,如下:
- /*********************************************************************
- * CONSTANTS
- */
- #define SERVAPP_NUM_ATTR_SUPPORTED 21//17
(4)新新增的特徵值char6具有通知功能,所以,我們需要在“SimpleProfile_AddService”函式中進行相應的初始化配置操作:
- // Allocate Client Characteristic Configuration table
- simpleProfileChar6Config = (gattCharCfg_t *)ICall_malloc( sizeof(gattCharCfg_t) *linkDBNumConns );
- if ( simpleProfileChar6Config == NULL )
- {
- // Free already allocated data
- ICall_free( simpleProfileChar6Config );
- return ( bleMemAllocError );
- }
- ......
- GATTServApp_InitCharCfg( INVALID_CONNHANDLE, simpleProfileChar6Config );
(5)“SimpleProfile_SetParameter”方法中參考其他特徵值的配置,新增如下程式碼:
- case SIMPLEPROFILE_CHAR6:
- if ( len <= SIMPLEPROFILE_CHAR6_LEN )
- {
- VOID memcpy( simpleProfileChar6, value, len );
- simpleProfileChar6Len = len;
- // See if Notification has been enabled
- GATTServApp_ProcessCharCfg( simpleProfileChar6Config, simpleProfileChar6, FALSE,
- simpleProfileAttrTbl, GATT_NUM_ATTRS( simpleProfileAttrTbl ),
- INVALID_TASK_ID, simpleProfile_ReadAttrCB );
- }
- else
- {
- ret = bleInvalidRange;
- }
- break;
(6)“SimpleProfile_GetParameter”方法中參考其他特徵值的配置,新增新特徵值的相關配置:
- case SIMPLEPROFILE_CHAR6:
- VOID memcpy( value, simpleProfileChar6, simpleProfileChar6Len );
- break;
(7)“simpleProfile_ReadAttrCB”函式是呼叫讀之後的回撥函式,在其中新增新特徵值的相應處理:
- case SIMPLEPROFILE_CHAR6_UUID:
- *pLen = SIMPLEPROFILE_CHAR6_LEN;
- VOID memcpy( pValue, pAttr->pValue, SIMPLEPROFILE_CHAR6_LEN );
- break;
(8)“simpleProfile_WriteAttrCB”函式是呼叫寫操作之後的回撥函式,在其中新增新特徵值的相應處理:
- case SIMPLEPROFILE_CHAR6_UUID:
- if ( offset == 0 )
- {
- if ( len > SIMPLEPROFILE_CHAR6_LEN )
- {
- status = ATT_ERR_INVALID_VALUE_SIZE;
- }
- }
- else
- {
- status = ATT_ERR_ATTR_NOT_LONG;
- }
- //Write the value
- if ( status == SUCCESS )
- {
- VOID memcpy( pAttr->pValue, pValue, SIMPLEPROFILE_CHAR6_LEN );
- //VOID memcpy( pAttr->pValue, pValue, len );
- //simpleProfileChar6Len = len;
- notifyApp = SIMPLEPROFILE_CHAR6;
- //tx_printf("pValue:%s",pAttr->pValue);
- }
- break;
(9)我們在該檔案中封裝一個通過通知功能傳送資料的介面函式,原始碼如下:
- /*********************************************************************
- * @fn SimpleProfile_Notification
- *
- * @brief Send a notification containing a ir value
- *
- * @param connHandle - connection handle
- * @param pNoti - pointer to notification structure
- *
- * @return Success or Failure
- */
- bStatus_t SimpleProfile_Notification( uint16 connHandle, attHandleValueNoti_t *pNoti )
- {
- uint16 value = GATTServApp_ReadCharCfg( connHandle, simpleProfileChar6Config );
- // If notifications is enabled
- if ( value & GATT_CLIENT_CFG_NOTIFY )
- {
- // Set the handle
- pNoti->handle = simpleProfileAttrTbl[SIMPLE_MEAS6_VALUE_POS].handle;
- // Send the notification
- return GATT_Notification( connHandle, pNoti, FALSE );
- }
- return bleIncorrectMode;
- }
開啟“C:\ti\simplelink\ble_cc26xx_2_01_00_44423\Projects\ble\Profiles\SimpleProfile”目錄下的“simpleGATTprofile.h”檔案,在其中新增該通知功能介面的宣告,便於外部呼叫:
- /*********************************************************************
- * @fn SimpleProfile_Notification
- *
- * @brief Send a notification containing a ir value
- *
- * @param connHandle - connection handle
- * @param pNoti - pointer to notification structure
- *
- * @return Success or Failure
- */
- extern bStatus_t SimpleProfile_Notification( uint16 connHandle, attHandleValueNoti_t *pNoti );
3.經過上面的配置,我們就在Profile中添加了自定義的特徵值char6,下面我們在應用檔案中新增測試程式,進行相應測試。
(1)定義兩個內部變數,通知功能使用的變數以及連線控制代碼的變數:
-
相關推薦
CC2640之新增一個自定義的特性值
測試環境 協議棧版本:BLE-STACK V2.1 IAR開發環境版本:IAR for Arm 7.40 硬體裝置:Amo-SmartRF v2.0 開發板(對應TI官方的SmartRF06EB 開發板) 示例測試Demo工程:simpleBLEPeriphera
C# 直接建立一個DataTable,併為之新增資料(自定義DataTable)
DataTable dt=new DataTable("cart"); DataColumn dc1=new DataColumn("prizename",Type.GetType("System.String")); DataColumn dc2=new Da
Pixhawk---通過串列埠方式新增一個自定義感測器(超聲波為例)
Pixhawk—新增一個自定義感測器—超聲波(串列埠方式) 1 說明 首先超聲波模組是通過串列埠方式傳送(Tx)出資料,使用的模組資料傳送週期為100ms,資料格式為: R0034 R0122 R0122 R0046 R0127 R0044 R00
C#之自定義特性
創建 tip comm 字段 運算符 包含 自動 名稱 程序 在前面介紹的代碼中有使用特性,這些特性都是Microsoft定義好的,作為.NET Framework類庫的一部分,許多特性都得到了C#編譯器的支持。 .NET Frmework也允許定義自己的特性。自
Android下新增新的自定義鍵值和按鍵處理流程
[cpp] view plain copy print? <span style="font-family:FangSong_GB2312;font-size:18px;">/* * Copyright (C) 2010 The Android Open So
Openstack元件部署 — 將一個自定義 Service 新增到 Keystone
目錄 Keystone 認證流程 User 使用憑證(username/password) 到 keystone 驗證並獲得一個臨時的 Token 和 Generic catalog(全域性目錄),臨時的 Token 會儲存在 keystone-
.NET(C#):獲取方法返回值的自定義特性(Attribute)
.NET中特性的索取就是圍繞著ICustomAttributeProvider介面(System.Reflection名稱空間內),而MethodInfo類的ReturnTypeCustomAttributes屬性直接返回方法返回值的ICustomAttributeProvider介面物件。同時Method
Python+Selenium中級篇之8-Python自定義封裝一個簡單的Log類
本文介紹如何寫一個Python日誌類,用來輸出不同級別的日誌資訊到本地資料夾下的日誌檔案裡。為什麼需要日誌輸出呢,我們需要記錄我們測試指令碼到底做了什麼事情,最好的辦法是寫事件監聽。這個
C++筆記之為什麼一個類定義了解構函式就幾乎肯定要定義拷貝建構函式和拷貝賦值運算子
這個問題本來很簡單,但是時間久了就容易忘,所以做個筆記用來提示下自己 先來看看這樣一個類: class HasPtr { public: HasPtr(const string& s = string()) :ps(new string(s)), i(0) {
在一個ros包下怎麽使用另外一個自定義ros包裏的message
com doc pack .cn .html docs ssa ace hit 假設自定義消息包my_message_package https://answers.ros.org/question/206257/catkin-use-ros-message-from-an
反射,自定義特性,對象復制
str pan 特性 復制 des sage tel write getprop [AttributeUsage(AttributeTargets.All)] public class VersionAttribute : Attribute {
創建一個自定義比較器
rac void ger 接口 table string pre ride com 雙列集合: -------------| Map 如果是實現了Map接口的集合類,具備的特點: 存儲的數據都是以鍵值對的形式存在的,鍵不可重復,值可以重復。 ---------------
Vue之徹底理解自定義組件的v-model
自動 value tro 需要 this 變量 mode type 自定義 最近在學習vue,今天看到自定義事件的表單輸入組件,糾結了一會會然後恍然大悟...官方教程寫得不是很詳細,所以我決定總結一下。 v-model語法糖 v-model實現了表單輸入的雙向綁定,我們
python之路_自定義forms組件
char deepcopy clean copy 所有 ges div object 失敗 import re import copy class ValidateError(Exception): def __init__(self,detail):
自定義特性與應用
TP stat target 一個 計算 如果 得到 for https 自定義特性允許把自定義元數據與程序元素關聯起來。在.NET Framework框架中,微軟定義了許多特性提供給開發人員使用,如StructLayout特性中的信息在內存中布置結構。這些已有的特性得
NPOI+反射+自定義特性實現上傳excel轉List及驗證
type set custom pre script private property xssf don 1.自定義特性 [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited
關於jQuery獲取html標簽自定義屬性值或data值
自定義屬性 標簽 定義 .data 獲取 div val data 屬性 //獲取屬性值<div id="id1" value="優秀" ></div>jQuery取值:$("#id1").attr("value"); //獲取自定義屬性值&l
Flutter:教你用CustomPaint畫一個自定義的CircleProgressBar
注意:這其實是一篇CustomPaint的使用教程!! 原始碼地址:github.com/yumi0629/Fl… 在Flutter中,CustomPaint就像是Android中的Paint一樣,可以用它繪製出各種各樣的自定義圖形。確實,Paint的使用比較複雜,我覺得直接講API的話也太無聊了
Xamarin自定義佈局系列——ListView的一個自定義實現ItemsControl(橫向列表)
原文: Xamarin自定義佈局系列——ListView的一個自定義實現ItemsControl(橫向列表) 在以前寫UWP程式的時候,瞭解到在ListView或者ListBox這類的列表空間中,有一個叫做ItemsPannel的屬性,它是所有列表中子元素實際的容器,如果要讓列表進行橫向排列,只需要在Xam
如何安裝和配置打印服務器之六:自定義客戶端電腦使用網絡打印機的默認設置
oss strong mode 客戶端 pre 51cto col str 裝配 如何安裝和配置打印服務器之六:自定義客戶端電腦使用網絡打印機的默認設置 ?Lander Zhang 專註外企按需IT基礎架構運維服務,IT Helpdesk 實戰培訓踐行者http://blo