Skip to content
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

Added DMXCreator 512 Basic USB interface #1136

Merged
merged 27 commits into from
Nov 9, 2016

Conversation

FloEdelmann
Copy link
Member

@FloEdelmann FloEdelmann commented Oct 14, 2016

see http://www.dmx512.ch/512.html

I reverse-engineered the USB protocol using WireShark and USBPcap. This is my first try, so there may be some functions that I didn't implement or that could be better, please just let me know.

DMXCreator sends two URB packets for each change:

  1. A constant byte string to endpoint 1 that indicates new data.
  2. The actual DMX data to endpoint 2.

It currently only supports 256 channels, I may work on that later. (Fixed in df44d5a)
Also, there is a bug that lets it consume way too much memory in synchronous libusb mode until it eventually gets killed.

see http://www.dmx512.ch/512.html

I reverse-engineered the USB protocol using WireShark and USBPcap. This is
my first try, so there may be some functions that I didn't implement or that
could be better, please just let me know.

DMXCreator sends two URB packets for each change:
1. A constant byte string to endpoint 1 that indicates new data.
2. The actual DMX data to endpoint 2.

It currently only supports 256 channels, I may work on that later.
Also, there is a bug that lets it consume way too much memory in synchronous
libusb mode until it eventually gets killed.
@FloEdelmann
Copy link
Member Author

There is one more bug: It doesn't handle unplugging correctly so the next time it gets plugged in, it refuses to connect because of the missing serial number (there can always only be one DMXCreator device at a time).

@peternewman peternewman self-assigned this Oct 17, 2016
Copy link
Member

@peternewman peternewman left a comment

Choose a reason for hiding this comment

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

A few comments so far.

We're also about to merge #1134 which will need a bit of minor tidying on your side to fix.

plugins/usbdmx/DMXCreatorFactory.cpp Show resolved Hide resolved
@@ -56,7 +56,7 @@ bool UsbDmxPlugin::StartHook() {
}

unsigned int debug_level;
if (!StringToInt(m_preferences->GetValue(LIBUSB_DEBUG_LEVEL_KEY) ,
if (!StringToInt(m_preferences->GetValue(LIBUSB_DEBUG_LEVEL_KEY),
Copy link
Member

Choose a reason for hiding this comment

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

Good spot!

plugins/usbdmx/UsbDmxPlugin.cpp Show resolved Hide resolved
@peternewman
Copy link
Member

I think the unplugging bug will be because m_missing_serial_number never gets reset when the serial number less widget gets unplugged. I suspect this bug affects all the widgets with the same code.

@peternewman peternewman added this to the 0.11.0 milestone Oct 17, 2016
@peternewman
Copy link
Member

I'd imagine you send a different constant to endpoint 1 to send the other half of the universe, or perhaps just a second packet to endpoint 2 before you send the endpoint 1 data (i.e. sending to endpoint 1 may reset the slot counter back to 0).

@peternewman
Copy link
Member

Hopefully the synchronous issue can be fixed, if not, it probably needs to be disabled for the moment.

@peternewman
Copy link
Member

The other PR is in, so you can resync this.

* allow all 512 channels to be sent
* disabled synchronous mode for now
* made timeout much shorter
* changed display name
@FloEdelmann
Copy link
Member Author

FloEdelmann commented Oct 18, 2016

It was exactly as you said: Just send two packets after another to endpoint 2. But I also had to change the constant that is sent to endpoint 1. It took me quite a while to figure that out 🙈

The unplugging bug and the synchronous mode issue unfortunately do both still exist. I'll look into them soon.

@peternewman
Copy link
Member

Please can you add the device to the list in plugins/usbdmx/UsbDmxPlugin.h too.

plugins/usbdmx/DMXCreator.cpp Show resolved Hide resolved
plugins/usbdmx/DMXCreator.cpp Show resolved Hide resolved
plugins/usbdmx/DMXCreator.cpp Show resolved Hide resolved
plugins/usbdmx/DMXCreator.cpp Show resolved Hide resolved
}

bool PerformTransfer(const DmxBuffer &buffer) {
// if we only wanted to send the first half, the last byte would be 0x01
Copy link
Member

Choose a reason for hiding this comment

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

I take it you've not worked out what the other bytes in the packet do?

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately not. I just have this one device for testing, I guess the other DMXCreator dongles use other bytes.

OLA_INFO << "Found a new DMXCreator device";
// Unfortunately, DMXCreator devices don't provide any additional information
// that identify them. So we have to stick with just testing vendor and
// product ids. Also, since DMXCreator devices don't have serial numbers and
Copy link
Member

Choose a reason for hiding this comment

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

Do you know for certain that none have serial numbers?

The m_adaptor->GetDeviceInfo(usb_device, descriptor, &info) call ought to succeed if the device is present, even if it returns no other info, so you could do the following still, and just remove the vendor/device name checks:

  LibUsbAdaptor::DeviceInformation info;
  if (!m_adaptor->GetDeviceInfo(usb_device, descriptor, &info)) {
    return false;
  }

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, I'll do that. I'm not completely sure that none of those devices have serial numbers but I think they don't since they do not even return valid manufacturer / product names.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks. As you say, I suspect they're unlikely to have serial numbers, but it would be a shame to be missing the functionality if they did (given it's already been written).

plugins/usbdmx/DMXCreatorFactory.cpp Show resolved Hide resolved
plugins/usbdmx/DMXCreatorFactory.h Show resolved Hide resolved
plugins/usbdmx/UsbDmxPlugin.cpp Show resolved Hide resolved
plugins/usbdmx/UsbDmxPlugin.cpp Show resolved Hide resolved
@peternewman
Copy link
Member

Can you also add the 512 Basic bit to the filenames too please, given they already have other interfaces we might want to support in future.

@FloEdelmann FloEdelmann changed the title Added DMXCreator USB interface Added DMXCreator 512 Basic USB interface Oct 19, 2016
peternewman and others added 3 commits October 19, 2016 11:19
* rename "DMXCreator" and "DMXCreator 512 Basic" to "DMXCreator512Basic" to be consistent
* add serial check again
* more minor fixes
causing doxygen to fail
Copy link
Member

@peternewman peternewman left a comment

Choose a reason for hiding this comment

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

A few more minor comments.

AUTHORS Show resolved Hide resolved
debian/ola.udev Show resolved Hide resolved
plugins/usbdmx/AsyncPluginImpl.cpp Show resolved Hide resolved
plugins/usbdmx/DMXCreator512Basic.cpp Show resolved Hide resolved
plugins/usbdmx/DMXCreator512Basic.cpp Show resolved Hide resolved
plugins/usbdmx/DMXCreator512BasicFactory.cpp Show resolved Hide resolved
plugins/usbdmx/DMXCreator512BasicFactory.cpp Show resolved Hide resolved
plugins/usbdmx/DMXCreator512BasicFactory.h Show resolved Hide resolved
plugins/usbdmx/SyncPluginImpl.cpp Show resolved Hide resolved
plugins/usbdmx/UsbDmxPlugin.cpp Show resolved Hide resolved
@FloEdelmann
Copy link
Member Author

Everything should be fine now 😉

return true;
}

m_dmx_buffer = new DmxBuffer(buffer); // force copy
Copy link
Member

Choose a reason for hiding this comment

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

You're copying the buffer just to see if it's changed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Is there a better way?

Copy link
Member

Choose a reason for hiding this comment

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

It was partly just a comment that you could use it for the buffer.Get/GetRange calls.

Copy link
Member Author

Choose a reason for hiding this comment

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

I honestly don't see an advantage in that.

Copy link
Member

Choose a reason for hiding this comment

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

Not that I can immediately think of.

Copy link
Member

Choose a reason for hiding this comment

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

No specific advantage, but it would just mean you sort of take control of that data and only use that data in the plugin. You've currently got an odd mix of the locally cached and freshly fed in data.

Copy link
Member

Choose a reason for hiding this comment

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

Actually, there is an improvement, you can switch to m_dmx_buffer = buffer; Due to some magic we do in the background, it will copy the data if it needs to, but otherwise just leave it as a pointer.

@FloEdelmann
Copy link
Member Author

Travis failed due to the GitHub outage, I guess.

https://status.github.com/

plugins/usbdmx/DMXCreator512Basic.cpp Show resolved Hide resolved
plugins/usbdmx/DMXCreator512Basic.cpp Show resolved Hide resolved
plugins/usbdmx/DMXCreator512Basic.cpp Show resolved Hide resolved
plugins/usbdmx/DMXCreator512Basic.cpp Show resolved Hide resolved
}

bytes_sent = 0;
r = m_adaptor->BulkTransfer(handle, ENDPOINT_2,
Copy link
Member

Choose a reason for hiding this comment

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

I'd move this code into a function since it's repeated 3 times.

plugins/usbdmx/DMXCreator512Basic.cpp Show resolved Hide resolved
plugins/usbdmx/DMXCreator512Basic.cpp Show resolved Hide resolved
@FloEdelmann
Copy link
Member Author

Sorry, I pushed by accident. Just ignore this commit until I comment again.

@FloEdelmann
Copy link
Member Author

FloEdelmann commented Oct 25, 2016

Now the BulkTransfer works as before. The size was wrong.
Also, I reduced the wait time to 50ns, that still works as expected.

@FloEdelmann
Copy link
Member Author

FloEdelmann commented Oct 26, 2016

Travis' PyChecker failed again due to network outage. Don't know if it was Sourceforge or Travis itself. At least it was not me ;)

Anyway, that test has nothing to do with my changes and the compiler tests come out well.

@FloEdelmann
Copy link
Member Author

Any updates on this? I believe I have addressed all of your requested changes @peternewman @nomis52

@peternewman
Copy link
Member

Hi @FloEdelmann , sorry I've been rather busy, I'll try and look in the next day or two.

Copy link
Member

@peternewman peternewman left a comment

Choose a reason for hiding this comment

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

Just a few more changes please.

plugins/usbdmx/DMXCreator512Basic.cpp Show resolved Hide resolved
plugins/usbdmx/DMXCreator512Basic.cpp Show resolved Hide resolved
plugins/usbdmx/DMXCreator512Basic.cpp Show resolved Hide resolved
plugins/usbdmx/DMXCreator512Basic.cpp Show resolved Hide resolved
plugins/usbdmx/DMXCreator512Basic.cpp Show resolved Hide resolved
@peternewman
Copy link
Member

@nomis52 any final comments from you?

@peternewman peternewman merged commit 8c0aea9 into OpenLightingProject:master Nov 9, 2016
@FloEdelmann
Copy link
Member Author

Yay, it's done! 🎉

@FloEdelmann FloEdelmann deleted the usb-dmxcreator branch November 9, 2016 21:17
@peternewman
Copy link
Member

Yep thanks for all your hard work @FloEdelmann , now onto the next one...

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.

None yet

3 participants