This page documents the embeNET UDP C API. The API consists of the following parts:
To get more information on how to use this API refer to: Using UDP sockets
◆ EMBENET_UDP_SocketDescriptor
◆ EMBENET_UDP_RxDataHandler
Data reception handler that is called every time some data on a certain registered port is received.
During socket registration (see EMBENET_UDP_RegisterSocket) the user is expected to pass the callback function that will be called each time a UDP datagram is received through this socket. This typedef defines the format of such function.
- Note
- This handler callback is called in non-privileged mode. It is called from a thread or main loop and not from an interrupt service routine.
- Parameters
-
[in] | socket | descriptor of the socket that received the data |
[in] | sourceAddress | IPv6 address of the sender |
[in] | sourcePort | source port number that was used in the sender to send the data |
[in] | data | pointer to memory region that holds the received data |
[in] | dataSize | size of the received data (in number of bytes) |
◆ EMBENET_UDP_Traffic
Possible types of an UDP socket that describe what is the socket's listening IPv6 address.
Enumerator |
---|
EMBENET_UDP_TRAFFIC_UNICAST | The socket only listens on node's unicast address. |
EMBENET_UDP_TRAFFIC_MULTICAST | The socket only listens on multicast address of given group. |
EMBENET_UDP_TRAFFIC_ALL | The socket listens both on nodes unicast address or any matching multicast address - equivalent to IPv6 [::]. |
◆ EMBENET_UDP_RegisterSocket()
Registers a new UDP socket.
This function is used to register a new UDP socket, thus enabling data reception on the resulting address/port combination.
- Parameters
-
[in] | socket | pointer to a valid socket descriptor structure |
- Note
- The provided socket descriptor instance MUST be valid and accessible until EMBENET_UDP_UnregisterSocket. In particular, the descriptor SHALL NOT have automatic storage duration.
- The user MAY register socket with EMBENET_UDP_SOCKET_TYPE_MULTICAST==socketType and group not joined by the node. The user will not receive messages on this socket until the node joines the required group
- Returns
- EMBENET_RESULT_OK if socket was properly registered, or error status when the registration failed
◆ EMBENET_UDP_UnregisterSocket()
Unregisters socket from interface.
- Parameters
-
[in] | socket | pointer to valid socket descriptor instance |
- Return values
-
EMBENET_RESULT_OK | if socket was successfully unregistered |
EMBENET_RESULT_UDP_SOCKET_UNREGISTERED | if the given socket has not been registered |
◆ EMBENET_UDP_GetMaxDataSize()
Gets the maximum size of a single UDP payload size.
This function returns the maximum size of data that can be sent in a single UDP datagram. This is the maximum allowed size of the data to be sent by a call to EMBENET_UDP_Send
- Parameters
-
[in] | socket | pointer to valid socket descriptor instance |
- Returns
- maximum size of data that can be sent in a single UDP datagram (in number of bytes)
◆ EMBENET_UDP_Send()
Sends UDP datagram from the given socket.
This function schedules an UDP datagram to be sent.
- Note
- An UDP datagram can be sent only from a registered port.
- The source address of the resulting IPv6 Packet will always resolve to Node's UNICAST address
- Parameters
-
[in] | socket | pointer to valid socket descriptor instance from which the data will be sent |
[in] | destinationAddress | IPv6 destination address |
[in] | destinationPort | UDP destination port number |
[in] | data | pointer to memory address storing UDP payload data |
[in] | dataSize | size of data in bytes (see EMBENET_UDP_GetMaxDataSize) |
- Return values
-
EMBENET_RESULT_OK | if datagram was scheduled properly for sending |
EMBENET_RESULT_INVALID_ARGUMENT | if at least one of the input arguments was invalid |
EMBENET_RESULT_UDP_MAX_DATA_SIZE_EXCEEDED | if the size of the data to be sent is too large (see EMBENET_UDP_GetMaxDataSize) |
EMBENET_RESULT_UDP_PACKET_QUEUE_FULL | if there is not enough space to buffer the data to send |
EMBENET_RESULT_UDP_SOCKET_UNREGISTERED | if the given socket has not been registered |