<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Javan Cook</title>
    <description>Webpage</description>
    <link>http://javancook.com</link>
    <atom:link href="http://javancook.com/feed.xml" rel="self" type="application/rss+xml" />
    
      <item>
        <title>Getting Data from a Controller</title>
        <description>&lt;p&gt;In the previous post &lt;a href=&quot;/2015/getting-information-about-a-usb-device&quot;&gt;we used Linux to find the Endpoints for the USB Xbox controller&lt;/a&gt;.
We also used &lt;a href=&quot;http://tattiebogle.net/index.php/ProjectRoot/Xbox360Controller/UsbInfo&quot;&gt;Tattiebogle’s post on wired controller information&lt;/a&gt; to identify the purposes of the different Interfaces so we know which of the Endpoints to target for information.
This leaves us with the final step for the first item on the checklist; detecting the inputs from the controller. In order to achieve this, we need some way of interacting with the Endpoints.
Given I was planning on using Python for this project the module &lt;a href=&quot;https://github.com/walac/pyusb&quot;&gt;PyUSB&lt;/a&gt; seems like the logical choice. The previous link provides details for installing the module and there is a &lt;a href=&quot;https://github.com/walac/pyusb/blob/master/docs/tutorial.rst&quot;&gt;PyUSB tutorial&lt;/a&gt; available containing a wealth of information.&lt;/p&gt;

&lt;p&gt;The main three lines of code we need from PyUSB are:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;usb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;core&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;idVendor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;idProduct&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dev&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;set_configuration&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dev&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;read&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dev&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;The first line is used to detect if a USB device of the correct Vendor and Product identifiers is connected.
We obtained values for &lt;em&gt;a&lt;/em&gt; and &lt;em&gt;b&lt;/em&gt; in the previous post and found that &lt;em&gt;a&lt;/em&gt; = 0x045e and &lt;em&gt;b&lt;/em&gt; = 0x028e.
The second line is used to set the device’s Configuration, as there is only one Configuration in this case there is no need to specify.
The final two lines are used to read and write data to the device respectively.
Here &lt;em&gt;x&lt;/em&gt; is the Endpoint address, &lt;em&gt;y&lt;/em&gt; is the number of bytes to read or the data to write and &lt;em&gt;z&lt;/em&gt; is the timeout time.
Again, &lt;em&gt;x&lt;/em&gt; and &lt;em&gt;y&lt;/em&gt; were determined in the previous post as the &lt;em&gt;bEndpointAddress&lt;/em&gt; and the &lt;em&gt;wMaxPacketSize&lt;/em&gt; respectively.
The final thing left to do before probing the device for data is to pick the right Endpoint to query to get the controller status.
It turned out that this is slightly more tricksy than I initially thought.&lt;/p&gt;

&lt;p&gt;From &lt;a href=&quot;http://tattiebogle.net/index.php/ProjectRoot/Xbox360Controller/UsbInfo&quot;&gt;Tattiebogle’s controller information&lt;/a&gt; it was determined that Interface 0 is the one responsible for the status of the controller.
In the literature it was stated that typically each Interface would correspond to a single device function.
In this case, Interface 0 incorporates a number of sub-functions including the LED status and the mic status, as well as the control status. It is therefore necessary to query the same Endpoint several times to get to the pertinent information.
I’ve prepared some code to do exactly that below:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;c1&quot;&gt;#Import PyUSB and sys
&lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;usb.core&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;usb.util&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;sys&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;#Find device
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dev&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;usb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;core&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;idVendor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mh&quot;&gt;0x045e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;idProduct&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mh&quot;&gt;0x028e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;#Is the controller there or not?
&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dev&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;is&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;None&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
 &lt;span class=&quot;n&quot;&gt;sys&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;exit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'Controller not present, please insert and try again.'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
 &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'Controller present.'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;#Configure device
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dev&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;set_configuration&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;#Get packets
&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
 &lt;span class=&quot;n&quot;&gt;packet&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dev&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;read&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mh&quot;&gt;0x81&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
 &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'Packet'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;':'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;packet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;When running this code it may return &lt;em&gt;‘usb.core.USBError: [Errno 16] Resource busy’&lt;/em&gt;.
