当前位置: 首页>>代码示例>>Golang>>正文


Golang gatt.Peripheral类代码示例

本文整理汇总了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
}
开发者ID:sjenning,项目名称:IoT-framework,代码行数:10,代码来源:devicehive-ble.go

示例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)
	}
}
开发者ID:sjenning,项目名称:IoT-framework,代码行数:16,代码来源:devicehive-ble.go

示例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))
	}
}
开发者ID:sjenning,项目名称:IoT-framework,代码行数:17,代码来源:devicehive-ble.go

示例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
}
开发者ID:sjenning,项目名称:IoT-framework,代码行数:52,代码来源:devicehive-ble.go


注:本文中的github.com/devicehive/gatt.Peripheral类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。