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 5dce1ae794 - Show all commits
+29 -39
View File
@@ -1,58 +1,48 @@
/*
* scan.c - Phase 1 inventory demo: scan UPC barcodes and display them.
* scan.c - Phase 1 barcode diagnostic for the Workabout MX integral laser.
*
* Blocking design: the app opens the barcode serial channel (TTY:D) and reads
* it with a blocking p_read, assembling bytes until the scanner's terminator,
* then validates and prints each barcode. Exit via the System screen.
* Loads the EAN/UPC decoder LDD (BAREAN.LDD), opens the decoder device (BAR:)
* and dumps every byte of each read: the decimal value of each byte plus a
* printable rendering. This shows exactly what the decoder delivers for a UPC
* (length, any prefix/type byte, terminator) so the reader and Phase 2 key
* format can be built on fact rather than assumption.
*
* (An earlier version waited on the keyboard asynchronously via CON: so Esc
* could quit; that panicked the Window Server - on SIBO the keyboard is
* event-driven through the window server, not a raw CON: byte read. A proper
* scan-or-key loop needs the Window Server event API, whose reference manual
* is not among the SDK docs in this repo. Blocking output via p_printf is
* fine, so this version sticks to that.)
*
* This also serves as the format diagnostic: it prints the byte length of each
* decoded barcode alongside the text, so we can see exactly what the scanner
* emits for a UPC (12 vs 13 digits, any prefix/suffix) before Phase 2 uses it
* as a database key.
* Blocking reads; exit via the System screen.
*/
#include <plib.h>
#include "bcode.h"
#include "upc.h"
GLDEF_C INT main(VOID)
{
VOID *bchan;
UBYTE raw[BCODE_MAXLEN];
TEXT line[BCODE_MAXLEN];
INT lineLen = 0;
INT err, n, textLen;
VOID *chan;
UBYTE buf[64];
INT err, n, i;
if ((err = bcodeOpen(&bchan)) < 0) {
p_printf("Cannot open barcode port TTY:D (err %d)\n", err);
err = bcodeLoad();
/* 0 = loaded now; E_FILE_EXIST = already loaded. Anything else is a problem
(e.g. E_FILE_NXIST = BAREAN.LDD not found on the device). */
p_printf("load %s.LDD: %d\n", BCODE_LDD, err);
if ((err = bcodeOpen(&chan)) < 0) {
p_printf("open %s failed: %d\n", BCODE_DEV, err);
return 1;
}
p_printf("Inventory scan demo\n");
p_printf("Scan UPC barcodes. Exit via the System screen.\n\n");
p_printf("%s open. Scan a barcode.\n\n", BCODE_DEV);
for (;;) {
n = p_read(bchan, raw, sizeof(raw)); /* blocks until bytes arrive */
n = p_read(chan, buf, sizeof(buf));
if (n < 0) {
p_printf("read error %d\n", n);
p_printf("read err %d\n", n);
continue;
}
if (bcodeAssemble(raw, n, line, &lineLen, BCODE_MAXLEN)) {
textLen = 0;
while (line[textLen] != '\0')
textLen++;
/* Diagnostic: length + text + validity. */
if (upcIsValid(line))
p_printf("len=%d [%s] OK\n", textLen, line);
else
p_printf("len=%d [%s] BAD\n", textLen, line);
if (n == 0)
continue;
p_printf("n=%d:", n);
for (i = 0; i < n; i++)
p_printf(" %d", buf[i]);
p_printf(" \"");
for (i = 0; i < n; i++)
p_putch(buf[i] >= ' ' ? buf[i] : '.');
p_printf("\"\n");
}
}
/* not reached in this diagnostic build */
}