RoveComm C++ 3.0.0
Welcome to the RoveComm C++ repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of RoveComm C++. The RoveComm C++ project is the RoveComm interface for high level systems and should not be used for microcontrollers.
Loading...
Searching...
No Matches
rovecomm::RoveCommUDP Class Reference

The RoveCommUDP class is used to send and receive data over a UDP connection. More...

#include <RoveCommUDP.h>

Inheritance diagram for rovecomm::RoveCommUDP:
Collaboration diagram for rovecomm::RoveCommUDP:

Classes

struct  CallbackEntry

Public Member Functions

 RoveCommUDP ()
 Construct a new RoveCommUDP::RoveCommUDP object.
 ~RoveCommUDP ()
 Destroy the RoveCommUDP::RoveCommUDP object.
bool Init (int nPort=manifest::General::ETHERNET_UDP_PORT)
 Initialize the UDP socket and bind it to the specified port. This method also starts the thread that will continuously receive UDP packets and invoke the appropriate callback function.
template<typename T>
ssize_t WriteAll (const RoveCommPacket< T > &stPacket, std::span< const std::pair< manifest::AddressEntry, int > > spDestinations)
 Sends a packet to all specified destinations. This is more efficient than using WriteTo() multiple times, as it uses sendmmsg() on Linux and sends the same packet to multiple destinations in one call.
template<typename T>
ssize_t WriteTo (const RoveCommPacket< T > &stPacket, const manifest::AddressEntry &stIPAddress, int nPort=manifest::General::ETHERNET_UDP_PORT)
 Sends a packet to a specific destination. This is often used to send a command to a specific device.
template<typename T>
ssize_t Write (const RoveCommPacket< T > &stPacket)
 Sends a packet to all subscribers. This is often used to send errors or telemetry data to all devices that have subscribed to this node.
template<typename manifest::ManifestEntry Entry>
ssize_t Write (std::span< const EntryType< Entry > > spData)
 Writes a packet, checked against the manifest.
template<typename manifest::ManifestEntry Entry>
ssize_t Write (std::initializer_list< EntryType< Entry > > ilData)
template<typename manifest::ManifestEntry Entry>
ssize_t WriteTo (std::span< const EntryType< Entry > > spData, const manifest::AddressEntry &stIPAddress=manifest::Helpers::FindBoardById(Entry.DATA_ID).ADDRESS, int nPort=manifest::General::ETHERNET_UDP_PORT)
template<typename manifest::ManifestEntry Entry>
ssize_t WriteTo (std::initializer_list< EntryType< Entry > > ilData, const manifest::AddressEntry &stIPAddress=manifest::Helpers::FindBoardById(Entry.DATA_ID).ADDRESS, int nPort=manifest::General::ETHERNET_UDP_PORT)
template<typename T>
CallbackHandle On (const uint16_t unDataId, std::function< void(const RoveCommPacket< T > &)> fnCallback)
 Register a callback for UDP packets with the given data ID. The callback belongs to this node: packets received by any other node never invoke it.
template<typename manifest::ManifestEntry Entry>
CallbackHandle On (std::function< void(const RoveCommPacket< EntryType< Entry > > &)> fnCallback)
void Clear (const CallbackHandle &stHandle)
 Remove the one callback identified by a handle from On(). Other callbacks for the same data ID stay registered. Waits for a callback that is already running, so once this returns the removed callback can no longer run. An empty or already-removed handle is ignored.
ssize_t Subscribe (const manifest::AddressEntry &stIPAddress, int nPort=manifest::General::ETHERNET_UDP_PORT)
ssize_t Unsubscribe (const manifest::AddressEntry &stIPAddress, int nPort=manifest::General::ETHERNET_UDP_PORT)
void Close ()
 Close the UDP socket. This method is called when the RoveCommUDP object is destroyed. Or when the user calls the CloseUDPSocket method.
IPS & GetIPS ()
 Accessor for the Frame I P S private member.

Private Types

template<typename T>
using CallbackMap = std::unordered_map<uint16_t, std::vector<CallbackEntry<T>>>
using SubscriberInfo = std::pair<manifest::AddressEntry, int>
Private Types inherited from AutonomyThread< void >
enum  AutonomyThreadState
enum  AutonomyThreadPriority

Private Member Functions

template<typename T>
constexpr CallbackMap< T > & GetCallbackMap ()
template<typename T>
void RemoveCallback (const CallbackHandle &stHandle)
 Remove the one callback identified by a handle from this node's map for payload type T.
template<typename T>
void ProcessPacket (std::span< const uint8_t > stData, const sockaddr_in &saClientAddr)
 Process a UDP packet and invoke the appropriate callback function. This function is called from the ReceiveUDPPacketAndCallback function and is used to invoke the appropriate callback function based on the data id of the received packet. The callback function is invoked with the received packet and the client address.
void ReceiveAndCallback ()
 Receive a UDP packet and invoke the appropriate callback function. Since data types are not known at compile time, this function calls the appropriate ProcessPacket function based on the data type of the received packet.
void ThreadedContinuousCode () override
 Initialize the thread that will continuously receive UDP packets and invoke the appropriate callback function. This is a component of the AutonomyThread class and is called when the thread is started.
void PooledLinearCode () override
 This method holds the code that is ran in the thread pool started by the ThreadedLinearCode() method. It currently does nothing and is not needed in the current implementation of the RoveCommUDP class.
Private Member Functions inherited from AutonomyThread< void >
 AutonomyThread ()
 Construct a new Autonomy Thread object.
virtual ~AutonomyThread ()
 Destroy the Autonomy Thread object. If the parent object or main thread is destroyed or exited while this thread is still running, a race condition will occur. Stopping and joining the thread here insures that the main program can't exit if the user forgot to stop and join the thread.
void Start ()
 When this method is called, it starts a new thread that runs the code within the ThreadedContinuousCode method. This is the users main code that will run the important and continuous code for the class.
void RequestStop ()
 Signals threads to stop executing user code, terminate. DOES NOT JOIN. This method will not force the thread to exit, if the user code is not written properly and contains WHILE statement or any other long-executing or blocking code, then the thread will not exit until the next iteration.
void Join ()
 Waits for thread to finish executing and then closes thread. This method will block the calling code until thread is finished.
bool Joinable () const
 Check if the code within the thread and all pools created by it are finished executing and the thread is ready to be closed.
AutonomyThreadState GetThreadState () const
 Accessor for the Threads State private member.
