feat: make --device flag optional with 'any' default
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.
This commit is contained in:
+2
-2
@@ -56,8 +56,8 @@ func ListenForTrainer(vendorId uint16, productId uint16, deviceNumber uint32,
|
||||
|
||||
logMsg("ant: listening...")
|
||||
for msg := range msgs {
|
||||
if msg.DeviceNumber() != deviceNumber {
|
||||
logPrintf("Received msg from ignored ant+ device %v\n", msg.DeviceNumber())
|
||||
if deviceNumber != 0 && msg.DeviceNumber() != deviceNumber {
|
||||
logPrintf("ant: received msg from ignored device %v\n", msg.DeviceNumber())
|
||||
continue
|
||||
}
|
||||
//fmt.Printf("raw msg: device type=0x%02x device number=%d content=%x\n",
|
||||
|
||||
+15
-8
@@ -52,19 +52,26 @@ This allows these trainers to be used with modern devices that don't support ANT
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid --product %q: %w", c.product, err)
|
||||
}
|
||||
deviceNumber, err := parseHex(c.device, 32)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid --device %q: %w", c.device, err)
|
||||
c.vendorID = uint64(vendorID)
|
||||
c.productID = uint64(productID)
|
||||
if c.device != "" {
|
||||
deviceNumber, err := parseHex(c.device, 32)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid --device %q: %w", c.device, err)
|
||||
}
|
||||
c.deviceNumber = uint32(deviceNumber)
|
||||
}
|
||||
|
||||
c.vendorID = vendorID
|
||||
c.productID = productID
|
||||
c.deviceNumber = uint32(deviceNumber)
|
||||
deviceNumber := c.deviceNumber
|
||||
|
||||
logMsgf("ANT Bridge %s built %s", Version, BuildTime)
|
||||
logMsgf("usb: vendor: 0x%04x/%d", vendorID, vendorID)
|
||||
logMsgf("usb: product: 0x%04x/%d", productID, productID)
|
||||
logMsgf("ant: device: 0x%03x/%d", deviceNumber, deviceNumber)
|
||||
if deviceNumber == 0 {
|
||||
logMsgf("ant: device: any")
|
||||
} else {
|
||||
logMsgf("ant: device: 0x%03x/%d", deviceNumber, deviceNumber)
|
||||
}
|
||||
|
||||
if err := exec.Command("hciconfig", "hci0", "down").Run(); err != nil {
|
||||
logPrintf("bt: hciconfig down failed: %v\n", err)
|
||||
@@ -83,7 +90,7 @@ This allows these trainers to be used with modern devices that don't support ANT
|
||||
|
||||
rootCmd.Flags().String("vendor", "0x0fcf", "USB vendor ID (hex, e.g. 0x0fcf)")
|
||||
rootCmd.Flags().String("product", "0x1008", "USB product ID (hex, e.g. 0x1008)")
|
||||
rootCmd.Flags().String("device", "3001", "ANT+ device number (hex or decimal, e.g. 3001 or 0xbb9)")
|
||||
rootCmd.Flags().String("device", "", "ANT+ device number (hex or decimal). Use 0 or omit to listen to all devices")
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user