| 1 | /* |
| 2 | * Mitsubishi CP-9xxx Photo Printer Family CUPS backend |
| 3 | * |
| 4 | * (c) 2014-2025 Solomon Peachy <[email protected]> |
| 5 | * |
| 6 | * The latest version of this program can be found at: |
| 7 | * |
| 8 | * https://git.shaftnet.org/gitea/slp/selphy_print.git |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify it |
| 11 | * under the terms of the GNU General Public License as published by the Free |
| 12 | * Software Foundation; either version 2 of the License, or (at your option) |
| 13 | * any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, but |
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 17 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 18 | * for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, see <https://www.gnu.org/licenses/>. |
| 22 | * |
| 23 | * SPDX-License-Identifier: GPL-2.0+ |
| 24 | * |
| 25 | */ |
| 26 | |
| 27 | #define BACKEND mitsu9550_backend |
| 28 | |
| 29 | #include "backend_common.h" |
| 30 | #include "backend_mitsu.h" |
| 31 | |
| 32 | #define MITSU_M98xx_LAMINATE_FILE "M98MATTE.raw" |
| 33 | #define MITSU_M98xx_DATATABLE_FILE "M98TABLE.dat" |
| 34 | #define MITSU_M98xx_LUT_FILE "M98XXL01.lut" |
| 35 | #define MITSU_CP30D_LUT_FILE "CP30LT_1.lut" |
| 36 | #define LAMINATE_STRIDE 1868 |
| 37 | |
| 38 | /* Spool file structures */ |
| 39 | |
| 40 | /* Print parameters1 */ |
| 41 | struct mitsu9550_hdr1 { |
| 42 | uint8_t cmd[4]; /* 1b 57 20 2e */ |
| 43 | uint8_t unk[10]; /* 00 0a 10 00 [...] */ |
| 44 | uint16_t cols; /* BE */ |
| 45 | uint16_t rows; /* BE */ |
| 46 | uint8_t matte; /* CP9810/9820 only. 01 for matte, 00 glossy */ |
| 47 | uint8_t null[31]; |
| 48 | } __attribute__((packed)); |
| 49 | |
| 50 | /* Print parameters2 */ |
| 51 | struct mitsu9550_hdr2 { |
| 52 | uint8_t cmd[4]; /* 1b 57 21 2e */ |
| 53 | uint8_t unk[24]; /* 00 80 00 22 08 03 [...] */ |
| 54 | uint16_t copies; /* BE, 1-680 */ |
| 55 | uint8_t null[2]; |
| 56 | uint8_t cut; /* 00 == normal, 83 == 2x6*2 */ |
| 57 | uint8_t unkb[5]; |
| 58 | uint8_t mode; /* 00 == fine, 80 == superfine */ |
| 59 | uint8_t unkc[11]; /* 00 [...] 00 01 ; note [7][8][9] are cp98xx extensions for sharpness/reversed/lut */ |
| 60 | } __attribute__((packed)); |
| 61 | |
| 62 | /* Fine Deep selection (9550 only) */ |
| 63 | struct mitsu9550_hdr3 { |
| 64 | uint8_t cmd[4]; /* 1b 57 22 2e */ |
| 65 | uint8_t unk[7]; /* 00 40 00 [...] */ |
| 66 | uint8_t mode2; /* 00 == normal, 01 == finedeep */ |
| 67 | uint8_t null[38]; |
| 68 | } __attribute__((packed)); |
| 69 | |
| 70 | /* Error policy? */ |
| 71 | struct mitsu9550_hdr4 { |
| 72 | uint8_t cmd[4]; /* 1b 57 26 2e */ |
| 73 | uint8_t unk[46]; /* 00 70 00 00 00 00 00 00 01 01 00 [...] */ |
| 74 | } __attribute__((packed)); |
| 75 | |
| 76 | /* Data plane header */ |
| 77 | struct mitsu9550_plane { |
| 78 | uint8_t cmd[4]; /* 1b 5a 54 XX */ /* XX == 0x10 if 16bpp, 0x00 for 8bpp */ |
| 79 | uint16_t col_offset; /* BE, normally 0, where we start dumping data */ |
| 80 | uint16_t row_offset; /* BE, normally 0, where we start dumping data */ |
| 81 | uint16_t cols; /* BE */ |
| 82 | uint16_t rows; /* BE */ |
| 83 | } __attribute__((packed)); |
| 84 | |
| 85 | /* Command header */ |
| 86 | struct mitsu9550_cmd { |
| 87 | uint8_t cmd[4]; |
| 88 | } __attribute__((packed)); |
| 89 | |
| 90 | /* Private data structure */ |
| 91 | struct mitsu9550_printjob { |
| 92 | struct dyesub_job_common common; |
| 93 | |
| 94 | uint8_t *databuf; |
| 95 | uint32_t datalen; |
| 96 | |
| 97 | uint16_t rows; |
| 98 | uint16_t cols; |
| 99 | uint32_t plane_len; |
| 100 | int is_raw; |
| 101 | |
| 102 | /* Parse headers separately */ |
| 103 | struct mitsu9550_hdr1 hdr1; |
| 104 | int hdr1_present; |
| 105 | struct mitsu9550_hdr2 hdr2; |
| 106 | int hdr2_present; |
| 107 | struct mitsu9550_hdr3 hdr3; |
| 108 | int hdr3_present; |
| 109 | struct mitsu9550_hdr4 hdr4; |
| 110 | int hdr4_present; |
| 111 | }; |
| 112 | |
| 113 | struct mitsu9550_ctx { |
| 114 | struct dyesub_connection *conn; |
| 115 | |
| 116 | int is_s; |
| 117 | int is_98xx; |
| 118 | int need_lib; |
| 119 | int footer_len; |
| 120 | const char *lut_fname; |
| 121 | |
| 122 | char fwver[7]; /* 6 + null */ |
| 123 | |
| 124 | struct marker marker; |
| 125 | |
| 126 | /* CP98xx stuff */ |
| 127 | struct mitsu_lib lib; |
| 128 | const struct mitsu98xx_data *m98xxdata; |
| 129 | }; |
| 130 | |
| 131 | /* Printer data structures */ |
| 132 | #define CP9XXX_STS_x20 0x20 |
| 133 | #define CP9XXX_STS_x21 0x21 /* struct mitsu9550_status2 */ |
| 134 | #define CP9XXX_STS_x22 0x22 |
| 135 | #define CP9XXX_STS_FWVER 0x23 |
| 136 | #define CP9XXX_STS_MEDIA 0x24 /* struct mitsu9550_media */ |
| 137 | #define CP9XXX_STS_x26 0x26 |
| 138 | #define CP9XXX_STS_x30 0x30 /* struct mitsu9550_status */ |
| 139 | #define CP9XXX_STS_x32 0x32 /* struct mitsucp30_status */ |
| 140 | |
| 141 | struct mitsu9550_media { |
| 142 | uint8_t hdr[2]; /* 24 2e */ |
| 143 | uint8_t unk[12]; |
| 144 | uint8_t type; |
| 145 | uint8_t unka[11]; |
| 146 | uint16_t unkb; /* 0d 00 (CP9810), 00 00 (others?) */ |
| 147 | uint16_t max; /* BE, prints per media */ |
| 148 | uint16_t remain2; /* BE, prints remaining (CP30)*/ |
| 149 | uint16_t remain; /* BE, prints remaining (Everything else) */ |
| 150 | uint8_t unkc[14]; |
| 151 | } __attribute__((packed)); |
| 152 | |
| 153 | struct mitsu9550_status { |
| 154 | uint8_t hdr[2]; /* 30 2e */ |
| 155 | uint8_t null[4]; |
| 156 | uint8_t sts1; // MM |
| 157 | uint8_t nullb[1]; |
| 158 | uint16_t copies; // BE, NN |
| 159 | uint8_t sts2; // ZZ (9600 only?) |
| 160 | uint8_t nullc[5]; |
| 161 | uint8_t sts3; // QQ |
| 162 | uint8_t sts4; // RR |
| 163 | uint8_t sts5; // SS |
| 164 | uint8_t nulld[25]; |
| 165 | uint8_t sts6; // TT |
| 166 | uint8_t sts7; // UU |
| 167 | uint8_t nulle[2]; |
| 168 | } __attribute__((packed)); |
| 169 | |
| 170 | struct mitsucp30_status { |
| 171 | uint8_t hdr[2]; /* 32 2e */ |
| 172 | uint8_t zero[2]; |
| 173 | uint16_t serno[13]; /* UTF16, BE */ |
| 174 | uint8_t sts; /* CP30_STS_* */ |
| 175 | uint8_t sts2; |
| 176 | uint8_t zerob; |
| 177 | uint16_t err; /* CP30_ERR_* */ |
| 178 | uint8_t zeroc[2]; |
| 179 | uint8_t remain; /* on media */ |
| 180 | uint8_t zerod[9]; |
| 181 | } __attribute__((packed)); |
| 182 | |
| 183 | #define CP30_STS_IDLE 0x00 |
| 184 | #define CP30_STS_PRINT 0x20 |
| 185 | |
| 186 | #define CP30_STS_PRINT_A 0x10 //Load |
| 187 | #define CP30_STS_PRINT_B 0x20 //Y |
| 188 | #define CP30_STS_PRINT_C 0x30 //M |
| 189 | #define CP30_STS_PRINT_D 0x40 //C |
| 190 | #define CP30_STS_PRINT_E 0x60 //Eject? |
| 191 | |
| 192 | #define CP30_ERR_OK 0x0000 |
| 193 | #define CP30_ERR_NOPC 0x0303 |
| 194 | #define CP30_ERR_NORIBBON 0x0101 |
| 195 | #define CP30_ERR_TRAYFULL 0x1404 |
| 196 | |
| 197 | struct mitsu9550_status2 { |
| 198 | uint8_t hdr[2]; /* 21 2e */ |
| 199 | uint8_t unk[40]; |
| 200 | uint16_t remain; /* BE, media remaining */ |
| 201 | uint8_t unkb[4]; /* 0a 00 00 01 */ |
| 202 | } __attribute__((packed)); |
| 203 | |
| 204 | static int mitsu9550_main_loop(void *vctx, const void *vjob, int wait_for_return); |
| 205 | |
| 206 | static const char *cp30_errors(uint16_t err) |
| 207 | { |
| 208 | switch(err){ |
| 209 | case CP30_ERR_OK: return "None"; |
| 210 | case CP30_ERR_NOPC: return "No Paper Cassette"; |
| 211 | case CP30_ERR_NORIBBON: return "No Ribbon Loaded"; |
| 212 | case CP30_ERR_TRAYFULL: return "Output Tray Full"; |
| 213 | default: return "Unknown"; |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | static const char *cp30_media_types(uint16_t remain) |
| 218 | { |
| 219 | switch(remain) { |
| 220 | case 80: return "CK30S"; |
| 221 | case 50: return "CK30L"; |
| 222 | default: return "Unknown"; |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | #define CMDBUF_LEN 64 |
| 227 | #define READBACK_LEN 128 |
| 228 | |
| 229 | #define QUERY_STATUS_I \ |
| 230 | const struct mitsu9550_status *sts = (struct mitsu9550_status*) rdbuf; \ |
| 231 | const struct mitsucp30_status *sts30 = (struct mitsucp30_status*) rdbuf; \ |
| 232 | const struct mitsu9550_media *media = (struct mitsu9550_media *) rdbuf; \ |
| 233 | uint16_t donor; \ |
| 234 | /* media */ \ |
| 235 | ret = mitsu9550_get_status(ctx, rdbuf, CP9XXX_STS_MEDIA); \ |
| 236 | if (ret < 0) \ |
| 237 | return CUPS_BACKEND_FAILED; \ |
| 238 | \ |
| 239 | if (ctx->conn->type == P_MITSU_CP30D) { \ |
| 240 | donor = be16_to_cpu(media->remain2); \ |
| 241 | } else { \ |
| 242 | donor = be16_to_cpu(media->remain); \ |
| 243 | } \ |
| 244 | if (donor != ctx->marker.levelnow) { \ |
| 245 | ctx->marker.levelnow = donor; \ |
| 246 | dump_markers(&ctx->marker, 1, 0); \ |
| 247 | } \ |
| 248 | /* Sanity-check media response */ \ |
| 249 | if ((media->remain == 0 && media->remain2 == 0) || media->max == 0) { \ |
| 250 | ERROR("Printer out of media!\n"); \ |
| 251 | return CUPS_BACKEND_STOP; \ |
| 252 | } \ |
| 253 | |
| 254 | #define QUERY_STATUS_II \ |
| 255 | if (ctx->conn->type != P_MITSU_CP30D) { \ |
| 256 | /* struct mitsu9550_status2 *sts2 = (struct mitsu9550_status2*) rdbuf; */ \ |
| 257 | ret = mitsu9550_get_status(ctx, rdbuf, CP9XXX_STS_x21); \ |
| 258 | if (ret < 0) \ |
| 259 | return CUPS_BACKEND_FAILED; \ |
| 260 | /* XXX validate status2 ? */ \ |
| 261 | } |
| 262 | |
| 263 | #define QUERY_STATUS_III \ |
| 264 | /* Check for known errors */ \ |
| 265 | if (sts->sts2 != 0) { \ |
| 266 | ERROR("Printer cover open!\n"); \ |
| 267 | return CUPS_BACKEND_STOP; \ |
| 268 | } |
| 269 | |
| 270 | #define QUERY_STATUS_IIIB \ |
| 271 | /* Check for known errors */ \ |
| 272 | if (sts30->err != CP30_ERR_OK) { \ |
| 273 | ERROR("%s (%04x)!\n", cp30_errors(be16_to_cpu(sts30->err)), be16_to_cpu(sts30->err)); \ |
| 274 | return CUPS_BACKEND_STOP; \ |
| 275 | } |
| 276 | |
| 277 | #define QUERY_STATUS_IV \ |
| 278 | if (ctx->conn->type == P_MITSU_CP30D) { \ |
| 279 | ret = mitsu9550_get_status(ctx, rdbuf, CP9XXX_STS_x32); \ |
| 280 | if (ret < 0) \ |
| 281 | return CUPS_BACKEND_FAILED; \ |
| 282 | \ |
| 283 | if (sts30->sts != CP30_STS_IDLE) { \ |
| 284 | sleep(1); \ |
| 285 | goto top; \ |
| 286 | } \ |
| 287 | QUERY_STATUS_IIIB; \ |
| 288 | } else { \ |
| 289 | ret = mitsu9550_get_status(ctx, rdbuf, CP9XXX_STS_x30); \ |
| 290 | if (ret < 0) \ |
| 291 | return CUPS_BACKEND_FAILED; \ |
| 292 | \ |
| 293 | /* Make sure we're idle */ \ |
| 294 | if (sts->sts5 != 0) { \ |
| 295 | sleep(1); \ |
| 296 | goto top; \ |
| 297 | } \ |
| 298 | QUERY_STATUS_III; \ |
| 299 | } \ |
| 300 | |
| 301 | static int mitsu98xx_fillmatte(struct mitsu9550_printjob *job) |
| 302 | { |
| 303 | int ret; |
| 304 | |
| 305 | /* Fill in the lamination plane header */ |
| 306 | struct mitsu9550_plane *matte = (struct mitsu9550_plane *)(job->databuf + job->datalen); |
| 307 | matte->cmd[0] = 0x1b; |
| 308 | matte->cmd[1] = 0x5a; |
| 309 | matte->cmd[2] = 0x54; |
| 310 | matte->cmd[3] = 0x10; |
| 311 | matte->row_offset = 0; |
| 312 | matte->col_offset = 0; |
| 313 | matte->cols = cpu_to_be16(job->cols); |
| 314 | matte->rows = cpu_to_be16(job->rows); |
| 315 | job->datalen += sizeof(struct mitsu9550_plane); |
| 316 | |
| 317 | ret = mitsu_readlamdata(MITSU_M98xx_LAMINATE_FILE, LAMINATE_STRIDE, |
| 318 | job->databuf, &job->datalen, |
| 319 | job->rows, job->cols, 2); |
| 320 | if (ret) |
| 321 | return ret; |
| 322 | |
| 323 | /* Fill in the lamination plane footer */ |
| 324 | job->databuf[job->datalen++] = 0x1b; |
| 325 | job->databuf[job->datalen++] = 0x50; |
| 326 | job->databuf[job->datalen++] = 0x56; |
| 327 | job->databuf[job->datalen++] = 0x00; |
| 328 | |
| 329 | return CUPS_BACKEND_OK; |
| 330 | } |
| 331 | |
| 332 | static int mitsu9550_get_status(struct mitsu9550_ctx *ctx, uint8_t *resp, int type); |
| 333 | static const char *mitsu9550_media_types(uint8_t type, uint8_t is_s); |
| 334 | |
| 335 | static void *mitsu9550_init(void) |
| 336 | { |
| 337 | struct mitsu9550_ctx *ctx = malloc(sizeof(struct mitsu9550_ctx)); |
| 338 | if (!ctx) { |
| 339 | ERROR("Memory Allocation Failure!\n"); |
| 340 | return NULL; |
| 341 | } |
| 342 | memset(ctx, 0, sizeof(struct mitsu9550_ctx)); |
| 343 | |
| 344 | return ctx; |
| 345 | } |
| 346 | |
| 347 | static int mitsu9550_attach(void *vctx, struct dyesub_connection *conn, uint8_t jobid) |
| 348 | { |
| 349 | struct mitsu9550_ctx *ctx = vctx; |
| 350 | struct mitsu9550_media media; |
| 351 | |
| 352 | UNUSED(jobid); |
| 353 | |
| 354 | ctx->conn = conn; |
| 355 | |
| 356 | if (ctx->conn->type == P_MITSU_9500S || |
| 357 | ctx->conn->type == P_MITSU_9550S || |
| 358 | ctx->conn->type == P_MITSU_9600S || |
| 359 | ctx->conn->type == P_MITSU_9800S || |
| 360 | ctx->conn->type == P_MITSU_9820S) |
| 361 | ctx->is_s = 1; |
| 362 | |
| 363 | if (ctx->conn->type == P_MITSU_9800 || |
| 364 | ctx->conn->type == P_MITSU_9800S || |
| 365 | ctx->conn->type == P_MITSU_9820S || |
| 366 | ctx->conn->type == P_MITSU_9810) { |
| 367 | ctx->is_98xx = 1; |
| 368 | ctx->need_lib = 1; |
| 369 | ctx->lut_fname = MITSU_M98xx_LUT_FILE; |
| 370 | } |
| 371 | |
| 372 | if (ctx->conn->type == P_MITSU_CP30D) { |
| 373 | ctx->need_lib = 1; |
| 374 | } |
| 375 | if (ctx->need_lib) { |
| 376 | #if defined(WITH_DYNAMIC) |
| 377 | /* Attempt to open the library */ |
| 378 | if (mitsu_loadlib(&ctx->lib, ctx->conn->type)) |
| 379 | #endif |
| 380 | WARNING("Dynamic library support not loaded, will be unable to print."); |
| 381 | } |
| 382 | |
| 383 | if (ctx->conn->type == P_MITSU_CP30D) { |
| 384 | ctx->footer_len = 6; |
| 385 | ctx->lut_fname = MITSU_CP30D_LUT_FILE; |
| 386 | } else { |
| 387 | ctx->footer_len = 4; |
| 388 | } |
| 389 | |
| 390 | if (test_mode < TEST_MODE_NOATTACH) { |
| 391 | uint8_t buf[48]; |
| 392 | if (mitsu9550_get_status(ctx, (uint8_t*) &media, CP9XXX_STS_MEDIA)) |
| 393 | return CUPS_BACKEND_FAILED; |
| 394 | |
| 395 | /* Get FW Version */ |
| 396 | if (mitsu9550_get_status(ctx, buf, CP9XXX_STS_FWVER)) |
| 397 | return CUPS_BACKEND_FAILED; |
| 398 | memcpy(ctx->fwver, &buf[6], 6); |
| 399 | ctx->fwver[6] = 0; |
| 400 | // XXX get serial number too? |
| 401 | } else { |
| 402 | int media_code = 0x2; |
| 403 | if (getenv("MEDIA_CODE")) |
| 404 | media_code = strtol(getenv("MEDIA_CODE"), NULL, 16) & 0xf; |
| 405 | |
| 406 | media.max = cpu_to_be16(400); |
| 407 | media.remain = cpu_to_be16(330); |
| 408 | media.remain2 = cpu_to_be16(330); |
| 409 | media.type = media_code; |
| 410 | ctx->fwver[0] = 0; |
| 411 | } |
| 412 | |
| 413 | ctx->marker.color = "#00FFFF#FF00FF#FFFF00"; |
| 414 | ctx->marker.numtype = media.type; |
| 415 | ctx->marker.levelmax = be16_to_cpu(media.max); |
| 416 | |
| 417 | if (ctx->conn->type == P_MITSU_CP30D) { |
| 418 | ctx->marker.name = cp30_media_types(be16_to_cpu(media.max)); |
| 419 | ctx->marker.levelnow = be16_to_cpu(media.remain2); |
| 420 | } else { |
| 421 | ctx->marker.name = mitsu9550_media_types(media.type, ctx->is_s); |
| 422 | ctx->marker.levelnow = be16_to_cpu(media.remain); |
| 423 | } |
| 424 | |
| 425 | return CUPS_BACKEND_OK; |
| 426 | } |
| 427 | |
| 428 | static void mitsu9550_cleanup_job(const void *vjob) |
| 429 | { |
| 430 | const struct mitsu9550_printjob *job = vjob; |
| 431 | |
| 432 | if (job->databuf) |
| 433 | free(job->databuf); |
| 434 | |
| 435 | free((void*)job); |
| 436 | } |
| 437 | |
| 438 | static void mitsu9550_teardown(void *vctx) { |
| 439 | struct mitsu9550_ctx *ctx = vctx; |
| 440 | |
| 441 | if (!ctx) |
| 442 | return; |
| 443 | |
| 444 | if (ctx->m98xxdata) |
| 445 | ctx->lib.CP98xx_DestroyData(ctx->m98xxdata); |
| 446 | |
| 447 | mitsu_destroylib(&ctx->lib); |
| 448 | |
| 449 | free(ctx); |
| 450 | } |
| 451 | |
| 452 | static int mitsu9550_read_parse(void *vctx, const void **vjob, int data_fd, int copies) { |
| 453 | struct mitsu9550_ctx *ctx = vctx; |
| 454 | uint8_t buf[sizeof(struct mitsu9550_hdr1)]; |
| 455 | int planes = 3, i; |
| 456 | uint32_t planelen = 0, remain = 0; |
| 457 | |
| 458 | struct mitsu9550_printjob *job = NULL; |
| 459 | |
| 460 | if (!ctx) |
| 461 | return CUPS_BACKEND_FAILED; |
| 462 | |
| 463 | job = malloc(sizeof(*job)); |
| 464 | if (!job) { |
| 465 | ERROR("Memory allocation failure!\n"); |
| 466 | return CUPS_BACKEND_RETRY_CURRENT; |
| 467 | } |
| 468 | memset(job, 0, sizeof(*job)); |
| 469 | job->is_raw = 0; |
| 470 | job->common.jobsize = sizeof(*job); |
| 471 | job->common.copies = copies; |
| 472 | |
| 473 | top: |
| 474 | /* Read in first two bytes */ |
| 475 | i = read(data_fd, buf, 2); |
| 476 | if (i == 0) { |
| 477 | mitsu9550_cleanup_job(job); |
| 478 | return CUPS_BACKEND_CANCEL; |
| 479 | } |
| 480 | if (i < 0) { |
| 481 | mitsu9550_cleanup_job(job); |
| 482 | return CUPS_BACKEND_CANCEL; |
| 483 | } |
| 484 | if (buf[0] != 0x1b) { |
| 485 | ERROR("Unrecognized cmd sequence (%02x %02x)!\n", |
| 486 | buf[0], buf[1]); |
| 487 | mitsu9550_cleanup_job(job); |
| 488 | return CUPS_BACKEND_CANCEL; |
| 489 | } |
| 490 | switch (buf[1]) { |
| 491 | case 0x57: |
| 492 | remain = sizeof(buf) - 2; |
| 493 | break; |
| 494 | case 0x5a: |
| 495 | remain = sizeof(struct mitsu9550_plane) - 2; |
| 496 | break; |
| 497 | default: |
| 498 | ERROR("Unrecognized cmd sequence (%02x %02x)!\n", |
| 499 | buf[0], buf[1]); |
| 500 | mitsu9550_cleanup_job(job); |
| 501 | return CUPS_BACKEND_CANCEL; |
| 502 | } |
| 503 | |
| 504 | /* Read in remainder of header */ |
| 505 | while (remain) { |
| 506 | i = read(data_fd, buf + 2, remain); |
| 507 | if (i == 0) { |
| 508 | mitsu9550_cleanup_job(job); |
| 509 | return CUPS_BACKEND_CANCEL; |
| 510 | } |
| 511 | if (i < 0) { |
| 512 | mitsu9550_cleanup_job(job); |
| 513 | return CUPS_BACKEND_CANCEL; |
| 514 | } |
| 515 | remain -= i; |
| 516 | } |
| 517 | |
| 518 | if (buf[1] == 0x5a) { |
| 519 | /* We're in the data portion now, bail on header processing */ |
| 520 | if (ctx->is_98xx && buf[3] == 0x10) { |
| 521 | job->is_raw = 1; |
| 522 | planelen *= 2; |
| 523 | if (job->hdr1.matte) |
| 524 | planes ++; |
| 525 | } else if (ctx->is_98xx && buf[3] == 0x80) { |
| 526 | planelen *= 3; |
| 527 | planes = 1; |
| 528 | } |
| 529 | goto hdr_done; |
| 530 | } |
| 531 | |
| 532 | switch(buf[2]) { |
| 533 | case 0x20: /* header 1 */ |
| 534 | memcpy(&job->hdr1, buf, sizeof(job->hdr1)); |
| 535 | job->hdr1_present = 1; |
| 536 | |
| 537 | /* Work out printjob size */ |
| 538 | job->rows = be16_to_cpu(job->hdr1.rows); |
| 539 | job->cols = be16_to_cpu(job->hdr1.cols); |
| 540 | planelen = job->rows * job->cols; |
| 541 | |
| 542 | break; |
| 543 | case 0x21: /* header 2 */ |
| 544 | memcpy(&job->hdr2, buf, sizeof(job->hdr2)); |
| 545 | job->hdr2_present = 1; |
| 546 | break; |
| 547 | case 0x22: /* header 3 */ |
| 548 | memcpy(&job->hdr3, buf, sizeof(job->hdr3)); |
| 549 | job->hdr3_present = 1; |
| 550 | break; |
| 551 | case 0x26: /* header 4 */ |
| 552 | memcpy(&job->hdr4, buf, sizeof(job->hdr4)); |
| 553 | job->hdr4_present = 1; |
| 554 | break; |
| 555 | default: |
| 556 | ERROR("Unrecognized header format (%02x)!\n", buf[2]); |
| 557 | mitsu9550_cleanup_job(job); |
| 558 | return CUPS_BACKEND_CANCEL; |
| 559 | } |
| 560 | |
| 561 | /* Read in the next chunk */ |
| 562 | goto top; |
| 563 | |
| 564 | hdr_done: |
| 565 | |
| 566 | /* 9550S/9800S doesn't typically sent over hdr4! */ |
| 567 | if (ctx->conn->type == P_MITSU_9500S || |
| 568 | ctx->conn->type == P_MITSU_9550S || |
| 569 | ctx->conn->type == P_MITSU_9600S || |
| 570 | ctx->conn->type == P_MITSU_9800S || |
| 571 | ctx->conn->type == P_MITSU_9820S) { |
| 572 | /* XXX Has to do with error policy, but not sure what. |
| 573 | Mitsu9550-S/9800-S will set this based on a command, |
| 574 | but it's not part of the standard job spool */ |
| 575 | job->hdr4_present = 0; |
| 576 | } |
| 577 | |
| 578 | /* Disable matte if the printer doesn't support it */ |
| 579 | if (job->hdr1.matte) { |
| 580 | if (ctx->conn->type != P_MITSU_9810 && |
| 581 | ctx->conn->type != P_MITSU_9820S) { |
| 582 | WARNING("Matte not supported on this printer, disabling\n"); |
| 583 | job->hdr1.matte = 0; |
| 584 | } |
| 585 | } |
| 586 | |
| 587 | /* Read in CP98xx data tables if necessary */ |
| 588 | if (ctx->is_98xx && !job->is_raw && !ctx->m98xxdata) { |
| 589 | char full[2048]; |
| 590 | |
| 591 | if (!ctx->lib.dl_handle) { |
| 592 | ERROR("!!! Image Processing Library not found, aborting!\n"); |
| 593 | mitsu9550_cleanup_job(job); |
| 594 | return CUPS_BACKEND_CANCEL; |
| 595 | } |
| 596 | |
| 597 | snprintf(full, sizeof(full), "%s/%s", corrtable_path, MITSU_M98xx_DATATABLE_FILE); |
| 598 | |
| 599 | DEBUG("Reading in 98xx data from disk\n"); |
| 600 | ctx->m98xxdata = ctx->lib.CP98xx_GetData(full); |
| 601 | if (!ctx->m98xxdata) { |
| 602 | ERROR("Unable to read 98xx data table file '%s'\n", full); |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | /* Work out the raw job size */ |
| 607 | remain = planes * (planelen + sizeof(struct mitsu9550_plane)) + (ctx->footer_len * (job->hdr1.matte ? 2 : 1)); |
| 608 | |
| 609 | /* Allocate buffer for the payload */ |
| 610 | job->datalen = 0; |
| 611 | job->databuf = malloc(remain); |
| 612 | if (!job->databuf) { |
| 613 | ERROR("Memory allocation failure!\n"); |
| 614 | mitsu9550_cleanup_job(job); |
| 615 | return CUPS_BACKEND_RETRY_CURRENT; |
| 616 | } |
| 617 | |
| 618 | /* Load up the data blocks.*/ |
| 619 | while(planes--) { |
| 620 | /* Note that 'buf' needs to be already filled here! */ |
| 621 | struct mitsu9550_plane *plane = (struct mitsu9550_plane *)buf; |
| 622 | |
| 623 | /* Sanity check header... */ |
| 624 | if (plane->cmd[0] != 0x1b || |
| 625 | plane->cmd[1] != 0x5a || |
| 626 | plane->cmd[2] != 0x54) { |
| 627 | ERROR("Unrecognized data read @%d (%02x%02x%02x%02x)!\n", |
| 628 | job->datalen, |
| 629 | plane->cmd[0], plane->cmd[1], plane->cmd[2], plane->cmd[3]); |
| 630 | mitsu9550_cleanup_job(job); |
| 631 | return CUPS_BACKEND_CANCEL; |
| 632 | } |
| 633 | |
| 634 | /* Work out the length of this block */ |
| 635 | remain = be16_to_cpu(plane->rows) * be16_to_cpu(plane->cols); |
| 636 | if (plane->cmd[3] == 0x10) |
| 637 | remain *= 2; |
| 638 | if (plane->cmd[3] == 0x80) |
| 639 | remain *= 3; |
| 640 | |
| 641 | if (planelen != remain) { |
| 642 | ERROR("Plane length mismatch! job %d vs plane %d\n", planelen, remain); |
| 643 | mitsu9550_cleanup_job(job); |
| 644 | return CUPS_BACKEND_CANCEL; |
| 645 | } |
| 646 | |
| 647 | /* Move plane header into job buffer */ |
| 648 | memcpy(job->databuf + job->datalen, buf, sizeof(struct mitsu9550_plane)); |
| 649 | job->datalen += sizeof(struct mitsu9550_plane); |
| 650 | |
| 651 | /* Final plane and Matte plane get an additional footer */ |
| 652 | if (planes == 0 || (planes == 1 && job->hdr1.matte && job->is_raw)) |
| 653 | remain += ctx->footer_len; |
| 654 | |
| 655 | /* Read in the plane data */ |
| 656 | while(remain) { |
| 657 | i = read(data_fd, job->databuf + job->datalen, remain); |
| 658 | if (i == 0) { |
| 659 | mitsu9550_cleanup_job(job); |
| 660 | return CUPS_BACKEND_CANCEL; |
| 661 | } |
| 662 | if (i < 0) { |
| 663 | mitsu9550_cleanup_job(job); |
| 664 | return CUPS_BACKEND_CANCEL; |
| 665 | } |
| 666 | job->datalen += i; |
| 667 | remain -= i; |
| 668 | } |
| 669 | |
| 670 | |
| 671 | /* If we're not done with our planes, read the next header */ |
| 672 | if (planes) |
| 673 | remain = sizeof(struct mitsu9550_plane); |
| 674 | |
| 675 | while (remain) { |
| 676 | i = read(data_fd, buf + sizeof(struct mitsu9550_plane) - remain, remain); |
| 677 | if (i == 0) { |
| 678 | mitsu9550_cleanup_job(job); |
| 679 | return CUPS_BACKEND_CANCEL; |
| 680 | } |
| 681 | if (i < 0) { |
| 682 | mitsu9550_cleanup_job(job); |
| 683 | return CUPS_BACKEND_CANCEL; |
| 684 | } |
| 685 | remain -= i; |
| 686 | } |
| 687 | } |
| 688 | |
| 689 | /* One bit of fixup */ |
| 690 | if (ctx->conn->type == P_MITSU_CP30D) |
| 691 | job->is_raw = 0; |
| 692 | |
| 693 | /* Apply LUT, if job calls for it.. */ |
| 694 | if (ctx->lut_fname && !job->is_raw && job->hdr2.unkc[9]) { |
| 695 | int ret; |
| 696 | if (ctx->conn->type == P_MITSU_CP30D) { |
| 697 | uint32_t plen = job->rows * job->cols + sizeof(struct mitsu9550_plane); |
| 698 | ret = mitsu_apply3dlut_plane(&ctx->lib, ctx->lut_fname, |
| 699 | job->databuf + sizeof(struct mitsu9550_plane), |
| 700 | job->databuf + (plen + sizeof(struct mitsu9550_plane)), |
| 701 | job->databuf + (plen * 2 + sizeof(struct mitsu9550_plane)), |
| 702 | job->cols, job->rows); |
| 703 | } else { |
| 704 | ret = mitsu_apply3dlut_packed(&ctx->lib, ctx->lut_fname, |
| 705 | job->databuf + sizeof(struct mitsu9550_plane), |
| 706 | job->cols, job->rows, |
| 707 | job->cols * 3, COLORCONV_BGR); |
| 708 | } |
| 709 | if (ret) { |
| 710 | mitsu9550_cleanup_job(job); |
| 711 | return ret; |
| 712 | } |
| 713 | |
| 714 | job->hdr2.unkc[9] = 0; |
| 715 | } |
| 716 | |
| 717 | /* Update printjob header to reflect number of requested copies */ |
| 718 | if (job->hdr2_present) { |
| 719 | if (be16_to_cpu(job->hdr2.copies) < copies) |
| 720 | job->hdr2.copies = cpu_to_be16(copies); |
| 721 | else |
| 722 | job->common.copies = be16_to_cpu(job->hdr2.copies); |
| 723 | } |
| 724 | |
| 725 | /* All further work is in main loop */ |
| 726 | if (test_mode >= TEST_MODE_NOPRINT) |
| 727 | mitsu9550_main_loop(ctx, job, 1); |
| 728 | |
| 729 | *vjob = job; |
| 730 | |
| 731 | return CUPS_BACKEND_OK; |
| 732 | } |
| 733 | |
| 734 | static int mitsu9550_get_status(struct mitsu9550_ctx *ctx, uint8_t *resp, int type) |
| 735 | { |
| 736 | struct mitsu9550_cmd cmd; |
| 737 | int num, ret; |
| 738 | |
| 739 | /* Send Printer Query */ |
| 740 | cmd.cmd[0] = 0x1b; |
| 741 | cmd.cmd[1] = 0x56; // XXX need version for 0x72 |
| 742 | cmd.cmd[2] = type; |
| 743 | cmd.cmd[3] = 0x00; |
| 744 | if ((ret = send_data(ctx->conn, |
| 745 | (uint8_t*) &cmd, sizeof(cmd)))) |
| 746 | return ret; |
| 747 | ret = read_data(ctx->conn, |
| 748 | resp, sizeof(struct mitsu9550_status), &num); |
| 749 | |
| 750 | if (ret < 0) |
| 751 | return ret; |
| 752 | if (num != sizeof(struct mitsu9550_status)) { |
| 753 | ERROR("Short Read! (%d/%d)\n", num, (int)sizeof(struct mitsu9550_status)); |
| 754 | return CUPS_BACKEND_FAILED; |
| 755 | } |
| 756 | |
| 757 | return CUPS_BACKEND_OK; |
| 758 | } |
| 759 | |
| 760 | static const char *mitsu9550_media_types(uint8_t type, uint8_t is_s) |
| 761 | { |
| 762 | if (is_s) { |
| 763 | switch (type & 0xf) { /* values can be 0x0? or 0x4? */ |
| 764 | case 0x02: |
| 765 | return "CK9015 (4x6)"; |
| 766 | case 0x04: |
| 767 | return "CK9318 (5x7)"; |
| 768 | case 0x05: |
| 769 | return "CK9523 (6x9)"; |
| 770 | default: |
| 771 | return "Unknown"; |
| 772 | } |
| 773 | return NULL; |
| 774 | } |
| 775 | |
| 776 | switch (type & 0xf) { /* values can be 0x0? or 0x4? */ |
| 777 | case 0x01: |
| 778 | return "CK9035 (3.5x5)"; |
| 779 | case 0x02: |
| 780 | return "CK9046 (4x6)"; |
| 781 | case 0x03: |
| 782 | return "CK9046PST (4x6)"; |
| 783 | case 0x04: |
| 784 | return "CK9057 (5x7)"; |
| 785 | case 0x05: |
| 786 | return "CK9069 (6x9)"; |
| 787 | case 0x06: |
| 788 | return "CK9068 (6x8)"; |
| 789 | default: |
| 790 | return "Unknown"; |
| 791 | } |
| 792 | return NULL; |
| 793 | } |
| 794 | |
| 795 | static int validate_media(int type, int media, int cols, int rows) |
| 796 | { |
| 797 | switch(type) { |
| 798 | case P_MITSU_9550: |
| 799 | switch(media & 0xf) { |
| 800 | case 0x01: /* 3.5x5 */ |
| 801 | if (cols != 1812 && rows != 1240) |
| 802 | return 1; |
| 803 | break; |
| 804 | case 0x02: /* 4x6 */ |
| 805 | case 0x03: /* 4x6 postcard */ |
| 806 | if (cols != 2152) |
| 807 | return 1; |
| 808 | if (rows != 1416 && rows != 1184 && rows != 1240) |
| 809 | return 1; |
| 810 | break; |
| 811 | case 0x04: /* 5x7 */ |
| 812 | if (cols != 1812) |
| 813 | return 1; |
| 814 | if (rows != 1240 && rows != 2452) |
| 815 | return 1; |
| 816 | break; |
| 817 | case 0x05: /* 6x9 */ |
| 818 | if (cols != 2152) |
| 819 | return 1; |
| 820 | if (rows != 1416 && rows != 2792 && |
| 821 | rows != 2956 && rows != 3146) |
| 822 | return 1; |
| 823 | break; |
| 824 | case 0x06: /* V (6x8??) */ |
| 825 | if (cols != 2152) |
| 826 | return 1; |
| 827 | if (rows != 1416 && rows != 2792) |
| 828 | return 1; |
| 829 | break; |
| 830 | default: /* Unknown */ |
| 831 | WARNING("Unknown media type %02x\n", media); |
| 832 | break; |
| 833 | } |
| 834 | break; |
| 835 | case P_MITSU_9500S: |
| 836 | case P_MITSU_9550S: |
| 837 | switch(media & 0xf) { |
| 838 | case 0x02: /* 4x6 */ |
| 839 | case 0x03: /* 4x6 postcard */ |
| 840 | if (cols != 2152) |
| 841 | return 1; |
| 842 | if (rows != 1416 && rows != 1184 && rows != 1240) |
| 843 | return 1; |
| 844 | break; |
| 845 | case 0x04: /* 5x7 */ |
| 846 | if (cols != 1812 && rows != 2452) |
| 847 | return 1; |
| 848 | break; |
| 849 | case 0x05: /* 6x9 */ |
| 850 | if (cols != 2152) |
| 851 | return 1; |
| 852 | if (rows != 1416 && rows != 2792 && |
| 853 | rows != 2956 && rows != 3146) |
| 854 | return 1; |
| 855 | break; |
| 856 | case 0x06: /* V (6x8??) */ |
| 857 | if (cols != 2152) |
| 858 | return 1; |
| 859 | if (rows != 1416 && rows != 2792) |
| 860 | return 1; |
| 861 | break; |
| 862 | default: /* Unknown */ |
| 863 | WARNING("Unknown media type %02x\n", media); |
| 864 | break; |
| 865 | } |
| 866 | break; |
| 867 | case P_MITSU_9600: |
| 868 | case P_MITSU_9600S: |
| 869 | switch(media & 0xf) { |
| 870 | case 0x01: /* 3.5x5 */ |
| 871 | if (cols == 1572) { |
| 872 | if (rows == 1076) |
| 873 | break; |
| 874 | } else if (cols == 3144) { |
| 875 | if (rows == 2152) |
| 876 | break; |
| 877 | } |
| 878 | return 1; |
| 879 | case 0x02: /* 4x6 */ |
| 880 | case 0x03: /* 4x6 postcard */ |
| 881 | if (cols == 1868) { |
| 882 | if (rows == 1228) |
| 883 | break; |
| 884 | } else if (cols == 3736) { |
| 885 | if (rows == 2458) |
| 886 | break; |
| 887 | } |
| 888 | return 1; |
| 889 | case 0x04: /* 5x7 */ |
| 890 | if (cols == 1572) { |
| 891 | if (rows == 1076 || rows == 2128) |
| 892 | break; |
| 893 | } else if (cols == 3144) { |
| 894 | if (rows == 2152 || rows == 4256) |
| 895 | break; |
| 896 | } |
| 897 | return 1; |
| 898 | case 0x05: /* 6x9 */ |
| 899 | if (cols == 1868) { |
| 900 | if (rows == 1228 || rows == 2442 || rows == 2564 || rows == 2730) |
| 901 | break; |
| 902 | } else if (cols == 3736) { |
| 903 | if (rows == 2458 || rows == 4846 || rows == 5130 || rows == 5462) |
| 904 | break; |
| 905 | } |
| 906 | return 1; |
| 907 | case 0x06: /* V (6x8??) */ |
| 908 | if (cols == 1868) { |
| 909 | if (rows == 1228 || rows == 2442) |
| 910 | break; |
| 911 | } else if (cols == 3736) { |
| 912 | if (rows == 2458 || rows == 4846) |
| 913 | break; |
| 914 | } |
| 915 | return 1; |
| 916 | default: /* Unknown */ |
| 917 | WARNING("Unknown media type %02x\n", media); |
| 918 | break; |
| 919 | } |
| 920 | break; |
| 921 | case P_MITSU_9800: |
| 922 | case P_MITSU_9810: |
| 923 | switch(media & 0xf) { |
| 924 | case 0x01: /* 3.5x5 */ |
| 925 | if (cols != 1572 && rows != 1076) |
| 926 | return 1; |
| 927 | break; |
| 928 | case 0x02: /* 4x6 */ |
| 929 | case 0x03: /* 4x6 postcard */ |
| 930 | if (cols != 1868 && rows != 1228) |
| 931 | return 1; |
| 932 | break; |
| 933 | case 0x04: /* 5x7 */ |
| 934 | if (cols != 1572 && rows != 2128) |
| 935 | return 1; |
| 936 | break; |
| 937 | case 0x05: /* 6x9 */ |
| 938 | if (cols != 1868) |
| 939 | return 1; |
| 940 | if (rows != 1228 && rows != 2442 && |
| 941 | rows != 2564 && rows != 2730) |
| 942 | return 1; |
| 943 | break; |
| 944 | case 0x06: /* V (6x8??) */ |
| 945 | if (cols != 1868) |
| 946 | return 1; |
| 947 | if (rows != 1228 && rows != 2442) |
| 948 | return 1; |
| 949 | break; |
| 950 | default: /* Unknown */ |
| 951 | WARNING("Unknown media type %02x\n", media); |
| 952 | break; |
| 953 | } |
| 954 | break; |
| 955 | case P_MITSU_9800S: |
| 956 | case P_MITSU_9820S: |
| 957 | switch(media & 0xf) { |
| 958 | case 0x02: /* 4x6 */ |
| 959 | case 0x03: /* 4x6 postcard */ |
| 960 | if (cols != 1868 && rows != 1228) |
| 961 | return 1; |
| 962 | break; |
| 963 | case 0x04: /* 5x7 */ |
| 964 | if (cols != 1572 && rows != 2128) |
| 965 | return 1; |
| 966 | break; |
| 967 | case 0x05: /* 6x9 */ |
| 968 | if (cols != 1868) |
| 969 | return 1; |
| 970 | if (rows != 1228 && rows != 2442 && |
| 971 | rows != 2564 && rows != 2730) |
| 972 | return 1; |
| 973 | break; |
| 974 | case 0x06: /* V (6x8??) */ |
| 975 | if (cols != 1868) |
| 976 | return 1; |
| 977 | if (rows != 1228 && rows != 2442) |
| 978 | return 1; |
| 979 | break; |
| 980 | default: /* Unknown */ |
| 981 | WARNING("Unknown media type %02x\n", media); |
| 982 | break; |
| 983 | } |
| 984 | break; |
| 985 | case P_MITSU_CP30D: |
| 986 | if (cols != 1600) |
| 987 | return 1; |
| 988 | if (rows != 1200 && rows != 2100) |
| 989 | return 1; |
| 990 | // XXX validate media type vs job size. Don't know readback codes. |
| 991 | // S == 1600x1200 |
| 992 | // L == 1600x2100 ( type 00 ?) |
| 993 | break; |
| 994 | default: |
| 995 | WARNING("Unknown printer type %d\n", type); |
| 996 | break; |
| 997 | } |
| 998 | return CUPS_BACKEND_OK; |
| 999 | } |
| 1000 | |
| 1001 | static int mitsu9550_main_loop(void *vctx, const void *vjob, int wait_for_return) { |
| 1002 | struct mitsu9550_ctx *ctx = vctx; |
| 1003 | struct mitsu9550_cmd cmd; |
| 1004 | uint8_t rdbuf[READBACK_LEN]; |
| 1005 | uint8_t *ptr; |
| 1006 | |
| 1007 | int ret; |
| 1008 | |
| 1009 | struct mitsu9550_printjob *job = (struct mitsu9550_printjob*) vjob; |
| 1010 | |
| 1011 | if (!ctx) |
| 1012 | return CUPS_BACKEND_FAILED; |
| 1013 | if (!job) |
| 1014 | return CUPS_BACKEND_FAILED; |
| 1015 | |
| 1016 | /* Okay, let's do this thing */ |
| 1017 | ptr = job->databuf; |
| 1018 | |
| 1019 | int sharpness = job->hdr2.unkc[7]; |
| 1020 | job->hdr2.unkc[7] = 0; /* Clear "sharpness" parameter */ |
| 1021 | |
| 1022 | /* Do the 98xx processing here */ |
| 1023 | if (!ctx->is_98xx || job->is_raw) |
| 1024 | goto non_98xx; |
| 1025 | |
| 1026 | /* Special CP98xx handling code */ |
| 1027 | uint8_t *newbuf; |
| 1028 | uint32_t newlen = 0; |
| 1029 | int i, remain, planelen; |
| 1030 | |
| 1031 | planelen = job->rows * job->cols * 2; |
| 1032 | remain = (job->hdr1.matte ? 4 : 3) * (planelen + sizeof(struct mitsu9550_plane)) + sizeof(struct mitsu9550_cmd) * (job->hdr1.matte? 2 : 1) + LAMINATE_STRIDE * 2; |
| 1033 | newbuf = malloc(remain); |
| 1034 | if (!newbuf) { |
| 1035 | ERROR("Memory allocation Failure!\n"); |
| 1036 | return CUPS_BACKEND_RETRY_CURRENT; |
| 1037 | } |
| 1038 | |
| 1039 | DEBUG("Running print data through processing library\n"); |
| 1040 | |
| 1041 | /* Create band images for input and output */ |
| 1042 | struct BandImage input; |
| 1043 | struct BandImage output; |
| 1044 | |
| 1045 | uint8_t *convbuf = malloc(planelen * 3); |
| 1046 | if (!convbuf) { |
| 1047 | free(newbuf); |
| 1048 | ERROR("Memory allocation Failure!\n"); |
| 1049 | return CUPS_BACKEND_RETRY_CURRENT; |
| 1050 | } |
| 1051 | |
| 1052 | input.origin_rows = input.origin_cols = 0; |
| 1053 | input.rows = job->rows; |
| 1054 | input.cols = job->cols; |
| 1055 | input.imgbuf = job->databuf + sizeof(struct mitsu9550_plane); |
| 1056 | input.bytes_per_row = job->cols * 3; |
| 1057 | |
| 1058 | output.origin_rows = output.origin_cols = 0; |
| 1059 | output.rows = job->rows; |
| 1060 | output.cols = job->cols; |
| 1061 | output.imgbuf = convbuf; |
| 1062 | output.bytes_per_row = job->cols * 3 * sizeof(uint16_t); |
| 1063 | |
| 1064 | if (!ctx->lib.CP98xx_DoConvert(ctx->m98xxdata, &input, &output, job->hdr2.mode, sharpness, job->hdr2.unkc[8])) { |
| 1065 | free(convbuf); |
| 1066 | free(newbuf); |
| 1067 | ERROR("CP98xx_DoConvert() failed!\n"); |
| 1068 | return CUPS_BACKEND_FAILED; |
| 1069 | } |
| 1070 | |
| 1071 | /* Clear special extension flags used by our backend */ |
| 1072 | if (job->hdr2.mode == 0x11) |
| 1073 | job->hdr2.mode = 0x10; |
| 1074 | job->hdr2.unkc[8] = 0; /* Clear "already reversed" flag */ |
| 1075 | |
| 1076 | /* Library is done, but its output is packed YMC16. |
| 1077 | We need to convert this to planar YMC16, with a header for |
| 1078 | each plane. */ |
| 1079 | uint8_t *yPtr, *mPtr, *cPtr; |
| 1080 | int j, offset; |
| 1081 | |
| 1082 | yPtr = newbuf + newlen; |
| 1083 | memcpy(yPtr, job->databuf, sizeof(struct mitsu9550_plane)); |
| 1084 | yPtr[3] = 0x10; /* ie 16bpp data */ |
| 1085 | yPtr += sizeof(struct mitsu9550_plane); |
| 1086 | newlen += sizeof(struct mitsu9550_plane) + planelen; |
| 1087 | |
| 1088 | mPtr = newbuf + newlen; |
| 1089 | memcpy(mPtr, job->databuf, sizeof(struct mitsu9550_plane)); |
| 1090 | mPtr[3] = 0x10; /* ie 16bpp data */ |
| 1091 | mPtr += sizeof(struct mitsu9550_plane); |
| 1092 | newlen += sizeof(struct mitsu9550_plane) + planelen; |
| 1093 | |
| 1094 | cPtr = newbuf + newlen; |
| 1095 | memcpy(cPtr, job->databuf, sizeof(struct mitsu9550_plane)); |
| 1096 | cPtr[3] = 0x10; /* ie 16bpp data */ |
| 1097 | cPtr += sizeof(struct mitsu9550_plane); |
| 1098 | newlen += sizeof(struct mitsu9550_plane) + planelen; |
| 1099 | |
| 1100 | for (offset = 0, i = 0; i < output.rows ; i++) { |
| 1101 | for (j = 0 ; j < output.cols ; j ++, offset += 3) { |
| 1102 | ((uint16_t*)yPtr)[i*output.cols + j] = ((uint16_t*)convbuf)[0 + offset]; |
| 1103 | ((uint16_t*)mPtr)[i*output.cols + j] = ((uint16_t*)convbuf)[1 + offset]; |
| 1104 | ((uint16_t*)cPtr)[i*output.cols + j] = ((uint16_t*)convbuf)[2 + offset]; |
| 1105 | } |
| 1106 | } |
| 1107 | |
| 1108 | /* All done with conversion buffer, nuke it */ |
| 1109 | free(convbuf); |
| 1110 | |
| 1111 | /* And finally, append the job footer. */ |
| 1112 | memcpy(newbuf + newlen, job->databuf + sizeof(struct mitsu9550_plane) + planelen/2 * 3, ctx->footer_len); |
| 1113 | newlen += sizeof(struct mitsu9550_cmd); |
| 1114 | |
| 1115 | /* Clean up, and move pointer to new buffer; */ |
| 1116 | free(job->databuf); |
| 1117 | job->databuf = newbuf; |
| 1118 | job->datalen = newlen; |
| 1119 | ptr = job->databuf; |
| 1120 | |
| 1121 | /* Now handle the matte plane generation */ |
| 1122 | if (job->hdr1.matte) { |
| 1123 | if ((i = mitsu98xx_fillmatte(job))) { |
| 1124 | return i; |
| 1125 | } |
| 1126 | } |
| 1127 | job->is_raw = 1; |
| 1128 | |
| 1129 | non_98xx: |
| 1130 | /* Bypass */ |
| 1131 | if (test_mode >= TEST_MODE_NOPRINT) |
| 1132 | return CUPS_BACKEND_OK; |
| 1133 | |
| 1134 | top: |
| 1135 | if (ctx->is_s) { |
| 1136 | int num; |
| 1137 | |
| 1138 | /* Send "unknown 1" command */ |
| 1139 | cmd.cmd[0] = 0x1b; |
| 1140 | cmd.cmd[1] = 0x53; |
| 1141 | cmd.cmd[2] = 0xc5; |
| 1142 | cmd.cmd[3] = 0x9d; |
| 1143 | if ((ret = send_data(ctx->conn, |
| 1144 | (uint8_t*) &cmd, sizeof(cmd)))) |
| 1145 | return CUPS_BACKEND_FAILED; |
| 1146 | |
| 1147 | /* Send "unknown query 1" command */ |
| 1148 | cmd.cmd[0] = 0x1b; |
| 1149 | cmd.cmd[1] = 0x4b; |
| 1150 | cmd.cmd[2] = 0x7f; |
| 1151 | cmd.cmd[3] = 0x00; |
| 1152 | if ((ret = send_data(ctx->conn, |
| 1153 | (uint8_t*) &cmd, sizeof(cmd)))) |
| 1154 | return CUPS_BACKEND_FAILED; |
| 1155 | |
| 1156 | ret = read_data(ctx->conn, |
| 1157 | rdbuf, READBACK_LEN, &num); |
| 1158 | if (ret < 0) |
| 1159 | return CUPS_BACKEND_FAILED; |
| 1160 | // XXX no idea how to interpret this. |
| 1161 | } |
| 1162 | |
| 1163 | if (ctx->conn->type == P_MITSU_9800S || |
| 1164 | ctx->conn->type == P_MITSU_9820S) { |
| 1165 | int num; |
| 1166 | |
| 1167 | /* Send "unknown query 2" command */ |
| 1168 | cmd.cmd[0] = 0x1b; |
| 1169 | cmd.cmd[1] = 0x4b; |
| 1170 | cmd.cmd[2] = 0x01; |
| 1171 | cmd.cmd[3] = 0x00; |
| 1172 | if ((ret = send_data(ctx->conn, |
| 1173 | (uint8_t*) &cmd, sizeof(cmd)))) |
| 1174 | return CUPS_BACKEND_FAILED; |
| 1175 | |
| 1176 | ret = read_data(ctx->conn, |
| 1177 | rdbuf, READBACK_LEN, &num); |
| 1178 | if (ret < 0) |
| 1179 | return CUPS_BACKEND_FAILED; |
| 1180 | // XXX no idea how to interpret this. |
| 1181 | } |
| 1182 | |
| 1183 | /* Sanity-check the printer state. */ |
| 1184 | { |
| 1185 | QUERY_STATUS_I; \ |
| 1186 | if (validate_media(ctx->conn->type, media->type, job->cols, job->rows)) { \ |
| 1187 | ERROR("Incorrect media (%u) type for printjob (%ux%u)!\n", media->type, job->cols, job->rows); \ |
| 1188 | return CUPS_BACKEND_HOLD; \ |
| 1189 | } \ |
| 1190 | QUERY_STATUS_II; \ |
| 1191 | QUERY_STATUS_IV; \ |
| 1192 | } |
| 1193 | |
| 1194 | /*** Now it's time for the actual print job! ***/ |
| 1195 | |
| 1196 | /* Send printjob headers from spool data */ |
| 1197 | if (job->hdr1_present) |
| 1198 | if ((ret = send_data(ctx->conn, |
| 1199 | (uint8_t*) &job->hdr1, sizeof(job->hdr1)))) |
| 1200 | return CUPS_BACKEND_FAILED; |
| 1201 | if (job->hdr2_present) |
| 1202 | if ((ret = send_data(ctx->conn, |
| 1203 | (uint8_t*) &job->hdr2, sizeof(job->hdr2)))) |
| 1204 | return CUPS_BACKEND_FAILED; |
| 1205 | if (job->hdr3_present) |
| 1206 | if ((ret = send_data(ctx->conn, |
| 1207 | (uint8_t*) &job->hdr3, sizeof(job->hdr3)))) |
| 1208 | return CUPS_BACKEND_FAILED; |
| 1209 | if (job->hdr4_present) |
| 1210 | if ((ret = send_data(ctx->conn, |
| 1211 | (uint8_t*) &job->hdr4, sizeof(struct mitsu9550_hdr4)))) |
| 1212 | return CUPS_BACKEND_FAILED; |
| 1213 | |
| 1214 | if (ctx->is_s) { |
| 1215 | /* I think this a "clear memory' command...? */ |
| 1216 | cmd.cmd[0] = 0x1b; |
| 1217 | cmd.cmd[1] = 0x5a; |
| 1218 | cmd.cmd[2] = 0x43; |
| 1219 | cmd.cmd[3] = 0x00; |
| 1220 | |
| 1221 | if ((ret = send_data(ctx->conn, |
| 1222 | (uint8_t*) &cmd, sizeof(cmd)))) |
| 1223 | return CUPS_BACKEND_FAILED; |
| 1224 | } |
| 1225 | |
| 1226 | /* Send over plane data */ |
| 1227 | while(ptr < (job->databuf + job->datalen)) { |
| 1228 | struct mitsu9550_plane *plane = (struct mitsu9550_plane *)ptr; |
| 1229 | if (plane->cmd[0] != 0x1b || |
| 1230 | plane->cmd[1] != 0x5a || |
| 1231 | plane->cmd[2] != 0x54) |
| 1232 | break; |
| 1233 | |
| 1234 | planelen = be16_to_cpu(plane->rows) * be16_to_cpu(plane->cols); |
| 1235 | if (plane->cmd[3] == 0x10) |
| 1236 | planelen *= 2; |
| 1237 | |
| 1238 | if ((ret = send_data(ctx->conn, |
| 1239 | (uint8_t*) ptr, sizeof(struct mitsu9550_plane)))) |
| 1240 | return CUPS_BACKEND_FAILED; |
| 1241 | ptr += sizeof(struct mitsu9550_plane); |
| 1242 | if ((ret = send_data(ctx->conn, |
| 1243 | (uint8_t*) ptr, planelen))) |
| 1244 | return CUPS_BACKEND_FAILED; |
| 1245 | ptr += planelen; |
| 1246 | } |
| 1247 | |
| 1248 | /* Query statuses after sending data */ |
| 1249 | { |
| 1250 | QUERY_STATUS_I; |
| 1251 | QUERY_STATUS_II; |
| 1252 | QUERY_STATUS_IV; |
| 1253 | } |
| 1254 | |
| 1255 | /* Send "end data" command */ |
| 1256 | if (getenv("CP9XXXX_START")) { |
| 1257 | cmd.cmd[0] = 0x1b; |
| 1258 | cmd.cmd[1] = 0x50; |
| 1259 | cmd.cmd[2] = strtol(getenv("CP9XXXX_START"), NULL, 16); |
| 1260 | cmd.cmd[3] = 0x00; |
| 1261 | |
| 1262 | DEBUG("CP9XXXX Override start = 0x%02x\n", cmd.cmd[2]); |
| 1263 | if ((ret = send_data(ctx->conn, |
| 1264 | (uint8_t*) &cmd, sizeof(cmd)))) |
| 1265 | return CUPS_BACKEND_FAILED; |
| 1266 | } else if (ctx->conn->type == P_MITSU_9500S) { |
| 1267 | /* Override spool, which may be wrong */ |
| 1268 | cmd.cmd[0] = 0x1b; |
| 1269 | cmd.cmd[1] = 0x50; |
| 1270 | cmd.cmd[2] = 0x45; |
| 1271 | cmd.cmd[3] = 0x00; |
| 1272 | if ((ret = send_data(ctx->conn, |
| 1273 | (uint8_t*) &cmd, sizeof(cmd)))) |
| 1274 | return CUPS_BACKEND_FAILED; |
| 1275 | } else if (ctx->conn->type == P_MITSU_9550S) { |
| 1276 | /* Override spool, which may be wrong */ |
| 1277 | cmd.cmd[0] = 0x1b; |
| 1278 | cmd.cmd[1] = 0x50; |
| 1279 | cmd.cmd[2] = 0x47; |
| 1280 | cmd.cmd[3] = 0x00; |
| 1281 | if ((ret = send_data(ctx->conn, |
| 1282 | (uint8_t*) &cmd, sizeof(cmd)))) |
| 1283 | return CUPS_BACKEND_FAILED; |
| 1284 | } else if (ctx->conn->type == P_MITSU_9600S) { |
| 1285 | /* Override spool, which may be wrong */ |
| 1286 | cmd.cmd[0] = 0x1b; |
| 1287 | cmd.cmd[1] = 0x50; |
| 1288 | cmd.cmd[2] = 0x49; |
| 1289 | cmd.cmd[3] = 0x00; |
| 1290 | if ((ret = send_data(ctx->conn, |
| 1291 | (uint8_t*) &cmd, sizeof(cmd)))) |
| 1292 | return CUPS_BACKEND_FAILED; |
| 1293 | } else if (ctx->conn->type == P_MITSU_9800S || |
| 1294 | ctx->conn->type == P_MITSU_9820S) { |
| 1295 | /* Override spool, which may be wrong */ |
| 1296 | cmd.cmd[0] = 0x1b; |
| 1297 | cmd.cmd[1] = 0x50; |
| 1298 | cmd.cmd[2] = 0x4e; |
| 1299 | cmd.cmd[3] = 0x00; |
| 1300 | if ((ret = send_data(ctx->conn, |
| 1301 | (uint8_t*) &cmd, sizeof(cmd)))) |
| 1302 | return CUPS_BACKEND_FAILED; |
| 1303 | } else { |
| 1304 | /* Send from spool file */ |
| 1305 | if ((ret = send_data(ctx->conn, |
| 1306 | ptr, ctx->footer_len))) |
| 1307 | return CUPS_BACKEND_FAILED; |
| 1308 | } |
| 1309 | ptr += ctx->footer_len; |
| 1310 | |
| 1311 | /* Don't forget the 9810's matte plane */ |
| 1312 | if (job->hdr1.matte) { |
| 1313 | struct mitsu9550_plane *plane = (struct mitsu9550_plane *)ptr; |
| 1314 | planelen = be16_to_cpu(plane->rows) * be16_to_cpu(plane->cols); |
| 1315 | |
| 1316 | if (plane->cmd[3] == 0x10) |
| 1317 | planelen *= 2; |
| 1318 | |
| 1319 | // XXX include a status loop here too? |
| 1320 | if ((ret = send_data(ctx->conn, |
| 1321 | (uint8_t*) ptr, sizeof(struct mitsu9550_plane)))) |
| 1322 | return CUPS_BACKEND_FAILED; |
| 1323 | ptr += sizeof(struct mitsu9550_plane); |
| 1324 | if ((ret = send_data(ctx->conn, |
| 1325 | (uint8_t*) ptr, planelen))) |
| 1326 | return CUPS_BACKEND_FAILED; |
| 1327 | ptr += planelen; |
| 1328 | |
| 1329 | /* Send "lamination end data" command from spool file */ |
| 1330 | if ((ret = send_data(ctx->conn, |
| 1331 | ptr, sizeof(cmd)))) |
| 1332 | return CUPS_BACKEND_FAILED; |
| 1333 | // ptr += sizeof(cmd); /* Unnecessary */ |
| 1334 | } |
| 1335 | |
| 1336 | /* Status loop, run until printer reports completion */ |
| 1337 | while(1) { |
| 1338 | sleep(1); |
| 1339 | |
| 1340 | QUERY_STATUS_I; |
| 1341 | QUERY_STATUS_II; |
| 1342 | |
| 1343 | if (ctx->conn->type == P_MITSU_CP30D) { |
| 1344 | ret = mitsu9550_get_status(ctx, rdbuf, CP9XXX_STS_x32); |
| 1345 | if (ret < 0) |
| 1346 | return CUPS_BACKEND_FAILED; |
| 1347 | |
| 1348 | if (sts30->err == CP30_ERR_TRAYFULL) { |
| 1349 | ERROR("Output Tray Full!\n"); |
| 1350 | return CUPS_BACKEND_STOP; |
| 1351 | } |
| 1352 | // XXX figure out remaining copy count? |
| 1353 | // print copy remaining |
| 1354 | |
| 1355 | if (sts30->sts == CP30_STS_IDLE) /* If printer transitions to idle */ |
| 1356 | break; |
| 1357 | |
| 1358 | // XXX if (!wait_for_return && copies_remaining == 0) break... |
| 1359 | |
| 1360 | if (!wait_for_return && sts30->sts != CP30_STS_IDLE) { |
| 1361 | INFO("Fast return mode enabled.\n"); |
| 1362 | break; |
| 1363 | } |
| 1364 | |
| 1365 | QUERY_STATUS_IIIB; |
| 1366 | } else { |
| 1367 | ret = mitsu9550_get_status(ctx, rdbuf, CP9XXX_STS_x30); |
| 1368 | if (ret < 0) |
| 1369 | return CUPS_BACKEND_FAILED; |
| 1370 | |
| 1371 | INFO("%03d copies remaining\n", be16_to_cpu(sts->copies)); |
| 1372 | |
| 1373 | if (!sts->sts1) /* If printer transitions to idle */ |
| 1374 | break; |
| 1375 | |
| 1376 | if (!wait_for_return && !be16_to_cpu(sts->copies)) { /* No remaining prints */ |
| 1377 | INFO("Fast return mode enabled.\n"); |
| 1378 | break; |
| 1379 | } |
| 1380 | |
| 1381 | if (!wait_for_return && !sts->sts5) { |
| 1382 | INFO("Fast return mode enabled.\n"); |
| 1383 | break; |
| 1384 | } |
| 1385 | QUERY_STATUS_III; |
| 1386 | } |
| 1387 | } |
| 1388 | |
| 1389 | INFO("Print complete\n"); |
| 1390 | |
| 1391 | return CUPS_BACKEND_OK; |
| 1392 | } |
| 1393 | |
| 1394 | static void mitsu9550_dump_media(struct mitsu9550_ctx *ctx, struct mitsu9550_media *resp) |
| 1395 | { |
| 1396 | INFO("Media type : %02x (%s)\n", |
| 1397 | resp->type, (ctx->conn->type == P_MITSU_CP30D ? cp30_media_types(be16_to_cpu(resp->max)): |
| 1398 | mitsu9550_media_types(resp->type, ctx->is_s))); |
| 1399 | INFO("Media remaining : %03d/%03d\n", |
| 1400 | (ctx->conn->type == P_MITSU_CP30D) ? be16_to_cpu(resp->remain2) : be16_to_cpu(resp->remain), be16_to_cpu(resp->max)); |
| 1401 | } |
| 1402 | |
| 1403 | static void mitsu9550_dump_status(struct mitsu9550_status *resp) |
| 1404 | { |
| 1405 | INFO("Printer status : %02x (%s)\n", |
| 1406 | resp->sts1, resp->sts1 ? "Printing": "Idle"); |
| 1407 | INFO("Pages remaining : %03d\n", |
| 1408 | be16_to_cpu(resp->copies)); |
| 1409 | INFO("Other status : %02x %02x %02x %02x %02x %02x\n", |
| 1410 | resp->sts2, resp->sts3, resp->sts4, |
| 1411 | resp->sts5, resp->sts6, resp->sts7); |
| 1412 | } |
| 1413 | |
| 1414 | static void mitsucp30_dump_status(struct mitsucp30_status *resp) |
| 1415 | { |
| 1416 | INFO("Printer status : %02x %02x\n", |
| 1417 | resp->sts, resp->sts2); |
| 1418 | INFO("Printer error : %s (%04x)\n", |
| 1419 | cp30_errors(be16_to_cpu(resp->err)), |
| 1420 | be16_to_cpu(resp->err)); |
| 1421 | } |
| 1422 | |
| 1423 | static void mitsu9550_dump_status2(struct mitsu9550_status2 *resp) |
| 1424 | { |
| 1425 | INFO("Prints remaining on media : %03d\n", |
| 1426 | be16_to_cpu(resp->remain)); |
| 1427 | } |
| 1428 | |
| 1429 | static int mitsu9550_query_media(struct mitsu9550_ctx *ctx) |
| 1430 | { |
| 1431 | struct mitsu9550_media resp; |
| 1432 | int ret; |
| 1433 | |
| 1434 | ret = mitsu9550_get_status(ctx, (uint8_t*) &resp, CP9XXX_STS_MEDIA); |
| 1435 | |
| 1436 | if (!ret) |
| 1437 | mitsu9550_dump_media(ctx, &resp); |
| 1438 | |
| 1439 | return ret; |
| 1440 | } |
| 1441 | |
| 1442 | static int mitsu9550_query_status2(struct mitsu9550_ctx *ctx) |
| 1443 | { |
| 1444 | struct mitsu9550_status2 resp; |
| 1445 | int ret; |
| 1446 | |
| 1447 | ret = mitsu9550_get_status(ctx, (uint8_t*) &resp, CP9XXX_STS_x21); |
| 1448 | |
| 1449 | if (!ret && ctx->conn->type != P_MITSU_CP30D) |
| 1450 | mitsu9550_dump_status2(&resp); |
| 1451 | |
| 1452 | return ret; |
| 1453 | } |
| 1454 | |
| 1455 | static int mitsu9550_query_status(struct mitsu9550_ctx *ctx) |
| 1456 | { |
| 1457 | int ret; |
| 1458 | |
| 1459 | if (ctx->conn->type == P_MITSU_CP30D) { |
| 1460 | struct mitsucp30_status resp; |
| 1461 | ret = mitsu9550_get_status(ctx, (uint8_t*) &resp, CP9XXX_STS_x32); |
| 1462 | if (!ret) { |
| 1463 | mitsucp30_dump_status(&resp); |
| 1464 | ret = mitsu9550_query_status2(ctx); |
| 1465 | } |
| 1466 | } else { |
| 1467 | struct mitsu9550_status resp; |
| 1468 | ret = mitsu9550_get_status(ctx, (uint8_t*) &resp, CP9XXX_STS_x30); |
| 1469 | if (!ret) { |
| 1470 | mitsu9550_dump_status(&resp); |
| 1471 | ret = mitsu9550_query_status2(ctx); |
| 1472 | } |
| 1473 | } |
| 1474 | |
| 1475 | return ret; |
| 1476 | } |
| 1477 | |
| 1478 | static int mitsu9550_query_statusX(struct mitsu9550_ctx *ctx) |
| 1479 | { |
| 1480 | struct mitsu9550_status2 resp; |
| 1481 | int ret; |
| 1482 | |
| 1483 | #if 0 |
| 1484 | int i; |
| 1485 | for (i = 0 ; i < 256 ; i++) { |
| 1486 | ret = mitsu9550_get_status(ctx, (uint8_t*) &resp, i); |
| 1487 | if (!ret) { |
| 1488 | DEBUG("Query %02x OK\n", i); |
| 1489 | } |
| 1490 | } |
| 1491 | #else |
| 1492 | ret = mitsu9550_get_status(ctx, (uint8_t*) &resp, CP9XXX_STS_x20); |
| 1493 | if (!ret) |
| 1494 | ret = mitsu9550_get_status(ctx, (uint8_t*) &resp, CP9XXX_STS_FWVER); |
| 1495 | if (!ret) |
| 1496 | ret = mitsu9550_get_status(ctx, (uint8_t*) &resp, CP9XXX_STS_x22); |
| 1497 | if (!ret) |
| 1498 | ret = mitsu9550_get_status(ctx, (uint8_t*) &resp, CP9XXX_STS_x26); |
| 1499 | if (!ret) |
| 1500 | ret = mitsu9550_get_status(ctx, (uint8_t*) &resp, CP9XXX_STS_x32); |
| 1501 | #endif |
| 1502 | return ret; |
| 1503 | } |
| 1504 | |
| 1505 | static int mitsu9550_query_serno(struct dyesub_connection *conn, char *buf, int buf_len) |
| 1506 | { |
| 1507 | struct mitsu9550_cmd cmd; |
| 1508 | uint8_t rdbuf[READBACK_LEN]; |
| 1509 | uint8_t *ptr; |
| 1510 | int ret, num, i; |
| 1511 | |
| 1512 | cmd.cmd[0] = 0x1b; |
| 1513 | cmd.cmd[1] = 0x72; |
| 1514 | cmd.cmd[2] = 0x6e; |
| 1515 | cmd.cmd[3] = 0x00; |
| 1516 | |
| 1517 | if ((ret = send_data(conn, |
| 1518 | (uint8_t*) &cmd, sizeof(cmd)))) |
| 1519 | return (ret < 0) ? ret : CUPS_BACKEND_FAILED; |
| 1520 | |
| 1521 | ret = read_data(conn, |
| 1522 | rdbuf, READBACK_LEN, &num); |
| 1523 | |
| 1524 | if (ret < 0) |
| 1525 | return CUPS_BACKEND_FAILED; |
| 1526 | |
| 1527 | if ((unsigned int)num < sizeof(cmd) + 1) /* Short read */ |
| 1528 | return CUPS_BACKEND_FAILED; |
| 1529 | |
| 1530 | if (rdbuf[0] != 0xe4 || |
| 1531 | rdbuf[1] != 0x72 || |
| 1532 | rdbuf[2] != 0x6e || |
| 1533 | rdbuf[3] != 0x00) /* Bad response */ |
| 1534 | return CUPS_BACKEND_FAILED; |
| 1535 | |
| 1536 | /* If response is truncated, handle it */ |
| 1537 | num -= (sizeof(cmd) + 1); |
| 1538 | if ((unsigned int) num != rdbuf[4]) |
| 1539 | WARNING("Short serno read! (%d vs %u)\r\n", |
| 1540 | num, rdbuf[4]); |
| 1541 | |
| 1542 | /* model and serial number are encoded as 16-bit unicode, |
| 1543 | little endian, separated by spaces. */ |
| 1544 | i = num; |
| 1545 | ptr = rdbuf + 5; |
| 1546 | while (i > 0 && buf_len > 1) { |
| 1547 | if (*ptr != 0x20) |
| 1548 | *buf++ = *ptr; |
| 1549 | buf_len--; |
| 1550 | ptr += 2; |
| 1551 | i -= 2; |
| 1552 | } |
| 1553 | *buf = 0; /* Null-terminate the returned string */ |
| 1554 | |
| 1555 | return ret; |
| 1556 | } |
| 1557 | |
| 1558 | static int mitsu9550_cancel_job(struct mitsu9550_ctx *ctx) |
| 1559 | { |
| 1560 | int ret; |
| 1561 | |
| 1562 | uint8_t buf[2] = { 0x1b, 0x44 }; |
| 1563 | ret = send_data(ctx->conn, buf, sizeof(buf)); |
| 1564 | |
| 1565 | return ret; |
| 1566 | } |
| 1567 | |
| 1568 | static void mitsu9550_cmdline(void) |
| 1569 | { |
| 1570 | DEBUG("\t\t[ -m ] # Query media\n"); |
| 1571 | DEBUG("\t\t[ -s ] # Query status\n"); |
| 1572 | DEBUG("\t\t[ -X ] # Cancel current job\n"); |
| 1573 | // DEBUG("\t\t[ -Z ] # Dump all parameters\n"); |
| 1574 | } |
| 1575 | |
| 1576 | static int mitsu9550_cmdline_arg(void *vctx, int argc, char **argv) |
| 1577 | { |
| 1578 | struct mitsu9550_ctx *ctx = vctx; |
| 1579 | int i, j = 0; |
| 1580 | |
| 1581 | if (!ctx) |
| 1582 | return -1; |
| 1583 | |
| 1584 | while ((i = getopt(argc, argv, GETOPT_LIST_GLOBAL "msXZ")) >= 0) { |
| 1585 | switch(i) { |
| 1586 | GETOPT_PROCESS_GLOBAL |
| 1587 | case 'm': |
| 1588 | j = mitsu9550_query_media(ctx); |
| 1589 | break; |
| 1590 | case 's': |
| 1591 | j = mitsu9550_query_status(ctx); |
| 1592 | INFO("Firmware Version: %s\n", ctx->fwver); |
| 1593 | break; |
| 1594 | case 'X': |
| 1595 | j = mitsu9550_cancel_job(ctx); |
| 1596 | break; |
| 1597 | case 'Z': |
| 1598 | j = mitsu9550_query_statusX(ctx); |
| 1599 | break; |
| 1600 | default: |
| 1601 | break; /* Ignore completely */ |
| 1602 | } |
| 1603 | |
| 1604 | if (j) return j; |
| 1605 | } |
| 1606 | |
| 1607 | return CUPS_BACKEND_OK; |
| 1608 | } |
| 1609 | |
| 1610 | static int mitsu9550_query_markers(void *vctx, struct marker **markers, int *count) |
| 1611 | { |
| 1612 | struct mitsu9550_ctx *ctx = vctx; |
| 1613 | struct mitsu9550_media media; |
| 1614 | |
| 1615 | /* Query printer status */ |
| 1616 | if (mitsu9550_get_status(ctx, (uint8_t*) &media, CP9XXX_STS_MEDIA)) |
| 1617 | return CUPS_BACKEND_FAILED; |
| 1618 | |
| 1619 | if (ctx->conn->type == P_MITSU_CP30D) { |
| 1620 | ctx->marker.levelnow = be16_to_cpu(media.remain2); |
| 1621 | } else { |
| 1622 | ctx->marker.levelnow = be16_to_cpu(media.remain); |
| 1623 | } |
| 1624 | |
| 1625 | *markers = &ctx->marker; |
| 1626 | *count = 1; |
| 1627 | |
| 1628 | return CUPS_BACKEND_OK; |
| 1629 | } |
| 1630 | |
| 1631 | static const char *mitsu9550_prefixes[] = { |
| 1632 | "mitsu9xxx", // Family driver, do not nuke. |
| 1633 | // Backwards compatibility |
| 1634 | "mitsu9000", "mitsu9500", "mitsu9550", "mitsu9600", "mitsu9800", "mitsu9810", |
| 1635 | NULL |
| 1636 | }; |
| 1637 | |
| 1638 | static const struct device_id mitsu9550_devices[] = { |
| 1639 | // { 0x06d3, 0x0380, P_MITSU_9550, NULL, "mitsubishi-8000d"}, |
| 1640 | // { 0x06d3, 0x0381, P_MITSU_9550, NULL, "mitsubishi-770d"}, |
| 1641 | // { 0x06d3, 0x0385, P_MITSU_9550, NULL, "mitsubishi-900d"}, |
| 1642 | // { 0x06d3, 0x0387, P_MITSU_9550, NULL, "mitsubishi-980d"}, |
| 1643 | // { 0x06d3, 0x038b, P_MITSU_CP3020, NULL, "mitsubishi-cp3020d"}, |
| 1644 | // { 0x06d3, 0x038c, P_MITSU_9550, NULL, "mitsubishi-900did"}, |
| 1645 | { 0x06d3, 0x0395, P_MITSU_9550, NULL, "mitsubishi-9000dw"}, // XXX -am instead? |
| 1646 | { 0x06d3, 0x0393, P_MITSU_9550, NULL, "mitsubishi-9500dw"}, |
| 1647 | { 0x06d3, 0x0394, P_MITSU_9550, NULL, "mitsubishi-9000dw"}, |
| 1648 | { 0x06d3, 0x039e, P_MITSU_9500S, NULL, "mitsubishi-9500dw-s"}, |
| 1649 | { 0x06d3, 0x03a1, P_MITSU_9550, NULL, "mitsubishi-9550dw"}, |
| 1650 | { 0x06d3, 0x03a1, P_MITSU_9550, NULL, "mitsubishi-9550d"}, /* Duplicate */ |
| 1651 | { 0x06d3, 0x03a5, P_MITSU_9550S, NULL, "mitsubishi-9550dw-s"}, // or DZ/DZS/DZU |
| 1652 | { 0x06d3, 0x03a5, P_MITSU_9550S, NULL, "mitsubishi-9550dz"}, /* Duplicate */ |
| 1653 | { 0x06d3, 0x03a6, P_MITSU_9600S, NULL, "mitsubishi-9600dw-s"}, |
| 1654 | { 0x06d3, 0x03a9, P_MITSU_9600, NULL, "mitsubishi-9600dw"}, |
| 1655 | // { 0x06d3, 0x03aa, P_MITSU_CP3020, NULL, "mitsubishi-cp3020da"}, |
| 1656 | { 0x06d3, 0x03ab, P_MITSU_CP30D, NULL, "mitsubishi-cp30dw"}, |
| 1657 | { 0x06d3, 0x03ad, P_MITSU_9800, NULL, "mitsubishi-9800dw"}, |
| 1658 | { 0x06d3, 0x03ad, P_MITSU_9800, NULL, "mitsubishi-9800d"}, /* Duplicate */ |
| 1659 | { 0x06d3, 0x03ae, P_MITSU_9800S, NULL, "mitsubishi-9800dw-s"}, |
| 1660 | { 0x06d3, 0x03ae, P_MITSU_9800S, NULL, "mitsubishi-9800dz"}, /* Duplicate */ |
| 1661 | { 0x06d3, 0x3b20, P_MITSU_9820S, NULL, "mitsubishi-9820dw-ag"}, |
| 1662 | { 0x06d3, 0x3b21, P_MITSU_9810, NULL, "mitsubishi-9810dw"}, |
| 1663 | { 0x06d3, 0x3b21, P_MITSU_9810, NULL, "mitsubishi-9810d"}, /* Duplicate */ |
| 1664 | // { 0x06d3, 0x3b2f, P_MITSU_9810, NULL, "mitsubishi-ls9820a"}, |
| 1665 | { 0, 0, 0, NULL, NULL} |
| 1666 | }; |
| 1667 | |
| 1668 | /* Exported */ |
| 1669 | const struct dyesub_backend mitsu9550_backend = { |
| 1670 | .name = "Mitsubishi CP9xxx family", |
| 1671 | .version = "0.72" " (lib " LIBMITSU_VER ")", |
| 1672 | .uri_prefixes = mitsu9550_prefixes, |
| 1673 | .devices = mitsu9550_devices, |
| 1674 | .cmdline_usage = mitsu9550_cmdline, |
| 1675 | .cmdline_arg = mitsu9550_cmdline_arg, |
| 1676 | .init = mitsu9550_init, |
| 1677 | .attach = mitsu9550_attach, |
| 1678 | .teardown = mitsu9550_teardown, |
| 1679 | .cleanup_job = mitsu9550_cleanup_job, |
| 1680 | .read_parse = mitsu9550_read_parse, |
| 1681 | .main_loop = mitsu9550_main_loop, |
| 1682 | .query_serno = mitsu9550_query_serno, |
| 1683 | .query_markers = mitsu9550_query_markers, |
| 1684 | }; |
| 1685 | |
| 1686 | /* Mitsubish CP-30/9500/9550/9600/9800/9810/9820 spool format: |
| 1687 | |
| 1688 | Spool file consists of 3 or 4 50-byte headers, followed by three |
| 1689 | image planes, each with a 12-byte header, then a 4 or 6-byte footer. |
| 1690 | |
| 1691 | All multi-byte numbers are big endian. |
| 1692 | |
| 1693 | ~~~ Header 1 |
| 1694 | |
| 1695 | 1b 57 20 2e 00 QQ QQ 00 00 00 00 00 00 00 XX XX :: XX XX == columns |
| 1696 | YY YY 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :: YY YY == rows |
| 1697 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :: QQ == 0x0a90 on 9810, 0x0a10 on all others. |
| 1698 | 00 00 |
| 1699 | |
| 1700 | ~~~ Header 2 |
| 1701 | |
| 1702 | 1b 57 21 2e 00 GG 00 HH QQ QQ 00 00 00 00 00 00 :: ZZ ZZ = num copies (>= 0x01) |
| 1703 | 00 00 00 00 00 00 00 00 00 00 00 00 ZZ ZZ 00 00 :: YY = 00/80 Fine/SuperFine (9550), 10/80 Fine/Superfine (98x0), 00 (9600), 0x80/0x00 Powersave/Normal (CP30) |
| 1704 | XX 00 00 00 00 00 YY 00 00 00 00 00 00 00 SS TT :: XX = 00 normal, 83 Cut 2x6 (9550 only!) |
| 1705 | RR II :: QQ QQ = 0x0803 on 9550, 0x0801 on 98x0, 0x0003 on 9600, 0xa803 on 9500, 0x0802 on CP30 |
| 1706 | :: RR = 01 for "use LUT" on 98xx, 0x00 otherwise. Extension to stock. |
| 1707 | :: TT = 01 for "already reversed". Extension to stock. |
| 1708 | :: SS == sharpening level, 0 for off, 1-10 otherwise. Extesion to stock. |
| 1709 | :: GG == 0x00 on CP30, 0x80 on others |
| 1710 | :: HH == 0x20 on CP30, 0x22 on others |
| 1711 | :: II == 0x00 on CP30, 0x01 on others. |
| 1712 | |
| 1713 | ~~~ Header 3 (9550, 9800-S, and CP30 only..) |
| 1714 | |
| 1715 | 1b 57 22 2e 00 QQ 00 00 00 00 00 XX 00 00 00 00 :: XX = 00 normal, 01 FineDeep |
| 1716 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :: QQ = 0xf0 on 9500, 0x40 on the rest |
| 1717 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
| 1718 | 00 00 |
| 1719 | |
| 1720 | ~~~ Header 4 (all but 9550-S and 9800-S, involves error policy?) |
| 1721 | |
| 1722 | 1b 57 26 2e 00 QQ TT 00 00 00 00 SS RR ZZ VV WW :: QQ = 0x70 on 9550/98x0, 0x60 on 9600 or 9800S, 0x3f on CP30 [also seen 0x20 & 0x00 on 9550S] |
| 1723 | WW 00 WW 00 00 00 00 00 00 00 00 00 00 00 00 00 :: RR = 0x01 on 9550/98x0/CP30, 0x00 on 9600 [ "ignore errors? ] |
| 1724 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :: SS = 0x01 on 9800S, 0x00 otherwise. |
| 1725 | 00 00 |
| 1726 | :: ZZ = Unknown; 0x01 [9550S/CP30] & 0x00 [9500]. |
| 1727 | :: TT = 0x80 on CP30, 0x00 otherwise |
| 1728 | :: VV = 0x80 on CP30, 0x00 otherwise |
| 1729 | :: WW = 0x10 on CP30, 0x00 otherwise |
| 1730 | |
| 1731 | ~~~~ Data follows: |
| 1732 | |
| 1733 | Format is: planar YMC16 for 98x0 (but only 12 bits used, BIG endian) |
| 1734 | planar RGB for all others |
| 1735 | |
| 1736 | 1b 5a 54 ?? RR RR CC CC 07 14 04 d8 :: 0714 == columns, 04d8 == rows |
| 1737 | :: RRRR == row offset for data, CCCC == col offset for data |
| 1738 | :: ?? == 0x00 for 8bpp, 0x10 for 16/12bpp. |
| 1739 | :: 0x80 for PACKED BGR! |
| 1740 | |
| 1741 | Data follows immediately, no padding. |
| 1742 | |
| 1743 | 1b 5a 54 00 00 00 00 00 07 14 04 d8 :: Another plane. |
| 1744 | |
| 1745 | Data follows immediately, no padding. |
| 1746 | |
| 1747 | 1b 5a 54 00 00 00 00 00 07 14 04 d8 :: Another plane. |
| 1748 | |
| 1749 | Data follows immediately, no padding. |
| 1750 | |
| 1751 | ~~~~ Footer: |
| 1752 | |
| 1753 | 1b 50 41 00 (9500AM) |
| 1754 | 1b 50 45 00 (9500-S) |
| 1755 | 1b 50 46 00 (9550) |
| 1756 | 1b 50 47 00 (9550-S) |
| 1757 | 1b 50 48 00 (9600) |
| 1758 | 1b 50 49 00 (9600-S) |
| 1759 | 1b 50 4c 00 (9800/9810) |
| 1760 | 1b 50 4d 00 (9000) |
| 1761 | 1b 50 4e 00 (9800-S, 9820-S) (#170/aa,173,174,180/b4,183) |
| 1762 | 1b 50 51 00 (CP3020DA) |
| 1763 | 1b 50 57 00 (9500) |
| 1764 | 1b 50 52 00 00 00 (CP30) |
| 1765 | |
| 1766 | ~~~~ Lamination data follows (on 9810 only, if matte selected) |
| 1767 | |
| 1768 | 1b 5a 54 10 00 00 00 00 06 24 04 34 |
| 1769 | |
| 1770 | Data follows immediately, no padding. |
| 1771 | |
| 1772 | 1b 50 56 00 (Lamination footer) |
| 1773 | |
| 1774 | ~~~~ QUESTIONS: |
| 1775 | |
| 1776 | * Lamination control? |
| 1777 | * Other 9550 multi-cut modes (on 6x9 media: 4x6*2, 4.4x6*2, 3x6*3, 2x6*4) |
| 1778 | * 9600/98x0 multi-cut modes? |
| 1779 | |
| 1780 | *********************************************************************** |
| 1781 | |
| 1782 | * Mitsubishi CP-9xxx Communications Protocol: |
| 1783 | |
| 1784 | JOB CANCEL |
| 1785 | |
| 1786 | -> 1b 44 |
| 1787 | |
| 1788 | [[ Unknown query 1 ]] |
| 1789 | |
| 1790 | -> 1b 4b 7f 00 |
| 1791 | <- eb 4b 8f 00 02 00 5e [[ '02' seems to be a length ]] |
| 1792 | |
| 1793 | [[ unknown query 2, 9800-only ]] |
| 1794 | |
| 1795 | -> 1b 4b 01 00 |
| 1796 | <- e4 4b 01 00 02 00 78 |
| 1797 | |
| 1798 | PRINT START |
| 1799 | |
| 1800 | -> 1b 50 47 00 [9550S] |
| 1801 | -> 1b 50 4e 00 [9800S] |
| 1802 | -> 1b 50 56 00 [9810 Lamination] |
| 1803 | [[ see "footer" above for other models ]] |
| 1804 | |
| 1805 | [[ Unknown 1 ]] |
| 1806 | |
| 1807 | -> 1b 51 c5 9d |
| 1808 | |
| 1809 | [[ Unknown ]] |
| 1810 | |
| 1811 | -> 1b 53 00 00 |
| 1812 | |
| 1813 | [[ Unknown ]] |
| 1814 | |
| 1815 | -> 1b 53 c5 9d |
| 1816 | |
| 1817 | [[ Status Query B ]] |
| 1818 | |
| 1819 | -> 1b 56 20 00 [ CP30 ] |
| 1820 | <- 20 2e 00 0a 10 00 00 00 00 00 00 00 CC CC RR RR :: CC == cols |
| 1821 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :: RR == rows (04b0 for L??) |
| 1822 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
| 1823 | |
| 1824 | [[ Status Query C ]] |
| 1825 | |
| 1826 | -> 1b 56 21 00 [ Most models ] |
| 1827 | <- 21 2e 00 80 00 22 XX 0b 00 00 00 00 00 00 00 00 :: XX == a8 (most) 08 (9810) |
| 1828 | 00 00 00 00 00 00 00 00 00 00 00 QQ 00 00 00 00 :: QQ == Prints in job? |
| 1829 | 00 00 00 00 00 00 00 00 00 00 NN NN 0a 00 00 01 :: NN NN = Remaining media |
| 1830 | |
| 1831 | 21 2e 00 00 00 20 08 02 00 00 00 00 00 00 00 00 [ CP30 ] |
| 1832 | 00 00 00 00 00 00 00 00 00 00 00 XX 00 00 00 00 :: XX == seen 01 and 02. Unknown. |
| 1833 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
| 1834 | |
| 1835 | [[ Status Query D (unknown, possibly lifetime print count?) ]] |
| 1836 | |
| 1837 | -> 1b 56 22 00 [ CP30 ] |
| 1838 | <- 22 2e 00 40 00 00 00 00 00 00 00 00 00 00 00 00 |
| 1839 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
| 1840 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
| 1841 | |
| 1842 | FIRWARE VERSIONS |
| 1843 | |
| 1844 | -> 1b 56 23 00 [ CP30 ] |
| 1845 | <- 23 2e 00 00 00 00 32 32 33 46 31 30 32 32 34 42 223F10 224B10 ... 222A10 |
| 1846 | 31 30 00 00 00 00 00 00 32 32 32 41 31 30 00 00 |
| 1847 | 00 00 00 05 d9 3f 79 20 00 00 13 97 00 00 00 00 |
| 1848 | |
| 1849 | MEDIA INFO |
| 1850 | |
| 1851 | -> 1b 56 24 00 |
| 1852 | <- 24 2e 00 00 00 00 00 00 00 00 00 00 XX 00 TT 00 :: TT = Type (!CP30) ; XX = 0x02 on CP30, 0x00 otherwise. |
| 1853 | 00 00 00 00 00 00 00 00 00 00 00 00 MM MM N1 N1 :: MM MM = Max prints |
| 1854 | NN NN 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :: NN NN = Remaining (!CP30) ; N1 N1 = Remaining (CP30) |
| 1855 | |
| 1856 | [[ Status Query E ]] |
| 1857 | |
| 1858 | -> 1b 56 26 00 [ CP30 ] |
| 1859 | <- 26 2e 00 3f 80 00 00 00 00 00 01 01 80 00 00 00 |
| 1860 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
| 1861 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
| 1862 | |
| 1863 | Status Query [All models except CP30] |
| 1864 | |
| 1865 | -> 1b 56 30 00 |
| 1866 | -> 30 2e 00 00 00 00 MM 00 NN NN ZZ 00 00 00 00 00 :: MM, NN, ZZ |
| 1867 | QQ RR SS 00 00 00 00 00 00 00 00 00 00 00 00 00 :: QQ, RR, SS |
| 1868 | 00 00 00 00 00 00 00 00 00 00 00 00 TT UU 00 00 :: TT, UU |
| 1869 | |
| 1870 | Status Query [CP30] |
| 1871 | |
| 1872 | -> 1b 56 32 00 |
| 1873 | <- 32 2e 00 00 00 43 00 50 00 33 00 30 00 44 00 20 :: Unicode, "CP30D 204578" |
| 1874 | 00 32 00 30 00 34 00 35 00 37 00 38 00 00 SS SS :: SS SS = status code (see CP30_STS_*) |
| 1875 | 00 EE EE 00 00 00 NN 00 00 00 00 00 00 00 00 00 :: NN = remaining prints on paper |
| 1876 | :: EE EE = error code (see CP30_ERR_*) |
| 1877 | |
| 1878 | Status Query X (unknown) |
| 1879 | |
| 1880 | -> 1b 56 33 00 |
| 1881 | <- ??? 48 bytes? |
| 1882 | |
| 1883 | Status Query Y (unknown) |
| 1884 | |
| 1885 | -> 1b 56 36 00 |
| 1886 | <- ??? 48 bytes? |
| 1887 | |
| 1888 | [[ Header 1 -- See above ]] |
| 1889 | |
| 1890 | -> 1b 57 20 2e .... |
| 1891 | |
| 1892 | [[ Header 2 -- See above ]] |
| 1893 | |
| 1894 | -> 1b 57 21 2e .... |
| 1895 | |
| 1896 | [[ Header 3 -- See above ]] |
| 1897 | |
| 1898 | -> 1b 57 22 2e .... |
| 1899 | |
| 1900 | [[ Header 4 -- See above ]] |
| 1901 | |
| 1902 | -> 1b 57 26 2e .... |
| 1903 | |
| 1904 | DATA Start [[ Or maybe it's "DATA Clear" ? Only seen on -S models ]] |
| 1905 | |
| 1906 | -> 1b 5a 43 00 |
| 1907 | |
| 1908 | PLANE Data |
| 1909 | |
| 1910 | -> 1b 5a 54 ?? 00 00 00 00 XX XX YY YY :: XX XX == Columns, YY YY == Rows |
| 1911 | :: ?? == x00 8bpp, x10 16bpp |
| 1912 | |
| 1913 | Followed by image plane data, XXXX * YYYY [ * 2 ] bytes |
| 1914 | |
| 1915 | [ Three planes are needed! ] |
| 1916 | |
| 1917 | Query Model & FW Version (XXX Confirm this!) |
| 1918 | |
| 1919 | -> 1b 72 01 00 |
| 1920 | <- e4 82 01 00 LL 39 00 35 00 35 00 30 00 5a 00 20 |
| 1921 | 00 41 00 32 00 30 00 30 00 36 00 37 00 |
| 1922 | |
| 1923 | 'LL' is length. Data is returned in 16-bit unicode, LE. |
| 1924 | Contents are model ('9550Z'), then space, then serialnum ('A20067') |
| 1925 | |
| 1926 | [[ Unknown query.. "Printer number" related? Seen in driver dump ]] |
| 1927 | |
| 1928 | -> 1b 72 10 00 |
| 1929 | <- e4 82 10 00 LL [ 10 unknown bytes. guess. ] |
| 1930 | |
| 1931 | Query Model & Serial number |
| 1932 | |
| 1933 | -> 1b 72 6e 00 |
| 1934 | <- e4 82 6e 00 LL 39 00 35 00 35 00 30 00 5a 00 20 |
| 1935 | 00 41 00 32 00 30 00 30 00 36 00 37 00 |
| 1936 | |
| 1937 | 'LL' is length. Data is returned in 16-bit unicode, LE. |
| 1938 | Contents are model ('9550Z'), then space, then serialnum ('A20067') |
| 1939 | |
| 1940 | |
| 1941 | **** After print starts, loop status/status b/media queries until printer idle |
| 1942 | |
| 1943 | MM, QQ RR SS, TT UU |
| 1944 | |
| 1945 | <- 00 3e 00 00 8a 44 :: Idle. |
| 1946 | 00 7e 00 00 8a 44 :: Plane data submitted, pre "end data" cmd |
| 1947 | 00 7e 40 01 8a 44 :: "end data" sent |
| 1948 | 30 7e 40 01 8a 44 |
| 1949 | 38 7e 40 01 8a 44 |
| 1950 | 59 7e 40 01 8a 44 |
| 1951 | 59 7e 40 00 8a 44 |
| 1952 | 4d 7e 40 00 8a 44 |
| 1953 | [...] |
| 1954 | 43 7e 40 00 82 44 |
| 1955 | [...] |
| 1956 | 50 7e 40 00 80 44 |
| 1957 | [...] |
| 1958 | 31 7e 40 00 7d 44 |
| 1959 | [...] |
| 1960 | 00 3e 00 00 80 44 :: Idle. |
| 1961 | |
| 1962 | Also seen: |
| 1963 | |
| 1964 | 00 3e 00 00 96 4b :: Idle |
| 1965 | 00 be 00 00 96 4b :: Data submitted, pre "start" |
| 1966 | 00 be 80 01 96 4b :: print start sent |
| 1967 | 30 be 80 01 96 4c |
| 1968 | [...] |
| 1969 | 30 be 80 01 89 4b |
| 1970 | 38 be 80 01 8a 4b |
| 1971 | 59 be 80 01 8b 4b |
| 1972 | [...] |
| 1973 | 4d be 80 01 89 4b |
| 1974 | [...] |
| 1975 | 43 be 80 01 89 4b |
| 1976 | [...] |
| 1977 | 50 be 80 01 82 4b |
| 1978 | [...] |
| 1979 | 31 be 80 01 80 4b |
| 1980 | [...] |
| 1981 | |
| 1982 | 00 be 80 01 76 37 :: printed 4x6 on 6x9? |
| 1983 | |
| 1984 | Working theory of interpreting the status flags: |
| 1985 | |
| 1986 | MM :: 00 is idle, else mechanical printer state. |
| 1987 | NN :: Remaining prints in job, or 0x00 0x00 when idle. |
| 1988 | QQ :: ?? 0x3e + 0x40 or 0x80 (see below) |
| 1989 | RR :: ?? 0x00 is idle, 0x40 or 0x80 is "printing"? |
| 1990 | SS :: ?? 0x00 means "ready for another print" but 0x01 is "busy" |
| 1991 | TT :: ?? seen values between 0x76 through 0x96) |
| 1992 | UU :: ?? seen values between 0x37 and 0x4c -- temperature? |
| 1993 | ZZ :: ?? Error code (08 = Door open on 9600) |
| 1994 | |
| 1995 | *** |
| 1996 | |
| 1997 | Other printer commands seen: |
| 1998 | |
| 1999 | [[ Set error policy ?? aka "header 4" ]] |
| 2000 | |
| 2001 | -> 1b 57 26 2e 00 QQ 00 00 00 00 00 00 RR ZZ 00 00 :: QQ/RR/ZZ 00 00 00 [9550S] |
| 2002 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :: 20 01 00 [9550S w/ ignore failures on] |
| 2003 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :: 70 01 01 [9550] |
| 2004 | 00 00 |
| 2005 | |
| 2006 | */ |