If this happens use &lt;kbd&gt;$ sudo rmmod xpad&lt;/kbd&gt; to stop the default Xbox controller driver running.
This should return the following answer:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;Controller present.
Packet 1 : array&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'B'&lt;/span&gt;, &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;1, 3, 14]&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
Packet 2 : array&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'B'&lt;/span&gt;, &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;2, 3, 0]&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
Packet 3 : array&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'B'&lt;/span&gt;, &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;3, 3, 3]&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
Packet 4 : array&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'B'&lt;/span&gt;, &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;8, 3, 0]&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
Packet 5 : array&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'B'&lt;/span&gt;, &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;0, 20, 0, 0, 0, 0, 88, 253, 184, 7, 58, 3, 255, 0, 0, 0, 0, 0, 0, 0]&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;This matches up nicely with the information obtained by &lt;a href=&quot;http://tattiebogle.net/index.php/ProjectRoot/Xbox360Controller/UsbInfo&quot;&gt;Tattiebogle&lt;/a&gt; where Packet 1 is the LED status, Packet 4 is the mic status and Packet 5 is the status of the controls.
The format is a bit odd and it will require some work to make it usable but it is definitely the control status and ticks off the first item on the list of requirements.
I’m not going to analyse the contents of Packet 5 immediately, that can wait until item three on the list of requirements is addressed, but feel free to consult &lt;a href=&quot;http://tattiebogle.net/index.php/ProjectRoot/Xbox360Controller/UsbInfo&quot;&gt;Tattiebogle&lt;/a&gt; if you can’t wait.
Instead I’m next going to address transferring data between a client and server.&lt;/p&gt;

&lt;h3 id=&quot;checklist&quot;&gt;Checklist&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;del&gt;A way of detecting the inputs from a controller.&lt;/del&gt;&lt;/li&gt;
  &lt;li&gt;A way of transferring this information from a client to a server.&lt;/li&gt;
  &lt;li&gt;A way of replicating the inputs on the server side as outputs to the 360 console.&lt;/li&gt;
  &lt;li&gt;A way to view the gameplay.&lt;/li&gt;
  &lt;li&gt;A way to control the TV.&lt;/li&gt;
&lt;/ul&gt;
</description>
        <pubDate>Sat, 29 Aug 2015 00:00:00 +0000</pubDate>
        <link>http://javancook.com/2015/getting-data-from-a-controller/</link>
        <guid isPermaLink="true">http://javancook.com/2015/getting-data-from-a-controller/</guid>
      </item>
    
      <item>
        <title>Getting Information about a USB Device</title>
        <description>&lt;p&gt;In the previous post &lt;a href=&quot;/2015/an-introduction-to-usb-protocol&quot;&gt;an introduction to USB protocol&lt;/a&gt; was presented.
Given what was learnt in that post, the next step for the Remote Xbox Project is to both figure out how to extract data from the wireless Xbox controller and make sense of it.
The first step in this process is to identify the different Interfaces and Endpoints within the device.
To do this the I used &lt;a href=&quot;https://github.com/gregkh/usbutils&quot;&gt;lsusb from usbutils&lt;/a&gt; on my raspberry pi obtained using
&lt;kbd&gt;$ sudo apt-get install usbutils&lt;/kbd&gt;.
After connecting the controller, I then used the command
&lt;kbd&gt;$ lsusb&lt;/kbd&gt;, which returned the list of USB devices currently connected to my raspberry pi and looked like this:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 005: ID 045e:028e Microsoft Corp. Xbox360 Controller
Bus 001 Device 004: ID 148f:5370 Ralink Technology, Corp. RT5370 Wireless Adapter&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;As you can see, the Xbox controller is Device number 5 and has a Vendor id of 045e and a Product id of 028e in hex. We can now use lsusb to inspect it in more detail using the command
&lt;kbd&gt;$ lsusb -d 045e:028e -v&lt;/kbd&gt;
, where
&lt;kbd&gt;-d&lt;/kbd&gt;
shows only the device of the specified vendor and product id and
&lt;kbd&gt;-v&lt;/kbd&gt;
provides more detail.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;Bus 001 Device 005: ID 045e:028e Microsoft Corp. Xbox360 Controller
Couldn&lt;span class=&quot;s1&quot;&gt;'t open device, some information will be missing
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass          255 Vendor Specific Class
  bDeviceSubClass       255 Vendor Specific Subclass
  bDeviceProtocol       255 Vendor Specific Protocol
  bMaxPacketSize0         8
  idVendor           0x045e Microsoft Corp.
  idProduct          0x028e Xbox360 Controller
  bcdDevice            1.14
  iManufacturer           1
  iProduct                2
  iSerial                 3
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength          153
    bNumInterfaces          4
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0xa0
      (Bus Powered)
      Remote Wakeup
    MaxPower              500mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumInterfaces           2
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass     93
      bInterfaceProtocol      1
      iInterface              0
      ** UNRECOGNIZED:  11 21 00 01 01 25 81 14 00 00 00 00 13 01 08 00 00
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0020  1x 32 bytes
        bInterval               4
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x01  EP 1 OUT
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0020  1x 32 bytes
        bInterval               8
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           4
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass     93
      bInterfaceProtocol      3
      iInterface              0
      ** UNRECOGNIZED:  1b 21 00 01 01 01 82 40 01 02 20 16 83 00 00 00 00 00 00 16 03 00 00 00 00 00 00
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0020  1x 32 bytes
        bInterval               2
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0020  1x 32 bytes
        bInterval               4
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x83  EP 3 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0020  1x 32 bytes
        bInterval              64
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x03  EP 3 OUT
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0020  1x 32 bytes
        bInterval              16
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        2
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass     93
      bInterfaceProtocol      2
      iInterface              0
      ** UNRECOGNIZED:  09 21 00 01 01 22 84 07 00
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x84  EP 4 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0020  1x 32 bytes
        bInterval              16
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        3
      bAlternateSetting       0
      bNumEndpoints           0
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass    253
      bInterfaceProtocol     19
      iInterface              4
      ** UNRECOGNIZED:  06 41 00 01 01 03&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;As you can see from the results above the controller has one Configuration with four Interfaces and no Alternate Settings to worry about.
