From 8740b7e7d6453cd588eba441a4f047bd0d1ec672 Mon Sep 17 00:00:00 2001 From: msereeyothin Date: Tue, 19 Mar 2024 20:14:07 -0400 Subject: [PATCH 1/2] implemented argparse into build_nrc_params --- .../usr/bin/build_nrc_params.py | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/odysseus/odysseus_tree/overlays/rootfs_overlay_nrc_common/usr/bin/build_nrc_params.py b/odysseus/odysseus_tree/overlays/rootfs_overlay_nrc_common/usr/bin/build_nrc_params.py index e6730265..02417a16 100755 --- a/odysseus/odysseus_tree/overlays/rootfs_overlay_nrc_common/usr/bin/build_nrc_params.py +++ b/odysseus/odysseus_tree/overlays/rootfs_overlay_nrc_common/usr/bin/build_nrc_params.py @@ -3,6 +3,7 @@ import sys import re import configparser +import argparse ''' Args: (in order first to last) @@ -12,11 +13,19 @@ ''' +parser = argparse.ArgumentParser() + +parser.add_argument('option', type=int, choices=[0, 1], help="0 returns STA, 1 returns AP") +parser.add_argument('--ip', '-op', help="path/to/this/ini/file (optional, otherwise default: /etc/nrc_opts_.ini)") +parser.add_argument('--mp', '-op', help="path/to/modprobe.d/directive.conf (optional, otherwise default: /etc/modprobe.d/nrc.conf)") + +args = parser.parse_args() def strSTA(): - if int(sys.argv[1]) == 0: + option = args.option + if int(option) == 0: return 'STA' - elif int(sys.argv[1]) == 1: + elif int(option) == 1: return 'AP' @@ -194,15 +203,12 @@ def load_conf(file_path): def run_common(): - ini_path = "" - # if not passed in, use live buildroot default - if len(sys.argv) <= 2: + ini_path = args.ip + if (ini_path is None) : if strSTA() == 'STA': ini_path = "/etc/nrc_opts_sta.ini" else: ini_path = "/etc/nrc_opts_ap.ini" - else: - ini_path = sys.argv[2] items = load_conf(ini_path) @@ -212,12 +218,11 @@ def run_common(): insmod_arg = setModuleParam(items) file_txt = "" - mod_path = "" + + mod_path = args.mp # if not passed in, use live buildroot default - if len(sys.argv) <= 3: + if mod_path is None: mod_path = "/etc/modprobe.d/nrc.conf" - else: - mod_path = sys.argv[3] with open(mod_path, "w") as mod_file: file_txt = "options nrc" + insmod_arg From da9e37c82b0b180f1f01a711d6d407d677f3c62c Mon Sep 17 00:00:00 2001 From: msereeyothin Date: Sun, 24 Mar 2024 14:15:13 -0400 Subject: [PATCH 2/2] updated build nrc params --- .../usr/bin/build_nrc_params.py | 30 +++++++------------ 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/odysseus/odysseus_tree/overlays/rootfs_overlay_nrc_common/usr/bin/build_nrc_params.py b/odysseus/odysseus_tree/overlays/rootfs_overlay_nrc_common/usr/bin/build_nrc_params.py index 02417a16..3d598a45 100755 --- a/odysseus/odysseus_tree/overlays/rootfs_overlay_nrc_common/usr/bin/build_nrc_params.py +++ b/odysseus/odysseus_tree/overlays/rootfs_overlay_nrc_common/usr/bin/build_nrc_params.py @@ -15,18 +15,13 @@ parser = argparse.ArgumentParser() -parser.add_argument('option', type=int, choices=[0, 1], help="0 returns STA, 1 returns AP") -parser.add_argument('--ip', '-op', help="path/to/this/ini/file (optional, otherwise default: /etc/nrc_opts_.ini)") -parser.add_argument('--mp', '-op', help="path/to/modprobe.d/directive.conf (optional, otherwise default: /etc/modprobe.d/nrc.conf)") +parser.add_argument('option', choices=['STA', 'AP'], help="STA or AP") +parser.add_argument('--ip', help="path/to/this/ini/file (optional, otherwise default: /etc/nrc_opts_.ini)") +parser.add_argument('--mp', help="path/to/modprobe.d/directive.conf (optional, otherwise default: /etc/modprobe.d/nrc.conf)", default="/etc/modprobe.d/nrc.conf") args = parser.parse_args() +option = args.option -def strSTA(): - option = args.option - if int(option) == 0: - return 'STA' - elif int(option) == 1: - return 'AP' def strBDName(bd_name, model): @@ -38,7 +33,7 @@ def strBDName(bd_name, model): def checkParamValidity(power_save, listen_interval): - if strSTA() == 'STA' and int(power_save) > 0 and int(listen_interval) > 65535: + if option == 'STA' and int(power_save) > 0 and int(listen_interval) > 65535: print("Max listen_interval is 65535!") exit() @@ -54,7 +49,7 @@ def setModuleParam(config): # Set module parameters based on configuration # Set parameters for AP (support NDP probing) - if strSTA() == 'AP': + if option == 'AP': ndp_preq = 1 else: ndp_preq = config['ndp_preq'] @@ -66,7 +61,7 @@ def setModuleParam(config): # module param for power_save # default: power_save(0: active mode) sleep_duration(0,0) - if strSTA() == 'STA' and int(config['power_save']) > 0: + if option == 'STA' and int(config['power_save']) > 0: # 7393/7394 STA (host_gpio_out(17) --> target_gpio_in(14)) if str(config['model']) == "7393" or str(config['model']) == "7394": ps_gpio_arg = " power_save_gpio=17,14" @@ -83,7 +78,7 @@ def setModuleParam(config): # module param for bss_max_idle (keep alive) # default: bss_max_idle(0: disabled) if int(config['bss_max_idle_enable']) == 1: - if strSTA() == 'AP' or strSTA() == 'RELAY' or strSTA() == 'STA': + if option == 'AP' or option == 'RELAY' or option == 'STA': bss_max_idle_arg = " bss_max_idle=" + str(config['bss_max_idle']) # module param for NDP Prboe Request (NDP scan) @@ -180,7 +175,7 @@ def setModuleParam(config): # module param for supported channel width # default : support 1/2/4MHz (1: 1/2/4Mhz) - if strSTA() == 'STA' and int(config['support_ch_width']) == 0: + if option == 'STA' and int(config['support_ch_width']) == 0: support_ch_width_arg = " support_ch_width=0" module_param += fw_arg + \ @@ -205,7 +200,7 @@ def run_common(): ini_path = args.ip if (ini_path is None) : - if strSTA() == 'STA': + if option == 'STA': ini_path = "/etc/nrc_opts_sta.ini" else: ini_path = "/etc/nrc_opts_ap.ini" @@ -220,10 +215,7 @@ def run_common(): file_txt = "" mod_path = args.mp - # if not passed in, use live buildroot default - if mod_path is None: - mod_path = "/etc/modprobe.d/nrc.conf" - + with open(mod_path, "w") as mod_file: file_txt = "options nrc" + insmod_arg file_txt = file_txt.strip("\n")