diff --git a/oresat_configs/scripts/gen_dbc.py b/oresat_configs/scripts/gen_dbc.py index d889854..a732618 100644 --- a/oresat_configs/scripts/gen_dbc.py +++ b/oresat_configs/scripts/gen_dbc.py @@ -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" @@ -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_", @@ -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}") @@ -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)) @@ -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: