#!/bin/sh

# 

A="04:00 longshot5ghz Kindergarten-Feld 240 242"		# time linktype name node1 node2
B="04:05 longshot5ghz Puppenfabrik-Kindergarten 211 217"


channel_list()
{
	local linktype="$1"
	local wifidev="${2:-wlan0}"
	local line

	iwlist $wifidev chan |
	 while read line; do {
	 	case "$line" in
	 		*" : "*)
	 			set $line	# fixme! remove leading zeros: e.g. 06 -> 6
				echo $2
			;;
		esac
	} done
}

# txpower
# channel
# frag
# htmode: HT20 HT40- HT40+
# rxantenna txantenna	// muss fest sein
# distance: 4000	// nein, muss fest angegeben sein, aendert sich nicht

# 0) measure-time? no: exit
# 1) loop over all defined links: my nodenumber involved? no: exit
# 2) timenow? no: exit
# 3) stop forwarding?
# 4) /etc/init.d/netserver start

# 1) runde1: frag = 512

for LINK in "$A" "$B" "$C"; do

remember_wifi_params
get_vals "$LINK"	# linktype="longshot5ghz"

wifidev="wlan0"

for htmode in none HT20 HT40- HT40+; do {

	for channel in $( channel_list "$linktype" ); do {
		iw dev "$wifidev" set channel "$channel" "$htmode"

		for frag in 512 1024 1500; do {
			iw phy "phy0" set frag "$frag"

			_speedtest do here $REMOTE_ADDRESS 20 >>"/tmp/LINK_MEASUREMENT.txt"
		} done
	} done
} done


/etc/init.d/netserver stop