Interface 0 has two Endpoints, one IN and one OUT; Interface 1 has four Endpoints, two IN and two OUT; Interface 2 has one Endpoint, an IN; and Interface 3 has no Endpoints.
Also of interest is the fact that all the Endpoints are of the interrupt transfer type.
Now that we’ve established the details of the different Interfaces and Endpoints, and most importantly their addresses, we need to figure out what processes they correspond to and where to extract the controller inputs from.&lt;/p&gt;

&lt;p&gt;Fortunately, this has already been done within &lt;a href=&quot;http://tattiebogle.net/index.php/ProjectRoot/Xbox360Controller/UsbInfo&quot;&gt;Tattiebogle’s post on wired controller information&lt;/a&gt;.
He found that Interface 0 corresponds to the data from the controller, including the status of components such as the rumble motors, the LED ring and whether the headset is present, as well as the controls status.
He also speculates that Interface 1 is for the audio data for the mic and speaker in the headset and Interface 3 is a security measure used by Microsoft to check that the controller is licensed.
This latter point makes sense due to the lack of Endpoint associated with Interface 3 and the presence of what appears to be a proprietary chip on the controller circuit board.
This also has implications for item three on the checklist, replicating the inputs on the server side as outputs to the 360 console, and as such will be discussed in more detail in a later post.
No speculation is offered for the role of Interface 2.
As it possesses only a solitary IN Endpoint, I reckon it could be for the chatpad accessory.
This is something I’ll be investigating further, once I acquire a chatpad, along with extracting data from the Endpoints in the next post.&lt;/p&gt;
</description>
        <pubDate>Fri, 28 Aug 2015 00:00:00 +0000</pubDate>
        <link>http://javancook.com/2015/getting-information-about-a-usb-device/</link>
        <guid isPermaLink="true">http://javancook.com/2015/getting-information-about-a-usb-device/</guid>
      </item>
    
      <item>
        <title>An Introduction to USB Protocol</title>
        <description>&lt;p&gt;In order to begin fulfilling the first item on the Remote Xbox checklist a I needed to find an input controller.
Fortunately, I happened to have a wired Xbox 360 controller that I could use.
That left me with having to figure out how to extract the inputs using the raspberry pi.
It turns out that there are plenty of pre-existing solutions to solve this problem, including using &lt;a href=&quot;http://pingus.seul.org/~grumbel/xboxdrv/&quot;&gt;xboxdrv&lt;/a&gt; combined with &lt;a href=&quot;http://www.pygame.org/hifi.html&quot;&gt;pygame&lt;/a&gt; as described here by &lt;a href=&quot;http://www.stuffaboutcode.com/2014/10/raspberry-pi-xbox-360-controller-python.html&quot;&gt;Martin O’Hanlon in his post on using an Xbox controller to control a robot&lt;/a&gt;.
However, it seemed like it would be more fun to figure things out from the beginning myself and as such would require me to carry out some research on how USB devices actually work.
This led me to the websites &lt;a href=&quot;http://www.usbmadesimple.co.uk/index.html&quot;&gt;USB Made Simple&lt;/a&gt;, &lt;a href=&quot;http://www.beyondlogic.org/usbnutshell/usb4.shtml#Control&quot;&gt;Beyond Logic’s USB in a NutShell&lt;/a&gt; and &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/windows/hardware/dn303352(v=vs.85).aspx&quot;&gt;Microsoft’s Concepts for all USB developers &lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;These sources provided me with a rudimentary knowledge of USB devices, enough to get started with anyway. Essentially, in addition to a Vendor and Product identifiers, USB devices feature Configurations, Interfaces and Endpoints, a combination of which control how the device works.
The top level is the Configuration which controls what the device does.
Whilst a device can have more than one Configuration associated with it, only one can be active at any time, and it is selected by the device driver.
A given Configuration can have a number of Interfaces which specifies the functions of the device, usually one function per Interface.
Again, Interfaces can have alternate settings associated with them and only one can be active at once.
Finally, Interfaces have Endpoints which are used to transfer the data in and out of the device and cannot be shared between Interfaces.&lt;/p&gt;

