Skip to content

Commit

Permalink
Merge branch 'master' into default_enable_dm_provider
Browse files Browse the repository at this point in the history
  • Loading branch information
andy31415 committed Oct 28, 2024
2 parents c015903 + cdb1920 commit f13aa6c
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,17 @@
#include <editline.h>
#include <stdlib.h>

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";
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<char *> mCommissionerName;
};
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
27 changes: 27 additions & 0 deletions scripts/py_matter_idl/matter_idl/test_zapxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,33 @@ def testGlobalStruct(self):
)
self.assertEqual(idl, Idl(global_structs=[struct]))

def testNameAttribute(self):
idl = XmlToIdl('''<?xml version="1.0"?>
<configurator>
<cluster>
<name>TestCluster</name>
<code>20</code>
<attribute side="server" code="0x0002" name="SubjectsPerAccessControlEntry" define="SUBJECTS_PER_ACCESS_CONTROL_ENTRY" type="int16u" min="4" default="4">
<mandatoryConform/>
</attribute>
</cluster>
</configurator>
''')
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('''<?xml version="1.0"?>
<configurator>
Expand Down
4 changes: 3 additions & 1 deletion scripts/py_matter_idl/matter_idl/zapxml/handlers/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
)

Expand Down

0 comments on commit f13aa6c

Please sign in to comment.