UdsNode, which was previously used for local communications, has been deprecated. This section describes the procedure for updating an application that makes calls to the UdsNode send and receive functions directly to use transport::UnreliableProtocol.
For more information about migrating the other parts of the API, see 3.3. Migrating From the UdsNode Network Management API to the LocalNetwork Mesh API.
Use the send functions in transport::UnreliableProtocol rather than the earlier UdsNode::SendTo and UdsNodeBase::SendToDirect functions. For more information about UnreliableProtocol, see 5. PiaTransport Guide.
nn::Result UdsNode::SendTo (u8* pSendBuffer,
u32 uiSendSize, u16 uiDestTransportNodeId ) nn::Result UdsNode::SendTo (UdsHandle* pHandle, u8* pSendBuffer, u32 uiSendSize, u16 uiDestTransportNodeId, u8 option ) nn::Result UdsNodeBase::SendToDirect (UdsHandle* pHandle, u8* pSendBuffer, u32 uiSendSize, u16 uiDestUdsNodeId, u8 option ) |
nn::Result UnreliableProtocol::Send (StationId destId,
const bit8* pData, size_t dataSize ) |
The following code shows an example of sending data using UnreliableProtocol.
// Get an instance of UnreliableProtocol.
nn::pia::transport::UnreliableProtocol* pUnreliable = nn::pia::transport::Transport::GetInstance()->GetProtocol<nn::pia::transport::UnreliableProtocol>(m_hUnreliable); PIA_ASSERT(PIA_IS_VALID_POINTER(pUnreliable)); // Send. nn::Result r = pUnreliable->Send(destStationId, data, dataSize); if (r.IsSuccess()) { // Send successful. } else if (r == nn::pia::transport::ResultIsNotInCommunication()) { // Communication is not active. } else { // Error handling. } |
Get the UnreliableProtocol instance by specifying the handle that you obtained when creating it instead of using UdsHandle.
Use StationId destId instead of u16 uiDestTransportNodeId for the destination. For more information about StationId, see 1.7. Station IDs. If uiDestTransportNodeId was set to UDS_NODE_BROADCAST_NODE_ID, use UnreliableProtocol::SendToAll instead of UnreliableProtocol::Send.
There is no equivalent to the NO_WAIT value for the option parameter. After UnreliableProtocol::Send is called, call common::Scheduler::Dispatch to send the data using the PiaTransport sending thread.
Use the receive functions in transport::UnreliableProtocol rather than the earlierUdsNode::ReceiveFrom and UdsNodeBase::ReceiveFromDirect functions. For more information about UnreliableProtocol, see 5. PiaTransport Guide.
nn::Result UdsNode::ReceiveFrom (u8* pReceiveBuffer,
u32 uiReceiveBufferSize, u32* uiReceivedSize, u16* pSrcTransportNodeId ) nn::Result UdsNode::ReceiveFrom (UdsHandle* pHandle, u8* pReceiveBuffer, u32 uiReceiveBufferSize, u32* uiReceivedSize, u16* pSrcTransportNodeId, u8 option ) nn::Result UdsNodeBase::ReceiveFromDirect (UdsHandle* pHandle, u8* pReceiveBuffer, u32* uiReceivedSize, u16* pSrcUdsNodeId, u32 uiReceiveBufferSize, u8 option ) |
nn::Result UnreliableProtocol::Receive (StationId* pSrcId,
bit8* pRecvBuf, size_t* pRecvDataSize, size_t recvBuffSize ) |
The following code shows an example of receiving data using UnreliableProtocol.
nn::Result r;
// Get an instance of UnreliableProtocol. nn::pia::transport::UnreliableProtocol* pUnreliable = nn::pia::transport::Transport::GetInstance()->GetProtocol<nn::pia::transport::UnreliableProtocol>(m_hUnreliable); PIA_ASSERT(PIA_IS_VALID_POINTER(pUnreliable)); // Buffer for saving the received data. bit8 buf[nn::pia::transport::UnreliableProtocol::MAX_DATA_SIZE]; nn::pia::StationId srcId; size_t receivedSize; // Receive. r = pUnreliable->Receive(&srcId, buf, &receivedSize, sizeof(buf)); if (r.IsSuccess()) { // Receive successful. } else if (r == nn::pia::ResultNoData()) { // No data received. } else { // Error handling. } |
Get the UnreliableProtocol instance by specifying the handle that you obtained when creating it instead of using UdsHandle.
Use StationId * pSrcId instead of u16 * pSrcUdsNodeId for the pointer to get the source. For more information about StationId, see 1.7. Station IDs.
There is no equivalent to the NO_WAIT value for the option parameter. When you call common::Scheduler::Dispatch, the data is received using the PiaTransport receiving thread and stored in the UnreliableProtocol receive buffer. If there is no data to receive, UnreliableProtocol::Receive immediately ends and returns ResultNoData.