Skip to content

JMRI fast clock implementation - #2

Open
tpfarr wants to merge 2 commits into
IowaScaledEngineering:masterfrom
tpfarr:JMRI-fastclock
Open

JMRI fast clock implementation#2
tpfarr wants to merge 2 commits into
IowaScaledEngineering:masterfrom
tpfarr:JMRI-fastclock

Conversation

@tpfarr

@tpfarr tpfarr commented Jul 16, 2018

Copy link
Copy Markdown

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.

@tpfarr

tpfarr commented Jul 27, 2018

Copy link
Copy Markdown
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.
Tom

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant