From 683a723d2fa86ad31e598ab562ec274528cdc1cf Mon Sep 17 00:00:00 2001 From: rusefillc <48498823+rusefillc@users.noreply.github.com> Date: Mon, 9 May 2022 16:49:23 -0400 Subject: [PATCH] CAN category (#4148) Co-authored-by: rusefillc --- firmware/console/binary/serial_can.cpp | 2 +- firmware/controllers/can/can_dash.cpp | 160 +++++++++---------- firmware/controllers/can/can_verbose.cpp | 14 +- firmware/controllers/can/obd2.cpp | 2 +- firmware/controllers/can/rusefi_wideband.cpp | 12 +- firmware/controllers/lua/lua_hooks.cpp | 2 +- firmware/controllers/sensors/can_sensor.h | 2 +- firmware/hw_layer/drivers/can/can_msg_tx.cpp | 2 +- firmware/hw_layer/drivers/can/can_msg_tx.h | 18 ++- 9 files changed, 112 insertions(+), 102 deletions(-) diff --git a/firmware/console/binary/serial_can.cpp b/firmware/console/binary/serial_can.cpp index 8504e1434e..bce7a1bf0d 100644 --- a/firmware/console/binary/serial_can.cpp +++ b/firmware/console/binary/serial_can.cpp @@ -40,7 +40,7 @@ static CanTsListener listener; int CanStreamerState::sendFrame(const IsoTpFrameHeader & header, const uint8_t *data, int num, can_sysinterval_t timeout) { int dlc = 8; // standard 8 bytes - CanTxMessage txmsg(CAN_ECU_SERIAL_TX_ID, dlc, false); + CanTxMessage txmsg(CanCategory::SERIAL, CAN_ECU_SERIAL_TX_ID, dlc, false); // fill the frame data according to the CAN-TP protocol (ISO 15765-2) txmsg[0] = (uint8_t)((header.frameType & 0xf) << 4); diff --git a/firmware/controllers/can/can_dash.cpp b/firmware/controllers/can/can_dash.cpp index ef6a0c88ef..08eb862640 100644 --- a/firmware/controllers/can/can_dash.cpp +++ b/firmware/controllers/can/can_dash.cpp @@ -143,17 +143,17 @@ void canDashboardBMW(CanCycle cycle) { if (cycle.isInterval(CI::_50ms)) { { - CanTxMessage msg(CAN_BMW_E46_SPEED); + CanTxMessage msg(CanCategory::NBC, CAN_BMW_E46_SPEED); msg.setShortValue(10 * 8, 1); } { - CanTxMessage msg(CAN_BMW_E46_RPM); + CanTxMessage msg(CanCategory::NBC, CAN_BMW_E46_RPM); msg.setShortValue((int) (Sensor::getOrZero(SensorType::Rpm) * 6.4), 2); } { - CanTxMessage msg(CAN_BMW_E46_DME2); + CanTxMessage msg(CanCategory::NBC, CAN_BMW_E46_DME2); msg.setShortValue((int) ((Sensor::getOrZero(SensorType::Clt) + 48.373) / 0.75), 1); } } @@ -163,12 +163,12 @@ void canDashboardBMW(CanCycle cycle) { void canMazdaRX8(CanCycle cycle) { if (cycle.isInterval(CI::_50ms)) { { - CanTxMessage msg(CAN_MAZDA_RX_STEERING_WARNING); + CanTxMessage msg(CanCategory::NBC, CAN_MAZDA_RX_STEERING_WARNING); // todo: something needs to be set here? see http://rusefi.com/wiki/index.php?title=Vehicle:Mazda_Rx8_2004 } { - CanTxMessage msg(CAN_MAZDA_RX_RPM_SPEED); + CanTxMessage msg(CanCategory::NBC, CAN_MAZDA_RX_RPM_SPEED); float kph = Sensor::getOrZero(SensorType::VehicleSpeed); @@ -179,7 +179,7 @@ void canMazdaRX8(CanCycle cycle) { } { - CanTxMessage msg(CAN_MAZDA_RX_STATUS_1); + CanTxMessage msg(CanCategory::NBC, CAN_MAZDA_RX_STATUS_1); msg[0] = 0xFE; //Unknown msg[1] = 0xFE; //Unknown msg[2] = 0xFE; //Unknown @@ -191,7 +191,7 @@ void canMazdaRX8(CanCycle cycle) { } { - CanTxMessage msg(CAN_MAZDA_RX_STATUS_2); + CanTxMessage msg(CanCategory::NBC, CAN_MAZDA_RX_STATUS_2); auto clt = Sensor::get(SensorType::Clt); msg[0] = (uint8_t)(clt.value_or(0) + 69); //temp gauge //~170 is red, ~165 last bar, 152 centre, 90 first bar, 92 second bar // TODO: fixme! @@ -220,7 +220,7 @@ void canDashboardFiat(CanCycle cycle) { if (cycle.isInterval(CI::_50ms)) { { //Fiat Dashboard - CanTxMessage msg(CAN_FIAT_MOTOR_INFO); + CanTxMessage msg(CanCategory::NBC, CAN_FIAT_MOTOR_INFO); msg.setShortValue((int) (Sensor::getOrZero(SensorType::Clt) - 40), 3); //Coolant Temp msg.setShortValue(Sensor::getOrZero(SensorType::Rpm) / 32, 6); //RPM } @@ -231,24 +231,24 @@ void canDashboardVAG(CanCycle cycle) { if (cycle.isInterval(CI::_10ms)) { { //VAG Dashboard - CanTxMessage msg(CAN_VAG_Motor_1); + CanTxMessage msg(CanCategory::NBC, CAN_VAG_Motor_1); msg.setShortValue(Sensor::getOrZero(SensorType::Rpm) * 4, 2); //RPM } float clt = Sensor::getOrZero(SensorType::Clt); { - CanTxMessage msg(CAN_VAG_Motor_2); + CanTxMessage msg(CanCategory::NBC, CAN_VAG_Motor_2); msg.setShortValue((int) ((clt + 48.373) / 0.75), 1); //Coolant Temp } { - CanTxMessage msg(CAN_VAG_CLT_V2); + CanTxMessage msg(CanCategory::NBC, CAN_VAG_CLT_V2); msg.setShortValue((int) ((clt + 48.373) / 0.75), 4); //Coolant Temp } { - CanTxMessage msg(CAN_VAG_IMMO); + CanTxMessage msg(CanCategory::NBC, CAN_VAG_IMMO); msg.setShortValue(0x80, 1); } } @@ -257,7 +257,7 @@ void canDashboardVAG(CanCycle cycle) { void canDashboardW202(CanCycle cycle) { if (cycle.isInterval(CI::_20ms)) { { - CanTxMessage msg(W202_STAT_1); + CanTxMessage msg(CanCategory::NBC, W202_STAT_1); uint16_t tmp = Sensor::getOrZero(SensorType::Rpm); msg[0] = 0x08; // Unknown msg[1] = (tmp >> 8); //RPM @@ -272,7 +272,7 @@ void canDashboardW202(CanCycle cycle) { if (cycle.isInterval(CI::_100ms)) { { - CanTxMessage msg(W202_STAT_2); //dlc 7 + CanTxMessage msg(CanCategory::NBC, W202_STAT_2); //dlc 7 msg[0] = (int)(Sensor::getOrZero(SensorType::Clt) + 40); // CLT -40 offset msg[1] = 0x3D; // TBD msg[2] = 0x63; // Const @@ -286,7 +286,7 @@ void canDashboardW202(CanCycle cycle) { if (cycle.isInterval(CI::_200ms)) { { - CanTxMessage msg(W202_ALIVE); + CanTxMessage msg(CanCategory::NBC, W202_ALIVE); msg[0] = 0x0A; // Const msg[1] = 0x18; // Const msg[2] = 0x00; // Const @@ -298,7 +298,7 @@ void canDashboardW202(CanCycle cycle) { } { - CanTxMessage msg(W202_STAT_3); + CanTxMessage msg(CanCategory::NBC, W202_STAT_3); msg[0] = 0x00; // Const msg[1] = 0x00; // Const msg[2] = 0x6D; // TBD @@ -316,13 +316,13 @@ static int rollingId = 0; void canDashboardGenesisCoupe(CanCycle cycle) { if (cycle.isInterval(CI::_50ms)) { { - CanTxMessage msg(GENESIS_COUPLE_RPM_316, 8); + CanTxMessage msg(CanCategory::NBC, GENESIS_COUPLE_RPM_316, 8); int rpm8 = Sensor::getOrZero(SensorType::Rpm) * 4; msg[3] = rpm8 >> 8; msg[4] = rpm8 & 0xFF; } { - CanTxMessage msg(GENESIS_COUPLE_COOLANT_329, 8); + CanTxMessage msg(CanCategory::NBC, GENESIS_COUPLE_COOLANT_329, 8); int clt = Sensor::getOrZero(SensorType::Clt) * 2; msg[1] = clt; } @@ -332,7 +332,7 @@ void canDashboardGenesisCoupe(CanCycle cycle) { void canDashboardNissanVQ(CanCycle cycle) { if (cycle.isInterval(CI::_50ms)) { { - CanTxMessage msg(NISSAN_RPM_1F9, 8); + CanTxMessage msg(CanCategory::NBC, NISSAN_RPM_1F9, 8); msg[0] = 0x20; int rpm8 = (int)(Sensor::getOrZero(SensorType::Rpm) * 8); msg[2] = rpm8 >> 8; @@ -340,7 +340,7 @@ void canDashboardNissanVQ(CanCycle cycle) { } { - CanTxMessage msg(NISSAN_CLT_551, 8); + CanTxMessage msg(CanCategory::OBD, NISSAN_CLT_551, 8); int clt = Sensor::getOrZero(SensorType::Clt); msg[0] = clt + 45; @@ -348,7 +348,7 @@ void canDashboardNissanVQ(CanCycle cycle) { { - CanTxMessage msg(NISSAN_RPM_CLT, 8); + CanTxMessage msg(CanCategory::NBC, NISSAN_RPM_CLT, 8); rollingId = (rollingId + 1) % 4; const uint8_t magicByte[4] = {0x03, 0x23, 0x42, 0x63}; @@ -374,13 +374,13 @@ void canDashboardVagMqb(CanCycle cycle) { if (cycle.isInterval(CI::_50ms)) { { // 'turn-on' - CanTxMessage msg(0x3C0, 4); + CanTxMessage msg(CanCategory::NBC, 0x3C0, 4); // ignition ON msg[2] = 3; } { //RPM - CanTxMessage msg(0x107, 8); + CanTxMessage msg(CanCategory::NBC, 0x107, 8); msg[3] = ((int)(Sensor::getOrZero(SensorType::Rpm) / 3.5)) & 0xFF; msg[4] = ((int)(Sensor::getOrZero(SensorType::Rpm) / 3.5)) >> 8; } @@ -393,7 +393,7 @@ void canDashboardBMWE90(CanCycle cycle) if (cycle.isInterval(CI::_50ms)) { { //T15 'turn-on' - CanTxMessage msg(E90_T15, 5); + CanTxMessage msg(CanCategory::NBC, E90_T15, 5); msg[0] = 0x45; msg[1] = 0x41; msg[2] = 0x61; @@ -402,7 +402,7 @@ void canDashboardBMWE90(CanCycle cycle) } { //Ebrake light - CanTxMessage msg(E90_EBRAKE, 2); + CanTxMessage msg(CanCategory::OBD, E90_EBRAKE, 2); msg[0] = 0xFD; msg[1] = 0xFF; } @@ -411,7 +411,7 @@ void canDashboardBMWE90(CanCycle cycle) rpmcounter++; if (rpmcounter > 0xFE) rpmcounter = 0xF0; - CanTxMessage msg(E90_RPM, 3); + CanTxMessage msg(CanCategory::OBD, E90_RPM, 3); msg[0] = rpmcounter; msg[1] = ((int)(Sensor::getOrZero(SensorType::Rpm)) * 4) & 0xFF; msg[2] = ((int)(Sensor::getOrZero(SensorType::Rpm)) * 4) >> 8; @@ -421,7 +421,7 @@ void canDashboardBMWE90(CanCycle cycle) tmp_cnt++; if (tmp_cnt >= 0x0F) tmp_cnt = 0x00; - CanTxMessage msg(E90_TEMP, 8); + CanTxMessage msg(CanCategory::OBD, E90_TEMP, 8); msg[0] = (int)(Sensor::getOrZero(SensorType::Clt) + e90_temp_offset); //coolant msg[1] = (int)(Sensor::getOrZero(SensorType::AuxTemp1) + e90_temp_offset); //oil (AuxTemp1) msg[2] = tmp_cnt; @@ -439,7 +439,7 @@ void canDashboardBMWE90(CanCycle cycle) seatbeltcnt++; if (seatbeltcnt > 0xFE) seatbeltcnt = 0x00; - CanTxMessage msg(E90_SEATBELT_COUNTER, 2); + CanTxMessage msg(CanCategory::NBC, E90_SEATBELT_COUNTER, 2); msg[0] = seatbeltcnt; msg[1] = 0xFF; } @@ -452,7 +452,7 @@ void canDashboardBMWE90(CanCycle cycle) brakecnt_1 = 0x0F; if (brakecnt_2 > 0xF0) brakecnt_2 = 0xA0; - CanTxMessage msg(E90_BRAKE_COUNTER, 8); + CanTxMessage msg(CanCategory::NBC, E90_BRAKE_COUNTER, 8); msg[0] = 0x00; msg[1] = 0xE0; msg[2] = brakecnt_1; @@ -467,13 +467,13 @@ void canDashboardBMWE90(CanCycle cycle) abscounter++; if (abscounter > 0xFE) abscounter = 0xF0; - CanTxMessage msg(E90_ABS_COUNTER, 2); + CanTxMessage msg(CanCategory::NBC, E90_ABS_COUNTER, 2); msg[0] = abscounter; msg[1] = 0xFF; } { //Fuel gauge - CanTxMessage msg(E90_FUEL, 5); //fuel gauge + CanTxMessage msg(CanCategory::NBC, E90_FUEL, 5); //fuel gauge msg[0] = 0x76; msg[1] = 0x0F; msg[2] = 0xBE; @@ -485,7 +485,7 @@ void canDashboardBMWE90(CanCycle cycle) gear_cnt++; if (gear_cnt >= 0x0F) gear_cnt = 0x00; - CanTxMessage msg(E90_GEAR, 6); + CanTxMessage msg(CanCategory::NBC, E90_GEAR, 6); msg[0] = 0x78; msg[1] = 0x0F; msg[2] = 0xFF; @@ -505,7 +505,7 @@ void canDashboardBMWE90(CanCycle cycle) if(mph_counter >= 0xFFF0) mph_counter = 0xF000; mph_timer = TIME_I2MS(chVTGetSystemTime()); - CanTxMessage msg(E90_SPEED, 8); + CanTxMessage msg(CanCategory::NBC, E90_SPEED, 8); msg[0] = mph_2a & 0xFF; msg[1] = mph_2a >> 8; msg[2] = mph_2a & 0xFF; @@ -521,7 +521,7 @@ void canDashboardBMWE90(CanCycle cycle) if (!cluster_time_set) { struct tm timp; date_get_tm(&timp); - CanTxMessage msg(E90_TIME, 8); + CanTxMessage msg(CanCategory::NBC, E90_TIME, 8); msg[0] = timp.tm_hour; msg[1] = timp.tm_min; msg[2] = timp.tm_sec; @@ -542,7 +542,7 @@ void canDashboardHaltech(CanCycle cycle) { if (cycle.isInterval(CI::_20ms)) { /* 0x360 - 50Hz rate */ { - CanTxMessage msg(0x360, 8); + CanTxMessage msg(CanCategory::NBC, 0x360, 8); tmp = Sensor::getOrZero(SensorType::Rpm); /* RPM */ msg[0] = (tmp >> 8); @@ -562,7 +562,7 @@ void canDashboardHaltech(CanCycle cycle) { /* 0x361 - 50Hz rate */ { - CanTxMessage msg(0x361, 8); + CanTxMessage msg(CanCategory::NBC, 0x361, 8); /* Fuel pressure */ tmp = (uint16_t)(Sensor::getOrZero(SensorType::FuelPressureLow)); msg[0] = (tmp >> 8); @@ -582,7 +582,7 @@ void canDashboardHaltech(CanCycle cycle) { /* 0x362 - 50Hz rate */ { - CanTxMessage msg(0x362, 6); + CanTxMessage msg(CanCategory::NBC, 0x362, 6); /* Injection Stage 1 Duty Cycle - y = x/10 */ uint16_t rpm = Sensor::getOrZero(SensorType::Rpm); tmp = (uint16_t)( getInjectorDutyCycle(rpm) * 10) ; @@ -600,7 +600,7 @@ void canDashboardHaltech(CanCycle cycle) { /* todo: 0x3E5 = 50Hz rate */ { - CanTxMessage msg(0x3E5, 8); + CanTxMessage msg(CanCategory::NBC, 0x3E5, 8); msg[0] = 0x00; msg[1] = 0x00; msg[2] = 0x00; @@ -613,7 +613,7 @@ void canDashboardHaltech(CanCycle cycle) { /* todo: 0x3EA = 50Hz rate */ { - CanTxMessage msg(0x3EA, 8); + CanTxMessage msg(CanCategory::NBC, 0x3EA, 8); msg[0] = 0x00; msg[1] = 0x00; msg[2] = 0x00; @@ -626,7 +626,7 @@ void canDashboardHaltech(CanCycle cycle) { /* todo: 0x3EB = 50Hz rate */ { - CanTxMessage msg(0x3EB, 8); + CanTxMessage msg(CanCategory::NBC, 0x3EB, 8); msg[0] = 0x00; msg[1] = 0x00; msg[2] = 0x00; @@ -639,7 +639,7 @@ void canDashboardHaltech(CanCycle cycle) { /* todo: 0x3EC = 50Hz rate */ { - CanTxMessage msg(0x3EC, 8); + CanTxMessage msg(CanCategory::NBC, 0x3EC, 8); msg[0] = 0x00; msg[1] = 0x00; msg[2] = 0x00; @@ -652,14 +652,14 @@ void canDashboardHaltech(CanCycle cycle) { /* todo: 0x3ED = 50Hz rate */ { - CanTxMessage msg(0x3ED, 2); + CanTxMessage msg(CanCategory::NBC, 0x3ED, 2); msg[0] = 0x00; msg[1] = 0x00; } /* todo: 0x471 = 50Hz rate */ { - CanTxMessage msg(0x471, 2); + CanTxMessage msg(CanCategory::NBC, 0x471, 2); msg[0] = 0x00; msg[1] = 0x00; msg[2] = 0x00; @@ -671,7 +671,7 @@ void canDashboardHaltech(CanCycle cycle) { /* 0x363 - 20Hz rate */ { - CanTxMessage msg(0x363, 4); + CanTxMessage msg(CanCategory::NBC, 0x363, 4); /* Wheel Slip */ msg[0] = 0x00; msg[1] = 0x00; @@ -682,7 +682,7 @@ void canDashboardHaltech(CanCycle cycle) { /* 0x368 - 20Hz rate */ { - CanTxMessage msg(0x368, 8); + CanTxMessage msg(CanCategory::NBC, 0x368, 8); /* Wideband Sensor 1 */ tmp = (uint16_t)(Sensor::getOrZero(SensorType::Lambda1)) * 1000; msg[0] = (tmp >> 8); @@ -702,7 +702,7 @@ void canDashboardHaltech(CanCycle cycle) { #if EFI_SHAFT_POSITION_INPUT /* 0x369 - 20Hz rate */ { - CanTxMessage msg(0x369, 8); + CanTxMessage msg(CanCategory::NBC, 0x369, 8); /* Trigger System Error Count */ tmp = engine->triggerCentral.triggerState.totalTriggerErrorCounter; msg[0] = (tmp >> 8); @@ -723,7 +723,7 @@ void canDashboardHaltech(CanCycle cycle) { /* 0x36A - 20Hz rate */ /* todo: one day we should split this */ { - CanTxMessage msg(0x36A, 4); + CanTxMessage msg(CanCategory::NBC, 0x36A, 4); /* Knock Level 1 */ tmp = (engine->outputChannels.knockLevel * 100); msg[0] = (tmp >> 8); @@ -735,7 +735,7 @@ void canDashboardHaltech(CanCycle cycle) { /* 0x36B - 20Hz rate */ { - CanTxMessage msg(0x36B, 8); + CanTxMessage msg(CanCategory::NBC, 0x36B, 8); /* Break Pressure */ msg[0] = 0x00; msg[1] = 0x00; @@ -752,7 +752,7 @@ void canDashboardHaltech(CanCycle cycle) { /* 0x36C = 20Hz rate */ { - CanTxMessage msg(0x36C, 8); + CanTxMessage msg(CanCategory::NBC, 0x36C, 8); /* Wheel Speed Front Left */ auto vehicleSpeed = Sensor::getOrZero(SensorType::VehicleSpeed); tmp = (vehicleSpeed * 10 ); @@ -771,7 +771,7 @@ void canDashboardHaltech(CanCycle cycle) { /* 0x36D = 20Hz rate */ { - CanTxMessage msg(0x36D, 8); + CanTxMessage msg(CanCategory::NBC, 0x36D, 8); /* Unused */ msg[0] = 0x00; msg[1] = 0x00; @@ -787,7 +787,7 @@ void canDashboardHaltech(CanCycle cycle) { /* 0x36E = 20Hz rate */ { - CanTxMessage msg(0x36E, 8); + CanTxMessage msg(CanCategory::NBC, 0x36E, 8); /* Engine Limiting Active 0 = off/1=on*/ msg[0] = 0x00; msg[1] = 0x00; @@ -804,7 +804,7 @@ void canDashboardHaltech(CanCycle cycle) { /* 0x36F = 20Hz rate */ { - CanTxMessage msg(0x36F, 4); + CanTxMessage msg(CanCategory::NBC, 0x36F, 4); /* Generic Output 1 Duty Cycle */ msg[0] = 0x00; msg[1] = 0x00; @@ -815,7 +815,7 @@ void canDashboardHaltech(CanCycle cycle) { /* 0x370 = 20Hz rate */ { - CanTxMessage msg(0x370, 8); + CanTxMessage msg(CanCategory::NBC, 0x370, 8); /* Vehicle Speed */ auto vehicleSpeed = Sensor::getOrZero(SensorType::VehicleSpeed); tmp = (vehicleSpeed * 10 ); @@ -834,7 +834,7 @@ void canDashboardHaltech(CanCycle cycle) { /* todo: 0x3E6 = 20Hz rate */ { - CanTxMessage msg(0x3E6, 8); + CanTxMessage msg(CanCategory::NBC, 0x3E6, 8); msg[0] = 0x00; msg[1] = 0x00; msg[2] = 0x00; @@ -847,7 +847,7 @@ void canDashboardHaltech(CanCycle cycle) { /* todo: 0x3E7 = 20Hz rate */ { - CanTxMessage msg(0x3E7, 8); + CanTxMessage msg(CanCategory::NBC, 0x3E7, 8); msg[0] = 0x00; msg[1] = 0x00; msg[2] = 0x00; @@ -860,7 +860,7 @@ void canDashboardHaltech(CanCycle cycle) { /* todo: 0x3E8 = 20Hz rate */ { - CanTxMessage msg(0x3E8, 8); + CanTxMessage msg(CanCategory::NBC, 0x3E8, 8); msg[0] = 0x00; msg[1] = 0x00; msg[2] = 0x00; @@ -873,7 +873,7 @@ void canDashboardHaltech(CanCycle cycle) { /* todo: 0x3E9 = 20Hz rate */ { - CanTxMessage msg(0x3E9, 8); + CanTxMessage msg(CanCategory::NBC, 0x3E9, 8); msg[0] = 0x00; msg[1] = 0x00; msg[2] = 0x00; @@ -886,7 +886,7 @@ void canDashboardHaltech(CanCycle cycle) { /* todo: 0x3EE = 20Hz rate */ { - CanTxMessage msg(0x3EE, 8); + CanTxMessage msg(CanCategory::NBC, 0x3EE, 8); msg[0] = 0x00; msg[1] = 0x00; msg[2] = 0x00; @@ -899,7 +899,7 @@ void canDashboardHaltech(CanCycle cycle) { /* todo: 0x3EF = 20Hz rate */ { - CanTxMessage msg(0x3EF, 8); + CanTxMessage msg(CanCategory::NBC, 0x3EF, 8); msg[0] = 0x00; msg[1] = 0x00; msg[2] = 0x00; @@ -912,7 +912,7 @@ void canDashboardHaltech(CanCycle cycle) { /* todo: 0x470 = 20Hz rate */ { - CanTxMessage msg(0x470, 8); + CanTxMessage msg(CanCategory::NBC, 0x470, 8); msg[0] = 0x00; msg[1] = 0x00; msg[2] = 0x00; @@ -925,7 +925,7 @@ void canDashboardHaltech(CanCycle cycle) { /* todo: 0x472 = 20Hz rate */ { - CanTxMessage msg(0x472, 8); + CanTxMessage msg(CanCategory::NBC, 0x472, 8); msg[0] = 0x00; msg[1] = 0x00; msg[2] = 0x00; @@ -941,7 +941,7 @@ void canDashboardHaltech(CanCycle cycle) { /* 0x371 = 10Hz rate */ { - CanTxMessage msg(0x371, 4); + CanTxMessage msg(CanCategory::NBC, 0x371, 4); /* Fuel Flow */ msg[0] = 0x00; msg[1] = 0x00; @@ -952,7 +952,7 @@ void canDashboardHaltech(CanCycle cycle) { /* 0x372 = 10Hz rate */ { - CanTxMessage msg(0x372, 8); + CanTxMessage msg(CanCategory::NBC, 0x372, 8); /* Battery Voltage */ tmp = (uint16_t)(Sensor::getOrZero(SensorType::BatteryVoltage) * 10); msg[0] = (tmp >> 8); @@ -971,7 +971,7 @@ void canDashboardHaltech(CanCycle cycle) { /* 0x373 = 10Hz rate */ { - CanTxMessage msg(0x373, 8); + CanTxMessage msg(CanCategory::NBC, 0x373, 8); /* EGT1 */ msg[0] = 0x00; msg[1] = 0x00; @@ -988,7 +988,7 @@ void canDashboardHaltech(CanCycle cycle) { /* 0x374 = 10Hz rate */ { - CanTxMessage msg(0x374, 8); + CanTxMessage msg(CanCategory::NBC, 0x374, 8); /* EGT5 */ msg[0] = 0x00; msg[1] = 0x00; @@ -1005,7 +1005,7 @@ void canDashboardHaltech(CanCycle cycle) { /* 0x375 = 10Hz rate */ { - CanTxMessage msg(0x375, 8); + CanTxMessage msg(CanCategory::NBC, 0x375, 8); /* EGT9 */ msg[0] = 0x00; msg[1] = 0x00; @@ -1022,7 +1022,7 @@ void canDashboardHaltech(CanCycle cycle) { /* 0x376 = 10Hz rate */ { - CanTxMessage msg(0x376, 8); + CanTxMessage msg(CanCategory::NBC, 0x376, 8); /* Ambient Air Temperature */ msg[0] = 0x00; msg[1] = 0x00; @@ -1041,7 +1041,7 @@ void canDashboardHaltech(CanCycle cycle) { if (cycle.isInterval(CI::_200ms)) { /* 0x3E0 = 5Hz rate */ { - CanTxMessage msg(0x3E0, 8); + CanTxMessage msg(CanCategory::NBC, 0x3E0, 8); /* Coolant temperature in K y = x/10 */ tmp = ((Sensor::getOrZero(SensorType::Clt) + 273.15) * 10); msg[0] = (tmp >> 8); @@ -1060,7 +1060,7 @@ void canDashboardHaltech(CanCycle cycle) { /* 0x3E1 = 5Hz rate */ { - CanTxMessage msg(0x3E1, 6); + CanTxMessage msg(CanCategory::NBC, 0x3E1, 6); /* Gearbox Oil Temperature */ msg[0] = 0x00; msg[1] = 0x00; @@ -1074,7 +1074,7 @@ void canDashboardHaltech(CanCycle cycle) { /* 0x3E2 = 5Hz rate */ { - CanTxMessage msg(0x3E2, 2); + CanTxMessage msg(CanCategory::NBC, 0x3E2, 2); /* Fuel Level in Liters */ tmp = (Sensor::getOrZero(SensorType::FuelLevel)* 10); msg[0] = (tmp >> 8); @@ -1083,7 +1083,7 @@ void canDashboardHaltech(CanCycle cycle) { /* 0x3E3 = 5Hz rate */ { - CanTxMessage msg(0x3E3, 8); + CanTxMessage msg(CanCategory::NBC, 0x3E3, 8); /* Fuel Trim Short Term Bank 1*/ msg[0] = 0x00; msg[1] = 0x00; @@ -1100,7 +1100,7 @@ void canDashboardHaltech(CanCycle cycle) { /* todo: 0x3E4 = 5Hz rate */ { - CanTxMessage msg(0x3E4, 8); + CanTxMessage msg(CanCategory::NBC, 0x3E4, 8); msg[0] = 0x00; //unused /* Switch status */ msg[1] = 0x00; @@ -1247,14 +1247,14 @@ void canDashboardAim(CanCycle cycle) { return; } - transmitStruct(0x5f0, false); - transmitStruct(0x5f1, false); - transmitStruct(0x5f2, false); - transmitStruct(0x5f3, false); - transmitStruct(0x5f4, false); - transmitStruct(0x5f5, false); - transmitStruct(0x5f6, false); - transmitStruct(0x5f7, false); + transmitStruct(CanCategory::NBC, 0x5f0, false); + transmitStruct(CanCategory::NBC, 0x5f1, false); + transmitStruct(CanCategory::NBC, 0x5f2, false); + transmitStruct(CanCategory::NBC, 0x5f3, false); + transmitStruct(CanCategory::NBC, 0x5f4, false); + transmitStruct(CanCategory::NBC, 0x5f5, false); + transmitStruct(CanCategory::NBC, 0x5f6, false); + transmitStruct(CanCategory::NBC, 0x5f7, false); // there are more, but less important for us // transmitStruct(0x5f8, false); diff --git a/firmware/controllers/can/can_verbose.cpp b/firmware/controllers/can/can_verbose.cpp index f9c7737f27..a47e38dd84 100644 --- a/firmware/controllers/can/can_verbose.cpp +++ b/firmware/controllers/can/can_verbose.cpp @@ -151,13 +151,13 @@ void sendCanVerbose() { auto base = engineConfiguration->verboseCanBaseAddress; auto isExt = engineConfiguration->rusefiVerbose29b; - transmitStruct (base + 0, isExt); - transmitStruct (base + 1, isExt); - transmitStruct (base + CAN_PEDAL_TPS_OFFSET, isExt); - transmitStruct (base + CAN_SENSOR_1_OFFSET, isExt); - transmitStruct (base + 4, isExt); - transmitStruct (base + 5, isExt); - transmitStruct (base + 6, isExt); + transmitStruct (CanCategory::VERBOSE, base + 0, isExt); + transmitStruct (CanCategory::VERBOSE, base + 1, isExt); + transmitStruct (CanCategory::VERBOSE, base + CAN_PEDAL_TPS_OFFSET, isExt); + transmitStruct (CanCategory::VERBOSE, base + CAN_SENSOR_1_OFFSET, isExt); + transmitStruct (CanCategory::VERBOSE, base + 4, isExt); + transmitStruct (CanCategory::VERBOSE, base + 5, isExt); + transmitStruct (CanCategory::VERBOSE, base + 6, isExt); } #endif // EFI_CAN_SUPPORT diff --git a/firmware/controllers/can/obd2.cpp b/firmware/controllers/can/obd2.cpp index 658442fc51..0b15a20594 100644 --- a/firmware/controllers/can/obd2.cpp +++ b/firmware/controllers/can/obd2.cpp @@ -57,7 +57,7 @@ static const int16_t supportedPids4160[] = { }; static void obdSendPacket(int mode, int PID, int numBytes, uint32_t iValue) { - CanTxMessage resp(OBD_TEST_RESPONSE); + CanTxMessage resp(CanCategory::OBD, OBD_TEST_RESPONSE); // write number of bytes resp[0] = (uint8_t)(2 + numBytes); diff --git a/firmware/controllers/can/rusefi_wideband.cpp b/firmware/controllers/can/rusefi_wideband.cpp index 30158132db..6b044323c8 100644 --- a/firmware/controllers/can/rusefi_wideband.cpp +++ b/firmware/controllers/can/rusefi_wideband.cpp @@ -43,7 +43,7 @@ void updateWidebandFirmware() { for (int i = 0; i < 2; i++) { { // Send bootloader entry command - CanTxMessage m(0xEF0'0000, 0, true); + CanTxMessage m(CanCategory::WBO_SERVICE, 0xEF0'0000, 0, true); } if (!waitAck()) { @@ -59,7 +59,7 @@ void updateWidebandFirmware() { { // Erase flash - opcode 1, magic value 0x5A5A - CanTxMessage m(0xEF1'5A5A, 0, true); + CanTxMessage m(CanCategory::WBO_SERVICE, 0xEF1'5A5A, 0, true); } if (!waitAck()) { @@ -74,7 +74,7 @@ void updateWidebandFirmware() { // Send flash data 8 bytes at a time for (size_t i = 0; i < totalSize; i += 8) { { - CanTxMessage m(0xEF2'0000 + i, 8, true); + CanTxMessage m(CanCategory::WBO_SERVICE, 0xEF2'0000 + i, 8, true); memcpy(&m[0], build_wideband_image_bin + i, 8); } @@ -88,7 +88,7 @@ void updateWidebandFirmware() { { // Reboot to firmware! - CanTxMessage m(0xEF3'0000, 0, true); + CanTxMessage m(CanCategory::WBO_SERVICE, 0xEF3'0000, 0, true); } waitAck(); @@ -109,7 +109,7 @@ void setWidebandOffset(uint8_t index) { efiPrintf("Setting all connected widebands to index %d...", index); { - CanTxMessage m(0xEF4'0000, 1, true); + CanTxMessage m(CanCategory::WBO_SERVICE, 0xEF4'0000, 1, true); m[0] = index; } @@ -121,7 +121,7 @@ void setWidebandOffset(uint8_t index) { } void sendWidebandInfo() { - CanTxMessage m(0xEF5'0000, 2, true); + CanTxMessage m(CanCategory::WBO_SERVICE, 0xEF5'0000, 2, true); float vbatt = Sensor::getOrZero(SensorType::BatteryVoltage) * 10; diff --git a/firmware/controllers/lua/lua_hooks.cpp b/firmware/controllers/lua/lua_hooks.cpp index 158562e72a..62fae03a2a 100644 --- a/firmware/controllers/lua/lua_hooks.cpp +++ b/firmware/controllers/lua/lua_hooks.cpp @@ -175,7 +175,7 @@ static int lua_txCan(lua_State* l) { } // conform ext parameter to true/false - CanTxMessage msg(id, 8, ext == 0 ? false : true); + CanTxMessage msg(CanCategory::LUA, id, 8, ext == 0 ? false : true); msg.busIndex = channel - HUMAN_OFFSET; // Unfortunately there is no way to inspect the length of a table, diff --git a/firmware/controllers/sensors/can_sensor.h b/firmware/controllers/sensors/can_sensor.h index 970705ee0e..8069bf8575 100644 --- a/firmware/controllers/sensors/can_sensor.h +++ b/firmware/controllers/sensors/can_sensor.h @@ -82,7 +82,7 @@ public: CanListener* request() override { { - CanTxMessage msg(OBD_TEST_REQUEST); + CanTxMessage msg(CanCategory::OBD, OBD_TEST_REQUEST); msg[0] = _OBD_2; msg[1] = OBD_CURRENT_DATA; msg[2] = PID; diff --git a/firmware/hw_layer/drivers/can/can_msg_tx.cpp b/firmware/hw_layer/drivers/can/can_msg_tx.cpp index 3d64d65e3a..f9d72288bf 100644 --- a/firmware/hw_layer/drivers/can/can_msg_tx.cpp +++ b/firmware/hw_layer/drivers/can/can_msg_tx.cpp @@ -22,7 +22,7 @@ } #endif // EFI_CAN_SUPPORT -CanTxMessage::CanTxMessage(uint32_t eid, uint8_t dlc, bool isExtended) { +CanTxMessage::CanTxMessage(CanCategory category, uint32_t eid, uint8_t dlc, bool isExtended) { #if HAL_USE_CAN || EFI_UNIT_TEST #ifndef STM32H7XX // ST bxCAN device diff --git a/firmware/hw_layer/drivers/can/can_msg_tx.h b/firmware/hw_layer/drivers/can/can_msg_tx.h index dd663c1270..8f6379b8aa 100644 --- a/firmware/hw_layer/drivers/can/can_msg_tx.h +++ b/firmware/hw_layer/drivers/can/can_msg_tx.h @@ -15,6 +15,16 @@ #include "os_access.h" #include "can.h" +enum class CanCategory : uint16_t { + NBC = 0, + VERBOSE = 1, + LUA = 2, + DOWNSTREAM_FLASHING = 3, + SERIAL = 4, + WBO_SERVICE = 5, + OBD = 6, +}; + /** * Represent a message to be transmitted over CAN. * @@ -29,7 +39,7 @@ public: /** * Create a new CAN message, with the specified extended ID. */ - explicit CanTxMessage(uint32_t eid, uint8_t dlc = 8, bool isExtended = false); + explicit CanTxMessage(CanCategory category, uint32_t eid, uint8_t dlc = 8, bool isExtended = false); /** * Destruction of an instance of CanTxMessage will transmit the message over the wire. @@ -90,7 +100,7 @@ class CanTxTyped final : public CanTxMessage #endif // EFI_CAN_SUPPORT public: - explicit CanTxTyped(uint32_t id, bool isExtended) : CanTxMessage(id, sizeof(TData), isExtended) { } + explicit CanTxTyped(CanCategory category, uint32_t id, bool isExtended) : CanTxMessage(category, id, sizeof(TData), isExtended) { } #if EFI_CAN_SUPPORT /** @@ -111,9 +121,9 @@ public: }; template -void transmitStruct(uint32_t id, bool isExtended) +void transmitStruct(CanCategory category, uint32_t id, bool isExtended) { - CanTxTyped frame(id, isExtended); + CanTxTyped frame(category, id, isExtended); // Destruction of an instance of CanTxMessage will transmit the message over the wire. // see CanTxMessage::~CanTxMessage() populateFrame(frame.get());