diff --git a/examples/darwin-framework-tool/commands/common/CHIPCommandBridge.h b/examples/darwin-framework-tool/commands/common/CHIPCommandBridge.h index 477e1ed8105101..90f3a6c56415f6 100644 --- a/examples/darwin-framework-tool/commands/common/CHIPCommandBridge.h +++ b/examples/darwin-framework-tool/commands/common/CHIPCommandBridge.h @@ -30,6 +30,7 @@ inline constexpr char kIdentityAlpha[] = "alpha"; inline constexpr char kIdentityBeta[] = "beta"; inline constexpr char kIdentityGamma[] = "gamma"; +inline constexpr char kControllerIdPrefix[] = "8DCADB14-AF1F-45D0-B084-00000000000"; class CHIPCommandBridge : public Command { public: @@ -69,6 +70,8 @@ class CHIPCommandBridge : public Command { static OTAProviderDelegate * mOTADelegate; + static NSNumber * GetCommissionerFabricId(const char * identity); + protected: // Will be called in a setting in which it's safe to touch the CHIP // stack. The rules for Run() are as follows: diff --git a/examples/darwin-framework-tool/commands/common/CHIPCommandBridge.mm b/examples/darwin-framework-tool/commands/common/CHIPCommandBridge.mm index 55df92f8b98a11..b237acaa5b7132 100644 --- a/examples/darwin-framework-tool/commands/common/CHIPCommandBridge.mm +++ b/examples/darwin-framework-tool/commands/common/CHIPCommandBridge.mm @@ -154,10 +154,10 @@ constexpr const char * identities[] = { kIdentityAlpha, kIdentityBeta, kIdentityGamma }; std::string commissionerName = mCommissionerName.HasValue() ? mCommissionerName.Value() : kIdentityAlpha; for (size_t i = 0; i < ArraySize(identities); ++i) { - __auto_type * uuidString = [NSString stringWithFormat:@"%@%@", @"8DCADB14-AF1F-45D0-B084-00000000000", @(i)]; + __auto_type * fabricId = GetCommissionerFabricId(identities[i]); + __auto_type * uuidString = [NSString stringWithFormat:@"%@%@", @(kControllerIdPrefix), fabricId]; __auto_type * controllerId = [[NSUUID alloc] initWithUUIDString:uuidString]; __auto_type * vendorId = @(mCommissionerVendorId.ValueOr(chip::VendorId::TestVendor1)); - __auto_type * fabricId = @(i + 1); __auto_type * nodeId = @(chip::kTestControllerNodeId); if (commissionerName.compare(identities[i]) == 0 && mCommissionerNodeId.HasValue()) { @@ -218,7 +218,7 @@ constexpr const char * identities[] = { kIdentityAlpha, kIdentityBeta, kIdentityGamma }; std::string commissionerName = mCommissionerName.HasValue() ? mCommissionerName.Value() : kIdentityAlpha; for (size_t i = 0; i < ArraySize(identities); ++i) { - __auto_type * fabricId = @(i + 1); + __auto_type * fabricId = GetCommissionerFabricId(identities[i]); __auto_type * params = [[MTRDeviceControllerStartupParams alloc] initWithIPK:certificateIssuer.ipk fabricID:fabricId nocSigner:certificateIssuer.signingKey]; @@ -264,14 +264,19 @@ NSNumber * CHIPCommandBridge::CurrentCommissionerFabricId() { - if (mCurrentIdentity.compare(kIdentityAlpha) == 0) { + return GetCommissionerFabricId(mCurrentIdentity.c_str()); +} + +NSNumber * CHIPCommandBridge::GetCommissionerFabricId(const char * identity) +{ + if (strcmp(identity, kIdentityAlpha) == 0) { return @(1); - } else if (mCurrentIdentity.compare(kIdentityBeta) == 0) { + } else if (strcmp(identity, kIdentityBeta) == 0) { return @(2); - } else if (mCurrentIdentity.compare(kIdentityGamma) == 0) { + } else if (strcmp(identity, kIdentityGamma) == 0) { return @(3); } else { - ChipLogError(chipTool, "Unknown commissioner name: %s. Supported names are [%s, %s, %s]", mCurrentIdentity.c_str(), kIdentityAlpha, + ChipLogError(chipTool, "Unknown commissioner name: %s. Supported names are [%s, %s, %s]", identity, kIdentityAlpha, kIdentityBeta, kIdentityGamma); chipDie(); } diff --git a/examples/darwin-framework-tool/commands/common/ControllerStorage.h b/examples/darwin-framework-tool/commands/common/ControllerStorage.h index f70081fee095a7..76811bcbb7e92e 100644 --- a/examples/darwin-framework-tool/commands/common/ControllerStorage.h +++ b/examples/darwin-framework-tool/commands/common/ControllerStorage.h @@ -44,6 +44,7 @@ extern NSString * const kDarwinFrameworkToolControllerDomain; - (NSData *)valueForKey:(NSString *)key; - (void)storeValue:(NSData *)value forKey:key; +- (void)print; @end NS_ASSUME_NONNULL_END diff --git a/examples/darwin-framework-tool/commands/common/ControllerStorage.mm b/examples/darwin-framework-tool/commands/common/ControllerStorage.mm index 058f00a6b302ae..03685d445a1e84 100644 --- a/examples/darwin-framework-tool/commands/common/ControllerStorage.mm +++ b/examples/darwin-framework-tool/commands/common/ControllerStorage.mm @@ -143,6 +143,20 @@ - (void)storeValue:(NSData *)value forKey:key self.storage[controllerKey] = value; } +- (void)print +{ + NSLog(@"%@ (%@)", kDarwinFrameworkToolControllerDomain, _keyScopingPrefix); + for (NSString * controllerKey in self.storage) { + if (![self _isControllerScopedKey:controllerKey]) { + continue; + } + + __auto_type * key = [self _controllerScopedKeyToKey:controllerKey]; + __auto_type * data = self.storage[controllerKey]; + NSLog(@" * %@: %@", key, data); + } +} + - (NSString *)_keyToControllerScopedKey:(NSString *)key { return [NSString stringWithFormat:@"%@%@", _keyScopingPrefix, key]; diff --git a/examples/darwin-framework-tool/commands/interactive/InteractiveCommands.mm b/examples/darwin-framework-tool/commands/interactive/InteractiveCommands.mm index 2652e2c2364101..cfad15b781e129 100644 --- a/examples/darwin-framework-tool/commands/interactive/InteractiveCommands.mm +++ b/examples/darwin-framework-tool/commands/interactive/InteractiveCommands.mm @@ -27,12 +27,17 @@ #include #include -constexpr char kInteractiveModePrompt[] = "Stop and restart stack: [Ctrl+_] & [Ctrl+^]\n" - "Trigger exit(0): [Ctrl+@]\n" - "Quit Interactive: 'quit()'\n" - ">>> "; +constexpr char kInteractiveModeInstruction[] = "╔══════════════════════════════════════════════════════════════════╗\n" + "║ Interactive Mode ║\n" + "╠══════════════════════════════════════════════════════════════════╣\n" + "║ Stop and restart stack: [Ctrl+_] & [Ctrl+^ ] ║\n" + "║ Trigger exit(0) : [Ctrl+@] ║\n" + "║ Quit Interactive : 'quit()' or `quit` ║\n" + "╚══════════════════════════════════════════════════════════════════╝\n"; +constexpr char kInteractiveModePrompt[] = ">>> "; constexpr char kInteractiveModeHistoryFilePath[] = "/tmp/darwin_framework_tool_history"; constexpr char kInteractiveModeStopCommand[] = "quit()"; +constexpr char kInteractiveModeStopAlternateCommand[] = "quit"; constexpr char kCategoryError[] = "Error"; constexpr char kCategoryProgress[] = "Info"; constexpr char kCategoryDetail[] = "Debug"; @@ -277,6 +282,11 @@ void ENFORCE_FORMAT(3, 0) InteractiveServerLoggingCallback(const char * module, printf("%s\n", mAdditionalPrompt.Value()); ClearLine(); } + + ClearLine(); + printf("%s", kInteractiveModeInstruction); + ClearLine(); + command = readline(kInteractiveModePrompt); // Do not save empty lines @@ -391,7 +401,7 @@ el_status_t ExitFunction() bool InteractiveCommand::ParseCommand(char * command, int * status) { - if (strcmp(command, kInteractiveModeStopCommand) == 0) { + if (strcmp(command, kInteractiveModeStopCommand) == 0 || strcmp(command, kInteractiveModeStopAlternateCommand) == 0) { ExecuteDeferredCleanups(); return NO; } diff --git a/examples/darwin-framework-tool/commands/storage/StorageManagementCommand.h b/examples/darwin-framework-tool/commands/storage/StorageManagementCommand.h index 8c3ed69184d742..35e111e92e7125 100644 --- a/examples/darwin-framework-tool/commands/storage/StorageManagementCommand.h +++ b/examples/darwin-framework-tool/commands/storage/StorageManagementCommand.h @@ -33,7 +33,15 @@ class StorageClearAll : public Command class StorageViewAll : public Command { public: - StorageViewAll() : Command("view-all") {} + StorageViewAll() : Command("view") + { + AddArgument("commissioner-name", &mCommissionerName, + "If specified, only the keys associated with the given commissioner will be displayed. Valid options are: " + "‘alpha’, ‘beta’, ‘gamma’."); + } CHIP_ERROR Run() override; + +private: + chip::Optional mCommissionerName; }; diff --git a/examples/darwin-framework-tool/commands/storage/StorageManagementCommand.mm b/examples/darwin-framework-tool/commands/storage/StorageManagementCommand.mm index 007d2821bda5a3..9e6e4b61f88a95 100644 --- a/examples/darwin-framework-tool/commands/storage/StorageManagementCommand.mm +++ b/examples/darwin-framework-tool/commands/storage/StorageManagementCommand.mm @@ -49,11 +49,22 @@ CHIP_ERROR StorageViewAll::Run() { - __auto_type * domains = GetDomains(); - for (NSString * domain in domains) { - __auto_type * storage = [[PreferencesStorage alloc] initWithDomain:domain]; - [storage print]; + if (!mCommissionerName.HasValue()) { + __auto_type * domains = GetDomains(); + for (NSString * domain in domains) { + __auto_type * storage = [[PreferencesStorage alloc] initWithDomain:domain]; + [storage print]; + } + + return CHIP_NO_ERROR; } + const char * commissionerName = mCommissionerName.Value(); + __auto_type * fabricId = CHIPCommandBridge::GetCommissionerFabricId(commissionerName); + __auto_type * uuidString = [NSString stringWithFormat:@"%@%@", @(kControllerIdPrefix), fabricId]; + __auto_type * controllerId = [[NSUUID alloc] initWithUUIDString:uuidString]; + __auto_type * storage = [[ControllerStorage alloc] initWithControllerID:controllerId]; + [storage print]; + return CHIP_NO_ERROR; } diff --git a/scripts/py_matter_idl/matter_idl/test_zapxml.py b/scripts/py_matter_idl/matter_idl/test_zapxml.py index 5ea15e27e8f9c2..2bf4338d20a928 100755 --- a/scripts/py_matter_idl/matter_idl/test_zapxml.py +++ b/scripts/py_matter_idl/matter_idl/test_zapxml.py @@ -360,6 +360,33 @@ def testGlobalStruct(self): ) self.assertEqual(idl, Idl(global_structs=[struct])) + def testNameAttribute(self): + idl = XmlToIdl(''' + + + TestCluster + 20 + + + + + + + ''') + self.assertEqual(idl, + Idl(clusters=[ + Cluster(name='TestCluster', code=20, + attributes=[ + Attribute( + definition=Field( + data_type=DataType(name='int16u', min_value=4), + code=2, + name='SubjectsPerAccessControlEntry', + ), + qualities=AttributeQuality.READABLE, + readacl=AccessPrivilege.VIEW, + writeacl=AccessPrivilege.OPERATE)])])) + def testStruct(self): idl = XmlToIdl(''' diff --git a/scripts/py_matter_idl/matter_idl/zapxml/handlers/parsing.py b/scripts/py_matter_idl/matter_idl/zapxml/handlers/parsing.py index 5244e6574d8de1..30ca8a5956f361 100644 --- a/scripts/py_matter_idl/matter_idl/zapxml/handlers/parsing.py +++ b/scripts/py_matter_idl/matter_idl/zapxml/handlers/parsing.py @@ -81,10 +81,12 @@ def AttrsToAttribute(attrs) -> Attribute: if 'max' in attrs: data_type.max_value = ParseInt(attrs['max'], data_type) + name = attrs['name'] if 'name' in attrs else '' + field = Field( data_type=data_type, code=ParseInt(attrs['code']), - name='', + name=name, is_list=(attrs['type'].lower() == 'array') )