IPS & GetIPS ()
 Accessor for the Frame I P S private member.
void SetMainThreadPriority (AutonomyThreadPriority ePriority)
 Set the OS priority for the main continuous thread.
void SetPoolThreadPriority (AutonomyThreadPriority ePriority)
 Set the OS priority for the highly parallelized pool threads.
void RunPool (const unsigned int nNumTasksToQueue, const unsigned int nNumThreads=2, const bool bForceStopCurrentThreads=false)
 When this method is called, it starts/adds tasks to a thread pool that runs nNumTasksToQueue copies of the code within the PooledLinearCode() method using nNumThreads number of threads. This is meant to be used as an internal utility of the child class to further improve parallelization. Default value for nNumThreads is 2.
void RunDetachedPool (const unsigned int nNumTasksToQueue, const unsigned int nNumThreads=2, const bool bForceStopCurrentThreads=false)
 When this method is called, it starts a thread pool full of threads that don't return std::futures (like a placeholder for the thread return type). This means the thread will not have a return type and there is no way to determine if the thread has finished other than calling the Join() method. Only use this if you want to 'set and forget'. It will be faster as it doesn't return futures. Runs PooledLinearCode() method code. This is meant to be used as an internal utility of the child class to further improve parallelization.
void ParallelizeLoop (const int nNumThreads, const N tTotalIterations, F &&tLoopFunction)
 Given a ref-qualified looping function and an arbitrary number of iterations, this method will divide up the loop and run each section in a thread pool. This function must not return anything. This method will block until the loop has completed.
void ClearPoolQueue ()
 Clears any tasks waiting to be ran in the queue, tasks currently running will remain running.
void JoinPool ()
 Waits for pool to finish executing tasks. This method will block the calling code until thread is finished.
bool PoolJoinable () const
 Check if the internal pool threads are done executing code and the queue is empty.
void SetMainThreadIPSLimit (int nMaxIterationsPerSecond=0)
 Mutator for the Main Thread Max I P S private member.
int GetPoolNumOfThreads ()
 Accessor for the Pool Num Of Threads private member.
int GetPoolQueueLength ()
 Accessor for the Pool Queue Size private member.
std::vector< void > GetPoolResults ()
 Accessor for the Pool Results private member. The action of getting results will destroy and remove them from this object. This method blocks if the thread is not finished, so no need to call JoinPool() before getting results.
int GetMainThreadMaxIPS () const
 Accessor for the Main Thread Max I P S private member.

Private Attributes

std::tuple< CallbackMap< int8_t >, CallbackMap< uint8_t >, CallbackMap< int16_t >, CallbackMap< uint16_t >, CallbackMap< int32_t >, CallbackMap< uint32_t >, CallbackMap< float >, CallbackMap< double >, CallbackMap< char > > m_tpCallbackMaps
uint64_t m_ullNextCallbackID = 1
std::atomic_int m_nUDPSocket
struct sockaddr_in m_saUDPServerAddr
std::set< SubscriberInfo > m_seSubscribers
std::shared_mutex m_muCallbackMutex
std::mutex m_muSocketSendMutex
std::mutex m_muSocketReceiveMutex
Private Attributes inherited from AutonomyThread< void >
IPS m_IPS

Detailed Description

The RoveCommUDP class is used to send and receive data over a UDP connection.

Author
Eli Byrd (edbgk.nosp@m.k@ms.nosp@m.t.edu)
Date
2024-02-07

Member Typedef Documentation

◆ CallbackMap

template<typename T>
using rovecomm::RoveCommUDP::CallbackMap = std::unordered_map<uint16_t, std::vector<CallbackEntry<T>>>
private

◆ SubscriberInfo

Constructor & Destructor Documentation

◆ RoveCommUDP()

rovecomm::RoveCommUDP::RoveCommUDP ( )

Construct a new RoveCommUDP::RoveCommUDP object.

Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2024-03-07
76 {
77 // Initialize member variables.
78 m_nUDPSocket = -1;
79
80 // Set an IPS cap in the backend RoveComm thread.
82 }
void SetMainThreadIPSLimit(int nMaxIterationsPerSecond=0)
Definition AutonomyThread.hpp:515
std::atomic_int m_nUDPSocket
Definition RoveCommUDP.h:95
const int ROVECOMM_THREAD_MAX_IPS
Definition RoveCommConsts.h:30
Here is the call graph for this function:

◆ ~RoveCommUDP()

rovecomm::RoveCommUDP::~RoveCommUDP ( )

Destroy the RoveCommUDP::RoveCommUDP object.

Author
Eli Byrd (edbgk.nosp@m.k@ms.nosp@m.t.edu)
Date
2024-02-07
92 {
93 Close();
94 }
void Close()
Close the UDP socket. This method is called when the RoveCommUDP object is destroyed....
Definition RoveCommUDP.cpp:696
Here is the call graph for this function:

Member Function Documentation

◆ Clear()

void rovecomm::RoveCommUDP::Clear ( const CallbackHandle & stHandle)

Remove the one callback identified by a handle from On(). Other callbacks for the same data ID stay registered. Waits for a callback that is already running, so once this returns the removed callback can no longer run. An empty or already-removed handle is ignored.

Parameters
stHandle- The handle On() returned for the callback.
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2026-09-26
358 {
359 // An empty handle was never registered.
360 if (stHandle.ullID == 0)
361 {
362 return;
363 }
364
365 // Dispatch to the map for the handle's payload type.
366 switch (stHandle.eDataType)
367 {
376 case manifest::DataTypes::CHAR: RemoveCallback<char>(stHandle); break;
377 }
378 }
void RemoveCallback(const CallbackHandle &stHandle)
Remove the one callback identified by a handle from this node's map for payload type T.
Definition RoveCommUDP.cpp:391
@ INT32_T
Definition RoveCommManifest.h:39
@ INT16_T
Definition RoveCommManifest.h:37
@ UINT32_T
Definition RoveCommManifest.h:40
@ INT8_T
Definition RoveCommManifest.h:35
@ UINT8_T
Definition RoveCommManifest.h:36
@ FLOAT_T
Definition RoveCommManifest.h:41
@ UINT16_T
Definition RoveCommManifest.h:38
@ DOUBLE_T
Definition RoveCommManifest.h:42
@ CHAR
Definition RoveCommManifest.h:43
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Close()

void rovecomm::RoveCommUDP::Close ( )

Close the UDP socket. This method is called when the RoveCommUDP object is destroyed. Or when the user calls the CloseUDPSocket method.

Author
Eli Byrd (edbgk.nosp@m.k@ms.nosp@m.t.edu)
Date
2024-02-07
697 {
698 // Check if the socket is open
699 if (m_nUDPSocket != -1)
700 {
701 // Stop the thread
702 RequestStop();
703 Join();
704
705 // Close the socket
707
708#if defined(__ROVECOMM_WINDOWS_MODE__) && __ROVECOMM_WINDOWS_MODE__ == 1
709 WSACleanup();
710#endif
711 }
712 }
#define CLOSE_SOCKET
Definition RoveCommTCP.cpp:20
void Join()
Definition AutonomyThread.hpp:198
void RequestStop()
Definition AutonomyThread.hpp:182
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetCallbackMap()

template<typename T>
CallbackMap< T > & rovecomm::RoveCommUDP::GetCallbackMap ( )
inlineconstexprprivate
87 {
88 return std::get<CallbackMap<T>>(m_tpCallbackMaps);
89 }
std::tuple< CallbackMap< int8_t >, CallbackMap< uint8_t >, CallbackMap< int16_t >, CallbackMap< uint16_t >, CallbackMap< int32_t >, CallbackMap< uint32_t >, CallbackMap< float >, CallbackMap< double >, CallbackMap< char > > m_tpCallbackMaps
Definition RoveCommUDP.h:82
Here is the caller graph for this function:

◆ GetIPS()

IPS & AutonomyThread< T >::GetIPS ( )
inline

Accessor for the Frame I P S private member.

Returns
IPS& - The iteration per second counter for the ThreadedContinuousCode()
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-08-20
242{ return m_IPS; }
IPS m_IPS
Definition AutonomyThread.hpp:278

◆ Init()

bool rovecomm::RoveCommUDP::Init ( int nPort = manifest::General::ETHERNET_UDP_PORT)

Initialize the UDP socket and bind it to the specified port. This method also starts the thread that will continuously receive UDP packets and invoke the appropriate callback function.

Parameters
nPort- The port that the UDP socket is to be bound to. If set to 0, then the operating system will automatically assign to an available port.
Returns
true - The UDP socket was successfully initialized and bound.
false - An error occurred while initializing the UDP socket.
Author
Eli Byrd (edbgk.nosp@m.k@ms.nosp@m.t.edu)
Date
2024-02-07
111 {
112#if defined(__ROVECOMM_WINDOWS_MODE__) && __ROVECOMM_WINDOWS_MODE__ == 1
113 WSADATA wsaData;
114 if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
115 {
116 std::cerr << "WSAStartup failed." << std::endl;
117 return 1;
118 }
119#endif
120
121 // Create a UDP socket
122 m_nUDPSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
123 if (m_nUDPSocket == -1)
124 {
125 perror("Failed to create UDP socket");
126 return false;
127 }
128 else
129 {
130 // Increase the socket buffer size to 1MB
131 int bufferSize = 1 * 1024 * 1024;
132 if (setsockopt(m_nUDPSocket, SOL_SOCKET, SO_RCVBUF, (char*) &bufferSize, sizeof(bufferSize)) == -1)
133 {
134 perror("Failed to set socket receive buffer size");
135 return false;
136 }
137 if (setsockopt(m_nUDPSocket, SOL_SOCKET, SO_SNDBUF, (char*) &bufferSize, sizeof(bufferSize)) == -1)
138 {
139 perror("Failed to set socket send buffer size");
140 return false;
141 }
142
143 // Set SO_REUSEADDR and SO_REUSEPORT
144 int optval = 1;
145 if (setsockopt(m_nUDPSocket, SOL_SOCKET, SO_REUSEADDR, (char*) &optval, sizeof(optval)) == -1)
146 {
147 perror("Failed to set SO_REUSEADDR");
148 return false;
149 }
150#ifdef SO_REUSEPORT
151 if (setsockopt(m_nUDPSocket, SOL_SOCKET, SO_REUSEPORT, (char*) &optval, sizeof(optval)) == -1)
152 {
153 perror("Failed to set SO_REUSEPORT");
154 return false;
155 }
156#endif
157
158#if defined(__ROVECOMM_WINDOWS_MODE__) && __ROVECOMM_WINDOWS_MODE__ == 1
159 // For asynchronous I/O, we use overlapped operations instead of non-blocking mode.
160 // Create an IOCP and associate our UDP socket with it.
161 m_stdIOCP = CreateIoCompletionPort((HANDLE) (SOCKET) m_nUDPSocket.load(), NULL, 0, 0);
162 if (m_stdIOCP == NULL)
163 {
164 perror("CreateIoCompletionPort failed.");
165 return false;
166 }
167#else
168 if (fcntl(m_nUDPSocket, F_SETFL, fcntl(m_nUDPSocket, F_GETFL) | O_NONBLOCK) == -1)
169 {
170 // Handle and print error.
171 perror("Failed to set UDP socket to non-blocking mode.");
172 return false;
173 }
174#endif
175 }
176
177 // Configure the server address
178 sockaddr_in saServerAddr;
179 memset(&saServerAddr, 0, sizeof(saServerAddr));
180 saServerAddr.sin_family = AF_INET;
181 saServerAddr.sin_addr.s_addr = htonl(INADDR_ANY);
182 saServerAddr.sin_port = htons(nPort);
183
184 // Bind the socket
185 if (bind(m_nUDPSocket.load(), (struct sockaddr*) &saServerAddr, sizeof(saServerAddr)) == -1)
186 {
187 perror("Failed to bind UDP socket");
189 return false;
190 }
191
192 // Start the thread
193 Start();
194
195 return true;
196 }
void Start()
Definition AutonomyThread.hpp:129
Here is the call graph for this function:
Here is the caller graph for this function:

◆ On() [1/2]

template<typename T>
CallbackHandle rovecomm::RoveCommUDP::On ( const uint16_t unDataId,
std::function< void(const RoveCommPacket< T > &)> fnCallback )

Register a callback for UDP packets with the given data ID. The callback belongs to this node: packets received by any other node never invoke it.

