Esempio n. 1
0
File: goble.go Progetto: raff/goble
// update rssi
func (ble *BLE) UpdateRssi(deviceUuid xpc.UUID) {
	uuid := deviceUuid.String()
	if p, ok := ble.peripherals[uuid]; ok {
		ble.sendCBMsg(43, xpc.Dict{"kCBMsgArgDeviceUUID": p.Uuid})
	} else {
		log.Println("no peripheral", deviceUuid)
	}
}
Esempio n. 2
0
File: goble.go Progetto: raff/goble
// connect
func (ble *BLE) Connect(deviceUuid xpc.UUID) {
	uuid := deviceUuid.String()
	if p, ok := ble.peripherals[uuid]; ok {
		ble.sendCBMsg(31, xpc.Dict{"kCBMsgArgOptions": xpc.Dict{"kCBConnectOptionNotifyOnDisconnection": 1}, "kCBMsgArgDeviceUUID": p.Uuid})
	} else {
		log.Println("no peripheral", deviceUuid)
	}
}
Esempio n. 3
0
File: goble.go Progetto: raff/goble
// discover services
func (ble *BLE) DiscoverServices(deviceUuid xpc.UUID, uuids []xpc.UUID) {
	sUuid := deviceUuid.String()
	if p, ok := ble.peripherals[sUuid]; ok {
		sUuids := make([]string, len(uuids))
		for i, uuid := range uuids {
			sUuids[i] = uuid.String() // uuids may be a list of []byte (2 bytes)
		}
		ble.sendCBMsg(44, xpc.Dict{"kCBMsgArgDeviceUUID": p.Uuid, "kCBMsgArgUUIDs": sUuids})
	} else {
		log.Println("no peripheral", deviceUuid)
	}
}
Esempio n. 4
0
File: goble.go Progetto: raff/goble
// read
func (ble *BLE) Read(deviceUuid xpc.UUID, serviceUuid, characteristicUuid string) {
	sUuid := deviceUuid.String()
	if p, ok := ble.peripherals[sUuid]; ok {
		s := p.Services[serviceUuid]
		c := s.Characteristics[characteristicUuid]

		ble.sendCBMsg(64, xpc.Dict{
			"kCBMsgArgDeviceUUID":                p.Uuid,
			"kCBMsgArgCharacteristicHandle":      c.Handle,
			"kCBMsgArgCharacteristicValueHandle": c.ValueHandle,
		})
	} else {
		log.Println("no peripheral", deviceUuid)
	}
}
Esempio n. 5
0
File: goble.go Progetto: raff/goble
// discover characteristics
func (ble *BLE) DiscoverCharacterstics(deviceUuid xpc.UUID, serviceUuid string, characteristicUuids []string) {
	sUuid := deviceUuid.String()
	if p, ok := ble.peripherals[sUuid]; ok {
		cUuids := make([]string, len(characteristicUuids))
		for i, cuuid := range characteristicUuids {
			cUuids[i] = cuuid // characteristicUuids may be a list of []byte (2 bytes)
		}

		ble.sendCBMsg(61, xpc.Dict{
			"kCBMsgArgDeviceUUID":         p.Uuid,
			"kCBMsgArgServiceStartHandle": p.Services[serviceUuid].startHandle,
			"kCBMsgArgServiceEndHandle":   p.Services[serviceUuid].endHandle,
			"kCBMsgArgUUIDs":              cUuids,
		})

	} else {
		log.Println("no peripheral", deviceUuid)
	}
}