From e5e41dec2d41651c7160662ecf43325d49b07b66 Mon Sep 17 00:00:00 2001
From: fctom1215 <fctom1215@outlook.com>
Date: 星期二, 10 三月 2020 21:51:00 +0800
Subject: [PATCH] 模拟夜间考试。
---
lib/src/main/java/com/anyun/exam/lib/util/Speaker.java | 13 +++-
lib/src/main/cpp/driver_test.cpp | 8 ++
lib/src/main/cpp/rtk_platform/platform.h | 1
lib/src/main/java/com/anyun/exam/lib/util/SpeakerCallback.java | 6 +-
lib/src/main/cpp/native-lib.h | 4
lib/src/main/cpp/native-lib.cpp | 45 ++++-----------
lib/src/main/cpp/test_items2/dummy_light.cpp | 27 ++++++++
lib/src/main/cpp/test_items2/dummy_light.h | 1
lib/src/main/cpp/rtk_platform/platform.cpp | 3 +
lib/src/main/java/com/anyun/exam/lib/RemoteService.java | 15 +++-
10 files changed, 73 insertions(+), 50 deletions(-)
diff --git a/lib/src/main/cpp/driver_test.cpp b/lib/src/main/cpp/driver_test.cpp
index 94a5278..d795059 100644
--- a/lib/src/main/cpp/driver_test.cpp
+++ b/lib/src/main/cpp/driver_test.cpp
@@ -374,9 +374,9 @@
void SetDummyLightExam(int n, struct dummy_light_exam *cfg)
{
- DEBUG("鑾峰彇妯℃嫙璺�冪伅鍏夋祴璇曢」鐩�");
+ DEBUG("鑾峰彇妯℃嫙璺�冪伅鍏夋祴璇曢」鐩� N = %d %d", n, TestStart);
- if (TestStart) return;
+// if (TestStart) return;
if (DummyLightContent != NULL) {
free(DummyLightContent);
@@ -389,6 +389,8 @@
for (int i = 0; i < n; i++) {
DummyLightContent[i] = cfg[i];
}
+
+ StartDummyLightExam(DummyLightContent, DummyLightContentSize);
}
void StartDriverExam(int start, int type)
@@ -397,6 +399,7 @@
DEBUG("++++++++++++鑰冭瘯鍚姩 start %d type %d+++++++++++++", start, type);
if (start == 0) {
+ DEBUG("缁撴潫鑰冭瘯");
// CurrExamMapIndex = -1;
// TestStart = false;
// CommTestStart(false);
@@ -419,6 +422,7 @@
if (!err) {
if (!TestStart) {
+ DEBUG("鍚姩鑰冭瘯");
ExamFaultList.clear();
examFaultIndex = 0;
diff --git a/lib/src/main/cpp/native-lib.cpp b/lib/src/main/cpp/native-lib.cpp
index 69ef30e..e19a097 100644
--- a/lib/src/main/cpp/native-lib.cpp
+++ b/lib/src/main/cpp/native-lib.cpp
@@ -82,36 +82,6 @@
return ciphertext_length;
}
-void TextSpeak(const char *text)
-{
- 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, "TextSpeak", "(Ljava/lang/String;)V");
-
- std::string cstext = text;
- env->CallVoidMethod(sg_obj, fun, env->NewStringUTF(cstext.c_str()));
- env->DeleteLocalRef(cls);
-
- if (!ready_in_java_env) {
- //Detach涓荤嚎绋�
- if (sg_jvm->DetachCurrentThread() != JNI_OK) {
- LOGE("%s: DetachCurrentThread() failed", __FUNCTION__);
- }
- }
-}
-
void TextOsd(int type, const char *text)
{
/* JNIEnv *env;
@@ -225,7 +195,7 @@
}
}
-void PlayTTS(const char *string)
+void PlayTTS(const char *string, int id)
{
DEBUG("PlayTTS: %s", string);
@@ -243,9 +213,9 @@
}
jclass cls = env->GetObjectClass(sg_obj);
- jmethodID fun = env->GetMethodID(cls, "TextSpeak", "(Ljava/lang/String;)V");
+ jmethodID fun = env->GetMethodID(cls, "TextSpeak", "(Ljava/lang/String;I)V");
- env->CallVoidMethod(sg_obj, fun, env->NewStringUTF(string));
+ env->CallVoidMethod(sg_obj, fun, env->NewStringUTF(string), id);
env->DeleteLocalRef(cls);
@@ -266,6 +236,8 @@
env->GetJavaVM(&sg_jvm);
// 涓嶈兘鐩存帴璧嬪��(g_obj = ojb)
sg_obj = env->NewGlobalRef(thiz);
+
+ srand(time(NULL));
AppTimer_Init();
ConfigMCU();
@@ -309,3 +281,10 @@
env->ReleaseByteArrayElements(data, c_dat, NULL);
}
+
+extern "C"
+JNIEXPORT void JNICALL
+Java_com_anyun_exam_lib_RemoteService_TextSpeakEnd(JNIEnv *env, jobject thiz, jint id) {
+ // TODO: implement TextSpeakEnd()
+ PlatformStatusChanged(PLAY_TTS_DONE_EVT, (uint8_t *)&id, sizeof(id));
+}
diff --git a/lib/src/main/cpp/native-lib.h b/lib/src/main/cpp/native-lib.h
index c5133de..77011b3 100644
--- a/lib/src/main/cpp/native-lib.h
+++ b/lib/src/main/cpp/native-lib.h
@@ -14,10 +14,10 @@
const uint8_t *plaintext, int plaintext_length,
uint8_t **ciphertext);
-void TextSpeak(const char *text);
+
void TextOsd(int type, const char *text);
void DrawScreen(const Polygon *map, const Polygon *car);
void SendMsgToMainProc(int cmd, const char *value);
-void PlayTTS(const char *string);
+void PlayTTS(const char *string, int id);
#endif //RTKBASESTATION_NATIVE_LIB_H
diff --git a/lib/src/main/cpp/rtk_platform/platform.cpp b/lib/src/main/cpp/rtk_platform/platform.cpp
index 71b79ba..d44eac7 100644
--- a/lib/src/main/cpp/rtk_platform/platform.cpp
+++ b/lib/src/main/cpp/rtk_platform/platform.cpp
@@ -430,6 +430,9 @@
MA_SendCardBrief(&brief);
}
+ if (events & PLAY_TTS_DONE_EVT) {
+ DummyLightTTSDone(*((int *)data));
+ }
}
static void *PlatformDataListenThread(void *p) {
diff --git a/lib/src/main/cpp/rtk_platform/platform.h b/lib/src/main/cpp/rtk_platform/platform.h
index d0c6c57..4063643 100644
--- a/lib/src/main/cpp/rtk_platform/platform.h
+++ b/lib/src/main/cpp/rtk_platform/platform.h
@@ -15,6 +15,7 @@
#define GPS_UPDATE_EVT 0x0020
#define MCU_UPDATE_EVT 0x0040
#define CARD_UPDATE_EVT 0x0080
+#define PLAY_TTS_DONE_EVT 0x0100
typedef struct {
char domain_name[32];
diff --git a/lib/src/main/cpp/test_items2/dummy_light.cpp b/lib/src/main/cpp/test_items2/dummy_light.cpp
index 8bf7ec4..c25c199 100644
--- a/lib/src/main/cpp/test_items2/dummy_light.cpp
+++ b/lib/src/main/cpp/test_items2/dummy_light.cpp
@@ -14,14 +14,39 @@
static int contentNum;
static int currContent;
+static void DummyLightCheckLight(union sigval sig);
static void ExamDummyLight(union sigval sig);
void StartDummyLightExam(struct dummy_light_exam *ptr, int num)
{
+ DEBUG("StartDummyLightExam");
content = ptr;
contentNum = num;
currContent = 0;
+
+ AppTimer_delete(DummyLightCheckLight);
+ AppTimer_delete(ExamDummyLight);
AppTimer_add(ExamDummyLight, D_SEC(2));
+}
+
+void DummyLightTTSDone(int id)
+{
+ DEBUG("DummyLightTTSDone %d", id);
+
+ if (id == 100) {
+ AppTimer_add(DummyLightCheckLight, D_SEC(3), id);
+ } else if (id == 101) {
+ AppTimer_add(DummyLightCheckLight, D_SEC(1), id);
+ } else {
+ AppTimer_add(DummyLightCheckLight, D_SEC(5), id);
+ }
+}
+
+static void DummyLightCheckLight(union sigval sig)
+{
+ AppTimer_delete(DummyLightCheckLight);
+
+ DEBUG("DummyLightCheckLight %d", sig.sival_int);
}
static void ExamDummyLight(union sigval sig)
@@ -31,7 +56,7 @@
if (currContent < contentNum) {
DEBUG("妯℃嫙鐏厜娴嬭瘯 %s", content[currContent].tts);
- PlayTTS(content[currContent].tts);
+ PlayTTS(content[currContent].tts, content[currContent].item);
currContent++;
AppTimer_add(ExamDummyLight, D_SEC(5));
}
diff --git a/lib/src/main/cpp/test_items2/dummy_light.h b/lib/src/main/cpp/test_items2/dummy_light.h
index 7ae97b3..34bc315 100644
--- a/lib/src/main/cpp/test_items2/dummy_light.h
+++ b/lib/src/main/cpp/test_items2/dummy_light.h
@@ -11,5 +11,6 @@
};
void StartDummyLightExam(struct dummy_light_exam *ptr, int num);
+void DummyLightTTSDone(int id);
#endif //MYAPPLICATION2_DUMMY_LIGHT_H
diff --git a/lib/src/main/java/com/anyun/exam/lib/RemoteService.java b/lib/src/main/java/com/anyun/exam/lib/RemoteService.java
index 2712b49..7b58c01 100644
--- a/lib/src/main/java/com/anyun/exam/lib/RemoteService.java
+++ b/lib/src/main/java/com/anyun/exam/lib/RemoteService.java
@@ -159,9 +159,11 @@
return null;
}
- public void TextSpeak(String text) {
+ public void TextSpeak(String text, int id) {
if (speaker != null && ttsInitSucc) {
- speaker.speak(text);
+ speaker.speak(text, Integer.toString(id));
+ } else {
+ TextSpeakEnd(id);
}
}
@@ -194,18 +196,20 @@
}
@Override
- public void PlayStart() {
+ public void PlayStart(String s) {
Log.d(TAG, "TTS寮曟搸鎾斁寮�濮�");
}
@Override
- public void PlayDone() {
+ public void PlayDone(String s) {
Log.d(TAG, "TTS寮曟搸鎾斁缁撴潫");
+ TextSpeakEnd(Integer.valueOf(s));
}
@Override
- public void PlayError() {
+ public void PlayError(String s) {
Log.d(TAG, "TTS寮曟搸鎾斁鍑洪敊");
+ TextSpeakEnd(Integer.valueOf(s));
}
}
@@ -217,4 +221,5 @@
public native void startNative();
public native void MainProcMsgEntry(int cmd, String value);
public native void MainProcBinMsgEntry(int cmd, byte []data, int length);
+ public native void TextSpeakEnd(int id);
}
diff --git a/lib/src/main/java/com/anyun/exam/lib/util/Speaker.java b/lib/src/main/java/com/anyun/exam/lib/util/Speaker.java
index dfbea00..f326415 100644
--- a/lib/src/main/java/com/anyun/exam/lib/util/Speaker.java
+++ b/lib/src/main/java/com/anyun/exam/lib/util/Speaker.java
@@ -49,28 +49,33 @@
@Override
public void onStart(String s) {
if (callback != null) {
- callback.PlayStart();
+ callback.PlayStart(s);
}
}
@Override
public void onDone(String s) {
if (callback != null) {
- callback.PlayDone();
+ callback.PlayDone(s);
}
}
@Override
public void onError(String s) {
if (callback != null) {
- callback.PlayError();
+ callback.PlayError(s);
}
}
});
}
+ public void speak(String text, String id) {
+// tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
+ tts.speak(text, TextToSpeech.QUEUE_ADD, null, id);
+ }
+
public void speak(String text) {
// tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
- tts.speak(text, TextToSpeech.QUEUE_ADD, null, "speech");
+ tts.speak(text, TextToSpeech.QUEUE_ADD, null, "talk");
}
}
diff --git a/lib/src/main/java/com/anyun/exam/lib/util/SpeakerCallback.java b/lib/src/main/java/com/anyun/exam/lib/util/SpeakerCallback.java
index faaa68e..83bf769 100644
--- a/lib/src/main/java/com/anyun/exam/lib/util/SpeakerCallback.java
+++ b/lib/src/main/java/com/anyun/exam/lib/util/SpeakerCallback.java
@@ -2,7 +2,7 @@
public interface SpeakerCallback {
void PlayInit(boolean ret);
- void PlayStart();
- void PlayDone();
- void PlayError();
+ void PlayStart(String s);
+ void PlayDone(String s);
+ void PlayError(String s);
}
--
Gitblit v1.8.0