Checksumming and USB port searching works

This commit is contained in:
2021-12-12 20:27:38 +01:00
parent 7c7593c601
commit 3f1fdd21fe
6 changed files with 206 additions and 41 deletions

67
usb/usb.go Normal file
View File

@@ -0,0 +1,67 @@
package usb
import (
"errors"
"fmt"
"github.com/albenik/go-serial/enumerator"
"log"
)
/*
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 := enumerator.GetDetailedPortsList()
if err != nil {
log.Fatal(err)
return nil, err
}
if len(ports) == 0 {
return nil, errors.New("No serial ports found")
}
for _, port := range ports {
fmt.Printf("Found Port: %s\n", 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
}