2021-05-24 03:03:58 -07:00
|
|
|
/*
|
|
|
|
* @file test_real_cranking_miata_NA.cpp
|
|
|
|
*
|
|
|
|
* @date May 22, 2021
|
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2021
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "engine_test_helper.h"
|
2021-06-23 02:22:08 -07:00
|
|
|
#include <string>
|
2021-05-24 03:03:58 -07:00
|
|
|
|
2021-06-23 08:32:06 -07:00
|
|
|
static constexpr trigger_event_e riseEvents[] = { SHAFT_PRIMARY_RISING,
|
|
|
|
SHAFT_SECONDARY_RISING, SHAFT_3RD_RISING };
|
|
|
|
static constexpr trigger_event_e fallEvents[] = { SHAFT_PRIMARY_FALLING,
|
|
|
|
SHAFT_SECONDARY_FALLING, SHAFT_3RD_FALLING };
|
2021-06-23 02:22:08 -07:00
|
|
|
|
2021-06-23 08:32:06 -07:00
|
|
|
static char* trim(char *str) {
|
2021-06-23 02:22:08 -07:00
|
|
|
while (str != nullptr && str[0] == ' ') {
|
|
|
|
str++;
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2021-06-23 08:32:06 -07:00
|
|
|
class CsvReader {
|
|
|
|
public:
|
|
|
|
FILE *fp;
|
2021-06-19 06:56:08 -07:00
|
|
|
char buffer[255];
|
|
|
|
|
2021-06-23 02:22:08 -07:00
|
|
|
bool currentState[2];
|
|
|
|
|
2021-06-23 08:32:06 -07:00
|
|
|
int lineIndex = -1;
|
|
|
|
|
2021-06-24 18:58:40 -07:00
|
|
|
int * columnIndeces;
|
|
|
|
|
|
|
|
void open(char *fileName, int * columnIndeces) {
|
2021-06-23 08:32:06 -07:00
|
|
|
fp = fopen(fileName, "r");
|
2021-06-24 18:58:40 -07:00
|
|
|
this->columnIndeces = columnIndeces;
|
2021-06-23 08:32:06 -07:00
|
|
|
ASSERT_TRUE(fp != nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool haveMore() {
|
|
|
|
bool result = fgets(buffer, sizeof(buffer), fp) != nullptr;
|
|
|
|
lineIndex++;
|
|
|
|
if (lineIndex == 0) {
|
2021-06-18 19:52:01 -07:00
|
|
|
// skip header
|
2021-06-23 08:32:06 -07:00
|
|
|
return haveMore();
|
2021-06-18 19:52:01 -07:00
|
|
|
}
|
2021-06-23 08:32:06 -07:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void processLine(EngineTestHelper *eth) {
|
|
|
|
Engine *engine = ð->engine;
|
|
|
|
EXPAND_Engine
|
|
|
|
|
2021-06-18 19:52:01 -07:00
|
|
|
const char s[2] = ",";
|
2021-06-19 06:56:08 -07:00
|
|
|
char *line = buffer;
|
2021-06-18 19:52:01 -07:00
|
|
|
|
2021-06-23 02:22:08 -07:00
|
|
|
char *timeStampstr = trim(strtok(line, s));
|
|
|
|
bool newState[2];
|
2021-06-24 18:58:40 -07:00
|
|
|
newState[columnIndeces[0]] = trim(strtok(NULL, s))[0] == '1';
|
|
|
|
newState[columnIndeces[1]] = trim(strtok(NULL, s))[0] == '1';
|
2021-06-18 19:52:01 -07:00
|
|
|
|
2021-06-23 02:22:08 -07:00
|
|
|
double timeStamp = std::stod(timeStampstr);
|
2021-06-18 19:52:01 -07:00
|
|
|
|
2021-06-23 08:32:06 -07:00
|
|
|
eth->setTimeAndInvokeEventsUs(1'000'000 * timeStamp);
|
|
|
|
for (int index = 0; index < 2; index++) {
|
2021-06-23 02:22:08 -07:00
|
|
|
if (currentState[index] == newState[index]) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-06-23 08:32:06 -07:00
|
|
|
trigger_event_e event =
|
|
|
|
(newState[index] ? riseEvents : fallEvents)[index];
|
2021-06-23 02:22:08 -07:00
|
|
|
efitick_t nowNt = getTimeNowNt();
|
2021-06-23 03:10:27 -07:00
|
|
|
engine->triggerCentral.handleShaftSignal(event, nowNt PASS_ENGINE_PARAMETER_SUFFIX);
|
2021-06-18 19:52:01 -07:00
|
|
|
|
2021-06-23 02:22:08 -07:00
|
|
|
currentState[index] = newState[index];
|
2021-06-18 19:52:01 -07:00
|
|
|
}
|
|
|
|
|
2021-06-23 08:32:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void readLine(EngineTestHelper *eth) {
|
|
|
|
if (!haveMore())
|
|
|
|
return;
|
|
|
|
processLine(eth);
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
2021-06-23 02:22:08 -07:00
|
|
|
|
2021-06-23 08:32:06 -07:00
|
|
|
TEST(cranking, realCrankingFromFile) {
|
|
|
|
CsvReader reader;
|
2021-06-24 18:58:40 -07:00
|
|
|
int indeces[2] = {1, 0}; // this logic data file has first trigger channel in second column and second trigger channel in first column
|
|
|
|
reader.open("tests/trigger/recourses/cranking_na_3.csv", indeces);
|
2021-06-23 08:32:06 -07:00
|
|
|
|
|
|
|
WITH_ENGINE_TEST_HELPER (MIATA_NA6_MAP);
|
|
|
|
|
|
|
|
ssize_t read;
|
|
|
|
|
2021-06-24 18:58:40 -07:00
|
|
|
for (int i = 0; i < 18; i++) {
|
2021-06-23 08:32:06 -07:00
|
|
|
reader.readLine(ð);
|
|
|
|
}
|
|
|
|
|
2021-06-24 19:21:30 -07:00
|
|
|
ASSERT_EQ( 0, GET_RPM())<< reader.lineIndex << " @ 0";
|
2021-06-23 08:32:06 -07:00
|
|
|
ASSERT_EQ( 0, eth.recentWarnings()->getCount())<< "warningCounter#got synch";
|
|
|
|
|
|
|
|
reader.readLine(ð);
|
2021-06-24 19:21:30 -07:00
|
|
|
ASSERT_EQ( 32, GET_RPM())<< reader.lineIndex << " @ 1";
|
2021-06-23 08:32:06 -07:00
|
|
|
|
2021-06-24 18:58:40 -07:00
|
|
|
for (int i = 0; i < 30; i++) {
|
2021-06-23 08:32:06 -07:00
|
|
|
reader.readLine(ð);
|
2021-06-18 19:52:01 -07:00
|
|
|
}
|
2021-06-24 18:58:40 -07:00
|
|
|
ASSERT_EQ( 223, GET_RPM())<< reader.lineIndex;
|
2021-05-24 03:03:58 -07:00
|
|
|
|
2021-06-24 19:21:30 -07:00
|
|
|
|
|
|
|
for (int i = 0; i < 30; i++) {
|
|
|
|
reader.readLine(ð);
|
|
|
|
}
|
|
|
|
ASSERT_EQ( 344, GET_RPM())<< reader.lineIndex << " @ 2";
|
|
|
|
|
2021-06-23 08:32:06 -07:00
|
|
|
while (reader.haveMore()) {
|
|
|
|
reader.processLine(ð);
|
|
|
|
}
|
2021-06-24 19:21:30 -07:00
|
|
|
ASSERT_EQ( 0, eth.recentWarnings()->getCount())<< "warningCounter#realCranking";
|
|
|
|
ASSERT_EQ( 499, GET_RPM())<< reader.lineIndex;
|
2021-05-24 03:03:58 -07:00
|
|
|
}
|