chip-tool 工具可用于调试 matter 设备,是matter协议新兴起时所使用的重要工具,由于资料都是英文 的很不友好,因此本文根据官方教程和自己的理解整理如下,本文主要介绍 chip-tool 常用的一些命令。
关于 使用 chip-tool 工具测试matter设备步骤,请参考博文:
【使用 chip-tool 工具测试matter设备步骤】
1. chip-tool 常用命令
1.1. 工作模式
有 【交互模式】和 【单命令模式】两种,Interactive mode
和 single command mode
,默认情况下 chip-tool 是单命令模式,若单命令模式下某条指令在一定时间周期内为完成, chip-tool 将会报错时间超时,比如报错信息:
[1650992689511] [32397:1415601] CHIP: [TOO] Run command failure: ../../../examples/chip-tool/commands/common/CHIPCommand.cpp:392: CHIP Error 0x00000032: Timeout
通过提供可选的–timeout参数,可以修改任何命令执行的超时,该参数以秒为单位,最大值为65535秒。
$ ./chip-tool otasoftwareupdaterequestor subscribe-event state-transition 5 10 0x1234567890 0 --timeout 65535
对于需要长时间运行的命令(如事件订阅),可以在运行命令之前先以交互模式启动芯片工具。在交互模式下,不会有超时,可以发出多个命令。
$ ./chip-tool interactive start
otasoftwareupdaterequestor subscribe-event state-transition 5 10 ${NODE_ID} 0
1.2 打印所有支持的 cluster
$ ./chip-tool
# 输出
[1647346057.900626][394605:394605] CHIP:TOO: Missing cluster name
Usage:
./chip-tool cluster_name command_name [param1 param2 ...]
+-------------------------------------------------------------------------------------+
| Clusters: |
+-------------------------------------------------------------------------------------+
| * accesscontrol |
| * accountlogin |
| * administratorcommissioning |
| * alarms |
| * any |
| * appliancecontrol |
| * applianceeventsandalert |
| * applianceidentification |
| * appliancestatistics |
| * applicationbasic |
1.3 获取指定的 cluster 列表的命令
$ ./chip-tool <cluster_name>
cluster_name 是在上述的列表中的 cluster 的名称,比如
$ ./chip-tool onoff
# 输出
[1647417645.182824][404411:404411] CHIP:TOO: Missing command name
Usage:
./chip-tool onoff command_name [param1 param2 ...]
+-------------------------------------------------------------------------------------+
| Commands: |
+-------------------------------------------------------------------------------------+
| * command-by-id |
| * off |
| * on |
| * toggle |
| * off-with-effect |
| * on-with-recall-global-scene |
| * on-with-timed-off |
| * read-by-id |
| * read |
| * write-by-id |
| * write |
| * subscribe-by-id |
| * subscribe |
| * read-event-by-id |
| * subscribe-event-by-id |
+-------------------------------------------------------------------------------------+
[1647417645.183836][404411:404411] CHIP:TOO: Run command failure: ../../examples/chip-tool/commands/common/Commands.cpp:84: Error 0x0000002F
1.4 获取指定 cluster 的 attribute 列表
$ ./chip-tool <cluster_name> read
# 比如
$ ./chip-tool onoff read
#输出
[1647417857.913942][404444:404444] CHIP:TOO: Missing attribute name
Usage:
./chip-tool onoff read attribute-name [param1 param2 ...]
+-------------------------------------------------------------------------------------+
| Attributes: |
+-------------------------------------------------------------------------------------+
| * on-off |
| * global-scene-control |
| * on-time |
| * off-wait-time |
| * start-up-on-off |
| * server-generated-command-list |
| * client-generated-command-list |
| * attribute-list |
| * feature-map |
| * cluster-revision |
+-------------------------------------------------------------------------------------+
[1647417857.914110][404444:404444] CHIP:TOO: Run command failure: ../../examples/chip-tool/commands/common/Commands.cpp:120: Error 0x0000002F
1.5 获取命令选项列表
$ ./chip-tool <cluster_name> <target_command>
$ ./chip-tool onoff on
更多的命令请参考官方文档:【Working with the CHIP Tool】