From 41202888e19fae4f8bb38d484464ce5af7be2dff Mon Sep 17 00:00:00 2001 From: lyrathorpe Date: Mon, 6 Jul 2026 17:41:44 +0100 Subject: [PATCH] feat(inventory): add bcode.c (Phase 1: scan + UPC validation) --- code/inventory/bcode.c | 46 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 code/inventory/bcode.c diff --git a/code/inventory/bcode.c b/code/inventory/bcode.c new file mode 100644 index 0000000..f9bff1f --- /dev/null +++ b/code/inventory/bcode.c @@ -0,0 +1,46 @@ +/* + * bcode.c - barcode scanner serial channel (see bcode.h). + */ +#include "bcode.h" + +GLDEF_C INT bcodeOpen(VOID **pChan) +{ + /* + * TTY:D = the top internal slot's serial port, where the barcode module + * sits. mode -1 asks the driver for its default open mode. + * + * If the scanner needs specific line settings (baud rate, parity, stop + * bits), configure the channel after opening with + * p_iow(*pChan, P_FSET, &config); + * where config is an E_CONFIG struct from p_config.h. See the RS232 + * section of the PLIB Reference. The module runs at up to 9600 baud. + */ + return p_open(pChan, "TTY:D", (UINT)-1); +} + +GLDEF_C VOID bcodeClose(VOID *chan) +{ + if (chan != NULL) + p_close(chan); +} + +GLDEF_C INT bcodeAssemble(UBYTE *raw, INT n, TEXT *line, INT *pLen, INT max) +{ + INT i; + + for (i = 0; i < n; i++) { + UBYTE c = raw[i]; + + if (c == BCODE_TERM) { + line[*pLen] = '\0'; + *pLen = 0; + return 1; + } + if (c < ' ') /* skip LF, NULs and other control bytes */ + continue; + if (*pLen < max - 1) + line[(*pLen)++] = (TEXT)c; + /* else: overflow - drop until the next terminator */ + } + return 0; +}