Refactor into __main__ block
This commit is contained in:
parent
e02af611ad
commit
b0130c27a6
1 changed files with 943 additions and 943 deletions
|
@ -40,10 +40,10 @@ import smbus
|
||||||
#
|
#
|
||||||
# <order> selects which Cluster CTRL devices matches that <order> number
|
# <order> selects which Cluster CTRL devices matches that <order> number
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
args = len(sys.argv)
|
||||||
|
|
||||||
args = len(sys.argv)
|
if ( args == 1 or sys.argv[1] == 'help' or sys.argv[1] == '--help' or sys.argv[1] == '-h' or sys.argv[1] == '/?' ):
|
||||||
|
|
||||||
if ( args == 1 or sys.argv[1] == 'help' or sys.argv[1] == '--help' or sys.argv[1] == '-h' or sys.argv[1] == '/?' ):
|
|
||||||
print( "Usage :{} <cmd> ".format(sys.argv[0]) )
|
print( "Usage :{} <cmd> ".format(sys.argv[0]) )
|
||||||
print( "" )
|
print( "" )
|
||||||
print( "## Commands <cmd>")
|
print( "## Commands <cmd>")
|
||||||
|
@ -100,93 +100,93 @@ if ( args == 1 or sys.argv[1] == 'help' or sys.argv[1] == '--help' or sys.argv[1
|
||||||
print( "" )
|
print( "" )
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
# Read configruation file
|
# Read configruation file
|
||||||
#
|
#
|
||||||
config = {}
|
config = {}
|
||||||
if os.path.isfile("/etc/default/clusterctrl"):
|
if os.path.isfile("/etc/default/clusterctrl"):
|
||||||
with open ("/etc/default/clusterctrl") as configfile:
|
with open ("/etc/default/clusterctrl") as configfile:
|
||||||
for line in configfile:
|
for line in configfile:
|
||||||
if( line[:1] != '#' ):
|
if( line[:1] != '#' ):
|
||||||
k, v = line.partition("=")[::2]
|
k, v = line.partition("=")[::2]
|
||||||
config[k.strip().lower()] = v.split('#')[0].strip(" \"'\n\t")
|
config[k.strip().lower()] = v.split('#')[0].strip(" \"'\n\t")
|
||||||
|
|
||||||
# If we're not a controller of some sort exit cleanly
|
# If we're not a controller of some sort exit cleanly
|
||||||
if( 'type' not in config or not ( config['type'] == "c" or config['type'] == "cnat" ) ):
|
if( 'type' not in config or not ( config['type'] == "c" or config['type'] == "cnat" ) ):
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
# Config
|
# Config
|
||||||
|
|
||||||
# I2C address of ClusterCTRL device
|
# I2C address of ClusterCTRL device
|
||||||
I2C_ADDRESS = 0x20
|
I2C_ADDRESS = 0x20
|
||||||
|
|
||||||
# Number of Pi Zero in ClusterHAT (set below)
|
# Number of Pi Zero in ClusterHAT (set below)
|
||||||
clusterhat_size = 0
|
clusterhat_size = 0
|
||||||
|
|
||||||
# ClusterCTRL Registers
|
# ClusterCTRL Registers
|
||||||
REG_VERSION = 0x00 # Register layout version
|
REG_VERSION = 0x00 # Register layout version
|
||||||
REG_MAXPI = 0x01 # Maximum number of Pi
|
REG_MAXPI = 0x01 # Maximum number of Pi
|
||||||
REG_ORDER = 0x02 # Order - used to sort multiple ClusterCTRL devices
|
REG_ORDER = 0x02 # Order - used to sort multiple ClusterCTRL devices
|
||||||
REG_MODE = 0x03 # N/A
|
REG_MODE = 0x03 # N/A
|
||||||
REG_TYPE = 0x04 # 0=DA, 1=pHAT
|
REG_TYPE = 0x04 # 0=DA, 1=pHAT
|
||||||
REG_DATA7 = 0x05 #
|
REG_DATA7 = 0x05 #
|
||||||
REG_DATA6 = 0x06 #
|
REG_DATA6 = 0x06 #
|
||||||
REG_DATA5 = 0x07 #
|
REG_DATA5 = 0x07 #
|
||||||
REG_DATA4 = 0x08 #
|
REG_DATA4 = 0x08 #
|
||||||
REG_DATA3 = 0x09 #
|
REG_DATA3 = 0x09 #
|
||||||
REG_DATA2 = 0x0a #
|
REG_DATA2 = 0x0a #
|
||||||
REG_DATA1 = 0x0b #
|
REG_DATA1 = 0x0b #
|
||||||
REG_DATA0 = 0x0c #
|
REG_DATA0 = 0x0c #
|
||||||
REG_CMD = 0x0d # Command
|
REG_CMD = 0x0d # Command
|
||||||
REG_STATUS = 0x0e # Status
|
REG_STATUS = 0x0e # Status
|
||||||
|
|
||||||
# ClusterCTRL Commands
|
# ClusterCTRL Commands
|
||||||
CMD_ON = 0x03 # Turn on Px (data0=x)
|
CMD_ON = 0x03 # Turn on Px (data0=x)
|
||||||
CMD_OFF = 0x04 # Turn off Px (data0=x)
|
CMD_OFF = 0x04 # Turn off Px (data0=x)
|
||||||
CMD_ALERT_ON = 0x05 # Turn on Alert LED
|
CMD_ALERT_ON = 0x05 # Turn on Alert LED
|
||||||
CMD_ALERT_OFF = 0x06 # Turn off Alert LED
|
CMD_ALERT_OFF = 0x06 # Turn off Alert LED
|
||||||
CMD_HUB_CYCLE = 0x07 # Reset USB HUB (turn off for data0*10ms, then back on)
|
CMD_HUB_CYCLE = 0x07 # Reset USB HUB (turn off for data0*10ms, then back on)
|
||||||
CMD_LED_EN = 0x0A # Enable Px LED (data0=x)
|
CMD_LED_EN = 0x0A # Enable Px LED (data0=x)
|
||||||
CMD_LED_DIS = 0x0B # Disable Px LED (data0=x)
|
CMD_LED_DIS = 0x0B # Disable Px LED (data0=x)
|
||||||
CMD_PWR_ON = 0x0C # Turn off PWR LED
|
CMD_PWR_ON = 0x0C # Turn off PWR LED
|
||||||
CMD_PWR_OFF = 0x0D # Turn off PWR LED
|
CMD_PWR_OFF = 0x0D # Turn off PWR LED
|
||||||
CMD_RESET = 0x0E # Resets ClusterCTRL (does not keep power state)
|
CMD_RESET = 0x0E # Resets ClusterCTRL (does not keep power state)
|
||||||
CMD_GET_PSTATUS = 0x0F # Get Px power status (data0=x)
|
CMD_GET_PSTATUS = 0x0F # Get Px power status (data0=x)
|
||||||
CMD_FAN = 0x10 # Turn fan on (data0=1) or off (data0=0)
|
CMD_FAN = 0x10 # Turn fan on (data0=1) or off (data0=0)
|
||||||
CMD_GETPATH = 0x11 # Get USB path to Px (data0=x 0=controller) returned in data7-data0
|
CMD_GETPATH = 0x11 # Get USB path to Px (data0=x 0=controller) returned in data7-data0
|
||||||
CMD_USBBOOT_EN = 0x12 # Turn on USBBOOT
|
CMD_USBBOOT_EN = 0x12 # Turn on USBBOOT
|
||||||
CMD_USBBOOT_DIS = 0x13 # Turn off USBBOOT
|
CMD_USBBOOT_DIS = 0x13 # Turn off USBBOOT
|
||||||
CMD_GET_USTATUS = 0x14 # Get Px USBBOOT status (data0=x)
|
CMD_GET_USTATUS = 0x14 # Get Px USBBOOT status (data0=x)
|
||||||
CMD_SET_ORDER = 0x15 # Set order (data0=order)
|
CMD_SET_ORDER = 0x15 # Set order (data0=order)
|
||||||
CMD_SAVE = 0xF0 # Save current PWR/P1-LED/P2-LED/P1/P2/Order/Mode to EEPROM
|
CMD_SAVE = 0xF0 # Save current PWR/P1-LED/P2-LED/P1/P2/Order/Mode to EEPROM
|
||||||
CMD_SAVEDEFAULTS = 0xF1 # Save factory defaults
|
CMD_SAVEDEFAULTS = 0xF1 # Save factory defaults
|
||||||
CMD_GET_DATA = 0xF2 # Get DATA (Temps/ADC/etc.)
|
CMD_GET_DATA = 0xF2 # Get DATA (Temps/ADC/etc.)
|
||||||
CMD_SAVE_ORDER = 0xF3 # Save order to EEPROM
|
CMD_SAVE_ORDER = 0xF3 # Save order to EEPROM
|
||||||
CMD_SAVE_USBBOOT = 0xF4 # Save usbboot status to EEPROM
|
CMD_SAVE_USBBOOT = 0xF4 # Save usbboot status to EEPROM
|
||||||
CMD_SAVE_POS = 0xF5 # Save Power On State to EEPROM
|
CMD_SAVE_POS = 0xF5 # Save Power On State to EEPROM
|
||||||
CMD_SAVE_LED = 0xF6 # Save LED to EEPROM
|
CMD_SAVE_LED = 0xF6 # Save LED to EEPROM
|
||||||
CMD_NOP = 0x90 # Do nothing
|
CMD_NOP = 0x90 # Do nothing
|
||||||
|
|
||||||
# Get arbitrary data from ClusterCTRL
|
# Get arbitrary data from ClusterCTRL
|
||||||
GET_DATA_VERSION = 0x00 # Get firmware version
|
GET_DATA_VERSION = 0x00 # Get firmware version
|
||||||
GET_DATA_ADC_CNT = 0x01 # Returns number of ADC ClusterCTRL supports
|
GET_DATA_ADC_CNT = 0x01 # Returns number of ADC ClusterCTRL supports
|
||||||
GET_DATA_ADC_READ = 0x02 # Read ADC data for ADC number 'data0'
|
GET_DATA_ADC_READ = 0x02 # Read ADC data for ADC number 'data0'
|
||||||
GET_DATA_ADC_TEMP = 0x03 # Read Temperature ADC
|
GET_DATA_ADC_TEMP = 0x03 # Read Temperature ADC
|
||||||
GET_DATA_FANSTATUS = 0x04 # Read fan status
|
GET_DATA_FANSTATUS = 0x04 # Read fan status
|
||||||
|
|
||||||
# Files/paths
|
# Files/paths
|
||||||
clusterctrl_prefix = '/dev/ClusterCTRL-'
|
clusterctrl_prefix = '/dev/ClusterCTRL-'
|
||||||
vcgencmdpath = "/usr/bin/vcgencmd"
|
vcgencmdpath = "/usr/bin/vcgencmd"
|
||||||
hat_product = "/proc/device-tree/hat/product"
|
hat_product = "/proc/device-tree/hat/product"
|
||||||
hat_version = "/proc/device-tree/hat/product_ver"
|
hat_version = "/proc/device-tree/hat/product_ver"
|
||||||
hat_uuid = "/proc/device-tree/hat/uuid"
|
hat_uuid = "/proc/device-tree/hat/uuid"
|
||||||
hat_vendor = "/proc/device-tree/hat/vendor"
|
hat_vendor = "/proc/device-tree/hat/vendor"
|
||||||
hat_pid = "/proc/device-tree/hat/product_id"
|
hat_pid = "/proc/device-tree/hat/product_id"
|
||||||
nfsboot = "/var/lib/clusterctrl/boot/"
|
nfsboot = "/var/lib/clusterctrl/boot/"
|
||||||
nfsroot = "/var/lib/clusterctrl/nfs/"
|
nfsroot = "/var/lib/clusterctrl/nfs/"
|
||||||
|
|
||||||
# Functions
|
# Functions
|
||||||
# Send command to ClusterCTRL via I2C
|
# Send command to ClusterCTRL via I2C
|
||||||
def send_cmd(c, cmd, data0=None,data1=None,data2=None,data3=None,data4=None,data5=None,data6=None,data7=None):
|
def send_cmd(c, cmd, data0=None,data1=None,data2=None,data3=None,data4=None,data5=None,data6=None,data7=None):
|
||||||
#print("CMD: {} - {} {} {} {} {} {} {} {}"format(cmd, data0, data1, data2, data3,data4, data5, data6, data7))
|
#print("CMD: {} - {} {} {} {} {} {} {} {}"format(cmd, data0, data1, data2, data3,data4, data5, data6, data7))
|
||||||
if(data7 is not None): c[1].write_byte_data( I2C_ADDRESS, REG_DATA7, data7 )
|
if(data7 is not None): c[1].write_byte_data( I2C_ADDRESS, REG_DATA7, data7 )
|
||||||
if(data6 is not None): c[1].write_byte_data( I2C_ADDRESS, REG_DATA6, data6 )
|
if(data6 is not None): c[1].write_byte_data( I2C_ADDRESS, REG_DATA6, data6 )
|
||||||
|
@ -201,22 +201,22 @@ def send_cmd(c, cmd, data0=None,data1=None,data2=None,data3=None,data4=None,data
|
||||||
except IOError:
|
except IOError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Read register from ClusterCTRL via I2C
|
# Read register from ClusterCTRL via I2C
|
||||||
def read_reg(c, offset, len=1):
|
def read_reg(c, offset, len=1):
|
||||||
if(len>1):
|
if(len>1):
|
||||||
tmp = c[1].read_i2c_block_data( I2C_ADDRESS, offset, len )
|
tmp = c[1].read_i2c_block_data( I2C_ADDRESS, offset, len )
|
||||||
else:
|
else:
|
||||||
tmp = c[1].read_byte_data( I2C_ADDRESS, offset )
|
tmp = c[1].read_byte_data( I2C_ADDRESS, offset )
|
||||||
return tmp
|
return tmp
|
||||||
|
|
||||||
# Get throttled status
|
# Get throttled status
|
||||||
def get_throttled():
|
def get_throttled():
|
||||||
if( not os.path.isfile(vcgencmdpath) or not os.access(vcgencmdpath,os.X_OK) ):
|
if( not os.path.isfile(vcgencmdpath) or not os.access(vcgencmdpath,os.X_OK) ):
|
||||||
return 'NA'
|
return 'NA'
|
||||||
return ( (os.popen(vcgencmdpath + ' get_throttled').readline()).split('=', 1)[-1].strip())
|
return ( (os.popen(vcgencmdpath + ' get_throttled').readline()).split('=', 1)[-1].strip())
|
||||||
|
|
||||||
# Get USB path (eg 1-1.4.1) for I2C bus
|
# Get USB path (eg 1-1.4.1) for I2C bus
|
||||||
def usbpathfrombus(bus):
|
def usbpathfrombus(bus):
|
||||||
for device in glob.glob("/sys/bus/usb/drivers/i2c-tiny-usb/*/i2c*"):
|
for device in glob.glob("/sys/bus/usb/drivers/i2c-tiny-usb/*/i2c*"):
|
||||||
parts = device.split('/')
|
parts = device.split('/')
|
||||||
path = parts[6].split(':')[0]
|
path = parts[6].split(':')[0]
|
||||||
|
@ -225,8 +225,8 @@ def usbpathfrombus(bus):
|
||||||
return path
|
return path
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Build list of pi zero numbers to get USB path of
|
# Build list of pi zero numbers to get USB path of
|
||||||
def getusbpaths():
|
def getusbpaths():
|
||||||
paths = {}
|
paths = {}
|
||||||
zeros = []
|
zeros = []
|
||||||
|
|
||||||
|
@ -321,33 +321,33 @@ def getusbpaths():
|
||||||
paths[str(zero)] = cache_clusterctrl[c[0]]+pathdata
|
paths[str(zero)] = cache_clusterctrl[c[0]]+pathdata
|
||||||
return paths
|
return paths
|
||||||
|
|
||||||
def is_float(n):
|
def is_float(n):
|
||||||
try:
|
try:
|
||||||
float(n)
|
float(n)
|
||||||
return True
|
return True
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
##########
|
##########
|
||||||
# Init #
|
# Init #
|
||||||
##########
|
##########
|
||||||
|
|
||||||
# Get Pi power on delay from config
|
# Get Pi power on delay from config
|
||||||
delay = 1 if 'clusterctrl_delay' not in config or not is_float(config['clusterctrl_delay']) or float(config['clusterctrl_delay'])<0 else config['clusterctrl_delay']
|
delay = 1 if 'clusterctrl_delay' not in config or not is_float(config['clusterctrl_delay']) or float(config['clusterctrl_delay'])<0 else config['clusterctrl_delay']
|
||||||
|
|
||||||
maxpi=0
|
maxpi=0
|
||||||
clusterctrl = False
|
clusterctrl = False
|
||||||
|
|
||||||
# Do we have a ClusterHAT ?
|
# Do we have a ClusterHAT ?
|
||||||
|
|
||||||
# Check for override
|
# Check for override
|
||||||
clusterhat = 1 if 'clusterhat_force' not in config else config['clusterhat_force']
|
clusterhat = 1 if 'clusterhat_force' not in config else config['clusterhat_force']
|
||||||
|
|
||||||
if(clusterhat != 1):
|
if(clusterhat != 1):
|
||||||
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)
|
||||||
or not os.access(hat_uuid, os.R_OK)
|
or not os.access(hat_uuid, os.R_OK)
|
||||||
|
@ -358,7 +358,7 @@ elif ( not os.path.isfile(hat_product)
|
||||||
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')
|
||||||
if ( f.read().strip('\x00') != 'ZC4:ClusterHAT' ):
|
if ( f.read().strip('\x00') != 'ZC4:ClusterHAT' ):
|
||||||
|
@ -376,13 +376,13 @@ else:
|
||||||
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
|
||||||
fangpio = False if 'fangpio' not in config else int(config['fangpio'])
|
fangpio = False if 'fangpio' not in config else int(config['fangpio'])
|
||||||
|
|
||||||
# Init ClusterHAT if we have one
|
# Init ClusterHAT if we have one
|
||||||
if(clusterhat):
|
if(clusterhat):
|
||||||
maxpi+=clusterhat_size
|
maxpi+=clusterhat_size
|
||||||
if ( version == 1 ):
|
if ( version == 1 ):
|
||||||
import RPi.GPIO as GPIO
|
import RPi.GPIO as GPIO
|
||||||
|
@ -454,19 +454,19 @@ if(clusterhat):
|
||||||
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+'*'):
|
||||||
clusterctrl+=1
|
clusterctrl+=1
|
||||||
length = len(clusterctrl_prefix)
|
length = len(clusterctrl_prefix)
|
||||||
busses.append( ( smbus.SMBus(int(fn[length:])), int(fn[length:]) ) )
|
busses.append( ( smbus.SMBus(int(fn[length:])), int(fn[length:]) ) )
|
||||||
|
|
||||||
# Ensure we have at least one ClusterCTRL or a ClusterHAT
|
# Ensure we have at least one ClusterCTRL or a ClusterHAT
|
||||||
if( len(busses)<1 and not clusterhat ):
|
if( len(busses)<1 and not clusterhat ):
|
||||||
print("ERROR: No ClusterHAT/CTRL devices found\n")
|
print("ERROR: No ClusterHAT/CTRL devices found\n")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if(clusterctrl):
|
if(clusterctrl):
|
||||||
# Make sure we haven't got a conflict on the ClusterCTRL "order"
|
# Make sure we haven't got a conflict on the ClusterCTRL "order"
|
||||||
# When using multiple ClusterCTRL devices they each have an "order" which must be unique
|
# When using multiple ClusterCTRL devices they each have an "order" which must be unique
|
||||||
orders = []
|
orders = []
|
||||||
|
@ -490,8 +490,8 @@ if(clusterctrl):
|
||||||
# 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?
|
# Are we running init and should we create the symlinks for usbboot?
|
||||||
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
|
||||||
if os.geteuid() == 0 and os.path.isdir(nfsboot) and os.path.isdir(nfsroot):
|
if os.geteuid() == 0 and os.path.isdir(nfsboot) and os.path.isdir(nfsroot):
|
||||||
|
@ -512,13 +512,13 @@ if( args == 2 and sys.argv[1] == 'init'):
|
||||||
os.unlink(nfsboot+path)
|
os.unlink(nfsboot+path)
|
||||||
os.symlink(nfsroot+'p'+p+"/boot/", nfsboot+path)
|
os.symlink(nfsroot+'p'+p+"/boot/", nfsboot+path)
|
||||||
|
|
||||||
##############
|
##############
|
||||||
## End Init ##
|
## End Init ##
|
||||||
##############
|
##############
|
||||||
|
|
||||||
# Parse arguments and do actions
|
# Parse arguments and do actions
|
||||||
|
|
||||||
if (args == 2 and ( sys.argv[1] == "on" or sys.argv[1] == "off" ) ):
|
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
|
||||||
|
@ -580,7 +580,7 @@ if (args == 2 and ( sys.argv[1] == "on" or sys.argv[1] == "off" ) ):
|
||||||
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
|
||||||
# Build list of pi zero numbers to turn alert LED on for
|
# Build list of pi zero numbers to turn alert LED on for
|
||||||
|
@ -644,7 +644,7 @@ elif ( args > 2 and ( sys.argv[1] == "on" or sys.argv[1] == "off" ) ):
|
||||||
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
|
||||||
# Build list of pi zero numbers to turn USBBOOT on for
|
# Build list of pi zero numbers to turn USBBOOT on for
|
||||||
|
@ -670,7 +670,7 @@ elif ( args > 2 and sys.argv[1] == 'usbboot' and ( sys.argv[2] == 'on' or sys.ar
|
||||||
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 ) )
|
||||||
print ( "clusterctrl:{}".format( clusterctrl ) )
|
print ( "clusterctrl:{}".format( clusterctrl ) )
|
||||||
|
@ -762,7 +762,7 @@ elif ( args == 2 and sys.argv[1] == "status" ):
|
||||||
if ( read_reg( c, REG_DATA0 ) != 0xFF ):
|
if ( read_reg( c, REG_DATA0 ) != 0xFF ):
|
||||||
print( "u{}:{}".format(cnt, read_reg( c, REG_DATA0 ) ) )
|
print( "u{}:{}".format(cnt, read_reg( c, REG_DATA0 ) ) )
|
||||||
|
|
||||||
elif ( args == 3 and sys.argv[1] == 'hub' and ( sys.argv[2] == 'on' or sys.argv[2] == 'off' ) ):
|
elif ( args == 3 and sys.argv[1] == 'hub' and ( sys.argv[2] == 'on' or sys.argv[2] == 'off' ) ):
|
||||||
if(clusterhat):
|
if(clusterhat):
|
||||||
if( version==1 ):
|
if( version==1 ):
|
||||||
print ( "ERROR: hub control not supported on Cluster HAT v1.x\n")
|
print ( "ERROR: hub control not supported on Cluster HAT v1.x\n")
|
||||||
|
@ -777,8 +777,8 @@ elif ( args == 3 and sys.argv[1] == 'hub' and ( sys.argv[2] == 'on' or sys.argv[
|
||||||
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 ):
|
||||||
if ( version_minor == 0 ):
|
if ( version_minor == 0 ):
|
||||||
hub.off()
|
hub.off()
|
||||||
|
@ -792,7 +792,7 @@ elif ( args == 3 and sys.argv[1] == 'hub' and ( sys.argv[2] == 'reset' ) ):
|
||||||
for c in ctrl:
|
for c in ctrl:
|
||||||
send_cmd( c, CMD_HUB_CYCLE )
|
send_cmd( c, CMD_HUB_CYCLE )
|
||||||
|
|
||||||
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 ALL ALERT LED on/off
|
# Turn ALL ALERT LED on/off
|
||||||
if(clusterhat):
|
if(clusterhat):
|
||||||
if(version==1):
|
if(version==1):
|
||||||
|
@ -812,7 +812,7 @@ elif ( args == 3 and sys.argv[1] == 'alert' and ( sys.argv[2] == 'on' or sys.arg
|
||||||
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
|
||||||
|
|
||||||
# Build list of pi zero numbers to turn alert LED on for
|
# Build list of pi zero numbers to turn alert LED on for
|
||||||
|
@ -848,7 +848,7 @@ elif ( args > 3 and sys.argv[1] == 'alert' and ( sys.argv[2] == 'on' or sys.argv
|
||||||
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):
|
||||||
if(sys.argv[2] == 'on'):
|
if(sys.argv[2] == 'on'):
|
||||||
|
@ -861,7 +861,7 @@ elif ( args == 3 and sys.argv[1] == 'led' and ( sys.argv[2] == 'on' or sys.argv[
|
||||||
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):
|
||||||
if ( sys.argv[2] == 'on' ):
|
if ( sys.argv[2] == 'on' ):
|
||||||
|
@ -871,11 +871,11 @@ elif ( args == 3 and sys.argv[1] == 'wp' and ( sys.argv[2] == 'on' or sys.argv[2
|
||||||
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):
|
||||||
print("Invalid order")
|
print("Invalid order")
|
||||||
|
@ -887,7 +887,7 @@ elif ( args == 3 and sys.argv[1] == 'savedefaults' ):
|
||||||
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")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
@ -898,7 +898,7 @@ elif ( args == 4 and sys.argv[1] == 'setorder'):
|
||||||
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):
|
||||||
print("Invalid order")
|
print("Invalid order")
|
||||||
|
@ -911,7 +911,7 @@ elif ( args == 3 and sys.argv[1] == 'save' ):
|
||||||
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 == 3 and sys.argv[1] == 'saveorder' ):
|
elif ( args == 3 and sys.argv[1] == 'saveorder' ):
|
||||||
# Set order to EEPROM for device with "order"
|
# Set 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):
|
||||||
print("Invalid order")
|
print("Invalid order")
|
||||||
|
@ -923,7 +923,7 @@ elif ( args == 3 and sys.argv[1] == 'saveorder' ):
|
||||||
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 == 3 and sys.argv[1] == 'saveusbboot' ):
|
elif ( args == 3 and sys.argv[1] == 'saveusbboot' ):
|
||||||
# Set usbboot to EEPROM for device with "order"
|
# Set usbboot 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):
|
||||||
print("Invalid order")
|
print("Invalid order")
|
||||||
|
@ -935,7 +935,7 @@ elif ( args == 3 and sys.argv[1] == 'saveusbboot' ):
|
||||||
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 == 3 and sys.argv[1] == 'savepos' ):
|
elif ( args == 3 and sys.argv[1] == 'savepos' ):
|
||||||
# Set Power On State to EEPROM for device with "order"
|
# Set Power On State 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):
|
||||||
print("Invalid order")
|
print("Invalid order")
|
||||||
|
@ -947,7 +947,7 @@ elif ( args == 3 and sys.argv[1] == 'savepos' ):
|
||||||
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 == 3 and sys.argv[1] == 'reset' ):
|
elif ( args == 3 and sys.argv[1] == 'reset' ):
|
||||||
# Reset Cluster CTRL device with "order"
|
# Reset Cluster CTRL 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):
|
||||||
print("Invalid order")
|
print("Invalid order")
|
||||||
|
@ -959,7 +959,7 @@ elif ( args == 3 and sys.argv[1] == 'reset' ):
|
||||||
print("reset")
|
print("reset")
|
||||||
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 == 3 and sys.argv[1] == 'fan' and (sys.argv[2] == 'on' or sys.argv[2] == 'off')):
|
elif ( args == 3 and sys.argv[1] == 'fan' and (sys.argv[2] == 'on' or sys.argv[2] == 'off')):
|
||||||
# Turn all fan on/off
|
# Turn all fan on/off
|
||||||
|
|
||||||
# "ClusterHAT" using GPIO
|
# "ClusterHAT" using GPIO
|
||||||
|
@ -980,7 +980,7 @@ elif ( args == 3 and sys.argv[1] == 'fan' and (sys.argv[2] == 'on' or sys.argv[2
|
||||||
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)):
|
||||||
print("Invalid order")
|
print("Invalid order")
|
||||||
|
@ -1003,10 +1003,10 @@ elif ( args == 4 and sys.argv[1] == 'fan' and (sys.argv[2] == 'on' or sys.argv[2
|
||||||
send_cmd(c, CMD_FAN, 0)
|
send_cmd(c, CMD_FAN, 0)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
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' ):
|
elif ( args == 2 and sys.argv[1] == 'init' ):
|
||||||
# First run init is handled above this is just here to allow the command to succeed
|
# First run init is handled above this is just here to allow the command to succeed
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
print ("Error: Missing arguments")
|
print ("Error: Missing arguments")
|
||||||
|
|
Loading…
Reference in a new issue