Commit da1fb8fb authored by Oleg Dzhimiev's avatar Oleg Dzhimiev

comments

parent eb503e74
#!/usr/bin/env python
from __future__ import division
from __future__ import print_function
......@@ -27,7 +28,7 @@ from __future__ import print_function
'''
__author__ = "Oleg Dzhimiev"
__copyright__ = "Copyright (C) 2016 Elphel Inc."
__copyright__ = "Copyright (C) 2016 Elphel, Inc."
__license__ = "GPL"
__version__ = "3.0+"
__maintainer__ = "Oleg Dzhimiev"
......@@ -55,6 +56,7 @@ FPGA_VERION_FILE = '/sys/devices/soc0/elphel393-framepars@0/fpga_version'
TIMEOUT = 120
#functions
def get_fpga():
with open(FPGA_VERION_FILE,'r') as f:
try:
......@@ -63,10 +65,14 @@ def get_fpga():
return None
def fpga_OK(timeout):
'''
Get fpga bitstream version once it's available
@timeout - int - seconds
'''
ntry = 0
fpga = None
while not fpga and ((not timeout) or (ntry<timeout)):
fpga= get_fpga()
fpga = get_fpga()
print ('.',end='')
sys.stdout.flush()
ntry += 1
......@@ -74,6 +80,12 @@ def fpga_OK(timeout):
return fpga
def colorize(string, color, bold):
'''
Colors for terminal output
@string - string - text to print
@color - string - see below
@bold - bool - True/False
'''
color=color.upper()
attr = []
if color == 'RED':
......@@ -98,6 +110,11 @@ def colorize(string, color, bold):
return '\x1b[%sm%s\x1b[0m' % (';'.join(attr), string)
def log_msg(msg, mode=0):
'''
Print log message
@msg
@mode - int - 0,2,3,4
'''
bold = False
color = ""
if mode == 2: #bold red - error
......@@ -118,26 +135,50 @@ def log_msg(msg, mode=0):
print (colorize("[%8.2f] %s: "%(t, sys.argv[0].split('/')[-1].split('.')[0]),'CYAN',0)+msg)
def shout(cmd):
'''
call subprocess with shell=True
@cmd
'''
#subprocess.call prints to console
subprocess.call(cmd,shell=True)
def init_ipaddr(ip, mask):
'''
simple 'ifconfig'
@ip - string - ip address
@mask - string - netmask
'''
shout("ifconfig eth0 "+ip+" netmask "+mask)
def init_imgsrv(port):
'''
Start Image Server (imgsrv), restart lighttpd (for imgsrv?) and initialize exif header template
@port - int or str
'''
shout("imgsrv -p "+str(port))
#restart PHP - it can get errors while opening/mmaping at startup, then some functions fail
shout("killall lighttpd; /usr/sbin/lighttpd -f /etc/lighttpd.conf")
shout("/www/pages/exif.php init=/etc/Exif_template.xml")
def init_autoexp_daemon(index):
'''
Start autoexposure daemon, provide port
@index - string
'''
shout("autoexposure -p "+index+" -c 0 -b 0 -d 1 &")
def init_sata(sata_en):
'''
SATA init
@sata_en - int - 0 or 1
'''
# init SATA only if 10389 board is present
if os.path.isfile("/sys/devices/soc0/elphel393-pwr@0/detected_10389"):
if (sata_en==1):
# SATA core is implented in fpga - first chech, then wait until programmed
if not get_fpga():
log_msg ("Waiting for the FPGA to be programmed to start SATA", 4)
# look up TIMEOUT in the params in the beginning of the file
if not fpga_OK(TIMEOUT):
log_msg ("Timeout while waiting for the FPGA to be programmed", 2)
return
......@@ -154,14 +195,15 @@ def init_sata(sata_en):
log_msg (" Details : /var/log/x393sata_control.log")
log_msg (" State : /var/state/ssd")
# Option 1: use internal SSDs: zynq <-> internal ssd
# Option 1: use internal SSDs: zynq <-> internal ssd, AHCI module will be loaded by the script
# uncomment for use
#shout(PYDIR+"/x393sata_control.py set_zynq_ssd")
# Option 2: use external SSDs: zynq <-> external ssd
# Option 2: use external SSDs: zynq <-> external ssd, AHCI module will be loaded by the script
# uncomment for use
shout(PYDIR+"/x393sata_control.py set_zynq_esata")
else:
# load the AHCI driver module
shout("modprobe ahci_elphel &")
shout("sleep 2")
shout("echo 1 > /sys/devices/soc0/amba@0/80000000.elphel-ahci/load_module")
......@@ -169,9 +211,9 @@ def init_sata(sata_en):
log_msg ("10389 was not detected: skipping SATA init")
def init_usb_hub():
"""
'''
Initializes USB HUB on 10389 board (stays initialized through reboot, does not respond after initialized)
"""
'''
if not os.path.exists('/sys/bus/usb/devices/1-1'):
if os.path.isfile('/sys/devices/soc0/elphel393-pwr@0/detected_10389'):
shout("i2cset -y 0 0x2c 0xff 0x0201 w")
......@@ -189,9 +231,9 @@ def init_usb_hub():
log_msg ("USB hub was already initialized")
def start_gps_compass():
"""
'''
Detect GPS and/or compass boards and start them
"""
'''
if not get_fpga():
log_msg ("Waiting for the FPGA to be programmed to start SATA", 4)
if not fpga_OK(TIMEOUT):
......@@ -203,6 +245,9 @@ def start_gps_compass():
shout("start_gps_compass.php")
def disable_gpio_10389():
'''
Is needed for Eyesis4Pi because GPIO is used to power something else
'''
gpio_10389 = "/sys/devices/soc0/elphel393-pwr@0/gpio_10389"
shout("echo '0x101' > "+gpio_10389) #power on
shout("echo '0x100' > "+gpio_10389) #power off
......@@ -222,21 +267,23 @@ switch = {
'eyesis':0
}
# update from argv
# update 'switch' dictionary from argv[1] which should be evaluated as dictionary as well:
# look it up in /etc/init.d/init_elphel393
if len(sys.argv) > 1:
switch.update(eval(sys.argv[1]))
#pre
volatile_html = '/var/volatile/html'
if not os.path.exists(volatile_html):
os.mkdir(volatile_html)
#need to disable fan for eyesis
#if switch['eyesis']!=0:
# need to disable fan for eyesis
# if switch['eyesis']!=0:
# log_msg('Eyesis mode: turn off gpio 10389')
# disable_gpio_10389()
# start temperature monitor and let it control fan (set 'off' to disable fan control)
#Move tempon early, so other problems will not block it
# Start temperature monitor and let it control fan (set 'off' to disable fan control)
# Move tempon early, so other problems will not block it
if switch['eyesis']!=0:
log_msg('Eyesis mode: turn off gpio 10389')
disable_gpio_10389()
......@@ -246,43 +293,59 @@ else:
log_msg("Fan on")
shout("tempmon.py --control_fan on &")
#0
'''
1: program USB hub
'''
if switch['usb_hub']==1:
log_msg('Initialize USB hub')
init_usb_hub()
else:
log_msg("skip USB hub initiualization")
#1
'''
2: set ip and netmask
'''
if switch['ip']==1:
log_msg(sys.argv[0]+": ip = "+IPADDR+", mask = "+NETMASK)
init_ipaddr(IPADDR, NETMASK)
else:
log_msg("skip ip")
#2
#3
'''
3: init image server
'''
if switch['imgsrv']==1:
log_msg(sys.argv[0]+": imgsrv")
init_imgsrv(IMGSRV_PORT)
else:
log_msg("skip imgsrv")
#5
'''
4: init autoexposure daemon - try for all possible ports
'''
log_msg(sys.argv[0]+": auto exposure daemon")
if switch['autoexp_daemon']==1:
for i in range(1,5):
init_autoexp_daemon(str(i-1))
'''
5: Init camera parameters
* FPGA gets programmed at this step - default bitstream is used which
depends on the camera type programmed in 10389 if detected.
If the board is not found then the default bitstream is:
/usr/local/verilog/x393_parallel.bit
'''
if switch ['autocampars'] == 1:
# shout("autocampars.php --init --ignore-revision")
shout("autocampars.php --init")
#6
'''
6: Init SATA
* If the bitstream wasn't programmed at the previous step
it will be programmed here by x339sata.py,
the default bitstream is /usr/local/verilog/x393_sata.bit
but it does not include the camera part
'''
if switch['sata']==1:
log_msg("init SATA")
init_sata(SATA_EN)
......@@ -290,14 +353,15 @@ else:
log_msg("skip SATA")
#7
'''
7: Start GPS/IMU if any detected
'''
if switch['gps']==1:
log_msg('Start GPS and event logger')
start_gps_compass()
else:
log_msg("skip GPS")
# create directory for camogm pipes, symlink /var/state should already be in rootfs
if not os.path.exists("/var/volatile/state"):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment