#!/bin/bash

function handler()
{
    kill -s SIGINT $CFPID
    kill -s SIGINT $APID
    kill -s SIGINT $BPID
}

cd ./crazyflie_groundstation
#xterm -hold -e './crazyflieGroundStation' &
./crazyflieGroundStation &
CFPID=$!
echo "Waiting for crazyflie groundstation to be created..."
cf_gs=crazyflie_groundstation.socket
while [ ! -S "$cf_gs"  ]
do
    sleep 1
done
cd ../groundStation/adapters/crazyflie
sleep 1
./bin/cf_adapter &
APID=$!
sleep 1
cd ../..
./BackEnd &
BPID=$!

trap handler INT

wait