daily pastebin goal
78%
SHARE
TWEET

Untitled

a guest Feb 13th, 2017 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /usr/bin/python
  2. try:
  3.     import pprint
  4.     import smbus
  5.     from sff8472 import sff8472Dom
  6.     from sff8472 import sff8472InterfaceId
  7.  
  8. except ImportError, e:
  9.     raise ImportError (str(e) + "- required module not found")
  10.  
  11.  
  12.  
  13. if_address = 0x50
  14. dom_address = 0x51
  15. bus = smbus.SMBus(5)
  16.  
  17. def read_eeprom(address,len=256,offset=0):
  18.     ret = []
  19.     for i in range(0,len):
  20.         byte = bus.read_byte_data(address, i+offset)
  21.         ret.append(hex(byte)[2:].zfill(2))
  22.     return ret
  23.  
  24. eeprom_if = read_eeprom(if_address)
  25. eeprom_dom = read_eeprom(dom_address)
  26.  
  27. sfp_data = {}
  28.  
  29. sfpi_obj = sff8472InterfaceId(eeprom_if)
  30. if sfpi_obj != None:
  31.   sfp_data['interface'] = sfpi_obj.get_data_pretty()
  32.   cal_type = sfpi_obj.get_calibration_type()
  33.  
  34. sfpd_obj = sff8472Dom(eeprom_dom, cal_type)
  35. if sfpd_obj != None:
  36.   sfp_data['dom'] = sfpd_obj.get_data_pretty()
  37.  
  38. pp = pprint.PrettyPrinter(indent=4)
  39. pp.pprint(sfp_data)
RAW Paste Data
Top