Skip to content

Commit

Permalink
Turning off / on submodules
Browse files Browse the repository at this point in the history
  • Loading branch information
srikarg89 committed May 31, 2020
1 parent 93819a6 commit 85a6ad4
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 6 deletions.
51 changes: 49 additions & 2 deletions src/hermes/hermes.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,64 @@
from hermes.modules.eps import EPS
import sys
import time
from threading import Thread
from hermes.modules.eps import EPS

class Hermes:

def __init__(self, config):
self.config = config
self.submodules = []
self.registry = {
"EPS_ON": True,
"PI_ON": True,
"ADCS_ON": True,
"ANTENNA_DEPLOYER_ON": True,
"IRIDIUM_ON": True
}
self.running = []
if "EPS" in self.config:
self.submodules.append(EPS(self.config))
self.submodules["EPS"] = EPS(self.config, self.registry)


def control(self):
while True:
if not self.registry["PI_ON"]:
# TODO: Somehow simulate a reboot (requires restarting MCL)
raise Exception("Pi turned off!")
sys.exit(0)
for submodule in self.submodules:
# If the submodule should be off but is currently on, turn it off
if not self.registry[submodule + "_ON"] and not self.submodules[submodule].terminated:
self.turn_off(submodule)
# If the submodule should be on but is currently off, restart it
elif self.registry[submodule + "_ON"] and not self.submodules[submodule].terminated:
self.reset(submodule)


def turn_off(self, submodule):
if submodule not in self.submodules:
print("Submodule {} not found!".format(submodule))
self.submodules[submodule].terminated = True


def turn_on(self, submodule):
if submodule not in self.submodules:
print("Submodule {} not found!".format(submodule))
self.submodules[submodule].terminated = False


def reset(self, submodule):
if submodule not in self.submodules:
print("Submodule {} not found!".format(submodule))
self.submodules[submodule].terminated = True
time.sleep(self.config[submodule]["reset_time"])
self.submodules[submodule].terminated = False
self.submodules[submodule].reset()


def run(self):
for submodule in self.submodules:
sub_thread = Thread(target=submodule.run)
sub_thread.daemon = True
sub_thread.start()
self.running.append(submodule)
25 changes: 21 additions & 4 deletions src/hermes/modules/eps.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,22 @@ class EPSRegister(Enum):

class EPS:

def __init__(self, config):
def __init__(self, config, registry):
# TODO: Use the actual initial states
self.config = config["EPS"]
self.registry = registry
self.address = self.config["address"]
self.state_filename = self.config["state_filename"]
self.command_filename = self.config["command_filename"]
self.initial_pdm_states = [0 for i in range(10)] # everything is off
self.initial_watchdog = 4
self.initial_watchdog_period = 4
self.board_version = 1234
self.board_checksum = 4321
self.board_firmware_revision = 2345
self.timer_limits = [30 for i in range(10)]
self.data_registers = [0x10, 0x21, 0x50, 0x51, 0x52, 0x53, 0x54, 0x60, 0x61, 0x62, 0x70]

self.terminated = False
self.reset()


Expand All @@ -71,8 +73,9 @@ def reset(self):
# 0 is off, 1 is on
self.expected_pdm_states = self.initial_pdm_states.copy()
self.timer_values = [0 for i in range(10)]
self.watchdog_period = self.initial_watchdog

self.watchdog_period = self.initial_watchdog_period
self.watchdog = time.time()

# Create files
# self.state = {register.value: 0 for register in EPSRegister}
self.state = 0x00
Expand All @@ -83,11 +86,25 @@ def reset(self):
write_file(self.command_filename, self.empty_commands)


def hard_reset(self):
self.reset()


def terminate(self):
self.hard_reset()
self.terminated = True


def run(self):
while True:
if self.terminated:
continue
time.sleep(0.1) # Temporary for testing, should remove this in final version
print(self.measure_pdms())
if time.time() - self.watchdog_period > self.watchdog:
self.registry["EPS_ON"] = False
self.registry["PI_ON"] = False
self.expected_pdm_states = [0 for i in range(10)]
# Implement watchdog
commands = read_file(self.command_filename)
performed_command = False
Expand Down

0 comments on commit 85a6ad4

Please sign in to comment.