2024-03-04 16:22:40 +08:00
|
|
|
|
#include "Channel.h"
|
|
|
|
|
#include "CheckStorageThread.h"
|
|
|
|
|
#include "Constant.h"
|
2024-08-12 11:26:42 +08:00
|
|
|
|
#include "DatabaseManager.h"
|
2024-03-04 16:22:40 +08:00
|
|
|
|
#include "Json.h"
|
2024-01-18 15:41:43 +08:00
|
|
|
|
#include "Link.h"
|
2024-03-04 16:22:40 +08:00
|
|
|
|
#include "Log.h"
|
2024-05-07 15:06:36 +08:00
|
|
|
|
#include "SerialPortTool.h"
|
2024-01-18 15:41:43 +08:00
|
|
|
|
#include "TcpServer.h"
|
2024-05-07 15:06:36 +08:00
|
|
|
|
#include "Tool.h"
|
2024-01-18 15:41:43 +08:00
|
|
|
|
#include "Widget.h"
|
|
|
|
|
#include <QApplication>
|
2024-08-12 11:26:42 +08:00
|
|
|
|
#include <cstring>
|
2024-05-11 15:40:07 +08:00
|
|
|
|
#include <stdlib.h>
|
2024-01-18 15:41:43 +08:00
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
2024-05-07 15:06:36 +08:00
|
|
|
|
// Tcp服务器
|
2024-12-24 03:51:48 +08:00
|
|
|
|
TcpServer* server;
|
2024-05-07 15:06:36 +08:00
|
|
|
|
// 串口工具
|
|
|
|
|
SerialPortTool* serialPortTool;
|
2024-08-12 11:26:42 +08:00
|
|
|
|
// 数据库管理
|
|
|
|
|
DatabaseManager* db;
|
2024-12-24 03:51:48 +08:00
|
|
|
|
// 硬盘检测线程
|
2024-08-22 15:29:39 +08:00
|
|
|
|
CheckStorageThread* thread;
|
2024-01-25 09:57:08 +08:00
|
|
|
|
|
2024-03-04 16:22:40 +08:00
|
|
|
|
// 通道列表
|
|
|
|
|
QList<Channel*> channelList;
|
|
|
|
|
// 录制模式
|
|
|
|
|
Constant::RecordMode recordMode;
|
|
|
|
|
// 回放模式
|
|
|
|
|
Constant::PlaybackMode playbackMode;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 加载配置文件
|
|
|
|
|
*/
|
|
|
|
|
bool loadConfiguration(QString path)
|
|
|
|
|
{
|
|
|
|
|
QFileInfo fileInfo(path);
|
|
|
|
|
if (!fileInfo.exists()) {
|
|
|
|
|
Log::critical("config.json does not exist, exit");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariantMap config = Json::loadFile(path).toMap();
|
|
|
|
|
recordMode = Constant::RecordMode(config["recordMode"].toInt());
|
|
|
|
|
playbackMode = Constant::PlaybackMode(config["playbackMode"].toInt());
|
|
|
|
|
QVariantList list = config["interface"].toList();
|
2024-05-11 15:40:07 +08:00
|
|
|
|
// 初始化通道
|
2024-03-04 16:22:40 +08:00
|
|
|
|
for (int i = 0; i < list.count(); i++) {
|
|
|
|
|
QVariantMap cfg = list.at(i).toMap();
|
2024-12-24 03:51:48 +08:00
|
|
|
|
QString channelName = cfg["name"].toString();
|
|
|
|
|
if (channelName.isEmpty()) {
|
|
|
|
|
return false;
|
2024-08-12 11:26:42 +08:00
|
|
|
|
}
|
2024-12-24 03:51:48 +08:00
|
|
|
|
QVariantMap output = cfg["output"].toMap();
|
|
|
|
|
Channel* chn = new Channel(channelName, output);
|
2024-03-04 16:22:40 +08:00
|
|
|
|
|
|
|
|
|
QVariantMap encV = cfg["encV"].toMap();
|
|
|
|
|
chn->videoEncoderParams = encV;
|
|
|
|
|
|
|
|
|
|
QVariantMap encA = cfg["encA"].toMap();
|
|
|
|
|
chn->audioEncoderParams = encA;
|
|
|
|
|
|
|
|
|
|
chn->pushCode = cfg["pushCode"].toString();
|
|
|
|
|
|
|
|
|
|
channelList.push_back(chn);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 开始录制
|
|
|
|
|
*/
|
|
|
|
|
void startRecord()
|
|
|
|
|
{
|
2024-05-07 15:06:36 +08:00
|
|
|
|
// 判断是否挂载了磁盘
|
|
|
|
|
QString info = Tool::writeCom(QString("df %1").arg(Constant::MountedPath));
|
|
|
|
|
if (!info.contains(Constant::MountedPath)) {
|
|
|
|
|
Log::error("there is no disk mounted");
|
2024-05-11 15:40:07 +08:00
|
|
|
|
serialPortTool->onLoopOn();
|
|
|
|
|
QThread::msleep(100);
|
2024-05-07 15:06:36 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
2024-08-22 15:29:39 +08:00
|
|
|
|
|
2024-05-11 15:40:07 +08:00
|
|
|
|
// 一路录制,只录制主通道
|
2024-03-04 16:22:40 +08:00
|
|
|
|
if (recordMode == Constant::OneChannelRecord) {
|
|
|
|
|
for (Channel* chn : channelList) {
|
|
|
|
|
if (chn->channelName == Constant::MainChannel) {
|
|
|
|
|
chn->startRecord();
|
2024-05-07 15:06:36 +08:00
|
|
|
|
serialPortTool->onRecordStart();
|
2024-05-11 15:40:07 +08:00
|
|
|
|
QThread::msleep(100);
|
2024-03-04 16:22:40 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 两路录制
|
|
|
|
|
else if (recordMode == Constant::TwoChannelRecord) {
|
|
|
|
|
for (Channel* chn : channelList) {
|
|
|
|
|
chn->startRecord();
|
2024-05-07 15:06:36 +08:00
|
|
|
|
serialPortTool->onRecordStart();
|
2024-05-11 15:40:07 +08:00
|
|
|
|
QThread::msleep(100);
|
2024-03-04 16:22:40 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-08-12 11:26:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-01-18 15:41:43 +08:00
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
|
{
|
2024-12-24 03:51:48 +08:00
|
|
|
|
// qDebug() << (R"(
|
|
|
|
|
// ____ _ _____
|
|
|
|
|
// / ___|| |__ __ _ _ __ | ___|__ _ __ __ _
|
|
|
|
|
// \___ \| '_ \ / _` | '_ \| |_ / _ \ '_ \ / _` |
|
|
|
|
|
// ___) | | | | (_| | | | | _| __/ | | | (_| |
|
|
|
|
|
// |____/|_| |_|\__,_|_| |_|_| \___|_| |_|\__, |
|
|
|
|
|
// |___/ )");
|
2024-05-11 15:40:07 +08:00
|
|
|
|
// std::atexit(resetLight);
|
2024-03-04 16:22:40 +08:00
|
|
|
|
// 初始化日志
|
|
|
|
|
Log::init();
|
|
|
|
|
|
|
|
|
|
// 初始化Link编码系统
|
2024-01-18 15:41:43 +08:00
|
|
|
|
if (!Link::init()) {
|
2024-03-04 16:22:40 +08:00
|
|
|
|
Log::error("Link init failed, exit");
|
2024-01-18 15:41:43 +08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
2024-03-04 16:22:40 +08:00
|
|
|
|
// 初始化配置文件, 需要在QApplication之后
|
|
|
|
|
if (!loadConfiguration(Constant::ConfigurationPath)) {
|
|
|
|
|
Log::error("load configuration failed, exit...");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2024-01-18 15:41:43 +08:00
|
|
|
|
|
2024-12-24 03:51:48 +08:00
|
|
|
|
QApplication a(argc, argv);
|
|
|
|
|
|
|
|
|
|
// 初始化通道配置,需要在QApplication之后进行
|
|
|
|
|
for (const auto& chn : channelList) {
|
|
|
|
|
chn->init();
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-11 15:40:07 +08:00
|
|
|
|
// 打开串口
|
2024-05-07 15:06:36 +08:00
|
|
|
|
serialPortTool = new SerialPortTool();
|
|
|
|
|
serialPortTool->open();
|
2024-03-04 16:22:40 +08:00
|
|
|
|
|
|
|
|
|
// 开启Tcp服务
|
2024-12-24 03:51:48 +08:00
|
|
|
|
// server = new TcpServer();
|
|
|
|
|
// server->listen();
|
2024-01-18 15:41:43 +08:00
|
|
|
|
|
2024-05-11 15:40:07 +08:00
|
|
|
|
// qt界面
|
|
|
|
|
Widget w;
|
|
|
|
|
w.show();
|
|
|
|
|
|
2024-03-04 16:22:40 +08:00
|
|
|
|
// 硬盘检测线程,检测硬盘容量
|
2024-08-22 15:29:39 +08:00
|
|
|
|
thread = new CheckStorageThread();
|
2024-03-05 13:47:32 +08:00
|
|
|
|
thread->start();
|
2024-12-24 03:51:48 +08:00
|
|
|
|
QObject::connect(thread, SIGNAL(diskWillFull()), serialPortTool, SLOT(onDiskWillFull()), Qt::QueuedConnection);
|
|
|
|
|
QObject::connect(thread, SIGNAL(diskNotFull()), serialPortTool, SLOT(onDiskNotFull()), Qt::QueuedConnection);
|
2024-03-05 13:47:32 +08:00
|
|
|
|
Log::info("start storage check thread...");
|
2024-01-18 15:41:43 +08:00
|
|
|
|
|
2024-05-11 15:40:07 +08:00
|
|
|
|
// 开始录制
|
|
|
|
|
startRecord();
|
2024-01-18 15:41:43 +08:00
|
|
|
|
return a.exec();
|
|
|
|
|
}
|