Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update platform/device to fix bugs #63

Merged
merged 3 commits into from Mar 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
__author__ = 'Pradchaya P.<pphuchar@celestica.com>'
__author__ = 'Wirut G.<wgetbumr@celestica.com>'
__license__ = "GPL"
__version__ = "0.1.0"
__version__ = "1.0.0"
__status__ = "Development"

import os
Expand All @@ -23,21 +23,23 @@ class OpticTempUtil():
def __init__(self):
pass

def read_eeprom_specific_bytes(self, bus_num, dev_addr, offset, num_bytes):
def read_eeprom_specific_bytes(self, sysfsfile_eeprom, offset, num_bytes):
eeprom_raw = []
for i in range(0, num_bytes):
eeprom_raw.append(0x00)
eeprom_raw.append("0x00")

try:
for i in range(0, num_bytes):
p = subprocess.Popen(['i2cget', '-f', '-y', str(bus_num), str(dev_addr), str(offset+i)],stdout=subprocess.PIPE,stderr=subprocess.PIPE)
raw, err = p.communicate()
if p.returncode != 0 or err != '':
raise IOError
eeprom_raw[i] = raw.strip()
sysfsfile_eeprom.seek(offset)
raw = sysfsfile_eeprom.read(num_bytes)
except IOError:
return None

try:
for n in range(0, num_bytes):
eeprom_raw[n] = hex(ord(raw[n]))[2:].zfill(2)
except:
return None

return eeprom_raw


Expand Down Expand Up @@ -69,12 +71,14 @@ def calc_temperature(self, cal_type, eeprom_data, offset, size):

return retval

def get_optic_temp(self, bus_num, port_type):
''' TODO: Change busnum to sysfs_sfp_i2c_client_eeprom_path from caller!!!
'''
def get_optic_temp(self, sysfs_sfp_i2c_client_eeprom_path, port_type):

EEPROM_ADDR = 0x50
DOM_ADDR = 0x51
EEPROM_OFFSET = 0
DOM_OFFSET = 0
DOM_OFFSET = 256

SFP_DMT_ADDR = 92
SFP_DMT_WIDTH = 1
Expand All @@ -85,24 +89,38 @@ def get_optic_temp(self, bus_num, port_type):
QSFP_TEMP_DATA_WIDTH = 2
temperature_raw = None


''' Open file here '''
try:
sysfsfile_eeprom = open(sysfs_sfp_i2c_client_eeprom_path, mode="rb", buffering=0)
except IOError:
print("Error: reading sysfs file %s" % sysfs_sfp_i2c_client_eeprom_path)
return 0

if port_type == 'QSFP':

# QSFP only have internal calibration mode.
cal_type = 1
# read temperature raw value
temperature_raw = self.read_eeprom_specific_bytes(bus_num,EEPROM_ADDR,(EEPROM_OFFSET+QSFP_TEMP_DATA_ADDR),QSFP_TEMP_DATA_WIDTH)
temperature_raw = self.read_eeprom_specific_bytes(sysfsfile_eeprom,(EEPROM_OFFSET+QSFP_TEMP_DATA_ADDR),QSFP_TEMP_DATA_WIDTH)
else:
# read calibration type at bit 5
cal_type = self.read_eeprom_specific_bytes(bus_num,EEPROM_ADDR,EEPROM_OFFSET+SFP_DMT_ADDR,SFP_DMT_WIDTH)
cal_type = self.read_eeprom_specific_bytes(sysfsfile_eeprom,EEPROM_OFFSET+SFP_DMT_ADDR,SFP_DMT_WIDTH)
if cal_type is None:
cal_type = 0
return 0
else:
cal_type = (int(cal_type[0],16) >> 5 ) & 1
# read temperature raw value
temperature_raw = self.read_eeprom_specific_bytes(bus_num,DOM_ADDR,(DOM_OFFSET+SFP_TEMP_DATA_ADDR),SFP_TEMP_DATA_WIDTH)
temperature_raw = self.read_eeprom_specific_bytes(sysfsfile_eeprom,(DOM_OFFSET+SFP_TEMP_DATA_ADDR),SFP_TEMP_DATA_WIDTH)

try:
sysfsfile_eeprom.close()
except IOError:
print("Error: closing sysfs file %s" % file_path)
return 0

