2016-03-03 14:43:41 +08:00
|
|
|
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
|
2016-07-09 02:36:53 +08:00
|
|
|
func NewBLEDeviceInformationDriver(a *BLEClientAdaptor, name string) *BLEDeviceInformationDriver {
|
2016-03-03 14:43:41 +08:00
|
|
|
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
|
2016-07-09 02:36:53 +08:00
|
|
|
func (b *BLEDeviceInformationDriver) adaptor() *BLEClientAdaptor {
|
|
|
|
return b.Connection().(*BLEClientAdaptor)
|
2016-03-03 14:43:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
2016-07-03 18:11:34 +08:00
|
|
|
val := buf.String()
|
|
|
|
return val
|
2016-03-03 14:43:41 +08:00
|
|
|
}
|
2016-07-03 18:46:29 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|