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 1 commit
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
Next Next commit
core for boot logic
  • Loading branch information
sparthaje committed Feb 21, 2020
commit ffa7c54b01020d3c8cda289b76fb74737c91f757
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
5 changes: 2 additions & 3 deletions MainControlLoop/tasks/PiMonitor/first_boot_read_task.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from time import time as sys_time
from os import path

from MainControlLoop.lib.StateFieldRegistry import StateFieldRegistry, StateField


class FirstBootReadTask:
class BootWaitCompleteReadTask:

def __init__(self, state_field_registry: StateFieldRegistry):
self.state_field_registry: StateFieldRegistry = state_field_registry
Expand All @@ -14,6 +13,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("/root/first_boot"))


2 changes: 2 additions & 0 deletions MainControlLoop/tasks/PiMonitor/system_time_read_task.py
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)
4 changes: 2 additions & 2 deletions MainControlLoop/tasks/PiMonitor/task.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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.first_boot_read_task import BootWaitCompleteReadTask
from MainControlLoop.tasks.PiMonitor.antenna_deploy_read_task import AntennaDeployReadTask


Expand All @@ -9,7 +9,7 @@ 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.first_boot_read_task = BootWaitCompleteReadTask(self.state_field_registry)
self.antenna_deploy_read_task = AntennaDeployReadTask(self.state_field_registry)

def read(self):
Expand Down
14 changes: 13 additions & 1 deletion MainControlLoop/tasks/core/Core.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Core:

LOW_POWER_BATTERY_THRESHOLD = 8
NORMAL_BATTERY_THRESHOLD = 9
BOOT_INTERVAL = 1800

ENTER_SAFE_COMMAND = "TJ:C;CORE;safe;;"
ENTER_COMMS_COMMAND = "TJ:C;CORE;comms;;"
Expand Down Expand Up @@ -55,7 +56,18 @@ def dispatch_comms(self):
return

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

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

if current_time - boot_time > 1800:
# create boot file
return

self.aprs_task.set_mode(Mode.BOOT)

def dispatch_startup(self):
return