-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcgm.go
41 lines (35 loc) · 869 Bytes
/
cgm.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 dexcom provides functions to access a Dexcom G4 Share
CGM receiver over a BLE or USB connection.
Based on the Python version at github.com/bewest/decoding-dexcom
*/
package dexcom
// Connection is the interface satisfied by a CGM connection.
type Connection interface {
Send([]byte) error
Receive([]byte) error
Close()
}
// CGM represents a CGM connection.
type CGM struct {
Connection
err error
}
// Open first attempts to open a USB connection;
// if that fails it tries a BLE connection.
func Open() *CGM {
conn, err := OpenUSB()
if err == nil {
return &CGM{Connection: conn}
}
conn, err = OpenBLE()
return &CGM{Connection: conn, err: err}
}
// Error returns the error state of the CGM.
func (cgm *CGM) Error() error {
return cgm.err
}
// SetError sets the error state of the CGM.
func (cgm *CGM) SetError(err error) {
cgm.err = err
}