From 8687c76d1c7d9797d6e1ccb40a2d471734a45c61 Mon Sep 17 00:00:00 2001 From: Connor Taffe Date: Sun, 20 Aug 2023 15:24:45 -0400 Subject: [PATCH] Fix PAP status for ImageWriter II Follow changes implemented in https://github.com/kakwa/image-writer to disable status checks which fail for ImageWriter, and update the status output to be human-readable. --- bin/pap/pap.c | 9 ++++++++- bin/pap/papstatus.c | 29 ++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/bin/pap/pap.c b/bin/pap/pap.c index 0c62da4b..53221c3f 100644 --- a/bin/pap/pap.c +++ b/bin/pap/pap.c @@ -890,17 +890,21 @@ static int send_file(int fd, ATP atp, int lastfile) * The stinking LaserWriter IINTX puts crap in this * field. */ + /* if (((char *) rniov[0].iov_base)[0] != 0) { fprintf(stderr, "Bad status response!\n"); exit(1); } + */ #endif /* NONZEROSTATUS */ + /* if (((char *) rniov[0].iov_base)[1] != PAP_STATUS || atpb.atp_rresiovcnt != 1) { fprintf(stderr, "Bad status response!\n"); exit(1); } + */ if (debug) { printf("< STATUS\n"), fflush(stdout); @@ -931,6 +935,7 @@ static void updatestatus(char *s, int len) { int fd = -1; struct iovec iov[3]; + char error_code[len]; if (status) { if ((fd = open(status, O_WRONLY | O_TRUNC)) < 0) { @@ -945,7 +950,9 @@ static void updatestatus(char *s, int len) iov[0].iov_base = "%%[ "; iov[0].iov_len = 4; - iov[1].iov_base = s; + //iov[1].iov_base = s; + sprintf(error_code, "%X", s); + iov[1].iov_base = error_code; iov[1].iov_len = len; iov[2].iov_base = " ]%%\n"; iov[2].iov_len = 5; diff --git a/bin/pap/papstatus.c b/bin/pap/papstatus.c index b113f667..3dea1743 100644 --- a/bin/pap/papstatus.c +++ b/bin/pap/papstatus.c @@ -44,6 +44,15 @@ #define _PATH_PAPRC ".paprc" +#define COLOR_RIBBON_INSTALLED 0b10000000 +#define SHEET_FEEDER_INSTALLED 0b01000000 +#define PAPER_OUT_ERROR 0b00100000 +#define COVER_OPEN_ERROR 0b00010000 +#define PRINTER_OFF_LINE 0b00001000 +#define PAPER_JAM_ERROR 0b00000100 +#define PRINTER_FAULT 0b00000010 +#define PRINTER_ACTIVE 0b00000001 + /* Forward Declaration */ static void getstatus(ATP atp, struct sockaddr_at *sat); @@ -87,6 +96,7 @@ static char *printer = NULL; static char cbuf[8]; static struct nbpnve nn; + int main(int ac, char **av) { ATP atp; @@ -199,5 +209,22 @@ static void getstatus(ATP atp, struct sockaddr_at *sat) return; /* This is weird, since TIDs must match... */ } - printf("%.*s\n", (int) iov.iov_len - 9, (char *) iov.iov_base + 9); + // printf("%.*s\n", (int) iov.iov_len - 9, (char *) iov.iov_base + 9); + char status = rbuf[9]; + if (status & COLOR_RIBBON_INSTALLED) + puts("Color ribbon installed"); + if (status & SHEET_FEEDER_INSTALLED) + puts("Sheet feeder installed"); + if (status & PAPER_OUT_ERROR) + puts("Out of papaer"); + if (status & COVER_OPEN_ERROR) + puts("Cover open"); + if (status & PRINTER_OFF_LINE) + puts("Printer offline"); + if (status & PAPER_JAM_ERROR) + puts("Paper jam"); + if (status & PRINTER_FAULT) + puts("Printer fault"); + if (status & PRINTER_ACTIVE) + puts("Printer active"); } -- 2.41.0