epson2 reorganization

Some subroutines have been moved from epson2.c to epson2-ops.c and
there's also a temporary fix for the networking code.
This is work in progress but should work.
merge-requests/1/head
Alessandro Zummo 2009-06-01 16:18:52 +02:00
rodzic 617b7c5be5
commit 728e032a5a
9 zmienionych plików z 2350 dodań i 2252 usunięć

Wyświetl plik

@ -456,7 +456,7 @@ libsane_epson_la_LDFLAGS = $(DIST_SANELIBS_LDFLAGS)
libsane_epson_la_LIBADD = $(COMMON_LIBS) libepson.la ../sanei/sanei_init_debug.lo ../sanei/sanei_constrain_value.lo ../sanei/sanei_config.lo ../sanei/sanei_config2.lo sane_strstatus.lo ../sanei/sanei_usb.lo ../sanei/sanei_scsi.lo ../sanei/sanei_pio.lo $(SCSI_LIBS) $(USB_LIBS)
EXTRA_DIST += epson.conf.in
libepson2_la_SOURCES = epson2.c epson2.h epson2_scsi.c epson2_scsi.h epson_usb.c epson2_net.c epson2_net.h epson2-io.c epson2-io.h epson2-commands.c epson2-commands.h
libepson2_la_SOURCES = epson2.c epson2.h epson2_scsi.c epson2_scsi.h epson_usb.c epson2_net.c epson2_net.h epson2-io.c epson2-io.h epson2-commands.c epson2-commands.h epson2-ops.c epson2-ops.h
libepson2_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=epson2
nodist_libsane_epson2_la_SOURCES = epson2-s.c

Wyświetl plik

@ -132,7 +132,7 @@ libepson2_la_LIBADD =
am_libepson2_la_OBJECTS = libepson2_la-epson2.lo \
libepson2_la-epson2_scsi.lo libepson2_la-epson_usb.lo \
libepson2_la-epson2_net.lo libepson2_la-epson2-io.lo \
libepson2_la-epson2-commands.lo
libepson2_la-epson2-commands.lo libepson2_la-epson2-ops.lo
libepson2_la_OBJECTS = $(am_libepson2_la_OBJECTS)
libfujitsu_la_LIBADD =
am_libfujitsu_la_OBJECTS = libfujitsu_la-fujitsu.lo
@ -1852,7 +1852,7 @@ nodist_libsane_epson_la_SOURCES = epson-s.c
libsane_epson_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=epson
libsane_epson_la_LDFLAGS = $(DIST_SANELIBS_LDFLAGS)
libsane_epson_la_LIBADD = $(COMMON_LIBS) libepson.la ../sanei/sanei_init_debug.lo ../sanei/sanei_constrain_value.lo ../sanei/sanei_config.lo ../sanei/sanei_config2.lo sane_strstatus.lo ../sanei/sanei_usb.lo ../sanei/sanei_scsi.lo ../sanei/sanei_pio.lo $(SCSI_LIBS) $(USB_LIBS)
libepson2_la_SOURCES = epson2.c epson2.h epson2_scsi.c epson2_scsi.h epson_usb.c epson2_net.c epson2_net.h epson2-io.c epson2-io.h epson2-commands.c epson2-commands.h
libepson2_la_SOURCES = epson2.c epson2.h epson2_scsi.c epson2_scsi.h epson_usb.c epson2_net.c epson2_net.h epson2-io.c epson2-io.h epson2-commands.c epson2-commands.h epson2-ops.c epson2-ops.h
libepson2_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=epson2
nodist_libsane_epson2_la_SOURCES = epson2-s.c
libsane_epson2_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=epson2
@ -2676,6 +2676,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libepjitsu_la-epjitsu.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libepson2_la-epson2-commands.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libepson2_la-epson2-io.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libepson2_la-epson2-ops.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libepson2_la-epson2.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libepson2_la-epson2_net.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libepson2_la-epson2_scsi.Plo@am__quote@
@ -3100,6 +3101,13 @@ libepson2_la-epson2-commands.lo: epson2-commands.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libepson2_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libepson2_la-epson2-commands.lo `test -f 'epson2-commands.c' || echo '$(srcdir)/'`epson2-commands.c
libepson2_la-epson2-ops.lo: epson2-ops.c
@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libepson2_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libepson2_la-epson2-ops.lo -MD -MP -MF $(DEPDIR)/libepson2_la-epson2-ops.Tpo -c -o libepson2_la-epson2-ops.lo `test -f 'epson2-ops.c' || echo '$(srcdir)/'`epson2-ops.c
@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/libepson2_la-epson2-ops.Tpo $(DEPDIR)/libepson2_la-epson2-ops.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='epson2-ops.c' object='libepson2_la-epson2-ops.lo' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libepson2_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libepson2_la-epson2-ops.lo `test -f 'epson2-ops.c' || echo '$(srcdir)/'`epson2-ops.c
libfujitsu_la-fujitsu.lo: fujitsu.c
@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libfujitsu_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libfujitsu_la-fujitsu.lo -MD -MP -MF $(DEPDIR)/libfujitsu_la-fujitsu.Tpo -c -o libfujitsu_la-fujitsu.lo `test -f 'fujitsu.c' || echo '$(srcdir)/'`fujitsu.c
@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/libfujitsu_la-fujitsu.Tpo $(DEPDIR)/libfujitsu_la-fujitsu.Plo

