Heartbeat implementation
This commit is contained in:
parent
3200feaa26
commit
ad58ecee85
@ -161,6 +161,14 @@ arduino_data_t find_packet_from_header(uint8_t header)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#define BYTE1_32BITS_VALUE(x) ((x & 0xFF000000) >> 24)
|
||||||
|
#define BYTE2_32BITS_VALUE(x) ((x & 0x00FF0000) >> 16)
|
||||||
|
#define BYTE3_32BITS_VALUE(x) ((x & 0x0000FF00) >> 8)
|
||||||
|
#define BYTE4_32BITS_VALUE(x) ((x & 0x000000FF) >> 0)
|
||||||
|
|
||||||
|
const uint32_t heartbeat_msg = 0xDEADBEEF;
|
||||||
|
const uint32_t heartbeat_rsp = 0xBA1DFACE;
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* BRIEF: A function that parses the message byte per byte and then
|
* BRIEF: A function that parses the message byte per byte and then
|
||||||
* if it was wrong it will do recursive call and parse the rest
|
* if it was wrong it will do recursive call and parse the rest
|
||||||
@ -175,6 +183,35 @@ void arduino_parse_message(uint8_t data)
|
|||||||
static uint8_t secondary_message_it = 0;
|
static uint8_t secondary_message_it = 0;
|
||||||
static arduino_data_t msg_header_and_size = { .size = 0, .dataPtr = NULL };
|
static arduino_data_t msg_header_and_size = { .size = 0, .dataPtr = NULL };
|
||||||
static uint8_t crc = 0;
|
static uint8_t crc = 0;
|
||||||
|
static uint8_t heartbeatiterator = 0;
|
||||||
|
|
||||||
|
if (heartbeatiterator == 0 && data == BYTE1_32BITS_VALUE(heartbeat_msg))
|
||||||
|
heartbeatiterator = 1;
|
||||||
|
|
||||||
|
if (heartbeatiterator > 0)
|
||||||
|
{
|
||||||
|
switch (heartbeatiterator)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
heartbeatiterator = 2;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
heartbeatiterator = (data == BYTE2_32BITS_VALUE(heartbeat_msg)) ? 3 : 0;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
heartbeatiterator = (data == BYTE3_32BITS_VALUE(heartbeat_msg)) ? 4 : 0;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
heartbeatiterator = 0;
|
||||||
|
if(data == BYTE4_32BITS_VALUE(heartbeat_msg))
|
||||||
|
{
|
||||||
|
usart_transmit(&usartdmaHandler.usart_pro, (uint8_t *) &heartbeat_rsp, 4, 10000);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(find_header)
|
if(find_header)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user