SPI DMX receiver - #1289
Conversation
|
It basically works! 🎉 I had to manually set the I still have to look into an occasionally happening segfault because it tries to free already freed memory. Also, documentation is still incomplete. But apart from that, I'm finished :) |
|
Now it's finished. I'd be happy to see you review it :) |
peternewman
left a comment
There was a problem hiding this comment.
A quick one for starters, can you fix the lint and Doxygen failures on Travis please @FloEdelmann . I'll try and find some time for a proper review soon.
| } | ||
|
|
||
| bool save = m_preferences->SetDefaultValue(DeviceBlocklength(), | ||
| UIntValidator(0, 65535), |
There was a problem hiding this comment.
Surely 0 as a minimum value is nonsense, you want at least 1 slot don't you?
| while (chunk_bitcount < buffersize) { | ||
| switch (state) { | ||
| case WAIT_FOR_BREAK: | ||
| // printf("%6ld 0x%02x wait for break (%d)\n", chunk_bitcount, |
There was a problem hiding this comment.
Can we remove this debug please, or convert it to OLA_DEBUG.
There was a problem hiding this comment.
If I put it in OLA_DEBUG, it outputs so much that receiving gets too laggy to be usable. I'll remove those comments shortly before merging but I keep them until then for easy debugging.
|
|
||
| /** | ||
| * Helper function that returns the number of zeros if a falling edge is | ||
| * detected in the given byte or -1 if the byte is no falling edge. |
There was a problem hiding this comment.
SPaG "is not a falling edge" is I think what you're trying to say?
|
|
||
| /** | ||
| * Helper function that returns the number of ones if a rising edge is | ||
| * detected in the given byte or -1 if the byte is no rising edge. |
| * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| * | ||
| * SpiDmxPlugin.cpp | ||
| * This looks for possible SPI devices to instanciate and is managed by OLAD. |
| m_plugin_adaptor(plugin_adaptor) { | ||
| } | ||
|
|
||
| ola_plugin_id Id() const { return OLA_PLUGIN_EXPERIMENTAL; } |
There was a problem hiding this comment.
Can you define a new OLA_PLUGIN_SPIDMX in https://github.com/OpenLightingProject/ola/blob/master/common/protocol/Ola.proto and set the value to 10000 for now, then we'll confirm an actual value when it gets merged. But doing it that way will increase the chances we'll remember to do so!
There was a problem hiding this comment.
When makeing, I get the following error:
"ola.proto.OLA_PLUGIN_EXPERIMENTAL" uses the same enum value as "ola.proto.OLA_PLUGIN_SPIDMX". If this is intended, set 'option allow_alias = true;' to the enum definition.
Should I add the suggested option somewhere (where?) or just set the constant to 9999?
There was a problem hiding this comment.
Interestingly this only happens on the OS X builds, which I think use a later protobuf.
As you can probably tell, we've only been through this particular workflow a few times with PRs. Essentially what we're trying to do initially is stopping you grabbing 23 for example and someone else having it too, as well as ensuring your code doesn't just use the OLA_PLUGIN_EXPERIMENTAL constant. I guess we could either comment out OLA_PLUGIN_EXPERIMENTAL (which will kill your same enum value error, or perhaps just change the comment there to say an ID greater than OLA_PLUGIN_EXPERIMENTAL, and allow a free for all up there, knowing they'll get updated before merging.
As a PR submitter, which one makes sense/is most clear to you? How can we reword the code comment so you'd do that from the off, rather than what you interpreted it as?
There was a problem hiding this comment.
Do we need the OLA_PLUGIN_EXPERIMENTAL then at all? The comment could just say that all IDs above 10000 are experimental and used during development until a fixed IDs is assigned.
There was a problem hiding this comment.
Yeah you're right, we probably don't. Hopefully that will make it less confusing for people too. Do you fancy trying to update the words for this, or would you rather I did it?
There was a problem hiding this comment.
I've made an attempt in b8ecf02. Is this okay?
| void SpiDmxThread::RegisterPort() { | ||
| m_registered_ports++; | ||
|
|
||
| if (m_registered_ports == 1) { |
There was a problem hiding this comment.
= 1 perhaps, although it shouldn't happen.
There was a problem hiding this comment.
Well done for understanding what I meant, even when the GitHub markdown confused it!
| void SpiDmxThread::UnregisterPort() { | ||
| m_registered_ports--; | ||
|
|
||
| if (m_registered_ports == 0) { |
peternewman
left a comment
There was a problem hiding this comment.
So apologies again, as per the comment in #1286 (review) , can we change the C++ classes to be called SPIDMX...?
|
|
||
| `<device>-blocklength = 4096` | ||
| How many SPI bytes (= DMX bits) should be received (optional). The default | ||
| is 4096, but 8192 is recommended. |
There was a problem hiding this comment.
Out of interest, how come we don't default to the value we recommend?
There was a problem hiding this comment.
On the Raspberry Pi, a 4kB read / transmit buffer is available without further configuration. If one wants to read more than that in a single call, the buffer size needs to be increased via a command line call. The default configuration should work without this call, though.
There was a problem hiding this comment.
Ah yes, a few lines up the same file. I wonder if it's worth an N.B. here when recommending 8192 that they'll need to do some local config to enable this. I see you've already done this...
Can you also detect and log that there's a mismatch based on the number of bytes returned when you do the reads, to alert the user their config isn't correct?
There was a problem hiding this comment.
The call used to read / write (ioctl, in SPIDMXWidget.cpp) does not return the number of received / transmitted bytes but only an unspecified non-negative integer or -1 in an error case.
Since the call fails if the buffer is not big enough, the check should already be enough, I guess.
There was a problem hiding this comment.
That's a shame. Perhaps the error on the line below needs a hint about buffer sizes though, if changing the value to 4097 will cause it to break?
| * Plugin IDs are usually assigned just prior to merging the code into the | ||
| * mainline. For development of plugins please use the value of | ||
| * OLA_PLUGIN_EXPERIMENTAL in a plugin ID you define above. | ||
| * mainline. During development of new plugins, please use a value of 10000 |
There was a problem hiding this comment.
We probably want this to be values of 10000 or more (so e.g. "a value of 10000 or greater")
|
|
||
| int ret = ioctl(m_fd, SPI_IOC_MESSAGE(1), &tr); | ||
| if (ret < 1) { | ||
| OLA_WARN << Name() << " ioctl read/write error. Maybe this is due to a" |
There was a problem hiding this comment.
Perhaps say "This may be due to a buffer size mismatch" or something similar.
|
|
||
| `device_prefix = <string>` | ||
| The prefix of files to match in `/dev`. Usually set to `spidev`. Each match | ||
| will instantiate a device. |
There was a problem hiding this comment.
You should add a note here that multiple device_prefix lines are supported.
| } | ||
|
|
||
| /** | ||
| * This thread does only have to run if ports using it are patched to a |
There was a problem hiding this comment.
SPaG "This thread only has to run if..."
| * @param callback The callback to call. | ||
| */ | ||
| bool SPIDMXThread::SetReceiveCallback(Callback0<void> *callback) { | ||
| if (!callback) { |
There was a problem hiding this comment.
Shouldn't this either be m_receive_callback, or the line below do a reset to NULL?
| * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| * | ||
| * SPIDMXWidget.cpp | ||
| * This is a wrapper around the needed SPIDEV calls. |
| * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| * | ||
| * SPIDMXWidget.h | ||
| * This is a wrapper around the needed SPIDEV calls. |
peternewman
left a comment
There was a problem hiding this comment.
Just a few more minor changes from me please.
|
LGTM, over to @nomis52 . |
|
Any news on this? |
|
@nomis52 have you got any time to review this please? |
|
Since this PR will be referenced in my Bachelor's Thesis due next month, it would be nice if it could already be merged then :) |
| OLA_PLUGIN_UARTDMX = 20; | ||
| OLA_PLUGIN_OPENPIXELCONTROL = 21; | ||
| OLA_PLUGIN_GPIO = 22; | ||
| OLA_PLUGIN_SPIDMX = 10001; |
There was a problem hiding this comment.
If we're merging to mainline this should have a non-dev code.
|
Nice, thank you! :) |
|
No worries, thanks for the code @FloEdelmann . Coverity is complaining about: I've not looked carefully enough to realise why it's only moaning about sampling_position and not the other members, but would you mind resolving this in a new PR please @FloEdelmann ? |
Closes #1285, see there for a description.
This is still a work in progress, I just want Travis to run its tests. On my laptop I compile and run it fine. On the Raspberry, even with a fresh
autoreconf, after compiling and installing, runningoladgivesI'm confused since it works on my laptop, so I can't have missed something, right?
EDIT: Apparently, Travis does also only fail due to a mistake in protobuf.
spidevis actually not available on Mac so it is skipped completely.