2 * Copyright (C) 2006 Paul Davis
3 * Copyright (C) 2007 Michael Taht
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #define __STDC_FORMAT_MACROS
30 #include <tranzport_control_protocol.h>
32 #if !HAVE_TRANZPORT_KERNEL_DRIVER
34 using namespace ARDOUR;
41 #include <pbd/abstract_ui.cc>
43 // I note that these usb specific open, close, probe, read routines are basically
44 // pure boilerplate and could easily be abstracted elsewhere
47 TranzportControlProtocol::probe ()
50 struct usb_device *dev;
56 for (bus = usb_busses; bus; bus = bus->next) {
58 for(dev = bus->devices; dev; dev = dev->next) {
59 if (dev->descriptor.idVendor == VENDORID && dev->descriptor.idProduct == PRODUCTID) {
69 TranzportControlProtocol::open ()
72 struct usb_device *dev;
78 for (bus = usb_busses; bus; bus = bus->next) {
80 for(dev = bus->devices; dev; dev = dev->next) {
81 if (dev->descriptor.idVendor != VENDORID)
83 if (dev->descriptor.idProduct != PRODUCTID)
85 return open_core (dev);
89 cerr << _("Tranzport: no device detected") << endmsg;
94 TranzportControlProtocol::open_core (struct usb_device* dev)
96 if (!(udev = usb_open (dev))) {
97 cerr << _("Tranzport: cannot open USB transport") << endmsg;
101 if (usb_claim_interface (udev, 0) < 0) {
102 cerr << _("Tranzport: cannot claim USB interface") << endmsg;
108 if (usb_set_configuration (udev, 1) < 0) {
109 cerr << _("Tranzport: cannot configure USB interface") << endmsg;
116 TranzportControlProtocol::close ()
124 if (usb_release_interface (udev, 0) < 0) {
125 cerr << _("Tranzport: cannot release interface") << endmsg;
129 if (usb_close (udev)) {
130 cerr << _("Tranzport: cannot close device") << endmsg;
138 int TranzportControlProtocol::read(uint8_t *buf, uint32_t timeout_override)
140 last_read_error = usb_interrupt_read (udev, READ_ENDPOINT, (char *) buf, 8, timeout_override);
141 switch(last_read_error) {
147 cerr << "Tranzport disconnected, errno: " << last_read_error;
149 case -ETIMEDOUT: // This is normal
153 cerr << "Got an unknown error on read:" << last_read_error "\n";
158 return last_read_error;
163 TranzportControlProtocol::write_noretry (uint8_t* cmd, uint32_t timeout_override)
166 if(inflight > MAX_TRANZPORT_INFLIGHT) { return (-1); }
167 val = usb_interrupt_write (udev, WRITE_ENDPOINT, (char*) cmd, 8, timeout_override ? timeout_override : timeout);
169 if (val < 0 && val !=8) {
171 printf("usb_interrupt_write failed: %d\n", val);
173 last_write_error = val;
174 switch(last_write_error) {
180 cerr << "Tranzport disconnected, errno: " << last_write_error;
182 case -ETIMEDOUT: // This is normal
186 cerr << "Got an unknown error on read:" << last_write_error "\n";
193 last_write_error = 0;
201 TranzportControlProtocol::write (uint8_t* cmd, uint32_t timeout_override)
206 if(inflight > MAX_TRANZPORT_INFLIGHT) { return (-1); }
208 while((val = usb_interrupt_write (udev, WRITE_ENDPOINT, (char*) cmd, 8, timeout_override ? timeout_override : timeout))!=8 && retry++ < MAX_RETRY) {
209 printf("usb_interrupt_write failed, retrying: %d\n", val);
212 if (retry == MAX_RETRY) {
213 printf("Too many retries on a tranzport write, aborting\n");
217 printf("usb_interrupt_write failed: %d\n", val);
221 printf("usb_interrupt_write failed: %d\n", val);
227 return (write_noretry(cmd,timeout_override));