Functions

UDPCommFn_Cyclic

Cyclic function for managing UDP communications. This function internally handles calling UDPCommManage, UDPCommReceive, and UDPCommSend.

Parameters

Direction Name Type Description
In / Out t UDPCommMgr_typ* UDP Comm manager to manage
Return Error UINT Returns 0 if okay, returns UDPCOMM_ERR_INVALIDINPUT if invalid input

Usage

Call this function every scan for a given commMgr instance. It drives the connection state machine and internally calls UDPCommManage, UDPCommReceive, and UDPCommSend, so most applications only need this one call.

UDPCommMgr_typ commMgr;
UINT error;

// Call every scan while UDP communication should be active
error = UDPCommFn_Cyclic(commMgr);

UDPCommManage

Handles the open and close of UDP communication on the local interface.

Parameters

Direction Name Type Description
In / Out t UDPCommMgr_typ* UDP Comm manager to manage
Return Error UINT Returns 0 if okay, returns UDPCOMM_ERR_INVALIDINPUT if invalid input

Usage

Opens the local socket on commMgr.IN.CFG.LocalInterface when commMgr.IN.CMD.Enable is set, and closes it when Enable is cleared. This is called automatically by UDPCommFn_Cyclic and only needs to be called directly if the manage/receive/send steps are being sequenced manually.

UINT error;

error = UDPCommManage(commMgr);

UDPCommReceive

Handles receiving UDP datagrams.

Parameters

Direction Name Type Description
In / Out t UDPCommMgr_typ* UDP Comm manager to manage
Return Error UINT Returns 0 if okay, returns UDPCOMM_ERR_INVALIDINPUT if invalid input

Usage

Listens for an incoming datagram while the socket is open and copies it into the buffer at commMgr.IN.PAR.pReceiveData (up to commMgr.IN.PAR.MaxReceiveLength bytes) when one arrives. On arrival it sets commMgr.OUT.STAT.NewDataAvailable, commMgr.OUT.STAT.ReceivedDataLength, and commMgr.OUT.STAT.ReceivedFromInterface (the sender’s IP address and port). Listening pauses until the data is acknowledged with commMgr.IN.CMD.AcknowledgeData, unless commMgr.IN.PAR.AllowContinuousReceive is set. Receiving can be turned off with commMgr.IN.PAR.DisableReceiving. Called automatically by UDPCommFn_Cyclic.

UINT error;

error = UDPCommReceive(commMgr);

UDPCommSend

Handles sending UDP datagrams.

Parameters

Direction Name Type Description
In / Out t UDPCommMgr_typ* UDP Comm manager to manage
Return Error UINT Returns 0 if okay, returns UDPCOMM_ERR_INVALIDINPUT if invalid input

Usage

Sends commMgr.IN.PAR.SendLength bytes from commMgr.IN.PAR.pSendData to commMgr.IN.CFG.RemoteInterface while the socket is open and commMgr.IN.CMD.Enable and commMgr.IN.CMD.Send are set. When the send completes, commMgr.OUT.STAT.DataSent and commMgr.OUT.STAT.SentDataLength are set. They are cleared when Send is reset, or on every scan if commMgr.IN.PAR.AllowContinuousSend is set, in which case the data is sent repeatedly while Send stays set. Called automatically by UDPCommFn_Cyclic.

UINT error;

error = UDPCommSend(commMgr);