Ejemplo n.º 1
0
        public void Add(NodeDataBySerialNumber newData)
        {
            if (SerialId == newData.SerialId.Value)
            {
                daters.Add(newData);
            }

            if (pbcounts.All(s => s.Code != newData.Code))
            {
                pbcounts.Add(new PBCounter(newData.Code));
            }

            foreach (var c in pbcounts.Where(c => c.Code == newData.Code))
            {
                c.Count++;
            }

            if (indexCounts.All(s => s.Index != newData.Index))
            {
                indexCounts.Add(new IndexCounter(newData.Index));
            }

            foreach (var c in indexCounts.Where(c => c.Index == newData.Index))
            {
                c.Count++;
            }
        }
Ejemplo n.º 2
0
        public void ProcessInOrder(string path)
        {
            string line;

            using (StreamReader tr = new StreamReader(path))
            {
                while ((line = tr.ReadLine()) != null)
                {
                    // remove whitespace
                    string message = String.Concat(line.Where(c => !Char.IsWhiteSpace(c))); // remove white space

                    // convert to bytes
                    var asBytes = StringToByteArray(message);

                    if (asBytes[3] != 0x90)
                    {
                        continue;
                    }

                    NodeDataBySerialNumber nd = new NodeDataBySerialNumber(asBytes);

                    Debug.WriteLine(nd.ToString());
                }
            }
        }
Ejemplo n.º 3
0
        public Metrics(NodeDataBySerialNumber nodeData)
        {
            if (daters == null)
            {
                daters   = new List <NodeDataBySerialNumber>();
                SerialId = nodeData.SerialId.Value;
            }

            Add(nodeData);
        }
Ejemplo n.º 4
0
        public void ProcessReadyMessages(string path)
        {
            // read file remove escapes, sort message types, parse time, serial number and packet number
            List <Metrics> metrics = new List <Metrics>();

            string line;

            using (StreamReader tr = new StreamReader(path))
            {
                while ((line = tr.ReadLine()) != null)
                {
                    // remove whitespace
                    string message = String.Concat(line.Where(c => !Char.IsWhiteSpace(c))); // remove white space

                    // convert to bytes
                    var asBytes = StringToByteArray(message);

                    if (asBytes[3] != 0x90)
                    {
                        continue;
                    }

                    NodeDataBySerialNumber nd = new NodeDataBySerialNumber(asBytes);
                    // NodeDataByTimeAndSerialNumber nd = new NodeDataByTimeAndSerialNumber(asBytes);

                    if (nd.Code == 0)
                    {
                        continue;
                    }

                    var metric = metrics.FirstOrDefault(o => o.SerialId == nd.SerialId.Value);

                    if (metric == null)
                    {
                        metrics.Add(new Metrics(nd));
                    }
                    else
                    {
                        metric.Add(nd);
                    }
                }

                foreach (var m in metrics)
                {
                    m.PrintMetrics();
                }
            }
        }
Ejemplo n.º 5
0
        public void ReadFile(string path)
        {
            // read file remove escapes, sort message types, parse time, serial number and packet number
            List <Metrics> metrics = new List <Metrics>();

            using (StreamReader tr = new StreamReader(path))
            {
                // divide file into individual messages
                string wholeFile = tr.ReadToEnd();

                string[] wholeFileAsStrings = Regex.Split(wholeFile, @"7E");
                //
                using (StreamWriter sw = new StreamWriter("c:\\temp\\messages.txt"))
                {
                    foreach (string s in wholeFileAsStrings)
                    {
                        if (s == "")
                        {
                            continue;
                        }
                        // remove whitespace
                        string message = String.Concat(s.Where(c => !Char.IsWhiteSpace(c))); // remove white space

                        // convert to bytes
                        var asBytes = StringToByteArray(message);

                        // remove escapes
                        var noEscapes = RemoveEscapes(asBytes);

                        NodeDataBySerialNumber nd = new NodeDataBySerialNumber(noEscapes);

                        if (nd.Code != 0)
                        {
                            var metric = metrics.FirstOrDefault(o => o.SerialId == nd.SerialId.Value);

                            if (metric == null)
                            {
                                metrics.Add(new Metrics(nd));
                            }
                            else
                            {
                                metric.Add(nd);
                            }
                        }

                        // convert back to a string, lol
                        string noEscapesString = DebugHelper.ByteArrayToHexString(noEscapes);

                        // write it to file
                        sw.WriteLine($"7E{noEscapesString}".Trim());
                    }

                    foreach (var m in metrics)
                    {
                        m.PrintMetrics();
                    }

                    sw.Flush();
                    sw.Close();
                }



                // using (StreamWriter sw = new StreamWriter("C:\\temp\\Roof.txt"))
                // {
                //     sw.Write(wholeFileAsString);
                //
                //     sw.Flush();
                //     sw.Close();
                // }
            }


            // using (BinaryWriter writer = new BinaryWriter(File.Open("C:\\temp\\Roof.bin", FileMode.Create)))
            // {
            //     var messageBytes = RemoveEscapes(wholeFileAsBytes);
            //
            //     writer.Flush();
            //     writer.Close();
            // }
        }