104 lines
3.2 KiB
C++
104 lines
3.2 KiB
C++
|
||
#include <iostream>
|
||
#include <QGuiApplication>
|
||
#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 "IVrUtils.h"
|
||
#include "VrLog.h"
|
||
#include "Version.h"
|
||
#include "VrError.h"
|
||
|
||
int main(int argc, char *argv[])
|
||
{
|
||
QGuiApplication 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 ERR_CODE(DEV_NO_OPEN);
|
||
}
|
||
|
||
// 启动相机
|
||
int cameraResult = presenter.startCamera();
|
||
if (cameraResult != 0) {
|
||
LOG_ERROR("Failed to start camera, error code: %d\n", cameraResult);
|
||
// 继续启动服务器,但记录错误
|
||
}
|
||
|
||
// 设置版本信息文本:版本号 + 编译时间
|
||
QString versionText = QString("%1_%2_%3")
|
||
.arg(BELT_TEARING_SERVER_VERSION_STRING)
|
||
.arg(BELT_TEARING_SERVER_VERSION_BUILD)
|
||
.arg(BUILD_TIME.c_str());
|
||
|
||
// 输出系统信息
|
||
LOG_INFO("=== BeltTearing Server Started %s===\n", versionText.toStdString().c_str());
|
||
LOG_INFO("Server is running on port %d\n", serverPort);
|
||
LOG_INFO("Press Ctrl+C to exit.\n");
|
||
|
||
#if 1
|
||
#ifdef _WIN32
|
||
LOG_INFO("Simulation thread started - sending test data every 5 seconds\n");
|
||
// 处理应用程序退出
|
||
std::thread testThread([&presenter]() {
|
||
QThread::sleep(10); // 等待10秒
|
||
while (true)
|
||
{
|
||
// presenter.sendTestData("C:\\tmp\\8_LazerData_Je08A052.txt");
|
||
presenter.sendSimulationData(); // 启用发送模拟撕裂数据
|
||
QThread::sleep(1); // 等待5秒
|
||
}
|
||
});
|
||
testThread.detach();
|
||
|
||
#endif
|
||
#endif
|
||
|
||
return app.exec();
|
||
}
|