static int get_errorlog(struct shinkos2145_ctx *ctx) { struct s2145_cmd_hdr cmd; struct s2145_errorlog_resp *resp = (struct s2145_errorlog_resp *) rdbuf; int ret, num = 0; int i; cmd.cmd = cpu_to_le16(S2145_CMD_ERRORLOG); cmd.len = cpu_to_le16(0); if ((ret = s2145_do_cmd(ctx, (uint8_t*)&cmd, sizeof(cmd), sizeof(*resp), &num)) < 0) { ERROR("Failed to execute %s command\n", cmd_names(cmd.cmd)); return ret; } if (le16_to_cpu(resp->hdr.payload_len) != (sizeof(struct s2145_errorlog_resp) - sizeof(struct s2145_status_hdr))) return -2; INFO("Stored Error Events: %d entries:\n", resp->count); for (i = 0 ; i < resp->count ; i++) { INFO(" %02d: @ %08u prints : 0x%02x/0x%02x (%s)\n", i, le32_to_cpu(resp->items[i].print_counter), resp->items[i].major, resp->items[i].minor, error_codes(resp->items[i].major, resp->items[i].minor)); } return 0; }
static int get_status(struct shinkos2145_ctx *ctx) { struct s2145_cmd_hdr cmd; struct s2145_status_resp *resp = (struct s2145_status_resp *) rdbuf; int ret, num = 0; cmd.cmd = cpu_to_le16(S2145_CMD_STATUS); cmd.len = cpu_to_le16(0); if ((ret = s2145_do_cmd(ctx, (uint8_t*)&cmd, sizeof(cmd), sizeof(*resp), &num)) < 0) { ERROR("Failed to execute %s command\n", cmd_names(cmd.cmd)); return ret; } INFO("Printer Status: 0x%02x (%s)\n", resp->hdr.status, status_str(resp->hdr.status)); if (resp->hdr.status == ERROR_PRINTER) { if(resp->hdr.error == ERROR_NONE) resp->hdr.error = resp->hdr.status; INFO(" Error 0x%02x (%s) 0x%02x/0x%02x (%s)\n", resp->hdr.error, error_str(resp->hdr.error), resp->hdr.printer_major, resp->hdr.printer_minor, error_codes(resp->hdr.printer_major, resp->hdr.printer_minor)); } if (le16_to_cpu(resp->hdr.payload_len) != (sizeof(struct s2145_status_resp) - sizeof(struct s2145_status_hdr))) return 0; INFO(" Print Counts:\n"); INFO("\tSince Paper Changed:\t%08u\n", le32_to_cpu(resp->count_paper)); INFO("\tLifetime:\t\t%08u\n", le32_to_cpu(resp->count_lifetime)); INFO("\tMaintainence:\t\t%08u\n", le32_to_cpu(resp->count_maint)); INFO("\tPrint Head:\t\t%08u\n", le32_to_cpu(resp->count_head)); INFO(" Cutter Actuations:\t%08u\n", le32_to_cpu(resp->count_cutter)); INFO(" Ribbon Remaining:\t%08u\n", le32_to_cpu(resp->count_ribbon_left)); INFO("Bank 1: 0x%02x (%s) Job %03u @ %03u/%03u (%03u remaining)\n", resp->bank1_status, bank_statuses(resp->bank1_status), resp->bank1_printid, le16_to_cpu(resp->bank1_finished), le16_to_cpu(resp->bank1_specified), le16_to_cpu(resp->bank1_remaining)); INFO("Bank 2: 0x%02x (%s) Job %03d @ %03d/%03d (%03d remaining)\n", resp->bank2_status, bank_statuses(resp->bank1_status), resp->bank2_printid, le16_to_cpu(resp->bank2_finished), le16_to_cpu(resp->bank2_specified), le16_to_cpu(resp->bank2_remaining)); INFO("Tonecurve Status: 0x%02x (%s)\n", resp->tonecurve_status, tonecurve_statuses(resp->tonecurve_status)); return 0; }
static int s2145_do_cmd(struct shinkos2145_ctx *ctx, uint8_t *cmd, int cmdlen, int minlen, int *num) { int ret; struct s2145_status_hdr *resp = (struct s2145_status_hdr *) rdbuf; libusb_device_handle *dev = ctx->dev; uint8_t endp_up = ctx->endp_up; uint8_t endp_down = ctx->endp_down; if ((ret = send_data(dev, endp_down, cmd, cmdlen))) return (ret < 0) ? ret : -99; ret = read_data(dev, endp_up, rdbuf, READBACK_LEN, num); if (ret < 0) return ret; if (*num < minlen) { ERROR("Short read! (%d/%d))\n", *num, minlen); return -99; } if (resp->result != RESULT_SUCCESS) { INFO("Printer Status: %02x (%s)\n", resp->status, status_str(resp->status)); INFO(" Result: 0x%02x Error: 0x%02x (0x%02x/0x%02x = %s)\n", resp->result, resp->error, resp->printer_major, resp->printer_minor, error_codes(resp->printer_major, resp->printer_minor)); return -99; } return ret; }
static int shinkos2145_main_loop(void *vctx, int copies) { struct shinkos2145_ctx *ctx = vctx; int ret, num; uint8_t cmdbuf[CMDBUF_LEN]; uint8_t rdbuf2[READBACK_LEN]; int i, last_state = -1, state = S_IDLE; struct s2145_cmd_hdr *cmd = (struct s2145_cmd_hdr *) cmdbuf;; struct s2145_print_cmd *print = (struct s2145_print_cmd *) cmdbuf; struct s2145_status_resp *sts = (struct s2145_status_resp *) rdbuf; struct s2145_mediainfo_resp *media = (struct s2145_mediainfo_resp *) rdbuf; /* Send Media Query */ memset(cmdbuf, 0, CMDBUF_LEN); cmd->cmd = cpu_to_le16(S2145_CMD_MEDIAINFO); cmd->len = cpu_to_le16(0); if ((ret = s2145_do_cmd(ctx, cmdbuf, sizeof(*cmd), sizeof(*media), &num)) < 0) { ERROR("Failed to execute %s command\n", cmd_names(cmd->cmd)); return CUPS_BACKEND_FAILED; } if (le16_to_cpu(media->hdr.payload_len) != (sizeof(struct s2145_mediainfo_resp) - sizeof(struct s2145_status_hdr))) return CUPS_BACKEND_FAILED; /* Validate print sizes */ for (i = 0; i < media->count ; i++) { /* Look for matching media */ if (le16_to_cpu(media->items[i].columns) == cpu_to_le16(le32_to_cpu(ctx->hdr.columns)) && le16_to_cpu(media->items[i].rows) == cpu_to_le16(le32_to_cpu(ctx->hdr.rows)) && media->items[i].print_type == le32_to_cpu(ctx->hdr.method)) break; } if (i == media->count) { ERROR("Incorrect media loaded for print!\n"); return CUPS_BACKEND_HOLD; } // XXX check copies against remaining media! top: if (state != last_state) { if (dyesub_debug) DEBUG("last_state %d new %d\n", last_state, state); } /* Send Status Query */ memset(cmdbuf, 0, CMDBUF_LEN); cmd->cmd = cpu_to_le16(S2145_CMD_STATUS); cmd->len = cpu_to_le16(0); if ((ret = s2145_do_cmd(ctx, cmdbuf, sizeof(*cmd), sizeof(struct s2145_status_hdr), &num)) < 0) { ERROR("Failed to execute %s command\n", cmd_names(cmd->cmd)); return CUPS_BACKEND_FAILED; } if (memcmp(rdbuf, rdbuf2, READBACK_LEN)) { memcpy(rdbuf2, rdbuf, READBACK_LEN); INFO("Printer Status: 0x%02x (%s)\n", sts->hdr.status, status_str(sts->hdr.status)); if (sts->hdr.result != RESULT_SUCCESS) goto printer_error; if (sts->hdr.error == ERROR_PRINTER) goto printer_error; } else if (state == last_state) { sleep(1); goto top; } last_state = state; fflush(stderr); switch (state) { case S_IDLE: INFO("Waiting for printer idle\n"); /* If either bank is free, continue */ if (sts->bank1_status == BANK_STATUS_FREE || sts->bank2_status == BANK_STATUS_FREE) state = S_PRINTER_READY_CMD; break; case S_PRINTER_READY_CMD: INFO("Initiating print job (internal id %d)\n", ctx->jobid); memset(cmdbuf, 0, CMDBUF_LEN); print->hdr.cmd = cpu_to_le16(S2145_CMD_PRINTJOB); print->hdr.len = cpu_to_le16(sizeof (*print) - sizeof(*cmd)); print->id = ctx->jobid; print->count = cpu_to_le16(copies); print->columns = cpu_to_le16(le32_to_cpu(ctx->hdr.columns)); print->rows = cpu_to_le16(le32_to_cpu(ctx->hdr.rows)); print->media = le32_to_cpu(ctx->hdr.media); print->mode = le32_to_cpu(ctx->hdr.mode); print->method = le32_to_cpu(ctx->hdr.method); if ((ret = s2145_do_cmd(ctx, cmdbuf, sizeof(*print), sizeof(struct s2145_status_hdr), &num)) < 0) { ERROR("Failed to execute %s command\n", cmd_names(print->hdr.cmd)); return ret; } if (sts->hdr.result != RESULT_SUCCESS) { if (sts->hdr.error == ERROR_BUFFER_FULL) { INFO("Printer Buffers full, retrying\n"); break; } else if ((sts->hdr.status & 0xf0) == 0x30 || sts->hdr.status == 0x21) { INFO("Printer busy (%s), retrying\n", status_str(sts->hdr.status)); break; } else if (sts->hdr.status != ERROR_NONE) goto printer_error; } INFO("Sending image data to printer\n"); if ((ret = send_data(ctx->dev, ctx->endp_down, ctx->databuf, ctx->datalen))) return CUPS_BACKEND_FAILED; INFO("Waiting for printer to acknowledge completion\n"); sleep(1); state = S_PRINTER_SENT_DATA; break; case S_PRINTER_SENT_DATA: if (fast_return) { INFO("Fast return mode enabled.\n"); state = S_FINISHED; } else if (sts->hdr.status == STATUS_READY || sts->hdr.status == STATUS_FINISHED) { state = S_FINISHED; } break; default: break; }; if (state != S_FINISHED) goto top; INFO("Print complete\n"); return CUPS_BACKEND_OK; printer_error: ERROR("Printer reported error: %#x (%s) status: %#x (%s) -> %#x.%#x (%s)\n", sts->hdr.error, error_str(sts->hdr.error), sts->hdr.status, status_str(sts->hdr.status), sts->hdr.printer_major, sts->hdr.printer_minor, error_codes(sts->hdr.printer_major, sts->hdr.printer_minor)); return CUPS_BACKEND_FAILED; }
int main(int argc, char **argv) { buffer_t in = {0}, out = {0}; in.host = (uint8_t *)malloc(64*64*4); in.elem_size = 4; in.extent[0] = 64; in.stride[0] = 1; in.extent[1] = 64; in.stride[1] = 64; out.host = (uint8_t *)malloc(64*64*4); out.elem_size = 4; out.extent[0] = 64; out.stride[0] = 1; out.extent[1] = 64; out.stride[1] = 64; // First, a successful run. int result = error_codes(&in, 64, &out); int correct = halide_error_code_success; check(result, correct); // Passing 50 as the second arg violates the call to Func::bound // in the generator result = error_codes(&in, 50, &out); correct = halide_error_code_explicit_bounds_too_small; check(result, correct); // Would read out of bounds on the input in.extent[0] = 50; result = error_codes(&in, 64, &out); correct = halide_error_code_access_out_of_bounds; check(result, correct); in.extent[0] = 64; // Input buffer larger than 2GB in.extent[0] = 10000000; in.extent[1] = 10000000; result = error_codes(&in, 64, &out); correct = halide_error_code_buffer_extents_too_large; check(result, correct); in.extent[0] = 64; in.extent[1] = 64; // Input buffer requires addressing math that would overflow 32 bits. in.stride[1] = 0x7fffffff; result = error_codes(&in, 64, &out); correct = halide_error_code_buffer_allocation_too_large; check(result, correct); in.stride[1] = 64; // stride[0] is constrained to be 1 in.stride[0] = 2; result = error_codes(&in, 64, &out); correct = halide_error_code_constraint_violated; check(result, correct); in.stride[0] = 1; // The second argument is supposed to be between 0 and 64. result = error_codes(&in, -23, &out); correct = halide_error_code_param_too_small; check(result, correct); in.extent[0] = 108; out.extent[0] = 108; result = error_codes(&in, 108, &out); correct = halide_error_code_param_too_large; check(result, correct); in.extent[0] = 64; out.extent[0] = 64; // You can't pass NULL as a buffer_t argument. result = error_codes(NULL, 64, &out); correct = halide_error_code_buffer_argument_is_null; check(result, correct); printf("Success!\n"); return 0; }