esp-matter SDK 软件开发框架及目录结构介绍记录

ESP-Matter SDK 软件开发框架及目录结构介绍

 

 1. esp-matter/compoents

该目录为ESP-Matter 的核心功能组件,定义了相应基本matter的数据模型

esp-matter/components/
├── esp_matter
├── esp_matter_bridge
├── esp_matter_console
├── esp_matter_identify
├── esp_matter_openthread
├── esp_matter_ota
├── esp_matter_rainmaker
└── route_hook

1.1 components/esp_matter 组件

esp_matter 组件主要针对基本matter 设备类型的数据模型定义

esp-matter/components/esp_matter/
├── CMakeLists.txt
├── esp_matter_attribute.cpp
├── esp_matter_attribute.h
├── esp_matter_attribute_utils.cpp
├── esp_matter_attribute_utils.h
├── esp_matter_client.cpp
├── esp_matter_client.h
├── esp_matter_cluster.cpp
├── esp_matter_cluster.h
├── esp_matter_command.cpp
├── esp_matter_command.h
├── esp_matter_core.cpp
├── esp_matter_core.h
├── esp_matter_endpoint.cpp
├── esp_matter_endpoint.h
├── esp_matter_event.cpp
├── esp_matter_event.h
├── esp_matter_feature.cpp
├── esp_matter_feature.h
├── esp_matter.h
└── zap_common

esp_matter_core 定义

在 esp_matter_core.cpp 中详细的定义了 node 数据模型的构建过程,如下图所示该文件提供了 node、endpoint、commd、attribute 等数据结构的定义。以及展示了如何创建一个原始的 node,在此文件中有详细的说明。

 在 esp_matter_core.cpp 还定义了matter 协议栈的运行入口和初始化接口以及恢复出长重置接口等

esp_err_t start(event_callback_t callback)
{
    esp_err_t err = chip_init(callback);
    if (err != ESP_OK) {
        ESP_LOGE(TAG, "Error initializing matter");
    }
    return err;
}

esp_err_t factory_reset()
{
    esp_err_t err = ESP_OK;
    node_t *node = node::get();
    if (node) {
        /* ESP Matter data model is used. Erase all the data that we have added in nvs. */
        endpoint_t *endpoint = endpoint::get_first(node);
        while (endpoint) {
            uint16_t endpoint_id = endpoint::get_id(endpoint);
            char nvs_namespace[16] = {0};
            snprintf(nvs_namespace, 16, "endpoint_%X", endpoint_id); /* endpoint_id */

            nvs_handle_t handle;
            err = nvs_open_from_partition(ESP_MATTER_NVS_PART_NAME, nvs_namespace, NVS_READWRITE, &handle);
            if (err != ESP_OK) {
                ESP_LOGE(TAG, "Error opening partition: %s, %d", nvs_namespace, err);
                continue;
            }
            err = nvs_erase_all(handle);
            if (err != ESP_OK) {
                ESP_LOGE(TAG, "Error erasing partition: %s, %d", nvs_namespace, err);
                continue;
            }
            endpoint = endpoint::get_next(endpoint);
        }
        if (err == ESP_OK) {
            ESP_LOGI(TAG, "Erasing attribute data completed");
        }
    }

    /* Submodule factory reset. This also restarts after completion. */
    ConfigurationMgr().InitiateFactoryReset();
    return err;
}

esp_matter_endpoint 定义

esp_matter_endpoint.h 文件中有不同设备类型的配置以及相应的 creat 函数,不同设备类型 endpiont 的 creat 函数要求传入node 指针,creat 函数会创建出一个 endpiont , 并且将该 endpiont 添加到 node 的数据结构当中,最终被esp_matter 的SDK 管理起来。

namespace color_temperature_light {
typedef struct config {
    cluster::identify::config_t identify;
    cluster::groups::config_t groups;
    cluster::scenes::config_t scenes;
    cluster::on_off::config_t on_off;
    cluster::level_control::config_t level_control;
    cluster::color_control::config_t color_control; //色温灯相关的功能簇
} config_t;

uint32_t get_device_type_id();
endpoint_t *create(node_t *node, config_t *config, uint8_t flags);
} /* color_temperature_light */

 esp_matter_cluster定义

