From 24428a1b69afcf113883e9cede1159443201a1b8 Mon Sep 17 00:00:00 2001
From: yy1717 <fctom1215@outlook.com>
Date: 星期四, 02 四月 2020 18:57:07 +0800
Subject: [PATCH] 进出科目二区域调整

---
 lib/src/main/cpp/test_items/driving_curve.cpp |   30 +++++++++++++++++++++++++-----
 1 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/lib/src/main/cpp/test_items/driving_curve.cpp b/lib/src/main/cpp/test_items/driving_curve.cpp
index 7a33a68..24ad383 100644
--- a/lib/src/main/cpp/test_items/driving_curve.cpp
+++ b/lib/src/main/cpp/test_items/driving_curve.cpp
@@ -7,6 +7,8 @@
 #include "../driver_test.h"
 #include "../common/apptimer.h"
 #include "../utils/xconvert.h"
+#include "../master/comm_if.h"
+#include "../native-lib.h"
 
 #include <vector>
 #include <cstdlib>
@@ -18,6 +20,7 @@
 const uint32_t STOP_CAR_TIME = D_SEC(2);
 
 static bool testing = false;
+static int mapIndex = 0;
 static uint32_t stopTimepoint = 0;
 
 static bool reportStopCarTimeout;
@@ -32,13 +35,14 @@
 
 static bool UpdateStartLine(struct scan_window_t *zone, const Polygon *map, const Polygon *map2, const Polygon *tireRect);
 static bool UpdateEndLine(bool mode, struct scan_window_t *zone, const Polygon *map, const Polygon *map2, const Polygon *tireRect);
-static bool CrashRedLine(const Polygon *map, const Polygon *map2, const car_model *car, struct scan_window_t *zone);
+static bool CrashRedLine(const Polygon *map, const Polygon *map2, const car_model *car, struct scan_window_t *zone, int &who);
 
-void StartDrivingCurve(int moveDirect, const struct RtkTime *rtkTime)
+void StartDrivingCurve(int index, int moveDirect, const struct RtkTime *rtkTime)
 {
     DEBUG("杩涘叆鏇茬嚎琛岄┒鍦哄湴");
 
     testing = true;
+    mapIndex = index;
 
     prevMoveDirect = moveDirect;
     if (moveDirect == 0) {
@@ -48,12 +52,14 @@
     crashRedLine = false;
 
     scanWindow.leftStart = scanWindow.leftEnd = scanWindow.rightStart = scanWindow.rightEnd = 0;
+
+    MA_EnterMap(mapIndex, MAP_TYPE_CURVE, 1);
 }
 
 int TestDrivingCurve(const Polygon *map, const Polygon *map2, const car_model *car, const car_model *carPrev, double speed, int moveDirect, const struct RtkTime *rtkTime)
 {
     Polygon tireRect;
-
+    int who = 0;
     MakePolygon(&tireRect, {car->carXY[car->left_front_tire[TIRE_OUTSIDE]],
                             car->carXY[car->right_front_tire[TIRE_OUTSIDE]],
                             car->carXY[car->right_rear_tire[TIRE_OUTSIDE]],
@@ -71,12 +77,17 @@
 
     DEBUG("scanWindow leftStart %d leftEnd %d rightStart %d rightEnd %d", scanWindow.leftStart, scanWindow.leftEnd, scanWindow.rightStart, scanWindow.rightEnd);
 
-    if (CrashRedLine(map, map2, car, &scanWindow)) {
+    if (CrashRedLine(map, map2, car, &scanWindow, who)) {
         if (!crashRedLine) {
             crashRedLine = true;
             // 杞﹁疆鍘嬭竟绾匡紝涓嶅悎鏍�
             AddExamFault(27, rtkTime);
             DEBUG("杞﹁疆鍘嬭竟绾�");
+            if (who == 1) {
+                PlayTTS("鍘嬪乏鏇茬嚎");
+            } else if (who == 2) {
+                PlayTTS("鍘嬪彸鏇茬嚎");
+            }
         }
     } else {
         crashRedLine = false;
@@ -105,6 +116,11 @@
 
 TEST_END:
     CleanPolygon(&tireRect);
+
+    if (!testing) {
+        MA_EnterMap(mapIndex, MAP_TYPE_CURVE, 0);
+    }
+
     return testing ? 1 : 0;
 }
 
@@ -276,7 +292,7 @@
 }
 
 // 杞﹁疆鏄惁鍘嬭竟绾�
-static bool CrashRedLine(const Polygon *map, const Polygon *map2, const car_model *car, struct scan_window_t *zone)
+static bool CrashRedLine(const Polygon *map, const Polygon *map2, const car_model *car, struct scan_window_t *zone, int &who)
 {
     bool ret = false;
 
@@ -290,9 +306,11 @@
     for (int e = zone->leftStart - 1; e >= zone->leftEnd; --e) {
         MakeLine(&redLine, &map->point[s], &map->point[e]);
         if (IntersectionOf(redLine, frontTireAxial) != GM_None) {
+            who = 1;
             return true;
         }
         if (IntersectionOf(redLine, rearTireAxial) != GM_None) {
+            who = 1;
             return true;
         }
         s = e;
@@ -302,9 +320,11 @@
     for (int e = zone->rightStart - 1; e >= zone->rightEnd; --e) {
         MakeLine(&redLine, &map2->point[s], &map2->point[e]);
         if (IntersectionOf(redLine, frontTireAxial) != GM_None) {
+            who = 2;
             return true;
         }
         if (IntersectionOf(redLine, rearTireAxial) != GM_None) {
+            who = 2;
             return true;
         }
         s = e;

--
Gitblit v1.8.0