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:
@@ -24,6 +24,7 @@ static void usage(const char *argv0)
|
||||
" -t, --threshold N しきい値 0–255(既定 %u、PNG/SVG)\n"
|
||||
" --trim-right[=DOTS] 右側空白を削減(省略時は左余白、失敗時 0)\n"
|
||||
" -n, --dry-run 読み込みと check_raster のみ(USB なし)\n"
|
||||
" -v, --verbose 印刷前情報と印刷後ステータスを標準出力\n"
|
||||
" -p, --pid HEX USB 製品 ID(既定: P900W の 0x2085)。例: P750W 0x2062、P710BT 0x20af\n"
|
||||
" -S, --status ステータスを表示して終了\n"
|
||||
" -V, --version バージョンを表示して終了\n"
|
||||
@@ -101,6 +102,53 @@ static int read_file(const char *path, uint8_t **out, size_t *out_len)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void verbose_print_pre_print_info(libptouch_ctx *ctx,
|
||||
const libptouch_raster_params_t *params,
|
||||
size_t data_len)
|
||||
{
|
||||
if (!ctx || !params)
|
||||
return;
|
||||
|
||||
printf("=== verbose: pre-print info ===\n");
|
||||
printf("raster bytes: %zu\n", data_len);
|
||||
printf("raster size: %ux%u dots (length x width)\n",
|
||||
(unsigned)params->width_dots, (unsigned)params->height_dots);
|
||||
printf("margin_mm: %u\n", (unsigned)params->margin_mm);
|
||||
|
||||
libptouch_media_info_t mi;
|
||||
if (libptouch_get_current_media_info(ctx, &mi) == LIBPTOUCH_OK) {
|
||||
printf("media width code: 0x%02X\n", (unsigned)mi.media_width_code);
|
||||
printf("media kind code: 0x%02X\n", (unsigned)mi.media_kind_code);
|
||||
printf("tape width: %.1f mm\n", mi.tape_width_mm);
|
||||
printf("printable dots: %u\n", (unsigned)mi.printable_dots);
|
||||
printf("left/right margins: %u/%u dots\n",
|
||||
(unsigned)mi.left_margin_dots, (unsigned)mi.right_margin_dots);
|
||||
printf("print/feed dpi: %.1f/%.1f\n", mi.print_dpi, mi.feed_dpi);
|
||||
} else {
|
||||
printf("media info: unavailable (%s)\n", libptouch_strerror(ctx));
|
||||
}
|
||||
|
||||
uint8_t st[LIBPTOUCH_STATUS_LENGTH];
|
||||
if (libptouch_get_status(ctx, st) == LIBPTOUCH_OK) {
|
||||
libptouch_status_fprint(stdout, st);
|
||||
} else {
|
||||
printf("status: unavailable (%s)\n", libptouch_strerror(ctx));
|
||||
}
|
||||
}
|
||||
|
||||
static void verbose_print_post_print_status(libptouch_ctx *ctx, const char *label)
|
||||
{
|
||||
if (!ctx)
|
||||
return;
|
||||
printf("=== verbose: post-print status (%s) ===\n", label);
|
||||
uint8_t st[LIBPTOUCH_STATUS_LENGTH];
|
||||
if (libptouch_get_status(ctx, st) == LIBPTOUCH_OK) {
|
||||
libptouch_status_fprint(stdout, st);
|
||||
} else {
|
||||
printf("status: unavailable (%s)\n", libptouch_strerror(ctx));
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
const char *file = NULL;
|
||||
@@ -108,6 +156,7 @@ int main(int argc, char **argv)
|
||||
unsigned threshold = LIBPTOUCH_PNG_DEFAULT_THRESHOLD;
|
||||
unsigned usb_pid_arg = 0;
|
||||
int dry_run = 0;
|
||||
int verbose = 0;
|
||||
int trim_right_enabled = 0;
|
||||
int trim_right_auto = 0;
|
||||
unsigned trim_right_dots = 0;
|
||||
@@ -120,6 +169,7 @@ int main(int argc, char **argv)
|
||||
{ "threshold", required_argument, NULL, 't' },
|
||||
{ "trim-right", optional_argument, NULL, 'r' },
|
||||
{ "dry-run", no_argument, NULL, 'n' },
|
||||
{ "verbose", no_argument, NULL, 'v' },
|
||||
{ "pid", required_argument, NULL, 'p' },
|
||||
{ "status", no_argument, NULL, 'S' },
|
||||
{ "version", no_argument, NULL, 'V' },
|
||||
@@ -128,7 +178,7 @@ int main(int argc, char **argv)
|
||||
};
|
||||
|
||||
int c;
|
||||
while ((c = getopt_long(argc, argv, "w:H:f:t:r::p:nhSV", longopts, NULL)) !=
|
||||
while ((c = getopt_long(argc, argv, "w:H:f:t:r::p:nvhSV", longopts, NULL)) !=
|
||||
-1) {
|
||||
switch (c) {
|
||||
case 'w':
|
||||
@@ -151,6 +201,9 @@ int main(int argc, char **argv)
|
||||
case 'n':
|
||||
dry_run = 1;
|
||||
break;
|
||||
case 'v':
|
||||
verbose = 1;
|
||||
break;
|
||||
case 'r':
|
||||
trim_right_enabled = 1;
|
||||
if (!optarg) {
|
||||
@@ -397,8 +450,13 @@ int main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
if (verbose)
|
||||
verbose_print_pre_print_info(ctx, ¶ms, data_len);
|
||||
|
||||
e = libptouch_print_raster(ctx, data, data_len, ¶ms);
|
||||
if (e != LIBPTOUCH_OK) {
|
||||
if (verbose)
|
||||
verbose_print_post_print_status(ctx, "print failed");
|
||||
fprintf(stderr, "print_raster: %s\n",
|
||||
libptouch_strerror(ctx));
|
||||
libptouch_close(ctx);
|
||||
@@ -410,6 +468,9 @@ int main(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (verbose)
|
||||
verbose_print_post_print_status(ctx, "print success");
|
||||
|
||||
libptouch_close(ctx);
|
||||
libptouch_destroy(ctx);
|
||||
if (data_from_lib)
|
||||
|
||||
Reference in New Issue
Block a user