public async Task <byte> ATTClientReadByGroupTypeAsync(byte connectionHandle, ushort handleRangeStart, ushort handleRangeEnd, byte[] primaryUUIDBytes) { const int TIMEOUT_MS = 6000; var cmd = _bglib.BLECommandATTClientReadByGroupType(connectionHandle, handleRangeStart, handleRangeEnd, primaryUUIDBytes); await _bglib.SendCommandAsync(cmd).ConfigureAwait(false); using (var cts = new CancellationTokenSource(TIMEOUT_MS)) { bool didTimeout = false; try { await _cmdRespWaitHandle.WaitAsync(cts.Token).ConfigureAwait(false); } catch (OperationCanceledException) { didTimeout = true; } if (didTimeout) { throw new TimeoutException(); } } if (_lastResult != 0) { var error = Enum.ToObject(typeof(BGErrorCode), _lastResult); string errMsg = $"ATTClientReadByGroupType returned: error={error} code={_lastResult:X4}"; throw new Exception(errMsg); } byte conHandle = ((ReadByGroupTypeEventArgs)_lastResponseArgs).connection; return(conHandle); }
private void OnDeviceConnected(object sender, StatusEventArgs e) { var deviceStatus = BleMappings.MapBleDeviceStatus(e); if (_device == null || deviceStatus == null || _device.Address != deviceStatus.Address) { return; } if (deviceStatus.IsConnected) // Connected { // Service Discovery _bglib.SendCommand(_serialPort, _bglib.BLECommandATTClientReadByGroupType(e.connection, 0x0001, 0xFFFF, new byte[] { 0x00, 0x28 })); // "service" UUID is 0x2800 (little-endian for UUID uint8array) } else { _logger.LogInformation( $"ControlPlus Repository: Connection changed: {deviceStatus.Address} {deviceStatus.Flags}"); } }