Exemplo n.º 1
0
        internal static void StartTempLogging(bool consolemode, bool logmode, bool dumpmode)
        {
            bool initialized = false;

            if (consolemode)
            {
                Console.Clear();
                Console.Title         = "TempServe";
                Console.BufferHeight  = Console.WindowHeight = 20;
                Console.BufferWidth   = Console.WindowWidth = 80;
                Console.CursorVisible = false;
                Console.WriteLine("Initializing ...");
            }

            SqlCeResultSet rs = null;

            using (var mon = new W83627DHG())
            {
                fc = mon;
                var cpu     = new CPU();
                var asp0800 = new SMBus.ASP0800();
                var ard     = new Arduino();
#if NVIDIA
                Debugger.Launch();
                var nv = new NVidiaGPU();
#endif

                if (consolemode)
                {
                    SetConsoleCtrlHandler(
                        x =>
                    {
                        running = false;
                        mon.Dispose();
                        Console.CursorVisible = true;
                        return(x != CtrlTypes.CTRL_C_EVENT);
                    }
                        , true);
                }

                Dictionary <string, Sample> min = null;
                Dictionary <string, Sample> max = null;

                var avg5 = new Queue <Dictionary <string, Sample> >(60);

                var sw = Stopwatch.StartNew();

                while (running)
                {
                    var elapsed = sw.Elapsed;

                    var alldata = cpu.GetData().
                                  Concat(mon.GetData()).
                                  Concat(asp0800.GetData()).
                                  Concat(ard.GetData()).
#if NVIDIA
                                  Concat(nv.GetData()).
#endif
                                  ToList();

                    var now = DateTime.Now;

                    foreach (var smp in alldata)
                    {
                        smp.Time = now;
                    }

                    lastsample = alldata;

                    if (!initialized)
                    {
                        if (consolemode)
                        {
                            var height = alldata.Count + 2;
                            Console.BufferHeight = Console.WindowHeight = height;
                        }

                        if (logmode)
                        {
                            rs = BuildDatabase(alldata.Where(x => x.Log).ToList());
                        }

                        initialized = true;
                    }

                    if (logmode)
                    {
                        RecordSample(rs, alldata);
                    }

                    if (dumpmode)
                    {
                        using (var w = new StringWriter())
                        {
                            mon.DumpRawByteData(w);
                            File.AppendAllText("W83627DHG.log", w.ToString());
                        }

                        using (var w = new StringWriter())
                        {
                            mon.DumpSIOByteData(w);
                            File.AppendAllText("Super-IO.log", w.ToString());
                        }

                        //using (var w = new StringWriter())
                        //{
                        //  asp0800.DumpRawByteData(w);
                        //  File.AppendAllText("ASP0800b.log", w.ToString());
                        //}

                        using (var w = new StringWriter())
                        {
                            asp0800.DumpRawWordData(w);
                            File.AppendAllText("ASP0800w.log", w.ToString());
                        }
                    }

                    if (consolemode)
                    {
                        Console.Title = string.Format("TempServe - Running for: {3}d {0:00}:{1:00}:{2:00}",
                                                      elapsed.Hours, elapsed.Minutes, elapsed.Seconds, elapsed.Days);

                        while (avg5.Count >= 60)
                        {
                            avg5.Dequeue();
                        }

                        var hashdata = alldata.ToDictionary(x => x.Name, x => x);;

                        avg5.Enqueue(hashdata);

                        if (min == null)
                        {
                            min = hashdata;
                        }
                        else
                        {
                            min = HashMap((x, y) => x.Value > y.Value ? y : x, min, hashdata);
                        }

                        if (max == null)
                        {
                            max = hashdata;
                        }
                        else
                        {
                            max = HashMap((x, y) => x.Value < y.Value ? y : x, max, hashdata);
                        }

                        using (var output = new StringWriter())
                        {
                            output.WriteLine("{0,-18}{1,10}{2,10}{3,10}{4,10}{5,10}{6,10}",
                                             "Sensor", "Current", "Min", "Max", "Avg(10)", "Avg(30)", "Avg(60)");

                            foreach (var s in alldata)
                            {
                                var avg = avg5.Reverse().ToArray();

                                var fs = BuildFormatString(s);

                                output.WriteLine(fs, s.Name, s.Value,
                                                 min[s.Name].Value,
                                                 max[s.Name].Value,
                                                 avg.Take(10).Select(x => x[s.Name]).Average(x => x.Value),
                                                 avg.Take(30).Select(x => x[s.Name]).Average(x => x.Value),
                                                 avg.Take(60).Select(x => x[s.Name]).Average(x => x.Value)
                                                 );
                            }

                            Console.Clear();
                            Console.Write(output.ToString());
                        }
                    }

                    var taken = Math.Min((sw.Elapsed - elapsed).TotalMilliseconds, 100) + 3;
                    Thread.Sleep(1000 - (int)taken);
                }
            }
        }
Exemplo n.º 2
0
        internal static void StartTempLogging(bool consolemode, bool logmode, bool dumpmode)
        {
            bool initialized = false;

              if (consolemode)
              {
            Console.Clear();
            Console.Title = "TempServe";
            Console.BufferHeight = Console.WindowHeight = 20;
            Console.BufferWidth = Console.WindowWidth = 80;
            Console.CursorVisible = false;
            Console.WriteLine("Initializing ...");
              }

              SqlCeResultSet rs = null;

              using (var mon = new W83627DHG())
              {
            fc = mon;
            var cpu = new CPU();
            var asp0800 = new SMBus.ASP0800();
            var ard = new Arduino();
            #if NVIDIA
            Debugger.Launch();
            var nv = new NVidiaGPU();
            #endif

            if (consolemode)
            {
              SetConsoleCtrlHandler(
            x =>
            {
              running = false;
              mon.Dispose();
              Console.CursorVisible = true;
              return x != CtrlTypes.CTRL_C_EVENT;
            }
            , true);
            }

            Dictionary<string, Sample> min = null;
            Dictionary<string, Sample> max = null;

            var avg5 = new Queue<Dictionary<string, Sample>>(60);

            var sw = Stopwatch.StartNew();

            while (running)
            {
              var elapsed = sw.Elapsed;

              var alldata = cpu.GetData().
            Concat(mon.GetData()).
            Concat(asp0800.GetData()).
            Concat(ard.GetData()).
            #if NVIDIA
            Concat(nv.GetData()).
            #endif
            ToList();

              var now = DateTime.Now;

              foreach (var smp in alldata)
              {
            smp.Time = now;
              }

              lastsample = alldata;

              if (!initialized)
              {
            if (consolemode)
            {
              var height = alldata.Count + 2;
              Console.BufferHeight = Console.WindowHeight = height;
            }

            if (logmode)
            {
              rs = BuildDatabase(alldata.Where(x => x.Log).ToList());
            }

            initialized = true;
              }

              if (logmode)
              {
            RecordSample(rs, alldata);
              }

              if (dumpmode)
              {
            using (var w = new StringWriter())
            {
              mon.DumpRawByteData(w);
              File.AppendAllText("W83627DHG.log", w.ToString());
            }

            using (var w = new StringWriter())
            {
              mon.DumpSIOByteData(w);
              File.AppendAllText("Super-IO.log", w.ToString());
            }

            //using (var w = new StringWriter())
            //{
            //  asp0800.DumpRawByteData(w);
            //  File.AppendAllText("ASP0800b.log", w.ToString());
            //}

            using (var w = new StringWriter())
            {
              asp0800.DumpRawWordData(w);
              File.AppendAllText("ASP0800w.log", w.ToString());
            }
              }

              if (consolemode)
              {
            Console.Title = string.Format("TempServe - Running for: {3}d {0:00}:{1:00}:{2:00}",
              elapsed.Hours, elapsed.Minutes, elapsed.Seconds, elapsed.Days);

            while (avg5.Count >= 60)
            {
              avg5.Dequeue();
            }

            var hashdata = alldata.ToDictionary(x => x.Name, x => x); ;

            avg5.Enqueue(hashdata);

            if (min == null)
            {
              min = hashdata;
            }
            else
            {
              min = HashMap((x, y) => x.Value > y.Value ? y : x, min, hashdata);
            }

            if (max == null)
            {
              max = hashdata;
            }
            else
            {
              max = HashMap((x, y) => x.Value < y.Value ? y : x, max, hashdata);
            }

            using (var output = new StringWriter())
            {
              output.WriteLine("{0,-18}{1,10}{2,10}{3,10}{4,10}{5,10}{6,10}",
                "Sensor", "Current", "Min", "Max", "Avg(10)", "Avg(30)", "Avg(60)");

              foreach (var s in alldata)
              {
                var avg = avg5.Reverse().ToArray();

                var fs = BuildFormatString(s);

                output.WriteLine(fs, s.Name, s.Value,
                  min[s.Name].Value,
                  max[s.Name].Value,
                  avg.Take(10).Select(x => x[s.Name]).Average(x => x.Value),
                  avg.Take(30).Select(x => x[s.Name]).Average(x => x.Value),
                  avg.Take(60).Select(x => x[s.Name]).Average(x => x.Value)
                  );
              }

              Console.Clear();
              Console.Write(output.ToString());
            }
              }

              var taken = Math.Min((sw.Elapsed - elapsed).TotalMilliseconds, 100) + 3;
              Thread.Sleep(1000 - (int)taken);
            }
              }
        }