Exemplo n.º 1
0
        public DroneConnectionInfo GetConnectionInfo()
        {
            var info = new DroneConnectionInfo();

            try {
                var         xml = send("get_connection_status", null);
                XmlDocument d   = new XmlDocument();
                d.Load(new StringReader(xml));
                var signalStrengthStr = d.SelectSingleNode("response/SignalStrength").InnerText;
                if (string.IsNullOrEmpty(signalStrengthStr))
                {
                    info.SignalStrength = int.Parse(d.SelectSingleNode("response/SignalIcon").InnerText) * 20;
                }
                else
                {
                    info.SignalStrength = int.Parse(signalStrengthStr);
                }

                var networkType = int.Parse(d.SelectSingleNode("response/CurrentNetworkType").InnerText);
                switch (networkType)
                {
                case 0: info.ConnectionType = "No service"; break;

                case 1: info.ConnectionType = "GSM"; break;

                case 2: info.ConnectionType = "GPRS"; break;

                case 3: info.ConnectionType = "EDGE"; break;

                case 4: info.ConnectionType = "WCDMA"; break;

                case 5: info.ConnectionType = "HSDPA"; break;

                case 6: info.ConnectionType = "HSUPA"; break;

                case 7: info.ConnectionType = "HSPA"; break;

                case 8: info.ConnectionType = "TDSCDMA"; break;

                case 9: info.ConnectionType = "HSPA+"; break;

                case 10: info.ConnectionType = "EVDO rev 0"; break;

                case 11: info.ConnectionType = "EVDO rev A"; break;

                case 12: info.ConnectionType = "EVDO rev B"; break;

                case 13: info.ConnectionType = "1xRTT"; break;

                case 14: info.ConnectionType = "UMB"; break;

                case 15: info.ConnectionType = "1xEVDV"; break;

                case 16: info.ConnectionType = "3xRTT"; break;

                case 17: info.ConnectionType = "HSPA+ 64QAM"; break;

                case 18: info.ConnectionType = "HSPA+ MIMO"; break;

                case 19: info.ConnectionType = "LTE"; break;

                case 41: info.ConnectionType = "3G"; break;

                default: info.ConnectionType = "Unknown"; break;
                }
            } catch {
                info.SignalStrength = -1;
                info.ConnectionType = "No signal";
            }
            try {
                var         xml = send("get_connection_traffic", null);
                XmlDocument d   = new XmlDocument();
                d.Load(new StringReader(xml));
                info.BytesPerSecIn  = int.Parse(d.SelectSingleNode("response/CurrentDownloadRate").InnerText);
                info.BytesPerSecOut = int.Parse(d.SelectSingleNode("response/CurrentUploadRate").InnerText);
                info.TotalBytesIn   = int.Parse(d.SelectSingleNode("response/CurrentDownload").InnerText);
                info.TotalBytesOut  = int.Parse(d.SelectSingleNode("response/CurrentUpload").InnerText);
            } catch {
                info.BytesPerSecIn  = -1;
                info.BytesPerSecOut = -1;
                info.TotalBytesIn   = -1;
                info.TotalBytesOut  = -1;
            }
            try {
                info.LastUpdate = int.Parse(send("get_drone_lastcontact", null));
            } catch {
                info.LastUpdate = -1;
            }
            return(info);
        }
Exemplo n.º 2
0
        private void dispatcherTimer_Tick(object sender, EventArgs e)
        {
            DroneConnectionInfo info = _proxy.GetConnectionInfo();
            int lastContactInSec     = info.LastUpdate;
            int signalStrength       = info.SignalStrength;

            if (lastContactInSec > 10)
            {
                txtInfo.Text       = "DRONE" + Environment.NewLine + "OFFLINE" + Environment.NewLine + Environment.NewLine + lastContactInSec + " s";
                signalStrength     = 0;
                txtInfo.Foreground = new SolidColorBrush(Color.FromRgb(255, 20, 20));
            }
            else
            {
                txtInfo.Text =
                    signalStrength + "% " + info.ConnectionType + Environment.NewLine +
                    FormatBytes(info.TotalBytesIn) + " in" + Environment.NewLine +
                    FormatBytes(info.TotalBytesOut) + " out" + Environment.NewLine +
                    FormatBytes(info.BytesPerSecIn) + "/s in" + Environment.NewLine +
                    FormatBytes(info.BytesPerSecOut) + "/s out" + Environment.NewLine +
                    lastContactInSec + " s";
            }
            prgConnection.Value   = signalStrength;
            prgConnection.ToolTip = prgConnection.Value;
            if (signalStrength > 80)
            {
                prgConnection.Foreground = new SolidColorBrush(Color.FromRgb(18, 234, 36));
                txtInfo.Foreground       = new SolidColorBrush(Color.FromRgb(20, 255, 20));
            }
            else if (signalStrength > 60)
            {
                prgConnection.Foreground = new SolidColorBrush(Color.FromRgb(162, 234, 75));
                txtInfo.Foreground       = new SolidColorBrush(Color.FromRgb(20, 255, 20));
            }
            else if (signalStrength > 40)
            {
                prgConnection.Foreground = new SolidColorBrush(Color.FromRgb(234, 234, 14));
                txtInfo.Foreground       = new SolidColorBrush(Color.FromRgb(20, 255, 20));
            }
            else if (signalStrength > 20)
            {
                prgConnection.Foreground = new SolidColorBrush(Color.FromRgb(255, 170, 0));
                txtInfo.Foreground       = new SolidColorBrush(Color.FromRgb(255, 255, 0));
            }
            else if (signalStrength > 0)
            {
                prgConnection.Foreground = new SolidColorBrush(Color.FromRgb(255, 56, 56));
                txtInfo.Foreground       = new SolidColorBrush(Color.FromRgb(255, 255, 0));
            }
            else
            {
                prgConnection.Foreground = new SolidColorBrush(Color.FromRgb(255, 20, 20));
            }
            if (!_hasFrontedPlayer)
            {
                try {
                    IntPtr hWnd = IntPtr.Zero;
                    foreach (Process pList in Process.GetProcesses())
                    {
                        if (pList.MainWindowTitle.Contains("GStreamer D3D"))
                        {
                            hWnd = pList.MainWindowHandle;
                            SetWindowPos(hWnd, new IntPtr(-1), 0, 0, 0, 0, 0x1 | 0x2);
                            _hasFrontedPlayer = true;
                        }
                    }
                    if (_videoPlayer != null && !_videoPlayer.HasExited)
                    {
                        ShowWindowAsync(_videoPlayer.MainWindowHandle, SW_SHOWMINIMIZED);
                    }
                } catch { }
            }
        }