Ejemplo n.º 1
0
        /// <summary>
        /// Entry point of the test pattern generator.
        /// </summary>
        /// <param name="args">Command line arguments. If one argument is present, then the stimulus is loaded from the file named by this arguments, else the stimulus is read from stdin.</param>
        public static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("Syntax TestPatternGenerator <stimulusFile>");
                return;
            }

            if (!File.Exists(args[0]))
            {
                Console.WriteLine("The required {0} file does not exist", args[0]);
            }

            StimulusDescriptor.LoadFrom(args[0]);
            TestPatternGenerator testPattern = new TestPatternGenerator();
            string hexOutput = Path.ChangeExtension(args[0], "hex");

            using (TextWriter tw = File.CreateText(hexOutput))
            {
                testPattern.ForeachState((w, s) =>
                {
                    tw.WriteLine("{0} {1:X4}", w, s);
                });
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TestPatternGenerator"/> class.
 /// </summary>
 public TestPatternGenerator()
 {
     this.Baud = StimulusDescriptor.Baud;
     StimulusDescriptor.Foreach((s) =>
     {
         GenerateStates(s);
     });
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Generates the states corresponding to the passed stimulus.
        /// </summary>
        /// <param name="descriptor">Descriptor of the stimulus to be generated.</param>
        private void GenerateStates(StimulusDescriptor descriptor)
        {
            int currentTimeMicroseconds = descriptor.WhenMicrosecond;

            foreach (byte c in Encoding.ASCII.GetBytes(descriptor.ToSend))
            {
                currentTimeMicroseconds = this.GenerateStates(currentTimeMicroseconds, descriptor.LineId, c);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Generates the states and checks if a string is emitted before the former on the same line has been totally sent.
        /// </summary>
        private static void PerformCheck()
        {
            for (int line = 0; line <= MAXLINES; line++)
            {
                Dictionary <int, int> initial2Index = new Dictionary <int, int>();
                for (int i = 0; i < stimuli.Count; i++)
                {
                    StimulusDescriptor stimulus = stimuli[i];
                    if (stimulus.LineId != line)
                    {
                        continue;
                    }

                    initial2Index.Add(stimulus.WhenMicrosecond, i);
                }

                if (initial2Index.Count <= 1)
                {
                    continue;
                }

                int[] times = initial2Index.Keys.ToArray <int>();
                Array.Sort <int>(times);
                for (int i = 0; i < times.Length - 1; i++)
                {
                    // We have 8 bit data + 1 bit start 1bit stop = 10;
                    double             microsecondsPerChar = 1E6 / StimulusDescriptor.Baud * 10.0;
                    int                startTime           = times[i];
                    StimulusDescriptor stimulus            = stimuli[initial2Index[startTime]];
                    int                endCurrentString    = (int)(startTime + (microsecondsPerChar * stimulus.ToSend.Length));
                    if (endCurrentString > times[i + 1])
                    {
                        throw new StimulusDescriptorException(i, "The following string starts before the former one has ended");
                    }
                }
            }
        }