diff --git a/docs/source/safety_protocol.rst b/docs/source/safety_protocol.rst index ab3c262..179fd4a 100644 --- a/docs/source/safety_protocol.rst +++ b/docs/source/safety_protocol.rst @@ -72,25 +72,36 @@ ChargeControl1 :: - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 0| CC_PWM_Active | | | | | | CC_TargetDutyCycle | | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 1| | | | | | | | | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 2| | | | | | CC_Contactor3State | CC_Contactor2State | CC_Contactor1State | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 3| | | | | | | | | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 4| | | | | | | | | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 5| | | | | | | | | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 6| | | | | | | | | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 7| | | | | | | | | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ + Bit + + 7 6 5 4 3 2 1 0 + +---+---+---+---+---+---+---+---+ + 0 |<-x| | | | | |<------| + +---+---+---+---+---+---+---+---+ + +-- CC_PWM_Active + +---+---+---+---+---+---+---+---+ + 1 |------------------------------x| + +---+---+---+---+---+---+---+---+ + +-- CC_TargetDutyCycle + +---+---+---+---+---+---+---+---+ + 2 | | | | | |<-x|<-x|<-x| + B +---+---+---+---+---+---+---+---+ + y | | +-- CC_Contactor1State + t | +-- CC_Contactor2State + e +-- CC_Contactor3State + +---+---+---+---+---+---+---+---+ + 3 | | | | | | | | | + +---+---+---+---+---+---+---+---+ + 4 | | | | | | | | | + +---+---+---+---+---+---+---+---+ + 5 | | | | | | | | | + +---+---+---+---+---+---+---+---+ + 6 | | | | | | | | | + +---+---+---+---+---+---+---+---+ + 7 | | | | | | | | | + +---+---+---+---+---+---+---+---+ + + ChargeState1 ^^^^^^^^^^^^ @@ -347,25 +358,50 @@ ChargeState1 :: - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 0| CS_PWM_Active | | | | CS_SafeStateActive | |CS_CurrentDutyCycle | | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 1| | | | | | | | | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 2| | | | CS_DiodeFault | CS_CpShortCircuit | CS_CurrentCpState | | | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 3| | | | | | CS_CurrentPpState | | | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 4| | CS_HV_Ready | CS_Contactor3State | | CS_Contactor2State | | CS_Contactor1State | | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 5| | |CS_Estop3ChargingAbo| |CS_Estop2ChargingAbo| |CS_Estop1ChargingAbo| | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 6| CS_SafeStateReason | | | | | | | | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 7| | | | | | | | | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ + Bit + + 7 6 5 4 3 2 1 0 + +---+---+---+---+---+---+---+---+ + 0 |<-x| | | |<-----x|<------| + +---+---+---+---+---+---+---+---+ + | +-- CS_SafeStateActive + +-- CS_PWM_Active + +---+---+---+---+---+---+---+---+ + 1 |------------------------------x| + +---+---+---+---+---+---+---+---+ + +-- CS_CurrentDutyCycle + +---+---+---+---+---+---+---+---+ + 2 | | | |<-x|<-x|<---------x| + +---+---+---+---+---+---+---+---+ + | | +-- CS_CurrentCpState + | +-- CS_CpShortCircuit + +-- CS_DiodeFault + +---+---+---+---+---+---+---+---+ + 3 | | | | | |<---------x| + B +---+---+---+---+---+---+---+---+ + y +-- CS_CurrentPpState + t +---+---+---+---+---+---+---+---+ + e 4 | |<-x|<-----x|<-----x|<-----x| + +---+---+---+---+---+---+---+---+ + | | | +-- CS_Contactor1State + | | +-- CS_Contactor2State + | +-- CS_Contactor3State + +-- CS_HV_Ready + +---+---+---+---+---+---+---+---+ + 5 | | |<-----x|<-----x|<-----x| + +---+---+---+---+---+---+---+---+ + | | +-- CS_Estop1ChargingAbort + | +-- CS_Estop2ChargingAbort + +-- CS_Estop3ChargingAbort + +---+---+---+---+---+---+---+---+ + 6 |<-----------------------------x| + +---+---+---+---+---+---+---+---+ + +-- CS_SafeStateReason + +---+---+---+---+---+---+---+---+ + 7 | | | | | | | | | + +---+---+---+---+---+---+---+---+ + + PT1000State ^^^^^^^^^^^ @@ -522,25 +558,43 @@ PT1000State :: - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 0| PT1_Temperature | | | | | | | | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 1| PT2_Temperature | | | | | | PT1_SelftestFailed |PT1_ChargingStopped | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 2| PT2_Temperature | | | | | | | | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 3| PT3_Temperature | | | | | | PT2_SelftestFailed |PT2_ChargingStopped | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 4| PT3_Temperature | | | | | | | | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 5| PT4_Temperature | | | | | | PT3_SelftestFailed |PT3_ChargingStopped | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 6| PT4_Temperature | | | | | | | | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 7| | | | | | | PT4_SelftestFailed |PT4_ChargingStopped | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ + Bit + + 7 6 5 4 3 2 1 0 + +---+---+---+---+---+---+---+---+ + 0 |<------------------------------| + +---+---+---+---+---+---+---+---+ + 1 |----------------------x|<-x|<-x| + +---+---+---+---+---+---+---+---+ + | | +-- PT1_ChargingStopped + | +-- PT1_SelftestFailed + +-- PT1_Temperature + +---+---+---+---+---+---+---+---+ + 2 |<------------------------------| + +---+---+---+---+---+---+---+---+ + 3 |----------------------x|<-x|<-x| + +---+---+---+---+---+---+---+---+ + | | +-- PT2_ChargingStopped + B | +-- PT2_SelftestFailed + y +-- PT2_Temperature + t +---+---+---+---+---+---+---+---+ + e 4 |<------------------------------| + +---+---+---+---+---+---+---+---+ + 5 |----------------------x|<-x|<-x| + +---+---+---+---+---+---+---+---+ + | | +-- PT3_ChargingStopped + | +-- PT3_SelftestFailed + +-- PT3_Temperature + +---+---+---+---+---+---+---+---+ + 6 |<------------------------------| + +---+---+---+---+---+---+---+---+ + 7 |----------------------x|<-x|<-x| + +---+---+---+---+---+---+---+---+ + | | +-- PT4_ChargingStopped + | +-- PT4_SelftestFailed + +-- PT4_Temperature + + FirmwareVersion ^^^^^^^^^^^^^^^ @@ -638,25 +692,40 @@ FirmwareVersion :: - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 0| MajorVersion | | | | | | | | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 1| MinorVersion | | | | | | | | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 2| BuildVersion | | | | | | | | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 3| PlatformType | | | | | | | | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 4| ParameterVersion | | | | | | | | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 5| ParameterVersion | | | | | | | | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 6| | | | | | | | | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 7| | | | | | | | | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ + Bit + + 7 6 5 4 3 2 1 0 + +---+---+---+---+---+---+---+---+ + 0 |<-----------------------------x| + +---+---+---+---+---+---+---+---+ + +-- MajorVersion + +---+---+---+---+---+---+---+---+ + 1 |<-----------------------------x| + +---+---+---+---+---+---+---+---+ + +-- MinorVersion + +---+---+---+---+---+---+---+---+ + 2 |<-----------------------------x| + +---+---+---+---+---+---+---+---+ + +-- BuildVersion + B +---+---+---+---+---+---+---+---+ + y 3 |<-----------------------------x| + t +---+---+---+---+---+---+---+---+ + e +-- PlatformType + +---+---+---+---+---+---+---+---+ + 4 |<-----------------------------x| + +---+---+---+---+---+---+---+---+ + +-- ApplicationType + +---+---+---+---+---+---+---+---+ + 5 |<------------------------------| + +---+---+---+---+---+---+---+---+ + 6 |------------------------------x| + +---+---+---+---+---+---+---+---+ + +-- ParameterVersion + +---+---+---+---+---+---+---+---+ + 7 | | | | | | | | | + +---+---+---+---+---+---+---+---+ + + GitHash ^^^^^^^ @@ -696,25 +765,29 @@ GitHash :: - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 0| HashSignal | | | | | | | | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 1| | | | | | | | | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 2| | | | | | | | | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 3| | | | | | | | | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 4| | | | | | | | | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 5| | | | | | | | | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 6| | | | | | | | | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 7| | | | | | | | | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ + Bit + + 7 6 5 4 3 2 1 0 + +---+---+---+---+---+---+---+---+ + 0 |<------------------------------| + +---+---+---+---+---+---+---+---+ + 1 |-------------------------------| + +---+---+---+---+---+---+---+---+ + 2 |-------------------------------| + +---+---+---+---+---+---+---+---+ + B 3 |-------------------------------| + y +---+---+---+---+---+---+---+---+ + t 4 |-------------------------------| + e +---+---+---+---+---+---+---+---+ + 5 |-------------------------------| + +---+---+---+---+---+---+---+---+ + 6 |-------------------------------| + +---+---+---+---+---+---+---+---+ + 7 |------------------------------x| + +---+---+---+---+---+---+---+---+ + +-- HashSignal + + InquiryPacket ^^^^^^^^^^^^^ @@ -761,23 +834,28 @@ InquiryPacket :: - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 0| PacketId | | | | | | | | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 1| | | | | | | | | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 2| | | | | | | | | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 3| | | | | | | | | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 4| | | | | | | | | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 5| | | | | | | | | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 6| | | | | | | | | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ - 7| | | | | | | | | - +--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+--------------------+ + Bit + + 7 6 5 4 3 2 1 0 + +---+---+---+---+---+---+---+---+ + 0 |<-----------------------------x| + +---+---+---+---+---+---+---+---+ + +-- PacketId + +---+---+---+---+---+---+---+---+ + 1 | | | | | | | | | + +---+---+---+---+---+---+---+---+ + B 2 | | | | | | | | | + y +---+---+---+---+---+---+---+---+ + t 3 | | | | | | | | | + e +---+---+---+---+---+---+---+---+ + 4 | | | | | | | | | + +---+---+---+---+---+---+---+---+ + 5 | | | | | | | | | + +---+---+---+---+---+---+---+---+ + 6 | | | | | | | | | + +---+---+---+---+---+---+---+---+ + 7 | | | | | | | | | + +---+---+---+---+---+---+---+---+ + + diff --git a/docs/source/utils/.gitignore b/docs/source/utils/.gitignore new file mode 100644 index 0000000..bee8a64 --- /dev/null +++ b/docs/source/utils/.gitignore @@ -0,0 +1 @@ +__pycache__ diff --git a/docs/source/utils/dbc_to_rst.py b/docs/source/utils/dbc_to_rst.py index a5613af..0d0829a 100644 --- a/docs/source/utils/dbc_to_rst.py +++ b/docs/source/utils/dbc_to_rst.py @@ -1,20 +1,10 @@ import cantools +from cantools.subparsers.dump import formatting +from dbc_to_rst_config import * # Load the DBC file db = cantools.database.load_file("uart_com.dbc") -# Messages you want to document -target_msgs = ["ChargeControl1", "ChargeState1", "PT1000State", "FirmwareVersion", "GitHash", "InquiryPacket"] - -# Sender name mapping -sender_name_map = { - "Default_SafetyController": "Safety Controller", - "Default_Linux": "Linux Processor" -} - -# Senders to exclude from display -excluded_senders = {"CCY_SafetyController"} - # Extract a signal row as a list of strings def signal_row(signal): def safe(value): @@ -42,50 +32,14 @@ def safe(value): ] def format_bit_matrix(msg): - bit_width = 20 - byte_label_width = 3 - bitfield = [None] * (msg.length * 8) - - for signal in msg.signals: - if signal.byte_order == "little_endian": - bit_indices = list(range(signal.start, signal.start + signal.length)) - else: - bit_indices = list(range(signal.start, signal.start - signal.length, -1)) - - for idx in bit_indices: - if 0 <= idx < len(bitfield): - bitfield[idx] = signal.name - - total_bits = msg.length * 8 - num_rows = total_bits // 8 - lines = [] - - # Header with byte index - border = " +" + "+".join(["-" * bit_width] * 8) + "+" - header = " |" + "|".join([f"{7 - i:^{bit_width}}" for i in range(8)]) + "|" - lines.extend([border, header, border]) - - for row in range(num_rows): - base = row * 8 - seen = set() - row_cells = [] - for i in range(8): - bit_index = base + (7 - i) - label = bitfield[bit_index] - if label and label not in seen: - cell = label[:bit_width].center(bit_width) - seen.add(label) - else: - cell = " " * bit_width - row_cells.append(cell) - lines.append(f"{row:>3}|" + "|".join(row_cells) + "|") - lines.append(border) - rst = "\n**Bitfield Layout**\n\n::\n\n" - rst += "\n".join(lines) + "\n" + rst += '\n'.join([ + (' ' + line).rstrip() + for line in formatting.layout_string(msg).splitlines() + ]) + rst += "\n\n\n" return rst - # Format one message block as RST def format_message_rst(msg): rst = f"{msg.name}\n{'^' * len(msg.name)}\n\n" diff --git a/docs/source/utils/dbc_to_rst_config.py b/docs/source/utils/dbc_to_rst_config.py new file mode 100644 index 0000000..d29b6fd --- /dev/null +++ b/docs/source/utils/dbc_to_rst_config.py @@ -0,0 +1,11 @@ +# Messages you want to document +target_msgs = ["ChargeControl1", "ChargeState1", "PT1000State", "FirmwareVersion", "GitHash", "InquiryPacket"] + +# Sender name mapping +sender_name_map = { + "Default_SafetyController": "Safety Controller", + "Default_Linux": "Linux Processor" +} + +# Senders to exclude from display +excluded_senders = {"CCY_SafetyController"}