progress
This commit is contained in:
parent
89f22d3a9c
commit
e2a95d566b
|
@ -5,3 +5,69 @@
|
|||
* @author Andrey Belomutskiy, (c) 2012-2021
|
||||
*/
|
||||
|
||||
#include "engine_test_helper.h"
|
||||
#include "logicdata_csv_reader.h"
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void CsvReader::open(char *fileName, int *columnIndeces) {
|
||||
fp = fopen(fileName, "r");
|
||||
this->columnIndeces = columnIndeces;
|
||||
ASSERT_TRUE(fp != nullptr);
|
||||
}
|
||||
|
||||
bool CsvReader::haveMore() {
|
||||
bool result = fgets(buffer, sizeof(buffer), fp) != nullptr;
|
||||
lineIndex++;
|
||||
if (lineIndex == 0) {
|
||||
// skip header
|
||||
return haveMore();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void CsvReader::processLine(EngineTestHelper *eth) {
|
||||
Engine *engine = ð->engine;
|
||||
EXPAND_Engine
|
||||
|
||||
const char s[2] = ",";
|
||||
char *line = buffer;
|
||||
|
||||
char *timeStampstr = trim(strtok(line, s));
|
||||
bool newState[2];
|
||||
newState[columnIndeces[0]] = trim(strtok(NULL, s))[0] == '1';
|
||||
newState[columnIndeces[1]] = trim(strtok(NULL, s))[0] == '1';
|
||||
|
||||
double timeStamp = std::stod(timeStampstr);
|
||||
|
||||
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();
|
||||
engine->triggerCentral.handleShaftSignal(event, nowNt PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
|
||||
currentState[index] = newState[index];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CsvReader::readLine(EngineTestHelper *eth) {
|
||||
if (!haveMore())
|
||||
return;
|
||||
processLine(eth);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,18 @@
|
|||
|
||||
class CsvReader {
|
||||
public:
|
||||
void open(char *fileName, int * columnIndeces);
|
||||
FILE *fp;
|
||||
char buffer[255];
|
||||
|
||||
bool currentState[2];
|
||||
|
||||
int lineIndex = -1;
|
||||
|
||||
int * columnIndeces;
|
||||
|
||||
void open(char *fileName, int * columnIndeces);
|
||||
bool haveMore();
|
||||
void processLine(EngineTestHelper *eth);
|
||||
void readLine(EngineTestHelper *eth);
|
||||
};
|
||||
|
||||
|
|
|
@ -6,85 +6,9 @@
|
|||
*/
|
||||
|
||||
#include "engine_test_helper.h"
|
||||
#include "logicdata_csv_reader.h"
|
||||
#include <string>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
class CsvReader {
|
||||
public:
|
||||
FILE *fp;
|
||||
char buffer[255];
|
||||
|
||||
bool currentState[2];
|
||||
|
||||
int lineIndex = -1;
|
||||
|
||||
int * columnIndeces;
|
||||
|
||||
void open(char *fileName, int * columnIndeces) {
|
||||
fp = fopen(fileName, "r");
|
||||
this->columnIndeces = columnIndeces;
|
||||
ASSERT_TRUE(fp != nullptr);
|
||||
}
|
||||
|
||||
bool haveMore() {
|
||||
bool result = fgets(buffer, sizeof(buffer), fp) != nullptr;
|
||||
lineIndex++;
|
||||
if (lineIndex == 0) {
|
||||
// skip header
|
||||
return haveMore();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void processLine(EngineTestHelper *eth) {
|
||||
Engine *engine = ð->engine;
|
||||
EXPAND_Engine
|
||||
|
||||
const char s[2] = ",";
|
||||
char *line = buffer;
|
||||
|
||||
char *timeStampstr = trim(strtok(line, s));
|
||||
bool newState[2];
|
||||
newState[columnIndeces[0]] = trim(strtok(NULL, s))[0] == '1';
|
||||
newState[columnIndeces[1]] = trim(strtok(NULL, s))[0] == '1';
|
||||
|
||||
double timeStamp = std::stod(timeStampstr);
|
||||
|
||||
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();
|
||||
engine->triggerCentral.handleShaftSignal(event, nowNt PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
|
||||
currentState[index] = newState[index];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void readLine(EngineTestHelper *eth) {
|
||||
if (!haveMore())
|
||||
return;
|
||||
processLine(eth);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
TEST(cranking, realCrankingFromFile) {
|
||||
CsvReader reader;
|
||||
int indeces[2] = {1, 0}; // this logic data file has first trigger channel in second column and second trigger channel in first column
|
||||
|
|
Loading…
Reference in New Issue