添加了状态翻转和设备在线函数
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include <unordered_map>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
#include <interface.h>
|
||||
|
||||
// 配置参数
|
||||
constexpr int BASE_RECONNECT_DELAY = 20000; // 基础重连延迟(ms)
|
||||
@@ -832,6 +833,35 @@ void ClientManager::restart_device(const std::string& device_id) {
|
||||
}
|
||||
}
|
||||
|
||||
//设备运行情况判断
|
||||
bool ClientManager::get_dev_status(const std::string& identifier) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
for (auto& pair : clients_) {
|
||||
auto& ctx = pair.second;
|
||||
// 匹配装置ID或MAC地址
|
||||
if (ctx->device_info.device_id == identifier ||
|
||||
ctx->device_info.mac == identifier) {
|
||||
|
||||
if (ctx->cloudstatus == 1) {
|
||||
//设备已登录
|
||||
std::cout << "[Device " << identifier
|
||||
<< "] online!" <<std::endl;
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
//设备状态异常
|
||||
//设备已登录
|
||||
std::cout << "[Device " << identifier
|
||||
<< "] offline!" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//修改客户端云前置登录状态
|
||||
bool ClientManager::set_cloud_status(const std::string& identifier, int status) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
@@ -844,11 +874,13 @@ bool ClientManager::set_cloud_status(const std::string& identifier, int status)
|
||||
|
||||
if (ctx->cloudstatus == 0 && status == 1) {
|
||||
//设备从离线转换至在线,通知前台状态发生翻转
|
||||
connect_status_update(identifier, status);
|
||||
std::cout << "[Device " << identifier
|
||||
<< "] ****Cloud status: " << ctx->cloudstatus << " updated to: " << status << std::endl;
|
||||
}
|
||||
else if (ctx->cloudstatus == 1 && status == 0) {
|
||||
//设备从在线转换至离线,通知前台状态发生翻转
|
||||
connect_status_update(identifier, status);
|
||||
std::cout << "[Device " << identifier
|
||||
<< "] ****Cloud status: " << ctx->cloudstatus << " updated to: " << status << std::endl;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user