Gank retry mechanism; instead, if sending sheet fails, initialize printer and start over

This commit is contained in:
XANTRONIX Development 2016-06-07 18:08:32 -05:00
parent 5b27cf9c79
commit 629f3e0049
2 changed files with 19 additions and 22 deletions

View file

@ -5,7 +5,6 @@
#define TABBY_PRINTER_SYNC_2 0x33 #define TABBY_PRINTER_SYNC_2 0x33
#define TABBY_PRINTER_DEVICE_ID 0x81 #define TABBY_PRINTER_DEVICE_ID 0x81
#define TABBY_PRINTER_RETRY_COUNT 5
#define TABBY_PRINTER_PACKET_MAX_SIZE 640 #define TABBY_PRINTER_PACKET_MAX_SIZE 640

View file

@ -107,33 +107,24 @@ int tabby_printer_packet_send(int fd,
void *body, void *body,
tabby_printer_response *response) { tabby_printer_response *response) {
uint16_t sum = checksum(header, body); uint16_t sum = checksum(header, body);
int tries = TABBY_PRINTER_RETRY_COUNT;
do { if (write(fd, header, sizeof(*header)) < 0) {
if (tries-- == 0) { goto error_io;
errno = EIO; }
if (header->size) {
if (write(fd, body, header->size) < 0) {
goto error_io; goto error_io;
} }
}
if (write(fd, header, sizeof(*header)) < 0) { if (write(fd, &sum, sizeof(sum)) < 0) {
goto error_io; goto error_io;
} }
if (header->size) { if (read(fd, response, sizeof(*response)) < 0) {
if (write(fd, body, header->size) < 0) { goto error_io;
goto error_io; }
}
}
if (write(fd, &sum, sizeof(sum)) < 0) {
goto error_io;
}
if (read(fd, response, sizeof(*response)) < 0) {
goto error_io;
}
} while (resend(response));
return 0; return 0;
@ -213,6 +204,13 @@ int tabby_printer_send_sheet(int fd, void *data,
goto error_packet_send; goto error_packet_send;
} }
if (resend(&current)) {
tabby_printer_init(fd, &current);
i = -1;
continue;
}
offset += TABBY_PRINTER_BAND_SIZE; offset += TABBY_PRINTER_BAND_SIZE;
} }