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.

sl_Send 发包



用 sl_Send发送连续的wifi包,怎么判断一个包已经完成、例程中是用延时,我需要一个发完马上发下一个包。

static int Tx_continuous(int iChannel,SlRateIndex_e rate,int iNumberOfPackets,
int iTxPowerLevel,long dIntervalMiliSec)
{
int iSoc;
long lRetVal = -1;
long ulIndex;

iSoc = sl_Socket(SL_AF_RF,SL_SOCK_RAW,iChannel);
ASSERT_ON_ERROR(iSoc);

UART_PRINT("Transmitting data...\r\n");
for(ulIndex = 0 ; ulIndex < iNumberOfPackets ; ulIndex++)
{
lRetVal = sl_Send(iSoc,RawData_Ping,sizeof(RawData_Ping),\
SL_RAW_RF_TX_PARAMS(iChannel, rate, iTxPowerLevel, PREAMBLE));
if(lRetVal < 0)
{
sl_Close(iSoc);
ASSERT_ON_ERROR(lRetVal);
}
//Sleep(dIntervalMiliSec);
MAP_UtilsDelay(4000000);
}

lRetVal = sl_Close(iSoc);
ASSERT_ON_ERROR(lRetVal);

UART_PRINT("Transmission complete.\r\n");
return SUCCESS;
}

  • 在例程中,发送后通过检测iStatus的返回标志来判断,调用sl_Send(iSockID, g_cBsdBuf, sTestBufLen, 0 )函数的作用是写数据到TCP socket

    这个函数的功能是传输数据完成后会立即返回返回值,表示传输完成。

    This function is used to transmit a message to another socket.
    Returns immediately after sending data to device.

    // connecting to TCP server
    iStatus = sl_Connect(iSockID, ( SlSockAddr_t *)&sAddr, iAddrSize); //<连接>目的IP地址及端口号
    if( iStatus < 0 )
    {
    // error
    sl_Close(iSockID);
    ASSERT_ON_ERROR(CONNECT_ERROR);
    }

    // sending multiple packets to the TCP server
    while (lLoopCount < g_ulPacketCount)
    {
    // sending packet
    iStatus = sl_Send(iSockID, g_cBsdBuf, sTestBufLen, 0 );
    if( iStatus < 0 )
    {
    // error
    sl_Close(iSockID);
    ASSERT_ON_ERROR(SEND_ERROR);
    }
    lLoopCount++;
    }

    Report("Sent %u packets successfully\n\r",g_ulPacketCount);