//
|
// Created by YY on 2020/3/9.
|
//
|
|
#include <cstdlib>
|
#include "../common/apptimer.h"
|
#include "dummy_light.h"
|
#include "../native-lib.h"
|
#include "../jni_log.h"
|
#include "../test_common/car_sensor.h"
|
|
#define DEBUG(fmt, args...) LOGD("<road_exam dummy_light> <%s>: " fmt, __func__, ##args)
|
|
static struct RtkTime currRtkTime;
|
static struct dummy_light_exam *content;
|
static int contentNum;
|
|
static int question;
|
|
static vector<int> process;
|
|
static bool testing;
|
|
static void CheckSolution(union sigval sig);
|
static void ExamDummyLight(void);
|
|
void StartDummyLightExam(struct dummy_light_exam *ptr, int num, const struct RtkTime* rtkTime)
|
{
|
DEBUG("StartDummyLightExam");
|
content = ptr;
|
contentNum = num;
|
question = 0;
|
|
if (content != NULL && num > 0) {
|
DEBUG("启动灯光");
|
currRtkTime = *rtkTime;
|
|
for (int i = 0; i < contentNum; ++i) {
|
DEBUG("灯光项目 <%d> item %d, TTS %s", i, content[i].item, content[i].tts.c_str());
|
for (int j = 0; j < content[i].process.size(); ++j) {
|
DEBUG("灯光过程解<%d> %d - %d", i, (content[i].process[j] >> 8) & 0xFF, content[i].process[j] & 0xFF);
|
}
|
for (int j = 0; j < content[i].solution.size(); ++j) {
|
DEBUG("灯光最终解<%d> %d - %d", i, (content[i].solution[j] >> 8) & 0xFF, content[i].solution[j] & 0xFF);
|
}
|
}
|
testing = true;
|
|
AppTimer_delete(CheckSolution);
|
ExamDummyLight();
|
} else {
|
testing = false;
|
}
|
}
|
|
bool ExecuteDummyLightExam(const struct RtkTime* rtkTime)
|
{
|
currRtkTime = *rtkTime;
|
return testing;
|
}
|
|
void DummyLightTTSDone(int id)
|
{
|
// 等语音播报完毕后计时
|
if (testing) {
|
vector<int>().swap(process);
|
|
// 预读取有中间操作步骤的灯光
|
for (int i = 0; i < content[question].process.size(); ++i) {
|
if (ReadCarStatus((content[question].process[i]>>8) & 0xFF) == content[question].process[i] & 0xFF) {
|
process.push_back(content[question].process[i]);
|
DEBUG("灯光操作过程解1<%d> %d - %d", question, (content[question].process[i]>>8) & 0xFF, content[question].process[i] & 0xFF);
|
}
|
}
|
|
AppTimer_delete(CheckSolution);
|
AppTimer_add(CheckSolution, D_SEC(5));
|
}
|
}
|
|
void TerminateDummyLightExam(void)
|
{
|
testing = false;
|
AppTimer_delete(CheckSolution);
|
}
|
|
// 记录中间过程
|
void handleLigthExam(uint16_t id, int value)
|
{
|
if (testing) {
|
for (int i = 0; i < content[question].process.size(); ++i) {
|
if (id == ((content[question].process[i] >> 8) & 0xFF) && value == (content[question].process[i] & 0xFF)) {
|
DEBUG("灯光操作过程解2<%d> %d - %d", question, (content[question].process[i]>>8) & 0xFF, content[question].process[i] & 0xFF);
|
if (process.size() == 0 || process.back() != content[question].process[i]) {
|
process.push_back(content[question].process[i]);
|
}
|
}
|
}
|
}
|
}
|
|
// 检查最终状态
|
static void CheckSolution(union sigval sig)
|
{
|
AppTimer_delete(CheckSolution);
|
|
if (content[question].process.size() > 0) {
|
if (content[question].process.size() != process.size()) {
|
AddExamFault(content[question].wrongCode, &currRtkTime);
|
goto NEXT_LIGHT;
|
} else {
|
// 操作顺序也要满足
|
for (int i = 0; i < content[question].process.size(); ++i) {
|
if (process[i] != content[question].process[i]) {
|
AddExamFault(content[question].wrongCode, &currRtkTime);
|
goto NEXT_LIGHT;
|
}
|
}
|
}
|
}
|
|
for (int i = 0; i < content[question].solution.size(); ++i) {
|
if (ReadCarStatus((content[question].solution[i]>>8)&0xFF) != (content[question].solution[i] & 0xFF)) {
|
DEBUG("灯光确认不合格<%d> %d != %d", question, (content[question].solution[i]>>8) & 0xFF, content[question].solution[i] & 0xFF);
|
AddExamFault(content[question].wrongCode, &currRtkTime);
|
break;
|
}
|
}
|
|
NEXT_LIGHT:
|
question++;
|
ExamDummyLight();
|
}
|
|
static void ExamDummyLight(void)
|
{
|
if (testing && question < contentNum) {
|
DEBUG("灯光题目: %s", content[question].tts.c_str());
|
PlayTTS(content[question].tts, DummyLightTTSDone);
|
} else {
|
testing = false;
|
}
|
}
|