2025-08-27 23:10:36 +08:00
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
#include <QCoreApplication>
|
2025-09-10 00:31:27 +08:00
|
|
|
|
#include <QDir>
|
|
|
|
|
|
#include <QFile>
|
2025-09-21 22:20:24 +08:00
|
|
|
|
#include <QTimer>
|
|
|
|
|
|
#include <QThread>
|
|
|
|
|
|
#include <QImage>
|
|
|
|
|
|
#include <QDateTime>
|
|
|
|
|
|
#include <QJsonObject>
|
|
|
|
|
|
#include <QJsonArray>
|
|
|
|
|
|
#include <QJsonDocument>
|
|
|
|
|
|
#include <QRandomGenerator>
|
2025-08-27 23:10:36 +08:00
|
|
|
|
#include "BeltTearingPresenter.h"
|
2025-09-10 00:31:27 +08:00
|
|
|
|
#include "PathManager.h"
|
|
|
|
|
|
#include "version.h"
|
2025-09-21 22:20:24 +08:00
|
|
|
|
#include "beltTearingDetection_Export.h"
|
2025-09-10 00:31:27 +08:00
|
|
|
|
|
2025-11-19 00:23:09 +08:00
|
|
|
|
#include "IVrUtils.h"
|
2025-09-10 00:31:27 +08:00
|
|
|
|
#include "VrLog.h"
|
2025-11-19 00:23:09 +08:00
|
|
|
|
#include "Version.h"
|
2025-11-26 22:44:38 +08:00
|
|
|
|
#include "VrError.h"
|
2025-08-27 23:10:36 +08:00
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
|
|
{
|
|
|
|
|
|
QCoreApplication app(argc, argv);
|
2025-09-21 22:20:24 +08:00
|
|
|
|
|
2025-09-10 00:31:27 +08:00
|
|
|
|
// 设置应用程序信息
|
|
|
|
|
|
app.setApplicationName(BELT_TEARING_SERVER_PRODUCT_NAME);
|
|
|
|
|
|
app.setApplicationVersion(BELT_TEARING_SERVER_VERSION_STRING);
|
|
|
|
|
|
app.setOrganizationName(BELT_TEARING_SERVER_COMPANY_NAME);
|
2025-09-21 22:20:24 +08:00
|
|
|
|
|
2025-09-29 00:56:53 +08:00
|
|
|
|
VrLogUtils::InitLog();
|
|
|
|
|
|
VrLogUtils::EnableTime(false);
|
|
|
|
|
|
|
2025-09-10 00:31:27 +08:00
|
|
|
|
// 打印启动横幅
|
|
|
|
|
|
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");
|
2025-09-21 22:20:24 +08:00
|
|
|
|
|
2025-08-27 23:10:36 +08:00
|
|
|
|
// 创建并初始化Presenter
|
|
|
|
|
|
BeltTearingPresenter presenter;
|
2025-09-21 22:20:24 +08:00
|
|
|
|
|
2025-09-10 00:31:27 +08:00
|
|
|
|
// 获取配置文件路径
|
|
|
|
|
|
QString configFilePath = PathManager::GetConfigFilePath();
|
2025-09-21 22:20:24 +08:00
|
|
|
|
|
2025-09-10 00:31:27 +08:00
|
|
|
|
// 加载配置文件
|
|
|
|
|
|
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());
|
|
|
|
|
|
}
|
2025-09-21 22:20:24 +08:00
|
|
|
|
|
2025-09-10 00:31:27 +08:00
|
|
|
|
// 启动TCP服务器(使用配置文件中的端口,如果配置加载失败则使用默认端口)
|
|
|
|
|
|
quint16 serverPort = presenter.getServerPort();
|
|
|
|
|
|
if (serverPort == 0) {
|
|
|
|
|
|
serverPort = 5900; // 默认端口
|
|
|
|
|
|
}
|
2025-09-21 22:20:24 +08:00
|
|
|
|
|
2025-09-10 00:31:27 +08:00
|
|
|
|
if (!presenter.startServer(serverPort)) {
|
|
|
|
|
|
LOG_ERROR("Failed to start server on port %d\n", serverPort);
|
2025-11-26 22:44:38 +08:00
|
|
|
|
return ERR_CODE(DEV_NO_OPEN);
|
2025-08-27 23:10:36 +08:00
|
|
|
|
}
|
2025-09-21 22:20:24 +08:00
|
|
|
|
|
2025-09-10 00:31:27 +08:00
|
|
|
|
// 启动相机
|
2025-11-26 22:44:38 +08:00
|
|
|
|
int cameraResult = presenter.startCamera();
|
|
|
|
|
|
if (cameraResult != 0) {
|
|
|
|
|
|
LOG_ERROR("Failed to start camera, error code: %d\n", cameraResult);
|
|
|
|
|
|
// 继续启动服务器,但记录错误
|
|
|
|
|
|
}
|
2025-09-21 22:20:24 +08:00
|
|
|
|
|
2025-11-19 00:23:09 +08:00
|
|
|
|
// 设置版本信息文本:版本号 + 编译时间
|
|
|
|
|
|
QString versionText = QString("%1_%2_%3")
|
|
|
|
|
|
.arg(BELT_TEARING_SERVER_VERSION_STRING)
|
|
|
|
|
|
.arg(BELT_TEARING_SERVER_VERSION_BUILD)
|
|
|
|
|
|
.arg(BUILD_TIME.c_str());
|
|
|
|
|
|
|
2025-09-10 00:31:27 +08:00
|
|
|
|
// 输出系统信息
|
2025-11-19 00:23:09 +08:00
|
|
|
|
LOG_INFO("=== BeltTearing Server Started %s===\n", versionText.toStdString().c_str());
|
2025-09-21 22:20:24 +08:00
|
|
|
|
LOG_INFO("Server is running on port %d\n", serverPort);
|
|
|
|
|
|
LOG_INFO("Press Ctrl+C to exit.\n");
|
2025-08-27 23:10:36 +08:00
|
|
|
|
|
2025-11-19 00:23:09 +08:00
|
|
|
|
#if 1
|
2025-09-21 22:20:24 +08:00
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
|
LOG_INFO("Simulation thread started - sending test data every 5 seconds\n");
|
|
|
|
|
|
// 处理应用程序退出
|
|
|
|
|
|
std::thread testThread([&presenter]() {
|
2025-11-19 00:23:09 +08:00
|
|
|
|
QThread::sleep(10); // 等待10秒
|
2025-09-29 00:56:53 +08:00
|
|
|
|
while (true)
|
2025-09-21 22:20:24 +08:00
|
|
|
|
{
|
2025-10-12 16:46:46 +08:00
|
|
|
|
// presenter.sendTestData("C:\\tmp\\8_LazerData_Je08A052.txt");
|
|
|
|
|
|
presenter.sendSimulationData(); // 启用发送模拟撕裂数据
|
2025-11-19 00:23:09 +08:00
|
|
|
|
QThread::sleep(1); // 等待5秒
|
2025-09-21 22:20:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
testThread.detach();
|
2025-10-12 16:46:46 +08:00
|
|
|
|
|
2025-11-10 00:19:20 +08:00
|
|
|
|
#endif
|
2025-09-21 22:20:24 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
|
2025-08-27 23:10:36 +08:00
|
|
|
|
return app.exec();
|
2025-09-21 22:20:24 +08:00
|
|
|
|
}
|