21afc6b942
- Added `bridge.cpp` to handle DALI bridge operations including model management, command execution, and response formatting. - Introduced `bridge_model.cpp` for defining bridge models, value transformations, and JSON serialization/deserialization. - Created `bridge_provisioning.cpp` for managing bridge configuration storage and retrieval using NVS on ESP platform. - Enhanced `gateway_cloud.cpp` to integrate DALI bridge requests and responses with cloud communication. - Introduced `modbus_bridge.cpp` to handle Modbus-specific operations and register management. - Implemented utility functions for converting between DaliValue and cJSON formats. - Added error handling and metadata management in bridge responses.
63 lines
1.5 KiB
C++
63 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#include "bridge.hpp"
|
|
#include "dali_comm.hpp"
|
|
|
|
#include <atomic>
|
|
#include <string>
|
|
|
|
#ifdef ESP_PLATFORM
|
|
#include "esp_event_base.h"
|
|
#include "mqtt_client.h"
|
|
#endif
|
|
|
|
struct GatewayCloudConfig {
|
|
std::string brokerURI;
|
|
std::string deviceID;
|
|
std::string username = "device";
|
|
std::string password;
|
|
std::string topicPrefix = "devices";
|
|
int qos = 1;
|
|
};
|
|
|
|
// DaliCloudBridge bridges MQTT cloud topics and local DALI frames.
|
|
class DaliCloudBridge {
|
|
public:
|
|
explicit DaliCloudBridge(DaliComm& comm);
|
|
|
|
bool start(const GatewayCloudConfig& config);
|
|
void stop();
|
|
bool isConnected() const;
|
|
DaliBridgeEngine& bridge() { return bridge_; }
|
|
const DaliBridgeEngine& bridge() const { return bridge_; }
|
|
|
|
bool publishStatus(const std::string& status);
|
|
bool publishRegister(const std::string& payloadJson);
|
|
|
|
private:
|
|
#ifdef ESP_PLATFORM
|
|
static void mqttEventHandler(void* handler_args,
|
|
esp_event_base_t base,
|
|
int32_t event_id,
|
|
void* event_data);
|
|
void onMqttEvent(esp_mqtt_event_handle_t event);
|
|
#endif
|
|
|
|
bool handleDownlink(const std::string& payload);
|
|
bool publishJSON(const std::string& topic, const std::string& payloadJson);
|
|
|
|
std::string topicDown() const;
|
|
std::string topicUp() const;
|
|
std::string topicStatus() const;
|
|
std::string topicRegister() const;
|
|
|
|
DaliComm& comm_;
|
|
DaliBridgeEngine bridge_;
|
|
GatewayCloudConfig config_;
|
|
std::atomic<bool> connected_{false};
|
|
|
|
#ifdef ESP_PLATFORM
|
|
esp_mqtt_client_handle_t client_ = nullptr;
|
|
#endif
|
|
};
|