Thanks.
From,
Bob
X-VM-v5-Data: ([nil nil nil nil nil nil nil nil nil]
["20470" "Wed" "11" "November" "1998" "14:01:50" "-0800" "owner-sane-devel@mostang.com" "owner-sane-devel@mostang.com" nil "664" "BOUNCE sane-devel@mostang.com: Non-member submission from [James Carter <james@cs.york.ac.uk>] " "^From:" nil nil "11" nil nil nil nil nil]
nil)
Return-Path: <owner-sane-devel@mostang.com>
Received: (from majordom@localhost)
by panda.mostang.com (8.8.7/8.8.7) id OAA21359;
Wed, 11 Nov 1998 14:01:50 -0800
Message-Id: <199811112201.OAA21359@panda.mostang.com>
Status: RO
From: owner-sane-devel@mostang.com
To: owner-sane-devel@mostang.com
Subject: BOUNCE sane-devel@mostang.com: Non-member submission from [James Carter <james@cs.york.ac.uk>]
Date: Wed, 11 Nov 1998 14:01:50 -0800
>From sane-devel-owner@mostang.com Wed Nov 11 14:01:49 1998
Received: from titan.cs.york.ac.uk (Titan.cs.york.ac.uk [144.32.40.9])
by panda.mostang.com (8.8.7/8.8.7) with SMTP id OAA21356
for <sane-devel@mostang.com>; Wed, 11 Nov 1998 14:01:47 -0800
Message-ID: <swordfish.910821656@cs.york.ac.uk>
Date: Wed, 11 Nov 1998 21:59:47 +0000
From: James Carter <james@cs.york.ac.uk>
Subject: hporig merge
To: sane-devel@mostang.com
In-Reply-To: <199811100536.VAA01423@panda.mostang.com>
MIME-Version: 1.0
Content-Type: MULTIPART/mixed; BOUNDARY="-1876940720-2078917053-910821594=:10009"
---1876940720-2078917053-910821594=:10009
Content-Type: TEXT/plain; CHARSET=US-ASCII
On 9 Nov, David Mosberger-Tang wrote:
> BTW: I really would prefer if someone could integrate the hporig stuff
> into hp. I don't want to have to distribute two different HP backends
> if I can help it.
ok. attached is my first attempt at doing this.
it basically works but there are a few problems:
1. the hp driver is very scsi oriented. without extensive restructuring,
i cannot find an elegant way of getting the parallel interface stuff
integrated. this effort is a bit hacky as a consequence of this.
2. i've not tested this on a system with scsi (yet), so i don't know if
i've broken that side of things.
3. i haven't worked out a way of determining if a device is scsi or
"hporig". i'd like it to try scsi first and if that fails try
hporig stuff but i get segmentation violations when i try scsi on a
non-scsi device (including /dev/null!). at the moment i check that
the device name is "/dev/hpscan" before doing anything non-scsi. i
think it's safe as long as /dev/scanner isn't linked to /dev/hpscan.
4. i don't know what to probe for in hp_device_probe to find the
scanjet and the scanjet plus. any ideas?
anyway, i hope it's useful.
-- J.F.Carter <URL:http://www.cs.york.ac.uk/~james/>
---1876940720-2078917053-910821594=:10009 Content-Type: TEXT/plain; CHARSET=US-ASCII Content-Description: hp.diff
diff -crN current/sane-pre1.00/backend/Makefile.in sane-pre1.00/backend/Makefile.in *** current/sane-pre1.00/backend/Makefile.in Fri Oct 30 08:11:05 1998 --- sane-pre1.00/backend/Makefile.in Wed Nov 11 20:40:02 1998 *************** *** 143,149 **** # additional dependencies ! EXTRA_hp = hp-accessor hp-device hp-handle hp-hpmem hp-option hp-scl # When preloading dll, we need to add in all preloaded objects: libsane-dll.la: $(addsuffix .lo,$(DLL_PRELOAD)) --- 143,149 ---- # additional dependencies ! EXTRA_hp = hp-accessor hp-device hp-handle hp-hpmem hp-option hp-scl hp-orig # When preloading dll, we need to add in all preloaded objects: libsane-dll.la: $(addsuffix .lo,$(DLL_PRELOAD)) diff -crN current/sane-pre1.00/backend/hp-device.c sane-pre1.00/backend/hp-device.c *** current/sane-pre1.00/backend/hp-device.c Tue Jul 28 19:25:29 1998 --- sane-pre1.00/backend/hp-device.c Wed Nov 11 17:58:29 1998 *************** *** 47,57 **** --- 47,59 ---- #include <stdlib.h> #include <string.h> #include <assert.h> + #include "hp.h" #include "hp-device.h" #include "hp-accessor.h" #include "hp-option.h" #include "hp-scsi.h" #include "hp-scl.h" + #include "hp-orig.h" static SANE_Status hp_device_probe (HpDevice this, HpScsi scsi) *************** *** 68,74 **** { SCL_HP_MODEL_6, "3p", HP_COMPAT_3P }, { SCL_HP_MODEL_8, "4P", HP_COMPAT_4P }, { SCL_HP_MODEL_9, "5P", HP_COMPAT_5P }, ! { SCL_HP_MODEL_10, "Photo Scanner", HP_COMPAT_PS } }; int i; char buf[8]; --- 70,77 ---- { SCL_HP_MODEL_6, "3p", HP_COMPAT_3P }, { SCL_HP_MODEL_8, "4P", HP_COMPAT_4P }, { SCL_HP_MODEL_9, "5P", HP_COMPAT_5P }, ! { SCL_HP_MODEL_10, "Photo Scanner", HP_COMPAT_PS }, ! /*{ SCL_HP_MODEL_11, "Plus", HP_COMPAT_PLUS }*/ }; int i; char buf[8]; *************** *** 80,85 **** --- 83,89 ---- for (i = 0; i < sizeof(probes)/sizeof(probes[0]); i++) { + DBG(1,"probing %s\n",probes[i].model); len = sizeof(buf); if (!FAILED( status = sanei_hp_scl_upload(scsi, probes[i].cmd, buf, sizeof(buf)) )) *************** *** 113,124 **** return SANE_STATUS_INVAL; /* Can't open device */ } ! if (sanei_hp_scsi_inq(scsi)[0] != 0x03 ! || memcmp(sanei_hp_scsi_vendor(scsi), "HP ", 8) != 0) { ! DBG(1, "%s: does not seem to be an HP scanner\n", devname); ! sanei_hp_scsi_destroy(scsi); ! return SANE_STATUS_INVAL; } /* reset scanner; returns all parameters to defaults */ --- 117,131 ---- return SANE_STATUS_INVAL; /* Can't open device */ } ! if (!sanei_hp_orig(scsi)) { ! if (sanei_hp_scsi_inq(scsi)[0] != 0x03 ! || memcmp(sanei_hp_scsi_vendor(scsi), "HP ", 8) != 0) ! { ! DBG(1, "%s: does not seem to be an HP scanner\n", devname); ! sanei_hp_scsi_destroy(scsi); ! return SANE_STATUS_INVAL; ! } } /* reset scanner; returns all parameters to defaults */ diff -crN current/sane-pre1.00/backend/hp-device.h sane-pre1.00/backend/hp-device.h *** current/sane-pre1.00/backend/hp-device.h Wed Oct 28 07:05:54 1998 --- sane-pre1.00/backend/hp-device.h Wed Nov 11 20:53:15 1998 *************** *** 56,61 **** --- 56,62 ---- HP_COMPAT_4P = 1 << 5, HP_COMPAT_5P = 1 << 6, HP_COMPAT_PS = 1 << 7 /* Hp PhotoSmart Photo Scanner */ + /*HP_COMPAT_PLUS = 1 << 8*/ }; struct hp_device_s diff -crN current/sane-pre1.00/backend/hp-orig.c sane-pre1.00/backend/hp-orig.c *** current/sane-pre1.00/backend/hp-orig.c Thu Jan 1 01:00:00 1970 --- sane-pre1.00/backend/hp-orig.c Wed Nov 11 20:15:55 1998 *************** *** 0 **** --- 1,155 ---- + /* sane - Scanner Access Now Easy. + Copyright (C) 1997 David Mosberger-Tang + Copyright (C) 1998 Christer Weinigel <wingel@ctrl-c.liu.se> + Copyright (C) 1998 James Carter <james@cs.york.ac.uk> + This file is part of the SANE package. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA. + + As a special exception, the authors of SANE give permission for + additional uses of the libraries contained in this release of SANE. + + The exception is that, if you link a SANE library with other files + to produce an executable, this does not by itself cause the + resulting executable to be covered by the GNU General Public + License. Your use of that executable is in no way restricted on + account of linking the SANE library code into it. + + This exception does not, however, invalidate any other reasons why + the executable file might be covered by the GNU General Public + License. + + If you submit changes to SANE to the maintainers to be included in + a subsequent release, you agree by submitting the changes that + those changes may be distributed with this exception intact. + + If you write modifications of your own for SANE, it is your choice + whether to permit this exception to apply to your modifications. + If you do not wish that, delete this exception notice. + + This file is part of a SANE backend for HP Scanners using the + HP Scanner Control Language (SCL). + */ + + #include <sane/config.h> + #include <lalloca.h> /* Must be first */ + + #ifdef HAVE_UNISTD_H + # include <unistd.h> + #endif + #include <ctype.h> + #include <string.h> + #include <ctype.h> + #include <errno.h> + #include <fcntl.h> + #include <assert.h> + #include <signal.h> + #include <unistd.h> + #include <sane/sanei_scsi.h> + + #include "hp.h" + + #include <sane/sanei_backend.h> + + #include "hp-option.h" + #include "hp-scsi.h" + #include "hp-scl.h" + + SANE_Status + sanei_hp_orig_open (const char *dev, int *fdp) + { + int fd; + + fd = open (dev, O_RDWR | O_EXCL); + if (fd < 0) + { + SANE_Status status = SANE_STATUS_INVAL; + + if (errno == EACCES) + status = SANE_STATUS_ACCESS_DENIED; + + DBG (1, "sanei_hp_orig_open: open of `%s' failed: %s\n", + dev, strerror (errno)); + return status; + } + if (fdp) + *fdp = fd; + + return SANE_STATUS_GOOD; + } + + void + sanei_hp_orig_close (int fd) + { + close(fd); + } + + static SANE_Status + read_data (int fd, u_char * dest, size_t *len) + { + size_t n; + + if ((n = read (fd, dest, *len)) == 0) + { + return SANE_STATUS_EOF; + } + else + { + if (n < 0) + { + return SANE_STATUS_IO_ERROR; + } + } + *len = n; + return SANE_STATUS_GOOD; + } + + static SANE_Status + write_data (int fd, void *data, size_t len) + { + size_t n; + + if ((n = write (fd, data, len)) == 0) + { + return SANE_STATUS_EOF; + } + else + { + if (n < 0) + { + return SANE_STATUS_IO_ERROR; + } + } + return SANE_STATUS_GOOD; + } + + SANE_Status + sanei_hp_orig_cmd (int fd, const void *src, size_t src_size, void *dst, + size_t * dst_size) + { + if (dst_size && *dst_size) + { + DBG (1, "sanei_hp_orig_cmd: read\n"); + return read_data(fd, dst, dst_size); + } + else + { + DBG (1, "sanei_hp_orig_cmd: write\n"); + return write_data(fd, src, src_size); + } + } + + diff -crN current/sane-pre1.00/backend/hp-orig.h sane-pre1.00/backend/hp-orig.h *** current/sane-pre1.00/backend/hp-orig.h Thu Jan 1 01:00:00 1970 --- sane-pre1.00/backend/hp-orig.h Wed Nov 11 20:16:21 1998 *************** *** 0 **** --- 1,55 ---- + /* sane - Scanner Access Now Easy. + Copyright (C) 1997 David Mosberger-Tang + Copyright (C) 1998 James Carter <james@cs.york.ac.uk> + This file is part of the SANE package. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA. + + As a special exception, the authors of SANE give permission for + additional uses of the libraries contained in this release of SANE. + + The exception is that, if you link a SANE library with other files + to produce an executable, this does not by itself cause the + resulting executable to be covered by the GNU General Public + License. Your use of that executable is in no way restricted on + account of linking the SANE library code into it. + + This exception does not, however, invalidate any other reasons why + the executable file might be covered by the GNU General Public + License. + + If you submit changes to SANE to the maintainers to be included in + a subsequent release, you agree by submitting the changes that + those changes may be distributed with this exception intact. + + If you write modifications of your own for SANE, it is your choice + whether to permit this exception to apply to your modifications. + If you do not wish that, delete this exception notice. + + This file is part of a SANE backend for HP Scanners supporting + HP Scanner Control Language (SCL). + */ + + #ifndef HP_ORIG_INCLUDED + #define HP_ORIG_INCLUDED + + SANE_Status sanei_hp_orig_open (const char *dev, int *fdp); + void sanei_hp_orig_close (int fd); + char sanei_hp_orig (HpScsi p); + SANE_Status sanei_hp_orig_cmd (int fd, const void *src, size_t src_size, + void *dst, size_t * dst_size); + + #endif /* HP_ORIG_INCLUDED */ diff -crN current/sane-pre1.00/backend/hp-scl.c sane-pre1.00/backend/hp-scl.c *** current/sane-pre1.00/backend/hp-scl.c Thu Oct 29 06:54:13 1998 --- sane-pre1.00/backend/hp-scl.c Wed Nov 11 19:51:07 1998 *************** *** 62,67 **** --- 62,68 ---- #include "hp-option.h" #include "hp-scsi.h" #include "hp-scl.h" + #include "hp-orig.h" #if (defined(__IBMC__) || defined(__IBMCPP__)) #ifndef _AIX *************** *** 74,80 **** #define HP_SCSI_BUFSIZ (HP_SCSI_MAX_WRITE + HP_SCSI_CMD_LEN) - /* * */ --- 75,80 ---- *************** *** 84,89 **** --- 84,92 ---- int fd; char * devname; + /* hporig flag */ + char hporig; + /* Output buffering */ hp_byte_t buf[HP_SCSI_BUFSIZ]; hp_byte_t * bufp; *************** *** 93,98 **** --- 96,108 ---- }; + char + sanei_hp_orig (HpScsi p) + { + return p->hporig; + } + + SANE_Status sanei_hp_scsi_new (HpScsi * newp, const char * devname) { *************** *** 105,136 **** if (!new) return SANE_STATUS_NO_MEM; ! status = sanei_scsi_open(devname, &new->fd, 0, 0); ! if (FAILED(status)) { ! DBG(1, "scsi_new: open failed (%s)\n", sane_strstatus(status)); ! sanei_hp_free(new); ! return SANE_STATUS_IO_ERROR; } - - DBG(3, "scsi_inquire: sending INQUIRE\n"); - status = sanei_scsi_cmd(new->fd, inq_cmd, 6, new->inq_data, &inq_len); if (FAILED(status)) { ! DBG(1, "scsi_inquire: inquiry failed: %s\n", sane_strstatus(status)); ! sanei_scsi_close(new->fd); sanei_hp_free(new); ! return status; } ! DBG(3, "scsi_new: sending TEST_UNIT_READY\n"); ! status = sanei_scsi_cmd(new->fd, tur_cmd, 6, 0, 0); ! if (FAILED(status)) { ! DBG(1, "hp_scsi_open: test unit ready failed (%s)\n", ! sane_strstatus(status)); ! sanei_scsi_close(new->fd); ! sanei_hp_free(new); } new->bufp = new->buf + HP_SCSI_CMD_LEN; --- 115,159 ---- if (!new) return SANE_STATUS_NO_MEM; ! /* there must be a better way - james@cs.york.ac.uk */ ! if (!strcmp(devname,"/dev/hpscan")) { ! status = sanei_hp_orig_open(devname, &new->fd); ! new->hporig = SANE_TRUE; ! } ! else ! { ! status = sanei_scsi_open(devname, &new->fd, 0, 0); ! new->hporig=SANE_FALSE; } if (FAILED(status)) { ! DBG(1, "scsi_new: open failed (%s)\n", sane_strstatus(status)); sanei_hp_free(new); ! return SANE_STATUS_IO_ERROR; } ! if (!new->hporig) { ! DBG(3, "scsi_inquire: sending INQUIRE\n"); ! status = sanei_scsi_cmd(new->fd, inq_cmd, 6, new->inq_data, &inq_len); ! if (FAILED(status)) ! { ! DBG(1, "scsi_inquire: inquiry failed: %s\n", sane_strstatus(status)); ! sanei_scsi_close(new->fd); ! sanei_hp_free(new); ! return status; ! } ! ! DBG(3, "scsi_new: sending TEST_UNIT_READY\n"); ! status = sanei_scsi_cmd(new->fd, tur_cmd, 6, 0, 0); ! if (FAILED(status)) ! { ! DBG(1, "hp_scsi_open: test unit ready failed (%s)\n", ! sane_strstatus(status)); ! sanei_scsi_close(new->fd); ! sanei_hp_free(new); ! } } new->bufp = new->buf + HP_SCSI_CMD_LEN; *************** *** 147,153 **** { assert(this->fd >= 0); DBG(3, "scsi_close: closing fd %d\n", this->fd); ! sanei_scsi_close(this->fd); if ( this->devname ) sanei_hp_free (this->devname); sanei_hp_free(this); } --- 170,176 ---- { assert(this->fd >= 0); DBG(3, "scsi_close: closing fd %d\n", this->fd); ! this->hporig ? sanei_hp_orig_close(this->fd) : sanei_scsi_close(this->fd); if ( this->devname ) sanei_hp_free (this->devname); sanei_hp_free(this); } *************** *** 217,223 **** DBG(10, "scsi_flush: writing %lu bytes:\n", (unsigned long) len); DBGDUMP(10, data, len); ! return sanei_scsi_cmd (this->fd, this->buf, HP_SCSI_CMD_LEN + len, 0, 0); } static inline size_t --- 240,253 ---- DBG(10, "scsi_flush: writing %lu bytes:\n", (unsigned long) len); DBGDUMP(10, data, len); ! if (this->hporig) ! { ! return sanei_hp_orig_cmd (this->fd, data, len, 0, 0); ! } ! else ! { ! return sanei_scsi_cmd (this->fd, this->buf, HP_SCSI_CMD_LEN + len, 0, 0); ! } } static inline size_t *************** *** 309,316 **** read_cmd[3] = *len >> 8; read_cmd[4] = *len; ! RETURN_IF_FAIL( sanei_scsi_cmd (this->fd, read_cmd, ! sizeof(read_cmd), dest, len) ); DBG(10, "scsi_read: %lu bytes:\n", (unsigned long) *len); DBGDUMP(10, dest, *len); return SANE_STATUS_GOOD; --- 339,354 ---- read_cmd[3] = *len >> 8; read_cmd[4] = *len; ! if (this->hporig) ! { ! RETURN_IF_FAIL( sanei_hp_orig_cmd (this->fd, read_cmd, ! sizeof(read_cmd), dest, len) ); ! } ! else ! { ! RETURN_IF_FAIL( sanei_scsi_cmd (this->fd, read_cmd, ! sizeof(read_cmd), dest, len) ); ! } DBG(10, "scsi_read: %lu bytes:\n", (unsigned long) *len); DBGDUMP(10, dest, *len); return SANE_STATUS_GOOD; *************** *** 419,426 **** DBG(3, "do_read: entering request to read %lu bytes\n", (unsigned long) req->len); ! status = sanei_scsi_req_enter(this->fd, req->cmd, 6, ! req->data, &req->len, &req->id); if (status != SANE_STATUS_GOOD) { DBG(1, "do_read: Error from scsi_req_enter: %s\n", --- 457,471 ---- DBG(3, "do_read: entering request to read %lu bytes\n", (unsigned long) req->len); ! if (!this->hporig) ! { ! status = sanei_scsi_req_enter(this->fd, req->cmd, 6, ! req->data, &req->len, &req->id); ! } ! else ! { ! status = sanei_hp_orig_cmd(this->fd, 0, 0, req->data, &req->len); ! } if (status != SANE_STATUS_GOOD) { DBG(1, "do_read: Error from scsi_req_enter: %s\n", *************** *** 437,452 **** assert(reqs_completed < reqs_issued); req = buf + (reqs_completed++ % 2); ! DBG(3, "do_read: waiting for data\n"); ! status = sanei_scsi_req_wait(req->id); ! if (status != SANE_STATUS_GOOD) ! { ! DBG(1, "do_read: Error from scsi_req_wait: %s\n", ! sane_strstatus(status)); ! goto quit; ! } ! if (signal_caught) ! goto quit; if ( mirror ) { --- 482,500 ---- assert(reqs_completed < reqs_issued); req = buf + (reqs_completed++ % 2); ! if (!this->hporig) ! { ! DBG(3, "do_read: waiting for data\n"); ! status = sanei_scsi_req_wait(req->id); ! if (status != SANE_STATUS_GOOD) ! { ! DBG(1, "do_read: Error from scsi_req_wait: %s\n", ! sane_strstatus(status)); ! goto quit; ! } ! if (signal_caught) ! goto quit; ! } if ( mirror ) { diff -crN current/sane-pre1.00/backend/hp-scl.h sane-pre1.00/backend/hp-scl.h *** current/sane-pre1.00/backend/hp-scl.h Wed Oct 28 07:06:39 1998 --- sane-pre1.00/backend/hp-scl.h Wed Nov 11 21:18:21 1998 *************** *** 108,113 **** --- 108,114 ---- #define SCL_HP_MODEL_8 HP_SCL_PARAMETER(15) #define SCL_HP_MODEL_9 HP_SCL_PARAMETER(16) #define SCL_HP_MODEL_10 HP_SCL_PARAMETER(17) + /*#define SCL_HP_MODEL_11 what do i put here?*/ #define SCL_CURRENT_ERROR_STACK HP_SCL_PARAMETER(257) #define SCL_CURRENT_ERROR HP_SCL_PARAMETER(259)
---1876940720-2078917053-910821594=:10009--
-- Source code, list archive, and docs: http://www.mostang.com/sane/ To unsubscribe: echo unsubscribe sane-devel | mail majordomo@mostang.com