Skip to content

Commit

Permalink
add node and general comments to gen_dbc
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanpdx committed Mar 7, 2024
1 parent 489a1e2 commit 576af92
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions oresat_configs/scripts/gen_dbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from canopen.objectdictionary import REAL32, REAL64, UNSIGNED_TYPES, Variable

from .. import Consts, OreSatConfig
from .. import Consts, OreSatConfig, __version__

GEN_DBC = "generate dbc file for SavvyCAN"

Expand Down Expand Up @@ -156,8 +156,7 @@ def write_dbc(config: OreSatConfig, dir_path: str = "."):
file_path = file_name

lines: list[str] = [
'VERSION ""',
"",
f'VERSION "{__version__}"',
"",
"NS_ :",
f"{INDENT4}NS_DESC_",
Expand Down Expand Up @@ -189,24 +188,34 @@ def write_dbc(config: OreSatConfig, dir_path: str = "."):
f"{INDENT4}BU_BO_REL_",
f"{INDENT4}SG_MUL_VAL_",
"",
"BS_: ",
"BS_: 1000", # bus speed in kbps
"",
]

# list of cards
cards = config.cards
lines.append("BU_: " + " ".join(cards) + " ")
lines.append("")

# general comments
lines.append(f'CM_: "{config.mission}"')
lines.append('CM_: "Generated by oresat-config from https://github.com/oresat/oreast-configs"')
lines.append("")

# SYNC
lines.append(f"BO_ {0x80} sync: 0 c3")
lines.append("")

enums: list[tuple[int, str, dict[int, str]]] = []
comments: list[tuple[int, str, str]] = []
signal_comments: list[tuple[int, str, str]] = []
node_comments: list[tuple[int, str]] = []
floats: list[tuple[int, str, int]] = []
for name, od in config.od_db.items():
if name not in cards:
continue

node_comments.append((od.node_id, od.device_information.product_name))

# EMCYs
cob_id = 0x80 + od.node_id
lines.append(f"BO_ {cob_id} {name}_emcy: 8 {name}")
Expand Down Expand Up @@ -265,7 +274,7 @@ def write_dbc(config: OreSatConfig, dir_path: str = "."):
)

if obj.description:
comments.append((cob_id, signal, obj.description))
signal_comments.append((cob_id, signal, obj.description))

if obj.data_type == REAL32:
floats.append((cob_id, signal, 1))
Expand Down Expand Up @@ -358,15 +367,23 @@ def write_dbc(config: OreSatConfig, dir_path: str = "."):
lines.append(f'{INDENT3}SG_ hearbeat : 0|8@1+ (1,0) [0|0] "" c3')
enums.append((cob_id, "hearbeat", CANOPEN_STATES))
lines.append("")
lines.append("")

# node comments
for node_id, desc in node_comments:
lines.append(f'CM_ BU_ {node_id} "{desc}";')
lines.append("")

# signal comments
for cob_id, signal, desc in comments:
for cob_id, signal, desc in signal_comments:
lines.append(f'CM_ SG_ {cob_id} {signal} "{desc}";')
lines.append("")

# signal enums
for cob_id, signal, value_defs in enums:
values = " ".join(f'{v} "{n}"' for v, n in value_defs.items())
lines.append(f"VAL_ {cob_id} {signal} {values};")
lines.append("")

# signal floats
for cob_id, signal, value in floats:
Expand Down

0 comments on commit 576af92

Please sign in to comment.