protected override void StartWatcher() { _logger.NotifyUserInfo("TCPIP Mgr", $"Started Watcher"); _ssdpClient = NetworkServices.GetSSDPClient(); _ssdpClient.ShowDiagnostics = true; _ssdpClient.NewDeviceFound += _ssdpClient_NewDeviceFound; _ssdpClient.SsdpQueryAsync(port: 1900); }
public override async Task <bool> ConnectAsync() { _socket = new StreamSocket(); State = States.Connecting; try { await _socket.ConnectAsync(_deviceService.ConnectionHostName, _deviceService.ConnectionServiceName); _writer = new DataWriter(_socket.OutputStream); var dataReader = new DataReader(_socket.InputStream); dataReader.InputStreamOptions = InputStreamOptions.Partial; ReceiveDataAsync(dataReader); State = States.Connected; ConnectCommand.Enabled = false; _logger.NotifyUserInfo("BT Channel", "Connected!"); return(true); } catch (Exception ex) { _logger.NotifyUserError("BT Channel", ex.Message); return(false); } }
public async void Listen() { try { // keep reading the serial input while (true) { await ReadAsync(_readCancellationTokenSource.Token); } } catch (TaskCanceledException) { _logger.NotifyUserInfo("SerialChannel_Listen", "Task Cancelled - Closing"); } catch (Exception ex) { _logger.NotifyUserError("SerialChannel_Listen", ex.Message); } finally { // Cleanup once complete if (_dataReaderObject != null) { _dataReaderObject.DetachStream(); _dataReaderObject = null; } } }
public TCPListener(ISoccerBotLogger logger, Server server, int port) { _server = server; _logger = logger; _port = port; _logger.NotifyUserInfo("TCPIP Listener", $"Created Listener"); _listener = new Windows.Networking.Sockets.StreamSocketListener(); _listener.ConnectionReceived += _listener_ConnectionReceived; }
public BluetoothChannel(DeviceInformation deviceInfo, ISoccerBotLogger logger) { _logger = logger; _deviceInfo = deviceInfo; Id = _deviceInfo.Id; DeviceName = _deviceInfo.Name; State = States.Disconnected; _logger.NotifyUserInfo("BT Channel", "Created"); }
public TCPIPChannel(uPnPDevice device, ISoccerBotLogger logger) { _remoteDevice = device; DeviceName = device.FriendlyName; Id = device.UDN + " " + device.IPAddress; _logger = logger; _logger.NotifyUserInfo("TCPIP Channel", $"Created Device for: {DeviceName}"); _parser = new MessageParser(); _parser.MessageReady += _parser_MessageReady; }
public async void StartListening() { try { _logger.NotifyUserInfo("TCPIP Listener", $"Started Listening on Port {_port}"); await _listener.BindServiceNameAsync(_port.ToString()); } catch (Exception ex) { _logger.NotifyUserError("TCPIP Listener", ex.Message); } }
private void ProcessBuffer(byte[] buffer) { if (_currentIncomingMessage == null) { _currentIncomingMessage = new mBlockIncomingMessage(); } foreach (var value in buffer) { /* Received message format * 0xFF - Header Byte 1 * 0x55 - Header Byte 2 * 0xXX - Message index corresponding to request * 0x0X - Payload Type - 1 byte 2 float 3 short 4 len+string 5 double * [0xXX....0xXX] Payload matcing size * 0x0D * 0x0A */ _currentIncomingMessage.AddByte(value); if (_currentIncomingMessage.EndsWithCRLF()) { IncomingMessages.Add(_currentIncomingMessage); // Debug.WriteLine(String.Format("{0:000000} <<<", (DateTime.Now - _start).TotalMilliseconds) + _currentIncomingMessage.MessageHexString); _logger.NotifyUserInfo("mBlock", "<<< " + _currentIncomingMessage.MessageHexString); if (_currentIncomingMessage.BufferSize > 4) { _currentIncomingMessage.MessageSerialNumber = _currentIncomingMessage.Buffer[2]; ProcessMessage(_currentIncomingMessage); } _currentIncomingMessage = new mBlockIncomingMessage(); } } }
private async void _parser_MessageReady(object sender, NetworkMessage e) { if (e.MessageTypeCode == SystemMessages.Ping) { await Write(SystemMessages.CreatePong().GetBuffer()); _logger.NotifyUserInfo("Client_MessageReceived", "Ping Received >> Pong Sent"); } else { MessageRecevied?.Invoke(sender, e); } _lastMessageDateStamp = DateTime.Now; }
private void _parser_MessageReady(object sender, NetworkMessage e) { _logger.NotifyUserInfo("Client_MessageReceived", "Message Received"); RaiseNetworkMessageReceived(e); }
protected override void StartWatcher() { // Request additional properties string[] requestedProperties = new string[] { "System.Devices.Aep.DeviceAddress", "System.Devices.Aep.IsConnected" }; _deviceWatcher = DeviceInformation.CreateWatcher("(System.Devices.Aep.ProtocolId:=\"{e0cbf06c-cd8b-4647-bb8a-263b43f0f974}\")", requestedProperties, DeviceInformationKind.AssociationEndpoint); _logger.NotifyUserInfo("BT Mgr", "Watcher Started"); // Hook up handlers for the watcher events before starting the watcher _deviceWatcher.Added += new TypedEventHandler <DeviceWatcher, DeviceInformation>((watcher, deviceInfo) => { // Since we have the collection databound to a UI element, we need to update the collection on the UI thread. Services.DispatcherServices.Invoke(() => { // Make sure device name isn't blank if (deviceInfo.Name != "") { _logger.NotifyUserInfo("BT Mgr", $"Found Channel => " + deviceInfo.Name); RaiseDeviceFoundEvent(new BluetoothChannel(deviceInfo, _logger)); } }); }); _deviceWatcher.Updated += new TypedEventHandler <DeviceWatcher, DeviceInformationUpdate>((watcher, deviceInfoUpdate) => { Services.DispatcherServices.Invoke(() => { _logger.NotifyUserInfo("BT Mgr", $"Device Updated => {deviceInfoUpdate.Id}."); var updatedChannel = _channels.Where(itm => itm.Id == deviceInfoUpdate.Id).FirstOrDefault(); if (updatedChannel != null) { //TODO: Maybe introduce again. //updatedChannel.Update(deviceInfoUpdate); } }); }); _deviceWatcher.EnumerationCompleted += new TypedEventHandler <DeviceWatcher, Object>((watcher, obj) => { _logger.NotifyUserInfo("BT Mgr", $"{_channels.Count} devices found. Enumeration completed. Watching for updates..."); }); _deviceWatcher.Removed += new TypedEventHandler <DeviceWatcher, DeviceInformationUpdate>((watcher, deviceInfoUpdate) => { // Since we have the collection databound to a UI element, we need to update the collection on the UI thread. Services.DispatcherServices.Invoke(() => { _logger.NotifyUserInfo("BT Mgr", $"Device Removed => {deviceInfoUpdate.Id}."); var removedDevice = _channels.Where(itm => itm.Id == deviceInfoUpdate.Id).FirstOrDefault(); if (removedDevice != null) { _channels.Remove(removedDevice); } }); }); _deviceWatcher.Stopped += new TypedEventHandler <DeviceWatcher, Object>((watcher, obj) => { Services.DispatcherServices.Invoke(() => { var status = (watcher.Status == DeviceWatcherStatus.Aborted ? "aborted" : "stopped"); _logger.NotifyUserInfo("BT Mgr", $"BT Manager State Change: {status}."); _channels.Clear(); }); }); _deviceWatcher.Start(); StartWatcherCommand.Enabled = false; StopWatcherCommand.Enabled = true; }