Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into tc_ace_1_1
Browse files Browse the repository at this point in the history
  • Loading branch information
cecille committed Jan 26, 2023
2 parents 3364c3b + d65d147 commit 9deb163
Show file tree
Hide file tree
Showing 49 changed files with 3,217 additions and 202 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,6 @@ compile_commands.json
# log files
*.log
examples/thermostat/ameba/build

# Downloaded zap without a pigweed root (via zap_download.py)
.zap
160 changes: 140 additions & 20 deletions examples/darwin-framework-tool/commands/clusters/ReportCommandBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,24 @@ class SubscribeEvent : public ModelCommand {
public:
SubscribeEvent()
: ModelCommand("subscribe-all-events")
{
AddCommonArguments();
}

SubscribeEvent(chip::ClusterId clusterId, bool isClusterAny = false)
: ModelCommand("subscribe-event-by-id")
, mClusterId(clusterId)
{
if (isClusterAny == true) {
AddArgument("cluster-id", 0, UINT32_MAX, &mClusterId);
}
AddArgument("event-id", 0, UINT32_MAX, &mEventId);
AddArgument("event-min", 0, UINT64_MAX, &mEventNumber);
AddArgument("is-urgent", 0, 1, &mIsUrgent);
AddCommonArguments();
}

void AddCommonArguments()
{
AddArgument("min-interval", 0, UINT16_MAX, &mMinInterval);
AddArgument("max-interval", 0, UINT16_MAX, &mMaxInterval);
Expand All @@ -199,34 +217,61 @@ class SubscribeEvent : public ModelCommand {
dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL);

MTRSubscribeParams * params = [[MTRSubscribeParams alloc] initWithMinInterval:@(mMinInterval) maxInterval:@(mMaxInterval)];
if (mEventNumber.HasValue()) {
params.minimumEventNumber = [NSNumber numberWithUnsignedLongLong:mEventNumber.Value()];
}
if (mKeepSubscriptions.HasValue()) {
params.replaceExistingSubscriptions = !mKeepSubscriptions.Value();
}
if (mIsUrgent.HasValue()) {
params.reportEventsUrgently = mIsUrgent.Value();
}
if (mAutoResubscribe.HasValue()) {
params.resubscribeIfLost = mAutoResubscribe.Value();
}

[device subscribeWithQueue:callbackQueue
params:params
clusterStateCacheContainer:nil
attributeReportHandler:^(NSArray * value) {
SetCommandExitStatus(CHIP_NO_ERROR);
}
eventReportHandler:^(NSArray * value) {
for (id item in value) {
NSLog(@"Response Item: %@", [item description]);
if (strcmp(GetName(), "subscribe-event-by-id") == 0) {
[device subscribeToEventsWithEndpointID:(endpointId == chip::kInvalidEndpointId)
? nil
: [NSNumber numberWithUnsignedShort:endpointId]
clusterID:(mClusterId == chip::kInvalidClusterId) ? nil : [NSNumber numberWithUnsignedInteger:mClusterId]
eventID:(mEventId == chip::kInvalidEventId) ? nil : [NSNumber numberWithUnsignedInteger:mEventId]
params:params
queue:callbackQueue
reportHandler:^(NSArray<NSDictionary<NSString *, id> *> * _Nullable values, NSError * _Nullable error) {
if (values) {
for (id item in values) {
NSLog(@"Response Item: %@", [item description]);
}
}
SetCommandExitStatus(error);
}
SetCommandExitStatus(CHIP_NO_ERROR);
}
errorHandler:^(NSError * error) {
SetCommandExitStatus(error);
}
subscriptionEstablished:^() {
mSubscriptionEstablished = YES;
}
resubscriptionScheduled:^(NSError * error, NSNumber * resubscriptionDelay) {
NSLog(@"Subscription dropped with error %@. Resubscription in %@ms", error, resubscriptionDelay);
}];
subscriptionEstablished:^() {
mSubscriptionEstablished = YES;
}];
} else {
[device subscribeWithQueue:callbackQueue
params:params
clusterStateCacheContainer:nil
attributeReportHandler:^(NSArray * value) {
SetCommandExitStatus(CHIP_NO_ERROR);
}
eventReportHandler:^(NSArray * value) {
for (id item in value) {
NSLog(@"Response Item: %@", [item description]);
}
SetCommandExitStatus(CHIP_NO_ERROR);
}
errorHandler:^(NSError * error) {
SetCommandExitStatus(error);
}
subscriptionEstablished:^() {
mSubscriptionEstablished = YES;
}
resubscriptionScheduled:^(NSError * error, NSNumber * resubscriptionDelay) {
NSLog(@"Subscription dropped with error %@. Resubscription in %@ms", error, resubscriptionDelay);
}];
}

return CHIP_NO_ERROR;
}
Expand All @@ -237,7 +282,82 @@ class SubscribeEvent : public ModelCommand {
chip::Optional<bool> mKeepSubscriptions;
chip::Optional<bool> mAutoResubscribe;
chip::Optional<chip::EventNumber> mEventNumber;
chip::Optional<bool> mIsUrgent;
bool mSubscriptionEstablished = NO;
uint16_t mMinInterval;
uint16_t mMaxInterval;

void Shutdown() override
{
mSubscriptionEstablished = NO;
ModelCommand::Shutdown();
}

bool DeferInteractiveCleanup() override { return mSubscriptionEstablished; }

private:
chip::ClusterId mClusterId;
chip::EventId mEventId;
};

class ReadEvent : public ModelCommand {
public:
ReadEvent()
: ModelCommand("read-event-by-id")
{
AddArgument("cluster-id", 0, UINT32_MAX, &mClusterId);
AddArgument("event-id", 0, UINT32_MAX, &mEventId);
AddArgument("event-min", 0, UINT64_MAX, &mEventNumber);
ModelCommand::AddArguments();
}

ReadEvent(chip::ClusterId clusterId)
: ModelCommand("read-event-by-id")
, mClusterId(clusterId)
{
AddArgument("event-id", 0, UINT32_MAX, &mEventId);
AddArgument("event-min", 0, UINT64_MAX, &mEventNumber);
ModelCommand::AddArguments();
}

~ReadEvent() {}

CHIP_ERROR SendCommand(MTRBaseDevice * _Nonnull device, chip::EndpointId endpointId) override
{
dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL);
MTRReadParams * params = [[MTRReadParams alloc] init];
if (mFabricFiltered.HasValue()) {
params.filterByFabric = mFabricFiltered.Value();
}
if (mEventNumber.HasValue()) {
params.minimumEventNumber = [NSNumber numberWithUnsignedLongLong:mEventNumber.Value()];
}

[device
readEventsWithEndpointID:(endpointId == chip::kInvalidEndpointId) ? nil : [NSNumber numberWithUnsignedShort:endpointId]
clusterID:(mClusterId == chip::kInvalidClusterId) ? nil : [NSNumber numberWithUnsignedInteger:mClusterId]
eventID:(mEventId == chip::kInvalidEventId) ? nil : [NSNumber numberWithUnsignedInteger:mEventId]
params:params
queue:callbackQueue
completion:^(NSArray<NSDictionary<NSString *, id> *> * _Nullable values, NSError * _Nullable error) {
if (error != nil) {
LogNSError("Error reading event", error);
}
if (values) {
for (id item in values) {
NSLog(@"Response Item: %@", [item description]);
}
}
SetCommandExitStatus(error);
}];
return CHIP_NO_ERROR;
}

protected:
chip::Optional<bool> mFabricFiltered;
chip::Optional<chip::EventNumber> mEventNumber;

private:
chip::ClusterId mClusterId;
chip::AttributeId mEventId;
};
8 changes: 8 additions & 0 deletions examples/darwin-framework-tool/templates/commands.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,12 @@ void registerCluster{{asUpperCamelCase name}}(Commands & commands)
{{/if}}
{{/unless}}
{{/chip_server_cluster_attributes}}
{{#zcl_events}}
{{#first}}
make_unique<ReadEvent>(Id), //
make_unique<SubscribeEvent>(Id), //
{{/first}}
{{/zcl_events}}
};

commands.Register(clusterName, clusterCommands);
Expand All @@ -308,6 +314,8 @@ void registerClusterAny(Commands & commands)
make_unique<ReadAttribute>(), //
make_unique<WriteAttribute>(), //
make_unique<SubscribeAttribute>(), //
make_unique<ReadEvent>(), //
make_unique<SubscribeEvent>(chip::kInvalidClusterId, true), //
make_unique<SubscribeEvent>(), //
};

Expand Down
26 changes: 26 additions & 0 deletions examples/placeholder/linux/AppOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ using chip::ArgParser::OptionSet;
using chip::ArgParser::PrintArgError;

constexpr uint16_t kOptionDacProviderFilePath = 0xFF01;
constexpr uint16_t kOptionInteractiveMode = 0xFF02;
constexpr uint16_t kOptionInteractiveModePort = 0xFF03;

static chip::Credentials::Examples::TestHarnessDACProvider mDacProvider;
static bool gInteractiveMode = false;
static chip::Optional<uint16_t> gInteractiveModePort;

bool AppOptions::HandleOptions(const char * program, OptionSet * options, int identifier, const char * name, const char * value)
{
Expand All @@ -34,6 +38,12 @@ bool AppOptions::HandleOptions(const char * program, OptionSet * options, int id
case kOptionDacProviderFilePath:
mDacProvider.Init(value);
break;
case kOptionInteractiveMode:
gInteractiveMode = true;
break;
case kOptionInteractiveModePort:
gInteractiveModePort = chip::MakeOptional(static_cast<uint16_t>(atoi(value)));
break;
default:
PrintArgError("%s: INTERNAL ERROR: Unhandled option: %s\n", program, name);
retval = false;
Expand All @@ -47,13 +57,19 @@ OptionSet * AppOptions::GetOptions()
{
static OptionDef optionsDef[] = {
{ "dac_provider", chip::ArgParser::kArgumentRequired, kOptionDacProviderFilePath },
{ "interactive", chip::ArgParser::kNoArgument, kOptionInteractiveMode },
{ "port", chip::ArgParser::kArgumentRequired, kOptionInteractiveModePort },
{},
};

static OptionSet options = {
AppOptions::HandleOptions, optionsDef, "PROGRAM OPTIONS",
" --dac_provider <filepath>\n"
" A json file with data used by the example dac provider to validate device attestation procedure.\n"
" --interactive\n"
" Enable server interactive mode.\n"
" --port <port>\n"
" Specify the listening port for the server interactive mode.\n"
};

return &options;
Expand All @@ -63,3 +79,13 @@ chip::Credentials::DeviceAttestationCredentialsProvider * AppOptions::GetDACProv
{
return &mDacProvider;
}

bool AppOptions::GetInteractiveMode()
{
return gInteractiveMode;
}

chip::Optional<uint16_t> AppOptions::GetInteractiveModePort()
{
return gInteractiveModePort;
}
2 changes: 2 additions & 0 deletions examples/placeholder/linux/AppOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class AppOptions
public:
static chip::ArgParser::OptionSet * GetOptions();
static chip::Credentials::DeviceAttestationCredentialsProvider * GetDACProvider();
static bool GetInteractiveMode();
static chip::Optional<uint16_t> GetInteractiveModePort();

private:
static bool HandleOptions(const char * program, chip::ArgParser::OptionSet * options, int identifier, const char * name,
Expand Down
6 changes: 5 additions & 1 deletion examples/placeholder/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,23 @@ chip_data_model("configuration") {
config("includes") {
include_dirs = [
".",
"${chip_root}/examples/common",
"include",
]
}

executable("chip-${chip_tests_zap_config}") {
sources = [
"AppOptions.cpp",
"InteractiveServer.cpp",
"main.cpp",
"src/bridged-actions-stub.cpp",
"static-supported-modes-manager.cpp",
]

deps = [
":configuration",
"${chip_root}/examples/common/websocket-server",
"${chip_root}/examples/platform/linux:app-main",
"${chip_root}/src/app/tests/suites/commands/delay",
"${chip_root}/src/app/tests/suites/commands/discovery",
Expand All @@ -54,9 +57,10 @@ executable("chip-${chip_tests_zap_config}") {
"${chip_root}/src/lib",
"${chip_root}/src/lib/support:testing", # For sleepMillis. TODO: this is
# odd and should be fixed
"${chip_root}/third_party/jsoncpp",
]

include_dirs = [ "include" ]
public_configs = [ ":includes" ]

cflags = [ "-Wconversion" ]

Expand Down
Loading

0 comments on commit 9deb163

Please sign in to comment.