예제 #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)
}
예제 #6
0
파일: explorer.go 프로젝트: flemay/gatt
func onPeriphConnected(p gatt.Peripheral, err error) {
	fmt.Println("Connected")
	defer p.Device().CancelConnection(p)

	if err := p.SetMTU(500); err != nil {
		fmt.Printf("Failed to set MTU, err: %s\n", err)
		return
	}

	// Discovery services
	ss, err := p.DiscoverServices(nil)
	if err != nil {
		fmt.Printf("Failed to discover services, err: %s\n", err)
		return
	}

	for _, s := range ss {
		msg := "Service: " + s.UUID().String()
		if len(s.Name()) > 0 {
			msg += " (" + s.Name() + ")"
		}
		fmt.Println(msg)

		// Discovery characteristics
		cs, err := p.DiscoverCharacteristics(nil, s)
		if err != nil {
			fmt.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()
			fmt.Println(msg)

			// Read the characteristic, if possible.
			if (c.Properties() & gatt.CharRead) != 0 {
				b, err := p.ReadLongCharacteristic(c)
				if err != nil {
					fmt.Printf("Failed to read characteristic, err: %s\n", err)
					continue
				}
				fmt.Printf("    value         %x | %q\n", b, b)
			}

			// Discovery descriptors
			ds, err := p.DiscoverDescriptors(nil, c)
			if err != nil {
				fmt.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() + ")"
				}
				fmt.Println(msg)

				// Read descriptor (could fail, if it's not readable)
				b, err := p.ReadDescriptor(d)
				if err != nil {
					fmt.Printf("Failed to read descriptor, err: %s\n", err)
					continue
				}
				fmt.Printf("    value         %x | %q\n", b, b)
			}
		}
		fmt.Println()
	}
}