mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-27 18:59:26 +08:00
修改运行监控场站及设备信息查询接口
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#include "Device.h"
|
||||
|
||||
#include "common/Logger.h"
|
||||
#include "common/Spdlogger.h"
|
||||
#include "common/Utils.h"
|
||||
#include "protocol/CommEntity.h"
|
||||
#include "common/JsonN.h"
|
||||
@@ -44,26 +44,66 @@ int Device::startComm()
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 从属性列表中获取通讯方式和通讯地址、端口
|
||||
std::string commType = attrs.value("commType");
|
||||
|
||||
// 如果entity的通讯协议类型当前配置不一致,需要关闭连接删除通讯后创建新的通讯
|
||||
if (commEntity && commEntity->type != commType)
|
||||
{
|
||||
commEntity->close();
|
||||
commEntity = nullptr;
|
||||
}
|
||||
// 创建新的通讯
|
||||
if (!commEntity)
|
||||
{
|
||||
commEntity = CommEntity::create(attrs);
|
||||
if (!commEntity) { return -1; }
|
||||
}
|
||||
|
||||
commEntity->start();
|
||||
//// 从属性列表中获取通讯方式和通讯地址、端口
|
||||
//std::string commType = attrs.value("commType");
|
||||
//
|
||||
//// 如果entity的通讯协议类型当前配置不一致,需要关闭连接删除通讯后创建新的通讯
|
||||
//if (commEntity && commEntity->type != commType)
|
||||
//{
|
||||
// commEntity->close();
|
||||
// commEntity = nullptr;
|
||||
//}
|
||||
//// 创建新的通讯
|
||||
//if (!commEntity)
|
||||
//{
|
||||
// commEntity = CommEntity::create(attrs);
|
||||
// if (!commEntity) { return -1; }
|
||||
//}
|
||||
//commEntity->start();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Device::getRuntimeParams(std::vector<std::pair<std::string, std::string>>& params)
|
||||
{
|
||||
params.push_back({"额定电压", "0.0V"});
|
||||
params.push_back({"实时电压", "0.0V"});
|
||||
params.push_back({"额定电流", "0.0A"});
|
||||
params.push_back({"实时电流", "0.0A"});
|
||||
params.push_back({"额定功率", "0.0kW"});
|
||||
params.push_back({"实时功率", "0.0A"});
|
||||
}
|
||||
|
||||
void Device::getCacheVoltage(std::vector<std::string>& vec)
|
||||
{
|
||||
vec.resize(mapCacheVoltage.size());
|
||||
int i = 0;
|
||||
for (auto iter = mapCacheVoltage.begin(); iter != mapCacheVoltage.end(); ++iter)
|
||||
{
|
||||
vec[i] = Utils::toStr(iter->second);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
void Device::getCacheCurrent(std::vector<std::string>& vec)
|
||||
{
|
||||
vec.resize(mapCacheCurrent.size());
|
||||
int i = 0;
|
||||
for (auto iter = mapCacheCurrent.begin(); iter != mapCacheCurrent.end(); ++iter)
|
||||
{
|
||||
vec[i] = Utils::toStr(iter->second);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
void Device::getCachePower(std::vector<std::string>& vec)
|
||||
{
|
||||
vec.resize(mapCachePower.size());
|
||||
int i = 0;
|
||||
for (auto iter = mapCachePower.begin(); iter != mapCachePower.end(); ++iter)
|
||||
{
|
||||
vec[i] = Utils::toStr(iter->second);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<Device> Device::create(Fields& fields)
|
||||
{
|
||||
auto device = std::make_shared<Device>();
|
||||
@@ -73,13 +113,14 @@ std::shared_ptr<Device> Device::create(Fields& fields)
|
||||
device->code = fields.value("code");
|
||||
device->isOpen = fields.get<int>("is_open");
|
||||
device->attrsJson = fields.value("attrs");
|
||||
device->category = fields.get<int>("category");
|
||||
|
||||
// 解析属性的JSON字符串,转换成键值对
|
||||
NJsonNode jsonroot;
|
||||
bool ret = NJson::parse(device->attrsJson, jsonroot);
|
||||
njson jsonroot;
|
||||
bool ret = JSON::parse(device->attrsJson, jsonroot);
|
||||
if (!ret) // 解析错误
|
||||
{
|
||||
XLOGE() << "device attr json parse error, device_id=" << device->deviceId;
|
||||
spdlog::error("[device] device attr json parse error, device_id={}", device->deviceId);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -92,30 +133,23 @@ std::shared_ptr<Device> Device::create(Fields& fields)
|
||||
device->attrs.set(key, val.get<int>());
|
||||
}
|
||||
else {
|
||||
XLOGE() << key << ": [" << valType << "]";
|
||||
spdlog::error("[device] device attr unknown type: key={}, valtype={}", key, valType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int step = 600;
|
||||
for (int i = 0; i*600<86400; ++i)
|
||||
{
|
||||
double voltage = double(Utils::random(20000, 30000))*0.01;
|
||||
double current = double(Utils::random(1000, 2000))*0.01;
|
||||
device->mapCacheVoltage[i*step] = voltage;
|
||||
device->mapCacheCurrent[i*step] = current;
|
||||
device->mapCachePower[i*step] = voltage * current;
|
||||
}
|
||||
|
||||
// 启动通讯,该函数中会自动判断isOpen状态,选择是否进行通讯连接
|
||||
device->startComm();
|
||||
//device->startComm();
|
||||
return device;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
//std::vector<std::shared_ptr<DeviceEntity>> Device::getDeviceByType(int type)
|
||||
//{
|
||||
// std::vector<std::shared_ptr<DeviceEntity>> vecDevice;
|
||||
// for (auto iter = mapDevices.begin(); iter!=mapDevices.end(); ++iter)
|
||||
// {
|
||||
// auto device = iter->second;
|
||||
// if (device && (type<=0 || device->type == type))
|
||||
// {
|
||||
// vecDevice.push_back(device);
|
||||
// }
|
||||
// }
|
||||
// return vecDevice;
|
||||
//}
|
||||
Reference in New Issue
Block a user