forked from hybridgroup/gobot
/
device_information_driver.go
87 lines (71 loc) · 2.46 KB
/
device_information_driver.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
78
79
80
81
82
83
84
85
86
87
package ble
import (
"bytes"
"gobot.io/x/gobot"
)
// DeviceInformationDriver represents the Device Information Service for a BLE Peripheral
type DeviceInformationDriver struct {
name string
connection gobot.Connection
gobot.Eventer
}
// NewDeviceInformationDriver creates a DeviceInformationDriver
func NewDeviceInformationDriver(a BLEConnector) *DeviceInformationDriver {
n := &DeviceInformationDriver{
name: gobot.DefaultName("DeviceInformation"),
connection: a,
Eventer: gobot.NewEventer(),
}
return n
}
// Connection returns the Driver's Connection to the associated Adaptor
func (b *DeviceInformationDriver) Connection() gobot.Connection { return b.connection }
// Name returns the Driver name
func (b *DeviceInformationDriver) Name() string { return b.name }
// SetName sets the Driver name
func (b *DeviceInformationDriver) SetName(n string) { b.name = n }
// adaptor returns BLE adaptor for this device
func (b *DeviceInformationDriver) adaptor() BLEConnector {
return b.Connection().(BLEConnector)
}
// Start tells driver to get ready to do work
func (b *DeviceInformationDriver) Start() (err error) {
return
}
// Halt stops driver (void)
func (b *DeviceInformationDriver) Halt() (err error) { return }
// GetModelNumber returns the model number for the BLE Peripheral
func (b *DeviceInformationDriver) GetModelNumber() (model string) {
c, _ := b.adaptor().ReadCharacteristic("2a24")
buf := bytes.NewBuffer(c)
val := buf.String()
return val
}
// GetFirmwareRevision returns the firmware revision for the BLE Peripheral
func (b *DeviceInformationDriver) GetFirmwareRevision() (revision string) {
c, _ := b.adaptor().ReadCharacteristic("2a26")
buf := bytes.NewBuffer(c)
val := buf.String()
return val
}
// GetHardwareRevision returns the hardware revision for the BLE Peripheral
func (b *DeviceInformationDriver) GetHardwareRevision() (revision string) {
c, _ := b.adaptor().ReadCharacteristic("2a27")
buf := bytes.NewBuffer(c)
val := buf.String()
return val
}
// GetManufacturerName returns the manufacturer name for the BLE Peripheral
func (b *DeviceInformationDriver) GetManufacturerName() (manufacturer string) {
c, _ := b.adaptor().ReadCharacteristic("2a29")
buf := bytes.NewBuffer(c)
val := buf.String()
return val
}
// GetPnPId returns the PnP ID for the BLE Peripheral
func (b *DeviceInformationDriver) GetPnPId() (model string) {
c, _ := b.adaptor().ReadCharacteristic("2a50")
buf := bytes.NewBuffer(c)
val := buf.String()
return val
}