/* * Start a new message */ void Pipe::start_msg() { if(inside_msg) throw Invalid_State("Pipe::start_msg: Message was already started"); if(pipe == nullptr) pipe = new Null_Filter; find_endpoints(pipe); pipe->new_msg(); inside_msg = true; }
/* * Find the endpoints of the Pipe */ void Pipe::find_endpoints(Filter* f) { for(size_t j = 0; j != f->total_ports(); ++j) if(f->next[j] && !dynamic_cast<SecureQueue*>(f->next[j])) find_endpoints(f->next[j]); else { SecureQueue* q = new SecureQueue; f->next[j] = q; outputs->add(q); } }
static int open_device(struct bslhid_transport *tr, struct usb_device *dev) { if (find_interface(tr, dev) < 0) return -1; printc_dbg("Opening interface %d (config %d)...\n", tr->int_number, tr->cfg_number); if (find_endpoints(tr, dev) < 0) return -1; printc_dbg("Found endpoints: IN: 0x%02x, OUT: 0x%02x\n", tr->in_ep, tr->out_ep); tr->handle = usb_open(dev); if (!tr->handle) { pr_error("bslhid: can't open device"); return -1; } #ifdef __Windows__ if (usb_set_configuration(tr->handle, tr->cfg_number) < 0) pr_error("warning: bslhid: can't set configuration"); #endif #ifdef __linux__ if (usb_detach_kernel_driver_np(tr->handle, tr->int_number) < 0) pr_error("warning: bslhid: can't detach kernel driver"); #endif if (usb_claim_interface(tr->handle, tr->int_number) < 0) { pr_error("bslhid: can't claim interface"); usb_close(tr->handle); return -1; } /* Save the bus path for a future suspend/resume */ strncpy(tr->bus_name, dev->bus->dirname, sizeof(tr->bus_name)); tr->bus_name[sizeof(tr->bus_name) - 1] = 0; return 0; }
Xbox360Controller::Xbox360Controller(struct usb_device* dev_, bool is_guitar_, bool try_detach) : dev(dev_), is_guitar(is_guitar_), dev_type(), handle(), endpoint_in(1), endpoint_out(2), read_thread() { find_endpoints(); if (0) { std::cout << "EP(IN): " << endpoint_in << std::endl; std::cout << "EP(OUT): " << endpoint_out << std::endl; } handle = usb_open(dev); if (0) { int err; if ((err = usb_set_configuration(handle, 0)) < 0) { std::ostringstream out; out << "Error set USB configuration: " << usb_strerror() << std::endl << "Try to run 'rmmod xpad' and then xboxdrv again or start xboxdrv with the option --detach-kernel-driver."; throw std::runtime_error(out.str()); } } if (!handle) { throw std::runtime_error("Error opening Xbox360 controller"); } else { // FIXME: bInterfaceNumber shouldn't be hardcoded int err = usb_claim_n_detach_interface(handle, 0, try_detach); if (err != 0) { std::ostringstream out; out << " Error couldn't claim the USB interface: " << usb_strerror() << std::endl << "Try to run 'rmmod xpad' and then xboxdrv again or start xboxdrv with the option --detach-kernel-driver."; throw std::runtime_error(out.str()); } } if (0) { unsigned char arr[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 16, 32, 64, 128, 255 }; for (int len = 3; len <= 8; ++len) { // Sending random data: for (int front = 0; front < 256; ++front) { for (size_t i = 0; i < sizeof(arr); ++i) { char ledcmd[] = { front, len, arr[i], arr[i], arr[i], arr[i], arr[i], arr[i], arr[i], arr[i], arr[i], arr[i], arr[i], arr[i], arr[i], arr[i] }; printf("%d %d %d\n", len, front, arr[i]); usb_interrupt_write(handle, endpoint_out, ledcmd, len, 0); uint8_t data[32]; int ret = usb_interrupt_read(handle, endpoint_in, reinterpret_cast<char*>(data), sizeof(data), 20); print_raw_data(std::cout, data, ret); } } } } read_thread = std::auto_ptr<USBReadThread>(new USBReadThread(handle, endpoint_in, 32)); read_thread->start_thread(); }