Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite bootlogic #93

Merged
merged 3 commits into from
Feb 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion MainControlLoop/lib/StateFieldRegistry/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ def __init__(self):
StateField.IRIDIUM_LAST_MESSAGE_TIME: 0.0,
StateField.APRS_LAST_BEACON_TIME: 0.0,
StateField.LAST_ARCHIVE_TIME: 0.0,
StateField.BOOT_TIME: -1,

# SYSTEM INFO
StateField.NOT_FIRST_BOOT: False,
StateField.BOOT_WAIT_COMPLETE: False,
StateField.ANTENNA_DEPLOYED: False
}

Expand Down
6 changes: 4 additions & 2 deletions MainControlLoop/lib/StateFieldRegistry/state_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ class StateField(Enum):
IRIDIUM_LAST_MESSAGE_TIME = 'IRIDIUM_LAST_MESSAGE_TIME'
APRS_LAST_BEACON_TIME = 'APRS_LAST_BEACON_TIME'
LAST_ARCHIVE_TIME = 'LAST_ARCHIVE_TIME'
BOOT_TIME = 'BOOT_TIME'

# SYSTEM INFO
NOT_FIRST_BOOT = "FIRST_BOOT"
BOOT_WAIT_COMPLETE = "FIRST_BOOT"
ANTENNA_DEPLOYED = "ANTENNA_DEPLOY"


Expand Down Expand Up @@ -91,9 +92,10 @@ class ErrorFlag(Enum):
StateField.IRIDIUM_LAST_MESSAGE_TIME: float,
StateField.APRS_LAST_BEACON_TIME: float,
StateField.LAST_ARCHIVE_TIME: float,
StateField.BOOT_TIME: float,

# SYSTEM INFO
StateField.NOT_FIRST_BOOT: bool,
StateField.BOOT_WAIT_COMPLETE: bool,
StateField.ANTENNA_DEPLOYED: bool
}

Expand Down
16 changes: 9 additions & 7 deletions MainControlLoop/main_control_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,23 @@ def __init__(self):
self.locker: StateFieldRegistryLocker = StateFieldRegistryLocker()
self.pi_monitor: PiMonitorTask = PiMonitorTask(self.state_field_registry)
self.archiver: StateFieldRegistryArchiver = StateFieldRegistryArchiver(self.state_field_registry, self.locker)
self.aprs_task: APRSTask = APRSTask(self.state_field_registry, self.locker)
self.iridium_task: IridiumTask = IridiumTask(self.state_field_registry)
self.core: Core = Core(self.state_field_registry, self.aprs_task)
self.aprs: APRSTask = APRSTask(self.state_field_registry, self.locker)
self.iridium: IridiumTask = IridiumTask(self.state_field_registry)
self.core: Core = Core(self.state_field_registry, self.aprs)

def execute(self):
# READ BLOCK
commands = []
self.pi_monitor.read()
commands.append(self.aprs_task.read())
commands.append(self.iridium_task.read())
commands.append(self.aprs.read())
commands.append(self.iridium.read())

# CONTROL BLOCK
self.core.control(commands)
self.archiver.control()
self.aprs_task.control(commands)
self.pi_monitor.control()
self.aprs.control(commands)

# ACTUATE BLOCK
self.aprs_task.actuate()
self.pi_monitor.actuate()
self.aprs.actuate()
3 changes: 2 additions & 1 deletion MainControlLoop/tasks/DownLinkProducer/down_link_producer.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def create_dump(state_field_registry: StateFieldRegistry) -> [str]:
value = state_field_registry.get(element)
dump_addition = f"{value};"
if len(dumpList[-1] + dump_addition) > max_length:
dumpList.append(dump_header + f"{len(dumpList) - 1};") # Add the message number, len() - 1 because 0-index
# Add the message number, len() - 1 because indexing by 0
dumpList.append(dump_header + f"{len(dumpList) - 1};")
dumpList[-1] += dump_addition

return dumpList
Expand Down
1 change: 1 addition & 0 deletions MainControlLoop/tasks/PiMonitor/actuate/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .boot_complete import BootCompleteActuateTask
14 changes: 14 additions & 0 deletions MainControlLoop/tasks/PiMonitor/actuate/boot_complete.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class BootCompleteActuateTask:
FILE_PATH = "/root/first_boot"

def __init__(self):
self.run = False

def execute(self):
if not self.run:
return

self.run = False

file = open(self.FILE_PATH, "w")
file.close()
13 changes: 13 additions & 0 deletions MainControlLoop/tasks/PiMonitor/actuate_task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from MainControlLoop.tasks.PiMonitor.actuate import BootCompleteActuateTask


class PiMonitorActuateTask:

def __init__(self):
self.boot_complete_actuate_task = BootCompleteActuateTask()

def enable_boot_complete(self):
self.boot_complete_actuate_task.run = True

def execute(self):
self.boot_complete_actuate_task.execute()
18 changes: 18 additions & 0 deletions MainControlLoop/tasks/PiMonitor/control_task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from MainControlLoop.lib.StateFieldRegistry import StateFieldRegistry, StateField

