修改网关参数设置接口

This commit is contained in:
lixiaoyuan
2025-10-11 19:30:15 +08:00
parent b12aca76c4
commit 567966d4f1
12 changed files with 408 additions and 956 deletions

View File

@@ -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];
}
}
}
}