rusefi/firmware/controllers/error_handling.c

43 lines
926 B
C
Raw Normal View History

2014-04-22 17:43:32 -07:00
/**
* @file error_handling.c
*
* @date Apr 1, 2014
* @author Andrey Belomutskiy, (c) 2012-2014
*/
#include "main.h"
#include "error_handling.h"
#include "wave_math.h"
2014-04-26 06:52:13 -07:00
static time_t timeOfPreviousWarning = -10;
2014-04-22 17:43:32 -07:00
static Logging logger;
extern int warningEnabled;
/**
* @returns TRUE in case there are too many warnings
*/
int warning(obd_code_e code, const char *fmt, ...) {
2014-04-26 06:52:13 -07:00
int now = getTimeNowSeconds();
if (now == timeOfPreviousWarning || !warningEnabled)
2014-04-22 17:43:32 -07:00
return TRUE; // we just had another warning, let's not spam
timeOfPreviousWarning = now;
resetLogging(&logger); // todo: is 'reset' really needed here?
appendMsgPrefix(&logger);
va_list ap;
va_start(ap, fmt);
vappendPrintf(&logger, fmt, ap);
va_end(ap);
append(&logger, DELIMETER);
scheduleLogging(&logger);
return FALSE;
}
void initErrorHandling(void) {
initLogging(&logger, "error handling");
}