Enhance DaliCloudBridge: add gateway settings handler and support for gateway configuration messages
Signed-off-by: Tony <tonylu@tony-cloud.com>
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include <atomic>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
@@ -36,6 +37,9 @@ struct GatewayCloudConfig {
|
||||
class DaliCloudBridge {
|
||||
public:
|
||||
using CemiDownlinkHandler = std::function<bool(const uint8_t* data, size_t len)>;
|
||||
/// Handles gateway-level configuration messages received on the normal MQTT
|
||||
/// downlink topic and returns the JSON acknowledgement for the up topic.
|
||||
using GatewaySettingsHandler = std::function<std::string(std::string_view request)>;
|
||||
|
||||
explicit DaliCloudBridge(DaliComm& comm);
|
||||
|
||||
@@ -46,6 +50,7 @@ class DaliCloudBridge {
|
||||
DaliBridgeEngine& bridge() { return bridge_; }
|
||||
const DaliBridgeEngine& bridge() const { return bridge_; }
|
||||
void setCemiDownlinkHandler(CemiDownlinkHandler handler);
|
||||
void setGatewaySettingsHandler(GatewaySettingsHandler handler);
|
||||
|
||||
bool publishStatus(const std::string& status);
|
||||
bool publishRegister(const std::string& payloadJson);
|
||||
@@ -81,6 +86,7 @@ class DaliCloudBridge {
|
||||
DaliBridgeEngine bridge_;
|
||||
GatewayCloudConfig config_;
|
||||
CemiDownlinkHandler cemi_downlink_handler_;
|
||||
GatewaySettingsHandler gateway_settings_handler_;
|
||||
std::atomic<bool> connected_{false};
|
||||
std::atomic<bool> lte_uart_started_{false};
|
||||
std::atomic<bool> lte_uart_stop_requested_{false};
|
||||
|
||||
@@ -339,6 +339,10 @@ void DaliCloudBridge::setCemiDownlinkHandler(CemiDownlinkHandler handler) {
|
||||
cemi_downlink_handler_ = std::move(handler);
|
||||
}
|
||||
|
||||
void DaliCloudBridge::setGatewaySettingsHandler(GatewaySettingsHandler handler) {
|
||||
gateway_settings_handler_ = std::move(handler);
|
||||
}
|
||||
|
||||
bool DaliCloudBridge::publishStatus(const std::string& status) {
|
||||
std::string payload = "{\"type\":\"status\",\"status\":\"" + status + "\"}";
|
||||
return publishJSON(topicStatus(), payload);
|
||||
@@ -571,6 +575,16 @@ bool DaliCloudBridge::handleDownlink(const std::string& payload) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::string type = toString(cJSON_GetObjectItemCaseSensitive(root, "type"));
|
||||
if (type == "gatewaySettingsGet" || type == "gatewaySettingsSet") {
|
||||
const std::string response = gateway_settings_handler_
|
||||
? gateway_settings_handler_(payload)
|
||||
: "{\"type\":\"gatewaySettings\",\"status\":\"error\","
|
||||
"\"error\":\"gateway settings are unavailable\"}";
|
||||
cJSON_Delete(root);
|
||||
return !response.empty() && publishJSON(topicUp(), response);
|
||||
}
|
||||
|
||||
DaliBridgeRequest request;
|
||||
const cJSON* seqItem = cJSON_GetObjectItemCaseSensitive(root, "seq");
|
||||
if (seqItem == nullptr) seqItem = cJSON_GetObjectItemCaseSensitive(root, "sequence");
|
||||
|
||||
Reference in New Issue
Block a user