Loading py393sata/x393sata_eyesis4pi_control.py +23 −9 Original line number Original line Diff line number Diff line Loading @@ -17,13 +17,13 @@ LOGFILE = "/var/log/x393sata_eyesis4pi.log" STATEFILE = "/var/state/ssd" STATEFILE = "/var/state/ssd" # constants # constants RESET_LIMIT = 10 RESET_LIMIT = 3 DRIVER_RELOAD_LIMIT = 5 DRIVER_RELOAD_LIMIT = 5 DRIVER_WAIT_TIME = 10 DRIVER_WAIT_TIME = 10 DRIVER_UNLOAD_TRIES = 30 DRIVER_UNLOAD_TRIES = 30 #global #global DEVICE_NOT_CONNECTED = True DEVICE_CONNECTED = False def colorize(string, color, bold): def colorize(string, color, bold): color=color.upper() color=color.upper() Loading Loading @@ -78,7 +78,7 @@ def shout(cmd): def connection_errors(): def connection_errors(): global DEVICE_NOT_CONNECTED global DEVICE_CONNECTED result = True result = True skip0 = True skip0 = True Loading @@ -100,7 +100,7 @@ def connection_errors(): if first_line: if first_line: log_msg("%s: 0x%08x [%08x]"%(group_range, data, byte_addr)) log_msg("%s: 0x%08x [%08x]"%(group_range, data, byte_addr)) if data!=0: if data!=0: DEVICE_NOT_CONNECTED = False DEVICE_CONNECTED = True first_line = False first_line = False if fld_value or not skip0: if fld_value or not skip0: log_msg("%8x : %s (%s)"%(fld_value, fld['name'], fld['description'] )) log_msg("%8x : %s (%s)"%(fld_value, fld['name'], fld['description'] )) Loading @@ -112,12 +112,18 @@ def connection_errors(): def reset_device(): def reset_device(): global DEVICE_CONNECTED result = False result = False sleep(0.5) sleep(0.5) for i in range(RESET_LIMIT): for i in range(RESET_LIMIT): if not connection_errors(): if not connection_errors(): if i==0: DEVICE_CONNECTED = False log_msg("connection error ("+str(i)+"), resetting device",4) log_msg("connection error ("+str(i)+"), resetting device",4) sata.reset_ie() sata.reset_ie() sata.reset_device() sata.reset_device() Loading @@ -126,9 +132,10 @@ def reset_device(): if i!=0: if i!=0: log_msg("resetting device: success") log_msg("resetting device: success") result = True result = True load_driver() break break # load driver in any case load_driver() return result return result def load_ahci_elphel_driver(): def load_ahci_elphel_driver(): Loading Loading @@ -185,7 +192,7 @@ def load_driver(): log_msg("SATA failed, SSD was not detected: reconnect SSD",2) log_msg("SATA failed, SSD was not detected: reconnect SSD",2) shout("echo 0 > "+STATEFILE) shout("echo 0 > "+STATEFILE) else: else: if DEVICE_NOT_CONNECTED: if not DEVICE_CONNECTED: log_msg("SSD was not detected, ahci_elphel driver is loaded",4) log_msg("SSD was not detected, ahci_elphel driver is loaded",4) else: else: log_msg("SATA ok, SSD detected after "+str(i)+" tries") log_msg("SATA ok, SSD detected after "+str(i)+" tries") Loading Loading @@ -219,10 +226,17 @@ def reload_driver(): connection_errors() connection_errors() load_ahci_elphel_driver() load_ahci_elphel_driver() if DEVICE_CONNECTED: sleep(DRIVER_WAIT_TIME) sleep(DRIVER_WAIT_TIME) result = check_device() result = check_device() if DEVICE_NOT_CONNECTED: # one more try if not result: log_msg(colorize("SSD was not detected: waiting for another "+str(DRIVER_WAIT_TIME)+" seconds",'YELLOW',True)) sleep(DRIVER_WAIT_TIME) result = check_device() else: result = True result = True return result return result Loading Loading
py393sata/x393sata_eyesis4pi_control.py +23 −9 Original line number Original line Diff line number Diff line Loading @@ -17,13 +17,13 @@ LOGFILE = "/var/log/x393sata_eyesis4pi.log" STATEFILE = "/var/state/ssd" STATEFILE = "/var/state/ssd" # constants # constants RESET_LIMIT = 10 RESET_LIMIT = 3 DRIVER_RELOAD_LIMIT = 5 DRIVER_RELOAD_LIMIT = 5 DRIVER_WAIT_TIME = 10 DRIVER_WAIT_TIME = 10 DRIVER_UNLOAD_TRIES = 30 DRIVER_UNLOAD_TRIES = 30 #global #global DEVICE_NOT_CONNECTED = True DEVICE_CONNECTED = False def colorize(string, color, bold): def colorize(string, color, bold): color=color.upper() color=color.upper() Loading Loading @@ -78,7 +78,7 @@ def shout(cmd): def connection_errors(): def connection_errors(): global DEVICE_NOT_CONNECTED global DEVICE_CONNECTED result = True result = True skip0 = True skip0 = True Loading @@ -100,7 +100,7 @@ def connection_errors(): if first_line: if first_line: log_msg("%s: 0x%08x [%08x]"%(group_range, data, byte_addr)) log_msg("%s: 0x%08x [%08x]"%(group_range, data, byte_addr)) if data!=0: if data!=0: DEVICE_NOT_CONNECTED = False DEVICE_CONNECTED = True first_line = False first_line = False if fld_value or not skip0: if fld_value or not skip0: log_msg("%8x : %s (%s)"%(fld_value, fld['name'], fld['description'] )) log_msg("%8x : %s (%s)"%(fld_value, fld['name'], fld['description'] )) Loading @@ -112,12 +112,18 @@ def connection_errors(): def reset_device(): def reset_device(): global DEVICE_CONNECTED result = False result = False sleep(0.5) sleep(0.5) for i in range(RESET_LIMIT): for i in range(RESET_LIMIT): if not connection_errors(): if not connection_errors(): if i==0: DEVICE_CONNECTED = False log_msg("connection error ("+str(i)+"), resetting device",4) log_msg("connection error ("+str(i)+"), resetting device",4) sata.reset_ie() sata.reset_ie() sata.reset_device() sata.reset_device() Loading @@ -126,9 +132,10 @@ def reset_device(): if i!=0: if i!=0: log_msg("resetting device: success") log_msg("resetting device: success") result = True result = True load_driver() break break # load driver in any case load_driver() return result return result def load_ahci_elphel_driver(): def load_ahci_elphel_driver(): Loading Loading @@ -185,7 +192,7 @@ def load_driver(): log_msg("SATA failed, SSD was not detected: reconnect SSD",2) log_msg("SATA failed, SSD was not detected: reconnect SSD",2) shout("echo 0 > "+STATEFILE) shout("echo 0 > "+STATEFILE) else: else: if DEVICE_NOT_CONNECTED: if not DEVICE_CONNECTED: log_msg("SSD was not detected, ahci_elphel driver is loaded",4) log_msg("SSD was not detected, ahci_elphel driver is loaded",4) else: else: log_msg("SATA ok, SSD detected after "+str(i)+" tries") log_msg("SATA ok, SSD detected after "+str(i)+" tries") Loading Loading @@ -219,10 +226,17 @@ def reload_driver(): connection_errors() connection_errors() load_ahci_elphel_driver() load_ahci_elphel_driver() if DEVICE_CONNECTED: sleep(DRIVER_WAIT_TIME) sleep(DRIVER_WAIT_TIME) result = check_device() result = check_device() if DEVICE_NOT_CONNECTED: # one more try if not result: log_msg(colorize("SSD was not detected: waiting for another "+str(DRIVER_WAIT_TIME)+" seconds",'YELLOW',True)) sleep(DRIVER_WAIT_TIME) result = check_device() else: result = True result = True return result return result Loading