Skip to content
Snippets Groups Projects
Commit a5ca1cb2 authored by bbartels's avatar bbartels Committed by dawehr
Browse files

quad: finish setting up benchmarking code and scripts.

- Fix one bug in uart buff size calculation
parent 34c56d82
No related branches found
No related tags found
No related merge requests found
......@@ -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()
......@@ -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)
......@@ -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);
}
}
......
......@@ -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
......
......@@ -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;
}
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment