summaryrefslogtreecommitdiffstats
path: root/backend_sonyupdneo.c
blob: 0d10693005069c1ab0fc08200f30f7a9af7cec2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
/*
 *   Sony UP-D series (new) Photo Printer CUPS backend -- libusb-1.0 version
 *
 *   (c) 2019 Solomon Peachy <pizza@shaftnet.org>
 *
 *   The latest version of this program can be found at:
 *
 *     http://git.shaftnet.org/cgit/selphy_print.git
 *
 *   This program is free software; you can redistribute it and/or modify it
 *   under the terms of the GNU General Public License as published by the Free
 *   Software Foundation; either version 3 of the License, or (at your option)
 *   any later version.
 *
 *   This program is distributed in the hope that it will be useful, but
 *   WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 *   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 *   for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 *          [http://www.gnu.org/licenses/gpl-3.0.html]
 *
 *   SPDX-License-Identifier: GPL-3.0+
 *
 */

#define BACKEND sonyupdneo_backend

#include "backend_common.h"

/* Private data structures */
struct updneo_printjob {
	uint8_t *databuf;
	int datalen;
	uint8_t *hdrbuf;
	int hdrlen;
	uint8_t *ftrbuf;
	int ftrlen;

//	int copies_offset;  // XXX eventually implement

	int copies;

	uint16_t rows;
	uint16_t cols;
};

struct updneo_ctx {
	struct libusb_device_handle *dev;
	uint8_t endp_up;
	uint8_t endp_down;
	int iface;
	int type;

	int native_bpp;

	struct marker marker;
};

/* Forward declaration */
static int updneo_get_status(struct updneo_ctx *ctx);

/* Now for the code */
static void* updneo_init(void)
{
	struct updneo_ctx *ctx = malloc(sizeof(struct updneo_ctx));
	if (!ctx) {
		ERROR("Memory Allocation Failure!\n");
		return NULL;
	}
	memset(ctx, 0, sizeof(struct updneo_ctx));
	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)
{
	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;

	/* Query printer status */
	if ((ret = updneo_get_status(ctx))) {
		return ret;
	}

	if (ctx->type == P_SONY_UPD898) {
		ctx->marker.color = "#000000";  /* Ie black! */
		ctx->native_bpp = 1;
	} else {
		ctx->marker.color = "#00FFFF#FF00FF#FFFF00";
		ctx->native_bpp = 3;
	}

	ctx->marker.name = "Unknown";
	ctx->marker.numtype = -1;
	ctx->marker.levelmax = -1;
	ctx->marker.levelnow = -2;

	return CUPS_BACKEND_OK;
}

static void updneo_cleanup_job(const void *vjob)
{
	const struct updneo_printjob *job = vjob;

	if (job->databuf)
		free(job->databuf);
	if (job->hdrbuf)
		free(job->hdrbuf);
	if (job->ftrbuf)
		free(job->ftrbuf);

	free((void*)job);
}

#define MAX_PRINTJOB_LEN (3400*2392*3 + 2048)

static int updneo_read_parse(void *vctx, const void **vjob, int data_fd, int copies) {
	struct updneo_ctx *ctx = vctx;
	int run = 1;

	uint8_t tmpbuf[257];

	struct updneo_printjob *job = NULL;

	if (!ctx)
		return CUPS_BACKEND_FAILED;

	/* Allocate job */
	job = malloc(sizeof(*job));
	if (!job) {
		ERROR("Memory allocation failure!\n");
		return CUPS_BACKEND_RETRY_CURRENT;
	}
	memset(job, 0, sizeof(*job));

	/* Read in data chunks. */
	while(run) {
		uint8_t *ptr = NULL;
		int i, len, *lenptr;

		/* Read in data block header (256 bytes) */
		i = read(data_fd, tmpbuf, 256);
		if (i < 0) {
			updneo_cleanup_job(job);
			return CUPS_BACKEND_CANCEL;
		}
		if (i == 0)
			break;

		/* Explicitly null terminate just in case */
		tmpbuf[256] = 0;

		/* Parse header.  Format:

		   JOBSIZE=pdlname,blocklen,printsize,arg1,..,argN<NULL>

		*/

		if (strncmp("JOBSIZE=", (char*) tmpbuf, 8)) {
			updneo_cleanup_job(job);
			ERROR("Invalid spool format!\n");
			return CUPS_BACKEND_CANCEL;
		}

		/* PDL type */
		char *tok = strtok((char*)&tmpbuf[8], "\r\n,");
		if (!tok) {
			updneo_cleanup_job(job);
			ERROR("Invalid spool format (PDL)!\n");
			return CUPS_BACKEND_CANCEL;
		}

		/* Payload length */
		char *tokl = strtok(NULL, "\r\n,");
		if (!tokl) {
			updneo_cleanup_job(job);
			ERROR("Invalid spool format (block length missing)!\n");
			return CUPS_BACKEND_CANCEL;
		}
		len = atoi(tokl);
		if (len == 0 || len > MAX_PRINTJOB_LEN) {
			updneo_cleanup_job(job);
			ERROR("Invalid spool format (block length %d)!\n", len);
			return CUPS_BACKEND_CANCEL;
		}

		/* Behavior based on the various PDL blocks */
		if (!strncmp("PJL-H", tok, 5)) {
			job->hdrbuf = malloc(len);
			if (!job->hdrbuf) {
				ERROR("Memory allocation failure!\n");
				updneo_cleanup_job(job);
				return CUPS_BACKEND_RETRY_CURRENT;
			}
			ptr = job->hdrbuf;
			lenptr = &job->hdrlen;
		} else if (!strncmp("PJL-T", tok, 5)) {
			job->ftrbuf = malloc(len);
			if (!job->ftrbuf) {
				ERROR("Memory allocation failure!\n");
				updneo_cleanup_job(job);
				return CUPS_BACKEND_RETRY_CURRENT;
			}
			ptr = job->ftrbuf;
			lenptr = &job->ftrlen;
			run = 0;
		} else if (!strncmp("PDL", tok, 3)) {
			job->databuf = malloc(len);
			if (!job->databuf) {
				ERROR("Memory allocation failure!\n");
				updneo_cleanup_job(job);
				return CUPS_BACKEND_RETRY_CURRENT;
			}
			ptr = job->databuf;
			lenptr = &job->datalen;
		} else {
			ERROR("Unrecognized PDL type '%s'\n", tok);
			updneo_cleanup_job(job);
			return CUPS_BACKEND_CANCEL;
		}

//		DEBUG("Read block '%s' @ %d ...\n", tok, job->datalen);

//		DEBUG("...len '%d'\n", len);

		// parse the rest?
		// 898MD: 6,0,0,0
		// D80MD: 4
		// CR20L: 64,0,0,0

		/* Read in the data chunk */
		while(len > 0) {
			i = read(data_fd, ptr + *lenptr, len);
			if (i < 0) {
				updneo_cleanup_job(job);
				return CUPS_BACKEND_CANCEL;
			}
			if (i == 0)
				break;

			*lenptr += i;
			len -= i;
		}
	}

	if (!job->datalen || !job->hdrlen || !job->ftrlen) {
		ERROR("Necessary block missing!\n");
		updneo_cleanup_job(job);
		return CUPS_BACKEND_CANCEL;
	}

	/* Sanity check job parameters */
	// rows * cols lines up with imgsize, and others?

	// set job copies to max(job, parameter)
	// job->copies = copies;
	job->copies = 1;  /* Printer makes copies */
	UNUSED(copies);

	*vjob = job;

	return CUPS_BACKEND_OK;
}

static int dlen;
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);

	if (!ieee_id)
		return CUPS_BACKEND_FAILED;

	dlen = parse1284_data(ieee_id, dict);

	// XXXX do something:
	// pull out what we care about..
	// parse out ALL fields in dict.
	// warn if there are extras.

	/* Clean up */
	if (ieee_id) free(ieee_id);
	while (dlen--) {
		free (dict[dlen].key);
		free (dict[dlen].val);
	}

	return CUPS_BACKEND_OK;
}

