Arduino com working with parser and everything (hopefully)
This commit is contained in:
parent
1c0c7fb00f
commit
50bc7bac30
@ -63,3 +63,16 @@ bool arduino_frame_available();
|
||||
void arduino_read();
|
||||
|
||||
#endif /* DRIVERS_ARDUINO_COM_H_ */
|
||||
|
||||
|
||||
|
||||
//----------------------- Example code for the parser --------------------------
|
||||
|
||||
//arduinoCom_init(USART1);
|
||||
//while (1) {
|
||||
// if(arduino_frame_available())
|
||||
// arduino_read();
|
||||
// HAL_Delay(15);
|
||||
// float lng = gps_data.longitude;
|
||||
// float lat = gps_data.latitude;
|
||||
//}
|
||||
|
@ -93,6 +93,13 @@ arduino_data_t find_packet_from_header(uint8_t header)
|
||||
return arduino_data;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
* 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
|
||||
* of the message
|
||||
* INFORMATION: *
|
||||
***********************************************************************/
|
||||
void arduino_parse_message(uint8_t data)
|
||||
{
|
||||
static uint8_t arduino_arr[ARDUINO_DMA_SIZE];
|
||||
@ -172,103 +179,13 @@ void arduino_parse_message(uint8_t data)
|
||||
***********************************************************************/
|
||||
void arduino_read()
|
||||
{
|
||||
static uint8_t arduino_arr[ARDUINO_DMA_SIZE];
|
||||
static uint8_t message_it = 0;
|
||||
static uint32_t missedMsg = 0;
|
||||
static uint8_t message_it_secondary_head = 0;
|
||||
static bool new_header = false;
|
||||
static uint8_t crc = 0;
|
||||
static arduino_data_t msg_header_and_size = { .size = 0, .dataPtr = NULL };
|
||||
static bool find_new_header = true;
|
||||
|
||||
//If the DMA has come to a new buffer
|
||||
if (raw_dma_data_t.new_data)
|
||||
{
|
||||
// parse the entire message to the gps_data and compass_data
|
||||
for (int i = 0; i < ARDUINO_DMA_SIZE; i++)
|
||||
{
|
||||
arduino_parse_message(raw_dma_data_t.buff[i]);
|
||||
|
||||
// uint8_t msg = raw_dma_data_t.buff[i]; //raw_dma_data_t.buff[i];
|
||||
// if(find_new_header)
|
||||
// {
|
||||
// msg_header_and_size = find_packet_from_header(msg);
|
||||
// if(msg_header_and_size.size != 0)
|
||||
// {
|
||||
// find_new_header = false;
|
||||
// arduino_arr[(message_it)] = msg;
|
||||
// message_it++;
|
||||
// new_header = false; // Just received one
|
||||
// crc ^= msg;
|
||||
// }
|
||||
// }
|
||||
// // Look for the end of sbus frame
|
||||
// else
|
||||
// {
|
||||
// /* If we find any new possible header then we should be able to return to that point in time */
|
||||
// if (((arduino_data_t)find_packet_from_header(msg)).size != 0 && new_header == false)
|
||||
// {
|
||||
// new_header = true;
|
||||
// message_it_secondary_head = message_it; //save the value of the position in The buffer array, not the dma array index
|
||||
// }
|
||||
//
|
||||
// /* Reading the message except the crc byte */
|
||||
// if ((message_it) < (msg_header_and_size.size - 1))
|
||||
// {
|
||||
// arduino_arr[(message_it)] = msg;
|
||||
// crc ^= msg;
|
||||
// message_it++;
|
||||
// }
|
||||
// else if ((message_it) == (msg_header_and_size.size - 1))
|
||||
// {
|
||||
// /* put the crc code into the data buffer as well */
|
||||
// arduino_arr[(message_it)] = msg;
|
||||
// missedMsg++;
|
||||
//
|
||||
// /* TODO: Replace with check for CRC */
|
||||
// if (crc == msg)
|
||||
// {
|
||||
// /* Clear necessary variables in order to fill the buffer with new ones */
|
||||
// message_it = 0;
|
||||
// find_new_header = true;
|
||||
// missedMsg--;
|
||||
// crc = 0;
|
||||
//
|
||||
// memcpy(msg_header_and_size.dataPtr, arduino_arr, msg_header_and_size.size);
|
||||
// }
|
||||
//
|
||||
// /* If CRC does not match */
|
||||
// else
|
||||
// {
|
||||
//
|
||||
// int temp_secondaryHeader = message_it_secondary_head;
|
||||
// int length = msg_header_and_size.size;
|
||||
// int new_struct_size = 0;
|
||||
// message_it = message_it - temp_secondaryHeader; //update the counter to the empty part of the updated array
|
||||
//
|
||||
// if(new_header)
|
||||
// msg_header_and_size = find_packet_from_header(arduino_arr[temp_secondaryHeader]);
|
||||
//
|
||||
// /* Clear necessary variables so that a new message can be read into the buffer correctly */
|
||||
// new_header = false; //set new header to false, this is true if there is another header within the buffer
|
||||
// crc = 0;
|
||||
//
|
||||
// //Move all the remaning messages in the buffer to the start of the buffer
|
||||
// for (int j = temp_secondaryHeader; j < length; j++)
|
||||
// {
|
||||
// int innerCount = j - temp_secondaryHeader;
|
||||
// arduino_arr[innerCount] = arduino_arr[j];
|
||||
//
|
||||
// crc ^= arduino_arr[j];
|
||||
//
|
||||
// //check if we find another possible header inside the rest of the buffer and save that
|
||||
// if (((arduino_data_t)(find_packet_from_header(innerCount))).size != 0 && innerCount > 0 && new_header == false )
|
||||
// {
|
||||
// new_header = true;
|
||||
// message_it_secondary_head = innerCount;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -59,12 +59,12 @@ void init_system()
|
||||
//sbus_init();
|
||||
|
||||
// TODO!! TEMP code
|
||||
arduinoCom_init(USART1);
|
||||
while (1) {
|
||||
if(arduino_frame_available())
|
||||
arduino_read();
|
||||
HAL_Delay(15);
|
||||
}
|
||||
// arduinoCom_init(USART1);
|
||||
// while (1) {
|
||||
// if(arduino_frame_available())
|
||||
// arduino_read();
|
||||
// HAL_Delay(15);
|
||||
// }
|
||||
|
||||
|
||||
//init motors to run with oneshot 125, small delay
|
||||
|
Reference in New Issue
Block a user