1

我正在尝试向模拟设备发送“你好”并从中接收反馈。我使用 writeCharacteristic 来模拟设备,但我不知道如何设置它的响应。

请帮忙,非常感谢!!!

@OnClick(R.id.write)
public void onWriteClick() {

    SoftCheckConnected();

    connectionObservable
            .flatMap(rxBleConnection -> rxBleConnection.writeCharacteristic(characteristicUuid, getInputBytes()))
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(bytes -> {
                String result = new String(bytes);
                onWriteStatus(result.trim().equals("Hello pin"));
            }, this::onWriteFailure);

}

对于模拟设备

 RxBleDevice bleDevice = new RxBleClientMock.DeviceBuilder()
            .deviceMacAddress("AA:BB:CC:DD:EE:FF")
            .deviceName("TestDevice")
            .scanRecord("ScanRecord".getBytes())
            .rssi(42)
            .notificationSource(characteristicNotifiedUUID, characteristicNotificationSubject)
            .addService(
                    serviceUUID,
                    new RxBleClientMock.CharacteristicsBuilder()
                            .addCharacteristic(
                                    characteristicUUID,
                                    characteristicData,
                                    new RxBleClientMock.DescriptorsBuilder()
                                            .addDescriptor(descriptorUUID, descriptorData)
                                            .build()
                            ).build()
            ).build();
4

0 回答 0