From aef1984ccc48e81ab238d889327f85867ca0a973 Mon Sep 17 00:00:00 2001
From: fctom1215 <fctom1215@outlook.com>
Date: 星期三, 25 三月 2020 22:51:59 +0800
Subject: [PATCH] 修改加减挡操作.

---
 lib/src/main/cpp/native-lib.cpp               |    2 
 lib/src/main/cpp/test_items2/operate_gear.h   |    2 
 lib/src/main/cpp/test_items2/road_exam.cpp    |    2 
 lib/src/main/cpp/test_items2/operate_gear.cpp |   91 +++++++++++++++++++++------------------------
 4 files changed, 46 insertions(+), 51 deletions(-)

diff --git a/lib/src/main/cpp/native-lib.cpp b/lib/src/main/cpp/native-lib.cpp
index 34720a2..ba7cd20 100644
--- a/lib/src/main/cpp/native-lib.cpp
+++ b/lib/src/main/cpp/native-lib.cpp
@@ -26,7 +26,7 @@
 const int RTK_PLATFORM_PORT = 12125;
 const uint8_t phone[] = {0x20,0x19,0x10,0x15,0x00,0x00,0x00,0x01};
 
-const char *VIRTUAL_RTK_IP = "192.168.16.100";
+const char *VIRTUAL_RTK_IP = "192.168.3.52";
 const int VIRTUAL_RTK_PORT = 9001;
 
 static pthread_mutex_t tts_mutex = PTHREAD_MUTEX_INITIALIZER;
diff --git a/lib/src/main/cpp/test_items2/operate_gear.cpp b/lib/src/main/cpp/test_items2/operate_gear.cpp
index b0cc48c..16f9000 100644
--- a/lib/src/main/cpp/test_items2/operate_gear.cpp
+++ b/lib/src/main/cpp/test_items2/operate_gear.cpp
@@ -11,33 +11,39 @@
 
 #define DEBUG(fmt, args...)     LOGD("<operate_gear> <%s>: " fmt, __func__, ##args)
 
+static struct RtkTime currRtkTime;
+
+static const int MAX_READ_GEAR = 6;
+
 static int opGear;
 static bool testing;
 static int examTtsSeq = 0;
 static int expectGear;
 static int upDownShift;
-static bool checkError;
+static int readGearCnt;
 static int opCnt = 0;
 
 enum {
-    START_GEAR,
-    WAIT_TTS_END,
-    TTS_END,
-    WAITE_CHECK,
-    CHECKED
+    SEND_OP_INS,
+    CHECK_OP
 };
 
 static void CheckGear(union sigval sig);
 
-void StartOperateGearExam(int index, LIST_ROAD_MAP &RoadMapList) {
+void StartOperateGearExam(int index, LIST_ROAD_MAP &RoadMapList, const struct RtkTime *rtkTime) {
     if (index == -1)
         return;
+    DEBUG("寮�濮嬪姞鍑忔尅鎿嶄綔");
 
     testing = true;
-    opGear = START_GEAR;
-    checkError = false;
+    opGear = SEND_OP_INS;
+    readGearCnt = 0;
     upDownShift = 0;
     opCnt = 0;
+    currRtkTime = *rtkTime;
+
+    AppTimer_delete(CheckGear);
+    AppTimer_add(CheckGear, 100);
 }
 
 void TerminateOperateGearExam(void)
@@ -45,22 +51,19 @@
     AppTimer_delete(CheckGear);
 }
 
