Gank retry mechanism; instead, if sending sheet fails, initialize printer and start over
This commit is contained in:
parent
5b27cf9c79
commit
629f3e0049
2 changed files with 19 additions and 22 deletions
|
@ -5,7 +5,6 @@
|
|||
#define TABBY_PRINTER_SYNC_2 0x33
|
||||
|
||||
#define TABBY_PRINTER_DEVICE_ID 0x81
|
||||
#define TABBY_PRINTER_RETRY_COUNT 5
|
||||
|
||||
#define TABBY_PRINTER_PACKET_MAX_SIZE 640
|
||||
|
||||
|
|
|
@ -107,33 +107,24 @@ int tabby_printer_packet_send(int fd,
|
|||
void *body,
|
||||
tabby_printer_response *response) {
|
||||
uint16_t sum = checksum(header, body);
|
||||
int tries = TABBY_PRINTER_RETRY_COUNT;
|
||||
|
||||
do {
|
||||
if (tries-- == 0) {
|
||||
errno = EIO;
|
||||
if (write(fd, header, sizeof(*header)) < 0) {
|
||||
goto error_io;
|
||||
}
|
||||
|
||||
if (header->size) {
|
||||
if (write(fd, body, header->size) < 0) {
|
||||
goto error_io;
|
||||
}
|
||||
}
|
||||
|
||||
if (write(fd, header, sizeof(*header)) < 0) {
|
||||
goto error_io;
|
||||
}
|
||||
if (write(fd, &sum, sizeof(sum)) < 0) {
|
||||
goto error_io;
|
||||
}
|
||||
|
||||
if (header->size) {
|
||||
if (write(fd, body, header->size) < 0) {
|
||||
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));
|
||||
if (read(fd, response, sizeof(*response)) < 0) {
|
||||
goto error_io;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
|
@ -213,6 +204,13 @@ int tabby_printer_send_sheet(int fd, void *data,
|
|||
goto error_packet_send;
|
||||
}
|
||||
|
||||
if (resend(¤t)) {
|
||||
tabby_printer_init(fd, ¤t);
|
||||
i = -1;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
offset += TABBY_PRINTER_BAND_SIZE;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue