Skip to content

Commit

Permalink
rework globals and imports
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanpdx committed Oct 1, 2023
1 parent 31f2177 commit 45337d0
Show file tree
Hide file tree
Showing 12 changed files with 186 additions and 166 deletions.
105 changes: 10 additions & 95 deletions oresat_od_db/__init__.py
Original file line number Diff line number Diff line change
@@ -1,100 +1,15 @@
"""OreSat OD database"""

__version__ = "0.1.0"
from .constants import NODE_NICE_NAMES, Index, NodeId, OreSatId, __version__
from .oresat0 import ORESAT0_BEACON_DEF, ORESAT0_OD_DB
from .oresat0_5 import ORESAT0_5_BEACON_DEF, ORESAT0_5_OD_DB

from enum import IntEnum


class OreSatId(IntEnum):
"""Unique ID for each OreSat."""

ORESAT0 = 1
ORESAT0_5 = 2
ORESAT1 = 3


class NodeId(IntEnum):
"""All the CANopen Node ID for OreSat cards."""

C3 = 0x01
BATTERY_1 = 0x04
BATTERY_2 = 0x08
SOLAR_MODULE_1 = 0x0C
SOLAR_MODULE_2 = 0x10
SOLAR_MODULE_3 = 0x14
SOLAR_MODULE_4 = 0x18
SOLAR_MODULE_5 = 0x1C
SOLAR_MODULE_6 = 0x20
SOLAR_MODULE_7 = 0x24
SOLAR_MODULE_8 = 0x28
STAR_TRACKER_1 = 0x2C
STAR_TRACKER_2 = 0x30
GPS = 0x34
IMU = 0x38
REACTION_WHEEL_1 = 0x3C
REACTION_WHEEL_2 = 0x40
REACTION_WHEEL_3 = 0x44
REACTION_WHEEL_4 = 0x48
DXWIFI = 0x4C
CFC = 0x50


