private void ProcedureCompletedHandler(object sender, ProcedureCompletedEventArgs e) { if (e.connection == this.Connection && e.chrhandle == this.AttributeHandle) { _response = e; } }
/******************* * Tool response events */////////////////// private void ProcedureCompleteEvent(object sender, ProcedureCompletedEventArgs e) { Console.WriteLine(String.Format("Got response from tool {0}", e.result)); // //TODO remove the 1,5. I just made that up //2,3 doesn't error //We can track globally for getting shit done, or per tool //use e.connection. That is the key for the dictionary if (connState == BluetoothState.STATE_FINDING_SERVICES) { Byte[] cmd = bglib.BLECommandATTClientFindInformation(e.connection, 2, 3); bglib.SendCommand(serialAPI, cmd); Console.WriteLine("getting attributes"); } if (connState == BluetoothState.STATE_FINDING_ATTRIBUTES) { //TODO replace e.connection with the tool connection. pull tool out based on e.connection //Also the payload has to mean something, like identify tool Byte[] payload = { 0x01, 0x01, 0x01, 0xA0, 0x23, 0x01, 0x00, 0xc7 }; Byte[] cmd = bglib.BLECommandATTClientAttributeWrite(e.connection, 0x000F, payload); bglib.SendCommand(serialAPI, cmd); Console.WriteLine("Wrote data to attribute"); connState = BluetoothState.STATE_SENDING_COMMAND; } }
private void BGApi_ATTClientProcedureCompleted(object sender, ProcedureCompletedEventArgs e) { try { if (State == ServiceState.Disposed) { return; } Debug.WriteLine($"BGService->ProcedureCompleted: conn={e.connection:X2} atthandle={e.atthandle:X4} result={e.result:X4}"); if (e.result != (UInt16)BGErrorCode.NoError) { var error = (BGErrorCode)Enum.ToObject(typeof(BGErrorCode), e.result); if (error != BGErrorCode.AttributeNotFound) { throw new Exception($"ATTClientProcedureCompleted with error={error} code=0x{e.result:X4}"); } } } catch (Exception ex) { if (_exceptionToRethrow == null) { _exceptionToRethrow = ExceptionDispatchInfo.Capture(ex); } } finally { _procedureCompletedWaitHandle.Set(); } }
private void BGApi_ATTClientProcedureCompleted(object sender, ProcedureCompletedEventArgs e) { try { lock (StateLock) if (State == CharacteristicState.Disposed) { return; } Debug.WriteLine($"BGCharacteristic->ProcedureCompleted: conn={e.connection:X2} atthandle={e.atthandle:X4} result={e.result:X4}"); if (e.result != 0x00) { throw new Exception($"ATTClientProcedureCompleted with error code: 0x{e.result:X4}"); } _handleOfLastAccessedAttribute = e.atthandle; } catch (Exception ex) { if (_exceptionToRethrow == null) { _exceptionToRethrow = ExceptionDispatchInfo.Capture(ex); } } finally { _procedureCompletedWaitHandle.Set(); } }
private void FindServices() { // (established connection, handle.min_address, handle.max_address, primary gatt service attribute identifier) byte[] readGroups = Ble.Lib.BLECommandATTClientReadByGroupType(this.Connection, GATT_MIN_HANDLE, GATT_MAX_HANDLE, (byte[])GATT_SERVICE_TYPE_PRIMARY); Ble.Lib.BLEEventATTClientGroupFound += GroupFound; ProcedureCompletedEventArgs procedureResponse = null; ProcedureCompletedEventHandler handler = (sender, e) => { procedureResponse = e; }; Ble.Lib.BLEEventATTClientProcedureCompleted += handler; Ble.SendCommand(this.Port, readGroups); this.WaitEvent(() => procedureResponse != null); Ble.Lib.BLEEventATTClientGroupFound -= GroupFound; Ble.Lib.BLEEventATTClientProcedureCompleted -= handler; }
private void FindAttributes(BlePeripheralService service) { byte[] findInfo = Ble.Lib.BLECommandATTClientFindInformation(this.Connection, service.StartHandle, service.EndHandle); FindInformationFoundEventHandler infoHandler = (sender, e) => this.AttributeFound(service, e); Ble.Lib.BLEEventATTClientFindInformationFound += infoHandler; ProcedureCompletedEventArgs procedureResponse = null; ProcedureCompletedEventHandler handler = (sender, e) => { procedureResponse = e; }; Ble.Lib.BLEEventATTClientProcedureCompleted += handler; Ble.SendCommand(this.Port, findInfo); this.WaitEvent(() => procedureResponse != null); Ble.Lib.BLEEventATTClientFindInformationFound -= infoHandler; Ble.Lib.BLEEventATTClientProcedureCompleted -= handler; }
private void BGApi_ATTClientProcedureCompleted(object sender, ProcedureCompletedEventArgs e) { try { if (State == PeripheralState.Disposed) { return; } Debug.WriteLine($"BGPeripheral->ProcedureCompleted: conn={e.connection:X2} atthandle={e.atthandle:X4} result={e.result:X4}"); if (e.result != 0x00) { throw new Exception($"ATTClientProcedureCompleted with error code: 0x{e.result:X4}"); } } catch (Exception ex) { if (_exceptionToRethrow == null) { _exceptionToRethrow = ExceptionDispatchInfo.Capture(ex); } } finally { _procedureCompletedWaitHandle.Set(); } }
private void Bglib_BLEEventATTClientProcedureCompleted(object sender, ProcedureCompletedEventArgs e) => ATTClientProcedureCompleted?.Invoke(this, e);
private void OnClientProcedureCompletedEvent(object sender, ProcedureCompletedEventArgs e) { _logger.LogInformation("OnClientProcedureCompletedEvent"); _currentAction?.Cancel(); }