#include #include #include #include #include #include #include #include #include #include static void usage(int argc, char **argv, char *message, ...) { if (message) { va_list args; va_start(args, message); vfprintf(stderr, message, args); fprintf(stderr, "\n"); va_end(args); } fprintf(stderr, "usage: %s device sheet.tile\n", argv[0]); exit(1); } int main(int argc, char **argv) { int fd, tile_fd; tabby_printer_response response; void *tile; if (argc != 3) { usage(argc, argv, "Must specify device and tile"); } if ((tile = malloc(TABBY_PRINTER_SHEET_SIZE)) == NULL) { goto error_malloc_tile; } if ((tile_fd = open(argv[2], O_RDONLY)) < 0) { fprintf(stderr, "%s: %s: %s: %s\n", argv[0], "open()", argv[2], strerror(errno)); goto error_open_tile; } if (read(tile_fd, tile, TABBY_PRINTER_SHEET_SIZE) < 0) { goto error_read_tile; } if ((fd = tabby_link_open(argv[1])) < 0) { fprintf(stderr, "%s: %s: %s: %s\n", argv[0], "tabby_link_open()", argv[1], strerror(errno)); goto error_link_open; } printf("Waiting for AVR to reboot after CTS\n"); sleep(1); tabby_printer_link_init(fd); printf("Link initialized\n"); do { tabby_printer_init(fd, &response); usleep(100000); printf("Got response %02x%02x\n", response.device, response.status); } while (response.device != TABBY_PRINTER_DEVICE_ID); tabby_printer_send_sheet(fd, tile, &response); printf("Sent sheet, got response %02x%02x\n", response.device, response.status); while (response.status & TABBY_PRINTER_UNTRAN) { tabby_printer_send_inquiry(fd, &response); usleep(100000); } tabby_link_close(fd); return 0; error_link_open: error_read_tile: close(tile_fd); error_open_tile: free(tile); error_malloc_tile: return 1; }