Functions which use the uart for packed communication. More...
Modules | |
Advanced informations | |
Enumerations | |
enum | ePackedComGet |
clusters select values for reading the distance measurements More... | |
Functions | |
void | packedCom_customRxPacket (uint8_t pd, uint8_t pLen, uint8_t *buffer) |
Weak function for custom packet descriptors. More... | |
uint8_t | packedCom_get (ePackedComGet select) |
Returns the last stored selected value. More... | |
Activation Funktions | |
void | packedCom_activate (void) |
Turns the reception of data packets on. More... | |
void | packedCom_deactivate (void) |
Turns the reception of data packets off. More... | |
Functions which use the uart for packed communication.
It allows the serialization of structs. There is a corresponding Python Module, which handles the data as well as the communication on the PC.
Using the functions serout0(), serfsend0() or etc. is the simplest way for communicating with the PC. However, these functions are not very efficient in terms of bandwidth usage. They send data values as strings. A preferable way, if lots of data packages have to be sent, is sending the data in binary format. Further on, this is referred to as packed communication.
Each communication follows a specific data frame convention:
Side note: If only one byte should be send, this will be a large overhead. Preferably, multiple information sources should be gathered before sending.
For sending data to the PC, the functions serstructsend0() and serstructsend1() can be used. Just define a custom struct, fill it with data and call the function with the pointer to the instance of the struct, the length of the struct in bytes, and a custom packet descriptor defining the type of your struct to distinguish different types of custom structs from each other.
For receiving data on the robot, define a function packedCom_customRxPacket(). This function is already definded in the library, but as a weak function, which means it can be overwritten by your own definition of this function. The working principle is as follows: If the packed communication is enabled by calling packedCom_activate(), all incoming packets are processed depending on their packet descriptors (see above). Some packet descriptors are already defined and used internally by the library. These packages can not be received by the user. Each package with an unknown packet descriptor is relayed to the function packedCom_customRxPacket(). If not re-defined by the user, nothing will happen with an unknown packet. Evaluation of the packet has to be done in user-code, see example below.
For sending and receiving data on the PC, there exists a Python Module. However, a simplified Python counterpart to the TUC-Bot example is given here - it shows how to send data in a packed form to the robot:
customData.py and packedCom.py
example
enum ePackedComGet |
clusters select values for reading the distance measurements
void packedCom_activate | ( | void | ) |
Turns the reception of data packets on.
void packedCom_customRxPacket | ( | uint8_t | pd, |
uint8_t | pLen, | ||
uint8_t * | buffer | ||
) |
Weak function for custom packet descriptors.
This function does nothing - it is just a dummy-function. If you want to evaluate your own packet(s), just define this function in your code to process incoming data.
pd | Detected packet descriptor. |
pLen | Length of data in Bytes. The underlying packets can be up to 64k bytes long. However, because of the buffer sizes (e.g. UART0_TX) the maximum possible length is less. Therefore, pLen is of type uint8_t. |
buffer | Pointer to the data. |
void packedCom_deactivate | ( | void | ) |
uint8_t packedCom_get | ( | ePackedComGet | select | ) |
Returns the last stored selected value.
select | value to be selected - see also ePackedComGet |