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/stop_and_start.cpp |   40 +++++++++++++++++++++++++++++++++-------
 1 files changed, 33 insertions(+), 7 deletions(-)

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 91a9b0b..b57ceec 100644
--- a/lib/src/main/cpp/test_items/stop_and_start.cpp
+++ b/lib/src/main/cpp/test_items/stop_and_start.cpp
@@ -12,6 +12,7 @@
 #include "../common/apptimer.h"
 #include "../utils/xconvert.h"
 #include "../test_common/car_sensor.h"
+#include "../master/comm_if.h"
 
 #define DEBUG(fmt, args...)     LOGD("<stop_and_start> <%s>: " fmt, __func__, ##args)
 
@@ -31,6 +32,7 @@
 
 static PointF stopPoint;
 
+static int mapIndex = 0;
 static int prevMoveDirect;
 static uint32_t stopTimepoint = 0;
 static bool stopCar = false;
@@ -46,11 +48,11 @@
 static double DistanceOfTire2Edge(const Polygon *map, const car_model *car);
 static bool ExitTestArea(const Polygon *map, const car_model *car);
 
-void StartSAS(int moveDirect, const struct RtkTime *rtkTime)
+void StartSAS(int index, int moveDirect, const struct RtkTime *rtkTime)
 {
     DEBUG("杩涘叆鍧¤捣椤圭洰");
     testing = true;
-
+    mapIndex = index;
     prevMoveDirect = moveDirect;
 
     if (moveDirect == 0) {
@@ -63,6 +65,8 @@
     slideNormalDistance = false;
     reportSlideFault = false;
     reportStartTimeout = false;
+
+    MA_EnterMap(mapIndex, MAP_TYPE_STOP_START, 1);
 }
 
 int TestSAS(const Polygon *map, const car_model *car, const car_model *carPrev, double speed, int moveDirect, const struct RtkTime *rtkTime)
@@ -81,6 +85,12 @@
     if (ExitTestArea(map, car)) {
         // 椹剁娴嬭瘯鍖�
         testing = false;
+    }
+
+    {
+        double dis2 = DistanceOfTire2Edge(map, car);
+
+        MA_SendDistance(-1, dis2);
     }
 
     if (prevMoveDirect != moveDirect) {
@@ -172,6 +182,10 @@
         }
     }
 
+    if (!testing) {
+        MA_EnterMap(mapIndex, MAP_TYPE_STOP_START, 0);
+    }
+
     return testing ? 1 : 0;
 }
 
@@ -245,10 +259,22 @@
 // 鏁翠釜杞﹁締閮借椹剁璇ユ祴璇曞尯鍩�
 static bool ExitTestArea(const Polygon *map, const car_model *car)
 {
-    // 鍦�8->7绾跨殑鍙充晶
-    for (int i = 0; i < car->bodyNum; ++i) {
-        if (IntersectionOfLine(map->point[8], map->point[7], car->carXY[car->body[i]]) != -1)
-            return false;
+    // 鍏ㄨ溅閮介渶涓嶅湪鍦板浘涓�
+    bool ret = false;
+
+    Polygon carBody;
+
+    carBody.num = car->bodyNum;
+    carBody.point = (PointF *)malloc(carBody.num * sizeof(PointF));
+    for (int i = 0; i < carBody.num; ++i) {
+        carBody.point[i] = car->carXY[car->body[i]];
     }
-    return true;
+
+    if (IntersectionOf(&carBody, map) == GM_None) {
+        ret = true;
+    }
+
+    free(carBody.point);
+
+    return ret;
 }

--
Gitblit v1.8.0