Close client sockets in case of exceptions
[remote/remote-mci.git] / contrib / scripts / control-mote.sh
blob0609e099518697a6edfca7fa246f98638b72c393
1 #!/bin/bash
3 # NAME
4 # ----
5 # control-mote.sh - script for executing the control commands
7 # SYNOPSIS
8 # --------
9 # /sbin/control-mote.sh TTY CMD
11 # DESCRIPTION
12 # -----------
13 # The script makes an use of a bootloader for a particular platform
14 # to issue one of the available commands (STOP/START/RESET).
16 # OPTION
17 # ------
18 # TTY::
20 # The first argument is a USB device name used by the bootloader
21 # to execute the command.
23 # CMD::
25 # The second one is the command itself to be executed.
27 # ENVIRONMENT VARIABLES
28 # ---------------------
29 # PLATFORM::
31 # It contains a name of the platform. The featured platforms
32 # are TMoteSky and MicaZ.
34 # EXAMPLE
35 # -------
36 # /sbin/control-mote.sh /dev/ttyUSB0 reset
38 # AUTHOR
39 # ------
40 # Copyright (c) 2008 Rostislav Spinar <rostislav.spinar@cit.ie>
42 #######################################################################
43 # The script
44 #######################################################################
46 #Get parameters from command line
47 TTY="$1"
48 CMD="$2"
50 #Have it as a env. variable
51 PLATFORM="$platform"
53 #Check the parameters first
54 #Suppose to have 2 args
55 if [ "$#" -ne 2 ]; then
56 echo "Incorrect number of arguments!"
57 exit
60 if [[ ! -n "$TTY" && ! -c "$TTY" ]]; then
61 echo "Port has to be defined and point to a valid character device! Port=$TTY!"
62 exit
65 #Run command(reset, stop & start)
66 case "$CMD" in
67 "reset" | "stop" | "start")
69 echo "$PLATFORM : command $CMD"
71 if [ "$CMD" = "start" ]; then
72 CMD="reset"
75 case "$PLATFORM" in
76 "TMoteSky")
77 #echo "tos-bsl --telosb -c $TTY --$CMD"
78 #echo "cppbsl -D -b -c $TTY --$CMD"
79 #tos-bsl --telosb -c "$TTY" --"$CMD"
80 cppbsl -D -b -c "$TTY" --"$CMD" > /dev/null 2>&1
81 RESULT=$?
83 "MicaZ")
84 #echo "uisp -dprog=mib510 -dserial=$TTY -dpart=ATmega128 --$CMD"
85 uisp -dprog=mib510 -dserial=$TTY -dpart=ATmega128 --"$CMD" > /dev/null 2>&1
86 RESULT=$?
89 echo "Unknown platform $PLATFORM!"
90 exit
92 esac
95 echo "Unknown command $CMD!"
96 exit
98 esac
100 echo "Done!"
101 exit "$RESULT"