程序优化,待测试
This commit is contained in:
Binary file not shown.
@@ -31,6 +31,7 @@ const int Qos = 1;
|
||||
|
||||
atomic<bool> isRunning(true); // 是否需要激活
|
||||
atomic<bool> Deactivate(false); // 激活标志
|
||||
mutex envMutex; // 配置锁
|
||||
mutex runMutex;
|
||||
condition_variable runCv; // 条件变量,判断是否可以启动验证程序
|
||||
|
||||
@@ -86,8 +87,31 @@ void StartCheck()
|
||||
isRunning = false;
|
||||
runCv.notify_one();
|
||||
|
||||
try
|
||||
{
|
||||
if (client.is_connected())
|
||||
{
|
||||
client.set_message_callback(nullptr); // 移除回调
|
||||
client.disconnect()->wait();
|
||||
}
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
std::cerr << e.what() << '\n';
|
||||
}
|
||||
|
||||
namespace bp = boost::process;
|
||||
string cmd = "../../softWareInit/bin/wifi ";
|
||||
system(cmd.c_str());
|
||||
try
|
||||
{
|
||||
bp::spawn(cmd);
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
std::cerr << e.what() << '\n';
|
||||
string sysCmd = cmd + " &";
|
||||
system(sysCmd.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
// 检测设备是否已经激活
|
||||
@@ -153,6 +177,8 @@ void messageCallback(mqtt::const_message_ptr msg)
|
||||
|
||||
thread([lines]()
|
||||
{
|
||||
lock_guard<mutex> lk(envMutex);
|
||||
|
||||
WriteFile wf(envPath);
|
||||
string out;
|
||||
out.reserve(1024);
|
||||
|
||||
3
Readme
3
Readme
@@ -1,4 +1,4 @@
|
||||
# 程序清单
|
||||
# 程序功能清单
|
||||
|
||||
## DeviceActivate(待测试)
|
||||
功能:
|
||||
@@ -7,7 +7,6 @@
|
||||
进行激活,并保存密文
|
||||
当检测到设备已被激活后,启动验证程序,并退出本程序
|
||||
|
||||
|
||||
## softWareInit(待测试)
|
||||
功能:
|
||||
本程序用于设备验证
|
||||
|
||||
Binary file not shown.
@@ -51,6 +51,7 @@ std::atomic<bool> isRunning(true); // 全局运行标志
|
||||
std::atomic<bool> confirm(true); // 发送卡和ID
|
||||
condition_variable runCv;
|
||||
mutex runMutex;
|
||||
mutex envMutex; // 配置锁
|
||||
|
||||
// 媒体对象
|
||||
struct Media
|
||||
@@ -198,6 +199,7 @@ void getMsgCallback(mqtt::const_message_ptr msg)
|
||||
double warn = toDouble(warning_json);
|
||||
double safe = toDouble(safe_json);
|
||||
|
||||
lock_guard<mutex> lk(envMutex);
|
||||
ReadFile rf(filepath);
|
||||
if (!rf.Open()) {
|
||||
cerr << "文件打开失败: " << filepath << "\n";
|
||||
|
||||
Reference in New Issue
Block a user