Exemplo n.º 1
0
        private void AddRadioEvents(DSEVENTSEntry entry)
        {
            int pFrom = entry.Data.IndexOf("Warning <Code> 44008 <radioLostEvents>  ") + "Warning <Code> 44008 <radioLostEvents>  ".Length;
            int pTo   = entry.Data.IndexOf("\r<Description>FRC:  Robot radio detection times.");

            if (pTo < 0 || pFrom < 0 || pTo <= pFrom)
            {
                return;
            }
            string processedData = entry.Data.Substring(pFrom, pTo - pFrom).Replace("<radioSeenEvents>", "~");

            string[] dataInArray = processedData.Split('~');
            if (!dataInArray[0].Trim().Equals(""))
            {
                foreach (var num in dataInArray[0].Trim().Split(','))
                {
                    double lostTime = 0;
                    if (double.TryParse(num, out lostTime))
                    {
                        DateTime  newTime = entry.Time.AddSeconds(-lostTime);
                        DataPoint pRL     = new DataPoint(newTime.ToOADate(), 14.7);
                        pRL.Color       = Color.Yellow;
                        pRL.MarkerSize  = 6;
                        pRL.MarkerStyle = MarkerStyle.Square;
                        pRL.YValues[0]  = 14.7;
                        GraphView.AddMessage(pRL);
                        AddEntryToDict(newTime.ToOADate(), "Radio Lost");
                    }
                }
            }
            if (dataInArray.Length > 1)
            {
                if (!dataInArray[1].Trim().Equals(""))
                {
                    if (dataInArray[1].Trim().Split('<').Length == 0)
                    {
                        return;
                    }
                    foreach (var num in dataInArray[1].Trim().Split('<')[0].Split(','))
                    {
                        double seenTime = 0;
                        if (double.TryParse(num, out seenTime))
                        {
                            DateTime  newTime = entry.Time.AddSeconds(-seenTime);
                            DataPoint pRL     = new DataPoint(newTime.ToOADate(), 14.7);
                            pRL.Color       = Color.Lime;
                            pRL.MarkerSize  = 6;
                            pRL.MarkerStyle = MarkerStyle.Square;
                            pRL.YValues[0]  = 14.7;
                            GraphView.AddMessage(pRL);
                            AddEntryToDict(newTime.ToOADate(), "Radio Seen");
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void AddEvents(bool onlyPlot = false)
        {
            richTextBox1.Text = "";
            if (Entries == null)
            {
                return;
            }
            if (MForm.GetCurrentMode() != MainMode.Events) //TODO Merge this with else for no repeated code
            {
                RefreshEvents = true;
            }
            else
            {
                RefreshEvents = false;
                listViewEvents.BeginUpdate();
                listViewEvents.ListViewItemSorter = null;
                lastIndexSelectedEvents           = -1;
                listViewEvents.Items.Clear();
            }


            GraphView.ClearMessages();

            var dupDict = new Dictionary <string, DateTime>(StringComparer.OrdinalIgnoreCase);

            EventsDict = new Dictionary <double, List <string> >();
            foreach (var entry in Entries.Where(e => e.Data.Contains(Filter, StringComparison.OrdinalIgnoreCase)))
            {
                DataPoint po = new DataPoint(entry.Time.ToOADate(), 15);
                po.MarkerSize = 6;
                ListViewItem item = new ListViewItem();
                item.UseItemStyleForSubItems = false;
                if (GraphView.CanUseMatchTime && GraphView.UseMatchTime)
                {
                    item.Text = ((entry.Time - GraphView.MatchTime).TotalMilliseconds / 1000.0).ToString("0.###");
                }
                else
                {
                    item.Text = entry.Time.ToString("h:mm:ss.fff tt");
                }

                string entryText = entry.Data;
                if (FilterImportant && !IsMessageImportant(entryText))
                {
                    continue;
                }
                if (RemoveJoystick)
                {
                    var NoJoyText = RemoveJoyStickMessages(entryText);
                    if (!NoJoyText.Contains(Filter, StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }
                    if (string.IsNullOrWhiteSpace(NoJoyText))
                    {
                        continue;
                    }
                    entryText = Regex.Replace(NoJoyText, @"\s+", " ", RegexOptions.Compiled);
                }
                if (FilterCodeOutput)
                {
                    entryText = CodeFilterRegex.Replace(entryText, "").Trim();
                    if (!entryText.Contains(Filter, StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }
                    if (string.IsNullOrWhiteSpace(entryText))
                    {
                        continue;
                    }
                }
                if (FilterRepeated && (dupDict.ContainsKey(entryText) && (dupDict[entryText] - entry.Time).Duration().TotalSeconds < 4.0))
                {
                    continue;
                }
                else
                {
                    dupDict[entryText] = entry.Time;
                }



                item.SubItems.Add(entryText);

                if (entry.Data.Contains("ERROR") || entry.Data.Contains("<flags> 1"))
                {
                    item.SubItems[1].BackColor = Color.Red;
                    po.Color      = Color.Red;
                    po.YValues[0] = 14.7;
                }
                else if (entry.Data.Contains("<Code> 44004 "))
                {
                    item.SubItems[1].BackColor = Color.SandyBrown;
                    po.Color       = Color.SandyBrown;
                    po.MarkerStyle = MarkerStyle.Square;
                    po.YValues[0]  = 14.7;
                }
                else if (entry.Data.Contains("<Code> 44008 "))
                {
                    AddRadioEvents(entry);
                    item.SubItems[1].BackColor = Color.Khaki;
                    po.Color      = Color.Khaki;
                    po.YValues[0] = 14.7;
                }
                else if (entry.Data.Contains("Warning") || entry.Data.Contains("<flags> 2") || entry.Data.Contains("<Code> -44009 "))
                {
                    item.SubItems[1].BackColor = Color.Khaki;
                    po.Color      = Color.Khaki;
                    po.YValues[0] = 14.7;
                }
                item.SubItems.Add("" + entry.Time.ToOADate());
                var mode = GraphView.GetEntryAt(entry.Time.ToOADate());

                item.SubItems[0].BackColor = Color.DarkGray;
                if (mode != null)
                {
                    if (mode.DSAuto)
                    {
                        item.SubItems[0].BackColor = Color.Lime;
                    }
                    else if (mode.DSTele)
                    {
                        item.SubItems[0].BackColor = Color.Cyan;
                    }
                }

                if (MForm.GetCurrentMode() == MainMode.Events)
                {
                    listViewEvents.Items.Add(item);
                }
                GraphView.AddMessage(po);
                AddEntryToDict(entry.Time.ToOADate(), entryText);
            }

            if (MForm.GetCurrentMode() == MainMode.Events)
            {
                listViewEvents.Columns[0].Width = -2;
                listViewEvents.EndUpdate();
            }
        }