kopia lustrzana https://gitlab.com/sane-project/backends
genesys: Return errors as exceptions from *bulk_read_data()
rodzic
7d1617e4c0
commit
a79f1404f3
|
@ -4120,20 +4120,14 @@ void Genesys_Buffer::consume(size_t size)
|
|||
static SANE_Status accurate_line_read(Genesys_Device * dev,
|
||||
Genesys_Buffer& buffer)
|
||||
{
|
||||
DBG_HELPER(dbg);
|
||||
buffer.reset();
|
||||
|
||||
SANE_Status status = SANE_STATUS_GOOD;
|
||||
status = dev->model->cmd_set->bulk_read_data(dev, 0x45, buffer.get_write_pos(buffer.size()),
|
||||
buffer.size());
|
||||
if (status != SANE_STATUS_GOOD)
|
||||
{
|
||||
DBG(DBG_error, "%s: failed to read %lu bytes (%s)\n", __func__, (u_long) buffer.size(),
|
||||
sane_strstatus(status));
|
||||
return SANE_STATUS_IO_ERROR;
|
||||
}
|
||||
dev->model->cmd_set->bulk_read_data(dev, 0x45, buffer.get_write_pos(buffer.size()),
|
||||
buffer.size());
|
||||
|
||||
buffer.produce(buffer.size());
|
||||
return status;
|
||||
return SANE_STATUS_GOOD;
|
||||
}
|
||||
|
||||
/** @brief fill buffer while reducing vertical resolution
|
||||
|
@ -4306,13 +4300,12 @@ genesys_fill_segmented_buffer (Genesys_Device * dev, uint8_t *work_buffer_dst, s
|
|||
static SANE_Status
|
||||
genesys_fill_read_buffer (Genesys_Device * dev)
|
||||
{
|
||||
DBG_HELPER(dbg);
|
||||
size_t size;
|
||||
size_t space;
|
||||
SANE_Status status = SANE_STATUS_GOOD;
|
||||
uint8_t *work_buffer_dst;
|
||||
|
||||
DBGSTART;
|
||||
|
||||
/* for sheetfed scanner, we must check is document is shorter than
|
||||
* the requested scan */
|
||||
if (dev->model->is_sheetfed == SANE_TRUE)
|
||||
|
@ -4365,21 +4358,27 @@ genesys_fill_read_buffer (Genesys_Device * dev)
|
|||
{
|
||||
/* line interpolation */
|
||||
status = genesys_fill_line_interp_buffer (dev, work_buffer_dst, size);
|
||||
if (status != SANE_STATUS_GOOD)
|
||||
{
|
||||
DBG(DBG_error, "%s: failed to read %lu bytes (%s)\n", __func__, (u_long) size,
|
||||
sane_strstatus(status));
|
||||
return SANE_STATUS_IO_ERROR;
|
||||
}
|
||||
}
|
||||
else if (dev->segnb>1)
|
||||
{
|
||||
/* multi-segment sensors processing */
|
||||
status = genesys_fill_segmented_buffer (dev, work_buffer_dst, size);
|
||||
if (status != SANE_STATUS_GOOD)
|
||||
{
|
||||
DBG(DBG_error, "%s: failed to read %lu bytes (%s)\n", __func__, (u_long) size,
|
||||
sane_strstatus(status));
|
||||
return SANE_STATUS_IO_ERROR;
|
||||
}
|
||||
}
|
||||
else /* regular case with no extra copy */
|
||||
{
|
||||
status = dev->model->cmd_set->bulk_read_data (dev, 0x45, work_buffer_dst, size);
|
||||
}
|
||||
if (status != SANE_STATUS_GOOD)
|
||||
{
|
||||
DBG(DBG_error, "%s: failed to read %lu bytes (%s)\n", __func__, (u_long) size,
|
||||
sane_strstatus(status));
|
||||
return SANE_STATUS_IO_ERROR;
|
||||
dev->model->cmd_set->bulk_read_data(dev, 0x45, work_buffer_dst, size);
|
||||
}
|
||||
|
||||
if (size > dev->read_bytes_left)
|
||||
|
@ -4389,8 +4388,6 @@ genesys_fill_read_buffer (Genesys_Device * dev)
|
|||
|
||||
dev->read_buffer.produce(size);
|
||||
|
||||
DBGCOMPLETED;
|
||||
|
||||
return SANE_STATUS_GOOD;
|
||||
}
|
||||
|
||||
|
|
|
@ -82,18 +82,13 @@ static void gl646_gpio_output_enable(UsbDevice& usb_dev, uint8_t value)
|
|||
}
|
||||
|
||||
/* Read bulk data (e.g. scanned data) */
|
||||
static SANE_Status
|
||||
gl646_bulk_read_data (Genesys_Device * dev, uint8_t addr,
|
||||
uint8_t * data, size_t len)
|
||||
static void gl646_bulk_read_data(Genesys_Device* dev, uint8_t addr, uint8_t* data, size_t len)
|
||||
{
|
||||
SANE_Status status = sanei_genesys_bulk_read_data(dev, addr, data, len);
|
||||
if (status != SANE_STATUS_GOOD) {
|
||||
return status;
|
||||
}
|
||||
DBG_HELPER(dbg);
|
||||
sanei_genesys_bulk_read_data(dev, addr, data, len);
|
||||
if (dev->model->is_sheetfed == SANE_TRUE) {
|
||||
gl646_detect_document_end (dev);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
static SANE_Bool
|
||||
|
@ -1039,13 +1034,12 @@ gl646_setup_sensor (Genesys_Device * dev, const Genesys_Sensor& sensor, Genesys_
|
|||
static SANE_Status
|
||||
gl646_asic_test (Genesys_Device * dev)
|
||||
{
|
||||
DBG_HELPER(dbg);
|
||||
SANE_Status status = SANE_STATUS_GOOD;
|
||||
uint8_t val;
|
||||
size_t size, verify_size;
|
||||
unsigned int i;
|
||||
|
||||
DBG(DBG_proc, "%s: start\n", __func__);
|
||||
|
||||
/* set and read exposure time, compare if it's the same */
|
||||
status = sanei_genesys_write_register (dev, 0x38, 0xde);
|
||||
if (status != SANE_STATUS_GOOD)
|
||||
|
@ -1122,13 +1116,7 @@ gl646_asic_test (Genesys_Device * dev)
|
|||
return status;
|
||||
}
|
||||
|
||||
status =
|
||||
gl646_bulk_read_data (dev, 0x45, verify_data.data(), verify_size);
|
||||
if (status != SANE_STATUS_GOOD)
|
||||
{
|
||||
DBG(DBG_error, "%s: failed to bulk read data: %s\n", __func__, sane_strstatus(status));
|
||||
return status;
|
||||
}
|
||||
gl646_bulk_read_data(dev, 0x45, verify_data.data(), verify_size);
|
||||
|
||||
/* i + 2 is needed as the changed address goes into effect only after one
|
||||
data word is sent. */
|
||||
|
@ -1141,8 +1129,6 @@ gl646_asic_test (Genesys_Device * dev)
|
|||
}
|
||||
}
|
||||
|
||||
DBG(DBG_info, "%s: end\n", __func__);
|
||||
|
||||
return SANE_STATUS_GOOD;
|
||||
}
|
||||
|
||||
|
@ -3917,15 +3903,15 @@ gl646_repark_head (Genesys_Device * dev)
|
|||
static SANE_Status
|
||||
gl646_init (Genesys_Device * dev)
|
||||
{
|
||||
DBG_INIT();
|
||||
DBG_HELPER(dbg);
|
||||
|
||||
SANE_Status status = SANE_STATUS_GOOD;
|
||||
struct timeval tv;
|
||||
uint8_t cold = 0, val = 0;
|
||||
uint32_t addr = 0xdead;
|
||||
size_t len;
|
||||
|
||||
DBG_INIT ();
|
||||
DBG(DBG_proc, "%s: start\n", __func__);
|
||||
|
||||
/* to detect real power up condition, we write to REG41
|
||||
* with pwrbit set, then read it back. When scanner is cold (just replugged)
|
||||
* PWRBIT will be set in the returned value
|
||||
|
@ -4046,26 +4032,16 @@ gl646_init (Genesys_Device * dev)
|
|||
}
|
||||
sanei_usb_set_timeout (2 * 1000);
|
||||
len = 6;
|
||||
status = gl646_bulk_read_data (dev, 0x45, dev->control, len);
|
||||
/* for some reason, read fails here for MD6471, HP2300 and XP200
|
||||
* one time out of 2 scanimage launches
|
||||
*/
|
||||
if (status != SANE_STATUS_GOOD)
|
||||
{
|
||||
DBG(DBG_warn, "%s: failed to read control\n", __func__);
|
||||
status = gl646_bulk_read_data (dev, 0x45, dev->control, len);
|
||||
}
|
||||
if (status != SANE_STATUS_GOOD)
|
||||
{
|
||||
DBG(DBG_warn, "%s: failed to read control\n", __func__);
|
||||
return SANE_STATUS_INVAL;
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG(DBG_info, "%s: control read=0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n", __func__,
|
||||
dev->control[0], dev->control[1], dev->control[2], dev->control[3], dev->control[4],
|
||||
dev->control[5]);
|
||||
}
|
||||
// for some reason, read fails here for MD6471, HP2300 and XP200 one time out of
|
||||
// 2 scanimage launches
|
||||
try {
|
||||
gl646_bulk_read_data(dev, 0x45, dev->control, len);
|
||||
} catch (...) {
|
||||
gl646_bulk_read_data(dev, 0x45, dev->control, len);
|
||||
}
|
||||
DBG(DBG_info, "%s: control read=0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n", __func__,
|
||||
dev->control[0], dev->control[1], dev->control[2], dev->control[3], dev->control[4],
|
||||
dev->control[5]);
|
||||
sanei_usb_set_timeout (30 * 1000);
|
||||
}
|
||||
else
|
||||
|
@ -4108,7 +4084,6 @@ gl646_init (Genesys_Device * dev)
|
|||
/* here session and device are initialized */
|
||||
dev->already_initialized = SANE_TRUE;
|
||||
|
||||
DBG(DBG_proc, "%s: end\n", __func__);
|
||||
return SANE_STATUS_GOOD;
|
||||
}
|
||||
|
||||
|
|
|
@ -308,13 +308,13 @@ static void sanei_gl841_setup_sensor(Genesys_Device * dev, const Genesys_Sensor&
|
|||
static SANE_Status
|
||||
sanei_gl841_asic_test (Genesys_Device * dev)
|
||||
{
|
||||
DBG_HELPER(dbg);
|
||||
|
||||
SANE_Status status = SANE_STATUS_GOOD;
|
||||
uint8_t val;
|
||||
size_t size, verify_size;
|
||||
unsigned int i;
|
||||
|
||||
DBG(DBG_proc, "%s\n", __func__);
|
||||
|
||||
return SANE_STATUS_INVAL;
|
||||
|
||||
/* set and read exposure time, compare if it's the same */
|
||||
|
@ -395,12 +395,7 @@ sanei_gl841_asic_test (Genesys_Device * dev)
|
|||
return status;
|
||||
}
|
||||
|
||||
status = sanei_genesys_bulk_read_data(dev, 0x45, verify_data.data(), verify_size);
|
||||
if (status != SANE_STATUS_GOOD)
|
||||
{
|
||||
DBG(DBG_error, "%s: failed to bulk read data: %s\n", __func__, sane_strstatus(status));
|
||||
return status;
|
||||
}
|
||||
sanei_genesys_bulk_read_data(dev, 0x45, verify_data.data(), verify_size);
|
||||
|
||||
/* todo: why i + 2 ? */
|
||||
for (i = 0; i < size; i++)
|
||||
|
@ -422,8 +417,6 @@ sanei_gl841_asic_test (Genesys_Device * dev)
|
|||
}
|
||||
}
|
||||
|
||||
DBG(DBG_info, "%s: completed\n", __func__);
|
||||
|
||||
return SANE_STATUS_GOOD;
|
||||
}
|
||||
|
||||
|
|
|
@ -254,8 +254,8 @@ void sanei_genesys_bulk_read_data_send_header(Genesys_Device* dev, size_t len)
|
|||
sizeof(outdata), outdata);
|
||||
}
|
||||
|
||||
SANE_Status sanei_genesys_bulk_read_data(Genesys_Device * dev, uint8_t addr, uint8_t* data,
|
||||
size_t len)
|
||||
void sanei_genesys_bulk_read_data(Genesys_Device * dev, uint8_t addr, uint8_t* data,
|
||||
size_t len)
|
||||
{
|
||||
DBG_HELPER(dbg);
|
||||
|
||||
|
@ -280,7 +280,7 @@ SANE_Status sanei_genesys_bulk_read_data(Genesys_Device * dev, uint8_t addr, uin
|
|||
}
|
||||
|
||||
if (len == 0)
|
||||
return SANE_STATUS_GOOD;
|
||||
return;
|
||||
|
||||
if (is_addr_used) {
|
||||
dev->usb_dev.control_msg(REQUEST_TYPE_OUT, REQUEST_REGISTER, VALUE_SET_REGISTER, 0x00,
|
||||
|
@ -322,8 +322,6 @@ SANE_Status sanei_genesys_bulk_read_data(Genesys_Device * dev, uint8_t addr, uin
|
|||
if (DBG_LEVEL >= DBG_data && dev->binary!=NULL) {
|
||||
fwrite(buffer, len, 1, dev->binary);
|
||||
}
|
||||
|
||||
return SANE_STATUS_GOOD;
|
||||
}
|
||||
|
||||
SANE_Status sanei_genesys_bulk_write_data(Genesys_Device * dev, uint8_t addr, uint8_t* data,
|
||||
|
@ -905,12 +903,11 @@ SANE_Status
|
|||
sanei_genesys_read_data_from_scanner (Genesys_Device * dev, uint8_t * data,
|
||||
size_t size)
|
||||
{
|
||||
DBG_HELPER_ARGS(dbg, "(size = %lu bytes)", (u_long) size);
|
||||
SANE_Status status = SANE_STATUS_GOOD;
|
||||
int time_count = 0;
|
||||
unsigned int words = 0;
|
||||
|
||||
DBG(DBG_proc, "%s (size = %lu bytes)\n", __func__, (u_long) size);
|
||||
|
||||
if (size & 1)
|
||||
DBG(DBG_info, "WARNING %s: odd number of bytes\n", __func__);
|
||||
|
||||
|
@ -938,14 +935,8 @@ sanei_genesys_read_data_from_scanner (Genesys_Device * dev, uint8_t * data,
|
|||
return SANE_STATUS_IO_ERROR;
|
||||
}
|
||||
|
||||
status = dev->model->cmd_set->bulk_read_data (dev, 0x45, data, size);
|
||||
if (status != SANE_STATUS_GOOD)
|
||||
{
|
||||
DBG(DBG_error, "%s: reading bulk data failed: %s\n", __func__, sane_strstatus(status));
|
||||
return status;
|
||||
}
|
||||
dev->model->cmd_set->bulk_read_data(dev, 0x45, data, size);
|
||||
|
||||
DBG(DBG_proc, "%s: completed\n", __func__);
|
||||
return SANE_STATUS_GOOD;
|
||||
}
|
||||
SANE_Status
|
||||
|
|
|
@ -1097,8 +1097,7 @@ typedef struct Genesys_Command_Set
|
|||
SANE_Status (*bulk_write_data) (Genesys_Device * dev, uint8_t addr,
|
||||
uint8_t * data, size_t len);
|
||||
|
||||
SANE_Status (*bulk_read_data) (Genesys_Device * dev, uint8_t addr,
|
||||
uint8_t * data, size_t len);
|
||||
void (*bulk_read_data) (Genesys_Device * dev, uint8_t addr, uint8_t * data, size_t len);
|
||||
|
||||
// Updates hardware sensor information in Genesys_Scanner.val[].
|
||||
SANE_Status (*update_hardware_sensors) (struct Genesys_Scanner * s);
|
||||
|
@ -1737,8 +1736,8 @@ extern SANE_Status sanei_genesys_write_0x8c (Genesys_Device * dev, uint8_t index
|
|||
|
||||
extern unsigned sanei_genesys_get_bulk_max_size(Genesys_Device * dev);
|
||||
|
||||
extern SANE_Status sanei_genesys_bulk_read_data(Genesys_Device * dev, uint8_t addr, uint8_t* data,
|
||||
size_t len);
|
||||
extern void sanei_genesys_bulk_read_data(Genesys_Device * dev, uint8_t addr, uint8_t* data,
|
||||
size_t len);
|
||||
|
||||
extern SANE_Status sanei_genesys_bulk_write_data(Genesys_Device * dev, uint8_t addr, uint8_t* data,
|
||||
size_t len);
|
||||
|
|
Ładowanie…
Reference in New Issue