diff --git a/selphy_print.c b/selphy_print.c index 15236bd..4b5eaa5 100644 --- a/selphy_print.c +++ b/selphy_print.c @@ -74,6 +74,79 @@ #define USB_PID_CANON_CP810 0x3256 #define USB_PID_CANON_CP900 0x3255 +static int fancy_memcmp(const uint8_t *buf_a, const int16_t *buf_b, uint len, int16_t papercode_offset, int16_t papercode_val) +{ + int i; + + for (i = 0 ; i < len ; i++) { + if (papercode_offset != -1 && i == papercode_offset) { + if (papercode_val == -1) + continue; + else if (buf_a[i] != papercode_val) + return INCORRECT_PAPER; + } else if (buf_b[i] == -1) + continue; + else if (buf_a[i] > buf_b[i]) + return 1; + else if (buf_a[i] < buf_b[i]) + return -1; + } + return 0; +} + +static int parse_printjob(uint8_t *buffer, int *bw_mode, int *plane_len) +{ + int printer_type = -1; + + if (buffer[0] != 0x40 && + buffer[1] != 0x00) { + goto done; + } + + if (buffer[12] == 0x40 && + buffer[13] == 0x01) { + if (buffer[2] == 0x00) { + printer_type = P_CP_XXX; + } else { + printer_type = P_ES1; + *bw_mode = (buffer[2] == 0x20); + } + + *plane_len = *(uint32_t*)(&buffer[16]); + *plane_len = le32_to_cpu(*plane_len); + goto done; + } + + *plane_len = *(uint32_t*)(&buffer[12]); + *plane_len = le32_to_cpu(*plane_len); + + if (buffer[16] == 0x40 && + buffer[17] == 0x01) { + + if (buffer[4] == 0x02) { + printer_type = P_ES2_20; + *bw_mode = (buffer[7] == 0x01); + goto done; + } + + if (es40_cp790_plane_lengths[buffer[2]] == *plane_len) { + printer_type = P_ES40_CP790; + *bw_mode = (buffer[3] == 0x01); + goto done; + } else { + printer_type = P_ES3_30; + *bw_mode = (buffer[3] == 0x01); + goto done; + } + } + + return -1; + +done: + + return printer_type; +} + static int dump_data_libusb(int remaining, int present, int data_fd, struct libusb_device_handle *dev, uint8_t endpoint, diff --git a/selphy_print_common.h b/selphy_print_common.h index 4c5389e..5aa0f62 100644 --- a/selphy_print_common.h +++ b/selphy_print_common.h @@ -25,7 +25,7 @@ * */ -#define VERSION "0.41" +#define VERSION "0.42" #define DEBUG( ... ) fprintf(stderr, "DEBUG: " __VA_ARGS__ ) #define ERROR( ... ) fprintf(stderr, "ERROR: " __VA_ARGS__ ) @@ -209,26 +209,6 @@ static void setup_paper_codes(void) #define INCORRECT_PAPER -999 -static int fancy_memcmp(const uint8_t *buf_a, const int16_t *buf_b, uint len, int16_t papercode_offset, int16_t papercode_val) -{ - int i; - - for (i = 0 ; i < len ; i++) { - if (papercode_offset != -1 && i == papercode_offset) { - if (papercode_val == -1) - continue; - else if (buf_a[i] != papercode_val) - return INCORRECT_PAPER; - } else if (buf_b[i] == -1) - continue; - else if (buf_a[i] > buf_b[i]) - return 1; - else if (buf_a[i] < buf_b[i]) - return -1; - } - return 0; -} - /* Program states */ enum { S_IDLE = 0, @@ -244,55 +224,3 @@ enum { S_FINISHED, }; -static int parse_printjob(uint8_t *buffer, int *bw_mode, int *plane_len) -{ - int printer_type = -1; - - if (buffer[0] != 0x40 && - buffer[1] != 0x00) { - goto done; - } - - if (buffer[12] == 0x40 && - buffer[13] == 0x01) { - if (buffer[2] == 0x00) { - printer_type = P_CP_XXX; - } else { - printer_type = P_ES1; - *bw_mode = (buffer[2] == 0x20); - } - - *plane_len = *(uint32_t*)(&buffer[16]); - *plane_len = le32_to_cpu(*plane_len); - goto done; - } - - *plane_len = *(uint32_t*)(&buffer[12]); - *plane_len = le32_to_cpu(*plane_len); - - if (buffer[16] == 0x40 && - buffer[17] == 0x01) { - - if (buffer[4] == 0x02) { - printer_type = P_ES2_20; - *bw_mode = (buffer[7] == 0x01); - goto done; - } - - if (es40_cp790_plane_lengths[buffer[2]] == *plane_len) { - printer_type = P_ES40_CP790; - *bw_mode = (buffer[3] == 0x01); - goto done; - } else { - printer_type = P_ES3_30; - *bw_mode = (buffer[3] == 0x01); - goto done; - } - } - - return -1; - -done: - - return printer_type; -}