调试修改MQTT通讯问题

This commit is contained in:
lixiaoyuan
2025-09-17 19:55:59 +08:00
parent 94d6d8a8db
commit c55da0bddc
18 changed files with 661 additions and 494 deletions

View File

@@ -7,13 +7,14 @@
#include "common/JsonN.h"
class Station;
class Device;
struct TopicInfo
{
std::string name;
int deviceType {0};
int polling {0}; // 召测
int enabled {1};
TopicInfo() {};
TopicInfo(std::string name, int deviceType, int polling=0)
:name(name), deviceType(deviceType), polling(polling)
@@ -25,6 +26,8 @@ using namespace std;
class MqttClient
{
public:
static bool load(std::string filename);
int init(string addr, string clientId, string username, string password);
void destory();
@@ -39,7 +42,8 @@ public:
void onConnectFaiure(MQTTAsync_failureData* resp);
int onMessageArrived(char* topic, int len, MQTTAsync_message* msg);
void ParseArrivedMessage(njson& json, string clientId, string command, std::shared_ptr<Station> station);
void ParseArrivedMessage(njson& json, string command, std::shared_ptr<Station> station);
void ParseMessageCharge(njson& json, string command, std::shared_ptr<Station> station, std::shared_ptr<Device> device);
public:
// MQTT clientId (使用station 的 code)
@@ -51,7 +55,7 @@ public:
bool isConnected {false};
bool isSubscribed {false};
std::map<std::string, TopicInfo> mapTopicInfo;
static std::map<std::string, TopicInfo> s_mapTopicInfo;
};
@@ -71,12 +75,3 @@ public:
#define TOPIC_PCS_YC "up/json/预制舱01/PCS_YC"
#define TOPIC_PCS_YC "up/json/预制舱01/PCS_YC"
class MQTT
{
public:
public:
static string pack(std::string name);
};