packedCom.c
/*******************************************************************************
* 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);
}
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.