Skip to content

Commit

Permalink
ble: rename drivers to make them more obvious, and add test placeholders
Browse files Browse the repository at this point in the history
Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram committed Dec 9, 2016
1 parent 480b739 commit 5ddfb63
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 6 deletions.
14 changes: 10 additions & 4 deletions platforms/ble/battery.go → platforms/ble/battery_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import (
"gobot.io/x/gobot"
)

var _ gobot.Driver = (*BatteryDriver)(nil)

// BatteryDriver represents the Battery Service for a BLE Peripheral
type BatteryDriver struct {
name string
connection gobot.Connection
Expand All @@ -24,9 +23,15 @@ func NewBatteryDriver(a *ClientAdaptor) *BatteryDriver {

return n
}

// Connection returns the Driver's Connection to the associated Adaptor
func (b *BatteryDriver) Connection() gobot.Connection { return b.connection }
func (b *BatteryDriver) Name() string { return b.name }
func (b *BatteryDriver) SetName(n string) { b.name = n }

// Name returns the Driver name
func (b *BatteryDriver) Name() string { return b.name }

// SetName sets the Driver name
func (b *BatteryDriver) SetName(n string) { b.name = n }

// adaptor returns BLE adaptor
func (b *BatteryDriver) adaptor() *ClientAdaptor {
Expand All @@ -41,6 +46,7 @@ func (b *BatteryDriver) Start() (err error) {
// Halt stops battery driver (void)
func (b *BatteryDriver) Halt() (err error) { return }

// GetBatteryLevel reads and returns the current battery level
func (b *BatteryDriver) GetBatteryLevel() (level uint8) {
var l uint8
c, _ := b.adaptor().ReadCharacteristic("180f", "2a19")
Expand Down
20 changes: 20 additions & 0 deletions platforms/ble/battery_driver_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package ble

import (
"testing"

"gobot.io/x/gobot"
"gobot.io/x/gobot/gobottest"
)

var _ gobot.Driver = (*BatteryDriver)(nil)

func initTestBatteryDriver() *BatteryDriver {
d := NewBatteryDriver(NewClientAdaptor("D7:99:5A:26:EC:38"))
return d
}

func TestBatteryDriver(t *testing.T) {
d := initTestBatteryDriver()
gobottest.Assert(t, d.Name(), "Battery")
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

var _ gobot.Driver = (*DeviceInformationDriver)(nil)

// DeviceInformationDriver represents the Device Information Service for a BLE Peripheral
type DeviceInformationDriver struct {
name string
connection gobot.Connection
Expand All @@ -24,9 +25,15 @@ func NewDeviceInformationDriver(a *ClientAdaptor) *DeviceInformationDriver {

return n
}

// Connection returns the Driver's Connection to the associated Adaptor
func (b *DeviceInformationDriver) Connection() gobot.Connection { return b.connection }
func (b *DeviceInformationDriver) Name() string { return b.name }
func (b *DeviceInformationDriver) SetName(n string) { b.name = n }

// 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() *ClientAdaptor {
Expand All @@ -41,34 +48,39 @@ func (b *DeviceInformationDriver) Start() (err error) {
// 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("180a", "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("180a", "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("180a", "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("180a", "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("180a", "2a50")
buf := bytes.NewBuffer(c)
Expand Down
17 changes: 17 additions & 0 deletions platforms/ble/device_information_driver_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ble

import (
"testing"

"gobot.io/x/gobot/gobottest"
)

func initTestDeviceInformationDriver() *DeviceInformationDriver {
d := NewDeviceInformationDriver(NewClientAdaptor("D7:99:5A:26:EC:38"))
return d
}

func TestDeviceInformationDriver(t *testing.T) {
d := initTestDeviceInformationDriver()
gobottest.Assert(t, d.Name(), "DeviceInformation")
}

0 comments on commit 5ddfb63

Please sign in to comment.