Wyświetl plik

@ -17,11 +17,7 @@
#define DEBUG_DECLARE_ONLY
#include "../include/sane/config.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "sane/config.h"
#include <byteorder.h>
@ -335,18 +331,18 @@ esci_request_extended_identity(SANE_Handle handle, unsigned char *buf)
return status;
DBG(1, " command level : %c%c\n", buf[0], buf[1]);
DBG(1, " basic resolution: %lu\n", (u_long) le32atoh(&buf[4]));
DBG(1, " min resolution : %lu\n", (u_long) le32atoh(&buf[8]));
DBG(1, " max resolution : %lu\n", (u_long) le32atoh(&buf[12]));
DBG(1, " max pixel num : %lu\n", (u_long) le32atoh(&buf[16]));
DBG(1, " basic resolution: %lu\n", (unsigned long) le32atoh(&buf[4]));
DBG(1, " min resolution : %lu\n", (unsigned long) le32atoh(&buf[8]));
DBG(1, " max resolution : %lu\n", (unsigned long) le32atoh(&buf[12]));
DBG(1, " max pixel num : %lu\n", (unsigned long) le32atoh(&buf[16]));
DBG(1, " scan area : %lux%lu\n",
(u_long) le32atoh(&buf[20]), (u_long) le32atoh(&buf[24]));
(unsigned long) le32atoh(&buf[20]), (unsigned long) le32atoh(&buf[24]));
DBG(1, " adf area : %lux%lu\n",
(u_long) le32atoh(&buf[28]), (u_long) le32atoh(&buf[32]));
(unsigned long) le32atoh(&buf[28]), (unsigned long) le32atoh(&buf[32]));
DBG(1, " tpu area : %lux%lu\n",
(u_long) le32atoh(&buf[36]), (u_long) le32atoh(&buf[40]));
(unsigned long) le32atoh(&buf[36]), (unsigned long) le32atoh(&buf[40]));
DBG(1, " main status : 0x%02x\n", buf[44]);
DBG(1, " input depth : %d\n", buf[66]);
@ -507,12 +503,12 @@ esci_set_scanning_parameter(SANE_Handle handle, unsigned char *buf)
params[0] = FS;
params[1] = 'W';
DBG(10, "resolution of main scan : %lu\n", (u_long) le32atoh(&buf[0]));
DBG(10, "resolution of sub scan : %lu\n", (u_long) le32atoh(&buf[4]));
DBG(10, "offset length of main scan : %lu\n", (u_long) le32atoh(&buf[8]));
DBG(10, "offset length of sub scan : %lu\n", (u_long) le32atoh(&buf[12]));
DBG(10, "scanning length of main scan: %lu\n", (u_long) le32atoh(&buf[16]));
DBG(10, "scanning length of sub scan : %lu\n", (u_long) le32atoh(&buf[20]));
DBG(10, "resolution of main scan : %lu\n", (unsigned long) le32atoh(&buf[0]));
DBG(10, "resolution of sub scan : %lu\n", (unsigned long) le32atoh(&buf[4]));
DBG(10, "offset length of main scan : %lu\n", (unsigned long) le32atoh(&buf[8]));
DBG(10, "offset length of sub scan : %lu\n", (unsigned long) le32atoh(&buf[12]));
DBG(10, "scanning length of main scan: %lu\n", (unsigned long) le32atoh(&buf[16]));
DBG(10, "scanning length of sub scan : %lu\n", (unsigned long) le32atoh(&buf[20]));
DBG(10, "scanning color : %d\n", buf[24]);
DBG(10, "data format : %d\n", buf[25]);
DBG(10, "option control : %d\n", buf[26]);
@ -804,7 +800,7 @@ esci_request_extended_status(SANE_Handle handle, unsigned char **data,
break;
default:
DBG(1, "%s: unknown reply length (%lu)\n", __func__,
(u_long) buf_len);
(unsigned long) buf_len);
break;
}

