#!/bin/bash

# After calling wr2rf_init.sh for both tx and rx wr2rf_vme cards. The sequence outlined below
# can be used to "simulate" a cycle of the sps. The slot numbers used are specific to cfv-774-celma4
# card configuration and should be adapted...

# configure the tx + rx slots from the input arguments
tx=$1
rx=$2
./wr2rf -s $rx set-rfout 1 mix
./wr2rf -s $rx set-rfout 2 mix

# reset the RX wr2rf trigger unit
sh vtu_setup.sh $rx

freq_LHCPILOT=43347.158955
freq_SFTION1=42966.157844
freq_SFTPRO2=43278.463683
freq=$freq_SFTION1
freq=$freq_LHCPILOT
freq=$freq_SFTPRO2
freq_wrclk=125000000
prod=`echo "$freq*(2^48)" | bc -q`
ftw_h1=`echo "$prod/($freq_wrclk)" | bc -q`
ftw_hex=`echo "obase=16;ibase=10; $ftw_h1" | bc -q`

echo "FTW calculated as $ftw_hex"
usleep 10

./wr2rf -s $tx ftw-send1 0x$ftw_hex reset


