Changeset 286 for trunk/CrypPlugins/CLK


Ignore:
Timestamp:
Apr 13, 2009, 7:25:02 PM (13 years ago)
Author:
Sören Rinne
Message:
  • revised Clock plugin
  • changed some LFSR features
  • added XOR that takes Boolean inputs and fires Output only when both inputs are fresh
Location:
trunk/CrypPlugins/CLK
Files:
3 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/CLK/CLK.cs

    r277 r286  
    1010using System.Runtime.Remoting.Contexts;
    1111using Cryptool.PluginBase.Miscellaneous;
     12//timer
     13using System.Timers;
    1214
    1315namespace Cryptool.Plugins.CLK
    1416{
    1517  [Author("Soeren Rinne", "soeren.rinne@cryptool.org", "Uni Bochum", "http://www.rub.de")]
    16   [PluginInfo(true, "CLK", "Simple clock for clock-based plugins.", null, "CLK/icon.png")]
     18  [PluginInfo(true, "CLK", "Simple clock for clock-based plugins.", null, "CLK/icon.png", "CLK/Images/true.png", "CLK/Images/false.png")]
    1719  public class CLK : IInput
    1820  {
    1921    # region private variables
    2022    private bool output;
     23    private int timeout = 2000;
     24    private int rounds = 10;
     25    private Timer aTimer = new Timer();
    2126    # endregion private variables
     27
     28    public int myRounds;
    2229
    2330    public CLK()
     
    2532        settings = new CLKSettings();
    2633        settings.PropertyChanged += settings_PropertyChanged;
     34
     35        // set picture according to settings value
     36        /* BRINGT NIX - WARUM?
     37        if (settings.SetClockToTrue) StatusChanged((int)CLKImage.True);
     38        else StatusChanged((int)CLKImage.False);*/
    2739    }
    2840
     
    3143      if (e.PropertyName == "SetClockToTrue")
    3244      {
    33         //output = settings.SetClockToTrue;
     45        output = settings.SetClockToTrue;
     46        if (output) StatusChanged((int)CLKImage.True);
     47        else StatusChanged((int)CLKImage.False);
     48      }
     49      if (e.PropertyName == "CLKTimeout")
     50      {
     51          timeout = settings.CLKTimeout;
     52      }
     53      if (e.PropertyName == "Rounds")
     54      {
     55          rounds = settings.Rounds;
    3456      }
    3557    }
     
    5779    #region IPlugin Members
    5880    public event StatusChangedEventHandler OnPluginStatusChanged;
    59     public event GuiLogNotificationEventHandler OnGuiLogNotificationOccured;
    6081    public event PluginProgressChangedEventHandler OnPluginProgressChanged;
    6182
     
    7899    public void PreExecution()
    79100    {
     101        if (settings.SetClockToTrue) StatusChanged((int)CLKImage.True);
     102        else StatusChanged((int)CLKImage.False);
     103
     104        myRounds = settings.Rounds;
     105        GuiLogMessage("myRounds: " + myRounds.ToString(), NotificationLevel.Info);
    80106    }
    81107
    82108    public void Execute()
    83     {
    84         //output = settings.SetClockToTrue;
    85         OnPropertyChanged("Output");
     109    {       
     110        process(settings.CLKTimeout);
     111        //change picture
     112        if (settings.SetClockToTrue) StatusChanged((int)CLKImage.True);
     113        else StatusChanged((int)CLKImage.False);
     114       
     115    }
     116
     117    private void process(int timeout)
     118    {
     119       
     120        // Normally, the timer is declared at the class level, so
     121        // that it doesn't go out of scope when the method ends.
     122        // In this example, the timer is needed only while Main
     123        // is executing. However, KeepAlive must be used at the
     124        // end of Main, to prevent the JIT compiler from allowing
     125        // aggressive garbage collection to occur before Main
     126        // ends.
     127
     128        // Hook up the Elapsed event for the timer.
     129        aTimer.Elapsed += new ElapsedEventHandler(sendCLKSignal);
     130
     131        // Set the Interval to 2 seconds (2000 milliseconds).
     132        aTimer.Interval = timeout;
     133        aTimer.Enabled = true;
     134
     135        // Keep the timer alive until the end of Main.
     136        //GC.KeepAlive(aTimer);
     137    }
     138
     139    private void sendCLKSignal(object sender, EventArgs e)
     140    {
     141        if (myRounds != 0)
     142        {
     143            OnPropertyChanged("Output");
     144            myRounds--;
     145        }
     146        else
     147        {
     148            aTimer.Enabled = false;
     149            // globally remove timer event
     150            aTimer.Elapsed -= new ElapsedEventHandler(sendCLKSignal);
     151        }
     152
    86153    }
    87154
     
    96163    public void Stop()
    97164    {
     165        aTimer.Enabled = false;
     166        // globally remove timer event
     167        aTimer.Elapsed -= new ElapsedEventHandler(sendCLKSignal);
    98168    }
    99169
    100170    public void Initialize()
    101171    {
    102       if (settings.SetClockToTrue)
    103         output = settings.SetClockToTrue;
     172      output = settings.SetClockToTrue;
     173      if (output) StatusChanged((int)CLKImage.True);
     174      else StatusChanged((int)CLKImage.False);
     175      settings.CLKTimeout = timeout;
    104176    }
    105177
     
    114186    public event PropertyChangedEventHandler PropertyChanged;
    115187
     188    public event GuiLogNotificationEventHandler OnGuiLogNotificationOccured;
     189    private void GuiLogMessage(string message, NotificationLevel logLevel)
     190    {
     191        EventsHelper.GuiLogMessage(OnGuiLogNotificationOccured, this, new GuiLogEventArgs(message, this, logLevel));
     192    }
     193
    116194    protected void OnPropertyChanged(string name)
    117195    {
    118196      EventsHelper.PropertyChanged(PropertyChanged, this, new PropertyChangedEventArgs(name));
     197    }
     198
     199    private void StatusChanged(int imageIndex)
     200    {
     201        EventsHelper.StatusChanged(OnPluginStatusChanged, this, new StatusEventArgs(StatusChangedMode.ImageUpdate, imageIndex));
    119202    }
    120203
    121204    #endregion
    122205  }
     206
     207  enum CLKImage
     208  {
     209      Default,
     210      True,
     211      False
     212  }
    123213}
  • trunk/CrypPlugins/CLK/CLK.csproj

    r277 r286  
    8989    <Resource Include="icon.png" />
    9090  </ItemGroup>
     91  <ItemGroup>
     92    <Resource Include="Images\false.png" />
     93    <Resource Include="Images\true.png" />
     94  </ItemGroup>
    9195  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
    9296  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
  • trunk/CrypPlugins/CLK/CLKSettings.cs

    r277 r286  
    1414    private bool hasChanges;
    1515    private bool setClockToTrue;
     16    private int clkTimeout = 2000;
    1617    # endregion private variables
    1718
     
    3738    }
    3839
     40    /*[ContextMenu("Set clock to...", " true / false ", 2, DisplayLevel.Beginner, ContextMenuControlType.ComboBox, null, new string[] { "true", "false"})]
     41    [TaskPane("Set clock to...", " true / false ", null, 2, false, DisplayLevel.Beginner, ControlType.RadioButton, new string[] { "true", "false" })]
     42    public bool SetClockToTrue
     43    {
     44        get
     45        {
     46            return (this.setClockToTrue == "true");
     47        }
     48        set
     49        {
     50            //if (this.setClockToTrue != setClockToTrue) HasChanges = true;
     51            this.setClockToTrue = value;
     52            OnPropertyChanged("SetClockToTrue");
     53        }
     54    }*/
     55
     56    //[ContextMenu("Set clock to true", " yes / no ", 0, DisplayLevel.Beginner, ContextMenuControlType.CheckBox, null, "Set clock to true")]
     57    [TaskPaneAttribute("Set CLK timeout in milliseconds", "How long should it last until next CLK event?", "", 1, false, DisplayLevel.Beginner, ControlType.TextBox, null)]
     58    public int CLKTimeout
     59    {
     60        get { return this.clkTimeout; }
     61        set
     62        {
     63            this.clkTimeout = value;
     64            OnPropertyChanged("CLKTimeout");
     65        }
     66
     67    }
     68
     69    private int rounds = 10; //how many bits will be generated
     70    //[ContextMenu("Rounds", "How many bits shall be generated?", 1, DisplayLevel.Beginner, ContextMenuControlType.ComboBox, new int[] { 10, 50, 100 }, "10 bits", "50 bits", "100 bits")]
     71    //[TaskPane("Rounds", "How many bits shall be generated?", null, 1, false, DisplayLevel.Beginner, ControlType.TextBox)]
     72    [TaskPane("Rounds", "How many clock cycles shall be generated?", null, 2, false, DisplayLevel.Beginner, ControlType.NumericUpDown, ValidationType.RangeInteger, 0, int.MaxValue)]
     73    public int Rounds
     74    {
     75        get { return this.rounds; }
     76        set
     77        {
     78            this.rounds = value;
     79            OnPropertyChanged("Rounds");
     80            HasChanges = true;
     81        }
     82    }
     83
    3984    #endregion
    4085
Note: See TracChangeset for help on using the changeset viewer.