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
UART plugin recovers granularity if timing improves - closes #1798 #1800
base: 0.10
Are you sure you want to change the base?
Conversation
…o master-resync
…esync Master resync
…ster Resync with upstream master
Given they work already...
Re-enable some Travis Mac tests that can currently run
…o master-resync
…esync Master resync
…ything about ncurses
Fix allowed failures on Travis
Explicitely link against tinfo. Needed for ncurses 6
Allow all origin in HTTPServer responses (CORS)
Simplify the sed command used to generate plugin header files, closes OpenLightingProject#1592 (hopefully)
This reverts commit b878fb9.
This reverts commit 59ea348.
This reverts commit 8ec45af.
83b6f48
to
4e475e0
Compare
I took care of the lint issues and the PR is now targeting the branch 0.10 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this was my error or yours, but there's one outstanding lint issue remaining if you wouldn't mind.
Have you re-tested on the 0.10 branch?
Also your Git-Fu is clearly much better than mine getting it targeting 0.10 branch, well done! |
It should be fixed now.
Yes I did some testing on the 0.10 branch, and with these fixes, OLA behaved as expected. |
Great thanks. For future reference you can also merge them directly from the web UI:
That's brilliant news! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @markus983 . Unfortunately I've just spotted an issue with how this calculation is mapped across to this code from the FTDI plugin...
You probably also want to add yourself to Authors for your contribution:
https://github.com/OpenLightingProject/ola/blob/0.10/AUTHORS
plugins/uartdmx/UartDmxThread.cpp
Outdated
Clock clock; | ||
CheckTimeGranularity(); | ||
DmxBuffer buffer; | ||
|
||
int frameTime = static_cast<int>(floor( | ||
(m_malft / static_cast<double>(1000)) + static_cast<double>(0.5))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I've just spotted this calculation won't be right for this plugin.
malft is Mark After Last Frame Time
The code you've copied it from is:
ola/plugins/ftdidmx/FtdiDmxThread.cpp
Lines 86 to 87 in 966c85b
int frameTime = static_cast<int>(floor( | |
(static_cast<double>(1000) / m_frequency) + static_cast<double>(0.5))); |
Which has a default frequency of 30:
ola/plugins/ftdidmx/FtdiDmxPlugin.h
Line 66 in b215c65
static const uint8_t DEFAULT_FREQUENCY = 30; |
Which gives:
=floor(1000/30)+0.5
=floor(33.33)+0.5
=33+0.5
=33.5
Whereas the input we've got here is the break time and the mark after last frame time (both in microseconds). So the frame time is
break time+(number of slots*slot time)+mark after last frame time
Your calculation will always be 0.5 with the default MALFT.
The standard is available here (E1.11):
https://tsp.esta.org/tsp/documents/published_docs.php
But essentially the break to break timing should be between 1204 microseconds and 1 second.
The standard also defines a minimum update time for 513 slots of 22.7 milliseconds (that appears to disagree with the minimum bit time from my calculations, but it's in the right ballpark).
So I suspect the easy fix here would be to find a frame time based on the minimum time for 513 slots plus the configured break and MALFT times. The nicer option would be to consider the number of slots being sent, but in both cases we should probably honour the minimum break to break time too, so we don't send too fast!
Which essentially is the conclusion that @richardash1981 and @rewolff reached in #1087 !
plugins/uartdmx/UartDmxThread.cpp
Outdated
TimeInterval elapsed = ts2 - ts1; | ||
|
||
if (m_granularity == GOOD) { | ||
while (elapsed.InMilliSeconds() < frameTime) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above this value, or the calculation of this value, needs changing...
plugins/uartdmx/UartDmxThread.cpp
Outdated
} | ||
|
||
elapsed = ts3 - ts1; | ||
while (elapsed.InMilliSeconds() < frameTime) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And again.
Just to be sure: The "write" returns immediately. So a working solution should probably get a timestamp at the moment the BREAK condition is released (A scheduling delay during the break then won't affect us), Then issue the write and calculate how long that should take, add in the mark-after-last-frame and wait until that moment before starting the next cycle. When I was looking at the code, the person writing the code assumed that write would return when all bytes had been written. My suggestion above does not depend on whether the write returns immediately or not. |
fixed calculation of frame time
@peternewman Thanks for the info, I fixed the calculation of the frame time and it should honor, the boundaries now. I tested it as well, and the UART plugin still behaves as expected. Personally I don't like goto statements so I just split the code into more methods, but it still behaves the same (and it helped me with debugging). @rewolff Thanks for your input, I incorporated this in my newest changes. |
Glad to have been of help. I haven't been "intimate" with the code in a while, so good to hear that my "research" from a while back wasn't wasted and helped the actual code. :-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for ignoring this for a bit, all sorts of stuff has been going on and I've been fighting the good fight with Python.
I'm hoping we can still sneak this into 0.10.9 if you've got a bit of time to just tweak it a bit?
I tweaked the code as you've suggested - thanks for the feedback! Hopefully, this PR can be included in 0.10.9. |
🤞
Yeah that's about what normally happens with me too! Do you want to open a PR against this which I think is what you actually intend to merge now?: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned can we have the PR from your 0.10 branch to our 0.10 one and some other fixes to add to it too.
FWIW, although we've just cut 0.10.9, I'm planning to roll out 0.10.10 within the next few days ideally, or few weeks if a few key outstanding PRs like this one get resolved and merged. |
Yeah, that would make it easier. The "new" PR is now here: #1825 |
Hi,
with these changes the UART plugin can recover the granularity if timing improves, similar to how the FTDI plugin solves this issue.