diff --git a/quad/scripts/uart_comm_listen.py b/quad/scripts/uart_comm_listen.py index c41209f442caab84c26c7aefb55410022a158588..0a251b5df409f1ffcb1dfc121b8efc793a1ee220 100755 --- a/quad/scripts/uart_comm_listen.py +++ b/quad/scripts/uart_comm_listen.py @@ -12,17 +12,6 @@ def read_packet(ser): checksum = ser.read() return data -def query_received(ser): - # Send request - query_msg = create_msg(0, 3, 0, b'') - ser.write(query_msg) - ser.flush() - - resp = read_packet(ser) - received_str = resp[:-1].decode() - - return tuple(map(int, received_str.split(','))) - if __name__ == '__main__': with serial.Serial('/dev/ttyUSB0', 921600, timeout=5) as ser: i = 0 @@ -31,8 +20,9 @@ if __name__ == '__main__': time.sleep(0.05) while ser.in_waiting != 0: resp = read_packet(ser) - elapsed = int.from_bytes(resp, byteorder='little') - print("{} {}".format(i, elapsed)) + elapsed = int.from_bytes(resp[0:3], byteorder='little') + processed = int.from_bytes(resp[4:7], byteorder='little') + print("{} {} {}".format(i, elapsed, processed)) i += 1 ser.flush() diff --git a/quad/scripts/uart_comm_send.py b/quad/scripts/uart_comm_send.py index c6528f041694d8f7fcdb7a38217bd2331bac727a..d915278e81cdcacdd172f7155a540c5e69b98e77 100755 --- a/quad/scripts/uart_comm_send.py +++ b/quad/scripts/uart_comm_send.py @@ -26,8 +26,8 @@ def create_test_packet(size=8): if __name__ == '__main__': with serial.Serial('/dev/ttyUSB0', 921600, timeout=5) as ser: - for i in range(0, 1): - time.sleep(0.5) + for i in range(0, 12): ser.reset_input_buffer() ser.write(create_test_packet(8)) - ser.flush() + #ser.flush() + #time.sleep(0.5) diff --git a/quad/sw/modular_quad_pid/src/communication.c b/quad/sw/modular_quad_pid/src/communication.c index ea86526aa05632dd408ab32fc32749c8a9cdc7e2..c4e166b20bbfc56ae9b44312b23be205a4da95f2 100644 --- a/quad/sw/modular_quad_pid/src/communication.c +++ b/quad/sw/modular_quad_pid/src/communication.c @@ -93,7 +93,7 @@ int process_packet(modular_structs_t *structs) { // Call appropriate function for packet (* (MessageTypes[meta_data.msg_type].subtypes[meta_data.msg_subtype].functionPtr))(structs); - uart_buff_flush_packet(); + uart_buff_consume_packet(); return 0; @@ -119,11 +119,7 @@ void restore_interrupts(u32 intr_state) { void process_received(modular_structs_t *structs) { // Parse as many packets as possible while (uart_buff_packet_ready()) { - u32 start = timer_get_count(); process_packet(structs); - u32 end = timer_get_count(); - u32 duration = end - start; - send_data(0, 0, 0, (char *) &duration, 4); } } diff --git a/quad/sw/modular_quad_pid/src/main.c b/quad/sw/modular_quad_pid/src/main.c index 712afda89d621ea65b1c3d2ecc05a3954f7e1b44..43a9b9dd30fd2b6927378a4b9bb94c18e56605b4 100644 --- a/quad/sw/modular_quad_pid/src/main.c +++ b/quad/sw/modular_quad_pid/src/main.c @@ -17,6 +17,7 @@ #include "update_gui.h" #define BENCH_TEST +#define UART_BENCHMARK int main() { @@ -50,8 +51,23 @@ int main() timer_start_loop(); // Process all received data + +#ifdef UART_BENCHMARK + usleep(500000); + u32 start_time = timer_get_count(); +#endif + process_received(&structs); +#ifdef UART_BENCHMARK + u32 end_time = timer_get_count(); + u32 duration = end_time - start_time; + u32 packets_processed = uart_buff_packets_processed(); + u32 data[2]; + data[0] = duration; + data[1] = packets_processed; + send_data(0, 0, 0, (char *) &data, 8); +#endif #ifndef BENCH_TEST // Get the user input and put it into user_input_struct diff --git a/quad/sw/modular_quad_pid/src/uart_buff.c b/quad/sw/modular_quad_pid/src/uart_buff.c index c2b1579021cdc3369cac3984fa82fe0935c1ea38..a7a28e509ee8b8e6b0a9565b38e90a7fed1f4602 100644 --- a/quad/sw/modular_quad_pid/src/uart_buff.c +++ b/quad/sw/modular_quad_pid/src/uart_buff.c @@ -2,16 +2,17 @@ #include "uart_buff.h" #include <stdlib.h> -#define UART_MAX_BUFF_SIZE 20 -#define UART_MAX_PACKET_SIZE 10 +#define UART_MAX_BUFF_SIZE 2048 +#define UART_MAX_PACKET_SIZE 256 static volatile u8 buff[UART_MAX_BUFF_SIZE]; static size_t start = UART_MAX_BUFF_SIZE; static size_t packet_data_length = 0; static volatile size_t end = 0; -static int packet_start_found = 0; -static int packet_size_found = 0; -static int packet_ready = 0; +static u8 packet_start_found = 0; +static u8 packet_size_found = 0; +static u8 packet_ready = 0; +static u32 packets_processed = 0; /** * Put a byte into the buffer. @@ -172,20 +173,21 @@ float uart_buff_data_get_float(size_t offset) { * Move the start index of the buffer to the end of the current packet. * If a packet is not ready, this function does nothing. */ -void uart_buff_flush_packet() { +void uart_buff_consume_packet() { if (!packet_ready) { return; } start = uart_buff_calc_index(start + uart_buff_packet_size() + 1); uart_buff_reset_flags(); + packets_processed += 1; } /** * Return the current number of bytes held in the buffer. */ size_t uart_buff_size() { - return uart_buff_calc_index(end - start); + return uart_buff_calc_index(end - start - 1); } /** @@ -290,3 +292,7 @@ void uart_buff_print() { puts("| |"); puts("'--'"); } + +u32 uart_buff_packets_processed() { + return packets_processed; +} diff --git a/quad/sw/modular_quad_pid/src/uart_buff.h b/quad/sw/modular_quad_pid/src/uart_buff.h index 184d7cb40edd5d0ccc2102e514d8384396a3b82b..58dfa0040abacf623b0706d094f94e2f28f1212b 100644 --- a/quad/sw/modular_quad_pid/src/uart_buff.h +++ b/quad/sw/modular_quad_pid/src/uart_buff.h @@ -15,7 +15,7 @@ u8 uart_buff_data_get_u8(size_t); u16 uart_buff_data_get_u16(size_t); u32 uart_buff_data_get_u32(size_t); float uart_buff_data_get_float(size_t); -void uart_buff_flush_packet(); +void uart_buff_consume_packet(); size_t uart_buff_size(); size_t uart_buff_data_length(); size_t uart_buff_packet_size(); @@ -25,5 +25,6 @@ int uart_buff_full(); size_t uart_buff_calc_index(int); char * uart_buff_get_packet(); void uart_buff_print(); +u32 uart_buff_packets_processed(); #endif