#calculate temperature
if temperature_raw is not None:
return self.calc_temperature(cal_type, temperature_raw, 0, 2)
else:
return 0
return 0
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
__author__ = 'Pradchaya P.<pphuchar@celestica.com>'
__author__ = 'Wirut G.<wgetbumr@celestica.com>'
__license__ = "GPL"
__version__ = "0.1.0"
__version__ = "1.0.0"
__status__ = "Development"

import os
Expand All @@ -23,21 +23,23 @@ class OpticTempUtil():
def __init__(self):
pass

def read_eeprom_specific_bytes(self, bus_num, dev_addr, offset, num_bytes):
def read_eeprom_specific_bytes(self, sysfsfile_eeprom, offset, num_bytes):
eeprom_raw = []
for i in range(0, num_bytes):
eeprom_raw.append(0x00)
eeprom_raw.append("0x00")

try:
for i in range(0, num_bytes):
p = subprocess.Popen(['i2cget', '-f', '-y', str(bus_num), str(dev_addr), str(offset+i)],stdout=subprocess.PIPE,stderr=subprocess.PIPE)
raw, err = p.communicate()
if p.returncode != 0 or err != '':
raise IOError
eeprom_raw[i] = raw.strip()
sysfsfile_eeprom.seek(offset)
raw = sysfsfile_eeprom.read(num_bytes)
except IOError:
return None

try:
for n in range(0, num_bytes):
eeprom_raw[n] = hex(ord(raw[n]))[2:].zfill(2)
except:
return None

return eeprom_raw


Expand Down Expand Up @@ -69,12 +71,14 @@ def calc_temperature(self, cal_type, eeprom_data, offset, size):

return retval

def get_optic_temp(self, bus_num, port_type):
''' TODO: Change busnum to sysfs_sfp_i2c_client_eeprom_path from caller!!!
'''
def get_optic_temp(self, sysfs_sfp_i2c_client_eeprom_path, port_type):

EEPROM_ADDR = 0x50
DOM_ADDR = 0x51
EEPROM_OFFSET = 0
DOM_OFFSET = 0
DOM_OFFSET = 256

SFP_DMT_ADDR = 92
SFP_DMT_WIDTH = 1
Expand All @@ -85,24 +89,38 @@ def get_optic_temp(self, bus_num, port_type):
QSFP_TEMP_DATA_WIDTH = 2
temperature_raw = None


''' Open file here '''
try:
sysfsfile_eeprom = open(sysfs_sfp_i2c_client_eeprom_path, mode="rb", buffering=0)
except IOError:
print("Error: reading sysfs file %s" % sysfs_sfp_i2c_client_eeprom_path)
return 0

if port_type == 'QSFP':

# QSFP only have internal calibration mode.
cal_type = 1
# read temperature raw value
temperature_raw = self.read_eeprom_specific_bytes(bus_num,EEPROM_ADDR,(EEPROM_OFFSET+QSFP_TEMP_DATA_ADDR),QSFP_TEMP_DATA_WIDTH)
temperature_raw = self.read_eeprom_specific_bytes(sysfsfile_eeprom,(EEPROM_OFFSET+QSFP_TEMP_DATA_ADDR),QSFP_TEMP_DATA_WIDTH)
else:
# read calibration type at bit 5
cal_type = self.read_eeprom_specific_bytes(bus_num,EEPROM_ADDR,EEPROM_OFFSET+SFP_DMT_ADDR,SFP_DMT_WIDTH)
cal_type = self.read_eeprom_specific_bytes(sysfsfile_eeprom,EEPROM_OFFSET+SFP_DMT_ADDR,SFP_DMT_WIDTH)
if cal_type is None:
cal_type = 0
return 0
else:
cal_type = (int(cal_type[0],16) >> 5 ) & 1
# read temperature raw value
temperature_raw = self.read_eeprom_specific_bytes(bus_num,DOM_ADDR,(DOM_OFFSET+SFP_TEMP_DATA_ADDR),SFP_TEMP_DATA_WIDTH)
temperature_raw = self.read_eeprom_specific_bytes(sysfsfile_eeprom,(DOM_OFFSET+SFP_TEMP_DATA_ADDR),SFP_TEMP_DATA_WIDTH)

try:
sysfsfile_eeprom.close()
except IOError:
print("Error: closing sysfs file %s" % file_path)
return 0

