#!/bin/bash

if [ $# -eq 0 -o $# -lt 4 ]
then
  echo "Usage: relay_conf serial_port /@F8kgsm.wav#B# source_mac [relay1_mac]...[relayN_mac] receiver_mac"
  echo "       relay_conf serial_port /@FdesQ10.dat#I# source_mac [relay1_mac]...[relayN_mac] receiver_mac"
  exit 1
fi

S_PORT=$1
CMD_STR=$2

shift
shift

echo "----> using serial port" $S_PORT
echo "----> Sending" $CMD_STR "to source node" $1
echo "------> will issue XBeeSendCmd -p $S_PORT -A -addr $1 $CMD_STR"
./XBeeSendCmd -p $S_PORT -A -addr $1 $CMD_STR

numargs=$#

for ((i=1 ; i <= numargs-1 ; i++))
do
    echo "----> Configuring relay nodes:" $1 "->" $2
    echo "----> Setting destination" $2 "for node" $1
    echo "------> will issue XBeeSendCmd -p $S_PORT -A -addr $1 /@D$2#"
    ./XBeeSendCmd -p $S_PORT -A -addr $1 "/@D$2#" 
    shift
done
	


