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 02:22:08 -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 };
|
|
|
|
|
|
|
|
static char* trim(char*str) {
|
|
|
|
while (str != nullptr && str[0] == ' ') {
|
|
|
|
str++;
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(cranking, realCrankingFromFile) {
|
2021-06-18 19:52:01 -07:00
|
|
|
FILE *fp = fopen("tests/trigger/recourses/cranking_na_3.csv", "r");
|
2021-06-23 02:22:08 -07:00
|
|
|
ASSERT_TRUE(fp != nullptr);
|
|
|
|
|
|
|
|
WITH_ENGINE_TEST_HELPER(MIATA_NA6_MAP);
|
2021-06-18 19:52:01 -07:00
|
|
|
|
|
|
|
ssize_t read;
|
|
|
|
|
2021-06-19 06:56:08 -07:00
|
|
|
char buffer[255];
|
|
|
|
|
2021-06-23 02:22:08 -07:00
|
|
|
bool currentState[2];
|
|
|
|
|
2021-06-18 19:52:01 -07:00
|
|
|
int index = -1;
|
2021-06-19 06:56:08 -07:00
|
|
|
while (fgets(buffer, sizeof(buffer), fp)) {
|
2021-06-18 19:52:01 -07:00
|
|
|
index++;
|
|
|
|
if (index == 0) {
|
|
|
|
// skip header
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
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];
|
|
|
|
newState[0] = trim(strtok(NULL, s))[0] == '1';
|
|
|
|
newState[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 02:22:08 -07:00
|
|
|
eth.setTimeAndInvokeEventsUs(1'000'000 * timeStamp);
|
|
|
|
for (int index = 0;index <2;index ++) {
|
|
|
|
if (currentState[index] == newState[index]) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
trigger_event_e event = (newState[index] ? riseEvents : fallEvents)[index];
|
|
|
|
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 02:22:08 -07:00
|
|
|
|
2021-06-18 19:52:01 -07:00
|
|
|
}
|
2021-05-24 03:03:58 -07:00
|
|
|
|
|
|
|
}
|