NODE_NICE_NAMES = {
NodeId.C3: "C3",
NodeId.BATTERY_1: "Battery 1",
NodeId.BATTERY_2: "Battery 2",
NodeId.SOLAR_MODULE_1: "Solar Module 1",
NodeId.SOLAR_MODULE_2: "Solar Module 2",
NodeId.SOLAR_MODULE_3: "Solar Module 3",
NodeId.SOLAR_MODULE_4: "Solar Module 4",
NodeId.SOLAR_MODULE_5: "Solar Module 5",
NodeId.SOLAR_MODULE_6: "Solar Module 6",
NodeId.SOLAR_MODULE_7: "Solar Module 7",
NodeId.SOLAR_MODULE_8: "Solar Module 8",
NodeId.STAR_TRACKER_1: "Star Tracker 1",
NodeId.STAR_TRACKER_2: "Star Tracker 2",
NodeId.GPS: "GPS",
NodeId.IMU: "IMU",
NodeId.REACTION_WHEEL_1: "Reaction Wheel 1",
NodeId.REACTION_WHEEL_2: "Reaction Wheel 2",
NodeId.REACTION_WHEEL_3: "Reaction Wheel 3",
NodeId.REACTION_WHEEL_4: "Reaction Wheel 4",
NodeId.DXWIFI: "DxWiFi",
NodeId.CFC: "CFC",
OD_DB = {
OreSatId.ORESAT0: ORESAT0_OD_DB,
OreSatId.ORESAT0_5: ORESAT0_5_OD_DB,
}
"""Nice name for CANopen Nodes."""


class Index(IntEnum):
"""OD posible indexes."""

# standard object indexes
PRODUCER_HEARTBEAT_TIME = 0x1017
OS_COMMAND = 0x1023
SCET = 0x2010
UTC = 0x2011
# OreSat indexes
COMMON_DATA = 0x3000
CARD_DATA = 0x6000
OTHER_CARD_BASE_INDEX = 0x7000
C3_DATA = OTHER_CARD_BASE_INDEX + NodeId.C3
BATTERY_1_DATA = OTHER_CARD_BASE_INDEX + NodeId.BATTERY_1
BATTERY_2_DATA = OTHER_CARD_BASE_INDEX + NodeId.BATTERY_2
SOLAR_MODULE_1_DATA = OTHER_CARD_BASE_INDEX + NodeId.SOLAR_MODULE_1
SOLAR_MODULE_2_DATA = OTHER_CARD_BASE_INDEX + NodeId.SOLAR_MODULE_2
SOLAR_MODULE_3_DATA = OTHER_CARD_BASE_INDEX + NodeId.SOLAR_MODULE_3
SOLAR_MODULE_4_DATA = OTHER_CARD_BASE_INDEX + NodeId.SOLAR_MODULE_4
SOLAR_MODULE_5_DATA = OTHER_CARD_BASE_INDEX + NodeId.SOLAR_MODULE_5
SOLAR_MODULE_6_DATA = OTHER_CARD_BASE_INDEX + NodeId.SOLAR_MODULE_6
SOLAR_MODULE_7_DATA = OTHER_CARD_BASE_INDEX + NodeId.SOLAR_MODULE_7
SOLAR_MODULE_8_DATA = OTHER_CARD_BASE_INDEX + NodeId.SOLAR_MODULE_8
STAR_TRACKER_1_DATA = OTHER_CARD_BASE_INDEX + NodeId.STAR_TRACKER_1
STAR_TRACKER_2_DATA = OTHER_CARD_BASE_INDEX + NodeId.STAR_TRACKER_2
GPS_DATA = OTHER_CARD_BASE_INDEX + NodeId.GPS
IMU_DATA = OTHER_CARD_BASE_INDEX + NodeId.IMU
REACTION_WHEEL_1_DATA = OTHER_CARD_BASE_INDEX + NodeId.REACTION_WHEEL_1
REACTION_WHEEL_2_DATA = OTHER_CARD_BASE_INDEX + NodeId.REACTION_WHEEL_2
REACTION_WHEEL_3_DATA = OTHER_CARD_BASE_INDEX + NodeId.REACTION_WHEEL_3
REACTION_WHEEL_4_DATA = OTHER_CARD_BASE_INDEX + NodeId.REACTION_WHEEL_4
DXWIFI_DATA = OTHER_CARD_BASE_INDEX + NodeId.DXWIFI
CFC_DATA = OTHER_CARD_BASE_INDEX + NodeId.CFC
BEACON_DEF_DB = {
OreSatId.ORESAT0: ORESAT0_BEACON_DEF,
OreSatId.ORESAT0_5: ORESAT0_5_BEACON_DEF,
}
2 changes: 2 additions & 0 deletions oresat_od_db/base/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""OreSat od base configs."""

import os

from .._json_to_od import read_json_od_config
Expand Down
100 changes: 100 additions & 0 deletions oresat_od_db/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
"""OreSat OD constants"""

from enum import IntEnum

__version__ = "0.1.0"


class OreSatId(IntEnum):
"""Unique ID for each OreSat."""

ORESAT0 = 1
ORESAT0_5 = 2
ORESAT1 = 3


class NodeId(IntEnum):
"""All the CANopen Node ID for OreSat cards."""

C3 = 0x01
BATTERY_1 = 0x04
BATTERY_2 = 0x08
SOLAR_MODULE_1 = 0x0C
SOLAR_MODULE_2 = 0x10
SOLAR_MODULE_3 = 0x14
SOLAR_MODULE_4 = 0x18
SOLAR_MODULE_5 = 0x1C
SOLAR_MODULE_6 = 0x20
SOLAR_MODULE_7 = 0x24
SOLAR_MODULE_8 = 0x28
STAR_TRACKER_1 = 0x2C
STAR_TRACKER_2 = 0x30
GPS = 0x34
IMU = 0x38
REACTION_WHEEL_1 = 0x3C
REACTION_WHEEL_2 = 0x40
REACTION_WHEEL_3 = 0x44
REACTION_WHEEL_4 = 0x48
DXWIFI = 0x4C
CFC = 0x50


NODE_NICE_NAMES = {
NodeId.C3: "C3",
NodeId.BATTERY_1: "Battery 1",
NodeId.BATTERY_2: "Battery 2",
NodeId.SOLAR_MODULE_1: "Solar Module 1",
NodeId.SOLAR_MODULE_2: "Solar Module 2",
NodeId.SOLAR_MODULE_3: "Solar Module 3",
NodeId.SOLAR_MODULE_4: "Solar Module 4",
NodeId.SOLAR_MODULE_5: "Solar Module 5",
NodeId.SOLAR_MODULE_6: "Solar Module 6",
NodeId.SOLAR_MODULE_7: "Solar Module 7",
NodeId.SOLAR_MODULE_8: "Solar Module 8",
NodeId.STAR_TRACKER_1: "Star Tracker 1",
NodeId.STAR_TRACKER_2: "Star Tracker 2",
NodeId.GPS: "GPS",
NodeId.IMU: "IMU",
NodeId.REACTION_WHEEL_1: "Reaction Wheel 1",
NodeId.REACTION_WHEEL_2: "Reaction Wheel 2",
NodeId.REACTION_WHEEL_3: "Reaction Wheel 3",
NodeId.REACTION_WHEEL_4: "Reaction Wheel 4",
NodeId.DXWIFI: "DxWiFi",
NodeId.CFC: "CFC",
}
"""Nice name for CANopen Nodes."""


class Index(IntEnum):
"""OD posible indexes."""

# standard object indexes
PRODUCER_HEARTBEAT_TIME = 0x1017
OS_COMMAND = 0x1023
SCET = 0x2010
UTC = 0x2011
# OreSat indexes
COMMON_DATA = 0x3000
CARD_DATA = 0x6000
OTHER_CARD_BASE_INDEX = 0x7000
C3_DATA = OTHER_CARD_BASE_INDEX + NodeId.C3
BATTERY_1_DATA = OTHER_CARD_BASE_INDEX + NodeId.BATTERY_1
BATTERY_2_DATA = OTHER_CARD_BASE_INDEX + NodeId.BATTERY_2
SOLAR_MODULE_1_DATA = OTHER_CARD_BASE_INDEX + NodeId.SOLAR_MODULE_1
SOLAR_MODULE_2_DATA = OTHER_CARD_BASE_INDEX + NodeId.SOLAR_MODULE_2
SOLAR_MODULE_3_DATA = OTHER_CARD_BASE_INDEX + NodeId.SOLAR_MODULE_3
SOLAR_MODULE_4_DATA = OTHER_CARD_BASE_INDEX + NodeId.SOLAR_MODULE_4
SOLAR_MODULE_5_DATA = OTHER_CARD_BASE_INDEX + NodeId.SOLAR_MODULE_5
SOLAR_MODULE_6_DATA = OTHER_CARD_BASE_INDEX + NodeId.SOLAR_MODULE_6
SOLAR_MODULE_7_DATA = OTHER_CARD_BASE_INDEX + NodeId.SOLAR_MODULE_7
SOLAR_MODULE_8_DATA = OTHER_CARD_BASE_INDEX + NodeId.SOLAR_MODULE_8
STAR_TRACKER_1_DATA = OTHER_CARD_BASE_INDEX + NodeId.STAR_TRACKER_1
STAR_TRACKER_2_DATA = OTHER_CARD_BASE_INDEX + NodeId.STAR_TRACKER_2
GPS_DATA = OTHER_CARD_BASE_INDEX + NodeId.GPS
IMU_DATA = OTHER_CARD_BASE_INDEX + NodeId.IMU
REACTION_WHEEL_1_DATA = OTHER_CARD_BASE_INDEX + NodeId.REACTION_WHEEL_1
REACTION_WHEEL_2_DATA = OTHER_CARD_BASE_INDEX + NodeId.REACTION_WHEEL_2
REACTION_WHEEL_3_DATA = OTHER_CARD_BASE_INDEX + NodeId.REACTION_WHEEL_3
REACTION_WHEEL_4_DATA = OTHER_CARD_BASE_INDEX + NodeId.REACTION_WHEEL_4
DXWIFI_DATA = OTHER_CARD_BASE_INDEX + NodeId.DXWIFI
CFC_DATA = OTHER_CARD_BASE_INDEX + NodeId.CFC
30 changes: 14 additions & 16 deletions oresat_od_db/oresat0/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@
SW_COMMON_CONFIG,
)

ORESAT_ID = OreSatId.ORESAT0

_JSON_DIR = f"{os.path.dirname(os.path.abspath(__file__))}/jsons"
BAT_CONFIG_OVERLAY = read_json_od_config(f"{_JSON_DIR}/battery_overlay.json")

with open(f"{_JSON_DIR}/beacon.json", "r") as f:
BEACON_DEF = json.load(f)
ORESAT0_BEACON_DEF = json.load(f)

OD_DB = gen_od_db(
ORESAT_ID,
BEACON_DEF,
ORESAT0_OD_DB = gen_od_db(
OreSatId.ORESAT0,
ORESAT0_BEACON_DEF,
{
NodeId.C3: (C3_CONFIG, FW_COMMON_CONFIG),
NodeId.BATTERY_1: (BAT_CONFIG, FW_COMMON_CONFIG, BAT_CONFIG_OVERLAY),
Expand All @@ -43,13 +41,13 @@
)

# direct access to ODs
C3_OD = OD_DB[NodeId.C3]
BATTERY_1_OD = OD_DB[NodeId.BATTERY_1]
SOLAR_MODULE_1_OD = OD_DB[NodeId.SOLAR_MODULE_1]
SOLAR_MODULE_2_OD = OD_DB[NodeId.SOLAR_MODULE_2]
SOLAR_MODULE_3_OD = OD_DB[NodeId.SOLAR_MODULE_3]
SOLAR_MODULE_4_OD = OD_DB[NodeId.SOLAR_MODULE_4]
IMU_OD = OD_DB[NodeId.IMU]
GPS_OD = OD_DB[NodeId.GPS]
STAR_TRACKER_1_OD = OD_DB[NodeId.STAR_TRACKER_1]
DXWIFI_OD = OD_DB[NodeId.DXWIFI]
ORESAT0_C3_OD = ORESAT0_OD_DB[NodeId.C3]
ORESAT0_BATTERY_1_OD = ORESAT0_OD_DB[NodeId.BATTERY_1]
ORESAT0_SOLAR_MODULE_1_OD = ORESAT0_OD_DB[NodeId.SOLAR_MODULE_1]
ORESAT0_SOLAR_MODULE_2_OD = ORESAT0_OD_DB[NodeId.SOLAR_MODULE_2]
ORESAT0_SOLAR_MODULE_3_OD = ORESAT0_OD_DB[NodeId.SOLAR_MODULE_3]
ORESAT0_SOLAR_MODULE_4_OD = ORESAT0_OD_DB[NodeId.SOLAR_MODULE_4]
ORESAT0_IMU_OD = ORESAT0_OD_DB[NodeId.IMU]
ORESAT0_GPS_OD = ORESAT0_OD_DB[NodeId.GPS]
ORESAT0_STAR_TRACKER_1_OD = ORESAT0_OD_DB[NodeId.STAR_TRACKER_1]
ORESAT0_DXWIFI_OD = ORESAT0_OD_DB[NodeId.DXWIFI]
46 changes: 22 additions & 24 deletions oresat_od_db/oresat0_5/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os

from .. import NodeId, OreSatId
from .._json_to_od import gen_od_db, read_json_od_config
from .._json_to_od import gen_od_db
from ..base import (
BAT_CONFIG,
C3_CONFIG,
Expand All @@ -19,16 +19,14 @@
SW_COMMON_CONFIG,
)

ORESAT_ID = OreSatId.ORESAT0_5

_JSON_DIR = f"{os.path.dirname(os.path.abspath(__file__))}/jsons"
with open(f"{_JSON_DIR}/beacon.json", "r") as f:
BEACON_DEF = json.load(f)
ORESAT0_5_BEACON_DEF = json.load(f)


OD_DB = gen_od_db(
ORESAT_ID,
BEACON_DEF,
ORESAT0_5_OD_DB = gen_od_db(
OreSatId.ORESAT0_5,
ORESAT0_5_BEACON_DEF,
{
NodeId.C3: (C3_CONFIG, SW_COMMON_CONFIG),
NodeId.BATTERY_1: (BAT_CONFIG, FW_COMMON_CONFIG),
Expand All @@ -51,20 +49,20 @@
)

# direct access to ODs
C3_OD = OD_DB[NodeId.C3]
BATTERY_1_OD = OD_DB[NodeId.BATTERY_1]
SOLAR_MODULE_1_OD = OD_DB[NodeId.SOLAR_MODULE_1]
SOLAR_MODULE_2_OD = OD_DB[NodeId.SOLAR_MODULE_2]
SOLAR_MODULE_3_OD = OD_DB[NodeId.SOLAR_MODULE_3]
SOLAR_MODULE_4_OD = OD_DB[NodeId.SOLAR_MODULE_4]
SOLAR_MODULE_5_OD = OD_DB[NodeId.SOLAR_MODULE_5]
SOLAR_MODULE_6_OD = OD_DB[NodeId.SOLAR_MODULE_6]
IMU_OD = OD_DB[NodeId.IMU]
REACTION_WHEEL_1_OD = OD_DB[NodeId.REACTION_WHEEL_1]
REACTION_WHEEL_2_OD = OD_DB[NodeId.REACTION_WHEEL_2]
REACTION_WHEEL_3_OD = OD_DB[NodeId.REACTION_WHEEL_3]
REACTION_WHEEL_4_OD = OD_DB[NodeId.REACTION_WHEEL_4]
GPS_OD = OD_DB[NodeId.GPS]
STAR_TRACKER_1_OD = OD_DB[NodeId.STAR_TRACKER_1]
DXWIFI_OD = OD_DB[NodeId.DXWIFI]
CFC_OD = OD_DB[NodeId.CFC]
ORESAT0_5_C3_OD = ORESAT0_5_OD_DB[NodeId.C3]
ORESAT0_5_BATTERY_1_OD = ORESAT0_5_OD_DB[NodeId.BATTERY_1]
ORESAT0_5_SOLAR_MODULE_1_OD = ORESAT0_5_OD_DB[NodeId.SOLAR_MODULE_1]
ORESAT0_5_SOLAR_MODULE_2_OD = ORESAT0_5_OD_DB[NodeId.SOLAR_MODULE_2]
ORESAT0_5_SOLAR_MODULE_3_OD = ORESAT0_5_OD_DB[NodeId.SOLAR_MODULE_3]
ORESAT0_5_SOLAR_MODULE_4_OD = ORESAT0_5_OD_DB[NodeId.SOLAR_MODULE_4]
ORESAT0_5_SOLAR_MODULE_5_OD = ORESAT0_5_OD_DB[NodeId.SOLAR_MODULE_5]
ORESAT0_5_SOLAR_MODULE_6_OD = ORESAT0_5_OD_DB[NodeId.SOLAR_MODULE_6]
ORESAT0_5_IMU_OD = ORESAT0_5_OD_DB[NodeId.IMU]
ORESAT0_5_REACTION_WHEEL_1_OD = ORESAT0_5_OD_DB[NodeId.REACTION_WHEEL_1]
ORESAT0_5_REACTION_WHEEL_2_OD = ORESAT0_5_OD_DB[NodeId.REACTION_WHEEL_2]
ORESAT0_5_REACTION_WHEEL_3_OD = ORESAT0_5_OD_DB[NodeId.REACTION_WHEEL_3]
ORESAT0_5_REACTION_WHEEL_4_OD = ORESAT0_5_OD_DB[NodeId.REACTION_WHEEL_4]
ORESAT0_5_GPS_OD = ORESAT0_5_OD_DB[NodeId.GPS]
ORESAT0_5_STAR_TRACKER_1_OD = ORESAT0_5_OD_DB[NodeId.STAR_TRACKER_1]
ORESAT0_5_DXWIFI_OD = ORESAT0_5_OD_DB[NodeId.DXWIFI]
ORESAT0_5_CFC_OD = ORESAT0_5_OD_DB[NodeId.CFC]
7 changes: 6 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ oresat-print-od = "scripts.print_od:main"
oresat-sdo-transfer = "scripts.sdo_transfer:main"

[tool.setuptools.dynamic]
version = {attr = "oresat_od_db.__version__"}
version = {attr = "oresat_od_db.constants.__version__"}

[tool.setuptools.packages.find]
exclude = ["docs*", "tests*"]
Expand Down Expand Up @@ -60,6 +60,11 @@ linters = "pycodestyle,pyflakes,pylint,mccabe,mypy,radon"
ignore = "E402,C901,C0103,E203,R0912,R0915,R901,R901,R0914,C0413,C0206,R1716,W1514"
max_line_length = 100

[[tool.pylama.files]]
path = "*/__init__.py"
# W0611: imported but unused
ignore = "W0611"

[[tool.mypy.overrides]]
module = "canopen"
ignore_missing_imports = true
Expand Down
22 changes: 12 additions & 10 deletions scripts/gen_canopennode_od.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import canopen

from oresat_od_db import oresat0, oresat0_5
from oresat_od_db import OD_DB, NodeId, OreSatId
from oresat_od_db._json_to_od import (
RPDO_COMM_START,
RPDO_PARA_START,
Expand Down Expand Up @@ -120,7 +120,7 @@ def write_canopennode(od: canopen.ObjectDictionary, dir_path: str = "."):
write_canopennode_h(od, dir_path)


def remove_node_id(default: str) -> str:
def remove_node_id(default: str):
"""Remove "+$NODEID" or "$NODEID+" from the default value"""

if not isinstance(default, str):
Expand Down Expand Up @@ -629,14 +629,16 @@ def write_canopennode_h(od: canopen.ObjectDictionary, dir_path: str = "."):


OD_LIST = {
("oresat0", "c3"): oresat0.C3_OD,
("oresat0", "battery"): oresat0.BATTERY_1_OD,
("oresat0", "solar"): oresat0.SOLAR_MODULE_1_OD,
("oresat0", "imu"): oresat0.IMU_OD,
("oresat0.5", "battery"): oresat0_5.BATTERY_1_OD,
("oresat0.5", "solar"): oresat0_5.SOLAR_MODULE_1_OD,
("oresat0.5", "imu"): oresat0_5.IMU_OD,
("oresat0.5", "reaction_wheel"): oresat0_5.REACTION_WHEEL_1_OD,
# OreSat0
("oresat0", "c3"): OD_DB[OreSatId.ORESAT0][NodeId.C3],
("oresat0", "battery"): OD_DB[OreSatId.ORESAT0][NodeId.BATTERY_1],
("oresat0", "solar"): OD_DB[OreSatId.ORESAT0][NodeId.SOLAR_MODULE_1],
("oresat0", "imu"): OD_DB[OreSatId.ORESAT0][NodeId.IMU],
# OreSat0.5
("oresat0.5", "battery"): OD_DB[OreSatId.ORESAT0_5][NodeId.BATTERY_1],
("oresat0.5", "solar"): OD_DB[OreSatId.ORESAT0_5][NodeId.SOLAR_MODULE_1],
("oresat0.5", "imu"): OD_DB[OreSatId.ORESAT0_5][NodeId.IMU],
("oresat0.5", "reaction_wheel"): OD_DB[OreSatId.ORESAT0_5][NodeId.REACTION_WHEEL_1],
}


Expand Down
Loading

0 comments on commit 45337d0

Please sign in to comment.