From 682b17ff66dff23e03c6a57de276ea0c3e670c0e Mon Sep 17 00:00:00 2001
From: yy1717 <fctom1215@outlook.com>
Date: 星期一, 23 三月 2020 18:44:47 +0800
Subject: [PATCH] 起步和直线

---
 lib/src/main/cpp/test_items2/dummy_light.cpp |   90 ++++++++++++++++++++++++++++++++++-----------
 1 files changed, 68 insertions(+), 22 deletions(-)

diff --git a/lib/src/main/cpp/test_items2/dummy_light.cpp b/lib/src/main/cpp/test_items2/dummy_light.cpp
index 83d3ee1..3f7298d 100644
--- a/lib/src/main/cpp/test_items2/dummy_light.cpp
+++ b/lib/src/main/cpp/test_items2/dummy_light.cpp
@@ -11,12 +11,22 @@
 
 #define DEBUG(fmt, args...)     LOGD("<dummy_light> <%s>: " fmt, __func__, ##args)
 
+enum {
+    TTS_NOT_START,
+    TTS_DOING,
+    TTS_DONE,
+    WAIT_OPERATE,
+    CHECK_OPERATE
+};
+
 static struct RtkTime currRtkTime;
 static struct dummy_light_exam *content;
 static int contentNum;
-static int currContent;
+
 static int checkCnt;
 static bool turn_left_active, flash_beam_active;
+static int examTtsSeq = 0;
+static bool testing;
 
 static void DummyLightCheckActive(union sigval sig);
 static void ExamDummyLight(union sigval sig);
@@ -26,10 +36,13 @@
     DEBUG("StartDummyLightExam");
     content = ptr;
     contentNum = num;
-    currContent = 0;
+
     currRtkTime = *rtkTime;
 
-    AppTimer_delete(DummyLightCheckActive);
+    for (int i = 0; i < contentNum; ++i) {
+        content[i].itemStatus = TTS_NOT_START;
+    }
+    testing = true;
     AppTimer_delete(ExamDummyLight);
     AppTimer_add(ExamDummyLight, D_SEC(2));
 }
@@ -37,31 +50,28 @@
 int ExecuteDummyLightExam(const struct RtkTime* rtkTime)
 {
     currRtkTime = *rtkTime;
-    return (currContent == contentNum)?2:1;
+    return (testing)?1:2;
 }
 
 void DummyLightTTSDone(int id)
 {
     DEBUG("DummyLightTTSDone %d", id);
     // 绛夎闊虫挱鎶ュ畬姣曞悗璁℃椂
-    if (id == 100) {
-        AppTimer_add(DummyLightCheckActive, D_SEC(3), id);
-    } else if (id == 101) {
-        AppTimer_add(DummyLightCheckActive, D_SEC(1), id);
-    } else if (id == OVERTAKE) {
-        checkCnt = 0;
-        turn_left_active = flash_beam_active = false;
-        AppTimer_add(DummyLightCheckActive, D_SEC(1), id);
-    } else {
-        AppTimer_add(DummyLightCheckActive, D_SEC(5), id);
+    if (id == examTtsSeq) {
+        for (int i = 0; i < contentNum; ++i) {
+            if (content[i].itemStatus == TTS_DOING) {
+                content[i].itemStatus = TTS_DONE;
+                break;
+            }
+        }
+
+        AppTimer_add(ExamDummyLight, 100);
     }
 }
 
 static void DummyLightCheckActive(union sigval sig)
 {
-    AppTimer_delete(DummyLightCheckActive);
-
-    DEBUG("DummyLightCheckActive %d", sig.sival_int);
+    DEBUG("DummyLightCheckActive item = %d", sig.sival_int);
 
     switch (sig.sival_int) {
         case DRIVE_AT_NIGHT:
@@ -119,17 +129,53 @@
             break;
     }
 
-    AppTimer_add(ExamDummyLight, D_SEC(1));
+    for (int i = 0; i < contentNum; ++i) {
+        if (content[i].item == sig.sival_int) {
+            content[i].itemStatus = CHECK_OPERATE;
+            break;
+        }
+    }
+
+    AppTimer_add(ExamDummyLight, 500);
 }
 
 static void ExamDummyLight(union sigval sig)
 {
+    int i = 0;
     AppTimer_delete(ExamDummyLight);
 
-    if (currContent < contentNum) {
-        DEBUG("妯℃嫙鐏厜娴嬭瘯 %s", content[currContent].tts);
+    for (; i < contentNum; ++i) {
+        switch (content[i].itemStatus) {
+            case TTS_NOT_START:
+                content[i].itemStatus = TTS_DOING;
+                examTtsSeq = PlayTTS(content[i].tts);
+                // 绛夊緟TTS鎾斁瀹屾瘯
+                return;
+            case TTS_DOING:
+                return;
+            case TTS_DONE:
+                content[i].itemStatus = WAIT_OPERATE;
 
-        PlayTTS(content[currContent].tts, content[currContent].item);
-        currContent++;
+                AppTimer_delete(DummyLightCheckActive);
+                if (content[i].item == OVERTAKE) {
+                    checkCnt = 0;
+                    turn_left_active = flash_beam_active = false;
+                    AppTimer_add(DummyLightCheckActive, D_SEC(1), content[i].item);
+                }
+                else if (content[i].item >= 100)
+                    AppTimer_add(DummyLightCheckActive, D_SEC(3), content[i].item);
+                else
+                    AppTimer_add(DummyLightCheckActive, D_SEC(5), content[i].item);
+                return;
+            case WAIT_OPERATE:
+                return;
+            case CHECK_OPERATE:
+            default:
+                break;
+        }
+    }
+
+    if (i >= contentNum) {
+        testing = false;
     }
 }

--
Gitblit v1.8.0