Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional paramerters to chip tool darwin #17998

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions examples/chip-tool-darwin/templates/commands.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public:
AddArgument("{{asUpperCamelCase label}}", {{asTypeMinValue type}}, {{asTypeMaxValue type}}, &m{{asUpperCamelCase label}});
{{/if_chip_complex}}
{{/chip_cluster_command_arguments}}
AddArgument("timedInteractionTimeoutMs", 0, UINT16_MAX, &mTimedInteractionTimeoutMs);
ModelCommand::AddArguments();
}

Expand All @@ -46,11 +47,9 @@ public:
dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL);
CHIP{{asUpperCamelCase clusterName}} * cluster = [[CHIP{{asUpperCamelCase clusterName}} alloc] initWithDevice:device endpoint:endpointId queue:callbackQueue];
CHIP_ERROR __block chipError = CHIP_NO_ERROR;
__auto_type * params = [[CHIP{{asUpperCamelCase clusterName}}Cluster{{asUpperCamelCase name}}Params alloc] init];
params.timedInvokeTimeoutMs = mTimedInteractionTimeoutMs.HasValue() ? [NSNumber numberWithUnsignedShort:mTimedInteractionTimeoutMs.Value()] : nil;
{{#chip_cluster_command_arguments}}
{{#first}}
__auto_type * params = [[CHIP{{asUpperCamelCase parent.clusterName}}Cluster{{asUpperCamelCase parent.name}}Params alloc] init];
{{/first}}

{{#if_chip_complex}}
{{>decodable_value target=(concat "params." (asStructPropertyName label)) source=(concat "mRequest." (asStructPropertyName label)) cluster=parent.clusterName type=type depth=0}}
{{else if (isOctetString type)}}
Expand All @@ -76,6 +75,7 @@ public:
}

private:
chip::Optional<uint16_t> mTimedInteractionTimeoutMs;
{{#chip_cluster_command_arguments}}
{{#if_chip_complex}}
chip::app::Clusters::{{asUpperCamelCase parent.clusterName}}::Commands::{{asUpperCamelCase parent.name}}::Type mRequest;
Expand Down Expand Up @@ -104,6 +104,7 @@ public:
Read{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}(): ModelCommand("read")
{
AddArgument("attr-name", "{{asDelimitedCommand (asUpperCamelCase name)}}");
AddArgument("fabric-filtered", 0, 1, &mFabricFiltered);
ModelCommand::AddArguments();
}

Expand All @@ -120,6 +121,7 @@ public:
CHIP_ERROR __block err = CHIP_NO_ERROR;
{{#if_is_fabric_scoped_struct type}}
CHIPReadParams * params = [[CHIPReadParams alloc] init];
params.fabricFiltered = mFabricFiltered.HasValue() ? [NSNumber numberWithBool:mFabricFiltered.Value()] : nil;
{{/if_is_fabric_scoped_struct}}
[cluster readAttribute{{asUpperCamelCase name}}With
{{~#if_is_fabric_scoped_struct type~}}
Expand All @@ -136,6 +138,8 @@ public:
}];
return err;
}
private:
chip::Optional<bool> mFabricFiltered;

};

Expand All @@ -155,6 +159,7 @@ public:
{{else}}
AddArgument("attr-value", {{asTypeMinValue type}}, {{asTypeMaxValue type}}, &mValue);
{{/if_chip_complex}}
AddArgument("timedInteractionTimeoutMs", 0, UINT16_MAX, &mTimedInteractionTimeoutMs);
ModelCommand::AddArguments();
}

Expand All @@ -168,7 +173,8 @@ public:
dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL);
CHIP{{asUpperCamelCase parent.name}} * cluster = [[CHIP{{asUpperCamelCase parent.name}} alloc] initWithDevice:device endpoint:endpointId queue:callbackQueue];
CHIP_ERROR __block chipError = CHIP_NO_ERROR;

CHIPWriteParams * params = [[CHIPWriteParams alloc] init];
params.timedWriteTimeoutMs = mTimedInteractionTimeoutMs.HasValue() ? [NSNumber numberWithUnsignedShort:mTimedInteractionTimeoutMs.Value()] : nil;
{{#if_chip_complex}}
{{asObjectiveCType type parent.name}} value;
{{>decodable_value target="value" source="mValue" cluster=parent.name errorCode="return err;" depth=0}}
Expand All @@ -180,7 +186,7 @@ public:
{{asObjectiveCType type parent.name}} value = [NSNumber numberWith{{asObjectiveCNumberType "" type false}}:mValue];
{{/if_chip_complex}}

[cluster writeAttribute{{asUpperCamelCase name}}WithValue:value completionHandler:^(NSError * _Nullable error) {
[cluster writeAttribute{{asUpperCamelCase name}}WithValue:value params:params completionHandler:^(NSError * _Nullable error) {
chipError = [CHIPError errorToCHIPErrorCode:error];
ChipLogError(chipTool, "{{asUpperCamelCase parent.name}} {{asUpperCamelCase name}} Error: %s", chip::ErrorStr(chipError));
SetCommandExitStatus(chipError);
Expand All @@ -189,6 +195,7 @@ public:
}

private:
chip::Optional<uint16_t> mTimedInteractionTimeoutMs;
{{#if_chip_complex}}
{{zapTypeToEncodableClusterObjectType type ns=parent.name forceNotOptional=true}} mValue;
TypedComplexArgument<{{zapTypeToEncodableClusterObjectType type ns=parent.name forceNotOptional=true}}> mComplex;
Expand All @@ -211,6 +218,7 @@ public:
AddArgument("attr-name", "{{asDelimitedCommand (asUpperCamelCase name)}}");
AddArgument("min-interval", 0, UINT16_MAX, &mMinInterval);
AddArgument("max-interval", 0, UINT16_MAX, &mMaxInterval);
AddArgument("fabric-filtered", 0, 1, &mFabricFiltered);
bzbarsky-apple marked this conversation as resolved.
Show resolved Hide resolved
AddArgument("wait", 0, 1, &mWait);
ModelCommand::AddArguments();
}
Expand All @@ -225,6 +233,7 @@ public:
dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL);
CHIP{{asUpperCamelCase parent.name}} * cluster = [[CHIP{{asUpperCamelCase parent.name}} alloc] initWithDevice:device endpoint:endpointId queue:callbackQueue];
CHIPSubscribeParams * params = [[CHIPSubscribeParams alloc] init];
params.fabricFiltered = mFabricFiltered.HasValue() ? [NSNumber numberWithBool:mFabricFiltered.Value()] : nil;
[cluster subscribe{{>attribute}}WithMinInterval:[NSNumber numberWithUnsignedInt:mMinInterval]
maxInterval:[NSNumber numberWithUnsignedInt:mMaxInterval]
params:params
Expand All @@ -244,6 +253,7 @@ public:
}

private:
chip::Optional<bool> mFabricFiltered;
uint16_t mMinInterval;
uint16_t mMaxInterval;
bool mWait;
Expand Down
Loading