common: Introduce a common USB connection object, and use it!

This commit is contained in:
Solomon Peachy 2020-08-11 20:27:26 -04:00
parent 1bd14cff80
commit 322ad8d7b7
22 changed files with 518 additions and 692 deletions

View File

@ -542,10 +542,7 @@ struct canonselphy_printjob {
};
struct canonselphy_ctx {
struct libusb_device_handle *dev;
uint8_t endp_up;
uint8_t endp_down;
int type;
struct dyesub_connection *conn;
struct printer_data *printer;
struct marker marker;
@ -559,12 +556,12 @@ static int canonselphy_get_status(struct canonselphy_ctx *ctx)
int ret, num;
/* Read in the printer status, twice. */
ret = read_data(ctx->dev, ctx->endp_up,
ret = read_data(ctx->conn,
(uint8_t*) rdbuf, READBACK_LEN, &num);
if (ret < 0)
return CUPS_BACKEND_FAILED;
ret = read_data(ctx->dev, ctx->endp_up,
ret = read_data(ctx->conn,
(uint8_t*) rdbuf, READBACK_LEN, &num);
if (ret < 0)
@ -583,7 +580,7 @@ static int canonselphy_send_reset(struct canonselphy_ctx *ctx)
0x00, 0x00, 0x00, 0x00 };
int ret;
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
rstcmd, sizeof(rstcmd))))
return CUPS_BACKEND_FAILED;
@ -605,27 +602,21 @@ static void *canonselphy_init(void)
return ctx;
}
static int canonselphy_attach(void *vctx, struct libusb_device_handle *dev, int type,
uint8_t endp_up, uint8_t endp_down, int iface, uint8_t jobid)
static int canonselphy_attach(void *vctx, struct dyesub_connection *conn, uint8_t jobid)
{
struct canonselphy_ctx *ctx = vctx;
int i, num;
uint8_t rdbuf[READBACK_LEN];
UNUSED(jobid);
UNUSED(iface);
ctx->dev = dev;
ctx->endp_up = endp_up;
ctx->endp_down = endp_down;
ctx->type = type;
ctx->conn = conn;
if (ctx->type == P_CP900) {
ctx->type = P_CP_XXX;
if (ctx->conn->type == P_CP900) {
ctx->conn->type = P_CP_XXX;
ctx->cp900 = 1;
}
for (i = 0 ; selphy_printers[i].type != -1; i++) {
if (selphy_printers[i].type == ctx->type) {
if (selphy_printers[i].type == ctx->conn->type) {
ctx->printer = &selphy_printers[i];
}
}
@ -640,12 +631,12 @@ static int canonselphy_attach(void *vctx, struct libusb_device_handle *dev, int
if (test_mode < TEST_MODE_NOATTACH) {
/* Read printer status. Twice. */
i = read_data(ctx->dev, ctx->endp_up,
i = read_data(ctx->conn,
rdbuf, READBACK_LEN, &num);
if (i < 0)
return CUPS_BACKEND_FAILED;
i = read_data(ctx->dev, ctx->endp_up,
i = read_data(ctx->conn,
rdbuf, READBACK_LEN, &num);
if (i < 0)
return CUPS_BACKEND_FAILED;
@ -743,14 +734,14 @@ static int canonselphy_read_parse(void *vctx, const void **vjob, int data_fd, in
printer_type = parse_printjob(rdbuf, &job->bw_mode, &job->plane_len);
/* Special cases for some models */
if (printer_type == P_ES40_CP790) {
if (ctx->type == P_CP790)
if (ctx->conn->type == P_CP790)
printer_type = P_CP790;
else
printer_type = P_ES40;
}
if (printer_type != ctx->type) {
ERROR("Printer/Job mismatch (%d/%d/%d)\n", ctx->type, ctx->printer->type, printer_type);
if (printer_type != ctx->conn->type) {
ERROR("Printer/Job mismatch (%d/%d/%d)\n", ctx->conn->type, ctx->printer->type, printer_type);
canonselphy_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
@ -853,7 +844,7 @@ static int canonselphy_main_loop(void *vctx, const void *vjob) {
copies = job->copies;
/* Read in the printer status to clear last state */
ret = read_data(ctx->dev, ctx->endp_up,
ret = read_data(ctx->conn,
rdbuf, READBACK_LEN, &num);
if (ret < 0)
@ -866,7 +857,7 @@ top:
}
/* Read in the printer status */
ret = read_data(ctx->dev, ctx->endp_up,
ret = read_data(ctx->conn,
rdbuf, READBACK_LEN, &num);
if (ret < 0)
return CUPS_BACKEND_FAILED;
@ -881,7 +872,7 @@ top:
dump_markers(&ctx->marker, 1, 0);
if (ctx->printer->clear_error_len)
/* Try to clear error state */
if ((ret = send_data(ctx->dev, ctx->endp_down, ctx->printer->clear_error, ctx->printer->clear_error_len)))
if ((ret = send_data(ctx->conn, ctx->printer->clear_error, ctx->printer->clear_error_len)))
return CUPS_BACKEND_FAILED;
return CUPS_BACKEND_HOLD;
}
@ -903,7 +894,7 @@ top:
/* Make sure paper/ribbon is correct */
if (job->paper_code != -1) {
if (ctx->type == P_CP_XXX) {
if (ctx->conn->type == P_CP_XXX) {
uint8_t pc = rdbuf[ctx->printer->paper_code_offset];
if (((pc >> 4) & 0xf) != (job->paper_code & 0x0f)) {
@ -934,7 +925,7 @@ top:
return CUPS_BACKEND_HOLD; /* Hold this job, don't stop queue */
}
}
} else if (ctx->type == P_CP790) {
} else if (ctx->conn->type == P_CP790) {
uint8_t ribbon = rdbuf[4] >> 4;
uint8_t paper = rdbuf[5];
@ -959,7 +950,7 @@ top:
case S_PRINTER_READY:
INFO("Printing started; Sending init sequence\n");
/* Send printer init */
if ((ret = send_data(ctx->dev, ctx->endp_down, job->header, ctx->printer->init_length)))
if ((ret = send_data(ctx->conn, job->header, ctx->printer->init_length)))
return CUPS_BACKEND_FAILED;
state = S_PRINTER_INIT_SENT;
@ -975,7 +966,7 @@ top:
else
INFO("Sending YELLOW plane\n");
if ((ret = send_data(ctx->dev, ctx->endp_down, job->plane_y, job->plane_len)))
if ((ret = send_data(ctx->conn, job->plane_y, job->plane_len)))
return CUPS_BACKEND_FAILED;
state = S_PRINTER_Y_SENT;
@ -991,7 +982,7 @@ top:
case S_PRINTER_READY_M:
INFO("Sending MAGENTA plane\n");
if ((ret = send_data(ctx->dev, ctx->endp_down, job->plane_m, job->plane_len)))
if ((ret = send_data(ctx->conn, job->plane_m, job->plane_len)))
return CUPS_BACKEND_FAILED;
state = S_PRINTER_M_SENT;
@ -1004,7 +995,7 @@ top:
case S_PRINTER_READY_C:
INFO("Sending CYAN plane\n");
if ((ret = send_data(ctx->dev, ctx->endp_down, job->plane_c, job->plane_len)))
if ((ret = send_data(ctx->conn, job->plane_c, job->plane_len)))
return CUPS_BACKEND_FAILED;
state = S_PRINTER_C_SENT;
@ -1021,7 +1012,7 @@ top:
uint32_t empty = 0;
INFO("Sending CP900 Footer\n");
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
(uint8_t*)&empty, sizeof(empty))))
return CUPS_BACKEND_FAILED;
@ -1032,7 +1023,7 @@ top:
if (ctx->printer->foot_length) {
INFO("Cleaning up\n");
if ((ret = send_data(ctx->dev, ctx->endp_down, job->footer, ctx->printer->foot_length)))
if ((ret = send_data(ctx->conn, job->footer, ctx->printer->foot_length)))
return CUPS_BACKEND_FAILED;
}
state = S_FINISHED;
@ -1096,12 +1087,12 @@ static int canonselphy_query_markers(void *vctx, struct marker **markers, int *c
int ret, num;
/* Read in the printer status, twice. */
ret = read_data(ctx->dev, ctx->endp_up,
ret = read_data(ctx->conn,
(uint8_t*) rdbuf, READBACK_LEN, &num);
if (ret < 0)
return CUPS_BACKEND_FAILED;
ret = read_data(ctx->dev, ctx->endp_up,
ret = read_data(ctx->conn,
(uint8_t*) rdbuf, READBACK_LEN, &num);
if (ret < 0)
@ -1134,7 +1125,7 @@ static const char *canonselphy_prefixes[] = {
struct dyesub_backend canonselphy_backend = {
.name = "Canon SELPHY CP/ES (legacy)",
.version = "0.105",
.version = "0.106",
.uri_prefixes = canonselphy_prefixes,
.cmdline_usage = canonselphy_cmdline,
.cmdline_arg = canonselphy_cmdline_arg,

View File

@ -57,10 +57,7 @@ struct selphyneo_printjob {
};
struct selphyneo_ctx {
struct libusb_device_handle *dev;
uint8_t endp_up;
uint8_t endp_down;
int type;
struct dyesub_connection *conn;
struct marker marker;
};
@ -134,7 +131,7 @@ static int selphyneo_send_reset(struct selphyneo_ctx *ctx)
0x00, 0x00, 0x00, 0x00 };
int ret;
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
rstcmd, sizeof(rstcmd))))
return CUPS_BACKEND_FAILED;
@ -147,14 +144,14 @@ static int selphyneo_get_status(struct selphyneo_ctx *ctx)
int ret, num;
/* Read in the printer status to clear last state */
ret = read_data(ctx->dev, ctx->endp_up,
ret = read_data(ctx->conn,
(uint8_t*) &rdback, sizeof(rdback), &num);
if (ret < 0)
return CUPS_BACKEND_FAILED;
/* And again, for the markers */
ret = read_data(ctx->dev, ctx->endp_up,
ret = read_data(ctx->conn,
(uint8_t*) &rdback, sizeof(rdback), &num);
if (ret < 0)
@ -183,31 +180,26 @@ static void *selphyneo_init(void)
extern struct dyesub_backend selphyneo_backend;
static int selphyneo_attach(void *vctx, struct libusb_device_handle *dev, int type,
uint8_t endp_up, uint8_t endp_down, int iface, uint8_t jobid)
static int selphyneo_attach(void *vctx, struct dyesub_connection *conn, uint8_t jobid)
{
struct selphyneo_ctx *ctx = vctx;
struct selphyneo_readback rdback;
int ret, num;
UNUSED(jobid);
UNUSED(iface);
ctx->dev = dev;
ctx->endp_up = endp_up;
ctx->endp_down = endp_down;
ctx->type = type;
ctx->conn = conn;
if (test_mode < TEST_MODE_NOATTACH) {
/* Read in the printer status to clear last state */
ret = read_data(ctx->dev, ctx->endp_up,
ret = read_data(ctx->conn,
(uint8_t*) &rdback, sizeof(rdback), &num);
if (ret < 0)
return CUPS_BACKEND_FAILED;
/* And again, for the markers */
ret = read_data(ctx->dev, ctx->endp_up,
ret = read_data(ctx->conn,
(uint8_t*) &rdback, sizeof(rdback), &num);
if (ret < 0)
@ -336,7 +328,7 @@ static int selphyneo_main_loop(void *vctx, const void *vjob) {
copies = job->copies;
/* Read in the printer status to clear last state */
ret = read_data(ctx->dev, ctx->endp_up,
ret = read_data(ctx->conn,
(uint8_t*) &rdback, sizeof(rdback), &num);
if (ret < 0)
@ -346,7 +338,7 @@ top:
INFO("Waiting for printer idle\n");
do {
ret = read_data(ctx->dev, ctx->endp_up,
ret = read_data(ctx->conn,
(uint8_t*) &rdback, sizeof(rdback), &num);
if (ret < 0)
@ -383,7 +375,7 @@ top:
int chunk = 256*1024;
int sent = 0;
while (chunk > 0) {
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
job->databuf + sent, chunk)))
return CUPS_BACKEND_FAILED;
sent += chunk;
@ -394,7 +386,7 @@ top:
}
/* Read in the printer status to clear last state */
ret = read_data(ctx->dev, ctx->endp_up,
ret = read_data(ctx->conn,
(uint8_t*) &rdback, sizeof(rdback), &num);
if (ret < 0)
@ -402,7 +394,7 @@ top:
INFO("Waiting for printer acknowledgement\n");
do {
ret = read_data(ctx->dev, ctx->endp_up,
ret = read_data(ctx->conn,
(uint8_t*) &rdback, sizeof(rdback), &num);
if (ret < 0)
@ -487,14 +479,14 @@ static int selphyneo_query_markers(void *vctx, struct marker **markers, int *cou
int ret, num;
/* Read in the printer status to clear last state */
ret = read_data(ctx->dev, ctx->endp_up,
ret = read_data(ctx->conn,
(uint8_t*) &rdback, sizeof(rdback), &num);
if (ret < 0)
return CUPS_BACKEND_FAILED;
/* And again, for the markers */
ret = read_data(ctx->dev, ctx->endp_up,
ret = read_data(ctx->conn,
(uint8_t*) &rdback, sizeof(rdback), &num);
if (ret < 0)
@ -520,7 +512,7 @@ static const char *canonselphyneo_prefixes[] = {
struct dyesub_backend canonselphyneo_backend = {
.name = "Canon SELPHY CP (new)",
.version = "0.20",
.version = "0.21",
.uri_prefixes = canonselphyneo_prefixes,
.cmdline_usage = selphyneo_cmdline,
.cmdline_arg = selphyneo_cmdline_arg,

View File

@ -29,7 +29,7 @@
#include <signal.h>
#include <strings.h> /* For strncasecmp */
#define BACKEND_VERSION "0.107"
#define BACKEND_VERSION "0.108"
#ifndef URI_PREFIX
#error "Must Define URI_PREFIX"
#endif
@ -226,22 +226,22 @@ char *dict_find(const char *key, int dlen, struct deviceid_dict* dict)
}
/* I/O functions */
int read_data(struct libusb_device_handle *dev, uint8_t endp,
uint8_t *buf, int buflen, int *readlen)
int read_data(struct dyesub_connection *conn, uint8_t *buf, int buflen, int *readlen)
{
int ret;
/* Clear buffer */
memset(buf, 0, buflen);
ret = libusb_bulk_transfer(dev, endp,
ret = libusb_bulk_transfer(conn->dev, conn->endp_up,
buf,
buflen,
readlen,
xfer_timeout);
if (ret < 0) {
ERROR("Failure to receive data from printer (libusb error %d: (%d/%d from 0x%02x))\n", ret, *readlen, buflen, endp);
ERROR("Failure to receive data from printer (libusb error %d: (%d/%d from 0x%02x))\n", ret, *readlen, buflen, conn->endp_up);
goto done;
}
@ -270,8 +270,7 @@ done:
return ret;
}
int send_data(struct libusb_device_handle *dev, uint8_t endp,
const uint8_t *buf, int len)
int send_data(struct dyesub_connection *conn, const uint8_t *buf, int len)
{
int num = 0;
@ -299,12 +298,12 @@ int send_data(struct libusb_device_handle *dev, uint8_t endp,
DEBUG2("\n");
}
int ret = libusb_bulk_transfer(dev, endp,
int ret = libusb_bulk_transfer(conn->dev, conn->endp_down,
(uint8_t*) buf, len2,
&num, xfer_timeout);
if (ret < 0) {
ERROR("Failure to send data to printer (libusb error %d: (%d/%d to 0x%02x))\n", ret, num, len2, endp);
ERROR("Failure to send data to printer (libusb error %d: (%d/%d to 0x%02x))\n", ret, num, len2, conn->endp_down);
return ret;
}
len -= num;
@ -405,8 +404,7 @@ static int probe_device(struct libusb_device *device,
const char *prefix, const char *manuf_override,
int found, int num_claim_attempts,
int scan_only, const char *match_serno,
uint8_t *r_iface, uint8_t *r_altset,
uint8_t *r_endp_up, uint8_t *r_endp_down,
struct dyesub_connection *conn,
struct dyesub_backend *backend)
{
struct libusb_device_handle *dev;
@ -613,9 +611,13 @@ candidate:
sanitize_string(buf);
serial = url_encode(buf);
} else if (backend->query_serno) { /* Get from backend hook */
buf[0] = 0;
/* Ignore result since a failure isn't critical here */
backend->query_serno(dev, endp_up, endp_down, iface, buf, STR_LEN_MAX);
struct dyesub_connection c2;
c2.dev = dev;
c2.iface = iface;
c2.altset = altset;
c2.endp_up = endp_up;
c2.endp_down = endp_down;
backend->query_serno(&c2, buf, STR_LEN_MAX);
serial = url_encode(buf);
}
@ -660,11 +662,11 @@ candidate:
DEBUG("VID: %04X PID: %04X Manuf: '%s' Product: '%s' Serial: '%s' found: %d\n",
desc->idVendor, desc->idProduct, manuf, product, serial, found);
if (found != -1) {
if (r_iface) *r_iface = iface;
if (r_altset) *r_altset = altset;
if (r_endp_up) *r_endp_up = endp_up;
if (r_endp_up) *r_endp_down = endp_down;
if (found != -1 && conn) {
conn->iface = iface;
conn->altset = altset;
conn->endp_up = endp_up;
conn->endp_down = endp_down;
}
/* Free things up */
@ -751,19 +753,18 @@ static int find_and_enumerate(struct libusb_context *ctx,
const char *match_serno,
const char *prefix,
int scan_only, int num_claim_attempts,
uint8_t *r_iface, uint8_t *r_altset,
uint8_t *r_endp_up, uint8_t *r_endp_down)
struct dyesub_connection *conn)
{
int num;
int i, j = 0, k;
int found = -1;
if (test_mode >= TEST_MODE_NOATTACH) {
if (test_mode >= TEST_MODE_NOATTACH && conn) {
found = 1;
*r_endp_up = 0x82;
*r_endp_down = 0x01;
*r_iface = 0;
*r_altset = 0;
conn->endp_up = 0x82;
conn->endp_down = 0x01;
conn->iface = 0;
conn->altset = 0;
return found;
}
@ -835,8 +836,7 @@ static int find_and_enumerate(struct libusb_context *ctx,
URI_PREFIX, backends[k]->devices[j].manuf_str,
found, num_claim_attempts,
scan_only, match_serno,
r_iface, r_altset,
r_endp_up, r_endp_down,
conn,
backends[k]);
foundprefix = NULL;
if (found != -1 && !scan_only)
@ -1068,8 +1068,8 @@ void print_help(const char *argv0, const struct dyesub_backend *backend)
DEBUG("\t[ -d copies ] [ infile | - ]\n");
}
/* Probe for printers */
find_and_enumerate(ctx, &list, backend, NULL, ptr, 1, 1, NULL, NULL, NULL, NULL);
/* Scan for all printers for the specified backend */
find_and_enumerate(ctx, &list, backend, NULL, ptr, 1, 1, NULL);
libusb_free_device_list(list, 1);
}
@ -1250,13 +1250,11 @@ int main (int argc, char **argv)
{
struct libusb_context *ctx = NULL;
struct libusb_device **list = NULL;
struct libusb_device_handle *dev = NULL;
struct dyesub_backend *backend = NULL;
void * backend_ctx = NULL;
uint8_t endp_up, endp_down;
uint8_t iface, altset;
struct dyesub_connection conn;
int ret = CUPS_BACKEND_OK;
@ -1269,7 +1267,6 @@ int main (int argc, char **argv)
const char *fname = NULL;
char *use_serno = NULL;
const char *backend_str = NULL;
int printer_type;
logger = stderr;
@ -1438,7 +1435,7 @@ int main (int argc, char **argv)
}
/* Enumerate devices */
found = find_and_enumerate(ctx, &list, backend, use_serno, backend_str, 0, NUM_CLAIM_ATTEMPTS, &iface, &altset, &endp_up, &endp_down);
found = find_and_enumerate(ctx, &list, backend, use_serno, backend_str, 0, NUM_CLAIM_ATTEMPTS, &conn);
if (found == -1) {
ERROR("Printer open failure (No matching printers found!)\n");
@ -1453,7 +1450,7 @@ int main (int argc, char **argv)
}
/* Open an appropriate device */
ret = libusb_open(list[found], &dev);
ret = libusb_open(list[found], &conn.dev);
if (ret) {
ERROR("Printer open failure (Need to be root?) (%d)\n", ret);
ret = CUPS_BACKEND_RETRY_CURRENT;
@ -1461,8 +1458,8 @@ int main (int argc, char **argv)
}
/* Detach the kernel driver */
if (libusb_kernel_driver_active(dev, iface)) {
ret = libusb_detach_kernel_driver(dev, iface);
if (libusb_kernel_driver_active(conn.dev, conn.iface)) {
ret = libusb_detach_kernel_driver(conn.dev, conn.iface);
if (ret && (ret != LIBUSB_ERROR_NOT_SUPPORTED)) {
ERROR("Printer open failure (Could not detach printer from kernel) (%d)\n", ret);
ret = CUPS_BACKEND_RETRY_CURRENT;
@ -1471,7 +1468,7 @@ int main (int argc, char **argv)
}
/* Claim the interface so we can start using this! */
ret = backend_claim_interface(dev, iface, NUM_CLAIM_ATTEMPTS);
ret = backend_claim_interface(conn.dev, conn.iface, NUM_CLAIM_ATTEMPTS);
if (ret) {
ERROR("Printer open failure (Unable to claim interface) (%d)\n", ret);
ret = CUPS_BACKEND_RETRY;
@ -1479,8 +1476,8 @@ int main (int argc, char **argv)
}
/* Use the appropriate altesetting! */
if (altset != 0) {
ret = libusb_set_interface_alt_setting(dev, iface, altset);
if (conn.altset != 0) {
ret = libusb_set_interface_alt_setting(conn.dev, conn.iface, conn.altset);
if (ret) {
ERROR("Printer open failure (Unable to issue altsettinginterface) (%d)\n", ret);
ret = CUPS_BACKEND_RETRY;
@ -1498,24 +1495,25 @@ bypass:
struct libusb_device *device;
struct libusb_device_descriptor desc;
device = libusb_get_device(dev);
device = libusb_get_device(conn.dev);
libusb_get_device_descriptor(device, &desc);
printer_type = lookup_printer_type(backend,
conn.type = lookup_printer_type(backend,
desc.idVendor, desc.idProduct);
} else {
printer_type = lookup_printer_type(backend,
conn.type = lookup_printer_type(backend,
extra_vid, extra_pid);
}
if (printer_type <= P_UNKNOWN) {
if (conn.type <= P_UNKNOWN) {
ERROR("Unable to lookup printer type\n");
ret = CUPS_BACKEND_FAILED;
goto done_claimed;
}
/* Attach backend to device */ // XXX pass backend_str?
if (backend->attach(backend_ctx, dev, printer_type, endp_up, endp_down, iface, jobid)) {
ret = backend->attach(backend_ctx, &conn, jobid);
if (ret) {
ERROR("Unable to attach to printer!\n");
ret = CUPS_BACKEND_FAILED;
goto done_claimed;
@ -1553,11 +1551,11 @@ bypass:
done_claimed:
if (test_mode < TEST_MODE_NOATTACH)
libusb_release_interface(dev, iface);
libusb_release_interface(conn.dev, conn.iface);
done_close:
if (test_mode < TEST_MODE_NOATTACH)
libusb_close(dev);
libusb_close(conn.dev);
done:
if (backend && backend_ctx) {

View File

@ -193,6 +193,18 @@ struct printerstats {
int32_t cnt_life[DECKS_MAX]; /* Lifetime prints */
};
struct dyesub_connection {
struct libusb_device_handle *dev;
uint8_t endp_up;
uint8_t endp_down;
uint8_t iface;
uint8_t altset;
// TODO: mutex/lock
int type; /* P_XXXX */
};
#define DYESUB_MAX_JOB_ENTRIES 3
struct dyesub_joblist {
@ -212,9 +224,8 @@ struct dyesub_job_common {
};
/* Exported functions */
int send_data(struct libusb_device_handle *dev, uint8_t endp,
const uint8_t *buf, int len);
int read_data(struct libusb_device_handle *dev, uint8_t endp,
int send_data(struct dyesub_connection *conn, const uint8_t *buf, int len);
int read_data(struct dyesub_connection *conn,
uint8_t *buf, int buflen, int *readlen);
void dump_markers(const struct marker *markers, int marker_count, int full);
@ -254,8 +265,7 @@ struct dyesub_backend {
const uint32_t flags;
void (*cmdline_usage)(void); /* Optional */
void *(*init)(void);
int (*attach)(void *ctx, struct libusb_device_handle *dev, int type,
uint8_t endp_up, uint8_t endp_down, int iface, uint8_t jobid);
int (*attach)(void *ctx, struct dyesub_connection *conn, uint8_t jobid);
void (*teardown)(void *ctx);
int (*cmdline_arg)(void *ctx, int argc, char **argv);
int (*read_parse)(void *ctx, const void **job, int data_fd, int copies);
@ -263,7 +273,7 @@ struct dyesub_backend {
void *(*combine_jobs)(const void *job1, const void *job2);
int (*job_polarity)(void *ctx);
int (*main_loop)(void *ctx, const void *job);
int (*query_serno)(struct libusb_device_handle *dev, uint8_t endp_up, uint8_t endp_down, int iface, char *buf, int buf_len); /* Optional */
int (*query_serno)(struct dyesub_connection *conn, char *buf, int buf_len); /* Optional */
int (*query_markers)(void *ctx, struct marker **markers, int *count);
int (*query_stats)(void *ctx, struct printerstats *stats); /* Optional */
const struct device_id devices[];

View File

@ -66,12 +66,8 @@ struct dnpds40_printjob {
};
struct dnpds40_ctx {
struct libusb_device_handle *dev;
uint8_t endp_up;
uint8_t endp_down;
int iface;
struct dyesub_connection *conn;
int type;
int mfg; /* 0 for dnp, 1 citizen, 2 other */
/* Version and whatnot */
@ -635,12 +631,12 @@ static int dnpds40_do_cmd(struct dnpds40_ctx *ctx,
{
int ret;
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
(uint8_t*)cmd, sizeof(*cmd))))
return ret;
if (data && len)
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
data, len)))
return ret;
@ -663,7 +659,7 @@ static uint8_t *dnpds40_resp_cmd2(struct dnpds40_ctx *ctx,
return NULL;
/* Read in the response header */
ret = read_data(ctx->dev, ctx->endp_up,
ret = read_data(ctx->conn,
(uint8_t*)tmp, 8, &num);
if (ret < 0)
return NULL;
@ -682,7 +678,7 @@ static uint8_t *dnpds40_resp_cmd2(struct dnpds40_ctx *ctx,
respbuf[i] = 0; /* Explicitly null-pad */
/* Read in the actual response */
ret = read_data(ctx->dev, ctx->endp_up,
ret = read_data(ctx->conn,
respbuf, i, &num);
if (ret < 0) {
free(respbuf);
@ -701,17 +697,14 @@ static uint8_t *dnpds40_resp_cmd2(struct dnpds40_ctx *ctx,
#define dnpds40_resp_cmd(__ctx, __cmd, __len) dnpds40_resp_cmd2(__ctx, __cmd, __len, NULL, 0)
static int dnpds40_query_serno(struct libusb_device_handle *dev, uint8_t endp_up, uint8_t endp_down, int iface, char *buf, int buf_len)
static int dnpds40_query_serno(struct dyesub_connection *conn, char *buf, int buf_len)
{
struct dnpds40_cmd cmd;
uint8_t *resp;
int len = 0;
struct dnpds40_ctx ctx = {
.dev = dev,
.endp_up = endp_up,
.endp_down = endp_down,
.iface = iface,
.conn = conn,
};
/* Get Serial Number */
@ -811,18 +804,13 @@ static int dnpds80dx_query_paper(struct dnpds40_ctx *ctx)
return CUPS_BACKEND_OK;
}
static int dnpds40_attach(void *vctx, struct libusb_device_handle *dev, int type,
uint8_t endp_up, uint8_t endp_down, int iface, uint8_t jobid)
static int dnpds40_attach(void *vctx, struct dyesub_connection *conn, uint8_t jobid)
{
struct dnpds40_ctx *ctx = vctx;
UNUSED(jobid);
ctx->dev = dev;
ctx->endp_up = endp_up;
ctx->endp_down = endp_down;
ctx->type = type;
ctx->iface = iface;
ctx->conn = conn;
/* Nearly all models support 600dpi */
ctx->supports_600dpi = 1;
@ -859,7 +847,7 @@ static int dnpds40_attach(void *vctx, struct libusb_device_handle *dev, int type
}
/* Per-printer options */
switch (ctx->type) {
switch (ctx->conn->type) {
case P_DNP_DS40:
ctx->native_width = 1920;
ctx->max_height = 5480;
@ -998,7 +986,7 @@ static int dnpds40_attach(void *vctx, struct libusb_device_handle *dev, int type
ctx->supports_systime = 1;
break;
default:
ERROR("Unknown printer type %d\n", ctx->type);
ERROR("Unknown printer type %d\n", ctx->conn->type);
return CUPS_BACKEND_FAILED;
}
@ -1033,7 +1021,7 @@ static int dnpds40_attach(void *vctx, struct libusb_device_handle *dev, int type
ctx->media = atoi(tmp);
if (ctx->type != P_DNP_QW410) {
if (ctx->conn->type != P_DNP_QW410) {
/* Subtract out the "mark" type */
if (ctx->media & 1)
ctx->media--;
@ -1055,7 +1043,7 @@ static int dnpds40_attach(void *vctx, struct libusb_device_handle *dev, int type
free(resp);
}
if (ctx->type == P_DNP_DS80D) {
if (ctx->conn->type == P_DNP_DS80D) {
if (dnpds80dx_query_paper(ctx))
return CUPS_BACKEND_FAILED;
}
@ -1065,13 +1053,13 @@ static int dnpds40_attach(void *vctx, struct libusb_device_handle *dev, int type
struct libusb_device_descriptor desc;
struct libusb_device *udev;
udev = libusb_get_device(ctx->dev);
udev = libusb_get_device(ctx->conn->dev);
libusb_get_device_descriptor(udev, &desc);
char buf[STR_LEN_MAX + 1];
buf[0] = 0;
buf[STR_LEN_MAX] = 0;
libusb_get_string_descriptor_ascii(ctx->dev, desc.iManufacturer, (unsigned char*)buf, STR_LEN_MAX);
libusb_get_string_descriptor_ascii(ctx->conn->dev, desc.iManufacturer, (unsigned char*)buf, STR_LEN_MAX);
if (!strncmp(buf, "Dai", 3)) /* "Dai Nippon Printing" */
ctx->mfg = 0;
@ -1092,7 +1080,7 @@ static int dnpds40_attach(void *vctx, struct libusb_device_handle *dev, int type
#endif
}
} else {
switch(ctx->type) {
switch(ctx->conn->type) {
case P_DNP_DS80D:
ctx->duplex_media = 200;
/* Intentional fallthrough */
@ -1163,7 +1151,7 @@ static int dnpds40_attach(void *vctx, struct libusb_device_handle *dev, int type
}
} else {
/* Look it up for legacy models & FW */
switch (ctx->type) {
switch (ctx->conn->type) {
case P_DNP_DS40:
switch (ctx->media) {
case 200: // L
@ -1342,7 +1330,7 @@ static int dnpds40_attach(void *vctx, struct libusb_device_handle *dev, int type
ctx->marker[0].levelnow = CUPS_MARKER_UNKNOWN;
ctx->marker_count = 1;
if (ctx->type == P_DNP_DS80D) {
if (ctx->conn->type == P_DNP_DS80D) {
ctx->marker[1].color = "#00FFFF#FF00FF#FFFF00";
ctx->marker[1].name = dnpds80_duplex_media_types(ctx->duplex_media);
ctx->marker[1].numtype = ctx->duplex_media;
@ -1369,7 +1357,7 @@ static void dnpds40_teardown(void *vctx) {
if (!ctx)
return;
if (test_mode < TEST_MODE_NOATTACH && ctx->type == P_DNP_DS80D) {
if (test_mode < TEST_MODE_NOATTACH && ctx->conn->type == P_DNP_DS80D) {
struct dnpds40_cmd cmd;
/* Check to see if last print was the front side
@ -1456,7 +1444,7 @@ static int dnpds40_read_parse(void *vctx, const void **vjob, int data_fd, int co
/* See if job lacks the standard ESC-P start sequence */
if (job->databuf[job->datalen + 0] != 0x1b ||
job->databuf[job->datalen + 1] != 0x50) {
switch(ctx->type) {
switch(ctx->conn->type) {
case P_DNP_QW410:
i = legacy_qw410_read_parse(job, data_fd, i);
break;
@ -1553,7 +1541,7 @@ static int dnpds40_read_parse(void *vctx, const void **vjob, int data_fd, int co
continue;
}
if (ctx->type == P_DNP_DS820) {
if (ctx->conn->type == P_DNP_DS820) {
if (j != 24) {
WARNING("Full cutter argument length incorrect, ignoring!\n");
continue;
@ -1649,7 +1637,7 @@ parsed:
}
/* QW410 only supports 0 and 3, supposedly. */
if (ctx->type == P_DNP_QW410 && job->printspeed > 1) {
if (ctx->conn->type == P_DNP_QW410 && job->printspeed > 1) {
job->printspeed = 3;
}
@ -1676,7 +1664,7 @@ parsed:
}
/* Make sure MULTICUT is sane, most validation needs this */
if (!job->multicut && ctx->type != P_CITIZEN_CW01) {
if (!job->multicut && ctx->conn->type != P_CITIZEN_CW01) {
WARNING("Missing or illegal MULTICUT command!\n");
if (job->dpi == 300)
job->buf_needed = 1;
@ -1688,7 +1676,7 @@ parsed:
/* Only DS80D supports Cut Paper types */
if (job->multicut > 100) {
if ( ctx->type == P_DNP_DS80D) {
if ( ctx->conn->type == P_DNP_DS80D) {
job->cut_paper = 1;
} else {
ERROR("Only DS80D supports cut-paper sizes!\n");
@ -1701,7 +1689,7 @@ parsed:
job->buf_needed = 1;
if (job->dpi == 600) {
switch(ctx->type) {
switch(ctx->conn->type) {
case P_DNP_DS620:
if (job->multicut == MULTICUT_6x9 ||
job->multicut == MULTICUT_6x4_5X2)
@ -1761,7 +1749,7 @@ parsed:
break;
}
}
if (job->dpi == 334 && ctx->type != P_CITIZEN_CW01)
if (job->dpi == 334 && ctx->conn->type != P_CITIZEN_CW01)
{
ERROR("Illegal resolution (%u) for printer!\n", job->dpi);
dnpds40_cleanup_job(job);
@ -1859,7 +1847,7 @@ parsed:
job->can_rewind = 1;
break;
case 500: //"8x10"
if (ctx->type == P_DNP_DS820 &&
if (ctx->conn->type == P_DNP_DS820 &&
(job->multicut == MULTICUT_8x7 || job->multicut == MULTICUT_8x9)) {
/* These are okay */
} else if (job->multicut < MULTICUT_8x10 || job->multicut == MULTICUT_8x12 ||
@ -2160,7 +2148,7 @@ top:
free(resp);
}
if (ctx->type == P_CITIZEN_CW01) {
if (ctx->conn->type == P_CITIZEN_CW01) {
/* Get Vertical resolution */
dnpds40_build_cmd(&cmd, "INFO", "RESOLUTION_V", 0);
@ -2217,7 +2205,7 @@ top:
snprintf(buf, sizeof(buf), "%08d", 1);
/* DS80D does not support BUFFCNTRL when using
cut media; all others support this */
if (ctx->type != P_DNP_DS80D ||
if (ctx->conn->type != P_DNP_DS80D ||
multicut < 100) {
dnpds40_build_cmd(&cmd, "CNTRL", "BUFFCNTRL", 8);
if ((ret = dnpds40_do_cmd(ctx, &cmd, (uint8_t*)buf, 8)))
@ -2265,7 +2253,7 @@ top:
memcpy(buf, ptr + 24, 8);
i = atoi(buf) + 32;
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
ptr, i)))
return CUPS_BACKEND_FAILED;
@ -2416,7 +2404,7 @@ static int dnpds40_get_info(struct dnpds40_ctx *ctx)
int cwd_index = 1;
uint8_t cwd_buf[5];
INFO("Model: %s\n", dnpds40_printer_type(ctx->type, ctx->mfg));
INFO("Model: %s\n", dnpds40_printer_type(ctx->conn->type, ctx->mfg));
/* Serial number already queried */
INFO("Serial Number: %s\n", ctx->serno);
@ -2425,7 +2413,7 @@ static int dnpds40_get_info(struct dnpds40_ctx *ctx)
INFO("Firmware Version: %s\n", ctx->version);
/* Figure out Duplexer */
if (ctx->type == P_DNP_DS80D) {
if (ctx->conn->type == P_DNP_DS80D) {
dnpds40_build_cmd(&cmd, "INFO", "UNIT_FVER", 0);
resp = dnpds40_resp_cmd(ctx, &cmd, &len);
@ -2439,7 +2427,7 @@ static int dnpds40_get_info(struct dnpds40_ctx *ctx)
free(resp);
}
if (ctx->type == P_CITIZEN_CW01) {
if (ctx->conn->type == P_CITIZEN_CW01) {
/* Get Horizonal resolution */
dnpds40_build_cmd(&cmd, "INFO", "RESOLUTION_H", 0);
@ -2545,7 +2533,7 @@ static int dnpds40_get_info(struct dnpds40_ctx *ctx)
free(resp);
if (ctx->type == P_CITIZEN_CW01)
if (ctx->conn->type == P_CITIZEN_CW01)
goto skip;
/* Get Ribbon ID code (?) */
@ -2693,7 +2681,7 @@ CWD_TOP:
}
if (cwd_extra && cwd_index == 1) {
if (ctx->type == P_DNP_QW410)
if (ctx->conn->type == P_DNP_QW410)
cwd_index = 2;
else
cwd_index = 3;
@ -2795,7 +2783,7 @@ static int dnpds40_get_status(struct dnpds40_ctx *ctx)
free(resp);
/* Figure out Duplexer */
if (ctx->type == P_DNP_DS80D) {
if (ctx->conn->type == P_DNP_DS80D) {
dnpds40_build_cmd(&cmd, "INFO", "UNIT_STATUS", 0);
resp = dnpds40_resp_cmd(ctx, &cmd, &len);
@ -2859,7 +2847,7 @@ static int dnpds40_get_status(struct dnpds40_ctx *ctx)
}
/* Report Cut Media */
if (ctx->type == P_DNP_DS80D) {
if (ctx->conn->type == P_DNP_DS80D) {
INFO("Duplex Media Type: %s\n", dnpds80_duplex_media_types(ctx->duplex_media));
INFO("Duplexer Media Status: %s\n", dnpds80_duplex_paper_status(ctx->duplex_media_status));
}
@ -2913,8 +2901,8 @@ static int dnpds40_get_counters(struct dnpds40_ctx *ctx)
free(resp);
if (ctx->type == P_DNP_DS620 ||
ctx->type == P_DNP_DS820) {
if (ctx->conn->type == P_DNP_DS620 ||
ctx->conn->type == P_DNP_DS820) {
/* Generate command */
dnpds40_build_cmd(&cmd, "MNT_RD", "COUNTER_HEAD", 0);
@ -2998,7 +2986,7 @@ static int dnpds40_get_counters(struct dnpds40_ctx *ctx)
free(resp);
}
if (ctx->type == P_DNP_DS80D) {
if (ctx->conn->type == P_DNP_DS80D) {
dnpds40_build_cmd(&cmd, "MNT_RD", "COUNTER_DUPLEX", 0);
resp = dnpds40_resp_cmd(ctx, &cmd, &len);
@ -3261,7 +3249,7 @@ static int dnpds40_query_markers(void *vctx, struct marker **markers, int *count
if (ctx->marker[0].levelnow < 0)
return CUPS_BACKEND_FAILED;
if (ctx->type == P_DNP_DS80D) {
if (ctx->conn->type == P_DNP_DS80D) {
if (dnpds80dx_query_paper(ctx))
return CUPS_BACKEND_FAILED;
switch (ctx->duplex_media_status) {
@ -3299,11 +3287,11 @@ static int dnp_query_stats(void *vctx, struct printerstats *stats)
default: stats->mfg = "Unknown" ; break;
}
stats->model = dnpds40_printer_type(ctx->type, ctx->mfg);
stats->model = dnpds40_printer_type(ctx->conn->type, ctx->mfg);
stats->serial = ctx->serno;
stats->fwver = ctx->version; // XXX duplexer version?
stats->decks = ctx->type == P_DNP_DS80D ? 2: 1;
stats->decks = ctx->conn->type == P_DNP_DS80D ? 2: 1;
stats->mediatype[0] = ctx->marker[0].name;
stats->levelmax[0] = ctx->marker[0].levelmax;
stats->levelnow[0] = ctx->marker[0].levelnow;
@ -3330,7 +3318,7 @@ static int dnp_query_stats(void *vctx, struct printerstats *stats)
stats->cnt_life[0] = atoi((char*)resp+2);
free(resp);
if (ctx->type == P_DNP_DS80D) {
if (ctx->conn->type == P_DNP_DS80D) {
stats->name[0] = "Sheet";
stats->mediatype[1] = ctx->marker[1].name;
stats->levelmax[1] = ctx->marker[1].levelmax;
@ -3409,7 +3397,7 @@ static const char *dnpds40_prefixes[] = {
/* Exported */
struct dyesub_backend dnpds40_backend = {
.name = "DNP DS-series / Citizen C-series",
.version = "0.133",
.version = "0.134",
.uri_prefixes = dnpds40_prefixes,
.cmdline_usage = dnpds40_cmdline,
.cmdline_arg = dnpds40_cmdline_arg,

View File

@ -362,11 +362,8 @@ struct hiti_printjob {
};
struct hiti_ctx {
struct libusb_device_handle *dev;
uint8_t endp_up;
uint8_t endp_down;
int iface;
int type;
struct dyesub_connection *conn;
int jobid;
char serno[32];
@ -407,7 +404,7 @@ static int hiti_query_unk8010(struct hiti_ctx *ctx);
static int hiti_query_counter(struct hiti_ctx *ctx, uint8_t arg, uint32_t *resp);
static int hiti_query_markers(void *vctx, struct marker **markers, int *count);
static int hiti_query_serno(struct libusb_device_handle *dev, uint8_t endp_up, uint8_t endp_down, int iface, char *buf, int buf_len);
static int hiti_query_serno(struct dyesub_connection *conn, char *buf, int buf_len);
static int hiti_docmd(struct hiti_ctx *ctx, uint16_t cmdid, uint8_t *buf, uint16_t buf_len, uint16_t *rsplen)
{
@ -423,14 +420,14 @@ static int hiti_docmd(struct hiti_ctx *ctx, uint16_t cmdid, uint8_t *buf, uint16
memcpy(cmd->payload, buf, buf_len);
/* Send over command */
if ((ret = send_data(ctx->dev, ctx->endp_down, (uint8_t*) cmd, buf_len + 3 + 3))) {
if ((ret = send_data(ctx->conn, (uint8_t*) cmd, buf_len + 3 + 3))) {
return ret;
}
__usleep(10*1000);
/* Read back command */
ret = read_data(ctx->dev, ctx->endp_up, cmdbuf, 6, &num);
ret = read_data(ctx->conn, cmdbuf, 6, &num);
if (ret)
return ret;
@ -473,7 +470,7 @@ static int hiti_docmd_resp(struct hiti_ctx *ctx, uint16_t cmdid,
__usleep(10*1000);
/* Read back the data*/
ret = read_data(ctx->dev, ctx->endp_up, respbuf, *resplen, &num);
ret = read_data(ctx->conn, respbuf, *resplen, &num);
if (ret)
return ret;
@ -507,14 +504,14 @@ static int hiti_sepd(struct hiti_ctx *ctx, uint32_t buf_len,
cmd->numLines = cpu_to_be16(numLines);
/* Send over command */
if ((ret = send_data(ctx->dev, ctx->endp_down, (uint8_t*) cmd, sizeof(*cmd)))) {
if ((ret = send_data(ctx->conn, (uint8_t*) cmd, sizeof(*cmd)))) {
return ret;
}
__usleep(10*1000);
/* Read back command */
ret = read_data(ctx->dev, ctx->endp_up, cmdbuf, 6, &num);
ret = read_data(ctx->conn, cmdbuf, 6, &num);
if (ret)
return ret;
@ -894,17 +891,12 @@ static void *hiti_init(void)
return ctx;
}
static int hiti_attach(void *vctx, struct libusb_device_handle *dev, int type,
uint8_t endp_up, uint8_t endp_down, int iface, uint8_t jobid)
static int hiti_attach(void *vctx, struct dyesub_connection *conn, uint8_t jobid)
{
struct hiti_ctx *ctx = vctx;
int ret;
ctx->dev = dev;
ctx->endp_up = endp_up;
ctx->endp_down = endp_down;
ctx->iface = iface;
ctx->type = type;
ctx->conn = conn;
/* Ensure jobid is sane */
ctx->jobid = (jobid & 0x7fff);
@ -915,8 +907,8 @@ static int hiti_attach(void *vctx, struct libusb_device_handle *dev, int type,
/* P52x firmware v1.19+ lose their minds when Linux
issues a routine CLEAR_ENDPOINT_HALT. Printer can recover
if it is reset. Unclear what the side effects are.. */
if (ctx->type == P_HITI_52X)
libusb_reset_device(dev);
if (ctx->conn->type == P_HITI_52X)
libusb_reset_device(ctx->conn->dev);
ret = hiti_query_unk8010(ctx);
if (ret)
@ -939,7 +931,7 @@ static int hiti_attach(void *vctx, struct libusb_device_handle *dev, int type,
ret = hiti_query_hilightadj(ctx);
if (ret)
return ret;
ret = hiti_query_serno(ctx->dev, ctx->endp_up, ctx->endp_down, ctx->iface, ctx->serno, sizeof(ctx->serno));
ret = hiti_query_serno(ctx->conn, ctx->serno, sizeof(ctx->serno));
if (ret)
return ret;
@ -985,7 +977,7 @@ static uint8_t *hiti_get_correction_data(struct hiti_ctx *ctx, uint8_t mode)
int mediaver = ctx->ribbonvendor & 0x3f;
int mediatype = ((ctx->ribbonvendor & 0xf000) == 0x1000);
switch (ctx->type)
switch (ctx->conn->type)
{
case P_HITI_51X:
if (!mediatype) {
@ -1136,14 +1128,14 @@ static int hiti_seht2(struct hiti_ctx *ctx, uint8_t plane,
cmd->plane = plane;
/* Send over command */
if ((ret = send_data(ctx->dev, ctx->endp_down, (uint8_t*) cmd, sizeof(*cmd)))) {
if ((ret = send_data(ctx->conn, (uint8_t*) cmd, sizeof(*cmd)))) {
return ret;
}
__usleep(10*1000);
/* Read back command */
ret = read_data(ctx->dev, ctx->endp_up, cmdbuf, 6, &num);
ret = read_data(ctx->conn, cmdbuf, 6, &num);
if (ret)
return ret;
@ -1151,7 +1143,7 @@ static int hiti_seht2(struct hiti_ctx *ctx, uint8_t plane,
/* Send payload, if any */
if (buf_len && !ret) {
ret = send_data(ctx->dev, ctx->endp_down, buf, buf_len);
ret = send_data(ctx->conn, buf, buf_len);
}
return ret;
@ -1169,7 +1161,7 @@ static int hiti_send_heat_data(struct hiti_ctx *ctx, uint8_t mode, uint8_t matte
// XXX if field_0x70 != 100) send blank/empty tables..
// no idea what sets this field.
switch (ctx->type)
switch (ctx->conn->type)
{
case P_HITI_51X:
if (!mediatype) {
@ -1499,7 +1491,7 @@ static int hiti_read_parse(void *vctx, const void **vjob, int data_fd, int copie
job->copies = job->hdr.copies;
/* Sanity check printer type vs job type */
switch(ctx->type)
switch(ctx->conn->type)
{
case P_HITI_52X:
if (job->hdr.model != 520) {
@ -1809,7 +1801,7 @@ static int hiti_main_loop(void *vctx, const void *vjob)
// XXX send ESD_SHTPC w/ heat table. Unknown.
// CMD_ESD_SHPTC // Heating Parameters & Tone Curve (~7Kb, seen on windows..)
/* Send heat table data */
if (ctx->type == P_HITI_51X) {
if (ctx->conn->type == P_HITI_51X) {
ret = hiti_send_heat_data(ctx, job->hdr.quality, job->hdr.overcoat);
}
@ -1821,7 +1813,7 @@ resend_y:
ret = hiti_sepd(ctx, rows * cols, startLine, numLines);
if (ret)
return CUPS_BACKEND_FAILED;
ret = send_data(ctx->dev, ctx->endp_down, job->databuf + sent, rows * cols);
ret = send_data(ctx->conn, job->databuf + sent, rows * cols);
if (ret)
return CUPS_BACKEND_FAILED;
__usleep(200*1000);
@ -1847,7 +1839,7 @@ resend_m:
ret = hiti_sepd(ctx, rows * cols, startLine, numLines);
if (ret)
return CUPS_BACKEND_FAILED;
ret = send_data(ctx->dev, ctx->endp_down, job->databuf + sent, rows * cols);
ret = send_data(ctx->conn, job->databuf + sent, rows * cols);
if (ret)
return CUPS_BACKEND_FAILED;
sent += rows * cols;
@ -1873,7 +1865,7 @@ resend_c:
ret = hiti_sepd(ctx, rows * cols, startLine, numLines);
if (ret)
return CUPS_BACKEND_FAILED;
ret = send_data(ctx->dev, ctx->endp_down, job->databuf + sent, rows * cols);
ret = send_data(ctx->conn, job->databuf + sent, rows * cols);
if (ret)
return CUPS_BACKEND_FAILED;
__usleep(200*1000);
@ -2236,18 +2228,14 @@ static int hiti_query_counter(struct hiti_ctx *ctx, uint8_t arg, uint32_t *resp)
return CUPS_BACKEND_OK;
}
static int hiti_query_serno(struct libusb_device_handle *dev, uint8_t endp_up, uint8_t endp_down, int iface, char *buf, int buf_len)
static int hiti_query_serno(struct dyesub_connection *conn, char *buf, int buf_len)
{
int ret;
uint16_t rsplen = 18;
uint8_t rspbuf[18];
UNUSED(iface);
struct hiti_ctx ctx = {
.dev = dev,
.endp_up = endp_up,
.endp_down = endp_down,
.conn = conn
};
uint8_t arg = sizeof(rspbuf);
@ -2348,7 +2336,7 @@ static const char *hiti_prefixes[] = {
struct dyesub_backend hiti_backend = {
.name = "HiTi Photo Printers",
.version = "0.21",
.version = "0.22",
.uri_prefixes = hiti_prefixes,
.cmdline_usage = hiti_cmdline,
.cmdline_arg = hiti_cmdline_arg,

View File

@ -74,10 +74,7 @@ struct kodak1400_printjob {
};
struct kodak1400_ctx {
struct libusb_device_handle *dev;
uint8_t endp_up;
uint8_t endp_down;
int type;
struct dyesub_connection *conn;
struct marker marker;
};
@ -97,7 +94,7 @@ static int send_plane(struct kodak1400_ctx *ctx,
cmdbuf[2] = 0x00;
cmdbuf[3] = 0x50;
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
cmdbuf, CMDBUF_LEN)))
return ret;
}
@ -115,14 +112,14 @@ static int send_plane(struct kodak1400_ctx *ctx,
memcpy(cmdbuf+9, &temp16, 2);
}
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
cmdbuf, CMDBUF_LEN)))
return ret;
if (planedata) {
int i;
for (i = 0 ; i < job->hdr.rows ; i++) {
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
planedata + i * job->hdr.columns,
job->hdr.columns)))
return ret;
@ -135,7 +132,7 @@ static int send_plane(struct kodak1400_ctx *ctx,
cmdbuf[2] = 0x01;
cmdbuf[3] = 0x50;
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
cmdbuf, CMDBUF_LEN)))
return ret;
@ -145,10 +142,6 @@ static int send_plane(struct kodak1400_ctx *ctx,
#define TONE_CURVE_SIZE 1552
static int kodak1400_set_tonecurve(struct kodak1400_ctx *ctx, char *fname)
{
libusb_device_handle *dev = ctx->dev;
uint8_t endp_down = ctx->endp_down;
uint8_t endp_up = ctx->endp_up;
uint8_t cmdbuf[8];
uint8_t respbuf[64];
int ret = 0, num = 0;
@ -179,13 +172,13 @@ static int kodak1400_set_tonecurve(struct kodak1400_ctx *ctx, char *fname)
memset(cmdbuf, 0, sizeof(cmdbuf));
cmdbuf[0] = 0x1b;
cmdbuf[1] = 0xa2;
if ((ret = send_data(dev, endp_down,
if ((ret = send_data(ctx->conn,
cmdbuf, 2))) {
ret = -3;
goto done;
}
ret = read_data(dev, endp_up,
ret = read_data(ctx->conn,
respbuf, sizeof(respbuf), &num);
if (ret < 0)
@ -209,17 +202,17 @@ static int kodak1400_set_tonecurve(struct kodak1400_ctx *ctx, char *fname)
cmdbuf[3] = 0x03;
cmdbuf[4] = 0x06;
cmdbuf[5] = 0x10; /* 06 10 == TONE_CURVE_SIZE */
if ((ret = send_data(dev, endp_down,
if ((ret = send_data(ctx->conn,
cmdbuf, 6)))
goto done;
/* Send the payload over */
if ((ret = send_data(dev, endp_down,
if ((ret = send_data(ctx->conn,
(uint8_t *) data, TONE_CURVE_SIZE)))
goto done;
/* get the response */
ret = read_data(dev, endp_up,
ret = read_data(ctx->conn,
respbuf, sizeof(respbuf), &num);
if (ret < 0)
@ -282,18 +275,14 @@ static void *kodak1400_init(void)
return ctx;
}
static int kodak1400_attach(void *vctx, struct libusb_device_handle *dev, int type,
uint8_t endp_up, uint8_t endp_down, int iface, uint8_t jobid)
static int kodak1400_attach(void *vctx, struct dyesub_connection *conn,
uint8_t jobid)
{
struct kodak1400_ctx *ctx = vctx;
UNUSED(jobid);
UNUSED(iface);
ctx->dev = dev;
ctx->endp_up = endp_up;
ctx->endp_down = endp_down;
ctx->type = type;
ctx->conn = conn;
ctx->marker.color = "#00FFFF#FF00FF#FFFF00";
ctx->marker.name = "Unknown";
@ -432,12 +421,12 @@ top:
cmdbuf[0] = 0x1b;
cmdbuf[1] = 0x72;
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
cmdbuf, CMDBUF_LEN)))
return CUPS_BACKEND_FAILED;
/* Read in the printer status */
ret = read_data(ctx->dev, ctx->endp_up,
ret = read_data(ctx->conn,
rdbuf, READBACK_LEN, &num);
if (ret < 0)
@ -466,7 +455,7 @@ top:
memset(cmdbuf, 0, CMDBUF_LEN);
cmdbuf[0] = 0x1b;
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
cmdbuf, CMDBUF_LEN)))
return CUPS_BACKEND_FAILED;
@ -480,7 +469,7 @@ top:
temp16 = be16_to_cpu(job->hdr.rows);
memcpy(cmdbuf+5, &temp16, 2);
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
cmdbuf, CMDBUF_LEN)))
return CUPS_BACKEND_FAILED;
@ -490,7 +479,7 @@ top:
cmdbuf[1] = 0x59;
cmdbuf[2] = job->hdr.matte; // ???
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
cmdbuf, CMDBUF_LEN)))
return CUPS_BACKEND_FAILED;
@ -500,7 +489,7 @@ top:
cmdbuf[1] = 0x60;
cmdbuf[2] = job->hdr.laminate;
if (send_data(ctx->dev, ctx->endp_down,
if (send_data(ctx->conn,
cmdbuf, CMDBUF_LEN))
return CUPS_BACKEND_FAILED;
@ -510,7 +499,7 @@ top:
cmdbuf[1] = 0x62;
cmdbuf[2] = job->hdr.lam_strength;
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
cmdbuf, CMDBUF_LEN)))
return CUPS_BACKEND_FAILED;
@ -520,7 +509,7 @@ top:
cmdbuf[1] = 0x61;
cmdbuf[2] = job->hdr.unk1; // ???
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
cmdbuf, CMDBUF_LEN)))
return CUPS_BACKEND_FAILED;
@ -579,7 +568,7 @@ top:
cmdbuf[2] = 0x00;
cmdbuf[3] = 0x50;
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
cmdbuf, CMDBUF_LEN)))
return CUPS_BACKEND_FAILED;
@ -633,7 +622,7 @@ static const char *kodak1400_prefixes[] = {
struct dyesub_backend kodak1400_backend = {
.name = "Kodak 1400/805",
.version = "0.40",
.version = "0.41",
.uri_prefixes = kodak1400_prefixes,
.cmdline_usage = kodak1400_cmdline,
.cmdline_arg = kodak1400_cmdline_arg,

View File

@ -357,19 +357,14 @@ static void *kodak605_init(void)
return ctx;
}
static int kodak605_attach(void *vctx, struct libusb_device_handle *dev, int type,
uint8_t endp_up, uint8_t endp_down, int iface, uint8_t jobid)
static int kodak605_attach(void *vctx, struct dyesub_connection *conn, uint8_t jobid)
{
struct kodak605_ctx *ctx = vctx;
ctx->dev.dev = dev;
ctx->dev.endp_up = endp_up;
ctx->dev.endp_down = endp_down;
ctx->dev.type = type;
ctx->dev.iface = iface;
ctx->dev.conn = conn;
ctx->dev.error_codes = &error_codes;
if (ctx->dev.type != P_KODAK_605) {
if (ctx->dev.conn->type != P_KODAK_605) {
ctx->dev.params = ek7000_params;
ctx->dev.params_count = ek7000_params_num;
}
@ -601,7 +596,7 @@ retry_print:
}
INFO("Sending image data\n");
if ((ret = send_data(ctx->dev.dev, ctx->dev.endp_down,
if ((ret = send_data(ctx->dev.conn,
job->databuf + offset, job->datalen - offset)))
return CUPS_BACKEND_FAILED;
@ -830,7 +825,7 @@ static int kodak605_query_stats(void *vctx, struct printerstats *stats)
if (kodak605_get_status(ctx, &status))
return CUPS_BACKEND_FAILED;
switch (ctx->dev.type) {
switch (ctx->dev.conn->type) {
case P_KODAK_605:
stats->mfg = "Kodak";
stats->model = "605";
@ -849,8 +844,7 @@ static int kodak605_query_stats(void *vctx, struct printerstats *stats)
break;
}
if (sinfonia_query_serno(ctx->dev.dev, ctx->dev.endp_up,
ctx->dev.endp_down, ctx->dev.iface,
if (sinfonia_query_serno(ctx->dev.conn,
ctx->serial, sizeof(ctx->serial)))
return CUPS_BACKEND_FAILED;
@ -900,7 +894,7 @@ static const char *kodak605_prefixes[] = {
/* Exported */
struct dyesub_backend kodak605_backend = {
.name = "Kodak 605/70xx",
.version = "0.54" " (lib " LIBSINFONIA_VER ")",
.version = "0.55" " (lib " LIBSINFONIA_VER ")",
.uri_prefixes = kodak605_prefixes,
.cmdline_usage = kodak605_cmdline,
.cmdline_arg = kodak605_cmdline_arg,
@ -910,6 +904,7 @@ struct dyesub_backend kodak605_backend = {
.read_parse = kodak605_read_parse,
.main_loop = kodak605_main_loop,
.query_markers = kodak605_query_markers,
.query_serno = sinfonia_query_serno,
.query_stats = kodak605_query_stats,
.devices = {
{ USB_VID_KODAK, USB_PID_KODAK_605, P_KODAK_605, "Kodak", "kodak-605"},

View File

@ -91,12 +91,8 @@ struct kodak68x0_media_readback {
/* Private data structure */
struct kodak6800_ctx {
struct libusb_device_handle *dev;
int iface;
uint8_t endp_up;
uint8_t endp_down;
struct dyesub_connection *conn;
int type;
int supports_sub4x6;
uint8_t jobid;
@ -122,12 +118,12 @@ static int kodak6800_do_cmd(struct kodak6800_ctx *ctx,
int ret;
/* Write command */
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
cmd, cmd_len)))
return (ret < 0) ? ret : -99;
/* Read response */
ret = read_data(ctx->dev, ctx->endp_up,
ret = read_data(ctx->conn,
resp, resp_len, actual_len);
if (ret < 0)
return ret;
@ -314,7 +310,7 @@ static void kodak68x0_dump_status(struct kodak6800_ctx *ctx, struct kodak68x0_st
INFO("\tThermal Head : %u\n", be32_to_cpu(status->maint));
INFO("\tCutter : %u\n", be32_to_cpu(status->cutter));
if (ctx->type == P_KODAK_6850) {
if (ctx->conn->type == P_KODAK_6850) {
int max = kodak6_mediamax(ctx->media_type);
INFO("\tMedia : %u\n", be32_to_cpu(status->media));
@ -541,13 +537,10 @@ done:
return ret;
}
static int kodak6800_query_serno(struct libusb_device_handle *dev, uint8_t endp_up, uint8_t endp_down, int iface, char *buf, int buf_len)
static int kodak6800_query_serno(struct dyesub_connection *conn, char *buf, int buf_len)
{
struct kodak6800_ctx ctx = {
.dev = dev,
.endp_up = endp_up,
.endp_down = endp_down,
.iface = iface,
.conn = conn,
};
int ret;
@ -679,16 +672,11 @@ static void *kodak6800_init(void)
return ctx;
}
static int kodak6800_attach(void *vctx, struct libusb_device_handle *dev, int type,
uint8_t endp_up, uint8_t endp_down, int iface, uint8_t jobid)
static int kodak6800_attach(void *vctx, struct dyesub_connection *conn, uint8_t jobid)
{
struct kodak6800_ctx *ctx = vctx;
ctx->dev = dev;
ctx->endp_up = endp_up;
ctx->endp_down = endp_down;
ctx->iface = iface;
ctx->type = type;
ctx->conn = conn;
/* Ensure jobid is sane */
ctx->jobid = jobid & 0x7f;
@ -702,7 +690,7 @@ static int kodak6800_attach(void *vctx, struct libusb_device_handle *dev, int ty
return CUPS_BACKEND_FAILED;
}
uint16_t fw = be16_to_cpu(ctx->sts.main_fw);
if (ctx->type == P_KODAK_6850) {
if (ctx->conn->type == P_KODAK_6850) {
if ((fw >= 878) ||
(fw < 800 && fw >= 678)) {
ctx->supports_sub4x6 = 1;
@ -933,7 +921,7 @@ static int kodak6800_main_loop(void *vctx, const void *vjob) {
}
/* This command is unknown, sort of a secondary status query */
if (ctx->type == P_KODAK_6850) {
if (ctx->conn->type == P_KODAK_6850) {
ret = kodak6850_send_unk(ctx);
if (ret)
return ret;
@ -968,7 +956,7 @@ static int kodak6800_main_loop(void *vctx, const void *vjob) {
// sleep(1); // Appears to be necessary for reliability
INFO("Sending image data\n");
if ((send_data(ctx->dev, ctx->endp_down,
if ((send_data(ctx->conn,
job->databuf, job->datalen)) != 0)
return CUPS_BACKEND_FAILED;
@ -1031,7 +1019,7 @@ static int kodak6800_query_stats(void *vctx, struct printerstats *stats)
if (kodak6800_query_markers(ctx, NULL, NULL))
return CUPS_BACKEND_FAILED;
switch (ctx->type) {
switch (ctx->conn->type) {
case P_KODAK_6800:
stats->mfg = "Kodak";
stats->model = "6800";
@ -1046,8 +1034,7 @@ static int kodak6800_query_stats(void *vctx, struct printerstats *stats)
break;
}
if (kodak6800_query_serno(ctx->dev, ctx->endp_up,
ctx->endp_down, ctx->iface,
if (kodak6800_query_serno(ctx->conn,
ctx->serial, sizeof(ctx->serial)))
return CUPS_BACKEND_FAILED;
@ -1079,7 +1066,7 @@ static const char *kodak6800_prefixes[] = {
/* Exported */
struct dyesub_backend kodak6800_backend = {
.name = "Kodak 6800/6850",
.version = "0.79" " (lib " LIBSINFONIA_VER ")",
.version = "0.80" " (lib " LIBSINFONIA_VER ")",
.uri_prefixes = kodak6800_prefixes,
.cmdline_usage = kodak6800_cmdline,
.cmdline_arg = kodak6800_cmdline_arg,

View File

@ -106,11 +106,7 @@ struct magicard_printjob {
/* Private data structure */
struct magicard_ctx {
struct libusb_device_handle *dev;
uint8_t endp_up;
uint8_t endp_down;
int type;
struct dyesub_connection *conn;
struct marker marker;
};
@ -254,13 +250,13 @@ static int magicard_query_sensors(struct magicard_ctx *ctx)
snprintf(buf2, sizeof(buf2), "SNR%d", i);
ret = magicard_build_cmd_simple(buf, buf2);
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
buf, ret)))
return ret;
memset(buf, 0, sizeof(buf));
ret = read_data(ctx->dev, ctx->endp_up,
ret = read_data(ctx->conn,
buf, sizeof(buf), &num);
if (ret < 0)
@ -282,7 +278,7 @@ static int magicard_selftest_card(struct magicard_ctx *ctx)
ret = magicard_build_cmd_simple(buf, "TST,");
ret = send_data(ctx->dev, ctx->endp_down,
ret = send_data(ctx->conn,
buf, ret);
return ret;
}
@ -294,7 +290,7 @@ static int magicard_reset(struct magicard_ctx *ctx)
ret = magicard_build_cmd_simple(buf, "RST,");
ret = send_data(ctx->dev, ctx->endp_down,
ret = send_data(ctx->conn,
buf, ret);
return ret;
}
@ -306,7 +302,7 @@ static int magicard_eject(struct magicard_ctx *ctx)
ret = magicard_build_cmd_simple(buf, "EJT,");
ret = send_data(ctx->dev, ctx->endp_down,
ret = send_data(ctx->conn,
buf, ret);
return ret;
}
@ -324,13 +320,13 @@ static int magicard_query_printer(struct magicard_ctx *ctx)
snprintf(buf2, sizeof(buf2), "QPR%d", i);
ret = magicard_build_cmd_simple(buf, buf2);
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
buf, ret)))
return ret;
memset(buf, 0, sizeof(buf));
ret = read_data(ctx->dev, ctx->endp_up,
ret = read_data(ctx->conn,
buf, sizeof(buf), &num);
if (ret < 0)
@ -362,13 +358,13 @@ static int magicard_query_status(struct magicard_ctx *ctx)
ret = magicard_build_cmd(buf, "REQ", "STA",
magicard_sta_requests[i].key);
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
buf, ret)))
return ret;
memset(buf, 0, sizeof(buf));
ret = read_data(ctx->dev, ctx->endp_up,
ret = read_data(ctx->conn,
buf, sizeof(buf), &num);
if (ret < 0)
@ -433,18 +429,13 @@ static void* magicard_init(void)
return ctx;
}
static int magicard_attach(void *vctx, struct libusb_device_handle *dev, int type,
uint8_t endp_up, uint8_t endp_down, int iface, uint8_t jobid)
static int magicard_attach(void *vctx, struct dyesub_connection *conn, uint8_t jobid)
{
struct magicard_ctx *ctx = vctx;
UNUSED(jobid);
UNUSED(iface);
ctx->dev = dev;
ctx->endp_up = endp_up;
ctx->endp_down = endp_down;
ctx->type = type;
ctx->conn = conn;
ctx->marker.color = "#00FFFF#FF00FF#FFFF00"; // XXX YMCK too!
ctx->marker.name = "Unknown"; // LC1/LC3/LC6/LC8
@ -848,11 +839,11 @@ static int magicard_main_loop(void *vctx, const void *vjob) {
copies = job->copies;
top:
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
job->databuf, job->hdr_len)))
return CUPS_BACKEND_FAILED;
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
job->databuf + job->hdr_len, job->datalen - job->hdr_len)))
return CUPS_BACKEND_FAILED;
@ -935,7 +926,7 @@ static const char *magicard_prefixes[] = {
struct dyesub_backend magicard_backend = {
.name = "Magicard family",
.version = "0.16",
.version = "0.17",
.uri_prefixes = magicard_prefixes,
.cmdline_arg = magicard_cmdline_arg,
.cmdline_usage = magicard_cmdline,

View File

@ -76,10 +76,8 @@ struct mitsu70x_printjob {
};
struct mitsu70x_ctx {
struct libusb_device_handle *dev;
uint8_t endp_up;
uint8_t endp_down;
int type;
struct dyesub_connection *conn;
int is_s;
uint16_t jobid;
@ -574,27 +572,21 @@ static void *mitsu70x_init(void)
return ctx;
}
static int mitsu70x_attach(void *vctx, struct libusb_device_handle *dev, int type,
uint8_t endp_up, uint8_t endp_down, int iface, uint8_t jobid)
static int mitsu70x_attach(void *vctx, struct dyesub_connection *conn, uint8_t jobid)
{
struct mitsu70x_ctx *ctx = vctx;
UNUSED(iface);
ctx->jobid = jobid;
if (!ctx->jobid)
jobid++;
ctx->dev = dev;
ctx->endp_up = endp_up;
ctx->endp_down = endp_down;
ctx->type = type;
ctx->conn = conn;
ctx->last_l = ctx->last_u = 65535;
#if defined(WITH_DYNAMIC)
/* Attempt to open the library */
if (mitsu_loadlib(&ctx->lib, ctx->type))
if (mitsu_loadlib(&ctx->lib, ctx->conn->type))
#endif
WARNING("Dynamic library support not loaded, will be unable to print.");
@ -627,7 +619,7 @@ static int mitsu70x_attach(void *vctx, struct libusb_device_handle *dev, int typ
}
/* Figure out if we're a D707 with two decks */
if (ctx->type == P_MITSU_D70X &&
if (ctx->conn->type == P_MITSU_D70X &&
resp.dual_deck == 0x80)
ctx->num_decks = 2;
else
@ -635,7 +627,7 @@ static int mitsu70x_attach(void *vctx, struct libusb_device_handle *dev, int typ
/* Set up markers */
ctx->marker[0].color = "#00FFFF#FF00FF#FFFF00";
ctx->marker[0].name = mitsu_media_types(ctx->type, resp.lower.media_brand, resp.lower.media_type);
ctx->marker[0].name = mitsu_media_types(ctx->conn->type, resp.lower.media_brand, resp.lower.media_type);
ctx->marker[0].numtype = resp.lower.media_type;
ctx->marker[0].levelmax = be16_to_cpu(resp.lower.capacity);
ctx->marker[0].levelnow = be16_to_cpu(resp.lower.remain);
@ -643,7 +635,7 @@ static int mitsu70x_attach(void *vctx, struct libusb_device_handle *dev, int typ
if (ctx->num_decks == 2) {
ctx->marker[1].color = "#00FFFF#FF00FF#FFFF00";
ctx->marker[1].name = mitsu_media_types(ctx->type, resp.upper.media_brand, resp.upper.media_type);
ctx->marker[1].name = mitsu_media_types(ctx->conn->type, resp.upper.media_brand, resp.upper.media_type);
ctx->marker[1].numtype = resp.upper.media_type;
ctx->marker[1].levelmax = be16_to_cpu(resp.upper.capacity);
ctx->marker[1].levelnow = be16_to_cpu(resp.upper.remain);
@ -660,13 +652,13 @@ static int mitsu70x_attach(void *vctx, struct libusb_device_handle *dev, int typ
ctx->serno[6] = 0;
/* Check for the -S variants */
if (ctx->type == P_MITSU_K60)
if (ctx->conn->type == P_MITSU_K60)
ctx->is_s = 1;
if (ctx->type == P_MITSU_D70X && resp.unk_c[2] == 0x5e)
if (ctx->conn->type == P_MITSU_D70X && resp.unk_c[2] == 0x5e)
ctx->is_s = 1;
/* FW sanity checking */
if (ctx->type == P_KODAK_305) {
if (ctx->conn->type == P_KODAK_305) {
/* Known versions:
v1.02: M 316E81 1433 (Add Ultrafine and matte support)
v1.04: M 316F83 2878 (Add 2x6 strip and support new "Triton" media)
@ -674,13 +666,13 @@ static int mitsu70x_attach(void *vctx, struct libusb_device_handle *dev, int typ
*/
if (strncmp(resp.vers[0].ver, "443A12", 6) < 0)
WARNING("Printer FW out of date. Highly recommend upgrading EK305 to v3.01 or newer!\n");
} else if (ctx->type == P_MITSU_K60) {
} else if (ctx->conn->type == P_MITSU_K60) {
/* Known versions:
v1.05: M 316M31 148C (Add HG media support)
*/
if (strncmp(resp.vers[0].ver, "316M31", 6) < 0)
WARNING("Printer FW out of date. Highly recommend upgrading K60 to v1.05 or newer!\n");
} else if (ctx->type == P_MITSU_D70X) {
} else if (ctx->conn->type == P_MITSU_D70X) {
/* Known versions for D70/D707:
v1.10: M 316V11 064D (Add ultrafine mode, 6x6 support, 2x6 strip, and more?)
v1.12: M 316W11 9FC3 (??)
@ -691,7 +683,7 @@ static int mitsu70x_attach(void *vctx, struct libusb_device_handle *dev, int typ
*/
if (strncmp(resp.vers[0].ver, "316W11", 6) < 0)
WARNING("Printer FW out of date. Highly recommend upgrading D70/D707 to v1.12 or newer!\n");
} else if (ctx->type == P_FUJI_ASK300) {
} else if (ctx->conn->type == P_FUJI_ASK300) {
/* Known versions:
v?.??: M 316A21 7998 (ancient. no matte or ultrafine)
v?.??: M 316H21 F8EB
@ -919,7 +911,7 @@ repeat:
/* Sanity check Matte mode */
if (!mhdr.laminate && mhdr.laminate_mode) {
if (ctx->type != P_MITSU_D70X) {
if (ctx->conn->type != P_MITSU_D70X) {
if (mhdr.speed != 0x03 && mhdr.speed != 0x04) {
WARNING("Forcing Ultrafine mode for matte printing!\n");
mhdr.speed = 0x04; /* Force UltraFine */
@ -933,7 +925,7 @@ repeat:
}
/* Figure out the correction data table to use */
if (ctx->type == P_MITSU_D70X) {
if (ctx->conn->type == P_MITSU_D70X) {
job->laminatefname = "D70MAT01.raw";
job->lutfname = "CPD70L01.lut";
@ -951,7 +943,7 @@ repeat:
WARNING("Print job has wrong submodel specifier (%x)\n", mhdr.hdr[3]);
mhdr.hdr[3] = 0x01;
}
} else if (ctx->type == P_MITSU_D80) {
} else if (ctx->conn->type == P_MITSU_D80) {
job->laminatefname = "D80MAT01.raw";
job->lutfname = "CPD80L01.lut";
@ -969,7 +961,7 @@ repeat:
WARNING("Print job has wrong submodel specifier (%x)\n", mhdr.hdr[3]);
mhdr.hdr[3] = 0x01;
}
} else if (ctx->type == P_MITSU_K60) {
} else if (ctx->conn->type == P_MITSU_K60) {
job->laminatefname = "S60MAT02.raw";
job->lutfname = "CPS60L01.lut";
@ -983,7 +975,7 @@ repeat:
WARNING("Print job has wrong submodel specifier (%x)\n", mhdr.hdr[3]);
mhdr.hdr[3] = 0x00;
}
} else if (ctx->type == P_KODAK_305) {
} else if (ctx->conn->type == P_KODAK_305) {
job->laminatefname = "EK305MAT.raw"; // Same as K60
job->lutfname = "EK305L01.lut";
@ -998,7 +990,7 @@ repeat:
WARNING("Print job has wrong submodel specifier (%x)\n", mhdr.hdr[3]);
mhdr.hdr[3] = 0x90;
}
} else if (ctx->type == P_FUJI_ASK300) {
} else if (ctx->conn->type == P_FUJI_ASK300) {
job->laminatefname = "ASK300M2.raw"; /* Same as D70 */
job->lutfname = NULL; /* Printer does not come with external LUT */
if (mhdr.speed == 3 || mhdr.speed == 4) {
@ -1182,8 +1174,8 @@ bypass_raw:
ctx->medias[1] == 0x5)
job->can_combine = !job->raw_format;
} else if (job->rows == 1076) {
if (ctx->type == P_KODAK_305 ||
ctx->type == P_MITSU_K60) {
if (ctx->conn->type == P_KODAK_305 ||
ctx->conn->type == P_MITSU_K60) {
if (ctx->medias[0] == 0x4) /* Only one deck */
job->can_combine = !job->raw_format;
}
@ -1210,13 +1202,13 @@ static int mitsu70x_get_jobstatus(struct mitsu70x_ctx *ctx, struct mitsu70x_jobs
cmdbuf[4] = (jobid >> 8) & 0xff;
cmdbuf[5] = jobid & 0xff;
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
cmdbuf, 6)))
return ret;
memset(resp, 0, sizeof(*resp));
ret = read_data(ctx->dev, ctx->endp_up,
ret = read_data(ctx->conn,
(uint8_t*) resp, sizeof(*resp), &num);
if (ret < 0)
@ -1244,13 +1236,13 @@ static int mitsu70x_get_jobs(struct mitsu70x_ctx *ctx, struct mitsu70x_jobs *res
cmdbuf[4] = 0x00;
cmdbuf[5] = 0x00;
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
cmdbuf, 6)))
return ret;
memset(resp, 0, sizeof(*resp));
ret = read_data(ctx->dev, ctx->endp_up,
ret = read_data(ctx->conn,
(uint8_t*) resp, sizeof(*resp), &num);
if (ret < 0)
@ -1285,8 +1277,8 @@ static int mitsu70x_get_memorystatus(struct mitsu70x_ctx *ctx, const struct mits
// XXX what about type4 (2x6*4) and type3 (3x6*3)
tmp = job->rows;
if (tmp == 2730 && mcut == 1) {
if (ctx->type == P_MITSU_D70X ||
ctx->type == P_FUJI_ASK300) {
if (ctx->conn->type == P_MITSU_D70X ||
ctx->conn->type == P_FUJI_ASK300) {
tmp = 2422;
}
}
@ -1296,12 +1288,12 @@ static int mitsu70x_get_memorystatus(struct mitsu70x_ctx *ctx, const struct mits
cmdbuf[8] = job->matte ? 0x80 : 0x00;
cmdbuf[9] = 0x00;
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
cmdbuf, 10)))
return CUPS_BACKEND_FAILED;
/* Read in the printer status */
ret = read_data(ctx->dev, ctx->endp_up,
ret = read_data(ctx->conn,
(uint8_t*) resp, sizeof(*resp), &num);
if (ret < 0)
return CUPS_BACKEND_FAILED;
@ -1334,11 +1326,11 @@ static int mitsu70x_get_printerstatus(struct mitsu70x_ctx *ctx, struct mitsu70x_
cmdbuf[2] = 0x32;
cmdbuf[3] = 0x30; /* or x31 or x32, for SINGLE DECK query!
Results will only have one deck. */
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
cmdbuf, 4)))
return ret;
memset(resp, 0, sizeof(*resp));
ret = read_data(ctx->dev, ctx->endp_up,
ret = read_data(ctx->conn,
(uint8_t*) resp, sizeof(*resp), &num);
if (ret < 0)
@ -1362,7 +1354,7 @@ static int mitsu70x_cancel_job(struct mitsu70x_ctx *ctx, uint16_t jobid)
cmdbuf[1] = 0x44;
cmdbuf[2] = (jobid >> 8) & 0xff;
cmdbuf[3] = jobid & 0xff;
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
cmdbuf, 4)))
return ret;
@ -1385,7 +1377,7 @@ static int mitsu70x_set_sleeptime(struct mitsu70x_ctx *ctx, uint8_t time)
cmdbuf[2] = 0x53;
cmdbuf[3] = time;
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
cmdbuf, 4)))
return ret;
@ -1409,7 +1401,7 @@ static int mitsu70x_set_iserial(struct mitsu70x_ctx *ctx, uint8_t enabled)
cmdbuf[2] = 0x4e;
cmdbuf[3] = enabled;
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
cmdbuf, 4)))
return ret;
@ -1438,7 +1430,7 @@ static int mitsu70x_set_printermode(struct mitsu70x_ctx *ctx, uint8_t enabled)
cmdbuf[2] = 0x50;
cmdbuf[3] = enabled;
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
cmdbuf, 4)))
return ret;
@ -1468,7 +1460,7 @@ top:
buf[2] = 0x57; // XXX also, 0x53, 0x54 seen.
buf[3] = 0x55;
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
buf, sizeof(buf))))
return CUPS_BACKEND_FAILED;
@ -1494,7 +1486,7 @@ static int d70_library_callback(void *context, void *buffer, uint32_t len)
if (chunk > CHUNK_LEN)
chunk = CHUNK_LEN;
ret = send_data(ctx->dev, ctx->endp_down, (uint8_t*)buffer + offset, chunk);
ret = send_data(ctx->conn, (uint8_t*)buffer + offset, chunk);
if (ret < 0)
break;
@ -1593,7 +1585,7 @@ static int mitsu70x_main_loop(void *vctx, const void *vjob)
}
/* Twiddle rewind stuff if needed */
if (ctx->type != P_MITSU_D70X) {
if (ctx->conn->type != P_MITSU_D70X) {
hdr->rewind[0] = !rew[0];
hdr->rewind[1] = !rew[1];
DEBUG("Rewind Inhibit? %02x %02x\n", hdr->rewind[0], hdr->rewind[1]);
@ -1643,7 +1635,7 @@ top:
This should be in the main loop due to copy retries */
/* First, try to respect requested deck */
if (ctx->type == P_MITSU_D70X) {
if (ctx->conn->type == P_MITSU_D70X) {
deck = reqdeck; /* Respect D70 deck choice, 0 is automatic. */
} else {
deck = 1; /* All others have one deck only */
@ -1811,7 +1803,7 @@ top:
hdr->deck = deck;
/* K60 and EK305 need the mcut type 1 specified for 4x6 prints! */
if ((ctx->type == P_MITSU_K60 || ctx->type == P_KODAK_305) &&
if ((ctx->conn->type == P_MITSU_K60 || ctx->conn->type == P_KODAK_305) &&
job->cols == 0x0748 &&
job->rows == 0x04c2 && !hdr->multicut) {
hdr->multicut = 1;
@ -1820,7 +1812,7 @@ top:
/* We're clear to send data over! */
INFO("Sending Print Job (internal id %u)\n", ctx->jobid);
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
job->databuf,
sizeof(struct mitsu70x_hdr))))
return CUPS_BACKEND_FAILED;
@ -1839,7 +1831,7 @@ top:
int chunk = CHUNK_LEN - sizeof(struct mitsu70x_hdr);
int sent = 512;
while (chunk > 0) {
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
job->databuf + sent, chunk)))
return CUPS_BACKEND_FAILED;
sent += chunk;
@ -2026,7 +2018,7 @@ static void mitsu70x_dump_printerstatus(struct mitsu70x_ctx *ctx,
INFO("Lower Mechanical Status: %s\n",
mitsu70x_mechastatus(resp->lower.mecha_status));
INFO("Lower Media Type: %s (%02x/%02x)\n",
mitsu_media_types(ctx->type, resp->lower.media_brand, resp->lower.media_type),
mitsu_media_types(ctx->conn->type, resp->lower.media_brand, resp->lower.media_type),
resp->lower.media_brand,
resp->lower.media_type);
INFO("Lower Prints Remaining: %03d/%03d\n",
@ -2048,7 +2040,7 @@ static void mitsu70x_dump_printerstatus(struct mitsu70x_ctx *ctx,
INFO("Upper Mechanical Status: %s\n",
mitsu70x_mechastatus(resp->upper.mecha_status));
INFO("Upper Media Type: %s (%02x/%02x)\n",
mitsu_media_types(ctx->type, resp->upper.media_brand, resp->upper.media_type),
mitsu_media_types(ctx->conn->type, resp->upper.media_brand, resp->upper.media_type),
resp->upper.media_brand,
resp->upper.media_type);
INFO("Upper Prints Remaining: %03d/%03d\n",
@ -2141,17 +2133,14 @@ static int mitsu70x_query_status(struct mitsu70x_ctx *ctx)
return ret;
}
static int mitsu70x_query_serno(struct libusb_device_handle *dev, uint8_t endp_up, uint8_t endp_down, int iface, char *buf, int buf_len)
static int mitsu70x_query_serno(struct dyesub_connection *conn, char *buf, int buf_len)
{
int ret, i;
struct mitsu70x_printerstatus_resp resp = { .hdr = { 0 } };
struct mitsu70x_ctx ctx = {
.dev = dev,
.endp_up = endp_up,
.endp_down = endp_down,
.conn = conn,
};
UNUSED(iface);
ret = mitsu70x_get_printerstatus(&ctx, &resp);
@ -2266,8 +2255,8 @@ static int mitsu70x_job_polarity(void *vctx)
return 0;
/* D70x and ASK300 don't support rewinding */
if (ctx->type == P_MITSU_D70X ||
ctx->type == P_FUJI_ASK300)
if (ctx->conn->type == P_MITSU_D70X ||
ctx->conn->type == P_FUJI_ASK300)
return 0;
/* All others do, and only have one deck */
@ -2285,7 +2274,7 @@ static int mitsu70x_query_stats(void *vctx, struct printerstats *stats)
if (mitsu70x_get_printerstatus(ctx, &resp))
return CUPS_BACKEND_FAILED;
switch (ctx->type) {
switch (ctx->conn->type) {
case P_MITSU_D70X:
stats->mfg = "Mitsubishi";
if (ctx->num_decks == 2)
@ -2347,7 +2336,7 @@ static const char *mitsu70x_prefixes[] = {
/* Exported */
struct dyesub_backend mitsu70x_backend = {
.name = "Mitsubishi CP-D70 family",
.version = "0.99" " (lib " LIBMITSU_VER ")",
.version = "0.100" " (lib " LIBMITSU_VER ")",
.flags = BACKEND_FLAG_DUMMYPRINT,
.uri_prefixes = mitsu70x_prefixes,
.cmdline_usage = mitsu70x_cmdline,

View File

@ -129,10 +129,8 @@ struct mitsu9550_printjob {
};
struct mitsu9550_ctx {
struct libusb_device_handle *dev;
uint8_t endp_up;
uint8_t endp_down;
int type;
struct dyesub_connection *conn;
int is_s;
int is_98xx;
int footer_len;
@ -207,7 +205,7 @@ static int mitsu9550_main_loop(void *vctx, const void *vjob);
ERROR("Printer out of media!\n"); \
return CUPS_BACKEND_HOLD; \
} \
if (validate_media(ctx->type, media->type, job->cols, job->rows)) { \
if (validate_media(ctx->conn->type, media->type, job->cols, job->rows)) { \
ERROR("Incorrect media (%u) type for printjob (%ux%u)!\n", media->type, job->cols, job->rows); \
return CUPS_BACKEND_HOLD; \
} \
@ -278,27 +276,22 @@ static void *mitsu9550_init(void)
return ctx;
}
static int mitsu9550_attach(void *vctx, struct libusb_device_handle *dev, int type,
uint8_t endp_up, uint8_t endp_down, int iface, uint8_t jobid)
static int mitsu9550_attach(void *vctx, struct dyesub_connection *conn, uint8_t jobid)
{
struct mitsu9550_ctx *ctx = vctx;
struct mitsu9550_media media;
UNUSED(jobid);
UNUSED(iface);
ctx->dev = dev;
ctx->endp_up = endp_up;
ctx->endp_down = endp_down;
ctx->type = type;
ctx->conn = conn;
if (ctx->type == P_MITSU_9550S ||
ctx->type == P_MITSU_9800S)
if (ctx->conn->type == P_MITSU_9550S ||
ctx->conn->type == P_MITSU_9800S)
ctx->is_s = 1;
if (ctx->type == P_MITSU_9800 ||
ctx->type == P_MITSU_9800S ||
ctx->type == P_MITSU_9810) {
if (ctx->conn->type == P_MITSU_9800 ||
ctx->conn->type == P_MITSU_9800S ||
ctx->conn->type == P_MITSU_9810) {
ctx->is_98xx = 1;
ctx->lut_fname = MITSU_M98xx_LUT_FILE;
}
@ -306,12 +299,12 @@ static int mitsu9550_attach(void *vctx, struct libusb_device_handle *dev, int ty
if (ctx->is_98xx) {
#if defined(WITH_DYNAMIC)
/* Attempt to open the library */
if (mitsu_loadlib(&ctx->lib, ctx->type))
if (mitsu_loadlib(&ctx->lib, ctx->conn->type))
#endif
WARNING("Dynamic library support not loaded, will be unable to print.");
}
if (ctx->type == P_MITSU_CP30D) {
if (ctx->conn->type == P_MITSU_CP30D) {
ctx->footer_len = 6;
ctx->lut_fname = MITSU_CP30D_LUT_FILE;
} else {
@ -489,13 +482,13 @@ hdr_done:
}
/* Mitsu9600 windows spool uses more, smaller blocks, but plane data is the same */
if (ctx->type == P_MITSU_9600) {
if (ctx->conn->type == P_MITSU_9600) {
remain += 128 * sizeof(struct mitsu9550_plane); /* 39 extra seen on 4x6" */
}
/* 9550S/9800S doesn't typically sent over hdr4! */
if (ctx->type == P_MITSU_9550S ||
ctx->type == P_MITSU_9800S) {
if (ctx->conn->type == P_MITSU_9550S ||
ctx->conn->type == P_MITSU_9800S) {
/* XXX Has to do with error policy, but not sure what.
Mitsu9550-S/9800-S will set this based on a command,
but it's not part of the standard job spool */
@ -504,7 +497,7 @@ hdr_done:
/* Disable matte if the printer doesn't support it */
if (job->hdr1.matte) {
if (ctx->type != P_MITSU_9810) {
if (ctx->conn->type != P_MITSU_9810) {
WARNING("Matte not supported on this printer, disabling\n");
job->hdr1.matte = 0;
} else if (job->is_raw) {
@ -657,10 +650,10 @@ static int mitsu9550_get_status(struct mitsu9550_ctx *ctx, uint8_t *resp, int st
else if (media)
cmd.cmd[2] = 0x24;
cmd.cmd[3] = 0x00;
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
(uint8_t*) &cmd, sizeof(cmd))))
return ret;
ret = read_data(ctx->dev, ctx->endp_up,
ret = read_data(ctx->conn,
resp, sizeof(struct mitsu9550_status), &num);
if (ret < 0)
@ -1054,7 +1047,7 @@ top:
cmd.cmd[1] = 0x53;
cmd.cmd[2] = 0xc5;
cmd.cmd[3] = 0x9d;
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
(uint8_t*) &cmd, sizeof(cmd))))
return CUPS_BACKEND_FAILED;
@ -1063,18 +1056,18 @@ top:
cmd.cmd[1] = 0x4b;
cmd.cmd[2] = 0x7f;
cmd.cmd[3] = 0x00;
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
(uint8_t*) &cmd, sizeof(cmd))))
return CUPS_BACKEND_FAILED;
ret = read_data(ctx->dev, ctx->endp_up,
ret = read_data(ctx->conn,
rdbuf, READBACK_LEN, &num);
if (ret < 0)
return CUPS_BACKEND_FAILED;
// seen so far: eb 4b 7f 00 02 00 5e
}
if (ctx->type == P_MITSU_9800S) {
if (ctx->conn->type == P_MITSU_9800S) {
int num;
/* Send "unknown 3" command */
@ -1082,11 +1075,11 @@ top:
cmd.cmd[1] = 0x4b;
cmd.cmd[2] = 0x01;
cmd.cmd[3] = 0x00;
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
(uint8_t*) &cmd, sizeof(cmd))))
return CUPS_BACKEND_FAILED;
ret = read_data(ctx->dev, ctx->endp_up,
ret = read_data(ctx->conn,
rdbuf, READBACK_LEN, &num);
if (ret < 0)
return CUPS_BACKEND_FAILED;
@ -1101,19 +1094,19 @@ top:
/* Send printjob headers from spool data */
if (job->hdr1_present)
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
(uint8_t*) &job->hdr1, sizeof(job->hdr1))))
return CUPS_BACKEND_FAILED;
if (job->hdr2_present)
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
(uint8_t*) &job->hdr2, sizeof(job->hdr2))))
return CUPS_BACKEND_FAILED;
if (job->hdr3_present)
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
(uint8_t*) &job->hdr3, sizeof(job->hdr3))))
return CUPS_BACKEND_FAILED;
if (job->hdr4_present)
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
(uint8_t*) &job->hdr4, sizeof(struct mitsu9550_hdr4))))
return CUPS_BACKEND_FAILED;
@ -1124,7 +1117,7 @@ top:
cmd.cmd[2] = 0x43;
cmd.cmd[3] = 0x00;
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
(uint8_t*) &cmd, sizeof(cmd))))
return CUPS_BACKEND_FAILED;
}
@ -1141,11 +1134,11 @@ top:
if (plane->cmd[3] == 0x10)
planelen *= 2;
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
(uint8_t*) ptr, sizeof(struct mitsu9550_plane))))
return CUPS_BACKEND_FAILED;
ptr += sizeof(struct mitsu9550_plane);
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
(uint8_t*) ptr, planelen)))
return CUPS_BACKEND_FAILED;
ptr += planelen;
@ -1197,27 +1190,27 @@ top:
}
/* Send "end data" command */
if (ctx->type == P_MITSU_9550S) {
if (ctx->conn->type == P_MITSU_9550S) {
/* Override spool, which may be wrong */
cmd.cmd[0] = 0x1b;
cmd.cmd[1] = 0x50;
cmd.cmd[2] = 0x47;
cmd.cmd[3] = 0x00;
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
(uint8_t*) &cmd, sizeof(cmd))))
return CUPS_BACKEND_FAILED;
} else if (ctx->type == P_MITSU_9800S) {
} else if (ctx->conn->type == P_MITSU_9800S) {
/* Override spool, which may be wrong */
cmd.cmd[0] = 0x1b;
cmd.cmd[1] = 0x50;
cmd.cmd[2] = 0x4e;
cmd.cmd[3] = 0x00;
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
(uint8_t*) &cmd, sizeof(cmd))))
return CUPS_BACKEND_FAILED;
} else {
/* Send from spool file */
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
ptr, ctx->footer_len)))
return CUPS_BACKEND_FAILED;
ptr += ctx->footer_len;
@ -1232,17 +1225,17 @@ top:
planelen *= 2;
// XXX include a status loop here too?
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
(uint8_t*) ptr, sizeof(struct mitsu9550_plane))))
return CUPS_BACKEND_FAILED;
ptr += sizeof(struct mitsu9550_plane);
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
(uint8_t*) ptr, planelen)))
return CUPS_BACKEND_FAILED;
ptr += planelen;
/* Send "lamination end data" command from spool file */
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
ptr, sizeof(cmd))))
return CUPS_BACKEND_FAILED;
// ptr += sizeof(cmd);
@ -1368,25 +1361,23 @@ static int mitsu9550_query_status2(struct mitsu9550_ctx *ctx)
return ret;
}
static int mitsu9550_query_serno(struct libusb_device_handle *dev, uint8_t endp_up, uint8_t endp_down, int iface, char *buf, int buf_len)
static int mitsu9550_query_serno(struct dyesub_connection *conn, char *buf, int buf_len)
{
struct mitsu9550_cmd cmd;
uint8_t rdbuf[READBACK_LEN];
uint8_t *ptr;
int ret, num, i;
UNUSED(iface);
cmd.cmd[0] = 0x1b;
cmd.cmd[1] = 0x72;
cmd.cmd[2] = 0x6e;
cmd.cmd[3] = 0x00;
if ((ret = send_data(dev, endp_down,
if ((ret = send_data(conn,
(uint8_t*) &cmd, sizeof(cmd))))
return (ret < 0) ? ret : CUPS_BACKEND_FAILED;
ret = read_data(dev, endp_up,
ret = read_data(conn,
rdbuf, READBACK_LEN, &num);
if (ret < 0)
@ -1428,7 +1419,7 @@ static int mitsu9550_cancel_job(struct mitsu9550_ctx *ctx)
int ret;
uint8_t buf[2] = { 0x1b, 0x44 };
ret = send_data(ctx->dev, ctx->endp_down, buf, sizeof(buf));
ret = send_data(ctx->conn, buf, sizeof(buf));
return ret;
}
@ -1499,7 +1490,7 @@ static const char *mitsu9550_prefixes[] = {
/* Exported */
struct dyesub_backend mitsu9550_backend = {
.name = "Mitsubishi CP9xxx family",
.version = "0.55" " (lib " LIBMITSU_VER ")",
.version = "0.56" " (lib " LIBMITSU_VER ")",
.uri_prefixes = mitsu9550_prefixes,
.cmdline_usage = mitsu9550_cmdline,
.cmdline_arg = mitsu9550_cmdline_arg,

View File

@ -455,11 +455,8 @@ struct mitsud90_printjob {
};
struct mitsud90_ctx {
struct libusb_device_handle *dev;
uint8_t endp_up;
uint8_t endp_down;
struct dyesub_connection *conn;
int type;
char serno[7];
/* Used in parsing.. */
@ -486,12 +483,12 @@ static int mitsud90_query_media(struct mitsud90_ctx *ctx, struct mitsud90_media_
cmdbuf[6] = 0x01; /* Number of commands */
cmdbuf[7] = COM_STATUS_TYPE_MEDIA;
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
cmdbuf, sizeof(cmdbuf))))
return ret;
memset(resp, 0, sizeof(*resp));
ret = read_data(ctx->dev, ctx->endp_up,
ret = read_data(ctx->conn,
(uint8_t*) resp, sizeof(*resp), &num);
if (ret < 0)
@ -520,12 +517,12 @@ static int mitsud90_query_status(struct mitsud90_ctx *ctx, struct mitsud90_statu
cmdbuf[8] = COM_STATUS_TYPE_MECHA;
cmdbuf[9] = COM_STATUS_TYPE_TEMP;
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
cmdbuf, sizeof(cmdbuf))))
return ret;
memset(resp, 0, sizeof(*resp));
ret = read_data(ctx->dev, ctx->endp_up,
ret = read_data(ctx->conn,
(uint8_t*) resp, sizeof(*resp), &num);
if (ret < 0)
@ -569,11 +566,11 @@ static int mitsud90_get_serno(struct mitsud90_ctx *ctx)
cmdbuf[20] = 0xff;
cmdbuf[21] = 0xcf;
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
cmdbuf, 22)))
return ret;
ret = read_data(ctx->dev, ctx->endp_up,
ret = read_data(ctx->conn,
cmdbuf, sizeof(cmdbuf), &num);
/* Store it */
@ -597,19 +594,14 @@ static void *mitsud90_init(void)
return ctx;
}
static int mitsud90_attach(void *vctx, struct libusb_device_handle *dev, int type,
uint8_t endp_up, uint8_t endp_down, int iface, uint8_t jobid)
static int mitsud90_attach(void *vctx, struct dyesub_connection *conn, uint8_t jobid)
{
struct mitsud90_ctx *ctx = vctx;
struct mitsud90_media_resp resp;
UNUSED(jobid);
UNUSED(iface);
ctx->dev = dev;
ctx->endp_up = endp_up;
ctx->endp_down = endp_down;
ctx->type = type;
ctx->conn = conn;
if (test_mode < TEST_MODE_NOATTACH) {
if (mitsud90_query_media(ctx, &resp))
@ -625,14 +617,14 @@ static int mitsud90_attach(void *vctx, struct libusb_device_handle *dev, int typ
ctx->marker.color = "#00FFFF#FF00FF#FFFF00";
ctx->marker.numtype = resp.media.type;
ctx->marker.name = mitsu_media_types(ctx->type, resp.media.brand, resp.media.type);
ctx->marker.name = mitsu_media_types(ctx->conn->type, resp.media.brand, resp.media.type);
ctx->marker.levelmax = be16_to_cpu(resp.media.capacity);
ctx->marker.levelnow = be16_to_cpu(resp.media.remain);
if (ctx->type == P_MITSU_M1) {
if (ctx->conn->type == P_MITSU_M1) {
#if defined(WITH_DYNAMIC)
/* Attempt to open the library */
if (mitsu_loadlib(&ctx->lib, ctx->type))
if (mitsu_loadlib(&ctx->lib, ctx->conn->type))
#endif
WARNING("Dynamic library support not loaded, will be unable to print.");
}
@ -654,7 +646,7 @@ static void mitsud90_teardown(void *vctx) {
if (!ctx)
return;
if (ctx->type == P_MITSU_M1) {
if (ctx->conn->type == P_MITSU_M1) {
mitsu_destroylib(&ctx->lib);
}
@ -746,7 +738,7 @@ static int mitsud90_read_parse(void *vctx, const void **vjob, int data_fd, int c
}
/* More sanity checks */
if (job->hdr.pano.pano_on && ctx->type != P_MITSU_M1) {
if (job->hdr.pano.pano_on && ctx->conn->type != P_MITSU_M1) {
ERROR("Unable to handle panorama jobs yet\n");
mitsud90_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
@ -786,7 +778,7 @@ static int mitsud90_read_parse(void *vctx, const void **vjob, int data_fd, int c
/* How many pixels do we need to read? */
remain = be16_to_cpu(job->hdr.cols) * be16_to_cpu(job->hdr.rows) * 3;
if (ctx->type == P_MITSU_M1) {
if (ctx->conn->type == P_MITSU_M1) {
/* See if it's a special gutenprint "not-raw" job */
job->is_raw = !job->hdr.zero_b[3];
job->hdr.zero_b[3] = 0;
@ -839,7 +831,7 @@ static int mitsud90_read_parse(void *vctx, const void **vjob, int data_fd, int c
}
/* CP-M1 has... other considerations */
if (ctx->type == P_MITSU_M1 && !job->is_raw) {
if (ctx->conn->type == P_MITSU_M1 && !job->is_raw) {
if (!ctx->lib.dl_handle) {
ERROR("!!! Image Processing Library not found, aborting!\n");
mitsud90_cleanup_job(job);
@ -914,7 +906,7 @@ static int mitsud90_main_loop(void *vctx, const void *vjob) {
return CUPS_BACKEND_FAILED;
copies = job->copies;
if (ctx->type == P_MITSU_M1 && !job->is_raw) {
if (ctx->conn->type == P_MITSU_M1 && !job->is_raw) {
struct BandImage input;
struct BandImage output;
struct M1CPCData *cpc;
@ -1078,11 +1070,11 @@ top:
mem.hdr[2] = 0x44;
mem.hdr[3] = 0x33;
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
(uint8_t*) &mem, sizeof(mem))))
return CUPS_BACKEND_FAILED;
ret = read_data(ctx->dev, ctx->endp_up,
ret = read_data(ctx->conn,
(uint8_t*)&mem_resp, sizeof(mem_resp), &num);
if (ret < 0)
@ -1103,25 +1095,25 @@ top:
}
/* Send job header */
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
(uint8_t*) &job->hdr, sizeof(job->hdr))))
return CUPS_BACKEND_FAILED;
/* Send Plane header */
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
job->databuf + sent, sizeof(job->hdr))))
return CUPS_BACKEND_FAILED;
sent += sizeof(job->hdr);
/* Send payload */
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
job->databuf + sent, job->datalen - sent)))
return CUPS_BACKEND_FAILED;
// sent += (job->datalen - sent);
/* Send job footer */
if (job->has_footer) {
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
(uint8_t*) &job->footer, sizeof(job->footer))))
return CUPS_BACKEND_FAILED;
}
@ -1183,11 +1175,11 @@ static int mitsud90_query_job(struct mitsud90_ctx *ctx, uint16_t jobid,
req.hdr[3] = 0x31;
req.jobid = cpu_to_be16(jobid);
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
(uint8_t*) &req, sizeof(req))))
return ret;
memset(resp, 0, sizeof(*resp));
ret = read_data(ctx->dev, ctx->endp_up,
ret = read_data(ctx->conn,
(uint8_t*) resp, sizeof(*resp), &num);
if (ret < 0)
@ -1221,7 +1213,7 @@ static int mitsud90_get_media(struct mitsud90_ctx *ctx)
return CUPS_BACKEND_FAILED;
INFO("Media Type: %s (%02x/%02x)\n",
mitsu_media_types(ctx->type, resp.media.brand, resp.media.type),
mitsu_media_types(ctx->conn->type, resp.media.brand, resp.media.type),
resp.media.brand,
resp.media.type);
INFO("Prints Remaining: %03d/%03d\n",
@ -1281,12 +1273,12 @@ static int mitsud90_get_info(struct mitsud90_ctx *ctx)
cmdbuf[24] = COM_STATUS_TYPE_x83;
cmdbuf[25] = D90_STATUS_TYPE_x84;
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
cmdbuf, sizeof(cmdbuf))))
return ret;
memset(&resp, 0, sizeof(resp));
ret = read_data(ctx->dev, ctx->endp_up,
ret = read_data(ctx->conn,
(uint8_t*) &resp, sizeof(resp), &num);
if (ret < 0)
@ -1368,12 +1360,12 @@ static int mitsum1_get_info(struct mitsud90_ctx *ctx)
cmdbuf[24] = COM_STATUS_TYPE_x83;
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
cmdbuf, sizeof(cmdbuf))))
return ret;
memset(&resp, 0, sizeof(resp));
ret = read_data(ctx->dev, ctx->endp_up,
ret = read_data(ctx->conn,
(uint8_t*) &resp, sizeof(resp), &num);
if (ret < 0)
@ -1435,12 +1427,12 @@ static int mitsud90_dumpall(struct mitsud90_ctx *ctx)
cmdbuf[7] = i;
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
cmdbuf, sizeof(cmdbuf))))
return ret;
memset(buf, 0, sizeof(buf));
ret = read_data(ctx->dev, ctx->endp_up,
ret = read_data(ctx->conn,
buf, sizeof(buf), &num);
if (ret < 0)
@ -1459,17 +1451,14 @@ static int mitsud90_dumpall(struct mitsud90_ctx *ctx)
return CUPS_BACKEND_OK;
}
static int mitsud90_query_serno(struct libusb_device_handle *dev, uint8_t endp_up, uint8_t endp_down, int iface, char *buf, int buf_len)
static int mitsud90_query_serno(struct dyesub_connection *conn, char *buf, int buf_len)
{
struct mitsud90_ctx ctx = {
.dev = dev,
.endp_up = endp_up,
.endp_down = endp_down
.conn = conn,
};
int ret;
UNUSED(iface);
UNUSED(buf_len);
ret = mitsud90_get_serno(&ctx);
@ -1513,11 +1502,11 @@ static int mitsud90_set_iserial(struct mitsud90_ctx *ctx, uint8_t enabled)
cmdbuf[21] = 0xfe;
cmdbuf[22] = enabled;
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
cmdbuf, sizeof(cmdbuf))))
return ret;
ret = read_data(ctx->dev, ctx->endp_up,
ret = read_data(ctx->conn,
cmdbuf, sizeof(cmdbuf), &num);
return ret;
@ -1560,7 +1549,7 @@ static int mitsud90_set_sleeptime(struct mitsud90_ctx *ctx, uint16_t time)
cmdbuf[22] = (time >> 8) & 0xff;
cmdbuf[23] = time & 0xff;
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
cmdbuf, 4)))
return ret;
@ -1592,7 +1581,7 @@ static int mitsud90_cmdline_arg(void *vctx, int argc, char **argv)
switch(i) {
GETOPT_PROCESS_GLOBAL
case 'i':
if (ctx->type == P_MITSU_D90)
if (ctx->conn->type == P_MITSU_D90)
j = mitsud90_get_info(ctx);
else
j = mitsum1_get_info(ctx);
@ -1610,7 +1599,7 @@ static int mitsud90_cmdline_arg(void *vctx, int argc, char **argv)
j = mitsud90_get_status(ctx);
break;
case 'x':
if (ctx->type == P_MITSU_D90)
if (ctx->conn->type == P_MITSU_D90)
j = mitsud90_set_iserial(ctx, atoi(optarg));
break;
case 'Z':
@ -1653,7 +1642,7 @@ static int mitsud90_query_stats(void *vctx, struct printerstats *stats)
return CUPS_BACKEND_FAILED;
stats->mfg = "Mitsubishi";
switch (ctx->type) {
switch (ctx->conn->type) {
case P_MITSU_D90:
stats->model = "CP-D90 family";
break;
@ -1698,7 +1687,7 @@ static const char *mitsud90_prefixes[] = {
/* Exported */
struct dyesub_backend mitsud90_backend = {
.name = "Mitsubishi CP-D90/CP-M1",
.version = "0.28" " (lib " LIBMITSU_VER ")",
.version = "0.29" " (lib " LIBMITSU_VER ")",
.uri_prefixes = mitsud90_prefixes,
.cmdline_arg = mitsud90_cmdline_arg,
.cmdline_usage = mitsud90_cmdline,

View File

@ -57,11 +57,8 @@ struct mitsup95d_printjob {
};
struct mitsup95d_ctx {
struct libusb_device_handle *dev;
uint8_t endp_up;
uint8_t endp_down;
struct dyesub_connection *conn;
int type;
char serno[STR_LEN_MAX + 1];
struct marker marker;
@ -107,39 +104,34 @@ static int mitsup95d_get_status(struct mitsup95d_ctx *ctx, uint8_t *resp)
/* P93D is ... special. Windows switches to this halfway through
but it seems be okay to use it everywhere */
if (ctx->type == P_MITSU_P93D) {
if (ctx->conn->type == P_MITSU_P93D) {
querycmd[2] = 0x03;
}
/* Query Status to sanity-check job */
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
querycmd, sizeof(querycmd))))
return CUPS_BACKEND_FAILED;
ret = read_data(ctx->dev, ctx->endp_up,
ret = read_data(ctx->conn,
resp, QUERYRESP_SIZE_MAX, &num);
if (ret < 0)
return CUPS_BACKEND_FAILED;
if (ctx->type == P_MITSU_P95D && num != 9) {
if (ctx->conn->type == P_MITSU_P95D && num != 9) {
return CUPS_BACKEND_FAILED;
} else if (ctx->type == P_MITSU_P93D && num != 8) {
} else if (ctx->conn->type == P_MITSU_P93D && num != 8) {
return CUPS_BACKEND_FAILED;
}
return CUPS_BACKEND_OK;
}
static int mitsup95d_attach(void *vctx, struct libusb_device_handle *dev, int type,
uint8_t endp_up, uint8_t endp_down, int iface, uint8_t jobid)
static int mitsup95d_attach(void *vctx, struct dyesub_connection *conn, uint8_t jobid)
{
struct mitsup95d_ctx *ctx = vctx;
UNUSED(jobid);
UNUSED(iface);
ctx->dev = dev;
ctx->endp_up = endp_up;
ctx->endp_down = endp_down;
ctx->type = type;
ctx->conn = conn;
ctx->marker.color = "#000000"; /* Ie black! */
ctx->marker.name = "Unknown";
@ -155,13 +147,13 @@ static int mitsup95d_attach(void *vctx, struct libusb_device_handle *dev, int ty
struct libusb_device_descriptor desc;
struct libusb_device *udev;
udev = libusb_get_device(ctx->dev);
udev = libusb_get_device(ctx->conn->dev);
libusb_get_device_descriptor(udev, &desc);
if (!desc.iSerialNumber) {
WARNING("Printer configured for iSerial mode U0, so no serial number is reported.\n");
} else {
libusb_get_string_descriptor_ascii(ctx->dev, desc.iSerialNumber, (uint8_t*)ctx->serno, STR_LEN_MAX);
libusb_get_string_descriptor_ascii(ctx->conn->dev, desc.iSerialNumber, (uint8_t*)ctx->serno, STR_LEN_MAX);
if (strstr(ctx->serno, "000000")) {
WARNING("Printer configured for iSerial mode U2, reporting a fixed serial number of 000000\n");
@ -237,7 +229,7 @@ top:
ptr = tmphdr;
break;
case 0x58: /* User Comment */
if (ctx->type == P_MITSU_P93D)
if (ctx->conn->type == P_MITSU_P93D)
job->hdr4_len = 42;
else
job->hdr4_len = 36;
@ -343,7 +335,7 @@ top:
} else if (ptr == job->ftr) {
/* Update unknown header field to match sniffs */
if (ctx->type == P_MITSU_P95D) {
if (ctx->conn->type == P_MITSU_P95D) {
if (job->hdr1[18] == 0x00)
job->hdr1[18] = 0x01;
}
@ -381,7 +373,7 @@ static int mitsup95d_main_loop(void *vctx, const void *vjob) {
if (ret)
return ret;
if (ctx->type == P_MITSU_P95D) {
if (ctx->conn->type == P_MITSU_P95D) {
if (queryresp[6] & 0x40) {
INFO("Printer Status: %s (%02x)\n", mitsup95d_errors(queryresp[6]), queryresp[6]);
return CUPS_BACKEND_STOP;
@ -404,35 +396,35 @@ static int mitsup95d_main_loop(void *vctx, const void *vjob) {
/* Send over Memory Clear, if present */
if (job->mem_clr_present) {
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
job->mem_clr, sizeof(job->mem_clr))))
return CUPS_BACKEND_FAILED;
}
/* Send Job Start */
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
job->hdr, sizeof(job->hdr))))
return CUPS_BACKEND_FAILED;
/* Send over headers */
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
job->hdr1, sizeof(job->hdr1))))
return CUPS_BACKEND_FAILED;
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
job->hdr2, sizeof(job->hdr2))))
return CUPS_BACKEND_FAILED;
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
job->hdr3, sizeof(job->hdr3))))
return CUPS_BACKEND_FAILED;
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
job->hdr4, job->hdr4_len)))
return CUPS_BACKEND_FAILED;
/* Send plane header and image data */
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
job->plane, sizeof(job->plane))))
return CUPS_BACKEND_FAILED;
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
job->databuf, job->datalen)))
return CUPS_BACKEND_FAILED;
@ -441,7 +433,7 @@ static int mitsup95d_main_loop(void *vctx, const void *vjob) {
if (ret)
return ret;
if (ctx->type == P_MITSU_P95D) {
if (ctx->conn->type == P_MITSU_P95D) {
if (queryresp[6] & 0x40) {
INFO("Printer Status: %s (%02x)\n", mitsup95d_errors(queryresp[6]), queryresp[6]);
return CUPS_BACKEND_STOP;
@ -462,7 +454,7 @@ static int mitsup95d_main_loop(void *vctx, const void *vjob) {
}
/* Send over Footer */
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
job->ftr, sizeof(job->ftr))))
return CUPS_BACKEND_FAILED;
@ -477,7 +469,7 @@ static int mitsup95d_main_loop(void *vctx, const void *vjob) {
if (ret)
return ret;
if (ctx->type == P_MITSU_P95D) {
if (ctx->conn->type == P_MITSU_P95D) {
if (queryresp[6] & 0x40) {
INFO("Printer Status: %s (%02x)\n", mitsup95d_errors(queryresp[6]), queryresp[6]);
return CUPS_BACKEND_STOP;
@ -528,7 +520,7 @@ static int mitsup95d_dump_status(struct mitsup95d_ctx *ctx)
INFO("Serial Number: %s\n", ctx->serno);
}
if (ctx->type == P_MITSU_P95D) {
if (ctx->conn->type == P_MITSU_P95D) {
if (queryresp[6] & 0x40) {
INFO("Printer Status: %s (%02x)\n", mitsup95d_errors(queryresp[6]), queryresp[6]);
} else if (queryresp[5] == 0x00) {
@ -588,7 +580,7 @@ static int mitsup95d_query_markers(void *vctx, struct marker **markers, int *cou
ctx->marker.levelnow = CUPS_MARKER_UNKNOWN_OK;
if (ctx->type == P_MITSU_P95D) {
if (ctx->conn->type == P_MITSU_P95D) {
if (queryresp[6] & 0x40) {
ctx->marker.levelnow = 0;
}
@ -614,7 +606,7 @@ static const char *mitsup95d_prefixes[] = {
/* Exported */
struct dyesub_backend mitsup95d_backend = {
.name = "Mitsubishi P93D/P95D",
.version = "0.14",
.version = "0.15",
.uri_prefixes = mitsup95d_prefixes,
.cmdline_arg = mitsup95d_cmdline_arg,
.cmdline_usage = mitsup95d_cmdline,

View File

@ -222,11 +222,7 @@ struct shinkos1245_resp_matte {
/* Private data structure */
struct shinkos1245_ctx {
struct libusb_device_handle *dev;
uint8_t endp_up;
uint8_t endp_down;
int type;
int iface;
struct dyesub_connection *conn;
uint8_t jobid;
@ -268,12 +264,12 @@ static int shinkos1245_do_cmd(struct shinkos1245_ctx *ctx,
int ret;
/* Write command */
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
cmd, cmd_len)))
return (ret < 0) ? ret : -99;
/* Read response */
ret = read_data(ctx->dev, ctx->endp_up,
ret = read_data(ctx->conn,
resp, resp_len, actual_len);
if (ret < 0)
return ret;
@ -693,7 +689,7 @@ static int get_tonecurve(struct shinkos1245_ctx *ctx, int type, int table, char
}
/* And read back 64-bytes of data */
ret = read_data(ctx->dev, ctx->endp_up,
ret = read_data(ctx->conn,
ptr, TONE_CURVE_DATA_BLOCK_SIZE, &num);
if (num != TONE_CURVE_DATA_BLOCK_SIZE) {
ret = -99;
@ -811,7 +807,7 @@ static int set_tonecurve(struct shinkos1245_ctx *ctx, int type, int table, char
}
/* Write 64-bytes of data */
ret = send_data(ctx->dev, ctx->endp_up,
ret = send_data(ctx->conn,
ptr, TONE_CURVE_DATA_BLOCK_SIZE);
if (ret < 0)
goto done;
@ -941,16 +937,11 @@ static void *shinkos1245_init(void)
return ctx;
}
static int shinkos1245_attach(void *vctx, struct libusb_device_handle *dev, int type,
uint8_t endp_up, uint8_t endp_down, int iface, uint8_t jobid)
static int shinkos1245_attach(void *vctx, struct dyesub_connection *conn, uint8_t jobid)
{
struct shinkos1245_ctx *ctx = vctx;
ctx->dev = dev;
ctx->endp_up = endp_up;
ctx->endp_down = endp_down;
ctx->iface = iface;
ctx->type = type;
ctx->conn = conn;
/* Ensure jobid is sane */
ctx->jobid = jobid & 0x7f;
@ -1167,7 +1158,7 @@ top:
/* Send over data */
INFO("Sending image data to printer\n");
if ((i = send_data(ctx->dev, ctx->endp_down,
if ((i = send_data(ctx->conn,
job->databuf, job->datalen)))
return CUPS_BACKEND_FAILED;
@ -1205,16 +1196,13 @@ printer_error2:
return CUPS_BACKEND_FAILED;
}
static int shinkos1245_query_serno(struct libusb_device_handle *dev, uint8_t endp_up, uint8_t endp_down, int iface, char *buf, int buf_len)
static int shinkos1245_query_serno(struct dyesub_connection *conn, char *buf, int buf_len)
{
struct shinkos1245_resp_getid resp;
int i;
struct shinkos1245_ctx ctx = {
.dev = dev,
.endp_up = endp_up,
.endp_down = endp_down,
.iface = iface,
.conn = conn,
};
i = shinkos1245_get_printerid(&ctx, &resp);
@ -1265,8 +1253,7 @@ static int shinkos1245_query_stats(void *vctx, struct printerstats *stats)
stats->mfg = "Sinfonia";
stats->model = "E1 / S1245";
if (shinkos1245_query_serno(ctx->dev, ctx->endp_up,
ctx->endp_down, ctx->iface,
if (shinkos1245_query_serno(ctx->conn,
ctx->serial, sizeof(ctx->serial)))
return CUPS_BACKEND_FAILED;
@ -1299,7 +1286,7 @@ static const char *shinkos1245_prefixes[] = {
struct dyesub_backend shinkos1245_backend = {
.name = "Shinko/Sinfonia CHC-S1245/E1",
.version = "0.33" " (lib " LIBSINFONIA_VER ")",
.version = "0.34" " (lib " LIBSINFONIA_VER ")",
.uri_prefixes = shinkos1245_prefixes,
.cmdline_usage = shinkos1245_cmdline,
.cmdline_arg = shinkos1245_cmdline_arg,

View File

@ -624,7 +624,7 @@ static int get_tonecurve(struct shinkos2145_ctx *ctx, int type, char *fname)
i = 0;
while (i < resp.total_size) {
ret = read_data(ctx->dev.dev, ctx->dev.endp_up,
ret = read_data(ctx->dev.conn,
data + i,
resp.total_size * 2 - i,
&num);
@ -715,7 +715,7 @@ static int set_tonecurve(struct shinkos2145_ctx *ctx, int target, char *fname)
}
/* Sent transfer */
if ((ret = send_data(ctx->dev.dev, ctx->dev.endp_down,
if ((ret = send_data(ctx->dev.conn,
(uint8_t *) data, TONE_CURVE_SIZE * sizeof(uint16_t)))) {
goto done;
}
@ -830,16 +830,11 @@ static void *shinkos2145_init(void)
return ctx;
}
static int shinkos2145_attach(void *vctx, struct libusb_device_handle *dev, int type,
uint8_t endp_up, uint8_t endp_down, int iface, uint8_t jobid)
static int shinkos2145_attach(void *vctx, struct dyesub_connection *conn, uint8_t jobid)
{
struct shinkos2145_ctx *ctx = vctx;
ctx->dev.dev = dev;
ctx->dev.endp_up = endp_up;
ctx->dev.endp_down = endp_down;
ctx->dev.type = type;
ctx->dev.iface = iface;
ctx->dev.conn = conn;
ctx->dev.error_codes = &error_codes;
/* Ensure jobid is sane */
@ -1050,7 +1045,7 @@ top:
}
INFO("Sending image data to printer\n");
if ((ret = send_data(ctx->dev.dev, ctx->dev.endp_down,
if ((ret = send_data(ctx->dev.conn,
job->databuf, job->datalen)))
return CUPS_BACKEND_FAILED;
@ -1101,17 +1096,15 @@ printer_error:
return CUPS_BACKEND_FAILED;
}
static int shinkos2145_query_serno(struct libusb_device_handle *dev, uint8_t endp_up, uint8_t endp_down, int iface, char *buf, int buf_len)
static int shinkos2145_query_serno(struct dyesub_connection *conn, char *buf, int buf_len)
{
struct sinfonia_cmd_hdr cmd;
struct s2145_getunique_resp resp;
int ret, num = 0;
struct sinfonia_usbdev sdev = {
.dev = dev,
.endp_up = endp_up,
.endp_down = endp_down,
.iface = iface,
.conn = conn,
.error_codes = &error_codes,
};
cmd.cmd = cpu_to_le16(SINFONIA_CMD_GETUNIQUE);
@ -1183,8 +1176,7 @@ static int shinkos2145_query_stats(void *vctx, struct printerstats *stats)
stats->mfg = "Sinfonia";
stats->model = "S2 / S2145";
if (sinfonia_query_serno(ctx->dev.dev, ctx->dev.endp_up,
ctx->dev.endp_down, ctx->dev.iface,
if (sinfonia_query_serno(ctx->dev.conn,
ctx->serial, sizeof(ctx->serial)))
return CUPS_BACKEND_FAILED;
@ -1236,7 +1228,7 @@ static const char *shinkos2145_prefixes[] = {
struct dyesub_backend shinkos2145_backend = {
.name = "Shinko/Sinfonia CHC-S2145/S2",
.version = "0.65" " (lib " LIBSINFONIA_VER ")",
.version = "0.66" " (lib " LIBSINFONIA_VER ")",
.uri_prefixes = shinkos2145_prefixes,
.cmdline_usage = shinkos2145_cmdline,
.cmdline_arg = shinkos2145_cmdline_arg,

View File

@ -782,7 +782,7 @@ static int get_status(struct shinkos6145_ctx *ctx)
INFO("Head Distance: %08u inches\n", le32_to_cpu(resp2.head_distance));
/* Query various params */
if (ctx->dev.type == P_SHINKO_S6145D) {
if (ctx->dev.conn->type == P_SHINKO_S6145D) {
if ((ret = sinfonia_getparam(&ctx->dev, PARAM_REGION_CODE, &val))) {
ERROR("Failed to execute command\n");
return ret;
@ -790,7 +790,7 @@ static int get_status(struct shinkos6145_ctx *ctx)
INFO("Region Code: %#x\n", val);
}
if (ctx->dev.type != P_SHINKO_S2245) {
if (ctx->dev.conn->type != P_SHINKO_S2245) {
if ((ret = sinfonia_getparam(&ctx->dev, PARAM_PAPER_PRESV, &val))) {
ERROR("Failed to execute command\n");
return ret;
@ -801,7 +801,7 @@ static int get_status(struct shinkos6145_ctx *ctx)
ERROR("Failed to execute command\n");
return ret;
}
if (ctx->dev.type != P_SHINKO_S2245) {
if (ctx->dev.conn->type != P_SHINKO_S2245) {
INFO("Driver mode: %s\n", s2245_drivermodes(val));
} else {
INFO("Driver mode: %s\n", (val ? "On" : "Off"));
@ -813,7 +813,7 @@ static int get_status(struct shinkos6145_ctx *ctx)
}
INFO("Paper load mode: %s\n", (val ? "Cut" : "No Cut"));
if (ctx->dev.type != P_SHINKO_S2245) {
if (ctx->dev.conn->type != P_SHINKO_S2245) {
if ((ret = sinfonia_getparam(&ctx->dev, PARAM_SLEEP_TIME, &val))) {
ERROR("Failed to execute command\n");
return ret;
@ -860,7 +860,7 @@ static int shinkos6145_dump_corrdata(struct shinkos6145_ctx *ctx, char *fname)
{
int ret;
if (ctx->dev.type == P_SHINKO_S2245) {
if (ctx->dev.conn->type == P_SHINKO_S2245) {
ret = shinkos2245_get_imagecorr(ctx, 0x0a); // XXX have to supply something.. this is HQ matte.
} else {
ret = shinkos6145_get_imagecorr(ctx);
@ -958,7 +958,7 @@ static int shinkos6145_get_imagecorr(struct shinkos6145_ctx *ctx)
while (total < ctx->corrdatalen) {
struct s6145_imagecorr_data data;
ret = read_data(ctx->dev.dev, ctx->dev.endp_up, (uint8_t *) &data,
ret = read_data(ctx->dev.conn, (uint8_t *) &data,
sizeof(data),
&num);
if (ret < 0)
@ -1016,7 +1016,7 @@ static int shinkos2245_get_imagecorr(struct shinkos6145_ctx *ctx, uint8_t option
while (total < ctx->corrdatalen) {
struct s6145_imagecorr_data data;
ret = read_data(ctx->dev.dev, ctx->dev.endp_up, (uint8_t *) &data,
ret = read_data(ctx->dev.conn, (uint8_t *) &data,
sizeof(data),
&num);
if (ret < 0)
@ -1165,7 +1165,7 @@ static int shinkos6145_cmdline_arg(void *vctx, int argc, char **argv)
j = sinfonia_settonecurve(&ctx->dev, UPDATE_TARGET_TONE_USER, optarg);
break;
case 'e':
if (ctx->dev.type == P_SHINKO_S2245) {
if (ctx->dev.conn->type == P_SHINKO_S2245) {
j = s2245_get_errorlog(&ctx->dev);
} else {
j = sinfonia_geterrorlog(&ctx->dev);
@ -1251,18 +1251,13 @@ static void *shinkos6145_init(void)
return ctx;
}
static int shinkos6145_attach(void *vctx, struct libusb_device_handle *dev, int type,
uint8_t endp_up, uint8_t endp_down, int iface, uint8_t jobid)
static int shinkos6145_attach(void *vctx, struct dyesub_connection *conn, uint8_t jobid)
{
struct shinkos6145_ctx *ctx = vctx;
ctx->dev.dev = dev;
ctx->dev.endp_up = endp_up;
ctx->dev.endp_down = endp_down;
ctx->dev.type = type;
ctx->dev.iface = iface;
ctx->dev.conn = conn;
if (type == P_SHINKO_S2245) {
if (conn->type == P_SHINKO_S2245) {
ctx->dev.params = s2245_params;
ctx->dev.params_count = s2245_params_num;
ctx->dev.error_codes = &s2245_error_codes;
@ -1288,8 +1283,8 @@ static int shinkos6145_attach(void *vctx, struct libusb_device_handle *dev, int
}
}
#endif
} else if (type == P_SHINKO_S6145 ||
type == P_SHINKO_S6145D) {
} else if (conn->type == P_SHINKO_S6145 ||
conn->type == P_SHINKO_S6145D) {
ctx->dev.params = s6145_params;
ctx->dev.params_count = s6145_params_num;
ctx->dev.error_codes = &s6145_error_codes;
@ -1345,7 +1340,7 @@ static int shinkos6145_attach(void *vctx, struct libusb_device_handle *dev, int
ctx->marker.color = "#00FFFF#FF00FF#FFFF00";
ctx->marker.name = print_ribbons(ctx->media.ribbon_code, ctx->is_card);
ctx->marker.numtype = ctx->media.ribbon_code;
ctx->marker.levelmax = ribbon_sizes(ctx->media.ribbon_code, ctx->is_card, ctx->dev.type == P_SHINKO_S2245);
ctx->marker.levelmax = ribbon_sizes(ctx->media.ribbon_code, ctx->is_card, ctx->dev.conn->type == P_SHINKO_S2245);
ctx->marker.levelnow = CUPS_MARKER_UNKNOWN;
return CUPS_BACKEND_OK;
@ -1379,8 +1374,8 @@ static int shinkos6145_read_parse(void *vctx, const void **vjob, int data_fd, in
if (!ctx)
return CUPS_BACKEND_FAILED;
if (ctx->dev.type == P_SHINKO_S6145 ||
ctx->dev.type == P_SHINKO_S6145D)
if (ctx->dev.conn->type == P_SHINKO_S6145 ||
ctx->dev.conn->type == P_SHINKO_S6145D)
model = 6145;
else
model = 2245;
@ -1394,7 +1389,7 @@ static int shinkos6145_read_parse(void *vctx, const void **vjob, int data_fd, in
job->jobsize = sizeof(*job);
/* Common read/parse code */
if (ctx->dev.type == P_KODAK_6900) {
if (ctx->dev.conn->type == P_KODAK_6900) {
ret = sinfonia_raw28_read_parse(data_fd, job);
} else {
ret = sinfonia_read_parse(data_fd, model, job);
@ -1427,7 +1422,7 @@ static int shinkos6145_read_parse(void *vctx, const void **vjob, int data_fd, in
input_ymc = job->jp.ext_flags & EXT_FLAG_PLANARYMC;
/* Convert packed RGB to planar YMC if necessary */
if (ctx->dev.type != P_SHINKO_S2245 && !input_ymc) {
if (ctx->dev.conn->type != P_SHINKO_S2245 && !input_ymc) {
INFO("Converting Packed RGB to Planar YMC\n");
int planelen = job->jp.columns * job->jp.rows;
uint8_t *databuf3 = malloc(job->datalen);
@ -1581,7 +1576,7 @@ static int shinkos6145_main_loop(void *vctx, const void *vjob) {
// XXX check copies against remaining media?
if (ctx->dev.type != P_SHINKO_S2245) {
if (ctx->dev.conn->type != P_SHINKO_S2245) {
/* Query printer mode */
ret = sinfonia_getparam(&ctx->dev, PARAM_OC_PRINT, &cur_mode);
if (ret) {
@ -1591,7 +1586,7 @@ static int shinkos6145_main_loop(void *vctx, const void *vjob) {
}
/* Send Set Time */
if (ctx->dev.type == P_SHINKO_S2245) {
if (ctx->dev.conn->type == P_SHINKO_S2245) {
struct sinfonia_settime_cmd settime;
time_t now = time(NULL);
struct tm *cur = localtime(&now);
@ -1672,14 +1667,14 @@ top:
uint32_t oc_mode = job->jp.oc_mode;
uint32_t updated = 0;
if (ctx->dev.type == P_SHINKO_S2245) {
if (ctx->dev.conn->type == P_SHINKO_S2245) {
oc_mode = (job->jp.oc_mode & SINFONIA_PRINT28_OC_MASK) | (job->jp.quality ? SINFONIA_PRINT28_OPTIONS_HQ : 0);
if (!ctx->corrdata ||
ctx->corrdatalen <= S2245_CORRDATA_HEADER_MODE_OFFSET ||
((uint8_t*)ctx->corrdata)[S2245_CORRDATA_HEADER_MODE_OFFSET] != oc_mode)
updated = 1;
}
if (ctx->dev.type != P_SHINKO_S2245) {
if (ctx->dev.conn->type != P_SHINKO_S2245) {
if (!oc_mode) /* if nothing set, default to glossy */
oc_mode = PARAM_OC_PRINT_GLOSS;
@ -1711,7 +1706,7 @@ top:
/* Get image correction parameters if necessary */
if (updated || !ctx->corrdata || !ctx->corrdatalen) {
if (ctx->dev.type == P_SHINKO_S2245) {
if (ctx->dev.conn->type == P_SHINKO_S2245) {
ret = shinkos2245_get_imagecorr(ctx, oc_mode);
} else {
ret = shinkos6145_get_imagecorr(ctx);
@ -1729,7 +1724,7 @@ top:
return CUPS_BACKEND_FAILED;
}
if (ctx->dev.type == P_SHINKO_S2245) {
if (ctx->dev.conn->type == P_SHINKO_S2245) {
uint32_t bufSize = 0;
uint16_t *newbuf;
@ -1787,7 +1782,7 @@ top:
INFO("Sending print job (internal id %u)\n", ctx->jobid);
if (ctx->dev.type != P_SHINKO_S2245) {
if (ctx->dev.conn->type != P_SHINKO_S2245) {
struct s6145_print_cmd print;
memset(&print, 0, sizeof(print));
print.hdr.cmd = cpu_to_le16(SINFONIA_CMD_PRINTJOB);
@ -1802,7 +1797,7 @@ top:
print.combo_wait = 0;
/* Brava21 header has a few quirks */
if(ctx->dev.type == P_SHINKO_S6145D) {
if(ctx->dev.conn->type == P_SHINKO_S6145D) {
print.media = job->jp.media;
print.unk_1 = 0x01;
}
@ -1851,7 +1846,7 @@ top:
INFO("Sending image data to printer\n");
// XXX we shouldn't send the lamination layer over if
// it's not needed. hdr->oc_mode == PRINT_MODE_NO_OC
if ((ret = send_data(ctx->dev.dev, ctx->dev.endp_down,
if ((ret = send_data(ctx->dev.conn,
job->databuf, job->datalen)))
return CUPS_BACKEND_FAILED;
@ -1954,13 +1949,13 @@ static int shinkos6145_query_stats(void *vctx, struct printerstats *stats)
struct libusb_device_descriptor desc;
struct libusb_device *dev;
dev = libusb_get_device(ctx->dev.dev);
dev = libusb_get_device(ctx->dev.conn->dev);
libusb_get_device_descriptor(dev, &desc);
usbID = desc.idProduct;
}
switch (ctx->dev.type) {
switch (ctx->dev.conn->type) {
case P_SHINKO_S6145:
stats->mfg = "Sinfonia";
stats->model = "CS2 / S6145";
@ -1990,8 +1985,7 @@ static int shinkos6145_query_stats(void *vctx, struct printerstats *stats)
break;
}
if (sinfonia_query_serno(ctx->dev.dev, ctx->dev.endp_up,
ctx->dev.endp_down, ctx->dev.iface,
if (sinfonia_query_serno(ctx->dev.conn,
ctx->serial, sizeof(ctx->serial)))
return CUPS_BACKEND_FAILED;
@ -2042,7 +2036,7 @@ static const char *shinkos6145_prefixes[] = {
struct dyesub_backend shinkos6145_backend = {
.name = "Shinko/Sinfonia CHC-S6145/CS2/S2245/S3",
.version = "0.43" " (lib " LIBSINFONIA_VER ")",
.version = "0.44" " (lib " LIBSINFONIA_VER ")",
.uri_prefixes = shinkos6145_prefixes,
.cmdline_usage = shinkos6145_cmdline,
.cmdline_arg = shinkos6145_cmdline_arg,

View File

@ -720,7 +720,7 @@ static int get_status(struct shinkos6245_ctx *ctx)
/* Query Extended counters */
if (ctx->dev.type == P_KODAK_8810)
if (ctx->dev.conn->type == P_KODAK_8810)
return CUPS_BACKEND_OK; /* Kodak 8810 returns 12 bytes of garbage. */
cmd.cmd = cpu_to_le16(SINFONIA_CMD_EXTCOUNTER);
@ -829,7 +829,7 @@ static int shinkos6245_cmdline_arg(void *vctx, int argc, char **argv)
switch(i) {
GETOPT_PROCESS_GLOBAL
case 'b':
if (ctx->dev.type != P_KODAK_8810)
if (ctx->dev.conn->type != P_KODAK_8810)
return -1;
else if (optarg[0] == '1')
j = sinfonia_button_set(&ctx->dev, BUTTON_ENABLED);
@ -845,7 +845,7 @@ static int shinkos6245_cmdline_arg(void *vctx, int argc, char **argv)
j = sinfonia_settonecurve(&ctx->dev, UPDATE_TARGET_TONE_USER, optarg);
break;
case 'e':
if (ctx->dev.type == P_KODAK_8810) {
if (ctx->dev.conn->type == P_KODAK_8810) {
j = sinfonia_geterrorlog(&ctx->dev);
} else {
j = get_errorlog(ctx);
@ -923,18 +923,13 @@ static void *shinkos6245_init(void)
return ctx;
}
static int shinkos6245_attach(void *vctx, struct libusb_device_handle *dev, int type,
uint8_t endp_up, uint8_t endp_down, int iface, uint8_t jobid)
static int shinkos6245_attach(void *vctx, struct dyesub_connection *conn, uint8_t jobid)
{
struct shinkos6245_ctx *ctx = vctx;
ctx->dev.dev = dev;
ctx->dev.endp_up = endp_up;
ctx->dev.endp_down = endp_down;
ctx->dev.type = type;
ctx->dev.iface = iface;
ctx->dev.conn = conn;
if (type == P_KODAK_8810) {
if (conn->type == P_KODAK_8810) {
ctx->dev.error_codes = &ek8810_error_codes;
ctx->dev.params = ek8810_params;
ctx->dev.params_count = ek8810_params_num;
@ -988,7 +983,7 @@ static int shinkos6245_read_parse(void *vctx, const void **vjob, int data_fd, in
memset(job, 0, sizeof(*job));
/* Common read/parse code */
if (ctx->dev.type == P_KODAK_8810) {
if (ctx->dev.conn->type == P_KODAK_8810) {
ret = sinfonia_raw18_read_parse(data_fd, job);
} else {
ret = sinfonia_read_parse(data_fd, 6245, job);
@ -1107,7 +1102,7 @@ static int shinkos6245_main_loop(void *vctx, const void *vjob) {
// XXX what about mcut |= PRINT_METHOD_DISABLE_ERR;
/* EK8810 uses special "cutlist" */
if (ctx->dev.type == P_KODAK_8810) {
if (ctx->dev.conn->type == P_KODAK_8810) {
switch (job->jp.media) {
case CODE_8x4_2:
if (job->jp.ext_flags & EXT_FLAG_DOUBLESLUG)
@ -1162,7 +1157,7 @@ static int shinkos6245_main_loop(void *vctx, const void *vjob) {
#endif
/* Send Set Time */
if (ctx->dev.type != P_KODAK_8810) {
if (ctx->dev.conn->type != P_KODAK_8810) {
struct sinfonia_settime_cmd *settime = (struct sinfonia_settime_cmd *)cmdbuf;
time_t now = time(NULL);
struct tm *cur = localtime(&now);
@ -1256,7 +1251,7 @@ top:
case S_PRINTER_READY_CMD:
// XXX send "get eeprom backup command"
if (ctx->dev.type == P_KODAK_8810 && cutlist) {
if (ctx->dev.conn->type == P_KODAK_8810 && cutlist) {
cutlist->hdr.cmd = cpu_to_le16(SINFONIA_CMD_SETCUTLIST);
cutlist->hdr.len = cpu_to_le16(sizeof(*cutlist) - sizeof(cutlist->hdr));
@ -1303,7 +1298,7 @@ top:
}
INFO("Sending image data to printer\n");
if ((ret = send_data(ctx->dev.dev, ctx->dev.endp_down,
if ((ret = send_data(ctx->dev.conn,
job->databuf, job->datalen)))
return CUPS_BACKEND_FAILED;
@ -1389,7 +1384,7 @@ static int shinkos6245_query_stats(void *vctx, struct printerstats *stats)
return CUPS_BACKEND_FAILED;
}
switch (ctx->dev.type) {
switch (ctx->dev.conn->type) {
case P_SHINKO_S6245:
stats->mfg = "Sinfonia";
stats->model = "CE1 / S6245";
@ -1408,8 +1403,7 @@ static int shinkos6245_query_stats(void *vctx, struct printerstats *stats)
break;
}
if (sinfonia_query_serno(ctx->dev.dev, ctx->dev.endp_up,
ctx->dev.endp_down, ctx->dev.iface,
if (sinfonia_query_serno(ctx->dev.conn,
ctx->serial, sizeof(ctx->serial)))
return CUPS_BACKEND_FAILED;
@ -1468,7 +1462,7 @@ static const char *shinkos6245_prefixes[] = {
struct dyesub_backend shinkos6245_backend = {
.name = "Sinfonia CHC-S6245 / Kodak 8810",
.version = "0.35" " (lib " LIBSINFONIA_VER ")",
.version = "0.36" " (lib " LIBSINFONIA_VER ")",
.uri_prefixes = shinkos6245_prefixes,
.cmdline_usage = shinkos6245_cmdline,
.cmdline_arg = shinkos6245_cmdline_arg,

View File

@ -326,20 +326,17 @@ int sinfonia_docmd(struct sinfonia_usbdev *usbh,
uint8_t *resp, int resplen,
int *num)
{
libusb_device_handle *dev = usbh->dev;
uint8_t endp_up = usbh->endp_up;
uint8_t endp_down = usbh->endp_down;
int ret;
struct sinfonia_cmd_hdr *cmdhdr = (struct sinfonia_cmd_hdr *) cmd;
struct sinfonia_status_hdr *resphdr = (struct sinfonia_status_hdr *)resp;
if ((ret = send_data(dev, endp_down,
if ((ret = send_data(usbh->conn,
cmd, cmdlen))) {
goto fail;
}
ret = read_data(dev, endp_up,
ret = read_data(usbh->conn,
(uint8_t *)resp, resplen, num);
if (ret < 0)
@ -501,8 +498,8 @@ int sinfonia_getfwinfo(struct sinfonia_usbdev *usbh)
INFO("FW Information:\n");
if (usbh->type == P_SHINKO_S6145) last = FWINFO_TARGET_PRINT_TABLES;
if (usbh->type == P_SHINKO_S2245) last = FWINFO_TARGET_DSP;
if (usbh->conn->type == P_SHINKO_S6145) last = FWINFO_TARGET_PRINT_TABLES;
if (usbh->conn->type == P_SHINKO_S2245) last = FWINFO_TARGET_DSP;
for (i = FWINFO_TARGET_MAIN_BOOT ; i <= last ; i++) {
int ret;
@ -630,7 +627,7 @@ int sinfonia_gettonecurve(struct sinfonia_usbdev *usbh, int type, char *fname)
i = 0;
while (i < resp.total_size) {
ret = read_data(usbh->dev, usbh->endp_up,
ret = read_data(usbh->conn,
data + i,
resp.total_size * 2 - i,
&num);
@ -736,7 +733,7 @@ int sinfonia_settonecurve(struct sinfonia_usbdev *usbh, int target, char *fname)
}
/* Sent transfer */
if ((ret = send_data(usbh->dev, usbh->endp_down,
if ((ret = send_data(usbh->conn,
(uint8_t *) data, TONE_CURVE_SIZE * sizeof(uint16_t)))) {
goto done;
}
@ -781,18 +778,15 @@ static const char *dummy_error_codes(uint8_t major, uint8_t minor)
return "Unknown";
}
int sinfonia_query_serno(struct libusb_device_handle *dev, uint8_t endp_up, uint8_t endp_down, int iface, char *buf, int buf_len)
int sinfonia_query_serno(struct dyesub_connection *conn, char *buf, int buf_len)
{
struct sinfonia_cmd_hdr cmd;
struct sinfonia_getserial_resp resp;
int ret, num = 0;
struct sinfonia_usbdev sdev = {
.dev = dev,
.iface = iface,
.endp_up = endp_up,
.endp_down = endp_down,
.error_codes = dummy_error_codes,
.conn = conn,
};
cmd.cmd = cpu_to_le16(SINFONIA_CMD_GETSERIAL);

View File

@ -24,7 +24,7 @@
*
*/
#define LIBSINFONIA_VER "0.15"
#define LIBSINFONIA_VER "0.16"
#define SINFONIA_HDR1_LEN 0x10
#define SINFONIA_HDR2_LEN 0x64
@ -79,11 +79,7 @@ struct sinfonia_param {
/* Common usb functions */
struct sinfonia_usbdev {
struct libusb_device_handle *dev;
uint8_t endp_up;
uint8_t endp_down;
int type;
int iface;
struct dyesub_connection *conn;
const struct sinfonia_param *params;
int params_count;
@ -105,7 +101,7 @@ int sinfonia_gettonecurve(struct sinfonia_usbdev *usbh, int type, char *fname);
int sinfonia_settonecurve(struct sinfonia_usbdev *usbh, int target, char *fname);
int sinfonia_button_set(struct sinfonia_usbdev *dev, int enable);
int sinfonia_query_serno(struct libusb_device_handle *dev, uint8_t endp_up, uint8_t endp_down, int iface, char *buf, int buf_len);
int sinfonia_query_serno(struct dyesub_connection *conn, char *buf, int buf_len);
int sinfonia_dumpallparams(struct sinfonia_usbdev *usbh, int known);
const char *sinfonia_paramname(struct sinfonia_usbdev *usbh, int id);

View File

@ -71,10 +71,7 @@ struct upd_printjob {
};
struct upd_ctx {
struct libusb_device_handle *dev;
uint8_t endp_up;
uint8_t endp_down;
int type;
struct dyesub_connection *conn;
int native_bpp;
@ -95,20 +92,15 @@ static void* upd_init(void)
return ctx;
}
static int upd_attach(void *vctx, struct libusb_device_handle *dev, int type,
uint8_t endp_up, uint8_t endp_down, int iface, uint8_t jobid)
static int upd_attach(void *vctx, struct dyesub_connection *conn, uint8_t jobid)
{
struct upd_ctx *ctx = vctx;
UNUSED(jobid);
UNUSED(iface);
ctx->dev = dev;
ctx->endp_up = endp_up;
ctx->endp_down = endp_down;
ctx->type = type;
ctx->conn = conn;
if (ctx->type == P_SONY_UPD895 || ctx->type == P_SONY_UPD897) {
if (ctx->conn->type == P_SONY_UPD895 || ctx->conn->type == P_SONY_UPD897) {
ctx->marker.color = "#000000"; /* Ie black! */
ctx->native_bpp = 1;
} else {
@ -172,20 +164,20 @@ static int sony_get_status(struct upd_ctx *ctx, struct sony_updsts *buf)
int ret, num = 0;
uint8_t query[7] = { 0x1b, 0xe0, 0, 0, 0, 0x0f, 0 };
if (ctx->type == P_SONY_UPD895)
if (ctx->conn->type == P_SONY_UPD895)
query[5] = 0x0e;
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
query, sizeof(query))))
return CUPS_BACKEND_FAILED;
ret = read_data(ctx->dev, ctx->endp_up, (uint8_t*) buf, sizeof(*buf),
ret = read_data(ctx->conn, (uint8_t*) buf, sizeof(*buf),
&num);
if (ret < 0)
return CUPS_BACKEND_FAILED;
#if 0
if (ctx->type == P_SONY_UPD895 && ret != 14)
if (ctx->conn->type == P_SONY_UPD895 && ret != 14)
return CUPS_BACKEND_FAILED;
else if (ret != 15)
return CUPS_BACKEND_FAILED;
@ -248,14 +240,14 @@ static int upd_read_parse(void *vctx, const void **vjob, int data_fd, int copies
if(dyesub_debug)
DEBUG("Block ID '%08x' (len %d)\n", len, 0);
len = 0;
if (ctx->type == P_SONY_UPDR150)
if (ctx->conn->type == P_SONY_UPDR150)
run = 0;
break;
case 0xfffffff7:
if(dyesub_debug)
DEBUG("Block ID '%08x' (len %d)\n", len, 0);
len = 0;
if (ctx->type == P_SONY_UPCR10)
if (ctx->conn->type == P_SONY_UPCR10)
run = 0;
break;
case 0xfffffff8: // 895
@ -263,7 +255,7 @@ static int upd_read_parse(void *vctx, const void **vjob, int data_fd, int copies
if(dyesub_debug)
DEBUG("Block ID '%08x' (len %d)\n", len, 0);
len = 0;
if (ctx->type == P_SONY_UPD895 || ctx->type == P_SONY_UPD897)
if (ctx->conn->type == P_SONY_UPD895 || ctx->conn->type == P_SONY_UPD897)
run = 0;
break;
case 0xffffff97:
@ -272,7 +264,7 @@ static int upd_read_parse(void *vctx, const void **vjob, int data_fd, int copies
len = 12;
break;
case 0xffffffef:
if (ctx->type == P_SONY_UPD895 || ctx->type == P_SONY_UPD897) {
if (ctx->conn->type == P_SONY_UPD895 || ctx->conn->type == P_SONY_UPD897) {
if(dyesub_debug)
DEBUG("Block ID '%08x' (len %d)\n", len, 0);
len = 0;
@ -287,7 +279,7 @@ static int upd_read_parse(void *vctx, const void **vjob, int data_fd, int copies
len = 4;
break;
case 0xffffffec:
if (ctx->type == P_SONY_UPD897) {
if (ctx->conn->type == P_SONY_UPD897) {
if(dyesub_debug)
DEBUG("Block ID '%08x' (len %d)\n", len, 4);
len = 4;
@ -416,9 +408,9 @@ static int upd_main_loop(void *vctx, const void *vjob) {
top:
/* Send Unknown CMD. Resets? */
if (ctx->type == P_SONY_UPD897) {
if (ctx->conn->type == P_SONY_UPD897) {
const uint8_t cmdbuf[7] = { 0x1b, 0x1f, 0, 0, 0, 0, 0 };
ret = send_data(ctx->dev, ctx->endp_down,
ret = send_data(ctx->conn,
cmdbuf, sizeof(cmdbuf));
if (ret)
return CUPS_BACKEND_FAILED;
@ -450,16 +442,16 @@ top:
}
/* Send RESET */
if (ctx->type != P_SONY_UPD895) {
if (ctx->conn->type != P_SONY_UPD895) {
const uint8_t rstbuf[7] = { 0x1b, 0x16, 0, 0, 0, 0, 0 };
ret = send_data(ctx->dev, ctx->endp_down,
ret = send_data(ctx->conn,
rstbuf, sizeof(rstbuf));
if (ret)
return CUPS_BACKEND_FAILED;
}
#if 0 /* Unknown query */
if (ctx->type == P_SONY_UPD897) {
if (ctx->conn->type == P_SONY_UPD897) {
// -> 1b e6 00 00 00 08 00
// <- ???
}
@ -474,7 +466,7 @@ top:
i += sizeof(uint32_t);
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
job->databuf + i, len)))
return CUPS_BACKEND_FAILED;
@ -605,7 +597,7 @@ static const char *sonyupd_prefixes[] = {
struct dyesub_backend sonyupd_backend = {
.name = "Sony UP-D",
.version = "0.39",
.version = "0.40",
.uri_prefixes = sonyupd_prefixes,
.cmdline_arg = upd_cmdline_arg,
.cmdline_usage = upd_cmdline,

View File

@ -69,11 +69,7 @@ struct updneo_sts {
};
struct updneo_ctx {
struct libusb_device_handle *dev;
uint8_t endp_up;
uint8_t endp_down;
int iface;
int type;
struct dyesub_connection *conn;
int native_bpp;
@ -113,19 +109,14 @@ static void* updneo_init(void)
return ctx;
}
static int updneo_attach(void *vctx, struct libusb_device_handle *dev, int type,
uint8_t endp_up, uint8_t endp_down, int iface, uint8_t jobid)
static int updneo_attach(void *vctx, struct dyesub_connection *conn, uint8_t jobid)
{
struct updneo_ctx *ctx = vctx;
int ret;
UNUSED(jobid);
ctx->dev = dev;
ctx->endp_up = endp_up;
ctx->endp_down = endp_down;
ctx->type = type;
ctx->iface = iface;
ctx->conn = conn;
if (test_mode < TEST_MODE_NOATTACH) {
if ((ret = updneo_get_status(ctx))) {
@ -133,7 +124,7 @@ static int updneo_attach(void *vctx, struct libusb_device_handle *dev, int type,
}
}
if (ctx->type == P_SONY_UPD898) {
if (ctx->conn->type == P_SONY_UPD898) {
ctx->marker.color = "#000000"; /* Ie black! */
ctx->native_bpp = 1;
@ -334,7 +325,7 @@ static struct deviceid_dict dict[MAX_DICT];
static int updneo_get_status(struct updneo_ctx *ctx)
{
char *ieee_id = get_device_id(ctx->dev, ctx->iface);
char *ieee_id = get_device_id(ctx->conn->dev, ctx->conn->iface);
int i;
if (!ieee_id)
@ -488,17 +479,17 @@ top:
}
/* Send over header */
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
job->hdrbuf, job->hdrlen)))
return CUPS_BACKEND_FAILED;
/* Send over data */
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
job->databuf, job->datalen)))
return CUPS_BACKEND_FAILED;
/* Send over footer */
if ((ret = send_data(ctx->dev, ctx->endp_down,
if ((ret = send_data(ctx->conn,
job->ftrbuf, job->ftrlen)))
return CUPS_BACKEND_FAILED;
@ -569,18 +560,14 @@ static int updneo_cmdline_arg(void *vctx, int argc, char **argv)
return CUPS_BACKEND_OK;
}
static int updneo_query_serno(struct libusb_device_handle *dev, uint8_t endp_up, uint8_t endp_down, int iface, char *buf, int buf_len)
static int updneo_query_serno(struct dyesub_connection *conn, char *buf, int buf_len)
{
int ret;
char *ptr;
struct updneo_ctx ctx = {
.dev = dev,
.endp_up = endp_up,
.endp_down = endp_down,
.conn = conn,
};
UNUSED(iface);
if ((ret = updneo_get_status(&ctx))) {
return ret;
}
@ -605,7 +592,7 @@ static int updneo_query_markers(void *vctx, struct marker **markers, int *count)
return ret;
}
if (ctx->type != P_SONY_UPD898) {
if (ctx->conn->type != P_SONY_UPD898) {
ctx->marker.levelnow = ctx->sts.scmds[4];
}
@ -629,7 +616,7 @@ static const char *sonyupdneo_prefixes[] = {
struct dyesub_backend sonyupdneo_backend = {
.name = "Sony UP-D Neo",
.version = "0.10",
.version = "0.11",
.uri_prefixes = sonyupdneo_prefixes,
.cmdline_arg = updneo_cmdline_arg,
.cmdline_usage = updneo_cmdline,