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

rb_unb2c.py tested on the pi

parent 0c47fba0
No related branches found
No related tags found
1 merge request!2Modified the scripts to run on Raspberry Pi.
......@@ -22,7 +22,7 @@ import smbus
import sys
from time import *
DEBUG = True
DEBUG = False #True
class I2C:
......@@ -39,6 +39,7 @@ class I2C:
for cnt in range(bytes_to_read):
ret_value += (hex(rd_value[cnt])[2:])
ret_ack = 1
# sleep(0.2)
except IOError, err:
ret_ack = 0
ret_value = 0
......@@ -54,6 +55,7 @@ class I2C:
try:
ret_value.append(bus.read_byte(self.I2C_Address))
ret_ack = 1
# sleep(0.2)
except IOError, err:
ret_ack = 0
ret_value = 0
......@@ -66,7 +68,7 @@ class I2C:
try:
bus.write_i2c_block_data(self.I2C_Address, register, [data])
ret_ack = 1
sleep(0.2)
sleep(0.3)
except IOError, err:
ret_ack = 0
ret_value = 0
......@@ -77,9 +79,9 @@ class I2C:
def write_pointer(self, register):
bus = smbus.SMBus(self.bus_nr)
try:
ret_value = bus.read_i2c_block_data(self.I2C_Address, register, 1)
ret_value = bus.read_i2c_block_data(self.I2C_Address, register, register)
ret_ack = 1
sleep(0.2)
sleep(0.3)
except IOError, err:
ret_ack = 0
ret_value = 0
......
......@@ -34,7 +34,7 @@ def rw_eeprom(value=0xAB):
print(pr_stri)
I2C_eeprom.write_bytes(0x00, value)
ret_ack, ret_value = I2C_eeprom.read_bytes(0x00, 1)
stri = "Wrote to EEPROM: {0}, Read from EEPROM: {1} ".format(value, ret_value)
stri = "Wrote to EEPROM: 0x{0:X}, Read from EEPROM: 0x{1} ".format(value, ret_value)
print(stri)
def front_led(value=0xFF):
......@@ -60,18 +60,28 @@ def front_led(value=0xFF):
front.write_bytes(0x01, 0xf)
def read_pol(node_nr, i2c_addr):
if node_nr >= 0:
main_switch = I2C(0x71)
main_switch.bus = I2CBUSNR
ret_ack = main_switch.write_bytes(0x0, 0x01<<node_nr) #select Node
if ret_ack < 1:
print("Main I2C switch not found")
return False
else:
node_switch = I2C(0x72)
node_switch.bus = I2CBUSNR
ret_ack = node_switch.write_bytes(0x0, 0x20) #select DDR4
if ret_ack < 1:
print("Node I2C switch not found")
return False
else:
print("Central POL")
main_switch = I2C(0x71)
main_switch.bus = I2CBUSNR
ret_ack = main_switch.write_bytes(0x0, 0x10) #select Pol
if ret_ack < 1:
print("Main I2C switch not found")
return False
LOC_PWR = I2C(i2c_addr)
LOC_PWR.bus = I2CBUSNR
ret_ack, ret_value = LOC_PWR.read_bytes(0)
......@@ -81,28 +91,27 @@ def read_pol(node_nr, i2c_addr):
# pr_stri = "Found device at address 0x{:02x}".format(LOC_PWR.I2C_Address)
# print(pr_stri)
ret_ack, vout_mod = LOC_PWR.read_bytes(LP_VOUT_MODE, 1)
ret_ack, ret_value = LOC_PWR.read_bytes(LP_VOUT, 2)
ret_ack, raw_value = LOC_PWR.read_bytes(LP_VOUT, 2)
vout_mod = int(vout_mod,16)
ret_value = []
ret_value.append(int(raw_value[:2], 16))
ret_value.append(int(raw_value[2:], 16))
vout = calc_lin_3bytes(ret_value, vout_mod)
stri = "Output Current :{0:2.2f} A ".format(iout)
# print(stri)
vout = calc_lin_3bytes(ret_value, [vout_mod])
stri = "Output voltage :{0: <5.2f} V ".format(vout)
ret_ack, raw_value = LOC_PWR.read_bytes(LP_IOUT, 2)
ret_value=[]
ret_value.append(int(raw_value[:2],16))
ret_value.append(int(raw_value[2:],16))
iout = calc_lin_2bytes(ret_value)
stri += "Output Current :{0:2.2f} A ".format(iout)
# print(stri)
stri += "Output Current :{0: <5.2f} A ".format(iout)
ret_ack,raw_value = LOC_PWR.read_bytes(LP_temp, 2)
ret_value=[]
ret_value.append(int(raw_value[:2],16))
ret_value.append(int(raw_value[2:],16))
temp = calc_lin_2bytes(ret_value)
stri=+ "temperature :{0:2.2f} Deg C".format(temp)
stri += "temperature :{0: <5.2f} Deg C".format(temp)
print(stri)
return True
def read_ddr(node_nr = 0, module=0):
main_switch = I2C(0x71)
......@@ -166,7 +175,7 @@ def read_qsfp(node_nr = 0, module=0):
stri = "Voltage QSFP in slot {0} node {1} is {2:3.2f} V".format(module, node_nr, Power_in_mod)
print(stri)
if 1:
if 0:
rw_eeprom(0xCD)
front_led()
for node_cnt in range(4):
......@@ -175,5 +184,7 @@ if 1:
for node_cnt in range(4):
for qsfp_cnt in range(6):
read_qsfp(node_nr = node_cnt, module=qsfp_cnt)
else:
for node_cnt in range(4):
read_pol(node_cnt, LOC_POWER_CORE)
read_pol(-1,0x01)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment