26#include <shared_mutex>
29#include <unordered_map>
54#if defined(__ROVECOMM_WINDOWS_MODE__) && __ROVECOMM_WINDOWS_MODE__ == 1
69 using CallbackMap = std::unordered_map<uint16_t, std::vector<CallbackEntry<T>>>;
73 std::tuple<CallbackMap<int8_t>,
103#if defined(__ROVECOMM_TESTS_MODE__) && __ROVECOMM_TESTS_MODE__ == 1
109 void ProcessPacket(std::span<const uint8_t> stData,
const sockaddr_in& saClientAddr);
128 ssize_t
WriteAll(
const RoveCommPacket<T>& stPacket, std::span<
const std::pair<manifest::AddressEntry, int>> spDestinations);
145 std::pair<manifest::AddressEntry, int> stdDestination{stIPAddress, nPort};
146 return WriteAll(stPacket, std::span<
const std::pair<manifest::AddressEntry, int>>{&stdDestination, 1});
165 return WriteAll(stPacket, vDestinations);
178 template<
typename manifest::ManifestEntry Entry>
184 template<
typename manifest::ManifestEntry Entry>
191 template<
typename manifest::ManifestEntry Entry>
199 template<
typename manifest::ManifestEntry Entry>
212 template<
typename manifest::ManifestEntry Entry>
215 return On(Entry.DATA_ID, fnCallback);
ExternalIncludes.h is a file that is included in the RoveComm library to include external dependencie...
Defines Global Constants within RoveComm C++.
RoveComm Packet Definition.
AutonomyThread()
Definition AutonomyThread.hpp:75
IPS & GetIPS()
Accessor for the Frame I P S private member.
Definition AutonomyThread.hpp:242
std::set< SubscriberInfo > m_seSubscribers
Definition RoveCommUDP.h:98
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
~RoveCommUDP()
Destroy the RoveCommUDP::RoveCommUDP object.
Definition RoveCommUDP.cpp:91
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
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)
Definition RoveCommUDP.h:192
void Close()
Close the UDP socket. This method is called when the RoveCommUDP object is destroyed....
Definition RoveCommUDP.cpp:696
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 ...
Definition RoveCommUDP.cpp:110
std::mutex m_muSocketSendMutex
Definition RoveCommUDP.h:100
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
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
RoveCommUDP()
Construct a new RoveCommUDP::RoveCommUDP object.
Definition RoveCommUDP.cpp:75
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
std::mutex m_muSocketReceiveMutex
Definition RoveCommUDP.h:101
void ThreadedContinuousCode() override
Initialize the thread that will continuously receive UDP packets and invoke the appropriate callback ...
Definition RoveCommUDP.cpp:665
std::pair< manifest::AddressEntry, int > SubscriberInfo
Definition RoveCommUDP.h:97
constexpr CallbackMap< T > & GetCallbackMap()
Definition RoveCommUDP.h:86
ssize_t Subscribe(const manifest::AddressEntry &stIPAddress, int nPort=manifest::General::ETHERNET_UDP_PORT)
Definition RoveCommUDP.h:220
void Clear(const CallbackHandle &stHandle)
Remove the one callback identified by a handle from On(). Other callbacks for the same data ID stay r...
Definition RoveCommUDP.cpp:357
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
ssize_t Write(std::initializer_list< EntryType< Entry > > ilData)
Definition RoveCommUDP.h:185
std::shared_mutex m_muCallbackMutex
Definition RoveCommUDP.h:99
CallbackHandle On(std::function< void(const RoveCommPacket< EntryType< Entry > > &)> fnCallback)
Definition RoveCommUDP.h:213
void ReceiveAndCallback()
Receive a UDP packet and invoke the appropriate callback function. Since data types are not known at ...
Definition RoveCommUDP.cpp:481
uint64_t m_ullNextCallbackID
Definition RoveCommUDP.h:83
std::atomic_int m_nUDPSocket
Definition RoveCommUDP.h:95
ssize_t Unsubscribe(const manifest::AddressEntry &stIPAddress, int nPort=manifest::General::ETHERNET_UDP_PORT)
Definition RoveCommUDP.h:225
void PooledLinearCode() override
This method holds the code that is ran in the thread pool started by the ThreadedLinearCode() method....
Definition RoveCommUDP.cpp:684
std::unordered_map< uint16_t, std::vector< CallbackEntry< T > > > CallbackMap
Definition RoveCommUDP.h:69
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
ssize_t Write(std::span< const EntryType< Entry > > spData)
Writes a packet, checked against the manifest.
Definition RoveCommUDP.h:179
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)
Definition RoveCommUDP.h:200
struct sockaddr_in m_saUDPServerAddr
Definition RoveCommUDP.h:96
const int ETHERNET_UDP_PORT
Definition RoveCommManifest.h:889
const BoardEntry & FindBoardById(uint16_t unDataId)
Definition RoveCommManifest.h:1202
const int UNSUBSCRIBE_DATA_ID
Definition RoveCommManifest.h:906
const int SUBSCRIBE_DATA_ID
Definition RoveCommManifest.h:905
The RoveComm namespace contains all of the functionality for the RoveComm library....
Definition RoveCommConsts.h:23
typename manifest::Helpers::RoveCommToCType< Entry.DATA_TYPE >::c_type EntryType
Definition RoveCommPacket.h:114
RoveCommPacket< EntryType< Entry > > CreatePacket()
Definition RoveCommPacket.h:117
IP Address Object for RoveComm. Default is 0.0.0.0.
Definition RoveCommManifest.h:63
Identifies one callback registered with a node's On(), so Clear() can remove that callback without to...
Definition RoveCommPacket.h:104
The RoveCommPacket struct is used to store data in a packet format for transmission over a network....
Definition RoveCommPacket.h:75
Definition RoveCommUDP.h:62
uint64_t ullID
Definition RoveCommUDP.h:63
std::function< void(const RoveCommPacket< T > &)> fnCallback
Definition RoveCommUDP.h:64