Skip to content

Commit

Permalink
Merge pull request #86 from arnowillig/master
Browse files Browse the repository at this point in the history
Added tcp port info to status output
  • Loading branch information
alexpevzner authored Nov 7, 2024
2 parents a77fe9b + b1c0a62 commit 0b37470
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions pnp.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ loop:
for _, addr := range added {
Log.Debug('+', "PNP %s: added", addr)
dev, err := NewDevice(devDescs[addr])
StatusSet(addr, devDescs[addr], err)
StatusSet(addr, devDescs[addr], dev.State.HTTPPort, err)

if err == nil {
devByAddr[addr] = dev
Expand Down Expand Up @@ -114,7 +114,7 @@ loop:

Log.Debug('+', "PNP %s: retry", addr)
dev, err := NewDevice(devDescs[addr])
StatusSet(addr, devDescs[addr], err)
StatusSet(addr, devDescs[addr], dev.State.HTTPPort, err)

if err == nil {
devByAddr[addr] = dev
Expand Down
12 changes: 7 additions & 5 deletions status.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
type statusOfDevice struct {
desc UsbDeviceDesc // Device descriptor
init error // Initialization error, nil if none
HTTPPort int // Assigned http port for the device
}

var (
Expand Down Expand Up @@ -87,20 +88,20 @@ func StatusFormat() []byte {
buf.WriteString(" not found\n")
} else {
buf.WriteString("\n")
fmt.Fprintf(buf, " Num Device Vndr:Prod Model\n")
fmt.Fprintf(buf, " Num Device Vndr:Prod Port Model\n")
for i, status := range devs {
info, _ := status.desc.GetUsbDeviceInfo()

fmt.Fprintf(buf, " %3d. %s %4.4x:%.4x %q\n",
fmt.Fprintf(buf, " %3d. %s %4.4x:%.4x %d %q\n",
i+1, status.desc.UsbAddr,
info.Vendor, info.Product, info.MfgAndProduct)
info.Vendor, info.Product, status.HTTPPort, info.MfgAndProduct)

s := "OK"
if status.init != nil {
s = devs[i].init.Error()
}

fmt.Fprintf(buf, " status: %s", s)
fmt.Fprintf(buf, " status: %s\n", s)
}
}

Expand All @@ -109,11 +110,12 @@ func StatusFormat() []byte {

// StatusSet adds device to the status table or updates status
// of the already known device
func StatusSet(addr UsbAddr, desc UsbDeviceDesc, init error) {
func StatusSet(addr UsbAddr, desc UsbDeviceDesc, HTTPPort int, init error) {
statusLock.Lock()
statusTable[addr] = &statusOfDevice{
desc: desc,
init: init,
HTTPPort: HTTPPort,
}
statusLock.Unlock()
}
Expand Down

0 comments on commit 0b37470

Please sign in to comment.