2025-05-19 09:54:33 +08:00
|
|
|
|
#include <Windows.h>
|
2025-07-18 09:08:09 +08:00
|
|
|
|
#include <thread>
|
2025-05-19 09:54:33 +08:00
|
|
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
|
#include <QtWebEngineWidgets/QtWebEngineWidgets>
|
|
|
|
|
|
#include <filesystem>
|
|
|
|
|
|
|
|
|
|
|
|
#include "common/Utils.h"
|
2025-07-18 09:08:09 +08:00
|
|
|
|
#include "common/Snowflake.h"
|
|
|
|
|
|
#include "common/JsonN.h"
|
|
|
|
|
|
|
2025-08-20 19:00:22 +08:00
|
|
|
|
#include "app/Application.h"
|
2025-07-18 09:08:09 +08:00
|
|
|
|
#include "app/Config.h"
|
2025-08-20 19:00:22 +08:00
|
|
|
|
#include "protocol/TcpEntity.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include "widgets/MainWindow.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include "pv/PvApp.h"
|
|
|
|
|
|
#include "pv/PvUser.h"
|
2025-07-18 09:08:09 +08:00
|
|
|
|
|
2025-08-28 18:42:37 +08:00
|
|
|
|
#include "rlsocket.h"
|
2025-09-01 20:08:40 +08:00
|
|
|
|
#include "common/Spdlogger.h"
|
2025-09-04 19:31:04 +08:00
|
|
|
|
#include "database/DaoEntity.h"
|
2025-08-31 14:38:53 +08:00
|
|
|
|
|
2025-09-01 20:08:40 +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
|
|
|
|
|
2025-09-01 20:08:40 +08:00
|
|
|
|
#define wsa rlwsa
|
2025-09-04 19:31:04 +08:00
|
|
|
|
void rlSocketTest()
|
2025-09-01 20:08:40 +08:00
|
|
|
|
{
|
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-08-26 18:36:25 +08:00
|
|
|
|
{
|
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-08-26 18:36:25 +08:00
|
|
|
|
}
|
2025-09-04 19:31:04 +08:00
|
|
|
|
}
|
2025-08-26 18:36:25 +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-01 20:08:40 +08:00
|
|
|
|
|
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-09-01 20:08:40 +08:00
|
|
|
|
|
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)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 设置控制台输出为 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-07-18 09:08:09 +08:00
|
|
|
|
|
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-07-18 09:08:09 +08:00
|
|
|
|
|
|
|
|
|
|
// 运行后台服务
|
2025-05-19 09:54:33 +08:00
|
|
|
|
Application::instance().init();
|
|
|
|
|
|
|
2025-09-04 19:31:04 +08:00
|
|
|
|
{
|
|
|
|
|
|
//REGInfo reg;
|
|
|
|
|
|
//std::string s = "BMS(电池堆)通信状态 R uint16 \"0:正常1:故障\" bit位从低到高分别对应1~16 0x2001";
|
|
|
|
|
|
//int pos;
|
|
|
|
|
|
//if (std::string::npos != (pos = s.find("\t0x")))
|
|
|
|
|
|
//{
|
|
|
|
|
|
// reg.name = s.substr(pos+1);
|
|
|
|
|
|
// s = s.substr(0, pos);
|
|
|
|
|
|
// std::cout << reg.name << std::endl;
|
|
|
|
|
|
//}
|
|
|
|
|
|
//if (std::string::npos != (pos = s.find("\t")))
|
|
|
|
|
|
//{
|
|
|
|
|
|
// reg.remark = s.substr(0, pos);
|
|
|
|
|
|
// s = s.substr(pos+1);
|
|
|
|
|
|
// std::cout << reg.remark << std::endl;
|
|
|
|
|
|
//}
|
|
|
|
|
|
//if (std::string::npos != (pos = s.find("uint")))
|
|
|
|
|
|
//{
|
|
|
|
|
|
// std::string bytename = s.substr(pos, 6);
|
|
|
|
|
|
// std::cout << bytename << std::endl;
|
|
|
|
|
|
// s = s.substr(pos+6);
|
|
|
|
|
|
//}
|
|
|
|
|
|
//std::cout << s << std::endl;
|
|
|
|
|
|
//std::cout << s << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-05-19 09:54:33 +08:00
|
|
|
|
// 运行QT主窗口
|
2025-08-20 19:00:22 +08:00
|
|
|
|
//QApplication qapp(argc, argv);
|
|
|
|
|
|
//MainWindow mainWin;
|
|
|
|
|
|
//mainWin.setWindowTitle("风光储能站控制管理系统");
|
|
|
|
|
|
//mainWin.resize(1920, 1080);
|
|
|
|
|
|
//mainWin.show();
|
|
|
|
|
|
//qapp.exec();
|
|
|
|
|
|
|
2025-08-26 18:36:25 +08:00
|
|
|
|
// 运行pv主流程
|
2025-08-20 19:00:22 +08:00
|
|
|
|
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);
|
|
|
|
|
|
}
|
2025-05-19 09:54:33 +08:00
|
|
|
|
return 0;
|
|
|
|
|
|
}
|