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:
@@ -1,9 +1,31 @@
|
||||
#include "MqttEntity.h"
|
||||
#include "common/Spdlogger.h"
|
||||
#include "common/JsonN.h"
|
||||
#include "common/Utils.h"
|
||||
|
||||
#define TIMEOUT 10000L
|
||||
|
||||
|
||||
static std::map<std::string, std::map<std::string, REGInfo>> g_mapRegInfo;
|
||||
|
||||
void MqttClient::loadDataStruct(std::string filename)
|
||||
{
|
||||
NJsonNode json;
|
||||
NJson::load(filename, json);
|
||||
|
||||
// 遍历 JSON 对象
|
||||
for (auto& jsonitem : json.items())
|
||||
{
|
||||
auto& mapItem = g_mapRegInfo[jsonitem.key()];
|
||||
|
||||
for (auto& itemaddrs : jsonitem.value().items())
|
||||
{
|
||||
auto& jsonreg = itemaddrs.value();
|
||||
mapItem[jsonreg["key"]] = REGInfo(jsonreg["key"], jsonreg["datatype"], jsonreg["remark"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int MqttClient::init(string addr, string clientId, string username, string password)
|
||||
{
|
||||
this->addr = addr;
|
||||
@@ -28,7 +50,8 @@ int MqttClient::init(string addr, string clientId, string username, string passw
|
||||
int rc {0};
|
||||
|
||||
// "tcp://localhost:1883"
|
||||
rc = MQTTAsync_create(&client, addr.c_str(), clientId.c_str(), MQTTCLIENT_PERSISTENCE_NONE, NULL);
|
||||
std::string str = "ESS-" + std::to_string(Utils::random(1000, 9999)) + "-" +clientId;
|
||||
rc = MQTTAsync_create(&client, addr.c_str(), str.c_str(), MQTTCLIENT_PERSISTENCE_NONE, NULL);
|
||||
if (rc != MQTTASYNC_SUCCESS)
|
||||
{
|
||||
spdlog::error("[mqtt] MQTTAsync_create error: {}", rc);
|
||||
@@ -87,10 +110,10 @@ int MqttClient::init(string addr, string clientId, string username, string passw
|
||||
|
||||
void MqttClient::destory()
|
||||
{
|
||||
return;
|
||||
if (client)
|
||||
{
|
||||
MQTTAsync_destroy(&client);
|
||||
client = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,7 +177,7 @@ int MqttClient::publish(string topic, string text)
|
||||
void MqttClient::onConnectionLost(char* cause)
|
||||
{
|
||||
this->isConnected = false;
|
||||
this->destory();
|
||||
//this->destory();
|
||||
spdlog::error("MQTT connection lost, cause={}", cause);
|
||||
}
|
||||
|
||||
@@ -184,10 +207,47 @@ int MqttClient::onMessageArrived(char* topic, int topicLen, MQTTAsync_message* m
|
||||
std::string command = GetSubStr("/", topicStr);
|
||||
std::string deviceCode = GetSubStr("/", topicStr);
|
||||
|
||||
if (command == "EMS_YX") {}
|
||||
else if (command == "EMS_YC") {}
|
||||
|
||||
//EMS遥信
|
||||
//EMS遥测
|
||||
//EMS遥调
|
||||
//PCU遥信
|
||||
//PCU遥测
|
||||
//PCS遥信
|
||||
//PCS遥测
|
||||
//BMS遥测
|
||||
//BCU遥信
|
||||
//BCU遥测
|
||||
//电表遥测
|
||||
//温湿度遥测
|
||||
//消防遥信4.0
|
||||
//冷机遥信
|
||||
//冷机遥测
|
||||
//充电桩遥测
|
||||
//网关遥信
|
||||
//网关遥测
|
||||
//网关遥调
|
||||
//台区
|
||||
|
||||
if (command == "EMS_YX") { this->parseEMS_YX(payload); }
|
||||
else if (command == "EMS_YC") { this->parseEMS_YC(payload); }
|
||||
else if (command == "PCU_YX") { this->parsePCU_YX(payload); }
|
||||
else if (command == "PCU_YC") {}
|
||||
else if (command == "PCU_YC") { this->parsePCU_YC(payload); }
|
||||
else if (command == "PCS_YX") { this->parsePCS_YX(payload); }
|
||||
else if (command == "PCS_YC") { this->parsePCS_YC(payload); }
|
||||
else if (command == "BMS_YC") { this->parseBMS_YC(payload); }
|
||||
else if (command == "BCU_YX") { this->parseBCU_YX(payload); }
|
||||
else if (command == "BCU_YC") { this->parseBCU_YC(payload); }
|
||||
else if (command == "MEM_YC") { this->parseMEM_YC(payload); }
|
||||
else if (command == "TH_YC") { this->parseTH_YC(payload); }
|
||||
else if (command == "Fire40_YX") { this->parseFire40_YX(payload); }
|
||||
else if (command == "Cooling_YX") { this->parseCooling_YX(payload); }
|
||||
else if (command == "Cooling_YC") { this->parseCooling_YC(payload); }
|
||||
else if (command == "Charger_YC") { this->parseCharger_YC(payload); }
|
||||
else if (command == "Gateway_YX") { this->parseGateway_YX(payload); }
|
||||
else if (command == "Gateway_YC") { this->parseGateway_YC(payload); }
|
||||
else if (command == "Gateway_YT") { this->parseGateway_YT(payload); }
|
||||
else if (command == "TQ") { this->parseTQ(payload); }
|
||||
|
||||
// 必须释放消息内存!
|
||||
MQTTAsync_freeMessage(&msg);
|
||||
@@ -205,7 +265,7 @@ void MqttClient::onDeliveryComplete(MQTTAsync_token token)
|
||||
|
||||
void MqttClient::onConnectSuccess( MQTTAsync_successData* resp)
|
||||
{
|
||||
spdlog::info("[mqtt] connect to {} success.", addr);
|
||||
spdlog::info("[mqtt] connect to {} success, clientId={}.", addr, clientId);
|
||||
this->isConnected = true;
|
||||
this->subscribe();
|
||||
//MQTTAsync_responseOptions options = MQTTAsync_responseOptions_initializer;
|
||||
@@ -234,20 +294,30 @@ void MqttClient::onConnectSuccess( MQTTAsync_successData* resp)
|
||||
}
|
||||
void MqttClient::onConnectFaiure(MQTTAsync_failureData* resp)
|
||||
{
|
||||
spdlog::error("[mqtt] connect to {} error.", addr);
|
||||
spdlog::error("[mqtt] connect to {} error, clientId={}.", addr, clientId);
|
||||
this->isConnected = false;
|
||||
this->destory();
|
||||
}
|
||||
|
||||
|
||||
void MqttClient::parseEMS_YC(std::string& text)
|
||||
{
|
||||
|
||||
}
|
||||
void MqttClient::parsePCU_YX(std::string& text)
|
||||
{
|
||||
}
|
||||
|
||||
void MqttClient::parseEMS_YX(std::string& text){}
|
||||
void MqttClient::parseEMS_YC(std::string& text) {};
|
||||
void MqttClient::parsePCU_YX(std::string& text) {};
|
||||
void MqttClient::parsePCU_YC(std::string& text) {};
|
||||
void MqttClient::parsePCS_YX(std::string& text) {};
|
||||
void MqttClient::parsePCS_YC(std::string& text) {};
|
||||
void MqttClient::parseBMS_YC(std::string& text) {};
|
||||
void MqttClient::parseBCU_YX(std::string& text) {};
|
||||
void MqttClient::parseBCU_YC(std::string& text) {};
|
||||
void MqttClient::parseMEM_YC(std::string& text) {};
|
||||
void MqttClient::parseTH_YC(std::string& text) {};
|
||||
void MqttClient::parseFire40_YX(std::string& text) {};
|
||||
void MqttClient::parseCooling_YX(std::string& text) {};
|
||||
void MqttClient::parseCooling_YC(std::string& text) {};
|
||||
void MqttClient::parseCharger_YC(std::string& text) {};
|
||||
void MqttClient::parseGateway_YX(std::string& text) {};
|
||||
void MqttClient::parseGateway_YC(std::string& text) {};
|
||||
void MqttClient::parseGateway_YT(std::string& text) {};
|
||||
void MqttClient::parseTQ(std::string& text) {};
|
||||
|
||||
string MQTT::packEquipmentInfo()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user