#!/bin/bash

set -o nounset

declare -i query

queries=('close trains' 'end of siding' 'misaligned turnout' 'train locations')  

# printf "Query,Exectime" >> results.csv
for q in {0..3}
do
	query=$q
	sed -i "$((30 + $query))"' s://::' src/main.c
	pio run --target debug
	sleep 1s
	pio run --target upload
	sleep 1s
	piodebuggdb --interface=gdb -x command_file.txt
	
	queryname=${queries[$query]}
    time=$(cat gdb.txt | grep \$[0-9] | grep -o "[0-9]*$")
	time=$(sed "s/^/$queryname,/g" <<< $time)
	echo "$time" >> results.csv
	rm gdb.txt
	sleep 2s
	sed -i "$((30 + $query))"' s:^://:' src/main.c
done


