IVA/app/HxTaskDispatch.cpp
hehaoyang ff66a2e0d6 V1.02
1. 删除图片存储到本地的方式;
2. 取流方式由Opencv修改为FFmpeg方式;
3. 解码后的数据直接转为RK_FORMAT_YCbCr_422_SP格式发送给算法;
4. 视频裸流数据存储在内存中,保存30s;
5. 报警图片从报警录像视频中获取;
2023-12-08 14:17:14 +08:00

748 lines
31 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "HxTaskDispatch.h"
#include "HxDataBase.h"
#include "HxVideoDevice.h"
#include <QJsonArray>
#include <QJsonObject>
#include <QJsonDocument>
/* 视频设备 */
HxVideoDevice adas_video_device, bsd_video_device[6], dsm_video_device;
HxTaskDispatch *dispatcher = new HxTaskDispatch();
QMutex upload_file_mutex;
QQueue<QString> upload_file_queue;
#ifdef USE_RABBITMQ
HxRabbitMQ rabbit;
#endif
/* 倒车灯10熄灭 */
static int reversing_light = 0;
/* 车辆状态: 1 直行; 2 左转弯; 3 右转弯; 4 倒车 */
static int vehicle_status = 0;
static int detect_channel = 0;
void HxTaskDispatch::initialization(void)
{
HxLog::append("initialization", QString("algorithm_type=%1").arg(HxDataBase::algorithm_type));
HxLog::append("initialization", QString("ftp=%1,%2,%3").arg(HxDataBase::ftp_address, HxDataBase::ftp_username, HxDataBase::ftp_password));
HxLog::append("initialization", QString("rabbitmq=%1,%2,%3").arg(HxDataBase::qamqp_address, HxDataBase::qamqp_username, HxDataBase::qamqp_password));
/* 算法模块初始化 */
#if USE_ALGORITHM
/* adas检测配置 */
strcpy(dispatcher->event_detect_config.szAdasDetectConfigPathName, "./resources/algmode/adas_detect.bin");
/* adas跟踪配置 */
strcpy(dispatcher->event_detect_config.szAdasTrackConfigPathName, "./resources/algmode/adas_track.bin");
/* bsd检测配置 */
strcpy(dispatcher->event_detect_config.szBsdDetectConfigPathName, "./resources/algmode/bsd_detect.bin");
// strcpy(dispatcher->event_detect_config.szRightBsdFrontDetectConfigPathName, "./resources/algmode/bsd_detect.bin");
/* dsm人脸检测配置 */
strcpy(dispatcher->event_detect_config.szDsmFaceDetectConfigPathName, "./resources/algmode/dsm_face_detect.bin");
/* dsm人脸特征点检测配置 */
strcpy(dispatcher->event_detect_config.szDsmFaceLandMarksDetectConfigPathName, "./resources/algmode/dsm_face_landmarks_detect.bin");
/* dsm人脸认证检测配置 */
strcpy(dispatcher->event_detect_config.szDsmFaceVerificationDetectConfigPathName, "./resources/algmode/dsm_face_verification_detect.bin");
/* dsm人眼认证检测配置 */
strcpy(dispatcher->event_detect_config.szDsmEyeLandMarksDetectConfigPathName, "./resources/algmode/dsm_eye_landmarks_detect.bin");
/* dsm人脸认证检测配置 */
strcpy(dispatcher->event_detect_config.szDsmSmokeConfPathName, "./resources/algmode/dsm_smoke_detect.bin");
strcpy(dispatcher->event_detect_config.szDsmCallConfPathName, "./resources/algmode/dsm_call_detect.bin");
strcpy(dispatcher->event_detect_config.szDsmFaceFeaturePathName, "./resources/algmode/dsm_face_feature.bin");
strcpy(dispatcher->event_detect_config.szDsmHeadPoseConfPathName, "./resources/algmode/data_68kp");
/* 输出调试信息 */
MvSetPrintf(false);
/* 目标跟踪事件检测初始化 */
auto result = MvObjectEventDetectInit(&dispatcher->event_detect_config, RIGHT_BSD_FRONT_DETECT_CHANNEL | RIGHT_BSD_REAR_DETECT_CHANNEL | LEFT_BSD_FRONT_DETECT_CHANNEL | LEFT_BSD_REAR_DETECT_CHANNEL | FRONT_BSD_DETECT_CHANNEL | REAR_BSD_DETECT_CHANNEL | DMS_DETECT_CHANNEL | ADAS_DETECT_CHANNEL);
if (result != 0)
{
HxLog::append("initialization", "object event detect init failed!!");
return;
}
/* 设置报警参数 */
result = MvSetEventWarnParamConfig(&HxDataBase::warm_param_config);
if (result != 0)
HxLog::append("initialization", "set event warn param config failed!!");
/* 相机标定 */
if (MvCameraCalibration(&HxDataBase::adas_camera_calibration) != 0)
HxLog::append("initialization", "camera calibration failed!!");
#endif
/* ADAS 通道初始化 */
if ((HxDataBase::algorithm_type & 0x1) == 1)
adas_video_device.set(0, HxDataBase::adas_video_input_source);
/* BSD 通道初始化 */
if (((HxDataBase::algorithm_type >> 1) & 0x1) == 1)
{
/* BSD-前 */
bsd_video_device[0].set(6, HxDataBase::bsd_video_input_source[0], HxDataBase::get_bsd_warn_region(0));
/* BSD-后 */
bsd_video_device[1].set(7, HxDataBase::bsd_video_input_source[1], HxDataBase::get_bsd_warn_region(1));
/* BSD-左前 */
bsd_video_device[2].set(4, HxDataBase::bsd_video_input_source[2], HxDataBase::get_bsd_warn_region(2));
/* BSD-右前 */
bsd_video_device[3].set(1, HxDataBase::bsd_video_input_source[3], HxDataBase::get_bsd_warn_region(3));
/* BSD-左后 */
bsd_video_device[4].set(5, HxDataBase::bsd_video_input_source[4], HxDataBase::get_bsd_warn_region(4));
/* BSD-右后 */
bsd_video_device[5].set(3, HxDataBase::bsd_video_input_source[5], HxDataBase::get_bsd_warn_region(5));
}
/* DSM 通道初始化 */
if (((HxDataBase::algorithm_type >> 2) & 0x1) == 1)
dsm_video_device.set(2, HxDataBase::dsm_video_input_source);
dispatcher->start();
#ifdef USE_RABBITMQ
rabbit.set(HxDataBase::qamqp_address, HxDataBase::qamqp_username, HxDataBase::qamqp_password);
rabbit.set_exchanger_name("vehicle.direct.exchange");
rabbit.set_queue_name("bsd_video_transcode_tag");
rabbit.set_routing_key("bsd_video_transcode_tag_1");
#endif
}
void HxTaskDispatch::listern(uint16_t port)
{
dispatcher->debug_tool = new HxSocket(port);
connect(dispatcher->debug_tool, &HxSocket::data_receive_event, dispatcher, &HxTaskDispatch::data_receive_event);
connect(dispatcher, &HxTaskDispatch::data_write_event, dispatcher->debug_tool, &HxSocket::write);
}
void HxTaskDispatch::connect_to_host(QString address, int port)
{
dispatcher->platform = new HxSocket(address, port);
connect(dispatcher->platform, &HxSocket::data_receive_event, dispatcher, &HxTaskDispatch::data_receive_event);
connect(dispatcher, &HxTaskDispatch::data_write_event, dispatcher->platform, &HxSocket::write);
}
void HxTaskDispatch::alarm_upload_event(int algorithm_type, QDateTime timestamp, int channel, int event_type, int danger_level, ObjectPara *object_info, int object_number, CalibrationPoint *face_land_marks, int face_land_marks_number, LaneType left_line_type, LaneType right_line_type)
{
HxVideoDevice *device = nullptr;
switch (algorithm_type)
{
case ALGORITHM_TYPE_ADAS:
device = &adas_video_device;
break;
case ALGORITHM_TYPE_BSD:
device = &bsd_video_device[channel];
break;
case ALGORITHM_TYPE_DSM:
device = &dsm_video_device;
break;
default:
return;
}
/* 判断报警是否在保护时间内 */
if (!device->determine_alarm_detection_timestamp(event_type))
return;
/* 生成报警图片+视频 */
auto filename = QString("%1_%2_%3_%4_%5").arg(HxDataBase::device_id).arg(algorithm_type, 2, 10, QChar('0')).arg(channel, 2, 10, QChar('0')).arg(timestamp.toString("yyyyMMdd"), timestamp.toString("HHmmss"));
device->create_alarm_data(event_type, filename);
QJsonObject root({{"type", 4}});
QJsonObject msg_info_json({{"time", timestamp.toString("yyyy-MM-dd HH:mm:ss")},
{"channel", channel},
{"level", danger_level},
{"event_type", event_type},
{"left_line_type", left_line_type},
{"right_line_type", right_line_type},
{"image_path", QString("/%1/%2/alarm/%3.jpg").arg(QDateTime::currentDateTime().toString("yyyyMMdd"), HxDataBase::device_id, filename)},
{"record_path", QString("/%1/%2/alarm/%3.mp4").arg(QDateTime::currentDateTime().toString("yyyyMMdd"), HxDataBase::device_id, filename)}});
QJsonArray object_info_json;
for (int i = 0; i < object_number; i++)
{
object_info_json.append(QJsonObject({{"detect_type", object_info[i].nDetectType},
{"left", object_info[i].nLeft},
{"top", object_info[i].nTop},
{"right", object_info[i].nRight},
{"bottom", object_info[i].nBottom},
{"distance", object_info[i].fDist},
{"speed", object_info[i].fVelo},
{"ttc", object_info[i].fTTC},
{"target_post_x", object_info[i].nTargetPosX},
{"target_post_y", object_info[i].nTargetPosY}}));
}
QJsonArray face_land_marks_json;
for (int i = 0; i < face_land_marks_number; i++)
face_land_marks_json.append(QJsonObject({{"x", face_land_marks[i].x}, {"y", face_land_marks[i].y}}));
msg_info_json.insert("object_info", object_info_json);
msg_info_json.insert("face_land_marks", face_land_marks_json);
root.insert("msgInfo", msg_info_json);
emit dispatcher->data_write_event(QJsonDocument(root).toJson(QJsonDocument::Compact));
HxLog::append("algorithm", QString("alarm type=0x%1, filepath=%2").arg(QString::number(event_type, 16), filename));
}
CarInfoInput *HxTaskDispatch::get_car_info(void) { return &dispatcher->car_info; }
void HxTaskDispatch::enqueue_upload_file(QString filename)
{
upload_file_mutex.lock();
upload_file_queue.enqueue(filename);
upload_file_mutex.unlock();
}
void HxTaskDispatch::update_heartbeat()
{
if (QDateTime::currentDateTime() > heartbeat_timestamp.addSecs(30))
{
heartbeat_timestamp = QDateTime::currentDateTime();
emit data_write_event(QJsonDocument(QJsonObject({{"type", 0}})).toJson(QJsonDocument::Compact));
}
}
void HxTaskDispatch::updata_vehiclue_status(QJsonObject object)
{
vehicle_status_update_time = QDateTime::currentDateTime();
car_info.fVelocity = object.value("speed").toDouble();
car_info.fAcceleration = object.value("acceleration").toDouble();
car_info.fDeceleration = object.value("deceleration").toDouble();
car_info.nBrake = object.value("brake").toInt();
car_info.nLLight = object.value("left_light").toInt();
car_info.nRLight = object.value("right_light").toInt();
car_info.fAlpha = object.value("steering_angle").toDouble();
car_info.fSteeingWheelAngle = object.value("seeing_wheel_angle").toDouble();
reversing_light = object.value("reversing_light").toInt();
HxLog::append("vehiclue status", QString(QJsonDocument(object).toJson(QJsonDocument::Compact)));
}
void HxTaskDispatch::parsing_vehiclue_status(void)
{
if (dispatcher->vehicle_status_update_time.secsTo(QDateTime::currentDateTime()) >= 10)
car_info.fVelocity = 0;
if (car_info.fVelocity > 0)
{
auto _detect_channel = 0;
/* ADAS 通道初始化 */
if ((HxDataBase::algorithm_type & 0x1) == 1)
{
_detect_channel |= ADAS_DETECT_CHANNEL;
}
/* DSM 通道初始化 */
if (((HxDataBase::algorithm_type >> 2) & 0x1) == 1)
{
_detect_channel |= DMS_DETECT_CHANNEL;
}
/* BSD 类型 */
else if (((HxDataBase::algorithm_type >> 1) & 0x1) == 1)
{
auto status = 0;
/* 倒车 */
if (reversing_light == 1)
status = 4;
/* 左转弯 */
else if (car_info.nLLight == 1)
status = 2;
/* 右转弯 */
else if (car_info.nRLight == 1)
status = 3;
/* 无左右转弯,车辆直行 */
else
status = 1;
/* 车辆状态发生改变 */
if (status != 0 && vehicle_status != status)
{
HxLog::append("vehicle status", QString("vehicle status change, %1=>%2").arg(vehicle_status).arg(status));
vehicle_status = status;
/* 禁止送帧 */
for (int i = 0; i < BSD_MAX_CHANNEL; i++)
bsd_video_device[i].set(false);
switch (status)
{
/* 直线行驶, 检测通道: A C D */
case 1:
/* 允许送帧 */
bsd_video_device[0].set(true);
bsd_video_device[2].set(true);
bsd_video_device[3].set(true);
/* 前侧, 左前, 右前 */
_detect_channel |= (FRONT_BSD_DETECT_CHANNEL | LEFT_BSD_FRONT_DETECT_CHANNEL | RIGHT_BSD_FRONT_DETECT_CHANNEL);
break;
/* 左转弯, 检测通道: C D E */
case 2:
/* 允许送帧 */
bsd_video_device[2].set(true);
bsd_video_device[3].set(true);
bsd_video_device[4].set(true);
/* 左前, 右前, 左后 */
_detect_channel |= (LEFT_BSD_FRONT_DETECT_CHANNEL | RIGHT_BSD_FRONT_DETECT_CHANNEL | LEFT_BSD_REAR_DETECT_CHANNEL);
break;
/* 右转弯, 检测通道: C D F */
case 3:
/* 允许送帧 */
bsd_video_device[2].set(true);
bsd_video_device[3].set(true);
bsd_video_device[5].set(true);
/* 左前, 右前, 右后 */
_detect_channel |= (LEFT_BSD_FRONT_DETECT_CHANNEL | RIGHT_BSD_FRONT_DETECT_CHANNEL | RIGHT_BSD_REAR_DETECT_CHANNEL);
break;
/* 倒车, 检测通道: B C D */
case 4:
/* 允许送帧 */
bsd_video_device[1].set(true);
bsd_video_device[2].set(true);
bsd_video_device[3].set(true);
/* 后侧, 左前, 左后 */
_detect_channel |= (REAR_BSD_DETECT_CHANNEL | LEFT_BSD_FRONT_DETECT_CHANNEL | RIGHT_BSD_FRONT_DETECT_CHANNEL);
break;
}
}
}
/* 确保状态改变后才调用该函数 */
if (detect_channel != _detect_channel)
{
detect_channel = _detect_channel;
#if USE_ALGORITHM
MvSetDetectChannel(detect_channel);
#endif
HxLog::append("algorithm", QString("starting detect channel=0x%1").arg(QString::number(detect_channel, 16)));
}
}
}
void HxTaskDispatch::recording_upload_task(void)
{
while (true)
{
msleep(1000);
if (!upload_file_queue.isEmpty())
{
upload_file_mutex.lock();
auto filename = upload_file_queue.dequeue();
upload_file_mutex.unlock();
QString fullpath = QString("%1/%2").arg(TEMPORARY_RECORD_DIRECTORY, filename);
if (!QFile::exists(fullpath))
{
HxLog::append("recording upload task", QString("file=%1 not exists, upload failed").arg(fullpath));
continue;
}
QString path = QString("%1/%2/alarm").arg(QDateTime::currentDateTime().toString("yyyyMMdd"), HxDataBase::device_id);
while (true)
{
msleep(100);
/* 上传 */
HxProcess::start(QString("curl -u %1:%2 ftp://%3/%4/ --ftp-create-dirs -T %5").arg(HxDataBase::ftp_username, HxDataBase::ftp_password, HxDataBase::ftp_address, path, fullpath));
/* 判断文件是否存在 */
auto res = HxProcess::start(QString("curl -u %1:%2 --ftp-ssl --head ftp://%3/%4/%5").arg(HxDataBase::ftp_username, HxDataBase::ftp_password, HxDataBase::ftp_address, path, filename));
QRegExp rx("Content-Length:\\s\\d{1,9}");
if (rx.indexIn(res, 0) == -1)
continue;
/* 比较大小 */
QFileInfo info(fullpath);
auto size1 = info.size();
auto size2 = rx.cap(0).replace("Content-Length:", "").toInt();
if (size1 == size2)
{
HxLog::append("recording upload task", QString("%1 upload finish").arg(filename));
if (info.suffix() == "mp4")
{
#ifdef USE_RABBITMQ
emit rabbit.publish(QString("{\"ftproot\": \"%1\", \"complate\": true}").arg(("/" + path + "/" + filename)));
#endif
}
break;
}
}
QFile::remove(fullpath);
HxLog::append("recording upload task", QString("%1 delete").arg(filename));
}
}
}
void HxTaskDispatch::run()
{
/* 启动 录像上传任务 */
QtConcurrent::run(this, &HxTaskDispatch::recording_upload_task);
while (true)
{
/* 事件循环用于响应信号 */
QCoreApplication::processEvents();
/* 发送心跳数据 */
update_heartbeat();
/* 分析车辆行驶状态 */
parsing_vehiclue_status();
/* 延时1s */
QThread::msleep(1000);
}
}
void HxTaskDispatch::debug_tool_response_event(int type, std::initializer_list<QPair<QString, QJsonValue>> args)
{
QJsonObject root, msginfo;
for (std::initializer_list<QPair<QString, QJsonValue>>::const_iterator i = args.begin(); i != args.end(); ++i)
msginfo.insert(i->first, i->second);
root.insert("type", type);
root.insert("msgInfo", msginfo);
emit data_write_event(QJsonDocument(root).toJson(QJsonDocument::Compact));
}
void HxTaskDispatch::get_warn_param_config(int type)
{
#if USE_ALGORITHM
if (MvGetEventWarnParamConfig(&HxDataBase::warm_param_config) == -1)
return;
#endif
QJsonArray start_event_warn_kind, abnormal_warn_frame_count, normal_frame_count, abnormal_warn_interval_frame_count, abnormal_warn_score_threshold, normal_warn_score_threshold;
for (int i = 0; i < EVENT_WARN_NUM; i++)
{
start_event_warn_kind.append(HxDataBase::warm_param_config.bStartEventWarnKind[i]);
abnormal_warn_frame_count.append(HxDataBase::warm_param_config.nAbnormalWarnFrameCount[i] / 25);
normal_frame_count.append(HxDataBase::warm_param_config.nNormalFrameCount[i] / 25);
// abnormal_warn_interval_frame_count.append(HxDataBase::warm_param_config.nAbnormalWarnIntervalFrameCount[i] / 25);
abnormal_warn_interval_frame_count.append(HxDataBase::alarm_protect_timestamp.at(i).toInt());
abnormal_warn_score_threshold.append((int)(HxDataBase::warm_param_config.fAbnormalWarnScoreThreshold[i] * ((i >= 17 && i <= 20) ? 1 : 100)));
normal_warn_score_threshold.append((int)(HxDataBase::warm_param_config.fNormalWarnScoreThreshold[i] * ((i >= 17 && i <= 20) ? 1 : 100)));
qDebug() << "enable=" << HxDataBase::warm_param_config.bStartEventWarnKind[i]
<< "nAbnormalWarnFrameCount=" << HxDataBase::warm_param_config.nAbnormalWarnFrameCount[i]
<< "nNormalFrameCount=" << HxDataBase::warm_param_config.nNormalFrameCount[i]
<< "nAbnormalWarnIntervalFrameCount" << HxDataBase::warm_param_config.nAbnormalWarnIntervalFrameCount[i]
<< "fAbnormalWarnScoreThreshold=" << HxDataBase::warm_param_config.fAbnormalWarnScoreThreshold[i]
<< "fNormalWarnScoreThreshold=" << HxDataBase::warm_param_config.fNormalWarnScoreThreshold[i];
}
debug_tool_response_event(type, {{"start_event_warn_kind", start_event_warn_kind},
{"abnormal_warn_frame_count", abnormal_warn_frame_count},
{"normal_frame_count", normal_frame_count},
{"abnormal_warn_interval_frame_count", abnormal_warn_interval_frame_count},
{"abnormal_warn_score_threshold", abnormal_warn_score_threshold},
{"normal_warn_score_threshold", normal_warn_score_threshold},
{"hmw_time", HxDataBase::warm_param_config.nHmwTime},
{"pcw_time", HxDataBase::warm_param_config.nPcwTime},
{"fcw_time", HxDataBase::warm_param_config.nFcwTime},
{"hmw_vel", HxDataBase::warm_param_config.fHmwVel},
{"fcw_vel", HxDataBase::warm_param_config.fFcwVel},
{"ldw_vel", HxDataBase::warm_param_config.fLdwVel},
{"pcw_vel", HxDataBase::warm_param_config.fPcwVel},
{"bsd_first_vel", HxDataBase::warm_param_config.fBsdFirstVel},
{"bsd_second_vel", HxDataBase::warm_param_config.fBsdSecondVel},
{"bsd_third_vel", HxDataBase::warm_param_config.fBsdThirdVel},
{"ldw_distance", HxDataBase::warm_param_config.nLdwDistance},
{"dsm_vel", HxDataBase::warm_param_config.fDsmVel}});
}
void HxTaskDispatch::set_warn_param_config(int type, QJsonObject object)
{
QJsonArray start_event_warn_kind = object.value("start_event_warn_kind").toArray();
QJsonArray abnormal_warn_frame_count = object.value("abnormal_warn_frame_count").toArray();
QJsonArray normal_frame_count = object.value("normal_frame_count").toArray();
QJsonArray abnormal_warn_interval_frame_count = object.value("abnormal_warn_interval_frame_count").toArray();
QJsonArray abnormal_warn_score_threshold = object.value("abnormal_warn_score_threshold").toArray();
QJsonArray normal_warn_score_threshold = object.value("normal_warn_score_threshold").toArray();
for (int i = 0; i < EVENT_WARN_NUM; i++)
{
HxDataBase::warm_param_config.bStartEventWarnKind[i] = start_event_warn_kind.at(i).toBool();
HxDataBase::warm_param_config.nAbnormalWarnFrameCount[i] = abnormal_warn_frame_count.at(i).toInt() * 25;
HxDataBase::warm_param_config.nNormalFrameCount[i] = normal_frame_count.at(i).toInt() * 25;
HxDataBase::warm_param_config.nAbnormalWarnIntervalFrameCount[i] = abnormal_warn_interval_frame_count.at(i).toInt() * 25;
HxDataBase::warm_param_config.fAbnormalWarnScoreThreshold[i] = abnormal_warn_score_threshold.at(i).toDouble() / ((i >= 17 && i <= 20) ? 1 : 100);
HxDataBase::warm_param_config.fNormalWarnScoreThreshold[i] = normal_warn_score_threshold.at(i).toDouble() / ((i >= 17 && i <= 20) ? 1 : 100);
/* 设置报警保护时长 */
HxDataBase::alarm_protect_timestamp[i] = QString::number(abnormal_warn_interval_frame_count.at(i).toInt());
}
HxDataBase::warm_param_config.nHmwTime = object.value("hmw_time").toInt();
HxDataBase::warm_param_config.nPcwTime = object.value("pcw_time").toInt();
HxDataBase::warm_param_config.nFcwTime = object.value("fcw_time").toInt();
HxDataBase::warm_param_config.fHmwVel = object.value("hmw_vel").toDouble();
HxDataBase::warm_param_config.fFcwVel = object.value("fcw_vel").toDouble();
HxDataBase::warm_param_config.fLdwVel = object.value("ldw_vel").toDouble();
HxDataBase::warm_param_config.fPcwVel = object.value("pcw_vel").toDouble();
HxDataBase::warm_param_config.fBsdFirstVel = object.value("bsd_first_vel").toDouble();
HxDataBase::warm_param_config.fBsdSecondVel = object.value("bsd_second_vel").toDouble();
HxDataBase::warm_param_config.fBsdThirdVel = object.value("bsd_third_vel").toDouble();
HxDataBase::warm_param_config.nLdwDistance = object.value("ldw_distance").toInt();
HxDataBase::warm_param_config.fDsmVel = object.value("dsm_vel").toDouble();
#if USE_ALGORITHM
if (MvSetEventWarnParamConfig(&HxDataBase::warm_param_config) != 0)
{
debug_tool_response_event(type, {{"status", false}});
return;
}
#endif
debug_tool_response_event(type, {{"status", HxDataBase::save_setting()}});
}
void HxTaskDispatch::get_adas_camera_calibration(int type)
{
#if USE_ALGORITHM
if (MvGetCameraCalibrationInfo(&HxDataBase::adas_camera_calibration) != 0)
return;
#endif
debug_tool_response_event(type, {{"car_len", HxDataBase::adas_camera_calibration.fCarLen},
{"car_width", HxDataBase::adas_camera_calibration.fCarWidth},
{"ref_center", HxDataBase::adas_camera_calibration.fRefCenter},
{"ref_top", HxDataBase::adas_camera_calibration.fRefTop},
{"dis_len_tyre", HxDataBase::adas_camera_calibration.fDisLen2Tyre},
{"camera_height", HxDataBase::adas_camera_calibration.fCameraHeight},
{"camera_focus", HxDataBase::adas_camera_calibration.fCameraFocus},
{"camera_dx", HxDataBase::adas_camera_calibration.fCameraDx},
{"pitch", HxDataBase::adas_camera_calibration.fPitch},
{"yaw", HxDataBase::adas_camera_calibration.fYaw}});
}
void HxTaskDispatch::set_adas_camera_calibration(int type, QJsonObject object)
{
HxDataBase::adas_camera_calibration.fCarLen = object.value("car_len").toInt();
HxDataBase::adas_camera_calibration.fCarWidth = object.value("car_width").toInt();
HxDataBase::adas_camera_calibration.fRefCenter = object.value("ref_center").toInt();
HxDataBase::adas_camera_calibration.fRefTop = object.value("ref_top").toDouble();
HxDataBase::adas_camera_calibration.fDisLen2Tyre = object.value("dis_len_tyre").toDouble();
HxDataBase::adas_camera_calibration.fCameraHeight = object.value("camera_height").toDouble();
HxDataBase::adas_camera_calibration.fCameraFocus = object.value("camera_focus").toDouble();
HxDataBase::adas_camera_calibration.fCameraDx = object.value("camera_dx").toDouble();
HxDataBase::adas_camera_calibration.fPitch = object.value("pitch").toDouble();
HxDataBase::adas_camera_calibration.fYaw = object.value("yaw").toDouble();
#if USE_ALGORITHM
if (MvCameraCalibration(&HxDataBase::adas_camera_calibration) != 0)
{
debug_tool_response_event(type, {{"status", false}});
return;
}
#endif
debug_tool_response_event(type, {{"status", HxDataBase::save_setting()}});
}
void HxTaskDispatch::data_receive_event(QByteArray data)
{
int type = -1;
auto document = QJsonDocument::fromJson(data);
auto root = document.object();
if (root.contains("type"))
{
type = root.value("type").toInt();
}
auto msginfo = root.value("msgInfo").toObject();
switch (type)
{
/* heart */
case 0:
break;
/* 车辆状态 */
case 3:
updata_vehiclue_status(msginfo);
break;
/* 校时 */
case 5:
HxProcess::start(QString("date -s %1").arg(msginfo.value("date").toString()));
HxProcess::start(QString("date -s %1").arg(msginfo.value("time").toString()));
debug_tool_response_event(type, {{"status", true}});
HxLog::append("timing", QString(QJsonDocument(msginfo).toJson(QJsonDocument::Compact)));
break;
/* 重启 */
case 200:
debug_tool_response_event(type, {{"status", true}});
HxProcess::start("systemctl restart app.service");
break;
/* 获取算法类型 */
case 240:
debug_tool_response_event(type, {{"mode", HxDataBase::algorithm_type}});
break;
/* 设置算法类型 */
case 241:
HxDataBase::algorithm_type = msginfo.value("mode").toInt();
debug_tool_response_event(type, {{"status", HxDataBase::save_setting()}});
break;
/* 获取ADAS视频输入源 */
case 242:
debug_tool_response_event(type, {{"source", HxDataBase::adas_video_input_source}});
break;
/* 设置ADAS视频输入源 */
case 243:
HxDataBase::adas_video_input_source = msginfo.value("source").toString();
debug_tool_response_event(type, {{"status", HxDataBase::save_setting()}});
break;
/* 获取BSD视频输入源 */
case 245:
debug_tool_response_event(type, {{"source", HxDataBase::bsd_video_input_source[msginfo.value("channel").toInt()]}});
break;
/* 设置BSD视频输入源 */
case 246:
HxDataBase::bsd_video_input_source[msginfo.value("channel").toInt()] = msginfo.value("source").toString();
debug_tool_response_event(type, {{"status", HxDataBase::save_setting()}});
break;
/* 获取Dsm视频输入源 */
case 248:
debug_tool_response_event(type, {{"source", HxDataBase::dsm_video_input_source}});
break;
/* 设置Dsm视频输入源 */
case 249:
HxDataBase::dsm_video_input_source = msginfo.value("source").toString();
debug_tool_response_event(type, {{"status", HxDataBase::save_setting()}});
break;
/* 获取BSD报警区域 */
case 251:
debug_tool_response_event(type, {{"data", HxDataBase::bsd_warn_regions[msginfo.value("channel").toInt()]}});
break;
/* 设置BSD报警区域 */
case 252:
HxDataBase::bsd_warn_regions[msginfo.value("channel").toInt()] = msginfo.value("data").toString();
debug_tool_response_event(type, {{"status", HxDataBase::save_setting()}});
break;
/* 获取设备编号及FTP信息 */
case 253:
debug_tool_response_event(type, {
{"device_id", HxDataBase::device_id},
{"ftp_address", HxDataBase::ftp_address},
{"ftp_username", HxDataBase::ftp_username},
{"ftp_password", HxDataBase::ftp_password},
});
break;
/* 设置设备编号及FTP信息 */
case 254:
HxDataBase::device_id = msginfo.value("device_id").toString();
HxDataBase::ftp_address = msginfo.value("ftp_address").toString();
HxDataBase::ftp_username = msginfo.value("ftp_username").toString();
HxDataBase::ftp_password = msginfo.value("ftp_password").toString();
debug_tool_response_event(type, {{"status", HxDataBase::save_setting()}});
break;
case 255:
get_warn_param_config(type);
break;
case 256:
set_warn_param_config(type, msginfo);
break;
case 257:
get_adas_camera_calibration(type);
break;
case 258:
set_adas_camera_calibration(type, msginfo);
break;
/* 获取 RabbitMQ 信息 */
case 259:
debug_tool_response_event(type, {{"qamqp_address", HxDataBase::qamqp_address},
{"qamqp_username", HxDataBase::qamqp_username},
{"qamqp_password", HxDataBase::qamqp_password}});
break;
/* 设置 RabbitMQ 信息 */
case 260:
HxDataBase::qamqp_address = msginfo.value("qamqp_address").toString();
HxDataBase::qamqp_username = msginfo.value("qamqp_username").toString();
HxDataBase::qamqp_password = msginfo.value("qamqp_password").toString();
debug_tool_response_event(type, {{"status", HxDataBase::save_setting()}});
break;
case 261:
debug_tool_response_event(type, {{"recording_prepend_time", HxDataBase::recording_prepend_time}});
break;
case 262:
HxDataBase::recording_prepend_time = msginfo.value("recording_prepend_time").toInt();
debug_tool_response_event(type, {{"status", HxDataBase::save_setting()}});
break;
case 0xFFFF:
adas_video_device.test();
dsm_video_device.test();
break;
}
}