#!/bin/bash

while true; do
    F=""
    [[ -f "$1" ]] && read F < "$1" && rm "$1"
    cmd=""
    if [[ "x$F" != "x" ]]; then
        case "$F" in
            "s" )
                cmd="-0"
            ;;
            "0" )
                cmd="-s0"
            ;;
            "1" )
                cmd="-s300"
            ;;
            "2" )
                cmd="-s800"
            ;;
            "3" )
                cmd="-s1300"
            ;;
        esac
    fi
    if [[ x$cmd != x ]]; then
	echo "got command $cmd; /home/eddy/bin/SEWcontrol $cmd"
	/home/eddy/bin/SEWcontrol $cmd > $2
    else
	echo "get state"
	/home/eddy/bin/SEWcontrol > $2 
    fi
    sleep 1
done
