forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
device_information.go
77 lines (63 loc) · 2.01 KB
/
device_information.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package ble
import (
"bytes"
"github.com/hybridgroup/gobot"
)
var _ gobot.Driver = (*BLEDeviceInformationDriver)(nil)
type BLEDeviceInformationDriver struct {
name string
connection gobot.Connection
gobot.Eventer
}
// NewBLEDeviceInformationDriver creates a BLEDeviceInformationDriver
// by name
func NewBLEDeviceInformationDriver(a *BLEClientAdaptor, name string) *BLEDeviceInformationDriver {
n := &BLEDeviceInformationDriver{
name: name,
connection: a,
Eventer: gobot.NewEventer(),
}
return n
}
func (b *BLEDeviceInformationDriver) Connection() gobot.Connection { return b.connection }
func (b *BLEDeviceInformationDriver) Name() string { return b.name }
// adaptor returns BLE adaptor for this device
func (b *BLEDeviceInformationDriver) adaptor() *BLEClientAdaptor {
return b.Connection().(*BLEClientAdaptor)
}
// Start tells driver to get ready to do work
func (b *BLEDeviceInformationDriver) Start() (errs []error) {
return
}
// Halt stops driver (void)
func (b *BLEDeviceInformationDriver) Halt() (errs []error) { return }
func (b *BLEDeviceInformationDriver) GetModelNumber() (model string) {
c, _ := b.adaptor().ReadCharacteristic("180a", "2a24")
buf := bytes.NewBuffer(c)
val := buf.String()
return val
}
func (b *BLEDeviceInformationDriver) GetFirmwareRevision() (revision string) {
c, _ := b.adaptor().ReadCharacteristic("180a", "2a26")
buf := bytes.NewBuffer(c)
val := buf.String()
return val
}
func (b *BLEDeviceInformationDriver) GetHardwareRevision() (revision string) {
c, _ := b.adaptor().ReadCharacteristic("180a", "2a27")
buf := bytes.NewBuffer(c)
val := buf.String()
return val
}
func (b *BLEDeviceInformationDriver) GetManufacturerName() (manufacturer string) {
c, _ := b.adaptor().ReadCharacteristic("180a", "2a29")
buf := bytes.NewBuffer(c)
val := buf.String()
return val
}
func (b *BLEDeviceInformationDriver) GetPnPId() (model string) {
c, _ := b.adaptor().ReadCharacteristic("180a", "2a50")
buf := bytes.NewBuffer(c)
val := buf.String()
return val
}