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

[samples/nrfconnect] Added updating ZCL cluster state to fit actual light/lock state. #3132

Merged
merged 2 commits into from
Oct 21, 2020

Conversation

kkasperczyk-no
Copy link
Contributor

Problem

Initial value of ZCL ON/OFF cluster is not defined, while the lock/lighting is initially turned on in nRF Connect examples.

Summary of Changes

  • Added UpdateClusterState method called on the init and each completed on/off action.

Fixes #3131

Copy link
Contributor

@bzbarsky-apple bzbarsky-apple left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments apply to lock-app as to lighting-app.

@@ -99,6 +102,9 @@ int AppTask::Init()
InitServer();
PrintQRCode(chip::RendezvousInformationFlags::kBLE);

// Initialize cluster state to meet with the real light state
UpdateClusterState();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should happen inside emberAfPluginOnOffClusterServerPostInitCallback, presumably, to happen at the right place in the ZCL model layer initialization. It looks like the gen files for lighting-app (and lock-app) don't set up the CLUSTER_MASK_INIT_FUNCTION bits for the on/off cluster; they should presumably be regenerated with that bit set, so emberAfPluginOnOffClusterServerPostInitCallback will be called.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok and could you tell me where I can find how to regenerate those files, to check if emberAfPluginOnOffClusterServerPostInitCallback is called and everything works as expected?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment you need to open up Simplicity Studio, create a configuration like the one we already have but with the "Cluster server init" box checked under the "Callbacks" tab, then do some hand-editing on the generated code to make it compile in CHIP and add licenses. And depending on how the version of Simplicity Studio and SDK you are using compares to what was used to generate the files, either hand-edit more stuff or end up with a bunch of extraneous changes.

