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 Namespace Reference

The RoveComm namespace contains all of the functionality for the RoveComm library. This includes the packet structure and the functions for packing and unpacking data. More...

Classes

struct  RoveCommPacket
 The RoveCommPacket struct is used to store data in a packet format for transmission over a network. This struct is used to store the data ID, data count, data type, and the data itself. The data is stored in a vector of the specified data type. More...
struct  CallbackHandle
 Identifies one callback registered with a node's On(), so Clear() can remove that callback without touching any other callback for the same data ID. A default-constructed handle is empty and Clear() ignores it. More...
class  RoveCommTCP
 The RoveCommTCP class is used to send and receive data over a TCP connection. More...
class  RoveCommUDP
 The RoveCommUDP class is used to send and receive data over a UDP connection. More...

Typedefs

template<manifest::ManifestEntry Entry>
using EntryType = typename manifest::Helpers::RoveCommToCType<Entry.DATA_TYPE>::c_type

Functions

template<typename T>
std::vector< uint8_t > PackPacket (const RoveCommPacket< T > &stPacket)
 Create a RoveCommData structure from a RoveCommPacket structure.
template std::vector< uint8_t > PackPacket< uint8_t > (const RoveCommPacket< uint8_t > &stPacket)
template std::vector< uint8_t > PackPacket< uint16_t > (const RoveCommPacket< uint16_t > &stPacket)
template std::vector< uint8_t > PackPacket< uint32_t > (const RoveCommPacket< uint32_t > &stPacket)
template std::vector< uint8_t > PackPacket< int8_t > (const RoveCommPacket< int8_t > &stPacket)
template std::vector< uint8_t > PackPacket< int16_t > (const RoveCommPacket< int16_t > &stPacket)
template std::vector< uint8_t > PackPacket< int32_t > (const RoveCommPacket< int32_t > &stPacket)
template std::vector< uint8_t > PackPacket< float > (const RoveCommPacket< float > &stPacket)
template std::vector< uint8_t > PackPacket< double > (const RoveCommPacket< double > &stPacket)
template std::vector< uint8_t > PackPacket< char > (const RoveCommPacket< char > &stPacket)
template<typename T>
RoveCommPacket< T > UnpackData (std::span< const uint8_t > spBytes)
 Create a RoveCommPacket structure from a RoveCommData structure.
template RoveCommPacket< uint8_t > UnpackData< uint8_t > (std::span< const uint8_t >)
template RoveCommPacket< uint16_t > UnpackData< uint16_t > (std::span< const uint8_t >)
template RoveCommPacket< uint32_t > UnpackData< uint32_t > (std::span< const uint8_t >)
template RoveCommPacket< int8_t > UnpackData< int8_t > (std::span< const uint8_t >)
template RoveCommPacket< int16_t > UnpackData< int16_t > (std::span< const uint8_t >)
template RoveCommPacket< int32_t > UnpackData< int32_t > (std::span< const uint8_t >)
template RoveCommPacket< float > UnpackData< float > (std::span< const uint8_t >)
template RoveCommPacket< double > UnpackData< double > (std::span< const uint8_t >)
template RoveCommPacket< char > UnpackData< char > (std::span< const uint8_t >)
template<manifest::ManifestEntry Entry>
RoveCommPacket< EntryType< Entry > > CreatePacket ()
template<manifest::ManifestEntry Entry, manifest::RoveCommType... Args>
RoveCommPacket< EntryType< Entry > > CreatePacket (Args... args)
template<manifest::ManifestEntry Entry>
RoveCommPacket< EntryType< Entry > > CreatePacket (std::span< const EntryType< Entry > > spData)
template<manifest::ManifestEntry Entry>
RoveCommPacket< EntryType< Entry > > CreatePacket (std::initializer_list< EntryType< Entry > > ilData)

Variables

const int ROVECOMM_ETHERNET_UDP_MAX_SUBSCRIBERS = 10
const int ROVECOMM_PACKET_MAX_DATA_SIZE = 65535 / 3
const int ROVECOMM_PACKET_HEADER_SIZE = 6
const int ROVECOMM_VERSION = 3
const int ROVECOMM_THREAD_MAX_IPS = 120

