yy1717
2020-01-07 6f2dc73bb6bd5ff48cb4a2e77e9e7b6a93828902
lib/src/main/cpp/native-lib.cpp
@@ -13,6 +13,7 @@
#include "rtk_module/rtk.h"
#include "mcu/mcu_if.h"
#include "driver_test.h"
#include "master/comm_if.h"
static JavaVM *sg_jvm = NULL;
static jobject sg_obj = NULL;
@@ -407,6 +408,36 @@
    }
}
void SendMsgToMainProc(int cmd, const char *value)
{
    JNIEnv *env;
    bool ready_in_java_env = false;
    if (sg_jvm->GetEnv((void **)&env, JNI_VERSION_1_6) != JNI_OK) {
        // Attach主线程
        if (sg_jvm->AttachCurrentThread(&env, NULL) != JNI_OK) {
            LOGE("%s: AttachCurrentThread() failed", __FUNCTION__);
            return;
        }
    } else {
        ready_in_java_env = true;
    }
    jclass cls = env->GetObjectClass(sg_obj);
    jmethodID fun = env->GetMethodID(cls, "SendMsgToMainProc", "(ILjava/lang/String;)V");
    env->CallVoidMethod(sg_obj, fun, cmd, value != NULL ? env->NewStringUTF(value) : NULL);
    env->DeleteLocalRef(cls);
    if (!ready_in_java_env) {
        //Detach主线程
        if (sg_jvm->DetachCurrentThread() != JNI_OK) {
            LOGE("%s: DetachCurrentThread() failed", __FUNCTION__);
        }
    }
}
void DisplayText(const char *string)
{
    DEBUG("DisplayText: %s", string);
@@ -422,11 +453,25 @@
    // 不能直接赋值(g_obj = ojb)
    sg_obj = env->NewGlobalRef(thiz);
    MA_NdkStart();
    AppTimer_Init();
    ConfigMCU();
    DriverTestInit();
    ConfigRTKModule();
    InitPlatform(phone, RTK_PLATFORM_IP, RTK_PLATFORM_PORT);
}
}
extern "C"
JNIEXPORT void JNICALL
Java_com_anyun_exam_lib_RemoteService_MainProcMsgEntry(JNIEnv *env, jobject thiz, jint cmd,
                                                       jstring value) {
    // TODO: implement MainProcMsgEntry()
    if (value != NULL) {
        const char *str = env->GetStringUTFChars(value, 0);
        MA_MainProcMsgEntry(cmd, str);
        env->ReleaseStringUTFChars(value, str);
    } else {
        MA_MainProcMsgEntry(cmd, NULL);
    }
}