Explain why we use gousb directly instead of antgo/driver/usb
(libusb context leak on error paths), document the defer cleanup
ordering, and note that errors are returned for graceful retry.
ant: replace usb.GetDevice with direct gousb usage
Remove dependency on antgo/driver/usb to fix libusb context leaks on
device-not-found errors. The previous code called usb.GetDevice which
creates a gousb.Context via libusb_init but leaks it on every error
path (device not found, interface claim failure, etc.). Calling
ListenForTrainer repeatedly (e.g. starting with no dongle and plugging
it in later) triggered a libusb assertion in pthread_key_create because
the leaked contexts were never torn down.
Replace with direct gousb calls in ListenForTrainer, managing the
gousb.Context lifecycle explicitly. Cleanup is ordered correctly on
all paths: release interface, close device, close context, cancel
the ANT message goroutine context.
Also convert panics to returned errors for graceful retry.
When --device is omitted or set to 0, the bridge listens to all
broadcasting ANT+ trainers instead of filtering by a specific device.
The actual transmitting device ID is shown in data logs, allowing
users to discover and then filter specific trainers.
Also fix vendorID/productID not being assigned to config struct
which caused ListenForTrainer to receive 0 for both values.
- Add BLE spec constants for service/characteristic UUIDs and signal flag
- Add ANT+ spec constants for data page mask and cycling power page
- Add descriptive comments explaining each constant's origin and purpose
- Add mutex to prevent interleaved log output from concurrent goroutines
- Make logMsg delegate to logPrintf for consistent synchronization
- Buffer events channel to size 1 with select/drop when full
- Close events channel on ListenForTrainer exit so process terminates
Introduce structured CLI argument parsing using Cobra with three
configurable flags:
--vendor: USB vendor ID (default: 0x0fcf)
--product: USB product ID (default: 0x1008)
--device: ANT+ device number (default: 3001)
Add timestamped logging for all log statements with format
YYYY-MM-DD HH:MM:SS. Log vendor, product, and device values at
startup in both hex and decimal.
Remove hardcoded USB identifiers from main.go and consolidate all
startup logic into cli.go with a dedicated Config struct.
Update ant.go ListenForTrainer signature to accept uint16 for
vendor and product IDs.