Detailed Description

The RoveComm namespace contains all of the functionality for the RoveComm library. This includes the packet structure and the functions for packing and unpacking data.

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

Typedef Documentation

◆ EntryType

template<manifest::ManifestEntry Entry>
using rovecomm::EntryType = typename manifest::Helpers::RoveCommToCType<Entry.DATA_TYPE>::c_type

Function Documentation

◆ CreatePacket() [1/4]

template<manifest::ManifestEntry Entry>
RoveCommPacket< EntryType< Entry > > rovecomm::CreatePacket ( )
118 {
119 RoveCommPacket<EntryType<Entry>> stPacket{.unDataId = Entry.DATA_ID, .vData = {}};
120 stPacket.vData.resize(Entry.DATA_COUNT);
121 return stPacket;
122 }
The RoveCommPacket struct is used to store data in a packet format for transmission over a network....
Definition RoveCommPacket.h:75
std::vector< T > vData
Definition RoveCommPacket.h:78
Here is the caller graph for this function:

◆ CreatePacket() [2/4]

template<manifest::ManifestEntry Entry, manifest::RoveCommType... Args>
RoveCommPacket< EntryType< Entry > > rovecomm::CreatePacket ( Args... args)
126 {
127 // Assume that the user expects the data count to be exactly correct since they are entering the arguments directly.
128 // The runtime functions will extend or truncate the data as needed.
129 static_assert(sizeof...(Args) == Entry.DATA_COUNT, "The number of arguments provided does not match the data count specified in the manifest entry.");
130 return {.unDataId = Entry.DATA_ID, .vData = {args...}};
131 }

◆ CreatePacket() [3/4]

template<manifest::ManifestEntry Entry>
RoveCommPacket< EntryType< Entry > > rovecomm::CreatePacket ( std::initializer_list< EntryType< Entry > > ilData)
143 {
144 RoveCommPacket<EntryType<Entry>> stPacket = {.unDataId = Entry.DATA_ID, .vData = ilData};
145 stPacket.vData.resize(Entry.DATA_COUNT);
146 return stPacket;
147 }

◆ CreatePacket() [4/4]

template<manifest::ManifestEntry Entry>
RoveCommPacket< EntryType< Entry > > rovecomm::CreatePacket ( std::span< const EntryType< Entry > > spData)
135 {
136 RoveCommPacket<EntryType<Entry>> stPacket = {.unDataId = Entry.DATA_ID, .vData = {spData.begin(), spData.end()}};
137 stPacket.vData.resize(Entry.DATA_COUNT);
138 return stPacket;
139 }

◆ PackPacket()

template<typename T>
std::vector< uint8_t > rovecomm::PackPacket ( const RoveCommPacket< T > & stPacket)

Create a RoveCommData structure from a RoveCommPacket structure.

Template Parameters
T- The type of data that is to be sent or received. This can be any of the types defined in the manifest.
Parameters
stPacket- The packet to be packed into a RoveCommData structure.
Returns
RoveCommData - The packed data.
Note
The accepted versions of the Pack Packet function are templated and are explicitly instantiated at the end of this file.
Author
Eli Byrd (edbgk.nosp@m.k@ms.nosp@m.t.edu)
Date
2024-02-07
45 {
46 size_t siPacketSize = ROVECOMM_PACKET_HEADER_SIZE + stPacket.GetDataSize();
47 if (siPacketSize > ROVECOMM_PACKET_MAX_DATA_SIZE)
48 {
49 throw std::runtime_error("RoveComm Packet Exceeds Maximum Packet Size.");
50 }
51 std::vector<uint8_t> vData;
52 vData.reserve(siPacketSize);
53
54 // The first byte of the data is the version number
55 vData.push_back(ROVECOMM_VERSION);
56
57 // The next two bytes are the data ID
58 vData.push_back(stPacket.unDataId >> 8);
59 vData.push_back(stPacket.unDataId);
60
61 // The next two bytes are the data count
62 vData.push_back(stPacket.GetDataCount() >> 8);
63 vData.push_back(stPacket.GetDataCount());
64
65 // The next byte is the data type
66 vData.push_back(stPacket.GetDataType());
67
68 // The rest of the data is the data payload
69 // Loop through data.
70 for (T tEl : stPacket.vData)
71 {
72 // INT8_T, UINT8_T, CHAR
74 {
75 // No need to convert to network order.
76 vData.push_back(tEl);
77 }
78 // INT16_T, UINT16_T
79 else if constexpr (manifest::Helpers::CToRoveCommType<T>::SIZE == 2)
80 {
81 // Convert to network order and add to RoveCommData.
82 uint16_t unResult;
83 memcpy(&unResult, &tEl, sizeof(unResult));
84 vData.push_back(static_cast<uint8_t>(unResult >> (8 * 1)));
85 vData.push_back(static_cast<uint8_t>(unResult >> (8 * 0)));
86 }
87 // INT32_T, UINT32_T, FLOAT_T
88 else if constexpr (manifest::Helpers::CToRoveCommType<T>::SIZE == 4)
89 {
90 // Convert to network order and add to RoveCommData.
91 uint32_t unResult;
92 memcpy(&unResult, &tEl, sizeof(unResult));
93 vData.push_back(static_cast<uint8_t>(unResult >> (8 * 3)));
94 vData.push_back(static_cast<uint8_t>(unResult >> (8 * 2)));
95 vData.push_back(static_cast<uint8_t>(unResult >> (8 * 1)));
96 vData.push_back(static_cast<uint8_t>(unResult >> (8 * 0)));
97 }
98 // DOUBLE_T
99 else if constexpr (manifest::Helpers::CToRoveCommType<T>::SIZE == 8)
100 {
101 // Convert to network order and add to RoveCommData.
102 uint64_t unResult;
103 memcpy(&unResult, &tEl, sizeof(unResult));
104 vData.push_back(static_cast<uint8_t>(unResult >> (8 * 7)));
105 vData.push_back(static_cast<uint8_t>(unResult >> (8 * 6)));
106 vData.push_back(static_cast<uint8_t>(unResult >> (8 * 5)));
107 vData.push_back(static_cast<uint8_t>(unResult >> (8 * 4)));
108 vData.push_back(static_cast<uint8_t>(unResult >> (8 * 3)));
109 vData.push_back(static_cast<uint8_t>(unResult >> (8 * 2)));
110 vData.push_back(static_cast<uint8_t>(unResult >> (8 * 1)));
111 vData.push_back(static_cast<uint8_t>(unResult >> (8 * 0)));
112 }
113 }
114
115 return vData;
116 }
const int ROVECOMM_PACKET_HEADER_SIZE
Definition RoveCommConsts.h:26
const int ROVECOMM_PACKET_MAX_DATA_SIZE
Definition RoveCommConsts.h:25
const int ROVECOMM_VERSION
Definition RoveCommConsts.h:27
Definition RoveCommManifest.h:1263
uint16_t unDataId
Definition RoveCommPacket.h:77
uint8_t GetDataType() const
Definition RoveCommPacket.h:85
size_t GetDataSize() const
Definition RoveCommPacket.h:83
uint16_t GetDataCount() const
Definition RoveCommPacket.h:81
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PackPacket< char >()

template std::vector< uint8_t > rovecomm::PackPacket< char > ( const RoveCommPacket< char > & stPacket)

◆ PackPacket< double >()

template std::vector< uint8_t > rovecomm::PackPacket< double > ( const RoveCommPacket< double > & stPacket)

◆ PackPacket< float >()

template std::vector< uint8_t > rovecomm::PackPacket< float > ( const RoveCommPacket< float > & stPacket)

◆ PackPacket< int16_t >()

template std::vector< uint8_t > rovecomm::PackPacket< int16_t > ( const RoveCommPacket< int16_t > & stPacket)

