A set of edges. Used internally by the pattern builder and its layout.
Exemplo n.º 1
0
		/** Generate the pattern. */
		public void BuildPattern( int length ) 
		{
			// Are there any events ?
			if (layout.EventTimes.Count == 0)
				throw new PatternBuildException("No events to build pattern for.");
		
			// Is that big enough ?
			if ( length < layout.LastEventTime + 1 )
				throw new PatternBuildException("Pattern will not fit in array of requested length.\n"
                    + "Pattern length is " + layout.LastEventTime + ". Array length is " + length);
		
			// make the pattern array
			pattern = new UInt32[length];
		
			// Get the event times and fill in the gaps
			ArrayList times = layout.EventTimes;
			int numberOfEvents = times.Count;
			// first the time before the first event, if there is any
			for (int i = 0 ; i < (int)times[0] ; i++ ) 
			{
				pattern[i] = 0;
			}
			int endTime = 0;
			for (int j = 1 ; j < numberOfEvents ; j++ ) 
			{
				int startTime = (int)times[j-1];
				endTime = (int)times[j];
				EdgeSet es = layout.GetEdgeSet(startTime);
				UInt32 nextInt;
				if (startTime != 0) 
				{
					// middle of a pattern
					UInt32 previousInt = pattern[startTime - 1];
					nextInt = GenerateNextInt( previousInt, es, true, startTime );
				} 
				else 
				{
					// start of a pattern, special case
					UInt32 previousInt = 0;
					nextInt = GenerateNextInt( previousInt, es, false, startTime );
				}
				// fill in the pattern
				for ( int i = startTime ; i < endTime ; i++ ) 
				{
					pattern[i] = nextInt;
				}
			}
			// pad up to the end
			UInt32 padInt;
			if (endTime == 0) padInt = 0;
			else padInt = GenerateNextInt( pattern[endTime-1], layout.GetEdgeSet(endTime), true, endTime );
			for (int i = endTime ; i < length ; i++ ) 
			{
				pattern[i] = padInt;
			}

			GenerateInt16Pattern();
			GenerateBytePattern();
		
		}
Exemplo n.º 2
0
        public override String ToString()
        {
            StringBuilder sb = new StringBuilder();

            // work out how many tabs are needed after the time field
            int maxTime       = LastEventTime;
            int maxTimeLength = maxTime.ToString().Length;
            int maxTabs       = maxTimeLength / 4 + 1;

            // Header
            sb.Append("t");
            for (int i = 0; i < maxTabs; i++)
            {
                sb.Append("\t");
            }
            for (int i = 0; i < channels; i++)
            {
                sb.Append(i + "\t");
            }
            sb.Append("\n");

            // Events
            foreach (DictionaryEntry ev in EventList)
            {
                int     time = (int)ev.Key;
                EdgeSet es   = (EdgeSet)ev.Value;
                // display this event
                sb.Append(time);
                // pad with tabs
                int timeLength = time.ToString().Length;
                int numTabs    = maxTabs - (timeLength / 4);
                for (int i = 0; i < numTabs; i++)
                {
                    sb.Append("\t");
                }
                for (int i = 0; i < channels; i++)
                {
                    EdgeSense sense = es.GetEdge(i);
                    if (sense == EdgeSense.NC)
                    {
                        sb.Append("-\t");
                    }
                    if (sense == EdgeSense.UP)
                    {
                        sb.Append("U\t");
                    }
                    if (sense == EdgeSense.DOWN)
                    {
                        sb.Append("D\t");
                    }
                }
                sb.Append("\n");
            }
            return(sb.ToString());
        }
Exemplo n.º 3
0
 public void AddEdge( int channel, int time, bool sense )
 {
     EdgeSet edgeSet = (EdgeSet)eventList[time];
     // is there already an edgeSet at this time ?
     if (edgeSet == null)
     {
         // If not add a new one
         edgeSet = new EdgeSet(channels);
         edgeSet.AddEdge(channel, sense);
         eventList[time] = edgeSet;
     }
     else
     {
         // else add the edge to the existing one
         edgeSet.AddEdge(channel, sense);
     }
 }
Exemplo n.º 4
0
        public void AddEdge(int channel, int time, bool sense)
        {
            EdgeSet edgeSet = (EdgeSet)EventList[time];

            // is there already an edgeSet at this time ?
            if (edgeSet == null)
            {
                // If not add a new one
                edgeSet = new EdgeSet(channels);
                edgeSet.AddEdge(channel, sense);
                EventList[time] = edgeSet;
            }
            else
            {
                // else add the edge to the existing one
                edgeSet.AddEdge(channel, sense);
            }
        }
Exemplo n.º 5
0
		private UInt32 GenerateNextInt( UInt32 previousInt, EdgeSet es, bool throwError, int time)
		{
			// build a bit mask for the upwards edges
			UInt32 upMask = 0;
			for (int i = 0 ; i < 32 ; i++) if (es.GetEdge(i) == EdgeSense.UP) upMask = upMask | bitValues[i];
			// and the downwards edges
			UInt32 downMask = 0;
			for (int i = 0 ; i < 32 ; i++) if (es.GetEdge(i) == EdgeSense.DOWN) downMask = downMask | bitValues[i];
	  	
			// error checking
			if (throwError) 
			{
				if ( (upMask & previousInt) != 0 )
					throw new PatternBuildException("Edge conflict on upward edge at time " + time);
				if ( (downMask & ~previousInt) != 0 )
					throw new PatternBuildException("Edge conflict on downward edge at time " + time);
			}
			UInt32 returnInt = previousInt | upMask;
			returnInt = ~(~returnInt | downMask);
			return returnInt;
		}
Exemplo n.º 6
0
        private UInt32 GenerateNextInt( UInt32 previousInt, EdgeSet es, bool throwError, int time)
        {
            // build a bit mask for the upwards edges
            UInt32 upMask = 0;
            for (int i = 0 ; i < 32 ; i++) if (es.GetEdge(i) == EdgeSense.UP) upMask = upMask | bitValues[i];
            // and the downwards edges
            UInt32 downMask = 0;
            for (int i = 0 ; i < 32 ; i++) if (es.GetEdge(i) == EdgeSense.DOWN) downMask = downMask | bitValues[i];

            // error checking
            if (throwError)
            {
                if ( (upMask & previousInt) != 0 )
                    throw new PatternBuildException("Edge conflict on upward edge at time " + time);
                if ( (downMask & ~previousInt) != 0 )
                    throw new PatternBuildException("Edge conflict on downward edge at time " + time);
            }
            UInt32 returnInt = previousInt | upMask;
            returnInt = ~(~returnInt | downMask);
            return returnInt;
        }