Wyświetl plik

@ -17,26 +17,24 @@
#define DEBUG_DECLARE_ONLY
#include "../include/sane/config.h"
#include "sane/config.h"
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <byteorder.h>
#include "epson2.h"
#include "epson2-io.h"
#include "../include/sane/sanei_scsi.h"
#include "../include/sane/sanei_usb.h"
#include "../include/sane/sanei_pio.h"
#include "../include/sane/sanei_tcp.h"
#include "sane/sanei_scsi.h"
#include "sane/sanei_usb.h"
#include "sane/sanei_pio.h"
#include "sane/sanei_tcp.h"
#include "epson2_scsi.h"
#include "epson_usb.h"
#include "epson2_net.h"
#include "byteorder.h"
/* flaming hack to get USB scanners
* working without timeouts under linux
* (cribbed from fujitsu.c)

2111
backend/epson2-ops.c 100644

Plik diff jest za duży Load Diff

Wyświetl plik

@ -0,0 +1,49 @@
/*
* epson2.c - SANE library for Epson scanners.
*
* Based on Kazuhiro Sasayama previous
* Work on epson.[ch] file from the SANE package.
* Please see those files for additional copyrights.
*
* Copyright (C) 2006-07 Tower Technologies
* Author: Alessandro Zummo <a.zummo@towertech.it>
*
* 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, version 2.
*/
/* some defines to make handling the TPU easier */
#define FILM_TYPE_NEGATIVE (1L << 0)
#define FILM_TYPE_SLIDE (1L << 1)
extern int sanei_scsi_max_request_size;
extern int *gamma_params;
extern void e2_dev_init(Epson_Device *dev);
extern SANE_Bool e2_model(Epson_Scanner *s, const char *model);
extern void e2_set_cmd_level(SANE_Handle handle, unsigned char *level);
extern SANE_Status e2_set_model(Epson_Scanner *s, unsigned char *model, size_t len);
extern SANE_Status e2_add_resolution(Epson_Scanner *s, int r);
extern void e2_set_fbf_area(Epson_Scanner *s, int x, int y, int unit);
extern void e2_set_adf_area(struct Epson_Scanner *s, int x, int y, int unit);
extern void e2_set_tpu_area(struct Epson_Scanner *s, int x, int y, int unit);
extern void e2_add_depth(Epson_Device *dev, SANE_Word depth);
extern SANE_Status e2_discover_capabilities(Epson_Scanner *s);
extern SANE_Status e2_set_extended_scanning_parameters(Epson_Scanner *s);
extern SANE_Status e2_set_scanning_parameters(Epson_Scanner *s);
extern void e2_setup_block_mode(Epson_Scanner *s);
extern SANE_Status e2_init_parameters(Epson_Scanner *s);
extern void e2_wait_button(Epson_Scanner *s);
extern SANE_Status e2_check_warm_up(Epson_Scanner *s, SANE_Bool *wup);
extern SANE_Status e2_wait_warm_up(Epson_Scanner *s);
extern SANE_Status e2_check_adf(Epson_Scanner *s);
extern SANE_Status e2_start_std_scan(Epson_Scanner *s);
extern SANE_Status e2_start_ext_scan(Epson_Scanner *s);
extern void e2_scan_finish(Epson_Scanner *s);
extern void e2_copy_image_data(Epson_Scanner *s, SANE_Byte *data, SANE_Int max_length,
SANE_Int *length);
extern SANE_Status e2_ext_sane_read(SANE_Handle handle);
extern SANE_Status e2_block_sane_read(SANE_Handle handle);

