yy1717
2020-08-20 2d6a9d02c77d7e08d4f18ee87d6e3d337b949f47
lib/src/main/cpp/test_items2/operate_gear.cpp
@@ -8,155 +8,127 @@
#include "../native-lib.h"
#include "../test_common/car_sensor.h"
#include "../jni_log.h"
#include "../test_common/odo_graph.h"
#include "road_exam.h"
#define DEBUG(fmt, args...)     LOGD("<operate_gear> <%s>: " fmt, __func__, ##args)
static struct RtkTime currRtkTime;
static const int MAX_READ_GEAR = 6;
static int opGear;
static bool testing;
static int examTtsSeq = 0;
static int expectGear;
static int upDownShift;
static int readGearCnt;
static int opCnt = 0;
enum {
    SEND_OP_INS,
    CHECK_OP
};
static int setup;
static void CheckGear(union sigval sig);
static double maxMoveDistance;
static double gearMoveDistance;
void StartOperateGearExam(const struct RtkTime *rtkTime) {
static void TtsBack(int seq)
{
    maxMoveDistance = ReadOdo();
    setup = 1;
}
void StartOperateGearExam(void) {
    DEBUG("开始加减挡操作");
    testing = true;
    opGear = SEND_OP_INS;
    readGearCnt = 0;
    upDownShift = 0;
    opCnt = 0;
    currRtkTime = *rtkTime;
    setup = 0;
    AppTimer_delete(CheckGear);
    AppTimer_add(CheckGear, 100);
    PlayTTS("请进行加减挡位操作", TtsBack);
}
void TerminateOperateGearExam(void)
bool TestOperateGear(const struct RtkTime *rtkTime)
{
    AppTimer_delete(CheckGear);
}
    car_sensor_value_t sensor = ReadCarSensorValue(GEAR);
static void CheckGear(union sigval sig) {
    AppTimer_delete(CheckGear);
    if (sensor.name != GEAR)
        return false;
    if (opGear == SEND_OP_INS) {
        readGearCnt++;
        switch (ReadCarStatus(GEAR)) {
    if (setup == 0) {
        return true;
    } else if (setup == 1) {
        switch (sensor.value) {
            case GEAR_1: {
                upDownShift = 1;
                expectGear = GEAR_2;
                examTtsSeq = PlayTTS("请加到二挡");
                upDownShift = 1;
                PlayTTS("请加到二挡", NULL);
                setup = 2;
                break;
            }
            case GEAR_2: {
                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("请加到三挡");
                }
                expectGear = GEAR_3;
                upDownShift = 1;
                PlayTTS("请加到三挡", NULL);
                setup = 2;
                break;
            }
            case GEAR_3: {
                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("请加到四挡");
                }
                expectGear = GEAR_2;
                upDownShift = -1;
                PlayTTS("请减到二挡", NULL);
                setup = 2;
                break;
            }
            case GEAR_4: {
                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("请加到五挡");
                }
                expectGear = GEAR_3;
                upDownShift = -1;
                PlayTTS("请减到三挡", NULL);
                setup = 2;
                break;
            }
            case GEAR_5: {
                upDownShift = -1;
                expectGear = GEAR_4;
                examTtsSeq = PlayTTS("请减到四挡");
                PlayTTS("请减到四挡", NULL);
                setup = 2;
                break;
            }
            default:
                // 未读到有效挡位,继续尝试
                if (readGearCnt > MAX_READ_GEAR) {
                    DEBUG("总是读到空挡或无效挡位");
                    AddExamFault(31, &currRtkTime);
                    testing = false;
                } else {
                    AppTimer_add(CheckGear, 500);
                }
                break;
        }
    } else {
        DEBUG("检测挡位 %d", expectGear);
        opCnt++;
        // 检查挡位
        if (ReadCarStatus(GEAR) != expectGear) {
    } else if (setup == 2) {
        if (sensor.value == GEAR_N) {
        } else if (sensor.value != expectGear) {
            // 未按指令操作挡位,不合格
            DEBUG("未按指令操作挡位");
            AddExamFault(31, &currRtkTime);
            testing = false;
        } else if (opCnt < 2) {
            opGear = SEND_OP_INS;
            readGearCnt = 0;
            AppTimer_add(CheckGear, 500);
            AddExamFault(31, rtkTime);
            return false;
        } else {
            testing = false;
            // 在此挡位行驶一定距离,再执行下一个
            gearMoveDistance = ReadOdo();
            setup = 3;
        }
    } else if (setup == 3) {
        if (ReadOdo() - gearMoveDistance > 10) {
            setup = 4;
            char buff[128];
            expectGear += 0 - upDownShift;
            sprintf(buff, "请%s到%d挡", upDownShift > 0 ? "减": "加", expectGear - GEAR_N);
        }
    }
    else if (setup == 4) {
        if (sensor.value == GEAR_N) {
        } else if (sensor.value != expectGear) {
            // 未按指令操作挡位,不合格
            DEBUG("未按指令操作挡位");
            AddExamFault(31, rtkTime);
            return false;
        } else {
            // 在此挡位行驶一定距离,再执行下一个
            gearMoveDistance = ReadOdo();
            setup = 5;
        }
    } else if (setup == 5) {
        if (ReadOdo() - gearMoveDistance > 10) {
            PlayTTS("加减挡位操作结束", NULL);
            return false;
        }
    }
}
int ExecuteOperateGearExam(const struct RtkTime *rtkTime) {
    currRtkTime = *rtkTime;
    return testing ? 1 : -1;
}
void OperateGearTTSDone(int id)
{
    // 等语音播报完毕后计时
    if (id == examTtsSeq) {
        DEBUG("升降挡指令发出完毕 %d", id);
        opGear = CHECK_OP;
        AppTimer_add(CheckGear, D_SEC(7));
    if (ReadOdo() - maxMoveDistance > 120) {
        // 未按指令操作挡位,不合格
        DEBUG("未按指令操作挡位");
        AddExamFault(31, rtkTime);
        return false;
    }
    return true;
}