最近开始编写CC2540协议栈程序,主控芯片与CC2540的串口相连进行通信,目前在CC2540协议栈通过串口回调函数接收主控芯片的AT指令,解析这部分,目前已能返回OK等简单回复。但想修改CC2540的名称和连接密码的话,感觉有点不知从哪下手,问题:
1、如何修改密码和名称?
2、每次重新上电,芯片都会重新复位,密码和名称又会初始化,这又该怎么处理呢?
下面是我解析AT指令的部分核心程序
if(dms_strcmp(pBuffer,"AT+NAME",7)==0) //识别到修改名称指令
{
scanRspData[0] =0x03;
scanRspData[1] = GAP_ADTYPE_LOCAL_NAME_COMPLETE;
scanRspData[2] =0x70; //0x70,0x68为两个字节的名称
scanRspData[3] =0x68;
scanRspData[4] =0x05;
scanRspData[5] =GAP_ADTYPE_SLAVE_CONN_INTERVAL_RANGE;
scanRspData[6] =LO_UINT16( 20 );
scanRspData[7] =LO_UINT16( 20 );
scanRspData[8] =LO_UINT16( 20 );
scanRspData[9] =LO_UINT16( 20 );
scanRspData[10] =LO_UINT16( 20 );
scanRspData[11] =0x02;
scanRspData[12] =GAP_ADTYPE_POWER_LEVEL;
scanRspData[13] =0;
RENAME=1;
osal_set_event(simpleBLEPeripheral_TaskID ,SYS_EVENT_MSG); //触发事件修改名称
}
//在SimpleBLEPeripheral_ProcessEvent函数中找到下列行
if ( events & SYS_EVENT_MSG )
{
uint8 *pMsg;
if(RENAME==1) //增加修改名称的处理
{
RENAME==0;
GAPRole_SetParameter( GAPROLE_SCAN_RSP_DATA, sizeof ( scanRspData ), scanRspData );
}
if ( (pMsg = osal_msg_receive( simpleBLEPeripheral_TaskID )) != NULL )
{
simpleBLEPeripheral_ProcessOSALMsg( (osal_event_hdr_t *)pMsg );
// Release the OSAL message
VOID osal_msg_deallocate( pMsg );
}
// return unprocessed events
return (events ^ SYS_EVENT_MSG);
}
修改密码:
if(dms_strcmp(pBuffer,"AT+CODE",7)==0)
{
GAPRole_TerminateConnection(); //首先断开与主机的连接,再修改密码
uint32 passkey = 123456; //将密码修改为123456
uint8 pairMode = GAPBOND_PAIRING_MODE_INITIATE;
uint8 mitm = TRUE;
uint8 ioCap = GAPBOND_IO_CAP_DISPLAY_ONLY;
uint8 bonding = TRUE;
GAPBondMgr_SetParameter( GAPBOND_DEFAULT_PASSCODE, sizeof ( uint32 ), &passkey );//设置密码
GAPBondMgr_SetParameter( GAPBOND_PAIRING_MODE, sizeof ( uint8 ), &pairMode );
GAPBondMgr_SetParameter( GAPBOND_MITM_PROTECTION, sizeof ( uint8 ), &mitm );
GAPBondMgr_SetParameter( GAPBOND_IO_CAPABILITIES, sizeof ( uint8 ), &ioCap );
GAPBondMgr_SetParameter( GAPBOND_BONDING_ENABLED, sizeof ( uint8 ), &bonding );
GAPBondMgr_SetParameter( GAPBOND_ERASE_ALLBONDS,0, NULL );
}
这只是我目前的代码,都没法实现。。。网上也找不到相关的程序,有的只是如何操控成熟的串口蓝牙模块的步骤,而没有具体的实现串口蓝牙的程序,希望有做过的朋友指点一下。谢谢~ |