Skip to content
Snippets Groups Projects
Commit 525bccc6 authored by Gijs Schoonderbeek's avatar Gijs Schoonderbeek
Browse files

Moved EEPROM to separate class

parent 6214a9dd
No related branches found
No related tags found
No related merge requests found
......@@ -41,47 +41,8 @@ class ApspuClass:
self.pols = []
for pol in list(CTR_POLS.keys()):
self.pols.append(PolClass(pol))
self.dev_i2c_eeprom = I2C(EEPROM)
self.dev_i2c_eeprom.bus_nr = I2CBUSNR
self.fans = FanmonitorClass()
def write_eeprom(self, data="APSPU", address=0):
#
# Write the EEPROM with the serial number etc.
#
ret_ack, ret_value = self.dev_i2c_eeprom.read_bytes(0)
if ret_ack < 1:
print("EEPROM not found during write")
return False
else:
wr_data = bytearray(data.encode("utf-8", errors="ignore"))
for loc, data_byte in enumerate(wr_data):
self.dev_i2c_eeprom.write_bytes(address+loc, data_byte)
sleep(0.1)
return True
def read_eeprom(self, address=0, nof_bytes=5):
#
# Read the EEPROM with the serial number etc.
#
ret_ack, ret_value = self.dev_i2c_eeprom.read_last_reg(1)
if ret_ack < 1:
print("no EEPROM found during read")
return False
else:
ret_ack, ret_value = self.dev_i2c_eeprom.read_bytes(address, nof_bytes)
str_return = bytes.fromhex(ret_value[:nof_bytes*2]).decode('UTF-8')
return str_return
def wr_rd_eeprom(self, value="APSPU-1", address = 0):
#
# Write and Read the EEPROM to check functionality
#
if self.write_eeprom(value, address=0):
ret_value = self.read_eeprom(address=0, nof_bytes=len(value))
stri = "Wrote to EEPROM register 0x{2:x} : {0}, Read from EEPROM: {1}".format(value, ret_value, address)
print(stri)
return True
self.eeprom = EepromClass()
def read_all(self):
#
......@@ -131,6 +92,54 @@ class ApspuClass:
pol.on_off(on)
return True
class EepromClass:
#
# Class to handle EEPROM communication
#
def __init__(self):
#
# All monitoring points Point of Load DC/DC converter
#
self.dev_i2c_eeprom = I2C(EEPROM)
self.dev_i2c_eeprom.bus_nr = I2CBUSNR
def write_eeprom(self, data="APSPU", address=0):
#
# Write the EEPROM with the serial number etc.
#
ret_ack, ret_value = self.dev_i2c_eeprom.read_bytes(0)
if ret_ack < 1:
print("EEPROM not found during write")
return False
else:
wr_data = bytearray(data.encode("utf-8", errors="ignore"))
for loc, data_byte in enumerate(wr_data):
self.dev_i2c_eeprom.write_bytes(address+loc, data_byte)
sleep(0.1)
return True
def read_eeprom(self, address=0, nof_bytes=5):
#
# Read the EEPROM with the serial number etc.
#
ret_ack, ret_value = self.dev_i2c_eeprom.read_last_reg(1)
if ret_ack < 1:
print("no EEPROM found during read")
return False
else:
ret_ack, ret_value = self.dev_i2c_eeprom.read_bytes(address, nof_bytes)
str_return = bytes.fromhex(ret_value[:nof_bytes*2]).decode('UTF-8')
return str_return
def wr_rd_eeprom(self, value="APSPU-1", address = 0):
#
# Write and Read the EEPROM to check functionality
#
if self.write_eeprom(value, address=0):
ret_value = self.read_eeprom(address=0, nof_bytes=len(value))
stri = "Wrote to EEPROM register 0x{2:x} : {0}, Read from EEPROM: {1}".format(value, ret_value, address)
print(stri)
return True
class PolClass:
......
......@@ -46,5 +46,5 @@ apspu.print_status()
#apspu.apspu_on_off(True)
id = "APSPU-" + sys.argv[1]
serial = sys.argv[2]
apspu.wr_rd_eeprom(id, address=0)
apspu.wr_rd_eeprom(serial, address=0x20)
apspu.eeprom.wr_rd_eeprom(id, address=0)
apspu.eeprom.wr_rd_eeprom(serial, address=0x20)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment