ZCL Advanced Platform (ZAP) 是以 Matter 叢集為基礎的 node.js 範本引擎。
ZAP 為 Matter 應用程式和 SDK 提供下列功能:
- 透過 GUI 介面設定 Matter 端點、叢集、屬性和其他裝置功能。
- 建立會自動產生資料模型定義、回呼和其他 Matter 原始碼的範本。
- 建立並使用預先設定的 ZAP 檔案,以便納入您的 SDK。
![ZAP 工具](https://developers.home.google.com/static/tools/images/zap-overview.png?authuser=0&hl=zh-tw)
安裝
前往 ZAP 版本頁面。
找出標記「最新」的版本 (大多會標記為「預先發布版」)。
在這個版本的「Assets」標題下方,選取並下載適用於您作業系統的套件。
在執行 Debian 或 Ubuntu 的機器上,請執行下列指令安裝 ZAP:
sudo dpkg -i path/to/zap_installation_package
在 Debian 或 Ubuntu Linux 上,zap
二進位檔會安裝在 /usr/bin/
中。二進位檔在其他作業系統上,則可能會在其他位置安裝。無論如何,請務必檢查執行檔的位置是否位於 PATH
環境變數中。
ZAP 檔案
ZAP 使用的範本檔案稱為 ZAP 檔案。ZAP 檔案是定義端點、指令、屬性和其他裝置功能的 JSON 檔案。ZAP 檔案的名稱結尾為 .zap
。例如 connectedhomeip/examples/lighting-app/lighting-common
中的 lighting-app.zap
。
connectedhomeip/examples/all-clusters-app/all-clusters-common
中的 all-clusters-app.zap
檔案已預先設定常見的 Matter 叢集和三個端點,包括 Matter 次要網路封包裝置類型。這個例子非常適合探索各種叢集設定。
執行
- 從其中一個 Matter 範例中選擇 ZAP 檔案。
- 在 Matter 存放區 (
connectedhomeip
) 的根目錄中執行run_zaptool.sh
包裝函式指令碼,將路徑傳遞至.zap
檔案。
例如:
./scripts/tools/zap/run_zaptool.sh ./examples/lighting-app/lighting-common/lighting-app.zap
設定
您可以在
「設定」中設定 ZAP 使用者介面 (包括選擇淺色或深色主題),以及啟用或停用開發人員工具。按一下
「Options」(選項) 可讓您選取「產品製造商」和「Default Response Policy」,以及啟用或停用指令探索功能。![ZAP 通用選項](https://developers.home.google.com/static/tools/images/zap-global-options.png?authuser=0&hl=zh-tw)
按一下
「擴充功能」,將自訂 ZCL 叢集或指令新增至 Zigbee 叢集設定器。使用
端點
lighting-app.zap
檔案已預先設定具有 Matter 根節點 (端點 - 0) 和 Matter 可調光燈 (端點 - 1)。
Endpoint - 0:包含與整個節點相關的一般叢集,例如網路、調試、描述元、作業憑證和 OTA 叢集。
![ZAP 端點 0](https://developers.home.google.com/static/tools/images/zap-endpoint-0.png?authuser=0&hl=zh-tw)
在後續步驟中,您會查看及設定「Endpoint - 1」。
Matter 從範例 lighting-app
中可調光燈。
從 Matter 存放區
connectedhomeip
執行 ZAP。scripts/tools/zap/run_zaptool.sh \ examples/lighting-app/lighting-common/lighting-app.zap
依序按一下「Endpoint - 1」和「
EDIT」。選用: Matter 支援多種裝置類型。在「Device」(裝置) 下拉式選單中開始輸入
matter
即可變更裝置,然後按一下「SAVE」(儲存)。
詳情請參閱 Matter Primer 中的裝置和端點。
叢集
根據預設,端點 - 1 會啟用預先定義的叢集、屬性和報表選項。
如果只要顯示已啟用的叢集,請按一下「Endpoint - 1」,然後從「Show」選單中選取「Enabled Clusters」。您也可以依名稱搜尋 on
。
![已啟用 ZAP 的叢集](https://developers.home.google.com/static/tools/images/zap-enabled-clusters.png?authuser=0&hl=zh-tw)
如要將任何叢集啟用為「用戶端」、「伺服器」或「用戶端與伺服器」,請使用「啟用」下拉式選單。您也可以選取「Not Enabled」,停用不適用於裝置類型的預先設定叢集。
![ZAP 停用叢集](https://developers.home.google.com/static/tools/images/zap-disable-cluster.png?authuser=0&hl=zh-tw)
詳情請參閱 Matter Primer 中的叢集。
屬性和指令
如要設定屬性和指令,請完成下列步驟:
- 找出
On/Off
叢集。 在同一列中按一下「設定」圖示
。
您可以在此啟用或停用屬性、設定各種屬性選項,以及依名稱的「SearchAttributes」
。![ZAP 屬性](https://developers.home.google.com/static/tools/images/zap-attributes.png?authuser=0&hl=zh-tw)
點選「指令」即可設定這個叢集的動作。舉例來說,燈具的「On/off」叢集會包含「On」、「Off」和「Toggle」指令。某些叢集 (例如 Temperature Measurement
叢集) 可能沒有相關聯的指令。
![ZAP 指令](https://developers.home.google.com/static/tools/images/zap-commands.png?authuser=0&hl=zh-tw)
詳情請參閱 Matter Primer 中的屬性和指令。
產生 ZAP 來源檔案
Matter 範例使用 ZAP 產生的原始碼,可在 connectedhomeip/zzz_generated
目錄中取得。有些檔案僅適用於應用程式,而其他一般 ZAP 檔案則會歸入 app-common
群組。
#include <app-common/zap-generated/ids/Attributes.h>
#include <app-common/zap-generated/ids/Clusters.h>
設定端點後,您可以產生來源檔案,以便整合至專案中。
- 按一下「產生」圖示 。
- 選取要儲存 ZAP 輸出內容的資料夾。例如,前往
connectedhomeip/zzz_generated/lighting-app/zap-generated
以取得lighting-app
。 - (選用) 在想用的 IDE 中開啟檔案。
ZAP 會產生定義、函式和其他依裝置類型和 ZAP 設定自訂的原始碼。
![ZAP 產生的檔案](https://developers.home.google.com/static/tools/images/zap-gen.png?authuser=0&hl=zh-tw)
舉例來說,callback-stub.cpp
中的叢集回呼方法僅包含已啟用的叢集:
void emberAfClusterInitCallback(EndpointId endpoint, ClusterId clusterId)
{
switch (clusterId)
{
...
case ZCL_ON_OFF_CLUSTER_ID :
emberAfOnOffClusterInitCallback(endpoint);
break;
...
}
}
使用 ZAP 來源檔案
常見的 ZAP 來源檔案 (例如 zzz_generated/app-common/app-common/zap-generated/ids/
中的 Attributes.h
) 可用來取得及設定裝置類型屬性:
Attributes.h
namespace DeviceTemperatureConfiguration {
namespace Attributes {
namespace CurrentTemperature {
static constexpr AttributeId Id = 0x00000000;
} // namespace CurrentTemperature
...
} // namespace Attributes
} // namespace DeviceTemperatureConfiguration
main.cpp
#include <app-common/zap-generated/att-storage.h>
#include <app-common/zap-generated/attribute-id.h>
#include <app-common/zap-generated/attribute-type.h>
#include <app-common/zap-generated/attributes/Accessors.h>
#include <app-common/zap-generated/callback.h>
#include <app-common/zap-generated/cluster-id.h>
#include <app-common/zap-generated/cluster-objects.h>
#include <app-common/zap-generated/command-id.h>
using namespace ::chip;
using namespace ::chip::app::Clusters;
static void InitServer(intptr_t context)
{
...
// Sets temperature to 20C
int16_t temperature = 2000;
auto status = DeviceTemperatureConfiguration::Attributes::CurrentTemperature::Set(1, temperature);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
ChipLogError(Shell, "Temp measurement set failed");
}
}
瞭解在 Matter 原始碼中如何使用 ZAP 檔案後,可以透過下列幾種方式整合 ZAP:
- 使用現有的
zzz_generated
檔案,建立專屬於裝置類型的新範例。 - 為專案建立自訂
.zap
檔案。
自訂
ZAP 檔案是根據 ZAP 範本產生。使用 run_zaptool.sh
啟動 ZAP 時,這個指令碼會傳入下列範本:
node src-script/zap-start.js --logToStdout \
--gen "$CHIP_ROOT/src/app/zap-templates/app-templates.json" \
--zcl "$CHIP_ROOT/src/app/zap-templates/zcl/zcl.json" \
"${ZAP_ARGS[@]}"
templates.json
會定義 Matter 範本名稱以及 Matter 範例中使用的對應輸出檔案。
{
"path": "templates/app/callback-stub-src.zapt",
"name": "ZCL callback-stub source",
"output": "callback-stub.cpp"
}
如要自訂 Matter 解決方案,您可以在使用 ZAP 時採取下列幾個步驟:
- 建立 ZAP 範本。
- 將 ZAP 整合到您的 SDK。
資源
如需其他 ZAP 資源,請參閱 GitHub 上的 ZAP 存放區 (zap
)。