openhab/openhab — pull request #839 by cdjackson (2014-02-09 13:15:28+00:00)
Title: Zwave wakeup changes

Note: This needs further testing (ie not intended for inclusion in 1.4!). I've raised the PR now so that there's visibility of this issue and people can try it out.

This changes the way that the wakeup command class works. Previously, as soon as the node woke up, all messages in the wakeup queue were added to the outgoing queue, along with the "Go To Sleep" message. This means that if there's anything else that needs to happen that wasn't already in the wakeup queue, it has to wait until the next wakeup period. This can result in messages getting queued rather than the transactions being closed out during this wakeup period. It also makes multi message transactions impossible within a single wakeup period (eg requesting association classes is an iterative function that needs the response to one message before sending the next - if the system sends the 'Go To Sleep' after the first message, the next message has to wait - this can make things take many hours if the wakeup period if 60 minutes!).

Now, when the node wakes, only 1 message is added to the send queue. When the notification for this event is received, the next message is added to the queue. When the queue is empty, a timer is started and if no further communications is sent within this period (2 seconds) then the 'Go To Sleep' message is sent. If more messages are sent in this time, the timer is restarted, so the timer should time out 2 seconds after the end of communications.

The checks in the controller that check if the node is alive and if not add a message to the queue have been merged into a single method in the wakeup class. This is so that the message itself can be checked. Previously it was possible if there was a timeout for the wakeup queue to contain the 'Go To Sleep' message. This meant that on the next wakeup, not all messages would be sent as the queued message would tell the device to sleep. This function now stops queuing of this message.

In the NodeStageAdvancer, when setup completed it would send a 'Go To Sleep' message. This has been removed as the new functionality makes this unnecessary as it's automatically handled by the timer now.