92 lines
2.8 KiB
C++
92 lines
2.8 KiB
C++
|
||
#include <iostream>
|
||
#include <QCoreApplication>
|
||
#include <QDir>
|
||
#include <QFile>
|
||
#include <QTimer>
|
||
#include <QThread>
|
||
#include <QImage>
|
||
#include <QDateTime>
|
||
#include <QJsonObject>
|
||
#include <QJsonArray>
|
||
#include <QJsonDocument>
|
||
#include <QRandomGenerator>
|
||
#include "BeltTearingPresenter.h"
|
||
#include "PathManager.h"
|
||
#include "version.h"
|
||
#include "beltTearingDetection_Export.h"
|
||
|
||
#include "VrLog.h"
|
||
|
||
int main(int argc, char *argv[])
|
||
{
|
||
QCoreApplication app(argc, argv);
|
||
|
||
// 设置应用程序信息
|
||
app.setApplicationName(BELT_TEARING_SERVER_PRODUCT_NAME);
|
||
app.setApplicationVersion(BELT_TEARING_SERVER_VERSION_STRING);
|
||
app.setOrganizationName(BELT_TEARING_SERVER_COMPANY_NAME);
|
||
|
||
VrLogUtils::InitLog();
|
||
VrLogUtils::EnableTime(false);
|
||
|
||
// 打印启动横幅
|
||
LOG_DEBUG("===========================================\n");
|
||
LOG_INFO(" %s\n", BELT_TEARING_SERVER_PRODUCT_NAME);
|
||
LOG_INFO(" %s\n", BELT_TEARING_SERVER_DESCRIPTION);
|
||
LOG_INFO(" %s\n", BELT_TEARING_SERVER_COPYRIGHT);
|
||
LOG_DEBUG("===========================================\n");
|
||
|
||
// 创建并初始化Presenter
|
||
BeltTearingPresenter presenter;
|
||
|
||
// 获取配置文件路径
|
||
QString configFilePath = PathManager::GetConfigFilePath();
|
||
|
||
// 加载配置文件
|
||
if (!presenter.loadConfiguration(configFilePath)) {
|
||
LOG_WARN("Warning: Failed to load configuration file. Using default settings.\n");
|
||
LOG_INFO("Config file location: %s\n", configFilePath.toStdString().c_str());
|
||
}
|
||
|
||
// 启动TCP服务器(使用配置文件中的端口,如果配置加载失败则使用默认端口)
|
||
quint16 serverPort = presenter.getServerPort();
|
||
if (serverPort == 0) {
|
||
serverPort = 5900; // 默认端口
|
||
}
|
||
|
||
if (!presenter.startServer(serverPort)) {
|
||
LOG_ERROR("Failed to start server on port %d\n", serverPort);
|
||
return -1;
|
||
}
|
||
|
||
// 启动相机
|
||
presenter.startCamera();
|
||
|
||
// 输出系统信息
|
||
LOG_INFO("=== BeltTearing Server Started %s===\n", BELT_TEARING_SERVER_VERSION_STRING);
|
||
LOG_DEBUG("===================================\n");
|
||
LOG_INFO("Server is running on port %d\n", serverPort);
|
||
LOG_INFO("Press Ctrl+C to exit.\n");
|
||
|
||
#if 0
|
||
#ifdef _WIN32
|
||
LOG_INFO("Simulation thread started - sending test data every 5 seconds\n");
|
||
// 处理应用程序退出
|
||
std::thread testThread([&presenter]() {
|
||
QThread::msleep(10); // 等待5秒
|
||
while (true)
|
||
{
|
||
// presenter.sendTestData("C:\\tmp\\8_LazerData_Je08A052.txt");
|
||
presenter.sendSimulationData(); // 启用发送模拟撕裂数据
|
||
presenter.sendSimulationImageData();
|
||
}
|
||
});
|
||
testThread.detach();
|
||
|
||
#endif
|
||
#endif
|
||
|
||
return app.exec();
|
||
}
|