-
Notifications
You must be signed in to change notification settings - Fork 0
Communication
In this section the usage of all communication related features will be explained.
PacketValue is a class with the aim of encapsulating the conversion procedure of a value such that is ready to be sent. It works the following way:

Where:
-
The cast_type is the type that needs to be transmitted or the value received from a sender.
-
The source is a double pointer thats used to store the reference of the lvalue that will store the data sent or received
-
The factor is a number that will multiply the rvalue contained in the source before casting it to the cast_type, this is used to maintain precision in floating point numbers while mainting the bit rate required to transmit the data at minimum. Similary when a new value is stored it is also divided by the factor
It contains 3 methods:
-
convert() which returns the converted value ready to be sent
-
load() which receives the new value received as a parameter, performs the inverse conversion and stores the converted value in the lvalue stored at source
-
size() which returns the size in bytes that the cast_type needs to be stored
A real use case might be the following:
double speed = 5.43;
double factor = 100;
using cast_type = uint16_t
uint16_t variable_to_be_sent;
PacketValue speed_packet_value = PacketValue<cast_type>(&speed,factor);
variable_to_be_sent = speed_packet_value.convert(); //Now variable_to_be_sent contains 543
uint16_t speed_received = 704;
speed_packet_value.load(speed_received); //Now speed contains 7.04
size_t size_of_variable = speed_packet_value.size() //returns sizeof(cast_type) which is 2 in this case