#calculate temperature
if temperature_raw is not None:
return self.calc_temperature(cal_type, temperature_raw, 0, 2)
else:
return 0
return 0
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
__author__ = 'Pradchaya P.<pphuchar@celestica.com>'
__author__ = 'Wirut G.<wgetbumr@celestica.com>'
__license__ = "GPL"
__version__ = "0.1.0"
__version__ = "1.0.0"
__status__ = "Development"

import os
Expand All @@ -23,21 +23,23 @@ class OpticTempUtil():
def __init__(self):
pass

def read_eeprom_specific_bytes(self, bus_num, dev_addr, offset, num_bytes):
def read_eeprom_specific_bytes(self, sysfsfile_eeprom, offset, num_bytes):
eeprom_raw = []
for i in range(0, num_bytes):
eeprom_raw.append(0x00)
eeprom_raw.append("0x00")

try:
for i in range(0, num_bytes):
p = subprocess.Popen(['i2cget', '-f', '-y', str(bus_num), str(dev_addr), str(offset+i)],stdout=subprocess.PIPE,stderr=subprocess.PIPE)
raw, err = p.communicate()
if p.returncode != 0 or err != '':
raise IOError
eeprom_raw[i] = raw.strip()
sysfsfile_eeprom.seek(offset)
raw = sysfsfile_eeprom.read(num_bytes)
except IOError:
return None

try:
for n in range(0, num_bytes):
eeprom_raw[n] = hex(ord(raw[n]))[2:].zfill(2)
except:
return None

return eeprom_raw


Expand Down Expand Up @@ -69,12 +71,14 @@ def calc_temperature(self, cal_type, eeprom_data, offset, size):

return retval

def get_optic_temp(self, bus_num, port_type):
''' TODO: Change busnum to sysfs_sfp_i2c_client_eeprom_path from caller!!!
'''
def get_optic_temp(self, sysfs_sfp_i2c_client_eeprom_path, port_type):

EEPROM_ADDR = 0x50
DOM_ADDR = 0x51
EEPROM_OFFSET = 0
DOM_OFFSET = 0
DOM_OFFSET = 256

SFP_DMT_ADDR = 92
SFP_DMT_WIDTH = 1
Expand All @@ -85,24 +89,38 @@ def get_optic_temp(self, bus_num, port_type):
QSFP_TEMP_DATA_WIDTH = 2
temperature_raw = None


''' Open file here '''
try:
sysfsfile_eeprom = open(sysfs_sfp_i2c_client_eeprom_path, mode="rb", buffering=0)
except IOError:
print("Error: reading sysfs file %s" % sysfs_sfp_i2c_client_eeprom_path)
return 0

if port_type == 'QSFP':

# QSFP only have internal calibration mode.
cal_type = 1
# read temperature raw value
temperature_raw = self.read_eeprom_specific_bytes(bus_num,EEPROM_ADDR,(EEPROM_OFFSET+QSFP_TEMP_DATA_ADDR),QSFP_TEMP_DATA_WIDTH)
temperature_raw = self.read_eeprom_specific_bytes(sysfsfile_eeprom,(EEPROM_OFFSET+QSFP_TEMP_DATA_ADDR),QSFP_TEMP_DATA_WIDTH)
else:
# read calibration type at bit 5
cal_type = self.read_eeprom_specific_bytes(bus_num,EEPROM_ADDR,EEPROM_OFFSET+SFP_DMT_ADDR,SFP_DMT_WIDTH)
cal_type = self.read_eeprom_specific_bytes(sysfsfile_eeprom,EEPROM_OFFSET+SFP_DMT_ADDR,SFP_DMT_WIDTH)
if cal_type is None:
cal_type = 0
return 0
else:
cal_type = (int(cal_type[0],16) >> 5 ) & 1
# read temperature raw value
temperature_raw = self.read_eeprom_specific_bytes(bus_num,DOM_ADDR,(DOM_OFFSET+SFP_TEMP_DATA_ADDR),SFP_TEMP_DATA_WIDTH)
temperature_raw = self.read_eeprom_specific_bytes(sysfsfile_eeprom,(DOM_OFFSET+SFP_TEMP_DATA_ADDR),SFP_TEMP_DATA_WIDTH)

try:
sysfsfile_eeprom.close()
except IOError:
print("Error: closing sysfs file %s" % file_path)
return 0

#calculate temperature
if temperature_raw is not None:
return self.calc_temperature(cal_type, temperature_raw, 0, 2)
else:
return 0
return 0