Skip to content

Commit

Permalink
add number arg and a flag to not load the core services/resoures
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanpdx committed Dec 13, 2023
1 parent 3e2b494 commit 594d4fc
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 18 deletions.
19 changes: 15 additions & 4 deletions olaf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ def olaf_setup(name: str) -> tuple[Namespace, dict]:
"""

# for backwards support
if isinstance(name, NodeId):
if name == NodeId.CFC:
name = "cfc_processor"
elif isinstance(name, NodeId):
name = name.name.lower()

parser = ArgumentParser(prog="OLAF")
Expand Down Expand Up @@ -77,6 +79,7 @@ def olaf_setup(name: str) -> tuple[Namespace, dict]:
parser.add_argument(
"-o", "--oresat", default="oresat0.5", help="oresat mission; oresat0, oresat0.5, etc"
)
parser.add_argument("-n", "--number", type=int, default=1, help="card number")
args = parser.parse_args()

if args.verbose:
Expand All @@ -97,23 +100,31 @@ def olaf_setup(name: str) -> tuple[Namespace, dict]:
oresat_id = OreSatId.ORESAT0
elif arg_oresat in ["oresat0.5", "oresat0_5", "0.5"]:
oresat_id = OreSatId.ORESAT0_5
elif arg_oresat in ["oresat", "1"]:
elif arg_oresat in ["oresat", "oresat1", "1"]:
oresat_id = OreSatId.ORESAT1
else:
raise ValueError(f"invalid oresat mission {args.oresat}")

config = OreSatConfig(oresat_id)

if name not in config.cards:
name += f"_{args.number}"
if name not in config.cards:
raise ValueError(f"invalid card {name} for {args.oresat}")

od = config.od_db[name]

if args.disable_flight_mode:
od["flight_mode"].value = False

od["versions"]["olaf_version"].value = __version__

is_octavo = config.cards[name].processor == "octavo"

if name == "c3":
app.setup(od, args.bus, config.od_db)
app.setup(od, args.bus, config.od_db, is_octavo)
else:
app.setup(od, args.bus)
app.setup(od, args.bus, None, is_octavo)

rest_api.setup(address=args.address, port=args.port)

Expand Down
32 changes: 20 additions & 12 deletions olaf/_internals/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import signal
import subprocess
from typing import Union

import canopen
from loguru import logger
Expand Down Expand Up @@ -52,14 +53,20 @@ def _quit(self, signo, _frame):
logger.debug(f"signal {signal.Signals(signo).name} was caught")
self.stop()

def setup(self, od, bus: str, master_od_db: dict = {}):
def setup(self, od, bus: str, master_od_db: Union[dict, None] = None, load_core: bool = True):
"""
Setup the app. Will be called by ``olaf_setup`` automatically.
Parameters
----------
node: Node
The node for the app.
bus: str
The name of CAN bus/interface to connect to.
master_od_db: dict
Master node od database. Only for the C3.
load_core: bool
Load the core olaf services and resources
Raises
------
Expand All @@ -80,17 +87,18 @@ def setup(self, od, bus: str, master_od_db: dict = {}):
f"{self._node.work_base_dir}/updater", f"{self._node.cache_base_dir}/updates"
)

# default core services
self.add_service(UpdaterService(self._updater))
self.add_service(LogsService())
self.add_service(OsCommandService())

# default core resources
self.add_resource(EcssResource())
self.add_resource(SystemResource())
self.add_resource(FreadResource())
self.add_resource(FwriteResource())
# self.add_resource(DaemonsResource())
if load_core:
# default core services
self.add_service(UpdaterService(self._updater))
self.add_service(LogsService())
self.add_service(OsCommandService())

# default core resources
self.add_resource(EcssResource())
self.add_resource(SystemResource())
self.add_resource(FreadResource())
self.add_resource(FwriteResource())
# self.add_resource(DaemonsResource())

def add_resource(self, resource: Resource):
"""
Expand Down
13 changes: 11 additions & 2 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
action="store_true",
help="disable flight mode on start, defaults to flight mode enabled",
)
parser.add_argument("-n", "--number", type=int, default=1, help="card number")
args = parser.parse_args()

if args.verbose:
Expand All @@ -46,11 +47,19 @@

config = OreSatConfig(oresat_id)

if card_name not in config.cards:
card_name += f"_{args.number}"
if card_name not in config.cards:
print(f"invalid card {args.card} for {args.oresat}")
sys.exit(1)

is_octavo = config.cards[card_name].processor == "octavo"

od = config.od_db[card_name]
if card_name == "c3":
app.setup(od, args.bus, config.od_db)
app.setup(od, args.bus, config.od_db, is_octavo)
else:
app.setup(od, args.bus)
app.setup(od, args.bus, None, is_octavo)

rest_api.setup(address=args.address, port=args.port)

Expand Down

0 comments on commit 594d4fc

Please sign in to comment.