◆ PackPacket< int32_t >()

template std::vector< uint8_t > rovecomm::PackPacket< int32_t > ( const RoveCommPacket< int32_t > & stPacket)

◆ PackPacket< int8_t >()

template std::vector< uint8_t > rovecomm::PackPacket< int8_t > ( const RoveCommPacket< int8_t > & stPacket)

◆ PackPacket< uint16_t >()

template std::vector< uint8_t > rovecomm::PackPacket< uint16_t > ( const RoveCommPacket< uint16_t > & stPacket)

◆ PackPacket< uint32_t >()

template std::vector< uint8_t > rovecomm::PackPacket< uint32_t > ( const RoveCommPacket< uint32_t > & stPacket)

◆ PackPacket< uint8_t >()

template std::vector< uint8_t > rovecomm::PackPacket< uint8_t > ( const RoveCommPacket< uint8_t > & stPacket)

◆ UnpackData()

template<typename T>
RoveCommPacket< T > rovecomm::UnpackData ( std::span< const uint8_t > spBytes)

Create a RoveCommPacket structure from a RoveCommData structure.

Template Parameters
T- The type of data that is to be sent or received. This can be any of the types defined in the manifest.
Parameters
spBytes- The data to be unpacked into a RoveCommPacket structure.
Returns
RoveCommPacket<T> - The unpacked packet.
Note
The accepted versions of the Unpack Data function are templated and are explicitly instantiated at the end of this file.
Author
Eli Byrd (edbgk.nosp@m.k@ms.nosp@m.t.edu)
Date
2024-02-07
145 {
146 if (spBytes.size() < ROVECOMM_PACKET_HEADER_SIZE)
147 {
148 throw std::runtime_error("Not enough data to parse RoveCommPacket header.");
149 }
150
151 RoveCommPacket<T> stPacket;
152
153 // Extract data from spBytes and fill stPacket
154 stPacket.unDataId = (spBytes[1] << 8) | spBytes[2];
155 uint16_t unDataCount = (spBytes[3] << 8) | spBytes[4];
156 manifest::DataTypes eDataType = static_cast<manifest::DataTypes>(spBytes[5]);
157
158 size_t siPacketSize = ROVECOMM_PACKET_HEADER_SIZE + unDataCount * manifest::Helpers::DataTypeSize(eDataType);
159 if (spBytes.size() < siPacketSize)
160 {
161 throw std::runtime_error("Packet header did not match packet size.");
162 }
163 if (manifest::Helpers::CToRoveCommType<T>::TYPE != eDataType)
164 {
165 throw std::runtime_error("Packet data type does not match.");
166 }
167
168 // Copy the data payload from spBytes to stPacket's vData vector
169 stPacket.vData.reserve(unDataCount);
170
171 // Loop through data.
172 std::span<const uint8_t> spData = spBytes.subspan(ROVECOMM_PACKET_HEADER_SIZE);
173 for (uint16_t unIt = 0; unIt < unDataCount * manifest::Helpers::DataTypeSize(eDataType);)
174 {
175 // INT8_T, UINT8_T, CHAR
176 if constexpr (manifest::Helpers::CToRoveCommType<T>::SIZE == 1)
177 {
178 // No need to convert to host order.
179 stPacket.vData.push_back(spData[unIt++]);
180 }
181 // INT16_T, UINT16_T
182 else if constexpr (manifest::Helpers::CToRoveCommType<T>::SIZE == 2)
183 {
184 // Convert to host order and add to RoveCommData.
185 T tResult;
186 uint16_t unResult = spData[unIt++] << (8 * 1) | //
187 spData[unIt++] << (8 * 0);
188 memcpy(&tResult, &unResult, sizeof(unResult));
189 stPacket.vData.push_back(tResult);
190 }
191 // INT32_T, UINT32_T, FLOAT_T
192 else if constexpr (manifest::Helpers::CToRoveCommType<T>::SIZE == 4)
193 {
194 // Convert to host order and add to RoveCommData.
195 T tResult;
196 uint32_t unResult = spData[unIt++] << (8 * 3) | //
197 spData[unIt++] << (8 * 2) | //
198 spData[unIt++] << (8 * 1) | //
199 spData[unIt++] << (8 * 0);
200 memcpy(&tResult, &unResult, sizeof(unResult));
201 stPacket.vData.push_back(tResult);
202 }
203 // DOUBLE_T
204 else if constexpr (manifest::Helpers::CToRoveCommType<T>::SIZE == 8)
205 {
206 // Convert to host order and add to RoveCommData.
207 T tResult;
208 uint64_t unResult = static_cast<uint64_t>(spData[unIt++]) << (8 * 7) | //
209 static_cast<uint64_t>(spData[unIt++]) << (8 * 6) | //
210 static_cast<uint64_t>(spData[unIt++]) << (8 * 5) | //
211 static_cast<uint64_t>(spData[unIt++]) << (8 * 4) | //
212 static_cast<uint64_t>(spData[unIt++]) << (8 * 3) | //
213 static_cast<uint64_t>(spData[unIt++]) << (8 * 2) | //
214 static_cast<uint64_t>(spData[unIt++]) << (8 * 1) | //
215 static_cast<uint64_t>(spData[unIt++]) << (8 * 0);
216 memcpy(&tResult, &unResult, sizeof(unResult));
217 stPacket.vData.push_back(tResult);
218 }
219 }
220 return stPacket;
221 }
constexpr size_t DataTypeSize(DataTypes eDataType)
Definition RoveCommManifest.h:1244
DataTypes
Enumeration of Data Types to be used in RoveComm.
Definition RoveCommManifest.h:34
Here is the call graph for this function:
Here is the caller graph for this function:

