feat: add KNX gateway snapshot and command transaction handling
Signed-off-by: Tony <tonylu@tony-cloud.com>
This commit is contained in:
@@ -169,6 +169,32 @@ struct GatewayKnxReg1ScanOptions {
|
||||
bool assign{false};
|
||||
};
|
||||
|
||||
struct GatewayKnxGatewayChannelSnapshot {
|
||||
uint8_t gateway_id{0};
|
||||
};
|
||||
|
||||
struct GatewayKnxGatewaySnapshot {
|
||||
std::vector<GatewayKnxGatewayChannelSnapshot> channels;
|
||||
};
|
||||
|
||||
enum class GatewayKnxGatewayTransactionStatus : uint8_t {
|
||||
kOk = 0,
|
||||
kInvalidFrame = 1,
|
||||
kQueueRejected = 2,
|
||||
kTimeout = 3,
|
||||
kNoResponse = 4,
|
||||
};
|
||||
|
||||
struct GatewayKnxGatewayTransactionResult {
|
||||
GatewayKnxGatewayTransactionStatus status{GatewayKnxGatewayTransactionStatus::kNoResponse};
|
||||
std::vector<uint8_t> frames;
|
||||
};
|
||||
|
||||
using GatewayKnxGatewaySnapshotProvider = std::function<GatewayKnxGatewaySnapshot()>;
|
||||
using GatewayKnxGatewayCommandTransactor =
|
||||
std::function<GatewayKnxGatewayTransactionResult(const std::vector<uint8_t>& frame,
|
||||
uint32_t timeout_ms)>;
|
||||
|
||||
std::optional<GatewayKnxConfig> GatewayKnxConfigFromValue(const DaliValue* value);
|
||||
DaliValue GatewayKnxConfigToValue(const GatewayKnxConfig& config);
|
||||
std::optional<GatewayKnxOamRouterConfig> GatewayKnxOamRouterConfigFromValue(
|
||||
@@ -194,6 +220,8 @@ class GatewayKnxBridge {
|
||||
|
||||
void setConfig(const GatewayKnxConfig& config);
|
||||
void setRuntimeContext(const openknx::EtsDeviceRuntime* runtime);
|
||||
void setGatewayControllerCallbacks(GatewayKnxGatewaySnapshotProvider snapshot_provider,
|
||||
GatewayKnxGatewayCommandTransactor command_transactor);
|
||||
const GatewayKnxConfig& config() const;
|
||||
size_t etsBindingCount() const;
|
||||
|
||||
@@ -211,6 +239,13 @@ class GatewayKnxBridge {
|
||||
std::vector<uint8_t>* response);
|
||||
|
||||
private:
|
||||
struct GatewayTransferState {
|
||||
uint16_t total_length{0};
|
||||
uint8_t total_chunks{0};
|
||||
std::map<uint8_t, std::vector<uint8_t>> request_chunks;
|
||||
std::vector<uint8_t> response_bytes;
|
||||
};
|
||||
|
||||
DaliBridgeResult executeForDecodedWrite(uint16_t group_address,
|
||||
GatewayKnxDaliDataType data_type,
|
||||
GatewayKnxDaliTarget target,
|
||||
@@ -244,13 +279,29 @@ class GatewayKnxBridge {
|
||||
std::vector<uint8_t>* response);
|
||||
bool handleReg1FoundEvgsState(const uint8_t* data, size_t len,
|
||||
std::vector<uint8_t>* response);
|
||||
bool handleDalimasterDiscoveryState(const uint8_t* data, size_t len,
|
||||
std::vector<uint8_t>* response);
|
||||
bool handleDalimasterTransferCommand(const uint8_t* data, size_t len,
|
||||
std::vector<uint8_t>* response);
|
||||
bool handleDalimasterTransferState(const uint8_t* data, size_t len,
|
||||
std::vector<uint8_t>* response);
|
||||
bool executeDalimasterTransfer(uint16_t transaction_id, uint32_t timeout_ms,
|
||||
std::vector<uint8_t>* response);
|
||||
bool appendDalimasterTransferResponse(uint8_t transfer_status,
|
||||
uint16_t transaction_id,
|
||||
const std::vector<uint8_t>& response_bytes,
|
||||
uint8_t chunk_index,
|
||||
std::vector<uint8_t>* response) const;
|
||||
static void CommissioningScanTaskEntry(void* arg);
|
||||
void runCommissioningScanTask();
|
||||
|
||||
DaliBridgeEngine& engine_;
|
||||
GatewayKnxGatewaySnapshotProvider gateway_snapshot_provider_;
|
||||
GatewayKnxGatewayCommandTransactor gateway_command_transactor_;
|
||||
GatewayKnxConfig config_;
|
||||
const openknx::EtsDeviceRuntime* runtime_{nullptr};
|
||||
std::map<uint16_t, std::vector<GatewayKnxDaliBinding>> ets_bindings_by_group_address_;
|
||||
std::map<uint16_t, GatewayTransferState> gateway_transfer_states_;
|
||||
SemaphoreHandle_t commissioning_lock_{nullptr};
|
||||
TaskHandle_t commissioning_scan_task_{nullptr};
|
||||
std::atomic_bool commissioning_scan_cancel_requested_{false};
|
||||
@@ -536,4 +587,4 @@ class GatewayKnxTpIpRouter {
|
||||
std::string last_error_;
|
||||
};
|
||||
|
||||
} // namespace gateway
|
||||
} // namespace gateway
|
||||
|
||||
Reference in New Issue
Block a user