Skip to content

SPI DMX receiver - #1289

Merged
peternewman merged 24 commits into
OpenLightingProject:masterfrom
FloEdelmann:spidmx
Nov 2, 2017
Merged

SPI DMX receiver#1289
peternewman merged 24 commits into
OpenLightingProject:masterfrom
FloEdelmann:spidmx

Conversation

@FloEdelmann

@FloEdelmann FloEdelmann commented Jul 21, 2017

Copy link
Copy Markdown
Member

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, running olad gives

olad: error while loading shared libraries: libolaspidmx.so.0: cannot open shared object file: No such file or directory

I'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. spidev is actually not available on Mac so it is skipped completely.

@FloEdelmann

FloEdelmann commented Jul 21, 2017

Copy link
Copy Markdown
Member Author

It basically works! 🎉

I had to manually set the LD_LIBRARY_PATH environment variable to /usr/local/lib; it was empty before. Any idea how that could have happened?

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 :)

@FloEdelmann FloEdelmann changed the title [WIP] SPI DMX receiver SPI DMX receiver Jul 22, 2017
@FloEdelmann

Copy link
Copy Markdown
Member Author

Now it's finished. I'd be happy to see you review it :)

@peternewman peternewman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@peternewman peternewman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An initial review

Comment thread plugins/spidmx/SpiDmxDevice.cpp Outdated
}

bool save = m_preferences->SetDefaultValue(DeviceBlocklength(),
UIntValidator(0, 65535),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surely 0 as a minimum value is nonsense, you want at least 1 slot don't you?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment thread plugins/spidmx/SpiDmxParser.cpp Outdated
while (chunk_bitcount < buffersize) {
switch (state) {
case WAIT_FOR_BREAK:
// printf("%6ld 0x%02x wait for break (%d)\n", chunk_bitcount,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove this debug please, or convert it to OLA_DEBUG.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread plugins/spidmx/SpiDmxParser.cpp Outdated

/**
* 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SPaG "is not a falling edge" is I think what you're trying to say?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread plugins/spidmx/SpiDmxParser.cpp Outdated

/**
* 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread plugins/spidmx/SpiDmxPlugin.cpp Outdated
* 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SPaG instantiate

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread plugins/spidmx/SpiDmxPlugin.h Outdated
m_plugin_adaptor(plugin_adaptor) {
}

ola_plugin_id Id() const { return OLA_PLUGIN_EXPERIMENTAL; }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@peternewman peternewman Sep 5, 2017

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made an attempt in b8ecf02. Is this okay?

Comment thread plugins/spidmx/SpiDmxThread.cpp Outdated
void SpiDmxThread::RegisterPort() {
m_registered_ports++;

if (m_registered_ports == 1) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

= 1 perhaps, although it shouldn't happen.

@peternewman peternewman Sep 5, 2017

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done for understanding what I meant, even when the GitHub markdown confused it!

Comment thread plugins/spidmx/SpiDmxThread.cpp Outdated
void SpiDmxThread::UnregisterPort() {
m_registered_ports--;

if (m_registered_ports == 0) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<= 0 again just in case.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@peternewman peternewman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So apologies again, as per the comment in #1286 (review) , can we change the C++ classes to be called SPIDMX...?

Comment thread plugins/spidmx/README.md Outdated

`<device>-blocklength = 4096`
How many SPI bytes (= DMX bits) should be received (optional). The default
is 4096, but 8192 is recommended.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of interest, how come we don't default to the value we recommend?

@FloEdelmann FloEdelmann Sep 5, 2017

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@peternewman peternewman Sep 9, 2017

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@FloEdelmann FloEdelmann Sep 11, 2017

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like this? (8724254)

Comment thread common/protocol/Ola.proto
* 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want this to be values of 10000 or more (so e.g. "a value of 10000 or greater")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread plugins/spidmx/SPIDMXWidget.cpp Outdated

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"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps say "This may be due to a buffer size mismatch" or something similar.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread plugins/spidmx/README.md Outdated

`device_prefix = <string>`
The prefix of files to match in `/dev`. Usually set to `spidev`. Each match
will instantiate a device.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add a note here that multiple device_prefix lines are supported.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread plugins/spidmx/SPIDMXThread.cpp Outdated
}

/**
* This thread does only have to run if ports using it are patched to a

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SPaG "This thread only has to run if..."

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

* @param callback The callback to call.
*/
bool SPIDMXThread::SetReceiveCallback(Callback0<void> *callback) {
if (!callback) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this either be m_receive_callback, or the line below do a reset to NULL?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, thanks!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, done.

Comment thread plugins/spidmx/SPIDMXWidget.cpp Outdated
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* SPIDMXWidget.cpp
* This is a wrapper around the needed SPIDEV calls.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SPaG "the required SPIDEV"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread plugins/spidmx/SPIDMXWidget.h Outdated
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* SPIDMXWidget.h
* This is a wrapper around the needed SPIDEV calls.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@peternewman peternewman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few more minor changes from me please.

@peternewman
peternewman requested a review from nomis52 September 19, 2017 03:43
@peternewman

Copy link
Copy Markdown
Member

LGTM, over to @nomis52 .

@FloEdelmann

Copy link
Copy Markdown
Member Author

Any news on this?

@peternewman peternewman assigned nomis52 and unassigned nomis52 Oct 16, 2017
@peternewman

Copy link
Copy Markdown
Member

@nomis52 have you got any time to review this please?

@peternewman peternewman assigned nomis52 and unassigned nomis52 Oct 27, 2017
@peternewman peternewman added this to the 0.11.0 milestone Oct 28, 2017
@FloEdelmann

Copy link
Copy Markdown
Member Author

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 :)

@nomis52 nomis52 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM bar the one comment.

Comment thread common/protocol/Ola.proto Outdated
OLA_PLUGIN_UARTDMX = 20;
OLA_PLUGIN_OPENPIXELCONTROL = 21;
OLA_PLUGIN_GPIO = 22;
OLA_PLUGIN_SPIDMX = 10001;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're merging to mainline this should have a non-dev code.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well spotted!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@peternewman
peternewman merged commit f9e7a76 into OpenLightingProject:master Nov 2, 2017
@FloEdelmann

Copy link
Copy Markdown
Member Author

Nice, thank you! :)

@FloEdelmann
FloEdelmann deleted the spidmx branch November 2, 2017 21:33
@peternewman

Copy link
Copy Markdown
Member

No worries, thanks for the code @FloEdelmann .

Coverity is complaining about:

** CID 185518:  Uninitialized members  (UNINIT_CTOR)
/plugins/spidmx/SPIDMXParser.h: 38 in ola::plugin::spidmx::SPIDMXParser::SPIDMXParser(ola::DmxBuffer *, ola::Callback0<void> *)()


________________________________________________________________________________________________________
*** CID 185518:  Uninitialized members  (UNINIT_CTOR)
/plugins/spidmx/SPIDMXParser.h: 38 in ola::plugin::spidmx::SPIDMXParser::SPIDMXParser(ola::DmxBuffer *, ola::Callback0<void> *)()
32
33     class SPIDMXParser {
34      public:
35       SPIDMXParser(DmxBuffer *buffer, Callback0<void> *callback)
36         : m_dmx_buffer(buffer),
37           m_callback(callback) {
>>>     CID 185518:  Uninitialized members  (UNINIT_CTOR)
>>>     Non-static class member "sampling_position" is not initialized in this constructor nor in any functions that it calls.
38       }
39       void ParseDmx(uint8_t *buffer, uint64_t chunksize);
40       void SetCallback(Callback0<void> *callback) {
41         m_callback = callback;
42       }
43

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 ?

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.

3 participants