esp_matter_cluster.c/esp_matter_cluster.c 文件定义了 不同功能类型的cluster 的定义,不同设备类型 cluster 的 creat 函数要求传入endpoint 指针,creat 函数会创建出一个 cluster , 并且将该 cluster 添加到 endpoint 的数据结构当中,最终被esp_matter 的SDK 管理起来。

namespace level_control {
typedef struct config {
    uint16_t cluster_revision;
    uint8_t current_level;
    uint8_t on_level;
    uint8_t options;
    feature::lighting::config_t lighting;
    config() : cluster_revision(5), current_level(0), on_level(1), options(0) {}
} config_t;

cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_t features);
} /* level_control */

namespace color_control {
typedef struct config {
    uint16_t cluster_revision; 
    uint8_t color_mode; //基本功能点
    uint8_t color_control_options;
    uint8_t enhanced_color_mode;
    uint16_t color_capabilities;
    feature::hue_saturation::config_t hue_saturation; //若需附加的功能,可选择此处的可选feature进行添加
    feature::color_temperature::config_t color_temperature;
    feature::xy::config_t xy;
    feature::enhanced_hue::config_t enhanced_hue;
    feature::color_loop::config_t color_loop;
    config() : cluster_revision(5), color_mode(1), color_control_options(0), enhanced_color_mode(1),
               color_capabilities(0) {} //结构体构造初始化赋值
} config_t;

cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_t features);
} /* color_control */

attribute、feature/command

每个Cluster 内都有自己的 Attribute 和 Command, Attribute表示可以读取或写入的内容, Command 代表触发 Cluster进行某种行为的能力, feature 代表某些cluster的附加功能,attribute、feature/command 等数据模型的定义和 endpoint和 cluster机制类似。

esp_matter_attribute_utils定义

esp_matter_attribute_utils 文件定义了 esp_matter SDK中经常使用到的 结构体的数据类型

1.2 components/esp_matter_bridge 组件

esp-matter/components/esp_matter_bridge/
├── CMakeLists.txt
├── esp_matter_bridge.cpp
└── esp_matter_bridge.h

esp_matter_bridge 组件主要针对 bridge 设备类型提供相关API 去创建桥接节点。

1.3 components/esp_matter_console 组件

esp-matter/components/esp_matter_console/
├── CMakeLists.txt
├── esp_matter_console.cpp
├── esp_matter_console_diagnostics.cpp
├── esp_matter_console.h
└── Kconfig

esp_matter_console 组件提供初始化 matter console (通过串口进行相关的命令交互)

2. esp-matter/connectedhomeip

esp-matter/connectedhomeip/
└── connectedhomeip
    ├── build
    ├── BUILD.gn
    ├── build_overrides
    ├── CODE_OF_CONDUCT.md
    ├── config
    ├── CONTRIBUTING.md
    ├── credentials
    ├── docs
    ├── examples
    ├── gn_build.sh
    ├── integrations
    ├── lgtm.yml
    ├── LICENSE
    ├── README.md
    ├── REVIEWERS.md
    ├── scripts
    ├── src
    ├── third_party
    └── zzz_generated

该文件夹为 chip sdk 源目录,之前讲过esp-matter 是在 chip sdk 的基础上来完成数据模型的封装,因此在esp-matter sdk 中将 chip sdk 作为一个submodule 包含进来。

开发过程中侧重关注以下几个目录文件:

esp-matter/connectedhomeip/connectedhomeip/docs/guides/

该目录文件为chip sdk 相关操作文档指南

esp-matter/connectedhomeip/connectedhomeip/docs/guides/
├── access-control-guide.md
├── android_building.md
├── BUILDING.md
├── chip_tool_guide.md //chip_tool操作文档
├── images
├── infineon_p6_software_update.md
├── ip_commissioning.md
├── matter-repl.md
├── mbedos_add_new_target.md
├── mbedos_commissioning.md
├── mbedos_platform_overview.md
├── nrfconnect_android_commissioning.md
├── nrfconnect_examples_cli.md
├── nrfconnect_examples_configuration.md
├── nrfconnect_examples_software_update.md
├── nrfconnect_factory_data_configuration.md
├── nrfconnect_platform_overview.md
├── nxp_imx8m_linux_examples.md
├── nxp_k32w_android_commissioning.md
├── openthread_border_router_pi.md
├── openthread_rcp_nrf_dongle.md
├── python_chip_controller_advanced_usage.md
├── python_chip_controller_building.md
├── repl
├── silabs_efr32_building.md
├── silabs_efr32_software_update.md
├── simulated_device_linux.md
├── ti_platform_overview.md
└── troubleshooting_avahi.md

