1818VDM_UNFREEZE = 0
1919
2020class CmisVdmApi (XcvrApi ):
21+
22+ VDM_REAL_VALUE = 0x1
23+ VDM_THRESHOLD = 0x2
24+ VDM_FLAG = 0x4
25+ ALL_FIELD = 0xff
26+
2127 def __init__ (self , xcvr_eeprom ):
2228 super (CmisVdmApi , self ).__init__ (xcvr_eeprom )
2329
@@ -30,7 +36,7 @@ def get_F16(self, value):
3036 result = mantissa * 10 ** (scale_exponent - 24 )
3137 return result
3238
33- def get_vdm_page (self , page , VDM_flag_page ):
39+ def get_vdm_page (self , page , VDM_flag_page , field_option = ALL_FIELD ):
3440 '''
3541 This function returns VDM items from a specific VDM page.
3642 Output format is a dictionary. Key is observable type; value is a dictionary.
@@ -67,42 +73,55 @@ def get_vdm_page(self, page, VDM_flag_page):
6773 for index , typeID in enumerate (vdm_typeID ):
6874 if typeID not in VDM_TYPE_DICT :
6975 continue
70- else :
71- vdm_info_dict = VDM_TYPE_DICT [typeID ]
72- thrshID = VDM_thresholdID [index ]
73- vdm_type = vdm_info_dict [0 ]
74- vdm_format = vdm_info_dict [1 ]
75- scale = vdm_info_dict [2 ]
76-
77- vdm_value_offset = vdm_valuePage * PAGE_SIZE + PAGE_OFFSET + VDM_SIZE * index
78- vdm_high_alarm_offset = vdm_thrshPage * PAGE_SIZE + PAGE_OFFSET + THRSH_SPACING * thrshID
79- vdm_low_alarm_offset = vdm_high_alarm_offset + 2
80- vdm_high_warn_offset = vdm_high_alarm_offset + 4
81- vdm_low_warn_offset = vdm_high_alarm_offset + 6
8276
77+ vdm_info_dict = VDM_TYPE_DICT [typeID ]
78+ thrshID = VDM_thresholdID [index ]
79+ vdm_type = vdm_info_dict [0 ]
80+ vdm_format = vdm_info_dict [1 ]
81+ scale = vdm_info_dict [2 ]
82+
83+ vdm_value_offset = vdm_valuePage * PAGE_SIZE + PAGE_OFFSET + VDM_SIZE * index
84+ vdm_high_alarm_offset = vdm_thrshPage * PAGE_SIZE + PAGE_OFFSET + THRSH_SPACING * thrshID
85+ vdm_low_alarm_offset = vdm_high_alarm_offset + 2
86+ vdm_high_warn_offset = vdm_high_alarm_offset + 4
87+ vdm_low_warn_offset = vdm_high_alarm_offset + 6
88+
89+ if field_option & self .VDM_REAL_VALUE :
8390 vdm_value_raw = self .xcvr_eeprom .read_raw (vdm_value_offset , VDM_SIZE , True )
84- vdm_thrsh_high_alarm_raw = self .xcvr_eeprom .read_raw (vdm_high_alarm_offset , VDM_SIZE , True )
85- vdm_thrsh_low_alarm_raw = self .xcvr_eeprom .read_raw (vdm_low_alarm_offset , VDM_SIZE , True )
86- vdm_thrsh_high_warn_raw = self .xcvr_eeprom .read_raw (vdm_high_warn_offset , VDM_SIZE , True )
87- vdm_thrsh_low_warn_raw = self .xcvr_eeprom .read_raw (vdm_low_warn_offset , VDM_SIZE , True )
88- if not vdm_value_raw or not vdm_thrsh_high_alarm_raw or not vdm_thrsh_low_alarm_raw \
89- or not vdm_high_warn_offset or not vdm_thrsh_low_warn_raw :
90- return {}
91+ if not vdm_value_raw :
92+ continue
9193 if vdm_format == 'S16' :
9294 vdm_value = struct .unpack ('>h' ,vdm_value_raw )[0 ] * scale
95+ elif vdm_format == 'U16' :
96+ vdm_value = struct .unpack ('>H' ,vdm_value_raw )[0 ] * scale
97+ elif vdm_format == 'F16' :
98+ vdm_value_int = struct .unpack ('>H' ,vdm_value_raw )[0 ]
99+ vdm_value = self .get_F16 (vdm_value_int )
100+ else :
101+ continue
102+ else :
103+ vdm_value = None
104+
105+ if field_option & self .VDM_THRESHOLD :
106+ vdm_thrsh_raw = self .xcvr_eeprom .read_raw (vdm_high_alarm_offset , VDM_SIZE * 4 , True )
107+ if not vdm_thrsh_raw :
108+ continue
109+ vdm_thrsh_high_alarm_raw = vdm_thrsh_raw [0 :2 ]
110+ vdm_thrsh_low_alarm_raw = vdm_thrsh_raw [2 :4 ]
111+ vdm_thrsh_high_warn_raw = vdm_thrsh_raw [4 :6 ]
112+ vdm_thrsh_low_warn_raw = vdm_thrsh_raw [6 :8 ]
113+
114+ if vdm_format == 'S16' :
93115 vdm_thrsh_high_alarm = struct .unpack ('>h' , vdm_thrsh_high_alarm_raw )[0 ] * scale
94116 vdm_thrsh_low_alarm = struct .unpack ('>h' , vdm_thrsh_low_alarm_raw )[0 ] * scale
95117 vdm_thrsh_high_warn = struct .unpack ('>h' , vdm_thrsh_high_warn_raw )[0 ] * scale
96118 vdm_thrsh_low_warn = struct .unpack ('>h' , vdm_thrsh_low_warn_raw )[0 ] * scale
97119 elif vdm_format == 'U16' :
98- vdm_value = struct .unpack ('>H' ,vdm_value_raw )[0 ] * scale
99120 vdm_thrsh_high_alarm = struct .unpack ('>H' , vdm_thrsh_high_alarm_raw )[0 ] * scale
100121 vdm_thrsh_low_alarm = struct .unpack ('>H' , vdm_thrsh_low_alarm_raw )[0 ] * scale
101122 vdm_thrsh_high_warn = struct .unpack ('>H' , vdm_thrsh_high_warn_raw )[0 ] * scale
102123 vdm_thrsh_low_warn = struct .unpack ('>H' , vdm_thrsh_low_warn_raw )[0 ] * scale
103124 elif vdm_format == 'F16' :
104- vdm_value_int = struct .unpack ('>H' ,vdm_value_raw )[0 ]
105- vdm_value = self .get_F16 (vdm_value_int )
106125 vdm_thrsh_high_alarm_int = struct .unpack ('>H' , vdm_thrsh_high_alarm_raw )[0 ]
107126 vdm_thrsh_low_alarm_int = struct .unpack ('>H' , vdm_thrsh_low_alarm_raw )[0 ]
108127 vdm_thrsh_high_warn_int = struct .unpack ('>H' , vdm_thrsh_high_warn_raw )[0 ]
@@ -113,13 +132,24 @@ def get_vdm_page(self, page, VDM_flag_page):
113132 vdm_thrsh_low_warn = self .get_F16 (vdm_thrsh_low_warn_int )
114133 else :
115134 continue
135+ else :
136+ vdm_thrsh_high_alarm = None
137+ vdm_thrsh_low_alarm = None
138+ vdm_thrsh_high_warn = None
139+ vdm_thrsh_low_warn = None
116140
117- vdm_flag_offset = 32 * (page - 0x20 ) + index // 2
118- bit_offset = 4 * (index % 2 )
119- vdm_high_alarm_flag = bool ((VDM_flag_page [vdm_flag_offset ] >> (bit_offset )) & 0x1 )
120- vdm_low_alarm_flag = bool ((VDM_flag_page [vdm_flag_offset ] >> (bit_offset + 1 )) & 0x1 )
121- vdm_high_warn_flag = bool ((VDM_flag_page [vdm_flag_offset ] >> (bit_offset + 2 )) & 0x1 )
122- vdm_low_warn_flag = bool ((VDM_flag_page [vdm_flag_offset ] >> (bit_offset + 3 )) & 0x1 )
141+ if VDM_flag_page :
142+ vdm_flag_offset = 32 * (page - 0x20 ) + index // 2
143+ bit_offset = 4 * (index % 2 )
144+ vdm_high_alarm_flag = bool ((VDM_flag_page [vdm_flag_offset ] >> (bit_offset )) & 0x1 )
145+ vdm_low_alarm_flag = bool ((VDM_flag_page [vdm_flag_offset ] >> (bit_offset + 1 )) & 0x1 )
146+ vdm_high_warn_flag = bool ((VDM_flag_page [vdm_flag_offset ] >> (bit_offset + 2 )) & 0x1 )
147+ vdm_low_warn_flag = bool ((VDM_flag_page [vdm_flag_offset ] >> (bit_offset + 3 )) & 0x1 )
148+ else :
149+ vdm_high_alarm_flag = None
150+ vdm_low_alarm_flag = None
151+ vdm_high_warn_flag = None
152+ vdm_low_warn_flag = None
123153
124154 if vdm_type not in vdm_Page_data :
125155 vdm_Page_data [vdm_type ] = {
@@ -148,7 +178,7 @@ def get_vdm_page(self, page, VDM_flag_page):
148178 vdm_low_warn_flag ]
149179 return vdm_Page_data
150180
151- def get_vdm_allpage (self ):
181+ def get_vdm_allpage (self , field_option = ALL_FIELD ):
152182 '''
153183 This function returns VDM items from all advertised VDM pages.
154184 Output format is a dictionary. Key is observable type; value is a dictionary.
@@ -170,8 +200,13 @@ def get_vdm_allpage(self):
170200 return None
171201 VDM_START_PAGE = 0x20
172202 vdm = dict ()
173- vdm_flag_page = self .xcvr_eeprom .read_raw (VDM_FLAG_PAGE * PAGE_SIZE + PAGE_OFFSET , PAGE_SIZE )
203+
204+ if field_option & self .VDM_FLAG :
205+ vdm_flag_page = self .xcvr_eeprom .read_raw (VDM_FLAG_PAGE * PAGE_SIZE + PAGE_OFFSET , PAGE_SIZE )
206+ else :
207+ vdm_flag_page = None
208+
174209 for page in range (VDM_START_PAGE , VDM_START_PAGE + vdm_page_supported_raw + 1 ):
175- vdm_current_page = self .get_vdm_page (page , vdm_flag_page )
210+ vdm_current_page = self .get_vdm_page (page , vdm_flag_page , field_option )
176211 vdm .update (vdm_current_page )
177212 return vdm
0 commit comments