mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-27 18:59:26 +08:00
修改网关参数设置接口
This commit is contained in:
@@ -15,6 +15,9 @@
|
||||
Station::Station() : stationId(0)
|
||||
{
|
||||
mqttCli = std::make_shared<MqttClient>();
|
||||
predictStorageIn = vector<int>(144, 0);
|
||||
predictStorageOut = vector<int>(144, 0);
|
||||
predictCharge = vector<int>(144, 0);
|
||||
}
|
||||
|
||||
void Station::setFields(Fields& fields)
|
||||
@@ -168,12 +171,9 @@ int64_t Station::getPollingTS()
|
||||
|
||||
void Station::setGarewayWorkMode()
|
||||
{
|
||||
if (!mqttCli)
|
||||
{
|
||||
return;
|
||||
}
|
||||
auto policy = Application::data().getPolicyByType(this->workMode);
|
||||
if (!mqttCli) { return; }
|
||||
|
||||
auto policy = Application::data().getPolicyByType(this->workMode);
|
||||
njson json;
|
||||
json["ts"] = Utils::time();
|
||||
json["no"] = 1; // 设备编号
|
||||
@@ -193,15 +193,25 @@ void Station::setGarewayWorkMode()
|
||||
}
|
||||
}
|
||||
|
||||
std::string text = json.dump();
|
||||
spdlog::info("[station] set gateway workmode [Gateway_YT], stationId={}, text={}", stationId, text);
|
||||
mqttCli->publish("Gateway_YT", text);
|
||||
}
|
||||
|
||||
void Station::setGarewayParams()
|
||||
{
|
||||
if (!mqttCli) { return; }
|
||||
njson json;
|
||||
json["ts"] = Utils::time();
|
||||
json["no"] = 1; // 设备编号
|
||||
json["40038"] = {gatewayParam.socMin, gatewayParam.socMax, gatewayParam.capacity, gatewayParam.powerSafe, gatewayParam.powerDischarge, gatewayParam.powerCharge};
|
||||
json["40058"] = {gatewayParam.backflow, gatewayParam.overload};
|
||||
|
||||
std::string text = json.dump();
|
||||
spdlog::info(text);
|
||||
spdlog::info("[station] set gateway params, stationId={}, text={}", stationId, text);
|
||||
mqttCli->publish("Gateway_YT", text);
|
||||
}
|
||||
|
||||
|
||||
string Station::getGatewayMode()
|
||||
{
|
||||
// 0:手动,1:峰谷套利,2:增网配容,3:应急供电,4:并网保电,5:自定时段
|
||||
@@ -336,7 +346,7 @@ void Station::readRuntimeData(int deviceNo, string addr, int val)
|
||||
{
|
||||
if (addr == "0x000B") { this->voltage = val; } // A相电压 R uint32 1V 0x000B
|
||||
if (addr == "0x0011") { this->current = val; } // A相电流 R int32 1A 0x0011
|
||||
if (addr == "0x0011") { this->power = val; } // 三相总有功 R int32 1kW 0x0023
|
||||
if (addr == "0x0023") { this->power = val; } // 三相总有功 R int32 1kW 0x0023
|
||||
}
|
||||
else if (deviceNo == 2)
|
||||
{
|
||||
@@ -461,14 +471,10 @@ void Station::readGatewayMode(int deviceNo, int mode, string p1, string p2, stri
|
||||
device->online = true;
|
||||
device->ts = Utils::time();
|
||||
}
|
||||
this->gatewayParam.mode = mode;
|
||||
this->gatewayParam.param1 = p1;
|
||||
this->gatewayParam.param2 = p2;
|
||||
this->gatewayParam.param3 = p3;
|
||||
if (mode != this->workMode)
|
||||
{
|
||||
//this->setGarewayWorkMode();
|
||||
}
|
||||
if (mode != -1) { this->gatewayParam.mode = mode; }
|
||||
if (!p1.empty()) { this->gatewayParam.param1 = p1; }
|
||||
if (!p2.empty()) { this->gatewayParam.param2 = p2; }
|
||||
if (!p3.empty()) { this->gatewayParam.param3 = p3; }
|
||||
|
||||
njson json;
|
||||
if (JSON::parse(gatewayParam.param3, json))
|
||||
@@ -695,3 +701,59 @@ void Station::writeStatistic()
|
||||
dao->duplicateUpdate(fields, {"value"});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Station::predict()
|
||||
{
|
||||
int64_t tNow = Utils::time();
|
||||
|
||||
string dt1 = Utils::dateStr(tNow-86400*7);
|
||||
string dt2 = Utils::dateStr(tNow-86400);
|
||||
|
||||
/// 预测实现方案:
|
||||
// 查询前7天的历史数据,根据历史数据计算今日数据,每10分钟一个数据,一天共144个数据点
|
||||
string sql = "SELECT * FROM predict_day pd WHERE pd.station_id='" + std::to_string(stationId)
|
||||
+ "'AND dt>='" + dt1 + "' AND dt<='" + dt2 + "'";
|
||||
vector<Fields> result;
|
||||
DAO::exec(NULL, sql, result);
|
||||
|
||||
// 数据源的条数(1天的数据算作1条)
|
||||
int countStorageIn = 0;
|
||||
int countStorageOut = 0;
|
||||
int countCharge = 0;
|
||||
|
||||
for (int row=0; row<result.size(); ++row)
|
||||
{
|
||||
auto& fields = result[row];
|
||||
|
||||
vector<int>* vdptr = NULL;
|
||||
int datatype = fields.get<int>("datatype"); // 1:储能充电,2:储能放电,3:充电桩充电,4:发电
|
||||
if (datatype == 1)
|
||||
{
|
||||
countStorageIn++;
|
||||
vdptr = &predictStorageIn;
|
||||
}
|
||||
else if (datatype == 2)
|
||||
{
|
||||
countStorageOut++;
|
||||
vdptr = &predictStorageOut;
|
||||
}
|
||||
else if (datatype == 3)
|
||||
{
|
||||
countCharge++;
|
||||
vdptr = &predictCharge;
|
||||
}
|
||||
if (vdptr)
|
||||
{
|
||||
string& strval = fields.value("value");
|
||||
std::vector<int> vec;
|
||||
JSON::parseArray(strval, vec);
|
||||
|
||||
for (int i = 0; i<vdptr->size() && i<vec.size(); ++i)
|
||||
{
|
||||
(*vdptr)[i] += vec[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user