&lt;figure&gt;
&lt;center&gt;&lt;a href=&quot;/assets/images/USBdevice.png&quot;&gt;&lt;img src=&quot;/assets/images/USBdevice.png&quot; align=&quot;middle&quot; width=&quot;500&quot; /&gt;&lt;/a&gt;&lt;/center&gt;
&lt;figcaption&gt;
&lt;b&gt;Figure 1:&lt;/b&gt;
&lt;i&gt;An example of a USB device. This device has one Configuration and two Interfaces, one of which has an alternate setting. The Interfaces have different Endpoints associated with them. Endpoint 0 is the control Endpoint used to configure the device.&lt;/i&gt;
&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;Every USB device must assign a bidirectional control Endpoint at the 0 address.
This is so information about the device can be obtained and the Configuration for the device can be set.
The data Endpoints are unidirectional (IN or OUT) and have one of four types (control, interrupt, isochronous and bulk).
IN and OUT are relative to the host, so IN is a transfer from the device to the host whilst OUT is a transfer from the host to the device.
A typical example of a USB device using Figure 1 would be that of a webcam with a built-in microphone and speaker.
Here Interface 0 would correspond to the camera of the device.
The Alternate Setting 0 would be active when the camera is not in use to save bandwidth as it has no Endpoint associated with it.
Alternative Setting 1 would be active when the camera is in use and the IN Endpoint is used to transfer the video data from the camera to the host.
Interface 1 would correspond to the microphone and speaker, where Endpoint 1 would take noise detected by the microphone and transfer it the host whilst Endpoint two would take data from the host and output it from the speaker.&lt;/p&gt;

&lt;p&gt;As mentioned above, there are four different types of transfer available for an Endpoint.
The transfer types each have their own properties which makes them suitable for different applications.
Control transfers are used by Endpoint 0 when configuring the device and are used for command and status operations.
Interrupt transfers are used to provide regular status updates from a device and have included error checking so the data arrives error free.
Isochronous transfers are used to transfer large amounts of time sensitive data, such as video or audio streams, where it is less important if a packet of data is dropped on the way.
Bulk transfers are also used to transfer large amounts of data, however, they are assigned the remaining bandwidth that has not already been allocated to interrupt and isochronous transfers.
As such, they are primarily used for non-time critical applications, such as print jobs, and they are error checked with guaranteed delivery unlike isochronous transfer. So for the example above the camera Endpoint would use isochronous transfer whilst the microphone/speaker Endpoints would likely use interrupt transfer.&lt;/p&gt;
</description>
        <pubDate>Mon, 24 Aug 2015 00:00:00 +0000</pubDate>
        <link>http://javancook.com/2015/an-introduction-to-usb-protocol/</link>
        <guid isPermaLink="true">http://javancook.com/2015/an-introduction-to-usb-protocol/</guid>
      </item>
    
      <item>
        <title>The Remote Xbox Project</title>
        <description>&lt;p&gt;This year for Christmas I was lucky enough to get a couple of Raspberry Pi devices and a load of miscellaneous accessories and gizmos. After getting back in to Python by making some flashing lights and random number generators, I was looking for a new project.
I toyed with making them into media servers or retro game emulators but in the end I didn’t really have any need for either of those things.
Instead I decided that I wanted to try something new where I could learn some new things and increase my knowledge of Python, preferably involving hardware of some description too.&lt;/p&gt;

&lt;p&gt;I decided to try to implement some sort of system to play my Xbox 360 remotely whilst I am away from home.
This would involve a number of different coding stages to make it work and would also require modifying hardware.
The recent announcements from Microsoft regarding streaming Xbox One to Windows 10 devices and the backwards compatibility of the Xbox One have rendered this project redundant.
However, as this was more of a learning exercise than an alternative to these services, and given I started this in January, I’ve continued with the project.&lt;/p&gt;

