@@ -30,6 +30,14 @@ using chip::DeviceLayer::ConfigurationMgr;
30
30
namespace chip {
31
31
namespace Shell {
32
32
33
+ static chip::Shell::Engine sShellConfigSubcommands ;
34
+
35
+ CHIP_ERROR ConfigHelpHandler (int argc, char ** argv)
36
+ {
37
+ sShellConfigSubcommands .ForEachCommand (PrintCommandHelp, nullptr );
38
+ return CHIP_NO_ERROR;
39
+ }
40
+
33
41
static CHIP_ERROR ConfigGetVendorId (bool printHeader)
34
42
{
35
43
streamer_t * sout = streamer_get ();
@@ -44,6 +52,11 @@ static CHIP_ERROR ConfigGetVendorId(bool printHeader)
44
52
return CHIP_NO_ERROR;
45
53
}
46
54
55
+ static CHIP_ERROR ConfigVendorId (int argc, char ** argv)
56
+ {
57
+ return ConfigGetVendorId (false );
58
+ }
59
+
47
60
static CHIP_ERROR ConfigGetProductId (bool printHeader)
48
61
{
49
62
streamer_t * sout = streamer_get ();
@@ -58,6 +71,11 @@ static CHIP_ERROR ConfigGetProductId(bool printHeader)
58
71
return CHIP_NO_ERROR;
59
72
}
60
73
74
+ static CHIP_ERROR ConfigProductId (int argc, char ** argv)
75
+ {
76
+ return ConfigGetProductId (false );
77
+ }
78
+
61
79
static CHIP_ERROR ConfigGetProductRevision (bool printHeader)
62
80
{
63
81
streamer_t * sout = streamer_get ();
@@ -72,6 +90,11 @@ static CHIP_ERROR ConfigGetProductRevision(bool printHeader)
72
90
return CHIP_NO_ERROR;
73
91
}
74
92
93
+ static CHIP_ERROR ConfigProductRevision (int argc, char ** argv)
94
+ {
95
+ return ConfigGetProductRevision (false );
96
+ }
97
+
75
98
static CHIP_ERROR ConfigGetSetupPinCode (bool printHeader)
76
99
{
77
100
streamer_t * sout = streamer_get ();
@@ -86,6 +109,11 @@ static CHIP_ERROR ConfigGetSetupPinCode(bool printHeader)
86
109
return CHIP_NO_ERROR;
87
110
}
88
111
112
+ static CHIP_ERROR ConfigPinCode (int argc, char ** argv)
113
+ {
114
+ return ConfigGetSetupPinCode (false );
115
+ }
116
+
89
117
static CHIP_ERROR ConfigGetSetupDiscriminator (bool printHeader)
90
118
{
91
119
streamer_t * sout = streamer_get ();
@@ -122,6 +150,18 @@ static CHIP_ERROR ConfigSetSetupDiscriminator(char * argv)
122
150
return error;
123
151
}
124
152
153
+ static CHIP_ERROR ConfigDiscriminator (int argc, char ** argv)
154
+ {
155
+ if (argc == 0 )
156
+ {
157
+ return ConfigGetSetupDiscriminator (false );
158
+ }
159
+ else
160
+ {
161
+ return ConfigSetSetupDiscriminator (argv[0 ]);
162
+ }
163
+ }
164
+
125
165
static CHIP_ERROR PrintAllConfigs ()
126
166
{
127
167
ReturnErrorOnFailure (ConfigGetVendorId (true ));
@@ -141,53 +181,35 @@ static CHIP_ERROR ConfigHandler(int argc, char ** argv)
141
181
case 0 :
142
182
return PrintAllConfigs ();
143
183
case 1 :
144
- if (strcmp (argv[0 ], " vendorid" ) == 0 )
145
- {
146
- return ConfigGetVendorId (false );
147
- }
148
- else if (strcmp (argv[0 ], " productid" ) == 0 )
149
- {
150
- return ConfigGetProductId (false );
151
- }
152
- else if (strcmp (argv[0 ], " productrev" ) == 0 )
153
- {
154
- return ConfigGetProductRevision (false );
155
- }
156
- else if (strcmp (argv[0 ], " pincode" ) == 0 )
184
+ if ((strcmp (argv[0 ], " help" ) == 0 ) || (strcmp (argv[0 ], " -h" ) == 0 ))
157
185
{
158
- return ConfigGetSetupPinCode ( false );
186
+ return ConfigHelpHandler (argc, argv );
159
187
}
160
- else if (strcmp (argv[0 ], " discriminator" ) == 0 )
161
- {
162
- return ConfigGetSetupDiscriminator (false );
163
- }
164
- else
165
- {
166
- return CHIP_ERROR_INVALID_ARGUMENT;
167
- }
168
- case 2 :
169
- if (strcmp (argv[0 ], " discriminator" ) == 0 )
170
- {
171
- return ConfigSetSetupDiscriminator (argv[1 ]);
172
- }
173
- else
174
- {
175
- return CHIP_ERROR_INVALID_ARGUMENT;
176
- }
177
- default :
178
- return CHIP_ERROR_INVALID_ARGUMENT;
179
188
}
189
+ return sShellConfigSubcommands .ExecCommand (argc, argv);
180
190
}
181
191
182
192
void RegisterConfigCommands ()
183
193
{
184
194
185
- static const shell_command_t sDeviceComand = { &ConfigHandler, " config" ,
195
+ static const shell_command_t sConfigComand = { &ConfigHandler, " config" ,
186
196
" Manage device configuration. Usage to dump value: config [param_name] and "
187
197
" to set some values (discriminator): config [param_name] [param_value]." };
188
198
189
- // Register the root `device` command with the top-level shell.
190
- Engine::Root ().RegisterCommands (&sDeviceComand , 1 );
199
+ static const shell_command_t sConfigSubCommands [] = {
200
+ { &ConfigHelpHandler, " help" , " Usage: config <subcommand>" },
201
+ { &ConfigVendorId, " vendorid" , " Get VendorId. Usage: config vendorid" },
202
+ { &ConfigProductId, " productid" , " Get ProductId. Usage: config productid" },
203
+ { &ConfigProductRevision, " productrev" , " Get ProductRevision. Usage: config preductrev" },
204
+ { &ConfigPinCode, " pincode" , " Get commissioning pincode. Usage: config pincode" },
205
+ { &ConfigDiscriminator, " discriminator" , " Get/Set commissioning discriminator. Usage: config discriminator [value]" },
206
+ };
207
+
208
+ // Register `config` subcommands with the local shell dispatcher.
209
+ sShellConfigSubcommands .RegisterCommands (sConfigSubCommands , ArraySize (sConfigSubCommands ));
210
+
211
+ // Register the root `config` command with the top-level shell.
212
+ Engine::Root ().RegisterCommands (&sConfigComand , 1 );
191
213
return ;
192
214
}
193
215
0 commit comments