Checksumming and USB port searching works
This commit is contained in:
48
main.go
48
main.go
@@ -1,5 +1,51 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/akamensky/argparse"
|
||||
"go-scsupdate/firmware"
|
||||
"go-scsupdate/usb"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
lsusb()
|
||||
parser := argparse.NewParser("go-scsupdate", "Update Firmware of SCS PACTOR modems")
|
||||
serialDevice := parser.String("s", "serialDevice", &argparse.Options{Required: false, Help: "(optional) serial device the modem is attached to, e.g. /dev/ttyUSB0. If not set, go-scsupdate will search for SCS modems."})
|
||||
_ = parser.String("b", "baudrate", &argparse.Options{Required: false, Help: "(optional) sets the serial baudrate, e.g. 115200"})
|
||||
f := parser.String("f", "file", &argparse.Options{Required: false, Help: "(required) the file to flash, e.g. profi41r.pro"})
|
||||
err := parser.Parse(os.Args)
|
||||
if err != nil {
|
||||
fmt.Print(parser.Usage(err))
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Println(*serialDevice)
|
||||
var ports []usb.Scsid
|
||||
if *serialDevice == "" {
|
||||
if ports, err = usb.FindSCS(); err == nil {
|
||||
fmt.Println(ports)
|
||||
if len(ports) == 0 {
|
||||
fmt.Println("Found no SCS modem.")
|
||||
//os.Exit(1)
|
||||
}
|
||||
if len(ports) != 1 {
|
||||
fmt.Println("Found more than one SCS modem. You need to choose one with the -s flag.\nfound: ")
|
||||
for _, p := range ports {
|
||||
fmt.Printf("Port: %30s : Name: %s\n", p.Port, p.Name)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fmt.Println("Error while seaching SCS modems: ", err)
|
||||
}
|
||||
}
|
||||
|
||||
if !firmware.FwExists(*f) {
|
||||
fmt.Printf("Error: firmware file %s does not exist.\n", *f)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if !firmware.ChkHeader(*f) {
|
||||
os.Exit(1)
|
||||
} else {
|
||||
fmt.Println("all ok")
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user