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
40 public:
47 libusb_device *usb_device);
48
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:
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:
144 const AsyncUsbTransceiverBase &operator=(const AsyncUsbTransceiverBase &) = delete;
145};
146} // namespace usbdmx
147} // namespace plugin
148} // namespace ola
149#endif // PLUGINS_USBDMX_ASYNCUSBTRANSCEIVERBASE_H_
A class used to hold a single universe of DMX data.
Helper macros.
A base class that implements common functionality to send or receive DMX asynchronously to a libusb_d...
Definition AsyncUsbTransceiverBase.h:39
virtual ~AsyncUsbTransceiverBase()
Destructor.
Definition AsyncUsbTransceiverBase.cpp:58
libusb_device *const m_usb_device
The libusb_device passed in the constructor.
Definition AsyncUsbTransceiverBase.h:82
virtual void PostTransferHook()
Called when the transfer completes.
Definition AsyncUsbTransceiverBase.h:97
ola::usb::LibUsbAdaptor *const m_adaptor
The LibUsbAdaptor passed in the constructor.
Definition AsyncUsbTransceiverBase.h:77
void FillInterruptTransfer(unsigned char endpoint, unsigned char *buffer, int length, unsigned int timeout)
Fill an interrupt transfer.
Definition AsyncUsbTransceiverBase.cpp:107
bool Init()
Initialize the transceiver.
Definition AsyncUsbTransceiverBase.cpp:64
libusb_device_handle * GetHandle()
Get the libusb_device_handle of an already opened widget.
Definition AsyncUsbTransceiverBase.h:71
void CancelTransfer()
Cancel any pending transfers.
Definition AsyncUsbTransceiverBase.cpp:69
virtual libusb_device_handle * SetupHandle()=0
Open the device handle.
virtual void TransferComplete(struct libusb_transfer *transfer)=0
Called from the libusb callback when the asynchronous transfer completes.
AsyncUsbTransceiverBase(ola::usb::LibUsbAdaptor *const adaptor, libusb_device *usb_device)
Create a new AsyncUsbTransceiverBase.
Definition AsyncUsbTransceiverBase.cpp:47
int SubmitTransfer()
Submit the transfer for tx.
Definition AsyncUsbTransceiverBase.cpp:115
void FillControlTransfer(unsigned char *buffer, unsigned int timeout)
Fill a control transfer.
Definition AsyncUsbTransceiverBase.cpp:93
void FillBulkTransfer(unsigned char endpoint, unsigned char *buffer, int length, unsigned int timeout)
Fill a bulk transfer.
Definition AsyncUsbTransceiverBase.cpp:99
Definition Mutex.h:41
Wraps calls to libusb so we can test the code.
Definition LibUsbAdaptor.h:36
The namespace containing all OLA symbols.
Definition Credentials.cpp:44