From 61e5b4b1adabfa0b5af839794e2a69e0e77ad102 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Tue, 11 Apr 2023 20:01:34 -0400 Subject: [PATCH] change ObdCode to enum class builds firmware --- .../config/boards/hellen/hellen_board_id.cpp | 2 +- firmware/console/binary/serial_can.cpp | 10 +-- firmware/console/binary/tooth_logger.cpp | 2 +- firmware/console/binary/ts_can_channel.cpp | 4 +- firmware/console/binary/tunerstudio.cpp | 2 +- firmware/console/binary/tunerstudio_io.cpp | 6 +- firmware/console/status_loop.cpp | 4 +- .../controllers/actuators/boost_control.cpp | 4 +- firmware/controllers/actuators/dc_motors.cpp | 2 +- .../actuators/electronic_throttle.cpp | 10 +-- .../actuators/gppwm/gppwm_channel.cpp | 6 +- .../controllers/actuators/idle_hardware.cpp | 2 +- firmware/controllers/algo/advance_map.cpp | 14 ++-- firmware/controllers/algo/airmass/airmass.cpp | 2 +- .../algo/airmass/speed_density_airmass.cpp | 4 +- .../algo/defaults/default_ignition.cpp | 2 +- firmware/controllers/algo/engine.cpp | 4 +- firmware/controllers/algo/engine2.cpp | 6 +- .../controllers/algo/engine_configuration.cpp | 6 +- firmware/controllers/algo/engine_parts.h | 4 +- .../controllers/algo/fuel/injector_model.cpp | 4 +- firmware/controllers/algo/fuel_math.cpp | 32 ++++---- firmware/controllers/algo/gear_detector.cpp | 6 +- firmware/controllers/algo/obd_error_codes.h | 32 ++------ firmware/controllers/bench_test.cpp | 14 ++-- firmware/controllers/can/can_dash.cpp | 2 +- firmware/controllers/can/can_verbose.cpp | 2 +- firmware/controllers/can/can_vss.cpp | 2 +- firmware/controllers/can/obd2.cpp | 4 +- firmware/controllers/can/rusefi_wideband.cpp | 2 +- firmware/controllers/core/error_handling.cpp | 4 +- firmware/controllers/core/state_sequence.cpp | 6 +- firmware/controllers/core/state_sequence.h | 4 +- firmware/controllers/engine_controller.cpp | 4 +- .../engine_cycle/fuel_schedule.cpp | 16 ++-- .../engine_cycle/high_pressure_fuel_pump.cpp | 2 +- .../engine_cycle/main_trigger_callback.cpp | 12 +-- .../engine_cycle/map_averaging.cpp | 24 +++--- .../engine_cycle/rpm_calculator.cpp | 2 +- firmware/controllers/flash_main.cpp | 6 +- .../gauges/malfunction_indicator.cpp | 8 +- firmware/controllers/gauges/tachometer.cpp | 2 +- firmware/controllers/lua/can_filter.cpp | 2 +- firmware/controllers/lua/lua.cpp | 6 +- firmware/controllers/lua/lua_can_rx.cpp | 2 +- firmware/controllers/math/speed_density.cpp | 6 +- firmware/controllers/sensors/core/sensor.cpp | 2 +- .../sensors/impl/AemXSeriesLambda.cpp | 4 +- firmware/controllers/sensors/impl/ego.cpp | 2 +- firmware/controllers/sensors/impl/map.cpp | 2 +- .../controllers/sensors/sensor_checker.cpp | 78 +++++++++---------- firmware/controllers/settings.cpp | 2 +- .../system/periodic_thread_controller.h | 2 +- .../controllers/system/timer/event_queue.cpp | 8 +- .../controllers/system/timer/event_queue.h | 4 +- .../system/timer/pwm_generator_logic.cpp | 36 ++++----- .../controllers/system/timer/scheduler.cpp | 2 +- .../system/timer/single_timer_executor.cpp | 10 +-- .../system/timer/trigger_scheduler.cpp | 2 +- .../trigger/decoders/trigger_structure.h | 2 +- .../trigger/decoders/trigger_universal.cpp | 8 +- .../controllers/trigger/trigger_central.cpp | 32 ++++---- .../controllers/trigger/trigger_decoder.cpp | 30 +++---- .../controllers/trigger/trigger_simulator.cpp | 8 +- firmware/development/engine_sniffer.cpp | 6 +- firmware/development/logic_analyzer.cpp | 8 +- firmware/hw_layer/adc/adc_inputs.cpp | 6 +- firmware/hw_layer/adc/adc_subscription.cpp | 2 +- .../digital_input/digital_input_exti.cpp | 6 +- .../digital_input/trigger/trigger_input.cpp | 2 +- firmware/hw_layer/drivers/can/can_hw.cpp | 6 +- firmware/hw_layer/drivers/can/can_msg_tx.cpp | 2 +- firmware/hw_layer/drivers/gpio/l9779.cpp | 2 +- firmware/hw_layer/drivers/gpio/tle8888.cpp | 2 +- .../hw_layer/drivers/serial/serial_hw.cpp | 4 +- firmware/hw_layer/hardware.cpp | 10 +-- firmware/hw_layer/io_pins.h | 2 +- .../microsecond_timer/microsecond_timer.cpp | 14 ++-- .../microsecond_timer_gpt.cpp | 4 +- firmware/hw_layer/mmc_card.cpp | 4 +- firmware/hw_layer/pin_repository.cpp | 6 +- firmware/hw_layer/ports/chconf_common.h | 6 +- .../hw_layer/ports/cypress/cypress_common.cpp | 2 +- .../hw_layer/ports/cypress/cypress_pins.cpp | 8 +- .../hw_layer/ports/kinetis/kinetis_common.cpp | 2 +- .../hw_layer/ports/kinetis/kinetis_pins.cpp | 8 +- firmware/hw_layer/ports/stm32/backup_ram.cpp | 4 +- .../hw_layer/ports/stm32/stm32_adc_v2.cpp | 2 +- .../hw_layer/ports/stm32/stm32_common.cpp | 14 ++-- firmware/hw_layer/ports/stm32/stm32_pins.cpp | 8 +- .../hw_layer/ports/stm32/stm32f7/mpu_util.cpp | 4 +- firmware/hw_layer/rtc_helper.cpp | 2 +- firmware/hw_layer/smart_gpio.cpp | 10 +-- firmware/hw_layer/stepper_dual_hbridge.cpp | 2 +- firmware/init/sensor/init_lambda.cpp | 2 +- firmware/init/sensor/init_map.cpp | 2 +- firmware/init/sensor/init_thermistors.cpp | 2 +- firmware/init/sensor/init_tps.cpp | 6 +- firmware/util/cli_registry.cpp | 6 +- firmware/util/containers/fl_stack.h | 10 +-- firmware/util/containers/listener_array.h | 2 +- firmware/util/containers/table_helper.h | 2 +- firmware/util/datalogging.cpp | 6 +- firmware/util/efilib.cpp | 2 +- firmware/util/efilib.h | 4 +- firmware/util/histogram.cpp | 4 +- firmware/util/loggingcentral.cpp | 2 +- firmware/util/math/biquad.cpp | 4 +- firmware/util/math/efi_interpolation.h | 10 +-- firmware/util/math/efi_pid.cpp | 4 +- firmware/util/math/interpolation.cpp | 18 ++--- simulator/simulator/rusEfiFunctionalTest.cpp | 2 +- unit_tests/engine_test_helper.cpp | 2 +- unit_tests/logicdata_csv_reader.cpp | 2 +- unit_tests/tests/test_util.cpp | 6 +- .../tests/trigger/test_cam_vvt_input.cpp | 8 +- unit_tests/tests/trigger/test_real_4b11.cpp | 2 +- .../test_real_cranking_nissan_vq40.cpp | 4 +- .../tests/trigger/test_real_nb2_cranking.cpp | 10 +-- .../tests/trigger/test_trigger_decoder.cpp | 10 +-- 120 files changed, 401 insertions(+), 425 deletions(-) diff --git a/firmware/config/boards/hellen/hellen_board_id.cpp b/firmware/config/boards/hellen/hellen_board_id.cpp index 40d28c5bbc..f06f880477 100644 --- a/firmware/config/boards/hellen/hellen_board_id.cpp +++ b/firmware/config/boards/hellen/hellen_board_id.cpp @@ -92,7 +92,7 @@ float HellenBoardIdSolver::solve(float Tc1, float Tc2, float x0, float y, float // since we had https://github.com/rusefi/rusefi/issues/4084 let's add paranoia check // All real cases seem to converge in <= 5 iterations, so we don't need to try more than 20. if (!result) { - firmwareError(OBD_PCM_Processor_Fault, "hellen boardID is broken"); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "hellen boardID is broken"); return 0; } diff --git a/firmware/console/binary/serial_can.cpp b/firmware/console/binary/serial_can.cpp index eed614ba09..ba01183618 100644 --- a/firmware/console/binary/serial_can.cpp +++ b/firmware/console/binary/serial_can.cpp @@ -211,7 +211,7 @@ int CanStreamerState::sendDataTimeout(const uint8_t *txbuf, int numBytes, can_sy #ifdef SERIAL_CAN_DEBUG PRINT("*** ERROR: CAN Flow Control frame not received" PRINT_EOL); #endif /* SERIAL_CAN_DEBUG */ - //warning(CUSTOM_ERR_CAN_COMMUNICATION, "CAN Flow Control frame not received"); + //warning(ObdCode::CUSTOM_ERR_CAN_COMMUNICATION, "CAN Flow Control frame not received"); return 0; } receiveFrame(&rxmsg, nullptr, 0, timeout); @@ -225,7 +225,7 @@ int CanStreamerState::sendDataTimeout(const uint8_t *txbuf, int numBytes, can_sy #ifdef SERIAL_CAN_DEBUG efiPrintf("*** ERROR: CAN Flow Control mode not supported"); #endif /* SERIAL_CAN_DEBUG */ - //warning(CUSTOM_ERR_CAN_COMMUNICATION, "CAN Flow Control mode not supported"); + //warning(ObdCode::CUSTOM_ERR_CAN_COMMUNICATION, "CAN Flow Control mode not supported"); return 0; } int blockSize = rxmsg.data8[1]; @@ -235,7 +235,7 @@ int CanStreamerState::sendDataTimeout(const uint8_t *txbuf, int numBytes, can_sy #ifdef SERIAL_CAN_DEBUG efiPrintf("*** ERROR: CAN Flow Control fields not supported"); #endif /* SERIAL_CAN_DEBUG */ - //warning(CUSTOM_ERR_CAN_COMMUNICATION, "CAN Flow Control fields not supported"); + //warning(ObdCode::CUSTOM_ERR_CAN_COMMUNICATION, "CAN Flow Control fields not supported"); } break; } @@ -316,7 +316,7 @@ can_msg_t CanStreamerState::streamAddToTxTimeout(size_t *np, const uint8_t *txbu can_msg_t CanStreamerState::streamFlushTx(can_sysinterval_t timeout) { int numSent = sendDataTimeout((const uint8_t *)txFifoBuf.getElements(), txFifoBuf.getCount(), timeout); if (numSent != txFifoBuf.getCount()) { - //warning(CUSTOM_ERR_CAN_COMMUNICATION, "CAN sendDataTimeout() problems"); + //warning(ObdCode::CUSTOM_ERR_CAN_COMMUNICATION, "CAN sendDataTimeout() problems"); } txFifoBuf.clear(); @@ -367,7 +367,7 @@ void CanTsListener::decodeFrame(const CANRxFrame& frame, efitick_t /*nowNt*/) { PRINT("*** INFO: CanTsListener decodeFrame %d" PRINT_EOL, isoTpPacketCounter++); } if (!rxFifo.put(msg)) { - warning(CUSTOM_ERR_CAN_COMMUNICATION, "CAN sendDataTimeout() problems"); + warning(ObdCode::CUSTOM_ERR_CAN_COMMUNICATION, "CAN sendDataTimeout() problems"); } } diff --git a/firmware/console/binary/tooth_logger.cpp b/firmware/console/binary/tooth_logger.cpp index 7c57a77db3..9fb297996a 100644 --- a/firmware/console/binary/tooth_logger.cpp +++ b/firmware/console/binary/tooth_logger.cpp @@ -156,7 +156,7 @@ void ReturnToothLoggerBuffer(CompositeBuffer* buffer) { chibios_rt::CriticalSectionLocker csl; msg_t msg = freeBuffers.postI(buffer); - efiAssertVoid(OBD_PCM_Processor_Fault, msg == MSG_OK, "Composite logger post to free buffer fail"); + efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, msg == MSG_OK, "Composite logger post to free buffer fail"); // If the used list is empty, clear the ready flag if (filledBuffers.getUsedCountI() == 0) { diff --git a/firmware/console/binary/ts_can_channel.cpp b/firmware/console/binary/ts_can_channel.cpp index fe056606f6..f2105b7b5d 100644 --- a/firmware/console/binary/ts_can_channel.cpp +++ b/firmware/console/binary/ts_can_channel.cpp @@ -40,12 +40,12 @@ public: void CanTsChannel::start() { if (!getIsCanEnabled()) { - warning(CUSTOM_ERR_CAN_CONFIGURATION, "CAN not enabled"); + warning(ObdCode::CUSTOM_ERR_CAN_CONFIGURATION, "CAN not enabled"); return; } if (!engineConfiguration->canReadEnabled || !engineConfiguration->canWriteEnabled) { - warning(CUSTOM_ERR_CAN_CONFIGURATION, "CAN read or write not enabled"); + warning(ObdCode::CUSTOM_ERR_CAN_CONFIGURATION, "CAN read or write not enabled"); } } diff --git a/firmware/console/binary/tunerstudio.cpp b/firmware/console/binary/tunerstudio.cpp index 0cd10a0744..abeda68cbb 100644 --- a/firmware/console/binary/tunerstudio.cpp +++ b/firmware/console/binary/tunerstudio.cpp @@ -458,7 +458,7 @@ bool TunerStudio::handlePlainCommand(TsChannelBase* tsChannel, uint8_t command) TunerStudio tsInstance; static int tsProcessOne(TsChannelBase* tsChannel) { - validateStack("communication", STACK_USAGE_COMMUNICATION, 128); + validateStack("communication", ObdCode::STACK_USAGE_COMMUNICATION, 128); if (!tsChannel->isReady()) { chThdSleepMilliseconds(10); diff --git a/firmware/console/binary/tunerstudio_io.cpp b/firmware/console/binary/tunerstudio_io.cpp index 39114c87b9..1844e923d0 100644 --- a/firmware/console/binary/tunerstudio_io.cpp +++ b/firmware/console/binary/tunerstudio_io.cpp @@ -23,7 +23,7 @@ size_t TsChannelBase::read(uint8_t* buffer, size_t size) { void TsChannelBase::copyAndWriteSmallCrcPacket(uint8_t responseCode, const uint8_t* buf, size_t size) { // don't transmit too large a buffer - efiAssertVoid(OBD_PCM_Processor_Fault, !isBigPacket(size), "copyAndWriteSmallCrcPacket tried to transmit too large a packet") + efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, !isBigPacket(size), "copyAndWriteSmallCrcPacket tried to transmit too large a packet") // If transmitting data, copy it in to place in the scratch buffer // We want to prevent the data changing itself (higher priority threads could write @@ -37,7 +37,7 @@ void TsChannelBase::copyAndWriteSmallCrcPacket(uint8_t responseCode, const uint8 } void TsChannelBase::crcAndWriteBuffer(uint8_t responseCode, size_t size) { - efiAssertVoid(OBD_PCM_Processor_Fault, !isBigPacket(size), "crcAndWriteBuffer tried to transmit too large a packet") + efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, !isBigPacket(size), "crcAndWriteBuffer tried to transmit too large a packet") // Index 0/1 = packet size (big endian) *(uint16_t*)scratchBuffer = SWAP_UINT16(size + 1); @@ -92,7 +92,7 @@ TsChannelBase::TsChannelBase(const char *name) { void TsChannelBase::assertPacketSize(size_t size, bool allowLongPackets) { if (isBigPacket(size) && !allowLongPackets) { - firmwareError(OBD_PCM_Processor_Fault, "[USE PROPER CONSOLE VERSION ] disallowed long packet of size %d", size); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "[USE PROPER CONSOLE VERSION ] disallowed long packet of size %d", size); } } diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index 1f9010e034..dbd182c7b6 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -723,9 +723,9 @@ DcHardware *getdcHardware(); #endif tsOutputChannels->warningCounter = engine->engineState.warnings.warningCounter; - tsOutputChannels->lastErrorCode = engine->engineState.warnings.lastErrorCode; + tsOutputChannels->lastErrorCode = static_cast(engine->engineState.warnings.lastErrorCode); for (int i = 0; i < 8;i++) { - tsOutputChannels->recentErrorCode[i] = engine->engineState.warnings.recentWarnings.get(i).Code; + tsOutputChannels->recentErrorCode[i] = static_cast(engine->engineState.warnings.recentWarnings.get(i).Code); } tsOutputChannels->starterState = enginePins.starterControl.getLogicValue(); diff --git a/firmware/controllers/actuators/boost_control.cpp b/firmware/controllers/actuators/boost_control.cpp index e02cc251f9..0694b7582b 100644 --- a/firmware/controllers/actuators/boost_control.cpp +++ b/firmware/controllers/actuators/boost_control.cpp @@ -65,7 +65,7 @@ expected BoostController::getSetpoint() { return unexpected; } - efiAssert(OBD_PCM_Processor_Fault, m_closedLoopTargetMap != nullptr, "boost closed loop target", unexpected); + efiAssert(ObdCode::OBD_PCM_Processor_Fault, m_closedLoopTargetMap != nullptr, "boost closed loop target", unexpected); return m_closedLoopTargetMap->getValue(rpm, driverIntent.Value) * luaTargetMult + luaTargetAdd; } @@ -83,7 +83,7 @@ expected BoostController::getOpenLoop(float target) { return unexpected; } - efiAssert(OBD_PCM_Processor_Fault, m_openLoopMap != nullptr, "boost open loop", unexpected); + efiAssert(ObdCode::OBD_PCM_Processor_Fault, m_openLoopMap != nullptr, "boost open loop", unexpected); openLoopPart = luaOpenLoopAdd + m_openLoopMap->getValue(rpm, driverIntent.Value); diff --git a/firmware/controllers/actuators/dc_motors.cpp b/firmware/controllers/actuators/dc_motors.cpp index 08fc90dd5d..e32e5b53aa 100644 --- a/firmware/controllers/actuators/dc_motors.cpp +++ b/firmware/controllers/actuators/dc_motors.cpp @@ -37,7 +37,7 @@ int clampedFrequency = maxI(100, frequency); if (clampedFrequency > ETB_HW_MAX_FREQUENCY) { - firmwareError(OBD_PCM_Processor_Fault, "Electronic throttle frequency too high, maximum %d hz", ETB_HW_MAX_FREQUENCY); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "Electronic throttle frequency too high, maximum %d hz", ETB_HW_MAX_FREQUENCY); return; } diff --git a/firmware/controllers/actuators/electronic_throttle.cpp b/firmware/controllers/actuators/electronic_throttle.cpp index 5c78c18a36..0dae66dad0 100644 --- a/firmware/controllers/actuators/electronic_throttle.cpp +++ b/firmware/controllers/actuators/electronic_throttle.cpp @@ -191,7 +191,7 @@ bool EtbController::init(dc_function_e function, DcMotor *motor, pid_s *pidParam if (!Sensor::isRedundant(m_positionSensor)) { firmwareError( - OBD_TPS_Configuration, + ObdCode::OBD_TPS_Configuration, "Use of electronic throttle requires %s to be redundant.", Sensor::getSensorName(m_positionSensor) ); @@ -202,7 +202,7 @@ bool EtbController::init(dc_function_e function, DcMotor *motor, pid_s *pidParam if (!Sensor::isRedundant(SensorType::AcceleratorPedal)) { firmwareError( - OBD_TPS_Configuration, + ObdCode::OBD_TPS_Configuration, "Use of electronic throttle requires accelerator pedal to be redundant." ); etbErrorCode = (int8_t)TpsState::Redundancy; @@ -748,7 +748,7 @@ struct EtbImpl final : public TBase { // Check that the calibrate actually moved the throttle if (absF(primaryMax - primaryMin) < 0.5f) { - firmwareError(OBD_TPS_Configuration, "Auto calibrate failed, check your wiring!\r\nClosed voltage: %.1fv Open voltage: %.1fv", primaryMin, primaryMax); + firmwareError(ObdCode::OBD_TPS_Configuration, "Auto calibrate failed, check your wiring!\r\nClosed voltage: %.1fv Open voltage: %.1fv", primaryMin, primaryMax); TBase::m_isAutocal = false; return; } @@ -1061,7 +1061,7 @@ void doInitElectronicThrottle() { if (!engineConfiguration->etb1configured && !engineConfiguration->etb2configured) { // It's not valid to have a PPS without any ETBs - check that at least one ETB was enabled along with the pedal if (hasPedal) { - firmwareError(OBD_PCM_Processor_Fault, "A pedal position sensor was configured, but no electronic throttles are configured."); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "A pedal position sensor was configured, but no electronic throttles are configured."); } } @@ -1071,7 +1071,7 @@ void doInitElectronicThrottle() { /** * Unexpected electronic throttle start-up position is worth a critical error */ - firmwareError(OBD_Throttle_Actuator_Control_Range_Performance_Bank_1, "startup ETB position %.2f not %d", + firmwareError(ObdCode::OBD_Throttle_Actuator_Control_Range_Performance_Bank_1, "startup ETB position %.2f not %d", startupThrottlePosition, engineConfiguration->etbNeutralPosition); startupPositionError = true; diff --git a/firmware/controllers/actuators/gppwm/gppwm_channel.cpp b/firmware/controllers/actuators/gppwm/gppwm_channel.cpp index ce28373447..11032a5ce2 100644 --- a/firmware/controllers/actuators/gppwm/gppwm_channel.cpp +++ b/firmware/controllers/actuators/gppwm/gppwm_channel.cpp @@ -78,14 +78,14 @@ float GppwmChannel::setOutput(float result) { } if (m_usePwm) { - efiAssert(OBD_PCM_Processor_Fault, m_usePwm, "m_usePwm null", 0); + efiAssert(ObdCode::OBD_PCM_Processor_Fault, m_usePwm, "m_usePwm null", 0); m_pwm->setSimplePwmDutyCycle(clampF(0, result / 100.0f, 1)); return result; } else { - efiAssert(OBD_PCM_Processor_Fault, m_output, "m_output null", 0); + efiAssert(ObdCode::OBD_PCM_Processor_Fault, m_output, "m_output null", 0); if (m_config->offBelowDuty > m_config->onAboveDuty) { - firmwareError(CUSTOM_ERR_6122, "You can't have off below %d greater than on above %d", + firmwareError(ObdCode::CUSTOM_ERR_6122, "You can't have off below %d greater than on above %d", m_config->offBelowDuty, m_config->onAboveDuty); } diff --git a/firmware/controllers/actuators/idle_hardware.cpp b/firmware/controllers/actuators/idle_hardware.cpp index eb4f05a73d..c3aa326a8c 100644 --- a/firmware/controllers/actuators/idle_hardware.cpp +++ b/firmware/controllers/actuators/idle_hardware.cpp @@ -155,7 +155,7 @@ void initIdleHardware() { if (engineConfiguration->isDoubleSolenoidIdle) { if (!isBrainPinValid(engineConfiguration->secondSolenoidPin)) { - firmwareError(OBD_PCM_Processor_Fault, "Second idle pin should be configured for double solenoid mode."); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "Second idle pin should be configured for double solenoid mode."); return; } diff --git a/firmware/controllers/algo/advance_map.cpp b/firmware/controllers/algo/advance_map.cpp index 46b7760428..c1119ad99b 100644 --- a/firmware/controllers/algo/advance_map.cpp +++ b/firmware/controllers/algo/advance_map.cpp @@ -40,11 +40,11 @@ static angle_t getRunningAdvance(int rpm, float engineLoad) { } if (cisnan(engineLoad)) { - warning(CUSTOM_NAN_ENGINE_LOAD, "NaN engine load"); + warning(ObdCode::CUSTOM_NAN_ENGINE_LOAD, "NaN engine load"); return NAN; } - efiAssert(CUSTOM_ERR_ASSERT, !cisnan(engineLoad), "invalid el", NAN); + efiAssert(ObdCode::CUSTOM_ERR_ASSERT, !cisnan(engineLoad), "invalid el", NAN); // compute base ignition angle from main table float advanceAngle = interpolate3d( @@ -163,13 +163,13 @@ angle_t getAdvance(int rpm, float engineLoad) { bool isCranking = engine->rpmCalculator.isCranking(); if (isCranking) { angle = getCrankingAdvance(rpm, engineLoad); - assertAngleRange(angle, "crAngle", CUSTOM_ERR_ANGLE_CR); - efiAssert(CUSTOM_ERR_ASSERT, !cisnan(angle), "cr_AngleN", 0); + assertAngleRange(angle, "crAngle", ObdCode::CUSTOM_ERR_ANGLE_CR); + efiAssert(ObdCode::CUSTOM_ERR_ASSERT, !cisnan(angle), "cr_AngleN", 0); } else { angle = getRunningAdvance(rpm, engineLoad); if (cisnan(angle)) { - warning(CUSTOM_ERR_6610, "NaN angle from table"); + warning(ObdCode::CUSTOM_ERR_6610, "NaN angle from table"); return 0; } } @@ -186,8 +186,8 @@ angle_t getAdvance(int rpm, float engineLoad) { } } - efiAssert(CUSTOM_ERR_ASSERT, !cisnan(angle), "_AngleN5", 0); - fixAngle(angle, "getAdvance", CUSTOM_ERR_ADCANCE_CALC_ANGLE); + efiAssert(ObdCode::CUSTOM_ERR_ASSERT, !cisnan(angle), "_AngleN5", 0); + fixAngle(angle, "getAdvance", ObdCode::CUSTOM_ERR_ADCANCE_CALC_ANGLE); return angle; #else return 0; diff --git a/firmware/controllers/algo/airmass/airmass.cpp b/firmware/controllers/algo/airmass/airmass.cpp index 2de12a1bd2..78d9425a35 100644 --- a/firmware/controllers/algo/airmass/airmass.cpp +++ b/firmware/controllers/algo/airmass/airmass.cpp @@ -15,7 +15,7 @@ float AirmassVeModelBase::getVeLoadAxis(float passedLoad) const { } float AirmassVeModelBase::getVe(int rpm, float load) const { - efiAssert(OBD_PCM_Processor_Fault, m_veTable != nullptr, "VE table null", 0); + efiAssert(ObdCode::OBD_PCM_Processor_Fault, m_veTable != nullptr, "VE table null", 0); // Override the load value if necessary load = getVeLoadAxis(load); diff --git a/firmware/controllers/algo/airmass/speed_density_airmass.cpp b/firmware/controllers/algo/airmass/speed_density_airmass.cpp index 1197ceede1..e32905cbd2 100644 --- a/firmware/controllers/algo/airmass/speed_density_airmass.cpp +++ b/firmware/controllers/algo/airmass/speed_density_airmass.cpp @@ -9,7 +9,7 @@ AirmassResult SpeedDensityAirmass::getAirmass(int rpm) { */ float tChargeK = engine->engineState.sd.tChargeK; if (cisnan(tChargeK)) { - warning(CUSTOM_ERR_TCHARGE_NOT_READY2, "tChargeK not ready"); // this would happen before we have CLT reading for example + warning(ObdCode::CUSTOM_ERR_TCHARGE_NOT_READY2, "tChargeK not ready"); // this would happen before we have CLT reading for example return {}; } @@ -19,7 +19,7 @@ AirmassResult SpeedDensityAirmass::getAirmass(int rpm) { float airMass = getAirmassImpl(ve, map, tChargeK); if (cisnan(airMass)) { - warning(CUSTOM_ERR_6685, "NaN airMass"); + warning(ObdCode::CUSTOM_ERR_6685, "NaN airMass"); return {}; } #if EFI_PRINTF_FUEL_DETAILS diff --git a/firmware/controllers/algo/defaults/default_ignition.cpp b/firmware/controllers/algo/defaults/default_ignition.cpp index 7101706587..96acbf7446 100644 --- a/firmware/controllers/algo/defaults/default_ignition.cpp +++ b/firmware/controllers/algo/defaults/default_ignition.cpp @@ -53,7 +53,7 @@ float getInitialAdvance(int rpm, float map, float advanceMax) { */ static void buildTimingMap(float advanceMax) { if (engineConfiguration->fuelAlgorithm != LM_SPEED_DENSITY) { - warning(CUSTOM_WRONG_ALGORITHM, "wrong algorithm for MAP-based timing"); + warning(ObdCode::CUSTOM_WRONG_ALGORITHM, "wrong algorithm for MAP-based timing"); return; } /** diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index 1376b71464..dfed6d3352 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -101,7 +101,7 @@ trigger_type_e getVvtTriggerType(vvt_mode_e vvtMode) { case VVT_MITSUBISHI_4G63: return TT_MITSU_4G63_CAM; default: - firmwareError(OBD_PCM_Processor_Fault, "getVvtTriggerType for %s", getVvt_mode_e(vvtMode)); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "getVvtTriggerType for %s", getVvt_mode_e(vvtMode)); return TT_ONE; // we have to return something for the sake of -Werror=return-type } } @@ -411,7 +411,7 @@ void Engine::efiWatchdog() { if (!getTriggerCentral()->isSpinningJustForWatchdog) { if (!isRunningBenchTest() && enginePins.stopPins()) { // todo: make this a firmwareError assuming functional tests would run - warning(CUSTOM_ERR_2ND_WATCHDOG, "Some pins were turned off by 2nd pass watchdog"); + warning(ObdCode::CUSTOM_ERR_2ND_WATCHDOG, "Some pins were turned off by 2nd pass watchdog"); } return; } diff --git a/firmware/controllers/algo/engine2.cpp b/firmware/controllers/algo/engine2.cpp index 8b8f02a137..f49218fd3e 100644 --- a/firmware/controllers/algo/engine2.cpp +++ b/firmware/controllers/algo/engine2.cpp @@ -33,7 +33,7 @@ WarningCodeState::WarningCodeState() { void WarningCodeState::clear() { warningCounter = 0; - lastErrorCode = 0; + lastErrorCode = ObdCode::None; recentWarnings.clear(); } @@ -114,7 +114,7 @@ void EngineState::periodicFastCallback() { #if EFI_ENGINE_CONTROL if (!engine->slowCallBackWasInvoked) { - warning(CUSTOM_SLOW_NOT_INVOKED, "Slow not invoked yet"); + warning(ObdCode::CUSTOM_SLOW_NOT_INVOKED, "Slow not invoked yet"); } efitick_t nowNt = getTimeNowNt(); @@ -255,7 +255,7 @@ bool isLockedFromUser() { int lock = engineConfiguration->tuneHidingKey; bool isLocked = lock > 0; if (isLocked) { - firmwareError(OBD_PCM_Processor_Fault, "password protected"); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "password protected"); } return isLocked; } diff --git a/firmware/controllers/algo/engine_configuration.cpp b/firmware/controllers/algo/engine_configuration.cpp index 1cf62fa141..72c44793f9 100644 --- a/firmware/controllers/algo/engine_configuration.cpp +++ b/firmware/controllers/algo/engine_configuration.cpp @@ -250,7 +250,7 @@ static void initTemperatureCurve(float *bins, float *values, int size, float def } void prepareVoidConfiguration(engine_configuration_s *engineConfiguration) { - efiAssertVoid(OBD_PCM_Processor_Fault, engineConfiguration != NULL, "ec NULL"); + efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, engineConfiguration != NULL, "ec NULL"); efi::clear(engineConfiguration); engineConfiguration->clutchDownPinMode = PI_PULLUP; @@ -1003,7 +1003,7 @@ void resetConfigurationExt(configuration_callback_t boardCallback, engine_type_e break; #endif //HW_SUBARU_EG33 default: - firmwareError(CUSTOM_UNEXPECTED_ENGINE_TYPE, "Unexpected engine type: %d", engineType); + firmwareError(ObdCode::CUSTOM_UNEXPECTED_ENGINE_TYPE, "Unexpected engine type: %d", engineType); } applyNonPersistentConfiguration(); } @@ -1025,7 +1025,7 @@ void validateConfiguration() { void applyNonPersistentConfiguration() { #if EFI_PROD_CODE - efiAssertVoid(CUSTOM_APPLY_STACK, getCurrentRemainingStack() > EXPECTED_REMAINING_STACK, "apply c"); + efiAssertVoid(ObdCode::CUSTOM_APPLY_STACK, getCurrentRemainingStack() > EXPECTED_REMAINING_STACK, "apply c"); efiPrintf("applyNonPersistentConfiguration()"); #endif diff --git a/firmware/controllers/algo/engine_parts.h b/firmware/controllers/algo/engine_parts.h index 3a20f73670..54f8738a2f 100644 --- a/firmware/controllers/algo/engine_parts.h +++ b/firmware/controllers/algo/engine_parts.h @@ -45,7 +45,7 @@ public: struct warning_t { Timer LastTriggered; - ObdCode Code = OBD_None; + ObdCode Code = ObdCode::None; warning_t() { } @@ -75,7 +75,7 @@ public: bool isWarningNow(ObdCode code) const; void clear(); int warningCounter; - int lastErrorCode; + ObdCode lastErrorCode = ObdCode::None; Timer timeSinceLastWarning; diff --git a/firmware/controllers/algo/fuel/injector_model.cpp b/firmware/controllers/algo/fuel/injector_model.cpp index bdb8045f0c..fb9139e8c8 100644 --- a/firmware/controllers/algo/fuel/injector_model.cpp +++ b/firmware/controllers/algo/fuel/injector_model.cpp @@ -57,7 +57,7 @@ expected InjectorModel::getAbsoluteRailPressure() const { return engineConfiguration->fuelReferencePressure + Sensor::get(SensorType::BarometricPressure).value_or(101.325f); case ICM_SensedRailPressure: if (!Sensor::hasSensor(SensorType::FuelPressureInjector)) { - firmwareError(OBD_PCM_Processor_Fault, "Fuel pressure compensation is set to use a pressure sensor, but none is configured."); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "Fuel pressure compensation is set to use a pressure sensor, but none is configured."); return unexpected; } @@ -77,7 +77,7 @@ float InjectorModel::getInjectorFlowRatio() { if (referencePressure < 50) { // impossibly low fuel ref pressure - firmwareError(OBD_PCM_Processor_Fault, "Impossible fuel reference pressure: %f", referencePressure); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "Impossible fuel reference pressure: %f", referencePressure); return 1.0f; } diff --git a/firmware/controllers/algo/fuel_math.cpp b/firmware/controllers/algo/fuel_math.cpp index 1ce8ba3307..b473761912 100644 --- a/firmware/controllers/algo/fuel_math.cpp +++ b/firmware/controllers/algo/fuel_math.cpp @@ -65,7 +65,7 @@ float getCrankingFuel3( bool alreadyWarned = false; if (e0Mult <= 0.1f) { - warning(CUSTOM_ERR_ZERO_E0_MULT, "zero e0 multiplier"); + warning(ObdCode::CUSTOM_ERR_ZERO_E0_MULT, "zero e0 multiplier"); alreadyWarned = true; } @@ -73,7 +73,7 @@ float getCrankingFuel3( auto e85Mult = interpolate2d(clt, config->crankingFuelBins, config->crankingFuelCoefE100); if (e85Mult <= 0.1f) { - warning(CUSTOM_ERR_ZERO_E85_MULT, "zero e85 multiplier"); + warning(ObdCode::CUSTOM_ERR_ZERO_E85_MULT, "zero e85 multiplier"); alreadyWarned = true; } @@ -105,7 +105,7 @@ float getCrankingFuel3( // don't re-warn for zero fuel when we already warned for a more specific problem if (!alreadyWarned && crankingFuel <= 0) { - warning(CUSTOM_ERR_ZERO_CRANKING_FUEL, "Cranking fuel value %f", crankingFuel); + warning(ObdCode::CUSTOM_ERR_ZERO_CRANKING_FUEL, "Cranking fuel value %f", crankingFuel); } return crankingFuel; } @@ -123,9 +123,9 @@ float getRunningFuel(float baseFuel) { float baroCorrection = engine->engineState.baroCorrection; - efiAssert(CUSTOM_ERR_ASSERT, !cisnan(iatCorrection), "NaN iatCorrection", 0); - efiAssert(CUSTOM_ERR_ASSERT, !cisnan(cltCorrection), "NaN cltCorrection", 0); - efiAssert(CUSTOM_ERR_ASSERT, !cisnan(postCrankingFuelCorrection), "NaN postCrankingFuelCorrection", 0); + efiAssert(ObdCode::CUSTOM_ERR_ASSERT, !cisnan(iatCorrection), "NaN iatCorrection", 0); + efiAssert(ObdCode::CUSTOM_ERR_ASSERT, !cisnan(cltCorrection), "NaN cltCorrection", 0); + efiAssert(ObdCode::CUSTOM_ERR_ASSERT, !cisnan(postCrankingFuelCorrection), "NaN postCrankingFuelCorrection", 0); float correction = baroCorrection * iatCorrection * cltCorrection * postCrankingFuelCorrection; @@ -143,7 +143,7 @@ float getRunningFuel(float baseFuel) { float runningFuel = baseFuel * correction; - efiAssert(CUSTOM_ERR_ASSERT, !cisnan(runningFuel), "NaN runningFuel", 0); + efiAssert(ObdCode::CUSTOM_ERR_ASSERT, !cisnan(runningFuel), "NaN runningFuel", 0); engine->fuelComputer.running.fuel = runningFuel * 1000; @@ -166,7 +166,7 @@ AirmassModelBase* getAirmassModel(engine_load_mode_e mode) { case LM_MOCK: return engine->mockAirmassModel; #endif default: - firmwareError(CUSTOM_ERR_ASSERT, "Invalid airmass mode %d", engineConfiguration->fuelAlgorithm); + firmwareError(ObdCode::CUSTOM_ERR_ASSERT, "Invalid airmass mode %d", engineConfiguration->fuelAlgorithm); return nullptr; } } @@ -177,7 +177,7 @@ static float getBaseFuelMass(int rpm) { // airmass modes - get airmass first, then convert to fuel auto model = getAirmassModel(engineConfiguration->fuelAlgorithm); - efiAssert(CUSTOM_ERR_ASSERT, model != nullptr, "Invalid airmass mode", 0.0f); + efiAssert(ObdCode::CUSTOM_ERR_ASSERT, model != nullptr, "Invalid airmass mode", 0.0f); auto airmass = model->getAirmass(rpm); @@ -224,12 +224,12 @@ angle_t getInjectionOffset(float rpm, float load) { if (cisnan(value)) { // we could be here while resetting configuration for example // huh? what? when do we have RPM while resetting configuration? is that CI edge case? shall we fix CI? - warning(CUSTOM_ERR_6569, "phase map not ready"); + warning(ObdCode::CUSTOM_ERR_6569, "phase map not ready"); return 0; } angle_t result = value; - fixAngle(result, "inj offset#2", CUSTOM_ERR_6553); + fixAngle(result, "inj offset#2", ObdCode::CUSTOM_ERR_6553); return result; } @@ -247,7 +247,7 @@ int getNumberOfInjections(injection_mode_e mode) { case IM_SEQUENTIAL: return 1; default: - firmwareError(CUSTOM_ERR_INVALID_INJECTION_MODE, "Unexpected injection_mode_e %d", mode); + firmwareError(ObdCode::CUSTOM_ERR_INVALID_INJECTION_MODE, "Unexpected injection_mode_e %d", mode); return 1; } } @@ -272,7 +272,7 @@ float getInjectionModeDurationMultiplier() { case IM_BATCH: return 0.5f; default: - firmwareError(CUSTOM_ERR_INVALID_INJECTION_MODE, "Unexpected injection_mode_e %d", mode); + firmwareError(ObdCode::CUSTOM_ERR_INVALID_INJECTION_MODE, "Unexpected injection_mode_e %d", mode); return 0; } } @@ -308,7 +308,7 @@ float getInjectionMass(int rpm) { bool isCranking = engine->rpmCalculator.isCranking(); float cycleFuelMass = getCycleFuelMass(isCranking, baseFuelMass); - efiAssert(CUSTOM_ERR_ASSERT, !cisnan(cycleFuelMass), "NaN cycleFuelMass", 0); + efiAssert(ObdCode::CUSTOM_ERR_ASSERT, !cisnan(cycleFuelMass), "NaN cycleFuelMass", 0); if (engine->module()->cutFuel()) { // If decel fuel cut, zero out fuel @@ -322,7 +322,7 @@ float getInjectionMass(int rpm) { engine->module()->prepare(); floatms_t tpsAccelEnrich = engine->tpsAccelEnrichment.getTpsEnrichment(); - efiAssert(CUSTOM_ERR_ASSERT, !cisnan(tpsAccelEnrich), "NaN tpsAccelEnrich", 0); + efiAssert(ObdCode::CUSTOM_ERR_ASSERT, !cisnan(tpsAccelEnrich), "NaN tpsAccelEnrich", 0); engine->engineState.tpsAccelEnrich = tpsAccelEnrich; // For legacy reasons, the TPS accel table is in units of milliseconds, so we have to convert BACK to mass @@ -387,7 +387,7 @@ float getBaroCorrection() { ); if (cisnan(correction) || correction < 0.01) { - warning(OBD_Barometric_Press_Circ_Range_Perf, "Invalid baro correction %f", correction); + warning(ObdCode::OBD_Barometric_Press_Circ_Range_Perf, "Invalid baro correction %f", correction); return 1; } diff --git a/firmware/controllers/algo/gear_detector.cpp b/firmware/controllers/algo/gear_detector.cpp index ab5412b182..95d87ebfba 100644 --- a/firmware/controllers/algo/gear_detector.cpp +++ b/firmware/controllers/algo/gear_detector.cpp @@ -15,14 +15,14 @@ void GearDetector::onConfigurationChange(engine_configuration_s const * /*previo } if (gearCount > GEARS_COUNT) { - firmwareError(OBD_PCM_Processor_Fault, "too many gears"); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "too many gears"); return; } // validate gears for (size_t i = 0; i < gearCount; i++) { if (engineConfiguration->gearRatio[i] <= 0) { - firmwareError(OBD_PCM_Processor_Fault, "Invalid gear ratio for #%d", i + 1); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "Invalid gear ratio for #%d", i + 1); return; } } @@ -33,7 +33,7 @@ void GearDetector::onConfigurationChange(engine_configuration_s const * /*previo float gearIplusOne = engineConfiguration->gearRatio[i + 1]; if (gearI <= gearIplusOne) { - firmwareError(OBD_PCM_Processor_Fault, "Invalid gear ordering near gear #%d", i + 1); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "Invalid gear ordering near gear #%d", i + 1); } m_gearThresholds[i] = geometricMean(gearI, gearIplusOne); diff --git a/firmware/controllers/algo/obd_error_codes.h b/firmware/controllers/algo/obd_error_codes.h index 7ac4ef92f7..4eeb6c0e6d 100644 --- a/firmware/controllers/algo/obd_error_codes.h +++ b/firmware/controllers/algo/obd_error_codes.h @@ -10,15 +10,10 @@ #pragma once -// this header should not depend on anything - actually chconf.h usually depends on this header +#include -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - -typedef enum { - OBD_None = 0, +enum class ObdCode : uint32_t { + None = 0, //P0001 Fuel Volume Regulator Control Circuit/Open //P0002 Fuel Volume Regulator Control Circuit Range/Performance //P0003 Fuel Volume Regulator Control Circuit Low @@ -2069,7 +2064,7 @@ typedef enum { CUSTOM_VVT_SYNC_POSITION = 6675, CUSTOM_STACK_ADC = 6676, CUSTOM_IH_STACK = 6677, - CUSTOM_EC_NULL = 6678, + CUSTOM_ERR_6678 = 6678, CUSTOM_ERR6679 = 6679, CUSTOM_ERR_ANGLE_CR = 6680, @@ -2120,7 +2115,7 @@ typedef enum { CUSTOM_NO_ETB_FOR_IDLE = 6723, CUSTOM_ERR_TLE8888_RESPONSE = 6724, CUSTOM_ERR_CJ125_DIAG = 6725, - NO_LONGER_USED_CUSTOM_ERR_VVT_OUT_OF_RANGE = 6726, + CUSTOM_6726 = 6726, CUSTOM_VVT_MODE_NOT_SELECTED = 6727, CUSTOM_ERR_6728 = 6728, CUSTOM_ARTIFICIAL_MISFIRE = 6729, @@ -2139,7 +2134,7 @@ typedef enum { WATCH_DOG_SECONDS = 8901, - CUSTOM_ERR_CUSTOM_GAPS_BAD = 8999, + CUSTOM_ERR_CUSTOM_GAPS_BAD = 8999, CUSTOM_ERR_TRIGGER_SYNC = 9000, CUSTOM_OBD_TRIGGER_WAVEFORM = 9001, @@ -2174,17 +2169,4 @@ typedef enum { * Commanded fuel exceeds your fuel injector flow */ CUSTOM_TOO_LONG_FUEL_INJECTION = 9013, - - - - -// Back in the day we wanted enums to be 32 bit integers. -// as of 2020 preference is with ' __attribute__ ((__packed__))' allowing one-byte enums - // this is needed for proper enum size, this matters for malfunction_central - Internal_ForceMyEnumIntSize_cranking_obd_code = 2000000000, -} ObdCode; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - +}; diff --git a/firmware/controllers/bench_test.cpp b/firmware/controllers/bench_test.cpp index 6c1d1aa589..62d1213ba2 100644 --- a/firmware/controllers/bench_test.cpp +++ b/firmware/controllers/bench_test.cpp @@ -83,7 +83,7 @@ static void runBench(brain_pin_e brainPin, OutputPin *output, float startDelayMs int offTimeUs = MS2US(maxF(0.1, offTimeMs)); if (onTimeUs > TOO_FAR_INTO_FUTURE_US) { - firmwareError(CUSTOM_ERR_BENCH_PARAM, "onTime above limit %dus", TOO_FAR_INTO_FUTURE_US); + firmwareError(ObdCode::CUSTOM_ERR_BENCH_PARAM, "onTime above limit %dus", TOO_FAR_INTO_FUTURE_US); return; } @@ -280,7 +280,7 @@ private: UNUSED(nowNt); setPeriod(50 /* ms */); - validateStack("Bench", STACK_USAGE_BENCH, 128); + validateStack("Bench", ObdCode::STACK_USAGE_BENCH, 128); // naive inter-thread communication - waiting for a flag if (isBenchTestPending) { @@ -334,7 +334,7 @@ static void handleBenchCategory(uint16_t index) { fan2Bench(); return; default: - firmwareError(OBD_PCM_Processor_Fault, "Unexpected bench function %d", index); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "Unexpected bench function %d", index); } } @@ -412,7 +412,7 @@ static void handleCommandX14(uint16_t index) { sys_dual_bank(); rebootNow(); #else - firmwareError(OBD_PCM_Processor_Fault, "Unexpected dbank command", index); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "Unexpected dbank command", index); #endif return; case 0x15: @@ -422,7 +422,7 @@ static void handleCommandX14(uint16_t index) { #endif // EFI_PROD_CODE return; default: - firmwareError(OBD_PCM_Processor_Fault, "Unexpected bench x14 %d", index); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "Unexpected bench x14 %d", index); } } @@ -430,7 +430,7 @@ extern bool rebootForPresetPending; static void fatalErrorForPresetApply() { rebootForPresetPending = true; - firmwareError(OBD_PCM_Processor_Fault, + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "\n\nTo complete preset apply:\n" " 1. Close TunerStudio\n" " 2. Power cycle ECU\n" @@ -526,7 +526,7 @@ void executeTSCommand(uint16_t subsystem, uint16_t index) { #endif default: - firmwareError(OBD_PCM_Processor_Fault, "Unexpected bench subsystem %d %d", subsystem, index); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "Unexpected bench subsystem %d %d", subsystem, index); } } diff --git a/firmware/controllers/can/can_dash.cpp b/firmware/controllers/can/can_dash.cpp index 72c12ebcb7..9bbd5d1d25 100644 --- a/firmware/controllers/can/can_dash.cpp +++ b/firmware/controllers/can/can_dash.cpp @@ -170,7 +170,7 @@ void updateDash(CanCycle cycle) { canDashboardAim(cycle); break; default: - firmwareError(OBD_PCM_Processor_Fault, "Nothing for canNbcType %s", getCan_nbc_e(engineConfiguration->canNbcType)); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "Nothing for canNbcType %s", getCan_nbc_e(engineConfiguration->canNbcType)); break; } } diff --git a/firmware/controllers/can/can_verbose.cpp b/firmware/controllers/can/can_verbose.cpp index 65b522a77b..14690369cb 100644 --- a/firmware/controllers/can/can_verbose.cpp +++ b/firmware/controllers/can/can_verbose.cpp @@ -39,7 +39,7 @@ struct Status { static void populateFrame(Status& msg) { msg.warningCounter = engine->engineState.warnings.warningCounter; - msg.lastErrorCode = engine->engineState.warnings.lastErrorCode; + msg.lastErrorCode = static_cast(engine->engineState.warnings.lastErrorCode); msg.revLimit = Sensor::getOrZero(SensorType::Rpm) > engineConfiguration->rpmHardLimit; msg.mainRelay = enginePins.mainRelay.getLogicValue(); diff --git a/firmware/controllers/can/can_vss.cpp b/firmware/controllers/can/can_vss.cpp index be8dfaad42..959c5ed60d 100644 --- a/firmware/controllers/can/can_vss.cpp +++ b/firmware/controllers/can/can_vss.cpp @@ -26,7 +26,7 @@ expected look_up_can_id(can_vss_nbc_e type) { case LUA: return 0; // a bit of a hack default: - firmwareError(OBD_Vehicle_Speed_SensorB, "Wrong Can DBC selected: %d", type); + firmwareError(ObdCode::OBD_Vehicle_Speed_SensorB, "Wrong Can DBC selected: %d", type); return unexpected; } } diff --git a/firmware/controllers/can/obd2.cpp b/firmware/controllers/can/obd2.cpp index a5762a3ef0..1a07947839 100644 --- a/firmware/controllers/can/obd2.cpp +++ b/firmware/controllers/can/obd2.cpp @@ -76,7 +76,7 @@ static void obdSendPacket(int mode, int PID, int numBytes, uint32_t iValue, size #define _1_MODE 1 static void obdSendValue(int mode, int PID, int numBytes, float value, size_t busIndex) { - efiAssertVoid(CUSTOM_ERR_6662, numBytes <= 2, "invalid numBytes"); + efiAssertVoid(ObdCode::CUSTOM_ERR_6662, numBytes <= 2, "invalid numBytes"); int iValue = (int)efiRound(value, 1.0f); // clamp to uint8_t (0..255) or uint16_t (0..65535) iValue = maxI(minI(iValue, (numBytes == 1) ? 255 : 65535), 0); @@ -174,7 +174,7 @@ static void handleGetDataRequest(const CANRxFrame& rx, size_t busIndex) { } } -static void handleDtcRequest(int numCodes, int *dtcCode) { +static void handleDtcRequest(int numCodes, ObdCode* dtcCode) { // TODO: this appears to be unfinished? UNUSED(numCodes); UNUSED(dtcCode); diff --git a/firmware/controllers/can/rusefi_wideband.cpp b/firmware/controllers/can/rusefi_wideband.cpp index 0c313bd58f..f2c3674ef3 100644 --- a/firmware/controllers/can/rusefi_wideband.cpp +++ b/firmware/controllers/can/rusefi_wideband.cpp @@ -124,7 +124,7 @@ void setWidebandOffset(uint8_t index) { } if (!waitAck()) { - firmwareError(OBD_PCM_Processor_Fault, "Wideband index set failed: no controller detected!"); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "Wideband index set failed: no controller detected!"); } waitingBootloaderThread = nullptr; diff --git a/firmware/controllers/core/error_handling.cpp b/firmware/controllers/core/error_handling.cpp index 673d224a5c..584dedda6a 100644 --- a/firmware/controllers/core/error_handling.cpp +++ b/firmware/controllers/core/error_handling.cpp @@ -94,7 +94,7 @@ void chDbgPanic3(const char *msg, const char * file, int line) { exit(-1); #else // EFI_PROD_CODE - firmwareError(OBD_PCM_Processor_Fault, "assert fail %s %s:%d", msg, file, line); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "assert fail %s %s:%d", msg, file, line); // If on the main thread, longjmp back to the init process so we can keep USB alive if (chThdGetSelfX()->threadId == 0) { @@ -123,7 +123,7 @@ WarningCodeState unitTestWarningCodeState; #endif /* EFI_SIMULATOR || EFI_PROD_CODE */ /** - * OBD_PCM_Processor_Fault is the general error code for now + * ObdCode::OBD_PCM_Processor_Fault is the general error code for now * * @returns TRUE in case there were warnings recently */ diff --git a/firmware/controllers/core/state_sequence.cpp b/firmware/controllers/core/state_sequence.cpp index fc7a121c66..1295d94f9f 100644 --- a/firmware/controllers/core/state_sequence.cpp +++ b/firmware/controllers/core/state_sequence.cpp @@ -10,7 +10,7 @@ #include "trigger_structure.h" void MultiChannelStateSequence::checkSwitchTimes(const float scale) const { - efiAssertVoid(CUSTOM_ERR_WAVE_1, phaseCount > 0, "StateSequence cannot be empty"); + efiAssertVoid(ObdCode::CUSTOM_ERR_WAVE_1, phaseCount > 0, "StateSequence cannot be empty"); if (getSwitchTime(phaseCount - 1) != 1) { #if EFI_UNIT_TEST for (int index = 0;index < phaseCount;index ++) { @@ -18,7 +18,7 @@ void MultiChannelStateSequence::checkSwitchTimes(const float scale) const { } #endif // EFI_UNIT_TEST - firmwareError(CUSTOM_ERR_WAVE_1, "[count=%d] last switch time has to be 1/%f not %.2f/%f", + firmwareError(ObdCode::CUSTOM_ERR_WAVE_1, "[count=%d] last switch time has to be 1/%f not %.2f/%f", phaseCount, scale, getSwitchTime(phaseCount - 1), scale * getSwitchTime(phaseCount - 1)); @@ -26,7 +26,7 @@ void MultiChannelStateSequence::checkSwitchTimes(const float scale) const { } for (int i = 0; i < phaseCount - 1; i++) { if (getSwitchTime(i) >= getSwitchTime(i + 1)) { - firmwareError(CUSTOM_ERR_WAVE_2, "invalid switchTimes @%d: %.2f/%.2f", + firmwareError(ObdCode::CUSTOM_ERR_WAVE_2, "invalid switchTimes @%d: %.2f/%.2f", i, getSwitchTime(i), getSwitchTime(i + 1)); } } diff --git a/firmware/controllers/core/state_sequence.h b/firmware/controllers/core/state_sequence.h index 8c5039882c..20a11f573f 100644 --- a/firmware/controllers/core/state_sequence.h +++ b/firmware/controllers/core/state_sequence.h @@ -81,7 +81,7 @@ public: pin_state_t getChannelState(int channelIndex, int phaseIndex) const override { if (channelIndex >= waveCount) { // todo: would be nice to get this asserting working - //firmwareError(OBD_PCM_Processor_Fault, "channel index %d/%d", channelIndex, waveCount); + //firmwareError(ObdCode::OBD_PCM_Processor_Fault, "channel index %d/%d", channelIndex, waveCount); } return ((waveForm[phaseIndex] >> channelIndex) & 1) ? TriggerValue::RISE : TriggerValue::FALL; } @@ -97,7 +97,7 @@ public: void setChannelState(const int channelIndex, const int phaseIndex, pin_state_t state) { if (channelIndex >= waveCount) { // todo: would be nice to get this asserting working - //firmwareError(OBD_PCM_Processor_Fault, "channel index %d/%d", channelIndex, waveCount); + //firmwareError(ObdCode::OBD_PCM_Processor_Fault, "channel index %d/%d", channelIndex, waveCount); } uint8_t & ref = waveForm[phaseIndex]; ref = (ref & ~(1U << channelIndex)) | ((state == TriggerValue::RISE ? 1 : 0) << channelIndex); diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index 1bb9838a42..012ec3f9d4 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -176,7 +176,7 @@ static void resetAccel() { static void doPeriodicSlowCallback() { #if EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT - efiAssertVoid(CUSTOM_ERR_6661, getCurrentRemainingStack() > 64, "lowStckOnEv"); + efiAssertVoid(ObdCode::CUSTOM_ERR_6661, getCurrentRemainingStack() > 64, "lowStckOnEv"); slowStartStopButtonCallback(); @@ -490,7 +490,7 @@ void commonInitEngineController() { // Returns false if there's an obvious problem with the loaded configuration bool validateConfig() { if (engineConfiguration->cylindersCount > MAX_CYLINDER_COUNT) { - firmwareError(OBD_PCM_Processor_Fault, "Invalid cylinder count: %d", engineConfiguration->cylindersCount); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "Invalid cylinder count: %d", engineConfiguration->cylindersCount); return false; } diff --git a/firmware/controllers/engine_cycle/fuel_schedule.cpp b/firmware/controllers/engine_cycle/fuel_schedule.cpp index 37dfc47056..e54bfc163f 100644 --- a/firmware/controllers/engine_cycle/fuel_schedule.cpp +++ b/firmware/controllers/engine_cycle/fuel_schedule.cpp @@ -55,11 +55,11 @@ static float getInjectionAngleCorrection(float fuelMs, float oneDegreeUs) { return 0; } - efiAssert(CUSTOM_ERR_ASSERT, !cisnan(fuelMs), "NaN fuelMs", false); + efiAssert(ObdCode::CUSTOM_ERR_ASSERT, !cisnan(fuelMs), "NaN fuelMs", false); angle_t injectionDurationAngle = MS2US(fuelMs) / oneDegreeUs; - efiAssert(CUSTOM_ERR_ASSERT, !cisnan(injectionDurationAngle), "NaN injectionDurationAngle", false); - assertAngleRange(injectionDurationAngle, "injectionDuration_r", CUSTOM_INJ_DURATION); + efiAssert(ObdCode::CUSTOM_ERR_ASSERT, !cisnan(injectionDurationAngle), "NaN injectionDurationAngle", false); + assertAngleRange(injectionDurationAngle, "injectionDuration_r", ObdCode::CUSTOM_INJ_DURATION); if (mode == InjectionTimingMode::Center) { // Center of injection is half-corrected for duration @@ -96,15 +96,15 @@ expected InjectionEvent::computeInjectionAngle(int cylinderIndex) const { } angle_t openingAngle = injectionOffset - injectionDurationAngle; - assertAngleRange(openingAngle, "openingAngle_r", CUSTOM_ERR_6554); + assertAngleRange(openingAngle, "openingAngle_r", ObdCode::CUSTOM_ERR_6554); // Convert from cylinder-relative to cylinder-1-relative openingAngle += getPerCylinderFiringOrderOffset(cylinderIndex, cylinderNumber); - efiAssert(CUSTOM_ERR_ASSERT, !cisnan(openingAngle), "findAngle#3", false); - assertAngleRange(openingAngle, "findAngle#a33", CUSTOM_ERR_6544); + efiAssert(ObdCode::CUSTOM_ERR_ASSERT, !cisnan(openingAngle), "findAngle#3", false); + assertAngleRange(openingAngle, "findAngle#a33", ObdCode::CUSTOM_ERR_6544); - wrapAngle2(openingAngle, "addFuel#2", CUSTOM_ERR_6555, getEngineCycle(getEngineRotationState()->getOperationMode())); + wrapAngle2(openingAngle, "addFuel#2", ObdCode::CUSTOM_ERR_6555, getEngineCycle(getEngineRotationState()->getOperationMode())); #if EFI_UNIT_TEST printf("registerInjectionEvent openingAngle=%.2f inj %d\r\n", openingAngle, cylinderNumber); @@ -155,7 +155,7 @@ bool FuelSchedule::addFuelEventsForCylinder(int i) { // Loop over the first half of the firing order twice injectorIndex = i % (engineConfiguration->cylindersCount / 2); } else { - firmwareError(CUSTOM_OBD_UNEXPECTED_INJECTION_MODE, "Unexpected injection mode %d", mode); + firmwareError(ObdCode::CUSTOM_OBD_UNEXPECTED_INJECTION_MODE, "Unexpected injection mode %d", mode); injectorIndex = 0; } diff --git a/firmware/controllers/engine_cycle/high_pressure_fuel_pump.cpp b/firmware/controllers/engine_cycle/high_pressure_fuel_pump.cpp index 1f9cf51cce..93a171c0bb 100644 --- a/firmware/controllers/engine_cycle/high_pressure_fuel_pump.cpp +++ b/firmware/controllers/engine_cycle/high_pressure_fuel_pump.cpp @@ -162,7 +162,7 @@ void HpfpController::onFastCallback() { m_deadtime = 0; } else { #if EFI_PROD_CODE && EFI_SHAFT_POSITION_INPUT - efiAssertVoid(OBD_PCM_Processor_Fault, engine->triggerCentral.triggerShape.getSize() > engineConfiguration->hpfpCamLobes * 6, "Too few trigger tooth for this number of HPFP lobes"); + efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, engine->triggerCentral.triggerShape.getSize() > engineConfiguration->hpfpCamLobes * 6, "Too few trigger tooth for this number of HPFP lobes"); #endif // EFI_PROD_CODE // Convert deadtime from ms to degrees based on current RPM float deadtime_ms = interpolate2d( diff --git a/firmware/controllers/engine_cycle/main_trigger_callback.cpp b/firmware/controllers/engine_cycle/main_trigger_callback.cpp index 1bb2060126..2547793928 100644 --- a/firmware/controllers/engine_cycle/main_trigger_callback.cpp +++ b/firmware/controllers/engine_cycle/main_trigger_callback.cpp @@ -103,7 +103,7 @@ void InjectionEvent::onTriggerTooth(int rpm, efitick_t nowNt, float currentPhase */ int numberOfInjections = isCranking ? getNumberOfInjections(engineConfiguration->crankingInjectionMode) : getNumberOfInjections(engineConfiguration->injectionMode); if (injectionDuration * numberOfInjections > getEngineCycleDuration(rpm)) { - warning(CUSTOM_TOO_LONG_FUEL_INJECTION, "Too long fuel injection %.2fms", injectionDuration); + warning(ObdCode::CUSTOM_TOO_LONG_FUEL_INJECTION, "Too long fuel injection %.2fms", injectionDuration); } getEngineState()->fuelConsumption.consumeFuel(injectionMassGrams * numberOfInjections, nowNt); @@ -113,11 +113,11 @@ void InjectionEvent::onTriggerTooth(int rpm, efitick_t nowNt, float currentPhase } if (cisnan(injectionDuration)) { - warning(CUSTOM_OBD_NAN_INJECTION, "NaN injection pulse"); + warning(ObdCode::CUSTOM_OBD_NAN_INJECTION, "NaN injection pulse"); return; } if (injectionDuration < 0) { - warning(CUSTOM_OBD_NEG_INJECTION, "Negative injection pulse %.2f", injectionDuration); + warning(ObdCode::CUSTOM_OBD_NEG_INJECTION, "Negative injection pulse %.2f", injectionDuration); return; } @@ -141,7 +141,7 @@ void InjectionEvent::onTriggerTooth(int rpm, efitick_t nowNt, float currentPhase if (engine->prevOutputName == outputName && engineConfiguration->injectionMode != IM_SIMULTANEOUS && engineConfiguration->injectionMode != IM_SINGLE_POINT) { - warning(CUSTOM_OBD_SKIPPED_FUEL, "looks like skipped fuel event revCounter=%d %s", getRevolutionCounter(), outputName); + warning(ObdCode::CUSTOM_OBD_SKIPPED_FUEL, "looks like skipped fuel event revCounter=%d %s", getRevolutionCounter(), outputName); } engine->prevOutputName = outputName; } @@ -203,7 +203,7 @@ if (isScheduled) { static void handleFuel(int rpm, efitick_t nowNt, float currentPhase, float nextPhase) { ScopePerf perf(PE::HandleFuel); - efiAssertVoid(CUSTOM_STACK_6627, getCurrentRemainingStack() > 128, "lowstck#3"); + efiAssertVoid(ObdCode::CUSTOM_STACK_6627, getCurrentRemainingStack() > 128, "lowstck#3"); LimpState limitedFuelState = getLimpManager()->allowInjection(); @@ -258,7 +258,7 @@ void mainTriggerCallback(uint32_t trgEventIndex, efitick_t edgeTimestamp, angle_ return; } if (rpm == NOISY_RPM) { - warning(OBD_Crankshaft_Position_Sensor_A_Circuit_Malfunction, "noisy trigger"); + warning(ObdCode::OBD_Crankshaft_Position_Sensor_A_Circuit_Malfunction, "noisy trigger"); // TODO: add 'pin shutdown' invocation somewhere - coils might be still open here! return; } diff --git a/firmware/controllers/engine_cycle/map_averaging.cpp b/firmware/controllers/engine_cycle/map_averaging.cpp index 65720c5733..3014709975 100644 --- a/firmware/controllers/engine_cycle/map_averaging.cpp +++ b/firmware/controllers/engine_cycle/map_averaging.cpp @@ -59,7 +59,7 @@ static void endAveraging(MapAverager* arg); static size_t currentMapAverager = 0; static void startAveraging(scheduling_s *endAveragingScheduling) { - efiAssertVoid(CUSTOM_ERR_6649, getCurrentRemainingStack() > 128, "lowstck#9"); + efiAssertVoid(ObdCode::CUSTOM_ERR_6649, getCurrentRemainingStack() > 128, "lowstck#9"); // TODO: set currentMapAverager based on cylinder bank auto& averager = getMapAvg(currentMapAverager); @@ -114,7 +114,7 @@ void MapAverager::stop() { setValidValue(minPressure, getTimeNowNt()); } else { - warning(CUSTOM_UNEXPECTED_MAP_VALUE, "No MAP values"); + warning(ObdCode::CUSTOM_UNEXPECTED_MAP_VALUE, "No MAP values"); } } @@ -126,13 +126,13 @@ void MapAverager::stop() { * as fast as possible */ void mapAveragingAdcCallback(float instantVoltage) { - efiAssertVoid(CUSTOM_ERR_6650, getCurrentRemainingStack() > 128, "lowstck#9a"); + efiAssertVoid(ObdCode::CUSTOM_ERR_6650, getCurrentRemainingStack() > 128, "lowstck#9a"); SensorResult mapResult = getMapAvg(currentMapAverager).submit(instantVoltage); if (!mapResult) { // hopefully this warning is not too much CPU consumption for fast ADC callback - warning(CUSTOM_INSTANT_MAP_DECODING, "Invalid MAP at %f", instantVoltage); + warning(ObdCode::CUSTOM_INSTANT_MAP_DECODING, "Invalid MAP at %f", instantVoltage); } float instantMap = mapResult.value_or(0); @@ -170,19 +170,19 @@ void refreshMapAveragingPreCalc() { if (isValidRpm(rpm)) { MAP_sensor_config_s * c = &engineConfiguration->map; angle_t start = interpolate2d(rpm, c->samplingAngleBins, c->samplingAngle); - efiAssertVoid(CUSTOM_ERR_MAP_START_ASSERT, !cisnan(start), "start"); + efiAssertVoid(ObdCode::CUSTOM_ERR_MAP_START_ASSERT, !cisnan(start), "start"); angle_t offsetAngle = engine->triggerCentral.triggerFormDetails.eventAngles[engineConfiguration->mapAveragingSchedulingAtIndex]; - efiAssertVoid(CUSTOM_ERR_MAP_AVG_OFFSET, !cisnan(offsetAngle), "offsetAngle"); + efiAssertVoid(ObdCode::CUSTOM_ERR_MAP_AVG_OFFSET, !cisnan(offsetAngle), "offsetAngle"); for (size_t i = 0; i < engineConfiguration->cylindersCount; i++) { angle_t cylinderOffset = getEngineCycle(getEngineRotationState()->getOperationMode()) * i / engineConfiguration->cylindersCount; - efiAssertVoid(CUSTOM_ERR_MAP_CYL_OFFSET, !cisnan(cylinderOffset), "cylinderOffset"); + efiAssertVoid(ObdCode::CUSTOM_ERR_MAP_CYL_OFFSET, !cisnan(cylinderOffset), "cylinderOffset"); // part of this formula related to specific cylinder offset is never changing - we can // move the loop into start-up calculation and not have this loop as part of periodic calculation // todo: change the logic as described above in order to reduce periodic CPU usage? float cylinderStart = start + cylinderOffset - offsetAngle + tdcPosition(); - fixAngle(cylinderStart, "cylinderStart", CUSTOM_ERR_6562); + fixAngle(cylinderStart, "cylinderStart", ObdCode::CUSTOM_ERR_6562); engine->engineState.mapAveragingStart[i] = cylinderStart; } engine->engineState.mapAveragingDuration = interpolate2d(rpm, c->samplingWindowBins, c->samplingWindow); @@ -224,9 +224,9 @@ void mapAveragingTriggerCallback( angle_t samplingDuration = engine->engineState.mapAveragingDuration; // todo: this assertion could be moved out of trigger handler - assertAngleRange(samplingDuration, "samplingDuration", CUSTOM_ERR_6563); + assertAngleRange(samplingDuration, "samplingDuration", ObdCode::CUSTOM_ERR_6563); if (samplingDuration <= 0) { - warning(CUSTOM_MAP_ANGLE_PARAM, "map sampling angle should be positive"); + warning(ObdCode::CUSTOM_MAP_ANGLE_PARAM, "map sampling angle should be positive"); return; } @@ -234,12 +234,12 @@ void mapAveragingTriggerCallback( if (cisnan(samplingEnd)) { // todo: when would this happen? - warning(CUSTOM_ERR_6549, "no map angles"); + warning(ObdCode::CUSTOM_ERR_6549, "no map angles"); return; } // todo: pre-calculate samplingEnd for each cylinder - fixAngle(samplingEnd, "samplingEnd", CUSTOM_ERR_6563); + fixAngle(samplingEnd, "samplingEnd", ObdCode::CUSTOM_ERR_6563); // only if value is already prepared int structIndex = getRevolutionCounter() % 2; diff --git a/firmware/controllers/engine_cycle/rpm_calculator.cpp b/firmware/controllers/engine_cycle/rpm_calculator.cpp index 73a2ec8e4a..7f482199cc 100644 --- a/firmware/controllers/engine_cycle/rpm_calculator.cpp +++ b/firmware/controllers/engine_cycle/rpm_calculator.cpp @@ -378,7 +378,7 @@ void tdcMarkCallback( if (isValidRpm(rpm)) { angle_t tdcPosition = tdcPosition(); // we need a positive angle offset here - fixAngle(tdcPosition, "tdcPosition", CUSTOM_ERR_6553); + fixAngle(tdcPosition, "tdcPosition", ObdCode::CUSTOM_ERR_6553); scheduleByAngle(&engine->tdcScheduler[revIndex2], edgeTimestamp, tdcPosition, onTdcCallback); } } diff --git a/firmware/controllers/flash_main.cpp b/firmware/controllers/flash_main.cpp index 0511835ec2..bee3dbad7a 100644 --- a/firmware/controllers/flash_main.cpp +++ b/firmware/controllers/flash_main.cpp @@ -139,13 +139,13 @@ int eraseAndFlashCopy(flashaddr_t storageAddress, const TStorage& data) { auto err = intFlashErase(storageAddress, sizeof(TStorage)); if (FLASH_RETURN_SUCCESS != err) { - firmwareError(OBD_PCM_Processor_Fault, "Failed to erase flash at 0x%08x: %d", storageAddress, err); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "Failed to erase flash at 0x%08x: %d", storageAddress, err); return err; } err = intFlashWrite(storageAddress, reinterpret_cast(&data), sizeof(TStorage)); if (FLASH_RETURN_SUCCESS != err) { - firmwareError(OBD_PCM_Processor_Fault, "Failed to write flash at 0x%08x: %d", storageAddress, err); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "Failed to write flash at 0x%08x: %d", storageAddress, err); return err; } @@ -312,7 +312,7 @@ void readFromFlash() { switch (result) { case FlashState::CrcFailed: - warning(CUSTOM_ERR_FLASH_CRC_FAILED, "flash CRC failed"); + warning(ObdCode::CUSTOM_ERR_FLASH_CRC_FAILED, "flash CRC failed"); efiPrintf("Need to reset flash to default due to CRC mismatch"); [[fallthrough]]; case FlashState::BlankChip: diff --git a/firmware/controllers/gauges/malfunction_indicator.cpp b/firmware/controllers/gauges/malfunction_indicator.cpp index 76c897e4f3..027058a1e9 100644 --- a/firmware/controllers/gauges/malfunction_indicator.cpp +++ b/firmware/controllers/gauges/malfunction_indicator.cpp @@ -84,7 +84,7 @@ private: void PeriodicTask(efitick_t nowNt) override { UNUSED(nowNt); - validateStack("MIL", STACK_USAGE_MIL, 128); + validateStack("MIL", ObdCode::STACK_USAGE_MIL, 128); #if EFI_SHAFT_POSITION_INPUT if (nowNt - engine->triggerCentral.triggerState.mostRecentSyncTime < MS2NT(500)) { enginePins.checkEnginePin.setValue(1); @@ -97,7 +97,7 @@ private: getErrorCodes(&localErrorCopy); for (int p = 0; p < localErrorCopy.count; p++) { // Calculate how many digits in this integer and display error code from start to end - int code = localErrorCopy.error_codes[p]; + int code = (int)localErrorCopy.error_codes[p]; DisplayErrorCode(DigitLength(code), code); } #endif // EFI_SHAFT_POSITION_INPUT @@ -108,8 +108,8 @@ static MILController instance; #if TEST_MIL_CODE static void testMil() { - addError(OBD_Engine_Coolant_Temperature_Circuit_Malfunction); - addError(OBD_Intake_Air_Temperature_Circuit_Malfunction); + addError(ObdCode::OBD_Engine_Coolant_Temperature_Circuit_Malfunction); + addError(ObdCode::OBD_Intake_Air_Temperature_Circuit_Malfunction); } #endif /* TEST_MIL_CODE */ diff --git a/firmware/controllers/gauges/tachometer.cpp b/firmware/controllers/gauges/tachometer.cpp index b9c2e5a351..615ee13299 100644 --- a/firmware/controllers/gauges/tachometer.cpp +++ b/firmware/controllers/gauges/tachometer.cpp @@ -38,7 +38,7 @@ void tachSignalCallback() { int periods = engineConfiguration->tachPulsePerRev; if (periods == 0 || periods > 10) { - firmwareError(CUSTOM_ERR_6709, "Invalid tachometer pulse per rev: %d", periods); + firmwareError(ObdCode::CUSTOM_ERR_6709, "Invalid tachometer pulse per rev: %d", periods); return; } diff --git a/firmware/controllers/lua/can_filter.cpp b/firmware/controllers/lua/can_filter.cpp index e02a0cc985..9820b6020a 100644 --- a/firmware/controllers/lua/can_filter.cpp +++ b/firmware/controllers/lua/can_filter.cpp @@ -28,7 +28,7 @@ void resetLuaCanRx() { void addLuaCanRxFilter(int32_t eid, uint32_t mask, int bus, int callback) { if (filterCount >= maxFilterCount) { - firmwareError(OBD_PCM_Processor_Fault, "Too many Lua CAN RX filters"); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "Too many Lua CAN RX filters"); } efiPrintf("Added Lua CAN RX filter id 0x%x mask 0x%x with%s custom function", eid, mask, (callback == -1 ? "out" : "")); diff --git a/firmware/controllers/lua/lua.cpp b/firmware/controllers/lua/lua.cpp index 2c25e06222..dc3b76cc97 100644 --- a/firmware/controllers/lua/lua.cpp +++ b/firmware/controllers/lua/lua.cpp @@ -47,7 +47,7 @@ public: } void reinit(char *buffer, size_t size) { - efiAssertVoid(OBD_PCM_Processor_Fault, m_memoryUsed == 0, "Too late to reinit Lua heap"); + efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, m_memoryUsed == 0, "Too late to reinit Lua heap"); m_size = size; m_buffer = buffer; @@ -161,13 +161,13 @@ static LuaHandle setupLuaState(lua_Alloc alloc) { LuaHandle ls = lua_newstate(alloc, NULL); if (!ls) { - firmwareError(OBD_PCM_Processor_Fault, "Failed to start Lua interpreter"); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "Failed to start Lua interpreter"); return nullptr; } lua_atpanic(ls, [](lua_State* l) { - firmwareError(OBD_PCM_Processor_Fault, "Lua panic: %s", lua_tostring(l, -1)); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "Lua panic: %s", lua_tostring(l, -1)); // hang the lua thread while (true) ; diff --git a/firmware/controllers/lua/lua_can_rx.cpp b/firmware/controllers/lua/lua_can_rx.cpp index 22dd35e1ac..4a89fe02bd 100644 --- a/firmware/controllers/lua/lua_can_rx.cpp +++ b/firmware/controllers/lua/lua_can_rx.cpp @@ -122,7 +122,7 @@ bool doOneLuaCanRx(LuaHandle& ls) { // We're done, return this frame to the free list msg = freeBuffers.post(data, TIME_IMMEDIATE); - efiAssert(OBD_PCM_Processor_Fault, msg == MSG_OK, "lua can post to free buffer fail", false); + efiAssert(ObdCode::OBD_PCM_Processor_Fault, msg == MSG_OK, "lua can post to free buffer fail", false); // We processed a frame so we should check again return true; diff --git a/firmware/controllers/math/speed_density.cpp b/firmware/controllers/math/speed_density.cpp index 4cc099fe97..48a6dd54b6 100644 --- a/firmware/controllers/math/speed_density.cpp +++ b/firmware/controllers/math/speed_density.cpp @@ -66,7 +66,7 @@ float IFuelComputer::getTChargeCoefficient(int rpm, float tps) { engineConfiguration->tchargeValues ); } else { - firmwareError(OBD_PCM_Processor_Fault, "Unexpected tChargeMode: %d", engineConfiguration->tChargeMode); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "Unexpected tChargeMode: %d", engineConfiguration->tChargeMode); return 0; } } @@ -98,7 +98,7 @@ temperature_t IFuelComputer::getTCharge(int rpm, float tps) { sdTcharge_coff = getTChargeCoefficient(rpm, tps); if (cisnan(sdTcharge_coff)) { - warning(CUSTOM_ERR_T2_CHARGE, "t2-getTCharge NaN"); + warning(ObdCode::CUSTOM_ERR_T2_CHARGE, "t2-getTCharge NaN"); return coolantTemp; } @@ -109,7 +109,7 @@ temperature_t IFuelComputer::getTCharge(int rpm, float tps) { if (cisnan(Tcharge)) { // we can probably end up here while resetting engine state - interpolation would fail - warning(CUSTOM_ERR_TCHARGE_NOT_READY, "getTCharge NaN"); + warning(ObdCode::CUSTOM_ERR_TCHARGE_NOT_READY, "getTCharge NaN"); return coolantTemp; } diff --git a/firmware/controllers/sensors/core/sensor.cpp b/firmware/controllers/sensors/core/sensor.cpp index 7a3596416f..12b4f10fcf 100644 --- a/firmware/controllers/sensors/core/sensor.cpp +++ b/firmware/controllers/sensors/core/sensor.cpp @@ -37,7 +37,7 @@ public: // If there's somebody already here - a consumer tried to double-register a sensor if (m_sensor && m_sensor != sensor) { // This sensor has already been registered. Don't re-register it. - firmwareError(CUSTOM_OBD_26, "Duplicate registration for sensor \"%s\"", sensor->getSensorName()); + firmwareError(ObdCode::CUSTOM_OBD_26, "Duplicate registration for sensor \"%s\"", sensor->getSensorName()); return false; } else { // Put the sensor in the registry diff --git a/firmware/controllers/sensors/impl/AemXSeriesLambda.cpp b/firmware/controllers/sensors/impl/AemXSeriesLambda.cpp index 5cd055d64d..255b347b14 100644 --- a/firmware/controllers/sensors/impl/AemXSeriesLambda.cpp +++ b/firmware/controllers/sensors/impl/AemXSeriesLambda.cpp @@ -85,7 +85,7 @@ void AemXSeriesWideband::decodeRusefiStandard(const CANRxFrame& frame, efitick_t auto data = reinterpret_cast(&frame.data8[0]); if (data->Version != RUSEFI_WIDEBAND_VERSION) { - firmwareError(OBD_WB_FW_Mismatch, "Wideband controller index %d has wrong firmware version, please update!", m_sensorIndex); + firmwareError(ObdCode::OBD_WB_FW_Mismatch, "Wideband controller index %d has wrong firmware version, please update!", m_sensorIndex); return; } @@ -117,7 +117,7 @@ void AemXSeriesWideband::decodeRusefiDiag(const CANRxFrame& frame) { faultCode = static_cast(data->Status); if (data->Status != wbo::Fault::None) { - auto code = m_sensorIndex == 0 ? Wideband_1_Fault : Wideband_2_Fault; + auto code = m_sensorIndex == 0 ? ObdCode::Wideband_1_Fault : ObdCode::Wideband_2_Fault; warning(code, "Wideband #%d fault: %s", (m_sensorIndex + 1), wbo::describeFault(data->Status)); } } diff --git a/firmware/controllers/sensors/impl/ego.cpp b/firmware/controllers/sensors/impl/ego.cpp index 86dbc26d2e..3b7f69de10 100644 --- a/firmware/controllers/sensors/impl/ego.cpp +++ b/firmware/controllers/sensors/impl/ego.cpp @@ -163,7 +163,7 @@ static void initEgoSensor(afr_sensor_s *sensor, ego_sensor_e type) { sensor->value2 = 14; break; default: - firmwareError(CUSTOM_EGO_TYPE, "Unexpected EGO %d", type); + firmwareError(ObdCode::CUSTOM_EGO_TYPE, "Unexpected EGO %d", type); break; } } diff --git a/firmware/controllers/sensors/impl/map.cpp b/firmware/controllers/sensors/impl/map.cpp index 45dd498aa6..234a7c09dc 100644 --- a/firmware/controllers/sensors/impl/map.cpp +++ b/firmware/controllers/sensors/impl/map.cpp @@ -17,7 +17,7 @@ static float validateBaroMap(float mapKPa) { // Highest interstate is the Eisenhower Tunnel at 11158 feet -> 66 kpa // Lowest point is the Dead Sea, -1411 feet -> 106 kpa if (cisnan(mapKPa) || mapKPa > 110 || mapKPa < 60) { - warning(OBD_Barometric_Press_Circ, "Invalid start-up baro pressure = %.2fkPa", mapKPa); + warning(ObdCode::OBD_Barometric_Press_Circ, "Invalid start-up baro pressure = %.2fkPa", mapKPa); return NAN; } return mapKPa; diff --git a/firmware/controllers/sensors/sensor_checker.cpp b/firmware/controllers/sensors/sensor_checker.cpp index d3ffc6a83a..e7eefdf4bd 100644 --- a/firmware/controllers/sensors/sensor_checker.cpp +++ b/firmware/controllers/sensors/sensor_checker.cpp @@ -6,86 +6,86 @@ static ObdCode getCode(SensorType type, UnexpectedCode code) { case SensorType::Tps1: case SensorType::Tps1Primary: switch (code) { - case UnexpectedCode::Timeout: return OBD_TPS1_Primary_Timeout; - case UnexpectedCode::Low: return OBD_TPS1_Primary_Low; - case UnexpectedCode::High: return OBD_TPS1_Primary_High; - case UnexpectedCode::Inconsistent: return OBD_TPS1_Correlation; + case UnexpectedCode::Timeout: return ObdCode::OBD_TPS1_Primary_Timeout; + case UnexpectedCode::Low: return ObdCode::OBD_TPS1_Primary_Low; + case UnexpectedCode::High: return ObdCode::OBD_TPS1_Primary_High; + case UnexpectedCode::Inconsistent: return ObdCode::OBD_TPS1_Correlation; default: break; } break; case SensorType::Tps1Secondary: switch (code) { - case UnexpectedCode::Timeout: return OBD_TPS1_Secondary_Timeout; - case UnexpectedCode::Low: return OBD_TPS1_Secondary_Low; - case UnexpectedCode::High: return OBD_TPS1_Secondary_High; + case UnexpectedCode::Timeout: return ObdCode::OBD_TPS1_Secondary_Timeout; + case UnexpectedCode::Low: return ObdCode::OBD_TPS1_Secondary_Low; + case UnexpectedCode::High: return ObdCode::OBD_TPS1_Secondary_High; default: break; } break; case SensorType::Tps2: case SensorType::Tps2Primary: switch (code) { - case UnexpectedCode::Timeout: return OBD_TPS2_Primary_Timeout; - case UnexpectedCode::Low: return OBD_TPS2_Primary_Low; - case UnexpectedCode::High: return OBD_TPS2_Primary_High; - case UnexpectedCode::Inconsistent: return OBD_TPS2_Correlation; + case UnexpectedCode::Timeout: return ObdCode::OBD_TPS2_Primary_Timeout; + case UnexpectedCode::Low: return ObdCode::OBD_TPS2_Primary_Low; + case UnexpectedCode::High: return ObdCode::OBD_TPS2_Primary_High; + case UnexpectedCode::Inconsistent: return ObdCode::OBD_TPS2_Correlation; default: break; } break; case SensorType::Tps2Secondary: switch (code) { - case UnexpectedCode::Timeout: return OBD_TPS2_Secondary_Timeout; - case UnexpectedCode::Low: return OBD_TPS2_Secondary_Low; - case UnexpectedCode::High: return OBD_TPS2_Secondary_High; + case UnexpectedCode::Timeout: return ObdCode::OBD_TPS2_Secondary_Timeout; + case UnexpectedCode::Low: return ObdCode::OBD_TPS2_Secondary_Low; + case UnexpectedCode::High: return ObdCode::OBD_TPS2_Secondary_High; default: break; } break; case SensorType::AcceleratorPedal: case SensorType::AcceleratorPedalPrimary: switch (code) { - case UnexpectedCode::Timeout: return OBD_PPS_Primary_Timeout; - case UnexpectedCode::Low: return OBD_PPS_Primary_Low; - case UnexpectedCode::High: return OBD_PPS_Primary_High; - case UnexpectedCode::Inconsistent: return OBD_PPS_Correlation; + case UnexpectedCode::Timeout: return ObdCode::OBD_PPS_Primary_Timeout; + case UnexpectedCode::Low: return ObdCode::OBD_PPS_Primary_Low; + case UnexpectedCode::High: return ObdCode::OBD_PPS_Primary_High; + case UnexpectedCode::Inconsistent: return ObdCode::OBD_PPS_Correlation; default: break; } break; case SensorType::AcceleratorPedalSecondary: switch (code) { - case UnexpectedCode::Timeout: return OBD_PPS_Secondary_Timeout; - case UnexpectedCode::Low: return OBD_PPS_Secondary_Low; - case UnexpectedCode::High: return OBD_PPS_Secondary_High; + case UnexpectedCode::Timeout: return ObdCode::OBD_PPS_Secondary_Timeout; + case UnexpectedCode::Low: return ObdCode::OBD_PPS_Secondary_Low; + case UnexpectedCode::High: return ObdCode::OBD_PPS_Secondary_High; default: break; } break; case SensorType::Map: switch (code) { - case UnexpectedCode::Timeout: return OBD_Map_Timeout; - case UnexpectedCode::Low: return OBD_Map_Low; - case UnexpectedCode::High: return OBD_Map_High; + case UnexpectedCode::Timeout: return ObdCode::OBD_Map_Timeout; + case UnexpectedCode::Low: return ObdCode::OBD_Map_Low; + case UnexpectedCode::High: return ObdCode::OBD_Map_High; default: break; } break; case SensorType::Clt: switch (code) { - case UnexpectedCode::Timeout: return OBD_Clt_Timeout; - case UnexpectedCode::Low: return OBD_Clt_Low; - case UnexpectedCode::High: return OBD_Clt_High; + case UnexpectedCode::Timeout: return ObdCode::OBD_Clt_Timeout; + case UnexpectedCode::Low: return ObdCode::OBD_Clt_Low; + case UnexpectedCode::High: return ObdCode::OBD_Clt_High; default: break; } break; case SensorType::Iat: switch (code) { - case UnexpectedCode::Timeout: return OBD_Iat_Timeout; - case UnexpectedCode::Low: return OBD_Iat_Low; - case UnexpectedCode::High: return OBD_Iat_High; + case UnexpectedCode::Timeout: return ObdCode::OBD_Iat_Timeout; + case UnexpectedCode::Low: return ObdCode::OBD_Iat_Low; + case UnexpectedCode::High: return ObdCode::OBD_Iat_High; default: break; } break; case SensorType::FuelEthanolPercent: switch (code) { - case UnexpectedCode::Timeout: return OBD_FlexSensor_Timeout; - case UnexpectedCode::Low: return OBD_FlexSensor_Low; - case UnexpectedCode::High: return OBD_FlexSensor_High; + case UnexpectedCode::Timeout: return ObdCode::OBD_FlexSensor_Timeout; + case UnexpectedCode::Low: return ObdCode::OBD_FlexSensor_Low; + case UnexpectedCode::High: return ObdCode::OBD_FlexSensor_High; default: break; } break; default: break; } - return OBD_None; + return ObdCode::None; } inline const char* describeUnexpected(UnexpectedCode code) { @@ -116,31 +116,31 @@ static void check(SensorType type) { ObdCode code = getCode(type, result.Code); - if (code != OBD_None) { + if (code != ObdCode::None) { warning(code, "Sensor fault: %s %s", Sensor::getSensorName(type), describeUnexpected(result.Code)); } } static ObdCode getCodeForInjector(int idx, brain_pin_diag_e diag) { if (idx < 0 || idx >= 12) { - return OBD_None; + return ObdCode::None; } // TODO: do something more intelligent with `diag`? UNUSED(diag); - return (ObdCode)((int)OBD_Injector_Circuit_1 + idx); + return (ObdCode)((int)ObdCode::OBD_Injector_Circuit_1 + idx); } static ObdCode getCodeForIgnition(int idx, brain_pin_diag_e diag) { if (idx < 0 || idx >= 12) { - return OBD_None; + return ObdCode::None; } // TODO: do something more intelligent with `diag`? UNUSED(diag); - return (ObdCode)((int)OBD_Ignition_Circuit_1 + idx); + return (ObdCode)((int)ObdCode::OBD_Ignition_Circuit_1 + idx); } void SensorChecker::onSlowCallback() { diff --git a/firmware/controllers/settings.cpp b/firmware/controllers/settings.cpp index 0eda437704..9372747ff2 100644 --- a/firmware/controllers/settings.cpp +++ b/firmware/controllers/settings.cpp @@ -265,7 +265,7 @@ static void setCrankingFuel(float timeMs) { static void setGlobalTriggerAngleOffset(float value) { if (cisnan(value)) { - warning(CUSTOM_ERR_SGTP_ARGUMENT, "Invalid argument"); + warning(ObdCode::CUSTOM_ERR_SGTP_ARGUMENT, "Invalid argument"); return; } engineConfiguration->globalTriggerAngleOffset = value; diff --git a/firmware/controllers/system/periodic_thread_controller.h b/firmware/controllers/system/periodic_thread_controller.h index 2171d1dd31..f1e9d6b379 100644 --- a/firmware/controllers/system/periodic_thread_controller.h +++ b/firmware/controllers/system/periodic_thread_controller.h @@ -79,7 +79,7 @@ private: chThdSleepUntilWindowed(before, before + m_period); } - firmwareError(OBD_PCM_Processor_Fault, "Thread died: %s", this->m_name); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "Thread died: %s", this->m_name); } public: diff --git a/firmware/controllers/system/timer/event_queue.cpp b/firmware/controllers/system/timer/event_queue.cpp index c7ee7477e1..b0433002f5 100644 --- a/firmware/controllers/system/timer/event_queue.cpp +++ b/firmware/controllers/system/timer/event_queue.cpp @@ -76,7 +76,7 @@ bool EventQueue::insertTask(scheduling_s *scheduling, efitick_t timeX, action_s #if EFI_UNIT_TEST assertListIsSorted(); #endif /* EFI_UNIT_TEST */ - efiAssert(CUSTOM_ERR_ASSERT, action.getCallback() != NULL, "NULL callback", false); + efiAssert(ObdCode::CUSTOM_ERR_ASSERT, action.getCallback() != NULL, "NULL callback", false); // please note that simulator does not use this code at all - simulator uses signal_executor_sleep @@ -148,11 +148,11 @@ void EventQueue::remove(scheduling_s* scheduling) { // Walked off the end, this is an error since this *should* have been scheduled if (!current) { - firmwareError(OBD_PCM_Processor_Fault, "EventQueue::remove didn't find element"); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "EventQueue::remove didn't find element"); return; } - efiAssertVoid(OBD_PCM_Processor_Fault, current == scheduling, "current not equal to scheduling"); + efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, current == scheduling, "current not equal to scheduling"); // Link around the removed item prev->nextScheduling_s = current->nextScheduling_s; @@ -286,7 +286,7 @@ int EventQueue::size(void) const { void EventQueue::assertListIsSorted() const { scheduling_s *current = head; while (current != NULL && current->nextScheduling_s != NULL) { - efiAssertVoid(CUSTOM_ERR_6623, current->momentX <= current->nextScheduling_s->momentX, "list order"); + efiAssertVoid(ObdCode::CUSTOM_ERR_6623, current->momentX <= current->nextScheduling_s->momentX, "list order"); current = current->nextScheduling_s; } } diff --git a/firmware/controllers/system/timer/event_queue.h b/firmware/controllers/system/timer/event_queue.h index 5f91ce6b25..324f7e01b8 100644 --- a/firmware/controllers/system/timer/event_queue.h +++ b/firmware/controllers/system/timer/event_queue.h @@ -20,7 +20,7 @@ int counter = 0; \ LL_FOREACH2(head, current, field) { \ if (++counter > QUEUE_LENGTH_LIMIT) { \ - firmwareError(CUSTOM_ERR_LOOPED_QUEUE, "Looped queue?"); \ + firmwareError(ObdCode::CUSTOM_ERR_LOOPED_QUEUE, "Looped queue?"); \ return false; \ } \ if (current == element) { \ @@ -29,7 +29,7 @@ * was not scheduled by angle but was scheduled by time. In case of scheduling \ * by time with slow RPM the whole next fast revolution might be within the wait period \ */ \ - warning(CUSTOM_RE_ADDING_INTO_EXECUTION_QUEUE, "re-adding element into event_queue"); \ + warning(ObdCode::CUSTOM_RE_ADDING_INTO_EXECUTION_QUEUE, "re-adding element into event_queue"); \ return true; \ } \ } \ diff --git a/firmware/controllers/system/timer/pwm_generator_logic.cpp b/firmware/controllers/system/timer/pwm_generator_logic.cpp index f1292f470b..68ca0b13ba 100644 --- a/firmware/controllers/system/timer/pwm_generator_logic.cpp +++ b/firmware/controllers/system/timer/pwm_generator_logic.cpp @@ -53,13 +53,13 @@ void SimplePwm::setSimplePwmDutyCycle(float dutyCycle) { return; } if (cisnan(dutyCycle)) { - warning(CUSTOM_DUTY_INVALID, "%s spwd:dutyCycle %.2f", name, dutyCycle); + warning(ObdCode::CUSTOM_DUTY_INVALID, "%s spwd:dutyCycle %.2f", name, dutyCycle); return; } else if (dutyCycle < 0) { - warning(CUSTOM_DUTY_TOO_LOW, "%s dutyCycle too low %.2f", name, dutyCycle); + warning(ObdCode::CUSTOM_DUTY_TOO_LOW, "%s dutyCycle too low %.2f", name, dutyCycle); dutyCycle = 0; } else if (dutyCycle > 1) { - warning(CUSTOM_PWM_DUTY_TOO_HIGH, "%s duty too high %.2f", name, dutyCycle); + warning(ObdCode::CUSTOM_PWM_DUTY_TOO_HIGH, "%s duty too high %.2f", name, dutyCycle); dutyCycle = 1; } @@ -93,7 +93,7 @@ void SimplePwm::setSimplePwmDutyCycle(float dutyCycle) { * returns absolute timestamp of state change */ static efitick_t getNextSwitchTimeNt(PwmConfig *state) { - efiAssert(CUSTOM_ERR_ASSERT, state->safe.phaseIndex < PWM_PHASE_MAX_COUNT, "phaseIndex range", 0); + efiAssert(ObdCode::CUSTOM_ERR_ASSERT, state->safe.phaseIndex < PWM_PHASE_MAX_COUNT, "phaseIndex range", 0); int iteration = state->safe.iteration; // we handle PM_ZERO and PM_FULL separately float switchTime = state->mode == PM_NORMAL ? state->multiChannelStateSequence->getSwitchTime(state->safe.phaseIndex) : 1; @@ -134,7 +134,7 @@ void PwmConfig::stop() { void PwmConfig::handleCycleStart() { if (safe.phaseIndex != 0) { // https://github.com/rusefi/rusefi/issues/1030 - firmwareError(CUSTOM_PWM_CYCLE_START, "handleCycleStart %d", safe.phaseIndex); + firmwareError(ObdCode::CUSTOM_PWM_CYCLE_START, "handleCycleStart %d", safe.phaseIndex); return; } @@ -151,8 +151,8 @@ void PwmConfig::handleCycleStart() { uint32_t iterationLimit = minI(iterationLimitInt32, iterationLimitFloat); - efiAssertVoid(CUSTOM_ERR_6580, periodNt != 0, "period not initialized"); - efiAssertVoid(CUSTOM_ERR_6580, iterationLimit > 0, "iterationLimit invalid"); + efiAssertVoid(ObdCode::CUSTOM_ERR_6580, periodNt != 0, "period not initialized"); + efiAssertVoid(ObdCode::CUSTOM_ERR_6580, iterationLimit > 0, "iterationLimit invalid"); if (forceCycleStart || safe.periodNt != periodNt || safe.iteration == iterationLimit) { /** * period length has changed - we need to reset internal state @@ -250,7 +250,7 @@ static void timerCallback(PwmConfig *state) { ScopePerf perf(PE::PwmGeneratorCallback); state->dbgNestingLevel++; - efiAssertVoid(CUSTOM_ERR_6581, state->dbgNestingLevel < 25, "PWM nesting issue"); + efiAssertVoid(ObdCode::CUSTOM_ERR_6581, state->dbgNestingLevel < 25, "PWM nesting issue"); efitick_t switchTimeNt = state->togglePwmState(); if (switchTimeNt == 0) { @@ -258,7 +258,7 @@ static void timerCallback(PwmConfig *state) { return; } if (state->executor == nullptr) { - firmwareError(CUSTOM_NULL_EXECUTOR, "exec on %s", state->name); + firmwareError(ObdCode::CUSTOM_NULL_EXECUTOR, "exec on %s", state->name); return; } @@ -288,16 +288,16 @@ void PwmConfig::weComplexInit(const char *msg, ExecutorInterface *executor, this->executor = executor; isStopRequested = false; - efiAssertVoid(CUSTOM_ERR_6582, periodNt != 0, "period is not initialized"); + efiAssertVoid(ObdCode::CUSTOM_ERR_6582, periodNt != 0, "period is not initialized"); if (seq->phaseCount == 0) { - firmwareError(CUSTOM_ERR_PWM_1, "signal length cannot be zero"); + firmwareError(ObdCode::CUSTOM_ERR_PWM_1, "signal length cannot be zero"); return; } if (seq->phaseCount > PWM_PHASE_MAX_COUNT) { - firmwareError(CUSTOM_ERR_PWM_2, "too many phases in PWM"); + firmwareError(ObdCode::CUSTOM_ERR_PWM_2, "too many phases in PWM"); return; } - efiAssertVoid(CUSTOM_ERR_6583, seq->waveCount > 0, "waveCount should be positive"); + efiAssertVoid(ObdCode::CUSTOM_ERR_6583, seq->waveCount > 0, "waveCount should be positive"); this->pwmCycleCallback = pwmCycleCallback; this->stateChangeCallback = stateChangeCallback; @@ -314,10 +314,10 @@ void PwmConfig::weComplexInit(const char *msg, ExecutorInterface *executor, void startSimplePwm(SimplePwm *state, const char *msg, ExecutorInterface *executor, OutputPin *output, float frequency, float dutyCycle) { - efiAssertVoid(CUSTOM_ERR_PWM_STATE_ASSERT, state != NULL, "state"); - efiAssertVoid(CUSTOM_ERR_PWM_DUTY_ASSERT, dutyCycle >= 0 && dutyCycle <= 1, "dutyCycle"); + efiAssertVoid(ObdCode::CUSTOM_ERR_PWM_STATE_ASSERT, state != NULL, "state"); + efiAssertVoid(ObdCode::CUSTOM_ERR_PWM_DUTY_ASSERT, dutyCycle >= 0 && dutyCycle <= 1, "dutyCycle"); if (frequency < 1) { - warning(CUSTOM_OBD_LOW_FREQUENCY, "low frequency %.2f %s", frequency, msg); + warning(ObdCode::CUSTOM_OBD_LOW_FREQUENCY, "low frequency %.2f %s", frequency, msg); return; } @@ -379,8 +379,8 @@ void applyPinState(int stateIndex, PwmConfig *state) /* pwm_gen_callback */ { } #endif // EFI_PROD_CODE - efiAssertVoid(CUSTOM_ERR_6663, stateIndex < PWM_PHASE_MAX_COUNT, "invalid stateIndex"); - efiAssertVoid(CUSTOM_ERR_6664, state->multiChannelStateSequence->waveCount <= PWM_PHASE_MAX_WAVE_PER_PWM, "invalid waveCount"); + efiAssertVoid(ObdCode::CUSTOM_ERR_6663, stateIndex < PWM_PHASE_MAX_COUNT, "invalid stateIndex"); + efiAssertVoid(ObdCode::CUSTOM_ERR_6664, state->multiChannelStateSequence->waveCount <= PWM_PHASE_MAX_WAVE_PER_PWM, "invalid waveCount"); for (int channelIndex = 0; channelIndex < state->multiChannelStateSequence->waveCount; channelIndex++) { OutputPin *output = state->outputPins[channelIndex]; TriggerValue value = state->multiChannelStateSequence->getChannelState(channelIndex, stateIndex); diff --git a/firmware/controllers/system/timer/scheduler.cpp b/firmware/controllers/system/timer/scheduler.cpp index 68fd997871..981a7ba9dc 100644 --- a/firmware/controllers/system/timer/scheduler.cpp +++ b/firmware/controllers/system/timer/scheduler.cpp @@ -8,7 +8,7 @@ #include "scheduler.h" void action_s::execute() { - efiAssertVoid(CUSTOM_ERR_ASSERT, callback != NULL, "callback==null1"); + efiAssertVoid(ObdCode::CUSTOM_ERR_ASSERT, callback != NULL, "callback==null1"); callback(param); } diff --git a/firmware/controllers/system/timer/single_timer_executor.cpp b/firmware/controllers/system/timer/single_timer_executor.cpp index 981f17e611..d24bbb884b 100644 --- a/firmware/controllers/system/timer/single_timer_executor.cpp +++ b/firmware/controllers/system/timer/single_timer_executor.cpp @@ -34,7 +34,7 @@ uint32_t hwSetTimerDuration; void globalTimerCallback() { - efiAssertVoid(CUSTOM_ERR_6624, getCurrentRemainingStack() > EXPECTED_REMAINING_STACK, "lowstck#2y"); + efiAssertVoid(ObdCode::CUSTOM_ERR_6624, getCurrentRemainingStack() > EXPECTED_REMAINING_STACK, "lowstck#2y"); ___engine.executor.onTimerCallback(); } @@ -72,7 +72,7 @@ void SingleTimerExecutor::scheduleByTimestampNt(const char *msg, scheduling_s* s if (deltaTimeNt >= TOO_FAR_INTO_FUTURE_NT) { // we are trying to set callback for too far into the future. This does not look right at all int32_t intDeltaTimeNt = (int32_t)deltaTimeNt; - firmwareError(CUSTOM_ERR_TASK_TIMER_OVERFLOW, "scheduleByTimestampNt() too far: %d %s", intDeltaTimeNt, msg); + firmwareError(ObdCode::CUSTOM_ERR_TASK_TIMER_OVERFLOW, "scheduleByTimestampNt() too far: %d %s", intDeltaTimeNt, msg); return; } #endif @@ -137,7 +137,7 @@ void SingleTimerExecutor::executeAllPendingActions() { // if we're stuck in a loop executing lots of events, panic! if (executeCounter++ == 500) { - firmwareError(CUSTOM_ERR_LOCK_ISSUE, "Maximum scheduling run length exceeded - CPU load too high"); + firmwareError(ObdCode::CUSTOM_ERR_LOCK_ISSUE, "Maximum scheduling run length exceeded - CPU load too high"); } } while (didExecute); @@ -145,7 +145,7 @@ void SingleTimerExecutor::executeAllPendingActions() { maxExecuteCounter = maxI(maxExecuteCounter, executeCounter); if (!isLocked()) { - firmwareError(CUSTOM_ERR_LOCK_ISSUE, "Someone has stolen my lock"); + firmwareError(ObdCode::CUSTOM_ERR_LOCK_ISSUE, "Someone has stolen my lock"); return; } reentrantFlag = false; @@ -167,7 +167,7 @@ void SingleTimerExecutor::scheduleTimerCallback() { return; // no pending events in the queue } - efiAssertVoid(CUSTOM_ERR_6625, nextEventTimeNt.Value > nowNt, "setTimer constraint"); + efiAssertVoid(ObdCode::CUSTOM_ERR_6625, nextEventTimeNt.Value > nowNt, "setTimer constraint"); setHardwareSchedulerTimer(nowNt, nextEventTimeNt.Value); } diff --git a/firmware/controllers/system/timer/trigger_scheduler.cpp b/firmware/controllers/system/timer/trigger_scheduler.cpp index a36c337d1c..d18f520702 100644 --- a/firmware/controllers/system/timer/trigger_scheduler.cpp +++ b/firmware/controllers/system/timer/trigger_scheduler.cpp @@ -151,7 +151,7 @@ AngleBasedEvent * TriggerScheduler::getElementAtIndexForUnitTest(int index) { return current; index--; } - firmwareError(OBD_PCM_Processor_Fault, "getElementAtIndexForUnitText: null"); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "getElementAtIndexForUnitText: null"); return nullptr; } #endif /* EFI_UNIT_TEST */ diff --git a/firmware/controllers/trigger/decoders/trigger_structure.h b/firmware/controllers/trigger/decoders/trigger_structure.h index 3b321c0ade..fd504c9f9f 100644 --- a/firmware/controllers/trigger/decoders/trigger_structure.h +++ b/firmware/controllers/trigger/decoders/trigger_structure.h @@ -33,7 +33,7 @@ #define wrapAngle2(angle, msg, code, engineCycle) \ { \ if (cisnan(angle)) { \ - firmwareError(CUSTOM_ERR_ANGLE, "a NaN %s", msg); \ + firmwareError(ObdCode::CUSTOM_ERR_ANGLE, "a NaN %s", msg); \ angle = 0; \ } \ assertAngleRange(angle, msg, code); \ diff --git a/firmware/controllers/trigger/decoders/trigger_universal.cpp b/firmware/controllers/trigger/decoders/trigger_universal.cpp index 1e0c6bc013..fc5e43840f 100644 --- a/firmware/controllers/trigger/decoders/trigger_universal.cpp +++ b/firmware/controllers/trigger/decoders/trigger_universal.cpp @@ -18,8 +18,8 @@ angle_t getEngineCycle(operation_mode_e operationMode) { void addSkippedToothTriggerEvents(TriggerWheel wheel, TriggerWaveform *s, int totalTeethCount, int skippedCount, float toothWidth, float offset, float engineCycle, float filterLeft, float filterRight) { - efiAssertVoid(CUSTOM_ERR_6586, totalTeethCount > 0, "total count"); - efiAssertVoid(CUSTOM_ERR_6587, skippedCount >= 0, "skipped count"); + efiAssertVoid(ObdCode::CUSTOM_ERR_6586, totalTeethCount > 0, "total count"); + efiAssertVoid(ObdCode::CUSTOM_ERR_6587, skippedCount >= 0, "skipped count"); for (int i = 0; i < totalTeethCount - skippedCount - 1; i++) { float angleDown = engineCycle / totalTeethCount * (i + (1 - toothWidth)); @@ -37,11 +37,11 @@ void addSkippedToothTriggerEvents(TriggerWheel wheel, TriggerWaveform *s, int to void initializeSkippedToothTrigger(TriggerWaveform *s, int totalTeethCount, int skippedCount, operation_mode_e operationMode, SyncEdge syncEdge) { if (totalTeethCount <= 0) { - firmwareError(CUSTOM_OBD_TRIGGER_WAVEFORM, "Invalid total tooth count for missing tooth decoder: %d", totalTeethCount); + firmwareError(ObdCode::CUSTOM_OBD_TRIGGER_WAVEFORM, "Invalid total tooth count for missing tooth decoder: %d", totalTeethCount); s->setShapeDefinitionError(true); return; } - efiAssertVoid(CUSTOM_NULL_SHAPE, s != NULL, "TriggerWaveform is NULL"); + efiAssertVoid(ObdCode::CUSTOM_NULL_SHAPE, s != NULL, "TriggerWaveform is NULL"); s->initialize(operationMode, syncEdge); diff --git a/firmware/controllers/trigger/trigger_central.cpp b/firmware/controllers/trigger/trigger_central.cpp index 50c8dc428b..2d16691e95 100644 --- a/firmware/controllers/trigger/trigger_central.cpp +++ b/firmware/controllers/trigger/trigger_central.cpp @@ -265,7 +265,7 @@ void hwHandleVvtCamSignal(TriggerValue front, efitick_t nowNt, int index) { tc->vvtEventFallCounter[index]++; } if (engineConfiguration->vvtMode[camIndex] == VVT_INACTIVE) { - warning(CUSTOM_VVT_MODE_NOT_SELECTED, "VVT: event on %d but no mode", camIndex); + warning(ObdCode::CUSTOM_VVT_MODE_NOT_SELECTED, "VVT: event on %d but no mode", camIndex); } #if VR_HW_CHECK_MODE @@ -385,7 +385,7 @@ void hwHandleVvtCamSignal(TriggerValue front, efitick_t nowNt, int index) { * wrong order due to belt flex or else * https://github.com/rusefi/rusefi/issues/3269 */ - warning(CUSTOM_VVT_SYNC_POSITION, "VVT sync position too close to trigger sync"); + warning(ObdCode::CUSTOM_VVT_SYNC_POSITION, "VVT sync position too close to trigger sync"); } } else { // Not using this cam for engine sync, just wrap the value in to the reasonable range @@ -687,7 +687,7 @@ bool TriggerCentral::isToothExpectedNow(efitick_t timestamp) { // #2 will be ignored // We're not sure which edge was the "real" one, but they were close enough // together that it doesn't really matter. - warning(CUSTOM_PRIMARY_DOUBLED_EDGE, "doubled trigger edge after %.2f deg at #%d", angleSinceLastTooth, triggerState.currentCycle.current_index); + warning(ObdCode::CUSTOM_PRIMARY_DOUBLED_EDGE, "doubled trigger edge after %.2f deg at #%d", angleSinceLastTooth, triggerState.currentCycle.current_index); return false; } @@ -698,7 +698,7 @@ bool TriggerCentral::isToothExpectedNow(efitick_t timestamp) { // TODO: configurable threshold if (isRpmEnough && absError > 10 && absError < 180) { // This tooth came at a very unexpected time, ignore it - warning(CUSTOM_PRIMARY_BAD_TOOTH_TIMING, "tooth #%d error of %.1f", triggerState.currentCycle.current_index, angleError); + warning(ObdCode::CUSTOM_PRIMARY_BAD_TOOTH_TIMING, "tooth #%d error of %.1f", triggerState.currentCycle.current_index, angleError); // TODO: this causes issues with some real engine logs, should it? // return false; @@ -718,7 +718,7 @@ bool TriggerCentral::isToothExpectedNow(efitick_t timestamp) { void TriggerCentral::handleShaftSignal(trigger_event_e signal, efitick_t timestamp) { if (triggerShape.shapeDefinitionError) { // trigger is broken, we cannot do anything here - warning(CUSTOM_ERR_UNEXPECTED_SHAFT_EVENT, "Shaft event while trigger is mis-configured"); + warning(ObdCode::CUSTOM_ERR_UNEXPECTED_SHAFT_EVENT, "Shaft event while trigger is mis-configured"); // magic value to indicate a problem hwEventCounters[0] = 155; return; @@ -744,7 +744,7 @@ void TriggerCentral::handleShaftSignal(trigger_event_e signal, efitick_t timesta m_lastEventTimer.reset(timestamp); int eventIndex = (int) signal; - efiAssertVoid(CUSTOM_TRIGGER_EVENT_TYPE, eventIndex >= 0 && eventIndex < HW_EVENT_TYPES, "signal type"); + efiAssertVoid(ObdCode::CUSTOM_TRIGGER_EVENT_TYPE, eventIndex >= 0 && eventIndex < HW_EVENT_TYPES, "signal type"); hwEventCounters[eventIndex]++; // Decode the trigger! @@ -773,7 +773,7 @@ void TriggerCentral::handleShaftSignal(trigger_event_e signal, efitick_t timesta auto currentPhaseFromSyncPoint = getTriggerCentral()->triggerFormDetails.eventAngles[triggerIndexForListeners]; // Adjust so currentPhase is in engine-space angle, not trigger-space angle - currentEngineDecodedPhase = wrapAngleMethod(currentPhaseFromSyncPoint - tdcPosition(), "currentEnginePhase", CUSTOM_ERR_6555); + currentEngineDecodedPhase = wrapAngleMethod(currentPhaseFromSyncPoint - tdcPosition(), "currentEnginePhase", ObdCode::CUSTOM_ERR_6555); // Record precise time and phase of the engine. This is used for VVT decode, and to check that the // trigger pattern selected matches reality (ie, we check the next tooth is where we think it should be) @@ -813,11 +813,11 @@ void TriggerCentral::handleShaftSignal(trigger_event_e signal, efitick_t timesta // I don't love this. nextToothIndex = (nextToothIndex + 1) % engineCycleEventCount; nextPhase = getTriggerCentral()->triggerFormDetails.eventAngles[nextToothIndex] - tdcPosition(); - wrapAngle(nextPhase, "nextEnginePhase", CUSTOM_ERR_6555); + wrapAngle(nextPhase, "nextEnginePhase", ObdCode::CUSTOM_ERR_6555); } while (nextPhase == currentEngineDecodedPhase); float expectNextPhase = nextPhase + tdcPosition(); - wrapAngle(expectNextPhase, "nextEnginePhase", CUSTOM_ERR_6555); + wrapAngle(expectNextPhase, "nextEnginePhase", ObdCode::CUSTOM_ERR_6555); expectedNextPhase = expectNextPhase; #if EFI_CDM_INTEGRATION @@ -1023,7 +1023,7 @@ void TriggerCentral::validateCamVvtCounters() { vvtCamCounter = 0; } else if (camVvtValidationIndex == 0xFE && vvtCamCounter < 60) { // magic logic: we expect at least 60 CAM/VVT events for each 256 trigger cycles, otherwise throw a code - warning(OBD_Camshaft_Position_Sensor_Circuit_Range_Performance, "No Camshaft Position Sensor signals"); + warning(ObdCode::OBD_Camshaft_Position_Sensor_Circuit_Range_Performance, "No Camshaft Position Sensor signals"); } } /** @@ -1035,20 +1035,20 @@ static void calculateTriggerSynchPoint( TriggerDecoderBase& initState) { #if EFI_PROD_CODE - efiAssertVoid(CUSTOM_TRIGGER_STACK, getCurrentRemainingStack() > EXPECTED_REMAINING_STACK, "calc s"); + efiAssertVoid(ObdCode::CUSTOM_TRIGGER_STACK, getCurrentRemainingStack() > EXPECTED_REMAINING_STACK, "calc s"); #endif shape.initializeSyncPoint(initState, primaryTriggerConfiguration); if (shape.getSize() >= PWM_PHASE_MAX_COUNT) { // todo: by the time we are here we had already modified a lot of RAM out of bounds! - firmwareError(CUSTOM_ERR_TRIGGER_WAVEFORM_TOO_LONG, "Trigger length above maximum: %d", shape.getSize()); + firmwareError(ObdCode::CUSTOM_ERR_TRIGGER_WAVEFORM_TOO_LONG, "Trigger length above maximum: %d", shape.getSize()); shape.setShapeDefinitionError(true); return; } if (shape.getSize() == 0) { - firmwareError(CUSTOM_ERR_TRIGGER_ZERO, "triggerShape size is zero"); + firmwareError(ObdCode::CUSTOM_ERR_TRIGGER_ZERO, "triggerShape size is zero"); } } @@ -1088,7 +1088,7 @@ void TriggerCentral::updateWaveform() { int length = triggerShape.getLength(); engineCycleEventCount = length; - efiAssertVoid(CUSTOM_SHAPE_LEN_ZERO, length > 0, "shapeLength=0"); + efiAssertVoid(ObdCode::CUSTOM_SHAPE_LEN_ZERO, length > 0, "shapeLength=0"); triggerErrorDetection.clear(); @@ -1135,11 +1135,11 @@ bool TriggerCentral::isTriggerConfigChanged() { void validateTriggerInputs() { if (!isBrainPinValid(engineConfiguration->triggerInputPins[0]) && isBrainPinValid(engineConfiguration->triggerInputPins[1])) { - firmwareError(OBD_PCM_Processor_Fault, "First trigger channel is missing"); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "First trigger channel is missing"); } if (!isBrainPinValid(engineConfiguration->camInputs[0]) && isBrainPinValid(engineConfiguration->camInputs[2])) { - firmwareError(OBD_PCM_Processor_Fault, "First bank cam input is required if second bank specified"); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "First bank cam input is required if second bank specified"); } } diff --git a/firmware/controllers/trigger/trigger_decoder.cpp b/firmware/controllers/trigger/trigger_decoder.cpp index 4779d644f2..dc7c4a2c6b 100644 --- a/firmware/controllers/trigger/trigger_decoder.cpp +++ b/firmware/controllers/trigger/trigger_decoder.cpp @@ -127,7 +127,7 @@ void TriggerFormDetails::prepareEventAngles(TriggerWaveform *shape) { return; } angle_t firstAngle = shape->getAngle(triggerShapeSynchPointIndex); - assertAngleRange(firstAngle, "firstAngle", CUSTOM_TRIGGER_SYNC_ANGLE); + assertAngleRange(firstAngle, "firstAngle", ObdCode::CUSTOM_TRIGGER_SYNC_ANGLE); int riseOnlyIndex = 0; @@ -138,8 +138,8 @@ void TriggerFormDetails::prepareEventAngles(TriggerWaveform *shape) { // this may be getSize(); - assertAngleRange(shape->triggerShapeSynchPointIndex, "triggerShapeSynchPointIndex", CUSTOM_TRIGGER_SYNC_ANGLE2); - efiAssertVoid(CUSTOM_TRIGGER_CYCLE, getTriggerCentral()->engineCycleEventCount != 0, "zero engineCycleEventCount"); + assertAngleRange(shape->triggerShapeSynchPointIndex, "triggerShapeSynchPointIndex", ObdCode::CUSTOM_TRIGGER_SYNC_ANGLE2); + efiAssertVoid(ObdCode::CUSTOM_TRIGGER_CYCLE, getTriggerCentral()->engineCycleEventCount != 0, "zero engineCycleEventCount"); for (size_t eventIndex = 0; eventIndex < length; eventIndex++) { if (eventIndex == 0) { @@ -158,12 +158,12 @@ void TriggerFormDetails::prepareEventAngles(TriggerWaveform *shape) { // Compute the relative angle of this tooth to the sync point's tooth float angle = shape->getAngle(wrappedIndex) - firstAngle; - efiAssertVoid(CUSTOM_TRIGGER_CYCLE, !cisnan(angle), "trgSyncNaN"); + efiAssertVoid(ObdCode::CUSTOM_TRIGGER_CYCLE, !cisnan(angle), "trgSyncNaN"); // Wrap the angle back in to [0, 720) - fixAngle(angle, "trgSync", CUSTOM_TRIGGER_SYNC_ANGLE_RANGE); + fixAngle(angle, "trgSync", ObdCode::CUSTOM_TRIGGER_SYNC_ANGLE_RANGE); if (shape->useOnlyRisingEdges) { - efiAssertVoid(OBD_PCM_Processor_Fault, triggerDefinitionIndex < triggerShapeLength, "trigger shape fail"); + efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, triggerDefinitionIndex < triggerShapeLength, "trigger shape fail"); assertIsInBounds(triggerDefinitionIndex, shape->isRiseEvent, "isRise"); // In case this is a rising event, replace the following fall event with the rising as well @@ -221,7 +221,7 @@ int TriggerDecoderBase::getCurrentIndex() const { } angle_t PrimaryTriggerDecoder::syncEnginePhase(int divider, int remainder, angle_t engineCycle) { - efiAssert(OBD_PCM_Processor_Fault, remainder < divider, "syncEnginePhase", false); + efiAssert(ObdCode::OBD_PCM_Processor_Fault, remainder < divider, "syncEnginePhase", false); angle_t totalShift = 0; while (getCrankSynchronizationCounter() % divider != remainder) { /** @@ -253,7 +253,7 @@ void PrimaryTriggerDecoder::onTriggerError() { } void PrimaryTriggerDecoder::onNotEnoughTeeth(int /*actual*/, int /*expected*/) { - warning(CUSTOM_PRIMARY_NOT_ENOUGH_TEETH, "primary trigger error: not enough teeth between sync points: expected %d/%d got %d/%d", + warning(ObdCode::CUSTOM_PRIMARY_NOT_ENOUGH_TEETH, "primary trigger error: not enough teeth between sync points: expected %d/%d got %d/%d", getTriggerCentral()->triggerShape.getExpectedEventCount(TriggerWheel::T_PRIMARY), getTriggerCentral()->triggerShape.getExpectedEventCount(TriggerWheel::T_SECONDARY), currentCycle.eventCount[0], @@ -261,7 +261,7 @@ void PrimaryTriggerDecoder::onNotEnoughTeeth(int /*actual*/, int /*expected*/) { } void PrimaryTriggerDecoder::onTooManyTeeth(int /*actual*/, int /*expected*/) { - warning(CUSTOM_PRIMARY_TOO_MANY_TEETH, "primary trigger error: too many teeth between sync points: expected %d/%d got %d/%d", + warning(ObdCode::CUSTOM_PRIMARY_TOO_MANY_TEETH, "primary trigger error: too many teeth between sync points: expected %d/%d got %d/%d", getTriggerCentral()->triggerShape.getExpectedEventCount(TriggerWheel::T_PRIMARY), getTriggerCentral()->triggerShape.getExpectedEventCount(TriggerWheel::T_SECONDARY), currentCycle.eventCount[0], @@ -292,11 +292,11 @@ case TriggerValue::RISE: } void VvtTriggerDecoder::onNotEnoughTeeth(int actual, int expected) { - warning(CUSTOM_CAM_NOT_ENOUGH_TEETH, "cam %s trigger error: not enough teeth between sync points: actual %d expected %d", name, actual, expected); + warning(ObdCode::CUSTOM_CAM_NOT_ENOUGH_TEETH, "cam %s trigger error: not enough teeth between sync points: actual %d expected %d", name, actual, expected); } void VvtTriggerDecoder::onTooManyTeeth(int actual, int expected) { - warning(CUSTOM_CAM_TOO_MANY_TEETH, "cam %s trigger error: too many teeth between sync points: %d > %d", name, actual, expected); + warning(ObdCode::CUSTOM_CAM_TOO_MANY_TEETH, "cam %s trigger error: too many teeth between sync points: %d > %d", name, actual, expected); } bool TriggerDecoderBase::validateEventCounters(const TriggerWaveform& triggerShape) const { @@ -392,7 +392,7 @@ expected TriggerDecoderBase::decodeTriggerEvent( bool useOnlyRisingEdgeForTrigger = triggerShape.useOnlyRisingEdges; - efiAssert(CUSTOM_TRIGGER_UNEXPECTED, signal <= SHAFT_SECONDARY_RISING, "unexpected signal", unexpected); + efiAssert(ObdCode::CUSTOM_TRIGGER_UNEXPECTED, signal <= SHAFT_SECONDARY_RISING, "unexpected signal", unexpected); TriggerWheel triggerWheel = eventIndex[signal]; TriggerValue type = eventType[signal]; @@ -407,7 +407,7 @@ expected TriggerDecoderBase::decodeTriggerEvent( currentCycle.eventCount[(int)triggerWheel]++; if (toothed_previous_time > nowNt) { - firmwareError(CUSTOM_OBD_93, "[%s] toothed_previous_time after nowNt prev=%d now=%d", msg, toothed_previous_time, nowNt); + firmwareError(ObdCode::CUSTOM_OBD_93, "[%s] toothed_previous_time after nowNt prev=%d now=%d", msg, toothed_previous_time, nowNt); } efitick_t currentDurationLong = isFirstEvent ? 0 : nowNt - toothed_previous_time; @@ -694,7 +694,7 @@ uint32_t TriggerDecoderBase::findTriggerZeroEventIndex( TriggerWaveform& shape, const TriggerConfiguration& triggerConfiguration) { #if EFI_PROD_CODE - efiAssert(CUSTOM_ERR_ASSERT, getCurrentRemainingStack() > 128, "findPos", -1); + efiAssert(ObdCode::CUSTOM_ERR_ASSERT, getCurrentRemainingStack() > 128, "findPos", -1); #endif @@ -712,7 +712,7 @@ uint32_t TriggerDecoderBase::findTriggerZeroEventIndex( } // Assert that we found the sync point on the very first revolution - efiAssert(CUSTOM_ERR_ASSERT, getCrankSynchronizationCounter() == 0, "findZero_revCounter", EFI_ERROR_CODE); + efiAssert(ObdCode::CUSTOM_ERR_ASSERT, getCrankSynchronizationCounter() == 0, "findZero_revCounter", EFI_ERROR_CODE); #if EFI_UNIT_TEST if (printTriggerDebug) { diff --git a/firmware/controllers/trigger/trigger_simulator.cpp b/firmware/controllers/trigger/trigger_simulator.cpp index 4806e9035c..9bc4605c64 100644 --- a/firmware/controllers/trigger/trigger_simulator.cpp +++ b/firmware/controllers/trigger/trigger_simulator.cpp @@ -42,7 +42,7 @@ void TriggerStimulatorHelper::feedSimulatedEvent( const TriggerWaveform& shape, int i ) { - efiAssertVoid(CUSTOM_ERR_6593, shape.getSize() > 0, "size not zero"); + efiAssertVoid(ObdCode::CUSTOM_ERR_6593, shape.getSize() > 0, "size not zero"); int stateIndex = i % shape.getSize(); int time = getSimulatedEventTime(shape, i); @@ -108,7 +108,7 @@ void TriggerStimulatorHelper::assertSyncPosition( int revolutionCounter = state.getCrankSynchronizationCounter(); if (revolutionCounter != TEST_REVOLUTIONS) { - warning(CUSTOM_OBD_TRIGGER_WAVEFORM, "sync failed/wrong gap parameters trigger=%s revolutionCounter=%d", + warning(ObdCode::CUSTOM_OBD_TRIGGER_WAVEFORM, "sync failed/wrong gap parameters trigger=%s revolutionCounter=%d", getTrigger_type_e(triggerConfiguration.TriggerType.type), revolutionCounter); shape.setShapeDefinitionError(true); @@ -141,9 +141,9 @@ expected TriggerStimulatorHelper::findTriggerSyncPoint( shape.setShapeDefinitionError(true); if (engineConfiguration->overrideTriggerGaps) { - firmwareError(CUSTOM_ERR_CUSTOM_GAPS_BAD, "Your custom trigger gaps are not good."); + firmwareError(ObdCode::CUSTOM_ERR_CUSTOM_GAPS_BAD, "Your custom trigger gaps are not good."); } else { - firmwareError(CUSTOM_ERR_TRIGGER_SYNC, "findTriggerZeroEventIndex() failed"); + firmwareError(ObdCode::CUSTOM_ERR_TRIGGER_SYNC, "findTriggerZeroEventIndex() failed"); } return unexpected; } diff --git a/firmware/development/engine_sniffer.cpp b/firmware/development/engine_sniffer.cpp index fe313a0d5e..6c0a50dd06 100644 --- a/firmware/development/engine_sniffer.cpp +++ b/firmware/development/engine_sniffer.cpp @@ -175,13 +175,13 @@ void WaveChart::addEvent3(const char *name, const char * msg) { return; } #endif - efiAssertVoid(CUSTOM_ERR_6651, name!=NULL, "WC: NULL name"); + efiAssertVoid(ObdCode::CUSTOM_ERR_6651, name!=NULL, "WC: NULL name"); #if EFI_PROD_CODE - efiAssertVoid(CUSTOM_ERR_6652, getCurrentRemainingStack() > 32, "lowstck#2c"); + efiAssertVoid(ObdCode::CUSTOM_ERR_6652, getCurrentRemainingStack() > 32, "lowstck#2c"); #endif /* EFI_PROD_CODE */ - efiAssertVoid(CUSTOM_ERR_6653, isInitialized, "chart not initialized"); + efiAssertVoid(ObdCode::CUSTOM_ERR_6653, isInitialized, "chart not initialized"); #if DEBUG_WAVE efiPrintf("current", chart->counter); #endif /* DEBUG_WAVE */ diff --git a/firmware/development/logic_analyzer.cpp b/firmware/development/logic_analyzer.cpp index df53be6b29..fa71461255 100644 --- a/firmware/development/logic_analyzer.cpp +++ b/firmware/development/logic_analyzer.cpp @@ -73,7 +73,7 @@ static void riseCallback(WaveReader *reader) { efitick_t nowUs = getTimeNowUs(); reader->riseEventCounter++; reader->lastActivityTimeUs = nowUs; - assertIsrContext(CUSTOM_ERR_6670); + assertIsrContext(ObdCode::CUSTOM_ERR_6670); addEngineSnifferLogicAnalyzerEvent(reader->laIndex, FrontDirection::UP); uint32_t width = nowUs - reader->periodEventTimeUs; @@ -87,7 +87,7 @@ void WaveReader::onFallEvent() { efitick_t nowUs = getTimeNowUs(); fallEventCounter++; lastActivityTimeUs = nowUs; - assertIsrContext(CUSTOM_ERR_6670); + assertIsrContext(ObdCode::CUSTOM_ERR_6670); addEngineSnifferLogicAnalyzerEvent(laIndex, FrontDirection::DOWN); efitick_t width = nowUs - widthEventTimeUs; @@ -129,7 +129,7 @@ void logicAnalyzerCallback(void* arg, efitick_t /*stamp*/) { static void initWave(size_t index) { brain_pin_e brainPin = engineConfiguration->logicAnalyzerPins[index]; - efiAssertVoid(CUSTOM_ERR_6655, index < efi::size(readers), "too many ICUs"); + efiAssertVoid(ObdCode::CUSTOM_ERR_6655, index < efi::size(readers), "too many ICUs"); WaveReader *reader = &readers[index]; if (!isBrainPinValid(brainPin)) { @@ -218,7 +218,7 @@ static void reportWave(Logging *logging, int index) { logging->appendPrintf("advance%d%s", index, LOG_DELIMITER); float angle = (offsetUs / oneDegreeUs) - tdcPosition(); - fixAngle(angle, "waveAn", CUSTOM_ERR_6564); + fixAngle(angle, "waveAn", ObdCode::CUSTOM_ERR_6564); logging->appendFloat(angle, 3); logging->appendPrintf("%s", LOG_DELIMITER); } diff --git a/firmware/hw_layer/adc/adc_inputs.cpp b/firmware/hw_layer/adc/adc_inputs.cpp index f68fdb1260..6b6606747d 100644 --- a/firmware/hw_layer/adc/adc_inputs.cpp +++ b/firmware/hw_layer/adc/adc_inputs.cpp @@ -164,7 +164,7 @@ static void fast_adc_callback(GPTDriver*) { ADC_FAST_DEVICE.state != ADC_COMPLETE && ADC_FAST_DEVICE.state != ADC_ERROR) { fastAdc.errorsCount++; - // todo: when? why? firmwareError(OBD_PCM_Processor_Fault, "ADC fast not ready?"); + // todo: when? why? firmwareError(ObdCode::OBD_PCM_Processor_Fault, "ADC fast not ready?"); chSysUnlockFromISR() ; return; @@ -186,7 +186,7 @@ float getMCUInternalTemperature() { int getInternalAdcValue(const char *msg, adc_channel_e hwChannel) { if (!isAdcChannelValid(hwChannel)) { - warning(CUSTOM_OBD_ANALOG_INPUT_NOT_CONFIGURED, "ADC: %s input is not configured", msg); + warning(ObdCode::CUSTOM_OBD_ANALOG_INPUT_NOT_CONFIGURED, "ADC: %s input is not configured", msg); return -1; } @@ -260,7 +260,7 @@ bool AdcDevice::isHwUsed(adc_channel_e hwChannelIndex) const { void AdcDevice::enableChannel(adc_channel_e hwChannel) { if ((channelCount + 1) >= ADC_MAX_CHANNELS_COUNT) { - firmwareError(OBD_PCM_Processor_Fault, "Too many ADC channels configured"); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "Too many ADC channels configured"); return; } diff --git a/firmware/hw_layer/adc/adc_subscription.cpp b/firmware/hw_layer/adc/adc_subscription.cpp index 4f9042a46b..f354e2e4a8 100644 --- a/firmware/hw_layer/adc/adc_subscription.cpp +++ b/firmware/hw_layer/adc/adc_subscription.cpp @@ -71,7 +71,7 @@ static AdcSubscriptionEntry* findEntry() { // Ensure that a free entry was found if (!entry) { - firmwareError(CUSTOM_INVALID_ADC, "too many ADC subscriptions subscribing %s", name); + firmwareError(ObdCode::CUSTOM_INVALID_ADC, "too many ADC subscriptions subscribing %s", name); return; } diff --git a/firmware/hw_layer/digital_input/digital_input_exti.cpp b/firmware/hw_layer/digital_input/digital_input_exti.cpp index c5100332c7..70d217f410 100644 --- a/firmware/hw_layer/digital_input/digital_input_exti.cpp +++ b/firmware/hw_layer/digital_input/digital_input_exti.cpp @@ -42,7 +42,7 @@ void efiExtiEnablePin(const char *msg, brain_pin_e brainPin, uint32_t mode, Exti return; } - efiAssertVoid(OBD_PCM_Processor_Fault, msg, "efiExtiEnablePin msg must not be null"); + efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, msg, "efiExtiEnablePin msg must not be null"); ioportid_t port = getHwPort(msg, brainPin); if (port == NULL) { @@ -61,7 +61,7 @@ void efiExtiEnablePin(const char *msg, brain_pin_e brainPin, uint32_t mode, Exti /* is this index already used? */ if (channel.Callback) { - firmwareError(CUSTOM_ERR_PIN_ALREADY_USED_2, "%s: pin %s/index %d: exti index already used by %s", + firmwareError(ObdCode::CUSTOM_ERR_PIN_ALREADY_USED_2, "%s: pin %s/index %d: exti index already used by %s", msg, hwPortname(brainPin), index, @@ -253,7 +253,7 @@ CH_FAST_IRQ_HANDLER(VectorE0) { // TODO: non-stm32 exti void efiExtiInit() { - firmwareError(OBD_PCM_Processor_Fault, "exti not supported"); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "exti not supported"); } void efiExtiEnablePin(const char *, brain_pin_e, uint32_t, ExtiCallback, void *) { } diff --git a/firmware/hw_layer/digital_input/trigger/trigger_input.cpp b/firmware/hw_layer/digital_input/trigger/trigger_input.cpp index 0e880709c7..a546b05653 100644 --- a/firmware/hw_layer/digital_input/trigger/trigger_input.cpp +++ b/firmware/hw_layer/digital_input/trigger/trigger_input.cpp @@ -91,7 +91,7 @@ static int turnOnTriggerInputPin(const char *msg, int index, bool isTriggerShaft return 0; } - firmwareError(CUSTOM_ERR_NOT_INPUT_PIN, "%s: Not input pin %s", msg, hwPortname(brainPin)); + firmwareError(ObdCode::CUSTOM_ERR_NOT_INPUT_PIN, "%s: Not input pin %s", msg, hwPortname(brainPin)); return -1; } diff --git a/firmware/hw_layer/drivers/can/can_hw.cpp b/firmware/hw_layer/drivers/can/can_hw.cpp index ec39080b58..03bcb6d893 100644 --- a/firmware/hw_layer/drivers/can/can_hw.cpp +++ b/firmware/hw_layer/drivers/can/can_hw.cpp @@ -292,7 +292,7 @@ void startCanPins() { // todo: smarter online change of settings, kill isCanEnabled with fire return; } - firmwareError(CUSTOM_OBD_70, "invalid CAN TX %s", hwPortname(engineConfiguration->canTxPin)); + firmwareError(ObdCode::CUSTOM_OBD_70, "invalid CAN TX %s", hwPortname(engineConfiguration->canTxPin)); return; } @@ -301,7 +301,7 @@ void startCanPins() { // todo: smarter online change of settings, kill isCanEnabled with fire return; } - firmwareError(CUSTOM_OBD_70, "invalid CAN RX %s", hwPortname(engineConfiguration->canRxPin)); + firmwareError(ObdCode::CUSTOM_OBD_70, "invalid CAN RX %s", hwPortname(engineConfiguration->canRxPin)); return; } @@ -355,7 +355,7 @@ void initCan() { // Devices can't be the same! if (device1 == device2) { - firmwareError(OBD_PCM_Processor_Fault, "CAN pins must be set to different devices"); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "CAN pins must be set to different devices"); return; } diff --git a/firmware/hw_layer/drivers/can/can_msg_tx.cpp b/firmware/hw_layer/drivers/can/can_msg_tx.cpp index cde4adf86f..784f2888bf 100644 --- a/firmware/hw_layer/drivers/can/can_msg_tx.cpp +++ b/firmware/hw_layer/drivers/can/can_msg_tx.cpp @@ -54,7 +54,7 @@ CanTxMessage::~CanTxMessage() { auto device = s_devices[busIndex]; if (!device) { - warning(CUSTOM_ERR_CAN_CONFIGURATION, "Send: CAN configuration issue %d", busIndex); + warning(ObdCode::CUSTOM_ERR_CAN_CONFIGURATION, "Send: CAN configuration issue %d", busIndex); return; } diff --git a/firmware/hw_layer/drivers/gpio/l9779.cpp b/firmware/hw_layer/drivers/gpio/l9779.cpp index 64aaf1bff7..3610ba7082 100644 --- a/firmware/hw_layer/drivers/gpio/l9779.cpp +++ b/firmware/hw_layer/drivers/gpio/l9779.cpp @@ -733,7 +733,7 @@ int L9779::deinit() int l9779_add(brain_pin_e base, unsigned int index, const l9779_config *cfg) { - efiAssert(OBD_PCM_Processor_Fault, cfg != NULL, "L9779CFG", 0) + efiAssert(ObdCode::OBD_PCM_Processor_Fault, cfg != NULL, "L9779CFG", 0) /* no config or no such chip */ if ((!cfg) || (!cfg->spi_bus) || (index >= BOARD_L9779_COUNT)) diff --git a/firmware/hw_layer/drivers/gpio/tle8888.cpp b/firmware/hw_layer/drivers/gpio/tle8888.cpp index 220614c107..0b987be96b 100644 --- a/firmware/hw_layer/drivers/gpio/tle8888.cpp +++ b/firmware/hw_layer/drivers/gpio/tle8888.cpp @@ -1235,7 +1235,7 @@ int Tle8888::deinit() int tle8888_add(brain_pin_e base, unsigned int index, const tle8888_config *cfg) { - efiAssert(OBD_PCM_Processor_Fault, cfg != NULL, "8888CFG", 0) + efiAssert(ObdCode::OBD_PCM_Processor_Fault, cfg != NULL, "8888CFG", 0) /* no config or no such chip */ if ((!cfg) || (!cfg->spi_bus) || (index >= BOARD_TLE8888_COUNT)) diff --git a/firmware/hw_layer/drivers/serial/serial_hw.cpp b/firmware/hw_layer/drivers/serial/serial_hw.cpp index 1a2cc59238..a478439fd7 100644 --- a/firmware/hw_layer/drivers/serial/serial_hw.cpp +++ b/firmware/hw_layer/drivers/serial/serial_hw.cpp @@ -73,12 +73,12 @@ void initAuxSerial(void) { // Validate pins if (isSerialTXEnabled && !isValidSerialTxPin(engineConfiguration->auxSerialTxPin)) { - firmwareError(OBD_PCM_Processor_Fault, "unexpected aux TX pin"); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "unexpected aux TX pin"); return; } if (isSerialRXEnabled && !isValidSerialRxPin(engineConfiguration->auxSerialRxPin)) { - firmwareError(OBD_PCM_Processor_Fault, "unexpected aux RX pin"); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "unexpected aux RX pin"); return; } diff --git a/firmware/hw_layer/hardware.cpp b/firmware/hw_layer/hardware.cpp index 36a314c449..a74d775393 100644 --- a/firmware/hw_layer/hardware.cpp +++ b/firmware/hw_layer/hardware.cpp @@ -80,7 +80,7 @@ extern bool isSpiInitialized[5]; * Only one consumer can use SPI bus at a given time */ void lockSpi(spi_device_e device) { - efiAssertVoid(CUSTOM_STACK_SPI, getCurrentRemainingStack() > 128, "lockSpi"); + efiAssertVoid(ObdCode::CUSTOM_STACK_SPI, getCurrentRemainingStack() > 128, "lockSpi"); spiAcquireBus(getSpiDevice(device)); } @@ -131,7 +131,7 @@ SPIDriver * getSpiDevice(spi_device_e spiDevice) { return &SPID4; } #endif - firmwareError(CUSTOM_ERR_UNEXPECTED_SPI, "Unexpected SPI device: %d", spiDevice); + firmwareError(ObdCode::CUSTOM_ERR_UNEXPECTED_SPI, "Unexpected SPI device: %d", spiDevice); return NULL; } #endif @@ -177,7 +177,7 @@ void onFastAdcComplete(adcsample_t*) { /** * this callback is executed 10 000 times a second, it needs to be as fast as possible */ - efiAssertVoid(CUSTOM_STACK_ADC, getCurrentRemainingStack() > 128, "lowstck#9b"); + efiAssertVoid(ObdCode::CUSTOM_STACK_ADC, getCurrentRemainingStack() > 128, "lowstck#9b"); #if EFI_SENSOR_CHART && EFI_SHAFT_POSITION_INPUT if (getEngineState()->sensorChartMode == SC_AUX_FAST1) { @@ -370,9 +370,7 @@ void setBor(int borValue) { // This function initializes hardware that can do so before configuration is loaded void initHardwareNoConfig() { - efiAssertVoid(CUSTOM_IH_STACK, getCurrentRemainingStack() > EXPECTED_REMAINING_STACK, "init h"); - efiAssertVoid(CUSTOM_EC_NULL, engineConfiguration!=NULL, "engineConfiguration"); - + efiAssertVoid(ObdCode::CUSTOM_IH_STACK, getCurrentRemainingStack() > EXPECTED_REMAINING_STACK, "init h"); efiPrintf("initHardware()"); diff --git a/firmware/hw_layer/io_pins.h b/firmware/hw_layer/io_pins.h index fc192360c7..7174b70e00 100644 --- a/firmware/hw_layer/io_pins.h +++ b/firmware/hw_layer/io_pins.h @@ -15,7 +15,7 @@ // mode >= 0 is always true since that's an unsigned #define assertOMode(mode) { \ - efiAssertVoid(CUSTOM_INVALID_MODE_SETTING, mode <= OM_OPENDRAIN_INVERTED, "invalid pin_output_mode_e"); \ + efiAssertVoid(ObdCode::CUSTOM_INVALID_MODE_SETTING, mode <= OM_OPENDRAIN_INVERTED, "invalid pin_output_mode_e"); \ } #define efiSetPadModeIfConfigurationChanged(msg, pin, mode) \ diff --git a/firmware/hw_layer/microsecond_timer/microsecond_timer.cpp b/firmware/hw_layer/microsecond_timer/microsecond_timer.cpp index 62c83f0743..18bbaa09ef 100644 --- a/firmware/hw_layer/microsecond_timer/microsecond_timer.cpp +++ b/firmware/hw_layer/microsecond_timer/microsecond_timer.cpp @@ -50,7 +50,7 @@ static bool hwStarted = false; * This function should be invoked under kernel lock which would disable interrupts. */ void setHardwareSchedulerTimer(efitick_t nowNt, efitick_t setTimeNt) { - efiAssertVoid(OBD_PCM_Processor_Fault, hwStarted, "HW.started"); + efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, hwStarted, "HW.started"); // How many ticks in the future is this event? auto timeDeltaNt = setTimeNt - nowNt; @@ -63,7 +63,7 @@ void setHardwareSchedulerTimer(efitick_t nowNt, efitick_t setTimeNt) { */ if (timeDeltaNt <= 0) { timerFreezeCounter++; - warning(CUSTOM_OBD_LOCAL_FREEZE, "local freeze cnt=%d", timerFreezeCounter); + warning(ObdCode::CUSTOM_OBD_LOCAL_FREEZE, "local freeze cnt=%d", timerFreezeCounter); } // We need the timer to fire after we return - 1 doesn't work as it may actually schedule in the past @@ -73,7 +73,7 @@ void setHardwareSchedulerTimer(efitick_t nowNt, efitick_t setTimeNt) { if (timeDeltaNt >= TOO_FAR_INTO_FUTURE_NT) { // we are trying to set callback for too far into the future. This does not look right at all - firmwareError(CUSTOM_ERR_TIMER_OVERFLOW, "setHardwareSchedulerTimer() too far: %d", timeDeltaNt); + firmwareError(ObdCode::CUSTOM_ERR_TIMER_OVERFLOW, "setHardwareSchedulerTimer() too far: %d", timeDeltaNt); return; } @@ -108,13 +108,13 @@ class MicrosecondTimerWatchdogController : public PeriodicTimerController { void PeriodicTask() override { efitick_t nowNt = getTimeNowNt(); if (nowNt >= lastSetTimerTimeNt + 2 * CORE_CLOCK) { - firmwareError(CUSTOM_ERR_SCHEDULING_ERROR, "watchdog: no events since %d", lastSetTimerTimeNt); + firmwareError(ObdCode::CUSTOM_ERR_SCHEDULING_ERROR, "watchdog: no events since %d", lastSetTimerTimeNt); return; } msg = isTimerPending ? "No_cb too long" : "Timer not awhile"; // 2 seconds of inactivity would not look right - efiAssertVoid(CUSTOM_TIMER_WATCHDOG, nowNt < lastSetTimerTimeNt + 2 * CORE_CLOCK, msg); + efiAssertVoid(ObdCode::CUSTOM_TIMER_WATCHDOG, nowNt < lastSetTimerTimeNt + 2 * CORE_CLOCK, msg); } int getPeriodMs() override { @@ -143,7 +143,7 @@ static void timerValidationCallback(void*) { efitimems_t actualTimeSinceScheduling = (getTimeNowMs() - testSchedulingStart); if (absI(actualTimeSinceScheduling - TEST_CALLBACK_DELAY) > TEST_CALLBACK_DELAY * TIMER_PRECISION_THRESHOLD) { - firmwareError(CUSTOM_ERR_TIMER_TEST_CALLBACK_WRONG_TIME, "hwTimer broken precision: %ld ms", actualTimeSinceScheduling); + firmwareError(ObdCode::CUSTOM_ERR_TIMER_TEST_CALLBACK_WRONG_TIME, "hwTimer broken precision: %ld ms", actualTimeSinceScheduling); } } @@ -162,7 +162,7 @@ static void validateHardwareTimer() { chThdSleepMilliseconds(TEST_CALLBACK_DELAY + 2); if (!testSchedulingHappened) { - firmwareError(CUSTOM_ERR_TIMER_TEST_CALLBACK_NOT_HAPPENED, "hwTimer not alive"); + firmwareError(ObdCode::CUSTOM_ERR_TIMER_TEST_CALLBACK_NOT_HAPPENED, "hwTimer not alive"); } } diff --git a/firmware/hw_layer/microsecond_timer/microsecond_timer_gpt.cpp b/firmware/hw_layer/microsecond_timer/microsecond_timer_gpt.cpp index 89e2e7803b..8ae73ee179 100644 --- a/firmware/hw_layer/microsecond_timer/microsecond_timer_gpt.cpp +++ b/firmware/hw_layer/microsecond_timer/microsecond_timer_gpt.cpp @@ -12,7 +12,7 @@ void portSetHardwareSchedulerTimer(efitick_t nowNt, efitick_t setTimeNt) { } if (GPTDEVICE.state != GPT_READY) { - firmwareError(CUSTOM_HW_TIMER, "HW timer state %d", GPTDEVICE.state); + firmwareError(ObdCode::CUSTOM_HW_TIMER, "HW timer state %d", GPTDEVICE.state); return; } @@ -34,7 +34,7 @@ static constexpr GPTConfig gpt5cfg = { 1000000, /* 1 MHz timer clock.*/ void portInitMicrosecondTimer() { gptStart(&GPTDEVICE, &gpt5cfg); - efiAssertVoid(CUSTOM_ERR_TIMER_STATE, GPTDEVICE.state == GPT_READY, "hw state"); + efiAssertVoid(ObdCode::CUSTOM_ERR_TIMER_STATE, GPTDEVICE.state == GPT_READY, "hw state"); } #endif // EFI_PROD_CODE diff --git a/firmware/hw_layer/mmc_card.cpp b/firmware/hw_layer/mmc_card.cpp index f4a6c9c330..b82953bec0 100644 --- a/firmware/hw_layer/mmc_card.cpp +++ b/firmware/hw_layer/mmc_card.cpp @@ -204,7 +204,7 @@ static void createLogFile() { FRESULT err = f_open(&FDLogFile, logName, FA_OPEN_ALWAYS | FA_WRITE); // Create new file if (err != FR_OK && err != FR_EXIST) { sdStatus = SD_STATE_OPEN_FAILED; - warning(CUSTOM_ERR_SD_MOUNT_FAILED, "SD: mount failed"); + warning(ObdCode::CUSTOM_ERR_SD_MOUNT_FAILED, "SD: mount failed"); printError("FS mount failed", err); // else - show error return; } @@ -212,7 +212,7 @@ static void createLogFile() { err = f_lseek(&FDLogFile, f_size(&FDLogFile)); // Move to end of the file to append data if (err) { sdStatus = SD_STATE_SEEK_FAILED; - warning(CUSTOM_ERR_SD_SEEK_FAILED, "SD: seek failed"); + warning(ObdCode::CUSTOM_ERR_SD_SEEK_FAILED, "SD: seek failed"); printError("Seek error", err); return; } diff --git a/firmware/hw_layer/pin_repository.cpp b/firmware/hw_layer/pin_repository.cpp index 0a67bbc0d4..9fdb78b401 100644 --- a/firmware/hw_layer/pin_repository.cpp +++ b/firmware/hw_layer/pin_repository.cpp @@ -63,7 +63,7 @@ bool brain_pin_markUsed(brain_pin_e brainPin, const char *msg) { if (getBrainUsedPin(index) != NULL) { /* TODO: get readable name of brainPin... */ - firmwareError(CUSTOM_ERR_PIN_ALREADY_USED_1, "Pin \"%s\" required by \"%s\" but is used by \"%s\" %s", + firmwareError(ObdCode::CUSTOM_ERR_PIN_ALREADY_USED_1, "Pin \"%s\" required by \"%s\" but is used by \"%s\" %s", hwPortname(brainPin), msg, getBrainUsedPin(index), @@ -281,8 +281,8 @@ bool gpio_pin_markUsed(ioportid_t port, ioportmask_t pin, const char *msg) { * todo: the problem is that this warning happens before the console is even * connected, so the warning is never displayed on the console and that's quite a problem! */ -// warning(OBD_PCM_Processor_Fault, "%s%d req by %s used by %s", portname(port), pin, msg, getBrainUsedPin(index)); - firmwareError(CUSTOM_ERR_PIN_ALREADY_USED_1, "%s%d req by %s used by %s", portname(port), pin, msg, getBrainUsedPin(index)); +// warning(ObdCode::OBD_PCM_Processor_Fault, "%s%d req by %s used by %s", portname(port), pin, msg, getBrainUsedPin(index)); + firmwareError(ObdCode::CUSTOM_ERR_PIN_ALREADY_USED_1, "%s%d req by %s used by %s", portname(port), pin, msg, getBrainUsedPin(index)); return true; } getBrainUsedPin(index) = msg; diff --git a/firmware/hw_layer/ports/chconf_common.h b/firmware/hw_layer/ports/chconf_common.h index 7b0bd4c033..104f95f6f7 100644 --- a/firmware/hw_layer/ports/chconf_common.h +++ b/firmware/hw_layer/ports/chconf_common.h @@ -16,16 +16,12 @@ #define CHPRINTF_USE_FLOAT TRUE -#if !defined(_FROM_ASM_) -#include "obd_error_codes.h" -#endif /* _FROM_ASM_ */ - #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ #ifndef __ASSEMBLER__ - void firmwareError(ObdCode code, const char *fmt, ...); + // void firmwareError(ObdCode code, const char *fmt, ...); void irqEnterHook(void); void irqExitHook(void); void contextSwitchHook(void); diff --git a/firmware/hw_layer/ports/cypress/cypress_common.cpp b/firmware/hw_layer/ports/cypress/cypress_common.cpp index d1b81443b5..2cebdded29 100644 --- a/firmware/hw_layer/ports/cypress/cypress_common.cpp +++ b/firmware/hw_layer/ports/cypress/cypress_common.cpp @@ -95,7 +95,7 @@ brain_pin_e getAdcChannelBrainPin(const char *msg, adc_channel_e hwChannel) { case EFI_ADC_31: return Gpio::C2; default: - firmwareError(CUSTOM_ERR_ADC_UNKNOWN_CHANNEL, "Unknown hw channel %d [%s]", hwChannel, msg); + firmwareError(ObdCode::CUSTOM_ERR_ADC_UNKNOWN_CHANNEL, "Unknown hw channel %d [%s]", hwChannel, msg); return Gpio::Invalid; } } diff --git a/firmware/hw_layer/ports/cypress/cypress_pins.cpp b/firmware/hw_layer/ports/cypress/cypress_pins.cpp index 2d11cb41b6..112882a45f 100644 --- a/firmware/hw_layer/ports/cypress/cypress_pins.cpp +++ b/firmware/hw_layer/ports/cypress/cypress_pins.cpp @@ -64,7 +64,7 @@ const char *portname(ioportid_t GPIOx) { } static int getPortIndex(ioportid_t port) { - efiAssert(CUSTOM_ERR_ASSERT, port != NULL, "null port", -1); + efiAssert(ObdCode::CUSTOM_ERR_ASSERT, port != NULL, "null port", -1); if (port == GPIOA) return 0; if (port == GPIOB) @@ -87,7 +87,7 @@ static int getPortIndex(ioportid_t port) { return 9; if (port == GPIOK) return 10; - firmwareError(CUSTOM_ERR_UNKNOWN_PORT, "unknown port"); + firmwareError(ObdCode::CUSTOM_ERR_UNKNOWN_PORT, "unknown port"); return -1; } @@ -106,7 +106,7 @@ int getBrainPinIndex(ioportid_t port, ioportmask_t pin) { ioportid_t getHwPort(const char *msg, brain_pin_e brainPin) { if (!isBrainPinValid(brainPin)) { - firmwareError(CUSTOM_ERR_INVALID_PIN, "%s: Invalid Gpio: %d", msg, brainPin); + firmwareError(ObdCode::CUSTOM_ERR_INVALID_PIN, "%s: Invalid Gpio: %d", msg, brainPin); return GPIO_NULL; } return ports[(brainPin - Gpio::A0) / PORT_SIZE]; @@ -123,7 +123,7 @@ ioportmask_t getHwPin(const char *msg, brain_pin_e brainPin) if (brain_pin_is_onchip(brainPin)) return getBrainPinIndex(brainPin); - firmwareError(CUSTOM_ERR_INVALID_PIN, "%s: Invalid on-chip brain_pin_e: %d", msg, brainPin); + firmwareError(ObdCode::CUSTOM_ERR_INVALID_PIN, "%s: Invalid on-chip brain_pin_e: %d", msg, brainPin); return EFI_ERROR_CODE; } diff --git a/firmware/hw_layer/ports/kinetis/kinetis_common.cpp b/firmware/hw_layer/ports/kinetis/kinetis_common.cpp index 3082959dd1..2942d6d915 100644 --- a/firmware/hw_layer/ports/kinetis/kinetis_common.cpp +++ b/firmware/hw_layer/ports/kinetis/kinetis_common.cpp @@ -65,7 +65,7 @@ brain_pin_e getAdcChannelBrainPin(const char *msg, adc_channel_e hwChannel) { case EFI_ADC_15: return Gpio::C17; default: - firmwareError(CUSTOM_ERR_ADC_UNKNOWN_CHANNEL, "Unknown hw channel %d [%s]", hwChannel, msg); + firmwareError(ObdCode::CUSTOM_ERR_ADC_UNKNOWN_CHANNEL, "Unknown hw channel %d [%s]", hwChannel, msg); return Gpio::Invalid; } } diff --git a/firmware/hw_layer/ports/kinetis/kinetis_pins.cpp b/firmware/hw_layer/ports/kinetis/kinetis_pins.cpp index 3044ca2c83..f5fcec64c8 100644 --- a/firmware/hw_layer/ports/kinetis/kinetis_pins.cpp +++ b/firmware/hw_layer/ports/kinetis/kinetis_pins.cpp @@ -39,7 +39,7 @@ const char *portname(ioportid_t GPIOx) { } static int getPortIndex(ioportid_t port) { - efiAssert(CUSTOM_ERR_ASSERT, port != NULL, "null port", -1); + efiAssert(ObdCode::CUSTOM_ERR_ASSERT, port != NULL, "null port", -1); if (port == GPIOA) return 0; if (port == GPIOB) @@ -50,7 +50,7 @@ static int getPortIndex(ioportid_t port) { return 3; if (port == GPIOE) return 4; - firmwareError(CUSTOM_ERR_UNKNOWN_PORT, "unknown port"); + firmwareError(ObdCode::CUSTOM_ERR_UNKNOWN_PORT, "unknown port"); return -1; } @@ -69,7 +69,7 @@ int getPortPinIndex(ioportid_t port, ioportmask_t pin) { ioportid_t getHwPort(const char *msg, brain_pin_e brainPin) { if (!isBrainPinValid(brainPin)) { - firmwareError(CUSTOM_ERR_INVALID_PIN, "%s: Invalid Gpio: %d", msg, brainPin); + firmwareError(ObdCode::CUSTOM_ERR_INVALID_PIN, "%s: Invalid Gpio: %d", msg, brainPin); return GPIO_NULL; } return ports[(brainPin - Gpio::A0) / PORT_SIZE]; @@ -86,7 +86,7 @@ ioportmask_t getHwPin(const char *msg, brain_pin_e brainPin) if (brain_pin_is_onchip(brainPin)) return getBrainPinIndex(brainPin); - firmwareError(CUSTOM_ERR_INVALID_PIN, "%s: Invalid on-chip Gpio: %d", msg, brainPin); + firmwareError(ObdCode::CUSTOM_ERR_INVALID_PIN, "%s: Invalid on-chip Gpio: %d", msg, brainPin); return EFI_ERROR_CODE; } diff --git a/firmware/hw_layer/ports/stm32/backup_ram.cpp b/firmware/hw_layer/ports/stm32/backup_ram.cpp index d6b0c4e33a..f126190652 100644 --- a/firmware/hw_layer/ports/stm32/backup_ram.cpp +++ b/firmware/hw_layer/ports/stm32/backup_ram.cpp @@ -21,7 +21,7 @@ uint32_t backupRamLoad(backup_ram_e idx) { // case DFU_JUMP_REQUESTED: // return RTCD1.rtc->BKP4R; default: - firmwareError(OBD_PCM_Processor_Fault, "Invalid backup ram idx %d", idx); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "Invalid backup ram idx %d", idx); return 0; } #else @@ -49,7 +49,7 @@ void backupRamSave(backup_ram_e idx, uint32_t value) { RTCD1.rtc->BKP4R = value; break; default: - firmwareError(OBD_PCM_Processor_Fault, "Invalid backup ram idx %d, value 0x08x", idx, value); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "Invalid backup ram idx %d, value 0x08x", idx, value); break; } #endif /* HAL_USE_RTC */ diff --git a/firmware/hw_layer/ports/stm32/stm32_adc_v2.cpp b/firmware/hw_layer/ports/stm32/stm32_adc_v2.cpp index 6507a15b4a..ab10991fcc 100644 --- a/firmware/hw_layer/ports/stm32/stm32_adc_v2.cpp +++ b/firmware/hw_layer/ports/stm32/stm32_adc_v2.cpp @@ -105,7 +105,7 @@ float getMcuTemperature() { if (degrees > 150.0f || degrees < -50.0f) { /* * we have a sporadic issue with this check todo https://github.com/rusefi/rusefi/issues/2552 - firmwareError(OBD_PCM_Processor_Fault, "Invalid CPU temperature measured %f", degrees); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "Invalid CPU temperature measured %f", degrees); */ } diff --git a/firmware/hw_layer/ports/stm32/stm32_common.cpp b/firmware/hw_layer/ports/stm32/stm32_common.cpp index e6ee589414..a2064185ec 100644 --- a/firmware/hw_layer/ports/stm32/stm32_common.cpp +++ b/firmware/hw_layer/ports/stm32/stm32_common.cpp @@ -92,7 +92,7 @@ brain_pin_e getAdcChannelBrainPin(const char *msg, adc_channel_e hwChannel) { default: /* todo: what is upper range ADC is used while lower range ADC is not used? how do we still mark pin used? external muxes for internal ADC #3350 - firmwareError(CUSTOM_ERR_ADC_UNKNOWN_CHANNEL, "Unknown hw channel %d [%s]", hwChannel, msg); + firmwareError(ObdCode::CUSTOM_ERR_ADC_UNKNOWN_CHANNEL, "Unknown hw channel %d [%s]", hwChannel, msg); */ return Gpio::Invalid; } @@ -135,7 +135,7 @@ adc_channel_e getAdcChannel(brain_pin_e pin) { case Gpio::Unassigned: return EFI_ADC_NONE; default: - firmwareError(OBD_PCM_Processor_Fault, "getAdcChannel %d", pin); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "getAdcChannel %d", pin); return EFI_ADC_ERROR; } } @@ -181,14 +181,14 @@ public: // These timers are only 16 bit - don't risk overflow if (m_period > 0xFFF0) { - firmwareError(CUSTOM_OBD_LOW_FREQUENCY, "PWM Frequency too low %f hz on pin \"%s\"", frequency, msg); + firmwareError(ObdCode::CUSTOM_OBD_LOW_FREQUENCY, "PWM Frequency too low %f hz on pin \"%s\"", frequency, msg); return; } // If we have too few usable bits, we run out of resolution, so don't allow that either. // 200 counts = 0.5% resolution if (m_period < 200) { - firmwareError(CUSTOM_OBD_HIGH_FREQUENCY, "PWM Frequency too high %d hz on pin \"%s\"", frequency, msg); + firmwareError(ObdCode::CUSTOM_OBD_HIGH_FREQUENCY, "PWM Frequency too high %d hz on pin \"%s\"", frequency, msg); return; } @@ -215,7 +215,7 @@ public: void setDuty(float duty) override { if (!m_driver) { - firmwareError(OBD_PCM_Processor_Fault, "Attempted to set duty on null hard PWM device"); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "Attempted to set duty on null hard PWM device"); return; } @@ -309,7 +309,7 @@ stm32_hardware_pwm* getNextPwmDevice() { } } - firmwareError(OBD_PCM_Processor_Fault, "Run out of hardware PWM devices!"); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "Run out of hardware PWM devices!"); return nullptr; } @@ -706,7 +706,7 @@ CANDriver* detectCanDevice(brain_pin_e pinRx, brain_pin_e pinTx) { if (isValidCan2RxPin(pinRx) && isValidCan2TxPin(pinTx)) return &CAND2; #endif - firmwareError(OBD_PCM_Processor_Fault, "invalid CAN pins tx %s and rx %s", hwPortname(pinTx), hwPortname(pinRx)); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "invalid CAN pins tx %s and rx %s", hwPortname(pinTx), hwPortname(pinRx)); return nullptr; } diff --git a/firmware/hw_layer/ports/stm32/stm32_pins.cpp b/firmware/hw_layer/ports/stm32/stm32_pins.cpp index d0c8c141cc..21eec6934f 100644 --- a/firmware/hw_layer/ports/stm32/stm32_pins.cpp +++ b/firmware/hw_layer/ports/stm32/stm32_pins.cpp @@ -99,7 +99,7 @@ const char *portname(ioportid_t GPIOx) { } static int getPortIndex(ioportid_t port) { - efiAssert(CUSTOM_ERR_ASSERT, port != NULL, "null port", -1); + efiAssert(ObdCode::CUSTOM_ERR_ASSERT, port != NULL, "null port", -1); if (port == GPIOA) return 0; if (port == GPIOB) @@ -136,7 +136,7 @@ static int getPortIndex(ioportid_t port) { if (port == GPIOK) return 10; #endif /* STM32_HAS_GPIOK */ - firmwareError(CUSTOM_ERR_UNKNOWN_PORT, "unknown port"); + firmwareError(ObdCode::CUSTOM_ERR_UNKNOWN_PORT, "unknown port"); return -1; } @@ -159,7 +159,7 @@ ioportid_t getHwPort(const char *msg, brain_pin_e brainPin) { if (!isBrainPinValid(brainPin)) { /* * https://github.com/dron0gus please help - firmwareError(CUSTOM_ERR_INVALID_PIN, "%s: Invalid Gpio: %d", msg, brainPin); + firmwareError(ObdCode::CUSTOM_ERR_INVALID_PIN, "%s: Invalid Gpio: %d", msg, brainPin); */ return GPIO_NULL; } @@ -177,7 +177,7 @@ ioportmask_t getHwPin(const char *msg, brain_pin_e brainPin) if (brain_pin_is_onchip(brainPin)) return getBrainPinIndex(brainPin); - firmwareError(CUSTOM_ERR_INVALID_PIN, "%s: Invalid on-chip Gpio: %d", msg, brainPin); + firmwareError(ObdCode::CUSTOM_ERR_INVALID_PIN, "%s: Invalid on-chip Gpio: %d", msg, brainPin); return EFI_ERROR_CODE; } diff --git a/firmware/hw_layer/ports/stm32/stm32f7/mpu_util.cpp b/firmware/hw_layer/ports/stm32/stm32f7/mpu_util.cpp index d4758f76f8..282c7f5325 100644 --- a/firmware/hw_layer/ports/stm32/stm32f7/mpu_util.cpp +++ b/firmware/hw_layer/ports/stm32/stm32f7/mpu_util.cpp @@ -39,14 +39,14 @@ static DeviceType determineDevice() { } else { if (fs == 1024) { // Unsupported scenario! Not enough space for program plus two config copies - firmwareError(OBD_PCM_Processor_Fault, "1MB single bank MCU detected: please clear nDBANK option bit and reinstall FW."); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "1MB single bank MCU detected: please clear nDBANK option bit and reinstall FW."); return DeviceType::SingleBank1MB; } else if (fs == 2048) { return DeviceType::SingleBank2MB; } } - firmwareError(OBD_PCM_Processor_Fault, "Unrecognized flash memory layout db=%d, size=%d", db, fs); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "Unrecognized flash memory layout db=%d, size=%d", db, fs); return DeviceType::Unknown; } diff --git a/firmware/hw_layer/rtc_helper.cpp b/firmware/hw_layer/rtc_helper.cpp index b9f9c4b7f9..a9159b1ad9 100644 --- a/firmware/hw_layer/rtc_helper.cpp +++ b/firmware/hw_layer/rtc_helper.cpp @@ -91,7 +91,7 @@ RTCDateTime convertRtcDateTimeFromEfi(efidatetime_t const * const dateTime) { static void put2(int offset, char *lcd_str, int value) { static char buff[_MAX_FILLER]; - efiAssertVoid(CUSTOM_ERR_6666, value >=0 && value <100, "value"); + efiAssertVoid(ObdCode::CUSTOM_ERR_6666, value >=0 && value <100, "value"); itoa10(buff, value); if (value < 10) { lcd_str[offset] = '0'; diff --git a/firmware/hw_layer/smart_gpio.cpp b/firmware/hw_layer/smart_gpio.cpp index 01305aa5d2..dc16136f8c 100644 --- a/firmware/hw_layer/smart_gpio.cpp +++ b/firmware/hw_layer/smart_gpio.cpp @@ -221,7 +221,7 @@ void initSmartGpio() { tle6240.spi_bus = getSpiDevice(engineConfiguration->tle6240spiDevice); int ret = tle6240_add(Gpio::TLE6240_PIN_1, 0, &tle6240); - efiAssertVoid(OBD_PCM_Processor_Fault, ret == (int)Gpio::TLE6240_PIN_1, "tle6240"); + efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, ret == (int)Gpio::TLE6240_PIN_1, "tle6240"); } #endif /* (BOARD_TLE6240_COUNT > 0) */ @@ -234,7 +234,7 @@ void initSmartGpio() { // todo: propogate 'basePinOffset' parameter int ret = mc33972_add(Gpio::MC33972_PIN_1, 0, &mc33972); - efiAssertVoid(OBD_PCM_Processor_Fault, ret == (int)Gpio::MC33972_PIN_1, "mc33972"); + efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, ret == (int)Gpio::MC33972_PIN_1, "mc33972"); } #endif /* (BOARD_MC33972_COUNT > 0) */ @@ -247,7 +247,7 @@ void initSmartGpio() { // todo: propogate 'basePinOffset' parameter int ret = l9779_add(Gpio::L9779_IGN_1, 0, &l9779_cfg); - efiAssertVoid(OBD_PCM_Processor_Fault, ret == (int)Gpio::L9779_IGN_1, "l9779"); + efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, ret == (int)Gpio::L9779_IGN_1, "l9779"); } #endif /* (BOARD_L9779_COUNT > 0) */ @@ -264,7 +264,7 @@ void initSmartGpio() { /* spi_bus == null checked in _add function */ int ret = tle8888_add(Gpio::TLE8888_PIN_1, 0, &tle8888_cfg); - efiAssertVoid(OBD_PCM_Processor_Fault, ret == (int)Gpio::TLE8888_PIN_1, "tle8888"); + efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, ret == (int)Gpio::TLE8888_PIN_1, "tle8888"); } #endif /* (BOARD_TLE8888_COUNT > 0) */ @@ -275,7 +275,7 @@ void initSmartGpio() { drv8860.spi_bus = getSpiDevice(engineConfiguration->drv8860spiDevice); int ret = drv8860_add(Gpio::DRV8860_PIN_1, 0, &drv8860); - efiAssertVoid(OBD_PCM_Processor_Fault, ret == (int)Gpio::DRV8860_PIN_1, "drv8860"); + efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, ret == (int)Gpio::DRV8860_PIN_1, "drv8860"); } #endif /* (BOARD_DRV8860_COUNT > 0) */ diff --git a/firmware/hw_layer/stepper_dual_hbridge.cpp b/firmware/hw_layer/stepper_dual_hbridge.cpp index fcc3b9260c..16775b82e0 100644 --- a/firmware/hw_layer/stepper_dual_hbridge.cpp +++ b/firmware/hw_layer/stepper_dual_hbridge.cpp @@ -41,7 +41,7 @@ void DualHBridgeStepper::initialize(DcMotor* motorPhaseA, DcMotor* motorPhaseB, m_motorPhaseA = motorPhaseA; m_motorPhaseB = motorPhaseB; - efiAssertVoid(CUSTOM_ERR_ASSERT, engineConfiguration->stepperNumMicroSteps <= maxNumSteps, "stepperNumMicroSteps"); + efiAssertVoid(ObdCode::CUSTOM_ERR_ASSERT, engineConfiguration->stepperNumMicroSteps <= maxNumSteps, "stepperNumMicroSteps"); } bool DualHBridgeStepper::step(bool positive) { diff --git a/firmware/init/sensor/init_lambda.cpp b/firmware/init/sensor/init_lambda.cpp index c5e52f480c..a68fac7119 100644 --- a/firmware/init/sensor/init_lambda.cpp +++ b/firmware/init/sensor/init_lambda.cpp @@ -50,7 +50,7 @@ void initLambda() { #if EFI_CAN_SUPPORT if (engineConfiguration->enableAemXSeries) { if (!engineConfiguration->canWriteEnabled || !engineConfiguration->canReadEnabled) { - firmwareError(OBD_PCM_Processor_Fault, "CAN read and write are required to use CAN wideband."); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "CAN read and write are required to use CAN wideband."); return; } diff --git a/firmware/init/sensor/init_map.cpp b/firmware/init/sensor/init_map.cpp index 34eff18a9f..89522e6ea1 100644 --- a/firmware/init/sensor/init_map.cpp +++ b/firmware/init/sensor/init_map.cpp @@ -68,7 +68,7 @@ static MapCfg getMapCfg(air_pressure_sensor_type_e sensorType) { case MT_MPXH6400: return {0.2, 20, 4.8, 400}; default: - firmwareError(CUSTOM_ERR_MAP_TYPE, "Unknown MAP type: decoder %d", sensorType); + firmwareError(ObdCode::CUSTOM_ERR_MAP_TYPE, "Unknown MAP type: decoder %d", sensorType); // falls through to custom return {}; case MT_CUSTOM: { diff --git a/firmware/init/sensor/init_thermistors.cpp b/firmware/init/sensor/init_thermistors.cpp index e40741dc45..57448588a0 100644 --- a/firmware/init/sensor/init_thermistors.cpp +++ b/firmware/init/sensor/init_thermistors.cpp @@ -26,7 +26,7 @@ static FuncPair fclt, fiat, faux1, faux2; static void validateThermistorConfig(const char *msg, thermistor_conf_s& cfg) { if (cfg.tempC_1 >= cfg.tempC_2 || cfg.tempC_2 >= cfg.tempC_3) { - firmwareError(OBD_ThermistorConfig, "Invalid thermistor %s configuration: please check that temperatures are in the ascending order %f %f %f", + firmwareError(ObdCode::OBD_ThermistorConfig, "Invalid thermistor %s configuration: please check that temperatures are in the ascending order %f %f %f", msg, cfg.tempC_1, cfg.tempC_2, diff --git a/firmware/init/sensor/init_tps.cpp b/firmware/init/sensor/init_tps.cpp index 01edb93938..2f2eab3477 100644 --- a/firmware/init/sensor/init_tps.cpp +++ b/firmware/init/sensor/init_tps.cpp @@ -70,7 +70,7 @@ private: // If the voltage for closed vs. open is very near, something is wrong with your calibration if (split < 0.5f) { - firmwareError(OBD_TPS_Configuration, "\"%s\" problem: open %.2f/closed %.2f cal values are too close together. Check your calibration and wiring!", name(), + firmwareError(ObdCode::OBD_TPS_Configuration, "\"%s\" problem: open %.2f/closed %.2f cal values are too close together. Check your calibration and wiring!", name(), cfg.open, cfg.closed); return false; @@ -116,7 +116,7 @@ public: bool tooCloseOpen = absF(primary.open - secondary.open) < 0.2f; if (hasBothSensors && tooCloseClosed && tooCloseOpen) { - firmwareError(OBD_TPS_Configuration, "Configuration for redundant pair %s/%s are too similar - did you wire one sensor to both inputs...?", m_pri.name(), m_sec.name()); + firmwareError(ObdCode::OBD_TPS_Configuration, "Configuration for redundant pair %s/%s are too similar - did you wire one sensor to both inputs...?", m_pri.name(), m_sec.name()); return; } } @@ -189,7 +189,7 @@ bool isDigitalTps1() { } void initTps() { - efiAssertVoid(OBD_PCM_Processor_Fault, engineConfiguration != nullptr, "null engineConfiguration"); + efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, engineConfiguration != nullptr, "null engineConfiguration"); percent_t min = engineConfiguration->tpsErrorDetectionTooLow; percent_t max = engineConfiguration->tpsErrorDetectionTooHigh; diff --git a/firmware/util/cli_registry.cpp b/firmware/util/cli_registry.cpp index 1f2e7e6a30..e880b0912c 100644 --- a/firmware/util/cli_registry.cpp +++ b/firmware/util/cli_registry.cpp @@ -44,16 +44,16 @@ static void doAddAction(const char *token, action_type_e type, Void callback, vo for (uint32_t i = 0; i < efiStrlen(token);i++) { char ch = token[i]; if (isupper(ch)) { - firmwareError(CUSTOM_ERR_COMMAND_LOWER_CASE_EXPECTED, "lowerCase expected [%s]", token); + firmwareError(ObdCode::CUSTOM_ERR_COMMAND_LOWER_CASE_EXPECTED, "lowerCase expected [%s]", token); } } for (int i = 0; i < consoleActionCount; i++) { if (strcmp(token, consoleActions[i].token) == 0 /* zero result means strings are equal */) { - firmwareError(CUSTOM_SAME_TWICE, "Same action twice [%s]", token); + firmwareError(ObdCode::CUSTOM_SAME_TWICE, "Same action twice [%s]", token); } } - efiAssertVoid(CUSTOM_CONSOLE_TOO_MANY, consoleActionCount < CONSOLE_MAX_ACTIONS, "Too many console actions"); + efiAssertVoid(ObdCode::CUSTOM_CONSOLE_TOO_MANY, consoleActionCount < CONSOLE_MAX_ACTIONS, "Too many console actions"); TokenCallback *current = &consoleActions[consoleActionCount++]; current->token = token; current->parameterType = type; diff --git a/firmware/util/containers/fl_stack.h b/firmware/util/containers/fl_stack.h index 05484a9a31..3ad4e41b23 100644 --- a/firmware/util/containers/fl_stack.h +++ b/firmware/util/containers/fl_stack.h @@ -57,7 +57,7 @@ bool FLStack::remove(T value) { template void FLStack::push(T value) { if (currentSize >= MAXSIZE) { - firmwareError(ERROR_FL_STACK_OVERFLOW, "FLstack overflow"); + firmwareError(ObdCode::ERROR_FL_STACK_OVERFLOW, "FLstack overflow"); return; //warning() } @@ -67,7 +67,7 @@ void FLStack::push(T value) { template T FLStack::pop() { if (currentSize == 0) { - firmwareError(CUSTOM_FLSTACK, "FLStack is empty"); + firmwareError(ObdCode::CUSTOM_FLSTACK, "FLStack is empty"); } return values[--currentSize]; } @@ -77,7 +77,7 @@ T FLStack::pop() { */ template T FLStack::get(int index) { - efiAssert(CUSTOM_ERR_ASSERT, index >= 0 && index < MAXSIZE, "FLget", values[0]); + efiAssert(ObdCode::CUSTOM_ERR_ASSERT, index >= 0 && index < MAXSIZE, "FLget", values[0]); return values[index]; } @@ -105,7 +105,7 @@ ArrayList::ArrayList(void) { template void ArrayList::removeAt(int index) { - efiAssertVoid(CUSTOM_ERR_ARRAY_REMOVE, index >= 0 && index < size, "invalid index"); + efiAssertVoid(ObdCode::CUSTOM_ERR_ARRAY_REMOVE, index >= 0 && index < size, "invalid index"); memcpy(&elements[index], &elements[size - 1], sizeof(Type)); memset(&elements[size - 1], 0, sizeof(Type)); size--; @@ -118,6 +118,6 @@ void ArrayList::reset(void) { template Type * ArrayList::add(void) { - efiAssert(CUSTOM_ERR_ASSERT, size < Dimention, "add() too many elements", (Type *)NULL); + efiAssert(ObdCode::CUSTOM_ERR_ASSERT, size < Dimention, "add() too many elements", (Type *)NULL); return &elements[size++]; } diff --git a/firmware/util/containers/listener_array.h b/firmware/util/containers/listener_array.h index b52689fb98..f5b6b94aa2 100644 --- a/firmware/util/containers/listener_array.h +++ b/firmware/util/containers/listener_array.h @@ -63,7 +63,7 @@ void IntListenerArray::clear() { template void IntListenerArray::registerCallback(VoidInt handler, void *arg) { - efiAssertVoid(CUSTOM_ERR_6606, currentListenersCount < MAX_INT_LISTENER_COUNT, "Too many callbacks"); + efiAssertVoid(ObdCode::CUSTOM_ERR_6606, currentListenersCount < MAX_INT_LISTENER_COUNT, "Too many callbacks"); int index = currentListenersCount++; callbacks[index] = handler; args[index] = arg; diff --git a/firmware/util/containers/table_helper.h b/firmware/util/containers/table_helper.h index 0f7a9159e5..4605a332c1 100644 --- a/firmware/util/containers/table_helper.h +++ b/firmware/util/containers/table_helper.h @@ -52,7 +52,7 @@ public: } void setAll(TValue value) { - efiAssertVoid(CUSTOM_ERR_6573, m_values, "map not initialized"); + efiAssertVoid(ObdCode::CUSTOM_ERR_6573, m_values, "map not initialized"); for (size_t r = 0; r < TRowNum; r++) { for (size_t c = 0; c < TColNum; c++) { diff --git a/firmware/util/datalogging.cpp b/firmware/util/datalogging.cpp index 81b22d304d..7c7a12b743 100644 --- a/firmware/util/datalogging.cpp +++ b/firmware/util/datalogging.cpp @@ -45,7 +45,7 @@ bool Logging::validateBuffer(uint32_t extraLen) { if (remainingSize() < extraLen + 1) { #if EFI_PROD_CODE - warning(CUSTOM_LOGGING_BUFFER_OVERFLOW, "output overflow %s %d", name, extraLen); + warning(ObdCode::CUSTOM_LOGGING_BUFFER_OVERFLOW, "output overflow %s %d", name, extraLen); #endif /* EFI_PROD_CODE */ return true; } @@ -54,7 +54,7 @@ bool Logging::validateBuffer(uint32_t extraLen) { } void Logging::append(const char *text) { - efiAssertVoid(CUSTOM_APPEND_NULL, text != NULL, "append NULL"); + efiAssertVoid(ObdCode::CUSTOM_APPEND_NULL, text != NULL, "append NULL"); uint32_t extraLen = efiStrlen(text); bool isCapacityProblem = validateBuffer(extraLen); if (isCapacityProblem) { @@ -78,7 +78,7 @@ void Logging::appendFast(const char *text) { } void Logging::appendPrintf(const char *fmt, ...) { - efiAssertVoid(CUSTOM_APPEND_STACK, getCurrentRemainingStack() > 128, "lowstck#4"); + efiAssertVoid(ObdCode::CUSTOM_APPEND_STACK, getCurrentRemainingStack() > 128, "lowstck#4"); size_t available = remainingSize(); diff --git a/firmware/util/efilib.cpp b/firmware/util/efilib.cpp index 2c3aef6396..0d32066873 100644 --- a/firmware/util/efilib.cpp +++ b/firmware/util/efilib.cpp @@ -31,7 +31,7 @@ float efiFloor(float value, float precision) { * @param precision for example '0.1' for one digit fractional part */ float efiRound(float value, float precision) { - efiAssert(CUSTOM_ERR_ASSERT, precision != 0, "zero precision", NAN); + efiAssert(ObdCode::CUSTOM_ERR_ASSERT, precision != 0, "zero precision", NAN); float a = round(value / precision); return fixNegativeZero(a * precision); } diff --git a/firmware/util/efilib.h b/firmware/util/efilib.h index ef98383f63..9f309a580b 100644 --- a/firmware/util/efilib.h +++ b/firmware/util/efilib.h @@ -97,9 +97,9 @@ bool isPhaseInRange(float test, float current, float next); #define IS_NEGATIVE_ZERO(value) (__builtin_signbit(value) && value==0) #define fixNegativeZero(value) (IS_NEGATIVE_ZERO(value) ? 0 : value) -#define assertIsInBounds(length, array, msg) efiAssertVoid(OBD_PCM_Processor_Fault, std::is_unsigned_v && (length) < efi::size(array), msg) +#define assertIsInBounds(length, array, msg) efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, std::is_unsigned_v && (length) < efi::size(array), msg) -#define assertIsInBoundsWithResult(length, array, msg, failedResult) efiAssert(OBD_PCM_Processor_Fault, std::is_unsigned_v && (length) < efi::size(array), msg, failedResult) +#define assertIsInBoundsWithResult(length, array, msg, failedResult) efiAssert(ObdCode::OBD_PCM_Processor_Fault, std::is_unsigned_v && (length) < efi::size(array), msg, failedResult) template bool isInRange(T min, T val, T max) { diff --git a/firmware/util/histogram.cpp b/firmware/util/histogram.cpp index 93637b8013..912e9e5ea9 100644 --- a/firmware/util/histogram.cpp +++ b/firmware/util/histogram.cpp @@ -64,7 +64,7 @@ void initHistogramsModule(void) { * @brief This internal method is only public so that we can test it. */ int histogramGetIndex(int64_t value) { - efiAssert(CUSTOM_ERR_ASSERT, initialized, "histo initialized", 0); + efiAssert(ObdCode::CUSTOM_ERR_ASSERT, initialized, "histo initialized", 0); if (value < 0) return 0; if (value < SBI_SIZE) @@ -104,7 +104,7 @@ void hsAdd(histogram_s *h, int64_t value) { int count = 1; h->total_value += value; h->total_count += count; - efiAssertVoid(CUSTOM_ERR_6670, index < BOUND_LENGTH, "histogram issue"); + efiAssertVoid(ObdCode::CUSTOM_ERR_6670, index < BOUND_LENGTH, "histogram issue"); h->values[index] += count; } diff --git a/firmware/util/loggingcentral.cpp b/firmware/util/loggingcentral.cpp index c69e763e45..8aaa1f5d10 100644 --- a/firmware/util/loggingcentral.cpp +++ b/firmware/util/loggingcentral.cpp @@ -110,7 +110,7 @@ const char* swapOutputBuffers(size_t* actualOutputBufferSize) { // Check that the actual length of the buffer matches the expected length of how much we thought we wrote if (*actualOutputBufferSize != expectedOutputSize) { - firmwareError(ERROR_LOGGING_SIZE_CALC, "lsize mismatch %d vs strlen %d", *actualOutputBufferSize, expectedOutputSize); + firmwareError(ObdCode::ERROR_LOGGING_SIZE_CALC, "lsize mismatch %d vs strlen %d", *actualOutputBufferSize, expectedOutputSize); return nullptr; } diff --git a/firmware/util/math/biquad.cpp b/firmware/util/math/biquad.cpp index b7f0d0e345..5d6a6350b0 100644 --- a/firmware/util/math/biquad.cpp +++ b/firmware/util/math/biquad.cpp @@ -30,7 +30,7 @@ static float getNorm(float K, float Q) { } void Biquad::configureBandpass(float samplingFrequency, float centerFrequency, float Q) { - efiAssertVoid(OBD_PCM_Processor_Fault, samplingFrequency >= 2.5f * centerFrequency, "Invalid biquad parameters"); + efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, samplingFrequency >= 2.5f * centerFrequency, "Invalid biquad parameters"); float K = getK(samplingFrequency, centerFrequency); float norm = getNorm(K, Q); @@ -43,7 +43,7 @@ void Biquad::configureBandpass(float samplingFrequency, float centerFrequency, f } void Biquad::configureLowpass(float samplingFrequency, float cutoffFrequency, float Q) { - efiAssertVoid(OBD_PCM_Processor_Fault, samplingFrequency >= 2.5f * cutoffFrequency, "Invalid biquad parameters"); + efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, samplingFrequency >= 2.5f * cutoffFrequency, "Invalid biquad parameters"); float K = getK(samplingFrequency, cutoffFrequency); float norm = getNorm(K, Q); diff --git a/firmware/util/math/efi_interpolation.h b/firmware/util/math/efi_interpolation.h index 07f17fd121..d0a0388496 100644 --- a/firmware/util/math/efi_interpolation.h +++ b/firmware/util/math/efi_interpolation.h @@ -36,7 +36,7 @@ void ensureArrayIsAscending(const char* msg, const TValue (&values)[TSize]) { float cur = values[i]; float next = values[i + 1]; if (next <= cur) { - firmwareError(CUSTOM_ERR_AXIS_ORDER, "Invalid table axis (must be ascending!): %s %f %f at %d", msg, cur, next, i); + firmwareError(ObdCode::CUSTOM_ERR_AXIS_ORDER, "Invalid table axis (must be ascending!): %s %f %f at %d", msg, cur, next, i); } } } @@ -59,7 +59,7 @@ template int findIndexMsgExt(const char *msg, const kType array[], int size, kType value) { float fvalue = (float)value; if (cisnan(fvalue)) { - firmwareError(ERROR_NAN_FIND_INDEX, "NaN in findIndex%s", msg); + firmwareError(ObdCode::ERROR_NAN_FIND_INDEX, "NaN in findIndex%s", msg); return 0; } @@ -75,7 +75,7 @@ int findIndexMsgExt(const char *msg, const kType array[], int size, kType value) #if 0 // that's an assertion to make sure we do not loop here size--; - efiAssert(CUSTOM_ERR_ASSERT, size > 0, "Unexpected state in binary search", 0); + efiAssert(ObdCode::CUSTOM_ERR_ASSERT, size > 0, "Unexpected state in binary search", 0); #endif // todo: compare current implementation with @@ -90,9 +90,9 @@ int findIndexMsgExt(const char *msg, const kType array[], int size, kType value) if (middle != 0 && array[middle - 1] > array[middle]) { #if EFI_UNIT_TEST - firmwareError(CUSTOM_ERR_6610, "%s: out of order %.2f %.2f", msg, array[middle - 1], array[middle]); + firmwareError(ObdCode::CUSTOM_ERR_6610, "%s: out of order %.2f %.2f", msg, array[middle - 1], array[middle]); #else - warning(CUSTOM_ERR_OUT_OF_ORDER, "%s: out of order %.2f %.2f", msg, array[middle - 1], array[middle]); + warning(ObdCode::CUSTOM_ERR_OUT_OF_ORDER, "%s: out of order %.2f %.2f", msg, array[middle - 1], array[middle]); #endif /* EFI_UNIT_TEST */ } diff --git a/firmware/util/math/efi_pid.cpp b/firmware/util/math/efi_pid.cpp index 9e80d496bb..997f73659c 100644 --- a/firmware/util/math/efi_pid.cpp +++ b/firmware/util/math/efi_pid.cpp @@ -33,7 +33,7 @@ bool Pid::isSame(const pid_s *parameters) const { // this 'null' could happen on first execution during initialization return false; } - efiAssert(OBD_PCM_Processor_Fault, parameters != NULL, "PID::isSame NULL", false); + efiAssert(ObdCode::OBD_PCM_Processor_Fault, parameters != NULL, "PID::isSame NULL", false); return this->parameters->pFactor == parameters->pFactor && this->parameters->iFactor == parameters->iFactor && this->parameters->dFactor == parameters->dFactor @@ -62,7 +62,7 @@ float Pid::getUnclampedOutput(float target, float input, float dTime) { previousError = error; if (dTime <=0) { - warning(CUSTOM_PID_DTERM, "PID: unexpected dTime"); + warning(ObdCode::CUSTOM_PID_DTERM, "PID: unexpected dTime"); return pTerm + getOffset(); } diff --git a/firmware/util/math/interpolation.cpp b/firmware/util/math/interpolation.cpp index bfd6fc7161..7d0a01710d 100644 --- a/firmware/util/math/interpolation.cpp +++ b/firmware/util/math/interpolation.cpp @@ -73,11 +73,11 @@ static void testBinary() { */ float interpolateMsg(const char *msg, float x1, float y1, float x2, float y2, float x) { if (cisnan(x1) || cisnan(x2) || cisnan(y1) || cisnan(y2)) { - warning(CUSTOM_INTEPOLATE_ERROR, "interpolate%s: why param", msg); + warning(ObdCode::CUSTOM_INTEPOLATE_ERROR, "interpolate%s: why param", msg); return NAN; } if (cisnan(x)) { - warning(CUSTOM_INTEPOLATE_ERROR, "interpolate%s: why X", msg); + warning(ObdCode::CUSTOM_INTEPOLATE_ERROR, "interpolate%s: why X", msg); return NAN; } // todo: double comparison using EPS @@ -85,16 +85,16 @@ float interpolateMsg(const char *msg, float x1, float y1, float x2, float y2, fl /** * we could end up here for example while resetting bins while changing engine type */ - warning(CUSTOM_INTEPOLATE_ERROR, "interpolate%s: Same x1 and x2 in interpolate: %.2f/%.2f", msg, x1, x2); + warning(ObdCode::CUSTOM_INTEPOLATE_ERROR, "interpolate%s: Same x1 and x2 in interpolate: %.2f/%.2f", msg, x1, x2); return NAN; } // a*x1 + b = y1 // a*x2 + b = y2 -// efiAssertVoid(CUSTOM_ERR_ASSERT_VOID, x1 != x2, "no way we can interpolate"); +// efiAssertVoid(ObdCode::CUSTOM_ERR_ASSERT_VOID, x1 != x2, "no way we can interpolate"); float a = INTERPOLATION_A(x1, y1, x2, y2); if (cisnan(a)) { - warning(CUSTOM_INTEPOLATE_ERROR, "interpolate%s: why a", msg); + warning(ObdCode::CUSTOM_INTEPOLATE_ERROR, "interpolate%s: why a", msg); return NAN; } float b = y1 - a * x1; @@ -129,15 +129,15 @@ float interpolateClamped(float x1, float y1, float x2, float y2, float x) { * Another implementation, which one is faster? */ int findIndex2(const float array[], unsigned size, float value) { - efiAssert(CUSTOM_ERR_ASSERT, !cisnan(value), "NaN in findIndex2", 0); - efiAssert(CUSTOM_ERR_ASSERT, size > 1, "size in findIndex", 0); + efiAssert(ObdCode::CUSTOM_ERR_ASSERT, !cisnan(value), "NaN in findIndex2", 0); + efiAssert(ObdCode::CUSTOM_ERR_ASSERT, size > 1, "size in findIndex", 0); // if (size <= 1) // return size && *array <= value ? 0 : -1; signed i = 0; //unsigned b = 1 << int(log(float(size) - 1) / 0.69314718055994530942); unsigned b = size >> 1; // in our case size is always a power of 2 - efiAssert(CUSTOM_ERR_ASSERT, b + b == size, "Size not power of 2", -1); + efiAssert(ObdCode::CUSTOM_ERR_ASSERT, b + b == size, "Size not power of 2", -1); for (; b; b >>= 1) { unsigned j = i | b; /** @@ -145,7 +145,7 @@ int findIndex2(const float array[], unsigned size, float value) { * "if (j < size && array[j] <= value)" * but in our case size is always power of 2 thus size is always more then j */ - // efiAssert(CUSTOM_ERR_ASSERT, j < size, "size", 0); + // efiAssert(ObdCode::CUSTOM_ERR_ASSERT, j < size, "size", 0); if (array[j] <= value) i = j; } diff --git a/simulator/simulator/rusEfiFunctionalTest.cpp b/simulator/simulator/rusEfiFunctionalTest.cpp index aa611dcde2..dd2f8a0008 100644 --- a/simulator/simulator/rusEfiFunctionalTest.cpp +++ b/simulator/simulator/rusEfiFunctionalTest.cpp @@ -39,7 +39,7 @@ int getRemainingStack(thread_t*) { static void assertString(const char*actual, const char *expected) { if (strcmp(actual, expected) != 0) { printf("assertString FAILED\n"); - firmwareError(OBD_PCM_Processor_Fault, "chprintf test: got %s while %s", actual, expected); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "chprintf test: got %s while %s", actual, expected); } } diff --git a/unit_tests/engine_test_helper.cpp b/unit_tests/engine_test_helper.cpp index 69b8ae06e4..c1592ac548 100644 --- a/unit_tests/engine_test_helper.cpp +++ b/unit_tests/engine_test_helper.cpp @@ -36,7 +36,7 @@ EngineTestHelperBase::EngineTestHelperBase(Engine * eng, engine_configuration_s minCrankingRpm = 0; EnableToothLogger(); if (engine || engineConfiguration || config) { - firmwareError(OBD_PCM_Processor_Fault, + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "Engine configuration not cleaned up by previous test"); } engine = eng; diff --git a/unit_tests/logicdata_csv_reader.cpp b/unit_tests/logicdata_csv_reader.cpp index 586b118455..c30f28a44e 100644 --- a/unit_tests/logicdata_csv_reader.cpp +++ b/unit_tests/logicdata_csv_reader.cpp @@ -80,7 +80,7 @@ void CsvReader::processLine(EngineTestHelper *eth) { } if (timeStampstr == nullptr) { - firmwareError(OBD_PCM_Processor_Fault, "End of File"); + firmwareError(ObdCode::OBD_PCM_Processor_Fault, "End of File"); return; } diff --git a/unit_tests/tests/test_util.cpp b/unit_tests/tests/test_util.cpp index 9226a4c1fb..e140c63b66 100644 --- a/unit_tests/tests/test_util.cpp +++ b/unit_tests/tests/test_util.cpp @@ -139,15 +139,15 @@ static void testMalfunctionCentralRemoveNonExistent() { clearWarnings(); // this should not crash - removeError(OBD_TPS1_Correlation); + removeError(ObdCode::OBD_TPS1_Correlation); } static void testMalfunctionCentralSameElementAgain() { clearWarnings(); error_codes_set_s localCopy; - addError(OBD_TPS1_Correlation); - addError(OBD_TPS1_Correlation); + addError(ObdCode::OBD_TPS1_Correlation); + addError(ObdCode::OBD_TPS1_Correlation); getErrorCodes(&localCopy); ASSERT_EQ(1, localCopy.count); } diff --git a/unit_tests/tests/trigger/test_cam_vvt_input.cpp b/unit_tests/tests/trigger/test_cam_vvt_input.cpp index 4695827cdc..23577180a3 100644 --- a/unit_tests/tests/trigger/test_cam_vvt_input.cpp +++ b/unit_tests/tests/trigger/test_cam_vvt_input.cpp @@ -54,7 +54,7 @@ TEST(trigger, testNoStartUpWarnings) { eth.fireFall(150); } EXPECT_EQ( 1, unitTestWarningCodeState.recentWarnings.getCount()) << "warningCounter#testNoStartUpWarnings CUSTOM_SYNC_COUNT_MISMATCH expected"; - EXPECT_EQ(CUSTOM_PRIMARY_TOO_MANY_TEETH, unitTestWarningCodeState.recentWarnings.get(0).Code); + EXPECT_EQ(ObdCode::CUSTOM_PRIMARY_TOO_MANY_TEETH, unitTestWarningCodeState.recentWarnings.get(0).Code); } TEST(trigger, testNoisyInput) { @@ -74,8 +74,8 @@ TEST(trigger, testNoisyInput) { ASSERT_EQ(NOISY_RPM, Sensor::getOrZero(SensorType::Rpm)) << "testNoisyInput RPM should be noisy"; ASSERT_EQ( 2, unitTestWarningCodeState.recentWarnings.getCount()) << "warningCounter#testNoisyInput"; - ASSERT_EQ(CUSTOM_PRIMARY_NOT_ENOUGH_TEETH, unitTestWarningCodeState.recentWarnings.get(0).Code) << "@0"; - ASSERT_EQ(OBD_Crankshaft_Position_Sensor_A_Circuit_Malfunction, unitTestWarningCodeState.recentWarnings.get(1).Code) << "@0"; + ASSERT_EQ(ObdCode::CUSTOM_PRIMARY_NOT_ENOUGH_TEETH, unitTestWarningCodeState.recentWarnings.get(0).Code) << "@0"; + ASSERT_EQ(ObdCode::OBD_Crankshaft_Position_Sensor_A_Circuit_Malfunction, unitTestWarningCodeState.recentWarnings.get(1).Code) << "@0"; } TEST(trigger, testCamInput) { @@ -106,7 +106,7 @@ TEST(trigger, testCamInput) { // asserting that lack of camshaft signal would be detecting ASSERT_EQ(1, unitTestWarningCodeState.recentWarnings.getCount()) << "warningCounter#testCamInput #2"; - ASSERT_EQ(OBD_Camshaft_Position_Sensor_Circuit_Range_Performance, unitTestWarningCodeState.recentWarnings.get(0).Code) << "@0"; + ASSERT_EQ(ObdCode::OBD_Camshaft_Position_Sensor_Circuit_Range_Performance, unitTestWarningCodeState.recentWarnings.get(0).Code) << "@0"; unitTestWarningCodeState.recentWarnings.clear(); for (int i = 0; i < 600;i++) { diff --git a/unit_tests/tests/trigger/test_real_4b11.cpp b/unit_tests/tests/trigger/test_real_4b11.cpp index 32de9a2c2d..fbac02eadb 100644 --- a/unit_tests/tests/trigger/test_real_4b11.cpp +++ b/unit_tests/tests/trigger/test_real_4b11.cpp @@ -72,5 +72,5 @@ TEST(real4b11, runningDoubledEdge) { // Should get a warning for the doubled edge, but NOT one for a trigger error! ASSERT_EQ(1, eth.recentWarnings()->getCount()); - ASSERT_EQ(CUSTOM_PRIMARY_DOUBLED_EDGE, eth.recentWarnings()->get(0).Code); + ASSERT_EQ(ObdCode::CUSTOM_PRIMARY_DOUBLED_EDGE, eth.recentWarnings()->get(0).Code); } diff --git a/unit_tests/tests/trigger/test_real_cranking_nissan_vq40.cpp b/unit_tests/tests/trigger/test_real_cranking_nissan_vq40.cpp index 7e1c161b9c..26b6c2fccf 100644 --- a/unit_tests/tests/trigger/test_real_cranking_nissan_vq40.cpp +++ b/unit_tests/tests/trigger/test_real_cranking_nissan_vq40.cpp @@ -50,8 +50,8 @@ static void test(int engineSyncCam, float camOffsetAdd) { // TODO: why warnings? ASSERT_EQ(2, eth.recentWarnings()->getCount()); - ASSERT_EQ(CUSTOM_OUT_OF_ORDER_COIL, eth.recentWarnings()->get(0).Code); // this is from a coil being protected by overdwell protection - ASSERT_EQ(CUSTOM_PRIMARY_TOO_MANY_TEETH, eth.recentWarnings()->get(1).Code); + ASSERT_EQ(ObdCode::CUSTOM_OUT_OF_ORDER_COIL, eth.recentWarnings()->get(0).Code); // this is from a coil being protected by overdwell protection + ASSERT_EQ(ObdCode::CUSTOM_PRIMARY_TOO_MANY_TEETH, eth.recentWarnings()->get(1).Code); } // On Nissan VQ, all cams have the same pattern, so all should be equally good for engine sync. Check them all! diff --git a/unit_tests/tests/trigger/test_real_nb2_cranking.cpp b/unit_tests/tests/trigger/test_real_nb2_cranking.cpp index 3eb356da05..12dbf7b5df 100644 --- a/unit_tests/tests/trigger/test_real_nb2_cranking.cpp +++ b/unit_tests/tests/trigger/test_real_nb2_cranking.cpp @@ -29,8 +29,8 @@ TEST(realCrankingNB2, normalCranking) { ASSERT_EQ(876, round(Sensor::getOrZero(SensorType::Rpm))); EXPECT_EQ(2, eth.recentWarnings()->getCount()); - EXPECT_EQ(CUSTOM_PRIMARY_NOT_ENOUGH_TEETH, eth.recentWarnings()->get(0).Code); - EXPECT_EQ(CUSTOM_CAM_TOO_MANY_TEETH, eth.recentWarnings()->get(1).Code); + EXPECT_EQ(ObdCode::CUSTOM_PRIMARY_NOT_ENOUGH_TEETH, eth.recentWarnings()->get(0).Code); + EXPECT_EQ(ObdCode::CUSTOM_CAM_TOO_MANY_TEETH, eth.recentWarnings()->get(1).Code); } TEST(realCrankingNB2, crankingMissingInjector) { @@ -50,7 +50,7 @@ TEST(realCrankingNB2, crankingMissingInjector) { ASSERT_EQ(316, round(Sensor::getOrZero(SensorType::Rpm))); EXPECT_EQ(3, eth.recentWarnings()->getCount()); - EXPECT_EQ(CUSTOM_PRIMARY_NOT_ENOUGH_TEETH, eth.recentWarnings()->get(0).Code); - EXPECT_EQ(CUSTOM_CAM_TOO_MANY_TEETH, eth.recentWarnings()->get(1).Code); - EXPECT_EQ(CUSTOM_PRIMARY_TOO_MANY_TEETH, eth.recentWarnings()->get(2).Code); + EXPECT_EQ(ObdCode::CUSTOM_PRIMARY_NOT_ENOUGH_TEETH, eth.recentWarnings()->get(0).Code); + EXPECT_EQ(ObdCode::CUSTOM_CAM_TOO_MANY_TEETH, eth.recentWarnings()->get(1).Code); + EXPECT_EQ(ObdCode::CUSTOM_PRIMARY_TOO_MANY_TEETH, eth.recentWarnings()->get(2).Code); } diff --git a/unit_tests/tests/trigger/test_trigger_decoder.cpp b/unit_tests/tests/trigger/test_trigger_decoder.cpp index 76312b38da..10d9e0520e 100644 --- a/unit_tests/tests/trigger/test_trigger_decoder.cpp +++ b/unit_tests/tests/trigger/test_trigger_decoder.cpp @@ -186,7 +186,7 @@ TEST(misc, testRpmCalculator) { ASSERT_EQ( 720, engine->engineState.engineCycle) << "engineCycle"; - efiAssertVoid(CUSTOM_ERR_6670, engineConfiguration!=NULL, "null config in engine"); + efiAssertVoid(ObdCode::CUSTOM_ERR_6670, engineConfiguration!=NULL, "null config in engine"); setWholeTimingTable(-13); @@ -763,7 +763,7 @@ void doTestFuelSchedulerBug299smallAndMedium(int startUpDelayMs) { ASSERT_EQ( 0, unitTestWarningCodeState.recentWarnings.getCount()) << "warningCounter#testFuelSchedulerBug299smallAndMedium"; /* - ASSERT_EQ(CUSTOM_OBD_SKIPPED_FUEL, unitTestWarningCodeState.recentWarnings.get(0).Code); + ASSERT_EQ(ObdCode::CUSTOM_OBD_SKIPPED_FUEL, unitTestWarningCodeState.recentWarnings.get(0).Code); */ } @@ -947,7 +947,7 @@ TEST(big, testFuelSchedulerBug299smallAndLarge) { eth.executeActions(); ASSERT_EQ( 0, unitTestWarningCodeState.recentWarnings.getCount()) << "warningCounter#testFuelSchedulerBug299smallAndLarge"; /* - ASSERT_EQ(CUSTOM_OBD_SKIPPED_FUEL, unitTestWarningCodeState.recentWarnings.get(0).Code); + ASSERT_EQ(ObdCode::CUSTOM_OBD_SKIPPED_FUEL, unitTestWarningCodeState.recentWarnings.get(0).Code); */ } @@ -1052,8 +1052,8 @@ TEST(big, testSparkReverseOrderBug319) { eth.executeActions(); ASSERT_EQ( 0, enginePins.coils[3].outOfOrder) << "out-of-order #8"; ASSERT_EQ( 2, unitTestWarningCodeState.recentWarnings.getCount()) << "warningCounter#SparkReverseOrderBug319"; - ASSERT_EQ(CUSTOM_DWELL_TOO_LONG, unitTestWarningCodeState.recentWarnings.get(0).Code) << "warning @0"; - ASSERT_EQ(CUSTOM_OUT_OF_ORDER_COIL, unitTestWarningCodeState.recentWarnings.get(1).Code); + ASSERT_EQ(ObdCode::CUSTOM_DWELL_TOO_LONG, unitTestWarningCodeState.recentWarnings.get(0).Code) << "warning @0"; + ASSERT_EQ(ObdCode::CUSTOM_OUT_OF_ORDER_COIL, unitTestWarningCodeState.recentWarnings.get(1).Code); } TEST(big, testMissedSpark299) {