-int ExecuteOperateGearExam(int index, LIST_ROAD_MAP &RoadMapList, const car_model *car,
-                       LIST_CAR_MODEL &CarModelList, double speed, int moveDirect, const struct RtkTime *rtkTime) {
-    DEBUG("opGear %d", opGear);
+static void CheckGear(union sigval sig) {
+    AppTimer_delete(CheckGear);
 
-    if (opGear == START_GEAR) {
-        int currGear = ReadCarStatus(GEAR);
-        switch (currGear) {
+    if (opGear == SEND_OP_INS) {
+        readGearCnt++;
+        switch (ReadCarStatus(GEAR)) {
             case GEAR_1: {
-                opGear = WAIT_TTS_END;
                 upDownShift = 1;
                 expectGear = GEAR_2;
                 examTtsSeq = PlayTTS("璇峰姞鍒颁簩鎸�");
                 break;
             }
             case GEAR_2: {
-                opGear = WAIT_TTS_END;
                 if (upDownShift == 0) {
                     upDownShift = 1;
                     expectGear = GEAR_3;
@@ -77,7 +80,6 @@
                 break;
             }
             case GEAR_3: {
-                opGear = WAIT_TTS_END;
                 if (upDownShift == 0) {
                     upDownShift = -1;
                     expectGear = GEAR_2;
@@ -94,7 +96,6 @@
                 break;
             }
             case GEAR_4: {
-                opGear = WAIT_TTS_END;
                 if (upDownShift == 0) {
                     upDownShift = -1;
                     expectGear = GEAR_3;
@@ -111,7 +112,6 @@
                 break;
             }
             case GEAR_5: {
-                opGear = WAIT_TTS_END;
                 upDownShift = -1;
                 expectGear = GEAR_4;
                 examTtsSeq = PlayTTS("璇峰噺鍒板洓鎸�");
@@ -119,51 +119,46 @@
             }
             default:
                 // 鏈鍒版湁鏁堟尅浣嶏紝缁х画灏濊瘯
+                if (readGearCnt > MAX_READ_GEAR) {
+                    DEBUG("鎬绘槸璇诲埌绌烘尅鎴栨棤鏁堟尅浣�");
+                    AddExamFault(31, &currRtkTime);
+                    testing = false;
+                } else {
+                    AppTimer_add(CheckGear, 500);
+                }
                 break;
         }
-    } else if (opGear == WAIT_TTS_END) {
-
-    } else if (opGear == TTS_END) {
+    } else {
+        DEBUG("妫�娴嬫尅浣� %d", expectGear);
         opCnt++;
-        opGear = WAITE_CHECK;
-        checkError = false;
-        AppTimer_delete(CheckGear);
-        AppTimer_add(CheckGear, D_SEC(5));
-    } else if (opGear == CHECKED) {
-        if (checkError) {
+        // 妫�鏌ユ尅浣�
+        if (ReadCarStatus(GEAR) != expectGear) {
             // 鏈寜鎸囦护鎿嶄綔鎸′綅锛屼笉鍚堟牸
             DEBUG("鏈寜鎸囦护鎿嶄綔鎸′綅");
-            AddExamFault(31, rtkTime);
-        }
+            AddExamFault(31, &currRtkTime);
 
-        if (opCnt < 2) {
-            opGear = START_GEAR;
+            testing = false;
+        } else if (opCnt < 2) {
+            opGear = SEND_OP_INS;
+            AppTimer_add(CheckGear, 500);
         } else {
             testing = false;
         }
     }
+}
 
+int ExecuteOperateGearExam(int index, LIST_ROAD_MAP &RoadMapList, const car_model *car,
+                       LIST_CAR_MODEL &CarModelList, double speed, int moveDirect, const struct RtkTime *rtkTime) {
+    currRtkTime = *rtkTime;
     return testing ? index : -1;
 }
 
 void OperateGearTTSDone(int id)
 {
-    DEBUG("OperateGearTTSDone %d", id);
+    DEBUG("鍗囬檷鎸℃寚浠ゅ彂鍑哄畬姣� %d", id);
     // 绛夎闊虫挱鎶ュ畬姣曞悗璁℃椂
     if (id == examTtsSeq) {
-        opGear = TTS_END;
+        opGear = CHECK_OP;
+        AppTimer_add(CheckGear, D_SEC(7));
     }
-}
-
-static void CheckGear(union sigval sig)
-{
-    AppTimer_delete(CheckGear);
-
-    DEBUG("妫�娴嬫尅浣� %d", expectGear);
-    // 妫�鏌ユ尅浣�
-    if (ReadCarStatus(GEAR) != expectGear) {
-        // 涓嶆墽琛屾寚瀹氭尅浣嶏紝涓嶅悎鏍�
-        checkError = true;
-    }
-    opGear = CHECKED;
 }
diff --git a/lib/src/main/cpp/test_items2/operate_gear.h b/lib/src/main/cpp/test_items2/operate_gear.h
index 9db3a44..a254549 100644
--- a/lib/src/main/cpp/test_items2/operate_gear.h
+++ b/lib/src/main/cpp/test_items2/operate_gear.h
@@ -7,7 +7,7 @@
 
 #include "../driver_test.h"
 
-void StartOperateGearExam(int index, LIST_ROAD_MAP &RoadMapList);
+void StartOperateGearExam(int index, LIST_ROAD_MAP &RoadMapList, const struct RtkTime *rtkTime);
 int ExecuteOperateGearExam(int index, LIST_ROAD_MAP &RoadMapList, const car_model *car,
                            LIST_CAR_MODEL &CarModelList, double speed, int moveDirect, const struct RtkTime *rtkTime);
 void OperateGearTTSDone(int id);
diff --git a/lib/src/main/cpp/test_items2/road_exam.cpp b/lib/src/main/cpp/test_items2/road_exam.cpp
index 6c9e1a6..e48b855 100644
--- a/lib/src/main/cpp/test_items2/road_exam.cpp
+++ b/lib/src/main/cpp/test_items2/road_exam.cpp
@@ -518,7 +518,7 @@
             } else if (RoadMapList[currExamMapIndex].type == STOP_CAR_MAP) {
                 StartStopCarExam(currExamMapIndex, RoadMapList);
             } else if (RoadMapList[currExamMapIndex].type == OP_GEAER_MAP) {
-                StartOperateGearExam(currExamMapIndex, RoadMapList);
+                StartOperateGearExam(currExamMapIndex, RoadMapList, rtkTime);
             }
         }
     } else if (startCar == START_CAR_DONE) {

--
Gitblit v1.8.0