mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-27 18:59:26 +08:00
修改HTTP接口测试问题
This commit is contained in:
@@ -16,53 +16,45 @@ static bool CheckCacheType(int type)
|
||||
std::shared_ptr<Device> Device::create(Fields& fields)
|
||||
{
|
||||
auto device = std::make_shared<Device>();
|
||||
device->deviceId = fields.get<int>("device_id");
|
||||
device->type = fields.get<int>("type");
|
||||
device->name = fields.value("name");
|
||||
device->code = fields.value("code");
|
||||
device->isOpen = fields.get<int>("is_open");
|
||||
device->attrsJson = fields.value("attrs");
|
||||
device->category = fields.get<int>("category");
|
||||
device->setFields(fields);
|
||||
return device;
|
||||
}
|
||||
|
||||
void Device::setFields(Fields& fields)
|
||||
{
|
||||
fields.get("device_id", this->deviceId);
|
||||
fields.get("type", this->type);
|
||||
fields.get("name", this->name);
|
||||
fields.get("code", this->code);
|
||||
fields.get("is_open", this->isOpen);
|
||||
fields.get("attrs", this->attrsJson);
|
||||
fields.get("category", this->category);
|
||||
|
||||
// 解析属性的JSON字符串,转换成键值对
|
||||
njson jsonroot;
|
||||
bool ret = JSON::parse(device->attrsJson, jsonroot);
|
||||
bool ret = JSON::parse(this->attrsJson, jsonroot);
|
||||
if (!ret) // 解析错误
|
||||
{
|
||||
spdlog::error("[device] device attr json parse error, device_id={}", device->deviceId);
|
||||
spdlog::error("[device] device attr json parse error, device_id={}", this->deviceId);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->attrs.clear();
|
||||
for (auto& [key, val] : jsonroot.items()) {
|
||||
std::string valType = val.type_name();
|
||||
if (valType == "string") {
|
||||
device->attrs.set(key, val.get<std::string>());
|
||||
this->attrs.set(key, val.get<std::string>());
|
||||
}
|
||||
else if (valType == "number") {
|
||||
device->attrs.set(key, val.get<int>());
|
||||
this->attrs.set(key, val.get<int>());
|
||||
}
|
||||
else {
|
||||
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();
|
||||
return device;
|
||||
}
|
||||
|
||||
|
||||
int Device::startComm()
|
||||
{
|
||||
if (!isOpen)
|
||||
|
||||
Reference in New Issue
Block a user