Esempio n. 1
0
 public static void Start(string[] args)
 {
     if (args.Length < 2)
     {
         TestMain.ErrorExit("utils command requires functionality to test.");
     }
     switch (args[1].ToLower())
     {
     case "datalog":
     {
         for (int i = 0; i < 10; i++)
         {
             Random  Random = new Random();
             DataLog Logger = new DataLog("ScarletTestSuite");
             Logger.Output(new DataUnit("TestData")
                 {
                     { "Index", i },
                     { "RandomNumber", Random.Next(100) }
                 }.SetSystem("Test"));
             Thread.Sleep(50);
         }
         break;
     }
     }
 }
Esempio n. 2
0
 public static BBBPin StringToPin(string pinName)
 {
     try
     {
         BBBPin Value = (BBBPin)Enum.Parse(typeof(BBBPin), pinName);
         if (Enum.IsDefined(typeof(BBBPin), Value))
         {
             return(Value);
         }
         else
         {
             throw new IndexOutOfRangeException("Not a pin");
         }
     }
     catch
     {
         TestMain.ErrorExit("Given BBBPin is invalid.");
         return(BBBPin.NONE);
     }
 }
Esempio n. 3
0
        public static void Start(string[] args)
        {
            if (args.Length < 3)
            {
                TestMain.ErrorExit("io pi command requires functionality to test.");
            }
            RaspberryPi.Initialize();

            switch (args[2].ToLower())
            {
            case "digin":
            {
                if (args.Length < 4)
                {
                    TestMain.ErrorExit("io pi digin command requires pin to test.");
                }
                int PinNum = int.Parse(args[3]);
                Log.Output(Log.Severity.INFO, Log.Source.HARDWAREIO, "Testing digital input on RPi pin " + PinNum);
                IDigitalIn Input = new DigitalInPi(PinNum);
                while (true)
                {
                    Log.Output(Log.Severity.INFO, Log.Source.HARDWAREIO, "Current pin state: " + (Input.GetInput() ? "HIGH" : "LOW"));
                    Thread.Sleep(250);
                }
            }

            case "digout":
            {
                if (args.Length < 4)
                {
                    TestMain.ErrorExit("io pi digout command requires pin to test.");
                }
                int PinNum = int.Parse(args[3]);
                if (args.Length < 5)
                {
                    TestMain.ErrorExit("io pi digout command requires output mode (high/low/blink).");
                }
                if (args[4] != "high" && args[4] != "low" && args[4] != "blink")
                {
                    TestMain.ErrorExit("Invalid digout test mode supplied.");
                }
                Log.Output(Log.Severity.INFO, Log.Source.HARDWAREIO, "Testing digital output on RPi pin " + PinNum);
                IDigitalOut Output = new DigitalOutPi(PinNum);
                if (args[4] == "high")
                {
                    Output.SetOutput(true);
                }
                else if (args[4] == "low")
                {
                    Output.SetOutput(false);
                }
                else
                {
                    bool Out = false;
                    while (true)
                    {
                        Output.SetOutput(Out);
                        Out = !Out;
                        Thread.Sleep(250);
                    }
                }
                break;
            }

            case "pwm":
            {
                TestMain.ErrorExit("io pi pwm command not yet implemented.");     // TODO: Remove when implementing.
                if (args.Length < 4)
                {
                    TestMain.ErrorExit("io pi pwm command requires pin to test.");
                }
                int PinNum = int.Parse(args[3]);
                if (args.Length < 5)
                {
                    TestMain.ErrorExit("io pi pwm command requires frequency.");
                }
                int Frequency = int.Parse(args[4]);
                if (args.Length < 6)
                {
                    TestMain.ErrorExit("io pi pwm command requires output mode.");
                }
                if (args[5] != "per" && args[5] != "sine")
                {
                    TestMain.ErrorExit("io pi pwm command invalid (per/sine).");
                }
                if (args[5] == "per" && args.Length < 7)
                {
                    TestMain.ErrorExit("io pi pwm per must be provided duty cycle.");
                }
                IPWMOutput Output = null;         // TODO: Implement RPi PWM output.
                Output.SetFrequency(Frequency);
                Log.Output(Log.Severity.INFO, Log.Source.HARDWAREIO, "Testing PWM output on RPi pin " + PinNum + " at " + Frequency + "Hz.");
                if (args[5] == "per")
                {
                    Output.SetOutput(int.Parse(args[6]) / 100F);
                    Output.SetEnabled(true);
                    Thread.Sleep(15000);     // Not sure if it stops outputting when the program exits.
                }
                else
                {
                    int Cycle = 0;
                    while (true)
                    {
                        float Val = (float)((Math.Sin(Cycle * Math.PI / 180.000D) + 1) / 2);
                        Output.SetOutput(Val);
                        Thread.Sleep(50);
                        Cycle += 20;
                    }
                }
                break;
            }

            case "adc": { TestMain.ErrorExit("RPI does not have an ADC."); break; }

            case "int":
            {
                if (args.Length < 4)
                {
                    TestMain.ErrorExit("io pi int command requires pin to test.");
                }
                int PinNum = int.Parse(args[3]);
                if (args.Length < 5)
                {
                    TestMain.ErrorExit("io pi int command requires interrupt mode (rise/fall/both).");
                }
                if (args[4] != "rise" && args[4] != "fall" && args[4] != "both")
                {
                    TestMain.ErrorExit("Invalid interrupt mode supplied.");
                }

                IDigitalIn Input = new DigitalInPi(PinNum);
                Log.Output(Log.Severity.INFO, Log.Source.HARDWAREIO, "Testing interrupts on RPi pin " + PinNum);
                switch (args[4])
                {
                case "rise": ((IInterruptSource)Input).RegisterInterruptHandler(GetInterrupt, InterruptType.RISING_EDGE); break;

                case "fall": ((IInterruptSource)Input).RegisterInterruptHandler(GetInterrupt, InterruptType.FALLING_EDGE); break;

                case "both": ((IInterruptSource)Input).RegisterInterruptHandler(GetInterrupt, InterruptType.ANY_EDGE); break;
                }
                while (true)
                {
                    Thread.Sleep(50);
                }                                      // Program needs to be running to receive.
            }

            case "outperf":
            {
                if (args.Length < 4)
                {
                    TestMain.ErrorExit("io pi outperf command requires pin to test.");
                }
                int PinNum = int.Parse(args[3]);
                Log.Output(Log.Severity.INFO, Log.Source.HARDWAREIO, "Testing digital output speed on RPi pin " + PinNum);
                IDigitalOut Output = new DigitalOutPi(PinNum);
                bool        Out    = false;
                while (!Console.KeyAvailable)
                {
                    Output.SetOutput(Out);
                    Out = !Out;
                }
                Output.SetOutput(false);
                break;
            }
            }
        }
