comparison rcctl.c @ 2:b16b82dbfe87

massive cleanup
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Wed, 05 Jan 2011 21:41:39 +0900
parents 05cc06e88a57
children cd846ca24ca4
comparison
equal deleted inserted replaced
1:05cc06e88a57 2:b16b82dbfe87
1 /* rcctl.c --------------------------------------------- 1 /* rcctl.c ---------------------------------------------
2 $Id: rcctl.c,v 1.1 2002/12/21 01:13:28 tosy Exp $ 2 $Id: rcctl.c,v 1.1 2002/12/21 01:13:28 tosy Exp $
3 3
4 v0.10 97.08.15 初期版(コミケット52) 4 v0.10 97.08.15 (潟宴52)
5 v0.11 97.08.27 通信タイミング修正 5 v0.11 97.08.27 篆<帥ゃ潟遺信罩
6 v0.12 97.09.12 U-kara-2サポート 6 v0.12 97.09.12 U-kara-2泣若
7 v0.12a 97.09.15 返り値設定 7 v0.12a 97.09.15 菴よ┃絎
8 v0.12b 97.09.20 Bug fix (JOY:[SP]) 8 v0.12b 97.09.20 Bug fix (JOY:[SP])
9 v0.20 97.10.01 FreeBSD版 9 v0.20 97.10.01 FreeBSD
10 v0.20a 97.10.18 Bug fix (X2k:[SP],[ST]) 10 v0.20a 97.10.18 Bug fix (X2k:[SP],[ST])
11 v0.21 97.12.10 ALISA-3シーケンス修正 11 v0.21 97.12.10 ALISA-3激若宴潟剛信罩
12 v0.30 97.12.13 コード変換部(cdcnv.c)分離 12 v0.30 97.12.13 潟若紊(cdcnv.c)
13 v0.40 02.12.16 USB版対応 13 v0.40 02.12.16 USB絲上
14 【cdcnv.c の履歴も参照のこと】 14 v0.50 11.01.06 linux絨吾眼 (yaz)
15 cdcnv.c 絮ユ眼с
15 ------------------------------------------------------*/ 16 ------------------------------------------------------*/
16 #define __LINUX__ 17 #define __LINUX__
17 #include <fcntl.h> 18 #include <fcntl.h>
18 #include <stdio.h> 19 #include <stdio.h>
19 #include <termios.h> 20 //#include <termios.h>
20 #include <unistd.h> 21 //#include <unistd.h>
21 #include <sys/ioctl.h> 22 //#include <sys/ioctl.h>
22 23
23 #define HID_MAX_USAGES 16 24 #define HID_MAX_USAGES 16
24 typedef unsigned int __u32; 25 typedef unsigned int __u32;
25 typedef unsigned int kernel_ulong_t; 26 typedef unsigned int kernel_ulong_t;
26 27
33 34
34 #include <asm/types.h> 35 #include <asm/types.h>
35 #include <errno.h> 36 #include <errno.h>
36 #include <string.h> 37 #include <string.h>
37 38
39 #include "debug.h"
38 40
39 #ifndef S_VERS 41 #ifndef S_VERS
40 #define S_VERS "0.41" 42 #define S_VERS "0.50"
41 #endif 43 #endif
42 44
43 /* globals */ 45 /* globals */
44 HIDInterface *hidif; 46 HIDInterface *hidif;
45 extern int errno; 47 extern int errno;
48 int debug = 0;
46 49
47 /* prototypes */ 50 /* prototypes */
48 int cdcnv(int buf[], char *mak, char *cod); 51 int cdcnv(int buf[], char *mak, char *cod);
49 extern char *cverrstr[]; 52 extern char *cverrstr[];
50 53
51 int init_usb(void) 54 int init_usb(void)
52 { 55 {
53 hid_return ret; 56 hid_return ret;
54 57
55 // unsigned int report_id;
56 // unsigned int report_type;
57 // unsigned int size;
58
59 /* vendor id and product id of okecon */ 58 /* vendor id and product id of okecon */
60 HIDInterfaceMatcher matcher = { 0x0bfe, 0x2022, NULL, NULL, 0 }; 59 HIDInterfaceMatcher matcher = { 0x0bfe, 0x2022, NULL, NULL, 0 };
61 60
62 /* see include/debug.h for possible values */ 61 /* see include/debug.h for possible values */
63 hid_set_debug(HID_DEBUG_ALL); 62 hid_set_debug(debug);
64 hid_set_debug_stream(stderr); 63 hid_set_debug_stream(stderr);
65 /* passed directly to libusb */ 64 /* passed directly to libusb */
66 hid_set_usb_debug(0); 65 hid_set_usb_debug(0);
67 66
68 ret = hid_init(); 67 ret = hid_init();
80 ret = hid_force_open(hidif, 0, &matcher, 3); 79 ret = hid_force_open(hidif, 0, &matcher, 3);
81 if (ret != HID_RET_SUCCESS) { 80 if (ret != HID_RET_SUCCESS) {
82 fprintf(stderr, "hid_force_open failed with return code %d\n", ret); 81 fprintf(stderr, "hid_force_open failed with return code %d\n", ret);
83 return 1; 82 return 1;
84 } 83 }
85
86
87
88 #if 0
89 /* read feature */
90 ret = hid_get_feature_report(hidif, path, depth, buffer, size);
91 if(ret != HID_RET_SUCCESS) {
92 fprintf(stderr, "hid_get_feature_report failed with return code %d\n", ret);
93 return 1;
94 }
95
96 /* parse */
97
98 /* prepare buffers */
99 hid_get_report_size(hidif, report_id, report_type, &size);
100 if(size != 8) {
101 fprintf(stderr, "%s is not 'OKCon/USB'?\n", UDEV);
102 return 1;
103 };
104
105
106 // BSD
107 /* read header */
108 if ((rd = hid_get_report_desc(fd)) == 0) {
109 fprintf(stderr, "Failed on USB_GET_REPORT_DESC.\n");
110 return 1;
111 }
112
113 /* parse */
114 hd = hid_start_parse(rd, 1<<hid_output);
115 while ( hid_get_item(hd, &shi) ) {
116 if(shi.kind == hid_output)
117 break;
118 }
119 hid_end_parse(hd);
120
121 /* prepare buffers */
122 hid_get_report_size(&hidif, report_id, report_type, &size);
123 if(size != 8) {
124 fprintf(stderr, "%s is not 'OKCon/USB'?\n", UDEV);
125 return 1;
126 };
127
128 hid_dispose_report_desc(rd);
129 #endif
130 84
131 return 0; 85 return 0;
132 } /* end of init_usb() */ 86 } /* end of init_usb() */
133 87
134 88
151 } 105 }
152 106
153 return 0; 107 return 0;
154 } 108 }
155 109
110 void usage(char *cmd)
111 {
112 printf("'Oke-Con' controller, version " S_VERS ".\n");
113 printf("Copyright (C) 1997-2002 by Tosy / W341IG.\n");
114 printf("Adapted to linux by yaz / honeyplanet development\n");
115 printf("usage: %s <options> <vender> <song number>\n", cmd);
116 printf("options: -d <debug level>\n");
117 exit(0);
118 }
156 119
157 120
158 int main(int ac, char *av[]) 121 int main(int argc, char **argv)
159 { 122 {
160 int i, u, buf[16]; 123 int i, u, buf[16];
161 unsigned char sbuf[8]; 124 unsigned char sbuf[8];
162 hid_return ret; 125 hid_return ret;
126 int opt;
163 127
164 if (ac < 3) { 128 if(argc < 3) {
165 printf("'Oke-Con' controller, version " S_VERS ".\n"); 129 usage(argv[0]);
166 printf("Copyright (C) 1997-2002 by Tosy / W341IG.\n");
167 printf("Usage: rcctl <maker> <code>\n");
168 return 255;
169 } 130 }
170 131
171 if ((u = cdcnv(buf, av[1], av[2])) < 0) { 132 while ((opt=getopt(argc, argv, "d:h")) != -1) {
172 fprintf(stderr, "%s: %s\n", av[0], cverrstr[~u]); 133 switch (opt) {
134 case 'd':
135 debug = atoi(optarg);
136 break;
137 case 'h':
138 default:
139 usage(argv[0]);
140 break;
141 }
142 }
143 argc -= optind;
144 argv += optind;
145
146 if ((u = cdcnv(buf, *argv, *(argv+1))) < 0) {
147 fprintf(stderr, "%s: %s\n", *argv, cverrstr[~u]);
173 return 1; 148 return 1;
174 } 149 }
175 printf("cdcnv %d\n", u); 150 debug(1, "cdcnv %d\n", u);
176 151 debug(1, "Initializing....\n");
177 #ifdef VERBOSE
178 printf("Initializing....\n");
179 #endif
180 152
181 if (init_usb()) 153 if (init_usb())
182 return 255; 154 return 255;
183 155
184 #ifdef VERBOSE 156 debug(1, " done.\n");
185 printf(" done.\n");
186 #endif
187 157
188 #ifdef VERBOSE
189 for(i=0; i<u; i++ ) { 158 for(i=0; i<u; i++ ) {
190 printf("%02x ", buf[i]); 159 debug(1, "%02x ", buf[i]);
191 } 160 }
192 printf("\n"); 161 debug(1, "\n");
193 #endif
194 162
195 /* xxx */
196 const int PATH_IN[1] = { 0xffa10004 }; 163 const int PATH_IN[1] = { 0xffa10004 };
197 // const int PATH_OUT[1] = { 0xffa10008 };
198 164
199 /* u is the total length of the packet to send */ 165 /* u is the total length of the packet to send */
200 for(i=1; i<u; i++ ) { 166 for(i=1; i<u; i++ ) {
201 sbuf[(i-1)%8] = buf[i] & 0x00ff; 167 sbuf[(i-1)%8] = buf[i] & 0x00ff;
202 #ifdef VERBOSE 168 debug(1, "%02x ", sbuf[(i-1)%8]);
203 printf("%02x ", sbuf[(i-1)%8]);
204 #endif
205 if ((i == 8)||(i == (u-1))) { 169 if ((i == 8)||(i == (u-1))) {
206 ret = hid_set_output_report(hidif, PATH_IN, 2, (char *)sbuf, 8); 170 ret = hid_set_output_report(hidif, PATH_IN, 2, (char *)sbuf, 8);
207 fprintf(stderr, "**WRITE**\n"); 171 fprintf(stderr, "**WRITE**\n");
208 if (ret != HID_RET_SUCCESS) { 172 if (ret != HID_RET_SUCCESS) {
209 fprintf(stderr, "hid_set_output_report failed with return code %d\n", ret); 173 fprintf(stderr, "hid_set_output_report failed with return code %d\n", ret);
210 } 174 }
211
212 #if 0
213 char packet[8];
214 ret = hid_get_input_report(hidif, PATH_OUT, 2, packet, 8);
215 if (ret != HID_RET_SUCCESS) {
216 fprintf(stderr, "hid_get_input_report failed with return code %d\n", ret);
217 }
218 #endif
219 } 175 }
220 } 176 }
221 #ifdef VERBOSE 177 debug(1, "\n");
222 printf("\n");
223 #endif
224 178
225 if(fin_usb()) 179 if(fin_usb())
226 return 255; 180 return 255;
227 181
228 return 0; 182 return 0;