Template Parameters
T- The payload type of the packets. Must be one of the manifest's types.
Parameters
unDataId- The data ID that invokes the callback.
fnCallback- The callback. It runs on this node's receive thread and must not call On() or Clear() on this node.
Returns
CallbackHandle - Pass it to Clear() to remove this callback, and only this one.
Author
Eli Byrd (edbgk.nosp@m.k@ms.nosp@m.t.edu)
Date
2024-02-07
334 {
335 // Acquire a write lock to protect the callback maps.
336 std::unique_lock lkCallbackLock(m_muCallbackMutex);
337
338 // Give the callback an ID so Clear() can remove exactly this one later.
339 const uint64_t ullID = m_ullNextCallbackID++;
340 // Note: C++ will default initialize a new vector if no entry is found.
341 GetCallbackMap<T>()[unDataId].push_back({ullID, std::move(fnCallback)});
342
343 return {.unDataId = unDataId, .eDataType = RoveCommPacket<T>::eDataType, .ullID = ullID};
344 }
constexpr CallbackMap< T > & GetCallbackMap()
Definition RoveCommUDP.h:86
std::shared_mutex m_muCallbackMutex
Definition RoveCommUDP.h:99
uint64_t m_ullNextCallbackID
Definition RoveCommUDP.h:83
static constexpr manifest::DataTypes eDataType
Definition RoveCommPacket.h:79
Here is the call graph for this function:
Here is the caller graph for this function:

◆ On() [2/2]

template<typename manifest::ManifestEntry Entry>
CallbackHandle rovecomm::RoveCommUDP::On ( std::function< void(const RoveCommPacket< EntryType< Entry > > &)> fnCallback)
inline
214 {
215 return On(Entry.DATA_ID, fnCallback);
216 }
CallbackHandle On(const uint16_t unDataId, std::function< void(const RoveCommPacket< T > &)> fnCallback)
Register a callback for UDP packets with the given data ID. The callback belongs to this node: packet...
Definition RoveCommUDP.cpp:333
Here is the call graph for this function:

◆ PooledLinearCode()

void rovecomm::RoveCommUDP::PooledLinearCode ( )
overrideprivatevirtual

This method holds the code that is ran in the thread pool started by the ThreadedLinearCode() method. It currently does nothing and is not needed in the current implementation of the RoveCommUDP class.

Note
This function is not intended to be called directly. It is called from the AutonomyThread class. After the thread pool has been started.
Author
Eli Byrd (edbgk.nosp@m.k@ms.nosp@m.t.edu)
Date
2024-02-07

Implements AutonomyThread< void >.

685 {
687 }
void ReceiveAndCallback()
Receive a UDP packet and invoke the appropriate callback function. Since data types are not known at ...
Definition RoveCommUDP.cpp:481
Here is the call graph for this function:

◆ ProcessPacket()

template<typename T>
void rovecomm::RoveCommUDP::ProcessPacket ( std::span< const uint8_t > spData,
const sockaddr_in & saClientAddr )
private

Process a UDP packet and invoke the appropriate callback function. This function is called from the ReceiveUDPPacketAndCallback function and is used to invoke the appropriate callback function based on the data id of the received packet. The callback function is invoked with the received packet and the client address.

Template Parameters
T- The type of data that the callback function will be invoked with. This can be any of the types defined in the manifest.
Parameters
spData- The received RoveCommData that is to be processed.
vCallbacks- The list of callback functions that are to be invoked when a packet with the specified data id is received.
saClientAddr- The address of the client that sent the packet.
Note
This function is not intended to be called directly. It is called from the ReceiveUDPPacketAndCallback function.
Author
Eli Byrd (edbgk.nosp@m.k@ms.nosp@m.t.edu)
Date
2024-02-07
434 {
435 // Unpack the received data into a RoveCommPacket
436 RoveCommPacket<T> stPacket = UnpackData<T>(spData);
437
438 // Check if the received packet is a subscribe or unsubscribe packet
439 if (stPacket.unDataId == manifest::System::SUBSCRIBE_DATA_ID)
440 {
442 {
443 // Add new subscriber
444 m_seSubscribers.insert({inet_ntoa(saClientAddr.sin_addr), ntohs(saClientAddr.sin_port)});
445 }
446 }
447 else if (stPacket.unDataId == manifest::System::UNSUBSCRIBE_DATA_ID)
448 {
449 // Remove subscriber
450 m_seSubscribers.erase({inet_ntoa(saClientAddr.sin_addr), ntohs(saClientAddr.sin_port)});
451 }
452
453 // Acquire a read lock to protect the callback vectors.
454 std::shared_lock lkCallbackLock(m_muCallbackMutex);
455
456 // Invoke the callbacks this node has for the packet's data ID.
457 const CallbackMap<T>& umCallbacks = GetCallbackMap<T>();
458 auto itEntry = umCallbacks.find(stPacket.unDataId);
459 if (itEntry != umCallbacks.end())
460 {
461 for (const CallbackEntry<T>& stEntry : itEntry->second)
462 {
463 stEntry.fnCallback(stPacket);
464 }
465 }
466 }
std::set< SubscriberInfo > m_seSubscribers
Definition RoveCommUDP.h:98
std::unordered_map< uint16_t, std::vector< CallbackEntry< T > > > CallbackMap
Definition RoveCommUDP.h:69
const int UNSUBSCRIBE_DATA_ID
Definition RoveCommManifest.h:906
const int SUBSCRIBE_DATA_ID
Definition RoveCommManifest.h:905
const int ROVECOMM_ETHERNET_UDP_MAX_SUBSCRIBERS
Definition RoveCommConsts.h:24
RoveCommPacket< T > UnpackData(std::span< const uint8_t > spBytes)
Create a RoveCommPacket structure from a RoveCommData structure.
Definition RoveCommPacket.cpp:144
Definition RoveCommUDP.h:62
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReceiveAndCallback()

void rovecomm::RoveCommUDP::ReceiveAndCallback ( )
private

Receive a UDP packet and invoke the appropriate callback function. Since data types are not known at compile time, this function calls the appropriate ProcessPacket function based on the data type of the received packet.

