-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathlf_atten_mod_test.py
More file actions
executable file
·113 lines (88 loc) · 4.48 KB
/
lf_atten_mod_test.py
File metadata and controls
executable file
·113 lines (88 loc) · 4.48 KB
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
#!/usr/bin/env python3
"""
NAME: lf_atten_mod_test.py
PURPOSE: lf_atten_mod_test.py is used to modify and/or read the LANforge Attenuator settings.
EXAMPLE: Set channel four (zero-indexed) of all attenuators on LANforge system \'192.168.200.12\'
to attenuation value 220 ddB (22.0 dB).
Command: './lf_atten_mod_test.py --mgr 192.168.200.12 --atten_serno all --atten_idx 3 --atten_val 220'
Set channel all channels of attenuator 2324 on LANforge system \'192.168.200.12\'
to attenuation value 0 ddB (0.0 dB).
Command: './lf_atten_mod_test.py --mgr 192.168.200.12 --atten_serno 2324 --atten_idx all --atten_val 0'
Set first 3 channels:
Command: './lf_atten_mod_test.py --mgr 192.168.200.12 --atten_serno 1.1.2324 --atten_idx 0,1,2 --atten_val 100'
Run with '--help' option to see full usage and all options.
Copyright (C) 2020-2026 Candela Technologies Inc
License: Free to distribute and modify. LANforge systems must be licensed.
"""
import sys
import os
import importlib
import argparse
import logging
if sys.version_info[0] != 3:
print("This script requires Python 3")
exit(1)
sys.path.append(os.path.join(os.path.abspath(__file__ + "../../../")))
realm = importlib.import_module("py-json.realm")
Realm = realm.Realm
logger = logging.getLogger(__name__)
lf_logger_config = importlib.import_module("py-scripts.lf_logger_config")
class CreateAttenuator(Realm):
def __init__(self, host, port, serno, idx, val, query,
_debug_on=False,
_exit_on_error=False,
_exit_on_fail=False):
super().__init__(host, port, debug_=_debug_on, _exit_on_fail=_exit_on_fail)
self.host = host
self.serno = serno
self.idx = idx
self.val = val
self.query = query
self.attenuator_profile = self.new_attenuator_profile()
self.attenuator_profile.atten_idx = self.idx
self.attenuator_profile.atten_val = self.val
self.attenuator_profile.atten_serno = self.serno
def build(self):
if self.query:
self.attenuator_profile.show()
else:
self.attenuator_profile.create()
def main():
# create_basic_argparse defined in lanforge-scripts/py-json/LANforge/lfcli_base.py
parser = Realm.create_bare_argparse(
prog='lf_atten_mod_test.py',
formatter_class=argparse.RawTextHelpFormatter,
epilog=None,
description='''\
NAME: lf_atten_mod_test.py
PURPOSE: lf_atten_mod_test.py is used to modify and/or read the LANforge Attenuator settings.
EXAMPLE: Set channel four (zero-indexed) of all attenuators on LANforge system \'192.168.200.12\'
to attenuation value 220 ddB (22 dB).
Command: './lf_atten_mod_test.py --mgr 192.168.200.12 --atten_serno all --atten_idx 3 --atten_val 220'
Set channel all channels of attenuator 2324 on LANforge system \'192.168.200.12\'
to attenuation value 0 ddB (0.0 dB).
Command: './lf_atten_mod_test.py --mgr 192.168.200.12 --atten_serno 2324 --atten_idx all --atten_val 0'
Set first 3 channels:
Command: './lf_atten_mod_test.py --mgr 192.168.200.12 --atten_serno 1.1.2324 --atten_idx 0,1,2 --atten_val 100'
''')
parser.add_argument('--atten_serno', help='Serial number for requested attenuator, or \'all\'', default='all')
parser.add_argument('--atten_idx', help='Attenuator index: For module 1 = 0, first 3 modules: 0,1,2, or \'all\'', default='all')
parser.add_argument('--atten_val', help='Requested attenuation in 1/10ths of dB (ddB).', default=0)
parser.add_argument('--query', help='Just query the attenuator settings, do not set.', default=0)
args = parser.parse_args()
help_summary = '''\
lf_atten_mod_test.py is used to modify and/or read the LANforge Attenuator settings.
'''
if args.help_summary:
print(help_summary)
exit(0)
# set up logger
logger_config = lf_logger_config.lf_logger_config()
# set the logger level to requested value
logger_config.set_level(level=args.log_level)
logger_config.set_json(json_file=args.lf_logger_config_json)
atten_mod_test = CreateAttenuator(host=args.mgr, port=args.mgr_port, serno=args.atten_serno, idx=args.atten_idx,
val=args.atten_val, query=args.query, _debug_on=args.debug)
atten_mod_test.build()
if __name__ == "__main__":
main()