Better error messages.
Update rawread to use the new endpoint interface.
This commit is contained in:
@@ -140,8 +140,19 @@ func main() {
|
|||||||
}
|
}
|
||||||
dev := devs[0]
|
dev := devs[0]
|
||||||
|
|
||||||
log.Printf("Connecting to endpoint %d...", *endpoint)
|
log.Printf("Setting configuration %d...", *config)
|
||||||
ep, err := dev.InEndpoint(*config, *iface, *alternate, *endpoint)
|
cfg, err := dev.Config(*config)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("dev.Config(%d): %v", *config, err)
|
||||||
|
}
|
||||||
|
log.Printf("Claiming interface %d (alt setting %d)...", *iface, *alternate)
|
||||||
|
intf, err := cfg.Interface(*iface, *alternate)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("cfg.Interface(%d, %d): %v", *iface, *alternate, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("Using endpoint %d...", *endpoint)
|
||||||
|
ep, err := intf.InEndpoint(*endpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("dev.InEndpoint(): %s", err)
|
log.Fatalf("dev.InEndpoint(): %s", err)
|
||||||
}
|
}
|
||||||
|
@@ -94,11 +94,11 @@ func (c *Config) Interface(intf, alt int) (*Interface, error) {
|
|||||||
return nil, fmt.Errorf("Interface(%d, %d) called on %s after Close", intf, alt, c)
|
return nil, fmt.Errorf("Interface(%d, %d) called on %s after Close", intf, alt, c)
|
||||||
}
|
}
|
||||||
if intf < 0 || intf >= len(c.Info.Interfaces) {
|
if intf < 0 || intf >= len(c.Info.Interfaces) {
|
||||||
return nil, fmt.Errorf("interface %d not found in %s. Interface number needs to be a 0-based index into the interface table, which has %d elements.", intf, c, len(c.Info.Interfaces))
|
return nil, fmt.Errorf("interface %d not found in %s, available interfaces 0..%d", intf, c, len(c.Info.Interfaces)-1)
|
||||||
}
|
}
|
||||||
ifInfo := c.Info.Interfaces[intf]
|
ifInfo := c.Info.Interfaces[intf]
|
||||||
if alt < 0 || alt >= len(ifInfo.AltSettings) {
|
if alt < 0 || alt >= len(ifInfo.AltSettings) {
|
||||||
return nil, fmt.Errorf("Inteface %d does not have alternate setting %d. Alt setting needs to be a 0-based index into the settings table, which has %d elements.", ifInfo, alt, len(ifInfo.AltSettings))
|
return nil, fmt.Errorf("alternate setting %d not found for %s in %s, available alt settings 0..%d", alt, ifInfo, c, len(ifInfo.AltSettings)-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
|
@@ -77,7 +77,11 @@ func (d *Device) Config(cfgNum int) (*Config, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !found {
|
if !found {
|
||||||
return nil, fmt.Errorf("configuration id %d not found in the descriptor of the device %s", cfg, d)
|
var cfgs []int
|
||||||
|
for _, c := range d.Descriptor.Configs {
|
||||||
|
cfgs = append(cfgs, c.Config)
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("configuration id %d not found in the descriptor of the device %s. Available config ids: %v", cfgNum, d, cfgs)
|
||||||
}
|
}
|
||||||
if err := libusb.setConfig(d.handle, uint8(cfgNum)); err != nil {
|
if err := libusb.setConfig(d.handle, uint8(cfgNum)); err != nil {
|
||||||
return nil, fmt.Errorf("failed to set active config %d for the device %s: %v", cfgNum, d, err)
|
return nil, fmt.Errorf("failed to set active config %d for the device %s: %v", cfgNum, d, err)
|
||||||
|
@@ -93,7 +93,7 @@ func (i *Interface) openEndpoint(epNum int) (*endpoint, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !found {
|
if !found {
|
||||||
return nil, fmt.Errorf("%s does not have endpoint number %d. Available endpoints: %v", epNum, i.Setting.Endpoints)
|
return nil, fmt.Errorf("%s does not have endpoint number %d. Available endpoints: %v", i, epNum, i.Setting.Endpoints)
|
||||||
}
|
}
|
||||||
return &endpoint{
|
return &endpoint{
|
||||||
InterfaceSetting: i.Setting,
|
InterfaceSetting: i.Setting,
|
||||||
|
Reference in New Issue
Block a user