feat(inventory): Phase 1 - scan and validate UPC barcodes #1

Open
lyrathorpe wants to merge 54 commits from feat/inventory-phase1-scan into main
Showing only changes of commit ff38d4eb70 - Show all commits
+48 -46
View File
@@ -1,72 +1,74 @@
/* /*
* scan.c - Phase 1 barcode diagnostic for the Workabout MX integral laser. * scan.c - Phase 1 barcode diagnostic: decoded laser over the serial port.
* *
* Per the I/O Devices Reference (HC Bar Code Reader chapter): load a decoder * The Workabout MX integral laser powered up and gave a good-read LED on
* LDD (BAREAN.LDD for UPC/EAN), open the device "BAR:<slot>" (top slot is "A" * TTY:D, i.e. it is a DECODED scanner that emits ASCII over the serial port -
* on the HC; the Workabout may map the top slot differently), and read with * no BAR: decoder LDD needed. The earlier TTY:D read returned nothing because
* p_iow(pcb, P_FREAD, buf), buf >= 256 bytes. The result is a leading byte * the port's default handshake sets P_OBEY_DSR, and the I/O Devices Reference
* count in buf[0] (0 = unsuccessful read), buf[1] = a barcode-type character, * states that if the remote device does not assert DSR, an outstanding P_FREAD
* and buf[2..] = the decoded digits. * is suspended. The laser does not drive DSR, so the read blocked forever.
* *
* This build probes the likely slot letters (bare "BAR:" gave E_FILE_NAME/-38 * This build opens TTY:D, applies a P_SRCHAR config at 9600/8/1 with P_OBEY_DSR
* because it lacks the slot letter), reports which opens, then dumps the raw * cleared (P_IGN_CTS only, so reads are not gated on modem lines), forces DTR
* [count][type][data] of each scan so the exact UPC format is confirmed. * active, then dumps every byte of each read so the decoded UPC format is seen.
* *
* Blocking I/O; exit via the System screen. * Blocking I/O; exit via the System screen.
*/ */
#include <plib.h> #include <plib.h>
#include "bcode.h" #include <p_serial.h>
#define NCAND 4
GLDEF_C INT main(VOID) GLDEF_C INT main(VOID)
{ {
VOID *chan; VOID *chan;
UBYTE buf[256]; P_SRCHAR ser;
INT loadErr, r, i, cnt, opened; UBYTE buf[64];
UINT k; UBYTE ctrl[2];
INT err, n, i;
static TEXT *names[NCAND] = { "BAR:A", "BAR:D", "BAR:B", "BAR:E" }; err = p_open(&chan, "TTY:D", (UINT)-1);
p_printf("open TTY:D: %d\n", err);
loadErr = bcodeLoad(); if (err < 0) {
p_printf("load %s.LDD: %d\n\n", BCODE_LDD, loadErr); p_printf("Press a key to exit.\n");
opened = 0;
for (k = 0; k < NCAND; k++) {
r = p_open(&chan, names[k], (UINT)-1);
p_printf("open \"%s\": %d\n", names[k], r);
if (r >= 0) {
opened = 1;
break;
}
}
if (opened == 0) {
p_printf("\nNothing opened. Press a key to exit.\n");
p_getch(); p_getch();
return 1; return 1;
} }
p_printf("\nOpened \"%s\". Scan a barcode. System screen to exit.\n\n", /* 9600 baud, 8 data bits, 1 stop, no parity; do NOT obey DSR/DCD (only
names[k]); ignore CTS) so a scanner that leaves the modem lines idle can be read. */
ser.tbaud = P_BAUD_9600;
ser.rbaud = P_BAUD_9600;
ser.frame = P_DATA_8;
ser.parity = 0;
ser.hand = P_IGN_CTS;
ser.xon = 0x11;
ser.xoff = 0x13;
ser.flags = 0;
ser.tmask = 0;
err = p_iow(chan, P_FSET, &ser);
p_printf("config 9600/8/1: %d\n", err);
/* Force DTR (the scanner enable line) active. Opening already drives it,
but make it explicit. ctrl[0] is the read-back of input lines. */
ctrl[0] = 0;
ctrl[1] = P_SRDTR_ON;
err = p_iow(chan, P_FCTRL, ctrl);
p_printf("assert DTR: %d\n", err);
p_printf("\nScan a barcode. System screen to exit.\n\n");
for (;;) { for (;;) {
/* Barcode read: buffer only, count returned in buf[0]. Blocking. */ n = p_read(chan, buf, sizeof(buf));
r = p_iow(chan, P_FREAD, buf); if (n < 0) {
if (r < 0) { p_printf("read err %d\n", n);
p_printf("read status %d\n", r);
continue; continue;
} }
cnt = buf[0]; if (n == 0)
if (cnt <= 0) {
p_printf("(empty read)\n");
continue; continue;
} p_printf("n=%d:", n);
p_printf("cnt=%d type=%d:", cnt, buf[1]); for (i = 0; i < n; i++)
for (i = 1; i <= cnt && i < 256; i++)
p_printf(" %d", buf[i]); p_printf(" %d", buf[i]);
p_printf(" \""); p_printf(" \"");
for (i = 1; i <= cnt && i < 256; i++) for (i = 0; i < n; i++)
p_putch(buf[i] >= ' ' ? buf[i] : '.'); p_putch(buf[i] >= ' ' ? buf[i] : '.');
p_printf("\"\n"); p_printf("\"\n");
} }