Note
This function is not intended to be called directly. It is called from the ThreadedContinuousCode function. If this is called directly, it will block the thread until a packet is received.
Author
Eli Byrd (edbgk.nosp@m.k@ms.nosp@m.t.edu)
Date
2024-02-07
482 {
483#if defined(__ROVECOMM_WINDOWS_MODE__) && __ROVECOMM_WINDOWS_MODE__ == 1
484 // Create a batch of RecvContext structures to receive multiple packets at once.
485 constexpr size_t BATCH_SIZE = 32;
486 RecvContext rcContexts[BATCH_SIZE];
487
488 // Post BATCH_SIZE asynchronous receives.
489 for (size_t siIter = 0; siIter < BATCH_SIZE; siIter++)
490 {
491 ZeroMemory(&rcContexts[siIter].overlapped, sizeof(OVERLAPPED));
492 rcContexts[siIter].wsabuf.buf = rcContexts[siIter].data.data();
493 rcContexts[siIter].wsabuf.len = rcContexts[siIter].data.size();
494 int nAddrLen = sizeof(rcContexts[siIter].addr);
495 DWORD stdFlags = 0;
496 int nRet = WSARecvFrom(m_nUDPSocket,
497 &rcContexts[siIter].wsabuf,
498 1,
499 NULL,
500 &stdFlags,
501 reinterpret_cast<sockaddr*>(&rcContexts[siIter].addr),
502 &nAddrLen,
503 &rcContexts[siIter].overlapped,
504 NULL);
505 if (nRet == SOCKET_ERROR)
506 {
507 int nErr = WSAGetLastError();
508 if (nErr != WSA_IO_PENDING)
509 {
510 perror("WSARecvFrom failed!");
511 }
512 }
513 }
514
515 // Wait for completions in a loop.
516 DWORD stdNumberOfBytesTransferred;
517 ULONG_PTR ulCompletionKey;
518 LPOVERLAPPED stdLPOverlapped;
519 // Set a short timeout (in milliseconds) to poll for completions.
520 const DWORD dwTimeout = 1; // 1ms timeout (adjust as needed).
521 while (true)
522 {
523 // Wait for an I/O completion event with a short timeout.
524 BOOL bSuccess = GetQueuedCompletionStatus(m_stdIOCP, &stdNumberOfBytesTransferred, &ulCompletionKey, &stdLPOverlapped, dwTimeout);
525 if (!bSuccess)
526 {
527 if (GetLastError() == WAIT_TIMEOUT)
528 {
529 // No completion available within the timeout period.
530 break; // Exit the loop so the function returns.
531 }
532 else
533 {
534 perror("GetQueuedCompletionStatus (recv) failed!");
535 continue;
536 }
537 }
538
539 // If stdLPOverlapped is NULL, something went wrong.
540 if (stdLPOverlapped == nullptr)
541 {
542 continue;
543 }
544
545 // Identify the RecvContext from the overlapped pointer.
546 RecvContext* pContext = CONTAINING_RECORD(stdLPOverlapped, RecvContext, overlapped);
547
548 // Process the received data.
549 std::span<uint8_t> spData{pContext->data.data(), stdNumberOfBytesTransferred};
550 sockaddr_in& saClientAddr = pContext->addr;
551
552 // Extract data id and data type from the packet.
553 uint16_t unDataId = (static_cast<uint16_t>(spData[1]) << 8) | static_cast<uint16_t>(spData[2]);
554 manifest::DataTypes eDataType = static_cast<manifest::DataTypes>(spData[5]);
555
556 switch (eDataType)
557 {
558 case manifest::DataTypes::UINT8_T: ProcessPacket<uint8_t>(spData, saClientAddr); break;
559 case manifest::DataTypes::INT8_T: ProcessPacket<int8_t>(spData, saClientAddr); break;
560 case manifest::DataTypes::UINT16_T: ProcessPacket<uint16_t>(spData, saClientAddr); break;
561 case manifest::DataTypes::INT16_T: ProcessPacket<int16_t>(spData, saClientAddr); break;
562 case manifest::DataTypes::UINT32_T: ProcessPacket<uint32_t>(spData, saClientAddr); break;
563 case manifest::DataTypes::INT32_T: ProcessPacket<int32_t>(spData, saClientAddr); break;
564 case manifest::DataTypes::FLOAT_T: ProcessPacket<float>(spData, saClientAddr); break;
565 case manifest::DataTypes::DOUBLE_T: ProcessPacket<double>(spData, saClientAddr); break;
566 case manifest::DataTypes::CHAR: ProcessPacket<char>(spData, saClientAddr); break;
567 }
568
569 // Re-post the asynchronous receive for this context.
570 ZeroMemory(&pContext->overlapped, sizeof(OVERLAPPED));
571 pContext->wsabuf.buf = reinterpret_cast<char*>(pContext->data.data());
572 pContext->wsabuf.len = sizeof(pContext->data);
573 int nAddrLen = sizeof(pContext->addr);
574 DWORD stdFlags = 0;
575 int nRet =
576 WSARecvFrom(m_nUDPSocket, &pContext->wsabuf, 1, NULL, &stdFlags, reinterpret_cast<sockaddr*>(&pContext->addr), &nAddrLen, &pContext->overlapped, NULL);
577 if (nRet == SOCKET_ERROR)
578 {
579 int nErr = WSAGetLastError();
580 if (nErr != WSA_IO_PENDING)
581 {
582 perror("WSARecvFrom (re-post) failed!");
583 }
584 }
585 }
586#else
587 // Create a batch of RoveCommData structures to receive multiple packets at once.
588 constexpr size_t BATCH_SIZE = 32;
589 std::array<uint8_t, ROVECOMM_PACKET_MAX_DATA_SIZE> aDataBatch[BATCH_SIZE];
590 struct iovec aIOVecs[BATCH_SIZE];
591 struct mmsghdr aMsgVec[BATCH_SIZE];
592 sockaddr_in aAddrs[BATCH_SIZE];
593
594 // Initialize the aIOVecs and aMsgVec arrays. These are used by the recvmmsg function.
595 memset(aMsgVec, 0, sizeof(aMsgVec));
596 for (size_t siIter = 0; siIter < BATCH_SIZE; siIter++)
597 {
598 aIOVecs[siIter].iov_base = aDataBatch[siIter].data();
599 aIOVecs[siIter].iov_len = aDataBatch[siIter].size();
600 aMsgVec[siIter].msg_hdr.msg_iov = &aIOVecs[siIter];
601 aMsgVec[siIter].msg_hdr.msg_iovlen = 1;
602 aMsgVec[siIter].msg_hdr.msg_name = &aAddrs[siIter];
603 aMsgVec[siIter].msg_hdr.msg_namelen = sizeof(sockaddr_in);
604 }
605
606 // Acquire a write lock on the socket receive mutex to protect the socket, which is shared between threads, but not thread-safe.
607 std::unique_lock lkSocketReceiveLock(m_muSocketReceiveMutex);
608
609 // Receive a batch of packets.
610 int nRet = recvmmsg(m_nUDPSocket, aMsgVec, BATCH_SIZE, MSG_DONTWAIT, nullptr);
611 if (nRet < 0)
612 {
613 // Still waiting for data or connection return without error.
614 if (errno != EAGAIN && errno != EWOULDBLOCK)
615 {
616 perror("Failed to receive data from UDP socket using recvmmsg.");
617 }
618 return;
619 }
620 // Release the lock.
621 lkSocketReceiveLock.unlock();
622
623 // Process each received packet.
624 for (int nIter = 0; nIter < nRet; nIter++)
625 {
626 // Get the data and client address from the received packet.
627 size_t siBytesReceived = aMsgVec[nIter].msg_len;
628 if (siBytesReceived < ROVECOMM_PACKET_HEADER_SIZE)
629 {
630 throw std::runtime_error("Not enough data to parse RoveCommPacket header.");
631 }
632 std::span<uint8_t> spData{aDataBatch[nIter].data(), siBytesReceived};
633 sockaddr_in& saClientAddr = aAddrs[nIter];
634 // Extract the data id and data type from the packet.
635 uint16_t unDataId = (static_cast<uint16_t>(spData[1]) << 8) | static_cast<uint16_t>(spData[2]);
636 manifest::DataTypes eDataType = static_cast<manifest::DataTypes>(spData[5]);
637
638 switch (eDataType)
639 {
640 case manifest::DataTypes::UINT8_T: ProcessPacket<uint8_t>(spData, saClientAddr); break;
641 case manifest::DataTypes::INT8_T: ProcessPacket<int8_t>(spData, saClientAddr); break;
642 case manifest::DataTypes::UINT16_T: ProcessPacket<uint16_t>(spData, saClientAddr); break;
643 case manifest::DataTypes::INT16_T: ProcessPacket<int16_t>(spData, saClientAddr); break;
644 case manifest::DataTypes::UINT32_T: ProcessPacket<uint32_t>(spData, saClientAddr); break;
645 case manifest::DataTypes::INT32_T: ProcessPacket<int32_t>(spData, saClientAddr); break;
646 case manifest::DataTypes::FLOAT_T: ProcessPacket<float>(spData, saClientAddr); break;
647 case manifest::DataTypes::DOUBLE_T: ProcessPacket<double>(spData, saClientAddr); break;
648 case manifest::DataTypes::CHAR: ProcessPacket<char>(spData, saClientAddr); break;
649 }
650 }
651#endif
652 }
void ProcessPacket(std::span< const uint8_t > stData, const sockaddr_in &saClientAddr)
Process a UDP packet and invoke the appropriate callback function. This function is called from the R...
Definition RoveCommUDP.cpp:433
std::mutex m_muSocketReceiveMutex
Definition RoveCommUDP.h:101
DataTypes
Enumeration of Data Types to be used in RoveComm.
Definition RoveCommManifest.h:34
const int ROVECOMM_PACKET_HEADER_SIZE
Definition RoveCommConsts.h:26
Here is the call graph for this function:
Here is the caller graph for this function:

