调试修改MQTT通讯解析

This commit is contained in:
lixiaoyuan
2025-09-16 19:38:46 +08:00
parent 9377e7f8e6
commit 393f68aec9
25 changed files with 943 additions and 1428 deletions

View File

@@ -14,10 +14,6 @@ Station::Station() : stationId(0)
mqttCli = std::make_shared<MqttClient>();
// 测试,设置默认值
for (int i = 1; i<=5; i++) { mapTempHumUnit[i] = TempHumUnit(Utils::random(20, 40), Utils::random(20, 80)); }
for (int i = 1; i<=5; i++) { mapFire40Unit[i] = 0; }
for (int i = 1; i<=5; i++) {
auto& unit = mapCoolingUnit[i];
unit.powerOn = 1;
@@ -41,6 +37,7 @@ void Station::setFields(Fields& fields)
this->code = fields.value(DMStation::CODE);
this->status = fields.get<int>(DMStation::STATUS);
this->operationDate = fields.value(DMStation::OPERATION_DATE);
this->isOpen = fields.get<int>(DMStation::STATUS);
this->policy.setFields(fields);
}
@@ -48,7 +45,6 @@ void Station::setFields(Fields& fields)
void Station::addDevice(int deviceId, std::shared_ptr<Device> device)
{
mapDevice[deviceId] = device;
mapDeviceGroup[device->category].push_back(device);
}
void Station::addDevice(Fields& fields)
@@ -63,7 +59,6 @@ void Station::addDevice(Fields& fields)
{
auto device = Device::create(fields);
mapDevice[deviceId] = device;
mapDeviceGroup[device->category].push_back(device);
}
}
@@ -77,6 +72,17 @@ std::shared_ptr<Device> Station::getDevice(int deviceId)
return nullptr;
}
void Station::groupDevice()
{
for (auto iter = mapDevice.begin(); iter!=mapDevice.end(); ++iter)
{
auto& device = iter->second;
char key[20] = {};
sprintf(key, "%03d_%03d_%04d", device->stationId, device->sortNo, device->deviceId);
mapDeviceGroup[device->category][key] = device;
}
}
std::shared_ptr<Device> Station::getDeviceByType(int deviceType, std::string code)
{
for (auto iter = mapDevice.begin(); iter!=mapDevice.end(); ++iter)
@@ -112,12 +118,17 @@ int Station::getDeviceCount(int category)
return 0;
}
void Station::getDeviceByGroup(int category, std::vector<std::shared_ptr<Device>>& res)
void Station::getDeviceByCategory(int category, std::vector<std::shared_ptr<Device>>& res)
{
auto iter = mapDeviceGroup.find(category);
if (iter != mapDeviceGroup.end())
{
res = iter->second;
res.resize(iter->second.size());
int i = 0;
for (auto& item: iter->second)
{
res[i++] = item.second;
}
}
}
@@ -185,6 +196,32 @@ void Station::writeRuntimeData(std::string dt, int npos)
}
}
void Station::writeStatistic(std::string dt)
{
Fields fields;
fields.set("storage_elect_in", statData.totalElectIn);
fields.set("storage_elect_out", statData.totalElectOut);
//fields.set("storage_num_in", statData.totalElectIn);
//fields.set("storage_num_out", 0);
//fields.set("storage_num_err", 0);
//fields.set("storage_t_in", 0);
//fields.set("storage_t_out", 0);
//fields.set("storage_usage", 0);
//fields.set("solar_elect_gen", 0);
//fields.set("solar_elect_grid", 0);
//fields.set("solar_num_err", 0);
//fields.set("solar_t", 0);
//fields.set("solar_usage", 0);
//fields.set("charge_elect", 0);
//fields.set("charge_num", 0);
//fields.set("charge_num_err", 0);
//fields.set("charge_t", 0);
//fields.set("charge_usage", 0);
fields.set("income_elect", statData.totalIncome);
//fields.set("income_charge", 0);
//fields.set("usage_rate", 0);
}
void Station::initMqtt()
{
if (status!=0 && mqttCli)
@@ -229,3 +266,78 @@ void Station::setGarewayWorkMode()
spdlog::info(text);
mqttCli->publish("Gateway_YT", text);
}
void Station::setRuntimeData(string addr, int val)
{
if (addr == "0x110E") { statData.dayElectIn = val; } //日充电电量 R uint32 1kWh 0 0x110E
else if (addr == "0x1110") { statData.dayElectOut = val; } //日放电电量 R uint32 1kWh 0 0x1110
else if (addr == "0x1112") { statData.dayIncomeIn = val; } //日充电费用 R uint32 1RMB 0 0x1112
else if (addr == "0x1114") { statData.dayIncomeOut = val; } //日放电费用 R uint32 1RMB 0 0x1114
else if (addr == "0x1116") { statData.dayIncome = val; } //日收益 R int32 1RMB 0 0x1116
else if (addr == "0x112C") { statData.totalElectIn = val; } //总充电电量 R uint32 1kWh 6659(0x112D) 0x112C
else if (addr == "0x112E") { statData.totalElectOut = val; } //总放电电量 R uint32 1kWh 4925(0x112F) 0x112E
else if (addr == "0x1130") { statData.totalIncomeIn = val; } //总充电费用 R uint32 1RMB 6605(0x1131) 0x1130
else if (addr == "0x1132") { statData.totalIncomeOut = val; } //总放电费用 R uint32 1RMB 4949(0x1133) 0x1132
else if (addr == "0x1134") { statData.totalIncome = val; } //总收益 R int32 1RMB -1 0x1134
}
void Station::setTHData(int deviceNo, string addr, int val)
{
auto& unit = mapTempHumUnit[deviceNo];
if (addr == "0x0001") { ; } //所属通道号 R uint16 1 0x0001
else if (addr == "0x0002") { ; } //所属温湿度号 R uint16 1~10 0x0002
else if (addr == "0x0003") { unit.temp = float(val) * 0.1; } //温度 R int16 0.1℃ 0x0003
else if (addr == "0x0004") { unit.hum = float(val) * 0.1; } //湿度 R int16 0.1℃ 0x0004
}
void Station::setFire40Data(int deviceNo, string addr, int val)
{
auto& unit = mapFire40Unit[deviceNo];
if (addr == "0x0001") { ; } //所属通道号 R uint16 1~10 0x0001
else if (addr == "0x0002") { ; } //主控数量 R uint16 1 0x0002
else if (addr == "0x0003") { ; } //主控ID R uint16 1 0x0003
else if (addr == "0x0004") { unit.statusMain = val; } //主控状态 R uint16 0正常 1预警 2火警 0x0004
else if (addr == "0x0005") { ; } //主控硬件版本 R uint16[2] 主控硬件版本 0x0005
else if (addr == "0x0007") { ; } //主控软件版本 R uint16[2] 主控软件版本 0x0007
else if (addr == "0x0009") { ; } //主电状态 R uint16 0使用市电 1使用备电 0x0009
else if (addr == "0x000A") { ; } //备电电流 R uint32 0.1A 0x000A
else if (addr == "0x000C") { ; } //备电电压 R uint32 0.1V 0x000C
else if (addr == "0x000E") { ; } //可用容量 R uint32 0.01Ah 0x000E
else if (addr == "0x0010") { ; } //可充放容量 R uint32 0.01Ah 0x0010
else if (addr == "0x0012") { unit.usedAlarm = val; } //警铃是否使用 R uint16 0x0012
else if (addr == "0x0013") { unit.statusAlarm = val; } //警铃状态 R uint16 0无效 1掉线 2正常 3启动 0x0013
else if (addr == "0x0014") { unit.usedValve = val; } //瓶头阀是否使用 R uint16 0x0014
else if (addr == "0x0015") { unit.statusValve = val; } //瓶头阀状态 R uint16 0无效 1掉线 2正常 3启动 0x0015
else if (addr == "0x0016") { unit.usedMCP = val; } //手报是否使用 R uint16 0x0016
else if (addr == "0x0017") { unit.statusMCP = val; } //手报状态 R uint16 0无效 1掉线 2正常 3启动 0x0017
else if (addr == "0x0018") { ; } //簇控制器数量 R uint16 0x0018
else if (addr == "0x0019") { ; } //复合探测器总数量 R uint16 0x0019
else if (addr == "0x001A") { ; } //烟雾探测器总数量 R uint16 0x001A
else if (addr == "0x001B") { ; } //压力探测器总数量 R uint16 0x001B
else if (addr == "0x001C") { ; } //吸气式探测器总数量 R uint16 0x001C
else if (addr == "0x001D") { ; } //PACK探测器总数量 R uint16 0x001D
else if (addr == "0x001E") { ; } //电池总数量 R uint16 0x001E
}
void Station::setCoolingData(int deviceNo, string addr, int val)
{
auto& unit = mapCoolingUnit[deviceNo];
if (addr == "0x1001") { ; } //所属通道号 R uint16 1 0x1001
else if (addr == "0x1002") { ; }// 所属冷机号 R uint16 1~10 0x1002
else if (addr == "0x1003") { unit.powerOn = val; }// 开关 R uint16 0关机1开机 0x1003
else if (addr == "0x1004") { ; }// 采样模式 R uint16 0-出水温度 1-电芯温度 0x1004
else if (addr == "0x1005") { unit.cooling = val; }// 制冷状态 R uint16 0关闭, 1启动 0x1005
else if (addr == "0x1006") { unit.heating = val; }// 制热状态 R uint16 0关闭, 1启动 0x1006
else if (addr == "0x1007") { unit.highTemp = val; }// 高温告警 R uint16 0正常1告警 0x1007
else if (addr == "0x1008") { unit.lowTemp = val; }// 低温告警 R uint16 0正常1告警 0x1008
else if (addr == "0x1009") { unit.highPressure = val; }// 高压告警 R uint16 0正常1告警 0x1009
else if (addr == "0x100A") { unit.lowPressure = val; }// 低压告警 R uint16 0正常1告警 0x100A
else if (addr == "0x100B") { ; }// 进水温度传感器 R uint16 0正常1告警 0x100B
else if (addr == "0x100C") { ; }// 出水温度传感器 R uint16 0正常1告警 0x100C
else if (addr == "0x100D") { ; }// 进水压力传感器 R uint16 0正常1告警 0x100D
else if (addr == "0x100E") { ; }// 出水压力传感器 R uint16 0正常1告警 0x100E
}