105 lines
3.0 KiB
C++
105 lines
3.0 KiB
C++
#pragma once
|
|
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <functional>
|
|
#include <memory>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "esp_err.h"
|
|
|
|
class Dali;
|
|
class DaliComm;
|
|
|
|
namespace gateway {
|
|
|
|
struct DaliTransportHooks {
|
|
std::function<bool(const uint8_t* data, size_t len)> send;
|
|
std::function<std::vector<uint8_t>(size_t len, uint32_t timeout_ms)> read;
|
|
std::function<std::vector<uint8_t>(const uint8_t* data, size_t len)> transact;
|
|
std::function<void(uint32_t ms)> delay;
|
|
};
|
|
|
|
struct DaliHardwareBusConfig {
|
|
uint8_t channel_index{0};
|
|
uint8_t gateway_id{0};
|
|
uint8_t bus_id{0};
|
|
uint8_t tx_pin{0};
|
|
uint8_t rx_pin{0};
|
|
uint32_t baudrate{1200};
|
|
std::string name{"gateway"};
|
|
};
|
|
|
|
struct DaliSerialBusConfig {
|
|
uint8_t channel_index{0};
|
|
uint8_t gateway_id{0};
|
|
int uart_port{1};
|
|
int tx_pin{0};
|
|
int rx_pin{1};
|
|
uint32_t baudrate{9600};
|
|
size_t rx_buffer_size{256};
|
|
size_t tx_buffer_size{256};
|
|
uint32_t query_timeout_ms{500};
|
|
std::string name{"gateway"};
|
|
};
|
|
|
|
struct DaliChannelConfig {
|
|
uint8_t channel_index{0};
|
|
uint8_t gateway_id{0};
|
|
std::string name{"gateway"};
|
|
};
|
|
|
|
enum class DaliPhyKind {
|
|
kCustom,
|
|
kNativeHardware,
|
|
kSerialUart,
|
|
};
|
|
|
|
struct DaliChannelInfo {
|
|
uint8_t channel_index{0};
|
|
uint8_t gateway_id{0};
|
|
DaliPhyKind phy_kind{DaliPhyKind::kCustom};
|
|
std::string name;
|
|
};
|
|
|
|
class DaliDomainService {
|
|
public:
|
|
DaliDomainService();
|
|
~DaliDomainService();
|
|
|
|
bool bindTransport(const DaliChannelConfig& config, DaliTransportHooks hooks);
|
|
esp_err_t bindHardwareBus(const DaliHardwareBusConfig& config);
|
|
esp_err_t bindSerialBus(const DaliSerialBusConfig& config);
|
|
bool isBound() const;
|
|
bool isHardwareBound(uint8_t gateway_id) const;
|
|
const char* implementationName() const;
|
|
size_t channelCount() const;
|
|
std::vector<DaliChannelInfo> channelInfo() const;
|
|
|
|
bool resetBus(uint8_t gateway_id) const;
|
|
bool sendRaw(uint8_t gateway_id, uint8_t raw_addr, uint8_t command) const;
|
|
bool sendExtRaw(uint8_t gateway_id, uint8_t raw_addr, uint8_t command) const;
|
|
std::optional<uint8_t> queryRaw(uint8_t gateway_id, uint8_t raw_addr, uint8_t command) const;
|
|
bool setBright(uint8_t gateway_id, int short_address, int brightness) const;
|
|
bool setColTempRaw(uint8_t gateway_id, int short_address, int mirek) const;
|
|
bool setColTemp(uint8_t gateway_id, int short_address, int kelvin) const;
|
|
bool setColourRaw(uint8_t gateway_id, int raw_addr, int x, int y) const;
|
|
bool setColourRGB(uint8_t gateway_id, int short_address, int r, int g, int b) const;
|
|
bool on(uint8_t gateway_id, int short_address) const;
|
|
bool off(uint8_t gateway_id, int short_address) const;
|
|
bool off(int short_address) const;
|
|
|
|
private:
|
|
struct DaliChannel;
|
|
|
|
DaliChannel* findChannelByGateway(uint8_t gateway_id);
|
|
const DaliChannel* findChannelByGateway(uint8_t gateway_id) const;
|
|
DaliChannel* findChannelByIndex(uint8_t channel_index);
|
|
bool hasSerialPort(int uart_port) const;
|
|
|
|
std::vector<std::unique_ptr<DaliChannel>> channels_;
|
|
};
|
|
|
|
} // namespace gateway
|