Esempio n. 4
0
        public static void Start(string[] args)
        {
            if (args.Length < 3)
            {
                TestMain.ErrorExit("io bbb command requires functionality to test.");
            }
            BeagleBone.Initialize(SystemMode.DEFAULT, true);

            switch (args[2].ToLower())
            {
            case "digin":
            {
                if (args.Length < 4)
                {
                    TestMain.ErrorExit("io bbb digin command requires pin to test.");
                }
                BBBPin InputPin = StringToPin(args[3]);
                Log.Output(Log.Severity.INFO, Log.Source.HARDWAREIO, "Testing digital input on BBB pin " + InputPin.ToString());
                BBBPinManager.AddMappingGPIO(InputPin, false, ResistorState.PULL_DOWN);
                BBBPinManager.ApplyPinSettings(BBBPinManager.ApplicationMode.APPLY_REGARDLESS);
                IDigitalIn Input = new DigitalInBBB(InputPin);
                while (true)
                {
                    Log.Output(Log.Severity.INFO, Log.Source.HARDWAREIO, "Current pin state: " + (Input.GetInput() ? "HIGH" : "LOW"));
                    Thread.Sleep(250);
                }
            }

            case "digout":
            {
                if (args.Length < 4)
                {
                    TestMain.ErrorExit("io bbb digout command requires pin to test.");
                }
                BBBPin OutputPin = StringToPin(args[3]);
                if (args.Length < 5)
                {
                    TestMain.ErrorExit("io bbb digout command requires output mode (high/low/blink).");
                }
                if (args[4] != "high" && args[4] != "low" && args[4] != "blink")
                {
                    TestMain.ErrorExit("Invalid digout test mode supplied.");
                }
                Log.Output(Log.Severity.INFO, Log.Source.HARDWAREIO, "Testing digital output on BBB pin " + OutputPin.ToString());
                BBBPinManager.AddMappingGPIO(OutputPin, true, ResistorState.PULL_DOWN);
                BBBPinManager.ApplyPinSettings(BBBPinManager.ApplicationMode.APPLY_REGARDLESS);
                IDigitalOut Output = new DigitalOutBBB(OutputPin);
                if (args[4] == "high")
                {
                    Output.SetOutput(true);
                }
                else if (args[4] == "low")
                {
                    Output.SetOutput(false);
                }
                else
                {
                    bool Out = false;
                    while (true)
                    {
                        Output.SetOutput(Out);
                        Out = !Out;
                        Thread.Sleep(250);
                    }
                }
                break;
            }

            case "pwm":
            {
                if (args.Length < 4)
                {
                    TestMain.ErrorExit("io bbb pwm command requires pin to test.");
                }
                BBBPin OutputPin = StringToPin(args[3]);
                if (args.Length < 5)
                {
                    TestMain.ErrorExit("io bbb pwm command requires frequency.");
                }
                int Frequency = int.Parse(args[4]);
                if (args.Length < 6)
                {
                    TestMain.ErrorExit("io bbb pwm command requires output mode.");
                }
                if (args[5] != "per" && args[5] != "sine")
                {
                    TestMain.ErrorExit("io bbb pwm command invalid (per/sine).");
                }
                if (args[5] == "per" && args.Length < 7)
                {
                    TestMain.ErrorExit("io bbb pwm per must be provided duty cycle.");
                }
                BBBPinManager.AddMappingPWM(OutputPin);
                BBBPinManager.ApplyPinSettings(BBBPinManager.ApplicationMode.APPLY_REGARDLESS);
                IPWMOutput Output = PWMBBB.GetFromPin(OutputPin);
                Output.SetFrequency(Frequency);
                Log.Output(Log.Severity.INFO, Log.Source.HARDWAREIO, "Testing PWM output on BBB pin " + OutputPin.ToString() + " at " + Frequency + "Hz.");
                if (args[5] == "per")
                {
                    Output.SetOutput(int.Parse(args[6]) / 100F);
                    Output.SetEnabled(true);
                    Thread.Sleep(15000);     // Not sure if it stops outputting when the program exits.
                }
                else
                {
                    int Cycle = 0;
                    while (true)
                    {
                        float Val = (float)((Math.Sin(Cycle * Math.PI / 180.000D) + 1) / 2);
                        Output.SetOutput(Val);
                        Thread.Sleep(50);
                        Cycle += 20;
                    }
                }
                break;
            }

            case "adc":
            {
                if (args.Length < 4)
                {
                    TestMain.ErrorExit("io bbb adc command requires pin to test.");
                }
                BBBPin InputPin = StringToPin(args[3]);
                BBBPinManager.AddMappingADC(InputPin);
                BBBPinManager.ApplyPinSettings(BBBPinManager.ApplicationMode.APPLY_REGARDLESS);
                IAnalogueIn Input = new AnalogueInBBB(InputPin);
                Log.Output(Log.Severity.INFO, Log.Source.HARDWAREIO, "Testing analogue input on BBB pin " + InputPin.ToString());
                while (true)
                {
                    Log.Output(Log.Severity.INFO, Log.Source.HARDWAREIO, "ADC Input: " + Input.GetInput() + " (Raw: " + Input.GetRawInput() + ")");
                    Thread.Sleep(250);
                }
            }

            case "int":
            {
                if (args.Length < 4)
                {
                    TestMain.ErrorExit("io bbb int command requires pin to test.");
                }
                BBBPin InputPin = StringToPin(args[3]);
                if (args.Length < 5)
                {
                    TestMain.ErrorExit("io bbb int command requires interrupt mode (rise/fall/both).");
                }
                if (args[4] != "rise" && args[4] != "fall" && args[4] != "both")
                {
                    TestMain.ErrorExit("Invalid interrupt mode supplied.");
                }

                BBBPinManager.AddMappingGPIO(InputPin, true, ResistorState.PULL_DOWN);
                BBBPinManager.ApplyPinSettings(BBBPinManager.ApplicationMode.APPLY_REGARDLESS);
                IDigitalIn Input = new DigitalInBBB(InputPin);
                Log.Output(Log.Severity.INFO, Log.Source.HARDWAREIO, "Testing interrupts on BBB pin " + InputPin.ToString());
                switch (args[4])
                {
                case "rise": ((IInterruptSource)Input).RegisterInterruptHandler(GetInterrupt, InterruptType.RISING_EDGE); break;

                case "fall": ((IInterruptSource)Input).RegisterInterruptHandler(GetInterrupt, InterruptType.FALLING_EDGE); break;

                case "both": ((IInterruptSource)Input).RegisterInterruptHandler(GetInterrupt, InterruptType.ANY_EDGE); break;
                }
                while (true)
                {
                    Thread.Sleep(50);
                }                                     // Program needs to be running to receive.
            }

            case "mtk3339":
            {
                BBBPinManager.AddMappingUART(BBBPin.P9_24);
                BBBPinManager.AddMappingUART(BBBPin.P9_26);
                BBBPinManager.ApplyPinSettings(BBBPinManager.ApplicationMode.APPLY_REGARDLESS);
                IUARTBus UART = UARTBBB.UARTBus1;
                Log.Output(Log.Severity.INFO, Log.Source.HARDWAREIO, "Press any key to stop.");
                while (Console.KeyAvailable)
                {
                    Console.ReadKey();
                }
                byte[] Buffer = new byte[32];
                while (true)
                {
                    Thread.Sleep(10);
                    if (UART.BytesAvailable() > 0)
                    {
                        int Count = UART.Read(32, Buffer);
                        Console.Write(System.Text.Encoding.ASCII.GetString(UtilMain.SubArray(Buffer, 0, Count)));
                    }
                    if (Console.KeyAvailable)
                    {
                        break;
                    }
                }
                break;
            }
            }
        }
Esempio n. 5
0
        public static void Start(string[] args)
        {
            if (args.Length < 2)
            {
                TestMain.ErrorExit("Device testing needs device to test.");
            }
            switch (args[1].ToLower())
            {
            case "hx711":
            {
                if (args.Length < 5)
                {
                    TestMain.ErrorExit("Insufficient info to run HX711 test. See help.");
                }
                IDigitalIn  DataPin  = null;
                IDigitalOut ClockPin = null;
                if (args[2].Equals("pi", StringComparison.InvariantCultureIgnoreCase))
                {
                    RaspberryPi.Initialize();
                    DataPin  = new DigitalInPi(int.Parse(args[3]));
                    ClockPin = new DigitalOutPi(int.Parse(args[4]));
                }
                else if (args[2].Equals("bbb", StringComparison.InvariantCultureIgnoreCase))
                {
                    BeagleBone.Initialize(SystemMode.DEFAULT, true);
                    BBBPin DataBBBPin  = IOBBB.StringToPin(args[3]);
                    BBBPin ClockBBBPin = IOBBB.StringToPin(args[4]);
                    BBBPinManager.AddMappingGPIO(DataBBBPin, false, ResistorState.NONE);
                    BBBPinManager.AddMappingGPIO(ClockBBBPin, true, ResistorState.NONE);
                    BBBPinManager.ApplyPinSettings(BBBPinManager.ApplicationMode.APPLY_IF_NONE);
                    DataPin  = new DigitalInBBB(DataBBBPin);
                    ClockPin = new DigitalOutBBB(ClockBBBPin);
                }
                else
                {
                    TestMain.ErrorExit("HX711 test: Unknown platform. See help.");
                }
                HX711 DUT = new HX711(ClockPin, DataPin);
                while (Console.KeyAvailable)
                {
                    Console.ReadKey();
                }
                Log.Output(Log.Severity.INFO, Log.Source.GUI, "[w] to increase gain, [s] to decrease. [z] to zero.");
                Log.Output(Log.Severity.INFO, Log.Source.GUI, "Press any other key to exit.");

                HX711.Gain Gain     = HX711.Gain.GAIN_128x;
                bool       Continue = true;
                while (Continue)
                {
                    if (Console.KeyAvailable)
                    {
                        char Key = Console.ReadKey().KeyChar;
                        switch (Key)
                        {
                        case 'w':
                        {
                            if (Gain == HX711.Gain.GAIN_32x)
                            {
                                Gain = HX711.Gain.GAIN_64x;
                            }
                            else if (Gain == HX711.Gain.GAIN_64x)
                            {
                                Gain = HX711.Gain.GAIN_128x;
                            }
                            else
                            {
                                Log.Output(Log.Severity.ERROR, Log.Source.SENSORS, "Gain at maximum already.");
                            }
                            DUT.SetGain(Gain);
                            Log.Output(Log.Severity.INFO, Log.Source.SENSORS, "Gain now at " + Gain);
                            break;
                        }

                        case 's':
                        {
                            if (Gain == HX711.Gain.GAIN_128x)
                            {
                                Gain = HX711.Gain.GAIN_64x;
                            }
                            else if (Gain == HX711.Gain.GAIN_64x)
                            {
                                Gain = HX711.Gain.GAIN_32x;
                            }
                            else
                            {
                                Log.Output(Log.Severity.ERROR, Log.Source.SENSORS, "Gain at minimum already.");
                            }
                            DUT.SetGain(Gain);
                            Log.Output(Log.Severity.INFO, Log.Source.SENSORS, "Gain now at " + Gain);
                            break;
                        }

                        case 'z':
                        {
                            DUT.Tare();
                            Log.Output(Log.Severity.INFO, Log.Source.SENSORS, "Tared.");
                            break;
                        }

                        default:
                        {
                            Continue = false;
                            break;
                        }
                        }
                    }
                    DUT.UpdateState();
                    Log.Output(Log.Severity.INFO, Log.Source.SENSORS, "HX711 readings: Raw: " + DUT.GetRawReading() + ", Adjusted: " + DUT.GetAdjustedReading());
                    Thread.Sleep(250);
                }
                break;
            }

            default:
            {
                TestMain.ErrorExit("Unknown device.");
                break;
            }
            }
        }
Esempio n. 6
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;
            }
            }
        }