static int updneo_main_loop(void *vctx, const void *vjob) {
	struct updneo_ctx *ctx = vctx;
	int ret;
	int copies;

	const struct updneo_printjob *job = vjob;

	if (!ctx)
		return CUPS_BACKEND_FAILED;
	if (!job)
		return CUPS_BACKEND_FAILED;

	copies = job->copies;

top:

	/* Query printer status */
	if ((ret = updneo_get_status(ctx))) {
		return ret;
	}

	// XXX Sanity check job parameters vs printer status
	// Check for idle

	/* Send over header */
	if ((ret = send_data(ctx->dev, ctx->endp_down,
			     job->hdrbuf, job->hdrlen)))
		return CUPS_BACKEND_FAILED;

	/* Send over data */
	if ((ret = send_data(ctx->dev, ctx->endp_down,
			     job->databuf, job->datalen)))
		return CUPS_BACKEND_FAILED;

	/* Send over footer */
	if ((ret = send_data(ctx->dev, ctx->endp_down,
			     job->ftrbuf, job->ftrlen)))
		return CUPS_BACKEND_FAILED;

	/* Wait for completion! */
retry:
	sleep(1);

	if ((ret = updneo_get_status(ctx))) {
		return ret;
	}

	// Check for idle
	if (fast_return /*&& ctx->stsbuf.printing > 0 */) {
		INFO("Fast return mode enabled.\n");
	} else {
		goto retry;
	}

	/* Clean up */
	if (terminate)
		copies = 1;

	INFO("Print complete (%d copies remaining)\n", copies - 1);

	if (copies && --copies) {
		goto top;
	}

	return CUPS_BACKEND_OK;
}

static int updneo_cmdline_arg(void *vctx, int argc, char **argv)
{
	struct updneo_ctx *ctx = vctx;
	int i, j = 0;

	if (!ctx)
		return -1;

	while ((i = getopt(argc, argv, GETOPT_LIST_GLOBAL "s")) >= 0) {
		switch(i) {
		GETOPT_PROCESS_GLOBAL
		case 's':
			j = updneo_get_status(ctx);
			break;
		}

		if (j) return j;
	}

	return 0;
}

static int updneo_query_markers(void *vctx, struct marker **markers, int *count)
{
	struct updneo_ctx *ctx = vctx;
	int ret;

	*markers = &ctx->marker;
	*count = 1;

	/* Query printer status */
	if ((ret = updneo_get_status(ctx))) {
		return ret;
	}

	// XXX Do something with results...

	return CUPS_BACKEND_OK;
}

static const char *sonyupdneo_prefixes[] = {
	"sonyupdneo",
	"sony-upd898", "sony-upcr20l", "sony-updr80", "sony-updr80md",
	"dnp-sl20",
	NULL
};

/* Exported */
#define USB_VID_SONY         0x054C
#define USB_PID_SONY_UPD898MD 0xabcd // 0x589a?
#define USB_PID_SONY_UPCR20L  0xbcde
#define USB_PID_SONY_UPDR80MD 0x03c3
#define USB_PID_SONY_UPDR80   0x03c5
#define USB_PID_SONY_UPCX1    0x02d4

struct dyesub_backend sonyupdneo_backend = {
	.name = "Sony UP-D Neo",
	.version = "0.04WIP",
	.uri_prefixes = sonyupdneo_prefixes,
	.cmdline_arg = updneo_cmdline_arg,
	.init = updneo_init,
	.attach = updneo_attach,
	.cleanup_job = updneo_cleanup_job,
	.read_parse = updneo_read_parse,
	.main_loop = updneo_main_loop,
	.query_markers = updneo_query_markers,
	.devices = {
		{ USB_VID_SONY, USB_PID_SONY_UPD898MD, P_SONY_UPD898, NULL, "sony-upd898"},
		{ USB_VID_SONY, USB_PID_SONY_UPCR20L, P_SONY_UPCR20L, NULL, "sony-upcr20l"},
		{ USB_VID_SONY, USB_PID_SONY_UPDR80, P_SONY_UPDR80, NULL, "sony-updr80"},
		{ USB_VID_SONY, USB_PID_SONY_UPDR80MD, P_SONY_UPDR80, NULL, "sony-updr80md"},

		{ 0, 0, 0, NULL, NULL}
	}
};

