From b73f32bc8ad86a7bb5f0739ac0fd7aa4c04cce98 Mon Sep 17 00:00:00 2001
From: yy1717 <fctom1215@outlook.com>
Date: 星期三, 25 三月 2020 19:00:06 +0800
Subject: [PATCH] 加减档

---
 lib/src/main/cpp/test_items2/stop_car.h        |    1 
 lib/src/main/cpp/driver_test.cpp               |    5 
 lib/src/main/cpp/test_items/stop_and_start.cpp |    3 
 lib/src/main/cpp/test_items2/dummy_light.cpp   |    6 +
 lib/src/main/cpp/test_items2/stop_car.cpp      |    7 +
 lib/src/main/cpp/CMakeLists.txt                |    1 
 lib/src/main/cpp/rtk_module/rtk.cpp            |    2 
 lib/src/main/cpp/test_items2/operate_gear.cpp  |  169 +++++++++++++++++++++++++++++++++
 lib/src/main/cpp/test_items/turn_a90.cpp       |   11 +
 lib/src/main/cpp/test_items2/road_exam.h       |    1 
 lib/src/main/cpp/test_items/park_edge.cpp      |    3 
 lib/src/main/cpp/test_items2/operate_gear.h    |   16 +++
 lib/src/main/cpp/test_items2/road_exam.cpp     |   43 +++++++-
 lib/src/main/cpp/test_items2/dummy_light.h     |    1 
 lib/src/main/cpp/rtk_platform/platform.cpp     |    2 
 15 files changed, 258 insertions(+), 13 deletions(-)

diff --git a/lib/src/main/cpp/CMakeLists.txt b/lib/src/main/cpp/CMakeLists.txt
index 171aee1..cb10f90 100644
--- a/lib/src/main/cpp/CMakeLists.txt
+++ b/lib/src/main/cpp/CMakeLists.txt
@@ -42,6 +42,7 @@
         test_items2/through_something.cpp
         test_items2/drive_straight.cpp
         test_items2/stop_car.cpp
+        test_items2/operate_gear.cpp
 
         rtk_module/rtk.cpp
         rtk_module/virtual_rtk.cpp
diff --git a/lib/src/main/cpp/driver_test.cpp b/lib/src/main/cpp/driver_test.cpp
index 57a835f..ca85d04 100644
--- a/lib/src/main/cpp/driver_test.cpp
+++ b/lib/src/main/cpp/driver_test.cpp
@@ -551,6 +551,9 @@
 
     if (start == 0) {
         DEBUG("缁撴潫鑰冭瘯");
+
+        TerminateRoadExam();
+
         CurrExamMapIndex = -1;
         ExamStart = false;
         MA_SendExamStatus(0, 0);
@@ -813,7 +816,7 @@
     if (ReadCarStatus(ENGINE_START) == ENGINE_START_ACTIVE) {
         if (!engineStart) {
             engineStart = true;
-            if (ReadCarStatus(GEAR) != 'N') {
+            if (ReadCarStatus(GEAR) != GEAR_N) {
                 // 涓嶆槸绌烘尅鐐圭伀锛屼笉鍚堟牸
                 if (ExamType == TEST_TYPE_AREA)
                     AddExamFault(3, rtkTime);
diff --git a/lib/src/main/cpp/rtk_module/rtk.cpp b/lib/src/main/cpp/rtk_module/rtk.cpp
index 5fc26f8..1a32349 100644
--- a/lib/src/main/cpp/rtk_module/rtk.cpp
+++ b/lib/src/main/cpp/rtk_module/rtk.cpp
@@ -200,7 +200,7 @@
         }*/
 
         if (RxBufLen > 0) {
-#if 0
+#if 1
             const uint8_t *ptr = parseGPS(RxBuf, RxBuf + RxBufLen);
             if(ptr != RxBuf) {
                 memcpy(RxBuf, ptr, RxBufLen - (ptr - RxBuf));
diff --git a/lib/src/main/cpp/rtk_platform/platform.cpp b/lib/src/main/cpp/rtk_platform/platform.cpp
index 48af7fa..c36ea92 100644
--- a/lib/src/main/cpp/rtk_platform/platform.cpp
+++ b/lib/src/main/cpp/rtk_platform/platform.cpp
@@ -23,6 +23,7 @@
 #include "../driver_test.h"
 #include "../test_common/car_sensor.h"
 #include "../test_items2/stop_car.h"
+#include "../test_items2/operate_gear.h"
 
 #define PARSE_BUFF_SIZE         4096
 
@@ -434,6 +435,7 @@
     if (events & PLAY_TTS_DONE_EVT) {
         DummyLightTTSDone(*((int *)data));
         StopCarTTSDone(*((int *)data));
+        OperateGearTTSDone(*((int *)data));
     }
 }
 
diff --git a/lib/src/main/cpp/test_items/park_edge.cpp b/lib/src/main/cpp/test_items/park_edge.cpp
index 2e18601..207d9e7 100644
--- a/lib/src/main/cpp/test_items/park_edge.cpp
+++ b/lib/src/main/cpp/test_items/park_edge.cpp
@@ -9,6 +9,7 @@
 #include "../common/apptimer.h"
 #include "../native-lib.h"
 #include "../utils/xconvert.h"
+#include "../test_common/car_sensor.h"
 
 #include <vector>
 #include <cstdlib>
@@ -136,7 +137,7 @@
                     }
 
                     // 鍦ㄨ繖閲屾鏌ヨ浆鍚戠伅鐘舵��
-                    if (true) {
+                    if (ReadCarStatus(TURN_SIGNAL_LAMP) != LEFT_TURN_LIGHT) {
                         // 涓嶅紑杞悜鐏紝鎵�10鍒�
                         AddExamFault(25, rtkTime);
                         DEBUG("鏈紑鍚浆鍚戠伅");
diff --git a/lib/src/main/cpp/test_items/stop_and_start.cpp b/lib/src/main/cpp/test_items/stop_and_start.cpp
index 980b782..0acc552 100644
--- a/lib/src/main/cpp/test_items/stop_and_start.cpp
+++ b/lib/src/main/cpp/test_items/stop_and_start.cpp
@@ -11,6 +11,7 @@
 #include "../jni_log.h"
 #include "../common/apptimer.h"
 #include "../utils/xconvert.h"
+#include "../test_common/car_sensor.h"
 
 #define DEBUG(fmt, args...)     LOGD("<stop_and_start> <%s>: " fmt, __func__, ##args)
 
@@ -121,7 +122,7 @@
             }
 
             // 妫�鏌ユ槸鍚︽媺浣忔墜鍒�
-            if (true) {
+            if (ReadCarStatus(HAND_BREAK) != BREAK_ACTIVE) {
                 AddExamFault(19, rtkTime);
                 DEBUG("娌℃媺鎵嬪埞");
             }
diff --git a/lib/src/main/cpp/test_items/turn_a90.cpp b/lib/src/main/cpp/test_items/turn_a90.cpp
index fa753ac..6ee18df 100644
--- a/lib/src/main/cpp/test_items/turn_a90.cpp
+++ b/lib/src/main/cpp/test_items/turn_a90.cpp
@@ -9,6 +9,7 @@
 #include "../jni_log.h"
 #include "../utils/xconvert.h"
 #include "../defs.h"
+#include "../test_common/car_sensor.h"
 
 #include <vector>
 #include <cstdlib>
@@ -96,14 +97,20 @@
 
     if (az >= 30) {
         if (!turnLeftFinished) {
+            char turn_direct;
             if((( ((int)heading) + 360 - enterAreaHeading) % 360) < 180) {
                 DEBUG("鍙宠浆");
+                turn_direct = 'R';
             } else {
                 DEBUG("宸﹁浆");
+                turn_direct = 'L';
             }
             // 杞悜鐏湭寮�鍚紝鎵�10鍒�
-            AddExamFault(30, rtkTime);
-            DEBUG("杞悜鐏湭寮�鍚�");
+            if ((turn_direct == 'R' && ReadCarStatus(TURN_SIGNAL_LAMP) != RIGHT_TURN_LIGHT) ||
+                    (turn_direct == 'L' && ReadCarStatus(TURN_SIGNAL_LAMP) != LEFT_TURN_LIGHT)) {
+                DEBUG("杞悜鐏湭寮�鍚�");
+                AddExamFault(30, rtkTime);
+            }
         }
         turnLeftFinished = true;
     }
diff --git a/lib/src/main/cpp/test_items2/dummy_light.cpp b/lib/src/main/cpp/test_items2/dummy_light.cpp
index 9c7fc71..c048150 100644
--- a/lib/src/main/cpp/test_items2/dummy_light.cpp
+++ b/lib/src/main/cpp/test_items2/dummy_light.cpp
@@ -72,6 +72,12 @@
     }
 }
 
+void TerminateDummyLightExam(void)
+{
+    AppTimer_delete(DummyLightCheckActive);
+    AppTimer_delete(ExamDummyLight);
+}
+
 static void DummyLightCheckActive(union sigval sig)
 {
     int active = sig.sival_int;
diff --git a/lib/src/main/cpp/test_items2/dummy_light.h b/lib/src/main/cpp/test_items2/dummy_light.h
index 6edb749..40a5cf8 100644
--- a/lib/src/main/cpp/test_items2/dummy_light.h
+++ b/lib/src/main/cpp/test_items2/dummy_light.h
@@ -31,5 +31,6 @@
 void StartDummyLightExam(struct dummy_light_exam *ptr, int num, const struct RtkTime* rtkTime);
 int ExecuteDummyLightExam(const struct RtkTime* rtkTime);
 void DummyLightTTSDone(int id);
+void TerminateDummyLightExam(void);
 
 #endif //MYAPPLICATION2_DUMMY_LIGHT_H
diff --git a/lib/src/main/cpp/test_items2/operate_gear.cpp b/lib/src/main/cpp/test_items2/operate_gear.cpp
new file mode 100644
index 0000000..b0cc48c
--- /dev/null
+++ b/lib/src/main/cpp/test_items2/operate_gear.cpp
@@ -0,0 +1,169 @@
+//
+// Created by YY on 2020/3/25.
+//
+
+#include "operate_gear.h"
+#include "../driver_test.h"
+#include "../common/apptimer.h"
+#include "../native-lib.h"
+#include "../test_common/car_sensor.h"
+#include "../jni_log.h"
+
+#define DEBUG(fmt, args...)     LOGD("<operate_gear> <%s>: " fmt, __func__, ##args)
+
+static int opGear;
+static bool testing;
+static int examTtsSeq = 0;
+static int expectGear;
+static int upDownShift;
+static bool checkError;
+static int opCnt = 0;
+
+enum {
+    START_GEAR,
+    WAIT_TTS_END,
+    TTS_END,
+    WAITE_CHECK,
+    CHECKED
+};
+
+static void CheckGear(union sigval sig);
+
+void StartOperateGearExam(int index, LIST_ROAD_MAP &RoadMapList) {
+    if (index == -1)
+        return;
+
+    testing = true;
+    opGear = START_GEAR;
+    checkError = false;
+    upDownShift = 0;
+    opCnt = 0;
+}
+
+void TerminateOperateGearExam(void)
+{
+    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);
+
+    if (opGear == START_GEAR) {
+        int currGear = ReadCarStatus(GEAR);
+        switch (currGear) {
+            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;
+                    examTtsSeq = PlayTTS("璇峰姞鍒颁笁鎸�");
+                } else if (upDownShift == 1) {
+                    upDownShift = -1;
+                    expectGear = GEAR_1;
+                    examTtsSeq = PlayTTS("璇峰噺鍒颁竴鎸�");
+                } else {
+                    upDownShift = 1;
+                    expectGear = GEAR_3;
+                    examTtsSeq = PlayTTS("璇峰姞鍒颁笁鎸�");
+                }
+                break;
+            }
+            case GEAR_3: {
+                opGear = WAIT_TTS_END;
+                if (upDownShift == 0) {
+                    upDownShift = -1;
+                    expectGear = GEAR_2;
+                    examTtsSeq = PlayTTS("璇峰噺鍒颁簩鎸�");
+                } else if (upDownShift == 1) {
+                    upDownShift = -1;
+                    expectGear = GEAR_2;
+                    examTtsSeq = PlayTTS("璇峰噺鍒颁簩鎸�");
+                } else {
+                    upDownShift = 1;
+                    expectGear = GEAR_4;
+                    examTtsSeq = PlayTTS("璇峰姞鍒板洓鎸�");
+                }
+                break;
+            }
+            case GEAR_4: {
+                opGear = WAIT_TTS_END;
+                if (upDownShift == 0) {
+                    upDownShift = -1;
+                    expectGear = GEAR_3;
+                    examTtsSeq = PlayTTS("璇峰噺鍒颁笁鎸�");
+                } else if (upDownShift == 1) {
+                    upDownShift = -1;
+                    expectGear = GEAR_3;
+                    examTtsSeq = PlayTTS("璇峰噺鍒颁笁鎸�");
+                } else {
+                    upDownShift = 1;
+                    expectGear = GEAR_5;
+                    examTtsSeq = PlayTTS("璇峰姞鍒颁簲鎸�");
+                }
+                break;
+            }
+            case GEAR_5: {
+                opGear = WAIT_TTS_END;
+                upDownShift = -1;
+                expectGear = GEAR_4;
+                examTtsSeq = PlayTTS("璇峰噺鍒板洓鎸�");
+                break;
+            }
+            default:
+                // 鏈鍒版湁鏁堟尅浣嶏紝缁х画灏濊瘯
+                break;
+        }
+    } else if (opGear == WAIT_TTS_END) {
+
+    } else if (opGear == TTS_END) {
+        opCnt++;
+        opGear = WAITE_CHECK;
+        checkError = false;
+        AppTimer_delete(CheckGear);
+        AppTimer_add(CheckGear, D_SEC(5));
+    } else if (opGear == CHECKED) {
+        if (checkError) {
+            // 鏈寜鎸囦护鎿嶄綔鎸′綅锛屼笉鍚堟牸
+            DEBUG("鏈寜鎸囦护鎿嶄綔鎸′綅");
+            AddExamFault(31, rtkTime);
+        }
+
+        if (opCnt < 2) {
+            opGear = START_GEAR;
+        } else {
+            testing = false;
+        }
+    }
+
+    return testing ? index : -1;
+}
+
+void OperateGearTTSDone(int id)
+{
+    DEBUG("OperateGearTTSDone %d", id);
+    // 绛夎闊虫挱鎶ュ畬姣曞悗璁℃椂
+    if (id == examTtsSeq) {
+        opGear = TTS_END;
+    }
+}
+
+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
new file mode 100644
index 0000000..9db3a44
--- /dev/null
+++ b/lib/src/main/cpp/test_items2/operate_gear.h
@@ -0,0 +1,16 @@
+//
+// Created by YY on 2020/3/25.
+//
+
+#ifndef MYAPPLICATION2_OPERATE_GEAR_H
+#define MYAPPLICATION2_OPERATE_GEAR_H
+
+#include "../driver_test.h"
+
+void StartOperateGearExam(int index, LIST_ROAD_MAP &RoadMapList);
+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);
+void TerminateOperateGearExam(void);
+
+#endif //MYAPPLICATION2_OPERATE_GEAR_H
diff --git a/lib/src/main/cpp/test_items2/road_exam.cpp b/lib/src/main/cpp/test_items2/road_exam.cpp
index b280802..6c9e1a6 100644
--- a/lib/src/main/cpp/test_items2/road_exam.cpp
+++ b/lib/src/main/cpp/test_items2/road_exam.cpp
@@ -14,6 +14,7 @@
 #include "../master/comm_if.h"
 #include "drive_straight.h"
 #include "stop_car.h"
+#include "operate_gear.h"
 
 #include <vector>
 #include <list>
@@ -40,6 +41,7 @@
 static bool occurCrashRedLine;
 static bool occurCrashGreenLine;
 static bool occurOverSpeed;
+static bool occurSecondBreak;
 static int checkCrashGreenTimeout;
 static char carIntersectionOfGreenLine;
 static int currTurnSignalStatus;
@@ -66,9 +68,13 @@
 static int startCar;
 static int currExamMapIndex;
 
+static bool checkDoor = false;
+static bool handBreakActive = false;
+static bool reportRPMOver = false;
+
 static const int MAX_ENGINE_RPM = 2500;
-static const double START_CAR_MOVE_DISTANCE = 0.5;//10.0;
-static const double START_CAR_CHECK_DOOR_DISTANCE = 0.1;//1.0;
+static const double START_CAR_MOVE_DISTANCE = 10.0;
+static const double START_CAR_CHECK_DOOR_DISTANCE = 1.0;
 static const uint32_t GEAR_N_SLIDE_TIMEOUT = D_SEC(5);
 static const uint32_t GEAR_ERROR_TIMEOUT = D_SEC(15);
 static const uint32_t STOP_CAR_TIME = D_SEC(2);
@@ -97,6 +103,7 @@
     occurCrashRedLine = false;
     occurCrashGreenLine = false;
     occurOverSpeed = false;
+    occurSecondBreak = false;
     checkCrashGreenTimeout = 0;
     carIntersectionOfGreenLine = 0;
 
@@ -116,14 +123,22 @@
     currExamMapIndex = -1;
 
     startCar = START_CAR_NOT_DO;
+
+    checkDoor = false;
+    handBreakActive = false;
+    reportRPMOver = false;
+}
+
+void TerminateRoadExam(void)
+{
+    TerminateDummyLightExam();
+    TerminateStopCarExam();
+    TerminateOperateGearExam();
 }
 
 static void TestRoadStartCar(const car_model *car, double speed, int moveDirect, const struct RtkTime *rtkTime)
 {
     double moveDistance;
-    static bool checkDoor = false;
-    static bool handBreakActive = false;
-    static bool reportRPMOver = false;
 
     if (startCar == START_CAR_NOT_DO) {
         startPoint = car->basePoint;
@@ -186,6 +201,18 @@
         }
     } else {
         occurOverSpeed = false;
+    }
+
+    // 鍓埞杞︽娴�
+    if (ReadCarStatus(SECOND_BREAK) == BREAK_ACTIVE) {
+        // 鍓埞杞﹁俯涓嬶紝涓嶅悎鏍�
+        if (!occurSecondBreak) {
+            DEBUG("鍓埞杞﹀姩浣滀簡");
+            occurSecondBreak = true;
+            AddExamFault(17, rtkTime);
+        }
+    } else {
+        occurSecondBreak = false;
     }
 
     // 鎸′綅鍖归厤妫�娴�
