/// <summary> /// Get the network properties /// </summary> private void GetNetworkProperties(out string eth0, out string wlan0, out string hostName) { eth0 = ""; wlan0 = ""; hostName = ""; try { BrainHatNetwork.NetworkUtilities.GetNetworkAddresses(out eth0, out wlan0); hostName = NetworkUtilities.GetHostName(); } catch (Exception e) { Log?.Invoke(this, new LogEventArgs(this, "RunStatusMonitorAsync", e, LogLevel.ERROR)); } }
/// <summary> /// Process the logging queue /// </summary> void ProcessLogs() { try { // empty the queue List <LogEventArgs> allEvents = new List <LogEventArgs>(); while (!LogsQueue.IsEmpty) { if (LogsQueue.TryDequeue(out var nextLog)) { allEvents.AddRange(GenerateLogsForLogEvent(nextLog)); } } // send event LoggedEvents?.Invoke(this, allEvents); LogToLog4(allEvents); // broadcast to listeners foreach (var nextLog in allEvents) { if (nextLog.Level >= LogLevelDisplay) { var test = new RemoteLogEventArgs(nextLog); var test2 = test.Sender.ToString(); var sendBytes = Encoding.UTF8.GetBytes($"log?sender={NetworkUtilities.GetHostName()}&log={JsonConvert.SerializeObject(new RemoteLogEventArgs(nextLog))}\n"); } LogBuffer.Enqueue(nextLog); } while (LogBuffer.Count > 333) { LogBuffer.TryDequeue(out var discard); } } catch (Exception e) { System.Diagnostics.Debug.WriteLine($"Exception in logging {e}"); } }
/// <summary> /// Run function /// </summary> private async Task RunDataBroadcastServerAsync(CancellationToken cancelToken) { try { var info = new StreamInfo("bhStatus", "bhStatus", 1, IRREGULAR_RATE, channel_format_t.cf_string, NetworkUtilities.GetHostName()); info.desc().append_child_value("boardId", BoardId.ToString()); info.desc().append_child_value("sampleRate", SampleRate.ToString()); // create UDP client using (var outlet = new StreamOutlet(info)) { try { while (!cancelToken.IsCancellationRequested) { await NotifyDataToBroadcast.WaitAsync(cancelToken); while (!StringsToBroadcast.IsEmpty) { try { StringsToBroadcast.TryDequeue(out var broadcastString); outlet.push_sample(new string[] { broadcastString }); } catch (Exception ex) { Log?.Invoke(this, new LogEventArgs(this, "RunBroadcastServerAsync", ex, LogLevel.ERROR)); } } } } catch (OperationCanceledException) { } catch (Exception e) { Log?.Invoke(this, new LogEventArgs(this, "RunBroadcastServerAsync", e, LogLevel.ERROR)); } } } catch (Exception e) { Log?.Invoke(this, new LogEventArgs(this, "RunBroadcastServerAsync", e, LogLevel.ERROR)); } }