Modules | Enumerations | Functions
Packed Communication

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...
 

Detailed Description

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

/*******************************************************************************
* examples/packedCom.c *
* ==================== *
* *
* Version: 1.0.6 *
* Date : 06.12.17 *
* Author : Peter Weissig *
* *
* If you are changing this file, you may also consider to update *
* demos/diagnosticTool/diagnosticTool.c *
*******************************************************************************/
//*********************************<Included files>*****************************
#include <tucbot/tucbot.h>
#include <tucbot_additionals/structio.h>
#include <tucbot_additionals/packedCom.h>
//*********************************<Types>**************************************
struct sTestPackedCom {
uint8_t data1;
uint8_t data2;
uint16_t data3;
} testPackedComReceive;
//*********************************<Variables>**********************************
volatile uint8_t testPackedCom_count_packets_custom;
//*********************************<Methods>************************************
void packedCom_customRxPacket(uint8_t pd, uint8_t pLen, uint8_t *buffer);
void testPackedCom(void);
int main(void);
//*********************************[packedCom_customRxPacket]*******************
void packedCom_customRxPacket(uint8_t pd, uint8_t pLen, uint8_t *buffer) {
uint8_t i;
uint8_t *data;
if (pd != 0xb1) {
return;
}
if (pLen != sizeof(testPackedComReceive)) {
return;
}
data = (uint8_t *) (&testPackedComReceive);
for (i = 0; i < pLen; i++) {
data[i] = buffer[i];
}
testPackedCom_count_packets_custom++;
}
//*********************************[testPackedCom]******************************
void testPackedCom(void) {
uint8_t value_active = 0x00;
uint8_t value_count = 0;
uint8_t value_error = 0;
uint16_t value_data = 0;
uint16_t temp;
struct sTestPackedCom testPackedComSend;
testPackedComSend.data1 = 'T';
testPackedComSend.data2 = 'S';
testPackedComSend.data3 = 0;
testPackedCom_count_packets_custom = 0;
lcdclr();
lcdstr_p(PSTR("packedCom # ###"));
lcdxy(0,1);
lcdstr_p(PSTR("err=### v=#####"));
while (1) {
// check if buttons were pushed
// middle button --> send packed data via serstructsendx
mdelay(100);
testPackedComSend.data3++;
// send data through UART0 and UART1
// (data will be send via usb-connector and xbee)
serstructsend0(&testPackedComSend, sizeof(testPackedComSend),
0xb1);
serstructsend1(&testPackedComSend, sizeof(testPackedComSend),
0xb1);
} else if (buttons_get(kButtonRight)) {
// right button --> toggle packed communication (on/off)
mdelay(100);
if (value_active) {
} else {
}
}
// update display
if (temp != value_active) {
value_active = temp;
lcdxy(10,0);
if (temp) {
lcdout('-');
} else {
lcdout('!');
}
}
temp = testPackedCom_count_packets_custom;
if (temp != value_count) {
value_count = temp;
lcdxy(13,0); uint16tostr(lcdout,temp,3);
}
if (temp != value_error) {
value_count = temp;
lcdxy(4,1); uint16tostr(lcdout,temp,3);
}
cli();
temp = testPackedComReceive.data3;
sei();
if (temp != value_data) {
value_data = temp;
lcdxy(11,1); uint16tostr(lcdout,temp,5);
}
mdelay(100);
}
}
//*********************************[main]***************************************
int main (void) {
init_tucbot(0xFF);
testPackedCom();
return (0);
}

Enumeration Type Documentation

◆ ePackedComGet

clusters select values for reading the distance measurements

See also
packedCom_get()
Enumerator
kPackedComGetActive 

constants (1): returns if packedCom is active or not (boolean value)

kPackedComGetPacketCount 

constants (2): number of correct received packets

kPackedComGetErrorCount 

constants (3): number of errors during reception

Function Documentation

◆ packedCom_activate()

void packedCom_activate ( void  )

Turns the reception of data packets on.

See also
packedCom_deactivate()
Examples
lausTracker.c, packedCom.c, and remoteControl.c.

◆ packedCom_customRxPacket()

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.

Note
crc16 check is automatically performed.
Parameters
pdDetected packet descriptor.
pLenLength 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.
bufferPointer to the data.
Examples
packedCom.c.

◆ packedCom_deactivate()

void packedCom_deactivate ( void  )

Turns the reception of data packets off.

See also
packedCom_activate()
Examples
packedCom.c.

◆ packedCom_get()

uint8_t packedCom_get ( ePackedComGet  select)

Returns the last stored selected value.

Parameters
selectvalue to be selected - see also ePackedComGet
Returns
8-bit unsigned integer
Examples
lausTracker.c, packedCom.c, and remoteControl.c.
leds_set
void leds_set(eLedMask bitmask, uint8_t bool)
Sets the selected leds on or off.
buttons_get
eButtonMask buttons_get(eButtonMask bitmask)
Returns the last stored value of the selected buttons.
kButtonMiddle
@ kButtonMiddle
bit mask (0x08): middle button
Definition: buttons.h:35
kLedOn
@ kLedOn
constant (0xFF): turn leds on
Definition: leds.h:63
kLedRight
@ kLedRight
bit mask (0x04): right led
Definition: leds.h:46
kButtonRight
@ kButtonRight
bit mask (0x10): right button
Definition: buttons.h:37
kPackedComGetErrorCount
@ kPackedComGetErrorCount
constants (3): number of errors during reception
Definition: packedCom.h:266
serstructsend1
void serstructsend1(void *data, uint16_t cnt, uint8_t pd)
Send packed data over the UART1 serial interface.
buttons_request
void buttons_request(eRequestType request)
Requests new data from the buttons.
kRequestContinuous
@ kRequestContinuous
constant (3): request continuous updates
Definition: update.h:37
packedCom_deactivate
void packedCom_deactivate(void)
Turns the reception of data packets off.
kLedMiddle
@ kLedMiddle
bit mask (0x08): middle led
Definition: leds.h:44
kLedOff
@ kLedOff
constant (0x00): turn leds off
Definition: leds.h:61
uint16tostr
void uint16tostr(void *out, uint16_t number, uint8_t digits)
Converts an unsigned integer to a string and passes it to an output function.
packedCom_activate
void packedCom_activate(void)
Turns the reception of data packets on.
lcdclr
void lcdclr(void)
Clears the display.
packedCom_get
uint8_t packedCom_get(ePackedComGet select)
Returns the last stored selected value.
lcdxy
void lcdxy(uint8_t x, uint8_t y)
Moves the cursor to a postion on the display.
kPackedComGetActive
@ kPackedComGetActive
constants (1): returns if packedCom is active or not (boolean value)
Definition: packedCom.h:262
lcdstr_p
void lcdstr_p(const char *send_data)
Writes a string located in the flash to the display.
lcdout
void lcdout(uint8_t data)
Writes one byte to the display.
serstructsend0
void serstructsend0(void *data, uint16_t cnt, uint8_t pd)
Send packed data over the UART0 serial interface.
init_tucbot
void init_tucbot(uint8_t enable_interrupts)
Initiates the TUC-Bot.
mdelay
void mdelay(uint16_t mseconds)
Waits for the given time in milliseconds.
packedCom_customRxPacket
void packedCom_customRxPacket(uint8_t pd, uint8_t pLen, uint8_t *buffer)
Weak function for custom packet descriptors.