from MainControlLoop.tasks.PiMonitor.actuate_task import PiMonitorActuateTask


class PiMonitorControlTask:
BOOT_INTERVAL = 1800

def __init__(self, state_field_registry: StateFieldRegistry, actuate_task: PiMonitorActuateTask):
self.state_field_registry: StateFieldRegistry = state_field_registry
self.actuate_task: PiMonitorActuateTask = actuate_task

def execute(self):
current_time = self.state_field_registry.get(StateField.TIME)
boot_time = self.state_field_registry.get(StateField.BOOT_TIME)

if current_time - boot_time > self.BOOT_INTERVAL:
self.actuate_task.enable_boot_complete()
3 changes: 3 additions & 0 deletions MainControlLoop/tasks/PiMonitor/read/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .system_time import SystemTimeReadTask
from .antenna_deployed import AntennaDeployReadTask
from .first_boot import BootWaitCompleteReadTask
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from time import time as sys_time
from os import path

from MainControlLoop.lib.StateFieldRegistry import StateFieldRegistry, StateField


class FirstBootReadTask:
class BootWaitCompleteReadTask:

FILE_PATH = "/root/first_boot"

def __init__(self, state_field_registry: StateFieldRegistry):
self.state_field_registry: StateFieldRegistry = state_field_registry
Expand All @@ -14,6 +15,6 @@ def execute(self):
Checks if current boot is first boot
:return: (None)
"""
self.state_field_registry.update(StateField.NOT_FIRST_BOOT, path.exists("/root/first_boot"))
self.state_field_registry.update(StateField.BOOT_WAIT_COMPLETE, path.exists(self.FILE_PATH))


Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ def __init__(self, state_field_registry: StateFieldRegistry):
def execute(self):
current_time: float = sys_time()
self.state_field_registry.update(StateField.TIME, current_time)
if self.state_field_registry.get(StateField.BOOT_TIME) == -1:
self.state_field_registry.update(StateField.BOOT_TIME, current_time)
16 changes: 16 additions & 0 deletions MainControlLoop/tasks/PiMonitor/read_task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from MainControlLoop.lib.StateFieldRegistry import StateFieldRegistry

from .read import AntennaDeployReadTask, BootWaitCompleteReadTask, SystemTimeReadTask


class PiMonitorReadTask:

def __init__(self, state_field_registry: StateFieldRegistry):
self.sys_time_read_task = SystemTimeReadTask(state_field_registry)
self.first_boot_read_task = BootWaitCompleteReadTask(state_field_registry)
self.antenna_deploy_read_task = AntennaDeployReadTask(state_field_registry)

def execute(self):
self.sys_time_read_task.execute()
self.first_boot_read_task.execute()
self.antenna_deploy_read_task.execute()
22 changes: 13 additions & 9 deletions MainControlLoop/tasks/PiMonitor/task.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
from MainControlLoop.lib.StateFieldRegistry import StateFieldRegistry
from MainControlLoop.tasks.PiMonitor.system_time_read_task import SystemTimeReadTask
from MainControlLoop.tasks.PiMonitor.first_boot_read_task import FirstBootReadTask
from MainControlLoop.tasks.PiMonitor.antenna_deploy_read_task import AntennaDeployReadTask
from MainControlLoop.tasks.PiMonitor.read_task import PiMonitorReadTask
from MainControlLoop.tasks.PiMonitor.actuate_task import PiMonitorActuateTask
from MainControlLoop.tasks.PiMonitor.control_task import PiMonitorControlTask


class PiMonitorTask:

def __init__(self, state_field_registry: StateFieldRegistry):
self.state_field_registry: StateFieldRegistry = state_field_registry
self.sys_time_read_task = SystemTimeReadTask(self.state_field_registry)
self.first_boot_read_task = FirstBootReadTask(self.state_field_registry)
self.antenna_deploy_read_task = AntennaDeployReadTask(self.state_field_registry)
self.read_task: PiMonitorReadTask = PiMonitorReadTask()
self.actuate_task: PiMonitorActuateTask = PiMonitorActuateTask()
self.control_task: PiMonitorControlTask = PiMonitorControlTask(state_field_registry, self.actuate_task)

def read(self):
self.sys_time_read_task.execute()
self.first_boot_read_task.execute()
self.antenna_deploy_read_task.execute()
self.read_task.execute()

def control(self):
self.control_task.execute()

def actuate(self):
self.actuate_task.execute()
10 changes: 9 additions & 1 deletion MainControlLoop/tasks/core/Core.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,15 @@ def dispatch_comms(self):
return

def dispatch_boot(self):
return
if self.state_field_registry.critical_failure():
self.dispatch_safe()
return

if self.state_field_registry.get(StateField.BOOT_WAIT_COMPLETE):
self.dispatch_startup()
return

self.aprs_task.set_mode(Mode.BOOT)

def dispatch_startup(self):
return