一些优化,待测试,Readme编写

This commit is contained in:
2025-11-20 16:24:15 +08:00
parent 0854bcd5ae
commit 914e208513
8 changed files with 85 additions and 18 deletions

Binary file not shown.

View File

@@ -8,6 +8,8 @@
#include <iostream>
#include <mqtt/async_client.h> //和App进行MQTT数据交互
#include <boost/process.hpp>
#include <mutex>
#include <condition_variable>
#include <nlohmann/json.hpp> //用于操作JSON文件
@@ -27,8 +29,10 @@ const string TopicRecv = "/bsd_camera/cmd"; // 接收手机传来的信息
const string TopicSend = "/bsd_camera/init"; // 发送的话题
const int Qos = 1;
atomic<bool> isRunning(true);
atomic<bool> isRunning(true); // 是否需要激活
atomic<bool> Deactivate(false); // 激活标志
mutex runMutex;
condition_variable runCv; // 条件变量,判断是否可以启动验证程序
mqtt::async_client client(mqtt_url, clientId);
@@ -65,17 +69,23 @@ int main()
// 初始化MQTT
mqttInit();
while (isRunning)
{
this_thread::sleep_for(1s); // 防止系统占用过高
}
unique_lock<mutex> lk(runMutex);
runCv.wait(lk, []()
{ return !isRunning.load(); });
// while (isRunning)
// {
// this_thread::sleep_for(1s); // 防止系统占用过高
// }
return 0;
}
// 退出程序,开始进行设备验证
void StartCheck()
{
isRunning = false; // 退出程序
// 退出程序
isRunning = false;
runCv.notify_one();
string cmd = "../../softWareInit/bin/wifi ";
system(cmd.c_str());
}
@@ -160,6 +170,7 @@ void messageCallback(mqtt::const_message_ptr msg)
if (Deactivate)
{ // 已激活
// 启动验证程序
StartCheck();
}
}