Telink TLSR8232 BLE SDK Developer Handbook
AN-19112700-E1
95
Ver.1.0.0
U16_LO(0x0111), U16_HI(0x0111), // bcdHID (USB HID version)
,
0x11,0x01
0x00, // bCountryCode
0x01 // Flags
};
{0, 2, sizeof(hidInformation), sizeof(hidInformation), (u8*)(&hidinformationUUID),
(u8*)(hidInformation), 0,0},
In practical
application, the key word “const” can be used to store the read-only 4-byte
hid information “0x01 0x00 0x01 0x11” into Flash. The “pAttrValue” points to the starting
address of hidInformation in F
lash, while the “attrLen” is the actual length of
hidInformation. When Master reads this Attribute, “0x01000111” will be returned to
Master correspondingly.
shows a packet example captured by BLE sniffer when Master reads this
Attribute. Master uses th
e “ATT_Read_Req” command to set the target AttHandle as
0x23 (35), corresponding to the hid information in Attribute Table of SDK.
Figure 3-31 BLE Sniffer Packet Sample When Master Reads hidInformation
For
Attribute “battery value” with Attribute Handle being 40, related code is as shown
below:
u8
my_batVal[1] = {99};
{0,1,2,1,(u8*)(&my_batCharUUID), (u8*)(my_batVal), 0},
In practical
application, the “my_batVal” indicates current battery level and it will be
updated according to ADC sampling result; then Slave will actively notify or Master will
actively read to transfer the “my_batVal” to Master. The starting address of the
“my_batVal” stored in RAM will be pointed by the “pAttrValue”.
3.4.2.5 Callback Function w
The callback function w is a write function, its prototype is:
typedef int (*att_readwrite_callback_t)(void* p);
User must follow the format above to define callback write function. The callback function
w is optional, i.e. for an Attribute, user can select whether to set the callback write
function as needed (null pointer 0 indicates not setting callback write function).
The trigger condition for callback function w is: When Slave receives any Attribute PDU
with Attribute Opcode as shown below, Slave will check whether the callback function w
is set.
1) opcode = 0x12,
Write Request,
see
Core_v5.0
.