| 1 |
/* |
| 2 |
|
| 3 |
Copyright (c) 2002 Finger Lakes Instrumentation (FLI), L.L.C. |
| 4 |
All rights reserved. |
| 5 |
|
| 6 |
Redistribution and use in source and binary forms, with or without |
| 7 |
modification, are permitted provided that the following conditions |
| 8 |
are met: |
| 9 |
|
| 10 |
Redistributions of source code must retain the above copyright |
| 11 |
notice, this list of conditions and the following disclaimer. |
| 12 |
|
| 13 |
Redistributions in binary form must reproduce the above |
| 14 |
copyright notice, this list of conditions and the following |
| 15 |
disclaimer in the documentation and/or other materials |
| 16 |
provided with the distribution. |
| 17 |
|
| 18 |
Neither the name of Finger Lakes Instrumentation (FLI), LLC |
| 19 |
nor the names of its contributors may be used to endorse or |
| 20 |
promote products derived from this software without specific |
| 21 |
prior written permission. |
| 22 |
|
| 23 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 24 |
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 25 |
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 26 |
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 27 |
REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 28 |
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 29 |
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 30 |
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 31 |
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 32 |
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
| 33 |
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 34 |
POSSIBILITY OF SUCH DAMAGE. |
| 35 |
|
| 36 |
====================================================================== |
| 37 |
|
| 38 |
Finger Lakes Instrumentation, L.L.C. (FLI) |
| 39 |
web: http://www.fli-cam.com |
| 40 |
email: [email protected] |
| 41 |
|
| 42 |
*/ |
| 43 |
|
| 44 |
//========================================================================== |
| 45 |
// Include Files for Mac OSX IO |
| 46 |
// |
| 47 |
//========================================================================== |
| 48 |
#include <CoreFoundation/CoreFoundation.h> |
| 49 |
#include <sys/types.h> |
| 50 |
#include <sys/ioctl.h> |
| 51 |
#include <sys/file.h> |
| 52 |
#include <sys/stat.h> |
| 53 |
#include <sys/param.h> |
| 54 |
#include <limits.h> |
| 55 |
|
| 56 |
#include <stdio.h> |
| 57 |
#include <unistd.h> |
| 58 |
#include <errno.h> |
| 59 |
#include <fcntl.h> |
| 60 |
#include <string.h> |
| 61 |
#include <signal.h> |
| 62 |
#include <stdlib.h> |
| 63 |
#include <glob.h> |
| 64 |
|
| 65 |
#include <IOKit/IOKitLib.h> |
| 66 |
#include <IOKit/IOMessage.h> |
| 67 |
#include <IOKit/IOCFPlugIn.h> |
| 68 |
#include <IOKit/usb/IOUSBLib.h> |
| 69 |
|
| 70 |
#include "libfli.h" |
| 71 |
#include "libfli-libfli.h" |
| 72 |
#include "libfli-usb.h" |
| 73 |
#include "libfli-camera.h" |
| 74 |
#include "libfli-filter-focuser.h" |
| 75 |
//------------------------------------------------------------------------- |
| 76 |
|
| 77 |
/* Structure to describe string descriptor transfers */ |
| 78 |
typedef struct { |
| 79 |
unsigned int index; |
| 80 |
char buf[64]; |
| 81 |
} fliusb_string_descriptor_t; |
| 82 |
|
| 83 |
/* Structure to describe bulk transfers */ |
| 84 |
typedef struct { |
| 85 |
u_int8_t ep; |
| 86 |
void *buf; |
| 87 |
size_t count; |
| 88 |
unsigned int timeout; /* in msec */ |
| 89 |
} fliusb_bulktransfer_t; |
| 90 |
|
| 91 |
/* 8-bit special value to identify ioctl 'type' */ |
| 92 |
#define FLIUSB_IOC_TYPE 0xf1 |
| 93 |
|
| 94 |
/* Recognized ioctl commands */ |
| 95 |
#define FLIUSB_GETRDEPADDR _IOR(FLIUSB_IOC_TYPE, 1, u_int8_t) |
| 96 |
#define FLIUSB_SETRDEPADDR _IOW(FLIUSB_IOC_TYPE, 2, u_int8_t) |
| 97 |
|
| 98 |
#define FLIUSB_GETWREPADDR _IOR(FLIUSB_IOC_TYPE, 3, u_int8_t) |
| 99 |
#define FLIUSB_SETWREPADDR _IOW(FLIUSB_IOC_TYPE, 4, u_int8_t) |
| 100 |
|
| 101 |
#define FLIUSB_GETBUFFERSIZE _IOR(FLIUSB_IOC_TYPE, 5, size_t) |
| 102 |
#define FLIUSB_SETBUFFERSIZE _IOW(FLIUSB_IOC_TYPE, 6, size_t) |
| 103 |
|
| 104 |
#define FLIUSB_GETTIMEOUT _IOR(FLIUSB_IOC_TYPE, 7, unsigned int) |
| 105 |
#define FLIUSB_SETTIMEOUT _IOW(FLIUSB_IOC_TYPE, 8, unsigned int) |
| 106 |
|
| 107 |
#define FLIUSB_BULKREAD _IOW(FLIUSB_IOC_TYPE, 9, fliusb_bulktransfer_t) |
| 108 |
#define FLIUSB_BULKWRITE _IOW(FLIUSB_IOC_TYPE, 10, fliusb_bulktransfer_t) |
| 109 |
|
| 110 |
#define FLIUSB_GET_DEVICE_DESCRIPTOR _IOR(FLIUSB_IOC_TYPE, 11, struct usb_device_descriptor) |
| 111 |
#define FLIUSB_GET_STRING_DESCRIPTOR _IOR(FLIUSB_IOC_TYPE, 12, struct usb_device_descriptor) |
| 112 |
|
| 113 |
#define FLIUSB_IOC_MAX 12 |
| 114 |
|
| 115 |
#define FLIUSB_PROD(name,id) case id: |
| 116 |
|
| 117 |
#define FLIUSB_PRODUCTS \ |
| 118 |
FLIUSB_PROD(FLIUSB_MAXCAM, 0x0002) \ |
| 119 |
FLIUSB_PROD(FLIUSB_STEPPER, 0x0005) \ |
| 120 |
FLIUSB_PROD(FLIUSB_FOCUSER, 0x0006) \ |
| 121 |
FLIUSB_PROD(FLIUSB_FILTERWHEEL,0x0007) \ |
| 122 |
FLIUSB_PROD(FLIUSB_PROLINECAM, 0x000A) |
| 123 |
|
| 124 |
#undef FLIUSB_PROD |
| 125 |
|
| 126 |
enum |
| 127 |
{ |
| 128 |
#define FLIUSB_PROD(name,id) name=id, |
| 129 |
FLIUSB_PRODUCTS |
| 130 |
#undef FLIUSB_PROD |
| 131 |
}; |
| 132 |
|
| 133 |
#define FLIUSB_PROD(name,id) case id: |
| 134 |
|
| 135 |
#define USB_DIR_OUT (0x00) |
| 136 |
#define USB_DIR_IN (0x80) |
| 137 |
|
| 138 |
#define BUFFERSIZE 65536 |
| 139 |
|
| 140 |
#define FLI_VENDOR_ID 0x0f18 |
| 141 |
|
| 142 |
#define MAX_SEARCH 32 |
| 143 |
|
| 144 |
//------------------------------------------------------------------------- |
| 145 |
|
| 146 |
typedef struct _mac_device_info |
| 147 |
{ |
| 148 |
IOUSBInterfaceInterface190 **interface; // Requires >= 10.2 |
| 149 |
IOUSBDeviceInterface182 **device; |
| 150 |
UInt8 interfaceNumEndpoints; |
| 151 |
unsigned int epWrite, epRead, epReadBulk; |
| 152 |
|
| 153 |
|
| 154 |
} mac_device_info; |
| 155 |
|
| 156 |
#define DEVICE_DATA ((mac_device_info*)DEVICE->sys_data) |
| 157 |
|
| 158 |
long mac_fli_list(flidomain_t domain, char ***names); |
| 159 |
|
| 160 |
long mac_fli_connect(flidev_t dev, char *name, long domain); |
| 161 |
long mac_fli_disconnect(flidev_t dev, fli_unixio_t *io); |
| 162 |
|
| 163 |
long mac_usb_connect(flidev_t dev, fli_unixio_t *io, char *name); |
| 164 |
IOReturn mac_usb_configure_device(IOUSBDeviceInterface182 **dev); |
| 165 |
IOReturn mac_usb_find_interfaces(flidev_t dev, IOUSBDeviceInterface182 **device); |
| 166 |
|
| 167 |
long mac_usb_disconnect(flidev_t dev, fli_unixio_t *io); |
| 168 |
|
| 169 |
long mac_bulktransfer(flidev_t dev, int ep, void *buf, long *len); |
| 170 |
|
| 171 |
long mac_bulkread(flidev_t dev, void *buf, long *rlen); |
| 172 |
long mac_bulkwrite(flidev_t dev, void *buf, long *wlen); |
| 173 |
|
| 174 |
ssize_t mac_usb_piperead(flidev_t dev, void *buf,size_t size, unsigned pipe, unsigned timeout); |
| 175 |
ssize_t mac_usb_pipewrite(flidev_t dev, void *buf, size_t size, unsigned pipe, unsigned timeout); |
| 176 |
|
| 177 |
long mac_fli_lock(flidev_t dev); |
| 178 |
long mac_fli_unlock(flidev_t dev); |
| 179 |
|