Plik diff jest za duży Load Diff

Wyświetl plik

@ -23,7 +23,22 @@
#define DEBUG_NOT_STATIC
#include <sys/ioctl.h>
#ifdef HAVE_STDDEF_H
#include <stddef.h>
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef NEED_SYS_TYPES_H
#include <sys/types.h>
#endif
#include <string.h> /* for memset and memcpy */
#include <stdio.h>
#include "../include/sane/sane.h"
#include "../include/sane/sanei_backend.h"
@ -166,7 +181,7 @@
* scanner with SANE get in touch with me and we can work something out - khk
*/
#define EPSON_LEVEL_DEFAULT EPSON_LEVEL_B3
#define EPSON_LEVEL_DEFAULT EPSON_LEVEL_B3
typedef struct
{
@ -275,7 +290,9 @@ struct Epson_Device
SANE_Bool duplex; /* does the ADF handle duplex scanning */
SANE_Bool focusSupport; /* does this scanner have support for "set focus position" ? */
SANE_Bool color_shuffle; /* does this scanner need color shuffling */
SANE_Int maxDepth; /* max. color depth */
SANE_Word *depth_list;
SANE_Int optical_res; /* optical resolution */
SANE_Int max_line_distance;
@ -334,4 +351,12 @@ struct Epson_Scanner
typedef struct Epson_Scanner Epson_Scanner;
struct mode_param
{
int color;
int flags;
int dropout_mask;
int depth;
};
#endif /* epson2_h */

Wyświetl plik

@ -11,38 +11,22 @@
* published by the Free Software Foundation, version 2.
*/
#include "../include/sane/config.h"
#define DEBUG_DECLARE_ONLY
#undef BACKEND_NAME
#define BACKEND_NAME epson2_net
#include "sane/config.h"
#include "../include/sane/sane.h"
#include "../include/sane/saneopts.h"
#include "../include/sane/sanei_tcp.h"
#include "../include/sane/sanei_config.h"
#include "../include/sane/sanei_backend.h"
#include "sane/sane.h"
#include "sane/saneopts.h"
#include "sane/sanei_tcp.h"
#include "sane/sanei_config.h"
#include "sane/sanei_backend.h"
#include "epson2.h"
#include "epson2_net.h"
#include "byteorder.h"
#include "../include/sane/sanei_debug.h"
#ifdef HAVE_STDDEF_H
#include <stddef.h>
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef NEED_SYS_TYPES_H
#include <sys/types.h>
#endif
#include <string.h> /* for memset and memcpy */
#include <stdio.h>
#include "sane/sanei_debug.h"
int
sanei_epson_net_read_raw(Epson_Scanner *s, unsigned char *buf, size_t wanted,
@ -52,7 +36,6 @@ sanei_epson_net_read_raw(Epson_Scanner *s, unsigned char *buf, size_t wanted,
*status = SANE_STATUS_GOOD;
while (read < wanted) {
size = sanei_tcp_read(s->fd, buf + read, wanted - read);
@ -77,7 +60,7 @@ sanei_epson_net_read(Epson_Scanner *s, unsigned char *buf, size_t wanted,
/* read from buffer, if available */
if (s->netptr != s->netbuf) {
DBG(4, "reading %lu from buffer at %p, %lu available\n",
DBG(15, "reading %lu from buffer at %p, %lu available\n",
(u_long) wanted, s->netptr, (u_long) s->netlen);
memcpy(buf, s->netptr, wanted);
@ -86,7 +69,7 @@ sanei_epson_net_read(Epson_Scanner *s, unsigned char *buf, size_t wanted,
s->netlen -= wanted;
if (s->netlen == 0) {
DBG(4, "%s: freeing %p\n", __func__, s->netbuf);
DBG(15, "%s: freeing %p\n", __func__, s->netbuf);
free(s->netbuf);
s->netbuf = s->netptr = NULL;
s->netlen = 0;
@ -103,24 +86,28 @@ sanei_epson_net_read(Epson_Scanner *s, unsigned char *buf, size_t wanted,
*status = SANE_STATUS_IO_ERROR;
return 0;
}
size = be32atoh(&header[6]);
DBG(4, "%s: wanted = %lu, available = %lu\n", __FUNCTION__,
DBG(15, "%s: wanted = %lu, available = %lu\n", __FUNCTION__,
(u_long) wanted, (u_long) size);
*status = SANE_STATUS_GOOD;
if (size == wanted) {
DBG(4, "%s: full read\n", __func__);
read = sanei_tcp_read(s->fd, buf, size);
DBG(15, "%s: full read\n", __func__);
/* read = sanei_tcp_read(s->fd, buf, size); */
read = recv(s->fd, buf, size, MSG_WAITALL); /* XXX temporary */
if (s->netbuf) {
free(s->netbuf);
s->netbuf = NULL;
s->netlen = 0;
}
} else if (wanted < size && s->netlen == size) {
DBG(4, "%s: partial read\n", __func__);
DBG(15, "%s: partial read\n", __func__);
sanei_tcp_read(s->fd, s->netbuf, size);
@ -128,8 +115,8 @@ sanei_epson_net_read(Epson_Scanner *s, unsigned char *buf, size_t wanted,
s->netptr += wanted;
read = wanted;
DBG(4, "0,4 %02x %02x\n", s->netbuf[0], s->netbuf[4]);
DBG(4, "storing %lu to buffer at %p, next read at %p, %lu bytes left\n",
DBG(15, "0,4 %02x %02x\n", s->netbuf[0], s->netbuf[4]);
DBG(15, "storing %lu to buffer at %p, next read at %p, %lu bytes left\n",
(u_long) size, s->netbuf, s->netptr, (u_long) s->netlen);
memcpy(buf, s->netbuf, wanted);
@ -155,11 +142,11 @@ sanei_epson_net_write(Epson_Scanner *s, unsigned int cmd, const unsigned char *b
if (reply_len) {
s->netbuf = s->netptr = malloc(reply_len);
s->netlen = reply_len;
DBG(8, "allocated %lu bytes at %p\n",
DBG(24, "allocated %lu bytes at %p\n",
(u_long) reply_len, s->netbuf);
}
DBG(2, "%s: cmd = %04x, buf = %p, buf_size = %lu, reply_len = %lu\n",
DBG(24, "%s: cmd = %04x, buf = %p, buf_size = %lu, reply_len = %lu\n",
__FUNCTION__, cmd, buf, (u_long) buf_size, (u_long) reply_len);
memset(h1, 0x00, 12);
@ -174,7 +161,7 @@ sanei_epson_net_write(Epson_Scanner *s, unsigned int cmd, const unsigned char *b
h1[4] = 0x00;
h1[5] = 0x0C; /* Don't know what's that */
DBG(9, "H1[0]: %02x %02x %02x %02x\n", h1[0], h1[1], h1[2], h1[3]);
DBG(24, "H1[0]: %02x %02x %02x %02x\n", h1[0], h1[1], h1[2], h1[3]);
if((cmd >> 8) == 0x20) {
htobe32a(&h1[6], buf_size + 8);
@ -182,9 +169,9 @@ sanei_epson_net_write(Epson_Scanner *s, unsigned int cmd, const unsigned char *b
htobe32a(&h2[0], buf_size);
htobe32a(&h2[4], reply_len);
DBG(9, "H1[6]: %02x %02x %02x %02x (%lu)\n", h1[6], h1[7], h1[8], h1[9], (u_long) (buf_size + 8));
DBG(9, "H2[0]: %02x %02x %02x %02x (%lu)\n", h2[0], h2[1], h2[2], h2[3], (u_long) buf_size);
DBG(9, "H2[4]: %02x %02x %02x %02x (%lu)\n", h2[4], h2[5], h2[6], h2[7], (u_long) reply_len);
DBG(24, "H1[6]: %02x %02x %02x %02x (%lu)\n", h1[6], h1[7], h1[8], h1[9], (u_long) (buf_size + 8));
DBG(24, "H2[0]: %02x %02x %02x %02x (%lu)\n", h2[0], h2[1], h2[2], h2[3], (u_long) buf_size);
DBG(24, "H2[4]: %02x %02x %02x %02x (%lu)\n", h2[4], h2[5], h2[6], h2[7], (u_long) reply_len);
}
if ((cmd >> 8) == 0x20 && (buf_size || reply_len)) {