/// <summary>
        /// Add a listener
        /// </summary>
        /// <param name="c"></param>
        internal override void AddListener(SignalBase c)
        {
            //Cast c
            SignalCollection <T> sc = c as SignalCollection <T>;

            //Add listeners between the signals
            for (int i = 0; i < signals.Count; i++)
            {
                if (i < sc.signals.Count)
                {
                    signals[i].AddListener(sc.signals[i]);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Writes definitions of the signals to be recorded
        /// </summary>
        /// <param name="cs">Signals</param>
        public void WriteNames(List <SystemDotNet.SignalBase> cs)
        {
            i1 = i2 = i3 = 0;
            filewriter.WriteLine("$scope module SystemDotNet $end");
            for (int i = 0; i < cs.Count; i++)
            {
                SignalBase c = cs[i];

                if (c is Signal <bool> )
                {
                    filewriter.WriteLine("$var wire 1 " + GetLabel() + " " + c.FullName + " $end");
                }
                else if (c is BitVectorUnsigned)
                {
                    BitVectorUnsigned bvu = (BitVectorUnsigned)c;
                    filewriter.WriteLine("$var reg " + bvu.Bits + " " + GetLabel() + " " + c.FullName + " [" + (bvu.Bits - 1) + ": 0 ] $end");
                }
                else if (c is SignalCollection <bool> )
                {
                    SignalCollection <bool> sc = c as SignalCollection <bool>;
                    for (int j = 0; j < sc.Count; j++)
                    {
                        filewriter.WriteLine("$var reg " + sc.Count + " " + GetLabel() + " " + c.FullName + "(" + j + ")" + " [" + (sc.Count - 1) + ": 0 ] $end");
                    }
                }
                else if (c is SignalCollection <double> )
                {
                    SignalCollection <double> sc = c as SignalCollection <double>;
                    for (int j = 0; j < sc.Count; j++)
                    {
                        filewriter.WriteLine("$var real 1 " + GetLabel() + " " + sc.FullName + "(" + j + ")" + " $end");
                    }
                }
                else if (c is SignalCollection <ulong> )
                {
                    SignalCollection <ulong> sc = c as SignalCollection <ulong>;
                    filewriter.WriteLine("$var reg " + sc.Count + " " + GetLabel() + " " + c.FullName + " [" + (sc.Count - 1) + ": 0 ] $end");
                }
                else
                {
                    filewriter.WriteLine("$var real 1 " + GetLabel() + " " + c.FullName + " $end");
                }
            }
            filewriter.WriteLine();
            filewriter.WriteLine("$upscope $end");
            filewriter.WriteLine("$enddefinitions $end");
            filewriter.WriteLine();
        }
        /// <summary>
        /// Conforms to the Logger.ValueWriterHandler delegate. Writes a bool signal collection as an unsigned integer
        /// </summary>
        /// <param name="o"></param>
        /// <returns></returns>
        public static string ValueWriterUnsignedInteger(object o)
        {
            SignalCollection <bool> sc = o as SignalCollection <bool>;

            if (sc != null)
            {
                uint s;
                SignalCollection <bool> .Convert(sc.Read(), out s);

                return(s.ToString());
            }
            else
            {
                return(o.ToString());
            }
        }
        /// <summary>
        /// Conforms to the Logger.ValueWriterHandler delegate. Writes a bool signal collection as a binary string
        /// </summary>
        /// <param name="o"></param>
        /// <returns></returns>
        public static string ValueWriterBinary(object o)
        {
            SignalCollection <bool> sc = o as SignalCollection <bool>;

            if (sc != null)
            {
                string s;
                SignalCollection <bool> .Convert(sc.Read(), out s);

                return(s);
            }
            else
            {
                return(o.ToString());
            }
        }
 /// <summary>
 /// Converts the signal collection into a string. If it is a bool signal collection it writes the value as a binary value.
 /// </summary>
 /// <returns></returns>
 public override string ToString()
 {
     if (this is SignalCollection <bool> )
     {
         SignalCollection <bool> sc = this as SignalCollection <bool>;
         uint u;
         Convert(sc.Read(), out u);
         //string s;
         //Convert(sc.Read(), out s);
         return(u.ToString());
     }
     else
     {
         return(base.ToString());
     }
 }
예제 #6
0
/// <summary>
/// Writes signal changes to the file
/// </summary>
/// <param name="cs">Signals</param>
/// <param name="time">Time</param>
        public void WriteSignals(List <SystemDotNet.SignalBase> cs, long time)
        {
            //Reset indexes for asci array
            i1 = i2 = i3 = 0;

            //Holds output
            StringBuilder sb = new StringBuilder();

            //Holds label
            string clabel = "";

            //Prev holds previous value. This checks that prev has the right length
            if (cs.Count != prev.Length)
            {
                prev = new string[cs.Count];
            }

            //Foreach signal
            for (int i = 0; i < cs.Count; i++)
            {
                //Get labe. Note that if the number of signals changes between WriteNames
                //WriteSignals the label will be wrong.
                clabel = GetLabel();

                //Get signal
                SignalBase c = cs[i];

                //Check signal type
                if (c is Signal <bool> )
                {
                    //If it is bool; convert to string (0 or 1) and check if it has changed. If it has changed append it to the string builder
                    bool   b     = ((Signal <bool>)c).Read();
                    string sbool = "0";
                    if (b)
                    {
                        sbool = "1";
                    }
                    if (prev[i] != sbool)
                    {
                        sb.Append(sbool + clabel + '\n');
                    }
                    prev[i] = sbool;
                }
                else if (c is SignalCollection <bool> )
                {
                    //If it is bool[]; convert to string (i.e 00010) and check if it has changed. If it has changed append it to the string builder
                    string val;
                    SignalCollection <bool> .Convert(((SignalCollection <bool>)c).Read(), out val);

                    if (prev[i] != val)
                    {
                        sb.Append("b" + val + " " + clabel + '\n');
                    }
                    prev[i] = val;
                }
                else if (c is SignalCollection <ulong> )
                {
                    SignalCollection <ulong> sc = c as SignalCollection <ulong>;
                    for (int j = 0; j < sc.Count; j++)
                    {
                        BitVectorUnsigned bc = new BitVectorUnsigned(64);
                        bc.Value = sc[j].Value;
                        string val = ((BitVectorUnsigned)bc).ToBinaryString();

                        if (prev[i] != val)
                        {
                            sb.Append("b" + val + " " + GetLabel() + '\n');
                        }
                        prev[i] = val;
                    }

//                    //If it is bool[]; convert to string (i.e 00010) and check if it has changed. If it has changed append it to the string builder
//                    string val;
//                    BitVectorUnsigned bc = new BitVectorUnsigned();
//                    bc.Value =
//                    SignalCollection<bool>.Convert(((SignalCollection<bool>)c).Read(), out val);
//
//                    if (prev[i] != val)
//                        sb.Append("b" + val + " " + clabel + '\n');
//                    prev[i] = val;
                }
                else if (c is BitVectorUnsigned)
                {
                    string val = ((BitVectorUnsigned)c).ToBinaryString();
                    if (prev[i] != val)
                    {
                        sb.Append("b" + val + " " + clabel + '\n');
                    }
                    prev[i] = val;
                }
                else if (c is Signal <Enum> )
                {
                    //If it is enum; convert to string (i.e Add) and check if it has changed. If it has changed append it to the string builder
                    string senum = ((Signal <Enum>)c).Read().ToString();
                    if (prev[i] != senum)
                    {
                        sb.Append("s" + senum + " " + clabel + '\n');
                    }
                    prev[i] = senum;
                }
                else if (c is Signal <double> )
                {
                    //If it is double; convert to string (i.e 0.1) and check if it has changed. If it has changed append it to the string builder
                    string sreal = ((Signal <double>)c).Read().ToString();
                    if (prev[i] != sreal)
                    {
                        sb.Append("r" + sreal + " " + clabel + '\n');
                    }
                    prev[i] = sreal;
                }
                else if (c is SignalCollection <double> )
                {
                    StringBuilder             sb1 = new StringBuilder();
                    SignalCollection <double> sc  = c as SignalCollection <double>;
                    sb1.Append("r" + sc[0].Read().ToString() + " " + clabel + '\n');
                    for (int j = 1; j < sc.Count; j++)
                    {
                        sb1.Append("r" + sc[j].Read().ToString() + " " + GetLabel() + '\n');
                    }

                    string screal = sb1.ToString();
                    if (prev[i] != screal)
                    {
                        sb.Append(screal);
                    }
                    prev[i] = screal;
//                }else if (c is SignalCollection<ulong>){
//                    foreach(Signal<ulong> in
                }
                else
                {
                    //If it is otherwise; convert to string and check if it has changed. If it has changed append it to the string builder.
                    string sobj = c.ToString();
                    if (prev[i] != sobj)
                    {
                        sb.Append("r" + sobj + " " + clabel + '\n');
                    }
                    prev[i] = sobj;
                }
            }

            //If any signals changed write them to the file
            if (sb.ToString().Length > 0)
            {
                filewriter.WriteLine("#" + time);
                filewriter.Write(sb.ToString());
                filewriter.WriteLine();
            }
        }