#! /bin/sh

echo "Pozor! Probiha aktualizace!" > /dev/tty1
echo "Neodpojujte napajeni !!! " > /dev/tty1
echo "Starting update..." 
logger -t "prstflash" -p 5 "Starting extension board FW update."

echo "Entering to bootload mode..."
echo Q > /var/pipes/prstd_in

sleep 1

echo "Stopping vizualization..."
pid=`/bin/pidof vizulaizace`
	if [ -n "$pid" ]; then
		kill -9 $pid
   fi 
sleep 1
echo "Stopping application server..."
    	pid=`/bin/pidof prstd`
	if [ -n "$pid" ]; then
		kill -9 $pid
   fi
sleep 1
echo "Creating backup of current firmware..."   
/sdcard/stm32flash -b 9600 -r /sdcard/firmware.bak /dev/ttySAC1 

sleep 1

echo "Writing new firmware..." 

/sdcard/stm32flash -c -b 9600 -v $1 -g 0x0 /dev/ttySAC1

sleep 2

echo "Startin application..." 
/sdcard/prstd &
   
   