yy1717
2020-03-25 b73f32bc8ad86a7bb5f0739ac0fd7aa4c04cce98
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
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;
}