68 lines
1.4 KiB
Go
68 lines
1.4 KiB
Go
package usb
|
|
|
|
import (
|
|
"errors"
|
|
enumerator2 "github.com/albenik/go-serial/v2/enumerator"
|
|
"github.com/go-playground/log/v8"
|
|
)
|
|
|
|
/*
|
|
USB Product IDs of the SCS devices:
|
|
0xD010 SCS PTC-IIusb
|
|
0xD011 SCS Tracker / DSP TNC
|
|
0xD012 SCS P4dragon DR-7800
|
|
0xD013 SCS P4dragon DR-7400
|
|
0xD014 - not used
|
|
0xD015 SCS PTC-IIIusb
|
|
0xD016 - not used
|
|
0xD017 - not used
|
|
*/
|
|
|
|
type Scsid struct {
|
|
Port, id, Name string
|
|
Baudrate int
|
|
}
|
|
|
|
var scsids map[string]string = map[string]string{
|
|
"d010": "SCS PTC-IIusb",
|
|
"d011": "SCS Tracker / DSP TNC",
|
|
"d012": "SCS P4dragon DR-7800",
|
|
"d013": "SCS P4dragon DR-7400",
|
|
"d015": "SCS PTC-IIIusb"}
|
|
|
|
var scsbaudrates map[string]int = map[string]int{
|
|
"d010": 115200,
|
|
"d011": 38400,
|
|
"d012": 829400,
|
|
"d013": 829400,
|
|
"d015": 115200}
|
|
|
|
func FindSCS() ([]Scsid, error) {
|
|
|
|
foundids := []Scsid{}
|
|
|
|
ports, err := enumerator2.GetDetailedPortsList()
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if len(ports) == 0 {
|
|
return nil, errors.New("No serial ports found")
|
|
}
|
|
|
|
for _, port := range ports {
|
|
log.Debugf("Found Port: %s", port.Name)
|
|
if port.IsUSB {
|
|
// fmt.Printf(" USB ID %s:%s\n", Port.VID, Port.PID)
|
|
// fmt.Printf(" USB serial %s\n", Port.SerialNumber)
|
|
if port.VID == "0403" {
|
|
if _, ok := scsids[port.PID]; ok {
|
|
foundids = append(foundids, Scsid{Port: port.Name, id: port.PID, Name: scsids[port.PID], Baudrate: scsbaudrates[port.PID]})
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return foundids, nil
|
|
|
|
}
|