forked from pleiades-cluster/yearling-flight-software
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
70 lines (59 loc) · 2 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""
PyCubed Beep-Sat Demo (advanced)
- improved fault handling & tolerance
- low power mode
- logging data to sd card
- over the air commands
M. Holliday
"""
'''
print('\n{lines}\n{:^40}\n{lines}\n'.format('Sapling',lines='-'*40))
print('Initializing PyCubed Hardware...')
import os, tasko, traceback
from pycubed import cubesat
print('Finished initializing PyCubed Hardware')
# create asyncio object
cubesat.tasko=tasko
# Dict to store scheduled objects by name
cubesat.scheduled_tasks={}
print('Loading Tasks...',end='')
# schedule all tasks in directory
for file in os.listdir('Tasks'):
# remove the '.py' from file name
file=file[:-3]
# ignore these files
if file in ("template_task","test_task","listen_task"):
continue
# auto-magically import the task file
exec('import Tasks.{}'.format(file))
# create a helper object for scheduling the task
task_obj=eval('Tasks.'+file).task(cubesat)
# determine if the task wishes to be scheduled later
if hasattr(task_obj,'schedule_later'):
schedule=cubesat.tasko.schedule_later
else:
schedule=cubesat.tasko.schedule
# schedule each task object and add it to our dict
cubesat.scheduled_tasks[task_obj.name]=schedule(task_obj.frequency,task_obj.main_task,task_obj.priority)
print(len(cubesat.scheduled_tasks),'total')
print('Running...')
try:
# should run forever
cubesat.tasko.run()
except Exception as e:
formated_exception = traceback.format_exception(e, e, e.__traceback__)
print(formated_exception)
try:
# increment our NVM error counter
cubesat.c_state_err+=1
# try to log everything
cubesat.log('{},{},{}'.format(formated_exception,cubesat.c_state_err,cubesat.c_boot))
except:
pass
# we shouldn't be here!
print('Engaging fail safe: hard reset')
from time import sleep
sleep(10)
cubesat.micro.on_next_reset(cubesat.micro.RunMode.NORMAL)
cubesat.micro.reset()
'''