private void GetTimingSets()
 {
     foreach (var child in stpTS.Children)
     {
         if (child is ucTS)
         {
             ucTS      uc = child as ucTS;
             TimingSet ts = timingSets.First(x => x.ID == uc.ID);
             uc.SetObj(ts);
         }
     }
 }
Example #2
0
        public void SetObj(TimingSet ts)
        {
            int value = 0;

            if (int.TryParse(txtTS.Text.Trim(), out value))
            {
                ts.data = value;
            }
            else
            {
                throw new Exception(lblTS.Text + " should be integer!");
            }
        }
        private Tuple <List <Mode>, List <ChannelGroup>, List <TimingSet> > ParsePAT(string filePAT)
        {
            try
            {
                List <Mode>         availableModes         = new List <Mode>();
                List <ChannelGroup> availableChannelGroups = new List <ChannelGroup>();
                List <TimingSet>    availableTimingSets    = new List <TimingSet>();

                using (FileStream fs = new FileStream(filePAT, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    using (StreamReader sr = new StreamReader(fs))
                    {
                        bool   valid = false;
                        string line  = string.Empty;
                        while ((line = sr.ReadLine()) != null)
                        {
                            if (line == string.Empty)
                            {
                                continue;
                            }
                            else if (line.ToUpper().Trim().StartsWith("//MIPI-CHANNEL"))
                            {
                                line = line.Split(':')[1].Trim();
                                string[] channelGroups = line.Split('|');
                                foreach (var channelgroup in channelGroups)
                                {
                                    int    iClock = 0;
                                    int    iData  = 0;
                                    string sClock = channelgroup.Split(',')[0];
                                    string sData  = channelgroup.Split(',')[1];
                                    if (!int.TryParse(sClock, out iClock))
                                    {
                                        throw new Exception("Invalid channel in " + line);
                                    }
                                    if (!int.TryParse(sData, out iData))
                                    {
                                        throw new Exception("Invalid channel in " + line);
                                    }
                                    ChannelGroup cg = new ChannelGroup();
                                    cg.Clock.ID = iClock;
                                    cg.Data.ID  = iData;
                                    availableChannelGroups.Add(cg);
                                }
                            }
                            else if (line.ToUpper().Trim().StartsWith("//MIPI-TS"))
                            {
                                line = line.Split(':')[1].Trim();
                                string[] timingSets = line.Split(',');
                                foreach (var timingset in timingSets)
                                {
                                    int id = 0;
                                    if (!int.TryParse(timingset, out id))
                                    {
                                        throw new Exception("Invalid timing set in " + line);
                                    }
                                    TimingSet ts = new TimingSet()
                                    {
                                        ID = id
                                    };
                                    availableTimingSets.Add(ts);
                                }
                            }
                            else if (line.ToUpper().Trim().StartsWith("//MIPI-START"))
                            {
                                valid = true;
                            }
                            else if (line.ToUpper().Trim().StartsWith("//MIPI-END"))
                            {
                                break;
                            }
                            else
                            {
                                if (valid)
                                {
                                    line = line.Substring(2);
                                    string name   = line.Split(':')[0].Trim();
                                    string start  = line.Split(':')[1].Trim().Split('-')[0].Trim();
                                    string end    = line.Split(':')[1].Trim().Split('-')[1].Trim();
                                    int    iStart = 0;
                                    if (!int.TryParse(start, out iStart))
                                    {
                                        throw new Exception("Invalid line in " + line);
                                    }
                                    int iEnd = 0;
                                    if (!int.TryParse(end, out iEnd))
                                    {
                                        throw new Exception("Invalid line in " + line);
                                    }
                                    Mode mode = new Mode()
                                    {
                                        Name = name, LineStart = iStart, LineEnd = iEnd
                                    };
                                    availableModes.Add(mode);
                                }
                            }
                        }
                        sr.Close();
                    }
                }

                if (availableModes.Count == 0)
                {
                    throw new Exception("No available mode detected!");
                }

                if (availableChannelGroups.Count == 0)
                {
                    throw new Exception("No available channel detected!");
                }

                if (availableTimingSets.Count == 0)
                {
                    throw new Exception("No available timing set detected!");
                }

                return(Tuple.Create(availableModes, availableChannelGroups, availableTimingSets));
            }
            catch (Exception ex)
            {
                throw new Exception("Invalid format in " + filePAT + ", please check the header section!\n\n" + ex.Message);
            }
        }