@@ -327,7 +354,6 @@
             currTurnSignalStatus = ReadCarStatus(TURN_SIGNAL_LAMP);
             break;
     }
-
 
     // 妫�鏌ユ槸鍚︽寔缁浆鍚�
     char turnDirect = CheckCarTurn(CarModelList);
@@ -491,6 +517,8 @@
                 StartDriveStraightExam(currExamMapIndex, RoadMapList);
             } else if (RoadMapList[currExamMapIndex].type == STOP_CAR_MAP) {
                 StartStopCarExam(currExamMapIndex, RoadMapList);
+            } else if (RoadMapList[currExamMapIndex].type == OP_GEAER_MAP) {
+                StartOperateGearExam(currExamMapIndex, RoadMapList);
             }
         }
     } else if (startCar == START_CAR_DONE) {
@@ -506,6 +534,9 @@
         } else if (RoadMapList[currExamMapIndex].type == STOP_CAR_MAP) {
             currExamMapIndex = ExecuteStopCarExam(currExamMapIndex, RoadMapList, car,
                                                         CarModelList, speed, moveDirect, rtkTime);
+        } else if (RoadMapList[currExamMapIndex].type == OP_GEAER_MAP) {
+            currExamMapIndex = ExecuteOperateGearExam(currExamMapIndex, RoadMapList, car,
+                                   CarModelList, speed, moveDirect, rtkTime);
         }
 
         if (currExamMapIndex == -1) {
diff --git a/lib/src/main/cpp/test_items2/road_exam.h b/lib/src/main/cpp/test_items2/road_exam.h
index ec4f712..015a29e 100644
--- a/lib/src/main/cpp/test_items2/road_exam.h
+++ b/lib/src/main/cpp/test_items2/road_exam.h
@@ -28,6 +28,7 @@
 
 void Rtk2DriveTimer(struct drive_timer &tm, const struct RtkTime *rtkTime);
 void InitRoadExam(void);
+void TerminateRoadExam(void);
 void TestRoadGeneral(LIST_ROAD_MAP &RoadMapList, const car_model *car, LIST_CAR_MODEL &CarModelList, double speed, int moveDirect, const struct RtkTime *rtkTime);
 bool ExitSonArea(int index, LIST_ROAD_MAP &RoadMapList, const car_model *car);
 bool CrashSonRedLine(int index, LIST_ROAD_MAP &RoadMapList, const car_model *car, LIST_CAR_MODEL &CarModelList);
diff --git a/lib/src/main/cpp/test_items2/stop_car.cpp b/lib/src/main/cpp/test_items2/stop_car.cpp
index 7630016..6629623 100644
--- a/lib/src/main/cpp/test_items2/stop_car.cpp
+++ b/lib/src/main/cpp/test_items2/stop_car.cpp
@@ -61,13 +61,18 @@
 
 void StopCarTTSDone(int id)
 {
-    DEBUG("DummyLightTTSDone %d", id);
+    DEBUG("StopCarTTSDone %d", id);
     // 绛夎闊虫挱鎶ュ畬姣曞悗璁℃椂
     if (id == examTtsSeq) {
         ttsPlayEnd = 1;
     }
 }
 
+void TerminateStopCarExam(void)
+{
+    AppTimer_delete(PlayTTSTimeout);
+}
+
 int ExecuteStopCarExam(int index, LIST_ROAD_MAP &RoadMapList, const car_model *car,
                              LIST_CAR_MODEL &CarModelList, double speed, int moveDirect, const struct RtkTime *rtkTime) {
     if (ttsPlayEnd == 1) {
diff --git a/lib/src/main/cpp/test_items2/stop_car.h b/lib/src/main/cpp/test_items2/stop_car.h
index fe2b92a..afaf176 100644
--- a/lib/src/main/cpp/test_items2/stop_car.h
+++ b/lib/src/main/cpp/test_items2/stop_car.h
@@ -11,5 +11,6 @@
 void StopCarTTSDone(int id);
 int ExecuteStopCarExam(int index, LIST_ROAD_MAP &RoadMapList, const car_model *car,
                        LIST_CAR_MODEL &CarModelList, double speed, int moveDirect, const struct RtkTime *rtkTime);
+void TerminateStopCarExam(void);
 
 #endif //MYAPPLICATION2_STOP_CAR_H

--
Gitblit v1.8.0