The gatt_db.h file don't make sense in central my project for KW41Z. Because the project as BLE Central don't need to build gatt db. Only use discovery service function to get handle of characteristic from peripheral.
I can not provide publicly to you my peripheral with 255-byte characteristic. But I make sure other central work with this peripheral. even my central on QN908X works totally.
Here is my code for Gatt operation: (implemented on both KW41Z and QN908X)
static void BleApp_GattClientCallback(deviceId_t serverDeviceId,gattProcedureType_t procedureType, gattProcedureResult_t procedureResult, bleResult_t error ) {
switch(procedureType) {
case gGattProcReadCharacteristicValue_c:
if (gGattProcSuccess_c == procedureResult) {
if(service_data[1].char_data[1].char_handle == myCharacteristic.value.handle) /* read only with len255 */
{
PRINTF("[rsp] Read long value len:%d\n\r", myCharacteristic.value.valueLength);
}
} /* Handle error */
else {
PRINTF("ERR_Read: %x ",error);
if(gBleFeatureNotSupported_c == error) {
PRINTF("The feature is not supported yet! \n\r");
}
}
break;
case gGattProcWriteCharacteristicValue_c:
if (gGattProcSuccess_c == procedureResult) {
/* wite property with len255 */
if(service_data[1].char_data[3].char_handle == myCharacteristic.value.handle) {
PRINTF("GATT Write response operation Success!\n\r");
}
} else {
PRINTF("ERR_Write: %x ",error);
if(gBleFeatureNotSupported_c == error) {
PRINTF("The feature is not supported yet! \n\r");
}
else if(gBleInvalidParameter_c == error) {
PRINTF("Invalid Params! \n\r");
}
}
break;
}
}
/* Function for read request operation. */
void CharReadLongRequest(deviceId_t peerDeviceId, uint8_t SerPosition, uint8_t CharPosition, uint16_t ValueLength)
{
myCharacteristic.value.handle = service_data[SerPosition].char_data[CharPosition].char_handle;
myCharacteristic.value.paValue = rdata;
bleResult_t result = GattClient_ReadCharacteristicValue(peerDeviceId,&myCharacteristic,ValueLength);
if (gBleSuccess_c != result)
{
/* Handle error */
PRINTF("ERR: GattClient_ReadCharacteristicValue\n\r");
}
}
/* Function for write request operation. */
void CharWriteLongRequest(deviceId_t peerDeviceId, uint8_t SerPosition, uint8_t CharPosition, uint8_t ValueLength) {
bleResult_t result;
myCharacteristic.value.handle = service_data[SerPosition].char_data[CharPosition].char_handle;
if(service_data[1].char_data[3].char_handle == myCharacteristic.value.handle)
{
uint8_t write_long_value[255] ;
for(uint8_t i =0;i<255;i++) {
write_long_value[i] = 0x00;
}
result = GattClient_WriteCharacteristicValue(peerDeviceId, &myCharacteristic, ValueLength, write_long_value, FALSE, FALSE, /* doReliableLongCharWrites on */ TRUE, NULL);
}
if (gBleSuccess_c != result) {
PRINTF("ERR: GattClient_WriteCharacteristicValue\n\r");
}
}
/* Run test gatt request. */
uint8_t FunctionTest_Execute(int tcindex) {
PRINTF("** Execute Test function #%d ", tcindex);
switch(tcindex) {
case 1:
PRINTF("**\n\r");
PRINTF("->Read long attributes 255 byte\n\r");
CharReadLongRequest(mPeerDeviceId, 1, 1, 255);
break;
case 2:
PRINTF("**\n\r");
PRINTF("->Write long attributes 255 byte\n\r");
CharWriteLongRequest(mPeerDeviceId, 1, 3, 255);
break;
default:
return 1;
}
### Output log on KW41Z ###
--Service Discovery Done & Begin Run Gatt Test function! ** Execute Test function #1 ** ->Read long attributes 255 byte ERR_Read: 4 The feature is not supported yet! ** Execute Test function #2 ** ->Write long attributes 255 byte ERR_Write: 4 The feature is not supported yet!
### Output log on QN908X ###
--Service Discovery Done & Begin Run Gatt Testcase!
** Execute Test Case #1 **
->Read long attributes 255 byte
<-longByte GATT_Read operation value len:255
<-longByte GATT_Read operation success
** Execute Test Case #2 **
->Write long attributes 255 byte
<-longByte GATT_Write operation Success!
I use all same APIs from SDK 2.2.1 on both, But result is different between KW41Z and QN908X. KW41Z may not support these functions.
Please help me review my code. I can provide confidentially my project by email.
Could you confirm the functionality of ble stack on KW41Z.
Regards,
VietHung