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>
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
#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
|
||||
@@ -0,0 +1,58 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum gateway_bacnet_object_kind {
|
||||
GW_BACNET_OBJECT_UNKNOWN = 0,
|
||||
GW_BACNET_OBJECT_ANALOG_VALUE,
|
||||
GW_BACNET_OBJECT_ANALOG_OUTPUT,
|
||||
GW_BACNET_OBJECT_BINARY_VALUE,
|
||||
GW_BACNET_OBJECT_BINARY_OUTPUT,
|
||||
GW_BACNET_OBJECT_MULTI_STATE_VALUE,
|
||||
} gateway_bacnet_object_kind_t;
|
||||
|
||||
typedef enum gateway_bacnet_write_value_kind {
|
||||
GW_BACNET_WRITE_VALUE_REAL = 1,
|
||||
GW_BACNET_WRITE_VALUE_BOOLEAN = 2,
|
||||
GW_BACNET_WRITE_VALUE_UNSIGNED = 3,
|
||||
} gateway_bacnet_write_value_kind_t;
|
||||
|
||||
typedef struct gateway_bacnet_write_value {
|
||||
gateway_bacnet_write_value_kind_t kind;
|
||||
double real_value;
|
||||
bool boolean_value;
|
||||
uint32_t unsigned_value;
|
||||
} gateway_bacnet_write_value_t;
|
||||
|
||||
typedef void (*gateway_bacnet_stack_write_callback_t)(
|
||||
gateway_bacnet_object_kind_t object_kind,
|
||||
uint32_t object_instance,
|
||||
const gateway_bacnet_write_value_t* value,
|
||||
void* context);
|
||||
|
||||
bool gateway_bacnet_stack_start(
|
||||
uint32_t device_instance,
|
||||
const char* device_name,
|
||||
uint16_t udp_port,
|
||||
gateway_bacnet_stack_write_callback_t write_callback,
|
||||
void* callback_context);
|
||||
|
||||
void gateway_bacnet_stack_cleanup(void);
|
||||
|
||||
bool gateway_bacnet_stack_upsert_object(
|
||||
gateway_bacnet_object_kind_t object_kind,
|
||||
uint32_t object_instance,
|
||||
const char* object_name,
|
||||
const char* description);
|
||||
|
||||
void gateway_bacnet_stack_send_i_am(void);
|
||||
void gateway_bacnet_stack_poll(uint16_t elapsed_ms);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user