We're getting close to having a better flow, but we're not there yet. :(

In the meantime, I created #3180 to change the generated files to ensure the callback is called. As far as testing, if you just add an assert(false) inside emberAfPluginOnOffClusterServerPostInitCallback in examples/lighting-app/lighting-common/gen/callback-stub.c on top of #3180 it should be obvious whether it's getting called or not. And then you'd want to remove it from callback-stub.c and move it to the relevant apps as needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested it with your changes from #3180 and it works, but I'm not sure about removing this implementation from callback-stub.c. Without removing it, the code obviously will not compile because of the multiple definition, but would you like me to remove it permanently from callback-stub.c and provide empty implementations for all platforms? Wouldn't be better to not remove the implementation, but give it weak attribute?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've had some weird issues with the linker, so are unlikely willing to trust it here. Ok with you to do the necessary for now and revisit when we think attribute(weak) is robust and better enough to justify the work of proving it robust? our build system for these generated files is still a WIP...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In practice, apps really should implement this callback to work properly, right? I think the right call is to remove from callback-stub.c, add empty impls to the apps that won't have a real impl, with TODO comments pointing to issues we file to track implementing those bits.

Copy link
Contributor Author

@kkasperczyk-no kkasperczyk-no Oct 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, I was just curious that's why I asked. So I followed your suggestions and I implemented empty callbacks for all platforms supporting lighting/lock apps. Hope that I did what you mean, but please verify it.

@@ -360,6 +366,8 @@ void AppTask::ActionCompleted(LightingManager::Action_t aAction)
{
LOG_INF("Turn Off Action has been completed");
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code will be reached even if the action is coming from the data model itself, right? Do we really want to re-enter the data model at that point with the attribute write?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I forgot about checking if action was triggered by pushing button manually. I fixed it.

@@ -360,6 +363,8 @@ void AppTask::ActionInitiated(LightingManager::Action_t aAction)
{
LOG_INF("Turn Off Action has been initiated");
}

sAppTask.mButtonTriggeredActon = (aActor == AppEvent::kEventType_Button) ? true : false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Action" instead of "Acton"? Also what's aActor?

But most importantly, do we want to store this in a global variable? What happens if another action is initiated before the previous one completes?

Copy link
Contributor Author

@kkasperczyk-no kkasperczyk-no Oct 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First of all I think that nothing wrong would happen, because LightManager and BoltLockManager don't allow to start new action before previous one is completed. However I agree that storing global variable there was not the best design, so I proposed two different solutions for lighting and lock app, as they are calling ActionCompleted event in different way. Lighting app is calling it directly from the LightingManager InitiateAction method, so I think that there is no need to store actor value anywhere and it could be just passed as a ActionCompleted method argument. In the case of lock-app situation is different, because ActionCompleted is called from the Timer event handler. I thought that maybe it would be better to store actor value as class field not in the AppTask class, but in the BoltLockManager, which can pass current value to the ActionCompleted method.

@@ -385,6 +390,12 @@ void AppTask::ActionCompleted(BoltLockManager::Action_t aAction)
LOG_INF("Unlock Action has been completed");
sLockLED.Set(false);
}

if (sAppTask.mButtonTriggeredActon)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a sane way to have the caller pass the actor here, like they did for ActionInitiated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I answered on this remark in the comment above.

…tual light/lock state.

Initial value of ZCL ON/OFF cluster is not defined,
while the lock/lighting is initially turned on in nRF Connect examples.

* Added UpdateClusterState method called on the cluster post init callback and each completed
on/off action.
* Removed emberAfPluginOnOffClusterServerPostInitCallback method implementation from callback-stub.c
files for lighting and lock apps.
* Added emberAfPluginOnOffClusterServerPostInitCallback method empty implementations
for all platforms supporting lighting/lock app.
@github-actions
Copy link

Size increase report for "nrfconnect-example-build"

File Section File VM
chip-lock.elf text 94 94
chip-lock.elf rodata 24 24
chip-lock.elf bss 0 4
chip-lock.elf [LOAD #1 [RWX]] 2 2
chip-lock.elf [LOAD #3 [RW]] 0 -4
chip-lighting.elf text 108 108
chip-lighting.elf noinit 0 40
chip-lighting.elf rodata 24 24
chip-lighting.elf [LOAD #1 [RWX]] -12 -12
Full report output
BLOAT REPORT

Files found only in the build output:
    report.csv

Comparing ./master_artifact/chip-lock.elf and ./pull_artifact/chip-lock.elf:

sections,vmsize,filesize
.debug_info,0,3233
.debug_line,0,512
.debug_loc,0,231
text,94,94
.symtab,0,80
.debug_abbrev,0,78
.debug_str,0,66
.strtab,0,31
.debug_frame,0,24
rodata,24,24
.debug_aranges,0,16
bss,4,0
[LOAD #1 [RWX]],2,2
[Unmapped],0,1
[LOAD #3 [RW]],-4,0
.debug_ranges,0,-8

Comparing ./master_artifact/chip-lighting.elf and ./pull_artifact/chip-lighting.elf:

sections,vmsize,filesize
.debug_info,0,3867
.debug_line,0,523
.debug_loc,0,447
.debug_abbrev,0,211
text,108,108
.symtab,0,80
.debug_str,0,66
.debug_frame,0,44
noinit,40,0
.strtab,0,38
.debug_ranges,0,24
rodata,24,24
.debug_aranges,0,16
[Unmapped],0,-8
[LOAD #1 [RWX]],-12,-12

Comparing ./master_artifact/chip-shell.elf and ./pull_artifact/chip-shell.elf:

sections,vmsize,filesize


Copy link
Contributor

@bzbarsky-apple bzbarsky-apple left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thank you!

@bzbarsky-apple
Copy link
Contributor

@mspang mspang merged commit 5dfde56 into project-chip:master Oct 21, 2020
@kkasperczyk-no kkasperczyk-no deleted the zcl_init_pr_public branch April 16, 2021 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Initialize ZCL ON/OFF cluster with real state of lock/lighting in nrfconnect samples.
6 participants