(mis-) adventures in coding. I created this more to document my little pet projects than anything else. It's public in case anyone wants to learn from my experience, or more likely my mistakes!
Friday, November 8, 2013
XiCam Tech Issues
However, even if I managed to get the firmware from the camera, there is still no guarantee that I'll be able to understand it once I've disassembled the code. And even after spending the effort in figuring it out, then I may still not be able to hack it to control exposure time or trigger the camera via USB. I decided I was better off, for my own sanity, to just buy a different camera when I'm ready to take pictures at that level.
It turns out, without any special settings or using my home made mounting bracket, I can still get decent pictures. Here's a picture I took of Jupiter this morning:
Tuesday, November 5, 2013
USB Protocol
$ sudo cat /sys/kernel/debug/usb/usbmon/2u > bus2data.txt
$ tail -f bus2data.txt
The first group of messages appear to be communication between the host controller and the USB port hub,
ffff880137cc2840 2476103001 S Ci:2:000:0 s 80 06 0100 0000 0040 64 < ffff880137cc2840 2476103172 C Ci:2:000:0 0 18 = 12010002 00000040 e8040613 00000102 0301
ffff880137cc2840 2476234892 S Ci:2:007:0 s 80 06 0100 0000 0012 18 < ffff880137cc2840 2476235047 C Ci:2:007:0 0 18 = 12010002 00000040 e8040613 00000102 0301
ffff880137cc2840 2476235204 S Ci:2:007:0 s 80 06 0200 0000 0009 9 < ffff880137cc2840 2476235293 C Ci:2:007:0 0 9 = 09022000 010100c0 00
Configuration Descriptor: bLength 9 bDescriptorType 2 wTotalLength 32 bNumInterfaces 1 bConfigurationValue 1 iConfiguration 0 bmAttributes 0xc0 Self Powered MaxPower 0mA
The next pair is the first (and only) interface,
ffff880137cc2840 2476235412 S Ci:2:007:0 s 80 06 0200 0000 0020 32 < ffff880137cc2840 2476235547 C Ci:2:007:0 0 32 = 09022000 010100c0 00090400 00020805 50000705 02020002 00070582 02000200
Configuration Descriptor: bLength 9 bDescriptorType 2 wTotalLength 32 bNumInterfaces 1 bConfigurationValue 1 iConfiguration 0 bmAttributes 0xc0 Self Powered MaxPower 0mA Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 0 bAlternateSetting 0 bNumEndpoints 2 bInterfaceClass 8 Mass Storage bInterfaceSubClass 5 SFF-8070i bInterfaceProtocol 80 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x02 EP 2 OUT bmAttributes 2 Transfer Type Bulk Synch Type None Usage Type Data wMaxPacketSize 0x0200 1x 512 bytes bInterval 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x82 EP 2 IN bmAttributes 2 Transfer Type Bulk Synch Type None Usage Type Data wMaxPacketSize 0x0200 1x 512 bytes bInterval 0
ffff880137cc2840 2476235709 S Ci:2:007:0 s 80 06 0300 0000 00ff 255 < ffff880137cc2840 2476235792 C Ci:2:007:0 0 4 = 04030904 ffff880137cc2840 2476235826 S Ci:2:007:0 s 80 06 0302 0409 00ff 255 < ffff880137cc2840 2476235917 C Ci:2:007:0 0 48 = 30035300 61006d00 73007500 6e006700 20004400 69006700 69007400 61006c00 ffff880137cc2840 2476235936 S Ci:2:007:0 s 80 06 0301 0409 00ff 255 < ffff880137cc2840 2476236042 C Ci:2:007:0 0 20 = 14035300 41004d00 53005500 4e004700 20002000 ffff880137cc2840 2476236055 S Ci:2:007:0 s 80 06 0303 0409 00ff 255 < ffff880137cc2840 2476236167 C Ci:2:007:0 0 28 = 1c034500 30003000 30003000 30003000 30003000 30003000 32002000 ffff880137cc2a80 2476236645 S Co:2:007:0 s 00 09 0001 0000 0000 0 ffff880137cc2a80 2476236792 C Co:2:007:0 0 0 ffff8801122bfc00 2477238949 S Ci:2:007:0 s a1 fe 0000 0000 0001 1 < ffff8801122bfc00 2477260196 C Ci:2:007:0 0 1 = 01
0x14=decimal 20, 0x03=index 3, 0x53='S', 0x41='A', 0x4d='M', 0x53='S', 0x55='U', 0x4e='N', 0x47='G', 0x20=' ', 0x20=' '
0x1c=decimal 28, 0x03=index 3, 0x45='E', 0x30='0', 0x32='2', 0x20=' '
So these must be the info strings, although the string "camera" doesn't show up. The first byte must be the string size in bytes (wide char format), the second byte the number of info strings, in this case '3', then the actual strings ("Samsung Digital", "SAMSUNG ", and "E00000000002 ").
Sunday, November 3, 2013
XiCam Assembly
I was tinkering around with the built-in exposure and ISO settings. The ST100 allows up to ST3200 and uses an exposure scale of -2 to 2 (I don't really know what that means. Could it be a multiplier for integration time?). The first picture I took the other night. It was fairly overcast, and we get a lot of light pollution around here. I used exposure setting "zero" (for "auto") and ISO 3200. The second picture is Vega, taken last night using my medieval eyepiece attachment device. The high magnification makes vibrations even more annoying, so I will certainly need to get a larger clamp so I can use the lower magnification, larger FOV eyepiece.
Getting USB Debugging Info from the Linux Command Line.
seans@snowpack:~$ sudo lsusb -v ... Bus 002 Device 005: ID 04e8:1306 Samsung Electronics Co., Ltd Device Descriptor: bLength 18 bDescriptorType 1 bcdUSB 2.00 bDeviceClass 0 (Defined at Interface level) bDeviceSubClass 0 bDeviceProtocol 0 bMaxPacketSize0 64 idVendor 0x04e8 Samsung Electronics Co., Ltd idProduct 0x1306 bcdDevice 0.00 iManufacturer 1 SAMSUNG iProduct 2 Samsung Digital Camera iSerial 3 E00000000002 bNumConfigurations 1 Configuration Descriptor: bLength 9 bDescriptorType 2 wTotalLength 32 bNumInterfaces 1 bConfigurationValue 1 iConfiguration 0 bmAttributes 0xc0 Self Powered MaxPower 0mA Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 0 bAlternateSetting 0 bNumEndpoints 2 bInterfaceClass 8 Mass Storage bInterfaceSubClass 5 SFF-8070i bInterfaceProtocol 80 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x02 EP 2 OUT bmAttributes 2 Transfer Type Bulk Synch Type None Usage Type Data wMaxPacketSize 0x0200 1x 512 bytes bInterval 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x82 EP 2 IN bmAttributes 2 Transfer Type Bulk Synch Type None Usage Type Data wMaxPacketSize 0x0200 1x 512 bytes bInterval 0 Device Qualifier (for other device speed): bLength 10 bDescriptorType 6 bcdUSB 2.00 bDeviceClass 0 (Defined at Interface level) bDeviceSubClass 0 bDeviceProtocol 0 bMaxPacketSize0 64 bNumConfigurations 1 Device Status: 0x0001 Self Powered
seans@snowpack:~$ sudo cat /sys/kernel/debug/usb/usbmon/2u > bus2data.txt
ffff88009bf78240 752186120 S Bo:2:005:2 -115 31 = 55534243 18070000 08000000 80010c4a 01000010 00000008 00000000 000000 ffff88009bf78240 752186154 C Bo:2:005:2 0 31 > ffff880062803c00 752186180 S Bi:2:005:2 -115 8 < ffff880062803c00 752186403 C Bi:2:005:2 -32 0 ffff88009bf78240 752186412 S Co:2:005:0 s 02 01 0000 0082 0000 0 ffff88009bf78240 752186527 C Co:2:005:0 0 0 ffff88009bf78240 752186548 S Bi:2:005:2 -115 13 < ffff88009bf78240 752207425 C Bi:2:005:2 0 13 = 55534253 18070000 08000000 01 ffff88009bf78240 752207452 S Bo:2:005:2 -115 31 = 55534243 19070000 12000000 80010c03 00000012 00000000 00000000 000000 ffff88009bf78240 752207652 C Bo:2:005:2 0 31 > ffff880062803c00 752207718 S Bi:2:005:2 -115 18 < ffff880062803c00 752207778 C Bi:2:005:2 0 18 = 70000500 0000000a 00000000 20000000 0000 ffff88009bf78240 752207788 S Bi:2:005:2 -115 13 < ffff88009bf78240 752207901 C Bi:2:005:2 0 13 = 55534253 19070000 00000000 00 ffff88009bf78240 752698083 S Bo:2:005:2 -115 31 = 55534243 1a070000 00000000 00000c00 00000000 00000000 00000000 000000 ffff88009bf78240 752698157 C Bo:2:005:2 0 31 > ffff88009bf78240 752698391 S Bi:2:005:2 -115 13 < ffff88009bf78240 752698527 C Bi:2:005:2 0 13 = 55534253 1a070000 00000000 00 ffff88009bf78240 754234230 S Bo:2:005:2 -115 31 = 55534243 1b070000 08000000 80010c4a 01000010 00000008 00000000 000000 ffff88009bf78240 754234295 C Bo:2:005:2 0 31 > ffff8801380f9f00 754234315 S Bi:2:005:2 -115 8 < ffff8801380f9f00 754234415 C Bi:2:005:2 -32 0 ffff88009bf78240 754234438 S Co:2:005:0 s 02 01 0000 0082 0000 0 ffff88009bf78240 754234528 C Co:2:005:0 0 0 ffff88009bf78240 754234540 S Bi:2:005:2 -115 13 < ffff88009bf78240 754255617 C Bi:2:005:2 0 13 = 55534253 1b070000 08000000 01 ffff88009bf78240 754255664 S Bo:2:005:2 -115 31 = 55534243 1c070000 12000000 80010c03 00000012 00000000 00000000 000000 ffff88009bf78240 754255906 C Bo:2:005:2 0 31 > ffff880132d0b3c0 754255925 S Bi:2:005:2 -115 18 < ffff880132d0b3c0 754256032 C Bi:2:005:2 0 18 = 70000500 0000000a 00000000 20000000 0000 ffff88009bf78240 754256047 S Bi:2:005:2 -115 13 < ffff88009bf78240 754256155 C Bi:2:005:2 0 13 = 55534253 1c070000 00000000 00
The upshot is that there seems to be a means to send a variety of commands over the same "configuration". However, I haven't been able to find any resource that describes the commands and arguments that would be recognized by the device. I thought about just sending 256 different command signals to see what comes back, but I think I'd risk sending a factory reset signal or something that might render the camera useless. I'd rather have a camera that doesn't do everything I want but works than have no camera at all.
Saturday, November 2, 2013
Side note: I could have installed an earlier version of Eclipse using apt-get, but I wanted to go with the Kepler edition, so I downloaded the tarball instead. After installing the Android SDK, I was surprised to find that adb wasn't working. I kept getting file not found errors, even though I could clearly see it was there. Problem was I didn't have 32-bit executable support installed yet. Ran apt-get intall ia32-libs, which installed a whole bunch of crap. But this did, in fact, solve the problem.
Back to business. At first glance it doesn't look like I'll be able to control the camera at the level I want, at least from the USB. Here's what I get from the command line:
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 002 Device 003: ID 090c:137b Silicon Motion, Inc. - Taiwan (formerly Feiya Technology Corp.) Bus 005 Device 002: ID 046d:c52f Logitech, Inc. Wireless Mouse M305 Bus 002 Device 004: ID 04e8:1306 Samsung Electronics Co., Ltd seans@snowpack:~$ sudo cat /sys/kernel/debug/usb/devices ... T: Bus=02 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 4 Spd=480 MxCh= 0 D: Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs= 1 P: Vendor=04e8 ProdID=1306 Rev= 0.00 S: Manufacturer=SAMSUNG S: Product=Samsung Digital Camera S: SerialNumber=E00000000002 C:* #Ifs= 1 Cfg#= 1 Atr=c0 MxPwr= 0mA I:* If#= 0 Alt= 0 #EPs= 2 Cls=08(stor.) Sub=05 Prot=50 Driver=usb-storage E: Ad=02(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=82(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms ...
I did some searching on the interwebs and found that, at least for other digital cameras, any "hacking" of the firmware had to be done via memory chip. I can see how this might work for this camera, since it does seem to do some check of the SD chip when turning it on. As of now there's no firmware provided for this particular model, but I'll keep my eyes peeled.
Friday, November 1, 2013
Getting Basic Information from a USB Device
From command line:
gives manufacturer ID : product ID and one-line description
gives more detailed info about device configurations
sample
D: Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs= 2
P: Vendor=04e8 ProdID=6860 Rev= 4.00
S: Manufacturer=SAMSUNG
S: Product=SAMSUNG_Android_SCH-I535
S: SerialNumber=d6190436
C:* #Ifs= 1 Cfg#= 1 Atr=c0 MxPwr= 96mA
I:* If#=0 Alt= 0 #EPs= 3 Cls=06(still) Sub=01 Prot=01 Driver=(none)
E: Ad=81(I) Atr=02(Bulk) MsPS= 512 Ivl=0ms
E: Ad=01(O) Atr=02(Bulk) MxPS=512 Ivl=125us
E: Ad=82(I) Atr=03(Int.) MxPS= 28 Ivl=4ms
C: #Ifs Cfg#= 2 Atr=c0 MxPwr= 96mA
A: FirstIf#= 1 IfCount= 2 Cls=02(comm.) Sub=02 Prot=01
I: If#= 0 Alt= 0 #EPs= 3 Cls=06(still) Sub=01 Prot=01 Driver=
E: Ad=81(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
E: Ad=01(O) Atr=02(Bulk) MxPS= 512 Ivl=125us
E: Ad=82(I) Atr=03(Int.) MxPS= 28 Ivl=4ms
I: If#= 1 Alt= 0 #EPs= 1 Cls=02(comm.) Sub=02 Prot=01 Driver=
E: Ad=84(I) Atr=03(Int.) MxPS= 10 Ivl=32ms
I: If#= 2 Alt= 0 #EPs= 2 Cls=0a(data ) Sub=00 Prot=00 Driver=
E: Ad=83(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
E: Ad=02(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
Thursday, October 31, 2013
Setting up Platform for Project XiCam
First step was install eclipse. Went with the the standard version of the Kepler release, since I don't expect to do much outside of Java programming. In fact, it probably would have made more sense to install the Java 7 SDK first, but it doesn't really make a difference. Both installed and run without any problems.
Next step was to install VirtualBox so I have something to write lower level stuff in C/C++. I used to use Cygwin, but that comes with some extra complications that I'd rather not deal with. Running Linux in a VM not only gives you the desktop appearance but also adds a nice layer of protection to help keep you from doing anything really damaging to your computer (like muffing up your USB host controller). I had intended to install Ubuntu 12.04 64-bit on the guest machine, but apparently 64-bit guests are not supported on this computer (it does, however work on 64-bit Windows 7 on the Intel quad-core I have at work, so I think this may be more an issue with the CPU on the notebook not supporting virtualization rather than an issue with VirtualBox).
Installed Ubuntu 10.04 for x86 architecture on the guest machine. I may have to deal with the 800x600 screen, which actually isn't so terrible. At least the USB 2.0 passthrough apparently works!
Ubuntu 10.04 running in VirtualBox with the mouse and camera showing up in lsusb. |
Tablet emulated using the Android SDK plugin in Eclipse. |
XiCam Project on Hold until USB Issue is Solved
- SD card reader still worked, so I used the 8GB micro SD I found for the camera to save my latest work.
- Did fresh install of Ubuntu. This solved the infinite login loop problem, but not the USB issue.
- Tried following the advice here (link), but that didn't work. I did, however, notice that the system recognized a device was there, it just wasn't responsive.
- I wanted to keep the 8GB card in the camera, so I used the card reader to move the saved data to the 32GB card in my phone and wiped the data from the 8GB card.
I did a full factory restore on the HP, but that still didn't fix the USB issue. Plugged in the mouse and Windows said the device wasn't recognized. Opened up the device manager and uninstalled all of the USB device drivers. After hitting check for new devices, they all came back and no errors came up, but USB ports still didn't work. The next step is to do a BIOS update. After that, I'm not sure what else to do.
Project XiCam Back on Track
- Plugged my phone into one of the USB ports at which point the computer stopped responding to the mouse. I thought the error might have come from a conflict after installing libusb-1.0-0 with its corresponding dev package.
- Ran apt-get remove the packages I had just installed and it removed a whole bunch of critical packages that were reassigned as dependencies. After install, it realized it needed to re-update them all so the whole thing was a mess.
- Rebooted computer and found the OS in an infinite loop on the logon screen. When I deliberately put in a wrong password, it indicated the bad password with a red "invalid password" message. When I entered the correct one, the screen would flash an error for 1/2-second an return to the logon screen. I tried to find a solution on-line. The most common cause of the problem was an .Xauthority file getting set to the wrong permissions. This was not the problem, though.
- Found an old Ubuntu install disk and started the computer in live mode. I had access to all the old directories and tried fixing the problem from there without any luck. Eventually I resigned myself to reinstalling the OS so I backed everything up on a SD card (the USB ports were still not responding, which I think should have been a hint that an OS reinstall wouldn't help).
- Reinstalled Ubuntu 12.04 but USB ports still didn't work. Checked /var/log/syslog and there were repeated error messages. The messages would change when I connected the mouse, but the system never responded to the mouse. Did some more checking of the interwebs but none of the fixes I found worked in my case. Checked HP support site and started researching USB host drivers, which apparently, for my computer, are owned by Microsoft, so I decided to restore the HP to factory default.
- Reinstalled Windows Vista from the recovery disks. This still didn't solve the problem.
- As a last resort, I downloaded the BIOS update. This required Windows to run the installer. This finally worked!
- Take extra care installing USB packages in Ubuntu. If there's a conflict, you won't be able to remove them without affecting a lot of other critical software.
- The USB drivers on HP notebooks are integrated as part of the motherboard chipset. If something goes wrong with it, then you need to flash the BIOS. In the case of this computer, this requires running from Windows (I've heard many complaints about Vista, but to be honest it's always worked well for me; I'm also a fan of Windows 7).
Tuesday, October 29, 2013
Project XiCam -- Part 1
Samsung ST100 digital camera. |
- Samsung ST100 14.2 Mpx digital camera
- 5x optical zoom
- 8GB micro SD
- ASUS TF201 Transformer prime
- NVIDIA Tegra 3 quad-core CPU
- 10.1" screen
- Android Ice Cream Sandwich OS
- 32GB micro SD
- HP Pavilion dv4
- Intel core 2 duo CPU
- Ubuntu 12.04 LTS OS
- Eclipse Juno IDE + Android SDK + ADK
ASUS Tablet with keyboard dock. |
HP Pavilion dv4 notebook |
Before I can do any of these things, I need to develop an understanding of USB protocol. I spent the last couple of days researching this and the communication format doesn't seem terribly complicated. However, many USB products, especially digital cameras, use proprietary formats which require their own drivers.
I ran into a big problem, likely due to installing libusb on the HP. Mouse suddenly stopped working. Thought it was the battery but it worked on another computer. When I checked /var/log/syslog, it was getting overloaded with messages about not being able to enumerate the USB devices. I tried removing libusb-1.0-0 and libusb-1.0-0-dev (the exact packages I installed), then the whole thing went to pot. When the system rebooted after removing and updating the packages, it got stuck in some weird loop where the login screen would come up, I'd enter my password (I had setup the OS to not go to a login screen, so even that was weird), another screen would come up with error messages, but it only stayed for about 1/2 second, so I couldn't tell what the errors were, then went back to the login screen.