Fix PT-P710BT raster protocol handling and add regression coverage.
Align print command payload generation with model-specific protocol requirements, add verbose CLI diagnostics and robust status retries, and introduce protocol regression tests to prevent future GF/ESC i z regressions. Made-with: Cursor
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
libptouch_err_t libptouch_get_status(libptouch_ctx *ctx, uint8_t *status)
|
||||
{
|
||||
@@ -28,18 +29,26 @@ libptouch_err_t libptouch_get_status(libptouch_ctx *ctx, uint8_t *status)
|
||||
static const uint8_t req[] = { 0x1B, 0x69, 0x53 };
|
||||
|
||||
int r = LIBUSB_ERROR_OTHER;
|
||||
for (int attempt = 0; attempt < 2; attempt++) {
|
||||
for (int attempt = 0; attempt < 5; attempt++) {
|
||||
/* First status read after reconnect can fail on some P-touch units. */
|
||||
(void)libusb_clear_halt(h, ctx->bulk_in_ep);
|
||||
(void)libusb_clear_halt(h, ctx->bulk_out_ep);
|
||||
if (attempt > 0) {
|
||||
(void)libusb_clear_halt(h, ctx->bulk_in_ep);
|
||||
(void)libusb_clear_halt(h, ctx->bulk_out_ep);
|
||||
usleep(120000); /* 120ms backoff */
|
||||
}
|
||||
r = ptouch_bulk_out(h, ctx->bulk_out_ep, init, 2, 5000u);
|
||||
if (r != 0) {
|
||||
if (r == LIBUSB_ERROR_IO || r == LIBUSB_ERROR_PIPE ||
|
||||
r == LIBUSB_ERROR_TIMEOUT)
|
||||
continue;
|
||||
ptouch_set_error_usb(ctx, r, "bulk OUT ESC @");
|
||||
return LIBPTOUCH_ERR_USB;
|
||||
}
|
||||
r = ptouch_bulk_out(h, ctx->bulk_out_ep, req, 3, 5000u);
|
||||
if (r != 0) {
|
||||
if (r == LIBUSB_ERROR_IO || r == LIBUSB_ERROR_PIPE ||
|
||||
r == LIBUSB_ERROR_TIMEOUT)
|
||||
continue;
|
||||
ptouch_set_error_usb(ctx, r, "bulk OUT ESC i S");
|
||||
return LIBPTOUCH_ERR_USB;
|
||||
}
|
||||
@@ -47,7 +56,8 @@ libptouch_err_t libptouch_get_status(libptouch_ctx *ctx, uint8_t *status)
|
||||
(int)LIBPTOUCH_STATUS_LENGTH, 5000u);
|
||||
if (r == 0)
|
||||
break;
|
||||
if (r != LIBUSB_ERROR_IO && r != LIBUSB_ERROR_PIPE)
|
||||
if (r != LIBUSB_ERROR_IO && r != LIBUSB_ERROR_PIPE &&
|
||||
r != LIBUSB_ERROR_TIMEOUT)
|
||||
break;
|
||||
}
|
||||
if (r != 0) {
|
||||
|
||||
Reference in New Issue
Block a user