ETB JNI test progress

This commit is contained in:
Andrey 2022-11-29 02:21:36 -05:00
parent afea024ffe
commit cf63cea45f
6 changed files with 49 additions and 1 deletions

View File

@ -223,6 +223,7 @@ void EtbController::onConfigurationChange(pid_s* previousConfiguration) {
}
m_dutyRocAverage.init(engineConfiguration->etbRocExpAverageLength);
m_dutyAverage.init(engineConfiguration->etbExpAverageLength);
doInitElectronicThrottle();
}
void EtbController::showStatus() {
@ -555,10 +556,12 @@ void EtbController::setOutput(expected<percent_t> outputValue) {
}
void EtbController::update() {
#if !EFI_UNIT_TEST
// If we didn't get initialized, fail fast
if (!m_motor) {
return;
}
#endif // EFI_UNIT_TEST
#if EFI_TUNER_STUDIO
// Only debug throttle #1
@ -944,6 +947,11 @@ static pid_s* getEtbPidForFunction(etb_function_e function) {
void doInitElectronicThrottle() {
bool shouldInitThrottles = Sensor::hasSensor(SensorType::AcceleratorPedalPrimary);
#if EFI_UNIT_TEST
printf("doInitElectronicThrottle %s\n", boolToString(shouldInitThrottles));
#endif // EFI_UNIT_TEST
engineConfiguration->etb1configured = engineConfiguration->etb2configured = false;
// todo: technical debt: we still have DC motor code initialization in ETB-specific file while DC motors are used not just as ETB

View File

@ -400,7 +400,7 @@ static void initConfigActions() {
void commonInitEngineController() {
initInterpolation();
#if EFI_SIMULATOR
#if EFI_SIMULATOR || EFI_UNIT_TEST
printf("commonInitEngineController\n");
#endif

View File

@ -17,6 +17,8 @@ public class EngineLogic {
public native void setEngineType(int engineType);
public native void initTps();
public native void invokePeriodicCallback();
public native void invokeEtbCycle();

View File

@ -51,6 +51,26 @@ public class JniUnitTest {
JniSandbox.loadLibrary();
EngineLogic engineLogic = new EngineLogic();
engineLogic.setSensor(SensorType.Tps1Primary.name(), 30);
engineLogic.setSensor(SensorType.Tps1Secondary.name(), 30);
engineLogic.burnRequest(); // hack: this is here to initialize engine helper prior to mocking sensors
engineLogic.setSensor(SensorType.AcceleratorPedalPrimary.name(), 40);
engineLogic.setSensor(SensorType.AcceleratorPedalSecondary.name(), 40);
engineLogic.setConfiguration(new byte[]{3}, Fields.TPS1_1ADCCHANNEL.getTotalOffset(), 1);
engineLogic.setConfiguration(new byte[]{3}, Fields.TPS1_2ADCCHANNEL.getTotalOffset(), 1);
engineLogic.setConfiguration(new byte[]{3}, Fields.THROTTLEPEDALPOSITIONADCCHANNEL.getTotalOffset(), 1);
engineLogic.setConfiguration(new byte[]{3}, Fields.THROTTLEPEDALPOSITIONSECONDADCCHANNEL.getTotalOffset(), 1);
engineLogic.initTps();
engineLogic.burnRequest();
System.out.println("engineLogic.invokeEtbCycle");
engineLogic.invokeEtbCycle();
assertEquals(120.36, getValue(engineLogic.getOutputs(), Sensor.etb1DutyCycle));
}
private double getField(EngineLogic engineLogic, Field field) {

View File

@ -47,6 +47,14 @@ JNIEXPORT void JNICALL Java_com_rusefi_native_1_EngineLogic_setConfiguration
JNIEXPORT void JNICALL Java_com_rusefi_native_1_EngineLogic_setEngineType
(JNIEnv *, jobject, jint);
/*
* Class: com_rusefi_native__EngineLogic
* Method: initTps
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_com_rusefi_native_1_EngineLogic_initTps
(JNIEnv *, jobject);
/*
* Class: com_rusefi_native__EngineLogic
* Method: invokePeriodicCallback

View File

@ -10,6 +10,7 @@
#include "auto_generated_sensor.h"
#include "tunerstudio.h"
#include "live_data.h"
#include "init.h"
#include <memory>
@ -17,6 +18,7 @@ static std::unique_ptr<EngineTestHelper> ethPtr;
static EngineTestHelper* getEth() {
if (!ethPtr) {
printf("make_unique<EngineTestHelper>(TEST_ENGINE)\n");
ethPtr = std::make_unique<EngineTestHelper>(TEST_ENGINE);
}
return ethPtr.get();
@ -97,9 +99,17 @@ JNIEXPORT void JNICALL Java_com_rusefi_native_1_EngineLogic_invokeEtbCycle
JNIEXPORT void JNICALL Java_com_rusefi_native_1_EngineLogic_burnRequest
(JNIEnv *, jobject) {
printf("[native] onBurnRequest\n");
getEth();// just to make sure we have initialized
onBurnRequest();
}
JNIEXPORT void JNICALL Java_com_rusefi_native_1_EngineLogic_initTps
(JNIEnv *, jobject) {
printf("[native] initTps\n");
getEth();// just to make sure we have initialized
initTps();
}
JNIEXPORT jbyteArray JNICALL Java_com_rusefi_native_1_EngineLogic_getOutputs(JNIEnv * env, jobject instance) {
jbyteArray retVal = env->NewByteArray(TS_TOTAL_OUTPUT_SIZE);
jbyte *buf = env->GetByteArrayElements(retVal, NULL);