/* * native_impl.cpp * * @date Feb 26, 2022 * @author Andrey Belomutskiy, (c) 2012-2022 */ #include "pch.h" #include "com_rusefi_native__EngineLogic.h" #include "auto_generated_sensor.h" #include "tunerstudio.h" #include static std::unique_ptr ethPtr; static EngineTestHelper* getEth() { if (!ethPtr) { ethPtr = std::make_unique(TEST_ENGINE); } return ethPtr.get(); } JNIEXPORT jstring JNICALL Java_com_rusefi_native_1_EngineLogic_getVersion(JNIEnv * env, jobject) { const char msg[60] = "Hello from unit tests"; const char* fileName = msg; jstring result = env->NewStringUTF(msg); printf("[native] hello\n"); return result; } JNIEXPORT jbyteArray JNICALL Java_com_rusefi_native_1_EngineLogic_getConfiguration(JNIEnv *env, jobject instance) { jbyteArray retVal = env->NewByteArray(sizeof(engine_configuration_s)); jbyte *buf = env->GetByteArrayElements(retVal, NULL); EngineTestHelper* eth = getEth(); memcpy(buf, (const void*)ð->persistentConfig.engineConfiguration, sizeof(engine_configuration_s)); env->ReleaseByteArrayElements(retVal, buf, 0); return retVal; } JNIEXPORT void JNICALL Java_com_rusefi_native_1_EngineLogic_setConfiguration(JNIEnv *env, jobject instance, jbyteArray data, jint offset, jint size) { printf("[native] setConfiguration %d %d\n", offset, size); // printf("[native] engine %d %d\n", engineConfiguration->engineType); } JNIEXPORT void JNICALL Java_com_rusefi_native_1_EngineLogic_setSensor (JNIEnv *env, jobject instance, jstring sensorName, jdouble sensorValue) { const char *sensorNameNative = env->GetStringUTFChars(sensorName, 0); SensorType type = findSensorTypeByName(sensorNameNative); printf("[native] Setting [%s] to %f\n", getSensorType(type), sensorValue); Sensor::setMockValue(type, sensorValue); env->ReleaseStringUTFChars(sensorName, sensorNameNative); } JNIEXPORT void JNICALL Java_com_rusefi_native_1_EngineLogic_setEngineType (JNIEnv *, jobject, jint engineType) { EngineTestHelper* eth = getEth(); resetConfigurationExt((engine_type_e)engineType); } JNIEXPORT void JNICALL Java_com_rusefi_native_1_EngineLogic_invokePeriodicCallback (JNIEnv *, jobject) { EngineTestHelper* eth = getEth(); eth->engine.periodicSlowCallback(); eth->engine.periodicFastCallback(); } JNIEXPORT jbyteArray JNICALL Java_com_rusefi_native_1_EngineLogic_getOutputs(JNIEnv * env, jobject instance) { jbyteArray retVal = env->NewByteArray(sizeof(TunerStudioOutputChannels)); jbyte *buf = env->GetByteArrayElements(retVal, NULL); EngineTestHelper* eth = getEth(); updateTunerStudioState(); memcpy(buf, (const void*)ð->engine.outputChannels, sizeof(TunerStudioOutputChannels)); env->ReleaseByteArrayElements(retVal, buf, 0); return retVal; }