Quantcast
Channel: Forums - Recent Threads
Viewing all articles
Browse latest Browse all 262198

cc2540 BLE, write/read from array value

$
0
0

Hi

I would like to create service value which is uint16 array

the question is how to do read write single place in array uisng abc_ReadAttrCB , abc_WriteAttrCB right

this is my example, can you please modify

/***********************************************************************************/

static uint8 abc_ReadAttrCB( uint16 connHandle, gattAttribute_t *pAttr, 

uint8 *pValue, uint8 *pLen, uint16 offset, uint8 maxLen )

{ ...

case ABC_ARRAY_UUID:
if ( offset >= sizeof(abcARRAY)) // abcARRAY is the uint16 array which pValue point at
{
return ( ATT_ERR_ATTR_NOT_LONG );
}
else
{
// determine read length
*pLen = sizeof( abcARRAY[offset]);

// copy data
osal_memcpy( pValue, pAttr->pValue + (pLen*offset), *pLen );
}
break;

...}

/***********************************************************************************/

/***********************************************************************************/

static bStatus_t abc_WriteAttrCB( uint16 connHandle, gattAttribute_t *pAttr,
uint8 *pValue, uint8 len, uint16 offset )

{...

case ABC_ARRAY_UUID:
if ( offset > ( sizeof( abcARRAY)/sizeof( abcARRAY[0]))) // abcARRAY is the uint16 array which pValue point at
{
status = ATT_ERR_ATTR_NOT_LONG;
}
else if (len != sizeof( abcARRAY[0]))
{
status = ATT_ERR_INVALID_VALUE_SIZE;
}
else// write
{
// arrange data
uint16 value = BUILD_UINT16( pValue[0], pValue[1] );

// copy data
osal_memcpy( pAttr->pValue + (len*offset), &value, len );

(*adcServiceCB)(ABC_ARRAY_SET);
}
break;

...}

/***********************************************************************************/

thanks


Viewing all articles
Browse latest Browse all 262198

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>