&lt;p&gt;In order for this project to work, I needed to integrate a number of features:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;A way of detecting the inputs from a controller.&lt;/li&gt;
  &lt;li&gt;A way of transferring this information from a client to a server.&lt;/li&gt;
  &lt;li&gt;A way of replicating the inputs on the server side as outputs to the 360 console.&lt;/li&gt;
  &lt;li&gt;A way to view the gameplay.&lt;/li&gt;
  &lt;li&gt;A way to control the TV.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is the checklist of essential features that I’ve worked on in an attempt to make this project succeed. This will be updated in subsequent posts as progress is made and some optional extras may be incorporated if feasible.&lt;/p&gt;
</description>
        <pubDate>Mon, 17 Aug 2015 00:00:00 +0000</pubDate>
        <link>http://javancook.com/2015/the-remote-xbox-project/</link>
        <guid isPermaLink="true">http://javancook.com/2015/the-remote-xbox-project/</guid>
      </item>
    
      <item>
        <title>Making This Blog</title>
        <description>&lt;p&gt;I first heard about Github pages from my friend &lt;a href=&quot;http://mattsumme.rs/&quot;&gt;Matt&lt;/a&gt; whilst looking for a place to host a blog for free that I could use to document my progress on various projects.
As I wanted to be able to produce content using my Windows based laptop I initially followed a &lt;a href=&quot;http://jekyll-windows.juthilo.com/]&quot;&gt;guide&lt;/a&gt; by &lt;a href=&quot;https://twitter.com/juthilo&quot;&gt;@juthilo&lt;/a&gt; which worked really well.
The only point at which I found this guide lacking is for if you plan to use pygments for syntax highlighting.
When posting samples of code, I found initially that pygments wasn’t working despite being installed sucessfully.
After visiting the &lt;a href=&quot;http://pygments.org/&quot;&gt;pygments website&lt;/a&gt; I found that I needed to generate a stylesheet first.&lt;/p&gt;

&lt;p&gt;I first used the following code in the Python command line to check which styles were already installed:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;pygments.styles&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;STYLE_MAP&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;STYLE_MAP&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;keys&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;From the list this provided I selected paraiso-dark, based on some &lt;a href=&quot;http://pygments.org/demo/&quot;&gt;experimentation on the pygments website&lt;/a&gt;.
Having selected my style of preference I then needed to generate my CSS stylesheet.
To do this I put the following line into the command prompt:&lt;/p&gt;

&lt;p&gt;&lt;kbd&gt;pygmentize -S style -f html &amp;gt;output.css&lt;/kbd&gt;&lt;/p&gt;

&lt;p&gt;Where  “style” is the name of the style obtained earlier and “output.css” is the output file.&lt;/p&gt;

&lt;p&gt;The majority of the rest of the blog was produced using the documentation on &lt;a href=&quot;http://jekyllrb.com/&quot;&gt;Jekyll&lt;/a&gt; and &lt;a href=&quot;http://getbootstrap.com/&quot;&gt;Bootstrap&lt;/a&gt; in conjuction with the &lt;a href=&quot;http://learn.andrewmunsell.com/learn/jekyll-by-example/tutorial&quot;&gt;Andrew Munsell tutorial&lt;/a&gt;.
The search bar was modified from &lt;a href=&quot;http://www.askdavetaylor.com/how_can_i_add_a_google_search_box_to_my_web_site/&quot;&gt;Dave Taylor’s site&lt;/a&gt; whilst the tag and category search function was modified from &lt;a href=&quot;https://alexpearce.me/2012/04/simple-jekyll-searching/&quot;&gt;Alex Pearce’s site&lt;/a&gt;.
Finally, the next and previous post buttons were adapted from &lt;a href=&quot;http://david.elbe.me/jekyll/2015/06/20/how-to-link-to-next-and-previous-post-with-jekyll.html&quot;&gt;David Elbe’s site&lt;/a&gt; and my favicon was generated using &lt;a href=&quot;http://www.favicomatic.com/&quot;&gt;Favic-o-matic&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;As you can see, most of the elements of this blog have been cannibalised from other people’s sites. However, being new to HTML, CSS and Javascript, it has been fun learning experience to adapt them to my needs and make them all work together.&lt;/p&gt;
</description>
        <pubDate>Sun, 16 Aug 2015 00:00:00 +0000</pubDate>
        <link>http://javancook.com/2015/making-this-blog/</link>
        <guid isPermaLink="true">http://javancook.com/2015/making-this-blog/</guid>
      </item>
    
  </channel>
</rss>
