-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathwakeup.go
41 lines (38 loc) · 880 Bytes
/
wakeup.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package medtronic
import (
"log"
"time"
)
const (
// Older pumps should have RF enabled to increase the
// frequency with which they listen for wakeups.
numWakeups = 100
xmitDelay = 10 * time.Millisecond
wakeupTimeout = 10 * time.Second
)
// Wakeup wakes up the pump.
// It first attempts a model command, which will succeed quickly if
// the pump is already awake. If that times out, it will repeatedly
// send wakeup commands.
func (pump *Pump) Wakeup() {
pump.Model()
if pump.Error() == nil {
return
}
if !pump.NoResponse() {
return
}
pump.SetError(nil)
log.Printf("waking pump")
n := pump.Retries()
defer pump.SetRetries(n)
t := pump.Timeout()
defer pump.SetTimeout(t)
pump.SetRetries(numWakeups)
pump.SetTimeout(xmitDelay)
pump.Execute(wakeup)
pump.SetError(nil)
pump.SetRetries(1)
pump.SetTimeout(wakeupTimeout)
pump.Execute(wakeup)
}