less dependence on that logger (#3884)

* less dependence on that logger

* comma

* refactor a bit, make it clear what this thing actually *does*

* static

* shrink the buffer a bit and make names useful

* dead util that's just subtraction lol
This commit is contained in:
Matthew Kennedy 2022-02-09 03:53:16 -08:00 committed by GitHub
parent c3201ab171
commit 47b4ace4cb
11 changed files with 60 additions and 69 deletions

View File

@ -11,7 +11,6 @@ export EXTRA_PARAMS="-DDUMMY -DSTM32F767xx \
-DEFI_INJECTOR_PIN3=GPIO_UNASSIGNED \ -DEFI_INJECTOR_PIN3=GPIO_UNASSIGNED \
-DFIRMWARE_ID=\\\"nucleo767\\\" \ -DFIRMWARE_ID=\\\"nucleo767\\\" \
-DEFI_COMMUNICATION_PIN=GPIOB_7 \ -DEFI_COMMUNICATION_PIN=GPIOB_7 \
-DSTATUS_LOGGING_BUFFER_SIZE=1400 \
-DLED_CRITICAL_ERROR_BRAIN_PIN=GPIOB_14 \ -DLED_CRITICAL_ERROR_BRAIN_PIN=GPIOB_14 \
-DEFI_ENABLE_ASSERTS=FALSE \ -DEFI_ENABLE_ASSERTS=FALSE \
-DCH_DBG_ENABLE_CHECKS=FALSE -DCH_DBG_ENABLE_ASSERTS=FALSE -DCH_DBG_ENABLE_STACK_CHECK=FALSE -DCH_DBG_FILL_THREADS=FALSE -DCH_DBG_THREADS_PROFILING=FALSE" -DCH_DBG_ENABLE_CHECKS=FALSE -DCH_DBG_ENABLE_ASSERTS=FALSE -DCH_DBG_ENABLE_STACK_CHECK=FALSE -DCH_DBG_FILL_THREADS=FALSE -DCH_DBG_THREADS_PROFILING=FALSE"

View File

@ -11,7 +11,6 @@ export EXTRA_PARAMS="-DDUMMY \
-DEFI_INJECTOR_PIN3=GPIO_UNASSIGNED \ -DEFI_INJECTOR_PIN3=GPIO_UNASSIGNED \
-DFIRMWARE_ID=\\\"nucleoH743\\\" \ -DFIRMWARE_ID=\\\"nucleoH743\\\" \
-DEFI_COMMUNICATION_PIN=GPIOB_7 \ -DEFI_COMMUNICATION_PIN=GPIOB_7 \
-DSTATUS_LOGGING_BUFFER_SIZE=1400 \
-DLED_CRITICAL_ERROR_BRAIN_PIN=GPIOB_14" -DLED_CRITICAL_ERROR_BRAIN_PIN=GPIOB_14"
export DEBUG_LEVEL_OPT="-O2" export DEBUG_LEVEL_OPT="-O2"

View File

@ -600,7 +600,7 @@ static void handleGetVersion(TsChannelBase* tsChannel) {
static void handleGetText(TsChannelBase* tsChannel) { static void handleGetText(TsChannelBase* tsChannel) {
tsState.textCommandCounter++; tsState.textCommandCounter++;
printOverallStatus(getTimeNowSeconds()); printOverallStatus();
size_t outputSize; size_t outputSize;
const char* output = swapOutputBuffers(&outputSize); const char* output = swapOutputBuffers(&outputSize);

View File

@ -108,14 +108,6 @@ int warningEnabled = true;
extern int maxTriggerReentrant; extern int maxTriggerReentrant;
extern uint32_t maxLockedDuration; extern uint32_t maxLockedDuration;
#if !defined(STATUS_LOGGING_BUFFER_SIZE)
#define STATUS_LOGGING_BUFFER_SIZE 1800
#endif /* STATUS_LOGGING_BUFFER_SIZE */
static char LOGGING_BUFFER[STATUS_LOGGING_BUFFER_SIZE];
static Logging logger("status loop", LOGGING_BUFFER, sizeof(LOGGING_BUFFER));
static void setWarningEnabled(int value) { static void setWarningEnabled(int value) {
warningEnabled = value; warningEnabled = value;
} }
@ -156,12 +148,22 @@ static int packEngineMode() {
static int prevCkpEventCounter = -1; static int prevCkpEventCounter = -1;
/** /**
* Time when the firmware version was reported last time, in seconds * Time when the firmware version was last reported
* TODO: implement a request/response instead of just constantly sending this out * TODO: implement a request/response instead of just constantly sending this out
*/ */
static systime_t timeOfPreviousPrintVersion = 0; static Timer printVersionTimer;
#if EFI_PROD_CODE static void printRusefiVersion(const char *engineTypeName, const char *firmwareBuildId) {
// VersionChecker in rusEFI console is parsing these version string, please follow the expected format
efiPrintfProto(PROTOCOL_VERSION_TAG, "%d@%s %s %s %d",
getRusEfiVersion(), VCS_VERSION,
firmwareBuildId,
engineTypeName,
getTimeNowSeconds());
}
// Inform the console about the mapping between a pin's logical name (for example, injector 3)
// and the physical MCU pin backing that function (for example, PE3)
static void printOutPin(const char *pinName, brain_pin_e hwPin) { static void printOutPin(const char *pinName, brain_pin_e hwPin) {
if (hwPin == GPIO_UNASSIGNED || hwPin == GPIO_INVALID) { if (hwPin == GPIO_UNASSIGNED || hwPin == GPIO_INVALID) {
return; return;
@ -172,29 +174,14 @@ static void printOutPin(const char *pinName, brain_pin_e hwPin) {
} else { } else {
hwPinName = "smart"; hwPinName = "smart";
} }
logger.appendPrintf(PROTOCOL_OUTPIN LOG_DELIMITER "%s@%s" LOG_DELIMITER, pinName, hwPinName);
efiPrintfProto(PROTOCOL_OUTPIN, "%s@%s", pinName, hwPinName);
} }
#endif /* EFI_PROD_CODE */
void printOverallStatus(efitimesec_t nowSeconds) { // Print out the current mapping between logical and physical pins that
#if EFI_ENGINE_SNIFFER // the engine sniffer cares about, so we can display a physical pin
waveChart.publishIfFull(); // in each engine sniffer row
#endif /* EFI_ENGINE_SNIFFER */ static void printEngineSnifferPinMappings() {
#if EFI_SENSOR_CHART
publishSensorChartIfFull();
#endif // EFI_SENSOR_CHART
/**
* we report the version every 4 seconds - this way the console does not need to
* request it and we will display it pretty soon
*/
if (overflowDiff(nowSeconds, timeOfPreviousPrintVersion) < 4) {
return;
}
timeOfPreviousPrintVersion = nowSeconds;
int seconds = getTimeNowSeconds();
printCurrentState(&logger, seconds, getEngine_type_e(engineConfiguration->engineType), FIRMWARE_ID);
#if EFI_PROD_CODE #if EFI_PROD_CODE
printOutPin(PROTOCOL_CRANK1, engineConfiguration->triggerInputPins[0]); printOutPin(PROTOCOL_CRANK1, engineConfiguration->triggerInputPins[0]);
printOutPin(PROTOCOL_CRANK2, engineConfiguration->triggerInputPins[1]); printOutPin(PROTOCOL_CRANK2, engineConfiguration->triggerInputPins[1]);
@ -218,13 +205,46 @@ void printOverallStatus(efitimesec_t nowSeconds) {
for (int i = 0; i < AUX_DIGITAL_VALVE_COUNT;i++) { for (int i = 0; i < AUX_DIGITAL_VALVE_COUNT;i++) {
printOutPin(enginePins.auxValve[i].getShortName(), engineConfiguration->auxValves[i]); printOutPin(enginePins.auxValve[i].getShortName(), engineConfiguration->auxValves[i]);
} }
#endif /* EFI_PROD_CODE */ #endif /* EFI_PROD_CODE */
scheduleLogging(&logger); }
void printOverallStatus() {
#if EFI_ENGINE_SNIFFER
waveChart.publishIfFull();
#endif /* EFI_ENGINE_SNIFFER */
#if EFI_SENSOR_CHART
publishSensorChartIfFull();
#endif // EFI_SENSOR_CHART
/**
* we report the version every second - this way the console does not need to
* request it and we will display it pretty soon
*/
if (printVersionTimer.hasElapsedSec(1)) {
// we're sending, reset the timer
printVersionTimer.reset();
// Output the firmware version, board type, git hash, uptime in seconds, etc
printRusefiVersion(getEngine_type_e(engineConfiguration->engineType), FIRMWARE_ID);
// Output the current engine sniffer pin mappings
printEngineSnifferPinMappings();
}
} }
static systime_t timeOfPreviousReport = (systime_t) -1; static systime_t timeOfPreviousReport = (systime_t) -1;
#if !defined(LOGIC_ANALYZER_BUFFER_SIZE)
// TODO: how small can this be?
#define LOGIC_ANALYZER_BUFFER_SIZE 1000
#endif /* LOGIC_ANALYZER_BUFFER_SIZE */
#if EFI_LOGIC_ANALYZER
static char logicAnalyzerBuffer[LOGIC_ANALYZER_BUFFER_SIZE];
static Logging logicAnalyzerLogger("logic analyzer", logicAnalyzerBuffer, sizeof(logicAnalyzerBuffer));
#endif // EFI_LOGIC_ANALYZER
/** /**
* @brief Sends all pending data to rusEfi console * @brief Sends all pending data to rusEfi console
* *
@ -266,10 +286,9 @@ void updateDevConsoleState(void) {
#endif #endif
#if EFI_LOGIC_ANALYZER #if EFI_LOGIC_ANALYZER
printWave(&logger); printWave(&logicAnalyzerLogger);
scheduleLogging(&logicAnalyzerLogger);
#endif /* EFI_LOGIC_ANALYZER */ #endif /* EFI_LOGIC_ANALYZER */
scheduleLogging(&logger);
} }
/* /*

View File

@ -16,4 +16,4 @@ void initStatusLoop(void);
struct Writer; struct Writer;
void writeLogLine(Writer& buffer); void writeLogLine(Writer& buffer);
void printOverallStatus(efitimesec_t nowSeconds); void printOverallStatus();

View File

@ -196,15 +196,6 @@ void EngineState::updateTChargeK(int rpm, float tps) {
#define VCS_VERSION "123" #define VCS_VERSION "123"
#endif #endif
void printCurrentState(Logging *logging, int seconds, const char *engineTypeName, const char *firmwareBuildId) {
// VersionChecker in rusEFI console is parsing these version string, please follow the expected format
logging->appendPrintf(PROTOCOL_VERSION_TAG LOG_DELIMITER "%d@%s %s %s %d" LOG_DELIMITER,
getRusEfiVersion(), VCS_VERSION,
firmwareBuildId,
engineTypeName,
seconds);
}
void TriggerConfiguration::update() { void TriggerConfiguration::update() {
UseOnlyRisingEdgeForTrigger = isUseOnlyRisingEdgeForTrigger(); UseOnlyRisingEdgeForTrigger = isUseOnlyRisingEdgeForTrigger();
VerboseTriggerSynchDetails = isVerboseTriggerSynchDetails(); VerboseTriggerSynchDetails = isVerboseTriggerSynchDetails();

View File

@ -18,5 +18,3 @@ void initStartStopButton();
void initDataStructures(); void initDataStructures();
void slowStartStopButtonCallback(); void slowStartStopButtonCallback();
void printCurrentState(Logging *logging, int seconds, const char *engineTypeName, const char *firmwareBuildId);

View File

@ -38,10 +38,6 @@ extern int waveChartUsedSize;
extern WaveChart waveChart; extern WaveChart waveChart;
#endif /* EFI_ENGINE_SNIFFER */ #endif /* EFI_ENGINE_SNIFFER */
#if !defined(SETTINGS_LOGGING_BUFFER_SIZE)
#define SETTINGS_LOGGING_BUFFER_SIZE 1000
#endif /* SETTINGS_LOGGING_BUFFER_SIZE */
void printSpiState(const engine_configuration_s *engineConfiguration) { void printSpiState(const engine_configuration_s *engineConfiguration) {
efiPrintf("spi 1=%s/2=%s/3=%s/4=%s", efiPrintf("spi 1=%s/2=%s/3=%s/4=%s",
boolToString(engineConfiguration->is_enabled_spi_1), boolToString(engineConfiguration->is_enabled_spi_1),

View File

@ -47,9 +47,6 @@
*/ */
#define DEEP_IN_THE_PAST_SECONDS -10 #define DEEP_IN_THE_PAST_SECONDS -10
// todo: implement a function to work with times considering counter overflow
#define overflowDiff(now, time) ((now) - (time))
#ifdef __cplusplus #ifdef __cplusplus
/** /**
* Provide a 62-bit counter from a 32-bit counter source that wraps around. * Provide a 62-bit counter from a 32-bit counter source that wraps around.

View File

@ -23,7 +23,8 @@ namespace priv
// "normal" logging messages need a header and footer, so put them in // "normal" logging messages need a header and footer, so put them in
// the format string at compile time // the format string at compile time
#define efiPrintf(fmt, ...) priv::efiPrintfInternal(PROTOCOL_MSG LOG_DELIMITER fmt LOG_DELIMITER, ##__VA_ARGS__) #define efiPrintfProto(proto, fmt, ...) priv::efiPrintfInternal(proto LOG_DELIMITER fmt LOG_DELIMITER, ##__VA_ARGS__)
#define efiPrintf(fmt, ...) efiPrintfProto(PROTOCOL_MSG, fmt, ##__VA_ARGS__)
/** /**
* This is the legacy function to copy the contents of a local Logging object in to the output buffer * This is the legacy function to copy the contents of a local Logging object in to the output buffer

View File

@ -482,15 +482,6 @@ int getRusEfiVersion(void) {
return 776655; return 776655;
} }
TEST(util, datalogging) {
char LOGGING_BUFFER[1000];
Logging logger("settings control", LOGGING_BUFFER, sizeof(LOGGING_BUFFER));
printCurrentState(&logger, 239, "DEFAULT_FRANKENSO", "ID");
// printf("Got [%s]\r\n", LOGGING_BUFFER);
// ASSERT_STREQ("rusEfiVersion,776655@321ID DEFAULT_FRANKENSO 239,", LOGGING_BUFFER);
}
TEST(util, PeakDetect) { TEST(util, PeakDetect) {
constexpr int startTime = 50; constexpr int startTime = 50;
constexpr int timeout = 100; constexpr int timeout = 100;