/* Sony UP-D (new) printer spool format

   Covers UP-CR20L, UP-DR80/DR80MD, UP-D898/UP-X898

  HP-PJL wrapper around custom Sony PDL:

    JOBSIZE=PJL-H,size,arg1,arg2,etc   [null terminated, padded to 256 bytes]
    [ size bytes of PJL header! ]
    JOBSIZE=PDL,size,args [null terminated, padded to 256 bytes]
    [ size bytes of PDL data! ]
    JOBSIZE=PJL-T,size,args [null terminated, padded to 256 bytes]
    [ size bytes of PJL trailer! ]

  PJL header:

   <ESC>%-12345X<CR><LF>
   @PJL COMMENT free form text here <CR><LF>
   @PJL JOB NAME="name me" ID="someid"<CR><LF>
   @PJL .... <CR><LF>
   @PJL ENTER LANGUAGE=SONY-PDL-DS2<CR><LF>

  PJL footer:

   @PJL EOJ<CR><LF>
   <ESC>%-12345X<CR><LF>

  PDL notes:

   size is the length mentioned in the payload (ie rows * cols * planes)
   plus the PDL header (varies) and PDL footer (7 bytes)


 UP-D898MD:  18*16+2 == 290 byte header

  00000250                                             00 00   YY YY = rows
  00000260  01 00 00 10 0f 00 1c 00  00 00 00 00 00 00 00 00   XX XX = columns (fixed at 05 00)
  00000270  00 00 00 00 00 01 02 00  09 00 NN 01 00 11 01 08   NN = Copies (01..?)  <-- GUESS
  00000280  00 1a 00 00 00 00 XX XX  YY YY 09 00 28 01 00 d4
  00000290  00 00 03 58 YY YY 00 00  13 01 00 04 00 80 00 23
  000002a0  00 0c 01 09 XX XX YY YY  00 00 00 00 08 ff 08 00
  000002b0  19 00 00 00 00 XX XX YY  YY 00 00 81 80 00 8f 00
  000002c0  b8 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
  000002d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
  000002f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
  00000300  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
  00000310  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
  00000320  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
  00000330  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
  00000340  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
  00000350  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
  00000360  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
  00000370  00 00 00 00 00 00 00 00  00 c0 00 82 LL LL LL LL   LL == payload bytes, BE (== XX * YY * 1)

   [payload of LL bytes follows]

 UP-CR20L:   290 byte header, 330 dpi, 1210x1728/1382x2048/1728*2380/2724*2048 (L/PC/2L/2PC)

  00000250                                             00 00
  00000260  01 00 00 10 0f 00 1c 00  00 00 00 00 00 00 00 00
  00000270  00 00 01 00 00 00 02 00  16 00 00 02 00 09 00 NN   NN = Copies (01..??)
  00000280  02 00 06 01 01 03 00 1d  00 00 00 01 00 20 01 01
  00000290  00 27 40 01 00 11 01 08  00 1a 00 00 00 00 RR RR
  000002a0  CC CC 00 00 13 01 00 04  00 80 00 23 00 10 03 00   CC CC == Columns  (BE)
  000002b0  RR RR CC CC 00 00 00 00  08 08 08 ff ff ff 01 00   RR RR == Rows     (BE)
  000002c0  17 00 08 00 19 00 00 00  00 RR RR CC CC 00 00 81
  000002d0  80 00 8f 00 a4 00 00 00  00 00 00 00 00 00 00 00
  000002e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
  000002f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
  00000300  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
  00000310  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
  00000320  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
  00000330  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
  00000340  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
  00000350  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
  00000360  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
  00000370  00 00 00 00 00 00 00 00  00 c0 00 82 LL LL LL LL   LL == payload bytes, BE (== RR * CC * 3)

   [payload of LL bytes follows]

 UP-DR80MD:   (19*16+8) = 312 byte header  (A4 = 3400x2392, Letter = 3192*2464)

  00000240                           00 00 01 00 00 10 0f 00
  00000250  1c 00 00 00 00 00 00 00  00 00 00 00 00 00 00 ZZ   ZZ = 0x00 (Letter) 0x56 (A4)
  00000260  02 00 16 00 01 80 00 15  00 12 55 50 44 52 38 30   SS = 0x00 (LUT0) 0xff (No LUT)
  00000270  00 00 4c 55 54 QQ 00 00  00 00 00 SS 02 00 09 00   QQ = 0x30 (LUT0) 0x2f (No LUT)
  00000280  NN 02 00 06 01 03 04 00  1d 01 00 00 05 01 00 20   NN = Copies (01...??)
  00000290  00 01 00 11 01 08 00 1a  00 00 00 00 CC CC RR RR   RR RR = Rows (BE)
  000002a0  00 00 13 01 00 04 00 80  00 23 00 10 03 00 CC CC   CC CC = Cols (BE)
  000002b0  RR RR 00 00 00 00 08 08  08 ff ff ff 01 00 17 00
  000002c0  08 00 19 00 00 00 00 CC  CC RR RR 00 00 81 80 00
  000002d0  8f 00 a6 00 00 00 00 00  00 00 00 00 00 00 00 00
  000002e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
  000002f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
  00000300  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
  00000310  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
  00000320  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
  00000330  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
  00000340  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
  00000350  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
  00000360  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
  00000370  00 00 00 00 00 00 00 00  00 c0 00 82 LL LL LL LL  LL == payload, BE (== RR * CC * 3)

   [payload of LL bytes follows]

 Common sequences:

  [ D898 ]

  [00 00 01 00 00 10 0f 00  1c 00 00 00 00 00 00 00
   00 00 00 00]00 00 00 01 [02 00 09 00 NN]01 00 11
   01 08 00 1a 00 00 00 00  XX XX YY YY 09 00 28 01
   00 d4 00 00 03 58 YY YY  00 00[13 01 00 04 00 80
   00 23]00 0c 01 09 XX XX  YY YY 00 00 00 00 08 ff
  [08 00 19 00 00 00 00 XX  XX YY YY 00 00 81 80 00
   8f 00 b8]

   [ 0xb8 of 0x00 ] ... c0 00 82 LL LL LL LL

  [ CR20L ]

  [00 00 01 00 00 10 0f 00  1c 00 00 00 00 00 00 00
   00 00 00 00]01 00 00 00  02 00 16 00 00[02 00 09
   00 NN]02 00 06 01 01 03  00 1d 00 00 00*01 00 20
   01 01 00 27 40 01 00 11  01 08 00 1a 00 00 00 00
   RR RR CC CC 00 00[13 01  00 04 00 80 00 23]00 10
   03 00 RR RR CC CC 00 00  00 00 08 08 08 ff ff ff
   01 00 17 00[08 00 19 00  00 00 00 RR RR CC CC 00
   00 81 80 00 8f 00 a4]

    * 03 00 13 00 01 02   [inserted when using multicut ]

   [ 0xa4 of 0x00 ] ... c0 00 82 LL LL LL LL

  [ UP-DR80MD ]

  [00 00 01 00 00 10 0f 00  1c 00 00 00 00 00 00 00
   00 00 00 00]00 00 00 ZZ  02 00 16 00 01 80 00 15
   00 12 55 50 44 52 38 30  00 00 4c 55 54 QQ 00 00
   00 00 00 SS[02 00 09 00  NN]02 00 06 01 03 04 00
   1d 01 00 00 05 01 00 20  00 01 00 11 01 08 00 1a
   00 00 00 00 CC CC RR RR  00 00[13 01 00 04 00 80
   00 23]00 10 03 00 CC CC  RR RR 00 00 00 00 08 08
   08 ff ff ff 01 00 17 00 [08 00 19 00 00 00 00 CC
   CC RR RR 00 00 81 80 00  8f 00 a6]

   [ 0xa6 of 0x00 ] ... c0 00 82 LL LL LL LL

 *********

   02 00 09 00 NN  <- Copy count
   00 00 00 ZZ     <- Media type?

   27 54 01 00

   00 10 03 00 RR RR CC CC
   08 00 19 00 00 00 00 00 RR RR CC CC 00 00 81 80 00 8f 00 a4

 *****************

  PRINTER COMMS:

   * Strip out "JOBSIZE=" headers
   * Send PJL header
   * Send PDL payload  (every 9*256KB, do a status query..)
   * Send PJL footer

  PJL header and footer need to be sent separately.
  the PJL wrapper around the PDL block needs to be
  stripped.

  ***********

  It appears that the printer status is tacked onto the IEEE1284 string:  Examples:

    MFG:SONY;MDL:UP-DR80MD;DES:Sony UP-DR80MD;CMD:SPJL-DS,SPDL-DS;CLS:PRINTER;SCDIV:0100;SCSYV:01060000;SCSNO:0000000000089864;SCSYS:0000001000010001000100;SCMDS:00000000002C002C002C;SCPRS:0000;SCSES:0000;SCWTS:0000;SCJBS:0000;SCSYE:00;SCMDE:0000;SCMCE:00;SCJBI:0000000000000000;SCSYI:0A300E5609A00C7809A00C78012D00;SCSVI:000342000342;SCMNI:000342000342;SCCAI:00000000000000;SCGAI:0000;SCGSI:00;SCMDI:110154

    MFG:SONY;MDL:UP-DR80MD;DES:Sony UP-DR80MD;CMD:SPJL-DS,SPDL-DS;CLS:PRINTER;SCDIV:0100;SCSYV:01060000;SCSNO:0000000000089864;SCSYS:0000011000010001000000;SCMDS:00000000002C002C002C;SCPRS:0005;SCSES:0000;SCWTS:0000;SCJBS:0000;SCSYE:00;SCMDE:0000;SCMCE:00;SCJBI:0000000000000000;SCSYI:0A300E5609A00C7809A00C78012D00;SCSVI:000342000342;SCMNI:000342000342;SCCAI:00000000000000;SCGAI:0000;SCGSI:00;SCMDI:110154

    MFG:SONY;MDL:UP-DR80MD;DES:Sony UP-DR80MD;CMD:SPJL-DS,SPDL-DS;CLS:PRINTER;SCDIV:0100;SCSYV:01060000;SCSNO:0000000000089864;SCSYS:0000001000010001000100;SCMDS:00000000002B002B002B;SCPRS:0000;SCSES:0000;SCWTS:0000;SCJBS:0000;SCSYE:00;SCMDE:0000;SCMCE:00;SCJBI:0000000000000000;SCSYI:0A300E5609A00C7809A00C78012D00;SCSVI:000343000343;SCMNI:000343000343;SCCAI:00000000000000;SCGAI:0000;SCGSI:00;SCMDI:110154

Breakdown:

  (+) means referenced by their Windows driver

  SCDIV
 +SCSYV
  SCSNO  # SerialNO (?)
 +SCSYS  # some sort of state array? 22 fields.  b19 is 1 when data can be sent?, b5 is 1 when printer busy?, b20:21 is 64 sometimes, maybe paper or ribbon feed?
 +SCMDS  # MeDiaStatus: five 4-value hex numbers, last three decrease in unison (remaining prints). second one is 0000/0100/0200/0300/0600, maybe Y/M/C/O?
  SCPRS  # PRinterStatus: (0000 = idle, 0002 = printing, 0005 = data xfer?)
 +SCSES
 +SCWTS
 +SCJBS  # some sort of job count?
  SCSYE
 +SCMDE  # MeDia???
 +SCMCE
  SCJBI
  SCSYI
 +SCSVI  # print counter(s)?  (XXXXXXYYYYYY, and X = Y so far.  SCSVI and SCMNI are identical so far)
  SCMNI  # print counter(s)?  (see SCSVI)
  SCCAI
  SCGAI
  SCGSI
 +SCMDI  # MeDia???

Guess:

  SCxxY  SC = Sony Corp
         xx = class (MD = media?)
          Y = var type (S = status, I = info, E = error V = ?, O

 */