Beispiel #1
0
        void setlinecount()
        {
            int offset = 0;

            byte[] buffer = new byte[1024 * 1024];

            var lineCount = 0;

            if (binary)
            {
                long length = basestream.Length;
                while (basestream.Position < length)
                {
                    var ans = binlog.ReadMessageTypeOffset(basestream, length);

                    if (ans.MsgType == 0 && ans.Offset == 0)
                    {
                        continue;
                    }

                    byte type = ans.Item1;
                    messageindex[type].Add((uint)(ans.Item2));
                    messageindexline[type].Add((uint)lineCount);

                    linestartoffset.Add((uint)(ans.Item2));
                    lineCount++;
                }

                _count = lineCount;

                // build fmt line database to pre seed the FMT message
                int amax = Math.Min(2000, _count - 1);
                for (int a = 0; a < amax; a++)
                {
                    dflog.GetDFItemFromLine(this[a].ToString(), a);
                }
            }
            else
            {
                // first line starts at 0
                linestartoffset.Add(0);

                long length = basestream.Length;
                while (basestream.Position < length)
                {
                    offset = 0;

                    long startpos = basestream.Position;

                    int read = basestream.Read(buffer, offset, buffer.Length);

                    while (read > 0)
                    {
                        if (buffer[offset] == '\n')
                        {
                            linestartoffset.Add((uint)(startpos + 1 + offset));
                            lineCount++;
                        }

                        offset++;
                        read--;
                    }
                }

                _count = lineCount;

                // create msg cache
                int b = 0;
                foreach (var item in this)
                {
                    var idx = item.IndexOf(',');

                    if (idx <= 0)
                    {
                        continue;
                    }

                    var msgtype = item.Substring(0, idx);

                    if (msgtype == "FMT")
                    {
                        dflog.FMTLine(item);
                    }

                    if (dflog.logformat.ContainsKey(msgtype))
                    {
                        var type = (byte)dflog.logformat[msgtype].Id;

                        messageindex[type].Add(linestartoffset[b]);
                        messageindexline[type].Add((uint)b);
                    }
                    b++;
                }
            }

            // build fmt line database using type
            foreach (var item in GetEnumeratorType("FMT"))
            {
                try
                {
                    FMT[int.Parse(item["Type"])] = new Tuple <int, string, string, string>(
                        int.Parse(item["Length"].Trim()),
                        item["Name"].Trim(),
                        item["Format"].Trim(),
                        item.items.Skip(dflog.FindMessageOffset("FMT", "Columns")).FirstOrDefault());

                    dflog.FMTLine(this[item.lineno]);
                }
                catch { }
            }

            foreach (var item in GetEnumeratorType("FMTU"))
            {
                try
                {
                    FMTU[int.Parse(item["FmtType"])] =
                        new Tuple <string, string>(item["UnitIds"].Trim(), item["MultIds"].Trim());
                }
                catch { }
            }

            foreach (var item in GetEnumeratorType("UNIT"))
            {
                try
                {
                    Unit[(char)int.Parse(item["Id"])] = item["Label"].Trim();
                }
                catch { }
            }

            foreach (var item in GetEnumeratorType("MULT"))
            {
                try
                {
                    Mult[(char)int.Parse(item["Id"])] = item["Mult"].Trim();
                }
                catch { }
            }

            BuildUnitMultiList();

            foreach (var item in GetEnumeratorType(new[]
            {
                "GPS", "GPS2"
            }))
            {
                // get first gps time
                break;
            }

            indexcachelineno = -1;
        }
        void setlinecount()
        {
            int offset = 0;

            byte[] buffer = new byte[1024 * 1024];

            var lineCount = 0;

            if (binary)
            {
                long length = basestream.Length;
                while (basestream.Position < length)
                {
                    var ans = binlog.ReadMessageTypeOffset(basestream);

                    if (ans == null)
                    {
                        continue;
                    }

                    byte type = ans.Item1;
                    messageindex[type].Add((uint)(ans.Item2));

                    linestartoffset.Add((uint)(ans.Item2));
                    lineCount++;
                }

                _count = lineCount;

                // build fmt line database to pre seed the FMT message
                int amax = Math.Min(2000, _count - 1);
                for (int a = 0; a < amax; a++)
                {
                    dflog.GetDFItemFromLine(this[a].ToString(), a);
                }

                // build fmt line database using type
                foreach (var item in GetEnumeratorType("FMT"))
                {
                    //Console.WriteLine("Found FMT");
                    bool t = true;
                }
            }
            else
            {
                // first line starts at 0
                linestartoffset.Add(0);

                while (basestream.Position < basestream.Length)
                {
                    offset = 0;

                    long startpos = basestream.Position;

                    int read = basestream.Read(buffer, offset, buffer.Length);

                    while (read > 0)
                    {
                        if (buffer[offset] == '\n')
                        {
                            linestartoffset.Add((uint)(startpos + 1 + offset));
                            lineCount++;
                        }

                        offset++;
                        read--;
                    }
                }

                _count = lineCount;

                // create msg cache
                int b = 0;
                foreach (var item in this)
                {
                    var dfitem = dflog.GetDFItemFromLine(item.ToString(), b);
                    if (dfitem.msgtype != null && dflog.logformat.ContainsKey(dfitem.msgtype))
                    {
                        var type = (byte)dflog.logformat[dfitem.msgtype].Id;

                        messageindex[type].Add(linestartoffset[b]);
                    }
                    b++;
                }
            }

            indexcachelineno = -1;
        }