rusefi-1/unit_tests/native/native_impl.cpp

87 lines
2.7 KiB
C++
Raw Normal View History

2022-02-26 09:51:50 -08:00
/*
* native_impl.cpp
*
* @date Feb 26, 2022
* @author Andrey Belomutskiy, (c) 2012-2022
*/
2022-02-26 14:48:07 -08:00
#include "pch.h"
#include "com_rusefi_native__EngineLogic.h"
2022-03-12 20:47:38 -08:00
#include "auto_generated_sensor.h"
2022-03-15 10:57:40 -07:00
#include "tunerstudio.h"
2022-02-26 09:51:50 -08:00
#include <memory>
2022-03-13 21:10:01 -07:00
static std::unique_ptr<EngineTestHelper> ethPtr;
static EngineTestHelper* getEth() {
2022-03-13 21:10:01 -07:00
if (!ethPtr) {
ethPtr = std::make_unique<EngineTestHelper>(TEST_ENGINE);
}
2022-03-13 21:10:01 -07:00
return ethPtr.get();
}
2022-02-28 09:29:02 -08:00
2022-02-26 14:48:07 -08:00
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);
2022-02-28 09:29:02 -08:00
printf("[native] hello\n");
2022-02-26 14:48:07 -08:00
return result;
}
2022-02-26 09:51:50 -08:00
2022-03-12 20:47:38 -08:00
JNIEXPORT jbyteArray JNICALL Java_com_rusefi_native_1_EngineLogic_getConfiguration(JNIEnv *env, jobject instance) {
2022-04-04 19:33:30 -07:00
jbyteArray retVal = env->NewByteArray(sizeof(engine_configuration_s));
jbyte *buf = env->GetByteArrayElements(retVal, NULL);
EngineTestHelper* eth = getEth();
memcpy(buf, (const void*)&eth->persistentConfig.engineConfiguration, sizeof(engine_configuration_s));
env->ReleaseByteArrayElements(retVal, buf, 0);
return retVal;
2022-02-28 09:29:02 -08:00
}
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);
}
2022-03-12 20:47:38 -08:00
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);
2022-03-18 19:30:17 -07:00
printf("[native] Setting [%s] to %f\n", getSensorType(type), sensorValue);
2022-03-12 20:47:38 -08:00
Sensor::setMockValue(type, sensorValue);
env->ReleaseStringUTFChars(sensorName, sensorNameNative);
}
2022-03-12 21:06:26 -08:00
2022-04-04 19:33:30 -07:00
JNIEXPORT void JNICALL Java_com_rusefi_native_1_EngineLogic_setEngineType
(JNIEnv *, jobject, jint engineType) {
EngineTestHelper* eth = getEth();
resetConfigurationExt((engine_type_e)engineType);
}
2022-03-12 21:06:26 -08:00
JNIEXPORT void JNICALL Java_com_rusefi_native_1_EngineLogic_invokePeriodicCallback
(JNIEnv *, jobject) {
EngineTestHelper* eth = getEth();
2022-03-13 18:35:59 -07:00
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);
2022-03-13 21:10:01 -07:00
EngineTestHelper* eth = getEth();
2022-03-15 10:57:40 -07:00
updateTunerStudioState();
2022-03-13 18:35:59 -07:00
memcpy(buf, (const void*)&eth->engine.outputChannels, sizeof(TunerStudioOutputChannels));
env->ReleaseByteArrayElements(retVal, buf, 0);
return retVal;
2022-03-12 21:06:26 -08:00
}