From da75648846e98b4c2e6b941839abd8ec41c482d9 Mon Sep 17 00:00:00 2001
From: GijsSchoonderbeek <schoonderbeek@astron.nl>
Date: Tue, 11 May 2021 13:29:30 +0200
Subject: [PATCH] start classification rd_unb2.py

---
 UniBoard2_I2C.py | 16 +++++++++++++-
 rd_unb2c.py      | 56 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 71 insertions(+), 1 deletion(-)

diff --git a/UniBoard2_I2C.py b/UniBoard2_I2C.py
index 3c7011d..0dfbc6b 100644
--- a/UniBoard2_I2C.py
+++ b/UniBoard2_I2C.py
@@ -13,6 +13,13 @@ LOC_POWER_TR_T    = 0x0F
 LOC_POWER_BAT     = 0x10
 LOC_POWER_IO      = 0x11
 
+LOC_POLS = {"LOC_POWER_CORE" : 0x01,
+            "LOC_POWER_ERAM" : 0x0D,
+            "LOC_POWER_TR_R" : 0x0E,
+            "LOC_POWER_TR_T" : 0x0F,
+            "LOC_POWER_BAT"  : 0x10,
+            "LOC_POWER_IO"   : 0x11}
+
 CTR_POWER_S_1V0   = 0x0E
 CTR_POWER_S_1V2   = 0x0F
 CTR_POWER_CLK     = 0x0D
@@ -46,7 +53,14 @@ CTRL_POWER        = 0x10
 # Front panel LED
 ################
 LED_DRIVER        = 0x41
-LED_COLORS = {"red": 0x06, "blue": 0x05, "green" : 0x03, "magenta": 0x04, "yellow": 0x02, "cyaan": 0x01, "white": 0x00, "black" :0x07}
+LED_COLORS = {"red": 0x06,
+              "blue": 0x05,
+              "green" : 0x03,
+              "magenta": 0x04,
+              "yellow": 0x02,
+              "cyaan": 0x01,
+              "white": 0x00,
+              "black" :0x07}
 
 ################
 # Node I2C switch
diff --git a/rd_unb2c.py b/rd_unb2c.py
index 8299b0a..b553765 100644
--- a/rd_unb2c.py
+++ b/rd_unb2c.py
@@ -15,6 +15,59 @@ else:
 from UniBoard2_I2C import *
 I2CBUSNR=3
 
+class c_pol:
+    def __init__(self, name):
+        self.name = name
+        self.vout
+        self.iout
+        self.temp
+        self.pol_dev = I2C(LOC_POLS[name])
+        self.pol_dev.bus = I2CBUSNR
+        ret_ack, ret_value = self.pol_dev.read_bytes(0)
+        if ret_ack < 1:
+            print("no device found")
+        else:
+
+    def read_vout(self):
+        sleep(0.1)
+        ret_ack, vout_mod = self.pol_dev.read_bytes(LP_VOUT_MODE, 1)
+        sleep(0.1)
+        ret_ack, raw_value = self.pol_dev.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))
+        self.vout = calc_lin_3bytes(ret_value, [vout_mod])
+
+    def read_iout(self):
+        sleep(0.1)
+        ret_ack, raw_value = self.pol_dev.read_bytes(LP_IOUT, 2)
+        ret_value=[]
+        ret_value.append(int(raw_value[:2],16))
+        ret_value.append(int(raw_value[2:],16))
+        self.iout = calc_lin_2bytes(ret_value)
+
+    def read_temp(self):
+        sleep(0.1)
+        ret_ack,raw_value = self.pol_dev.read_bytes(LP_temp, 2)
+        ret_value=[]
+        ret_value.append(int(raw_value[:2],16))
+        ret_value.append(int(raw_value[2:],16))
+        self.temp = calc_lin_2bytes(ret_value)
+
+    def read_all(self):
+        self.read_vout()
+        self.read_iout()
+        self.read_temp()
+
+    def print_status(self):
+        self.read_all()
+        stri = "POL: " + self.name + "  "
+        stri += "Output voltage :{0: <5.2f} V ".format(self.vout)
+        stri += "Output Current :{0: <5.2f} A ".format(self.iout)
+        stri += "temperature :{0: <5.2f} Deg C".format(self.temp)
+        print(stri)
+
 
 def rw_eeprom(value=0xAB):
     I2C_eeprom = I2C(EEPROM)
@@ -179,3 +232,6 @@ else:
     for node_cnt in range(4):
         read_pol(node_cnt, LOC_POWER_CORE)
     read_pol(-1,0x01)
+
+polletje = c_pol(LOC_POWER_CORE)
+polletje.print_status()
\ No newline at end of file
-- 
GitLab