Example #1
0
        /// <summary>
        /// This method parses the packet of sensor data into a Dataunit that can be used by the graph.
        /// </summary>
        /// <param name="packet">This packet should be formatted: {system}|{valueName}={value},{valueName}={value};repeat</param>
        public static void ParseSensorPacket(Packet packet)
        {
            string          data = UtilData.ToString(packet.Data.Payload);
            List <DataUnit> info = new List <DataUnit>();

            data = data.Substring(0, data.Length - 1);
            string[] sensSplit = data.Split(';');
            foreach (string s in sensSplit)
            {
                string   sens     = s.Substring(0, s.Length - 1);
                string[] sysSplit = sens.Split('|');
                string[] values   = sysSplit[1].Split(',');
                string[] temp2;
                DataUnit tempUnit = new DataUnit("GraphPacket");
                foreach (string v in values)
                {
                    temp2 = v.Split('=');
                    tempUnit.Add <double>(temp2[0], Convert.ToDouble(temp2[1]));
                }
                tempUnit.System = sysSplit[0];
                info.Add(tempUnit);
            }
            sensorRealTimeGraph.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, (Action)(() =>
            {
                sensorRealTimeGraph.updateGraph(info);
            }));
        }
Example #2
0
        public static void Start(string[] args)
        {
            if (args.Length < 2)
            {
                TestMain.ErrorExit("perf command requires functionality to test.");
            }
            switch (args[1].ToLower())
            {
            case "dataunit":
            {
                if (args.Length < 3)
                {
                    TestMain.ErrorExit("perf dataunit command requires # of elements to test.");
                }
                int TestLength = int.Parse(args[2]);
                Log.Output(Log.Severity.INFO, Log.Source.OTHER, "Testing DataUnit performance, " + TestLength.ToString("N0", CultureInfo.InvariantCulture) + " iterations.");
                Log.Output(Log.Severity.INFO, Log.Source.OTHER, "Generating keyset...");
                string[] Values = { "Erza", "Homura", "Reika", "Jibril", "Aqua", "Kurisu" };
                byte[]   IDs    = new byte[TestLength];
                Random   Random = new Random();
                for (int i = 0; i < IDs.Length; i++)
                {
                    IDs[i] = (byte)Random.Next(Values.Length);
                }
                DataUnit DUT = new DataUnit("Testing Structure");         // DataUnit under Test

                Log.Output(Log.Severity.INFO, Log.Source.OTHER, "Writing to DataUnit...");
                Stopwatch Stopwatch = Stopwatch.StartNew();
                for (int i = 0; i < IDs.Length; i++)
                {
                    DUT.Add(i.ToString(), Values[IDs[i]]);
                }
                Stopwatch.Stop();
                Log.Output(Log.Severity.INFO, Log.Source.OTHER, "  Took " + Math.Round(Stopwatch.ElapsedTicks * 1000F / Stopwatch.Frequency, 5) + "ms.");

                Log.Output(Log.Severity.INFO, Log.Source.OTHER, "Reading from DataUnit...");
                Stopwatch = Stopwatch.StartNew();
                for (int i = 0; i < IDs.Length; i++)
                {
                    DUT.GetValue <string>(i.ToString());
                }
                Stopwatch.Stop();
                Log.Output(Log.Severity.INFO, Log.Source.OTHER, "  Took " + Math.Round(Stopwatch.ElapsedTicks * 1000F / Stopwatch.Frequency, 5) + "ms.");
                break;
            }

            case "filter":
            {
                if (args.Length < 3)
                {
                    TestMain.ErrorExit("perf filter command requires filter type to test.");
                }
                if (args[2] != "lowpass" && args[2] != "average")
                {
                    TestMain.ErrorExit("Invalid filter type supplied.");
                }
                if (args.Length < 4)
                {
                    TestMain.ErrorExit("perf filter command requires # of cycles to test.");
                }

                IFilter <double> FUT = null;
                switch (args[2].ToLower())
                {
                case "lowpass": { FUT = new LowPass <double>(); break; }

                case "average": { FUT = new Average <double>(); break; }
                }
                int TestLength = int.Parse(args[3]);

                Log.Output(Log.Severity.INFO, Log.Source.OTHER, "Testing Filter performance, " + TestLength.ToString("N0", CultureInfo.InvariantCulture) + " iterations.");
                Log.Output(Log.Severity.INFO, Log.Source.OTHER, "Generating inputs...");
                double[] Inputs = new double[TestLength];
                Random   Random = new Random();
                for (int i = 0; i < Inputs.Length; i++)
                {
                    Inputs[i] = Random.NextDouble();
                }

                Log.Output(Log.Severity.INFO, Log.Source.OTHER, "Cycling Filter...");
                Stopwatch Stopwatch = Stopwatch.StartNew();
                for (int i = 0; i < Inputs.Length; i++)
                {
                    FUT.Feed(Inputs[i]);
                    double Output = FUT.GetOutput();
                }
                Stopwatch.Stop();
                Log.Output(Log.Severity.INFO, Log.Source.OTHER, "  Took " + Math.Round(Stopwatch.ElapsedTicks * 1000F / Stopwatch.Frequency, 5) + "ms.");

                break;
            }
            }
        }