◆ RemoveCallback()

template<typename T>
void rovecomm::RoveCommUDP::RemoveCallback ( const CallbackHandle & stHandle)
private

Remove the one callback identified by a handle from this node's map for payload type T.

Template Parameters
T- The payload type the handle was registered with.
Parameters
stHandle- The handle On() returned for the callback.
Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2026-09-26
392 {
393 // Acquire a write lock. This waits for a callback that is already running.
394 std::unique_lock lkCallbackLock(m_muCallbackMutex);
395
396 // Find the callbacks for the handle's data ID and drop the one with the handle's ID.
397 CallbackMap<T>& umCallbacks = GetCallbackMap<T>();
398 auto itEntry = umCallbacks.find(stHandle.unDataId);
399 if (itEntry == umCallbacks.end())
400 {
401 return;
402 }
403 std::erase_if(itEntry->second, [&stHandle](const CallbackEntry<T>& stEntry) { return stEntry.ullID == stHandle.ullID; });
404
405 // Drop the data ID entirely once its last callback is gone.
406 if (itEntry->second.empty())
407 {
408 umCallbacks.erase(itEntry);
409 }
410 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Subscribe()

ssize_t rovecomm::RoveCommUDP::Subscribe ( const manifest::AddressEntry & stIPAddress,
int nPort = manifest::General::ETHERNET_UDP_PORT )
inline
221 {
222 return WriteTo(RoveCommPacket<uint8_t>{.unDataId = manifest::System::SUBSCRIBE_DATA_ID, .vData = {}}, stIPAddress, nPort);
223 }
ssize_t WriteTo(const RoveCommPacket< T > &stPacket, const manifest::AddressEntry &stIPAddress, int nPort=manifest::General::ETHERNET_UDP_PORT)
Sends a packet to a specific destination. This is often used to send a command to a specific device.
Definition RoveCommUDP.h:143
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ThreadedContinuousCode()

void rovecomm::RoveCommUDP::ThreadedContinuousCode ( )
overrideprivatevirtual

Initialize the thread that will continuously receive UDP packets and invoke the appropriate callback function. This is a component of the AutonomyThread class and is called when the thread is started.

Note
This function is not intended to be called directly. It is called from the AutonomyThread class. After the thread has been started.
Author
Eli Byrd (edbgk.nosp@m.k@ms.nosp@m.t.edu)
Date
2024-02-07

Implements AutonomyThread< void >.

666 {
667 // Start the thread pool to receive multiple packets at once.
668 this->RunDetachedPool(10, 5);
669 // Wait for thread pool to finish.
670 this->JoinPool();
671 }
void RunDetachedPool(const unsigned int nNumTasksToQueue, const unsigned int nNumThreads=2, const bool bForceStopCurrentThreads=false)
Definition AutonomyThread.hpp:384
void JoinPool()
Definition AutonomyThread.hpp:487
Here is the call graph for this function:

◆ Unsubscribe()

ssize_t rovecomm::RoveCommUDP::Unsubscribe ( const manifest::AddressEntry & stIPAddress,
int nPort = manifest::General::ETHERNET_UDP_PORT )
inline
226 {
227 return WriteTo(RoveCommPacket<uint8_t>{.unDataId = manifest::System::UNSUBSCRIBE_DATA_ID, .vData = {}}, stIPAddress, nPort);
228 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Write() [1/3]

template<typename T>
ssize_t rovecomm::RoveCommUDP::Write ( const RoveCommPacket< T > & stPacket)
inline

Sends a packet to all subscribers. This is often used to send errors or telemetry data to all devices that have subscribed to this node.

Template Parameters
T- The payload type of the packet. Must be one of the manifest's types.
Parameters
stPacket- The packet to be sent.
Returns
ssize_t - The number of bytes sent, or -1 if an error occurred.
Author
OcelotEmpire (hobbz.nosp@m..pi@.nosp@m.gmail.nosp@m..com)
Date
2026-10-23
161 {
162 // std::set is non-contiguous, so we need to copy the subscribers into a contiguous vector before passing it to WriteAll().
163 // In C++26 we will have std::flat_set, which will allow us to avoid this copy.
164 std::vector<std::pair<manifest::AddressEntry, int>> vDestinations(m_seSubscribers.begin(), m_seSubscribers.end());
165 return WriteAll(stPacket, vDestinations);
166 }
ssize_t WriteAll(const RoveCommPacket< T > &stPacket, std::span< const std::pair< manifest::AddressEntry, int > > spDestinations)
Sends a packet to all specified destinations. This is more efficient than using WriteTo() multiple ti...
Definition RoveCommUDP.cpp:211
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Write() [2/3]

template<typename manifest::ManifestEntry Entry>
ssize_t rovecomm::RoveCommUDP::Write ( std::initializer_list< EntryType< Entry > > ilData)
inline
186 {
187 // Necessary because std::initializer_list cannot be deduced as std::span for some stupid reason: https://isocpp.org/files/papers/P4144R1.html
188 return Write(rovecomm::CreatePacket<Entry>(ilData));
189 }
ssize_t Write(const RoveCommPacket< T > &stPacket)
Sends a packet to all subscribers. This is often used to send errors or telemetry data to all devices...
Definition RoveCommUDP.h:160
RoveCommPacket< EntryType< Entry > > CreatePacket()
Definition RoveCommPacket.h:117
Here is the call graph for this function:

◆ Write() [3/3]

template<typename manifest::ManifestEntry Entry>
ssize_t rovecomm::RoveCommUDP::Write ( std::span< const EntryType< Entry > > spData)
inline

Writes a packet, checked against the manifest.

Template Parameters
Entry-
Parameters
spData-
Returns
ssize_t -
Author
OcelotEmpire (hobbz.nosp@m..pi@.nosp@m.gmail.nosp@m..com)
Date
2026-10-23
180 {
181 return Write(rovecomm::CreatePacket<Entry>(spData));
182 }
Here is the call graph for this function:

◆ WriteAll()

template<typename T>
template ssize_t rovecomm::RoveCommUDP::WriteAll< char > ( const RoveCommPacket< T > & stPacket,
std::span< const std::pair< manifest::AddressEntry, int > > spDestinations )

Sends a packet to all specified destinations. This is more efficient than using WriteTo() multiple times, as it uses sendmmsg() on Linux and sends the same packet to multiple destinations in one call.

Template Parameters
T- The payload type of the packet. Must be one of the manifest's types.
Parameters
stPacket- The packet to be sent.
spDestinations- A span of pairs of AddressEntry and port number, representing the destinations to send the packet to.
Returns
ssize_t - The number of bytes sent, or -1 if an error occurred.
Author
OcelotEmpire (hobbz.nosp@m..pi@.nosp@m.gmail.nosp@m..com)
Date
2026-10-23
212 {
213 // Pack the RoveCommPacket into a RoveCommData structure
214 std::vector<uint8_t> vData = PackPacket(stPacket);
215 // Get size of data not including the data not filled. (the null/zero data in RoveCommData)
216 size_t siDataSize = ROVECOMM_PACKET_HEADER_SIZE + stPacket.GetDataSize();
217
218#if defined(__ROVECOMM_WINDOWS_MODE__) && __ROVECOMM_WINDOWS_MODE__ == 1
219 // Setup the base UDP client address
220 struct sockaddr_in saUDPClientAddr;
221 memset(&saUDPClientAddr, 0, sizeof(saUDPClientAddr));
222 saUDPClientAddr.sin_family = AF_INET;
223
224 // Send the packet to all subscribers
225 for (const auto& [stSubscriberIPAddress, nSubscriberPort] : spDestinations)
226 {
227 // Assemble client address.
228 saUDPClientAddr.sin_port = htons(nSubscriberPort);
229 saUDPClientAddr.sin_addr.s_addr = htonl(stSubscriberIPAddress.FIRST_OCTET << 24 | stSubscriberIPAddress.SECOND_OCTET << 16 |
230 stSubscriberIPAddress.THIRD_OCTET << 8 | stSubscriberIPAddress.FOURTH_OCTET);
231 // Acquire a write lock on the socket send mutex to protect the socket, which is shared between threads, but not thread-safe.
232 std::unique_lock lkSocketSendLock(m_muSocketSendMutex);
233 // Send data.
234 if (sendto(m_nUDPSocket, reinterpret_cast<char*>(&spData), siDataSize, 0, (struct sockaddr*) &saUDPClientAddr, sizeof(saUDPClientAddr)) == -1)
235 {
236 // Handle and print error message.
237 perror("Failed to send data to UDP client socket subscriber.");
238 }
239 // Release the lock.
240 lkSocketSendLock.unlock();
241 }
242
243 // Send the packet to the specified IP address and port.
244 if (stIPAddress != manifest::AddressEntry{0, 0, 0, 0} && nPort != 0)
245 {
246 saUDPClientAddr.sin_port = htons(nPort);
247 saUDPClientAddr.sin_addr.s_addr =
248 htonl(stIPAddress.FIRST_OCTET << 24 | stIPAddress.SECOND_OCTET << 16 | stIPAddress.THIRD_OCTET << 8 | stIPAddress.FOURTH_OCTET);
249
250 // Acquire a write lock on the socket send mutex to protect the socket, which is shared between threads, but not thread-safe.
251 std::unique_lock lkSocketSendLock(m_muSocketSendMutex);
252 return sendto(m_nUDPSocket, reinterpret_cast<char*>(vData.data()), siDataSize, 0, (struct sockaddr*) &saUDPClientAddr, sizeof(saUDPClientAddr));
253 }
254
255 return -1;
256#else
257 // Use sendmmsg to send the same packet to multiple destinations in one call.
258 std::vector<sockaddr_in> vDestinations;
259 // Add all subscribers.
260 for (const auto& [stSubscriberIPAddress, nSubscriberPort] : spDestinations)
261 {
262 // Assemble client address.
263 sockaddr_in stdAddr{};
264 stdAddr.sin_family = AF_INET;
265 stdAddr.sin_port = htons(nSubscriberPort);
266 // Convert the IP address to binary form.
267 stdAddr.sin_addr.s_addr = htonl(stSubscriberIPAddress.FIRST_OCTET << 24 | stSubscriberIPAddress.SECOND_OCTET << 16 | stSubscriberIPAddress.THIRD_OCTET << 8 |
268 stSubscriberIPAddress.FOURTH_OCTET);
269 // Add the subscriber to the list of destinations.
270 vDestinations.push_back(stdAddr);
271 }
272
273 // Send the packet to all destinations.
274 if (vDestinations.empty())
275 {
276 return -1;
277 }
278
279 // Get the number of destinations and create the necessary data structures.
280 size_t siCount = vDestinations.size();
281 std::vector<struct mmsghdr> vMsgVec(siCount);
282 std::vector<struct iovec> vIOVecs(siCount);
283 // Send the packet to all destinations.
284 for (size_t siIter = 0; siIter < siCount; siIter++)
285 {
286 // Set the data to be sent.
287 vIOVecs[siIter].iov_base = reinterpret_cast<char*>(vData.data());
288 vIOVecs[siIter].iov_len = siDataSize;
289 memset(&vMsgVec[siIter], 0, sizeof(struct mmsghdr));
290 // Set the destination address.
291 vMsgVec[siIter].msg_hdr.msg_iov = &vIOVecs[siIter];
292 vMsgVec[siIter].msg_hdr.msg_iovlen = 1;
293 vMsgVec[siIter].msg_hdr.msg_name = &vDestinations[siIter];
294 // Set the length of the destination address.
295 vMsgVec[siIter].msg_hdr.msg_namelen = sizeof(sockaddr_in);
296 }
297
298 // Acquire a write lock on the socket send mutex to protect the socket, which is shared between threads, but not thread-safe.
299 std::unique_lock lkSocketSendLock(m_muSocketSendMutex);
300 // Send the packet to all destinations.
301 int nSentMessages = sendmmsg(m_nUDPSocket, vMsgVec.data(), siCount, 0);
302 if (nSentMessages == -1)
303 {
304 perror("sendmmsg error");
305 return -1;
306 }
307 // Do the math to get the number of bytes sent.
308 ssize_t siBytesSent = 0;
309 for (size_t siIter = 0; siIter < siCount; siIter++)
310 {
311 siBytesSent += vIOVecs[siIter].iov_len;
312 }
313
314 // Return the number of packets sent.
315 return siBytesSent;
316#endif
317 }
std::mutex m_muSocketSendMutex
Definition RoveCommUDP.h:100
std::vector< uint8_t > PackPacket(const RoveCommPacket< T > &stPacket)
Create a RoveCommData structure from a RoveCommPacket structure.
Definition RoveCommPacket.cpp:44
Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteTo() [1/3]

template<typename T>
ssize_t rovecomm::RoveCommUDP::WriteTo ( const RoveCommPacket< T > & stPacket,
const manifest::AddressEntry & stIPAddress,
int nPort = manifest::General::ETHERNET_UDP_PORT )
inline

Sends a packet to a specific destination. This is often used to send a command to a specific device.

Template Parameters
T- The payload type of the packet. Must be one of the manifest's types.
Parameters
stPacket- The packet to be sent.
stIPAddress- The IP address of the destination.
nPort- The port number of the destination.
Returns
ssize_t - The number of bytes sent, or -1 if an error occurred.
Author
OcelotEmpire (hobbz.nosp@m..pi@.nosp@m.gmail.nosp@m..com)
Date
2026-10-23
144 {
145 std::pair<manifest::AddressEntry, int> stdDestination{stIPAddress, nPort};
146 return WriteAll(stPacket, std::span<const std::pair<manifest::AddressEntry, int>>{&stdDestination, 1});
147 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteTo() [2/3]

template<typename manifest::ManifestEntry Entry>
ssize_t rovecomm::RoveCommUDP::WriteTo ( std::initializer_list< EntryType< Entry > > ilData,
const manifest::AddressEntry & stIPAddress = manifest::Helpers::FindBoardById(Entry.DATA_ID).ADDRESS,
int nPort = manifest::General::ETHERNET_UDP_PORT )
inline
203 {
204 return WriteTo(rovecomm::CreatePacket<Entry>(ilData), stIPAddress, nPort);
205 }
Here is the call graph for this function:

◆ WriteTo() [3/3]

template<typename manifest::ManifestEntry Entry>
ssize_t rovecomm::RoveCommUDP::WriteTo ( std::span< const EntryType< Entry > > spData,
const manifest::AddressEntry & stIPAddress = manifest::Helpers::FindBoardById(Entry.DATA_ID).ADDRESS,
int nPort = manifest::General::ETHERNET_UDP_PORT )
inline
195 {
196 return WriteTo(rovecomm::CreatePacket<Entry>(spData), stIPAddress, nPort);
197 }
Here is the call graph for this function:

Member Data Documentation

◆ m_muCallbackMutex

std::shared_mutex rovecomm::RoveCommUDP::m_muCallbackMutex
private

◆ m_muSocketReceiveMutex

std::mutex rovecomm::RoveCommUDP::m_muSocketReceiveMutex
private

◆ m_muSocketSendMutex

std::mutex rovecomm::RoveCommUDP::m_muSocketSendMutex
private

◆ m_nUDPSocket

std::atomic_int rovecomm::RoveCommUDP::m_nUDPSocket
private

◆ m_saUDPServerAddr

struct sockaddr_in rovecomm::RoveCommUDP::m_saUDPServerAddr
private

◆ m_seSubscribers

std::set<SubscriberInfo> rovecomm::RoveCommUDP::m_seSubscribers
private

◆ m_tpCallbackMaps

std::tuple<CallbackMap<int8_t>, CallbackMap<uint8_t>, CallbackMap<int16_t>, CallbackMap<uint16_t>, CallbackMap<int32_t>, CallbackMap<uint32_t>, CallbackMap<float>, CallbackMap<double>, CallbackMap<char> > rovecomm::RoveCommUDP::m_tpCallbackMaps
private

◆ m_ullNextCallbackID

uint64_t rovecomm::RoveCommUDP::m_ullNextCallbackID = 1
private

The documentation for this class was generated from the following files: