Add an auto-measure toggle with a cable length range, and console keys through the harness

This commit is contained in:
flamingcow
2026-08-30 19:10:00 -07:00
parent 36c2ff34fe
commit 5a74fe0c76
6 changed files with 188 additions and 41 deletions
+50 -5
View File
@@ -267,7 +267,7 @@ type cableInfo struct {
haveMaps [2]bool
}
func (c cableInfo) metresString() string {
func (c cableInfo) metresValue() (int, bool) {
sum, n := 0, 0
for i, v := range c.ecd.verdicts {
if v == pairOK {
@@ -276,9 +276,39 @@ func (c cableInfo) metresString() string {
}
}
if n == 0 {
return 0, false
}
return (sum + n/2) / n, true
}
func (c cableInfo) metresString() string {
m, ok := c.metresValue()
if !ok {
return "-"
}
return fmt.Sprintf("%d", (sum+n/2)/n)
return fmt.Sprintf("%d", m)
}
type cableRange struct {
have bool
min, max int
}
func (r *cableRange) add(m int) {
if !r.have || m < r.min {
r.min = m
}
if !r.have || m > r.max {
r.max = m
}
r.have = true
}
func (r cableRange) String() string {
if r.min == r.max {
return fmt.Sprintf("%d", r.min)
}
return fmt.Sprintf("%d-%d", r.min, r.max)
}
const (
@@ -348,7 +378,7 @@ func cableSummary(cable cableInfo, measuring bool) (string, int) {
// The margin is the worst pair across the ends that measure SNR (the Wiitek's
// IEEE 1.133–136), gated on the whole pair being fresh and linked.
func phyDisplayFrom(cable cableInfo, measuring bool, a, b phyModView) phyDisplay {
func phyDisplayFrom(cable cableInfo, rng cableRange, measuring bool, a, b phyModView) phyDisplay {
d := phyDisplay{
haveSNR: a.fresh && b.fresh && a.link && b.link && (a.haveSNR || b.haveSNR),
corrected: a.blocks + a.ber + a.retrain + b.blocks + b.ber + b.retrain,
@@ -369,6 +399,9 @@ func phyDisplayFrom(cable cableInfo, measuring bool, a, b phyModView) phyDisplay
}
}
d.metres, d.metresClass = cableSummary(cable, measuring)
if d.metresClass == clsGood && rng.have {
d.metres = rng.String()
}
return d
}
@@ -444,16 +477,23 @@ type cableDiag struct {
mu sync.Mutex
info cableInfo
rng cableRange
}
func newCableDiag(mods []*phyModule, info cableInfo) *cableDiag {
return &cableDiag{mods: mods, info: info}
}
func (c *cableDiag) snapshot() (cableInfo, bool) {
func (c *cableDiag) snapshot() (cableInfo, cableRange, bool) {
c.mu.Lock()
defer c.mu.Unlock()
return c.info, c.measuring.Load()
return c.info, c.rng, c.measuring.Load()
}
func (c *cableDiag) resetRange() {
c.mu.Lock()
c.rng = cableRange{}
c.mu.Unlock()
}
// A measure that errors means the diag transport or the µC is broken, and a
@@ -471,6 +511,11 @@ func (c *cableDiag) kick(done *atomic.Bool) bool {
}
c.mu.Lock()
c.info = info
if _, cls := cableSummary(info, false); cls == clsGood {
if m, ok := info.metresValue(); ok {
c.rng.add(m)
}
}
c.mu.Unlock()
c.measuring.Store(false)
}()