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
Native braille display drivers: provide a generic way to handle acknowledgement packets. #7721
Comments
Conceptually, this sounds reasonable to me. A couple of clarifications:
1. You suggest that both the executor and _handleAck should "queue the
executor APC to the background thread". These functions (the executor and
_handleAck) will be running in the background thread, right? So we're
actually queuing to the same thread we're in. There's no problem with that;
I just want to be super clear.
2. I assume awaitingAck should never be touched by braille display drivers
themselves; i.e. it is just used by core for managing state? If so, perhaps
it should be underscore prefixed and the docstring amended to reflect that
this is for internal use by core code only, not the driver.
|
@jcsteh commented on 3 Nov 2017, 05:35 CET:
That is true, but I was a bit reluctant to call a PAPCFUNC like a regular python function, so that's why I decided to queue here.
That is true, I will do that. |
I just had a look at BRLTTY's code to see how they handle this. They also abstracted the acknowledgement handling from the drivers into core. Each driver structure that uses this has the following attributes to keep state:
A braille message is a structure containing a packet and some metadata about it. Most importantly, every message gets a type. Usually, these types seem to follow the packet types (first byte of a packet in most protocols). If a packet needs to be send and there is already a queue in messages, the previous item in the queue with the same type is replaced. This is like what we do for braille cells, but more generic. This generic approach might com in handy when we are sending more messages to displays, such as dot pressure and a user is quickly changing settings. If an ACK is received, or the timeout has been reached, the next packet from the queue is sent. Every time the timeout is reached, the missing counter is increased. If a max missing number of ACKs is reached, the driver goes into error state. As mentioned earlier, the missing counter is reset when an ACK is received. Lessons we might learn from this:
|
I agree this would be handy. Note that queueing messages to the background thread now also only applies to braille cells, so that's why I suggested building upon this system. If we make ACK handling more generic, we should make queueing to the thread more generic as well. |
It certainly makes sense to explore these ideas. However, I'd advise caution on a few points:
1. Queuing to the background is great for writing cells because the main thread doesn't care about the response. However, if there were ever any queries where the main thread needed some kind of response, you'd then have to come up with a mechanism to wait on that response. That's certainly possible, but it's tedious to implement. Having said that, I can't think of any cases where this is currently needed.
2. For writing cells, you can just skip the previous write if a newer one comes in before you get to it. This is not necessarily the case with any other kind of packetb; e.g. a packet which changes multiple settings.
3. We'd need to be certain that this approach of structuring packets made things simpler and not more complex. Abstraction is fantastic until it isn't. :)
4. Finally, while most drivers seem to be moving to hwIo, this probably won't be the case for *all* drivers. We need to keep in mind that not all drivers will deal with the protocol directly. It might be possible to deal with this by having a subclass of BrailleDisplayDriver called RawBrailleDisplayDriver or similar which contains stuff specific to raw protocol drivers.
|
Issue summary
For several braille displays, when sending a packet, the display acknowledges the receipt of a packet. This is a mechanism to make sure that a packet has been delivered to a braille display in a correct way. Several displays have such a feature, including Handy Tech, Eurobraille and Freedom Scientific displays.
Proposal
Since there are multiple drivers with the need of proper ACK handling, I propose creating a generic system for this.
Note that we can also put awaitingAck on the background thread.
2. in BrailleHandler._writeCells, check for not self.display.awaitingAck, and only queue the executor if we aren't waiting for an ACK and there is no queued write.
3. The executor should set awaitingAck to True whenever a succesful write has been made. Furthermore, it should start a waitable timer that, if not canceled by BrailleDisplayDriver._handleAck, logs the fact that an ACK has been missed, resets awaitingAck to False and queues the executor APC to the background thread.
4. BrailleDisplayDriver._handleAck should set awaitingAck to False and queue the executor APC to the background thread.
Thoughts from @jcsteh, @michaelDCurran and @bramd are appreciated.
The text was updated successfully, but these errors were encountered: