From ff867b93014f346c03836f4476670a1f2f446ea3 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Sun, 12 Apr 2020 06:39:14 -0700 Subject: [PATCH] fix warnings (#1282) * warnings * don't need to template those --- firmware/controllers/can/obd2.cpp | 4 +- .../engine_cycle/main_trigger_callback.cpp | 2 +- .../sensors/converters/linear_func.cpp | 2 +- .../sensors/converters/resistance_func.cpp | 4 +- .../converters/sensor_converter_func.h | 6 +- firmware/controllers/system/efi_gpio.cpp | 5 -- firmware/controllers/system/efi_gpio.h | 6 +- .../controllers/trigger/trigger_central.cpp | 2 +- .../controllers/trigger/trigger_decoder.cpp | 4 +- .../controllers/trigger/trigger_decoder.h | 2 +- firmware/development/engine_emulator.cpp | 71 ------------------- firmware/hw_layer/mmc_card.cpp | 1 - firmware/util/math/interpolation.h | 55 +++++++------- unit_tests/Makefile | 1 + 14 files changed, 49 insertions(+), 116 deletions(-) diff --git a/firmware/controllers/can/obd2.cpp b/firmware/controllers/can/obd2.cpp index 6825e73c2d..d7d88042b5 100644 --- a/firmware/controllers/can/obd2.cpp +++ b/firmware/controllers/can/obd2.cpp @@ -181,7 +181,9 @@ static void handleGetDataRequest(const CANRxFrame& rx) { static void handleDtcRequest(int numCodes, int *dtcCode) { // TODO: this appears to be unfinished? - + UNUSED(numCodes); + UNUSED(dtcCode); + // int numBytes = numCodes * 2; // // write CAN-TP Single Frame header? // txmsg.data8[0] = (uint8_t)((0 << 4) | numBytes); diff --git a/firmware/controllers/engine_cycle/main_trigger_callback.cpp b/firmware/controllers/engine_cycle/main_trigger_callback.cpp index 112ac03e52..2051a0b892 100644 --- a/firmware/controllers/engine_cycle/main_trigger_callback.cpp +++ b/firmware/controllers/engine_cycle/main_trigger_callback.cpp @@ -230,8 +230,8 @@ static ALWAYS_INLINE void handleFuelInjectionEvent(int injEventIndex, InjectionE prevOutputName = outputName; } +#if EFI_UNIT_TEST || EFI_SIMULATOR || EFI_PRINTF_FUEL_DETAILS InjectorOutputPin *output = event->outputs[0]; -#if EFI_PRINTF_FUEL_DETAILS printf("fuelout %s duration %d total=%d\t\n", output->name, (int)durationUs, (int)MS2US(getCrankshaftRevolutionTimeMs(GET_RPM_VALUE))); #endif /*EFI_PRINTF_FUEL_DETAILS */ diff --git a/firmware/controllers/sensors/converters/linear_func.cpp b/firmware/controllers/sensors/converters/linear_func.cpp index 10ed4d3ef0..0f99583439 100644 --- a/firmware/controllers/sensors/converters/linear_func.cpp +++ b/firmware/controllers/sensors/converters/linear_func.cpp @@ -25,5 +25,5 @@ SensorResult LinearFunc::convert(float inputValue) const { void LinearFunc::showInfo(Logging* logger, float testRawValue) const { scheduleMsg(logger, " Linear function slope: %.2f offset: %.2f min: %.1f max: %.1f", m_a, m_b, m_minOutput, m_maxOutput); const auto [valid, value] = convert(testRawValue); - scheduleMsg(logger, " raw value %.2f converts to %.2f", testRawValue, value); + scheduleMsg(logger, " raw value %.2f converts to %.2f valid: %d", testRawValue, value, valid); } diff --git a/firmware/controllers/sensors/converters/resistance_func.cpp b/firmware/controllers/sensors/converters/resistance_func.cpp index a83900d95b..04fc06123f 100644 --- a/firmware/controllers/sensors/converters/resistance_func.cpp +++ b/firmware/controllers/sensors/converters/resistance_func.cpp @@ -28,6 +28,6 @@ SensorResult ResistanceFunc::convert(float raw) const { } void ResistanceFunc::showInfo(Logging* logger, float testInputValue) const { - const auto [valid, value] = convert(testInputValue); - scheduleMsg(logger, " %.2f volts -> %.1f ohms with supply voltage %.2f and pullup %.1f.", testInputValue, value, m_supplyVoltage, m_pullupResistor); + const auto result = convert(testInputValue); + scheduleMsg(logger, " %.2f volts -> %.1f ohms with supply voltage %.2f and pullup %.1f.", testInputValue, result.Value, m_supplyVoltage, m_pullupResistor); } diff --git a/firmware/controllers/sensors/converters/sensor_converter_func.h b/firmware/controllers/sensors/converters/sensor_converter_func.h index cc23776a0b..b2f25f9b7b 100644 --- a/firmware/controllers/sensors/converters/sensor_converter_func.h +++ b/firmware/controllers/sensors/converters/sensor_converter_func.h @@ -11,5 +11,9 @@ struct SensorConverter { SensorConverter() = default; virtual SensorResult convert(float raw) const = 0; - virtual void showInfo(Logging* logger, float testRawValue) const {} + virtual void showInfo(Logging* logger, float testRawValue) const { + // Unused base - nothing to print + (void)logger; + (void)testRawValue; + } }; diff --git a/firmware/controllers/system/efi_gpio.cpp b/firmware/controllers/system/efi_gpio.cpp index 5f4d4ef977..1793bc05df 100644 --- a/firmware/controllers/system/efi_gpio.cpp +++ b/firmware/controllers/system/efi_gpio.cpp @@ -299,11 +299,6 @@ void IgnitionOutputPin::reset() { OutputPin::OutputPin() { modePtr = &DEFAULT_OUTPUT; -#if EFI_GPIO_HARDWARE - port = NULL; - pin = 0; -#endif /* EFI_GPIO_HARDWARE */ - currentLogicValue = INITIAL_PIN_STATE; } bool OutputPin::isInitialized() { diff --git a/firmware/controllers/system/efi_gpio.h b/firmware/controllers/system/efi_gpio.h index 0c12fb8cd1..400582c7fa 100644 --- a/firmware/controllers/system/efi_gpio.h +++ b/firmware/controllers/system/efi_gpio.h @@ -53,15 +53,15 @@ public: #if EFI_GPIO_HARDWARE - ioportid_t port; - uint8_t pin; + ioportid_t port = 0; + uint8_t pin = 0; #if (BOARD_EXT_GPIOCHIPS > 0) /* used for external pins */ brain_pin_e brainPin; bool ext; #endif #endif /* EFI_GPIO_HARDWARE */ - int8_t currentLogicValue; + int8_t currentLogicValue = INITIAL_PIN_STATE; /** * we track current pin status so that we do not touch the actual hardware if we want to write new pin bit * which is same as current pin value. This maybe helps in case of status leds, but maybe it's a total over-engineering diff --git a/firmware/controllers/trigger/trigger_central.cpp b/firmware/controllers/trigger/trigger_central.cpp index c4f84f3d74..be5fbefb22 100644 --- a/firmware/controllers/trigger/trigger_central.cpp +++ b/firmware/controllers/trigger/trigger_central.cpp @@ -409,7 +409,7 @@ static void triggerShapeInfo(void) { scheduleMsg(logger, "useRise=%s", boolToString(TRIGGER_WAVEFORM(useRiseEdge))); scheduleMsg(logger, "gap from %.2f to %.2f", TRIGGER_WAVEFORM(syncronizationRatioFrom[0]), TRIGGER_WAVEFORM(syncronizationRatioTo[0])); - for (int i = 0; i < s->getSize(); i++) { + for (size_t i = 0; i < s->getSize(); i++) { scheduleMsg(logger, "event %d %.2f", i, s->eventAngles[i]); } #endif diff --git a/firmware/controllers/trigger/trigger_decoder.cpp b/firmware/controllers/trigger/trigger_decoder.cpp index a3a2122838..cae8058b98 100644 --- a/firmware/controllers/trigger/trigger_decoder.cpp +++ b/firmware/controllers/trigger/trigger_decoder.cpp @@ -352,7 +352,7 @@ bool TriggerState::validateEventCounters(TriggerWaveform *triggerShape) const { } void TriggerState::onShaftSynchronization(const TriggerStateCallback triggerCycleCallback, - efitick_t nowNt, trigger_wheel_e triggerWheel, TriggerWaveform *triggerShape) { + efitick_t nowNt, TriggerWaveform *triggerShape) { if (triggerCycleCallback) { @@ -627,7 +627,7 @@ void TriggerState::decodeTriggerEvent(TriggerWaveform *triggerShape, const Trigg nextTriggerEvent() ; - onShaftSynchronization(triggerCycleCallback, nowNt, triggerWheel, triggerShape); + onShaftSynchronization(triggerCycleCallback, nowNt, triggerShape); } else { /* if (!isSynchronizationPoint) */ nextTriggerEvent() diff --git a/firmware/controllers/trigger/trigger_decoder.h b/firmware/controllers/trigger/trigger_decoder.h index 9583a88222..94b0698c9e 100644 --- a/firmware/controllers/trigger/trigger_decoder.h +++ b/firmware/controllers/trigger/trigger_decoder.h @@ -74,7 +74,7 @@ public: bool validateEventCounters(TriggerWaveform *triggerShape) const; void onShaftSynchronization(const TriggerStateCallback triggerCycleCallback, - efitick_t nowNt, trigger_wheel_e triggerWheel, TriggerWaveform *triggerShape); + efitick_t nowNt, TriggerWaveform *triggerShape); bool isValidIndex(TriggerWaveform *triggerShape) const; diff --git a/firmware/development/engine_emulator.cpp b/firmware/development/engine_emulator.cpp index dd883c9a19..6c0929dd01 100644 --- a/firmware/development/engine_emulator.cpp +++ b/firmware/development/engine_emulator.cpp @@ -22,78 +22,8 @@ #include "poten.h" #include "trigger_emulator.h" -static THD_WORKING_AREA(eeThreadStack, UTILITY_THREAD_STACK_SIZE); - -#define DIAG_PIN GPIOD_0 - -void setDiag(int value) { - print("Setting diag: %d\r\n", value); -// todo: convert to new api palWritePad(DIAG_PORT, DIAG_PIN, value); -} - -#define PERIOD 3000 - EXTERN_ENGINE; -static void emulate(void) { - print("Emulating...\r\n"); - setDiag(1); - chThdSleep(1); - - for (int i = 400; i <= 1300; i++) { - if (i % 50 != 0) - continue; - setTriggerEmulatorRPM(i PASS_ENGINE_PARAMETER_SUFFIX); - chThdSleepMilliseconds(PERIOD); - } - - setTriggerEmulatorRPM(0 PASS_ENGINE_PARAMETER_SUFFIX); - - setDiag(0); - chThdSleep(1); - print("Emulation DONE!\r\n"); -} - -static int flag = FALSE; - -static msg_t eeThread(void *arg) { - (void)arg; - chRegSetThreadName("Engine"); - - while (TRUE) { - while (!flag) - chThdSleepMilliseconds(200); - flag = FALSE; - emulate(); - } -#if defined __GNUC__ - return (msg_t)NULL; -#endif -} - -void startEmulator(void) { - flag = TRUE; -} - -//static void printAdvance(int rpm, int maf100) { -// float advance = getAdvance(rpm, maf100 / 100.0); -// print("advance for %d rpm %d maf100: %.2f\r\n", rpm, maf100, advance); -//} - -#if defined(EFI_ENGINE_STIMULATOR) -static void initECUstimulator(Engine *engine) { - efiSetPadMode("TEN", DIAG_PIN, PAL_MODE_OUTPUT_PUSHPULL); - - addConsoleActionI("diag", setDiag); - addConsoleAction("emu", startEmulator); -// addConsoleActionII("ad", printAdvance); - - setDiag(1); - - chThdCreateStatic(eeThreadStack, sizeof(eeThreadStack), NORMALPRIO, (tfunc_t)(void*) eeThread, engine); -} -#endif /* EFI_ENGINE_STIMULATOR */ - void initEngineEmulator(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) { if (hasFirmwareError()) return; @@ -102,6 +32,5 @@ void initEngineEmulator(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) { initPotentiometers(sharedLogger PASS_ENGINE_PARAMETER_SUFFIX); #endif /* EFI_POTENTIOMETER && HAL_USE_SPI*/ - //initECUstimulator(); initTriggerEmulator(sharedLogger PASS_ENGINE_PARAMETER_SUFFIX); } diff --git a/firmware/hw_layer/mmc_card.cpp b/firmware/hw_layer/mmc_card.cpp index 776762d88a..1a44f7d157 100644 --- a/firmware/hw_layer/mmc_card.cpp +++ b/firmware/hw_layer/mmc_card.cpp @@ -274,7 +274,6 @@ static void listDirectory(const char *path) { scheduleMsg(&logger, LS_RESPONSE); - int i = strlen(path); for (int count = 0;count < FILE_LIST_MAX_COUNT;) { FILINFO fno; diff --git a/firmware/util/math/interpolation.h b/firmware/util/math/interpolation.h index 4d03a89e6a..8e1267d9e0 100644 --- a/firmware/util/math/interpolation.h +++ b/firmware/util/math/interpolation.h @@ -132,10 +132,10 @@ float interpolate3d(float x, const kType xBin[], int xBinSize, float y, const kT #endif /* DEBUG_INTERPOLATION */ if (yIndex == yBinSize - 1) return map[0][yIndex]; - kType keyMin = yBin[yIndex]; - kType keyMax = yBin[yIndex + 1]; - vType rpmMinValue = map[0][yIndex]; - vType rpmMaxValue = map[0][yIndex + 1]; + float keyMin = yBin[yIndex]; + float keyMax = yBin[yIndex + 1]; + float rpmMinValue = map[0][yIndex]; + float rpmMaxValue = map[0][yIndex + 1]; return interpolateMsg("3d", keyMin, rpmMinValue, keyMax, rpmMaxValue, y); } @@ -147,10 +147,10 @@ float interpolate3d(float x, const kType xBin[], int xBinSize, float y, const kT #endif /* DEBUG_INTERPOLATION */ if (xIndex == xBinSize - 1) return map[xIndex][0]; - kType key1 = xBin[xIndex]; - kType key2 = xBin[xIndex + 1]; - vType value1 = map[xIndex][0]; - vType value2 = map[xIndex + 1][0]; + float key1 = xBin[xIndex]; + float key2 = xBin[xIndex + 1]; + float value1 = map[xIndex][0]; + float value2 = map[xIndex + 1][0]; return interpolateMsg("out3d", key1, value1, key2, value2, x); } @@ -170,10 +170,10 @@ float interpolate3d(float x, const kType xBin[], int xBinSize, float y, const kT #endif /* DEBUG_INTERPOLATION */ // here yIndex is less than yBinSize - 1, we've checked that condition already - kType key1 = yBin[yIndex]; - kType key2 = yBin[yIndex + 1]; - vType value1 = map[xIndex][yIndex]; - vType value2 = map[xIndex][yIndex + 1]; + float key1 = yBin[yIndex]; + float key2 = yBin[yIndex + 1]; + float value1 = map[xIndex][yIndex]; + float value2 = map[xIndex][yIndex + 1]; return interpolateMsg("out3d", key1, value1, key2, value2, y); } @@ -185,10 +185,10 @@ float interpolate3d(float x, const kType xBin[], int xBinSize, float y, const kT #endif /* DEBUG_INTERPOLATION */ // here xIndex is less than xBinSize - 1, we've checked that condition already - kType key1 = xBin[xIndex]; - kType key2 = xBin[xIndex + 1]; - vType value1 = map[xIndex][yIndex]; - vType value2 = map[xIndex + 1][yIndex]; + float key1 = xBin[xIndex]; + float key2 = xBin[xIndex + 1]; + float value1 = map[xIndex][yIndex]; + float value2 = map[xIndex + 1][yIndex]; return interpolateMsg("out3d", key1, value1, key2, value2, x); } @@ -198,10 +198,10 @@ float interpolate3d(float x, const kType xBin[], int xBinSize, float y, const kT */ int rpmMaxIndex = xIndex + 1; - kType xMin = xBin[xIndex]; - kType xMax = xBin[xIndex + 1]; - vType rpmMinKeyMinValue = map[xIndex][yIndex]; - vType rpmMaxKeyMinValue = map[xIndex + 1][yIndex]; + float xMin = xBin[xIndex]; + float xMax = xBin[xIndex + 1]; + float rpmMinKeyMinValue = map[xIndex][yIndex]; + float rpmMaxKeyMinValue = map[xIndex + 1][yIndex]; float keyMinValue = interpolateMsg("", xMin, rpmMinKeyMinValue, xMax, rpmMaxKeyMinValue, x); @@ -213,10 +213,10 @@ float interpolate3d(float x, const kType xBin[], int xBinSize, float y, const kT #endif /* DEBUG_INTERPOLATION */ int keyMaxIndex = yIndex + 1; - kType keyMin = yBin[yIndex]; - kType keyMax = yBin[keyMaxIndex]; - vType rpmMinKeyMaxValue = map[xIndex][keyMaxIndex]; - vType rpmMaxKeyMaxValue = map[rpmMaxIndex][keyMaxIndex]; + float keyMin = yBin[yIndex]; + float keyMax = yBin[keyMaxIndex]; + float rpmMinKeyMaxValue = map[xIndex][keyMaxIndex]; + float rpmMaxKeyMaxValue = map[rpmMaxIndex][keyMaxIndex]; float keyMaxValue = interpolateMsg("3d", xMin, rpmMinKeyMaxValue, xMax, rpmMaxKeyMaxValue, x); @@ -224,11 +224,14 @@ float interpolate3d(float x, const kType xBin[], int xBinSize, float y, const kT if (needInterpolationLogging()) { printf("key=%.2f:\r\nrange %.2f - %.2f\r\n", y, keyMin, keyMax); printf("key interpolation range %.2f %.2f result %.2f\r\n", rpmMinKeyMaxValue, rpmMaxKeyMaxValue, keyMaxValue); + + printf("%f", rpmMinKeyMaxValue); + printf("%f", rpmMaxKeyMaxValue); + printf("%f", keyMaxValue); } #endif /* DEBUG_INTERPOLATION */ - float result = interpolateMsg("3d", keyMin, keyMinValue, keyMax, keyMaxValue, y); - return result; + return interpolateMsg("3d", keyMin, keyMinValue, keyMax, keyMaxValue, y); } void setCurveValue(float bins[], float values[], int size, float key, float value); void initInterpolation(Logging *sharedLogger); diff --git a/unit_tests/Makefile b/unit_tests/Makefile index 7f50c59f1c..0dc0d51827 100644 --- a/unit_tests/Makefile +++ b/unit_tests/Makefile @@ -26,6 +26,7 @@ ifeq ($(USE_OPT),) USE_OPT = -c -Wall -O0 -ggdb -g3 USE_OPT += -fprofile-arcs -ftest-coverage USE_OPT += -Werror=missing-field-initializers + USE_OPT += -Wno-unused-parameter -Wno-unused-function endif