moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kstars / kstars / indi / fli / libfli-parport.c
blob05d761ec54616fc9b3ff02abee60e3e04b047823
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/ioctl.h>
45 #include <asm/param.h>
47 #include <errno.h>
48 #include <unistd.h>
50 #include "libfli-libfli.h"
51 #include "libfli-debug.h"
52 #include "libfli-camera.h"
54 #include "fli_ioctl.h"
56 long unix_parportio_linux(flidev_t dev, void *buf, long *wlen, long *rlen)
58 fli_unixio_t *io;
59 flicamdata_t *cam;
60 int err = 0, locked = 0;
61 long org_wlen = *wlen, org_rlen = *rlen;
62 int wto, rto, dto;
64 io = DEVICE->io_data;
65 cam = DEVICE->device_data;
67 if ((err = unix_fli_lock(dev)))
69 debug(FLIDEBUG_WARN, "Lock failed");
70 goto done;
73 locked = 1;
75 /* Convert timeout to jiffies */
76 wto = cam->writeto / 1000 * HZ;
77 rto = cam->readto / 1000 * HZ;
78 dto = cam->dirto / 1000 * HZ;
80 if (ioctl(io->fd, FLI_SET_WTO, &wto))
82 err = -errno;
83 goto done;
86 if (ioctl(io->fd, FLI_SET_DTO, &dto))
88 err = -errno;
89 goto done;
92 if (ioctl(io->fd, FLI_SET_RTO, &rto))
94 err = -errno;
95 goto done;
98 if ((*wlen = write(io->fd, buf, *wlen)) != org_wlen)
100 debug(FLIDEBUG_WARN, "write failed, only %d of %d bytes written",
101 *wlen, org_wlen);
102 err = -errno;
103 goto done;
106 if (*rlen > 0)
108 if ((*rlen = read(io->fd, buf, *rlen)) != org_rlen)
110 debug(FLIDEBUG_WARN, "read failed, only %d of %d bytes read",
111 *rlen, org_rlen);
112 err = -errno;
113 goto done;
117 done:
119 if (locked)
121 int r;
123 if ((r = unix_fli_unlock(dev)))
124 debug(FLIDEBUG_WARN, "Unlock failed");
125 if (err == 0)
126 err = r;
129 return err;