◆ UnpackData< char >()

template RoveCommPacket< char > rovecomm::UnpackData< char > ( std::span< const uint8_t > )

◆ UnpackData< double >()

template RoveCommPacket< double > rovecomm::UnpackData< double > ( std::span< const uint8_t > )

◆ UnpackData< float >()

template RoveCommPacket< float > rovecomm::UnpackData< float > ( std::span< const uint8_t > )
Here is the caller graph for this function:

◆ UnpackData< int16_t >()

template RoveCommPacket< int16_t > rovecomm::UnpackData< int16_t > ( std::span< const uint8_t > )

◆ UnpackData< int32_t >()

template RoveCommPacket< int32_t > rovecomm::UnpackData< int32_t > ( std::span< const uint8_t > )

◆ UnpackData< int8_t >()

template RoveCommPacket< int8_t > rovecomm::UnpackData< int8_t > ( std::span< const uint8_t > )

◆ UnpackData< uint16_t >()

template RoveCommPacket< uint16_t > rovecomm::UnpackData< uint16_t > ( std::span< const uint8_t > )

◆ UnpackData< uint32_t >()

template RoveCommPacket< uint32_t > rovecomm::UnpackData< uint32_t > ( std::span< const uint8_t > )
Here is the caller graph for this function:

◆ UnpackData< uint8_t >()

template RoveCommPacket< uint8_t > rovecomm::UnpackData< uint8_t > ( std::span< const uint8_t > )

Variable Documentation

◆ ROVECOMM_ETHERNET_UDP_MAX_SUBSCRIBERS

const int rovecomm::ROVECOMM_ETHERNET_UDP_MAX_SUBSCRIBERS = 10

◆ ROVECOMM_PACKET_HEADER_SIZE

const int rovecomm::ROVECOMM_PACKET_HEADER_SIZE = 6

◆ ROVECOMM_PACKET_MAX_DATA_SIZE

const int rovecomm::ROVECOMM_PACKET_MAX_DATA_SIZE = 65535 / 3

◆ ROVECOMM_THREAD_MAX_IPS

const int rovecomm::ROVECOMM_THREAD_MAX_IPS = 120

◆ ROVECOMM_VERSION

const int rovecomm::ROVECOMM_VERSION = 3