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,8 +15,8 @@ enum class EDeviceType
|
||||
NUL = 0,
|
||||
//1 变压器 0
|
||||
//2 配电柜 0
|
||||
E_METER = 3, //3 电表 1
|
||||
//4 门禁 0
|
||||
E_METER = 3, //3 电表 1
|
||||
E_METER_TD = 4, //4 电表(台区)
|
||||
//5 空调 0
|
||||
//6 照明 0
|
||||
//7 消防 0
|
||||
|
||||
@@ -307,8 +307,11 @@ static map<int, map<string, string>> g_mapAddrValStr =
|
||||
|
||||
void Device::getRuntimeParams(std::vector<std::pair<std::string, std::string>>& params)
|
||||
{
|
||||
if (type == int(EDeviceType::E_METER_TD))
|
||||
{
|
||||
}
|
||||
auto& vecAddr = REGAddr::s_mapDeviceAddrParam[this->type];
|
||||
for (auto& item: vecAddr)
|
||||
for (auto& item : vecAddr)
|
||||
{
|
||||
std::string v = getParam(item.addr, item.defaultVal);
|
||||
auto& mapValStr = REGAddr::g_mapRegAddrValStr[type][item.addr];
|
||||
@@ -317,7 +320,7 @@ void Device::getRuntimeParams(std::vector<std::pair<std::string, std::string>>&
|
||||
{
|
||||
v = iter->second;
|
||||
}
|
||||
params.push_back({item.name, v + item.unit});
|
||||
params.push_back({ item.name, v + item.unit });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -121,6 +121,17 @@ static void PeriodsTimeStrToInt(std::string str, int& h, int& m)
|
||||
}
|
||||
}
|
||||
|
||||
// 0: 无,1:尖;2:峰;3:平;4:谷;5:深谷
|
||||
static void PeriodsStrToInt(std::string str, int& v)
|
||||
{
|
||||
if (str == "无") v = 0;
|
||||
else if (str == "尖") v = 1;
|
||||
else if (str == "峰") v = 2;
|
||||
else if (str == "平") v = 3;
|
||||
else if (str == "谷") v = 4;
|
||||
else if (str == "深谷") v = 5;
|
||||
}
|
||||
|
||||
void SysPolicy::getGatewayJsonPeriods(njson& json)
|
||||
{
|
||||
if (type == 1)
|
||||
@@ -133,10 +144,7 @@ void SysPolicy::getGatewayJsonPeriods(njson& json)
|
||||
int h = 0; int m = 0;
|
||||
PeriodsTimeStrToInt(item.first, h, m);
|
||||
int p = 1;
|
||||
if (item.second == "谷") p = 1;
|
||||
else if (item.second == "平") p = 2;
|
||||
else if (item.second == "峰") p = 3;
|
||||
else if (item.second == "尖") p = 4;
|
||||
PeriodsStrToInt(item.second, p);
|
||||
jsonArrayMonth.push_back({h, m, p});
|
||||
}
|
||||
json.push_back(jsonArrayMonth);
|
||||
@@ -152,11 +160,7 @@ void SysPolicy::getGatewayJsonPeriods(njson& json)
|
||||
int h = 0; int m = 0;
|
||||
PeriodsTimeStrToInt(item.first, h, m);
|
||||
int p = 0;
|
||||
if (item.second == "谷") p = 1;
|
||||
else if (item.second == "平") p = 2;
|
||||
else if (item.second == "峰") p = 3;
|
||||
else if (item.second == "尖") p = 4;
|
||||
else p = 0;
|
||||
PeriodsStrToInt(item.second, p);
|
||||
char str[5] = {};
|
||||
sprintf(str, "%02d:%02d", h, m);
|
||||
mapT[str] = {h, m, p};
|
||||
|
||||
@@ -248,10 +248,11 @@ static map<int, string> mapPeriodOper =
|
||||
string Station::getGatewayParam()
|
||||
{
|
||||
stringstream ss;
|
||||
std::string str1 = std::format("运行模式:{}<br>储能EMY状态:{}<br>充电桩状态:{}<br><br>",
|
||||
std::string str1 = std::format("运行模式:{}<br>储能EMU状态:{}<br>充电桩状态:{}<br>台区电表状态:{}<br><br>",
|
||||
getGatewayMode(),
|
||||
this->emuStatus == 1 ? "在线" : (this->emuStatus == 0 ? "离线" : "--"),
|
||||
this->cdzStatus == 1 ? "在线" : (this->cdzStatus == 0 ? "离线" : "--"));
|
||||
this->cdzStatus == 1 ? "在线" : (this->cdzStatus == 0 ? "离线" : "--"),
|
||||
this->tamStatus == 1 ? "在线" : (this->tamStatus == 0 ? "离线" : "--"));
|
||||
str1 += "峰谷套利时段:<br>";
|
||||
{
|
||||
njson json;
|
||||
@@ -354,6 +355,7 @@ void Station::readAlert(std::shared_ptr<Device> device, std::string addr, int v,
|
||||
fields.set("log_id", Snowflake::instance().getIdStr());
|
||||
if (device) { fields.set("device_id", device->deviceId); }
|
||||
fields.set("type", int(EAlertType::DEVICE));
|
||||
fields.set("errcode", addr);
|
||||
fields.set("content", text + ":故障(" + std::to_string(v) + ")");
|
||||
fields.set("status", 0);
|
||||
auto dao = DaoEntity::create("log_alert");
|
||||
@@ -542,7 +544,7 @@ void Station::readGatewayMode(int deviceNo, int mode, string p1, string p2, stri
|
||||
}
|
||||
}
|
||||
|
||||
void Station::readGatewayStatus(int deviceNo, int cdzStatus, int emuStatus)
|
||||
void Station::readGatewayStatus(int deviceNo, int cdzStatus, int emuStatus, int tamStatus)
|
||||
{
|
||||
auto device = this->getDeviceByType(int(EDeviceType::GATEWAY), Utils::toStr(deviceNo));
|
||||
if (device)
|
||||
@@ -553,6 +555,7 @@ void Station::readGatewayStatus(int deviceNo, int cdzStatus, int emuStatus)
|
||||
|
||||
if (cdzStatus == 0) charge.status = 0;
|
||||
else if (charge.status == 0) charge.status = 1;
|
||||
|
||||
if (emuStatus == 0) storage.status = 0;
|
||||
else if (storage.status == 0) storage.status = 1;
|
||||
|
||||
@@ -578,6 +581,52 @@ void Station::readGatewayStatus(int deviceNo, int cdzStatus, int emuStatus)
|
||||
this->emuStatus = emuStatus;
|
||||
}
|
||||
}
|
||||
|
||||
//台区电表 1:在线,0:离线
|
||||
if (tamStatus >= 0)
|
||||
{
|
||||
if (tamStatus != this->tamStatus)
|
||||
{
|
||||
std::string text = "场站[" + name + "(" + std::to_string(stationId) + ")]台区电表状态变化:" + (tamStatus > 0 ? "在线" : "离线");
|
||||
if (this->tamStatus < 0) { text = "系统启动," + text; }
|
||||
DAO::insertSystemLogDevice(stationId, 0, text, tamStatus);
|
||||
this->tamStatus = tamStatus;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void DeviceReadJsonArray(std::shared_ptr<Device> device, njson& json, string key)
|
||||
{
|
||||
if (json.contains(key))
|
||||
{
|
||||
vector<int> vecd = json[key].get<std::vector<int>>();
|
||||
for (int i = 0; i <= vecd.size(); ++i)
|
||||
{
|
||||
device->setParam(key + std::to_string(i+1), vecd[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Station::readTDData(int deviceNo, string str)
|
||||
{
|
||||
njson json;
|
||||
bool ret = JSON::parse(str, json);
|
||||
if (!ret)
|
||||
{
|
||||
spdlog::error("TD_YC parse error: json={}", str);
|
||||
return;
|
||||
}
|
||||
auto device = this->getDeviceByType(int(EDeviceType::E_METER_TD), Utils::toStr(deviceNo));
|
||||
if (!device)
|
||||
{
|
||||
spdlog::error("TD_YC parse error, get device failed, deviceNo={}, json={}", deviceNo, str);
|
||||
return;
|
||||
}
|
||||
DeviceReadJsonArray(device, json, "U");
|
||||
DeviceReadJsonArray(device, json, "I");
|
||||
DeviceReadJsonArray(device, json, "P");
|
||||
DeviceReadJsonArray(device, json, "Ep");
|
||||
DeviceReadJsonArray(device, json, "En");
|
||||
}
|
||||
|
||||
static std::string MapValueToJson(int npos, std::map<int, float>& mapV)
|
||||
|
||||
@@ -125,9 +125,10 @@ public:
|
||||
void readFire40Data(int deviceNo, string addr, int val);
|
||||
void readCoolingData(int deviceNo, string addr, int val);
|
||||
void readGatewayMode(int deviceNo, int mode, string p1, string p2, string p3);
|
||||
void readGatewayStatus(int deviceNo, int cdzStatus, int emuStatus);
|
||||
void readGatewayStatus(int deviceNo, int cdzStatus, int emuStatus, int tamStatus);
|
||||
|
||||
void readTDData(int deviceNo);
|
||||
// 台区电表的数据结构和其它不一致(不是点表)进行特殊处理
|
||||
void readTDData(int deviceNo, string str);
|
||||
|
||||
void setCache(int datatype, std::vector<float>& vd);
|
||||
void cache();
|
||||
@@ -178,7 +179,9 @@ public:
|
||||
|
||||
int cdzStatus{ -1 }; // 充电桩 1:在线,0:离线
|
||||
int emuStatus{ -1 }; // 储能 1:在线,0:离线
|
||||
int tamStatus{ -1 }; // 台区电表 1:在线,0:离线
|
||||
int pvStatus{ -1 };
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// === 储能相关数据 ===
|
||||
|
||||
@@ -445,7 +445,7 @@ Errcode DAO::queryDeviceList(PageInfo& pageInfo, vector<Fields>& result)
|
||||
}
|
||||
Errcode DAO::queryDeviceListByStation(PageInfo& pageInfo, string stationId, vector<Fields>& result)
|
||||
{
|
||||
std::string sqlFrom = "FROM device d LEFT JOIN station s ON d.station_id =s.station_id WHERE d.station_id='" + stationId + "'";
|
||||
std::string sqlFrom = "FROM device d LEFT JOIN station s ON d.station_id =s.station_id WHERE d.station_id='" + stationId + "' ORDER BY station_id, sort_no";
|
||||
return QueryPagination("d.*, s.name station_name", sqlFrom, pageInfo, result);
|
||||
}
|
||||
|
||||
|
||||
@@ -309,9 +309,15 @@ int MqttClient::onMessageArrived(char* topic, int topicLen, MQTTAsync_message* m
|
||||
{
|
||||
int cdzStatus = -1;
|
||||
int emuStatus = -1;
|
||||
int tamStatus = -1;
|
||||
JSON::read(json, "cdz", cdzStatus);
|
||||
JSON::read(json, "emu", emuStatus);
|
||||
station->readGatewayStatus(deviceNo, cdzStatus, emuStatus);
|
||||
JSON::read(json, "tam", tamStatus);
|
||||
station->readGatewayStatus(deviceNo, cdzStatus, emuStatus, tamStatus);
|
||||
}
|
||||
else if (command == "TD_YC")
|
||||
{
|
||||
station->readTDData(deviceNo, payload);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user