SimpleApp 例子解读-3 程序分析:
1.SAPI_Init()//任务初始化函数
void SAPI_Init( byte task_id )
{
uint8 startOptions; //--
sapi_TaskID = task_id; //--分配任务ID
sapi_bindInProgress = 0xffff; //--绑定标志位,不允许绑定过程
sapi_epDesc.endPoint = zb_SimpleDesc.EndPoint; //--初始化描述符
sapi_epDesc.task_id = &sapi_TaskID;
sapi_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&zb_SimpleDesc;//--简单描述符
sapi_epDesc.latencyReq = noLatencyReqs;
// Register the endpoint/interface description with the AF
afRegister( &sapi_epDesc ); //--登记相关信息
// Turn off match descriptor response by default--默认关闭匹配描述符响应
afSetMatch(sapi_epDesc.simpleDesc->EndPoint, FALSE);
// Register callback evetns from the ZDApp
ZDO_RegisterForZDOMsg( sapi_TaskID, NWK_addr_rsp );
ZDO_RegisterForZDOMsg( sapi_TaskID, Match_Desc_rsp );
#if (defined HAL_KEY) && (HAL_KEY == TRUE)
// Register for HAL events
RegisterForKeys( sapi_TaskID );
if ( HalKeyRead () == HAL_KEY_SW_1)
{
// If SW5 is pressed and held while powerup, force auto-start and nv-restore off and reset
//--如果打开设备的电源,同时按下SW5,关闭自动启动复位
startOptions = ZCD_STARTOPT_CLEAR_STATE | ZCD_STARTOPT_CLEAR_CONFIG;
zb_WriteConfiguration( ZCD_NV_STARTUP_OPTION, sizeof(uint8), &startOptions );
zb_SystemReset();
}
#endif // HAL_KEY
#ifdef LCD_SUPPORTED
Print8(HAL_LCD_LINE_2 ,20,"Simple",1);
#endif
// Set an event to start the application--设置事件,启动应用
osal_set_event(task_id, ZB_ENTRY_EVENT);
}