示例#1
0
文件: discoverer.go 项目: flemay/gatt
func onPeriphDiscovered(p gatt.Peripheral, a *gatt.Advertisement, rssi int) {
	fmt.Printf("\nPeripheral ID:%s, NAME:(%s)\n", p.ID(), p.Name())
	fmt.Println("  Local Name        =", a.LocalName)
	fmt.Println("  TX Power Level    =", a.TxPowerLevel)
	fmt.Println("  Manufacturer Data =", a.ManufacturerData)
	fmt.Println("  Service Data      =", a.ServiceData)
}
示例#2
0
func (g *Gonashi) onPeriphDisconnected(p gatt.Peripheral, err error) {
	connected := g.connected.GetKonashiMap()
	idStr := strings.ToUpper(p.ID())
	if k, ok := connected[idStr]; ok {
		g.connected.DelKonashi(idStr)
		k.Disconnected <- struct{}{}
	}
}
示例#3
0
func (g *Gonashi) onPeriphConnected(p gatt.Peripheral, err error) {
	discovered := g.discovered.GetKonashiMap()
	idStr := strings.ToUpper(p.ID())
	if k, ok := discovered[idStr]; ok {
		k.SetPeripheral(p)
		g.connected.AddKonashi(k)
		k.Connected <- struct{}{}
	}
}
示例#4
0
func (dp *discovered) AddDiscovered(p gatt.Peripheral, a *gatt.Advertisement, rssi int) {
	dp.mu.Lock()
	defer dp.mu.Unlock()
	idStr := strings.ToUpper(p.ID())
	if k, ok := dp.konashis[idStr]; ok {
		k.Update(a, rssi)
	} else {
		dp.konashis[idStr] = NewKonashi(p, a, rssi)
	}
	dp.Update.In() <- dp.konashis
}
示例#5
0
文件: explorer.go 项目: flemay/gatt
func onPeriphDiscovered(p gatt.Peripheral, a *gatt.Advertisement, rssi int) {
	id := strings.ToUpper(flag.Args()[0])
	if strings.ToUpper(p.ID()) != id {
		return
	}

	// Stop scanning once we've got the peripheral we're looking for.
	p.Device().StopScanning()

	fmt.Printf("\nPeripheral ID:%s, NAME:(%s)\n", p.ID(), p.Name())
	fmt.Println("  Local Name        =", a.LocalName)
	fmt.Println("  TX Power Level    =", a.TxPowerLevel)
	fmt.Println("  Manufacturer Data =", a.ManufacturerData)
	fmt.Println("  Service Data      =", a.ServiceData)
	fmt.Println("")

	p.Device().Connect(p)
}