JMRI fast clock implementation - #2
Open
tpfarr wants to merge 2 commits into
Open
Conversation
Author
|
I just realized why you should not play with GitHub and then go on vacation.... I did not commit my last set of changes before doing the pull request so the "real" code for the offset application to the UTC time is not there. I'm away from home at the moment and can't upload the correct code. What's here now is just a stub in the time calculation area. In the real code the offset gets passed as a class argument to JMRIClock and is applied in the class get method instead of the incomplete stub code in esu-bridge.py. I'll update withrottle.py and esu-bridge.py on Sunday the 29th of July when I get back home. Sorry for the mixup. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This is an attempt at adding fast clock support for JMRI servers. There is a class JMRIClock in withrottle.py that connects to the JMRI webserver using a websocket (port 12080) to retrieve the fast clock string. As far as I know this is always in UTC so I've added a simple +- offset from UTC to display "local" time as desired. I did not want to get into timezone setting and stuff at this point.
protothrottle.ini has 3 new entries for the webPort, a flag useJMRIClock to set if you want to use this functionality and the clock offset parameter. If the web server is not running a time of 99+offset:99 will be displayed on the protothrottle indicating that you have not received any time updates from JMRI. If it connects it takes about 30sec to get the first time update. The time packet is sent to the mrbee in the same area as the status packet is sent in esu-bridge.py.
One point is that I used the lomond websocket client package which would have to be pip installed prior to use in your normal image. This is a BSD-3 license package and I've included the copyright and disclaimer in withrottle.py.
Also included are 2 updates for connect and disconnect of the withrottle connection. The connect code was changed to modify the timeout initially since it seems that the connect takes a bit of time (much more than the 0.01 interval used for the normal i/o). It is then set to 0.01 after the connection. this seems to connect always on the first try now.
The second update to disconnect is a bunch of try statements to let it stumble through in the case that the JMRI server is rudely disconnected (like shutting down JMRI). This allows the re-connect loop to start and continue forever until it connects again without bombing out.
Enjoy.