mirror of
https://github.com/hybridgroup/gobot.git
synced 2025-04-26 13:48:49 +08:00
[ble] Device information service
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
parent
da9054d197
commit
04bf4c355c
34
examples/ble_device_info.go
Normal file
34
examples/ble_device_info.go
Normal file
@ -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()
|
||||
}
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user