-
Notifications
You must be signed in to change notification settings - Fork 142
/
Copy pathcom_parameters.py
84 lines (69 loc) · 2.4 KB
/
com_parameters.py
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
from pathlib import Path
from pyaedt import pyaedt_function_handler
from pyaedt import settings
from pyaedt.generic.general_methods import open_file
logger = settings.logger
class COMParameters:
_CFG_DIR = Path(__file__).parent.parent / "misc" / "spisim_com_configuration_files"
_STD_TABLE_MAPPING = {"50GAUI-1_C2C": "com_120d_8.cfg", "100GBASE-KR4": "com_93_8.cfg"}
def __init__(self, standard="50GAUI-1_C2C"):
self._standard = standard
self.standard = standard
@property
def standard(self):
"""Standard name.
Returns
-------
str
"""
return self._standard
@standard.setter
def standard(self, value):
std_table = self._STD_TABLE_MAPPING[value]
cfg_path = self._CFG_DIR / std_table
self.load(cfg_path)
self._standard = value
@property
def parameters(self):
"""Parameters of the standard with value.
Returns
-------
dict
"""
return {i: j for i, j in self.__dict__.items() if not i.startswith("_")}
@pyaedt_function_handler
def load(self, file_path):
"""Load configuration file.
Returns
-------
bool
"""
self._standard = "custom"
with open_file(file_path, "r") as fp:
lines = fp.readlines()
for line in lines:
if not line.startswith("#") and "=" in line:
split_line = [i.strip() for i in line.split("=")]
name, value = split_line
self.__setattr__(name, str(value))
return True
@pyaedt_function_handler
def export(self, file_path):
"""Generate a configuration file for SpiSim.
Parameters
----------
file_path : str
Full path to configuration file to create.
Returns
-------
bool
"""
with open_file(file_path, "w") as fp:
fp.write("################################################################################\n")
fp.write("# MODULE: COM\n")
fp.write("# GENERATED ON\n")
fp.write("################################################################################\n")
for k, v in self.parameters.items():
fp.write("# {0}: {0}\n".format(k.upper()))
fp.write("{} = {}\n".format(k.upper(), v))
return True