Files
Tony 7424b43bdd Add diagnostic bit support to Gateway Modbus
- Introduced new enum value `kShortDiagnosticBit` to `GatewayModbusGeneratedKind`.
- Enhanced `GatewayModbusPoint` and `GatewayModbusPointBinding` structures to include diagnostic snapshot, boolean key, and device type.
- Added new diagnostic bit specifications and updated the corresponding arrays for generated discrete inputs and holding registers.
- Implemented `addGeneratedDiagnosticPoint` function to handle the creation of diagnostic points.
- Updated `rebuildMap` method to include generated diagnostic points during the map rebuilding process.

Co-authored-by: Copilot <copilot@github.com>
2026-05-04 02:26:09 +08:00

94 lines
2.7 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 <optional>
#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"};
bool out_of_service{false};
uint32_t reliability{0};
bool readable{false};
};
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)>;
using GatewayBacnetReadCallback =
std::function<std::optional<DaliValue>(BridgeObjectType object_type,
uint32_t object_instance,
const std::string& property)>;
class GatewayBacnetServer {
public:
static GatewayBacnetServer& instance();
esp_err_t registerChannel(uint8_t gateway_id, const GatewayBacnetServerConfig& config,
std::vector<GatewayBacnetObjectBinding> bindings,
GatewayBacnetWriteCallback write_callback,
GatewayBacnetReadCallback read_callback = nullptr);
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();
void refreshPresentValues();
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