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:
@@ -127,8 +127,7 @@ void AppData::initFromDB()
|
||||
auto station = this->getStation(stationId);
|
||||
if (station)
|
||||
{
|
||||
auto device = Device::create(fields);
|
||||
station->addDevice(deviceId, device);
|
||||
station->addDevice(fields);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -248,7 +247,6 @@ void AppData::init()
|
||||
for (auto& item : mapStation)
|
||||
{
|
||||
auto& station = item.second;
|
||||
|
||||
if (station->status == 1)
|
||||
{
|
||||
// "tcp://localhost:1883"
|
||||
@@ -256,7 +254,6 @@ void AppData::init()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this->launchDate = Config::option.lunchDate;
|
||||
}
|
||||
|
||||
|
||||
@@ -102,6 +102,17 @@ void Application::runThreadMain()
|
||||
// }
|
||||
//}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// 召测
|
||||
static TimeTick tt1;
|
||||
if (tt1.elapse(10))
|
||||
{
|
||||
for (auto& item: appdata.mapStation)
|
||||
{
|
||||
auto& station = item.second;
|
||||
station->polling();
|
||||
}
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
}
|
||||
}
|
||||
@@ -131,6 +142,16 @@ void Application::runThreadStat()
|
||||
{
|
||||
//spdlog::info("保存历史数据倒计时: {}", 600 - offset);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
for (auto& station : appdata.mapStation)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -16,6 +16,8 @@ class Device
|
||||
public:
|
||||
static std::shared_ptr<Device> create(Fields& fields);
|
||||
|
||||
void setFields(Fields& fields);
|
||||
|
||||
int startComm();
|
||||
|
||||
void getCacheVoltage(std::vector<std::string>& vec);
|
||||
|
||||
@@ -35,7 +35,7 @@ void Station::setFields(Fields& fields)
|
||||
{
|
||||
this->stationId = fields.get<int>(DMStation::STATION_ID);
|
||||
this->name = fields.value(DMStation::NAME);
|
||||
this->energyCapacity = fields.get<double>(DMStation::CAPACITY);
|
||||
this->capacity = fields.get<double>(DMStation::CAPACITY);
|
||||
this->workModeId = fields.get<int>(DMStation::WORK_MODE);
|
||||
this->code = fields.value(DMStation::CODE);
|
||||
this->status = fields.get<int>(DMStation::STATUS);
|
||||
@@ -47,6 +47,22 @@ void Station::addDevice(int deviceId, std::shared_ptr<Device> device)
|
||||
mapDeviceGroup[device->category].push_back(device);
|
||||
}
|
||||
|
||||
void Station::addDevice(Fields& fields)
|
||||
{
|
||||
int deviceId = fields.get<int>(DMDevice::DEVICE_ID);
|
||||
int stationId = fields.get<int>(DMDevice::STATION_ID);
|
||||
if (mapDevice.find(deviceId) != mapDevice.end())
|
||||
{
|
||||
mapDevice[deviceId]->setFields(fields);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto device = Device::create(fields);
|
||||
mapDevice[deviceId] = device;
|
||||
mapDeviceGroup[device->category].push_back(device);
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<Device> Station::getDevice(int deviceId)
|
||||
{
|
||||
auto iter = mapDevice.find(deviceId);
|
||||
@@ -82,8 +98,13 @@ void Station::getDeviceByType(int deviceType, std::vector<std::shared_ptr<Device
|
||||
}
|
||||
}
|
||||
|
||||
int Station::getDeviceNumByGroup(int category)
|
||||
int Station::getDeviceCount(int category)
|
||||
{
|
||||
auto iter = mapDeviceGroup.find(category);
|
||||
if (iter != mapDeviceGroup.end())
|
||||
{
|
||||
return iter->second.size();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -159,3 +180,12 @@ void Station::writeRuntimeData(std::string dt, int npos)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Station::polling()
|
||||
{
|
||||
if (mqttCli)
|
||||
{
|
||||
mqttCli->polling();
|
||||
}
|
||||
}
|
||||
@@ -95,11 +95,12 @@ public:
|
||||
void setFields(Fields& fields);
|
||||
|
||||
void addDevice(int deviceId, std::shared_ptr<Device> device);
|
||||
void addDevice(Fields& fields);
|
||||
std::shared_ptr<Device> getDevice(int deviceId);
|
||||
|
||||
std::shared_ptr<Device> getDeviceByType(int deviceType, std::string code);
|
||||
void getDeviceByType(int typeId, std::vector<std::shared_ptr<Device>>& res);
|
||||
int getDeviceNumByGroup(int category);
|
||||
int getDeviceCount(int category);
|
||||
void getDeviceByGroup(int category, std::vector<std::shared_ptr<Device>>& res);
|
||||
|
||||
void setWorkMode(int modeId);
|
||||
@@ -108,6 +109,7 @@ public:
|
||||
|
||||
void writeRuntimeData(std::string dt, int npos);
|
||||
|
||||
void polling();
|
||||
|
||||
public:
|
||||
int stationId {};
|
||||
@@ -119,24 +121,22 @@ public:
|
||||
int workModeId {}; // 运行模式
|
||||
int runPolicyId {}; // 运行策略
|
||||
|
||||
// 储能容量
|
||||
double energyCapacity {};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// === 系统统计 ===
|
||||
// 累计发电量,单位:kWh
|
||||
double electGenTatal {};
|
||||
double electGenTotal {};
|
||||
// 累计入网电量,单位:kWh
|
||||
double electGridTotal {};
|
||||
// 累计收益,单位:元
|
||||
double incomeTotal {};
|
||||
// 碳减排量, 单位:吨
|
||||
double ccers {};
|
||||
// 累计储能充电电量
|
||||
double electStorageIn {};
|
||||
// 累计储能放电电量
|
||||
double electStorageOut {};
|
||||
|
||||
// 储能容量
|
||||
double capacity {};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// === 日统计 ===
|
||||
double storageIn {}; // 储能充电电量
|
||||
|
||||
Reference in New Issue
Block a user