gobot.io/x/gobot/v2@v2.1.0/platforms/ble/device_information_driver.go (about) 1 package ble 2 3 import ( 4 "bytes" 5 "log" 6 7 "gobot.io/x/gobot/v2" 8 ) 9 10 // DeviceInformationDriver represents the Device Information Service for a BLE Peripheral 11 type DeviceInformationDriver struct { 12 name string 13 connection gobot.Connection 14 gobot.Eventer 15 } 16 17 // NewDeviceInformationDriver creates a DeviceInformationDriver 18 func NewDeviceInformationDriver(a BLEConnector) *DeviceInformationDriver { 19 n := &DeviceInformationDriver{ 20 name: gobot.DefaultName("DeviceInformation"), 21 connection: a, 22 Eventer: gobot.NewEventer(), 23 } 24 25 return n 26 } 27 28 // Connection returns the Driver's Connection to the associated Adaptor 29 func (b *DeviceInformationDriver) Connection() gobot.Connection { return b.connection } 30 31 // Name returns the Driver name 32 func (b *DeviceInformationDriver) Name() string { return b.name } 33 34 // SetName sets the Driver name 35 func (b *DeviceInformationDriver) SetName(n string) { b.name = n } 36 37 // adaptor returns BLE adaptor for this device 38 func (b *DeviceInformationDriver) adaptor() BLEConnector { 39 return b.Connection().(BLEConnector) 40 } 41 42 // Start tells driver to get ready to do work 43 func (b *DeviceInformationDriver) Start() (err error) { 44 return 45 } 46 47 // Halt stops driver (void) 48 func (b *DeviceInformationDriver) Halt() (err error) { return } 49 50 // GetModelNumber returns the model number for the BLE Peripheral 51 func (b *DeviceInformationDriver) GetModelNumber() (model string) { 52 c, err := b.adaptor().ReadCharacteristic("2a24") 53 if err != nil { 54 log.Println(err) 55 return 56 } 57 buf := bytes.NewBuffer(c) 58 model = buf.String() 59 return 60 } 61 62 // GetFirmwareRevision returns the firmware revision for the BLE Peripheral 63 func (b *DeviceInformationDriver) GetFirmwareRevision() (revision string) { 64 c, err := b.adaptor().ReadCharacteristic("2a26") 65 if err != nil { 66 log.Println(err) 67 return 68 } 69 buf := bytes.NewBuffer(c) 70 val := buf.String() 71 return val 72 } 73 74 // GetHardwareRevision returns the hardware revision for the BLE Peripheral 75 func (b *DeviceInformationDriver) GetHardwareRevision() (revision string) { 76 c, err := b.adaptor().ReadCharacteristic("2a27") 77 if err != nil { 78 log.Println(err) 79 return 80 } 81 buf := bytes.NewBuffer(c) 82 val := buf.String() 83 return val 84 } 85 86 // GetManufacturerName returns the manufacturer name for the BLE Peripheral 87 func (b *DeviceInformationDriver) GetManufacturerName() (manufacturer string) { 88 c, err := b.adaptor().ReadCharacteristic("2a29") 89 if err != nil { 90 log.Println(err) 91 return 92 } 93 buf := bytes.NewBuffer(c) 94 val := buf.String() 95 return val 96 } 97 98 // GetPnPId returns the PnP ID for the BLE Peripheral 99 func (b *DeviceInformationDriver) GetPnPId() (model string) { 100 c, err := b.adaptor().ReadCharacteristic("2a50") 101 if err != nil { 102 log.Println(err) 103 return 104 } 105 buf := bytes.NewBuffer(c) 106 val := buf.String() 107 return val 108 }