diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index 0c2b47d1fa..93a231c752 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -27,15 +27,13 @@ #include "global.h" #include "status_loop.h" #include "HIP9011_logic.h" +#include "engine_controller.h" #include "adc_inputs.h" #if EFI_WAVE_ANALYZER || defined(__DOXYGEN__) #include "wave_analyzer.h" #endif /* EFI_WAVE_ANALYZER */ -// see RUS_EFI_VERSION_TAG in console source code -#define RUS_EFI_VERSION_TAG "rusEfiVersion" - #include "trigger_central.h" #include "engine_state.h" #include "io_pins.h" @@ -394,11 +392,8 @@ void printOverallStatus(systime_t nowSeconds) { return; } timeOfPreviousPrintVersion = nowSeconds; - appendPrintf(&logger, "%s%s%d@%s %s %d%s", RUS_EFI_VERSION_TAG, DELIMETER, - getRusEfiVersion(), VCS_VERSION, - getConfigurationName(engineConfiguration->engineType), - getTimeNowSeconds(), - DELIMETER); + int seconds = getTimeNowSeconds(); + printCurrentState(&logger, seconds, getConfigurationName(engineConfiguration->engineType)); #if EFI_PROD_CODE || defined(__DOXYGEN__) printOutPin(CRANK1, CONFIGB(triggerInputPins)[0]); printOutPin(CRANK2, CONFIGB(triggerInputPins)[1]); diff --git a/firmware/console/status_loop.h b/firmware/console/status_loop.h index 5064928864..a330427fa1 100644 --- a/firmware/console/status_loop.h +++ b/firmware/console/status_loop.h @@ -19,4 +19,7 @@ bool getFullLog(void); void setFullLog(int value); void printOverallStatus(systime_t nowSeconds); +// see RUS_EFI_VERSION_TAG in console source code +#define RUS_EFI_VERSION_TAG "rusEfiVersion" + #endif /* CONSOLE_LOOP_H_ */ diff --git a/firmware/controllers/algo/engine2.cpp b/firmware/controllers/algo/engine2.cpp index 716d45584e..fd1a46db65 100644 --- a/firmware/controllers/algo/engine2.cpp +++ b/firmware/controllers/algo/engine2.cpp @@ -15,6 +15,13 @@ #include "engine_math.h" #include "advance_map.h" #include "aux_valves.h" +#if EFI_PROD_CODE +#include "svnversion.h" +#endif + +#if ! EFI_UNIT_TEST +#include "status_loop.h" +#endif extern fuel_Map3D_t veMap; extern afr_Map3D_t afrMap; @@ -288,4 +295,15 @@ void StartupFuelPumping::update(DECLARE_ENGINE_PARAMETER_SIGNATURE) { } } +#if EFI_SIMULATOR +#define VCS_VERSION "123" +#endif + +void printCurrentState(Logging *logging, int seconds, const char *name) { + logging->appendPrintf("%s%s%d@%s %s %d%s", RUS_EFI_VERSION_TAG, DELIMETER, + getRusEfiVersion(), VCS_VERSION, + name, + seconds, + DELIMETER); +} diff --git a/firmware/controllers/engine_controller.h b/firmware/controllers/engine_controller.h index 64aed9509d..2ba426688f 100644 --- a/firmware/controllers/engine_controller.h +++ b/firmware/controllers/engine_controller.h @@ -35,4 +35,6 @@ void setMockMafVoltage(float voltage); void setMockIatVoltage(float voltage); void setMockCltVoltage(float voltage); +void printCurrentState(Logging *logging, int seconds, const char *name); + #endif /* ENGINE_STATUS_H_ */ diff --git a/firmware/util/datalogging.cpp b/firmware/util/datalogging.cpp index ba5aff3296..270406e3ba 100644 --- a/firmware/util/datalogging.cpp +++ b/firmware/util/datalogging.cpp @@ -275,6 +275,19 @@ void initIntermediateLoggingBuffer(void) { intermediateLoggingBufferInited = true; } +#else +/* unit test implementations */ +void Logging::vappendPrintf(const char *fmt, va_list arg) { + +} + +void Logging::appendPrintf(const char *fmt, ...) { + va_list ap; + va_start(ap, fmt); + vsprintf(buffer, fmt, ap); + va_end(ap); +} + #endif /* ! EFI_UNIT_TEST */ void Logging::baseConstructor() { @@ -293,6 +306,8 @@ Logging::Logging(char const *name, char *buffer, int bufferSize) { baseConstructor(); #if ! EFI_UNIT_TEST initLoggingExt(name, buffer, bufferSize); +#else + this->buffer = buffer; #endif /* ! EFI_UNIT_TEST */ } diff --git a/unit_tests/global.h b/unit_tests/global.h index f7fc54867f..9940014d22 100644 --- a/unit_tests/global.h +++ b/unit_tests/global.h @@ -42,6 +42,8 @@ void print(const char *fmt, ...); #define US_TO_NT_MULTIPLIER 100 +#define VCS_VERSION "321" +#define RUS_EFI_VERSION_TAG "rusEfiVersion" #define ALWAYS_INLINE INLINE diff --git a/unit_tests/tests/test_util.cpp b/unit_tests/tests/test_util.cpp index a1649984e8..ea303a2db3 100644 --- a/unit_tests/tests/test_util.cpp +++ b/unit_tests/tests/test_util.cpp @@ -15,6 +15,7 @@ #include "malfunction_central.h" #include "cli_registry.h" #include "unit_test_framework.h" +#include "engine_controller.h" #include "nmea.h" #include "efilib2.h" @@ -486,5 +487,16 @@ void testMenuTree(void) { tree.back(); assertTrue(tree.current == &miTopLevel1); - +} + +int getRusEfiVersion(void) { + return 776655; +} + +TEST(util, datalogging) { + char LOGGING_BUFFER[1000]; + Logging logger("settings control", LOGGING_BUFFER, sizeof(LOGGING_BUFFER)); + + printCurrentState(&logger, 239, "CUSTOM_ENGINE"); + ASSERT_STREQ("rusEfiVersion,776655@321 CUSTOM_ENGINE 239,", LOGGING_BUFFER); }