Files
energy_storage/src/main.cpp

229 lines
6.8 KiB
C++
Raw Normal View History

2025-05-19 09:54:33 +08:00
#include <Windows.h>
#include <thread>
2025-05-19 09:54:33 +08:00
#include <QApplication>
#include <QtWebEngineWidgets/QtWebEngineWidgets>
#include <filesystem>
#include "common/Utils.h"
#include "common/Snowflake.h"
#include "common/JsonN.h"
#include "app/Application.h"
#include "app/Config.h"
#include "protocol/TcpEntity.h"
#include "widgets/MainWindow.h"
#include "common/Spdlogger.h"
2025-09-04 19:31:04 +08:00
#include "database/DaoEntity.h"
2025-08-31 14:38:53 +08:00
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
2025-09-04 19:31:04 +08:00
#include <iostream>
#include <fstream>
#include <string>
#include "DataStruct.h"
2025-08-31 14:38:53 +08:00
#include "qt/MainWeb.h"
//#define wsa rlwsa
//void rlSocketTest()
//{
// rlwsa();
// rlSocket socket("127.0.0.1", 19801, 1);
// int ret = socket.connect();
// std::string s1 = "helloworld";
// socket.write(s1.c_str(), s1.size());
//
// std::vector<char> buf(1024, 0);
// while (true)
// {
// int len = socket.read(&buf[0], 1, 0);
// if (len > 0)
// {
// std::cout << "===>>> " << std::string(buf.begin(), buf.end());
// }
// }
//}
2025-09-04 19:31:04 +08:00
void memberJsonTest()
{
std::string fromJson = "fromJson(const std::string& str) {\nNJsonNode jsonroot;\nauto ret = NJson::parse(str, jsonroot);\nif (!ret) { return; }\n";
std::string toJson = "toJson() {\nNJsonNode jsonroot;";
2025-09-04 19:31:04 +08:00
std::ifstream ifs("", std::ios::in);
std::string line;
std::string cpp = "#include \"DataStruct.h\"\n\n";
if (ifs.is_open())
{
std::string s1;
std::string s2;
while (std::getline(ifs, line))
{
int pos = line.find("struct");
if (pos != std::string::npos)
{
std::string className = line.substr(pos+7);
s1 = "void " + className + "::" + fromJson;
s2 = "}\nstd::string " + className + "::" + toJson;
}
else
{
std::string key;
pos = line.find("uint");
if (pos != std::string::npos) { key = line.substr(pos+9); }
if (!key.empty())
{
pos = key.find(";");
if (pos != std::string::npos) { key = key.substr(0, pos); }
}
if (!key.empty())
{
s1 += ("NJson::read(jsonroot, \"" + key + "\", " + key + ");\n");
s2 += ("jsonroot[\"" + key + "\"] = " + key + ";\n");
}
}
}
ifs.close();
}
2025-08-28 18:42:37 +08:00
2025-09-04 19:31:04 +08:00
//std::string strTmp = R"()";
//std::vector<std::string> vecTmp;
//Utils::split(strTmp, "\n", vecTmp);
2025-08-28 18:42:37 +08:00
2025-09-04 19:31:04 +08:00
//std::string from = "void fromJson(const std::string& str) {\nNJsonNode jsonroot;\nauto ret = NJson::parse(str, jsonroot);\nif (!ret) { return; }\n";
//std::string to = "std::string toJson() {\nNJsonNode jsonroot;";
//for (auto& item: vecTmp)
2025-08-28 18:42:37 +08:00
//{
2025-09-04 19:31:04 +08:00
// std::string key;
// int pos = item.find_first_of("_");
// if (pos != std::string::npos) { key = item.substr(pos+3); }
// pos = key.find_first_of(";");
// if (pos != std::string::npos) { key = key.substr(0, pos); }
// if (!key.empty())
2025-08-28 18:42:37 +08:00
// {
2025-09-04 19:31:04 +08:00
// from += ("NJson::read(jsonroot, \"" + key + "\", " + key + ");\n");
// to += ("jsonroot[\"" + key + "\"] = " + key + ";\n");
2025-08-28 18:42:37 +08:00
// }
//}
2025-09-04 19:31:04 +08:00
//from += "}";
//to += "return jsonroot.dump();\n}";
//std::cout << from << std::endl;
//std::cout << to << std::endl;
}
2025-05-19 09:54:33 +08:00
2025-09-04 19:31:04 +08:00
int main(int argc, char** argv)
{
2025-09-04 19:31:04 +08:00
// 设置控制台输出为 UTF-8 编码
SetConsoleOutputCP(CP_UTF8);
// 设置控制台输入为 UTF-8 编码(如果需要输入中文)
SetConsoleCP(CP_UTF8);
2025-05-19 09:54:33 +08:00
float ratio = 1.1f;
int precision = 0;
if (ratio != 1.0f)
{
precision = 2;
};
//qputenv("QTWEBENGINE_REMOTE_DEBUGGING", "9222"); // 即使内置视图,有时也需要开启调试端口
//QApplication app(argc, argv);
//QMainWindow mainWindow;
//// 主窗口和布局
//QWidget myRoot;
//QHBoxLayout* layout = new QHBoxLayout(&myRoot);
//// 创建主 Web 视图
//QWebEngineView* mainWebView = new QWebEngineView;
//mainWebView->load(QUrl("https://www.example.com"));
//// 创建用于显示开发者工具的 Web 视图
//QWebEngineView* devToolsView = new QWebEngineView;
//// 将主 Web 页面的开发者工具页面设置为 devToolsView 的页面
//mainWebView->page()->setDevToolsPage(devToolsView->page());
//// 如果你需要先导航主页面,然后在某个事件(如按钮点击)后显示开发者工具,可以将这行代码放在事件处理函数中。
//// 将两个视图添加到布局中
//layout->addWidget(mainWebView);
//layout->addWidget(devToolsView);
//// 可以适当设置两个视图的大小比例,例如:
//// layout->setStretchFactor(0, 2); // 主视图占2份
//// layout->setStretchFactor(1, 1); // 开发者工具视图占1份
//myRoot.show();
//mainWindow.resize(1600, 900);
//mainWindow.setCentralWidget(&myRoot);
//mainWindow.show();
//// 如果你想在启动时自动打开开发者工具可以触发一个“打开”事件但setDevToolsPage本身调用后通常需要一些条件才弹出有时需要手动在浏览器中inspected后再内置查看
//// 更常见的做法是连接一个信号,例如页面加载完成后,或者通过一个按钮触发 devToolsView->show()。
//return app.exec();
2025-09-04 19:31:04 +08:00
Spdlogger::init(spdlog::level::debug, "");
spdlog::info("[main] start ... ======================================================================");
// 运行后台服务
2025-05-19 09:54:33 +08:00
Application::instance().init();
// 启动 PV 服务主线程
//std::thread([=]()
// {
// // 运行pv主流程
// PARAM p;
// int s;
// pvInit(argc, argv, &p);
// /* here you may interpret ac,av and set p->user to your data */
// while (1)
// {
// s = pvAccept(&p);
// if (s != -1) pvCreateThread(&p, s);
// std::this_thread::sleep_for(std::chrono::milliseconds(10));
// }
// }).detach();
QApplication qapp(argc, argv);
qapp.setWindowIcon(QIcon("./yhicon.ico"));
MainWeb mainWin;
qapp.exec();
2025-09-04 19:31:04 +08:00
//QApplication a(argc, argv);
//QMainWindow w;
//QWebEngineView webView(&w);
//webView.load(QUrl("http://127.0.0.1:19600/"));
//w.setCentralWidget(&webView);
//w.setWindowTitle("Qt 6.7 WebEngine Demo");
//w.resize(1280, 720);
//w.show();
//webView.show();
//a.exec();
2025-05-19 09:54:33 +08:00
// 运行QT主窗口
//QApplication qapp(argc, argv);
//MainWindow mainWin;
//mainWin.setWindowTitle("风光储能站控制管理系统");
//mainWin.resize(1920, 1080);
//mainWin.show();
//qapp.exec();
2025-05-19 09:54:33 +08:00
return 0;
}