diff --git a/DeviceActivate/bin/init b/DeviceActivate/bin/init index 0f7b58c..eb5a412 100755 Binary files a/DeviceActivate/bin/init and b/DeviceActivate/bin/init differ diff --git a/DeviceActivate/src/main.cpp b/DeviceActivate/src/main.cpp index 65fd828..43783ec 100644 --- a/DeviceActivate/src/main.cpp +++ b/DeviceActivate/src/main.cpp @@ -31,6 +31,7 @@ const int Qos = 1; atomic isRunning(true); // 是否需要激活 atomic 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 lk(envMutex); + WriteFile wf(envPath); string out; out.reserve(1024); diff --git a/Readme b/Readme index ec7fc67..fc55879 100644 --- a/Readme +++ b/Readme @@ -1,4 +1,4 @@ -# 程序清单 +# 程序功能清单 ## DeviceActivate(待测试) 功能: @@ -7,7 +7,6 @@ 进行激活,并保存密文 当检测到设备已被激活后,启动验证程序,并退出本程序 - ## softWareInit(待测试) 功能: 本程序用于设备验证 diff --git a/softWareInit/bin/wifi b/softWareInit/bin/wifi index 0a6e6be..3e4d69c 100755 Binary files a/softWareInit/bin/wifi and b/softWareInit/bin/wifi differ diff --git a/softWareInit/src/main.cpp b/softWareInit/src/main.cpp index 57be964..d77f4ee 100644 --- a/softWareInit/src/main.cpp +++ b/softWareInit/src/main.cpp @@ -51,6 +51,7 @@ std::atomic isRunning(true); // 全局运行标志 std::atomic 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 lk(envMutex); ReadFile rf(filepath); if (!rf.Open()) { cerr << "文件打开失败: " << filepath << "\n";