// get new messages from the utopia-hub, and store the list of new public List <UtopiaMessage> getNewMessages(int timeout_ms = 0) { if (this.client == null) { return(null); } // get any messages with predictions this.msgs = this.client.getNewMessages();//timeout_ms); if (timeout_ms > 0) { Console.WriteLine("Warning: timeout not supported yet!!"); } // process these messages as needed & call-callbacks if (this.msgs.Count > 0) { //foreach (MessageDegelateType h in this.messageHandlers) { // h.Invoke(this.msgs); //} if (messageHandlers != null) { this.messageHandlers.Invoke(this.msgs); } PredictedTargetProb newPrediction = null; foreach (UtopiaMessage m in this.msgs) { if (m.msgID() == PredictedTargetProb.MSGID) { this.lastPrediction = (PredictedTargetProb)m; // process new prediction callbacks //foreach (PredictionDegelateType h in this.predictionHandlers) { // h.Invoke(newPrediction); //} if (predictionHandlers != null) { this.predictionHandlers.Invoke(this.lastPrediction); } } else if (m.msgID() == Selection.MSGID) { // process selection callbacks //foreach (SelectionDegelateType h in this.selectionHandlers) { // h.Invoke(((Selection)m).objID); //} if (selectionHandlers != null) { this.selectionHandlers.Invoke(((Selection)m).objID); } } else if (m.msgID() == SignalQuality.MSGID) { this.lastSignalQuality = (SignalQuality)m; if (signalQualityHandlers != null) { this.signalQualityHandlers.Invoke(this.lastSignalQuality.signalQuality); } } } } return(this.msgs); }
public void DisplayDhcpNodesInfo() { var wiFiToString = IsWifi ? $"{SignalQuality.ToString().PadLeft(3)}%" : ""; var toString = $"{HostName.Trim().PadRight(20, ' ').Substring(0, 20)}, " + $"{IpAddress.Trim().PadRight(15)}, {MacAddress}, {LeaseTime:c} {wiFiToString}"; Console.WriteLine(toString); }
public void DisplayGeneralInfo() { var wiFiToString = IsWifi ? $"{SignalQuality.ToString().PadLeft(3)}%" : ""; var toString = $"{HostName.Trim().PadRight(20, ' ').Substring(0, 20)}, " + $"{IpAddress.Trim().PadRight(15)}, {MacAddress}, {ConnectionsCount.ToString().PadLeft(3)}, {wiFiToString}"; var originalFontColor = Console.ForegroundColor; var fontColor = IsActive ? ConsoleColor.White : ConsoleColor.DarkGray; Console.ForegroundColor = fontColor; Console.WriteLine(toString); Console.ForegroundColor = originalFontColor; }
public void DisplayWiFiNodesInfo() { var toString = $"{HostName.Trim().PadRight(20, ' ').Substring(0, 20)}, " + $"{IpAddress.Trim().PadRight(15)}, {MacAddress}," + //$"{ Interface}, " + $"{ UpTime.ToString("c").PadLeft(11)}, { TxRateMb.ToString().PadLeft(3)}, { RxRateMb.ToString().PadLeft(3)}, " + //$"{ Info}, " + $"{SignalLeveldB.ToString().PadLeft(3)}, {NoiseLeveldB.ToString().PadLeft(4)}, {SignalToNoiseRatiodB.ToString().PadLeft(4)}, {SignalQuality.ToString().PadLeft(3)}%"; Console.WriteLine(toString); }
/// <summary> /// </summary> /// <param name="request"></param> /// <param name="param"></param> /// <returns></returns> public override ModemRequestContext Handle(ModemRequestContext request, string param) { var signalQuality = new SignalQuality { dBmW = 0, IsValid = false, Percent = string.Empty }; if (param == Command) { var result = request.Response; var helper = ModemManager.Instance; var received = false; helper.OnSerialPortOpened += (sender, response) => { if (!response) { return; } try { received = true; helper.SendString(param); } catch (Exception exception) { Debug.WriteLine(exception.Message); request.Response.IsSuccess = false; //request.Description.Add($"Error send {Command} - {exception.Message}"); received = false; #if DEBUG throw; #endif } }; helper.OnStatusChanged += (sender, response) => { Debug.WriteLine(response); }; helper.OnDataReceived += (sender, response) => { if (string.IsNullOrEmpty(response)) { result.SignalQuality = signalQuality; } else { try { var matches = Regex.Matches(response, @"[\S ]+", RegexOptions.Singleline); if (matches.Count >= 2 && "OK".Equals(matches[matches.Count - 1].Value, StringComparison.OrdinalIgnoreCase)) { matches = Regex.Matches(matches[matches.Count - 2].Value, @"\d+", RegexOptions.None); if (matches.Count > 0) { var r = int.Parse(matches[0].Value); if (r > 32) { signalQuality.dBmW = 0; result.SignalQuality.Percent = "0.0"; result.SignalQuality.IsValid = false; } if (r == 99) { result.SignalQuality = signalQuality; } else { result.SignalQuality.dBmW = -113 + (r << 1); result.SignalQuality.Percent = (r * 100.0 / 31.0).ToString("F2"); result.SignalQuality.IsValid = true; result.IsSuccess = true; } } } } finally { received = false; (sender as ModemManager)?.Close(); } } }; if (!helper.IsOpen) { helper.Open(request.Connection.PortName); } else { helper.Close(); helper.Open(request.Connection.PortName); } lock (_locker) { while (received) { Monitor.Wait(_locker, TimeSpan.FromMilliseconds(Sleep)); } } return(request); } return(base.Handle(request, param)); }
public UtopiaMessage decodePayload() { // Decode the payload UtopiaMessage evt = null; if ((this.msgID == StimulusEvent.MSGID)) { if ((VERBOSITY > 2)) { System.Console.WriteLine("Trying to read " + StimulusEvent.MSGNAME + " message"); } evt = StimulusEvent.deserialize(this.msgbuffer); } else if ((this.msgID == PredictedTargetProb.MSGID)) { if ((VERBOSITY > 2)) { System.Console.WriteLine("Trying to read " + PredictedTargetProb.MSGNAME + " message"); } evt = PredictedTargetProb.deserialize(this.msgbuffer); } else if ((this.msgID == PredictedTargetDist.MSGID)) { if ((VERBOSITY > 2)) { System.Console.WriteLine("Trying to read " + PredictedTargetDist.MSGNAME + " message"); } evt = PredictedTargetDist.deserialize(this.msgbuffer); } else if ((this.msgID == ModeChange.MSGID)) { if ((VERBOSITY > 2)) { System.Console.WriteLine("Trying to read " + ModeChange.MSGNAME + " message"); } evt = ModeChange.deserialize(this.msgbuffer); } else if ((this.msgID == Reset.MSGID)) { if ((VERBOSITY > 2)) { System.Console.WriteLine("Trying to read " + Reset.MSGNAME + " message"); } evt = Reset.deserialize(this.msgbuffer); } else if ((this.msgID == NewTarget.MSGID)) { if ((VERBOSITY > 2)) { System.Console.WriteLine("Trying to read " + NewTarget.MSGNAME + " message"); } evt = NewTarget.deserialize(this.msgbuffer); } else if ((this.msgID == Heartbeat.MSGID)) { if ((VERBOSITY > 2)) { System.Console.WriteLine("Trying to read " + Heartbeat.MSGNAME + " message"); } evt = Heartbeat.deserialize(this.msgbuffer); } else if ((this.msgID == SignalQuality.MSGID)) { if ((VERBOSITY > 2)) { System.Console.WriteLine("Trying to read " + SignalQuality.MSGNAME + " message"); } evt = SignalQuality.deserialize(this.msgbuffer); } else { throw new ClientException("Unsupported Message type: " + this.msgID); } if ((VERBOSITY > 1)) { System.Console.WriteLine("Got message: " + evt.ToString()); } return(evt); }