我最近使用了TIcc2540开发板的一个串口透传的例程,例程中提供了串口的AT指令,主机连接从机后,可以进行透传,但是AT指令中的想char1写数据却始终无法实现,麻烦各位大神指点。我想利用写入的特征值,控制LED灯。出错的原因我怀疑是特征值没有写入成功,主机程序向char1写数据部分如下:
//AT+WRITE0xXX
if(length>=12 && str_cmp(pBuffer+3,"WRITE",5)==0){
//uint8 val=0;
simpleBLECharVal=str2hex(pBuffer+10);
if ( simpleBLEState == BLE_STATE_CONNECTED &&
simpleBLECharHdl != 0 &&
simpleBLEProcedureInProgress == FALSE )
{
uint8 status;
// Do a write
attWriteReq_t req;
req.handle = simpleBLECharHdl;
req.len = 1;
req.value[0] = simpleBLECharVal;
req.sig = 0;
req.cmd = 0;
status = GATT_WriteCharValue( simpleBLEConnHandle, &req, simpleBLETaskId );
if ( status == SUCCESS )
{
simpleBLEProcedureInProgress = TRUE;
}
} return ;
另外,我用串口助手向从机char1写数据时例程文档中写道,应该是主机的串口助手界面显示写入的值,而我的是从机串口界面显示对应的ASC值。请大神指点。
从机的回调函数simpleProfilChangCB()如下:
static void simpleProfileChangeCB( uint8 paramID )
{
uint8 newValue;
uint8 newValueBuf[20]={0};
switch( paramID )
{
case SIMPLEPROFILE_CHAR1:
//SimpleProfile_GetParameter( SIMPLEPROFILE_CHAR1, &newValue );
SimpleProfile_GetParameter( SIMPLEPROFILE_CHAR1, newValueBuf ); #if (defined HAL_LCD) && (HAL_LCD == TRUE)
//HalLcdWriteStringValue( "Char 1:", (uint16)(newValue), 10, HAL_LCD_LINE_3 );
HalLcdWriteString((char*)newValueBuf, HAL_LCD_LINE_4 );
sbpSerialAppWrite (newValueBuf, 20);
// 添加对char1的判断,点亮LED灯
if( osal_memcmp( newValueBuf, 0x01 , SIMPLEPROFILE_CHAR1_LEN) )
{
// HalLedSet(HAL_LED_1,HAL_LED_MODE_ON);
// HalLedSet(HAL_LED_2,HAL_LED_MODE_ON);
HalLedSet(HAL_LED_3,HAL_LED_MODE_ON);
// extern void send_dat();
// HalUARTWrite( 0, newValueBuf ,7);
osal_memset( newValueBuf, 0 ,7);
}
if( osal_memcmp( newValueBuf, 0x02 , SIMPLEPROFILE_CHAR1_LEN) )
{
// HalLedSet(HAL_LED_1,HAL_LED_MODE_OFF);
// HalLedSet(HAL_LED_2,HAL_LED_MODE_OFF);
HalLedSet(HAL_LED_3,HAL_LED_MODE_OFF);
// HalUARTWrite( 0, buf ,7);
osal_memset( newValueBuf, 0 ,7);
} #endif // (defined HAL_LCD) && (HAL_LCD == TRUE)
break;
Yan:
Yang Yu12,
osal_memcmp( newValueBuf, 0x01 , SIMPLEPROFILE_CHAR1_LEN)
别的不说,这个0x01是什么意思?osal_memcmp()的第二个参数应该是地址,你的地址是0x01?