Skip to content

Commit 4078924

Browse files
rgoliverpull[bot]
rgoliver
authored andcommitted
RPC: Add descriptor cluster and QR code (#15217)
* RPC: Add Descriptor RPC Service Add an RPC service for reading the descriptor cluster, this can be used by test harnesses to identify the device types and automatically select the correct tests to run. * RPC: Add QR Code to device service Add the QR code and QR code URL to the device RPC service.
1 parent 77718e9 commit 4078924

File tree

20 files changed

+246
-3
lines changed

20 files changed

+246
-3
lines changed

examples/all-clusters-app/esp32/main/CMakeLists.txt

+13
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,17 @@ pw_proto_library(button_service
160160
pw_protobuf.common_protos
161161
)
162162

163+
pw_proto_library(descriptor_service
164+
SOURCES
165+
${CHIP_ROOT}/examples/common/pigweed/protos/descriptor_service.proto
166+
PREFIX
167+
descriptor_service
168+
STRIP_PREFIX
169+
${CHIP_ROOT}/examples/common/pigweed/protos
170+
DEPS
171+
pw_protobuf.common_protos
172+
)
173+
163174
pw_proto_library(device_service
164175
SOURCES
165176
${CHIP_ROOT}/examples/common/pigweed/protos/device_service.proto
@@ -211,6 +222,7 @@ pw_proto_library(wifi_service
211222
target_link_libraries(${COMPONENT_LIB} PUBLIC
212223
attributes_service.nanopb_rpc
213224
button_service.nanopb_rpc
225+
descriptor_service.nanopb_rpc
214226
device_service.nanopb_rpc
215227
lighting_service.nanopb_rpc
216228
locking_service.nanopb_rpc
@@ -233,6 +245,7 @@ target_link_options(${COMPONENT_LIB}
233245
target_compile_options(${COMPONENT_LIB} PRIVATE
234246
"-DPW_RPC_ATTRIBUTE_SERVICE=1"
235247
"-DPW_RPC_BUTTON_SERVICE=1"
248+
"-DPW_RPC_DESCRIPTOR_SERVICE=1"
236249
"-DPW_RPC_DEVICE_SERVICE=1"
237250
"-DPW_RPC_LIGHTING_SERVICE=1"
238251
"-DPW_RPC_LOCKING_SERVICE=1"

examples/common/pigweed/BUILD.gn

+7
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ if (chip_enable_pw_rpc) {
5252
prefix = "device_service"
5353
}
5454

55+
pw_proto_library("descriptor_service") {
56+
sources = [ "protos/descriptor_service.proto" ]
57+
deps = [ "$dir_pw_protobuf:common_protos" ]
58+
strip_prefix = "protos"
59+
prefix = "descriptor_service"
60+
}
61+
5562
pw_proto_library("button_service") {
5663
sources = [ "protos/button_service.proto" ]
5764
deps = [ "$dir_pw_protobuf:common_protos" ]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
syntax = "proto3";
2+
3+
package chip.rpc;
4+
5+
import 'pw_protobuf_protos/common.proto';
6+
7+
message DeviceType {
8+
uint32 device_type = 1;
9+
}
10+
11+
message Cluster {
12+
uint32 cluster_id = 1;
13+
}
14+
15+
message Endpoint {
16+
uint32 endpoint = 1;
17+
}
18+
19+
service Descriptor {
20+
rpc DeviceTypeList(Endpoint) returns (stream DeviceType){}
21+
rpc ServerList(Endpoint) returns (stream Cluster){}
22+
rpc ClientList(Endpoint) returns (stream Cluster){}
23+
rpc PartsList(Endpoint) returns (stream Endpoint){}
24+
}
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
chip.rpc.DeviceInfo.serial_number max_size:32 // length defined in chip spec 8.2.3.1
2-
chip.rpc.DeviceState.fabric_info max_count:2
2+
chip.rpc.DeviceState.fabric_info max_count:2
3+
chip.rpc.PairingInfo.qr_code max_size:256
4+
chip.rpc.PairingInfo.qr_code_url max_size:256

examples/common/pigweed/protos/device_service.proto

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import 'pw_protobuf_protos/common.proto';
77
message PairingInfo {
88
uint32 code = 1;
99
uint32 discriminator = 2;
10+
string qr_code = 3;
11+
string qr_code_url = 4;
1012
}
1113

1214
// type lengths defined in chip spec 8.2.3.1
@@ -40,4 +42,5 @@ service Device {
4042
rpc GetDeviceState(pw.protobuf.Empty) returns (DeviceState){}
4143
rpc SetPairingState(PairingState) returns (pw.protobuf.Empty){}
4244
rpc GetPairingState(pw.protobuf.Empty) returns (PairingState){}
45+
rpc SetPairingInfo(PairingInfo) returns (pw.protobuf.Empty){}
4346
}

examples/common/pigweed/rpc_console/py/BUILD.gn

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ pw_python_package("chip_rpc") {
3838
"$dir_pw_rpc/py",
3939
"${chip_root}/examples/common/pigweed:attributes_service.python",
4040
"${chip_root}/examples/common/pigweed:button_service.python",
41+
"${chip_root}/examples/common/pigweed:descriptor_service.python",
4142
"${chip_root}/examples/common/pigweed:device_service.python",
4243
"${chip_root}/examples/common/pigweed:echo_service.python",
4344
"${chip_root}/examples/common/pigweed:lighting_service.python",

examples/common/pigweed/rpc_console/py/chip_rpc/console.py

+4
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@
3636
rpcs.chip.rpc.DeviceCommon.GetDeviceInfo()
3737
"""
3838

39+
import json
3940
import argparse
4041
from collections import namedtuple
4142
import logging
43+
import functools
4244
import sys
4345
from typing import Any, BinaryIO
4446
import socket
@@ -56,6 +58,7 @@
5658
# Protos
5759
from attributes_service import attributes_service_pb2
5860
from button_service import button_service_pb2
61+
from descriptor_service import descriptor_service_pb2
5962
from device_service import device_service_pb2
6063
from echo_service import echo_pb2
6164
from lighting_service import lighting_service_pb2
@@ -73,6 +76,7 @@
7376

7477
PROTOS = [attributes_service_pb2,
7578
button_service_pb2,
79+
descriptor_service_pb2,
7680
device_service_pb2,
7781
echo_pb2,
7882
lighting_service_pb2,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
*
3+
* Copyright (c) 2022 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#pragma once
20+
21+
#include "descriptor_service/descriptor_service.rpc.pb.h"
22+
23+
#include <app-common/zap-generated/af-structs.h>
24+
#include <app-common/zap-generated/cluster-objects.h>
25+
#include <app-common/zap-generated/ids/Attributes.h>
26+
#include <app-common/zap-generated/ids/Clusters.h>
27+
28+
namespace chip {
29+
namespace rpc {
30+
31+
class Descriptor : public pw_rpc::nanopb::Descriptor::Service<Descriptor>
32+
{
33+
public:
34+
virtual ~Descriptor() = default;
35+
36+
virtual void DeviceTypeList(const ::chip_rpc_Endpoint & request, ServerWriter<::chip_rpc_DeviceType> & writer)
37+
{
38+
constexpr uint16_t kInvalidEndpointIndex = 0xFFFF;
39+
uint16_t index = emberAfIndexFromEndpoint(request.endpoint);
40+
if (index == kInvalidEndpointIndex)
41+
{
42+
writer.Finish(pw::Status::InvalidArgument());
43+
return;
44+
}
45+
46+
chip_rpc_DeviceType out{ .device_type = emberAfDeviceIdFromIndex(index) };
47+
writer.Write(out);
48+
writer.Finish();
49+
}
50+
51+
void ServerList(const ::chip_rpc_Endpoint & request, ServerWriter<::chip_rpc_Cluster> & writer)
52+
{
53+
ClusterList(request.endpoint, true /*server*/, writer);
54+
}
55+
56+
void ClientList(const ::chip_rpc_Endpoint & request, ServerWriter<::chip_rpc_Cluster> & writer)
57+
{
58+
ClusterList(request.endpoint, false /*server*/, writer);
59+
}
60+
61+
void PartsList(const ::chip_rpc_Endpoint & request, ServerWriter<::chip_rpc_Endpoint> & writer)
62+
{
63+
if (request.endpoint == 0x00)
64+
{
65+
for (uint16_t index = 0; index < emberAfEndpointCount(); index++)
66+
{
67+
if (emberAfEndpointIndexIsEnabled(index))
68+
{
69+
EndpointId endpoint_id = emberAfEndpointFromIndex(index);
70+
if (endpoint_id == 0)
71+
continue;
72+
chip_rpc_Endpoint out{ endpoint : endpoint_id };
73+
writer.Write(out);
74+
}
75+
}
76+
}
77+
writer.Finish();
78+
}
79+
80+
private:
81+
void ClusterList(EndpointId endpoint, bool server, ServerWriter<::chip_rpc_Cluster> & writer)
82+
{
83+
uint16_t cluster_count = emberAfClusterCount(endpoint, server);
84+
85+
for (uint8_t cluster_index = 0; cluster_index < cluster_count; cluster_index++)
86+
{
87+
const EmberAfCluster * cluster = emberAfGetNthCluster(endpoint, cluster_index, server);
88+
chip_rpc_Cluster out{ cluster_id : cluster->clusterId };
89+
writer.Write(out);
90+
}
91+
writer.Finish();
92+
}
93+
};
94+
95+
} // namespace rpc
96+
} // namespace chip

examples/common/pigweed/rpc_services/Device.h

+11-2
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@
2020

2121
#include <platform/CHIPDeviceConfig.h>
2222

23+
#include "app/server/OnboardingCodesUtil.h"
2324
#include "app/server/Server.h"
2425
#include "credentials/FabricTable.h"
2526
#include "device_service/device_service.rpc.pb.h"
2627
#include "platform/ConfigurationManager.h"
28+
#include "platform/DiagnosticDataProvider.h"
2729
#include "platform/PlatformManager.h"
28-
#include <platform/DiagnosticDataProvider.h>
2930

3031
namespace chip {
3132
namespace rpc {
@@ -138,12 +139,20 @@ class Device : public pw_rpc::nanopb::Device::Service<Device>
138139
response.has_pairing_info = true;
139140
}
140141

141-
if (DeviceLayer::ConfigurationMgr().GetSerialNumber(response.serial_number, sizeof(response.serial_number)) !=
142+
if (DeviceLayer::ConfigurationMgr().GetSerialNumber(response.serial_number, sizeof(response.serial_number)) ==
142143
CHIP_NO_ERROR)
143144
{
144145
snprintf(response.serial_number, sizeof(response.serial_number), CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER);
145146
}
146147

148+
std::string qrCodeText;
149+
if (GetQRCode(qrCodeText, chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE)) == CHIP_NO_ERROR)
150+
{
151+
snprintf(response.pairing_info.qr_code, sizeof(response.pairing_info.qr_code), "%s", qrCodeText.c_str());
152+
GetQRCodeUrl(response.pairing_info.qr_code_url, sizeof(response.pairing_info.qr_code_url), qrCodeText);
153+
response.has_pairing_info = true;
154+
}
155+
147156
return pw::OkStatus();
148157
}
149158

examples/light-switch-app/efr32/BUILD.gn

+2
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ efr32_executable("light_switch_app") {
220220
"PW_RPC_ENABLED",
221221
"PW_RPC_ATTRIBUTE_SERVICE=1",
222222
"PW_RPC_BUTTON_SERVICE=1",
223+
"PW_RPC_DESCRIPTOR_SERVICE=1",
223224
"PW_RPC_DEVICE_SERVICE=1",
224225
"PW_RPC_LIGHTING_SERVICE=1",
225226
]
@@ -237,6 +238,7 @@ efr32_executable("light_switch_app") {
237238
"${chip_root}/config/efr32/lib/pw_rpc:pw_rpc",
238239
"${chip_root}/examples/common/pigweed:attributes_service.nanopb_rpc",
239240
"${chip_root}/examples/common/pigweed:button_service.nanopb_rpc",
241+
"${chip_root}/examples/common/pigweed:descriptor_service.nanopb_rpc",
240242
"${chip_root}/examples/common/pigweed:device_service.nanopb_rpc",
241243
"${chip_root}/examples/common/pigweed:lighting_service.nanopb_rpc",
242244
"${examples_plat_dir}/pw_sys_io:pw_sys_io_efr32",

examples/lighting-app/efr32/BUILD.gn

+2
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ efr32_executable("lighting_app") {
222222
"PW_RPC_ENABLED",
223223
"PW_RPC_ATTRIBUTE_SERVICE=1",
224224
"PW_RPC_BUTTON_SERVICE=1",
225+
"PW_RPC_DESCRIPTOR_SERVICE=1",
225226
"PW_RPC_DEVICE_SERVICE=1",
226227
"PW_RPC_LIGHTING_SERVICE=1",
227228
"PW_RPC_OTCLI_SERVICE=1",
@@ -241,6 +242,7 @@ efr32_executable("lighting_app") {
241242
"${chip_root}/config/efr32/lib/pw_rpc:pw_rpc",
242243
"${chip_root}/examples/common/pigweed:attributes_service.nanopb_rpc",
243244
"${chip_root}/examples/common/pigweed:button_service.nanopb_rpc",
245+
"${chip_root}/examples/common/pigweed:descriptor_service.nanopb_rpc",
244246
"${chip_root}/examples/common/pigweed:device_service.nanopb_rpc",
245247
"${chip_root}/examples/common/pigweed:lighting_service.nanopb_rpc",
246248
"${chip_root}/examples/common/pigweed:ot_cli_service.nanopb_rpc",

examples/lighting-app/linux/BUILD.gn

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ executable("chip-lighting-app") {
5454
"PW_RPC_ENABLED",
5555
"PW_RPC_ATTRIBUTE_SERVICE=1",
5656
"PW_RPC_BUTTON_SERVICE=1",
57+
"PW_RPC_DESCRIPTOR_SERVICE=1",
5758
"PW_RPC_DEVICE_SERVICE=1",
5859
"PW_RPC_LIGHTING_SERVICE=1",
5960
]
@@ -76,6 +77,7 @@ executable("chip-lighting-app") {
7677
"${chip_root}/config/linux/lib/pw_rpc:pw_rpc",
7778
"${chip_root}/examples/common/pigweed:attributes_service.nanopb_rpc",
7879
"${chip_root}/examples/common/pigweed:button_service.nanopb_rpc",
80+
"${chip_root}/examples/common/pigweed:descriptor_service.nanopb_rpc",
7981
"${chip_root}/examples/common/pigweed:device_service.nanopb_rpc",
8082
"${chip_root}/examples/common/pigweed:lighting_service.nanopb_rpc",
8183
"${chip_root}/examples/common/pigweed:rpc_services",

examples/lighting-app/nrfconnect/CMakeLists.txt

+13
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,17 @@ pw_proto_library(button_service
155155
pw_protobuf.common_protos
156156
)
157157

158+
pw_proto_library(descriptor_service
159+
SOURCES
160+
${CHIP_ROOT}/examples/common/pigweed/protos/descriptor_service.proto
161+
PREFIX
162+
descriptor_service
163+
STRIP_PREFIX
164+
${CHIP_ROOT}/examples/common/pigweed/protos
165+
DEPS
166+
pw_protobuf.common_protos
167+
)
168+
158169
pw_proto_library(device_service
159170
SOURCES
160171
${CHIP_ROOT}/examples/common/pigweed/protos/device_service.proto
@@ -224,6 +235,7 @@ target_include_directories(app PRIVATE
224235
target_compile_options(app PRIVATE
225236
"-DPW_RPC_ATTRIBUTE_SERVICE=1"
226237
"-DPW_RPC_BUTTON_SERVICE=1"
238+
"-DPW_RPC_DESCRIPTOR_SERVICE=1"
227239
"-DPW_RPC_DEVICE_SERVICE=1"
228240
"-DPW_RPC_LIGHTING_SERVICE=1"
229241
"-DPW_RPC_THREAD_SERVICE=1"
@@ -232,6 +244,7 @@ target_compile_options(app PRIVATE
232244
target_link_libraries(app PRIVATE
233245
attributes_service.nanopb_rpc
234246
button_service.nanopb_rpc
247+
descriptor_service.nanopb_rpc
235248
device_service.nanopb_rpc
236249
lighting_service.nanopb_rpc
237250
thread_service.nanopb_rpc

examples/lock-app/efr32/BUILD.gn

+2
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ efr32_executable("lock_app") {
221221
"PW_RPC_ENABLED",
222222
"PW_RPC_ATTRIBUTE_SERVICE=1",
223223
"PW_RPC_BUTTON_SERVICE=1",
224+
"PW_RPC_DESCRIPTOR_SERVICE=1",
224225
"PW_RPC_DEVICE_SERVICE=1",
225226
"PW_RPC_LOCKING_SERVICE=1",
226227
"PW_RPC_OTCLI_SERVICE=1",
@@ -240,6 +241,7 @@ efr32_executable("lock_app") {
240241
"${chip_root}/config/efr32/lib/pw_rpc:pw_rpc",
241242
"${chip_root}/examples/common/pigweed:attributes_service.nanopb_rpc",
242243
"${chip_root}/examples/common/pigweed:button_service.nanopb_rpc",
244+
"${chip_root}/examples/common/pigweed:descriptor_service.nanopb_rpc",
243245
"${chip_root}/examples/common/pigweed:device_service.nanopb_rpc",
244246
"${chip_root}/examples/common/pigweed:locking_service.nanopb_rpc",
245247
"${chip_root}/examples/common/pigweed:ot_cli_service.nanopb_rpc",

examples/lock-app/esp32/main/CMakeLists.txt

+13
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,17 @@ include(${PIGWEED_ROOT}/pw_build/pigweed.cmake)
6969
include(${PIGWEED_ROOT}/pw_protobuf_compiler/proto.cmake)
7070
set(dir_pw_third_party_nanopb "${CHIP_ROOT}/third_party/nanopb/repo" CACHE STRING "" FORCE)
7171

72+
pw_proto_library(descriptor_service
73+
SOURCES
74+
${CHIP_ROOT}/examples/common/pigweed/protos/descriptor_service.proto
75+
PREFIX
76+
descriptor_service
77+
STRIP_PREFIX
78+
${CHIP_ROOT}/examples/common/pigweed/protos
79+
DEPS
80+
pw_protobuf.common_protos
81+
)
82+
7283
pw_proto_library(device_service
7384
SOURCES
7485
${CHIP_ROOT}/examples/common/pigweed/protos/device_service.proto
@@ -106,6 +117,7 @@ pw_proto_library(locking_service
106117

107118
target_link_libraries(${COMPONENT_LIB} PUBLIC
108119
attributes_service.nanopb_rpc
120+
descriptor_service.nanopb_rpc
109121
device_service.nanopb_rpc
110122
button_service.nanopb_rpc
111123
locking_service.nanopb_rpc
@@ -118,6 +130,7 @@ target_link_libraries(${COMPONENT_LIB} PUBLIC
118130
target_compile_options(${COMPONENT_LIB} PRIVATE
119131
"-DPW_RPC_ATTRIBUTE_SERVICE=2"
120132
"-DPW_RPC_BUTTON_SERVICE=1"
133+
"-DPW_RPC_DESCRIPTOR_SERVICE=1"
121134
"-DPW_RPC_DEVICE_SERVICE=1"
122135
"-DPW_RPC_LOCKING_SERVICE=1")
123136

0 commit comments

Comments
 (0)