rusefi/simulator/simulator/rusEfiFunctionalTest.cpp

153 lines
3.2 KiB
C++
Raw Normal View History

2015-07-10 06:01:56 -07:00
/**
* @file rusEfiFunctionalTest.cpp
*
* @date Mar 1, 2014
2020-01-13 18:57:43 -08:00
* @author Andrey Belomutskiy, (c) 2012-2020
2015-07-10 06:01:56 -07:00
*/
#include "pch.h"
2015-07-10 06:01:56 -07:00
#include "boards.h"
#include "rusEfiFunctionalTest.h"
#include "console_io.h"
#include "eficonsole.h"
#include "trigger_central.h"
#include "datalogging.h"
2015-07-15 18:01:45 -07:00
#include "engine_sniffer.h"
2015-07-10 06:01:56 -07:00
#include "status_loop.h"
#include "trigger_emulator_algo.h"
#include "main_trigger_callback.h"
#include "sensor_chart.h"
#include "bench_test.h"
2015-07-10 06:01:56 -07:00
#include "tunerstudio.h"
#include "map_averaging.h"
#include "memstreams.h"
#include <chprintf.h>
#include "rusefi_lua.h"
2015-07-10 06:01:56 -07:00
2016-07-23 12:05:04 -07:00
#define DEFAULT_SIM_RPM 1200
#define DEFAULT_SNIFFER_THR 2500
2015-07-10 06:01:56 -07:00
extern WaveChart waveChart;
int getRemainingStack(thread_t*) {
2015-07-10 06:01:56 -07:00
return 99999;
}
2018-01-23 08:44:18 -08:00
static void assertString(const char*actual, const char *expected) {
if (strcmp(actual, expected) != 0) {
firmwareError(OBD_PCM_Processor_Fault, "chprintf test: got %s while %s", actual, expected);
}
}
2017-04-07 12:12:49 -07:00
static void runChprintfTest() {
static MemoryStream ts;
static char testBuffer[200];
msObjectInit(&ts, (uint8_t *) testBuffer, sizeof(testBuffer), 0);
2018-01-23 09:05:14 -08:00
// it's a very, very long and mostly forgotten story how this became our %.2f precision format
ts.eos = 0; // reset
chprintf((BaseSequentialStream*)&ts, "%.2f/%.4f/%.4f", 0.239f, 239.932, 0.1234);
ts.buffer[ts.eos] = 0;
2018-01-23 08:44:18 -08:00
assertString(testBuffer, "0.23/239.9320/0.1234");
2017-04-07 12:12:49 -07:00
{
LoggingWithStorage testLogging("test");
testLogging.appendFloat(1.23, 5);
testLogging.appendFloat(1.234, 2);
2018-01-23 08:44:18 -08:00
assertString(testLogging.buffer, "1.230001.23");
2017-04-07 12:12:49 -07:00
2018-01-23 08:44:18 -08:00
}
2017-04-07 12:12:49 -07:00
2018-01-23 08:44:18 -08:00
{
LoggingWithStorage testLogging("test");
testLogging.appendFloat(-1.23, 5);
2018-01-23 08:44:18 -08:00
assertString(testLogging.buffer, "-1.23000");
}
{
LoggingWithStorage testLogging("test");
testLogging.appendPrintf( "a%.2fb%fc", -1.2, -3.4);
2018-01-23 09:05:14 -08:00
assertString(testLogging.buffer, "a-1.20b-3.400000095c");
2017-04-07 12:12:49 -07:00
}
}
2015-07-10 06:01:56 -07:00
void rusEfiFunctionalTest(void) {
printToConsole("Running rusEfi simulator version:");
2018-03-24 18:13:08 -07:00
static char versionBuffer[20];
itoa10(versionBuffer, (int)getRusEfiVersion());
printToConsole(versionBuffer);
2015-07-10 06:01:56 -07:00
engine->setConfig();
2016-12-18 10:01:47 -08:00
initializeConsole();
2015-07-10 06:01:56 -07:00
initStatusLoop();
initDataStructures();
2015-07-10 06:01:56 -07:00
// todo: reduce code duplication with initEngineContoller
resetConfigurationExt(MINIMAL_PINS);
enableTriggerStimulator();
2015-07-10 06:01:56 -07:00
commonInitEngineController();
2015-07-10 06:01:56 -07:00
initTriggerCentral();
initTriggerEmulator();
2015-07-10 06:01:56 -07:00
startStatusThreads();
2015-07-10 06:01:56 -07:00
startLoggingProcessor();
void initMmcCard();
initMmcCard();
2017-04-07 12:12:49 -07:00
runChprintfTest();
initPeriodicEvents();
2016-07-23 12:05:04 -07:00
setTriggerEmulatorRPM(DEFAULT_SIM_RPM);
2016-07-23 12:05:04 -07:00
engineConfiguration->engineSnifferRpmThreshold = DEFAULT_SNIFFER_THR;
startSerialChannels();
startLua();
extern bool main_loop_started;
main_loop_started = true;
2015-07-10 06:01:56 -07:00
}
void printPendingMessages(void) {
updateDevConsoleState();
2016-01-30 19:03:36 -08:00
waveChart.publishIfFull();
2015-07-10 06:01:56 -07:00
}
int isSerialOverTcpReady;
2017-01-05 01:03:02 -08:00
bool isCommandLineConsoleReady(void) {
2015-07-10 06:01:56 -07:00
return isSerialOverTcpReady;
}
void applyNewConfiguration(void) {
}
void onFatalError(const char *msg, const char * file, int line) {
printf("onFatalError %s %s%d", msg, file, line);
exit(-1);
}
void logMsg(const char *format, ...) {
// FILE * fp;
// fp = fopen ("simulator.log", "a");
//
// va_list(args);
// va_start(args, format);
// vfprintf(fp, format, args);
//
// fclose(fp);
}