FreeRTOS_sockets.h
BaseType_t FreeRTOS_SendPingRequest( uint32_t ulIPAddress,
size_t xNumberOfBytesToSend,
TickType_t xBlockTimeTicks );
Send a ping (ICMP echo) request to a remote computer.
ipconfigSUPPORT_OUTGOING_PINGS must be set to 1 in FreeRTOSIPConfig.h for
FreeRTOS_SendPingRequest() to be available.
the TCP/IP stack calls the application defined
vApplicationPingReplyHook()
hook (or callback) function when it receives a reply to an outgoing ping request.
Parameters:
ulIPAddress
|
The IP address to which the ping request is sent.
The IP address is expressed as a 32-bit number in
network byte order.
|
xNumberOfBytesToSend
|
The number of data bytes to send in the ping request.
|
xBlockTimeTicks
|
The maximum time the calling RTOS task is prepared to wait
for a network buffer if one is not immediately available.
If a network buffer is not available then the calling RTOS task will be
held in the Blocked state (so other tasks can execute)
until either a buffer becomes available and therefore the ping
request transmitted, or
the block time expires.
The block time is specified in ticks. Milliseconds can be
converted to ticks by dividing the time in milliseconds by
portTICK_PERIOD_MS.
|
Returns:
If a ping request is successfully sent then the sequence number sent in the ping
message is returned to allow the application writer to match ping requests transmitted
with ping replies received. See the example below.
If a ping request could not be sent then pdFAIL is returned.
Example usage:
This example defines two functions. vSendPing() transmits 8 bytes to a remote IP address.
vApplicationPingReplyHook() is the standard FreeRTOS-Plus-TCP ping reply callback function.
vApplicationPingReplyHook() receives the ping reply, then sends the received sequence number
to vSendPing() where it is compared to the sequence number from the ping request.
#include "FreeRTOS_sockets.h"
QueueHandle_t xPingReplyQueue;
void vApplicationPingReplyHook( ePingReplyStatus_t eStatus, uint16_t usIdentifier )
{
switch( eStatus )
{
case eSuccess :
xQueueSend( xPingReplyQueue, &usIdentifier, 10 / portTICK_PERIOD_MS );
break;
case eInvalidChecksum :
case eInvalidData :
break;
}
}
BaseType_t vSendPing( const int8_t *pcIPAddress )
{
uint16_t usRequestSequenceNumber, usReplySequenceNumber;
uint32_t ulIPAddress;
ulIPAddress = FreeRTOS_inet_addr( pcIPAddress );
usRequestSequenceNumber = FreeRTOS_SendPingRequest( ulIPAddress, 8, 100 / portTICK_PERIOD_MS );
if( usRequestSequenceNumber == pdFAIL )
{
}
else
{
if( xQueueReceive( xPingReplyQueue,
&usReplySequenceNumber,
200 / portTICK_PERIOD_MS ) == pdPASS )
{
if( usRequestSequenceNumber == usReplySequenceNumber )
{
}
}
}
}
Example use of the FreeRTOS_SendPingRequest() API function
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.