From dce78c05f584cb1d40992070174a215c91b38cc2 Mon Sep 17 00:00:00 2001 From: Lennart Eriksson Date: Fri, 25 Nov 2016 11:52:00 +0100 Subject: [PATCH] Added ping sensor data to the system --- UAV-ControlSystem/inc/drivers/arduino_com.h | 12 ++++++++++++ UAV-ControlSystem/src/drivers/arduino_com.c | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/UAV-ControlSystem/inc/drivers/arduino_com.h b/UAV-ControlSystem/inc/drivers/arduino_com.h index 627692a..e274513 100644 --- a/UAV-ControlSystem/inc/drivers/arduino_com.h +++ b/UAV-ControlSystem/inc/drivers/arduino_com.h @@ -37,12 +37,24 @@ typedef struct gps_data_t { uint8_t crc; } gps_data_t; +/*********************************************************************** +* BRIEF: RX packet structure from arduino com * +* INFORMATION: Contains the whole ping sensor data message * +***********************************************************************/ +typedef struct ping_data_t { + uint8_t header; + uint16_t distance_mm; + uint8_t crc; +}ping_data_t; + /* An instance of the GPS data read from Arduino Com */ gps_data_t gps_data; /* An instance of the compass data read from Arduino Com */ compass_data_t compass_data; +/* An instance of the ping data read from Arduino Com */ +ping_data_t ping_data; /*********************************************************************** * BRIEF: Initializes the UART for Arduino com * diff --git a/UAV-ControlSystem/src/drivers/arduino_com.c b/UAV-ControlSystem/src/drivers/arduino_com.c index 0068ea9..6860400 100644 --- a/UAV-ControlSystem/src/drivers/arduino_com.c +++ b/UAV-ControlSystem/src/drivers/arduino_com.c @@ -13,6 +13,7 @@ #define COMPASS_PACKET_SIZE 8 #define GPS_PACKET_SIZE 10 +#define PING_PACKET_SIZE 4 #define ARDUINO_SENSOR_SIZE 6 typedef struct arduino_sensor_t { @@ -56,6 +57,7 @@ dma_usart_return raw_dma_data_t; enum packet_ids { COMPASS_PACKET_ID = 0xA1, GPS_PACKET_ID = 0xB1, + PING_PACKET_ID = 0xC1, }; // Structure used to hold the data for "data_arr" @@ -68,6 +70,7 @@ typedef struct arduino_data_t { enum arduino_data_e { COMPASS_DATA_ID, GPS_DATA_ID, + PING_DATA_ID, ARDUINO_DATA_COUNT, }; @@ -81,6 +84,10 @@ arduino_data_t data_arr[ARDUINO_DATA_COUNT] = { .size = GPS_PACKET_SIZE, .dataPtr = &gps_data, }, + [PING_DATA_ID] = { + .size = PING_PACKET_SIZE, + .dataPtr = &ping_data, + }, }; @@ -144,6 +151,9 @@ arduino_data_t find_packet_from_header(uint8_t header) case GPS_PACKET_ID: arduino_data = data_arr[GPS_DATA_ID]; break; + case PING_PACKET_ID: + arduino_data = data_arr[PING_DATA_ID]; + break; default: break; }