yy1717
2021-02-03 026e1750503ec74bbe181bce3ece9931c244e367
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//
// Created by YY on 2020/12/16.
//
 
#include "prepare.h"
#include "../native-lib.h"
#include "../driver_test.h"
#include "../test_common/car_sensor.h"
#include "../common/apptimer.h"
#include "../jni_log.h"
 
#define DEBUG(fmt, args...)     LOGD("<prepare> <%s>: " fmt, __func__, ##args)
 
static int touch[4];
static int hint_cnt;
static bool exec = false;
 
static void TtsBack(int seq);
static void PrepareTimeout(union sigval sig);
static void PrepareTimeout2(union sigval sig);
void StartPrepare(void)
{
    exec = true;
    hint_cnt = 0;
    memset(touch, 0, sizeof(touch));
    PlayTTS(examParam.prepare_tts, TtsBack);
    DEBUG("开始上车准备");
}
 
void TerminatePrepare(void)
{
    exec = false;
    AppTimer_delete(PrepareTimeout);
    AppTimer_delete(PrepareTimeout2);
}
 
void handlePrepare(uint16_t sensor_id, int value)
{
    if (!exec)
        return;
    if (sensor_id == SEATBELT) {
        if (value == INSERT_SEATBELT) {
            AppTimer_delete(PrepareTimeout);
            // 检查绕车传感器情况
            if (touch[0] + touch[1] + touch[2] + touch[3] != 4) {
                exec = false;
                PrepareOver(-1);
            } else {
                exec = false;
                PrepareOver(0);
            }
        } else {
            // 安全带解开
            AppTimer_delete(PrepareTimeout2);
        }
    }
 
    if (sensor_id == SURROUND_CAR_1 && value == SURROUND_CAR_ACTIVE && touch[0] != 1) {
        touch[0] = 1;
        PlayTTS(examParam.touch_leftfront_tts, NULL);
        DEBUG("触摸传感器1");
    }
    if (sensor_id == SURROUND_CAR_2 && value == SURROUND_CAR_ACTIVE && touch[1] != 1) {
        touch[1] = 1;
        PlayTTS(examParam.touch_leftrear_tts, NULL);
        DEBUG("触摸传感器2");
    }
    if (sensor_id == SURROUND_CAR_3 && value == SURROUND_CAR_ACTIVE && touch[2] != 1) {
        touch[2] = 1;
        PlayTTS(examParam.touch_rightrear_tts, NULL);
        DEBUG("触摸传感器3");
    }
    if (sensor_id == SURROUND_CAR_4 && value == SURROUND_CAR_ACTIVE && touch[3] != 1) {
        touch[3] = 1;
        PlayTTS(examParam.touch_rightfront_tts, NULL);
        DEBUG("触摸传感器4");
    }
}
 
static void TtsBack(int seq)
{
    if (hint_cnt == 0) {
        if (ReadCarStatus(SEATBELT) == INSERT_SEATBELT) {
            // 再次提示
            AppTimer_add(PrepareTimeout2, D_SEC(10));
            DEBUG("设置再次提醒");
        }
        AppTimer_add(PrepareTimeout, D_MIN(2));
        DEBUG("设置2分钟超时");
    }
    hint_cnt++;
}
 
static void PrepareTimeout(union sigval sig)
{
    DEBUG("上车准备超时");
    AppTimer_delete(PrepareTimeout);
    exec = false;
    PrepareOver(-2);
}
 
static void PrepareTimeout2(union sigval sig)
{
    AppTimer_delete(PrepareTimeout2);
 
    PlayTTS(examParam.prepare_tts, TtsBack);
}