34d2d9caa0
- Introduced GatewayModbusSerialConfig structure to encapsulate serial communication settings. - Added clamping functions for integer and size values to ensure valid configuration ranges. - Updated GatewayModbusConfigFromValue to parse serial configuration from JSON input. - Implemented transport type checking functions for TCP, RTU, ASCII, and Serial. - Enhanced GatewayModbusConfigToValue to include serial configuration in output. Signed-off-by: Tony <tonylu@tony-cloud.com>
68 lines
1.8 KiB
C++
68 lines
1.8 KiB
C++
#pragma once
|
|
|
|
#include <cstdint>
|
|
#include <memory>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "esp_err.h"
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/task.h"
|
|
#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 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};
|
|
std::vector<int> reserved_uart_ports;
|
|
uint32_t bacnet_task_stack_size{8192};
|
|
UBaseType_t bacnet_task_priority{5};
|
|
};
|
|
|
|
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;
|
|
|
|
DaliDomainService& dali_domain_;
|
|
GatewayCache& cache_;
|
|
GatewayBridgeServiceConfig config_;
|
|
std::vector<std::unique_ptr<ChannelRuntime>> runtimes_;
|
|
};
|
|
|
|
} // namespace gateway
|