-
Notifications
You must be signed in to change notification settings - Fork 213
Support added for Nicolaudie SIUDI #1887
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
Open
CreaValix
wants to merge
12
commits into
OpenLightingProject:master
Choose a base branch
from
CreaValix:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e5b3b0c
Support added for Nicolaudie SIUDI
CreaValix 20c6dda
Split comment in UsbDmxPlugin.h to one driver per line
CreaValix 75d5f56
SIUDI: Add USB IDs for SIUDI-6 variants
CreaValix 96e10f7
SIUDI: Rework building the transmit buffer
CreaValix 8e48a0a
SIUDI: Rework USB timing
CreaValix 768def2
SIUDI: Move fixed values to constants
CreaValix abcddc1
SIUDI: Updated authors, udev and Debian metainfo
CreaValix fd056b5
SIUDI: OLA_DEBUG out device info upon start
CreaValix 1a69926
Merge branch 'master' of github.com:CreaValix/ola
CreaValix 42b23c7
SIUDI: Fix buffer size TransmitBuffer
CreaValix 60bc8fe
SIUDI: Fix a typo in SiudiFactory.cpp
CreaValix e3fb809
Merge branch 'master' into master
CreaValix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
/* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Library General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Siudi.cpp | ||
* The synchronous SIUDI widgets. | ||
* Copyright (C) 2023 Alexander Simon | ||
*/ | ||
|
||
#include "plugins/usbdmx/Siudi.h" | ||
|
||
#include <string.h> | ||
#include <unistd.h> | ||
|
||
#include "libs/usb/LibUsbAdaptor.h" | ||
#include "ola/Constants.h" | ||
#include "ola/Logging.h" | ||
#include "ola/strings/Format.h" | ||
#include "plugins/usbdmx/AsyncUsbSender.h" | ||
#include "plugins/usbdmx/ThreadedUsbSender.h" | ||
|
||
namespace ola { | ||
namespace plugin { | ||
namespace usbdmx { | ||
|
||
using ola::usb::LibUsbAdaptor; | ||
|
||
namespace { | ||
|
||
static const uint8_t ENDPOINT = 2; | ||
// SIUDI-6 blocks USB transfers during an ongoing DMX TX. | ||
// One package needs about 32 ms to be sent. | ||
// Wait 30 ms between two USB bulk transfers and expect 2 ms USB response delay. | ||
static const unsigned int BULK_TIMEOUT = 10; | ||
static const unsigned int BULK_DELAY = (30 * 1000); | ||
static const unsigned int CONTROL_TIMEOUT = 500; | ||
static const unsigned int DEVINFO_REQUEST = 0x3f; | ||
static const unsigned int DEVINFO_SIZE = 64; | ||
|
||
} // namespace | ||
|
||
// SiudiThreadedSender | ||
// ----------------------------------------------------------------------------- | ||
|
||
/* | ||
* Sends messages to a SIUDI device in a separate thread. | ||
*/ | ||
class SiudiThreadedSender: public ThreadedUsbSender { | ||
public: | ||
SiudiThreadedSender(LibUsbAdaptor *adaptor, | ||
libusb_device *usb_device, | ||
libusb_device_handle *handle); | ||
|
||
bool Start(); | ||
|
||
private: | ||
LibUsbAdaptor* const m_adaptor; | ||
libusb_device_handle* const m_usb_handle; | ||
|
||
bool TransmitBuffer(libusb_device_handle *handle, | ||
const DmxBuffer &buffer); | ||
}; | ||
|
||
SiudiThreadedSender::SiudiThreadedSender( | ||
LibUsbAdaptor *adaptor, | ||
libusb_device *usb_device, | ||
libusb_device_handle *usb_handle) | ||
: ThreadedUsbSender(usb_device, usb_handle), | ||
m_adaptor(adaptor), m_usb_handle(usb_handle) { | ||
} | ||
|
||
bool SiudiThreadedSender::Start() { | ||
if (!ThreadedUsbSender::Start()) { | ||
return false; | ||
} | ||
|
||
// Read device info. This call takes about 270 ms. | ||
// Discard the buffer as the format is currently unknown. | ||
uint8_t buf[DEVINFO_SIZE]; | ||
int ret = libusb_control_transfer(m_usb_handle, | ||
LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_IN, | ||
DEVINFO_REQUEST, 0x0000, 1, buf, DEVINFO_SIZE, CONTROL_TIMEOUT); | ||
if (ret != DEVINFO_SIZE) { | ||
OLA_WARN << "Failed to read SIUDI information: " | ||
<< (ret < 0 ? LibUsbAdaptor::ErrorCodeToString(ret) : "Short read"); | ||
return false; | ||
} | ||
if (ola::OLA_LOG_DEBUG <= ola::LogLevel()) { | ||
ola::LogLine(__FILE__, __LINE__, ola::OLA_LOG_DEBUG).stream() << "SIUDI device info:"; | ||
ola::strings::FormatData(&std::cout, buf, DEVINFO_SIZE, 4); | ||
ola::LogLine(__FILE__, __LINE__, ola::OLA_LOG_DEBUG).stream() << "If you know how to interprete this, please let us know."; | ||
} | ||
|
||
// Unstall the endpoint. The original software seems to call this regularly. | ||
ret = libusb_clear_halt(m_usb_handle, ENDPOINT); | ||
if (ret != 0) { | ||
OLA_WARN << "Failed to reset SIUDI endpoint: " | ||
<< (ret < 0 ? LibUsbAdaptor::ErrorCodeToString(ret) : "Unknown"); | ||
return false; | ||
} | ||
usleep(BULK_DELAY); // Might receive errors if writing too early. | ||
|
||
return true; | ||
} | ||
|
||
bool SiudiThreadedSender::TransmitBuffer(libusb_device_handle *handle, | ||
const DmxBuffer &buffer) { | ||
int transferred, r; | ||
if (buffer.Size() == ola::DMX_UNIVERSE_SIZE) { | ||
// As we are sending, we can cast the const buffer to a writeable pointer. | ||
r = m_adaptor->BulkTransfer( | ||
handle, ENDPOINT, (unsigned char*)buffer.GetRaw(), | ||
ola::DMX_UNIVERSE_SIZE, &transferred, BULK_TIMEOUT); | ||
} else { | ||
unsigned char buf[ola::DMX_UNIVERSE_SIZE]; | ||
unsigned int buf_get_size = ola::DMX_UNIVERSE_SIZE; | ||
buffer.GetRange(0, buf, &buf_get_size); | ||
if (buf_get_size < ola::DMX_UNIVERSE_SIZE) { | ||
memset(&buf[buf_get_size], 0x00, ola::DMX_UNIVERSE_SIZE - buf_get_size); | ||
} | ||
r = m_adaptor->BulkTransfer( | ||
handle, ENDPOINT, buf, ola::DMX_UNIVERSE_SIZE, &transferred, BULK_TIMEOUT); | ||
} | ||
if (transferred != ola::DMX_UNIVERSE_SIZE) { | ||
// not sure if this is fatal or not | ||
OLA_WARN << "SIUDI driver failed to transfer all data"; | ||
} | ||
usleep(BULK_DELAY); | ||
return r == 0; | ||
} | ||
|
||
// SynchronousSiudi | ||
// ----------------------------------------------------------------------------- | ||
|
||
SynchronousSiudi::SynchronousSiudi(LibUsbAdaptor *adaptor, | ||
libusb_device *usb_device) | ||
: Siudi(adaptor, usb_device) { | ||
} | ||
|
||
bool SynchronousSiudi::Init() { | ||
libusb_device_handle *usb_handle; | ||
|
||
bool ok = m_adaptor->OpenDeviceAndClaimInterface( | ||
m_usb_device, 0, &usb_handle); | ||
if (!ok) { | ||
return false; | ||
} | ||
|
||
std::auto_ptr<SiudiThreadedSender> sender( | ||
new SiudiThreadedSender(m_adaptor, m_usb_device, usb_handle)); | ||
if (!sender->Start()) { | ||
return false; | ||
} | ||
m_sender.reset(sender.release()); | ||
return true; | ||
} | ||
|
||
bool SynchronousSiudi::SendDMX(const DmxBuffer &buffer) { | ||
return m_sender.get() ? m_sender->SendDMX(buffer) : false; | ||
} | ||
} // namespace usbdmx | ||
} // namespace plugin | ||
} // namespace ola |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Library General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Siudi.h | ||
* The synchronous SIUDI widgets. | ||
* Copyright (C) 2023 Alexander Simon | ||
*/ | ||
|
||
#ifndef PLUGINS_USBDMX_SIUDI_H_ | ||
#define PLUGINS_USBDMX_SIUDI_H_ | ||
|
||
#include <libusb.h> | ||
#include <memory> | ||
#include "ola/DmxBuffer.h" | ||
#include "ola/base/Macro.h" | ||
#include "ola/thread/Mutex.h" | ||
#include "plugins/usbdmx/Widget.h" | ||
|
||
namespace ola { | ||
namespace plugin { | ||
namespace usbdmx { | ||
|
||
class SiudiThreadedSender; | ||
|
||
/** | ||
* @brief The interface for the Siudi Widgets | ||
*/ | ||
class Siudi : public SimpleWidget { | ||
public: | ||
explicit Siudi(ola::usb::LibUsbAdaptor *adaptor, | ||
libusb_device *usb_device) | ||
: SimpleWidget(adaptor, usb_device) { | ||
} | ||
}; | ||
|
||
|
||
/** | ||
* @brief An SIUDI widget that uses synchronous libusb operations. | ||
* | ||
* Internally this spawns a new thread to avoid blocking SendDMX() calls. | ||
*/ | ||
class SynchronousSiudi: public Siudi { | ||
public: | ||
/** | ||
* @brief Create a new SynchronousSiudi. | ||
* @param adaptor the LibUsbAdaptor to use. | ||
* @param usb_device the libusb_device to use for the widget. | ||
*/ | ||
SynchronousSiudi(ola::usb::LibUsbAdaptor *adaptor, | ||
libusb_device *usb_device); | ||
|
||
bool Init(); | ||
|
||
bool SendDMX(const DmxBuffer &buffer); | ||
|
||
private: | ||
std::auto_ptr<class ThreadedUsbSender> m_sender; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(SynchronousSiudi); | ||
}; | ||
} // namespace usbdmx | ||
} // namespace plugin | ||
} // namespace ola | ||
#endif // PLUGINS_USBDMX_SIUDI_H_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Library General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* SiudiFactory.cpp | ||
* The WidgetFactory for SIUDI widgets. | ||
* Copyright (C) 2023 Alexander Simon | ||
*/ | ||
|
||
#include "plugins/usbdmx/SiudiFactory.h" | ||
|
||
#include "ola/Logging.h" | ||
#include "ola/base/Flags.h" | ||
|
||
DECLARE_bool(use_async_libusb); | ||
|
||
namespace ola { | ||
namespace plugin { | ||
namespace usbdmx { | ||
|
||
const uint16_t SiudiFactory::NICOLAUDIE_ID = 0x6244; | ||
const uint16_t SiudiFactory::SIUDI6_COLD_ID = 0x0300; | ||
const uint16_t SiudiFactory::SIUDI6C_HOT_ID = 0x301; | ||
const uint16_t SiudiFactory::SIUDI6A_HOT_ID = 0x302; | ||
const uint16_t SiudiFactory::SIUDI6D_HOT_ID = 0x303; | ||
|
||
bool SiudiFactory::DeviceAdded( | ||
WidgetObserver *observer, | ||
libusb_device *usb_device, | ||
const struct libusb_device_descriptor &descriptor) { | ||
if (descriptor.idVendor != NICOLAUDIE_ID) { | ||
return false; | ||
} | ||
if (descriptor.idProduct == SIUDI6_COLD_ID) { | ||
OLA_WARN << "Found a Nicoleaudie SIUDI-6 device in cold state. " | ||
"Firmware download is currently not supported."; | ||
return false; | ||
} | ||
if (descriptor.idProduct == SIUDI6C_HOT_ID || | ||
descriptor.idProduct == SIUDI6A_HOT_ID || | ||
descriptor.idProduct == SIUDI6D_HOT_ID) { | ||
if (descriptor.idProduct == SIUDI6C_HOT_ID) { | ||
OLA_INFO << "Found a new Nicoleaudie SIUDI-6C device"; | ||
} else if (descriptor.idProduct == SIUDI6A_HOT_ID) { | ||
OLA_INFO << "Found a new Nicoleaudie SIUDI-6A device"; | ||
} else if (descriptor.idProduct == SIUDI6A_HOT_ID) { | ||
OLA_INFO << "Found a new Nicoleaudie SIUDI-6D device"; | ||
} | ||
Siudi *widget = NULL; | ||
widget = new SynchronousSiudi(m_adaptor, usb_device); | ||
return AddWidget(observer, widget); | ||
} | ||
CreaValix marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return false; | ||
} | ||
} // namespace usbdmx | ||
} // namespace plugin | ||
} // namespace ola |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.