f18f7570ed
Signed-off-by: Tony <tonylu@tony-cloud.com>
95 lines
2.7 KiB
C++
95 lines
2.7 KiB
C++
#pragma once
|
|
|
|
#include "bridge.hpp"
|
|
#include "dali_comm.hpp"
|
|
|
|
#include <atomic>
|
|
#include <functional>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#ifdef ESP_PLATFORM
|
|
#include "esp_event_base.h"
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/task.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";
|
|
std::string cemiTransport = "mqtt";
|
|
bool lteUartEnabled = false;
|
|
int lteUartPort = -1;
|
|
int lteTxPin = -1;
|
|
int lteRxPin = -1;
|
|
int lteBaudrate = 115200;
|
|
int lteRxBufferSize = 2048;
|
|
int lteTxBufferSize = 2048;
|
|
int qos = 1;
|
|
};
|
|
|
|
// DaliCloudBridge bridges MQTT cloud topics and local DALI frames.
|
|
class DaliCloudBridge {
|
|
public:
|
|
using CemiDownlinkHandler = std::function<bool(const uint8_t* data, size_t len)>;
|
|
|
|
explicit DaliCloudBridge(DaliComm& comm);
|
|
|
|
bool start(const GatewayCloudConfig& config);
|
|
void stop();
|
|
bool isConnected() const;
|
|
bool lteUartActive() const;
|
|
DaliBridgeEngine& bridge() { return bridge_; }
|
|
const DaliBridgeEngine& bridge() const { return bridge_; }
|
|
void setCemiDownlinkHandler(CemiDownlinkHandler handler);
|
|
|
|
bool publishStatus(const std::string& status);
|
|
bool publishRegister(const std::string& payloadJson);
|
|
bool publishCemiFrame(const uint8_t* data, size_t len);
|
|
|
|
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 handleCemiDownlink(const uint8_t* payload, size_t len);
|
|
bool publishJSON(const std::string& topic, const std::string& payloadJson);
|
|
bool publishBytes(const std::string& topic, const uint8_t* data, size_t len, int qos);
|
|
bool startLteUart();
|
|
void stopLteUart();
|
|
bool publishLteUartBytes(const uint8_t* data, size_t len);
|
|
void lteUartLoop();
|
|
|
|
std::string topicDown() const;
|
|
std::string topicUp() const;
|
|
std::string topicStatus() const;
|
|
std::string topicRegister() const;
|
|
std::string topicCemiDown() const;
|
|
std::string topicCemiUp() const;
|
|
std::string topicCemiStatus() const;
|
|
|
|
DaliComm& comm_;
|
|
DaliBridgeEngine bridge_;
|
|
GatewayCloudConfig config_;
|
|
CemiDownlinkHandler cemi_downlink_handler_;
|
|
std::atomic<bool> connected_{false};
|
|
std::atomic<bool> lte_uart_started_{false};
|
|
std::atomic<bool> lte_uart_stop_requested_{false};
|
|
std::atomic<uint32_t> cemi_sequence_{0};
|
|
|
|
#ifdef ESP_PLATFORM
|
|
static void lteUartTaskEntry(void* arg);
|
|
esp_mqtt_client_handle_t client_ = nullptr;
|
|
TaskHandle_t lte_uart_task_ = nullptr;
|
|
#endif
|
|
};
|