From dc2a01d4764efd33a23afcaf4f1d7543dc35c4fa Mon Sep 17 00:00:00 2001 From: fctom1215 <fctom1215@outlook.com> Date: 星期三, 19 二月 2020 15:32:57 +0800 Subject: [PATCH] 上坡地图修正 --- lib/src/main/cpp/test_items/comm_test.cpp | 156 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 132 insertions(+), 24 deletions(-) diff --git a/lib/src/main/cpp/test_items/comm_test.cpp b/lib/src/main/cpp/test_items/comm_test.cpp index 3ea8099..3ca6c44 100644 --- a/lib/src/main/cpp/test_items/comm_test.cpp +++ b/lib/src/main/cpp/test_items/comm_test.cpp @@ -5,20 +5,37 @@ #include "comm_test.h" #include "../driver_test.h" #include "../defs.h" +#include "../common/apptimer.h" static bool seatbeltInsert; static bool engineStart; const int ENGINE_MIN_ROTATE = 200; +static bool commTest = false; static uint16_t gpioStore = 0; -static uint16_t engineStore = 0; -static void SensorChange(int index, bool value); +static void SensorChange(int gpio, bool value); +static void EngineStartHold(union sigval sig); -void CommTestStart(void) +void CommTestInit(void) { - gpioStore = engineStore = 0; + gpioStore = 0; + engineStart = true; + commTest = false; +} + +void CommTestStart(bool start) +{ + commTest = start; + if (start) { + // 妫�鏌ュ畨鍏ㄥ甫 + if (CheckSensorX(SEATBELT) == 0) { + struct RtkTime rt; + GetRtkClock(&rt); + AddExamFault(1, &rt); + } + } } void UpdateSensor(uint16_t gpio, uint16_t speed, uint16_t engine) @@ -27,37 +44,128 @@ uint16_t chg = gpioStore^gpio; - if (chg == 0) - return; + gpioStore = gpio; - for (int i = 0; i < 16; ++i) { - if (chg & BV(i)) { - SensorChange(i, (bool)(gpio & BV(i))); + if (commTest) { + for (int i = 0; i < 16; ++i) { + if (chg & BV(i)) { + SensorChange(i, (bool) (gpio & BV(i))); + } } } - gpioStore = gpio; - - - - // 瀹夊叏甯� - - // 鎸′綅 - - // 鍚姩鎸囩ず - - // 鐔勭伀鐩戞帶 + if (engine < ENGINE_MIN_ROTATE) { + if (engineStart) { + if (commTest) { + // 鐔勭伀1娆★紝鎵�10鍒� + struct RtkTime rt; + GetRtkClock(&rt); + AddExamFault(5, &rt); + } + engineStart = false; + } + } else { + engineStart = true; + } } -static void SensorChange(int index, bool value) +int CheckSensorX(int func) +{ + int gpio; + bool level; + int validLevel = GetSensorValidLevel(); + + // 浼犳劅鍣ㄦ棤鏁堬紝璁や负閫氳繃 + switch (func) { + case SEATBELT: + FindSensorCfg(SENSOR_SEATBELT, gpio, level); + if (gpio >= 0 && (gpioStore & BV(gpio)) != (validLevel & BV(gpio)) ) { + return 0; + } + return 1; + case LEFT_TURN_SIGNAL: + FindSensorCfg(SENSOR_LEFT_TURN_SIGNAL, gpio, level); + if (gpio == -1 || (gpioStore & BV(gpio)) == (validLevel & BV(gpio)) ) { + return 1; + } + return 0; + case RIGHT_TURN_SIGNAL: + FindSensorCfg(SENSOR_RIGHT_TURN_SIGNAL, gpio, level); + if (gpio == -1 || (gpioStore & BV(gpio)) == (validLevel & BV(gpio)) ) { + return 1; + } + return 0; + case HANDBREAK: + FindSensorCfg(SENSOR_HANDBREAK, gpio, level); + if (gpio == -1 || (gpioStore & BV(gpio)) == (validLevel & BV(gpio)) ) { + return 1; + } + return 0; + case SHIFT: + FindSensorCfg(SENSOR_SHIFT_N, gpio, level); + if (gpio == -1 || (gpioStore & BV(gpio)) == (validLevel & BV(gpio))) { + return 'N'; + } + return 0; + default: + break; + } + + return -1; +} + +static void EngineStartHold(union sigval sig) { + AppTimer_delete(EngineStartHold); + + // 涓嶅強鏃舵澗寮�鍚姩寮�鍏筹紝鎵�10鍒� + struct RtkTime rt; + GetRtkClock(&rt); + AddExamFault(4, &rt); +} + +static void SensorChange(int gpio, bool value) { int func; + bool level; + + GetSensorCfg(gpio, func, level); switch (func) { case SENSOR_SEATBELT: - break; - case SENSOR_TURNRIGHT: - break; + if (level != value) { + // 涓嶄娇鐢ㄥ畨鍏ㄥ甫锛屼笉鍚堟牸 + seatbeltInsert = false; + struct RtkTime rt; + GetRtkClock(&rt); + AddExamFault(1, &rt); + } else { + seatbeltInsert = true; + } + break; + case SENSOR_RIGHT_TURN_SIGNAL: + break; + case SENSOR_LEFT_TURN_SIGNAL: + break; + case SENSOR_HANDBREAK: + break; + case SENSOR_ENGINE_START: + AppTimer_delete(EngineStartHold); + if (level == value) { + AppTimer_add(EngineStartHold, D_SEC(2)); + + // 妫�鏌ユ槸鍚﹀湪绌烘尅 + if (CheckSensorX(SHIFT) != 'N') { + // 涓嶆槸绌烘尅鐐圭伀锛屼笉鍚堟牸 + struct RtkTime rt; + GetRtkClock(&rt); + AddExamFault(3, &rt); + } + } else { + + } + break; + default: + break; } } -- Gitblit v1.8.0