Other Parts Discussed in Thread: BLE-STACK, , CC2640
Tool/software: Code Composer Studio
I have created one BLE service to write the data to microcontroller using service generator. following is the code for callback :
static void user_Led_ServiceValueChangeCB(uint8_t paramID)
{
// See Led_Service.h to compare paramID with characteristic value attribute.
// Called in Stack Task context, so can't do processing here.
// Send message to application message queue about received data.
uint16_t readLen=0; // How much to read via service API
switch (paramID)
{
case LED_SERVICE_LED_CONTROL:
readLen = LED_SERVICE_LED_CONTROL_LEN;
break;
}
app_msg_t *pMsg = ICall_malloc( sizeof(app_msg_t) + sizeof(server_char_write_t) + readLen );
// Allocate memory for the message.
// Note: The message doesn't have to contain the data itself, as that's stored in
// a variable in the service. However, to prevent data loss if a new value is received
// before GetParameter is called, we call GetParameter now.
server_char_write_t *pWrite = ICall_malloc(sizeof(server_char_write_t) + readLen);
if (pWrite != NULL)
{
//pMsg->type = appMsgType;
// server_char_write_t *pWrite = (server_char_write_t *)pMsg->pdu;
pWrite->svcUUID = LED_SERVICE_SERV_UUID;
pWrite->dataLen = readLen;
pWrite->paramID = paramID;
// memcpy(pWrite->data, pValue, readLen);
// Get the data from the service API.
// Note: Fixed length is used here, but changing the GetParameter signature is not
// a problem, in case variable length is needed.
// Note: It could be just as well to send dataLen and a pointer to the received data directly to this callback, avoiding GetParameter alltogether.
Led_Service_GetParameter( paramID, pWrite->data );
// Enqueue the message using pointer to queue node element.
Queue_enqueue(hServiceMsgQ, &pWrite->_elem);
// Let application know there's a message
Event_post(syncEvent, PRZ_APP_MSG_EVT);
}
}
void user_Led_Service_ValueChangeDispatchHandler(server_char_write_t *pWrite)
{
//*a=pWrite->data;
switch (pWrite->paramID)
{
case LED_SERVICE_LED_CONTROL:
// Do something useful with pWrite->data here
// -------------------------
GPIO_write(Board_GPIO_LED1, Board_GPIO_LED_ON);
// Do something useful with pWrite->data here
// -------------------------
if (pWrite->data == "00")
{
// PIN_setOutputValue(ledPinHandle, Board_RLED, 0);
GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_OFF);
}
else if (pWrite->data == "01" )
{
GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_ON);
// PIN_setOutputValue(ledPinHandle, Board_RLED, 1);
}
break;
default:
return;
}
}
following is the code for writeattributecallback defined in Led_Service.c
static bStatus_t Led_Service_WriteAttrCB( uint16 connHandle, gattAttribute_t *pAttr,
uint8 *pValue, uint16 len, uint16 offset,
uint8 method )
{
bStatus_t status = SUCCESS;
uint8_t paramID = 0xFF;
// See if request is regarding a Client Characterisic Configuration
if ( ! memcmp(pAttr->type.uuid, clientCharCfgUUID, pAttr->type.len) )
{
// Allow only notifications.
status = GATTServApp_ProcessCCCWriteReq( connHandle, pAttr, pValue, len,
offset, GATT_CLIENT_CFG_NOTIFY);
}
// See if request is regarding the Led_Control Characteristic Value
else if ( ! memcmp(pAttr->type.uuid, Led_Service_Led_ControlUUID, pAttr->type.len) )
{
if ( offset + len > LED_SERVICE_LED_CONTROL_LEN )
{
status = ATT_ERR_INVALID_OFFSET;
}
else
{
// Copy pValue into the variable we point to from the attribute table.
memcpy(pAttr->pValue + offset, pValue, len);
// Only notify application if entire expected value is written
if ( offset + len == LED_SERVICE_LED_CONTROL_LEN)
paramID = LED_SERVICE_LED_CONTROL;
}
}
else
{
// If we get here, that means you've forgotten to add an if clause for a
// characteristic value attribute in the attribute table that has WRITE permissions.
status = ATT_ERR_ATTR_NOT_FOUND;
}
// Let the application know something changed (if it did) by using the
// callback it registered earlier (if it did).
if (paramID != 0xFF)
if ( pAppCBs && pAppCBs->pfnChangeCb )
pAppCBs->pfnChangeCb( paramID ); // Call app function from stack task context.
return status;
}
no value is received in pWrite->data what can be the error in this.
Please help me with this.
Urgently Required.
Cheers,
Smriti