static int read_image_block (pixma_t * s, uint8_t * data, unsigned size) { int error; unsigned maxchunksize, chunksize, count = 0; maxchunksize = MAX_CHUNK_SIZE * ((s->cfg->pid == MF3010_PID || s->cfg->pid == MF4410_PID || s->cfg->pid == MF4770_PID || s->cfg->pid == MF4550_PID || s->cfg->pid == MF4600_PID || s->cfg->pid == MF6500_PID || s->cfg->pid == MF8030_PID) ? 4 : 1); while (size) { if (size >= maxchunksize) chunksize = maxchunksize; else if (size < MIN_CHUNK_SIZE) chunksize = size; else chunksize = size - (size % MIN_CHUNK_SIZE); error = pixma_read (s->io, data, chunksize); if (error < 0) return count; count += error; data += error; size -= error; } return count; }
static int read_image_block (pixma_t * s, uint8_t * data, unsigned size) { iclass_t *mf = (iclass_t *) s->subdriver; int error; unsigned maxchunksize, chunksize, count = 0; maxchunksize = MAX_CHUNK_SIZE * ((mf->generation >= 2 || s->cfg->pid == MF4600_PID || s->cfg->pid == MF6500_PID || s->cfg->pid == MF8030_PID) ? 4 : 1); while (size) { if (size >= maxchunksize) chunksize = maxchunksize; else if (size < MIN_CHUNK_SIZE) chunksize = size; else chunksize = size - (size % MIN_CHUNK_SIZE); error = pixma_read (s->io, data, chunksize); if (error < 0) return count; count += error; data += error; size -= error; } return count; }
static int read_image_block (pixma_t * s, uint8_t * data) { int count, temp; count = pixma_read (s->io, data, IMAGE_BLOCK_SIZE); if (count < 0) return count; if (count == IMAGE_BLOCK_SIZE) { int error = pixma_read (s->io, &temp, 0); if (error < 0) { PDBG (pixma_dbg (1, "WARNING: reading zero-length packet failed %d\n", error)); } } return count; }
static void workaround_first_command (pixma_t * s) { /* FIXME: Send a dummy command because the device doesn't response to the first command that is sent directly after the USB interface has been set up. Why? USB isn't set up properly? */ uint8_t cmd[10]; int error; if (s->cfg->pid == MP750_PID) return; /* MP750 doesn't have this problem(?) */ PDBG (pixma_dbg (1, "Work-around for the problem: device doesn't response to the first command.\n")); memset (cmd, 0, sizeof (cmd)); pixma_set_be16 (cmd_calibrate, cmd); error = pixma_write (s->io, cmd, 10); if (error != 10) { if (error < 0) { PDBG (pixma_dbg (1, " Sending a dummy command failed: %s\n", pixma_strerror (error))); } else { PDBG (pixma_dbg (1, " Sending a dummy command failed: count = %d\n", error)); } return; } error = pixma_read (s->io, cmd, sizeof (cmd)); if (error >= 0) { PDBG (pixma_dbg (1, " Got %d bytes response from a dummy command.\n", error)); } else { PDBG (pixma_dbg (1, " Reading response of a dummy command failed: %s\n", pixma_strerror (error))); } }
static int read_image_block (pixma_t * s, uint8_t * header, uint8_t * data) { static const uint8_t cmd[10] = /* 0xd420 cmd */ { 0xd4, 0x20, 0, 0, 0, 0, 0, IMAGE_BLOCK_SIZE / 256, 4, 0 }; mp730_t *mp = (mp730_t *) s->subdriver; const int hlen = 2 + 4; int error, datalen; mp->state = state_transfering; mp->cb.reslen = pixma_cmd_transaction (s, cmd, sizeof (cmd), mp->cb.buf, 512); datalen = mp->cb.reslen; if (datalen < 0) return datalen; memcpy (header, mp->cb.buf, hlen); if (datalen >= hlen) { datalen -= hlen; memcpy (data, mp->cb.buf + hlen, datalen); data += datalen; if (mp->cb.reslen == 512) { error = pixma_read (s->io, data, IMAGE_BLOCK_SIZE - 512 + hlen); if (error < 0) return error; datalen += error; } } mp->state = state_scanning; mp->cb.expected_reslen = 0; error = pixma_check_result (&mp->cb); if (error < 0) return error; if (mp->cb.reslen < hlen) return PIXMA_EPROTO; return datalen; }
static void drain_bulk_in (pixma_t * s) { mp730_t *mp = (mp730_t *) s->subdriver; while (pixma_read (s->io, mp->imgbuf, IMAGE_BLOCK_SIZE) >= 0); }