firmware/controllers/can/wideband_firmware/for_rusefi/wideband_can.h
| Line | Branch | Decision | Exec | Source |
|---|---|---|---|---|
| 1 | #pragma once | |||
| 2 | ||||
| 3 | #define RUSEFI_WIDEBAND_VERSION (0xA0) | |||
| 4 | ||||
| 5 | // ascii "rus" | |||
| 6 | #define WB_ACK 0x727573 | |||
| 7 | ||||
| 8 | #define WB_BL_HEADER 0x0EF | |||
| 9 | #define WB_OPCODE_START 0 | |||
| 10 | #define WB_OPCODE_ERASE 1 | |||
| 11 | #define WB_ERASE_TAG 0x5A5A | |||
| 12 | #define WB_OPCODE_DATA 2 | |||
| 13 | #define WB_OPCODE_REBOOT 3 | |||
| 14 | #define WB_OPCODE_SET_INDEX 4 | |||
| 15 | #define WB_OPCODE_ECU_STATUS 5 | |||
| 16 | #define WB_OPCODE_PING 6 | |||
| 17 | #define WB_OPCODE_SET_SENS_TYPE 7 | |||
| 18 | ||||
| 19 | #define WB_BL_BASE (WB_BL_HEADER << 4) | |||
| 20 | #define WB_BL_CMD(opcode, extra) (((WB_BL_BASE | (opcode)) << 16) | (extra)) | |||
| 21 | ||||
| 22 | #define WB_BL_CMD_MASK 0X0FFF0000 | |||
| 23 | ||||
| 24 | #define WB_MSG_GET_HEADER(id) (((id) >> 20) & 0XFFF) | |||
| 25 | #define WB_MSG_GET_OPCODE(id) (((id) >> 16) & 0XF) | |||
| 26 | #define WB_MSG_GET_EXTRA(id) ((id) & 0XFFFF) | |||
| 27 | ||||
| 28 | // 0xEF0'0000 | |||
| 29 | #define WB_BL_ENTER WB_BL_CMD(WB_OPCODE_START, 0) | |||
| 30 | // 0xEF1'5A5A | |||
| 31 | #define WB_BL_ERASE WB_BL_CMD(WB_OPCODE_ERASE, WB_ERASE_TAG) | |||
| 32 | // 0xEF2'0000 | |||
| 33 | #define WB_BL_DATA_BASE WB_BL_CMD(WB_OPCODE_DATA, 0) | |||
| 34 | // 0xEF3'0000 | |||
| 35 | #define WB_BL_REBOOT WB_BL_CMD(WB_OPCODE_REBOOT, 0) | |||
| 36 | // 0xEF4'0000 | |||
| 37 | #define WB_MSG_SET_INDEX WB_BL_CMD(WB_OPCODE_SET_INDEX, 0) | |||
| 38 | // 0xEF5'0000 | |||
| 39 | #define WB_MSG_ECU_STATUS WB_BL_CMD(WB_OPCODE_ECU_STATUS, 0) | |||
| 40 | // 0xEF6'0000 | |||
| 41 | #define WB_MSG_PING WB_BL_CMD(WB_OPCODE_PING, 0) | |||
| 42 | // 0xEF7'0000 | |||
| 43 | #define WB_MSG_SET_SENS_TYPE WB_BL_CMD(WB_OPCODE_SET_SENS_TYPE, 0) | |||
| 44 | ||||
| 45 | #define WB_DATA_BASE_ADDR 0x190 | |||
| 46 | ||||
| 47 | // we transmit every 10ms | |||
| 48 | #define WBO_TX_PERIOD_MS 10 | |||
| 49 | ||||
| 50 | namespace wbo | |||
| 51 | { | |||
| 52 | enum class Status : uint8_t | |||
| 53 | { | |||
| 54 | Preheat = 0, | |||
| 55 | Warmup = 1, | |||
| 56 | RunningClosedLoop = 2, | |||
| 57 | ||||
| 58 | // First fault code at 3 so it's easier to see blink code | |||
| 59 | FirstError = 3, | |||
| 60 | SensorDidntHeat = 3, | |||
| 61 | SensorOverheat = 4, | |||
| 62 | SensorUnderheat = 5, | |||
| 63 | LastError = 5, | |||
| 64 | ||||
| 65 | // Heating is not allowed | |||
| 66 | NotAllowed = 6, | |||
| 67 | // No CAN communication | |||
| 68 | CanSilent = 7, | |||
| 69 | }; | |||
| 70 | ||||
| 71 | 4 | static inline bool isStatusError(Status s) { | ||
| 72 |
3/4✓ Branch 0 taken 1 time.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
|
4 | return ((s >= Status::FirstError) && | |
| 73 | 4 | (s <= Status::LastError)); | ||
| 74 | } | |||
| 75 | ||||
| 76 | enum class SensorType : uint8_t { | |||
| 77 | LSU49 = 0, | |||
| 78 | LSU42 = 1, | |||
| 79 | LSUADV = 2, | |||
| 80 | LSU49_FAE = 3, | |||
| 81 | }; | |||
| 82 | ||||
| 83 | struct StandardData | |||
| 84 | { | |||
| 85 | // DO NOT move the version field - its position and format must be | |||
| 86 | // fixed so that incompatible versions can be identified. | |||
| 87 | uint8_t Version; | |||
| 88 | uint8_t Valid; | |||
| 89 | ||||
| 90 | uint16_t Lambda; | |||
| 91 | uint16_t TemperatureC; | |||
| 92 | ||||
| 93 | uint16_t pad; | |||
| 94 | }; | |||
| 95 | ||||
| 96 | struct DiagData | |||
| 97 | { | |||
| 98 | uint16_t Esr; | |||
| 99 | uint16_t NernstDc; | |||
| 100 | uint8_t PumpDuty; | |||
| 101 | Status status; | |||
| 102 | ||||
| 103 | uint8_t HeaterDuty; | |||
| 104 | uint8_t pad; | |||
| 105 | }; | |||
| 106 | ||||
| 107 | struct PongData | |||
| 108 | { | |||
| 109 | uint8_t hwId; | |||
| 110 | uint8_t Version; | |||
| 111 | ||||
| 112 | // FW build date | |||
| 113 | uint8_t year; // starting from 2000 | |||
| 114 | uint8_t month; | |||
| 115 | uint8_t day; | |||
| 116 | ||||
| 117 | uint8_t reserved[3]; | |||
| 118 | }; | |||
| 119 | ||||
| 120 | 1 | static inline const char* describeStatus(Status status) { | ||
| 121 |
1/9✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 time.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
|
1 | switch (status) { | |
| 122 | ✗ | case Status::Preheat: | ||
| 123 | ✗ | return "Preheat (waiting)"; | ||
| 124 | ✗ | case Status::Warmup: | ||
| 125 | ✗ | return "Warming up"; | ||
| 126 | ✗ | case Status::RunningClosedLoop: | ||
| 127 | ✗ | return "Running"; | ||
| 128 | ✗ | case Status::SensorDidntHeat: | ||
| 129 | ✗ | return "Sensor failed to heat"; | ||
| 130 | ✗ | case Status::SensorOverheat: | ||
| 131 | ✗ | return "Sensor overheat"; | ||
| 132 |
1/1✓ Decision 'true' taken 1 time.
|
1 | case Status::SensorUnderheat: | |
| 133 | 1 | return "Sensor underheat"; | ||
| 134 | ✗ | case Status::NotAllowed: | ||
| 135 | ✗ | return "Heating not allowed"; | ||
| 136 | ✗ | case Status::CanSilent: | ||
| 137 | ✗ | return "CAN silent"; | ||
| 138 | } | |||
| 139 | ||||
| 140 | ✗ | return "Unknown"; | ||
| 141 | } | |||
| 142 | ||||
| 143 | } // namespace wbo | |||
| 144 |