auto-sync

This commit is contained in:
rusEfi 2015-01-09 22:06:13 -06:00
parent e6a6b26d86
commit 93072c913c
7 changed files with 84 additions and 95 deletions

View File

@ -86,84 +86,119 @@ static void setWarningEnabled(int value) {
static Logging fileLogger;
#endif /* EFI_FILE_LOGGING */
static void reportSensorF(const char *caption, float value, int precision) {
static int logFileLineIndex = 0;
#define TAB "\t"
static void reportSensorF(Logging *log, bool fileFormat, const char *caption, const char *units, float value,
int precision) {
if (!fileFormat) {
#if (EFI_PROD_CODE || EFI_SIMULATOR) || defined(__DOXYGEN__)
debugFloat(&logger, caption, value, precision);
debugFloat(log, caption, value, precision);
#endif /* EFI_PROD_CODE || EFI_SIMULATOR */
} else {
#if EFI_FILE_LOGGING || defined(__DOXYGEN__)
debugFloat(&fileLogger, caption, value, precision);
if (logFileLineIndex == 0) {
append(log, caption);
append(log, TAB);
} else if (logFileLineIndex == 1) {
append(log, units);
append(log, TAB);
} else {
appendFloat(log, value, precision);
append(log, TAB);
}
#endif /* EFI_FILE_LOGGING */
}
}
static void reportSensorI(const char *caption, int value) {
static void reportSensorI(Logging *log, bool fileFormat, const char *caption, const char *units, int value) {
if (!fileFormat) {
#if (EFI_PROD_CODE || EFI_SIMULATOR) || defined(__DOXYGEN__)
debugInt(&logger, caption, value);
debugInt(log, caption, value);
#endif /* EFI_PROD_CODE || EFI_SIMULATOR */
} else {
#if EFI_FILE_LOGGING || defined(__DOXYGEN__)
debugInt(&fileLogger, caption, value);
if (logFileLineIndex == 0) {
append(log, caption);
append(log, TAB);
} else if (logFileLineIndex == 1) {
append(log, units);
append(log, TAB);
} else {
appendPrintf(log, "%d%s", value, TAB);
}
#endif /* EFI_FILE_LOGGING */
}
}
static const char* boolean2string(int value) {
return value ? "YES" : "NO";
}
void printSensors(Engine *engine) {
#if EFI_FILE_LOGGING || defined(__DOXYGEN__)
resetLogging(&fileLogger);
#endif /* EFI_FILE_LOGGING */
void printSensors(Logging *log, bool fileFormat, Engine *engine) {
// current time, in milliseconds
int nowMs = currentTimeMillis();
float sec = ((float) nowMs) / 1000;
reportSensorF("time", sec, 3);
reportSensorF(log, fileFormat, "time", "", sec, 3);
reportSensorI("rpm", getRpmE(engine));
reportSensorF("maf", getMaf(), 2);
reportSensorI(log, fileFormat, "rpm", "RPM", getRpmE(engine));
reportSensorF(log, fileFormat, "maf", "V", getMaf(), 2);
engine_configuration_s *engineConfiguration = engine->engineConfiguration;
if (engineConfiguration->hasMapSensor) {
reportSensorF(getCaption(LP_MAP), getMap(), 2);
reportSensorF("map_r", getRawMap(), 2);
reportSensorF(log, fileFormat, "MAP", "kPa", getMap(), 2);
reportSensorF(log, fileFormat, "map_r", "V", getRawMap(), 2);
}
if (engineConfiguration->hasBaroSensor) {
reportSensorF("baro", getBaroPressure(), 2);
reportSensorF(log, fileFormat, "baro", "kPa", getBaroPressure(), 2);
}
if (engineConfiguration->hasAfrSensor) {
reportSensorF("afr", getAfr(), 2);
reportSensorF(log, fileFormat, "afr", "AFR", getAfr(), 2);
}
#if EFI_PROD_CODE || defined(__DOXYGEN__)
if (engineConfiguration->hasVehicleSpeedSensor) {
reportSensorF("vss", getVehicleSpeed(), 2);
reportSensorF(log, fileFormat, "vss", "kph", getVehicleSpeed(), 2);
}
#endif /* EFI_PROD_CODE */
reportSensorF("vref", getVRef(engineConfiguration), 2);
reportSensorF("vbatt", getVBatt(engineConfiguration), 2);
reportSensorF(log, fileFormat, "vref", "V", getVRef(engineConfiguration), 2);
reportSensorF(log, fileFormat, "vbatt", "V", getVBatt(engineConfiguration), 2);
reportSensorF("TRG_0_DUTY", getTriggerDutyCycle(0), 2);
reportSensorF("TRG_1_DUTY", getTriggerDutyCycle(1), 2);
reportSensorF(log, fileFormat, "TRG_0_DUTY", "%", getTriggerDutyCycle(0), 2);
reportSensorF(log, fileFormat, "TRG_1_DUTY", "%", getTriggerDutyCycle(1), 2);
reportSensorF(getCaption(LP_THROTTLE), getTPS(PASS_ENGINE_PARAMETER_F), 2);
reportSensorF(log, fileFormat, "TP", "%", getTPS(PASS_ENGINE_PARAMETER_F), 2);
if (engineConfiguration->hasCltSensor) {
reportSensorF(getCaption(LP_ECT), getCoolantTemperature(engine), 2);
reportSensorF(log, fileFormat, "CLT", "C", getCoolantTemperature(engine), 2);
}
reportSensorF(getCaption(LP_IAT), getIntakeAirTemperature(engine), 2);
reportSensorF(log, fileFormat, "MAT", "C", getIntakeAirTemperature(engine), 2);
// debugFloat(&logger, "tch", getTCharge1(tps), 2);
}
EXTERN_ENGINE;
void writeLogLine(void) {
#if EFI_FILE_LOGGING || defined(__DOXYGEN__)
appendPrintf(&fileLogger, "\r\n");
appendToLog(fileLogger.buffer);
resetLogging(&fileLogger);
printSensors(&fileLogger, true, engine);
if (isSdCardAlive()) {
appendPrintf(&fileLogger, "\r\n");
appendToLog(fileLogger.buffer);
logFileLineIndex++;
}
#endif /* EFI_FILE_LOGGING */
}
void printState(Engine *engine, int currentCkpEventCounter) {
#if EFI_SHAFT_POSITION_INPUT || defined(__DOXYGEN__)
printSensors(engine);
printSensors(&logger, false, engine);
engine_configuration_s *engineConfiguration = engine->engineConfiguration;
@ -358,10 +393,7 @@ OutputPin checkEnginePin;
OutputPin warningPin;
OutputPin runningPin;
static OutputPin *leds[] = { &warningPin, &runningPin,
&errorLedPin,
&communicationPin,
&checkEnginePin };
static OutputPin *leds[] = { &warningPin, &runningPin, &errorLedPin, &communicationPin, &checkEnginePin };
/**
* This method would blink all the LEDs just to test them
@ -441,6 +473,7 @@ static void lcdThread(Engine *engine) {
}
}
// stack for Tuner Studio thread
static THD_WORKING_AREA(tsThreadStack, UTILITY_THREAD_STACK_SIZE);
#if EFI_TUNER_STUDIO
@ -541,7 +574,6 @@ void initStatusLoop(Engine *engine) {
#if EFI_FILE_LOGGING
initLogging(&fileLogger, "file logger");
#endif /* EFI_FILE_LOGGING */
}
void startStatusThreads(Engine *engine) {

View File

@ -23,6 +23,7 @@ extern "C"
{
#endif /* __cplusplus */
void writeLogLine(void);
bool getFullLog(void);
void setFullLog(int value);
void sayOsHello(void);

View File

@ -675,6 +675,8 @@ static void enableOrDisable(const char *param, bool isEnabled) {
boardConfiguration->isFastAdcEnabled = isEnabled;
} else if (strEqualCaseInsensitive(param, "joystick")) {
engineConfiguration->isJoystickEnabled = isEnabled;
} else if (strEqualCaseInsensitive(param, "sd")) {
boardConfiguration->isSdCardEnabled = isEnabled;
} else if (strEqualCaseInsensitive(param, "can")) {
engineConfiguration->isCanEnabled = isEnabled;
} else if (strEqualCaseInsensitive(param, "can_read")) {

View File

@ -21,6 +21,7 @@
#include "ff.h"
#include "hardware.h"
#include "engine_configuration.h"
#include "status_loop.h"
extern board_configuration_s *boardConfiguration;
@ -44,7 +45,7 @@ static MMCConfig mmccfg = { &MMC_CARD_SPI, &ls_spicfg, &hs_spicfg };
static bool fs_ready = false;
#define PUSHPULLDELAY 500
#define FILE_LOG_DELAY 200
/**
* fatfs MMC/SPI
@ -72,6 +73,7 @@ static void printMmcPinout(void) {
static void sdStatistics(void) {
printMmcPinout();
scheduleMsg(&logger, "SD enabled: %s", boolToString(boardConfiguration->isSdCardEnabled));
scheduleMsg(&logger, "fs_ready=%d totalLoggedBytes=%d", fs_ready, totalLoggedBytes);
}
@ -87,7 +89,7 @@ static void createLogFile(void) {
FRESULT err = f_open(&FDLogFile, "rusefi.log", FA_OPEN_ALWAYS | FA_WRITE); // Create new file
if (err != FR_OK && err != FR_EXIST) {
unlockSpi();
printError("Card mounted...\r\nCan't create Log file, check your SD.\r\nFS mount failed", err); // else - show error
printError("FS mount failed", err); // else - show error
return;
}
@ -103,7 +105,7 @@ static void createLogFile(void) {
}
static void ff_cmd_dir(const char *pathx) {
char *path = (char *)pathx; // todo: fix this hack!
char *path = (char *) pathx; // todo: fix this hack!
DIR dir;
FILINFO fno;
char *fn;
@ -213,15 +215,15 @@ static void MMCmount(void) {
}
unlockSpi();
// if Ok - mount FS now
memset(&MMC_FS, 0, sizeof(FATFS)); // reserve the memory
memset(&MMC_FS, 0, sizeof(FATFS));
if (f_mount(0, &MMC_FS) == FR_OK) {
createLogFile();
scheduleMsg(&logger, "MMC/SD mounted!\r\nDon't forget umountsd before remove to prevent lost your data");
scheduleMsg(&logger, "MMC/SD mounted!");
}
}
#if defined __GNUC__
__attribute__((noreturn)) static msg_t MMCmonThread(void)
__attribute__((noreturn)) static msg_t MMCmonThread(void)
#else
static msg_t MMCmonThread(void)
#endif
@ -237,8 +239,10 @@ static msg_t MMCmonThread(void)
}
}
// this thread is activated 10 times per second
chThdSleepMilliseconds(PUSHPULLDELAY);
if (isSdCardAlive())
writeLogLine();
chThdSleepMilliseconds(FILE_LOG_DELAY);
}
}
@ -248,6 +252,7 @@ bool isSdCardAlive(void) {
void initMmcCard(void) {
initLogging(&logger, "mmcCard");
addConsoleAction("sdstat", sdStatistics);
if (!boardConfiguration->isSdCardEnabled) {
return;
}
@ -262,7 +267,6 @@ void initMmcCard(void) {
chThdCreateStatic(mmcThreadStack, sizeof(mmcThreadStack), LOWPRIO, (tfunc_t) MMCmonThread, NULL);
addConsoleAction("sdstat", sdStatistics);
addConsoleAction("mountsd", MMCmount);
addConsoleActionS("appendToLog", appendToLog);
addConsoleAction("umountsd", MMCumount);

View File

@ -634,8 +634,8 @@ fileVersion = { 20141225 }
indicator = { needBurn }, "no Burn", "Need Burn", white, black, red, black
indicator = { hasSdCard}, "no SD", "with SD", white, black, green, black
indicator = { ind_fuel_pump}, "no pump", "pump", white, black, green, black
indicator = { clutchUpState }, "clutch", "c UP", white, black, red, black
indicator = { clutchDownState }, "clutch", "c UP", white, black, red, black
indicator = { clutchUpState }, "clutch", "cltch Up", white, black, red, black
indicator = { clutchDownState }, "clutch", "cltch Down", white, black, red, black
; error codes
indicator = { ind_tps_error}, "tps", "tps error", white, black, red, black

View File

@ -171,55 +171,6 @@ void appendPrintf(Logging *logging, const char *fmt, ...) {
va_end(ap);
}
// todo: this method does not really belong to this file
char* getCaption(LoggingPoints loggingPoint) {
switch (loggingPoint) {
case LP_RPM:
return "RPM";
case LP_THROTTLE:
return "TP";
case LP_IAT:
return "MAT";
case LP_ECT:
return "CLT";
// case LP_SECONDS:
// return "SecL";
case LP_MAF:
return "MAF";
case LP_MAP:
return "MAP";
case LP_MAP_RAW:
return "MAP_R";
default:
firmwareError("No such loggingPoint");
return NULL;
}
}
/*
// todo: this method does not really belong to this file
static char* get2ndCaption(int loggingPoint) {
switch (loggingPoint) {
case LP_RPM:
return "RPM";
case LP_THROTTLE:
return "%";
case LP_IAT:
return "°F";
case LP_ECT:
return "°F";
case LP_SECONDS:
return "s";
case LP_MAP:
return "MAP";
case LP_MAF:
return "MAF";
}
firmwareError("No such loggingPoint");
return NULL;
}
*/
void initLoggingExt(Logging *logging, const char *name, char *buffer, int bufferSize) {
print("Init logging %s\r\n", name);
logging->name = name;

View File

@ -91,7 +91,6 @@ void appendMsgPostfix(Logging *logging);
void scheduleMsg(Logging *logging, const char *fmt, ...);
void printMsg(Logging *logging, const char *fmt, ...);
char* getCaption(LoggingPoints loggingPoint);
void appendPrintf(Logging *logging, const char *fmt, ...);
void vappendPrintf(Logging *logging, const char *fmt, va_list arg);
void append(Logging *logging, const char *text);