private void RespondButton_Clicked(object sender, EventArgs e) { if (GattRequestViewModel.GattServerRequest is ICharacteristicReadRequest) { if (ResponseErrorCodePicker.SelectedIndex == 0) { (GattRequestViewModel.GattServerRequest as ICharacteristicReadRequest).RespondWithValue(Encoding.UTF8.GetBytes(ResponseEditor.Text)); } else { GattErrorCode errorcode = (GattErrorCode)(Enum.Parse(typeof(GattErrorCode), GattRequestViewModel.ErrorCodeNames[ResponseErrorCodePicker.SelectedIndex])); GattRequestViewModel.GattServerRequest.RespondWithProtocolError(errorcode); } } else if (GattRequestViewModel.GattServerRequest is ICharacteristicWriteRequest) { if (ResponseErrorCodePicker.SelectedIndex == 0) { (GattRequestViewModel.GattServerRequest as ICharacteristicWriteRequest).RespondSuccess(); } else { GattErrorCode errorcode = (GattErrorCode)(Enum.Parse(typeof(GattErrorCode), GattRequestViewModel.ErrorCodeNames[ResponseErrorCodePicker.SelectedIndex])); GattRequestViewModel.GattServerRequest.RespondWithProtocolError(errorcode); } } _UpdateUI(); }
public void RespondWithProtocolError(GattErrorCode errorCode) { (TargetCharacteristic.Service.Server as GattServer).DroidGattServer.SendResponse((SourceDevice as BluetoothManager.BluetoothDeviceWrapper).DroidDevice, RequestId, (Android.Bluetooth.GattStatus)errorCode, 0, null); State = GattRequestState.Canceled; StateChanged?.Invoke(this, GattRequestState.Pending); }