feat: add -c, -V, add manpage

This commit is contained in:
s3lph 2024-11-30 21:39:50 +01:00
parent c26b55a06e
commit 4d9be10dd9
Signed by: s3lph
GPG key ID: 0AA29A52FB33CFB5
4 changed files with 90 additions and 39 deletions

View file

@ -16,12 +16,15 @@ jobs:
run: |
mkdir -p \
package/debian/honeywell-config/usr/bin \
package/debian/honeywell-config/usr/lib/udev/rules.d/
package/debian/honeywell-config/usr/lib/udev/rules.d/ \
package/debian/honeywell-config/usr/share/man/man1/
sed -re "s/__VERSION__/0.$(git rev-list --count ${GITHUB_REF_NAME})-1/g" -i package/debian/honeywell-config/DEBIAN/control
apt install --yes libusb-1.0-0-dev
apt install --yes libusb-1.0-0-dev help2man
make
strip honeywell-config
cp honeywell-config package/debian/honeywell-config/usr/bin
PATH=$PATH:. help2man -N -v -V -h -h ./honeywell-config > package/debian/honeywell-config/usr/share/man/man1/honeywell-config.1
gzip -9n package/debian/honeywell-config/usr/share/man/man1/honeywell-config.1
cp 99-honeywell.rules package/debian/honeywell-config/usr/lib/udev/rules.d/
find package/debian/honeywell-config -exec touch -m -d "$(git log -1 --format="%aI")" {} \;
cd package/debian/

View file

@ -1,11 +1,17 @@
CC := gcc
REVISION != git rev-list --count HEAD
CCFLAGS := -D_VERSION='"'0.$(REVISION)'"' -Wall -Werror
LIB := -lusb-1.0
.PHONY: honeywell-config debug clean
honeywell-config:
gcc -Wall -Werror -o honeywell-config honeywell-config.c -lusb-1.0
$(CC) $(CCFLAGS) -o honeywell-config honeywell-config.c $(LIB)
debug:
gcc -Wall -Werror -O0 -ggdb3 -o honeywell-config honeywell-config.c -lusb-1.0
$(CC) $(CCFLAGS) -O0 -ggdb3 -o honeywell-config honeywell-config.c $(LIB)
clean:
rm -f honeywell-config

View file

@ -19,15 +19,17 @@ First of all, compile the program using `make`. It depends only on `libusb-1.0`
The configuration commands can be provided either as CLI arguments or via stdin; if CLI commands are present, stdin is ignrored.
```
Usage: ./honeywell-config [-v vendor] [-p product] [-1] [-r] [-d] [-i infile] [-o outfile] [command1 [... commandN]]
honeywell-config [-v vendor] [-p product] [-1] [-c] [-r] [-d] [-i infile] [-o outfile] [command1 [... commandN]]
-v vendor USB vendor ID of the barcode scanner
-p product USB product ID of the barcode scanner
-p product USB product ID of the barcode scanner
-1 Print response on one line, rather than one token per line
-c Print only received commands that contain an argument. Useful for config backups.
-r Reset device after configuration
-d Debug mode (more verbose output)
-i infile Read input from infile instead of stdin
-o outfile Write output to outfile instead of stdout
-h Show this help
-V Show the version number
```
If no vendor ID or product ID is provided, the following set of IDs is tried:
@ -40,66 +42,89 @@ USB serial mode (`0c2e:0b0a`) is skipped because USB configuration does not seem
For the actual configuration commands, please refer to your scanner's manual. Here are some examples.
### Dump Current Config
### Dump & Restore Config
When invoked without any command or input file, the command `?.` is run, which dumps the current config of the barcode scanner:
When invoked without any command or input file, the command `?.` is run, which asks the barcode scanner for all known config commands and their current value.
Please not that this dump can not be restored as-is - it contains some commands that are not really config options, among them the factor reset commands `DEFOVR.` and `DEFALT.`
To only retrieve the config commands that have a value associated with them, use the `-c` flag. You can additionally write the configuration to a textfile using `-o`:
```shell-session
$ ./honeywell-config
$ honeywell-config -c -o scanner.conf
```
This configuration can be restored the the scanner by providing it as an input file using `-i`. Each sent config command should be acknowledged
- `0c2e:0b01` (Honeywell 1300G, USB Kkeyboard mode PC)
- `0c2e:0b02` (Honeywell 1300G, USB Keyboard Apple)
- `0c2e:0b07` (Honeywell 1300G, USB HID POS mode)
USB serial mode (`0c2e:0b0a`) is skipped because USB configuration does not seem to work for it (and it isn't found by EZconfig either).
by the scanner and printed to stdout:
```shell-session
$ honeywell-config -i scanner.conf
BEPFQ12550.
BEPFQ2100.
...
AXXMOD0.
```
Please not that this dump can not be restored as-is - it contains some commands that are not really config options, among them the factor reset commands `DEFOVR.` and `DEFALT.`
### Retrieve Firmware Version and Build Date
```shell-session
$ ./honeywell-config 'REV?'
REV_SW13718|/tags/BE000186BAA,_TDFeb 11 2014,_WABE000186BAA,INF.
$ honeywell-config REVINF
REVINFProduct Name: Hyperion-1300
Boot Revision: BE000038BAD
Software Part Number: BE000186BAA
Software Revision: 13718|/tags/BE000186BAA
Serial Number: 14143B0807
Supported IF: Standard
PCB Assembly ID: 0
.
```
### Factory Reset
```shell-session
$ ./honeywell-config DEFOVR DEFALT
$ honeywell-config DEFOVR DEFALT
DEFOVR.
DEFALT.
```
### Switch Operation Mode
### Switch Operation Mode ("Plug-and-Play Mode")
USBHID:
```shell-session
$ ./honeywell-config PAP131
$ honeywell-config PAP131
PAP131.
```
Keyboard (PC):
```shell-session
$ ./honeywell-config PAP124
$ honeywell-config PAP124
PAP124.
```
Keyboard (Apple):
```shell-session
$ ./honeywell-config PAP125
$ honeywell-config PAP125
PAP124.
```
Please note that when switching modes, the scanner restarts on its own, so some error messages are to be expected.
The following caveats exist:
- When switching modes, the scanner restarts on its own, so some error messages are to be expected.
- When switching to serial console mode (`PAP130`), this tool can no longer configure it via USB (and neither can EZConfig).
### Add Prefix to Output
The following adds the string `FCKAFD ` (ASCII hex `46 43 4B 41 46 44 20`) in front of every scanned barcode:
```shell-session
$ ./honeywell-config PREBK29946434B41464420
$ honeywell-config PREBK29946434B41464420
PREBK29946434B41464420.
```
@ -121,14 +146,14 @@ On the USB config interface, all of that goes into a single string instead.
### Query Current Beeper Settings
```
$ ./honeywell-config 'BEP?'
$ honeywell-config 'BEP?'
BEPFQ12550,FQ2100,RPT1,ERR1,BEP1,BIP0,LVL0,EXZ,GRX,EXE,DFT,LED1.
```
### List all Settings and Their Possible Values
```
$ ./honeywell-config '*.'
$ honeywell-config '*'
BEPFQ1100-5000.
BEPFQ2100-5000.
...

View file

@ -7,11 +7,15 @@
#include <libusb-1.0/libusb.h>
#ifndef _VERSION
#define _VERSION "none"
#endif
#define S_ENQ 0x05
#define S_ACK 0x06
#define S_NAK 0x15
#define ISSTATUS(c) (*c == S_ENQ || *c == S_ACK || *c == S_NAK)
#define USBERR(msg, rc) { dprintf(2, "%s: %s\n", msg, libusb_strerror(rc)); }
#define DEBUG(...) { if (debug >= 1) { dprintf(2, __VA_ARGS__); } }
#define DEBUG2(...) { if (debug >= 2) { dprintf(2, __VA_ARGS__); } }
@ -23,6 +27,7 @@ uint16_t vendor_id = 0;
uint16_t product_id = 0;
uint8_t reset = 0;
uint8_t oneline = 0;
uint8_t onlyargs = 0;
uint8_t debug = 0;
int infd = 0;
int outfd = 1;
@ -70,11 +75,11 @@ int tok_read(struct tokenizer *t, char *buf, size_t n) {
}
if (end) {
if (end > start) {
for (char *c = start; c < end < buf+n; ++c) {
if (isprint(*c)) {
*(t->tok++) = *c;
} else {
for (char *c = start; c < end; ++c) {
if (ISSTATUS(c)) {
t->status = *c;
} else {
*(t->tok++) = *c;
}
}
}
@ -93,10 +98,10 @@ int tok_read(struct tokenizer *t, char *buf, size_t n) {
*end = 0;
}
for (char *c = start; *c != 0; ++c) {
if (isprint(*c)) {
*(t->tok++) = *c;
} else {
if (ISSTATUS(c)) {
t->status = *c;
} else {
*(t->tok++) = *c;
}
}
*(t->tok) = 0;
@ -113,6 +118,9 @@ struct tokenizer out_tok;
int print_token(const char *tok, uint8_t status, uint8_t last) {
switch (status) {
case S_ACK:
if (onlyargs && (strlen(tok) <= 6 || !strncmp("REV", tok, 3))) {
return 0;
}
int rc;
if (oneline && !last) {
rc = dprintf(outfd, "%s;", tok);
@ -408,7 +416,7 @@ int main(int argc, char **argv) {
int opt;
char *end;
long parsed;
while ((opt = getopt(argc, argv, "v:p:1rdi:o:h")) != -1) {
while ((opt = getopt(argc, argv, "v:p:1crdi:o:hV")) != -1) {
switch (opt) {
case 'v':
end = optarg;
@ -442,6 +450,9 @@ int main(int argc, char **argv) {
case '1':
oneline = 1;
break;
case 'c':
onlyargs = 1;
break;
case 'd':
++debug;
break;
@ -468,16 +479,22 @@ int main(int argc, char **argv) {
}
}
break;
case 'V':
puts(_VERSION);
exit(0);
break;
default:
printf("Usage: %s [-v vendor] [-p product] [-1] [-r] [-d] [-i infile] [-o outfile] [command1 [... commandN]]\n", argv[0]);
puts(" -v vendor\tUSB vendor ID of the barcode scanner");
puts(" -p product\tUSB product ID of the barcode scanner");
puts(" -1\t\tPrint response on one line, rather than one token per line");
puts(" -r\t\tReset device after configuration");
puts(" -d\t\tDebug mode (more verbose output)");
puts(" -i infile\tRead input from infile instead of stdin");
puts(" -o outfile\tWrite output to outfile instead of stdout");
puts(" -h \t\tShow this help");
printf("%s [-v vendor] [-p product] [-1] [-c] [-r] [-d] [-i infile] [-o outfile] [command1 [... commandN]]\n", argv[0]);
puts(" -v vendor\tUSB vendor ID of the barcode scanner to configure.");
puts(" -p product\tUSB product ID of the barcode scanner to configure.");
puts(" -1\t\tPrint response on one line, rather than one token per line.");
puts(" -c\t\tPrint only received commands that contain an argument. Useful for config backups.");
puts(" -r\t\tReset device after configuration.");
puts(" -d\t\tDebug mode (more verbose output). Can be provided repeatedly to increase verbosity.");
puts(" -i infile\tRead input from infile instead of stdin.");
puts(" -o outfile\tWrite output to outfile instead of stdout.");
puts(" -h \t\tShow this help and exit.");
puts(" -V \t\tShow the version number and exit.");
return 1;
}
}