Files
gateway/components/gateway_knx/src/ets_memory_loader.cpp
T
Tony e79223c87e Refactor KNX DALI Gateway Configuration and Update Device Parameters
- Introduced configuration macros for OEM manufacturer ID, application number, and application version in knxprod.h.
- Updated product identity definitions to use the new configuration macros.
- Modified device type enumeration to include additional device types.
- Adjusted color space enumeration values for consistency.
- Defined generated group object layout constants for memory offsets and block sizes.
- Enhanced knx_dali_gw.cpp to utilize the new configuration macros for manufacturer ID and program version.
- Updated the device initialization logic to reflect the new hardware and program version structures.
- Removed obsolete knx_dali_gw subproject and updated related submodules.

Signed-off-by: Tony <tonylu@tony-cloud.com>
2026-05-16 01:51:01 +08:00

76 lines
2.7 KiB
C++

#include "ets_memory_loader.h"
#include "esp_idf_platform.h"
#include "gateway_knx_internal.h"
#include "knx/bau07B0.h"
#include "knx/property.h"
#include <algorithm>
#include <cstdint>
#include <memory>
namespace gateway::openknx {
namespace {
void CollectAssociation(uint16_t group_address, uint16_t group_object_number,
void* context) {
auto* associations = static_cast<std::vector<EtsAssociation>*>(context);
if (associations == nullptr) {
return;
}
associations->push_back(EtsAssociation{group_address, group_object_number});
}
bool IsErasedMemory(const uint8_t* data, size_t size) {
if (data == nullptr) {
return false;
}
return std::all_of(data, data + size, [](uint8_t value) { return value == 0xff; });
}
void ApplyReg1DaliIdentity(Bau07B0& device, EspIdfPlatform& platform) {
device.deviceObject().manufacturerId(knx_internal::kReg1DaliManufacturerId);
device.deviceObject().bauNumber(platform.uniqueSerialNumber());
device.deviceObject().hardwareType(knx_internal::kReg1DaliHardwareType);
device.deviceObject().orderNumber(knx_internal::kReg1DaliOrderNumber);
device.parameters().property(PID_PROG_VERSION)->write(
knx_internal::kReg1DaliProgramVersion);
}
} // namespace
EtsMemorySnapshot LoadEtsMemorySnapshot(const std::string& nvs_namespace) {
EspIdfPlatform platform(nullptr, nvs_namespace.c_str());
EtsMemorySnapshot snapshot;
const uint8_t* memory = platform.getNonVolatileMemoryStart();
const size_t memory_size = platform.getNonVolatileMemorySize();
if (memory == nullptr || memory_size == 0 || IsErasedMemory(memory, memory_size)) {
return snapshot;
}
auto device = std::make_unique<Bau07B0>(platform);
ApplyReg1DaliIdentity(*device, platform);
device->readMemory();
snapshot.configured = device->configured();
snapshot.individual_address = device->deviceObject().individualAddress();
device->forEachEtsAssociation(CollectAssociation, &snapshot.associations);
std::sort(snapshot.associations.begin(), snapshot.associations.end(),
[](const EtsAssociation& lhs, const EtsAssociation& rhs) {
if (lhs.group_address != rhs.group_address) {
return lhs.group_address < rhs.group_address;
}
return lhs.group_object_number < rhs.group_object_number;
});
snapshot.associations.erase(
std::unique(snapshot.associations.begin(), snapshot.associations.end(),
[](const EtsAssociation& lhs, const EtsAssociation& rhs) {
return lhs.group_address == rhs.group_address &&
lhs.group_object_number == rhs.group_object_number;
}),
snapshot.associations.end());
return snapshot;
}
} // namespace gateway::openknx