本文整理汇总了Golang中github.com/devicehive/gatt.Peripheral类的典型用法代码示例。如果您正苦于以下问题:Golang Peripheral类的具体用法?Golang Peripheral怎么用?Golang Peripheral使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Peripheral类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: OnPeripheralConnected
func (w *BleDbusWrapper) OnPeripheralConnected(p gatt.Peripheral, err error) {
id, _ := normalizeHex(p.ID())
w.devicesDiscovered[id].peripheral = p
w.devicesConnectedsync.Lock()
w.devicesConnected[id] = &sync.Mutex{}
w.devicesConnectedsync.Unlock()
w.connChan <- true
}
示例2: OnPeripheralDisconnected
func (w *BleDbusWrapper) OnPeripheralDisconnected(p gatt.Peripheral, err error) {
w.devicesConnectedsync.Lock()
defer w.devicesConnectedsync.Unlock()
id, _ := normalizeHex(p.ID())
if _, ok := w.devicesDiscovered[id]; ok {
delete(w.devicesDiscovered, id)
}
if _, ok := w.devicesConnected[id]; ok {
log.Printf("Disconnected: %s", id)
delete(w.devicesConnected, id)
w.emitPeripheralDisconnected(id)
}
}
示例3: OnPeripheralDiscovered
func (w *BleDbusWrapper) OnPeripheralDiscovered(p gatt.Peripheral, a *gatt.Advertisement, rssi int) {
w.devicesDiscoveredsync.Lock()
defer w.devicesDiscoveredsync.Unlock()
id, _ := normalizeHex(p.ID())
name := strings.Trim(p.Name(), "\x00")
dev, ok := w.devicesDiscovered[id]
if !ok {
w.devicesDiscovered[id] = &DiscoveredDeviceInfo{name: name, rssi: rssi, peripheral: p, ready: false, connectedOnce: false}
w.emitPeripheralDiscovered(id, name, int16(rssi))
} else {
if (dev.name == "") && (name != "") {
dev.name = name
}
w.emitPeripheralDiscovered(id, dev.name, int16(rssi))
}
}
示例4: explorePeripheral
func (b *DiscoveredDeviceInfo) explorePeripheral(p gatt.Peripheral) error {
ss, err := p.DiscoverServices(nil)
if err != nil {
log.Printf("Failed to discover services, err: %s\n", err)
return err
}
for _, s := range ss {
// msg := "Service: " + s.UUID().String()
// if len(s.Name()) > 0 {
// msg += " (" + s.Name() + ")"
// }
// log.Println(msg)
// Discovery characteristics
cs, err := p.DiscoverCharacteristics(nil, s)
if err != nil {
log.Printf("Failed to discover characteristics, err: %s\n", err)
continue
}
for _, c := range cs {
// msg := " Characteristic " + c.UUID().String()
// if len(c.Name()) > 0 {
// msg += " (" + c.Name() + ")"
// }
// msg += "\n properties " + c.Properties().String()
// log.Println(msg)
// Discovery descriptors
_, err := p.DiscoverDescriptors(nil, c)
if err != nil {
log.Printf("Failed to discover descriptors, err: %s\n", err)
continue
}
// for _, d := range ds {
// msg := " Descriptor " + d.UUID().String()
// if len(d.Name()) > 0 {
// msg += " (" + d.Name() + ")"
// }
// log.Println(msg)
// }
id, _ := normalizeHex(c.UUID().String())
b.characteristics[id] = c
}
b.ready = true
}
return nil
}