#!/bin/sh

#########################################################################################################
# ------------------------------------------------------------------------------------------------------
#  | Type:USER_DEFINE | Length  |                                Value                                  |
#  ------------------------------------------------------------------------------------------------------
#                               | Type:script_name | Length | name | Type:script_value | Length | value |
#                               -------------------------------------------------------------------------
#  1. buf中的内容包含两个TLV, 其中一个value为脚本名称，另一个value为参数
#  脚本名称格式：/module_name_xxx/script_name_xxx
#  run_script函数在脚本名称前添加/etc/scripts路径，合并成
#  /etc/scripts/module_name_xxx/script_name_xxx并执行。
#
#  2. 脚本应当在模块对应files文件夹下进行管理，打包时复制到/etc/scripts路径下。
#
# 参数格式：
# set_wlan_band <band>
# get_wlan_band
#
#########################################################################################################

# 产测方法
METHOD_SET_WLAN_BAND="set_wlan_band"
METHOD_GET_WLAN_BAND="get_wlan_band"


show_help() {
	echo "Usage: $0 <method> [<band>]" > /dev/console
	echo "method:" > /dev/console
	echo "        $METHOD_SET_WLAN_BAND" > /dev/console
	echo "            band: 2G or 5G"    > /dev/console
	echo "        $METHOD_GET_WLAN_BAND" > /dev/console
}

show_log() {
	# 重定向到串口输出，不会被管道捕获
	echo "[perf-test] $*" > /dev/console
}

set_wlan_band() {
	case $1 in
		"2G")
			ubus call perf_test set_wlan_band '{"band":"2G"}'
			;;
		"5G")
			ubus call perf_test set_wlan_band '{"band":"5G"}'
			;;
		*)
			show_log "invalid band $2"
			return 1;
			;;
	esac
}

get_wlan_band() {
	local resp=""

	resp=$(ubus call perf_test get_wlan_band)
	echo $resp
}

call_method() {
	case "$1" in
		$METHOD_SET_WLAN_BAND)
			set_wlan_band $2
			;;
		$METHOD_GET_WLAN_BAND)
			get_wlan_band
			;;
		*)
			show_log "invalid method $1"
			return 1
			;;
	esac

	return 0
}


call_method $@

if [ $? -ne 0 ]; then
	show_help
	exit 1
fi

exit 0
