This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AF_DataRequest()返回afStatus_MEM_FAIl,内存溢出

我用协调器接收串口数据,然后通过无线发送出去,接受的无线数据通过串口发送,串口波特率57600,数据长度20字节左右,直接调用AF_DataRequest()函数时状态会返回afStatus_MEM_FAIl ,重复调用也是同样的返回。

1.发送几十次AF_DataRequest就是出现内存溢出的报错,AF_DataRequest函数内部一点没改。

2.应用层的程序,没有任何内存的申请

3.协议栈版本home1.2.2a

4.soc是cc2530f256

  • 建议一下写法:


    msgBuf = zcl_mem_alloc( msgLen );
    if ( msgBuf != NULL )
    {



    status = AF_DataRequest( destAddr, epDesc, clusterID, msgLen, msgBuf,
    &zcl_TransID, options, AF_DEFAULT_RADIUS );
    zcl_mem_free ( msgBuf );
    }
    else
    {
    status = ZMemError;
    }
  • 感谢回答,方法我试了,AF_DataRequest返回还是内存溢出。
    我的发送函数是这样写的
    /*********************************************************************
    * @fn sraum_send_uincast
    *
    * @brief 依据簇和短地址发送单播数据
    *
    * @param buf 数据
    * len 长度
    * sraum_cluster 输出簇
    * shortaddr 短地址
    * @return none
    *
    *********************************************************************/
    void sraum_send_uincast( uint8 *buf,uint8 len ,uint16 sraum_cluster,uint16 shortaddr)
    {
    //网络成功标记
    if(gateway_information.network_status)
    {
    HAL_TOGGLE_LED1();
    Sraum_Control_Uincast_Dstaddr.addrMode = (afAddrMode_t)Addr16Bit; //单播
    Sraum_Control_Uincast_Dstaddr.endPoint = SAMPLELIGHT_ENDPOINT; //指定端点号
    Sraum_Control_Uincast_Dstaddr.addr.shortAddr = shortaddr; //指定目的网络地址为广播地址

    AF_return = AF_DataRequest( &Sraum_Control_Uincast_Dstaddr, //目的地址指针
    &sampleLight_TestEp,
    sraum_cluster,
    len,
    buf,
    &zclSampleLight_TaskID,
    AF_DISCV_ROUTE,
    AF_DEFAULT_RADIUS );
    //osal_mem_free( buf );
    if ( AF_return == afStatus_SUCCESS )
    {
    }else if ( AF_return == afStatus_MEM_FAIL )//内存溢出
    {
    SystemResetSoft();
    }else if ( AF_return == afStatus_INVALID_PARAMETER )//参数错误
    {
    SystemResetSoft();
    }else if ( AF_return == afStatus_NO_ROUTE )//无设备
    {

    }
    }
    }
  • 补充一下,调用这个函数。输入的参数都是数组和变量,没有涉及动态内存的分配。
  • 我建议你不要直接使用你的传输的指针,而是分配一个内存来存储这个指针的数据,然后使用开辟的buf去发送。
  • 尝试过了,没有解决内存溢出的问题。AF_DataRequest()还是返回afStatus_MEM_FAIl。