Skip to content

Commit

Permalink
Merge branch 'master' into bit_plane_encoder
Browse files Browse the repository at this point in the history
  • Loading branch information
kk60503 committed Nov 19, 2023
2 parents 8a13d0d + 60f43c5 commit a820ced
Show file tree
Hide file tree
Showing 73 changed files with 2,287 additions and 8,079 deletions.
5 changes: 0 additions & 5 deletions .flake8

This file was deleted.

42 changes: 27 additions & 15 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,9 @@ name: tests

on:
push:
paths:
- 'requirements-dev.txt'
- 'setup.*'
- 'docs/**'
- 'olaf/**'
- 'tests/**'
branches:
- master
pull_request:
paths:
- 'requirements-dev.txt'
- 'setup.*'
- 'docs/**'
- 'olaf/**'
- 'tests/**'
branches:
- master

Expand All @@ -27,20 +15,44 @@ jobs:
timeout-minutes: 10

steps:
- uses: actions/checkout@v2
- name: Clone oresat-c3 repository
uses: actions/checkout@v2

- name: Clone oresat-configs repository
uses: actions/checkout@v2
with:
repository: oresat/oresat-configs
path: resources/oresat-configs

- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: "3.9"

- name: Build and install oresat-configs
working-directory: resources/oresat-configs
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
python -m build
pip install dist/*.whl
- name: Clean up oresat-configs
run: rm -rf resources/oresat-configs

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Lint with flake8
run: flake8 . --count --show-source --statistics
- name: Lint with Pylama
run: pylama

- name: Check format with Black
run: black --check --diff .

- name: Check format with isort
run: isort --check --diff .

- name: Test with Python's unittest
run: python -m unittest
Expand Down
16 changes: 11 additions & 5 deletions docs/api/gpio.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@ GPIO

.. autoclass:: olaf.GpioError

.. autodata:: olaf.common.gpio.GPIO_HIGH
.. autodata:: olaf.common.gpio.GPIO_LOW
.. autodata:: olaf.common.gpio.GPIO_IN
.. autodata:: olaf.common.gpio.GPIO_OUT
.. autodata:: olaf.GPIO_HIGH
.. autodata:: olaf.GPIO_LOW
.. autodata:: olaf.GPIO_IN
.. autodata:: olaf.GPIO_OUT

.. autoclass:: olaf.GpioPin
:members:
:undoc-members:
:member-order: bysource

Backward Compatibility
----------------------

These alias should be avoid. Only for backward compatibility with previous versions of OLAF.
These alias should be avoided. Theses are only for backward compatibility with previous versions
of OLAF.

.. autoclass:: olaf.GPIO
:class-doc-from: both
Expand Down
41 changes: 16 additions & 25 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
"""Configuration file for the Sphinx documentation builder."""

# -- Path setup --------------------------------------------------------------

Expand All @@ -12,15 +8,18 @@

import os
import sys
sys.path.insert(0, os.path.abspath('..'))

sys.path.insert(0, os.path.abspath(".."))


# -- Project information -----------------------------------------------------

from datetime import datetime
project = 'OreSat Linux App Framework'
copyright = f'{datetime.now().date().year}, Portland State Aerospace Society'
author = 'PSAS'

project = "OreSat Linux App Framework"
year = datetime.now().date().year
copyright = f"{year}, Portland State Aerospace Society" # pylint: disable=W0622
author = "PSAS"


# -- General configuration ---------------------------------------------------
Expand All @@ -29,37 +28,29 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.napoleon',
'sphinx.ext.coverage',
'sphinx.ext.viewcode',
'sphinx.ext.intersphinx',
'sphinx.ext.autodoc'
"sphinx.ext.napoleon",
"sphinx.ext.coverage",
"sphinx.ext.viewcode",
"sphinx.ext.intersphinx",
"sphinx.ext.autodoc",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = []

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['Thumbs.db', '.DS_Store']
exclude_patterns = ["Thumbs.db", ".DS_Store"]


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = []
html_theme = "sphinx_rtd_theme"


# -- Others Options ----------------------------------------------------------

# Example configuration for intersphinx: refer to the Python standard library.
# To add links to stand python type definitions.
intersphinx_mapping = {'python': ('https://docs.python.org/3/', None)}
intersphinx_mapping = {"python": ("https://docs.python.org/3/", None)}
1 change: 0 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ Society).
api/index
rest_api
updater/index
scripts


Indices and tables
Expand Down
24 changes: 0 additions & 24 deletions docs/scripts.rst

This file was deleted.

134 changes: 80 additions & 54 deletions olaf/__init__.py
Original file line number Diff line number Diff line change
@@ -1,97 +1,123 @@
"""OLAF (OreSat Linux App Framework)"""

import os
import sys
from logging.handlers import SysLogHandler
from argparse import ArgumentParser, Namespace
from logging.handlers import SysLogHandler

import canopen
from loguru import logger
from oresat_configs import NodeId, OreSatConfig, OreSatId

from ._internals.app import app, App
from ._internals.node import Node, NodeStop, NetworkError
from ._internals.app import App, app
from ._internals.master_node import MasterNode
from ._internals.rest_api import rest_api, RestAPI, render_olaf_template
from .common.resource import Resource
from .common.service import Service
from ._internals.node import NetworkError, Node, NodeStop
from ._internals.rest_api import RestAPI, render_olaf_template, rest_api
from ._internals.services.logs import logger_tmp_file_setup
from .common.adc import Adc
from .common.cpufreq import A8_CPUFREQS, get_cpufreq, get_cpufreq_gov, set_cpufreq, set_cpufreq_gov
from .common.daemon import Daemon, DaemonState
from .common.ecss import scet_int_from_time, scet_int_to_time, utc_int_from_time, utc_int_to_time
from .common.gpio import GPIO_HIGH, GPIO_IN, GPIO_LOW, GPIO_OUT, Gpio, GpioError
from .common.oresat_file import OreSatFile, new_oresat_file
from .common.oresat_file_cache import OreSatFileCache
from .common.pru import Pru, PruError, PruState
from .common.resource import Resource
from .common.service import Service
from .common.timer_loop import TimerLoop
from .common.gpio import Gpio, GpioError, GPIO_LOW, GPIO_HIGH, GPIO_IN, GPIO_OUT
from .common.gpio import Gpio as GPIO # for backwards compatibility
from .common.gpio import GpioError as GPIOError # for backwards compatibility
from .common.adc import Adc
from .common.daemon import Daemon, DaemonState
from .common.cpufreq import get_cpufreq, get_cpufreq_gov, set_cpufreq, set_cpufreq_gov, A8_CPUFREQS
from .common.pru import Pru, PruState, PruError


__version__ = '2.2.0'
__version__ = "3.0.0"


def olaf_setup(eds_path: str = None, master_node: bool = False) -> Namespace:
'''
def olaf_setup(node_id: NodeId) -> tuple[Namespace, dict]:
"""
Parse runtime args and setup the app and REST API.
Parameters
----------
eds_path: str
The path to the eds or dcf file.
master_node: bool
Run as master node.
node: Node
The card's node
Returns
-------
Namespace
The runtime args.
'''

parser = ArgumentParser(prog='OLAF')
parser.add_argument('-b', '--bus', default='vcan0', help='CAN bus to use, defaults to vcan0')
parser.add_argument('-n', '--node-id', type=str, default='0', metavar='ID',
help='set the node ID')
parser.add_argument('-v', '--verbose', action='store_true', help='enable verbose logging')
parser.add_argument('-l', '--log', action='store_true', help='log to only journald')
parser.add_argument('-e', '--eds', metavar='FILE', help='EDS / DCF file to use')
parser.add_argument('-m', '--mock-hw', nargs='*', metavar='HW', default=[],
help='list the hardware to mock or just "all" to mock all hardware')
parser.add_argument('-a', '--address', default='localhost',
help='rest api address, defaults to localhost')
parser.add_argument('-p', '--port', type=int, default=8000,
help='rest api port number, defaults to 8000')
parser.add_argument('-d', '--disable-flight-mode', action='store_true',
help='disable flight mode on start, defaults to flight mode enabled')
dict
The OreSat configs.
"""

parser = ArgumentParser(prog="OLAF")
parser.add_argument("-b", "--bus", default="vcan0", help="CAN bus to use, defaults to vcan0")
parser.add_argument("-v", "--verbose", action="store_true", help="enable verbose logging")
parser.add_argument("-l", "--log", action="store_true", help="log to only journald")
parser.add_argument(
"-m",
"--mock-hw",
nargs="*",
metavar="HW",
default=[],
help='list the hardware to mock or just "all" to mock all hardware',
)
parser.add_argument(
"-a", "--address", default="localhost", help="rest api address, defaults to localhost"
)
parser.add_argument(
"-p", "--port", type=int, default=8000, help="rest api port number, defaults to 8000"
)
parser.add_argument(
"-d",
"--disable-flight-mode",
action="store_true",
help="disable flight mode on start, defaults to flight mode enabled",
)
parser.add_argument(
"-o", "--oresat", default="oresat0.5", help="oresat mission; oresat0, oresat0.5, etc"
)
args = parser.parse_args()

if args.verbose:
level = 'DEBUG'
level = "DEBUG"
else:
level = 'INFO'
level = "INFO"

logger.remove() # remove default logger
if args.log:
logger.add(SysLogHandler(address='/dev/log'), level=level, backtrace=True)
logger.add(SysLogHandler(address="/dev/log"), level=level, backtrace=True)
else:
logger.add(sys.stdout, level=level, backtrace=True)

olaf_boot_logs = '/tmp/olaf.log'
if os.path.isfile(olaf_boot_logs):
os.remove(olaf_boot_logs)
logger.add(olaf_boot_logs, level=level, backtrace=True)
logger_tmp_file_setup(level)

if eds_path is None:
eds_path = args.eds
arg_oresat = args.oresat.lower()
if arg_oresat in ["oresat0", "0"]:
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"]:
oresat_id = OreSatId.ORESAT1
else:
raise ValueError(f"invalid oresat mission {args.oresat}")

app.setup(eds_path, args.bus, args.node_id, master_node=master_node)
rest_api.setup(address=args.address, port=args.port)
config = OreSatConfig(oresat_id)
od = config.od_db[node_id]

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

if args.disable_flight_mode and 0x3007 in app.od and 0x2 in app.od[0x3007]:
logger.info('disabling flight mode')
app.od[0x3007][0x2].value = not args.disable_flight_mode
od["versions"]["olaf_version"].value = __version__

if node_id == NodeId.C3:
app.setup(od, args.bus, config.od_db)
else:
app.setup(od, args.bus)

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

return args
return args, config


def olaf_run():
'''Start the app and REST API.'''
"""Start the app and REST API."""

rest_api.start()
app.run()
Expand Down
Loading

0 comments on commit a820ced

Please sign in to comment.