s2145: Get rid of early parse.

This commit is contained in:
Solomon Peachy 2015-07-02 22:43:43 -04:00
parent 3965f237ed
commit 8f1243de31

View file

@ -99,8 +99,6 @@ struct shinkos2145_ctx {
struct s2145_printjob_hdr hdr;
uint32_t model;
uint8_t *databuf;
int datalen;
};
@ -684,11 +682,11 @@ struct s2145_status_resp {
static char *bank_statuses(uint8_t v)
{
switch (v) {
case 0:
case BANK_STATUS_FREE:
return "Free";
case 1:
case BANK_STATUS_XFER:
return "Xfer";
case 2:
case BANK_STATUS_FULL:
return "Full";
default:
return "Unknown";
@ -1438,7 +1436,6 @@ static void shinkos2145_attach(void *vctx, struct libusb_device_handle *dev,
ctx->jobid = (jobid & 0x7f) + 1;
}
static void shinkos2145_teardown(void *vctx) {
struct shinkos2145_ctx *ctx = vctx;
@ -1451,18 +1448,19 @@ static void shinkos2145_teardown(void *vctx) {
free(ctx);
}
static int shinkos2145_early_parse(void *vctx, int data_fd) {
static int shinkos2145_read_parse(void *vctx, int data_fd) {
struct shinkos2145_ctx *ctx = vctx;
int printer_type, ret;
int ret;
uint8_t tmpbuf[4];
if (!ctx)
return -1;
return CUPS_BACKEND_FAILED;
/* Read in then validate header */
ret = read(data_fd, &ctx->hdr, sizeof(ctx->hdr));
if (ret < 0 || ret != sizeof(ctx->hdr)) {
if (ret == 0)
return -1; /* deliberate */
return CUPS_BACKEND_CANCEL;
ERROR("Read failed (%d/%d/%d)\n",
ret, 0, (int)sizeof(ctx->hdr));
perror("ERROR: Read failed");
@ -1473,42 +1471,20 @@ static int shinkos2145_early_parse(void *vctx, int data_fd) {
le32_to_cpu(ctx->hdr.len2) != 0x64 ||
le32_to_cpu(ctx->hdr.dpi) != 300) {
ERROR("Unrecognized header data format!\n");
return -1;
return CUPS_BACKEND_CANCEL;
}
ctx->model = le32_to_cpu(ctx->hdr.model);
switch(ctx->model) {
case 2145:
printer_type = P_SHINKO_S2145;
break;
case 6145:
case 6245:
default:
if (le32_to_cpu(ctx->hdr.model) != 2145) {
ERROR("Unrecognized printer (%d)!\n", le32_to_cpu(ctx->hdr.model));
return -1;
return CUPS_BACKEND_CANCEL;
}
INFO("File intended for an S%d printer\n", ctx->model);
return printer_type;
}
static int shinkos2145_read_parse(void *vctx, int data_fd) {
struct shinkos2145_ctx *ctx = vctx;
int ret;
uint8_t tmpbuf[4];
if (!ctx)
return CUPS_BACKEND_FAILED;
if (ctx->databuf) {
free(ctx->databuf);
ctx->databuf = NULL;
}
ctx->datalen = le32_to_cpu(ctx->hdr.rows) * le32_to_cpu(ctx->hdr.columns) * 3;
ctx->databuf = malloc(ctx->datalen);
if (!ctx->databuf) {
@ -1645,19 +1621,13 @@ static int shinkos2145_main_loop(void *vctx, int copies) {
print->hdr.cmd = cpu_to_le16(S2145_CMD_PRINTJOB);
print->hdr.len = cpu_to_le16(sizeof (*print) - sizeof(*cmd));
if (ctx->model == 2145) {
print->id = ctx->jobid;
print->count = cpu_to_le16(copies);
print->columns = cpu_to_le16(le32_to_cpu(ctx->hdr.columns));
print->rows = cpu_to_le16(le32_to_cpu(ctx->hdr.rows));
print->media = le32_to_cpu(ctx->hdr.media);
print->mode = le32_to_cpu(ctx->hdr.mode);
print->method = le32_to_cpu(ctx->hdr.method);
} else {
// s6145, s6245 use different fields
ERROR("Don't know how to initiate print on non-2145 models!\n");
return CUPS_BACKEND_FAILED;
}
print->id = ctx->jobid;
print->count = cpu_to_le16(copies);
print->columns = cpu_to_le16(le32_to_cpu(ctx->hdr.columns));
print->rows = cpu_to_le16(le32_to_cpu(ctx->hdr.rows));
print->media = le32_to_cpu(ctx->hdr.media);
print->mode = le32_to_cpu(ctx->hdr.mode);
print->method = le32_to_cpu(ctx->hdr.method);
if ((ret = s2145_do_cmd(ctx,
cmdbuf, sizeof(*print),
@ -1764,29 +1734,21 @@ static int shinkos2145_query_serno(struct libusb_device_handle *dev, uint8_t end
/* Exported */
#define USB_VID_SHINKO 0x10CE
#define USB_PID_SHINKO_S2145 0x000E
#define USB_PID_SHINKO_S6145 0x0019
#define USB_PID_SHINKO_S6245 0x001D
//#define USB_VID_CIAAT xxxxxx
//#define USB_PID_CIAAT_BRAVA21 xxxxx
struct dyesub_backend shinkos2145_backend = {
.name = "Shinko/Sinfonia CHC-S2145",
.version = "0.40",
.version = "0.41",
.uri_prefix = "shinkos2145",
.cmdline_usage = shinkos2145_cmdline,
.cmdline_arg = shinkos2145_cmdline_arg,
.init = shinkos2145_init,
.attach = shinkos2145_attach,
.teardown = shinkos2145_teardown,
.early_parse = shinkos2145_early_parse,
.read_parse = shinkos2145_read_parse,
.main_loop = shinkos2145_main_loop,
.query_serno = shinkos2145_query_serno,
.devices = {
{ USB_VID_SHINKO, USB_PID_SHINKO_S2145, P_SHINKO_S2145, ""},
// { USB_VID_SHINKO, USB_PID_SHINKO_S6145, P_SHINKO_S2145, ""},
// { USB_VID_SHINKO, USB_PID_SHINKO_S6245, P_SHINKO_S2145, ""},
// { USB_VID_CIAAT, USB_PID_CIAAT_BRAVA21, P_SHINKO_S2145, ""},
{ 0, 0, 0, ""}
}
};
@ -1810,25 +1772,6 @@ struct dyesub_backend shinkos2145_backend = {
04 03 02 01 [[ footer ]]
* CHC-S6245 data format
Spool file consists of an 116-byte header, followed by RGB-packed data,
followed by a 4-byte footer. Header appears to consist of a series of
4-byte Little Endian words.
10 00 00 00 MM MM 00 00 01 00 00 00 01 00 00 00 MM == Model (ie 6245d)
64 00 00 00 00 00 00 00 TT 00 00 00 00 00 00 00 TT == 0x20 8x4, 0x21 8x5, 0x22 8x6, 0x23 8x8, 0x10 8x10, 0x11 8x12
00 00 00 00 00 00 00 00 XX 00 00 00 00 00 00 00 XX == 0x03 matte, 0x02 glossy, 0x01 no coat
00 00 00 00 WW WW 00 00 HH HH 00 00 NN 00 00 00 WW/HH Width, Height (LE), NN == Copies
00 00 00 00 00 00 00 00 00 00 00 00 ce ff ff ff
00 00 00 00 ce ff ff ff QQ QQ 00 00 ce ff ff ff QQ == DPI (300)
00 00 00 00 ce ff ff ff 00 00 00 00 00 00 00 00
00 00 00 00
[[Packed RGB payload of WW*HH*3 bytes]]
04 03 02 01 [[ footer ]]
* CHC-S6145 data format
Spool file consists of an 116-byte header, followed by RGB-packed data,