Files
gateway/components/gateway_bacnet/include/gateway_bacnet.hpp
T
Tony d16c289626 feat(gateway_network): integrate GatewayBridgeService and add bridge handling
- Updated CMakeLists.txt to require gateway_bridge component.
- Modified GatewayNetworkService to include a pointer to GatewayBridgeService.
- Added new HTTP handlers for bridge GET and POST requests.
- Implemented query utility functions for handling request parameters.
- Enhanced response handling for bridge actions with JSON responses.

Co-authored-by: Copilot <copilot@github.com>
2026-05-01 03:54:02 +08:00

83 lines
2.3 KiB
C++

#pragma once
#include "bridge_model.hpp"
#include "model_value.hpp"
#include "esp_err.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include <cstdint>
#include <functional>
#include <string>
#include <vector>
namespace gateway {
struct GatewayBacnetServerConfig {
uint32_t device_instance{4194303};
std::string device_name{"DALI Gateway"};
std::string local_address;
uint16_t udp_port{47808};
uint32_t task_stack_size{8192};
UBaseType_t task_priority{5};
};
struct GatewayBacnetObjectBinding {
uint8_t gateway_id{0};
std::string model_id;
std::string name;
BridgeObjectType object_type{BridgeObjectType::unknown};
uint32_t object_instance{0};
std::string property{"presentValue"};
};
struct GatewayBacnetServerStatus {
bool started{false};
uint32_t device_instance{0};
uint16_t udp_port{0};
size_t channel_count{0};
size_t object_count{0};
};
using GatewayBacnetWriteCallback =
std::function<bool(BridgeObjectType object_type, uint32_t object_instance,
const std::string& property, const DaliValue& value)>;
class GatewayBacnetServer {
public:
static GatewayBacnetServer& instance();
esp_err_t registerChannel(uint8_t gateway_id, const GatewayBacnetServerConfig& config,
std::vector<GatewayBacnetObjectBinding> bindings,
GatewayBacnetWriteCallback write_callback);
GatewayBacnetServerStatus status() const;
bool configCompatible(const GatewayBacnetServerConfig& config) const;
bool handleWrite(BridgeObjectType object_type, uint32_t object_instance,
const DaliValue& value);
private:
GatewayBacnetServer();
~GatewayBacnetServer();
GatewayBacnetServer(const GatewayBacnetServer&) = delete;
GatewayBacnetServer& operator=(const GatewayBacnetServer&) = delete;
struct ChannelRegistration;
struct RuntimeBinding;
esp_err_t startStackLocked(const GatewayBacnetServerConfig& config);
esp_err_t rebuildObjectsLocked();
static void TaskEntry(void* arg);
void taskLoop();
GatewayBacnetServerConfig active_config_;
std::vector<ChannelRegistration> channels_;
std::vector<RuntimeBinding> runtime_bindings_;
mutable SemaphoreHandle_t lock_{nullptr};
TaskHandle_t task_handle_{nullptr};
bool started_{false};
};
} // namespace gateway