moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kstars / kstars / indi / fli / libfli-usb-sys-bsd.c
blobd1f6a2b04d1b1a1a1f81eb3bd945891068a1b2e9
1 /*
3 Copyright (c) 2002 Finger Lakes Instrumentation (FLI), L.L.C.
4 All rights reserved.
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
10 Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
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.
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.
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.
36 ======================================================================
38 Finger Lakes Instrumentation, L.L.C. (FLI)
39 web: http://www.fli-cam.com
40 email: support@fli-cam.com
44 #include <sys/types.h>
45 #include <dev/usb/usb.h>
46 #include <sys/ioctl.h>
48 #include <unistd.h>
49 #include <errno.h>
51 #include "libfli-libfli.h"
52 #include "libfli-sys.h"
53 #include "libfli-usb.h"
55 long unix_usbverifydescriptor(flidev_t dev, fli_unixio_t *io)
57 usb_device_descriptor_t usb_desc;
58 int r;
60 if ((r = read(io->fd, &usb_desc, sizeof(usb_device_descriptor_t))) !=
61 sizeof(usb_device_descriptor_t))
63 debug(FLIDEBUG_FAIL, "linux_usbverifydescriptor(): Could not read descriptor.");
64 return -EIO;
66 else
68 debug(FLIDEBUG_INFO, "USB device descriptor:");
69 if(usb_desc.idVendor != 0x0f18)
71 debug(FLIDEBUG_FAIL, "linux_usbverifydescriptor(): Not a FLI device!");
72 return -ENODEV;
75 switch(DEVICE->domain)
77 case FLIDOMAIN_USB:
78 if(usb_desc.idProduct != 0x0002)
80 return -ENODEV;
82 break;
84 default:
85 return -EINVAL;
86 break;
89 DEVICE->devinfo.fwrev = usb_desc.bcdDevice;
92 return 0;
95 long bsd_bulkwrite(flidev_t dev, void *buf, long *wlen)
97 fli_unixio_t *io;
98 long org_wlen = *wlen;
99 int to;
101 io = DEVICE->io_data;
102 to = DEVICE->io_timeout;
104 if (ioctl(io->fd, USB_SET_TIMEOUT, &to) == -1)
105 return -errno;
107 *wlen = write(io->fd, buf, *wlen);
109 if (*wlen != org_wlen)
110 return -errno;
111 else
112 return 0;
115 long bsd_bulkread(flidev_t dev, void *buf, long *rlen)
117 fli_unixio_t *io;
118 long org_rlen = *rlen;
119 int to;
121 io = DEVICE->io_data;
122 to = DEVICE->io_timeout;
124 if (ioctl(io->fd, USB_SET_TIMEOUT, &to) == -1)
125 return -errno;
127 *rlen = read(io->fd, buf, *rlen);
129 if (*rlen != org_rlen)
130 return -errno;
131 else
132 return 0;