2026-07-06 17:41:44 +01:00
|
|
|
/*
|
|
|
|
|
* scan.c - Phase 1 inventory demo: scan UPC barcodes and display them.
|
|
|
|
|
*
|
2026-07-06 17:51:17 +01:00
|
|
|
* 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.
|
2026-07-06 17:41:44 +01:00
|
|
|
*
|
2026-07-06 17:51:17 +01:00
|
|
|
* (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.
|
2026-07-06 17:41:44 +01:00
|
|
|
*/
|
|
|
|
|
#include <plib.h>
|
|
|
|
|
#include "bcode.h"
|
|
|
|
|
#include "upc.h"
|
|
|
|
|
|
|
|
|
|
GLDEF_C INT main(VOID)
|
|
|
|
|
{
|
2026-07-06 17:51:17 +01:00
|
|
|
VOID *bchan;
|
|
|
|
|
UBYTE raw[BCODE_MAXLEN];
|
|
|
|
|
TEXT line[BCODE_MAXLEN];
|
2026-07-06 17:41:44 +01:00
|
|
|
INT lineLen = 0;
|
2026-07-06 17:51:17 +01:00
|
|
|
INT err, n, textLen;
|
2026-07-06 17:41:44 +01:00
|
|
|
|
|
|
|
|
if ((err = bcodeOpen(&bchan)) < 0) {
|
|
|
|
|
p_printf("Cannot open barcode port TTY:D (err %d)\n", err);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p_printf("Inventory scan demo\n");
|
2026-07-06 17:51:17 +01:00
|
|
|
p_printf("Scan UPC barcodes. Exit via the System screen.\n\n");
|
2026-07-06 17:41:44 +01:00
|
|
|
|
2026-07-06 17:51:17 +01:00
|
|
|
for (;;) {
|
|
|
|
|
n = p_read(bchan, raw, sizeof(raw)); /* blocks until bytes arrive */
|
|
|
|
|
if (n < 0) {
|
|
|
|
|
p_printf("read error %d\n", n);
|
2026-07-06 17:41:44 +01:00
|
|
|
continue;
|
|
|
|
|
}
|
2026-07-06 17:51:17 +01:00
|
|
|
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);
|
2026-07-06 17:41:44 +01:00
|
|
|
}
|
|
|
|
|
}
|
2026-07-06 17:51:17 +01:00
|
|
|
/* not reached in this diagnostic build */
|
2026-07-06 17:41:44 +01:00
|
|
|
}
|