diff options
author | Raptor Engineering Development Team <support@raptorengineering.com> | 2018-02-19 18:05:50 -0600 |
---|---|---|
committer | Raptor Engineering Development Team <support@raptorengineering.com> | 2019-04-19 10:28:12 +0000 |
commit | 61fc936d039de054cd5b89549ca900dd96cd6ab6 (patch) | |
tree | 9151532ac3947bbdc6e09d39dddd3c8444d1a6dd | |
parent | ffd276f4f0a7b61f14b64165074a77058b0f9f16 (diff) | |
download | blackbird-skeleton-61fc936d039de054cd5b89549ca900dd96cd6ab6.tar.gz blackbird-skeleton-61fc936d039de054cd5b89549ca900dd96cd6ab6.zip |
Retry I2C set commands if readback does not match desired value
-rw-r--r-- | pyiplledmonitor/ipl_status_led_monitor.py | 53 |
1 files changed, 44 insertions, 9 deletions
diff --git a/pyiplledmonitor/ipl_status_led_monitor.py b/pyiplledmonitor/ipl_status_led_monitor.py index 6e36d00..555e26b 100644 --- a/pyiplledmonitor/ipl_status_led_monitor.py +++ b/pyiplledmonitor/ipl_status_led_monitor.py @@ -80,8 +80,9 @@ class IPLStatusLEDMonitor(DbusProperties, DbusObjectManager): if (proc.returncode != 0): comm_fail = True else: - retval = int(out, 64) - except: + retval = int(out, 16) + except Exception as e: + print e comm_fail = True; pass if (comm_fail == True): @@ -91,9 +92,46 @@ class IPLStatusLEDMonitor(DbusProperties, DbusObjectManager): time.sleep(0.1) if (comm_fail == False): candidate_values.append(retval) - retval = max(set(candidate_values), key=candidate_values.count) + try: + retval = max(set(candidate_values), key=candidate_values.count) + except: + retval = 0xff return retval + def IPLLEDWriteI2CByte(self, byte, value): + retry_number = 0 + readback_value = 0 + comm_fail = True; + while (comm_fail == True): + comm_fail = False; + try: + proc = subprocess.Popen(["i2cset", "-y", "12", "0x31", str(byte), str(value)], stdout=subprocess.PIPE, stderr=open(os.devnull, 'wb'), shell=False) + (out, err) = proc.communicate() + if (proc.returncode != 0): + comm_fail = True + except: + comm_fail = True; + pass + if (comm_fail == False): + try: + proc = subprocess.Popen(["i2cget", "-y", "12", "0x31", str(byte)], stdout=subprocess.PIPE, stderr=open(os.devnull, 'wb'), shell=False) + (out, err) = proc.communicate() + if (proc.returncode != 0): + comm_fail = True + else: + readback_value = int(out, 16) + except: + comm_fail = True; + pass + if (comm_fail == False): + if (readback_value != value): + comm_fail = True + if (comm_fail == True): + retry_number += 1 + if (retry_number > 64): + break + time.sleep(0.1) + def IPLLEDCheckSystem(self): self.check = list(chr(self.IPLLEDReadI2CByte(12))) self.check.append(chr(self.IPLLEDReadI2CByte(13))) @@ -163,15 +201,12 @@ class IPLStatusLEDMonitor(DbusProperties, DbusObjectManager): '21': 11, '22': 12 }.get(self.current_ipl_istep_major, 0) - proc = subprocess.Popen(["i2cset", "-y", "12", "0x31", "0x10", str(128 + led_code)], stdout=subprocess.PIPE, stderr=open(os.devnull, 'wb'), shell=False) - (out, err) = proc.communicate() + self.IPLLEDWriteI2CByte(0x10, 0x80 + led_code) except: - proc = subprocess.Popen(["i2cset", "-y", "12", "0x31", "0x10", "128"], stdout=subprocess.PIPE, stderr=open(os.devnull, 'wb'), shell=False) - (out, err) = proc.communicate() + self.IPLLEDWriteI2CByte(0x10, 0x80) else: # Put LED bank back into normal operation - proc = subprocess.Popen(["i2cset", "-y", "12", "0x31", "0x10", "0x00"], stdout=subprocess.PIPE, stderr=open(os.devnull, 'wb'), shell=False) - (out, err) = proc.communicate() + self.IPLLEDWriteI2CByte(0x10, 0x00) if ((status_changed == True) and (self.current_ipl_status == "IPL_COMPLETE")): if (initial_start == False): |