// 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) } }
// 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) } }
// 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) } }
// 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) } }
// 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) } }