程序优化,待测试
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);
|
||||
|
||||
Reference in New Issue
Block a user