-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathhistorypage.go
36 lines (32 loc) · 941 Bytes
/
historypage.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
package medtronic
const (
// MaxHistoryPages is the maximum number of pump history pages.
MaxHistoryPages = 36
// Max512HistoryPages is the maximum number of pump history pages for model x12 pumps.
Max512HistoryPages = 32
)
// HistoryPage downloads the given history page.
func (pump *Pump) HistoryPage(page int) []byte {
return pump.Download(historyPage, page)
}
// LastHistoryPage returns the pump's last (oldest) history page number.
func (pump *Pump) LastHistoryPage() int {
data := pump.Execute(lastHistoryPage)
if pump.Error() != nil {
e, ok := pump.Error().(InvalidCommandError)
if ok && e.PumpError == CommandRefused && pump.Family() == 12 {
pump.SetError(nil)
return Max512HistoryPages
}
return 0
}
if len(data) < 5 || data[0] != 4 {
pump.BadResponse(lastHistoryPage, data)
return 0
}
page := fourByteUint(data[1:5])
if page >= MaxHistoryPages {
page = MaxHistoryPages - 1
}
return int(page)
}