Extracting the Length of Characteristic Value in Long Write – KBA223087

Version 3

    Version: *A

     

    Translation - Japanese: ロングライトの特性値の長さの抽出– KBA223087 - Community Translated (JA)

     

    Question:

    How do I extract the length of the Characteristic value written to the Server from a Client when the Characteristic value is longer than the MTU size?

     

    Answer:

    When the length of the Characteristic value written is greater than the MTU size, at the Server end, the CYBLE_EVT_GATTS_EXEC_WRITE_REQ event is generated. The event parameter is pointer to the CYBLE_GATTS_EXEC_WRITE_REQ_T structure.

    In the CYBLE_GATTS_EXEC_WRITE_REQ_T structure, baseAddr.handleValuePair.value.len can be added for the total of the prepwritecount value to get the total length of the Characteristic value written. A sample code can be found below.

     

    Declare the following variables:

    CYBLE_GATTS_EXEC_WRITE_REQ_T *longwrite;      

    CYBLE_GATT_HANDLE_VALUE_OFFSET_PARAM_T *dataaddress;

     

    In Stackeventhandler, add the following case statement:

    case CYBLE_EVT_GATTS_EXEC_WRITE_REQ:

    {

       uint8 length=0;

       uint8 writecount;

       //getting the eventparamter

       longwrite= (CYBLE_GATTS_EXEC_WRITE_REQ_T *)eventParam;

               

       dataaddress= longwrite->baseAddr;

       //getting the total prepwritecount value

       writecount=longwrite->prepWriteReqCount;

       //adding the baseaddress.handevaluepair.value.len for total prepwritecount value

       for(int8 i=0;i<writecount;i++)

       length+= dataaddress[i].handleValuePair.value.len;

               

        printf("\nLength written is %d \n",length);

    }

        break;