-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcast_rx.sh
executable file
·203 lines (142 loc) · 5.21 KB
/
cast_rx.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#!/usr/bin/env bash
# (c) 2022 Northeastern University
# Created by Davide Villa ([email protected])
# cast_rx.sh - This is the main file that allows to start the receiver and sound a scenario in Colosseum.
# This file will guide the user on defining the required parameters to perform the sounding of CaST.
# The default Rx node will be the current one where the script is executed.
echo "Starting receiver CaST sounding..."
### Sounding parameters
## Get scenario ID
while true; do
read -p "What is the scenario ID to sound?: " -r
if [[ $REPLY =~ ^([0-9]{4,5})$ ]] # Scenario id valid
then
SCENARIO_ID=$REPLY
break
fi
echo 'Scenario ID not valid. It must contain 4 or 5 digits (e.g. 1009).'
done
## Get scenario frequency
while true; do
read -p "What is the scenario frequency in Hz to sound?: " -r
if [[ $REPLY =~ ^([1-9][0-9]{6,9})$ ]] # Scenario id valid
then
SCENARIO_FREQ=$REPLY
break
fi
echo 'Scenario frequency not valid. It must contain between 7 and 10 digits (e.g. 1000000000).'
done
## Get total number of scenario nodes
while true; do
read -p "What is the total number of nodes in the scenario?: " -r
if [[ $REPLY =~ ^([1-9][0-9]{0,1})$ ]] # Scenario nodes number valid [1-99]
then
SCENARIO_NODES=$REPLY
break
fi
echo 'Number of nodes not valid. It must contain 1 or 2 digits (e.g. 10).'
done
## Get Rx node id
RX_ID=$(ifconfig col0 | grep -Eo '(172.30.[0-9]+.[0-9]+)' | awk -v s=100 '{print substr($1,length($1)-2)-s }')
printf 'The current node will be used as Rx: %d\n' "$RX_ID"
## Get Tx node id
while true; do
read -p "What is the SRN node ID of the reservation acting as the tx (e.g. 3)?: " -r
if [[ $REPLY =~ ^([1-9][0-9]{0,2})$ ]] # Tx node id valid
then
TX_ID=$REPLY
break
fi
echo 'Tx SRN ID not valid. It must contain 3 digits (e.g. 12).'
done
## Ensure the tx node is running
while true; do
read -p "Is the tx node running with the same frequency (y/n)?: " -r
if [[ $REPLY =~ ^(y|Y)(es)?$ ]] # Y y Yes yes
then
break
fi
echo 'Start the tx node by running in its terminal window: ./run_tx_sounding.sh'
done
## Get sounding duration
while true; do
read -p "What is the desired sounding duration in seconds?: " -r
if [[ $REPLY =~ ^([1-9][0-9]{0,2})$ ]] # Sounding duration should be between [1-999]
then
SOUNDING_DURATION=$(echo "$REPLY" | awk '{print $1 + 0}' )
break
fi
echo 'Sounding duration not valid. It must be between [1-999] seconds.'
done
## Get sounding link
while true; do
read -p "What is the scenario link tx-rx to sound (e.g. 1-2)?: " -r
if [[ $REPLY =~ ^([1-9]{1,2}-[0-9]{1,2})$ ]] # Sounding link [1-2]
then
SOUNDING_LINK=$REPLY
IFS=- read -r SOUNDING_TX_ID SOUNDING_RX_ID <<< "$SOUNDING_LINK" # Split tx and rx
break
fi
echo 'Sounding link not valid. It must be in the format: tx-rx (e.g. tx 1 and rx 4 is: 1-4).'
done
## Get scenario offset [TO-DO]
## Print configuration values
echo '
########## CONFIGURATION VALUES ##########
SCENARIO ID: '"$SCENARIO_ID"'
SCENARIO FREQUENCY: '"$SCENARIO_FREQ"' Hz
SCENARIO NODES: '"$SCENARIO_NODES"'
TX NODE ID: '"$TX_ID"'
RX NODE ID: '"$RX_ID"'
SOUNDING DURATION: '"$SOUNDING_DURATION"' seconds
SOUNDING LINK: '"$SOUNDING_LINK"'
##########################################
'
## Export configuration values [TO-DO]
echo 'Sounding configuration completed.'
### Sounding operations
echo 'Starting sounding operations...'
## Flash fpga
echo 'Flashing FPGA.'
source /opt/fpga/usrp3/top/x300/setupenv.sh
viv_jtag_program /usr/share/uhd/images/usrp_x310_fpga_HG.bit
## Set scenario radio map
echo 'Setting scenario radio map.'
# Remove extra 0s before number
TX_ID_SCEN=$(echo "$TX_ID" | awk '{print $1 + 0}' )
RX_ID_SCEN=$(echo "$RX_ID" | awk '{print $1 + 0}' )
# Remove previous radio map file
rm -f radio_api/radio_map.json
# Define empty json variable
SCEN_JSON='{}'
# Populate json variable with all none values
for ((i=1;i<=SCENARIO_NODES;i++)); do
SCEN_JSON="$(echo "$SCEN_JSON" | jq '. + {"Node '"$i"'": "None"}')"
done
# Set tx and rx nodes in the radio map variable
SCEN_JSON="$(echo "$SCEN_JSON" | jq '. + {"Node '"$SOUNDING_TX_ID"'":{"SRN":'"$TX_ID_SCEN"',"RadioA":1,"RadioB":2}}')"
SCEN_JSON="$(echo "$SCEN_JSON" | jq '. + {"Node '"$SOUNDING_RX_ID"'":{"SRN":'"$RX_ID_SCEN"',"RadioA":1,"RadioB":2}}')"
# Export variable into a json file
echo "$SCEN_JSON" >> radio_api/radio_map.json
## Create results folder
echo 'Creating results folder.'
mkdir -p /root/results/raw_data
## Stop possible running scenario
echo 'Stopping previous running scenario.'
colosseumcli rf stop
## Start scenario
printf 'Starting scenario %d.\n' "$SCENARIO_ID"
colosseumcli rf start "$SCENARIO_ID" -c -m radio_api/radio_map.json
## Wait to sync for scenario time
echo 'Waiting to sync.'
sleep 15
## Start rx
echo 'Starting rx.'
# Calling parameters: ./rx.py tx_time frequency gain file_sink_ext
./radio_api/rx.py "$SOUNDING_DURATION" "$SCENARIO_FREQ" 15 0
## Perform sounding operations
echo 'Performing sounding operations.'
# Calling parameters: ./channel-estimate.py 0
# If the first argument is 0, it will take the default rx file from this interactive sounding
./radio_api/channel-estimate.py 0 "$SCENARIO_ID" "$SOUNDING_LINK"
echo 'CaST sounding completed.'