| 1 | /* |
| 2 | * Mitsubishi CP-D90DW Photo Printer CUPS backend |
| 3 | * |
| 4 | * (c) 2019-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 mitsud90_backend |
| 28 | |
| 29 | #include "backend_common.h" |
| 30 | #include "backend_mitsu.h" |
| 31 | |
| 32 | /* CPM1 stuff */ |
| 33 | #define CPM1_LAMINATE_STRIDE 1852 |
| 34 | |
| 35 | #define CPM1_LAMINATE_FILE "M1_MAT02.raw" |
| 36 | #define CPM1_CPC_FNAME "CPM1_N1.csv" |
| 37 | #define CPM1_CPC_G1_FNAME "CPM1_G1.csv" |
| 38 | #define CPM1_CPC_G5_FNAME "CPM1_G5.csv" |
| 39 | #define CPM1_CPC_G5_VIVID_FNAME "CPM1_G5_vivid.csv" |
| 40 | #define CPM1_LUT_FNAME "CPM1_NL.lut" |
| 41 | |
| 42 | /* D90 LUT for when we are doing panoramas */ |
| 43 | #define CPD90_LUT_FNAME "CPD90L01.lut" |
| 44 | #define CPD90_CPC_FNAME "CPD90_N1.csv" |
| 45 | #define CPD90_CPC_3_1_FNAME "CP90_3_1.csv" |
| 46 | #define CPD90_CPC_3_2_FNAME "CP90_3_2.csv" |
| 47 | |
| 48 | /* ASK500 stuff -- Note the lack of LUT or G5_vivid! */ |
| 49 | #define ASK5_LAMINATE_FILE "ASK5_MAT.raw" |
| 50 | #define ASK5_CPC_FNAME "ASK5_N1.csv" |
| 51 | #define ASK5_CPC_G1_FNAME "ASK5_G1.csv" |
| 52 | #define ASK5_CPC_G5_FNAME "ASK5_G5.csv" |
| 53 | |
| 54 | /* Printer data structures */ |
| 55 | #define COM_STATUS_TYPE_MODEL 0x01 // 10, null-terminated ASCII. 'CPD90D' |
| 56 | #define W5K_STATUS_TYPE_MODEL 0x01 // 5, ASCII, non-terminated: 'W5000' |
| 57 | #define COM_STATUS_TYPE_x02 0x02 // 1, 0x5f ? |
| 58 | #define CM1_STATUS_TYPE_ISERIAL 0x03 // 24, full iSerial string in UTF16(LE) |
| 59 | #define CM1_STATUS_TYPE_SERIAL 0x04 // 6, serial number only (ascii) |
| 60 | #define W5K_STATUS_TYPE_SERIAL 0x06 // 8, 36 30 31 34 30 35 43 20 (601405M ) |
| 61 | #define W5K_STATUS_TYPE_x07 0x07 // 6, 30 38 46 35 46 37 (08F5F7) |
| 62 | #define W5K_STATUS_TYPE_x08 0x08 // 9, 00 00 00 00 00 00 00 00 00 |
| 63 | #define W5K_STATUS_TYPE_x09 0x09 // 9, 00 00 00 00 00 00 00 00 00 |
| 64 | #define CM1_STATUS_TYPE_FW_0a 0x0a // 8, 34 34 38 41 31 32 29 f4 (448A12) |
| 65 | #define COM_STATUS_TYPE_FW_LOADER 0x0b // 8, 34 31 34 42 31 31 a7 de (414D11) |
| 66 | #define COM_STATUS_TYPE_FW_MAIN 0x0c // 8, 34 31 35 41 38 31 86 bf (415A81) |
| 67 | #define COM_STATUS_TYPE_FW_FPGA 0x0d // 8, 34 31 36 41 35 31 dc 8a (416A51) |
| 68 | #define COM_STATUS_TYPE_FW_TBL 0x0e // 8, 34 31 37 45 31 31 e7 e6 (417E11) |
| 69 | #define COM_STATUS_TYPE_FW_TAG 0x0f // 8, 34 31 38 41 31 32 6c 64 (418A12) |
| 70 | |
| 71 | #define W5K_STATUS_TYPE_FW_LUT 0x10 // 8, 33 37 30 41 32 34 91 22 (370A24) |
| 72 | #define COM_STATUS_TYPE_FW_SATIN 0x11 // 8, 34 32 31 51 31 31 74 f2 (421Q11) |
| 73 | #define W5K_STATUS_TYPE_FW_12 0x12 // 8, 30 30 30 30 30 30 30 30 (000000) |
| 74 | #define COM_STATUS_TYPE_FW_MECH 0x13 // 8, 34 31 39 45 31 31 15 bf (419E11) NOT W5K |
| 75 | #define W5K_STATUS_TYPE_x15 0x15 // 2, 00 00 |
| 76 | #define COM_STATUS_TYPE_ERROR 0x16 // 11 (see below) |
| 77 | #define COM_STATUS_TYPE_MECHA 0x17 // 2 (see below) |
| 78 | #define W5K_STAUTS_TYPE_x1a 0x1a // 1, 00 (error flag? 0x10 seems to be a |
| 79 | #define COM_STATUS_TYPE_x1e 0x1e // 1, power state or time? (x00) |
| 80 | #define COM_STATUS_TYPE_TEMP 0x1f // 1 (see below) |
| 81 | |
| 82 | #define W5K_STATUS_TYPE_x20 0x20 // 1, 00 |
| 83 | #define COM_STATUS_TYPE_x22 0x22 // 2, all 0 (NOT W5K) |
| 84 | #define W5K_STATUS_TYPE_x23 0x23 // 16, all 0 |
| 85 | #define W5K_STATUS_TYPE_x24 0x24 // 26, all 0 |
| 86 | #define W5K_STATUS_TYPE_x25 0x25 // 16, all 0 |
| 87 | #define COM_STATUS_TYPE_JOBID 0x28 // 2, _next_ Job ID. |
| 88 | #define COM_STATUS_TYPE_INKID 0x29 // 8, e0 07 00 00 21 e6 b3 22 or e0 07 80 96 3f 28 12 2d or e0 07 00 00 2b e8 db bd |
| 89 | #define COM_STATUS_TYPE_MEDIA 0x2a // 10 (see below) |
| 90 | #define COM_STATUS_TYPE_x2b 0x2b // 2, all 0 |
| 91 | #define W5K_STATUS_TYPE_INKID2 0x2b // 8, 0c 57 dc 00 [a1 18] 00 00 |
| 92 | #define COM_STATUS_TYPE_x2c 0x2c // 2, 00 56 (D90) 00 23 (M1) |
| 93 | #define W5K_STATUS_TYPE_x2c 0x2c // 12,06 00 00 00 00 00 00 00 40 54 33 01 |
| 94 | #define W5K_STATUS_TYPE_x2d 0x2d // 4, all 0 |
| 95 | |
| 96 | #define W5K_STATUS_TYPE_x30 0x30 // 2, all 0 |
| 97 | #define W5K_STATUS_TYPE_x31 0x31 // 2, 00 44 |
| 98 | #define W5K_STATUS_TYPE_x33 0x33 // 12, all 0 |
| 99 | #define W5K_STATUS_TYPE_x34 0x34 // 2, 00 4f |
| 100 | #define W5K_STATUS_TYPE_x35 0x35 // 2, 02 |
| 101 | #define W5K_STATUS_TYPE_x37 0x37 // 2, 02 |
| 102 | #define W5K_STATUS_CNT_HEAD 0x3d // 4 |
| 103 | #define W5K_STATUS_CNT_SERVICE 0x3e // 4 |
| 104 | #define W5K_STATUS_CNT_PRINTED 0x3f // 4 |
| 105 | |
| 106 | #define W5K_STATUS_TYPE_x40 0x40 // 4, 00 00 3f b0 (seen it go up and down) |
| 107 | #define W5K_STATUS_TYPE_x45 0x45 // 4, 00 00 00 84 (counter?) <-- incremetns one per print |
| 108 | #define W5K_STATUS_TYPE_DENSITY 0x46 // 2 |
| 109 | #define W5K_STATUS_TYPE_TPHR 0x4b // 2 // Thermal Print Head Resistance |
| 110 | #define W5K_STATUS_TYPE_TPHSN 0x4c // 8 // Thermal Print Head Serno (ASCII, non-terminated) |
| 111 | |
| 112 | #define W5K_STATUS_TYPE_x52 0x52 // 1, 42 |
| 113 | #define W5K_STATUS_CNT_CUTTER 0x5b |
| 114 | |
| 115 | #define W5K_STATUS_CNT_SLITTER 0x60 |
| 116 | #define COM_STATUS_TYPE_x65 0x65 // 50, see below (sensors?) |
| 117 | #define W5K_STATUS_TYPE_x65 0x65 // 54, see below |
| 118 | #define W5K_STATUS_TYPE_LENGTHS 0x6f // 16, BLANKLENA_s16, BLANKLENB_s16, 00 00, MARGINLEN s16, 00 00, CUTLEN_s16, 00 00 00 00 |
| 119 | |
| 120 | #define W5K_STATUS_TYPE_x70 0x70 // 16, 0a 07 ff 0b 00 00 00 00 00 00 00 00 00 00 00 00 |
| 121 | #define W5K_STATUS_TYPE_MOTOR3 0x71 // 16, NN NN NN NN TT TT TT TT 00 00 00 00 00 00 00 00 |
| 122 | #define W5K_STATUS_TYPE_MOTOR5 0x72 // 16, NN NN NN NN TT TT TT TT 00 00 00 00 00 00 00 00 |
| 123 | #define W5K_STATUS_TYPE_MOTOR1 0x73 // 4, CC CC CC CC |
| 124 | |
| 125 | #define D90_STATUS_TYPE_ISEREN 0x82 // 1, 80 (iserial disabled) |
| 126 | #define COM_STATUS_TYPE_x83 0x83 // 1, 00 |
| 127 | #define W5K_STATUS_TYPE_x83 0x83 // 2, 00 80 |
| 128 | #define D90_STATUS_TYPE_x84 0x84 // 1, 00 |
| 129 | #define W5K_STATUS_TYPE_x84 0x84 // 2, 00 0a |
| 130 | #define D90_STATUS_TYPE_x85 0x85 // 2, 00 ?? BE, wait time? combined total of 5. |
| 131 | #define W5K_STATUS_TYPE_x85 0x85 // 2, 00 04 |
| 132 | #define W5K_STATUS_TYPE_x86 0x86 // 2, 01 2c |
| 133 | #define W5K_STATUS_TYPE_DMAXY 0x87 // 1 |
| 134 | #define W5K_STATUS_TYPE_DMINY 0x88 // 1 |
| 135 | #define W5K_STATUS_TYPE_DMAXM 0x89 // 1 |
| 136 | #define W5K_STATUS_TYPE_DMINM 0x8a // 1 |
| 137 | #define W5K_STATUS_TYPE_DMAXC 0x8b // 1 |
| 138 | #define W5K_STATUS_TYPE_DMINC 0x8c // 1 |
| 139 | #define W5K_STATUS_TYPE_LUT 0x8d // 120, 53 4c 54 41 58 32 37 30 -- "SLTAX270" for older media type (vs "SLTA7180" for new media type), followed by 14 more entries for B1-7/C1-7 |
| 140 | #define W5K_STATUS_TYPE_x8e 0x8e // 8, all ff |
| 141 | |
| 142 | #define W5K_STATUS_TYPE_x97 0x97 // 2, 00 01 |
| 143 | |
| 144 | #define W5K_STATUS_TYPE_xc0 0xc0 // 1, 00 |
| 145 | #define W5K_STATUS_TYPE_xc1 0xc1 // 1, 00 |
| 146 | #define W5K_STATUS_TYPE_xc2 0xc2 // 1, 00 |
| 147 | #define W5K_STATUS_TYPE_xc3 0xc3 // 1, 00 |
| 148 | #define W5K_STATUS_TYPE_xc4 0xc4 // 1, 00 |
| 149 | #define W5K_STATUS_TYPE_xc5 0xc5 // 1, 00 |
| 150 | #define W5K_STATUS_TYPE_xc6 0xc6 // 1, 00 |
| 151 | #define W5K_STATUS_TYPE_xc7 0xc7 // 1, 00 |
| 152 | #define W5K_STATUS_TYPE_xc8 0xc8 // 1, 00 |
| 153 | #define W5K_STATUS_TYPE_xc9 0xc9 // 1, 00 |
| 154 | #define W5K_STATUS_TYPE_xca 0xca // 1, 00 |
| 155 | #define W5K_STATUS_TYPE_xcb 0xcb // 1, 00 |
| 156 | #define W5K_STATUS_TYPE_xcf 0xcf // 1, 00 |
| 157 | |
| 158 | struct mitsud90_fw_resp_single { |
| 159 | uint8_t version[6]; |
| 160 | uint16_t csum; |
| 161 | } __attribute__((packed)); |
| 162 | |
| 163 | struct mitsud90_media_resp { |
| 164 | uint8_t hdr[4]; /* e4 47 44 30 */ |
| 165 | struct { |
| 166 | uint8_t brand; |
| 167 | uint8_t type; |
| 168 | uint8_t unk_a[2]; |
| 169 | uint16_t capacity; /* BE */ |
| 170 | uint16_t remain; /* BE */ |
| 171 | uint8_t unk_b[2]; |
| 172 | } __attribute__((packed)) media; /* COM_STATUS_TYPE_MEDIA */ |
| 173 | } __attribute__((packed)); |
| 174 | |
| 175 | struct mitsud90_status_resp { |
| 176 | uint8_t hdr[4]; /* e4 47 44 30 */ |
| 177 | /* COM_STATUS_TYPE_ERROR */ |
| 178 | uint8_t code[2]; /* 00 is ok, nonzero is error */ |
| 179 | uint8_t unk[9]; |
| 180 | /* COM_STATUS_TYPE_MECHA */ |
| 181 | uint8_t mecha[2]; |
| 182 | /* COM_STATUS_TYPE_TEMP */ |
| 183 | uint8_t temp; |
| 184 | } __attribute__((packed)); |
| 185 | |
| 186 | struct mitsud90_info_resp { |
| 187 | uint8_t hdr[4]; /* e4 47 44 30 */ |
| 188 | uint8_t model[10]; |
| 189 | uint8_t x02; |
| 190 | struct mitsud90_fw_resp_single fw_vers[7]; |
| 191 | uint8_t x1e; |
| 192 | uint8_t x22[2]; |
| 193 | uint16_t jobid; |
| 194 | uint8_t inkid[8]; |
| 195 | uint8_t x2b[2]; |
| 196 | uint8_t x2c[2]; |
| 197 | uint8_t x65[50]; |
| 198 | uint8_t iserial; |
| 199 | uint8_t x83; |
| 200 | uint8_t x84; |
| 201 | } __attribute__((packed)); |
| 202 | |
| 203 | struct mitsud90_fwver_resp { |
| 204 | uint8_t hdr[4]; /* e4 47 44 30 */ |
| 205 | struct mitsud90_fw_resp_single fw_ver; |
| 206 | } __attribute((packed)); |
| 207 | |
| 208 | struct mitsum1_info_resp { |
| 209 | uint8_t hdr[4]; /* e4 47 44 30 */ |
| 210 | uint8_t model[10]; |
| 211 | uint8_t x02; |
| 212 | struct mitsud90_fw_resp_single fw_vers[8]; |
| 213 | uint8_t x1e; |
| 214 | uint8_t x22[2]; |
| 215 | uint16_t jobid; |
| 216 | uint8_t inkid[8]; |
| 217 | uint8_t x2b[2]; |
| 218 | uint8_t x2c[2]; |
| 219 | uint8_t x65[50]; |
| 220 | uint8_t x83; |
| 221 | } __attribute__((packed)); |
| 222 | |
| 223 | struct mitsuw5k_info_resp { |
| 224 | uint8_t hdr[4]; /* e4 47 44 30 */ |
| 225 | uint8_t model[5]; |
| 226 | uint8_t x02; |
| 227 | struct mitsud90_fw_resp_single fw_vers[7]; |
| 228 | uint8_t x1a; |
| 229 | uint8_t x1e; |
| 230 | uint8_t inkid[8]; |
| 231 | uint8_t x2b[8]; |
| 232 | uint8_t x2c[12]; |
| 233 | uint32_t cnt_head; |
| 234 | uint32_t cnt_service; |
| 235 | uint32_t cnt_printed; |
| 236 | uint32_t cnt_cutter; |
| 237 | uint32_t cnt_slitter; |
| 238 | #if 0 |
| 239 | uint32_t x40; |
| 240 | uint32_t x45; |
| 241 | uint8_t x65[54]; |
| 242 | uint8_t x83[2]; |
| 243 | uint8_t x84[2]; |
| 244 | #endif |
| 245 | } __attribute__((packed)); |
| 246 | |
| 247 | #define D90_MECHA_STATUS_IDLE 0x00 |
| 248 | #define W5K_MECHA_STATUS_PRINTING 0x20 |
| 249 | #define D90_MECHA_STATUS_PRINTING 0x50 |
| 250 | #define D90_MECHA_STATUS_INIT 0x80 |
| 251 | #define D90_MECHA_STATUS_INIT_FEEDCUT 0x10 |
| 252 | |
| 253 | #define D90_MECHA_STATUS_PRINT_FEEDING 0x10 // feeding ? |
| 254 | #define D90_MECHA_STATUS_PRINT_x20 0x20 // ?? |
| 255 | #define D90_MECHA_STATUS_PRINT_PRE_Y 0x21 // pre Y ? |
| 256 | #define D90_MECHA_STATUS_PRINT_Y 0x22 // Y ? |
| 257 | #define D90_MECHA_STATUS_PRINT_PRE_M 0x23 // pre M ? |
| 258 | #define D90_MECHA_STATUS_PRINT_M 0x24 // M ? |
| 259 | #define D90_MECHA_STATUS_PRINT_PRE_C 0x25 // pre C ? guess! |
| 260 | #define D90_MECHA_STATUS_PRINT_C 0x26 // C ? |
| 261 | #define D90_MECHA_STATUS_PRINT_PRE_OC 0x27 // pre OC ? guess! |
| 262 | #define D90_MECHA_STATUS_PRINT_OC 0x28 // O C? |
| 263 | #define D90_MECHA_STATUS_PRINT_x2f 0x2f // ?? |
| 264 | #define D90_MECHA_STATUS_PRINT_x38 0x38 // eject ? |
| 265 | |
| 266 | #define D90_ERROR_STATUS_OK 0x00 |
| 267 | #define D90_ERROR_STATUS_OK_WARMING 0x40 |
| 268 | #define D90_ERROR_STATUS_OK_COOLING 0x80 |
| 269 | #define D90_ERROR_STATUS_RIBBON 0x21 |
| 270 | #define D90_ERROR_STATUS_PAPER 0x22 |
| 271 | #define D90_ERROR_STATUS_PAP_RIB 0x23 |
| 272 | #define D90_ERROR_STATUS_OPEN 0x29 |
| 273 | |
| 274 | struct mitsud90_job_query { |
| 275 | uint8_t hdr[4]; /* 1b 47 44 31 */ |
| 276 | uint16_t jobid; /* BE */ |
| 277 | } __attribute__((packed)); |
| 278 | |
| 279 | struct mitsud90_job_resp { |
| 280 | uint8_t hdr[4]; /* e4 47 44 31 */ |
| 281 | uint8_t unk1; |
| 282 | uint8_t unk2; |
| 283 | uint16_t unk3; |
| 284 | } __attribute__((packed)); |
| 285 | |
| 286 | struct mitsud90_job_hdr { |
| 287 | uint8_t hdr[6]; /* 1b 53 50 30 00 ?? -- 03 on D90SL, 33 on rest */ |
| 288 | uint16_t cols; /* BE */ |
| 289 | uint16_t rows; /* BE */ |
| 290 | uint8_t waittime; /* 0-100 */ |
| 291 | uint8_t unk[3]; /* 00 00 01 */ // XXX 00 01 might be the jobid? |
| 292 | uint8_t margincut; /* 1 for enabled, 0 for disabled */ |
| 293 | uint8_t numcuts; /* # of cuts (0-3) but 0-8 legal */ |
| 294 | /*@0x10*/ |
| 295 | struct { |
| 296 | uint16_t position; // BE, @ center |
| 297 | uint8_t margincut; /* 0 for double cut, 1 for single */ |
| 298 | uint8_t zeropad; |
| 299 | } cutlist[8] __attribute__((packed)); /* 3 is current legal max */ |
| 300 | /*@x30*/uint8_t overcoat; /* 0 glossy, matte is 2 (D90) or 3 (M1) */ |
| 301 | uint8_t quality; /* 0 is automatic, 5 is "fast" on M1 */ |
| 302 | uint8_t colorcorr; /* Always 1 on M1 */ |
| 303 | uint8_t sharp_h; /* Always 0 on M1 */ |
| 304 | uint8_t sharp_v; /* Always 0 on M1 */ |
| 305 | uint8_t zero_b[5]; /* 0 on D90, on M1, zero_b[3] is the not-raw flag */ |
| 306 | struct { |
| 307 | /* @x3a */ uint8_t on; /* 0x01 when pano is on / always 0x02 on M1 / 0x03 on D90 panorama that needs backend processing */ |
| 308 | uint8_t zero_a; |
| 309 | uint8_t total; /* 2 or 3 */ |
| 310 | uint8_t page; /* 1, 2, 3 */ |
| 311 | uint16_t rows; /* always 0x097c (BE), ie 2428 ie 8" print */ |
| 312 | /* @x40 */ uint16_t rows2; /* Always 0x30 less than pano_rows */ |
| 313 | uint16_t zero_b; /* 0x0000 */ |
| 314 | uint16_t overlap; /* always 0x0258, ie 600 or 2 inches */ |
| 315 | uint8_t unk[4]; /* 00 0c 00 06 */ |
| 316 | } pano __attribute__((packed)); |
| 317 | uint8_t zero_c[5]; |
| 318 | uint8_t copies; /* EXTENSION */ |
| 319 | /*@x50*/uint8_t unk_m1; /* 00 on d90 & m1 Linux, 01 on m1 (windows) */ |
| 320 | uint8_t rgbrate; /* M1 only, see below */ |
| 321 | uint8_t oprate; /* M1 only, see below */ |
| 322 | uint8_t zero_fill[429]; |
| 323 | } __attribute__((packed)); |
| 324 | |
| 325 | struct mitsud90_plane_hdr { |
| 326 | uint8_t hdr[6]; /* 1b 5a 54 01 00 09 */ |
| 327 | uint16_t origin_cols; /* Leave at 0 */ |
| 328 | uint16_t origin_rows; /* Leave at 0 */ |
| 329 | uint16_t cols; /* BE */ |
| 330 | uint16_t rows; /* BE */ |
| 331 | uint8_t zero_a[6]; |
| 332 | uint16_t lamcols; /* BE (M1 only, OC=3) should be cols+origin_cols */ |
| 333 | uint16_t lamrows; /* BE (M1 only, OC=3) should be rows+origin_rows+12 */ |
| 334 | uint8_t zero_b[8]; |
| 335 | uint8_t unk_m1[8]; /* 07 e4 02 19 xx xx xx 00 always incrementing. timestamp? Only seen from win-generated jobs? */ |
| 336 | uint8_t zero_fill[472]; |
| 337 | } __attribute__((packed)); |
| 338 | |
| 339 | struct mitsud90_job_footer { |
| 340 | uint8_t hdr[4]; /* 1b 42 51 31 */ |
| 341 | uint16_t seconds; /* BE, 0x0005 by default (windows), 0x00ff means don't wait */ |
| 342 | } __attribute__((packed)); |
| 343 | |
| 344 | struct mitsud90_memcheck { |
| 345 | uint8_t hdr[6]; /* 1b 47 44 33 00 33 */ |
| 346 | uint16_t cols; /* BE */ |
| 347 | uint16_t rows; /* BE */ |
| 348 | uint8_t waittime; /* 0-100 */ |
| 349 | uint8_t unk[3]; /* 00 00 01 */ |
| 350 | uint8_t zero_fill[498]; |
| 351 | } __attribute__((packed)); |
| 352 | |
| 353 | struct mitsud90_memcheck_resp { |
| 354 | uint8_t hdr[4]; /* e4 47 44 43 */ |
| 355 | uint8_t size_bad; /* 0x00 is ok */ |
| 356 | uint8_t mem_bad; /* 0x00 is ok */ |
| 357 | } __attribute__((packed)); |
| 358 | |
| 359 | struct mitsuw5k_job_hdr { |
| 360 | uint8_t hdr[4]; // 1b 53 50 30 |
| 361 | uint16_t cols; |
| 362 | uint16_t rows; |
| 363 | uint8_t cuts; // 0-2 |
| 364 | uint16_t cut1; |
| 365 | uint16_t cut2; |
| 366 | uint8_t single; // 1:single page, 0:duplex |
| 367 | uint8_t finish; // 0:gloss, 1:semi-gloss 2:matte |
| 368 | uint8_t finishback; // 0:gloss, 1:semi-gloss, 2:matte, ff:none |
| 369 | uint8_t unk[2]; // XXX 01 00, 01 01, 01 02 seen on windows driver, latter two with duplex of some sort. 00 00 hardcoded with linux driver. |
| 370 | uint8_t colorconv; // 1: off, 0: internal |
| 371 | uint8_t sharp_H; // 0-8 or 0xff (ie printer) |
| 372 | uint8_t sharp_V; // 0-8 or 0xff (ie printer) |
| 373 | uint8_t copies; // EXTENSION |
| 374 | /*@22*/ uint8_t pad[512-22]; |
| 375 | } __attribute__((packed)); |
| 376 | |
| 377 | struct mitsuw5k_plane_hdr { |
| 378 | int8_t hdr[4]; // 1b 5a 54 01 |
| 379 | uint8_t zero[4]; |
| 380 | uint16_t cols; |
| 381 | uint16_t rows; |
| 382 | uint8_t zero2; |
| 383 | uint8_t printout; // 1 to start printing |
| 384 | uint8_t zero3; |
| 385 | /*@15*/ uint8_t pad[512-15]; |
| 386 | } __attribute__((packed)); |
| 387 | |
| 388 | struct mitsud90_generic_hdr { /* See GENERIC GET/SET below */ |
| 389 | uint8_t hdr[3]; /* 1b 61 36 */ |
| 390 | uint8_t getset; /* 36 get, 30 set */ |
| 391 | uint8_t type[2]; /* 41 be, 45 ba, etc */ |
| 392 | uint32_t len; /* Payload len, BE */ |
| 393 | uint8_t index[4]; /* 00 00 ?? ?? */ |
| 394 | uint8_t term1[4]; /* ff ff ?? ?? */ |
| 395 | uint8_t term2[4]; /* ff ff ?? ?? */ |
| 396 | } __attribute((packed)); |
| 397 | |
| 398 | struct mitsum1_errorlog_item { |
| 399 | uint8_t unk[256]; |
| 400 | /* Printer dumps: 0000000 0000 0000 0000000000 0000 00 */ |
| 401 | } __attribute((packed)); |
| 402 | |
| 403 | struct mitsum1_getinfo_resp { |
| 404 | struct mitsud90_generic_hdr hdr; /* @ 0 */ |
| 405 | uint32_t cnt_prints; /* @ 22 */ |
| 406 | uint32_t cnt_total; |
| 407 | uint32_t cnt_unka; // increased by 97 for a single 8" print |
| 408 | uint32_t cnt_cutter; |
| 409 | uint32_t cnt_unkb[25]; |
| 410 | uint8_t unk[1472-29*4]; /* @ 138 */ |
| 411 | struct mitsum1_errorlog_item items[20]; /* @1494 */ |
| 412 | /* End @6614 bytes */ |
| 413 | } __attribute((packed)); |
| 414 | |
| 415 | static const char *mitsud90_mecha_statuses(const uint8_t *code) |
| 416 | { |
| 417 | switch (code[0]) { |
| 418 | case D90_MECHA_STATUS_IDLE: |
| 419 | return "Idle"; |
| 420 | case W5K_MECHA_STATUS_PRINTING: |
| 421 | // codes seen: |
| 422 | // 22 30 31 32 33 34 35 37 38 <-- Side A? |
| 423 | // 42 50 51 52 53 55 57 58 <-- Side B? |
| 424 | // 60 <-- Finish? |
| 425 | return "Printing (Unknown)"; |
| 426 | case D90_MECHA_STATUS_PRINTING: |
| 427 | switch (code[1]) { |
| 428 | case D90_MECHA_STATUS_PRINT_FEEDING: |
| 429 | case D90_MECHA_STATUS_PRINT_x20: // XXX |
| 430 | return "Feeding Media"; |
| 431 | case D90_MECHA_STATUS_PRINT_PRE_Y: |
| 432 | case D90_MECHA_STATUS_PRINT_Y: |
| 433 | return "Printing Yellow"; |
| 434 | case D90_MECHA_STATUS_PRINT_PRE_M: |
| 435 | case D90_MECHA_STATUS_PRINT_M: |
| 436 | return "Printing Magenta"; |
| 437 | case D90_MECHA_STATUS_PRINT_PRE_C: |
| 438 | case D90_MECHA_STATUS_PRINT_C: |
| 439 | return "Printing Cyan"; |
| 440 | case D90_MECHA_STATUS_PRINT_PRE_OC: |
| 441 | case D90_MECHA_STATUS_PRINT_OC: |
| 442 | return "Applying Overcoat"; |
| 443 | case D90_MECHA_STATUS_PRINT_x2f: |
| 444 | case D90_MECHA_STATUS_PRINT_x38: |
| 445 | return "Ejecting Media?"; // XXX |
| 446 | default: |
| 447 | return "Printing (Unknown)"; |
| 448 | } |
| 449 | case D90_MECHA_STATUS_INIT: |
| 450 | if (code[1] == D90_MECHA_STATUS_INIT_FEEDCUT) |
| 451 | return "Feed & Cut paper"; |
| 452 | else |
| 453 | return "Initializing"; |
| 454 | default: |
| 455 | return "Unknown"; |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | static const char *mitsud90_error_codes(const uint8_t *code) |
| 460 | { |
| 461 | switch(code[0]) { |
| 462 | case D90_ERROR_STATUS_OK: |
| 463 | if (code[1] & D90_ERROR_STATUS_OK_WARMING) |
| 464 | return "Heating"; |
| 465 | else if (code[1] & D90_ERROR_STATUS_OK_COOLING) |
| 466 | return "Cooling Down"; |
| 467 | else |
| 468 | return "Idle"; |
| 469 | case D90_ERROR_STATUS_RIBBON: |
| 470 | switch (code[1]) { |
| 471 | case 0x00: |
| 472 | return "Ribbon exhausted"; |
| 473 | case 0x10: |
| 474 | return "Insufficient remaining ribbon"; |
| 475 | case 0x20: |
| 476 | return "Ribbon Cue Timeout"; |
| 477 | case 0x30: |
| 478 | return "Cannot Cue Ribbon"; |
| 479 | case 0x90: |
| 480 | return "No ribbon"; |
| 481 | default: |
| 482 | return "Unknown Ribbon Error"; |
| 483 | } |
| 484 | case D90_ERROR_STATUS_PAPER: |
| 485 | switch (code[1]) { |
| 486 | case 0x00: |
| 487 | return "No paper"; |
| 488 | case 0x02: |
| 489 | return "Paper exhausted"; |
| 490 | default: |
| 491 | return "Unknown Paper Error"; |
| 492 | } |
| 493 | case D90_ERROR_STATUS_PAP_RIB: |
| 494 | switch (code[1]) { |
| 495 | case 0x00: |
| 496 | return "Ribbon/Paper mismatch"; |
| 497 | case 0x90: |
| 498 | return "Ribbon/Job mismatch"; |
| 499 | default: |
| 500 | return "Unknown ribbon match error"; |
| 501 | } |
| 502 | case 0x26: |
| 503 | return "Illegal Ribbon"; |
| 504 | case 0x28: |
| 505 | return "Cut Bin Missing"; |
| 506 | case D90_ERROR_STATUS_OPEN: |
| 507 | switch (code[1]) { |
| 508 | case 0x00: |
| 509 | return "Printer Open during Stop"; |
| 510 | case 0x10: |
| 511 | return "Printer Open during Initialization"; |
| 512 | case 0x90: |
| 513 | return "Printer Open during Printing"; |
| 514 | default: |
| 515 | return "Unknown Door error"; |
| 516 | } |
| 517 | case 0x2f: |
| 518 | return "Printer turned off during printing"; |
| 519 | case 0x31: |
| 520 | return "Ink feed stop"; |
| 521 | case 0x32: |
| 522 | return "Ink Skip 1 timeout"; |
| 523 | case 0x33: |
| 524 | return "Ink Skip 2 timeout"; |
| 525 | case 0x34: |
| 526 | return "Ink Sticking"; |
| 527 | case 0x35: |
| 528 | return "Ink return stop"; |
| 529 | case 0x36: |
| 530 | return "Ink Rewind timeout"; |
| 531 | case 0x37: |
| 532 | return "Winding sensing error"; |
| 533 | case 0x40: |
| 534 | case 0x41: |
| 535 | case 0x42: |
| 536 | case 0x43: |
| 537 | case 0x44: |
| 538 | return "Paper Jam"; |
| 539 | case 0x60: |
| 540 | if (code[1] == 0x20) |
| 541 | return "Preheat error"; |
| 542 | else if (code[1] == 0x04) |
| 543 | return "Humidity sensor error"; |
| 544 | else if (code[1] & 0x1f) |
| 545 | return "Thermistor error"; |
| 546 | else |
| 547 | return "Unknown error"; |
| 548 | case 0x61: |
| 549 | if (code[1] == 0x00) |
| 550 | return "Color Sensor Error"; |
| 551 | else if (code[1] & 0x10) |
| 552 | return "Matte OP Error"; |
| 553 | else |
| 554 | return "Unknown error"; |
| 555 | case 0x62: |
| 556 | return "Data Transfer error"; |
| 557 | case 0x63: |
| 558 | return "EEPROM error"; |
| 559 | case 0x64: |
| 560 | return "Flash access error"; |
| 561 | case 0x65: |
| 562 | return "FPGA configuration error"; |
| 563 | case 0x66: |
| 564 | return "Power voltage Error"; |
| 565 | case 0x67: |
| 566 | return "RFID access error"; |
| 567 | case 0x68: |
| 568 | if (code[1] == 0x00) |
| 569 | return "Fan Lock Error"; |
| 570 | else if (code[1] == 0x90) |
| 571 | return "MDA Error"; |
| 572 | else |
| 573 | return "Unknown error"; |
| 574 | case 0x69: |
| 575 | if (code[1] == 0x10) |
| 576 | return "DDR Error"; |
| 577 | else if (code[1] == 0x00) |
| 578 | return "Firmware Error"; |
| 579 | else |
| 580 | return "Unknown error"; |
| 581 | case 0x70: |
| 582 | case 0x71: |
| 583 | case 0x73: |
| 584 | case 0x74: |
| 585 | case 0x75: |
| 586 | return "Mechanical Error (check ribbon and power cycle)"; |
| 587 | case 0x82: |
| 588 | return "USB Timeout"; |
| 589 | case 0x83: |
| 590 | return "Illegal paper size"; |
| 591 | case 0x84: |
| 592 | return "Illegal parameter"; |
| 593 | case 0x85: |
| 594 | return "Job Cancel"; |
| 595 | case 0x89: |
| 596 | return "Last Job Error"; |
| 597 | default: |
| 598 | return "Unknown"; |
| 599 | } |
| 600 | } |
| 601 | |
| 602 | static void mitsud90_dump_status(struct mitsud90_status_resp *resp) |
| 603 | { |
| 604 | INFO("Error Status: %s (%02x %02x) -- %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", |
| 605 | mitsud90_error_codes(resp->code), |
| 606 | resp->code[0], resp->code[1], |
| 607 | resp->unk[0], resp->unk[1], resp->unk[2], resp->unk[3], |
| 608 | resp->unk[4], resp->unk[5], resp->unk[6], resp->unk[7], |
| 609 | resp->unk[8]); |
| 610 | INFO("Printer Status: %s (%02x %02x)\n", |
| 611 | mitsud90_mecha_statuses(resp->mecha), |
| 612 | resp->mecha[0], resp->mecha[1]); |
| 613 | INFO("Temperature Status: %s\n", |
| 614 | mitsu_temperatures(resp->temp)); |
| 615 | } |
| 616 | |
| 617 | /* Private data structure */ |
| 618 | struct mitsud90_printjob { |
| 619 | struct dyesub_job_common common; |
| 620 | |
| 621 | uint8_t *databuf; |
| 622 | uint32_t datalen; |
| 623 | |
| 624 | int is_raw; |
| 625 | int is_pano; |
| 626 | int is_duplex; |
| 627 | |
| 628 | int m1_colormode; |
| 629 | |
| 630 | struct mitsud90_job_hdr hdr; |
| 631 | |
| 632 | int has_footer; |
| 633 | struct mitsud90_job_footer footer; |
| 634 | |
| 635 | int has_start; |
| 636 | }; |
| 637 | |
| 638 | struct mitsud90_ctx { |
| 639 | struct dyesub_connection *conn; |
| 640 | |
| 641 | struct marker marker; |
| 642 | |
| 643 | struct mitsud90_media_resp media; |
| 644 | char serno[9]; /* 8+null */ |
| 645 | char fwver_main[7]; /* 6+null */ |
| 646 | char fwver_mech[7]; /* 6+null */ |
| 647 | |
| 648 | /* Used in parsing.. */ |
| 649 | struct mitsud90_job_footer holdover; |
| 650 | int holdover_on; |
| 651 | int duplex_on; |
| 652 | int pano_page; |
| 653 | |
| 654 | /* For the CP-M1 family */ |
| 655 | struct mitsu_lib lib; |
| 656 | }; |
| 657 | |
| 658 | static int mitsud90_query_media(struct mitsud90_ctx *ctx, struct mitsud90_media_resp *resp) |
| 659 | { |
| 660 | uint8_t cmdbuf[8]; |
| 661 | uint8_t cmdlen = 0; |
| 662 | |
| 663 | int ret, num; |
| 664 | |
| 665 | cmdbuf[cmdlen++] = 0x1b; |
| 666 | cmdbuf[cmdlen++] = 0x47; |
| 667 | cmdbuf[cmdlen++] = 0x44; |
| 668 | cmdbuf[cmdlen++] = 0x30; |
| 669 | if (ctx->conn->type != P_MITSU_W5000) { |
| 670 | cmdbuf[cmdlen++] = 0; |
| 671 | cmdbuf[cmdlen++] = 0; |
| 672 | } |
| 673 | cmdbuf[cmdlen++] = 0x01; /* Number of commands */ |
| 674 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_MEDIA; |
| 675 | |
| 676 | if ((ret = send_data(ctx->conn, |
| 677 | cmdbuf, cmdlen))) |
| 678 | return ret; |
| 679 | memset(resp, 0, sizeof(*resp)); |
| 680 | |
| 681 | ret = read_data(ctx->conn, |
| 682 | (uint8_t*) resp, sizeof(*resp), &num); |
| 683 | |
| 684 | if (ret < 0) |
| 685 | return ret; |
| 686 | if (num != sizeof(*resp)) { |
| 687 | ERROR("Short Read! (%d/%d)\n", num, (int)sizeof(*resp)); |
| 688 | return 4; |
| 689 | } |
| 690 | |
| 691 | return CUPS_BACKEND_OK; |
| 692 | } |
| 693 | |
| 694 | static int mitsud90_query_status(struct mitsud90_ctx *ctx, struct mitsud90_status_resp *resp) |
| 695 | { |
| 696 | uint8_t cmdbuf[10]; |
| 697 | uint8_t cmdlen = 0; |
| 698 | int ret, num; |
| 699 | |
| 700 | cmdbuf[cmdlen++] = 0x1b; |
| 701 | cmdbuf[cmdlen++] = 0x47; |
| 702 | cmdbuf[cmdlen++] = 0x44; |
| 703 | cmdbuf[cmdlen++] = 0x30; |
| 704 | if (ctx->conn->type != P_MITSU_W5000) { |
| 705 | cmdbuf[cmdlen++] = 0; |
| 706 | cmdbuf[cmdlen++] = 0; |
| 707 | } |
| 708 | cmdbuf[cmdlen++] = 0x03; /* Number of commands */ |
| 709 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_ERROR; |
| 710 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_MECHA; |
| 711 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_TEMP; |
| 712 | |
| 713 | if ((ret = send_data(ctx->conn, |
| 714 | cmdbuf, cmdlen))) |
| 715 | return ret; |
| 716 | memset(resp, 0, sizeof(*resp)); |
| 717 | |
| 718 | ret = read_data(ctx->conn, |
| 719 | (uint8_t*) resp, sizeof(*resp), &num); |
| 720 | |
| 721 | if (ret < 0) |
| 722 | return ret; |
| 723 | if (num != sizeof(*resp)) { |
| 724 | ERROR("Short Read! (%d/%d)\n", num, (int)sizeof(*resp)); |
| 725 | return 4; |
| 726 | } |
| 727 | |
| 728 | return CUPS_BACKEND_OK; |
| 729 | } |
| 730 | |
| 731 | static int mitsud90_query_fwver(struct mitsud90_ctx *ctx) |
| 732 | { |
| 733 | uint8_t cmdbuf[8]; |
| 734 | uint8_t cmdlen = 0; |
| 735 | int ret, num; |
| 736 | struct mitsud90_fwver_resp resp; |
| 737 | |
| 738 | cmdbuf[cmdlen++] = 0x1b; |
| 739 | cmdbuf[cmdlen++] = 0x47; |
| 740 | cmdbuf[cmdlen++] = 0x44; |
| 741 | cmdbuf[cmdlen++] = 0x30; |
| 742 | if (ctx->conn->type != P_MITSU_W5000) { |
| 743 | cmdbuf[cmdlen++] = 0; |
| 744 | cmdbuf[cmdlen++] = 0; |
| 745 | } |
| 746 | cmdbuf[cmdlen++] = 1; /* Number of commands */ |
| 747 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_FW_MAIN; |
| 748 | |
| 749 | if ((ret = send_data(ctx->conn, |
| 750 | cmdbuf, cmdlen))) |
| 751 | return ret; |
| 752 | memset(&resp, 0, sizeof(resp)); |
| 753 | |
| 754 | ret = read_data(ctx->conn, |
| 755 | (uint8_t*) &resp, sizeof(resp), &num); |
| 756 | |
| 757 | if (ret) |
| 758 | return CUPS_BACKEND_FAILED; |
| 759 | |
| 760 | memcpy(ctx->fwver_main, resp.fw_ver.version, 6); |
| 761 | ctx->fwver_main[6] = 0; |
| 762 | |
| 763 | if (ctx->conn->type != P_MITSU_W5000) { |
| 764 | cmdbuf[cmdlen-1] = COM_STATUS_TYPE_FW_MECH; |
| 765 | |
| 766 | if ((ret = send_data(ctx->conn, |
| 767 | cmdbuf, cmdlen))) |
| 768 | return ret; |
| 769 | memset(&resp, 0, sizeof(resp)); |
| 770 | |
| 771 | ret = read_data(ctx->conn, |
| 772 | (uint8_t*) &resp, sizeof(resp), &num); |
| 773 | |
| 774 | if (ret) |
| 775 | return CUPS_BACKEND_FAILED; |
| 776 | |
| 777 | memcpy(ctx->fwver_mech, resp.fw_ver.version, 6); |
| 778 | ctx->fwver_mech[6] = 0; |
| 779 | } |
| 780 | |
| 781 | return CUPS_BACKEND_OK; |
| 782 | } |
| 783 | |
| 784 | static int mitsuw5k_get_serno(struct mitsud90_ctx *ctx) |
| 785 | { |
| 786 | uint8_t cmdbuf[12]; |
| 787 | uint8_t cmdlen = 0; |
| 788 | int ret, num; |
| 789 | struct mitsud90_fwver_resp resp; |
| 790 | |
| 791 | cmdbuf[cmdlen++] = 0x1b; |
| 792 | cmdbuf[cmdlen++] = 0x47; |
| 793 | cmdbuf[cmdlen++] = 0x44; |
| 794 | cmdbuf[cmdlen++] = 0x30; |
| 795 | cmdbuf[cmdlen++] = 1; /* Number of commands */ |
| 796 | cmdbuf[cmdlen++] = W5K_STATUS_TYPE_SERIAL; |
| 797 | |
| 798 | if ((ret = send_data(ctx->conn, |
| 799 | cmdbuf, cmdlen))) |
| 800 | return ret; |
| 801 | memset(&resp, 0, sizeof(resp)); |
| 802 | |
| 803 | ret = read_data(ctx->conn, |
| 804 | cmdbuf, sizeof(cmdbuf), &num); |
| 805 | |
| 806 | if (ret) |
| 807 | return CUPS_BACKEND_FAILED; |
| 808 | |
| 809 | memcpy(ctx->serno, cmdbuf + 4, sizeof(cmdbuf)-4); |
| 810 | ctx->serno[sizeof(cmdbuf)-4-1] = 0; |
| 811 | |
| 812 | return CUPS_BACKEND_OK; |
| 813 | } |
| 814 | |
| 815 | static int mitsud90_get_serno(struct mitsud90_ctx *ctx) |
| 816 | { |
| 817 | uint8_t cmdbuf[32]; |
| 818 | uint8_t cmdlen = 0; |
| 819 | int ret, num; |
| 820 | |
| 821 | /* Send Request */ |
| 822 | cmdbuf[cmdlen++] = 0x1b; |
| 823 | cmdbuf[cmdlen++] = 0x61; |
| 824 | cmdbuf[cmdlen++] = 0x36; |
| 825 | cmdbuf[cmdlen++] = 0x36; |
| 826 | cmdbuf[cmdlen++] = 0x41; |
| 827 | cmdbuf[cmdlen++] = 0xbe; |
| 828 | cmdbuf[cmdlen++] = 0x00; |
| 829 | cmdbuf[cmdlen++] = 0x00; |
| 830 | |
| 831 | cmdbuf[cmdlen++] = 0x00; |
| 832 | cmdbuf[cmdlen++] = 0x06; |
| 833 | cmdbuf[cmdlen++] = 0x00; |
| 834 | cmdbuf[cmdlen++] = 0x00; |
| 835 | cmdbuf[cmdlen++] = 0x00; |
| 836 | cmdbuf[cmdlen++] = 0x30; |
| 837 | cmdbuf[cmdlen++] = 0xff; |
| 838 | cmdbuf[cmdlen++] = 0xff; |
| 839 | |
| 840 | cmdbuf[cmdlen++] = 0xff; |
| 841 | cmdbuf[cmdlen++] = 0xf9; |
| 842 | cmdbuf[cmdlen++] = 0xff; |
| 843 | cmdbuf[cmdlen++] = 0xff; |
| 844 | cmdbuf[cmdlen++] = 0xff; |
| 845 | cmdbuf[cmdlen++] = 0xcf; |
| 846 | |
| 847 | if ((ret = send_data(ctx->conn, |
| 848 | cmdbuf, cmdlen))) |
| 849 | return ret; |
| 850 | |
| 851 | ret = read_data(ctx->conn, |
| 852 | cmdbuf, sizeof(cmdbuf), &num); |
| 853 | |
| 854 | /* Store it */ |
| 855 | memcpy(ctx->serno, &cmdbuf[22], 6); |
| 856 | ctx->serno[6] = 0; |
| 857 | |
| 858 | return ret; |
| 859 | } |
| 860 | |
| 861 | static int mitsud90_get_counter(struct mitsud90_ctx *ctx, uint8_t type, uint32_t *val) |
| 862 | { |
| 863 | uint8_t cmdbuf[32]; |
| 864 | uint8_t cmdlen = 0; |
| 865 | int ret, num; |
| 866 | |
| 867 | /* Send Request */ |
| 868 | cmdbuf[cmdlen++] = 0x1b; |
| 869 | cmdbuf[cmdlen++] = 0x61; |
| 870 | cmdbuf[cmdlen++] = 0x36; |
| 871 | cmdbuf[cmdlen++] = 0x36; |
| 872 | cmdbuf[cmdlen++] = 0x45; |
| 873 | cmdbuf[cmdlen++] = 0xba; |
| 874 | cmdbuf[cmdlen++] = 0x00; |
| 875 | cmdbuf[cmdlen++] = 0x00; |
| 876 | |
| 877 | cmdbuf[cmdlen++] = 0x00; |
| 878 | cmdbuf[cmdlen++] = 0x04; |
| 879 | cmdbuf[cmdlen++] = 0x00; |
| 880 | cmdbuf[cmdlen++] = 0x00; |
| 881 | cmdbuf[cmdlen++] = 0x06; |
| 882 | cmdbuf[cmdlen++] = type ? 0x44: 0x40; |
| 883 | cmdbuf[cmdlen++] = 0xff; |
| 884 | cmdbuf[cmdlen++] = 0xff; |
| 885 | |
| 886 | cmdbuf[cmdlen++] = 0xff; |
| 887 | cmdbuf[cmdlen++] = type ? 0xfb : 0xfe; |
| 888 | cmdbuf[cmdlen++] = 0xff; |
| 889 | cmdbuf[cmdlen++] = 0xff; |
| 890 | cmdbuf[cmdlen++] = 0xf9; |
| 891 | cmdbuf[cmdlen++] = type ? 0xbb: 0xbf; |
| 892 | |
| 893 | if ((ret = send_data(ctx->conn, |
| 894 | cmdbuf, cmdlen))) |
| 895 | return ret; |
| 896 | |
| 897 | ret = read_data(ctx->conn, |
| 898 | cmdbuf, sizeof(cmdbuf), &num); |
| 899 | |
| 900 | *val = le32_to_cpu(*((uint32_t*)&cmdbuf[22])); |
| 901 | |
| 902 | return ret; |
| 903 | } |
| 904 | |
| 905 | /* Generic functions */ |
| 906 | |
| 907 | static void *mitsud90_init(void) |
| 908 | { |
| 909 | struct mitsud90_ctx *ctx = malloc(sizeof(struct mitsud90_ctx)); |
| 910 | if (!ctx) { |
| 911 | ERROR("Memory Allocation Failure!\n"); |
| 912 | return NULL; |
| 913 | } |
| 914 | memset(ctx, 0, sizeof(struct mitsud90_ctx)); |
| 915 | |
| 916 | return ctx; |
| 917 | } |
| 918 | |
| 919 | static int mitsud90_attach(void *vctx, struct dyesub_connection *conn, uint8_t jobid) |
| 920 | { |
| 921 | struct mitsud90_ctx *ctx = vctx; |
| 922 | |
| 923 | UNUSED(jobid); |
| 924 | |
| 925 | ctx->conn = conn; |
| 926 | |
| 927 | if (test_mode < TEST_MODE_NOATTACH) { |
| 928 | if (mitsud90_query_media(ctx, &ctx->media)) |
| 929 | return CUPS_BACKEND_FAILED; |
| 930 | if (ctx->conn->type == P_MITSU_W5000) { |
| 931 | if (mitsuw5k_get_serno(ctx)) |
| 932 | return CUPS_BACKEND_FAILED; |
| 933 | } else { |
| 934 | if (mitsud90_get_serno(ctx)) |
| 935 | return CUPS_BACKEND_FAILED; |
| 936 | } |
| 937 | if (mitsud90_query_fwver(ctx)) |
| 938 | return CUPS_BACKEND_FAILED; |
| 939 | } else { |
| 940 | ctx->media.media.brand = 0xff; |
| 941 | ctx->media.media.type = 0x0f; |
| 942 | ctx->media.media.capacity = cpu_to_be16(230); |
| 943 | ctx->media.media.remain = cpu_to_be16(200); |
| 944 | ctx->fwver_main[0] = 0; |
| 945 | ctx->fwver_mech[0] = 0; |
| 946 | } |
| 947 | |
| 948 | ctx->marker.color = "#00FFFF#FF00FF#FFFF00"; |
| 949 | ctx->marker.numtype = ctx->media.media.type; |
| 950 | ctx->marker.name = mitsu_media_types(ctx->conn->type, ctx->media.media.brand, ctx->media.media.type); |
| 951 | ctx->marker.levelmax = be16_to_cpu(ctx->media.media.capacity); |
| 952 | ctx->marker.levelnow = be16_to_cpu(ctx->media.media.remain); |
| 953 | |
| 954 | if (ctx->conn->type == P_MITSU_M1 || |
| 955 | ctx->conn->type == P_FUJI_ASK500) { // || D90 & pano |
| 956 | #if defined(WITH_DYNAMIC) |
| 957 | /* Attempt to open the library */ |
| 958 | if (mitsu_loadlib(&ctx->lib, ctx->conn->type)) |
| 959 | #endif |
| 960 | WARNING("Dynamic library not loaded, will be unable to print.\n"); |
| 961 | } else if (ctx->conn->type == P_MITSU_D90) { |
| 962 | #if defined(WITH_DYNAMIC) |
| 963 | /* Attempt to open the library */ |
| 964 | if (mitsu_loadlib(&ctx->lib, ctx->conn->type)) |
| 965 | #endif |
| 966 | WARNING("Dynamic library not loaded, panorama printing may not work.\n"); |
| 967 | } |
| 968 | |
| 969 | if (ctx->conn->type == P_MITSU_M1) { |
| 970 | /* Known types: |
| 971 | CP-M1A/E v1.00 is 450B11 (ME is 454C11) |
| 972 | "" v?.?? is 450E11 (ME is 454E11) |
| 973 | "" v1.30 is 450F12 (ME is 454F11) |
| 974 | M15 v1.10 is 450C41 (ME is 454E11) |
| 975 | "" v1.20 is 450D42 (ME is 454F11) |
| 976 | */ |
| 977 | // XXX All CP-M1 variants appear to share same USB VID/PID. |
| 978 | // Unclear if any functional or runtime difference. |
| 979 | /* Compare MECHA firmware here since it's shared between M1A/M1E/M15 */ |
| 980 | if (strncmp(ctx->fwver_mech, "454F11", 6) < 0) |
| 981 | WARNING("Printer FW out of date. Highly recommeding updating M1A/M1E to v1.30 or newer, and M15 to v1.20 or newer\n"); |
| 982 | } else if (ctx->conn->type == P_MITSU_D90) { |
| 983 | // XXX figure out if printer can handle panorama! (FW "2.10" is needed) |
| 984 | // |
| 985 | // CP-D90DW v2.10 is 415A81/415G11 (revA/B) ME is 419E11 |
| 986 | // CP-D90DW-P v2.10 is 415B94/415E54 (revA/B) ME is 419E42 |
| 987 | // CP-D90DW-SL v3.10 is 415D71 ME is 419D61 |
| 988 | // D90DW-P and D90DW share same USB VID/PID. Unclear if any functional or runtime difference. |
| 989 | } else if (ctx->conn->type == P_FUJI_ASK500) { |
| 990 | // Completely unknown. |
| 991 | } else if (ctx->conn->type == P_MITSU_W5000) { |
| 992 | // W5000 MA:53C21S T:55A21@ F:369B21 |
| 993 | } |
| 994 | |
| 995 | return CUPS_BACKEND_OK; |
| 996 | } |
| 997 | |
| 998 | static void mitsud90_teardown(void *vctx) { |
| 999 | struct mitsud90_ctx *ctx = vctx; |
| 1000 | |
| 1001 | if (!ctx) |
| 1002 | return; |
| 1003 | |
| 1004 | if (ctx->pano_page) { |
| 1005 | WARNING("Panorama state left dangling!\n"); |
| 1006 | } |
| 1007 | |
| 1008 | if (ctx->conn->type == P_MITSU_M1 || |
| 1009 | ctx->conn->type == P_FUJI_ASK500) { |
| 1010 | mitsu_destroylib(&ctx->lib); |
| 1011 | } |
| 1012 | |
| 1013 | free(ctx); |
| 1014 | } |
| 1015 | |
| 1016 | static void mitsud90_cleanup_job(const void *vjob) |
| 1017 | { |
| 1018 | const struct mitsud90_printjob *job = vjob; |
| 1019 | |
| 1020 | if (job->databuf) |
| 1021 | free(job->databuf); |
| 1022 | |
| 1023 | free((void*)job); |
| 1024 | } |
| 1025 | |
| 1026 | /* Sanity check some stuff */ |
| 1027 | STATIC_ASSERT(sizeof(struct mitsud90_job_hdr) == 512); |
| 1028 | STATIC_ASSERT(sizeof(struct mitsud90_memcheck) == 512); |
| 1029 | STATIC_ASSERT(sizeof(struct mitsud90_plane_hdr) == 512); |
| 1030 | STATIC_ASSERT(sizeof(struct mitsuw5k_plane_hdr) == 512); |
| 1031 | STATIC_ASSERT(sizeof(struct mitsuw5k_job_hdr) == 512); |
| 1032 | STATIC_ASSERT(sizeof(struct mitsud90_generic_hdr) == 22); |
| 1033 | STATIC_ASSERT(sizeof(struct mitsum1_getinfo_resp) == 6614); |
| 1034 | |
| 1035 | static int mitsud90_main_loop(void *vctx, const void *vjob, int wait_for_return); |
| 1036 | |
| 1037 | static int mitsud90_panorama_splitjob(struct mitsud90_printjob *injob, struct mitsud90_printjob **newjobs) |
| 1038 | { |
| 1039 | uint8_t *panels[3] = { NULL, NULL, NULL }; |
| 1040 | uint16_t panel_rows[3] = { 0, 0, 0 }; |
| 1041 | uint16_t overlap_rows = 600; |
| 1042 | uint16_t pad_rows = 14; |
| 1043 | uint8_t numpanels; |
| 1044 | uint16_t cols; |
| 1045 | uint16_t inrows; |
| 1046 | uint16_t max_rows = 2428; /* 6x8" only */ |
| 1047 | |
| 1048 | cols = be16_to_cpu(injob->hdr.cols); |
| 1049 | inrows = be16_to_cpu(injob->hdr.rows); |
| 1050 | |
| 1051 | /* Work out parameters */ |
| 1052 | if (inrows == 6028) { |
| 1053 | numpanels = 3; |
| 1054 | } else if (inrows == 4228) { |
| 1055 | numpanels = 2; |
| 1056 | } else { |
| 1057 | ERROR("Invalid panorama row count (%d)\n", inrows); |
| 1058 | return CUPS_BACKEND_CANCEL; |
| 1059 | } |
| 1060 | |
| 1061 | /* Work out panel sizes... */ |
| 1062 | for (int src_rows = inrows - 2 * pad_rows, i = 0 ; src_rows > 0; ) { |
| 1063 | panel_rows[i] = (src_rows < max_rows) ? src_rows : max_rows - 2*pad_rows; |
| 1064 | src_rows -= panel_rows[i]; |
| 1065 | i++; |
| 1066 | |
| 1067 | if (i < numpanels) |
| 1068 | src_rows += overlap_rows; |
| 1069 | } |
| 1070 | |
| 1071 | /* Allocate and set up new jobs and buffers */ |
| 1072 | for (int i = 0 ; i < numpanels ; i++) { |
| 1073 | newjobs[i] = malloc(sizeof(struct mitsud90_printjob)); |
| 1074 | if (!newjobs[i]) { |
| 1075 | ERROR("Memory allocation failure"); |
| 1076 | return CUPS_BACKEND_RETRY_CURRENT; |
| 1077 | } |
| 1078 | panel_rows[i] += 2 * pad_rows; |
| 1079 | panels[i] = malloc((cols * panel_rows[i] * 3) + sizeof(struct mitsud90_plane_hdr)); |
| 1080 | if (!panels[i]) { |
| 1081 | ERROR("Memory allocation failure"); |
| 1082 | return CUPS_BACKEND_RETRY_CURRENT; |
| 1083 | } |
| 1084 | /* Fill in job header differences */ |
| 1085 | memcpy(newjobs[i], injob, sizeof(struct mitsud90_printjob)); |
| 1086 | newjobs[i]->databuf = panels[i]; |
| 1087 | newjobs[i]->hdr.rows = cpu_to_be16(panel_rows[i]); |
| 1088 | newjobs[i]->hdr.sharp_h = 0; // XXX do sharpening _before_ split |
| 1089 | newjobs[i]->hdr.sharp_v = 0; |
| 1090 | newjobs[i]->hdr.pano.on = 1; |
| 1091 | newjobs[i]->hdr.pano.total = numpanels; |
| 1092 | newjobs[i]->hdr.pano.page = i + 1; |
| 1093 | newjobs[i]->hdr.pano.rows = cpu_to_be16(panel_rows[i]); |
| 1094 | newjobs[i]->hdr.pano.rows2 = cpu_to_be16(panel_rows[i] - 0x30); |
| 1095 | newjobs[i]->hdr.pano.overlap = cpu_to_be16(overlap_rows); |
| 1096 | newjobs[i]->hdr.pano.unk[1] = 0x0c; |
| 1097 | newjobs[i]->hdr.pano.unk[3] = 0x06; |
| 1098 | newjobs[i]->has_footer = 0; |
| 1099 | panel_rows[i] -= 2 * pad_rows; |
| 1100 | |
| 1101 | /* Fill in plane header differences */ |
| 1102 | memcpy(newjobs[i]->databuf, injob->databuf, sizeof(struct mitsud90_plane_hdr)); |
| 1103 | struct mitsud90_plane_hdr *phdr = (struct mitsud90_plane_hdr*)panels[i]; |
| 1104 | phdr->rows = cpu_to_be16(panel_rows[i]); |
| 1105 | if (phdr->lamrows) |
| 1106 | phdr->lamrows = cpu_to_be16(panel_rows[i] + 12); |
| 1107 | panels[i] += sizeof(struct mitsud90_plane_hdr); |
| 1108 | } |
| 1109 | /* Last panel gets the footer, if any */ |
| 1110 | if (injob->has_footer) { |
| 1111 | newjobs[numpanels - 1]->has_footer = injob->has_footer; |
| 1112 | memcpy(&newjobs[numpanels-1]->footer, &injob->footer, sizeof(injob->footer)); |
| 1113 | } |
| 1114 | |
| 1115 | dyesub_pano_split_rgb8(injob->databuf, cols, numpanels, |
| 1116 | overlap_rows, pad_rows, |
| 1117 | panel_rows, panels); |
| 1118 | |
| 1119 | return CUPS_BACKEND_OK; |
| 1120 | } |
| 1121 | |
| 1122 | static int mitsud90_read_parse(void *vctx, const void **vjob, int data_fd, int copies) { |
| 1123 | struct mitsud90_ctx *ctx = vctx; |
| 1124 | int i, remain; |
| 1125 | |
| 1126 | struct mitsud90_printjob *job; |
| 1127 | |
| 1128 | if (!ctx) |
| 1129 | return CUPS_BACKEND_FAILED; |
| 1130 | |
| 1131 | job = malloc(sizeof(*job)); |
| 1132 | if (!job) { |
| 1133 | ERROR("Memory allocation failure!\n"); |
| 1134 | return CUPS_BACKEND_RETRY_CURRENT; |
| 1135 | } |
| 1136 | memset(job, 0, sizeof(*job)); |
| 1137 | job->common.jobsize = sizeof(*job); |
| 1138 | job->common.copies = copies; |
| 1139 | |
| 1140 | /* Read in header */ |
| 1141 | uint8_t *hptr = (uint8_t*) &job->hdr; |
| 1142 | uint16_t hremain = sizeof(struct mitsud90_job_hdr); |
| 1143 | |
| 1144 | /* Make sure there's no holdover */ |
| 1145 | if (ctx->holdover_on) { |
| 1146 | memcpy(hptr, &ctx->holdover, sizeof(ctx->holdover)); |
| 1147 | hremain -= sizeof(ctx->holdover); |
| 1148 | ctx->holdover_on = 0; |
| 1149 | } |
| 1150 | /* Read the rest */ |
| 1151 | while (hremain) { |
| 1152 | i = read(data_fd, hptr, hremain); |
| 1153 | if (i == 0) { |
| 1154 | mitsud90_cleanup_job(job); |
| 1155 | return CUPS_BACKEND_CANCEL; |
| 1156 | } |
| 1157 | if (i < 0) { |
| 1158 | mitsud90_cleanup_job(job); |
| 1159 | return CUPS_BACKEND_CANCEL; |
| 1160 | } |
| 1161 | hremain -= i; |
| 1162 | hptr += i; |
| 1163 | } |
| 1164 | |
| 1165 | /* Sanity check header */ |
| 1166 | if (job->hdr.hdr[0] != 0x1b || |
| 1167 | job->hdr.hdr[1] != 0x53 || |
| 1168 | job->hdr.hdr[2] != 0x50 || |
| 1169 | job->hdr.hdr[3] != 0x30 ) { |
| 1170 | ERROR("Unrecognized data format (%02x%02x%02x%02x)!\n", |
| 1171 | job->hdr.hdr[0], job->hdr.hdr[1], |
| 1172 | job->hdr.hdr[2], job->hdr.hdr[3]); |
| 1173 | mitsud90_cleanup_job(job); |
| 1174 | return CUPS_BACKEND_CANCEL; |
| 1175 | } |
| 1176 | |
| 1177 | /* Initial parsing */ |
| 1178 | if (ctx->conn->type == P_MITSU_M1 || |
| 1179 | ctx->conn->type == P_FUJI_ASK500) { |
| 1180 | /* See if it's a special gutenprint "not-raw" job */ |
| 1181 | job->is_raw = !job->hdr.zero_b[3]; |
| 1182 | job->hdr.zero_b[3] = 0; |
| 1183 | } else if (ctx->conn->type == P_MITSU_D90) { |
| 1184 | if (job->hdr.zero_b[3] && job->hdr.pano.on == 0x03) { |
| 1185 | job->is_pano = 1; |
| 1186 | job->hdr.zero_b[3] = 0; |
| 1187 | job->hdr.pano.on = 0; /* Will get inserted later */ |
| 1188 | } else if (be16_to_cpu(job->hdr.rows) > 2729) { |
| 1189 | job->is_pano = 1; |
| 1190 | job->hdr.pano.on = 0; |
| 1191 | } |
| 1192 | |
| 1193 | } else if (ctx->conn->type == P_MITSU_W5000) { |
| 1194 | struct mitsuw5k_job_hdr *hdr = (struct mitsuw5k_job_hdr*) &job->hdr; |
| 1195 | |
| 1196 | remain = be16_to_cpu(hdr->cols) * be16_to_cpu(hdr->rows) * 3; |
| 1197 | |
| 1198 | /* Add in the plane header */ |
| 1199 | remain += sizeof(struct mitsuw5k_plane_hdr); |
| 1200 | |
| 1201 | if (!hdr->single) |
| 1202 | job->is_duplex = 1; |
| 1203 | |
| 1204 | /* Note the job has an OPTIONAL start block. |
| 1205 | We check for that later */ |
| 1206 | |
| 1207 | job->common.copies = hdr->copies; |
| 1208 | hdr->copies = 0; |
| 1209 | |
| 1210 | /* Use larger of our copy counts */ |
| 1211 | if (job->common.copies < copies) |
| 1212 | job->common.copies = copies; |
| 1213 | |
| 1214 | goto read_data; |
| 1215 | } |
| 1216 | |
| 1217 | /* Sanity check panorama parameters */ |
| 1218 | if (job->hdr.pano.on && |
| 1219 | ctx->conn->type == P_MITSU_D90) { |
| 1220 | if ((job->hdr.pano.total < 2 && |
| 1221 | job->hdr.pano.total > 3) || |
| 1222 | (job->hdr.pano.page < 1 && |
| 1223 | job->hdr.pano.page > 3) || |
| 1224 | job->hdr.pano.page != (ctx->pano_page + 1) || |
| 1225 | (job->hdr.pano.rows != 2428) || |
| 1226 | be16_to_cpu(job->hdr.pano.rows2 != (2428-0x30)) || |
| 1227 | be16_to_cpu(job->hdr.pano.overlap != 600) |
| 1228 | ) { |
| 1229 | ERROR("Invalid panorama job parameters\n"); |
| 1230 | mitsud90_cleanup_job(job); |
| 1231 | return CUPS_BACKEND_CANCEL; |
| 1232 | } |
| 1233 | } |
| 1234 | |
| 1235 | /* Sanity check cutlist */ |
| 1236 | if (job->hdr.numcuts > 3) { |
| 1237 | ERROR("Cut list too long!\n"); |
| 1238 | mitsud90_cleanup_job(job); |
| 1239 | return CUPS_BACKEND_CANCEL; |
| 1240 | } |
| 1241 | if (job->hdr.numcuts >= 1) { |
| 1242 | int rows = be16_to_cpu(job->hdr.rows); |
| 1243 | for (i = 0 ; i < job->hdr.numcuts ; i++) { |
| 1244 | int min_size; |
| 1245 | int position = be16_to_cpu(job->hdr.cutlist[i].position); |
| 1246 | int last_position = (i == 0) ? 0 : be16_to_cpu(job->hdr.cutlist[i-1].position); |
| 1247 | |
| 1248 | if (i == 0) |
| 1249 | min_size = 613; |
| 1250 | else |
| 1251 | min_size = (job->hdr.cutlist[i-1].margincut) ? 601 : 660; // XXX inverted? |
| 1252 | |
| 1253 | if ((position - last_position) < min_size) { |
| 1254 | ERROR("Minumum cut#%d length is %d rows\n", i, min_size); |
| 1255 | mitsud90_cleanup_job(job); |
| 1256 | return CUPS_BACKEND_CANCEL; |
| 1257 | } |
| 1258 | if ((rows - position) < min_size) { |
| 1259 | ERROR("Cut#%d is too close to end\n", i); |
| 1260 | mitsud90_cleanup_job(job); |
| 1261 | return CUPS_BACKEND_CANCEL; |
| 1262 | } |
| 1263 | } |
| 1264 | } |
| 1265 | |
| 1266 | remain = be16_to_cpu(job->hdr.cols) * be16_to_cpu(job->hdr.rows) * 3; |
| 1267 | if (job->is_raw) |
| 1268 | remain *= 2; |
| 1269 | /* Add in the plane header */ |
| 1270 | remain += sizeof(struct mitsud90_plane_hdr); |
| 1271 | |
| 1272 | read_data: |
| 1273 | /* Allocate ourselves a payload buffer */ |
| 1274 | job->databuf = malloc(remain + 1024); |
| 1275 | if (!job->databuf) { |
| 1276 | ERROR("Memory allocation failure!\n"); |
| 1277 | mitsud90_cleanup_job(job); |
| 1278 | return CUPS_BACKEND_RETRY_CURRENT; |
| 1279 | } |
| 1280 | job->datalen = 0; |
| 1281 | |
| 1282 | /* Now read in the rest */ |
| 1283 | while(remain) { |
| 1284 | i = read(data_fd, job->databuf + job->datalen, remain); |
| 1285 | if (i == 0) { |
| 1286 | mitsud90_cleanup_job(job); |
| 1287 | return CUPS_BACKEND_CANCEL; |
| 1288 | } |
| 1289 | if (i < 0) { |
| 1290 | mitsud90_cleanup_job(job); |
| 1291 | return CUPS_BACKEND_CANCEL; |
| 1292 | } |
| 1293 | job->datalen += i; |
| 1294 | remain -= i; |
| 1295 | } |
| 1296 | |
| 1297 | /* Read in the footer. Hopefully... */ |
| 1298 | i = read(data_fd, (uint8_t*)&job->footer, sizeof(job->footer)); |
| 1299 | if (i == 0) { |
| 1300 | mitsud90_cleanup_job(job); |
| 1301 | return CUPS_BACKEND_CANCEL; |
| 1302 | } |
| 1303 | if (i < 0) { |
| 1304 | mitsud90_cleanup_job(job); |
| 1305 | return CUPS_BACKEND_CANCEL; |
| 1306 | } |
| 1307 | |
| 1308 | if (ctx->conn->type == P_MITSU_W5000) { |
| 1309 | if (job->footer.hdr[0] != 0x1b || |
| 1310 | job->footer.hdr[1] != 0x5a || |
| 1311 | job->footer.hdr[2] != 0x54 || |
| 1312 | job->footer.hdr[3] != 0x01) { |
| 1313 | memcpy(&ctx->holdover, &job->footer, sizeof(job->footer)); |
| 1314 | ctx->holdover_on = 1; |
| 1315 | } else { |
| 1316 | uint8_t tmpbuf[512]; |
| 1317 | job->has_start = 1; |
| 1318 | ctx->holdover_on = 0; |
| 1319 | |
| 1320 | /* read in remaining footer and discard */ |
| 1321 | remain = sizeof(tmpbuf)-sizeof(job->footer); |
| 1322 | while(remain) { |
| 1323 | i = read(data_fd, tmpbuf, remain); |
| 1324 | if (i == 0) { |
| 1325 | mitsud90_cleanup_job(job); |
| 1326 | return CUPS_BACKEND_CANCEL; |
| 1327 | } |
| 1328 | if (i < 0) { |
| 1329 | mitsud90_cleanup_job(job); |
| 1330 | return CUPS_BACKEND_CANCEL; |
| 1331 | } |
| 1332 | job->datalen += i; |
| 1333 | remain -= i; |
| 1334 | } |
| 1335 | } |
| 1336 | } else { |
| 1337 | /* See if this is a job footer. If it is, keep, else holdover. */ |
| 1338 | if (job->footer.hdr[0] != 0x1b || |
| 1339 | job->footer.hdr[1] != 0x42 || |
| 1340 | job->footer.hdr[2] != 0x51 || |
| 1341 | job->footer.hdr[3] != 0x31) { |
| 1342 | memcpy(&ctx->holdover, &job->footer, sizeof(job->footer)); |
| 1343 | ctx->holdover_on = 1; |
| 1344 | // XXX generate a footer! |
| 1345 | } else { |
| 1346 | job->has_footer = 1; |
| 1347 | ctx->holdover_on = 0; |
| 1348 | } |
| 1349 | } |
| 1350 | |
| 1351 | /* CP-M1 has... other considerations */ |
| 1352 | if (((ctx->conn->type == P_MITSU_M1 || |
| 1353 | ctx->conn->type == P_FUJI_ASK500) && !job->is_raw) || |
| 1354 | (ctx->conn->type == P_MITSU_D90 && job->is_pano)) { |
| 1355 | if (!ctx->lib.dl_handle) { |
| 1356 | ERROR("!!! Image Processing Library not found, aborting!\n"); |
| 1357 | mitsud90_cleanup_job(job); |
| 1358 | return CUPS_BACKEND_CANCEL; |
| 1359 | } |
| 1360 | |
| 1361 | job->m1_colormode = job->hdr.colorcorr; |
| 1362 | |
| 1363 | if (job->m1_colormode == 0) { |
| 1364 | const char *lutfname = NULL; |
| 1365 | |
| 1366 | if (ctx->conn->type == P_MITSU_M1) { |
| 1367 | lutfname = CPM1_LUT_FNAME; |
| 1368 | } |
| 1369 | if (ctx->conn->type == P_MITSU_D90) { |
| 1370 | lutfname = CPD90_LUT_FNAME; |
| 1371 | } |
| 1372 | |
| 1373 | /* NOTE: No LUT for ASK-500 yet */ |
| 1374 | if (lutfname) { |
| 1375 | int ret = mitsu_apply3dlut_packed(&ctx->lib, lutfname, |
| 1376 | job->databuf + sizeof(struct mitsud90_plane_hdr), |
| 1377 | be16_to_cpu(job->hdr.cols), |
| 1378 | be16_to_cpu(job->hdr.rows), |
| 1379 | be16_to_cpu(job->hdr.cols) * 3, COLORCONV_RGB); |
| 1380 | if (ret) { |
| 1381 | mitsud90_cleanup_job(job); |
| 1382 | return ret; |
| 1383 | } |
| 1384 | } |
| 1385 | } |
| 1386 | job->hdr.colorcorr = 1; // XXX not sure if right for ASK500? |
| 1387 | } |
| 1388 | |
| 1389 | job->common.copies = job->hdr.copies; |
| 1390 | |
| 1391 | /* Use larger of our copy counts */ |
| 1392 | if (job->common.copies < copies) |
| 1393 | job->common.copies = copies; |
| 1394 | |
| 1395 | /* Clear header to pristine shape */ |
| 1396 | job->hdr.copies = 0; |
| 1397 | |
| 1398 | if (job->is_pano) { |
| 1399 | int rval; |
| 1400 | |
| 1401 | // XXX do any print sharpening here! If possible.. |
| 1402 | rval = mitsud90_panorama_splitjob(job, (struct mitsud90_printjob**)vjob); |
| 1403 | /* Clean up original parsed job regardless */ |
| 1404 | mitsud90_cleanup_job(job); |
| 1405 | |
| 1406 | return rval; |
| 1407 | } else { |
| 1408 | *vjob = job; |
| 1409 | } |
| 1410 | |
| 1411 | return CUPS_BACKEND_OK; |
| 1412 | } |
| 1413 | |
| 1414 | static int cpm1_fillmatte(struct mitsud90_printjob *job) |
| 1415 | { |
| 1416 | int ret; |
| 1417 | int rows, cols; |
| 1418 | |
| 1419 | struct mitsud90_plane_hdr *phdr = (struct mitsud90_plane_hdr *) job->databuf; |
| 1420 | |
| 1421 | rows = be16_to_cpu(job->hdr.rows) + 12; |
| 1422 | cols = be16_to_cpu(job->hdr.cols); |
| 1423 | |
| 1424 | /* Fill in matte data */ |
| 1425 | ret = mitsu_readlamdata(CPM1_LAMINATE_FILE, CPM1_LAMINATE_STRIDE, |
| 1426 | job->databuf, &job->datalen, |
| 1427 | rows, cols, 1); |
| 1428 | |
| 1429 | if (ret) |
| 1430 | return ret; |
| 1431 | |
| 1432 | /* Update plane header and overall length */ |
| 1433 | phdr->lamcols = cpu_to_be16(cols); |
| 1434 | phdr->lamrows = cpu_to_be16(rows); |
| 1435 | |
| 1436 | return CUPS_BACKEND_OK; |
| 1437 | } |
| 1438 | |
| 1439 | static int mitsud90_main_loop(void *vctx, const void *vjob, int wait_for_return) { |
| 1440 | struct mitsud90_ctx *ctx = vctx; |
| 1441 | struct mitsud90_status_resp resp; |
| 1442 | uint8_t last_status[2] = {0xff, 0xff}; |
| 1443 | |
| 1444 | int sent; |
| 1445 | int ret; |
| 1446 | int copies; |
| 1447 | |
| 1448 | struct mitsud90_printjob *job = (struct mitsud90_printjob *)vjob; |
| 1449 | |
| 1450 | if (!ctx) |
| 1451 | return CUPS_BACKEND_FAILED; |
| 1452 | if (!job) |
| 1453 | return CUPS_BACKEND_FAILED; |
| 1454 | copies = job->common.copies; |
| 1455 | |
| 1456 | /* Handle panorama state */ |
| 1457 | if (ctx->conn->type == P_MITSU_D90) { |
| 1458 | if (job->hdr.pano.on) { |
| 1459 | ctx->pano_page++; |
| 1460 | if (job->hdr.pano.page != ctx->pano_page) { |
| 1461 | ERROR("Invalid panorama state (page %d of %d)\n", |
| 1462 | ctx->pano_page, job->hdr.pano.page); |
| 1463 | return CUPS_BACKEND_FAILED; |
| 1464 | } |
| 1465 | if (copies > 1) { |
| 1466 | WARNING("Cannot print non-collated copies of a panorama job\n"); |
| 1467 | copies = 1; |
| 1468 | } |
| 1469 | } else if (ctx->pano_page) { |
| 1470 | /* Clean up panorama state */ |
| 1471 | WARNING("Dangling panorama state!\n"); |
| 1472 | ctx->pano_page = 0; |
| 1473 | } |
| 1474 | } else { |
| 1475 | ctx->pano_page = 0; |
| 1476 | } |
| 1477 | |
| 1478 | if ((ctx->conn->type == P_MITSU_M1 || |
| 1479 | ctx->conn->type == P_FUJI_ASK500) && !job->is_raw) { |
| 1480 | struct BandImage input; |
| 1481 | struct BandImage output; |
| 1482 | struct M1CPCData *cpc; |
| 1483 | |
| 1484 | input.origin_rows = input.origin_cols = 0; |
| 1485 | input.rows = be16_to_cpu(job->hdr.rows); |
| 1486 | input.cols = be16_to_cpu(job->hdr.cols); |
| 1487 | input.imgbuf = job->databuf + sizeof(struct mitsud90_plane_hdr); |
| 1488 | input.bytes_per_row = input.cols * 3; |
| 1489 | |
| 1490 | /* Allocate new buffer, with extra room for header */ |
| 1491 | uint8_t *convbuf = malloc(input.rows * input.cols * sizeof(uint16_t) * 3 + (job->hdr.overcoat? (input.rows + 12) * input.cols + CPM1_LAMINATE_STRIDE / 2 : 0) + sizeof(struct mitsud90_plane_hdr)); |
| 1492 | if (!convbuf) { |
| 1493 | ERROR("Memory allocation Failure!\n"); |
| 1494 | return CUPS_BACKEND_RETRY_CURRENT; |
| 1495 | } |
| 1496 | |
| 1497 | output.origin_rows = output.origin_cols = 0; |
| 1498 | output.rows = input.rows; |
| 1499 | output.cols = input.cols; |
| 1500 | output.imgbuf = convbuf + sizeof(struct mitsud90_plane_hdr); |
| 1501 | output.bytes_per_row = output.cols * 3 * sizeof(uint16_t); |
| 1502 | |
| 1503 | /* Copy over the plane header */ |
| 1504 | memcpy(convbuf, job->databuf, sizeof(struct mitsud90_plane_hdr)); |
| 1505 | |
| 1506 | // Do CContrastConv prior to RGBRate |
| 1507 | job->hdr.rgbrate = ctx->lib.M1_CalcRGBRate(input.rows, |
| 1508 | input.cols, |
| 1509 | input.imgbuf); |
| 1510 | |
| 1511 | /* Color modes: 0 LUT, NOMATCH |
| 1512 | 1 NOLUT, MATCH <-- ie use with external ICC profile! |
| 1513 | 2 NOLUT, NOMATCH */ |
| 1514 | |
| 1515 | const char *gammatab; |
| 1516 | |
| 1517 | if (ctx->conn->type == P_FUJI_ASK500) { |
| 1518 | if (job->m1_colormode == 1) { |
| 1519 | gammatab = ASK5_CPC_G5_FNAME; |
| 1520 | } else { /* Mode 0 or 2 */ |
| 1521 | gammatab = ASK5_CPC_G1_FNAME; |
| 1522 | } |
| 1523 | cpc = ctx->lib.M1_GetCPCData(corrtable_path, ASK5_CPC_FNAME, gammatab); |
| 1524 | } else if (ctx->conn->type == P_MITSU_D90) { |
| 1525 | // XXX not used in this code path yet... |
| 1526 | // Note that these CSVs are actually BGR->YMC gamma! |
| 1527 | if (job->m1_colormode == 1) |
| 1528 | gammatab = CPD90_CPC_3_1_FNAME; |
| 1529 | else |
| 1530 | gammatab = CPD90_CPC_3_2_FNAME; |
| 1531 | cpc = ctx->lib.M1_GetCPCData(corrtable_path, CPD90_CPC_FNAME, gammatab); |
| 1532 | } else { |
| 1533 | if (job->m1_colormode == 1) { |
| 1534 | gammatab = CPM1_CPC_G5_FNAME; |
| 1535 | } else if (job->m1_colormode == 3) { |
| 1536 | gammatab = CPM1_CPC_G5_VIVID_FNAME; |
| 1537 | } else { /* Mode 0 or 2 */ |
| 1538 | gammatab = CPM1_CPC_G1_FNAME; |
| 1539 | } |
| 1540 | cpc = ctx->lib.M1_GetCPCData(corrtable_path, CPM1_CPC_FNAME, gammatab); |
| 1541 | } |
| 1542 | |
| 1543 | if (!cpc) { |
| 1544 | ERROR("Cannot read data tables\n"); |
| 1545 | free(convbuf); |
| 1546 | return CUPS_BACKEND_FAILED; |
| 1547 | } |
| 1548 | |
| 1549 | /* Do gamma conversion */ |
| 1550 | if (ctx->conn->type != P_MITSU_D90) |
| 1551 | ctx->lib.M1_Gamma8to14(cpc, &input, &output); |
| 1552 | |
| 1553 | if (job->hdr.sharp_h || job->hdr.sharp_v) { |
| 1554 | /* 0 is off, 1-7 corresponds to level 0-6 */ |
| 1555 | int sharp = ((job->hdr.sharp_h > job->hdr.sharp_v) ? job->hdr.sharp_h : job->hdr.sharp_v) - 1; |
| 1556 | job->hdr.sharp_h = 0; |
| 1557 | job->hdr.sharp_v = 0; |
| 1558 | |
| 1559 | /* And do the sharpening */ |
| 1560 | if (ctx->lib.M1_CLocalEnhancer(cpc, sharp, &output)) { |
| 1561 | ERROR("CLocalEnhancer failed (out of memory?)\n"); |
| 1562 | free(convbuf); |
| 1563 | ctx->lib.M1_DestroyCPCData(cpc); |
| 1564 | return CUPS_BACKEND_RETRY_CURRENT; |
| 1565 | } |
| 1566 | } |
| 1567 | |
| 1568 | /* We're done with the CPC data */ |
| 1569 | ctx->lib.M1_DestroyCPCData(cpc); |
| 1570 | |
| 1571 | #if (__BYTE_ORDER == __BIG_ENDIAN) |
| 1572 | /* Convert data to LITTLE ENDIAN if needed */ |
| 1573 | int i; |
| 1574 | uint16_t *ptr = output.imgbuf; |
| 1575 | for (i = 0; i < output.rows * output.cols ; i ++) { |
| 1576 | ptr[i] = cpu_to_le16(i); |
| 1577 | } |
| 1578 | #endif |
| 1579 | |
| 1580 | free(job->databuf); |
| 1581 | job->databuf = convbuf; |
| 1582 | job->datalen = sizeof(struct mitsud90_plane_hdr) + input.rows * input.cols * sizeof(uint16_t) * 3; |
| 1583 | |
| 1584 | /* Deal with lamination settings */ |
| 1585 | if (job->hdr.overcoat == 3) { |
| 1586 | int pre_matte_len = job->datalen; |
| 1587 | ret = cpm1_fillmatte(job); |
| 1588 | if (ret) { |
| 1589 | mitsud90_cleanup_job(job); |
| 1590 | return ret; |
| 1591 | } |
| 1592 | job->hdr.oprate = ctx->lib.M1_CalcOpRateMatte(output.rows, |
| 1593 | output.cols, |
| 1594 | job->databuf + pre_matte_len); |
| 1595 | } else { |
| 1596 | job->hdr.oprate = ctx->lib.M1_CalcOpRateGloss(output.rows, |
| 1597 | output.cols); |
| 1598 | } |
| 1599 | |
| 1600 | job->is_raw = 1; |
| 1601 | } |
| 1602 | |
| 1603 | /* Bypass */ |
| 1604 | if (test_mode >= TEST_MODE_NOPRINT) |
| 1605 | return CUPS_BACKEND_OK; |
| 1606 | |
| 1607 | INFO("Waiting for printer idle...\n"); |
| 1608 | |
| 1609 | top: |
| 1610 | sent = 0; |
| 1611 | |
| 1612 | // XXX Figure out if printer is asleep, and wake it up if necessary. |
| 1613 | |
| 1614 | /* Query status, wait for idle or error out */ |
| 1615 | do { |
| 1616 | if (mitsud90_query_status(ctx, &resp)) |
| 1617 | return CUPS_BACKEND_FAILED; |
| 1618 | |
| 1619 | if (resp.code[0] != D90_ERROR_STATUS_OK) { |
| 1620 | ERROR("Printer reported error condition: %s (%02x %02x)\n", |
| 1621 | mitsud90_error_codes(resp.code), resp.code[0], resp.code[1]); |
| 1622 | return CUPS_BACKEND_STOP; |
| 1623 | } |
| 1624 | |
| 1625 | if (resp.code[1] & D90_ERROR_STATUS_OK_WARMING || |
| 1626 | resp.temp & D90_ERROR_STATUS_OK_WARMING ) { |
| 1627 | INFO("Printer warming up\n"); |
| 1628 | sleep(1); |
| 1629 | continue; |
| 1630 | } |
| 1631 | if (resp.code[1] & D90_ERROR_STATUS_OK_COOLING || |
| 1632 | resp.temp & D90_ERROR_STATUS_OK_COOLING) { |
| 1633 | INFO("Printer cooling down\n"); |
| 1634 | sleep(1); |
| 1635 | continue; |
| 1636 | } |
| 1637 | |
| 1638 | if (resp.mecha[0] != last_status[0] || |
| 1639 | resp.mecha[1] != last_status[1]) { |
| 1640 | INFO("Printer status: %s\n", |
| 1641 | mitsud90_mecha_statuses(resp.mecha)); |
| 1642 | last_status[0] = resp.mecha[0]; |
| 1643 | last_status[1] = resp.mecha[1]; |
| 1644 | } |
| 1645 | |
| 1646 | /* Send memory check, but NOT on W5000 */ |
| 1647 | if (ctx->conn->type != P_MITSU_W5000) { |
| 1648 | struct mitsud90_memcheck mem; |
| 1649 | struct mitsud90_memcheck_resp mem_resp; |
| 1650 | int num; |
| 1651 | |
| 1652 | memcpy(&mem, &job->hdr, sizeof(mem)); |
| 1653 | mem.hdr[0] = 0x1b; |
| 1654 | mem.hdr[1] = 0x47; |
| 1655 | mem.hdr[2] = 0x44; |
| 1656 | mem.hdr[3] = 0x33; |
| 1657 | |
| 1658 | if ((ret = send_data(ctx->conn, |
| 1659 | (uint8_t*) &mem, sizeof(mem)))) |
| 1660 | return CUPS_BACKEND_FAILED; |
| 1661 | |
| 1662 | ret = read_data(ctx->conn, |
| 1663 | (uint8_t*)&mem_resp, sizeof(mem_resp), &num); |
| 1664 | |
| 1665 | if (ret < 0) |
| 1666 | return ret; |
| 1667 | if (num != sizeof(mem_resp)) { |
| 1668 | ERROR("Short Read! (%d/%d)\n", num, (int)sizeof(mem_resp)); |
| 1669 | return CUPS_BACKEND_FAILED; |
| 1670 | } |
| 1671 | if (mem_resp.size_bad || mem_resp.mem_bad == 0xff) { |
| 1672 | ERROR("Printer reported bad print params (%02x/%02x)\n", mem_resp.size_bad, mem_resp.mem_bad); |
| 1673 | return CUPS_BACKEND_CANCEL; |
| 1674 | } |
| 1675 | |
| 1676 | if (mem_resp.mem_bad) { |
| 1677 | ERROR("Printer buffers full, retrying!\n"); |
| 1678 | sleep(1); |
| 1679 | continue; |
| 1680 | } else { |
| 1681 | break; |
| 1682 | } |
| 1683 | } else if (resp.mecha[0] != D90_MECHA_STATUS_IDLE) { |
| 1684 | /* On W5K, just wait for printer to be idle */ |
| 1685 | sleep(1); |
| 1686 | continue; |
| 1687 | } else { |
| 1688 | break; |
| 1689 | } |
| 1690 | } while(1); |
| 1691 | |
| 1692 | /* Send job header */ |
| 1693 | if ((ret = send_data(ctx->conn, |
| 1694 | (uint8_t*) &job->hdr, sizeof(job->hdr)))) |
| 1695 | return CUPS_BACKEND_FAILED; |
| 1696 | |
| 1697 | /* Override code in plane command if needed */ |
| 1698 | if (ctx->conn->type == P_MITSU_D90 && |
| 1699 | ctx->conn->usb_pid == 0x3b62) { |
| 1700 | job->databuf[3] = 0x0f; |
| 1701 | } |
| 1702 | |
| 1703 | /* Send Plane header */ |
| 1704 | if ((ret = send_data(ctx->conn, |
| 1705 | job->databuf + sent, sizeof(job->hdr)))) |
| 1706 | return CUPS_BACKEND_FAILED; |
| 1707 | sent += sizeof(job->hdr); |
| 1708 | |
| 1709 | /* Send payload */ |
| 1710 | if ((ret = send_data(ctx->conn, |
| 1711 | job->databuf + sent, job->datalen - sent))) |
| 1712 | return CUPS_BACKEND_FAILED; |
| 1713 | // sent += (job->datalen - sent); |
| 1714 | |
| 1715 | if (ctx->conn->type == P_MITSU_W5000) { |
| 1716 | /* Duplex handling */ |
| 1717 | if (job->is_duplex) { |
| 1718 | ctx->duplex_on++; |
| 1719 | copies = 1; |
| 1720 | } |
| 1721 | |
| 1722 | if (ctx->duplex_on == 2) |
| 1723 | ctx->duplex_on = 0; |
| 1724 | |
| 1725 | if (!ctx->duplex_on || job->has_start) { |
| 1726 | /* Sent job START */ |
| 1727 | struct mitsuw5k_plane_hdr start = { |
| 1728 | .hdr = { 0x1b, 0x5a, 0x54, 0x01 }, |
| 1729 | .printout = 1 |
| 1730 | }; |
| 1731 | if ((ret = send_data(ctx->conn, |
| 1732 | (uint8_t*)&start, sizeof(start)))) |
| 1733 | return CUPS_BACKEND_FAILED; |
| 1734 | } else { |
| 1735 | goto skip_duplex; |
| 1736 | } |
| 1737 | } else if (job->has_footer) { |
| 1738 | if ((ret = send_data(ctx->conn, |
| 1739 | (uint8_t*) &job->footer, sizeof(job->footer)))) |
| 1740 | return CUPS_BACKEND_FAILED; |
| 1741 | |
| 1742 | /* Initiating printing means we're done parsing panorama */ |
| 1743 | if (ctx->pano_page) |
| 1744 | ctx->pano_page = 0; |
| 1745 | } |
| 1746 | |
| 1747 | /* Work out printer delay/countdown */ |
| 1748 | int countdown = (job->has_footer) ? be16_to_cpu(job->footer.seconds) : job->hdr.waittime; |
| 1749 | if (countdown >= 0xff) |
| 1750 | countdown = 0; |
| 1751 | |
| 1752 | /* If we're printing multiple copies, don't wait */ |
| 1753 | if (copies > 1) |
| 1754 | countdown = 0; |
| 1755 | |
| 1756 | /* If we're told to not bother waiting, don't? */ |
| 1757 | if (!wait_for_return) |
| 1758 | countdown = 0; |
| 1759 | |
| 1760 | // XXX Alternatively, don't wait if printer is not idle? |
| 1761 | // should we _ever_ wait? Since each "job" is currently standalone.. |
| 1762 | |
| 1763 | if (countdown) |
| 1764 | INFO("Job includes wait for %d seconds before starting\n", countdown); |
| 1765 | |
| 1766 | /* Wait for completion */ |
| 1767 | do { |
| 1768 | sleep(1); |
| 1769 | |
| 1770 | if (mitsud90_query_status(ctx, &resp)) |
| 1771 | return CUPS_BACKEND_FAILED; |
| 1772 | |
| 1773 | if (resp.code[0] != D90_ERROR_STATUS_OK) { |
| 1774 | ERROR("Printer reported error condition: %s (%02x %02x)\n", |
| 1775 | mitsud90_error_codes(resp.code), resp.code[0], resp.code[1]); |
| 1776 | return CUPS_BACKEND_STOP; |
| 1777 | } |
| 1778 | |
| 1779 | if (resp.mecha[0] != last_status[0] || |
| 1780 | resp.mecha[1] != last_status[1]) { |
| 1781 | INFO("Printer status: %s\n", |
| 1782 | mitsud90_mecha_statuses(resp.mecha)); |
| 1783 | last_status[0] = resp.mecha[0]; |
| 1784 | last_status[1] = resp.mecha[1]; |
| 1785 | } |
| 1786 | |
| 1787 | /* Terminate when printing complete */ |
| 1788 | if (resp.mecha[0] == D90_MECHA_STATUS_IDLE) { |
| 1789 | if (countdown-- <= 0) |
| 1790 | break; |
| 1791 | } |
| 1792 | |
| 1793 | if (!wait_for_return && copies <= 1) { /* Copies generated by backend? */ |
| 1794 | INFO("Fast return mode enabled.\n"); |
| 1795 | break; |
| 1796 | } |
| 1797 | } while(1); |
| 1798 | |
| 1799 | /* Clean up */ |
| 1800 | if (terminate) |
| 1801 | copies = 1; |
| 1802 | |
| 1803 | INFO("Print complete (%d copies remaining)\n", copies - 1); |
| 1804 | |
| 1805 | if (copies && --copies) { |
| 1806 | goto top; |
| 1807 | } |
| 1808 | |
| 1809 | skip_duplex: |
| 1810 | return CUPS_BACKEND_OK; |
| 1811 | } |
| 1812 | |
| 1813 | static int mitsud90_query_job(struct mitsud90_ctx *ctx, uint16_t jobid, |
| 1814 | struct mitsud90_job_resp *resp) |
| 1815 | { |
| 1816 | struct mitsud90_job_query req; |
| 1817 | int ret, num; |
| 1818 | |
| 1819 | // XXX does this work on W5000? |
| 1820 | req.hdr[0] = 0x1b; |
| 1821 | req.hdr[1] = 0x47; |
| 1822 | req.hdr[2] = 0x44; |
| 1823 | req.hdr[3] = 0x31; |
| 1824 | req.jobid = cpu_to_be16(jobid); |
| 1825 | |
| 1826 | if ((ret = send_data(ctx->conn, |
| 1827 | (uint8_t*) &req, sizeof(req)))) |
| 1828 | return ret; |
| 1829 | memset(resp, 0, sizeof(*resp)); |
| 1830 | ret = read_data(ctx->conn, |
| 1831 | (uint8_t*) resp, sizeof(*resp), &num); |
| 1832 | |
| 1833 | if (ret < 0) |
| 1834 | return ret; |
| 1835 | if (num != sizeof(*resp)) { |
| 1836 | ERROR("Short Read! (%d/%d)\n", num, (int)sizeof(*resp)); |
| 1837 | return 4; |
| 1838 | } |
| 1839 | |
| 1840 | return CUPS_BACKEND_OK; |
| 1841 | } |
| 1842 | |
| 1843 | static int mitsud90_get_jobstatus(struct mitsud90_ctx *ctx, uint16_t jobid) |
| 1844 | { |
| 1845 | struct mitsud90_job_resp resp; |
| 1846 | |
| 1847 | if (mitsud90_query_job(ctx, jobid, &resp)) |
| 1848 | return CUPS_BACKEND_FAILED; |
| 1849 | |
| 1850 | INFO("Job Status: %04x = %02x/%02x/%04x\n", |
| 1851 | jobid, resp.unk1, resp.unk2, be16_to_cpu(resp.unk3)); |
| 1852 | |
| 1853 | return CUPS_BACKEND_OK; |
| 1854 | } |
| 1855 | |
| 1856 | static int mitsud90_get_media(struct mitsud90_ctx *ctx) |
| 1857 | { |
| 1858 | if (mitsud90_query_media(ctx, &ctx->media)) |
| 1859 | return CUPS_BACKEND_FAILED; |
| 1860 | |
| 1861 | INFO("Media Type: %s (%02x/%02x)\n", |
| 1862 | mitsu_media_types(ctx->conn->type, ctx->media.media.brand, ctx->media.media.type), |
| 1863 | ctx->media.media.brand, |
| 1864 | ctx->media.media.type); |
| 1865 | INFO("Prints Remaining: %03d/%03d\n", |
| 1866 | be16_to_cpu(ctx->media.media.remain), |
| 1867 | be16_to_cpu(ctx->media.media.capacity)); |
| 1868 | |
| 1869 | return CUPS_BACKEND_OK; |
| 1870 | } |
| 1871 | |
| 1872 | static int mitsud90_get_status(struct mitsud90_ctx *ctx) |
| 1873 | { |
| 1874 | struct mitsud90_status_resp resp; |
| 1875 | |
| 1876 | if (mitsud90_query_status(ctx, &resp)) |
| 1877 | return CUPS_BACKEND_FAILED; |
| 1878 | |
| 1879 | mitsud90_dump_status(&resp); |
| 1880 | |
| 1881 | return CUPS_BACKEND_OK; |
| 1882 | } |
| 1883 | |
| 1884 | static int mitsud90_get_info(struct mitsud90_ctx *ctx) |
| 1885 | { |
| 1886 | uint8_t cmdbuf[26]; |
| 1887 | uint8_t cmdlen = 0; |
| 1888 | int ret, num; |
| 1889 | struct mitsud90_info_resp resp; |
| 1890 | |
| 1891 | cmdbuf[cmdlen++] = 0x1b; |
| 1892 | cmdbuf[cmdlen++] = 0x47; |
| 1893 | cmdbuf[cmdlen++] = 0x44; |
| 1894 | cmdbuf[cmdlen++] = 0x30; |
| 1895 | if (ctx->conn->type != P_MITSU_W5000) { |
| 1896 | cmdbuf[cmdlen++] = 0; |
| 1897 | cmdbuf[cmdlen++] = 0; |
| 1898 | } |
| 1899 | cmdbuf[cmdlen++] = 19; /* Number of commands */ |
| 1900 | |
| 1901 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_MODEL; |
| 1902 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_x02; |
| 1903 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_FW_LOADER; |
| 1904 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_FW_MAIN; |
| 1905 | |
| 1906 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_FW_FPGA; |
| 1907 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_FW_TBL; |
| 1908 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_FW_TAG; |
| 1909 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_FW_SATIN; |
| 1910 | |
| 1911 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_FW_MECH; |
| 1912 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_x1e; |
| 1913 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_x22; |
| 1914 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_JOBID; |
| 1915 | |
| 1916 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_INKID; |
| 1917 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_x2b; |
| 1918 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_x2c; |
| 1919 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_x65; |
| 1920 | |
| 1921 | cmdbuf[cmdlen++] = D90_STATUS_TYPE_ISEREN; |
| 1922 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_x83; |
| 1923 | cmdbuf[cmdlen++] = D90_STATUS_TYPE_x84; |
| 1924 | |
| 1925 | if ((ret = send_data(ctx->conn, |
| 1926 | cmdbuf, cmdlen))) |
| 1927 | return ret; |
| 1928 | memset(&resp, 0, sizeof(resp)); |
| 1929 | |
| 1930 | ret = read_data(ctx->conn, |
| 1931 | (uint8_t*) &resp, sizeof(resp), &num); |
| 1932 | |
| 1933 | if (ret < 0) |
| 1934 | return ret; |
| 1935 | if (num != sizeof(resp)) { |
| 1936 | ERROR("Short Read! (%d/%d)\n", num, (int)sizeof(resp)); |
| 1937 | return CUPS_BACKEND_FAILED; |
| 1938 | } |
| 1939 | |
| 1940 | /* start dumping output */ |
| 1941 | memset(cmdbuf, 0, sizeof(cmdbuf)); |
| 1942 | memcpy(cmdbuf, resp.model, sizeof(resp.model)); |
| 1943 | INFO("Model: %s\n", (char*)cmdbuf); |
| 1944 | INFO("Serial: %s\n", ctx->serno); |
| 1945 | for (num = 0; num < 7 ; num++) { |
| 1946 | memset(cmdbuf, 0, sizeof(cmdbuf)); |
| 1947 | memcpy(cmdbuf, resp.fw_vers[num].version, sizeof(resp.fw_vers[num].version)); |
| 1948 | INFO("FW Component %02d: %s (%04x)\n", |
| 1949 | num, cmdbuf, be16_to_cpu(resp.fw_vers[num].csum)); |
| 1950 | } |
| 1951 | INFO("TYPE_02: %02x\n", resp.x02); |
| 1952 | INFO("TYPE_1e: %02x\n", resp.x1e); |
| 1953 | INFO("TYPE_22: %02x %02x\n", resp.x22[0], resp.x22[1]); |
| 1954 | INFO("Job ID: %04x\n", be16_to_cpu(resp.jobid)); |
| 1955 | INFO("Ink ID: %02x %02x %02x %02x %02x %02x %02x %02x\n", |
| 1956 | resp.inkid[0], resp.inkid[1], resp.inkid[2], resp.inkid[3], |
| 1957 | resp.inkid[4], resp.inkid[5], resp.inkid[6], resp.inkid[7]); |
| 1958 | INFO("TYPE_2b: %02x %02x\n", resp.x2b[0], resp.x2b[1]); |
| 1959 | INFO("TYPE_2c: %02x %02x\n", resp.x2c[0], resp.x2c[1]); |
| 1960 | |
| 1961 | INFO("TYPE_65:"); |
| 1962 | for (num = 0; num < 50 ; num++) { |
| 1963 | DEBUG2(" %02x", resp.x65[num]); |
| 1964 | } |
| 1965 | DEBUG2("\n"); |
| 1966 | INFO("iSerial: %s\n", resp.iserial ? "Disabled" : "Enabled"); |
| 1967 | INFO("TYPE_83: %02x\n", resp.x83); |
| 1968 | INFO("TYPE_84: %02x\n", resp.x84); |
| 1969 | |
| 1970 | // XXX what about resume, wait time, "cut limit", sleep time ? |
| 1971 | |
| 1972 | return CUPS_BACKEND_OK; |
| 1973 | } |
| 1974 | |
| 1975 | static int mitsum1_getinfo_dump(struct mitsud90_ctx *ctx, struct mitsum1_getinfo_resp *resp) |
| 1976 | { |
| 1977 | struct mitsud90_generic_hdr hdr; |
| 1978 | |
| 1979 | int ret, num; |
| 1980 | |
| 1981 | hdr.hdr[0] = 0x1b; |
| 1982 | hdr.hdr[1] = 0x61; |
| 1983 | hdr.hdr[2] = 0x36; |
| 1984 | hdr.getset = 0x36; |
| 1985 | hdr.type[0] = 0x45; |
| 1986 | hdr.type[1] = 0xba; |
| 1987 | hdr.len = cpu_to_be32(0x19c0); |
| 1988 | hdr.index[0] = 0; |
| 1989 | hdr.index[1] = 0; |
| 1990 | hdr.index[2] = 0x06; |
| 1991 | hdr.index[3] = 0x40; |
| 1992 | hdr.term1[0] = 0xff; |
| 1993 | hdr.term1[1] = 0xff; |
| 1994 | hdr.term1[2] = 0xe6; |
| 1995 | hdr.term1[3] = 0x3f; |
| 1996 | hdr.term2[0] = 0xff; |
| 1997 | hdr.term2[1] = 0xff; |
| 1998 | hdr.term2[2] = 0xf9; |
| 1999 | hdr.term2[3] = 0xbf; |
| 2000 | |
| 2001 | if ((ret = send_data(ctx->conn, |
| 2002 | (uint8_t*)&hdr, sizeof(hdr)))) |
| 2003 | return ret; |
| 2004 | memset(resp, 0, sizeof(*resp)); |
| 2005 | |
| 2006 | ret = read_data(ctx->conn, |
| 2007 | (uint8_t*) resp, sizeof(*resp), &num); |
| 2008 | |
| 2009 | if (ret < 0) |
| 2010 | return ret; |
| 2011 | if (num != sizeof(*resp)) { |
| 2012 | ERROR("Short Read! (%d/%d)\n", num, (int)sizeof(*resp)); |
| 2013 | return CUPS_BACKEND_FAILED; |
| 2014 | } |
| 2015 | |
| 2016 | return CUPS_BACKEND_OK; |
| 2017 | } |
| 2018 | |
| 2019 | static int mitsuw5k_get_info(struct mitsud90_ctx *ctx, struct mitsuw5k_info_resp *resp) |
| 2020 | { |
| 2021 | uint8_t cmdbuf[32]; |
| 2022 | uint8_t cmdlen = 0; |
| 2023 | int ret, num; |
| 2024 | |
| 2025 | cmdbuf[cmdlen++] = 0x1b; |
| 2026 | cmdbuf[cmdlen++] = 0x47; |
| 2027 | cmdbuf[cmdlen++] = 0x44; |
| 2028 | cmdbuf[cmdlen++] = 0x30; |
| 2029 | if (ctx->conn->type != P_MITSU_W5000) { |
| 2030 | cmdbuf[cmdlen++] = 0; |
| 2031 | cmdbuf[cmdlen++] = 0; |
| 2032 | } |
| 2033 | cmdbuf[cmdlen++] = 19; /* Number of commands */ |
| 2034 | |
| 2035 | cmdbuf[cmdlen++] = W5K_STATUS_TYPE_MODEL; |
| 2036 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_x02; |
| 2037 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_FW_LOADER; |
| 2038 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_FW_MAIN; |
| 2039 | |
| 2040 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_FW_FPGA; |
| 2041 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_FW_TBL; |
| 2042 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_FW_TAG; |
| 2043 | cmdbuf[cmdlen++] = W5K_STATUS_TYPE_FW_LUT; |
| 2044 | |
| 2045 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_FW_SATIN; |
| 2046 | cmdbuf[cmdlen++] = W5K_STAUTS_TYPE_x1a; |
| 2047 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_x1e; |
| 2048 | |
| 2049 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_INKID; |
| 2050 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_x2b; |
| 2051 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_x2c; |
| 2052 | cmdbuf[cmdlen++] = W5K_STATUS_CNT_HEAD; |
| 2053 | |
| 2054 | cmdbuf[cmdlen++] = W5K_STATUS_CNT_SERVICE; |
| 2055 | cmdbuf[cmdlen++] = W5K_STATUS_CNT_PRINTED; |
| 2056 | cmdbuf[cmdlen++] = W5K_STATUS_CNT_CUTTER; |
| 2057 | cmdbuf[cmdlen++] = W5K_STATUS_CNT_SLITTER; |
| 2058 | |
| 2059 | #if 0 |
| 2060 | cmdbuf[cmdlen++] = W5K_STATUS_TYPE_x40; |
| 2061 | cmdbuf[cmdlen++] = W5K_STATUS_TYPE_x45; |
| 2062 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_x65; |
| 2063 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_x83; |
| 2064 | cmdbuf[cmdlen++] = D90_STATUS_TYPE_x84; |
| 2065 | #endif |
| 2066 | |
| 2067 | if ((ret = send_data(ctx->conn, |
| 2068 | cmdbuf, cmdlen))) |
| 2069 | return ret; |
| 2070 | memset(resp, 0, sizeof(*resp)); |
| 2071 | |
| 2072 | ret = read_data(ctx->conn, |
| 2073 | (uint8_t*) resp, sizeof(*resp), &num); |
| 2074 | |
| 2075 | if (ret < 0) |
| 2076 | return ret; |
| 2077 | if (num != sizeof(*resp)) { |
| 2078 | ERROR("Short Read! (%d/%d)\n", num, (int)sizeof(*resp)); |
| 2079 | return CUPS_BACKEND_FAILED; |
| 2080 | } |
| 2081 | |
| 2082 | return CUPS_BACKEND_OK; |
| 2083 | } |
| 2084 | |
| 2085 | static int mitsuw5k_dump_info(struct mitsud90_ctx *ctx, struct mitsuw5k_info_resp *resp) { |
| 2086 | uint8_t cmdbuf[26]; |
| 2087 | int num; |
| 2088 | |
| 2089 | /* start dumping output */ |
| 2090 | memset(cmdbuf, 0, sizeof(cmdbuf)); |
| 2091 | memcpy(cmdbuf, resp->model, sizeof(resp->model)); |
| 2092 | INFO("Model: %s\n", (char*)cmdbuf); |
| 2093 | INFO("Serial: %s\n", ctx->serno); |
| 2094 | for (num = 0; num < 7 ; num++) { |
| 2095 | memset(cmdbuf, 0, sizeof(cmdbuf)); |
| 2096 | memcpy(cmdbuf, resp->fw_vers[num].version, sizeof(resp->fw_vers[num].version)); |
| 2097 | INFO("FW Component %02d: %s (%04x)\n", |
| 2098 | num, cmdbuf, be16_to_cpu(resp->fw_vers[num].csum)); |
| 2099 | } |
| 2100 | INFO("TYPE_02: %02x\n", resp->x02); |
| 2101 | INFO("TYPE_1a: %02x\n", resp->x1a); |
| 2102 | INFO("TYPE_1e: %02x\n", resp->x1e); |
| 2103 | INFO("Ink ID: %02x %02x %02x %02x %02x %02x %02x %02x\n", |
| 2104 | resp->inkid[0], resp->inkid[1], resp->inkid[2], resp->inkid[3], |
| 2105 | resp->inkid[4], resp->inkid[5], resp->inkid[6], resp->inkid[7]); |
| 2106 | INFO("TYPE_2b: %02x %02x %02x %02x %02x %02x %02x %02x\n", |
| 2107 | resp->x2b[0], resp->x2b[1], resp->x2b[2], resp->x2b[3], |
| 2108 | resp->x2b[4], resp->x2b[5], resp->x2b[6], resp->x2b[7]); |
| 2109 | INFO("TYPE_2c: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", |
| 2110 | resp->x2c[0], resp->x2c[1], resp->x2c[2], resp->x2c[3], |
| 2111 | resp->x2c[4], resp->x2c[5], resp->x2c[6], resp->x2c[7], |
| 2112 | resp->x2c[8], resp->x2c[9], resp->x2c[10], resp->x2c[11]); |
| 2113 | |
| 2114 | INFO("Head Count: %u\n", be32_to_cpu(resp->cnt_head)); |
| 2115 | INFO("Service Count: %u\n", be32_to_cpu(resp->cnt_service)); |
| 2116 | INFO("Print Count: %u\n", be32_to_cpu(resp->cnt_printed)); |
| 2117 | INFO("Cutter Count: %u\n", be32_to_cpu(resp->cnt_cutter)); |
| 2118 | INFO("Slitter Count: %u\n", be32_to_cpu(resp->cnt_slitter)); |
| 2119 | |
| 2120 | #if 0 |
| 2121 | INFO("TYPE_40: %08x\n", be32_to_cpu(resp->x40)); |
| 2122 | INFO("TYPE_45: %08x\n", be32_to_cpu(resp->x45)); |
| 2123 | INFO("TYPE_65:"); |
| 2124 | for (num = 0; num < 54 ; num++) { |
| 2125 | DEBUG2(" %02x", resp->x65[num]); |
| 2126 | } |
| 2127 | DEBUG2("\n"); |
| 2128 | INFO("TYPE_83: %02x %02x\n", resp->x83[0], resp->x83[1]); |
| 2129 | INFO("TYPE_84: %02x %02x\n", resp->x84[1], resp->x84[2]); |
| 2130 | #endif |
| 2131 | |
| 2132 | // XXX what about resume, wait time, "cut limit", sleep time ? |
| 2133 | |
| 2134 | return CUPS_BACKEND_OK; |
| 2135 | } |
| 2136 | |
| 2137 | static int mitsum1_get_info(struct mitsud90_ctx *ctx) |
| 2138 | { |
| 2139 | uint8_t cmdbuf[25]; |
| 2140 | uint8_t cmdlen = 0; |
| 2141 | int ret, num; |
| 2142 | struct mitsum1_info_resp resp; |
| 2143 | |
| 2144 | cmdbuf[cmdlen++] = 0x1b; |
| 2145 | cmdbuf[cmdlen++] = 0x47; |
| 2146 | cmdbuf[cmdlen++] = 0x44; |
| 2147 | cmdbuf[cmdlen++] = 0x30; |
| 2148 | if (ctx->conn->type != P_MITSU_W5000) { |
| 2149 | cmdbuf[cmdlen++] = 0; |
| 2150 | cmdbuf[cmdlen++] = 0; |
| 2151 | } |
| 2152 | cmdbuf[cmdlen++] = 18; /* Number of commands */ |
| 2153 | |
| 2154 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_MODEL; |
| 2155 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_x02; |
| 2156 | cmdbuf[cmdlen++] = CM1_STATUS_TYPE_FW_0a; |
| 2157 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_FW_LOADER; |
| 2158 | |
| 2159 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_FW_MAIN; |
| 2160 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_FW_FPGA; |
| 2161 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_FW_TBL; |
| 2162 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_FW_TAG; |
| 2163 | |
| 2164 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_FW_SATIN; |
| 2165 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_FW_MECH; |
| 2166 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_x1e; |
| 2167 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_x22; |
| 2168 | |
| 2169 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_JOBID; |
| 2170 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_INKID; |
| 2171 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_x2b; |
| 2172 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_x2c; |
| 2173 | |
| 2174 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_x65; |
| 2175 | cmdbuf[cmdlen++] = COM_STATUS_TYPE_x83; |
| 2176 | |
| 2177 | if ((ret = send_data(ctx->conn, |
| 2178 | cmdbuf, cmdlen))) |
| 2179 | return ret; |
| 2180 | memset(&resp, 0, sizeof(resp)); |
| 2181 | |
| 2182 | ret = read_data(ctx->conn, |
| 2183 | (uint8_t*) &resp, sizeof(resp), &num); |
| 2184 | |
| 2185 | if (ret < 0) |
| 2186 | return ret; |
| 2187 | if (num != sizeof(resp)) { |
| 2188 | ERROR("Short Read! (%d/%d)\n", num, (int)sizeof(resp)); |
| 2189 | return 4; |
| 2190 | } |
| 2191 | |
| 2192 | /* start dumping output */ |
| 2193 | memset(cmdbuf, 0, sizeof(cmdbuf)); |
| 2194 | memcpy(cmdbuf, resp.model, sizeof(resp.model)); |
| 2195 | INFO("Model: %s\n", (char*)cmdbuf); |
| 2196 | INFO("Serial: %s\n", ctx->serno); |
| 2197 | for (num = 0; num < 8 ; num++) { |
| 2198 | memset(cmdbuf, 0, sizeof(cmdbuf)); |
| 2199 | memcpy(cmdbuf, resp.fw_vers[num].version, sizeof(resp.fw_vers[num].version)); |
| 2200 | INFO("FW Component %02d: %s (%04x)\n", |
| 2201 | num, cmdbuf, be16_to_cpu(resp.fw_vers[num].csum)); |
| 2202 | } |
| 2203 | INFO("TYPE_02: %02x\n", resp.x02); |
| 2204 | INFO("TYPE_1e: %02x\n", resp.x1e); |
| 2205 | INFO("TYPE_22: %02x %02x\n", resp.x22[0], resp.x22[1]); |
| 2206 | INFO("Job ID: %04x\n", be16_to_cpu(resp.jobid)); |
| 2207 | INFO("Ink ID: %02x %02x %02x %02x %02x %02x %02x %02x\n", |
| 2208 | resp.inkid[0], resp.inkid[1], resp.inkid[2], resp.inkid[3], |
| 2209 | resp.inkid[4], resp.inkid[5], resp.inkid[6], resp.inkid[7]); |
| 2210 | INFO("TYPE_2b: %02x %02x\n", resp.x2b[0], resp.x2b[1]); |
| 2211 | INFO("TYPE_2c: %02x %02x\n", resp.x2c[0], resp.x2c[1]); |
| 2212 | |
| 2213 | INFO("TYPE_65:"); |
| 2214 | for (num = 0; num < 50 ; num++) { |
| 2215 | DEBUG2(" %02x", resp.x65[num]); |
| 2216 | } |
| 2217 | DEBUG2("\n"); |
| 2218 | INFO("TYPE_83: %02x\n", resp.x83); |
| 2219 | |
| 2220 | // XXX what about resume, wait time, "cut limit", sleep time ? |
| 2221 | |
| 2222 | uint32_t cntr = 0; |
| 2223 | // mitsud90_get_counter(ctx, 0, &cntr); |
| 2224 | // INFO("Head Prints: %d\n", cntr); |
| 2225 | mitsud90_get_counter(ctx, 1, &cntr); |
| 2226 | INFO("Cutter count: %d\n", cntr); |
| 2227 | |
| 2228 | struct mitsum1_getinfo_resp resp2; |
| 2229 | mitsum1_getinfo_dump(ctx, &resp2); |
| 2230 | cntr = le32_to_cpu(resp2.cnt_prints); |
| 2231 | INFO("Head Prints: %d\n", cntr); |
| 2232 | |
| 2233 | return CUPS_BACKEND_OK; |
| 2234 | } |
| 2235 | |
| 2236 | static int mitsud90_dumpall(struct mitsud90_ctx *ctx) |
| 2237 | { |
| 2238 | int i; |
| 2239 | uint8_t cmdbuf[8]; |
| 2240 | uint8_t cmdlen = 0; |
| 2241 | uint8_t buf[256]; |
| 2242 | |
| 2243 | cmdbuf[cmdlen++] = 0x1b; |
| 2244 | cmdbuf[cmdlen++] = 0x47; |
| 2245 | cmdbuf[cmdlen++] = 0x44; |
| 2246 | cmdbuf[cmdlen++] = 0x30; |
| 2247 | if (ctx->conn->type != P_MITSU_W5000) { |
| 2248 | cmdbuf[cmdlen++] = 0; |
| 2249 | cmdbuf[cmdlen++] = 0; |
| 2250 | } |
| 2251 | cmdbuf[cmdlen++] = 1; /* Number of commands */ |
| 2252 | |
| 2253 | for (i = 0 ; i < 256 ; i++) { |
| 2254 | int num, ret; |
| 2255 | |
| 2256 | cmdbuf[cmdlen] = i; |
| 2257 | |
| 2258 | if ((ret = send_data(ctx->conn, |
| 2259 | cmdbuf, cmdlen + 1))) |
| 2260 | return ret; |
| 2261 | memset(buf, 0, sizeof(buf)); |
| 2262 | |
| 2263 | ret = read_data(ctx->conn, |
| 2264 | buf, sizeof(buf), &num); |
| 2265 | |
| 2266 | if (ret < 0) |
| 2267 | continue; |
| 2268 | |
| 2269 | if (num > 4) { |
| 2270 | DEBUG("TYPE %02x LEN: %d\n", i, num - 4); |
| 2271 | DEBUG("<--"); |
| 2272 | for (ret = 4; ret < num ; ret ++) { |
| 2273 | DEBUG2(" %02x", buf[ret]); |
| 2274 | } |
| 2275 | DEBUG2("\n"); |
| 2276 | } |
| 2277 | } |
| 2278 | |
| 2279 | return CUPS_BACKEND_OK; |
| 2280 | } |
| 2281 | |
| 2282 | static int mitsud90_test_print(struct mitsud90_ctx *ctx, int type) |
| 2283 | { |
| 2284 | uint8_t cmdbuf[16]; |
| 2285 | int ret, num = 0; |
| 2286 | uint8_t resp[256]; |
| 2287 | |
| 2288 | // XXX does this work on W5000? |
| 2289 | |
| 2290 | /* Send Test ON */ |
| 2291 | memset(cmdbuf, 0, 8); |
| 2292 | cmdbuf[0] = 0x1b; |
| 2293 | cmdbuf[1] = 0x76; |
| 2294 | cmdbuf[2] = 0x54; |
| 2295 | cmdbuf[3] = 0x45; |
| 2296 | cmdbuf[4] = 0x53; |
| 2297 | cmdbuf[5] = 0x54; |
| 2298 | cmdbuf[6] = 0x4f; |
| 2299 | cmdbuf[7] = 0x4e; |
| 2300 | if ((ret = send_data(ctx->conn, |
| 2301 | cmdbuf, 8))) |
| 2302 | return ret; |
| 2303 | |
| 2304 | memset(resp, 0, sizeof(resp)); |
| 2305 | |
| 2306 | ret = read_data(ctx->conn, |
| 2307 | resp, sizeof(resp), &num); // always e4 44 4f 4e 45 |
| 2308 | |
| 2309 | if (ret) return ret; |
| 2310 | |
| 2311 | /* Send Test print. */ |
| 2312 | memset(cmdbuf, 0x00, 16); |
| 2313 | cmdbuf[0] = 0x1b; |
| 2314 | cmdbuf[1] = 0x61; |
| 2315 | cmdbuf[2] = 0x36; |
| 2316 | cmdbuf[3] = 0x31; |
| 2317 | cmdbuf[7] = 0x02; |
| 2318 | |
| 2319 | switch(type) { |
| 2320 | default: |
| 2321 | case 0: /* Test Print */ |
| 2322 | cmdbuf[15] = 0x01; |
| 2323 | break; |
| 2324 | case 1: /* Solid Black */ |
| 2325 | cmdbuf[4] = 0x02; |
| 2326 | cmdbuf[9] = 0xFF; |
| 2327 | cmdbuf[15] = 0x01; |
| 2328 | break; |
| 2329 | case 2: /* Solid Gray */ |
| 2330 | cmdbuf[4] = 0x02; |
| 2331 | cmdbuf[9] = 0x80; |
| 2332 | cmdbuf[15] = 0x01; |
| 2333 | break; |
| 2334 | case 3: /* Head Pattern */ |
| 2335 | cmdbuf[4] = 0x01; |
| 2336 | cmdbuf[10] = 0x01; |
| 2337 | cmdbuf[15] = 0x01; |
| 2338 | break; |
| 2339 | case 4: /* Color Bar */ |
| 2340 | cmdbuf[4] = 0x04; |
| 2341 | cmdbuf[15] = 0x01; |
| 2342 | break; |
| 2343 | case 5: /* Vertical Alignment */ |
| 2344 | cmdbuf[4] = 0x02; |
| 2345 | cmdbuf[9] = 0x80; |
| 2346 | cmdbuf[15] = 0x02; |
| 2347 | break; |
| 2348 | case 6: /* Horizontal Alignment; Grey Cross */ |
| 2349 | cmdbuf[4] = 0x02; |
| 2350 | cmdbuf[9] = 0x80; |
| 2351 | cmdbuf[15] = 0x01; |
| 2352 | break; |
| 2353 | case 7: /* Solid Gray 1 */ |
| 2354 | cmdbuf[4] = 0x02; |
| 2355 | cmdbuf[9] = 0x80; |
| 2356 | cmdbuf[10] = 0x01; |
| 2357 | cmdbuf[15] = 0x01; |
| 2358 | break; |
| 2359 | case 8: /* Solid Gray 2 */ |
| 2360 | cmdbuf[4] = 0x02; |
| 2361 | cmdbuf[9] = 0x80; |
| 2362 | cmdbuf[10] = 0x02; |
| 2363 | cmdbuf[15] = 0x01; |
| 2364 | break; |
| 2365 | case 9: /* Solid Gray 3 */ |
| 2366 | cmdbuf[4] = 0x02; |
| 2367 | cmdbuf[9] = 0x80; |
| 2368 | cmdbuf[10] = 0x04; |
| 2369 | cmdbuf[15] = 0x01; |
| 2370 | break; |
| 2371 | } |
| 2372 | if ((ret = send_data(ctx->conn, |
| 2373 | cmdbuf, 16))) |
| 2374 | return ret; |
| 2375 | |
| 2376 | ret = read_data(ctx->conn, |
| 2377 | resp, sizeof(resp), &num); /* Get 5 back */ |
| 2378 | |
| 2379 | return ret; |
| 2380 | } |
| 2381 | |
| 2382 | static int mitsud90_query_serno(struct dyesub_connection *conn, char *buf, int buf_len) |
| 2383 | { |
| 2384 | struct mitsud90_ctx ctx = { |
| 2385 | .conn = conn, |
| 2386 | }; |
| 2387 | |
| 2388 | int ret; |
| 2389 | |
| 2390 | UNUSED(buf_len); |
| 2391 | |
| 2392 | if (conn->type == P_MITSU_W5000) |
| 2393 | ret = mitsuw5k_get_serno(&ctx); |
| 2394 | else |
| 2395 | ret = mitsud90_get_serno(&ctx); |
| 2396 | |
| 2397 | /* Copy it */ |
| 2398 | memcpy(buf, ctx.serno, sizeof(ctx.serno)); |
| 2399 | |
| 2400 | return ret; |
| 2401 | } |
| 2402 | static int mitsud90_set_iserial(struct mitsud90_ctx *ctx, uint8_t enabled) |
| 2403 | { |
| 2404 | uint8_t cmdbuf[23]; |
| 2405 | uint8_t cmdlen = 0; |
| 2406 | int ret, num; |
| 2407 | |
| 2408 | // XXX DOES NOT WORK ON W5K |
| 2409 | |
| 2410 | enabled = (enabled) ? 0: 0x80; |
| 2411 | |
| 2412 | /* Send Parameter.. */ |
| 2413 | cmdbuf[cmdlen++] = 0x1b; |
| 2414 | cmdbuf[cmdlen++] = 0x31; |
| 2415 | cmdbuf[cmdlen++] = 0x36; |
| 2416 | cmdbuf[cmdlen++] = 0x30; |
| 2417 | cmdbuf[cmdlen++] = 0x41; |
| 2418 | cmdbuf[cmdlen++] = 0xbe; |
| 2419 | cmdbuf[cmdlen++] = 0x00; |
| 2420 | cmdbuf[cmdlen++] = 0x00; |
| 2421 | |
| 2422 | cmdbuf[cmdlen++] = 0x00; |
| 2423 | cmdbuf[cmdlen++] = 0x01; |
| 2424 | cmdbuf[cmdlen++] = 0x00; |
| 2425 | cmdbuf[cmdlen++] = 0x00; |
| 2426 | cmdbuf[cmdlen++] = 0x00; |
| 2427 | cmdbuf[cmdlen++] = 0x11; |
| 2428 | cmdbuf[cmdlen++] = 0xff; |
| 2429 | cmdbuf[cmdlen++] = 0xff; |
| 2430 | |
| 2431 | cmdbuf[cmdlen++] = 0xff; |
| 2432 | cmdbuf[cmdlen++] = 0xfe; |
| 2433 | cmdbuf[cmdlen++] = 0xff; |
| 2434 | cmdbuf[cmdlen++] = 0xff; |
| 2435 | cmdbuf[cmdlen++] = 0xff; |
| 2436 | cmdbuf[cmdlen++] = 0xee; |
| 2437 | cmdbuf[cmdlen++] = enabled; |
| 2438 | |
| 2439 | if ((ret = send_data(ctx->conn, |
| 2440 | cmdbuf, cmdlen))) |
| 2441 | return ret; |
| 2442 | |
| 2443 | ret = read_data(ctx->conn, |
| 2444 | cmdbuf, sizeof(cmdbuf), &num); |
| 2445 | |
| 2446 | return ret; |
| 2447 | } |
| 2448 | |
| 2449 | static int mitsud90_set_sleeptime(struct mitsud90_ctx *ctx, uint16_t time) |
| 2450 | { |
| 2451 | uint8_t cmdbuf[24]; |
| 2452 | uint8_t cmdlen = 0; |
| 2453 | int ret; |
| 2454 | |
| 2455 | /* 255 minutes max, according to RE work */ |
| 2456 | if (time > 255) |
| 2457 | time = 255; |
| 2458 | |
| 2459 | // XXX does this work on W5000? |
| 2460 | |
| 2461 | /* Send Parameter.. */ |
| 2462 | cmdbuf[cmdlen++] = 0x1b; |
| 2463 | cmdbuf[cmdlen++] = 0x31; |
| 2464 | cmdbuf[cmdlen++] = 0x36; |
| 2465 | cmdbuf[cmdlen++] = 0x30; |
| 2466 | cmdbuf[cmdlen++] = 0x41; |
| 2467 | cmdbuf[cmdlen++] = 0xbe; |
| 2468 | cmdbuf[cmdlen++] = 0x00; |
| 2469 | cmdbuf[cmdlen++] = 0x00; |
| 2470 | |
| 2471 | cmdbuf[cmdlen++] = 0x00; |
| 2472 | cmdbuf[cmdlen++] = 0x02; |
| 2473 | cmdbuf[cmdlen++] = 0x00; |
| 2474 | cmdbuf[cmdlen++] = 0x00; |
| 2475 | cmdbuf[cmdlen++] = 0x05; |
| 2476 | cmdbuf[cmdlen++] = 0x02; |
| 2477 | cmdbuf[cmdlen++] = 0xff; |
| 2478 | cmdbuf[cmdlen++] = 0xff; |
| 2479 | |
| 2480 | cmdbuf[cmdlen++] = 0xff; |
| 2481 | cmdbuf[cmdlen++] = 0xfd; |
| 2482 | cmdbuf[cmdlen++] = 0xff; |
| 2483 | cmdbuf[cmdlen++] = 0xff; |
| 2484 | cmdbuf[cmdlen++] = 0xfa; |
| 2485 | cmdbuf[cmdlen++] = 0xff; |
| 2486 | cmdbuf[cmdlen++] = (time >> 8) & 0xff; |
| 2487 | cmdbuf[cmdlen++] = time & 0xff; |
| 2488 | |
| 2489 | if ((ret = send_data(ctx->conn, |
| 2490 | cmdbuf, cmdlen))) |
| 2491 | return ret; |
| 2492 | |
| 2493 | /* No response */ |
| 2494 | |
| 2495 | return CUPS_BACKEND_OK; |
| 2496 | } |
| 2497 | |
| 2498 | static void mitsud90_cmdline(void) |
| 2499 | { |
| 2500 | DEBUG("\t\t[ -i ] # Query printer info\n"); |
| 2501 | DEBUG("\t\t[ -j jobid ] # Query job status\n"); |
| 2502 | DEBUG("\t\t[ -k time ] # Set sleep time in minutes\n"); |
| 2503 | DEBUG("\t\t[ -m ] # Query printer media\n"); |
| 2504 | DEBUG("\t\t[ -s ] # Query printer status\n"); |
| 2505 | DEBUG("\t\t[ -x 0|1 ] # Enable/disable iSerial reporting (D90 only)\n"); |
| 2506 | // DEBUG("\t\t[ -T 0-9 ] # Test print\n"); |
| 2507 | // DEBUG("\t\t[ -Z ] # Dump all parameters\n"); |
| 2508 | } |
| 2509 | |
| 2510 | static int mitsud90_cmdline_arg(void *vctx, int argc, char **argv) |
| 2511 | { |
| 2512 | struct mitsud90_ctx *ctx = vctx; |
| 2513 | int i, j = 0; |
| 2514 | |
| 2515 | if (!ctx) |
| 2516 | return -1; |
| 2517 | |
| 2518 | while ((i = getopt(argc, argv, GETOPT_LIST_GLOBAL "ij:k:msT:x:Z")) >= 0) { |
| 2519 | switch(i) { |
| 2520 | GETOPT_PROCESS_GLOBAL |
| 2521 | case 'i': |
| 2522 | switch (ctx->conn->type) { |
| 2523 | case P_MITSU_M1: |
| 2524 | j = mitsum1_get_info(ctx); |
| 2525 | break; |
| 2526 | case P_MITSU_W5000: { |
| 2527 | struct mitsuw5k_info_resp resp; |
| 2528 | j = mitsuw5k_get_info(ctx, &resp); |
| 2529 | if (!j) |
| 2530 | mitsuw5k_dump_info(ctx, &resp); |
| 2531 | break; |
| 2532 | } |
| 2533 | case P_MITSU_D90: |
| 2534 | default: |
| 2535 | j = mitsud90_get_info(ctx); |
| 2536 | break; |
| 2537 | } |
| 2538 | break; |
| 2539 | case 'j': |
| 2540 | j = mitsud90_get_jobstatus(ctx, atoi(optarg)); |
| 2541 | break; |
| 2542 | case 'k': |
| 2543 | j = mitsud90_set_sleeptime(ctx, atoi(optarg)); |
| 2544 | break; |
| 2545 | case 'm': |
| 2546 | j = mitsud90_get_media(ctx); |
| 2547 | break; |
| 2548 | case 's': |
| 2549 | j = mitsud90_get_status(ctx); |
| 2550 | break; |
| 2551 | case 'T': |
| 2552 | j = mitsud90_test_print(ctx, atoi(optarg)); |
| 2553 | break; |
| 2554 | case 'x': |
| 2555 | if (ctx->conn->type == P_MITSU_D90) |
| 2556 | j = mitsud90_set_iserial(ctx, atoi(optarg)); |
| 2557 | break; |
| 2558 | case 'Z': |
| 2559 | j = mitsud90_dumpall(ctx); |
| 2560 | break; |
| 2561 | default: |
| 2562 | break; /* Ignore completely */ |
| 2563 | } |
| 2564 | |
| 2565 | if (j) return j; |
| 2566 | } |
| 2567 | |
| 2568 | return CUPS_BACKEND_OK; |
| 2569 | } |
| 2570 | |
| 2571 | static int mitsud90_query_markers(void *vctx, struct marker **markers, int *count) |
| 2572 | { |
| 2573 | struct mitsud90_ctx *ctx = vctx; |
| 2574 | |
| 2575 | if (markers) *markers = &ctx->marker; |
| 2576 | if (count) *count = 1; |
| 2577 | |
| 2578 | if (mitsud90_query_media(ctx, &ctx->media)) |
| 2579 | return CUPS_BACKEND_FAILED; |
| 2580 | |
| 2581 | ctx->marker.levelnow = be16_to_cpu(ctx->media.media.remain); |
| 2582 | |
| 2583 | return CUPS_BACKEND_OK; |
| 2584 | } |
| 2585 | |
| 2586 | static int mitsud90_query_stats(void *vctx, struct printerstats *stats) |
| 2587 | { |
| 2588 | struct mitsud90_ctx *ctx = vctx; |
| 2589 | struct mitsud90_status_resp resp; |
| 2590 | |
| 2591 | if (mitsud90_query_markers(ctx, NULL, NULL)) |
| 2592 | return CUPS_BACKEND_FAILED; |
| 2593 | if (mitsud90_query_status(ctx, &resp)) |
| 2594 | return CUPS_BACKEND_FAILED; |
| 2595 | |
| 2596 | switch (ctx->conn->type) { |
| 2597 | case P_MITSU_D90: |
| 2598 | stats->mfg = "Mitsubishi"; |
| 2599 | stats->model = "CP-D90 family"; |
| 2600 | break; |
| 2601 | case P_MITSU_M1: |
| 2602 | stats->mfg = "Mitsubishi"; |
| 2603 | stats->model = "CP-M1 family"; |
| 2604 | break; |
| 2605 | case P_MITSU_W5000: |
| 2606 | stats->mfg = "Mitsubishi"; |
| 2607 | stats->model = "CP-W5000 family"; |
| 2608 | break; |
| 2609 | case P_FUJI_ASK500: |
| 2610 | stats->mfg = "Fujifilm"; |
| 2611 | stats->model = "AK500"; |
| 2612 | break; |
| 2613 | default: |
| 2614 | stats->model = "Unknown!"; |
| 2615 | stats->mfg = "Unknown!"; |
| 2616 | break; |
| 2617 | } |
| 2618 | |
| 2619 | switch (ctx->conn->type) { |
| 2620 | case P_MITSU_W5000: { |
| 2621 | struct mitsuw5k_info_resp resp2; |
| 2622 | mitsuw5k_get_info(ctx, &resp2); |
| 2623 | stats->cnt_life[0] = be32_to_cpu(resp2.cnt_printed); |
| 2624 | break; |
| 2625 | } |
| 2626 | case P_MITSU_M1: |
| 2627 | case P_FUJI_ASK500: { |
| 2628 | struct mitsum1_getinfo_resp resp2; |
| 2629 | mitsum1_getinfo_dump(ctx, &resp2); |
| 2630 | stats->cnt_life[0] = le32_to_cpu(resp2.cnt_prints); |
| 2631 | } |
| 2632 | default: |
| 2633 | // XXX should work for D90 |
| 2634 | // uint32_t head = 0; |
| 2635 | // mitsud90_get_counter(ctx, 0, &head); |
| 2636 | // stats->cnt_life[0] = head; |
| 2637 | break; |
| 2638 | } |
| 2639 | |
| 2640 | stats->serial = ctx->serno; |
| 2641 | stats->fwver = ctx->fwver_main; |
| 2642 | |
| 2643 | stats->decks = 1; |
| 2644 | |
| 2645 | stats->name[0] = "Roll"; |
| 2646 | if (resp.code[0] != D90_ERROR_STATUS_OK) |
| 2647 | stats->status[0] = strdup(mitsud90_error_codes(resp.code)); |
| 2648 | else if (resp.code[1] & D90_ERROR_STATUS_OK_WARMING || |
| 2649 | resp.temp & D90_ERROR_STATUS_OK_WARMING) |
| 2650 | stats->status[0] = strdup("Warming up"); |
| 2651 | else if (resp.code[1] & D90_ERROR_STATUS_OK_COOLING || |
| 2652 | resp.temp & D90_ERROR_STATUS_OK_COOLING) |
| 2653 | stats->status[0] = strdup("Cooling down"); |
| 2654 | else |
| 2655 | stats->status[0] = strdup(mitsud90_mecha_statuses(resp.mecha)); |
| 2656 | |
| 2657 | stats->mediatype[0] = ctx->marker.name; |
| 2658 | stats->levelmax[0] = ctx->marker.levelmax; |
| 2659 | stats->levelnow[0] = ctx->marker.levelnow; |
| 2660 | |
| 2661 | return CUPS_BACKEND_OK; |
| 2662 | } |
| 2663 | |
| 2664 | static const char *mitsud90_prefixes[] = { |
| 2665 | "mitsud90", /* Family Name */ |
| 2666 | NULL |
| 2667 | }; |
| 2668 | |
| 2669 | static const struct device_id mitsud90_devices[] = { |
| 2670 | { 0x06d3, 0x3b60, P_MITSU_D90, NULL, "mitsubishi-d90dw"}, |
| 2671 | { 0x06d3, 0x3b62, P_MITSU_D90, NULL, "mitsubishi-d90dwsl"}, |
| 2672 | { 0x06d3, 0x3b80, P_MITSU_M1, NULL, "mitsubishi-cpm1"}, |
| 2673 | { 0x06d3, 0x3b80, P_MITSU_M1, NULL, "mitsubishi-cpm15"}, // Duplicate for the M15 |
| 2674 | { 0x06d3, 0x3b50, P_MITSU_W5000, NULL, "mitsubishi-cpw5000"}, |
| 2675 | // { 0x04cb, 0x1234, P_FUJI_ASK500, NULL, "fujifilm-ask500"}, |
| 2676 | { 0, 0, 0, NULL, NULL} |
| 2677 | }; |
| 2678 | |
| 2679 | /* Exported */ |
| 2680 | const struct dyesub_backend mitsud90_backend = { |
| 2681 | .name = "Mitsubishi CP-D90/CP-M1/CP-W5000", |
| 2682 | .version = "0.58" " (lib " LIBMITSU_VER ")", |
| 2683 | .flags = BACKEND_FLAG_DUMMYPRINT, |
| 2684 | .uri_prefixes = mitsud90_prefixes, |
| 2685 | .devices = mitsud90_devices, |
| 2686 | .cmdline_arg = mitsud90_cmdline_arg, |
| 2687 | .cmdline_usage = mitsud90_cmdline, |
| 2688 | .init = mitsud90_init, |
| 2689 | .attach = mitsud90_attach, |
| 2690 | .teardown = mitsud90_teardown, |
| 2691 | .cleanup_job = mitsud90_cleanup_job, |
| 2692 | .read_parse = mitsud90_read_parse, |
| 2693 | .main_loop = mitsud90_main_loop, |
| 2694 | .query_serno = mitsud90_query_serno, |
| 2695 | .query_markers = mitsud90_query_markers, |
| 2696 | .query_stats = mitsud90_query_stats, |
| 2697 | }; |
| 2698 | |
| 2699 | /* ToDo: |
| 2700 | |
| 2701 | * consolidate M1 vs D90 vs W5000 info query/dump more efficiently? |
| 2702 | * better job control (job id, active job, etc?) |
| 2703 | * Print counters on M1 and D90 (need to validate the D90 in particular) |
| 2704 | * sleep and waking up |
| 2705 | * cut limits? |
| 2706 | * Validate Fujifilm ASK500 support & spool format (likely moot now) |
| 2707 | * Validate Panorama mode on D90 |
| 2708 | * W5000 validate media type vs loaded LUT, if possible? |
| 2709 | Non-HG media: |
| 2710 | e0 07 00 00 00 eb e8 de bd / 18 a1 (00192 061 / 15962 078) LUT SLTAX270 |
| 2711 | HG media: |
| 2712 | ??? LUT SLTA7180 |
| 2713 | * Job combining (esp for W5000; M1 too maybe?) |
| 2714 | |
| 2715 | */ |
| 2716 | |
| 2717 | /* |
| 2718 | Mitsubishi CP-D90DW data format |
| 2719 | |
| 2720 | All multi-byte values are BIG endian |
| 2721 | |
| 2722 | [[ PAGE HEADER ]] |
| 2723 | |
| 2724 | 1b 53 50 30 00 33 XX XX YY YY TT 00 00 01 MM NN XX XX == COLS, YY XX ROWS (BE) |
| 2725 | ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? 00 00 00 00 NN == num of cuts, ?? see below |
| 2726 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 MM == 0 for no margin cut, 1 for margin cut |
| 2727 | QQ RR SS HH VV 00 00 00 00 00 ZZ 00 JJ II 09 7c QQ == 02 matte (D90) or 03 (M1), 00 glossy, |
| 2728 | 09 4c 00 00 02 58 00 0c 00 06 00 00 00 00 00 00 RR == 00 auto, (D90: 03 == fine, 02 == superfine), (M1: 05 == Fast) |
| 2729 | Z0 Z1 Z2 00 00 00 00 00 00 00 00 00 00 00 00 00 SS == 00 colorcorr, 01 == none (01 on M1 or D90 if LUT done in driver) |
| 2730 | HH/VV sharpening for Horiz/Vert, 0-8, 0 is off, 4 is normal (always 00 on M1) |
| 2731 | TT is waittime (100 max, always 100 on D90) |
| 2732 | ZZ is 0x02 on M1, D90 see PANORAMA |
| 2733 | Z0 is 0x01 (M1 windows) (00 Linux and d90 UNK!) |
| 2734 | Z1 is RGB Rate (M1) |
| 2735 | Z2 is OP Rate (M1) |
| 2736 | |
| 2737 | [pad to 512b] |
| 2738 | |
| 2739 | normal == rows 00 00 00 00 00 00 00 00 00 |
| 2740 | 4x6div2 == 1226 01 02 65 01 00 00 00 00 00 |
| 2741 | 8x6div2 == 2488 01 04 be 00 00 00 00 00 00 |
| 2742 | |
| 2743 | guesses based on SDK docs: |
| 2744 | |
| 2745 | 9x6div2 == 2728 01 05 36 01 00 00 00 00 00 00 00 00 00 |
| 2746 | 9x6div3 == 2724 02 03 90 01 00 07 14 00 00 00 00 00 00 |
| 2747 | 9x6div4 == 2628 03 02 97 01 00 05 22 00 00 07 ad 00 00 |
| 2748 | |
| 2749 | PANORAMA [ZZ 00 JJ II] onwards, only shows in 8x20" PANORAMA prints. Assume 2" overlap. |
| 2750 | ZZ == 00 (normal) or 01 (panorama) |
| 2751 | JJ == 02 03 (num of panorama panels) |
| 2752 | II == 01 02 03 (which panel # in panorama!) |
| 2753 | [02 58] == 600, aka 2" * 300dpi? |
| 2754 | [09 4c] == 2380 (48 less than 8 size? (trim length on ends?) |
| 2755 | [09 7c] == 2428 (ie 8" print) |
| 2756 | |
| 2757 | (6x20 == 1852x6036) |
| 2758 | (6x14 == 1852x4232) |
| 2759 | |
| 2760 | 3*8" panels == 2428*3=7284. -6036 = 1248. /2 = 624 (0x270) |
| 2761 | |
| 2762 | [[ DATA PLANE HEADER ]] |
| 2763 | |
| 2764 | 1b 5a 54 XX 00 09 00 00 00 00 CC CC RR RR 00 00 |
| 2765 | 00 00 00 00 LC LC LR LR |
| 2766 | ... |
| 2767 | [pad to 512b] |
| 2768 | |
| 2769 | CC CC cols (BE) |
| 2770 | RR RR rows (BE) |
| 2771 | LC LC lamination columns (BE, M1 only, same as cols) |
| 2772 | LR LR lamination rows (BE, M1 only, rows + 12d ) |
| 2773 | XX is 0x0f for D90SL, 0x01 for everything else |
| 2774 | |
| 2775 | D90 family: |
| 2776 | data is *RGB* packed, @ 8bpp. No padding to 512b! |
| 2777 | M1 family: |
| 2778 | data is *RGB* packed, @16bpp, LITTLE ENDIAN. No padding to 512b! |
| 2779 | optional matte data is 8bpp, follows immediately. |
| 2780 | |
| 2781 | [[FOOTER]] |
| 2782 | |
| 2783 | 1b 42 51 31 00 TT ## TT == secs to wait for second print, 0xff disables? |
| 2784 | |
| 2785 | **************************************************** |
| 2786 | |
| 2787 | Comms Protocol for D90, CP-M1, and CP-W5000 families |
| 2788 | |
| 2789 | [[ STATUS QUERIES ]] |
| 2790 | |
| 2791 | -> 1b 47 44 30 00 00 XX [ A1, A2, A3, ... ] ** D90 & M1 |
| 2792 | -> 1b 47 44 30 XX [ A1, A2, A3, ... ] ** W5000 |
| 2793 | <- e4 47 44 30 [ R1, R2, R3, ... ] |
| 2794 | |
| 2795 | XX is the number of items to query. Each item has a unique code and a |
| 2796 | fixed response length. item's repsonse is concatenated onto the response. |
| 2797 | |
| 2798 | For item codes and responses, see *_STATUS_TYPE_* definitions above. |
| 2799 | |
| 2800 | [[ GENERIC GET/SET ]] |
| 2801 | |
| 2802 | -> 1b 61 36 QQ T1 T2 LL LL QQ == 0x30 (set) 0x36 (get) |
| 2803 | LL LL 00 00 VV VV ff ff LL == length (32-bit BE) |
| 2804 | M1 M1 ff ff M2 M2 T1 = type1 (41, 45, others?) |
| 2805 | <- e4 61 36 QQ TT TT 00 00 T2 = type2 (be, ba, 00, others?) |
| 2806 | LL LL 00 00 VV VV ff ff VV VV = index/variable? |
| 2807 | M1 M1 ff ff M2 M2 ?? ?? ?? == data (length LL) |
| 2808 | |
| 2809 | ----------------------------------------------- |
| 2810 | T1 T2 LL LL VV VV M1 M1 M2 M2 Meaning |
| 2811 | |
| 2812 | 41 be 00 01 00 10 ff fe ff ef 34v Adjustment (0x00->0xff) |
| 2813 | 41 be 00 01 00 11 ff fe ff ee USB iSerial on/off (0x80 off, 0x00 on, D90 only?) |
| 2814 | 41 be 00 06 00 30 ff f9 ff cf Ascii serial number |
| 2815 | 45 00 00 01 05 05 ff fe fa f8 Wait time (seconds) |
| 2816 | 45 ba 00 06 06 00 ff f9 fc ff M1 motor current (6 values) |
| 2817 | 45 ba 00 04 07 00 ff fb f8 ff GetTotalPrintCount2 (? Not M1) |
| 2818 | 45 ba 00 04 07 10 ff fb f8 ef GetTotalPrintCount (? Not M1) |
| 2819 | 45 ba 00 02 02 40 ff fd fd bf Density (6800d -> 9000d) |
| 2820 | 45 ba 00 01 02 47 ff fe fd 87 Horizontal Position (0x00->0xff) |
| 2821 | 45 ba 19 c0 06 40 e6 3f f9 bf "Read Info" (BIG payload!) (M1) |
| 2822 | 45 ba 00 06 03 00 ff f9 fc ff M1 Adj (F/SF/UF, two bytes each?) |
| 2823 | 45 ba 00 06 03 10 ff f9 fc ef Vertical Position (A/B/C combined) |
| 2824 | 45 ba 00 02 03 16 ff fd fc e9 Feed (default 43402d) |
| 2825 | 45 ba 00 10 04 10 ff ef fb ef M3 Adj (unknown value) |
| 2826 | 45 ba 00 02 05 02 ff fd fa fd Sleep Time (LE value) |
| 2827 | 45 ba 00 01 05 04 ff fe fa fb ??? on/off |
| 2828 | 45 ba 00 01 05 06 ff fe fa f9 Resume on/off (0x80 off, 0x00 on) |
| 2829 | 45 ba 00 01 05 07 ff fe fa f8 Cutter on/off (0x80 off, 0x00 on) |
| 2830 | 45 ba 00 04 06 40 ff fe f9 bf Head Count (? Not M1) |
| 2831 | 45 ba 00 04 06 44 ff fb f9 bb Cutter Count (LE!) |
| 2832 | 45 ba 14 00 0c 00 eb ff f3 ff Error History (BIG payload) (d90?) |
| 2833 | |
| 2834 | [[ JOB STATUS QUERY ?? ]] |
| 2835 | |
| 2836 | -> 1b 47 44 31 00 00 JJ JJ Jobid? |
| 2837 | <- e4 47 44 31 XX YY ZZ ZZ No idea... maybe remaining prints? |
| 2838 | |
| 2839 | [[ WAKE UP PRINTER ]] |
| 2840 | |
| 2841 | -> 1b 45 57 55 |
| 2842 | |
| 2843 | [[ SANITY CHECK PRINT ARGUMENTS / MEM CHECK ]] |
| 2844 | |
| 2845 | -> 1b 47 44 33 00 33 07 3c 04 ca 64 00 00 01 00 00 |
| 2846 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
| 2847 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
| 2848 | 00 00 00 04 04 00 00 00 00 00 00 00 00 00 00 00 |
| 2849 | [[ pad to 512 ]] |
| 2850 | |
| 2851 | ... 07 3c onwards is the same as main payload header. |
| 2852 | |
| 2853 | <- e4 47 44 43 XX YY |
| 2854 | |
| 2855 | ... possibly the same as the D70's "memorystatus" |
| 2856 | XX == 00 size ok, 01 bad size, ff out of range |
| 2857 | YY == 00 memory ok, 01 memory full, 02 driver setting, ff out of range |
| 2858 | |
| 2859 | [[ UNKNOWN (seen in SDK; alt footer?) ]] |
| 2860 | |
| 2861 | 1b 42 61 32 00 00 |
| 2862 | |
| 2863 | [[ UNKNOWN (seen in SDK) ]] |
| 2864 | |
| 2865 | 1b 44 43 41 4e 43 45 4c 00 00 00 00 : \ESC D CANCEL |
| 2866 | |
| 2867 | [[ UNKNOWON (seen in SDK) ]] |
| 2868 | |
| 2869 | 1b 42 51 32 00 ff [ Footer of some sort ? ] |
| 2870 | |
| 2871 | ALSO SEEN: |
| 2872 | |
| 2873 | 1b 61 36 39 43 00 "AdjustColSCmd" |
| 2874 | 1b 61 36 37 39 43 "GetColSCmd" (12 len payload) |
| 2875 | 1b 6a 30 71 31 31 42 38 "SetM1AdjCmd" |
| 2876 | 1b 6a 36 34 31 00 "GetM1AdjCmd" |
| 2877 | 1b 6a 31 32 51 30 38 30 30 30 30 31 "M1AdjSolidGreyCmd" ??? |
| 2878 | 1b 61 36 34 50 00 "PaperSensorAdjCmd" |
| 2879 | 1b 61 36 37 34 50 "PaperSensorGetCmd" (24 len payload) |
| 2880 | 1b 61 36 36 45 ba Read EEProm (16 byte cmd payload, 0x8000 max len) |
| 2881 | 1b 61 36 30 45 ba Write EEProm |
| 2882 | 1b 47 44 30 00 00 01 65 Read Sensors (streams?) |
| 2883 | |
| 2884 | [ request x65 examples on the D90: ] |
| 2885 | |
| 2886 | ac 80 00 01 bb b8 fe 48 05 13 5d 9c 00 33 00 00 00 00 00 00 00 00 00 00 00 00 02 39 00 00 00 00 03 13 00 02 10 40 00 00 00 00 00 00 05 80 00 3a 00 00 |
| 2887 | aa 79 00 01 bb b7 fe 47 05 13 5d 9c 01 2f 00 68 00 00 00 00 00 00 00 00 00 00 02 08 00 00 00 00 03 14 00 02 10 40 00 00 00 00 00 00 05 80 00 3a 00 00 |
| 2888 | [ power cycle ] |
| 2889 | a3 5d 00 01 ba ba fe 43 04 13 5d 9c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 0c 00 00 00 00 03 0f 00 03 10 40 00 00 00 00 00 00 05 80 00 3a 00 00 |
| 2890 | a3 5d 00 01 ba ba fe 42 04 13 5d 9c 01 08 00 87 00 00 00 00 00 00 00 00 00 00 01 e5 00 00 00 00 03 0f 00 03 10 40 00 00 00 00 00 00 05 80 00 3a 00 00 |
| 2891 | a2 5d 00 01 ba ba fe 42 06 13 5d 9c 01 08 00 87 00 00 00 00 00 00 00 00 00 00 01 d1 00 00 00 00 03 0f 00 03 10 40 00 00 00 00 00 00 05 80 00 3a 00 00 |
| 2892 | [ power cycle ] |
| 2893 | a2 5c 00 01 ba ba fe 42 06 13 5d 9c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 e0 00 00 00 00 03 0f 00 03 10 40 00 00 00 00 00 00 05 80 00 3a 00 00 |
| 2894 | a2 5d 00 01 ba ba fe 41 04 13 5d 9c 01 08 00 89 00 00 00 00 00 00 00 00 00 00 01 c9 00 00 00 00 03 0f 00 03 10 40 00 00 00 00 00 00 05 80 00 3a 00 00 |
| 2895 | |
| 2896 | [ x65 on the M1 ] |
| 2897 | 00 00 01 f2 00 07 00 00 00 0f 00 a7 02 9f 03 91 00 00 00 00 00 00 02 36 00 07 03 ff 02 07 03 ff 03 4c 00 01 10 00 00 00 00 00 00 00 05 80 00 24 04 00 |
| 2898 | |
| 2899 | 00 00 00 f3 00 00 00 00 00 0f 00 27 01 8a 00 00 00 00 00 00 00 00 02 3b 00 07 03 fe 02 23 03 ff 03 46 00 01 10 00 00 00 00 00 00 00 05 80 00 24 04 00 |
| 2900 | 00 00 01 f3 00 00 00 00 00 0f 00 a7 02 48 03 6b 00 00 00 00 00 00 02 2d 00 08 03 fd 01 bf 03 ff 03 46 00 01 10 00 00 00 00 00 00 00 05 80 00 24 00 00 |
| 2901 | |
| 2902 | D90 Panorama data table files ("CP90PAN??.dat") |
| 2903 | |
| 2904 | struct d90_panodata { // All fields are LE |
| 2905 | uint32_t header; // @0 0x00000007 (ie number of ymc tuple useds) |
| 2906 | uint32_t [3][16] table1; // @4 YMC values |
| 2907 | uint32_t pad; // @192 0x00000000 |
| 2908 | uint32_t header2; // @196 0x00000011 (ie number of bgr tuples used) |
| 2909 | uint32_t [3][17] table2; // @200 BGR values |
| 2910 | double table3[600][184] // @408 TBD |
| 2911 | double unk[] // @110808 TBD |
| 2912 | uint8_t footer[8] // @71208408 "PA17424a" |
| 2913 | }; |
| 2914 | |
| 2915 | -- Table 3 seems to be a set of 600 row blocks (1 per overlap row?) |
| 2916 | 184 == 92 sets of L/R coeffients? |
| 2917 | ...30ea for Y/M/C, with 2 left over? |
| 2918 | |
| 2919 | */ |