diff --git a/code/inventory/bcode.h b/code/inventory/bcode.h new file mode 100644 index 0000000..77dfbb1 --- /dev/null +++ b/code/inventory/bcode.h @@ -0,0 +1,43 @@ +/* + * bcode.h - barcode scanner input via the Workabout serial port. + * + * On the Workabout the barcode module decodes the label in hardware and + * delivers the result as an RS232 stream, so a scan is simply read from the + * serial channel using the standard PLIB serial I/O. The scanner here is on + * the top internal slot, which is port D -> device "TTY:D". + */ +#ifndef BCODE_H +#define BCODE_H + +#include + +/* + * Terminator the scanner appends after each decoded barcode. Most serial + * barcode readers send a carriage return (0x0D). If yours sends LF or a + * different suffix, change this to match its configuration. + */ +#define BCODE_TERM 0x0D + +/* Longest decoded barcode we handle (UPC-A is 12; headroom for EAN etc.). */ +#define BCODE_MAXLEN 20 + +/* + * Open the barcode serial channel (TTY:D). Stores the channel handle in + * *pChan. Returns 0 on success or a negative PLIB error code. + */ +GLREF_C INT bcodeOpen(VOID **pChan); + +/* Close a channel opened by bcodeOpen. Safe to call with NULL. */ +GLREF_C VOID bcodeClose(VOID *chan); + +/* + * Line assembler. Feeds n freshly-read bytes from raw into the caller's line + * buffer (current length *pLen, capacity max). When BCODE_TERM is seen the + * completed, NUL-terminated barcode is left in line, *pLen is reset to 0 and + * 1 is returned. Otherwise returns 0 (more bytes needed). Control bytes below + * space (other than the terminator) are ignored; overflow bytes are dropped + * until the next terminator. + */ +GLREF_C INT bcodeAssemble(UBYTE *raw, INT n, TEXT *line, INT *pLen, INT max); + +#endif /* BCODE_H */