protected virtual void onBoardValueChanged(char newSquareValue) { //Console.Clear(); if (BoardValueChanged != null) { BoardValueChanged.Invoke(newSquareValue); } }
public void UpdatedCharacterteristicValue(CBPeripheral peripheral, CBCharacteristic characteristic, NSError error) { #if DEBUG string name = OWBoard.GetNameFromUUID(characteristic.UUID.ToString()); Debug.WriteLine($"Peripheral_UpdatedCharacterteristicValue - {name}"); #endif if (_characteristics.ContainsKey(characteristic.UUID) == false) { Debug.WriteLine($"ERROR: Peripheral missing ({characteristic.UUID})"); return; } if (_readQueue.ContainsKey(characteristic.UUID) || _notifyList.Contains(characteristic.UUID)) { byte[] dataBytes = null; if (characteristic.Value != null) { var data = characteristic.Value; dataBytes = new byte[data.Length]; System.Runtime.InteropServices.Marshal.Copy(data.Bytes, dataBytes, 0, Convert.ToInt32(data.Length)); // Don't reveres for serial read or write var characteristicGuid = characteristic.UUID.ToString(); if (OWBoard.SerialWriteUUID.Equals(characteristicGuid, StringComparison.InvariantCultureIgnoreCase) == false && OWBoard.SerialReadUUID.Equals(characteristicGuid, StringComparison.InvariantCultureIgnoreCase) == false) { // If our system is little endian, reverse the array. if (BitConverter.IsLittleEndian) { Array.Reverse(dataBytes); } } } if (_notifyList.Contains(characteristic.UUID)) { BoardValueChanged?.Invoke(characteristic.UUID.ToString(), dataBytes); } if (_readQueue.ContainsKey(characteristic.UUID)) { var task = _readQueue[characteristic.UUID]; _readQueue.Remove(characteristic.UUID); task.SetResult(dataBytes); } } }
void MessagePump() { while (BoardValueChanged == null) { Thread.Sleep(100); } OWBoardEvent previousEvent = null; OWBoardEvent currentEvent = null; try { using (FileStream fs = new FileStream(_logFilename, FileMode.Open, FileAccess.Read)) { do { previousEvent = currentEvent; currentEvent = OWBoardEvent.Parser.ParseDelimitedFrom(fs); if (previousEvent != null) { long sleepDuration = currentEvent.Timestamp - previousEvent.Timestamp; Thread.Sleep((int)sleepDuration); } if (currentEvent.Uuid == RSSIKey) { RSSIUpdated?.Invoke(BitConverter.ToInt32(currentEvent.Data.ToByteArray())); } else { BoardValueChanged.Invoke(currentEvent.Uuid, currentEvent.Data.ToByteArray()); } }while (fs.Position < fs.Length); } } catch (Exception err) { System.Diagnostics.Debug.WriteLine("ERROR: " + err.Message); } }
private void OnCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { var uuid = characteristic.Uuid.ToString().ToLower(); if (_notifyList.Contains(uuid)) { var dataBytes = characteristic.GetValue(); if (OWBoard.SerialWriteUUID.Equals(uuid, StringComparison.InvariantCultureIgnoreCase) == false && OWBoard.SerialReadUUID.Equals(uuid, StringComparison.InvariantCultureIgnoreCase) == false) { // If our system is little endian, reverse the array. if (BitConverter.IsLittleEndian) { Array.Reverse(dataBytes); } } BoardValueChanged.Invoke(uuid, dataBytes); } }