Mercurial > rcctl_linux
comparison rcctl.c @ 6:cd846ca24ca4
more cleanup
| author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
|---|---|
| date | Wed, 05 Jan 2011 22:32:50 +0900 |
| parents | b16b82dbfe87 |
| children | d2b8d45019d9 |
comparison
equal
deleted
inserted
replaced
| 5:37e662c427a1 | 6:cd846ca24ca4 |
|---|---|
| 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 v0.50 11.01.06 linux専用に書き直し (yaz) | 14 v0.50 11.01.06 linux専用に書き直し (yaz) |
| 15 【cdcnv.c の履歴も参照のこと】 | 15 【cdcnv.c の履歴も参照のこと】 |
| 16 ------------------------------------------------------*/ | 16 ------------------------------------------------------*/ |
| 17 #define __LINUX__ | 17 |
| 18 #include <fcntl.h> | |
| 19 #include <stdio.h> | 18 #include <stdio.h> |
| 20 //#include <termios.h> | |
| 21 //#include <unistd.h> | |
| 22 //#include <sys/ioctl.h> | |
| 23 | |
| 24 #define HID_MAX_USAGES 16 | |
| 25 typedef unsigned int __u32; | |
| 26 typedef unsigned int kernel_ulong_t; | |
| 27 | |
| 28 #include <hid.h> | 19 #include <hid.h> |
| 29 #include <libusb.h> | 20 #include <libusb.h> |
| 30 | |
| 31 #include <linux/types.h> | |
| 32 | |
| 33 #define BITS_PER_LONG 32 | |
| 34 | |
| 35 #include <asm/types.h> | |
| 36 #include <errno.h> | |
| 37 #include <string.h> | |
| 38 | |
| 39 #include "debug.h" | 21 #include "debug.h" |
| 40 | 22 |
| 41 #ifndef S_VERS | 23 #ifndef S_VERS |
| 42 #define S_VERS "0.50" | 24 #define S_VERS "0.50" |
| 43 #endif | 25 #endif |
| 44 | 26 |
| 45 /* globals */ | 27 /* globals */ |
| 46 HIDInterface *hidif; | 28 HIDInterface *hidif; |
| 47 extern int errno; | |
| 48 int debug = 0; | 29 int debug = 0; |
| 49 | 30 |
| 50 /* prototypes */ | 31 /* prototypes */ |
| 51 int cdcnv(int buf[], char *mak, char *cod); | 32 int cdcnv(int buf[], char *mak, char *cod); |
| 52 extern char *cverrstr[]; | 33 extern char *cverrstr[]; |
| 64 /* passed directly to libusb */ | 45 /* passed directly to libusb */ |
| 65 hid_set_usb_debug(0); | 46 hid_set_usb_debug(0); |
| 66 | 47 |
| 67 ret = hid_init(); | 48 ret = hid_init(); |
| 68 if (ret != HID_RET_SUCCESS) { | 49 if (ret != HID_RET_SUCCESS) { |
| 69 fprintf(stderr, "hid_init failed with return code %d\n", ret); | 50 message(0, "hid_init failed with return code %d\n", ret); |
| 70 return 1; | 51 return 1; |
| 71 } | 52 } |
| 72 | 53 |
| 73 hidif = hid_new_HIDInterface(); | 54 hidif = hid_new_HIDInterface(); |
| 74 if (hidif == 0) { | 55 if (hidif == 0) { |
| 76 return 1; | 57 return 1; |
| 77 } | 58 } |
| 78 | 59 |
| 79 ret = hid_force_open(hidif, 0, &matcher, 3); | 60 ret = hid_force_open(hidif, 0, &matcher, 3); |
| 80 if (ret != HID_RET_SUCCESS) { | 61 if (ret != HID_RET_SUCCESS) { |
| 81 fprintf(stderr, "hid_force_open failed with return code %d\n", ret); | 62 message(0, "hid_force_open failed with return code %d\n", ret); |
| 82 return 1; | 63 return 1; |
| 83 } | 64 } |
| 84 | 65 |
| 85 return 0; | 66 return 0; |
| 86 } /* end of init_usb() */ | 67 } /* end of init_usb() */ |
| 90 { | 71 { |
| 91 hid_return ret; | 72 hid_return ret; |
| 92 | 73 |
| 93 ret = hid_close(hidif); | 74 ret = hid_close(hidif); |
| 94 if (ret != HID_RET_SUCCESS) { | 75 if (ret != HID_RET_SUCCESS) { |
| 95 fprintf(stderr, "hid_close failed with return code %d\n", ret); | 76 message(0, "hid_close failed with return code %d\n", ret); |
| 96 return 1; | 77 return 1; |
| 97 } | 78 } |
| 98 | 79 |
| 99 hid_delete_HIDInterface(&hidif); | 80 hid_delete_HIDInterface(&hidif); |
| 100 | 81 |
| 101 ret = hid_cleanup(); | 82 ret = hid_cleanup(); |
| 102 if (ret != HID_RET_SUCCESS) { | 83 if (ret != HID_RET_SUCCESS) { |
| 103 fprintf(stderr, "hid_cleanup failed with return code %d\n", ret); | 84 message(0, "hid_cleanup failed with return code %d\n", ret); |
| 104 return 1; | 85 return 1; |
| 105 } | 86 } |
| 106 | 87 |
| 107 return 0; | 88 return 0; |
| 108 } | 89 } |
| 151 debug(1, "Initializing....\n"); | 132 debug(1, "Initializing....\n"); |
| 152 | 133 |
| 153 if (init_usb()) | 134 if (init_usb()) |
| 154 return 255; | 135 return 255; |
| 155 | 136 |
| 156 debug(1, " done.\n"); | 137 debug(1, "done.\n"); |
| 157 | 138 |
| 139 debug(1, ""); | |
| 158 for(i=0; i<u; i++ ) { | 140 for(i=0; i<u; i++ ) { |
| 159 debug(1, "%02x ", buf[i]); | 141 message(1, "%02x ", buf[i]); |
| 160 } | 142 } |
| 161 debug(1, "\n"); | 143 message(1, "\n"); |
| 162 | 144 |
| 163 const int PATH_IN[1] = { 0xffa10004 }; | 145 const int PATH_IN[1] = { 0xffa10004 }; |
| 164 | 146 |
| 165 /* u is the total length of the packet to send */ | 147 /* u is the total length of the packet to send */ |
| 148 debug(1,""); | |
| 166 for(i=1; i<u; i++ ) { | 149 for(i=1; i<u; i++ ) { |
| 167 sbuf[(i-1)%8] = buf[i] & 0x00ff; | 150 sbuf[(i-1)%8] = buf[i] & 0x00ff; |
| 168 debug(1, "%02x ", sbuf[(i-1)%8]); | 151 message(1, "%02x ", sbuf[(i-1)%8]); |
| 169 if ((i == 8)||(i == (u-1))) { | 152 if ((i == 8)||(i == (u-1))) { |
| 170 ret = hid_set_output_report(hidif, PATH_IN, 2, (char *)sbuf, 8); | 153 ret = hid_set_output_report(hidif, PATH_IN, 2, (char *)sbuf, 8); |
| 171 fprintf(stderr, "**WRITE**\n"); | 154 message(1, "**WRITE** "); |
| 172 if (ret != HID_RET_SUCCESS) { | 155 if (ret != HID_RET_SUCCESS) { |
| 173 fprintf(stderr, "hid_set_output_report failed with return code %d\n", ret); | 156 message(0, "hid_set_output_report failed with return code %d\n", ret); |
| 174 } | 157 } |
| 175 } | 158 } |
| 176 } | 159 } |
| 177 debug(1, "\n"); | 160 message(1, "\n"); |
| 178 | 161 |
| 179 if(fin_usb()) | 162 if(fin_usb()) |
| 180 return 255; | 163 return 255; |
| 181 | 164 |
| 182 return 0; | 165 return 0; |
