Files
energy_storage/src/main.cpp

186 lines
5.1 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-09-04 19:31:04 +08:00
Spdlogger::init(spdlog::level::debug, "");
spdlog::info("[main] start ... ======================================================================");
njson json;
json = {1, 2, 3, 4};
spdlog::info(json.dump());
// 运行后台服务
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;
}