e94945fc0f
Signed-off-by: Tony <tonylu@tony-cloud.com>
80 lines
2.3 KiB
C++
80 lines
2.3 KiB
C++
#pragma once
|
|
|
|
#include <cstdint>
|
|
#include <memory>
|
|
#include <optional>
|
|
#include <set>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "esp_err.h"
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/task.h"
|
|
#include "gateway_knx.hpp"
|
|
#include "gateway_modbus.hpp"
|
|
|
|
namespace gateway {
|
|
|
|
class DaliDomainService;
|
|
class GatewayCache;
|
|
|
|
struct GatewayBridgeServiceConfig {
|
|
bool bridge_enabled{true};
|
|
bool modbus_enabled{true};
|
|
bool modbus_startup_enabled{false};
|
|
bool bacnet_enabled{false};
|
|
bool bacnet_startup_enabled{false};
|
|
bool knx_enabled{false};
|
|
bool knx_startup_enabled{false};
|
|
bool cloud_enabled{true};
|
|
bool cloud_startup_enabled{false};
|
|
uint32_t modbus_task_stack_size{6144};
|
|
UBaseType_t modbus_task_priority{4};
|
|
std::optional<GatewayModbusConfig> default_modbus_config;
|
|
bool allow_modbus_uart0{false};
|
|
bool allow_knx_uart0{false};
|
|
std::vector<int> reserved_uart_ports;
|
|
uint32_t bacnet_task_stack_size{8192};
|
|
UBaseType_t bacnet_task_priority{5};
|
|
uint32_t knx_task_stack_size{8192};
|
|
UBaseType_t knx_task_priority{5};
|
|
std::optional<GatewayKnxConfig> default_knx_config;
|
|
};
|
|
|
|
struct GatewayBridgeHttpResponse {
|
|
esp_err_t err{ESP_OK};
|
|
std::string body;
|
|
};
|
|
|
|
class GatewayBridgeService {
|
|
public:
|
|
GatewayBridgeService(DaliDomainService& dali_domain,
|
|
GatewayCache& cache,
|
|
GatewayBridgeServiceConfig config = {});
|
|
~GatewayBridgeService();
|
|
|
|
esp_err_t start();
|
|
|
|
GatewayBridgeHttpResponse handleGet(const std::string& action, int gateway_id = -1,
|
|
const std::string& query = {});
|
|
GatewayBridgeHttpResponse handlePost(const std::string& action, int gateway_id,
|
|
const std::string& body);
|
|
|
|
private:
|
|
struct ChannelRuntime;
|
|
|
|
ChannelRuntime* findRuntime(uint8_t gateway_id);
|
|
const ChannelRuntime* findRuntime(uint8_t gateway_id) const;
|
|
void collectUsedRuntimeResources(uint8_t except_gateway_id,
|
|
std::set<uint16_t>* modbus_tcp_ports,
|
|
std::set<uint16_t>* knx_udp_ports,
|
|
std::set<int>* serial_uarts) const;
|
|
|
|
DaliDomainService& dali_domain_;
|
|
GatewayCache& cache_;
|
|
GatewayBridgeServiceConfig config_;
|
|
std::vector<std::unique_ptr<ChannelRuntime>> runtimes_;
|
|
};
|
|
|
|
} // namespace gateway
|