trigger: increase timeout again and only read once for now - need a way to figure...
[alphamote.git] / info.c
blob17569393e7785a8d2a40e6d30578eaa1aca5d90d
1 /* This file is generated with usbsnoop2libusb.pl from a usbsnoop log file. */
2 /* Latest version of the script should be in http://iki.fi/lindi/usb/usbsnoop2libusb.pl */
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <assert.h>
7 #include <signal.h>
8 #include <ctype.h>
9 #include <usb.h>
10 #include "alphamote.h"
12 void print_bytes(char *bytes, int len) {
13 int i;
14 if (len > 0) {
15 printf("00: ");
16 for (i=0; i<len; i++) {
17 printf("%02x ", (int)((unsigned char)bytes[i]));
18 if ((i + 1) % 10 == 0) {
19 printf("\n");
20 printf("%02d: ", (i / 10) + 1);
23 printf("\n");
27 void print_interpretation(char *buf) {
28 // byte 35 and 36 are 100 * fstop
29 long fstop_scaled = buf[35] & 255;
30 fstop_scaled |= (buf[36] << 8);
31 double fstop;
32 fstop = (fstop_scaled / 100.0);
33 printf("f%2.1f\n", fstop);
35 if (buf[95] == 1) {
36 // if byte 95 is 1
37 // byte 93 and 94 are 1/time
38 printf("using 1/s\n");
39 long time = (buf[93] & 255) | (buf[94] << 8);
40 printf("1/%ds\n", time);
42 else {
43 // byte 95 and 96 are 10*s (or bulb if 0)
44 long time = (buf[95] & 255) | (buf[96] << 8);
45 if (time != 0) {
46 double time_s;
47 time_s = (time / 10.0);
48 printf("%2.1fs\n", time_s);
50 else {
51 printf("bulb\n");
54 // byte 41 identifies the focusing type
55 if (buf[41] == 1) {
56 printf("M\n");
58 else if (buf[41] == 4) {
59 printf("AF-C\n");
61 else if (buf[41] == 5) {
62 printf("AF-A\n");
64 else if (buf[41] == 2) {
65 printf("AF-S\n");
68 // bytes 71/72 identify drive/bracketing type
69 if (buf[71] == 1) {
70 printf("Singleshot\n");
72 else if (buf[71] == 2) {
73 printf("Continuous drive (high)\n");
75 else if (buf[71] == 0x12) {
76 printf("Continuous drive (low)\n");
78 else if (buf[71] == 4) {
79 printf("Timer (10s)\n");
81 else if (buf[71] == 5) {
82 printf("Timer (2s)\n");
84 else if (buf[71] == '\x37' && buf[72] == '\x83') {
85 printf("Continuous bracketing (0.3 f-stops, 3 pictures)\n");
87 else if (buf[71] == '\x37' && buf[72] == '\x85') {
88 printf("Continuous bracketing (0.3 f-stops, 5 pictures)\n");
90 else if (buf[71] == '\x57' && buf[72] == '\x83') {
91 printf("Continuous bracketing (0.5 f-stops, 3 pictures)\n");
93 else if (buf[71] == '\x57' && buf[72] == '\x85') {
94 printf("Continuous bracketing (0.5 f-stops, 5 pictures)\n");
96 else if (buf[71] == '\x77' && buf[72] == '\x83') {
97 printf("Continuous bracketing (0.7 f-stops, 3 pictures)\n");
99 else if (buf[71] == '\x77' && buf[72] == '\x85') {
100 printf("Continuous bracketing (0.7 f-stops, 5 pictures)\n");
102 else if (buf[71] == '\x47') {
103 printf("Continuous bracketing (2 f-stops, 3 pictures)\n");
105 else if (buf[71] == '\x29') {
106 printf("DR-+ bracketing (high)\n");
108 else if (buf[71] == '\x19') {
109 printf("DR-+ bracketing (low)\n");
111 else if (buf[71] == '\x36' && buf[72] == '\x83') {
112 printf("Single bracketing (0.3 f-stops, 3 pictures)\n");
114 else if (buf[71] == '\x36' && buf[72] == '\x85') {
115 printf("Single bracketing (0.3 f-stops, 5 pictures)\n");
117 else if (buf[71] == '\x56' && buf[72] == '\x83') {
118 printf("Single bracketing (0.5 f-stops, 3 pictures)\n");
120 else if (buf[71] == '\x56' && buf[72] == '\x85') {
121 printf("Single bracketing (0.5 f-stops, 5 pictures)\n");
123 else if (buf[71] == '\x76' && buf[72] == '\x83') {
124 printf("Single bracketing (0.7 f-stops, 3 pictures)\n");
126 else if (buf[71] == '\x76' && buf[72] == '\x85') {
127 printf("Single bracketing (0.7 f-stops, 5 pictures)\n");
129 else if (buf[71] == '\x46') {
130 printf("Single bracketing (2 f-stops, 3 pictures)\n");
132 else if (buf[71] == '\x28') {
133 printf("WB bracketing (high)\n");
135 else if (buf[71] == '\x18') {
136 printf("WB bracketing (low)\n");
138 else if (buf[71] == '\x0a') {
139 printf("Remote control\n");
143 int main(int argc, char **argv) {
144 int ret;
145 char buf[65535];
147 init_usb();
149 ret = usb_get_descriptor(devh, 0x0000001, 0x0000000, buf, 0x0000012);
150 usleep(4*1000);
151 ret = usb_get_descriptor(devh, 0x0000002, 0x0000000, buf, 0x0000009);
152 usleep(3*1000);
153 ret = usb_get_descriptor(devh, 0x0000002, 0x0000000, buf, 0x0000027);
154 usleep(4*1000);
155 ret = usb_release_interface(devh, 0);
156 if (ret != 0) printf("failed to release interface before set_configuration: %d\n", ret);
157 ret = usb_set_configuration(devh, 0x0000001);
158 ret = usb_claim_interface(devh, 0);
159 if (ret != 0) printf("claim after set_configuration failed with error %d\n", ret);
160 ret = usb_set_altinterface(devh, 0);
162 // get info (bulk read 62)
163 usleep(100*1000);
164 memcpy(buf, "\x0c\x00\x00\x00\x01\x00\x08\x92\x0f\x00\x00\x00", 0x000000c);
165 ret = usb_bulk_write(devh, 0x00000001, buf, 0x000000c, 1000);
166 usleep(4*1000);
167 ret = usb_bulk_read(devh, 0x00000082, buf, 0x0000200, 1030);
168 int i;
169 print_interpretation(buf);
170 printf("\n");
171 print_bytes(buf, ret);
172 usleep(4*1000);
173 ret = usb_bulk_read(devh, 0x00000082, buf, 0x0000200, 1030);
174 ret = usb_release_interface(devh, 0);
175 assert(ret == 0);
176 ret = usb_close(devh);
177 assert(ret == 0);
178 return 0;