You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
550 B
24 lines
550 B
|
2 months ago
|
package serial
|
||
|
|
|
||
|
|
import "time"
|
||
|
|
|
||
|
|
// Allow several normal four-second sweeps to recover from a slow/noisy reply.
|
||
|
|
// A CR timeout alone cannot establish physical cable disconnection.
|
||
|
|
const CRResponseGracePeriod = 15 * time.Second
|
||
|
|
|
||
|
|
func CRConnectionStatus(probe CRProbeState, now time.Time) string {
|
||
|
|
if !probe.Enabled {
|
||
|
|
return "unknown"
|
||
|
|
}
|
||
|
|
if probe.Up {
|
||
|
|
return "up"
|
||
|
|
}
|
||
|
|
if probe.EverUp && probe.LastResponseAt != nil {
|
||
|
|
age := now.Sub(*probe.LastResponseAt)
|
||
|
|
if age >= 0 && age <= CRResponseGracePeriod {
|
||
|
|
return "up"
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return "unknown"
|
||
|
|
}
|