diff --git a/examples/ble_device_info.go b/examples/ble_device_info.go new file mode 100644 index 00000000..9807ec62 --- /dev/null +++ b/examples/ble_device_info.go @@ -0,0 +1,34 @@ +package main + +import ( + "fmt" + "os" + + "github.com/hybridgroup/gobot" + "github.com/hybridgroup/gobot/platforms/ble" +) + +func main() { + gbot := gobot.NewGobot() + + bleAdaptor := ble.NewBLEAdaptor("ble", os.Args[1]) + info := ble.NewBLEDeviceInformationDriver(bleAdaptor, "info") + + work := func() { + fmt.Println("Model number:", info.GetModelNumber()) + fmt.Println("Firmware rev:", info.GetFirmwareRevision()) + fmt.Println("Hardware rev:", info.GetHardwareRevision()) + fmt.Println("Manufacturer name:", info.GetManufacturerName()) + fmt.Println("PnPId:", info.GetPnPId()) + } + + robot := gobot.NewRobot("bleBot", + []gobot.Connection{bleAdaptor}, + []gobot.Device{info}, + work, + ) + + gbot.AddRobot(robot) + + gbot.Start() +} diff --git a/platforms/ble/device_information.go b/platforms/ble/device_information.go index c72ed27c..6f0efbc0 100644 --- a/platforms/ble/device_information.go +++ b/platforms/ble/device_information.go @@ -47,3 +47,31 @@ func (b *BLEDeviceInformationDriver) GetModelNumber() (model string) { 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 +}