2 directories, 27 files

esp-matter/connectedhomeip/connectedhomeip/config/esp32/

该目录文件为乐鑫平台为适配 chip sdk 所开发的配置相关文件。

esp-matter/connectedhomeip/connectedhomeip/config/esp32/
├── args.gni
├── build -> third_party/connectedhomeip/build
├── BUILD.gn
├── build_overrides -> ../../examples/build_overrides
├── components
├── firmware_rom
├── lib
├── mbedtls
├── third_party
└── toolchain

8 directories, 2 files

esp-matter/connectedhomeip/connectedhomeip/src/platform/ESP32/

该目录为 ESP32 芯片平台的支持和相关初始化适配工作,包含 WiFi、ble的初始化和WiFi的连接、ble广播如何工作等相关操作由 chip sdk 统一管理调度。

esp-matter/connectedhomeip/connectedhomeip/src/platform/ESP32/
├── BLEManagerImpl.h
├── BlePlatformConfig.h
├── bluedroid
├── BUILD.gn
├── CHIPDevicePlatformConfig.h
├── CHIPDevicePlatformEvent.h
├── CHIPPlatformConfig.h
├── ConfigurationManagerImpl.cpp
├── ConfigurationManagerImpl.h
├── ConnectivityManagerImpl.cpp
├── ConnectivityManagerImpl.h
├── ConnectivityManagerImpl_WiFi.cpp
├── DeviceInfoProviderImpl.cpp
├── DeviceInfoProviderImpl.h
├── DeviceNetworkProvisioningDelegateImpl.cpp
├── DeviceNetworkProvisioningDelegateImpl.h
├── DiagnosticDataProviderImpl.cpp
├── DiagnosticDataProviderImpl.h
├── DnssdImpl.cpp
├── DnssdImpl.h
├── ESP32Config.cpp
├── ESP32Config.h
├── ESP32FactoryDataProvider.cpp
├── ESP32FactoryDataProvider.h
├── ESP32Utils.cpp
├── ESP32Utils.h
├── InetPlatformConfig.h
├── KeyValueStoreManagerImpl.cpp
├── KeyValueStoreManagerImpl.h
├── Logging.cpp
├── LwIPCoreLock.cpp
├── NetworkCommissioningDriver.cpp
├── NetworkCommissioningDriver.h
├── nimble
├── OpenthreadConfig.h
├── OpenthreadLauncher.c
├── OpenthreadLauncher.h
├── OTAImageProcessorImpl.cpp
├── OTAImageProcessorImpl.h
├── PlatformManagerImpl.cpp
├── PlatformManagerImpl.h
├── ScopedNvsHandle.h
├── SystemPlatformConfig.h
├── SystemTimeSupport.cpp
├── SystemTimeSupport.h
├── ThreadStackManagerImpl.cpp
├── ThreadStackManagerImpl.h
└── WarmPlatformConfig.h

2 directories, 46 files

3. esp-matter/device_hal

该文件夹包含乐鑫提供的部分设备外设驱动。

4. esp-matter/example

该文件夹为乐鑫matter 相关demo 程序,可用于快速构建相关示例功能。

esp-matter/examples/
├── blemesh_bridge
├── common
├── light
├── light_switch
├── rainmaker_light
├── zap_light
└── zigbee_bridge

7 directories, 0 files

5. esp-matter/tools

该目录为量产工具相关配置文件,量产工具可以生成烧录所需的固件、matter的设备证书以及一些应用的配置。

esp-matter/tools
├── ci
│   └── format_all.sh
└── mfg_tool
    ├── chip_nvs_keys.py
    ├── mfg_tool.py
    ├── README.md
    └── requirements.txt

2 directories, 5 files

 

转载:https://blog.csdn.net/weixin_40209493/article/details/128645745

posted @ 2023-04-13 16:25  K_Code  阅读(283)  评论(0编辑  收藏  举报