Format the commands so they'll be easier to pull apart
This commit is contained in:
parent
14a8201f00
commit
8d0599040c
1 changed files with 23 additions and 12 deletions
|
@ -345,6 +345,7 @@ if __name__ == "__main__":
|
||||||
parts = clusterhat.split(".")
|
parts = clusterhat.split(".")
|
||||||
version = int(parts[0])
|
version = int(parts[0])
|
||||||
version_minor = int(parts[1])
|
version_minor = int(parts[1])
|
||||||
|
|
||||||
elif (not os.path.isfile(hat_product)
|
elif (not os.path.isfile(hat_product)
|
||||||
or not os.access(hat_product, os.R_OK)
|
or not os.access(hat_product, os.R_OK)
|
||||||
or not os.path.isfile(hat_uuid)
|
or not os.path.isfile(hat_uuid)
|
||||||
|
@ -356,6 +357,7 @@ if __name__ == "__main__":
|
||||||
or not os.path.isfile(hat_version)
|
or not os.path.isfile(hat_version)
|
||||||
or not os.access(hat_version, os.R_OK)):
|
or not os.access(hat_version, os.R_OK)):
|
||||||
clusterhat = False # No HAT found
|
clusterhat = False # No HAT found
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# HAT has been found validate it
|
# HAT has been found validate it
|
||||||
f = open(hat_product, "r")
|
f = open(hat_product, "r")
|
||||||
|
@ -374,6 +376,7 @@ if __name__ == "__main__":
|
||||||
version_minor = tmp - 32
|
version_minor = tmp - 32
|
||||||
else:
|
else:
|
||||||
clusterhat = False # No ClusterHAT found
|
clusterhat = False # No ClusterHAT found
|
||||||
|
|
||||||
if (clusterhat):
|
if (clusterhat):
|
||||||
clusterhat_size = 4 if "clusterhat_size" not in config else int(config["clusterhat_size"])
|
clusterhat_size = 4 if "clusterhat_size" not in config else int(config["clusterhat_size"])
|
||||||
if clusterhat_size > 4: clusterhat_size = 4
|
if clusterhat_size > 4: clusterhat_size = 4
|
||||||
|
@ -451,7 +454,6 @@ if __name__ == "__main__":
|
||||||
else:
|
else:
|
||||||
wp_link = -1
|
wp_link = -1
|
||||||
|
|
||||||
|
|
||||||
# Get list of ClusterCTRL I2C devices
|
# Get list of ClusterCTRL I2C devices
|
||||||
busses = [] # Get list of devices
|
busses = [] # Get list of devices
|
||||||
for fn in glob.glob(clusterctrl_prefix+"*"):
|
for fn in glob.glob(clusterctrl_prefix+"*"):
|
||||||
|
@ -488,7 +490,12 @@ if __name__ == "__main__":
|
||||||
# Sort devices based on order
|
# Sort devices based on order
|
||||||
ctrl.sort(key=lambda tup: tup[0])
|
ctrl.sort(key=lambda tup: tup[0])
|
||||||
|
|
||||||
# Are we running init and should we create the symlinks for usbboot?
|
##############
|
||||||
|
## End Init ##
|
||||||
|
##############
|
||||||
|
|
||||||
|
# Parse arguments and do actions
|
||||||
|
|
||||||
if (args == 2 and sys.argv[1] == "init"):
|
if (args == 2 and sys.argv[1] == "init"):
|
||||||
if "link" in config and config["link"] == "1":
|
if "link" in config and config["link"] == "1":
|
||||||
# Only root should fiddle with the links
|
# Only root should fiddle with the links
|
||||||
|
@ -510,13 +517,7 @@ if __name__ == "__main__":
|
||||||
os.unlink(nfsboot+path)
|
os.unlink(nfsboot+path)
|
||||||
os.symlink(nfsroot+"p"+p+"/boot/", nfsboot+path)
|
os.symlink(nfsroot+"p"+p+"/boot/", nfsboot+path)
|
||||||
|
|
||||||
##############
|
elif (args == 2 and (sys.argv[1] == "on" or sys.argv[1] == "off")):
|
||||||
## End Init ##
|
|
||||||
##############
|
|
||||||
|
|
||||||
# Parse arguments and do actions
|
|
||||||
|
|
||||||
if (args == 2 and (sys.argv[1] == "on" or sys.argv[1] == "off")):
|
|
||||||
# Turn on/off ALL devices
|
# Turn on/off ALL devices
|
||||||
if (clusterhat):
|
if (clusterhat):
|
||||||
# Turn all ClusterHAT ports on
|
# Turn all ClusterHAT ports on
|
||||||
|
@ -578,6 +579,7 @@ if __name__ == "__main__":
|
||||||
else:
|
else:
|
||||||
send_cmd(c, CMD_OFF, pi)
|
send_cmd(c, CMD_OFF, pi)
|
||||||
send_cmd(c, CMD_ALERT_OFF)
|
send_cmd(c, CMD_ALERT_OFF)
|
||||||
|
|
||||||
elif (args > 2 and (sys.argv[1] == "on" or sys.argv[1] == "off")):
|
elif (args > 2 and (sys.argv[1] == "on" or sys.argv[1] == "off")):
|
||||||
# Turn on/off pX
|
# Turn on/off pX
|
||||||
actioned = 0
|
actioned = 0
|
||||||
|
@ -642,6 +644,7 @@ if __name__ == "__main__":
|
||||||
else:
|
else:
|
||||||
send_cmd(c, CMD_OFF, zero-lastpi+c[3])
|
send_cmd(c, CMD_OFF, zero-lastpi+c[3])
|
||||||
break
|
break
|
||||||
|
|
||||||
elif (args > 2 and sys.argv[1] == "usbboot" and (sys.argv[2] == "on" or sys.argv[2] == "off")):
|
elif (args > 2 and sys.argv[1] == "usbboot" and (sys.argv[2] == "on" or sys.argv[2] == "off")):
|
||||||
# Enable of Disable USBBOOT (supported on Compute Modules) for Px
|
# Enable of Disable USBBOOT (supported on Compute Modules) for Px
|
||||||
actioned = 0
|
actioned = 0
|
||||||
|
@ -668,6 +671,7 @@ if __name__ == "__main__":
|
||||||
actioned+=1
|
actioned+=1
|
||||||
else:
|
else:
|
||||||
send_cmd(c, CMD_USBBOOT_DIS, zero-lastpi+c[3])
|
send_cmd(c, CMD_USBBOOT_DIS, zero-lastpi+c[3])
|
||||||
|
|
||||||
elif (args == 2 and sys.argv[1] == "status"):
|
elif (args == 2 and sys.argv[1] == "status"):
|
||||||
# Show status of all Cluster HAT / ClusterCTRL devices
|
# Show status of all Cluster HAT / ClusterCTRL devices
|
||||||
print("clusterhat:{}".format(clusterhat))
|
print("clusterhat:{}".format(clusterhat))
|
||||||
|
@ -775,6 +779,7 @@ if __name__ == "__main__":
|
||||||
hub.off()
|
hub.off()
|
||||||
else:
|
else:
|
||||||
hub.on()
|
hub.on()
|
||||||
|
|
||||||
# if (clusterctrl): # TODO
|
# if (clusterctrl): # TODO
|
||||||
elif (args == 3 and sys.argv[1] == "hub" and (sys.argv[2] == "reset")):
|
elif (args == 3 and sys.argv[1] == "hub" and (sys.argv[2] == "reset")):
|
||||||
if (clusterhat and version!=1):
|
if (clusterhat and version!=1):
|
||||||
|
@ -810,6 +815,7 @@ if __name__ == "__main__":
|
||||||
send_cmd(c, CMD_ALERT_ON)
|
send_cmd(c, CMD_ALERT_ON)
|
||||||
else:
|
else:
|
||||||
send_cmd(c, CMD_ALERT_OFF)
|
send_cmd(c, CMD_ALERT_OFF)
|
||||||
|
|
||||||
elif (args > 3 and sys.argv[1] == "alert" and (sys.argv[2] == "on" or sys.argv[2] == "off")):
|
elif (args > 3 and sys.argv[1] == "alert" and (sys.argv[2] == "on" or sys.argv[2] == "off")):
|
||||||
# Turn on/off ALERT LED for pX
|
# Turn on/off ALERT LED for pX
|
||||||
|
|
||||||
|
@ -846,6 +852,7 @@ if __name__ == "__main__":
|
||||||
else:
|
else:
|
||||||
send_cmd(c, CMD_ALERT_OFF)
|
send_cmd(c, CMD_ALERT_OFF)
|
||||||
break
|
break
|
||||||
|
|
||||||
elif (args == 3 and sys.argv[1] == "led" and (sys.argv[2] == "on" or sys.argv[2] == "off")):
|
elif (args == 3 and sys.argv[1] == "led" and (sys.argv[2] == "on" or sys.argv[2] == "off")):
|
||||||
# Enable or Disable LED (not supported on ClusterHAT v1.x)
|
# Enable or Disable LED (not supported on ClusterHAT v1.x)
|
||||||
if (clusterhat and version == 2):
|
if (clusterhat and version == 2):
|
||||||
|
@ -859,6 +866,7 @@ if __name__ == "__main__":
|
||||||
send_cmd(c, CMD_LED_EN, 0)
|
send_cmd(c, CMD_LED_EN, 0)
|
||||||
else:
|
else:
|
||||||
send_cmd(c, CMD_LED_DIS, 0)
|
send_cmd(c, CMD_LED_DIS, 0)
|
||||||
|
|
||||||
elif (args == 3 and sys.argv[1] == "wp" and (sys.argv[2] == "on" or sys.argv[2] == "off")):
|
elif (args == 3 and sys.argv[1] == "wp" and (sys.argv[2] == "on" or sys.argv[2] == "off")):
|
||||||
# Not supported on ClusterCTRL or ClusterHAT v1.x
|
# Not supported on ClusterCTRL or ClusterHAT v1.x
|
||||||
if (clusterhat and version == 2):
|
if (clusterhat and version == 2):
|
||||||
|
@ -869,10 +877,12 @@ if __name__ == "__main__":
|
||||||
print("Unable to disable EEPROM WP (Solder link set)")
|
print("Unable to disable EEPROM WP (Solder link set)")
|
||||||
else:
|
else:
|
||||||
wp.off()
|
wp.off()
|
||||||
|
|
||||||
elif (args > 1 and sys.argv[1] == "getpath"):
|
elif (args > 1 and sys.argv[1] == "getpath"):
|
||||||
paths = getusbpaths()
|
paths = getusbpaths()
|
||||||
for p, path in sorted(paths.iteritems()):
|
for p, path in sorted(paths.iteritems()):
|
||||||
print("p{}:{}".format(p, path))
|
print("p{}:{}".format(p, path))
|
||||||
|
|
||||||
elif (args == 3 and sys.argv[1] == "savedefaults"):
|
elif (args == 3 and sys.argv[1] == "savedefaults"):
|
||||||
# Set default EEPROM for device with "order"
|
# Set default EEPROM for device with "order"
|
||||||
if (int(sys.argv[2])<1 or int(sys.argv[2])>255):
|
if (int(sys.argv[2])<1 or int(sys.argv[2])>255):
|
||||||
|
@ -885,6 +895,7 @@ if __name__ == "__main__":
|
||||||
print("saved")
|
print("saved")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
print("Error: Unable to find Cluster CTRL device with that order")
|
print("Error: Unable to find Cluster CTRL device with that order")
|
||||||
|
|
||||||
elif (args == 4 and sys.argv[1] == "setorder"):
|
elif (args == 4 and sys.argv[1] == "setorder"):
|
||||||
if (int(sys.argv[2])<1 or int(sys.argv[2])>255):
|
if (int(sys.argv[2])<1 or int(sys.argv[2])>255):
|
||||||
print("Invalid order old")
|
print("Invalid order old")
|
||||||
|
@ -896,6 +907,7 @@ if __name__ == "__main__":
|
||||||
for c in ctrl:
|
for c in ctrl:
|
||||||
if (int(sys.argv[2]) == int(c[0])):
|
if (int(sys.argv[2]) == int(c[0])):
|
||||||
send_cmd(c, CMD_SET_ORDER, int(sys.argv[3]))
|
send_cmd(c, CMD_SET_ORDER, int(sys.argv[3]))
|
||||||
|
|
||||||
elif (args == 3 and sys.argv[1] == "save"):
|
elif (args == 3 and sys.argv[1] == "save"):
|
||||||
# Set Power on state/USBBOOT/order to EEPROM for device with "order"
|
# Set Power on state/USBBOOT/order to EEPROM for device with "order"
|
||||||
if (int(sys.argv[2])<1 or int(sys.argv[2])>255):
|
if (int(sys.argv[2])<1 or int(sys.argv[2])>255):
|
||||||
|
@ -978,6 +990,7 @@ if __name__ == "__main__":
|
||||||
send_cmd(c, CMD_FAN, 1)
|
send_cmd(c, CMD_FAN, 1)
|
||||||
else:
|
else:
|
||||||
send_cmd(c, CMD_FAN, 0)
|
send_cmd(c, CMD_FAN, 0)
|
||||||
|
|
||||||
elif (args == 4 and sys.argv[1] == "fan" and (sys.argv[2] == "on" or sys.argv[2] == "off")):
|
elif (args == 4 and sys.argv[1] == "fan" and (sys.argv[2] == "on" or sys.argv[2] == "off")):
|
||||||
# Turn fan on/off for CTRL device with "order" or Controller if arg is "c"
|
# Turn fan on/off for CTRL device with "order" or Controller if arg is "c"
|
||||||
if (sys.argv[3] != "c" and (int(sys.argv[3])<1 or int(sys.argv[3])>255)):
|
if (sys.argv[3] != "c" and (int(sys.argv[3])<1 or int(sys.argv[3])>255)):
|
||||||
|
@ -1003,8 +1016,6 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
elif (args == 2 and sys.argv[1] == "maxpi"):
|
elif (args == 2 and sys.argv[1] == "maxpi"):
|
||||||
print(maxpi)
|
print(maxpi)
|
||||||
elif (args == 2 and sys.argv[1] == "init"):
|
|
||||||
# First run init is handled above this is just here to allow the command to succeed
|
|
||||||
pass
|
|
||||||
else:
|
else:
|
||||||
print("Error: Missing arguments")
|
print("Error: Missing arguments")
|
||||||
|
|
Loading…
Reference in a new issue