forked from sonic-net/sonic-platform-common
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inf8628.py
160 lines (134 loc) · 5.1 KB
/
inf8628.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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#----------------------------------------------------------------------------
# QSFP-DD 8X Transceiver (QSFP Double Density)
#----------------------------------------------------------------------------
from __future__ import print_function
try:
from .sff8024 import type_of_transceiver # Dot module supports both Python 2 and Python 3 using explicit relative import methods
from .sff8024 import type_abbrv_name # Dot module supports both Python 2 and Python 3 using explicit relative import methods
from .sffbase import sffbase # Dot module supports both Python 2 and Python 3 using explicit relative import methods
except ImportError as e:
raise ImportError ("%s - required module not found" % e)
class inf8628InterfaceId(sffbase):
def decode_revision_compliance(self, eeprom_data, offset, size):
return '%c.%c' % (eeprom_data[offset][0], eeprom_data[offset][1])
def decode_module_state(self, eeprom_data, offset, size):
module_state_byte = eeprom_data[offset]
module_state = int(module_state_byte, 16) & 14
if module_state == 2:
return 'Low Power State'
elif module_state == 4:
return 'Power Up State'
elif module_state == 6:
return 'Ready State'
elif module_state == 8:
return 'Power Down State'
elif module_state == 10:
return 'Fault State'
return 'Unknown State %s' % module_state
version = '1.0'
interface_id = {
'Identifier':
{'offset': 0,
'size': 1,
'type': 'enum',
'decode': type_of_transceiver},
'Revision Compliance':
{'offset': 1,
'type': 'func',
'decode': {'func': decode_revision_compliance}},
'Module State':
{'offset': 3,
'type': 'func',
'decode': {'func': decode_module_state}},
'Interrupt Asserted':
{'offset': 3,
'bit': 0,
'type': 'bitvalue'},
'Vendor Name':
{'offset': 129,
'size': 16,
'type': 'str'},
'Vendor Part Number':
{'offset': 148,
'size': 16,
'type': 'str'},
'Vendor Revision':
{'offset': 164,
'size': 2,
'type': 'str'},
'Vendor Serial Number':
{'offset': 166,
'size': 16,
'type': 'str'},
}
sfp_type = {
'type':
{'offset': 0,
'size': 1,
'type': 'enum',
'decode': type_of_transceiver}
}
sfp_type_abbrv_name = {
'type_abbrv_name':
{'offset': 0,
'size': 1,
'type': 'enum',
'decode': type_abbrv_name}
}
vendor_name = {
'Vendor Name':
{'offset': 0,
'size': 16,
'type': 'str'}
}
vendor_pn = {
'Vendor PN':
{'offset': 0,
'size': 16,
'type': 'str'}
}
vendor_rev = {
'Vendor Rev':
{'offset': 0,
'size': 2,
'type': 'str'}
}
vendor_sn = {
'Vendor SN':
{'offset': 0,
'size': 16,
'type': 'str'}
}
def __init__(self, eeprom_raw_data=None):
self.interface_data = None
start_pos = 0
if eeprom_raw_data is not None:
self.interface_data = sffbase.parse(self,
self.interface_id,
eeprom_raw_data,
start_pos)
def parse(self, eeprom_raw_data, start_pos):
return sffbase.parse(self, self.interface_id, eeprom_raw_data, start_pos)
def parse_sfp_type(self, type_raw_data, start_pos):
return sffbase.parse(self, self.sfp_type, type_raw_data, start_pos)
def parse_sfp_type_abbrv_name(self, type_raw_data, start_pos):
return sffbase.parse(self, self.sfp_type_abbrv_name, type_raw_data, start_pos)
def parse_vendor_name(self, name_raw_data, start_pos):
return sffbase.parse(self, self.vendor_name, name_raw_data, start_pos)
def parse_vendor_rev(self, rev_raw_data, start_pos):
return sffbase.parse(self, self.vendor_rev, rev_raw_data, start_pos)
def parse_vendor_pn(self, pn_raw_data, start_pos):
return sffbase.parse(self, self.vendor_pn, pn_raw_data, start_pos)
def parse_vendor_sn(self, sn_raw_data, start_pos):
return sffbase.parse(self, self.vendor_sn, sn_raw_data, start_pos)
def dump_pretty(self):
if self.interface_data is None:
print('Object not initialized, nothing to print')
return
sffbase.dump_pretty(self, self.interface_data)
def get_calibration_type(self):
return self.calibration_type
def get_data(self):
return self.interface_data
def get_data_pretty(self):
return sffbase.get_data_pretty(self, self.interface_data)