Open Lighting Architecture: plugins/usbdmx/AsyncUsbTransceiverBase.h Source File

| Open Lighting Architecture 0.10.9

Loading...
Searching...
No Matches
AsyncUsbTransceiverBase.h
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU Library General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15 *
16 * AsyncUsbTransceiverBase.h
17 * An Asynchronous DMX USB transceiver.
18 * Copyright (C) 2014 Simon Newton
19 */
20
21#ifndef PLUGINS_USBDMX_ASYNCUSBTRANSCEIVERBASE_H_
22#define PLUGINS_USBDMX_ASYNCUSBTRANSCEIVERBASE_H_
23
24#include <libusb.h>
25
26#include "libs/usb/LibUsbAdaptor.h"
27#include "ola/DmxBuffer.h"
28#include "ola/base/Macro.h"
29#include "ola/thread/Mutex.h"
30
31namespace ola {
32namespace plugin {
33namespace usbdmx {
34
39 class AsyncUsbTransceiverBase {
40 public:
46 AsyncUsbTransceiverBase(ola::usb::LibUsbAdaptor* const adaptor,
47 libusb_device *usb_device);
48
52 virtual ~AsyncUsbTransceiverBase();
53
58 bool Init();
59
65 virtual void TransferComplete(struct libusb_transfer *transfer) = 0;
66
71 libusb_device_handle *GetHandle() { return m_usb_handle; }
72
73 protected:
77 ola::usb::LibUsbAdaptor* const m_adaptor;
78
82 libusb_device* const m_usb_device;
83
89 virtual libusb_device_handle* SetupHandle() = 0;
90
97 virtual void PostTransferHook() {}
98
102 void CancelTransfer();
103
109 void FillControlTransfer(unsigned char *buffer, unsigned int timeout);
110
114 void FillBulkTransfer(unsigned char endpoint, unsigned char *buffer,
115 int length, unsigned int timeout);
116
120 void FillInterruptTransfer(unsigned char endpoint, unsigned char *buffer,
121 int length, unsigned int timeout);
122
127 int SubmitTransfer();
128
129 enum TransferState {
130 IDLE,
131 IN_PROGRESS,
132 DISCONNECTED,
133 };
134
135 libusb_device_handle *m_usb_handle;
136 bool m_suppress_continuation;
137 struct libusb_transfer *m_transfer;
138
139 TransferState m_transfer_state; // GUARDED_BY(m_mutex);
140 ola::thread::Mutex m_mutex;
141
142 private:
143 AsyncUsbTransceiverBase(const AsyncUsbTransceiverBase &) = delete;
144 const AsyncUsbTransceiverBase &operator=(const AsyncUsbTransceiverBase &) = delete;
145};
146} // namespace usbdmx
147} // namespace plugin
148} // namespace ola
149#endif // PLUGINS_USBDMX_ASYNCUSBTRANSCEIVERBASE_H_
DmxBuffer.h
A class used to hold a single universe of DMX data.
Macro.h
Helper macros.
ola::plugin::usbdmx::AsyncUsbTransceiverBase::~AsyncUsbTransceiverBase
virtual ~AsyncUsbTransceiverBase()
Destructor.
Definition AsyncUsbTransceiverBase.cpp:58
ola::plugin::usbdmx::AsyncUsbTransceiverBase::m_usb_device
libusb_device *const m_usb_device
The libusb_device passed in the constructor.
Definition AsyncUsbTransceiverBase.h:82
ola::plugin::usbdmx::AsyncUsbTransceiverBase::PostTransferHook
virtual void PostTransferHook()
Called when the transfer completes.
Definition AsyncUsbTransceiverBase.h:97
ola::plugin::usbdmx::AsyncUsbTransceiverBase::m_adaptor
ola::usb::LibUsbAdaptor *const m_adaptor
The LibUsbAdaptor passed in the constructor.
Definition AsyncUsbTransceiverBase.h:77
ola::plugin::usbdmx::AsyncUsbTransceiverBase::FillInterruptTransfer
void FillInterruptTransfer(unsigned char endpoint, unsigned char *buffer, int length, unsigned int timeout)
Fill an interrupt transfer.
Definition AsyncUsbTransceiverBase.cpp:107
ola::plugin::usbdmx::AsyncUsbTransceiverBase::Init
bool Init()
Initialize the transceiver.
Definition AsyncUsbTransceiverBase.cpp:64
ola::plugin::usbdmx::AsyncUsbTransceiverBase::GetHandle
libusb_device_handle * GetHandle()
Get the libusb_device_handle of an already opened widget.
Definition AsyncUsbTransceiverBase.h:71
ola::plugin::usbdmx::AsyncUsbTransceiverBase::CancelTransfer
void CancelTransfer()
Cancel any pending transfers.
Definition AsyncUsbTransceiverBase.cpp:69
ola::plugin::usbdmx::AsyncUsbTransceiverBase::SetupHandle
virtual libusb_device_handle * SetupHandle()=0
Open the device handle.
ola::plugin::usbdmx::AsyncUsbTransceiverBase::TransferComplete
virtual void TransferComplete(struct libusb_transfer *transfer)=0
Called from the libusb callback when the asynchronous transfer completes.
ola::plugin::usbdmx::AsyncUsbTransceiverBase::AsyncUsbTransceiverBase
AsyncUsbTransceiverBase(ola::usb::LibUsbAdaptor *const adaptor, libusb_device *usb_device)
Create a new AsyncUsbTransceiverBase.
Definition AsyncUsbTransceiverBase.cpp:47
ola::plugin::usbdmx::AsyncUsbTransceiverBase::SubmitTransfer
int SubmitTransfer()
Submit the transfer for tx.
Definition AsyncUsbTransceiverBase.cpp:115
ola::plugin::usbdmx::AsyncUsbTransceiverBase::FillControlTransfer
void FillControlTransfer(unsigned char *buffer, unsigned int timeout)
Fill a control transfer.
Definition AsyncUsbTransceiverBase.cpp:93
ola::plugin::usbdmx::AsyncUsbTransceiverBase::FillBulkTransfer
void FillBulkTransfer(unsigned char endpoint, unsigned char *buffer, int length, unsigned int timeout)
Fill a bulk transfer.
Definition AsyncUsbTransceiverBase.cpp:99
ola::thread::Mutex
Definition Mutex.h:41
ola::usb::LibUsbAdaptor
Wraps calls to libusb so we can test the code.
Definition LibUsbAdaptor.h:36
ola::plugin::usbdmx
The plugin for hardware using libusb.
ola::plugin
Code for supported devices and protocols.
ola
The namespace containing all OLA symbols.
Definition Credentials.cpp:44