AF层学习总结

来源:互联网 发布:js switch 编辑:程序博客网 时间:2024/04/29 05:43

AF层学习总结

AF层学习总结

2010-03-16 19:00

/*
* afInit - Initialize the AF.
*/
extern void afInit( void );
作用:初始化AF层,在ZMain中mian()函数中调用

/*
* afRegisterExtended - Register an Application's EndPoint description
*           with a callback function for descriptors.
*
*/
extern epList_t *afRegisterExtended( endPointDesc_t *epDesc, pDescCB descFn );
作用:在afRegister()中调用,注册一个端点描述符,可以选择是否需要为端点设定回调函数,
默认为空,即不设定

/*
* afRegister - Register an Application's EndPoint description.
*
*/
extern afStatus_t afRegister( endPointDesc_t *epDesc );
作用:任务中注册一个端点描述符,示例如下:
GenericApp_epDesc.endPoint = GENERICAPP_ENDPOINT;
GenericApp_epDesc.task_id = &GenericApp_TaskID;
GenericApp_epDesc.simpleDesc
            = (SimpleDescriptionFormat_t *)&GenericApp_SimpleDesc;
GenericApp_epDesc.latencyReq = noLatencyReqs;

// Register the endpoint description with the AF
afRegister( &GenericApp_epDesc );

/*
* afDataConfirm - APS will call this function after a data message
*                 has been sent.
*/
extern void afDataConfirm( uint8 endPoint, uint8 transID, ZStatus_t status );
作用:应用层AF_DataRequest()函数中先调用APSDE_DataReq()向下层发送,再调用这个函数,
向与端点相关联的应用层任务中注册一个AF_DATA_CONFIRM_CMD事件,表示确认数据已经发送出去


/*
* afIncomingData - APS will call this function when an incoming
*                   message is received.
*/
extern void afIncomingData( aps_FrameFormat_t *aff, zAddrType_t *SrcAddress,
                       uint8 LinkQuality, byte SecurityUse, uint32 timestamp );
作用:在APS层接收到数据后,会调用这个函数,函数内部调用afBuildMSGIncoming(),
如果项目中定义了MT_AF_CB_FUNC,则向MT注册SPI_CB_AF_DATA_IND事件,否则向应用层注册
AF_INCOMING_MSG_CMD事件,两者只取其一


afStatus_t AF_DataRequest( afAddrType_t *dstAddr, endPointDesc_t *srcEP,
                             uint16 cID, uint16 len, uint8 *buf, uint8 *transID,
                             uint8 options, uint8 radius );
作用:应用层利用此函数,向目标网络地址的设备发送buf中的数据


/*********************************************************************
* Direct Access Functions - ZigBee Device Object
*/

/*
* afFindEndPointDesc - Find the endpoint description entry from the
*                      endpoint number.
*/
extern endPointDesc_t *afFindEndPointDesc( byte endPoint );
作用:该函数可以返回与某个端点相关的端点描述符,示例如下:
endPointDesc_t * epDesc = afFindEndPointDesc( endPoint );

/*
* afFindSimpleDesc - Find the Simple Descriptor from the endpoint number.
*      If return value is not zero, the descriptor memory must be freed.
*/
extern byte afFindSimpleDesc( SimpleDescriptionFormat_t **ppDesc, byte EP );
作用:该函数可以获取与端点EP相关的简单描述符,保存到ppDesc中,示例如下
SimpleDescriptionFormat_t *sDesc = NULL;
byte free = false;
free = afFindSimpleDesc( &sDesc, endPoint );


/*
* afDataReqMTU - Get the Data Request MTU(Max Transport Unit)
*/
extern uint8 afDataReqMTU( afDataReqMTU_t* fields );
作用:该函数可以查询应用层可以发送的最大数据单元,示例如下:
if (len > afDataReqMTU( &mtu ) )
{
   //不发送数据
}
else
{
    //否则发送数据
    stat = APSDE_DataReq( &req );
}


/*
* afGetMatch - Get the action for the Match Descriptor Response
*             TRUE allow match descriptor response
*/
extern uint8 afGetMatch( uint8 ep );
作用:获取端点的行为是否允许Response,返回true则允许,否则不允许


/*
* afSetMatch - Set the action for the Match Descriptor Response
*             TRUE allow match descriptor response
*/
extern uint8 afSetMatch( uint8 ep, uint8 action );
作用:设定AF层端点的行为是否允许Response,action为true则允许,否则不允许
示例如下:
afSetMatch(sapi_epDesc.simpleDesc->EndPoint, FALSE);

/*
* afNumEndPoints - returns the number of endpoints defined.
*/
extern byte afNumEndPoints( void );
作用:获取AF层注册的端点的个数,示例如下:
uint8 cnt = afNumEndPoints() - 1; // -1 for ZDO endpoint descriptor


/*
* afCnvtSP_uint16 - Converts uint16 to semi-precision structure format.
*/
extern uint16 afCnvtSP_uint16( afSemiPrecision_t sp );
作用:微精度(afSemiPrecision_t)格式数据转换成普通16位数格式数据


/*
* afCnvtuint16_SP - Converts uint16 to semi-precision structure format.
*/
extern afSemiPrecision_t afCnvtuint16_SP( uint16 rawSP );
作用:把普通16位数格式的数据转换成微精度格式数据


/*
* afCnvtFloat_SP - Converts float to semi-precision
*                    structure format
* NOTE: This function will convert to the closest possible
*       representation in a 16 bit format. Meaning that
*       the number may not be exact. For example, 10.7 will
*       convert to 10.69531, because .7 is a repeating binary
*       number. The mantissa for afSemiPrecision_t is 10 bits
*       and .69531 is the 10 bit representative of .7.
*/
extern afSemiPrecision_t afCnvtFloat_SP( float f );
作用:把普通float格式数据转换成微精度格式数据


/*
* afCnvtSP_Float - Converts semi-precision structure format to float.
*/
extern float afCnvtSP_Float( afSemiPrecision_t sp );
作用:转换微精度格式数据为普通float格式数据


/*
* afCopyAddress
*
*/
extern void afCopyAddress (afAddrType_t *afAddr, zAddrType_t *zAddr);
作用:AF层地址拷贝,示例如下:
afCopyAddress( &MSGpkt->srcAddr, SrcAddress );

原创粉丝点击