Files
energy_storage/src/main.cpp

174 lines
4.9 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 "pv/PvApp.h"
#include "pv/PvUser.h"
2025-08-28 18:42:37 +08:00
#include "rlsocket.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
2025-09-04 19:31:04 +08:00
void rlSocketTest()
{
2025-09-04 19:31:04 +08:00
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)
{
2025-09-04 19:31:04 +08:00
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
}
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
2025-09-04 19:31:04 +08:00
Spdlogger::init(spdlog::level::debug, "");
spdlog::info("[main] start ... ======================================================================");
2025-09-05 19:44:26 +08:00
spdlog::info("");
2025-09-04 19:31:04 +08:00
std::cout << Snowflake::instance().getId() << std::endl;
for (int i = 0; i<=10; ++i) {
std::cout << Snowflake::instance().getId() << std::endl;
}
// 运行后台服务
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;
mainWin.show();
qapp.exec();
2025-09-04 19:31:04 +08:00
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;
}