Пример #1
0
        public bool parse(string[] lines)
        {
            TiTxtRecord tr = new TiTxtRecord();

            foreach (string lin in lines)
            {
                string line = lin.Trim();
                if (line.Length < 1)
                {
                    continue;
                }
                if (tr.parse(line))
                {
                    if (TiTxtRecord.RecordTypeE.SecStrtAddr == tr.RecordType)
                    {
                        MemBlock mb = new MemBlock();
                        mb.StartAddr = tr.Address;
                        mb.AddrSize  = 16;
                        Memblks.Add(mb);
                    }
                    else if (TiTxtRecord.RecordTypeE.EOF == tr.RecordType)
                    {
                        // end of file
                    }
                    else if (TiTxtRecord.RecordTypeE.Data == tr.RecordType)
                    {
                        MemBlock mb = Memblks [Memblks.Count - 1];
                        if (0 == this.BytesEachLine)
                        {
                            this.BytesEachLine = tr.Data.Length;
                        }
                        mb.AppendData(tr.Data);
                    }
                    else
                    {
                    }
                }
            }
            MemBlock.MergeMBs(this.Memblks);
            return(true);
        }
Пример #2
0
        public bool parse(string[] lines)
        {
            SRecord sr = new SRecord();

            foreach (string lin in lines)
            {
                string line = lin.Trim();
                if (line.Length < 1)
                {
                    continue;
                }
                if (sr.parse(line))
                {
                    switch (sr.RecordType)
                    {
                    case SRecord.RecordTypeE.S0:
                    {
                        this.HeadRec = new byte[sr.Data.Length];
                        sr.Data.CopyTo(this.HeadRec, 0);
                    }
                    break;

                    case SRecord.RecordTypeE.S1:
                    {
                        this.SFileType = SFileTypeE.S19;
                        this.DataRecordNum++;
                        if (0 == Memblks.Count)
                        {
                            MemBlock mb = new MemBlock();
                            mb.AddrSize  = 16;
                            mb.StartAddr = sr.Address;
                            mb.AppendData(sr.Data);
                            Memblks.Add(mb);
                        }
                        else
                        {
                            MemBlock mb = Memblks [Memblks.Count - 1];
                            if (mb.NextAddress == sr.Address)
                            {
                                mb.AppendData(sr.Data);
                            }
                            else                                         // create a new MemBlock
                            {
                                MemBlock mbn = new MemBlock();
                                mbn.AddrSize  = 16;
                                mbn.StartAddr = sr.Address;
                                mbn.AppendData(sr.Data);
                                Memblks.Add(mbn);
                            }
                        }
                    }
                    break;

                    case SRecord.RecordTypeE.S2:
                    {
                        this.SFileType = SFileTypeE.S28;
                        this.DataRecordNum++;
                        if (0 == Memblks.Count)
                        {
                            MemBlock mb = new MemBlock();
                            mb.AddrSize  = 24;
                            mb.StartAddr = sr.Address;
                            mb.AppendData(sr.Data);
                            Memblks.Add(mb);
                        }
                        else
                        {
                            MemBlock mb = Memblks [Memblks.Count - 1];
                            if (mb.NextAddress == sr.Address)
                            {
                                mb.AppendData(sr.Data);
                            }
                            else                                         // create a new MemBlock
                            {
                                MemBlock mbn = new MemBlock();
                                mbn.AddrSize  = 24;
                                mbn.StartAddr = sr.Address;
                                mbn.AppendData(sr.Data);
                                Memblks.Add(mbn);
                            }
                        }
                    }
                    break;

                    case SRecord.RecordTypeE.S3:
                    {
                        this.SFileType = SFileTypeE.S37;
                        this.DataRecordNum++;
                        if (0 == Memblks.Count)
                        {
                            MemBlock mb = new MemBlock();
                            mb.AddrSize  = 32;
                            mb.StartAddr = sr.Address;
                            mb.AppendData(sr.Data);
                            Memblks.Add(mb);
                        }
                        else
                        {
                            MemBlock mb = Memblks [Memblks.Count - 1];
                            if (mb.NextAddress == sr.Address)
                            {
                                mb.AppendData(sr.Data);
                            }
                            else                                         // create a new MemBlock
                            {
                                MemBlock mbn = new MemBlock();
                                mbn.AddrSize  = 32;
                                mbn.StartAddr = sr.Address;
                                mbn.AppendData(sr.Data);
                                Memblks.Add(mbn);
                            }
                        }
                    }
                    break;

                    case SRecord.RecordTypeE.S4:
                    {
                        // not used now
                    }
                    break;

                    case SRecord.RecordTypeE.S5:
                    {
                        // check record count
                        ushort recCount = BitConverter.ToUInt16(sr.Data, 0);
                        if (recCount != this.DataRecordNum)
                        {
                            // error happens
                        }
                    }
                    break;

                    case SRecord.RecordTypeE.S6:
                    {
                        // check record count
                        uint recCount = BitConverter.ToUInt16(sr.Data, 1);
                        recCount += (uint)(sr.Data [0] << 16);
                        if (recCount != this.DataRecordNum)
                        {
                            // error happens
                        }
                    }
                    break;

                    case SRecord.RecordTypeE.S7:
                    {
                        // end of S37, nothing to do
                    }
                    break;

                    case SRecord.RecordTypeE.S8:
                    {
                        // end of S28, nothing to do
                    }
                    break;

                    case SRecord.RecordTypeE.S9:
                    {
                        // end of S19, nothing to do
                    }
                    break;

                    default:
                    {
                    }
                    break;
                    }
                }
            }
            MemBlock.MergeMBs(this.Memblks);
            return(true);
        }