6d0b36b60a
- Introduced `NativeChannelConfig` and `SerialChannelConfig` functions to streamline the creation of `ChannelBindingConfig` instances. - Replaced manual channel configuration with macros `GATEWAY_CONFIGURE_NATIVE_CHANNEL` and `GATEWAY_CONFIGURE_SERIAL_CHANNEL` for better maintainability. - Updated `BuildChannelBindings` to utilize the new configuration functions, reducing redundancy. - Enhanced `ValidateChannelBindings` to check for required TX and RX GPIO pins for native channels. - Simplified `BindConfiguredChannels` to iterate over the built channel bindings, improving readability and reducing code duplication. - Adjusted the handling of reserved UART ports in `app_main` to dynamically include all serial channels. - Updated SDK configuration for channel 1 gateway ID and modified KNX-related configurations for enhanced functionality. - Removed obsolete NVS flash initialization code and replaced it with a more streamlined approach for managing runtime data. - Added a new command in `GatewayController` to publish gateway IDs when requested. - Defined a constant for maximum KNX instance count to improve clarity in the codebase. Signed-off-by: Tony <tonylu@tony-cloud.com>
147 lines
5.0 KiB
C++
147 lines
5.0 KiB
C++
#pragma once
|
|
|
|
// Internal helpers and product identity shared by gateway_knx component sources.
|
|
|
|
#include "driver/uart.h"
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/semphr.h"
|
|
#include "sdkconfig.h"
|
|
#include "soc/uart_periph.h"
|
|
|
|
#include <cstdint>
|
|
#include <string>
|
|
|
|
namespace gateway {
|
|
namespace knx_internal {
|
|
|
|
constexpr const char* kTag = "gateway_knx";
|
|
|
|
#ifndef CONFIG_GATEWAY_KNX_OEM_MANUFACTURER_ID
|
|
#define CONFIG_GATEWAY_KNX_OEM_MANUFACTURER_ID 0x00A4
|
|
#endif
|
|
|
|
#ifndef CONFIG_GATEWAY_KNX_OEM_APPLICATION_NUMBER
|
|
#define CONFIG_GATEWAY_KNX_OEM_APPLICATION_NUMBER 0x0001
|
|
#endif
|
|
|
|
#ifndef CONFIG_GATEWAY_KNX_OEM_APPLICATION_VERSION
|
|
#define CONFIG_GATEWAY_KNX_OEM_APPLICATION_VERSION 0x08
|
|
#endif
|
|
|
|
#ifndef CONFIG_GATEWAY_KNX_OEM_HARDWARE_ID
|
|
#define CONFIG_GATEWAY_KNX_OEM_HARDWARE_ID 0xA401
|
|
#endif
|
|
|
|
#ifndef CONFIG_GATEWAY_KNX_OAM_ROUTER_OEM_MANUFACTURER_ID
|
|
#define CONFIG_GATEWAY_KNX_OAM_ROUTER_OEM_MANUFACTURER_ID 0x00FA
|
|
#endif
|
|
|
|
#ifndef CONFIG_GATEWAY_KNX_OAM_ROUTER_APPLICATION_NUMBER
|
|
#define CONFIG_GATEWAY_KNX_OAM_ROUTER_APPLICATION_NUMBER 0xA11F
|
|
#endif
|
|
|
|
#ifndef CONFIG_GATEWAY_KNX_OAM_ROUTER_APPLICATION_VERSION
|
|
#define CONFIG_GATEWAY_KNX_OAM_ROUTER_APPLICATION_VERSION 0x07
|
|
#endif
|
|
|
|
#ifndef CONFIG_GATEWAY_KNX_OAM_ROUTER_HARDWARE_ID
|
|
#define CONFIG_GATEWAY_KNX_OAM_ROUTER_HARDWARE_ID 0x0001
|
|
#endif
|
|
|
|
inline constexpr uint16_t kReg1DaliManufacturerId =
|
|
static_cast<uint16_t>(CONFIG_GATEWAY_KNX_OEM_MANUFACTURER_ID);
|
|
inline constexpr uint16_t kReg1DaliHardwareId =
|
|
static_cast<uint16_t>(CONFIG_GATEWAY_KNX_OEM_HARDWARE_ID);
|
|
inline constexpr uint16_t kReg1DaliApplicationNumber =
|
|
static_cast<uint16_t>(CONFIG_GATEWAY_KNX_OEM_APPLICATION_NUMBER);
|
|
inline constexpr uint8_t kReg1DaliApplicationVersion =
|
|
static_cast<uint8_t>(CONFIG_GATEWAY_KNX_OEM_APPLICATION_VERSION);
|
|
inline constexpr uint8_t kReg1DaliHardwareType[6] = {
|
|
0x00,
|
|
0x00,
|
|
static_cast<uint8_t>((kReg1DaliHardwareId >> 8) & 0xff),
|
|
static_cast<uint8_t>(kReg1DaliHardwareId & 0xff),
|
|
kReg1DaliApplicationVersion,
|
|
0x00};
|
|
inline constexpr uint8_t kReg1DaliOrderNumber[10] = {
|
|
'R', 'E', 'G', '1', '-', 'D', 'a', 'l', 'i', 0};
|
|
inline constexpr uint8_t kReg1DaliProgramVersion[5] = {
|
|
static_cast<uint8_t>((kReg1DaliManufacturerId >> 8) & 0xff),
|
|
static_cast<uint8_t>(kReg1DaliManufacturerId & 0xff),
|
|
static_cast<uint8_t>((kReg1DaliApplicationNumber >> 8) & 0xff),
|
|
static_cast<uint8_t>(kReg1DaliApplicationNumber & 0xff),
|
|
kReg1DaliApplicationVersion};
|
|
|
|
inline constexpr uint32_t kDaliMaxKnxInstanceCount = 16;
|
|
inline constexpr uint32_t kReg1DaliSerialMacIncrement = 0;
|
|
inline constexpr uint32_t kOamRouterSerialMacIncrement = kDaliMaxKnxInstanceCount;
|
|
inline constexpr uint16_t kOamRouterDeviceDescriptor = 0x091A;
|
|
inline constexpr uint16_t kOamRouterManufacturerId =
|
|
static_cast<uint16_t>(CONFIG_GATEWAY_KNX_OAM_ROUTER_OEM_MANUFACTURER_ID);
|
|
inline constexpr uint16_t kOamRouterHardwareId =
|
|
static_cast<uint16_t>(CONFIG_GATEWAY_KNX_OAM_ROUTER_HARDWARE_ID);
|
|
inline constexpr uint16_t kOamRouterApplicationNumber =
|
|
static_cast<uint16_t>(CONFIG_GATEWAY_KNX_OAM_ROUTER_APPLICATION_NUMBER);
|
|
inline constexpr uint8_t kOamRouterApplicationVersion =
|
|
static_cast<uint8_t>(CONFIG_GATEWAY_KNX_OAM_ROUTER_APPLICATION_VERSION);
|
|
inline constexpr uint8_t kOamRouterHardwareType[6] = {
|
|
0x00,
|
|
0x00,
|
|
static_cast<uint8_t>((kOamRouterHardwareId >> 8) & 0xff),
|
|
static_cast<uint8_t>(kOamRouterHardwareId & 0xff),
|
|
kOamRouterApplicationVersion,
|
|
0x00};
|
|
inline constexpr uint8_t kOamRouterOrderNumber[10] = {
|
|
'I', 'P', '-', 'R', 'o', 'u', 't', 'e', 'r', 0};
|
|
inline constexpr uint8_t kOamRouterProgramVersion[5] = {
|
|
static_cast<uint8_t>((kOamRouterManufacturerId >> 8) & 0xff),
|
|
static_cast<uint8_t>(kOamRouterManufacturerId & 0xff),
|
|
static_cast<uint8_t>((kOamRouterApplicationNumber >> 8) & 0xff),
|
|
static_cast<uint8_t>(kOamRouterApplicationNumber & 0xff),
|
|
kOamRouterApplicationVersion};
|
|
|
|
// RAII semaphore guard.
|
|
class SemaphoreGuard {
|
|
public:
|
|
explicit SemaphoreGuard(SemaphoreHandle_t semaphore) : semaphore_(semaphore) {
|
|
if (semaphore_ != nullptr) {
|
|
xSemaphoreTake(semaphore_, portMAX_DELAY);
|
|
locked_ = true;
|
|
}
|
|
}
|
|
~SemaphoreGuard() {
|
|
if (locked_) {
|
|
xSemaphoreGive(semaphore_);
|
|
}
|
|
}
|
|
private:
|
|
SemaphoreHandle_t semaphore_{nullptr};
|
|
bool locked_{false};
|
|
};
|
|
|
|
// Resolve a UART IO pin from config or SoC defaults.
|
|
inline bool ResolveUartIoPin(uart_port_t uart_port, int configured_pin,
|
|
uint32_t pin_index, int* resolved_pin) {
|
|
if (resolved_pin == nullptr) return false;
|
|
if (configured_pin >= 0) {
|
|
*resolved_pin = configured_pin;
|
|
return true;
|
|
}
|
|
if (uart_port < 0 || uart_port >= SOC_UART_NUM ||
|
|
pin_index >= SOC_UART_PINS_COUNT) {
|
|
*resolved_pin = UART_PIN_NO_CHANGE;
|
|
return false;
|
|
}
|
|
const int default_pin =
|
|
uart_periph_signal[uart_port].pins[pin_index].default_gpio;
|
|
if (default_pin < 0) {
|
|
*resolved_pin = UART_PIN_NO_CHANGE;
|
|
return false;
|
|
}
|
|
*resolved_pin = default_pin;
|
|
return true;
|
|
}
|
|
|
|
} // namespace knx_internal
|
|
} // namespace gateway
|