Fifo queue, implementing switches #13
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi!
This branch implements a new feature that permits sending commands from the controller/gateway to a node. This gives the possibility of controlling switches connected to mysensors nodes.
The basis is a FIFO queue that enables comm with the SerialGateway thread from another thread. The queue is filled by a function fill_queue that puts a function and any arguments on the queue. The queue is handled by a function handle_queue that gets the functions from the queue and calls them, in FIFO order. Commands are issued from the controller by calling a new function in the Gateway class, set_child_value. This function calls the fill_queue function and puts the other set_child_value function from the Sensor class with correct arguments to the queue. I also changed the Sensor class set function to return a set message. The new set_child_value function in the Gateway class is for convenience.
When testing this branch I encountered problems when reconnecting to the Serial interface. My guess is that this has to do with pyserial 2.7 and onwards. Testing with pyserial 2.5 worked flawlessly as far as I could tell. Therefore I changed the required version of pyserial to 2.5. Since this problem might not effect everyone, it can be discussed if it's really a good idea to downgrade pyserial. There seems to be at least some other people that are having similar issues, if looking at pyserial repo. Maybe this part of my pull request should be removed?
The following points are a summary of my changes in the pull request.
queue.
the queue, and calling them.
function. It will set a new value for a child and send the
corresponding Message from the gateway to the child's node.
This is not done directly but by putting a function with arguments to
the FIFO queue. The function in the queue is the set_child_value
function in the Sensor class.
Message.
queue first, then read from serial interface. If valid input is
read from serial and decoded, add logic function with input as
argument to the queue.
by changing pyserial required version to 2.5 or less.
a while after connecting, and by checking if connection is open
after connecting, and by closing connection when thread stops.
is true.
formatting.
set_child_value functions in Gateway class.
As in my previous pull request, I've put the base branch to dev for merging. I don't know if that's what you would like, or if it should be the master branch, if you decide to merge this.
Best regards,
Martin