public PeripheralTreeEntry(IPeripheral peripheral, IPeripheral parent, Type type, IRegistrationPoint registrationPoint, string name, int level) { this.type = type; Name = name; RegistrationPoint = registrationPoint; Peripheral = peripheral; Parent = parent; Level = level; }
public PrimeCellIDHelper(int peripheralSize, byte[] data, IPeripheral parent) { this.peripheralSize = peripheralSize; this.data = data.ToArray(); // to obtain a copy this.parent = parent; if(data.Length != 8) { throw new RecoverableException("You have to provide full peripheral id and prime cell id (8 bytes)."); } }
public string AddPeripheral(int computerId, int id, string peripheralType, string manufacturer, string model, decimal price, double overallPerformance, string connectionType) { CheckIfComputerIdExist(computerId); IComputer computer = _computers[computerId]; if (_peripherals.ContainsKey(id)) { throw new ArgumentException(ExceptionMessages.ExistingPeripheralId); } IPeripheral peripheral = _factory.CreatePeripheral(id, peripheralType, manufacturer, model, price, overallPerformance, connectionType); computer.AddPeripheral(peripheral); _peripherals.Add(id, peripheral); return(string.Format(SuccessMessages.AddedPeripheral, peripheralType, id, computerId)); }
private static IPeripheral PeripheralFactory( int id, string peripheralType, string manufacturer, string model, decimal price, double overallPerformance, string connectionType) { Enum.TryParse(peripheralType, out PeripheralType type); IPeripheral peripheral = type switch { PeripheralType.Headset => new Headset(id, manufacturer, model, price, overallPerformance, connectionType), PeripheralType.Keyboard => new Keyboard(id, manufacturer, model, price, overallPerformance, connectionType), PeripheralType.Monitor => new Monitor(id, manufacturer, model, price, overallPerformance, connectionType), PeripheralType.Mouse => new Mouse(id, manufacturer, model, price, overallPerformance, connectionType), _ => null }; return(peripheral); }
async Task Setup() { this.peripheral = await this.manager .ScanUntilPeripheralFound(Constants.PeripheralName) .Timeout(Constants.DeviceScanTimeout) .ToTask(); await this.peripheral .ConnectWait() .Timeout(Constants.ConnectTimeout) // android can take some time :P .ToTask(); this.characteristics = await this.peripheral .GetCharacteristicsForService(Constants.ScratchServiceUuid) .Take(5) .Timeout(Constants.OperationTimeout) .ToArray() .ToTask(); }
private void FindPaths(string nameSoFar, IPeripheral peripheralToFind, MultiTreeNode <IPeripheral, IRegistrationPoint> currentNode, List <string> paths) { foreach (var child in currentNode.Children) { var currentPeripheral = child.Value; string localName; if (!TryGetLocalName(currentPeripheral, out localName)) { continue; } var name = Subname(nameSoFar, localName); if (currentPeripheral == peripheralToFind) { paths.Add(name); return; // shouldn't be attached to itself } FindPaths(name, peripheralToFind, child, paths); } }
void ConnectPrinter(IPeripheral selectedPeripheral) { if (!selectedPeripheral.IsConnected()) { selectedPeripheral.Connect(); } _perifDisposable = selectedPeripheral.WhenAnyCharacteristicDiscovered().Subscribe((characteristic) => { //System.Diagnostics.Debug.WriteLine(characteristic.Description); //this is not suppported at this momment, and no neccesary I guess if (characteristic.CanWrite() && !characteristic.CanRead() && !characteristic.CanNotify()) { IsReadyToPrint = true; _savedCharacteristic = characteristic; System.Diagnostics.Debug.WriteLine($"Writing {characteristic.Uuid} - {characteristic.CanRead()} - {characteristic.CanIndicate()} - {characteristic.CanNotify()}"); _perifDisposable.Dispose(); } }); }
public string RemovePeripheral(string peripheralType, int computerId) { var computer = this.computers.FirstOrDefault(x => x.Id == computerId); if (computer == null) { throw new ArgumentException(ExceptionMessages.NotExistingComputerId); } computer.RemovePeripheral(peripheralType); IPeripheral peripheral = this.peripherals.FirstOrDefault(x => x.GetType().Name == peripheralType); if (peripheral != null) { this.peripherals.Remove(peripheral); } return(String.Format(SuccessMessages.RemovedPeripheral, peripheralType, peripheral.Id)); }
public string AddPeripheral(int computerId, int id, string peripheralType, string manufacturer, string model, decimal price, double overallPerformance, string connectionType) { IComputer computer = computers.FirstOrDefault(c => c.Id == computerId); if (computer == null) { throw new ArgumentException(String.Format(ExceptionMessages.NotExistingComputerId)); } if (peripherals.Any(p => p.Id == id)) { throw new ArgumentException(String.Format(ExceptionMessages.ExistingPeripheralId)); } IPeripheral peripheral = null; if (peripheralType == "Headset") { peripheral = new Headset(id, manufacturer, model, price, overallPerformance, connectionType); } else if (peripheralType == "Keyboard") { peripheral = new Keyboard(id, manufacturer, model, price, overallPerformance, connectionType); } else if (peripheralType == "Monitor") { peripheral = new Monitor(id, manufacturer, model, price, overallPerformance, connectionType); } else if (peripheralType == "Mouse") { peripheral = new Mouse(id, manufacturer, model, price, overallPerformance, connectionType); } else { throw new ArgumentException(String.Format(ExceptionMessages.InvalidPeripheralType)); } computer.AddPeripheral(peripheral); peripherals.Add(peripheral); return(String.Format(SuccessMessages.AddedPeripheral, peripheralType, id, computerId)); }
public string AddPeripheral(int computerId, int id, string peripheralType, string manufacturer, string model, decimal price, double overallPerformance, string connectionType) { CheckIfComputerExists(computerId); if (peripherals.Any(x => x.Id == id)) { throw new ArgumentException(ExceptionMessages.ExistingPeripheralId); } IPeripheral peripheral = null; switch (peripheralType) { case "Headset": peripheral = new Headset (id, manufacturer, model, price, overallPerformance, connectionType); break; case "Keyboard": peripheral = new Keyboard (id, manufacturer, model, price, overallPerformance, connectionType); break; case "Monitor": peripheral = new Monitor (id, manufacturer, model, price, overallPerformance, connectionType); break; case "Mouse": peripheral = new Mouse (id, manufacturer, model, price, overallPerformance, connectionType); break; default: throw new ArgumentException(ExceptionMessages.InvalidPeripheralType); } peripherals.Add(peripheral); computers.FirstOrDefault(x => x.Id == computerId).AddPeripheral(peripheral); return(string.Format(SuccessMessages.AddedPeripheral, peripheralType, id, computerId)); }
public string AddPeripheral(int computerId, int id, string peripheralType, string manufacturer, string model, decimal price, double overallPerformance, string connectionType) { if (!computers.Any(x => x.Id == computerId)) { throw new ArgumentException("Computer with this id does not exist."); } IComputer computer = computers.FirstOrDefault(x => x.Id == computerId); if (peripherals.Any(x => x.Id == id)) { throw new ArgumentException("Peripheral with this id already exists."); } IPeripheral peripheral = null; if (peripheralType == "Headset") { peripheral = new Headset(id, manufacturer, model, price, overallPerformance, connectionType); } else if (peripheralType == "Keyboard") { peripheral = new Keyboard(id, manufacturer, model, price, overallPerformance, connectionType); } else if (peripheralType == "Monitor") { peripheral = new Monitor(id, manufacturer, model, price, overallPerformance, connectionType); } else if (peripheralType == "Mouse") { peripheral = new Mouse(id, manufacturer, model, price, overallPerformance, connectionType); } else { throw new ArgumentException("Peripheral type is invalid."); } computer.AddPeripheral(peripheral); peripherals.Add(peripheral); return($"Peripheral {peripheralType} with id {id} added successfully in computer with id {computerId}."); }
public string AddPeripheral(int computerId, int id, string peripheralType, string manufacturer, string model, decimal price, double overallPerformance, string connectionType) { var computer = this.computers.FirstOrDefault(x => x.Id == computerId); if (computer == null) { throw new ArgumentException(ExceptionMessages.NotExistingComputerId); } IPeripheral peripheral = null; if (peripheralType == PeripheralType.Headset.ToString()) { peripheral = new Headset(id, manufacturer, model, price, overallPerformance, connectionType); } else if (peripheralType == PeripheralType.Keyboard.ToString()) { peripheral = new Keyboard(id, manufacturer, model, price, overallPerformance, connectionType); } else if (peripheralType == PeripheralType.Mouse.ToString()) { peripheral = new Mouse(id, manufacturer, model, price, overallPerformance, connectionType); } else if (peripheralType == PeripheralType.Monitor.ToString()) { peripheral = new Monitor(id, manufacturer, model, price, overallPerformance, connectionType); } else { throw new ArgumentException(ExceptionMessages.InvalidPeripheralType); } if (this.peripherals.Any(x => x.Id == id)) { throw new ArgumentException(ExceptionMessages.ExistingPeripheralId); } computer.AddPeripheral(peripheral); this.peripherals.Add(peripheral); return(string.Format(SuccessMessages.AddedPeripheral, peripheralType, id, computerId)); }
private IPeripheral CreatePeripheral(int id, string peripheralType, string manufacturer, string model, decimal price, double overallPerformance, string connectionType) { Type type = GetDefaultType(peripheralType); if (type == null) { throw new ArgumentException (ExceptionMessages.InvalidPeripheralType); } IPeripheral peripheral = null; if (peripheralType == PeripheralType.Headset.ToString()) { peripheral = new Headset(id, manufacturer, model, price, overallPerformance, connectionType); } if (peripheralType == PeripheralType.Keyboard.ToString()) { peripheral = new Keyboard(id, manufacturer, model, price, overallPerformance, connectionType); } if (peripheralType == PeripheralType.Monitor.ToString()) { peripheral = new Monitor(id, manufacturer, model, price, overallPerformance, connectionType); } if (peripheralType == PeripheralType.Mouse.ToString()) { peripheral = new Mouse(id, manufacturer, model, price, overallPerformance, connectionType); } return(peripheral); }
private async Task ReadFromDevice(IPeripheral device) { StopSearch(); var ServiceId = Guid.Parse("0000180A-0000-1000-8000-00805F9B34FB"); var ManufacturerName = Guid.Parse("00002A29-0000-1000-8000-00805F9B34FB"); var connectedDevice = await device.ConnectWait(); var service = await device.GetKnownService(ServiceId); var characteristic = await service.GetKnownCharacteristics(new Guid[] { ManufacturerName }); if (characteristic.CanRead()) { var data = await characteristic.Read(); var readValue = Encoding.UTF8.GetString(data.Data); Debug.WriteLine($"> Read characteristic is: {readValue}"); } }
public string AddPeripheral(int computerId, int id, string peripheralType, string manufacturer, string model, decimal price, double overallPerformance, string connectionType) { this.ValidateComputerWithIdExists(computerId); if (this.peripherals.Any(x => x.Id == id)) { throw new ArgumentException(ExceptionMessages.ExistingPeripheralId); } IPeripheral peripheral = CreateValidPeripheral(id, peripheralType, manufacturer, model, price, overallPerformance, connectionType); IComputer computer = this.computers.First(x => x.Id == computerId); computer.AddPeripheral(peripheral); this.peripherals.Add(peripheral); string result = string.Format(SuccessMessages.AddedPeripheral, peripheralType, peripheral.Id, computer.Id); return(result); }
public string AddPeripheral(int computerId, int id, string peripheralType, string manufacturer, string model, decimal price, double overallPerformance, string connectionType) { CheckIfPeripheralAlreadyExist(id); IPeripheral peripheral = CreatePeripheral(id, peripheralType, manufacturer, model, price, overallPerformance, connectionType); CheckIfComputerExist(computerId); IComputer computer = GetComputerById(computerId); computer.AddPeripheral(peripheral); peripherals.Add(peripheral); return(string.Format(SuccessMessages .AddedPeripheral, peripheral.GetType().Name, peripheral.Id, computerId)); }
public static IObservable <DeviceInfo> ReadDeviceInformation(this IPeripheral peripheral) => peripheral .GetKnownService(StandardUuids.DeviceInformationServiceUuid, true) .SelectMany(x => x.GetCharacteristics()) .SelectMany(x => x.Select(y => y.Read())) .Concat() .ToList() .Select(data => { var dev = new DeviceInfo(); foreach (var item in data) { switch (item.Characteristic.Uuid[3]) { case '4': dev.ModelNumber = BitConverter.ToString(item.Data); break; case '5': dev.SerialNumber = BitConverter.ToString(item.Data); break; case '6': dev.FirmwareRevision = BitConverter.ToString(item.Data); break; case '7': dev.HardwareRevision = BitConverter.ToString(item.Data); break; case '8': dev.SoftwareRevision = BitConverter.ToString(item.Data); break; case '9': dev.ManufacturerName = BitConverter.ToString(item.Data); break; } } return(dev); });
async Task <IGattCharacteristic> SetupCharacteristic(CancellationToken cancelToken) { var suuid = Guid.Parse(this.ServiceUuid); var cuuid = Guid.Parse(this.CharacteristicUuid); this.Info = "Searching for device.."; this.peripheral = await this.centralManager .ScanUntilPeripheralFound(this.DeviceName.Trim()) .ToTask(cancelToken); this.Info = "Device Found - Connecting"; await this.peripheral .ConnectWait() .ToTask(cancelToken); this.Info = "Connected - Requesting MTU Change"; if (this.peripheral is ICanRequestMtu mtu) { this.MTU = await mtu .RequestMtu(512) .ToTask(cancelToken); } else { this.MTU = this.peripheral.MtuSize; } this.Info = "Searching for characteristic"; var characteristic = await this.peripheral .GetKnownCharacteristics( suuid, cuuid ) .ToTask(cancelToken); this.Info = "Characteristic Found"; return(characteristic); }
public string AddPeripheral(int computerId, int id, string peripheralType, string manufacturer, string model, decimal price, double overallPerformance, string connectionType) { if (peripherals.Any(p => p.Id == id)) { throw new ArgumentException(ExceptionMessages.ExistingPeripheralId); } if (!IsValidPeriferial(peripheralType)) { throw new ArgumentException(ExceptionMessages.InvalidPeripheralType); } EnsureExistence(computerId); IPeripheral peripheral = null; switch (peripheralType) { case "Headset": peripheral = new Headset(id, manufacturer, model, price, overallPerformance, connectionType); break; case "Keyboard": peripheral = new Keyboard(id, manufacturer, model, price, overallPerformance, connectionType); break; case "Monitor": peripheral = new Monitor(id, manufacturer, model, price, overallPerformance, connectionType); break; case "Mouse": peripheral = new Mouse(id, manufacturer, model, price, overallPerformance, connectionType); break; } this.computers.First(c => c.Id == computerId).AddPeripheral(peripheral); this.peripherals.Add(peripheral); return(string.Format(SuccessMessages.AddedPeripheral, peripheralType, id, computerId)); }
void InitializeGPIO(IPeripheral device, string deviceName, IGPIOReceiver receiver, IList <object> irqEntry, PropertyInfo defaultConnector) { if (!(irqEntry[0] is string && irqEntry[1] is int)) { throw new ArgumentException(); } //May throw AmbiguousMatchException - then use BindingFlags.DeclaredOnly or sth var connector = device.GetType().GetProperty(irqEntry[0] as string); if (connector == null) { throw new ArgumentException(); } var gpio = connector.GetValue(device, null) as GPIO; if (gpio == null) { FailDevice(deviceName); } gpio.Connect(receiver, (int)irqEntry[1]); }
public bool TryGetMachineForPeripheral(IPeripheral p, out Machine machine) { if (peripheralToMachineCache.TryGetValue(p, out machine)) { return(true); } foreach (var candidate in Machines) { var candidateAsMachine = candidate; if (candidateAsMachine != null && candidateAsMachine.IsRegistered(p)) { machine = candidateAsMachine; peripheralToMachineCache.Add(p, machine); return(true); } } machine = null; return(false); }
public string AddPeripheral(int computerId, int id, string peripheralType, string manufacturer, string model, decimal price, double overallPerformance, string connectionType) { PeripheralType pType = new PeripheralType(); IPeripheral peripheral = null; if (DoesComputerExist(computerId)) { throw new ArgumentException(COMPUTER_DOESNT_EXIST); } else if (computers.Where(x => x.Id == computerId).Any(x => x.Peripherals.Any(x => x.Id == id))) { throw new ArgumentException("Peripheral with this id already exists."); } else if (!Enum.TryParse <PeripheralType>(peripheralType, out pType)) { throw new ArgumentException("Peripheral type is invalid."); } else if (pType == PeripheralType.Headset) { peripheral = new Headset(id, manufacturer, model, price, overallPerformance, connectionType); } else if (pType == PeripheralType.Keyboard) { peripheral = new Keyboard(id, manufacturer, model, price, overallPerformance, connectionType); } else if (pType == PeripheralType.Monitor) { peripheral = new Monitor(id, manufacturer, model, price, overallPerformance, connectionType); } else if (pType == PeripheralType.Mouse) { peripheral = new Mouse(id, manufacturer, model, price, overallPerformance, connectionType); } peripherals.Add(peripheral); computers.Where(i => i.Id == computerId).FirstOrDefault().AddPeripheral(peripheral); return($"Peripheral {peripheral.GetType().Name} with id { peripheral.Id} added successfully in computer with id {computerId}."); }
public string AddPeripheral(int computerId, int id, string peripheralType, string manufacturer, string model, decimal price, double overallPerformance, string connectionType) { CheckDoesComputerExist(computerId); var computer = this.computers.FirstOrDefault(c => c.Id == computerId); if (this.peripherals.Any(p => p.Id == id)) { throw new ArgumentException(ExceptionMessages.ExistingPeripheralId); } IPeripheral peripheral = CreatePeripheral(peripheralType, id, manufacturer, model, price, overallPerformance, connectionType); if (peripheral == null) { throw new ArgumentException(ExceptionMessages.InvalidPeripheralType); } computer.AddPeripheral(peripheral); this.peripherals.Add(peripheral); return(String.Format(SuccessMessages.AddedPeripheral, peripheralType, id, computerId)); }
public string AddPeripheral(int computerId, int id, string peripheralTypeName, string manufacturer, string model, decimal price, double overallPerformance, string connectionType) { var currentComputer = this.computers.FirstOrDefault(x => x.Id == computerId); NonExistingComputeId(currentComputer); if (!Enum.TryParse(peripheralTypeName, out PeripheralType peripheralType)) { throw new ArgumentException(ExceptionMessages.InvalidPeripheralType); } if (peripherals.Any(x => x.Id == id)) { throw new ArgumentException(ExceptionMessages.ExistingPeripheralId); } IPeripheral peripheral = null; switch (peripheralType) { case PeripheralType.Headset: peripheral = new Headset(id, manufacturer, model, price, overallPerformance, connectionType); break; case PeripheralType.Keyboard: peripheral = new Keyboard(id, manufacturer, model, price, overallPerformance, connectionType); break; case PeripheralType.Monitor: peripheral = new Monitor(id, manufacturer, model, price, overallPerformance, connectionType); break; case PeripheralType.Mouse: peripheral = new Mouse(id, manufacturer, model, price, overallPerformance, connectionType); break; } peripherals.Add(peripheral); currentComputer.AddPeripheral(peripheral); return(string.Format(SuccessMessages.AddedPeripheral, peripheralTypeName, id, computerId)); }
public string AddPeripheral(int computerId, int id, string peripheralType, string manufacturer, string model, decimal price, double overallPerformance, string connectionType) { IComputer currentComputer = computers.Where(x => x.Id == computerId).FirstOrDefault(); if (currentComputer == null) { throw new ArgumentException(ExceptionMessages.NotExistingComputerId); } IPeripheral currentPeripheral = null; if (peripherals.Any(x => x.Id == id)) { throw new ArgumentException(ExceptionMessages.ExistingPeripheralId); } if (peripheralType == "Headset") { currentPeripheral = new Headset(id, manufacturer, model, price, overallPerformance, connectionType); } else if (peripheralType == "Keyboard") { currentPeripheral = new Keyboard(id, manufacturer, model, price, overallPerformance, connectionType); } else if (peripheralType == "Monitor") { currentPeripheral = new Monitor(id, manufacturer, model, price, overallPerformance, connectionType); } else if (peripheralType == "Mouse") { currentPeripheral = new Mouse(id, manufacturer, model, price, overallPerformance, connectionType); } else { throw new ArgumentException(ExceptionMessages.InvalidPeripheralType); } currentComputer.AddPeripheral(currentPeripheral); peripherals.Add(currentPeripheral); //public const string AddedComponent = "Component {0} with id {1} added successfully in computer with id {2}."; return(string.Format(SuccessMessages.AddedPeripheral, currentPeripheral.GetType().Name, currentPeripheral.Id, currentComputer.Id)); }
public string AddPeripheral(int computerId, int id, string peripheralType, string manufacturer, string model, decimal price, double overallPerformance, string connectionType) { CheckIfComputerExists(computerId); if (periherals.Any(x => x.Id == id)) { throw new ArgumentException(ExceptionMessages.ExistingPeripheralId); } IPeripheral peripheral = peripheralType switch { nameof(Headset) => new Headset(id, manufacturer, model, price, overallPerformance, connectionType), nameof(Keyboard) => new Keyboard(id, manufacturer, model, price, overallPerformance, connectionType), nameof(Monitor) => new Monitor(id, manufacturer, model, price, overallPerformance, connectionType), nameof(Mouse) => new Mouse(id, manufacturer, model, price, overallPerformance, connectionType), _ => throw new ArgumentException(ExceptionMessages.InvalidPeripheralType) }; IComputer computer = computers.FirstOrDefault(x => x.Id == computerId); computer.AddPeripheral(peripheral); periherals.Add(peripheral); return(string.Format(SuccessMessages.AddedPeripheral, peripheralType, id, computerId)); }
//[source,dest] or [dest] with non-null defaultConnector void InitializeGPIO(IPeripheral device, string deviceName, IGPIOReceiver receiver, IList <int> irqEntry, PropertyInfo defaultConnector) { var periByNumber = device as INumberedGPIOOutput; if (irqEntry.Count == 2 && periByNumber != null) { periByNumber.Connections[irqEntry[0]].Connect(receiver, irqEntry[1]); } else if (irqEntry.Count == 1 && defaultConnector != null) { var gpioField = defaultConnector.GetValue(device, null) as GPIO; if (gpioField == null) { FailDevice(deviceName); } gpioField.Connect(receiver, irqEntry[0]); } else { throw new ArgumentException(); } }
public override void OnNavigatedTo(INavigationParameters parameters) { base.OnNavigatedTo(parameters); this.peripheral = parameters.GetValue <IPeripheral>("Peripheral"); this.Name = this.peripheral.Name; this.Uuid = this.peripheral.Uuid; this.IsMtuVisible = this.peripheral.IsMtuRequestsAvailable(); this.IsPairingVisible = this.peripheral.IsPairingRequestsAvailable(); this.PairingText = this.peripheral.TryGetPairingStatus() == PairingState.Paired ? "Peripheral Paired" : "Pair Peripheral"; //this.peripheral // .WhenConnected() // .Select(x => x.ReadRssiContinuously(TimeSpan.FromSeconds(3))) // .Switch() // .SubOnMainThread(x => this.Rssi = x) // .DisposedBy(this.DeactivateWith); this.peripheral .WhenStatusChanged() .Do(x => { if (x == ConnectionState.Connected) { this.GattCharacteristics.Clear(); } }) .Select(x => x switch { ConnectionState.Connecting => "Cancel Connection", ConnectionState.Connected => "Disconnect", ConnectionState.Disconnected => "Connect", ConnectionState.Disconnecting => "Disconnecting..." })
public string AddPeripheral(int computerId, int id, string peripheralType, string manufacturer, string model, decimal price, double overallPerformance, string connectionType) { IsIdExist(computerId); if (peripheralType == "Headset") { peripheral = new Headset(id, manufacturer, model, price, overallPerformance, connectionType); } else if (peripheralType == "Keyboard") { peripheral = new Keyboard(id, manufacturer, model, price, overallPerformance, connectionType); } else if (peripheralType == "Monitor") { peripheral = new Monitor(id, manufacturer, model, price, overallPerformance, connectionType); } else if (peripheralType == "Mouse") { peripheral = new Mouse(id, manufacturer, model, price, overallPerformance, connectionType); } else { throw new ArgumentException(ExceptionMessages.InvalidPeripheralType); } computers.First(x => x.Id == computerId).AddPeripheral(peripheral); if (peripherals.Any(x => x.Id == id)) { throw new ArgumentException(ExceptionMessages.ExistingPeripheralId); } else { peripherals.Add(peripheral); } return(string.Format(SuccessMessages.AddedPeripheral, peripheralType, id, computerId)); }
public string AddPeripheral(int computerId, int id, string peripheralType, string manufacturer, string model, decimal price, double overallPerformance, string connectionType) { IComputer comp = IsExist(computerId); if (comp.Peripherals.Any(x => x.Id == id)) { throw new ArgumentException(ExceptionMessages.ExistingPeripheralId); } if (!Enum.TryParse(peripheralType, out PeripheralType)) { throw new ArgumentException(ExceptionMessages.InvalidPeripheralType); } IPeripheral peripheral = null; switch (PeripheralType) { case PeripheralType.Headset: peripheral = new Headset(id, manufacturer, model, price, overallPerformance, connectionType); break; case PeripheralType.Keyboard: peripheral = new Keyboard(id, manufacturer, model, price, overallPerformance, connectionType); break; case PeripheralType.Monitor: peripheral = new Monitor(id, manufacturer, model, price, overallPerformance, connectionType); break; case PeripheralType.Mouse: peripheral = new Mouse(id, manufacturer, model, price, overallPerformance, connectionType); break; } comp.AddPeripheral(peripheral); peripherals.Add(peripheral); return(string.Format(SuccessMessages.AddedPeripheral, peripheral.GetType().Name, id, computerId)); }
/// <summary> /// Waits for connection to actually happen /// </summary> /// <param name="peripheral"></param> /// <returns></returns> public static IObservable <IPeripheral> ConnectWait(this IPeripheral peripheral) => Observable.Create <IPeripheral>(ob => { var sub1 = peripheral .WhenConnected() .Take(1) .Subscribe(_ => ob.Respond(peripheral)); var sub2 = peripheral .WhenConnectionFailed() .Subscribe(ob.OnError); peripheral.ConnectIf(); return(() => { sub1.Dispose(); sub2.Dispose(); if (peripheral.Status != ConnectionState.Connected) { peripheral.CancelConnection(); } }); });
//public override void OnAppearing() //{ // this.bleManager // .Scan() // .Subscribe(x => // { // }) // .DisposeWith(this.DeactivateWith); //} //public override void OnDisappearing() //{ // Console.WriteLine("ONDISAPPEARING CALLED"); //} async Task PairingTest() { this.Append("Scanning.."); this.peripheral = await bleManager .ScanForUniquePeripherals(new ScanConfig { ServiceUuids = { "FFF0" } }) .Take(1) .ToTask(this.cancelSrc.Token); this.Append("Device Found"); //await this.peripheral.WithConnectIf().ToTask(this.cancelSrc.Token); this.Append("Device Connected - trying to pair"); var result = await this.peripheral.TryPairingRequest().ToTask(this.cancelSrc.Token); if (result == null) { this.Append("Pairing Not Supported"); } else { this.Append("Pairing Result: " + result.Value); } }
public void Remove(IPeripheral peripheral) { lock(sync) { // list is scanned first blocks = blocks.Where(x => x.Peripheral.Peripheral != peripheral).ToArray(); // then dictionary var toRemove = shortBlocks.Where(x => x.Value.Peripheral.Peripheral == peripheral).Select(x => x.Key).ToArray(); foreach(var keyToRemove in toRemove) { shortBlocks.Remove(keyToRemove); } InvalidateLastBlock(); } }
private bool TryFindPeripheralByName(string name, out IPeripheral peripheral, out string longestMatch) { longestMatch = string.Empty; if(currentMachine == null) { peripheral = null; return false; } string longestMatching; string currentMatch; string longestPrefix = string.Empty; var ret = currentMachine.TryGetByName(name, out peripheral, out longestMatching); longestMatch = longestMatching; if(!ret) { foreach(var prefix in usings) { ret = currentMachine.TryGetByName(prefix + name, out peripheral, out currentMatch); if(longestMatching.Split('.').Length < currentMatch.Split('.').Length - prefix.Split('.').Length) { longestMatching = currentMatch; longestPrefix = prefix; } if(ret) { break; } } } longestMatch = longestPrefix + longestMatching; return ret; }
private bool IsShortNotation(IPeripheral peripheral, PropertyInfo defaultConnector, IList<dynamic> entry) { return (peripheral is INumberedGPIOOutput && entry.Count == 2 && entry.All(x => x is int)) || (defaultConnector != null && entry.Count == 1 && entry[0] is int) || (entry.Count == 2 && entry[0] is String && entry[1] is int); }
void InitializeGPIO(IPeripheral device, IGPIOReceiver receiver, IList<object> irqEntry, PropertyInfo defaultConnector) { if(!(irqEntry[0] is string && irqEntry[1] is int)) { throw new ArgumentException(); } //May throw AmbiguousMatchException - then use BindingFlags.DeclaredOnly or sth var connector = device.GetType().GetProperty(irqEntry[0] as string); if(connector == null) { throw new ArgumentException(); } var gpio = connector.GetValue(device, null) as GPIO; if(gpio == null) { connector.SetValue(device, new GPIO(), null); gpio = connector.GetValue(device, null) as GPIO; } gpio.Connect(receiver, (int)irqEntry[1]); }
//[source,dest] or [dest] with non-null defaultConnector void InitializeGPIO(IPeripheral device, IGPIOReceiver receiver, IList<int> irqEntry, PropertyInfo defaultConnector) { var periByNumber = device as INumberedGPIOOutput; if(irqEntry.Count == 2 && periByNumber != null) { periByNumber.Connections[irqEntry[0]].Connect(receiver, irqEntry[1]); } else if(irqEntry.Count == 1 && defaultConnector != null) { var gpioField = defaultConnector.GetValue(device, null) as GPIO; if(gpioField == null) { defaultConnector.SetValue(device, new GPIO(), null); gpioField = defaultConnector.GetValue(device, null) as GPIO; } gpioField.Connect(receiver, irqEntry[0]); } else { throw new ArgumentException(); } }
public PeripheralsChangedEventArgs(IPeripheral peripheral, PeripheralChangeType operation) { Peripheral = peripheral; Operation = operation; }
/// <summary> /// Initializes a new instance of the <see cref="Emul8.Core.Structure.Registers.DoubleWordRegisterCollection"/> class. /// </summary> /// <param name="parent">Parent peripheral (for logging purposes).</param> /// <param name="registersMap">Map of register offsets and registers.</param> public DoubleWordRegisterCollection(IPeripheral parent, IDictionary<long, DoubleWordRegister> registersMap) { this.parent = parent; this.registers = new Dictionary<long, DoubleWordRegister>(registersMap); }
private static DoubleWordRegister[] CreateRegistersGroup(int size, IPeripheral parent, int position, int width, FieldMode mode = FieldMode.Read | FieldMode.Write, Action<int, uint> writeCallback = null, Func<int, uint> valueProviderCallback = null, string name = null) { var result = new DoubleWordRegister[size]; for(var i = 0; i < size; i++) { var j = i; result[i] = new DoubleWordRegister(parent) .WithValueField(position, width, mode, name: name + j, valueProviderCallback: valueProviderCallback == null ? (Func<uint, uint>)null : _ => valueProviderCallback(j), writeCallback: writeCallback == null ? (Action<uint, uint>)null : (_, @new) => { writeCallback(j, @new); }); } return result; }