Esempio n. 1
0
        public SortTasks(int TasksCount, Task[] List)
        {
            TaskPriority = new int[2, TasksCount];
            numbers = new int[TasksCount];
            for (int i = 0; i < TasksCount; i++)
            {
                numbers[i] = TaskPriority[0, i] = Convert.ToInt32(List[i].GetTaskPrio());

            }
            Array.Sort(numbers);
            for (int i = 0; i < TasksCount; i++)
            {
                TaskPriority[1, i] = Array.IndexOf(numbers, TaskPriority[0, i]);
            }
        }
Esempio n. 2
0
        //==============================================================================
        // DESCRIPTION :
        //
        // PARAMETERS (Type,Name,Min,Max) :
        //
        // RETURN VALUE :
        //
        // DESIGN INFORMATION :
        //==============================================================================
        private void OnMiceClick(object sender, EventArgs e)
        {
            DisableTaskEvents();
            DisableAlarmEvents();
            DisableCounterEvents();
            MenuItem miClicked = (MenuItem)sender;
            string item = miClicked.Text;
            string t = MyContext.ToString();
            if("OSEK_CONF" == OStree.SelectedNode.Text)
            {
                return;
            }
            else
            {
                if( (null != OStree.SelectedNode.Parent)&&
                    ("OSEK_CONF" == OStree.SelectedNode.Parent.Text)
                    )
                {
                    if("New" == item)
                    {
                        OStree.SelectedNode.Nodes.Add("OSEK Properties");

                        try
                        {
                            // OS should have only one set of property
                            MyContext.MenuItems.Clear();

                        }
                        catch
                        {
                            MessageBox.Show("Problem in the clear context menu");
                        }
                    }
                    else if("Add" == item)
                    {

                        if("TASK" == OStree.SelectedNode.Text)
                        {
                            string NameForm = OStree.SelectedNode.Text + "_Child" + TaskNameCounter.ToString();
                            TaskNameCounter++;
                            OStree.SelectedNode.Nodes.Add(NameForm);
                            // Allocate space for task's struct
                            if (TaskCounter >= (int)15)
                            {
                                MessageBox.Show("Exceeeded max number of tasks");
                            }

                            TaskList[TaskCounter] = new Task();
                            TaskList[TaskCounter++].SetTaskName(NameForm);

                        }
                        if ("ALARM" == OStree.SelectedNode.Text)
                        {
                            string NameForm = OStree.SelectedNode.Text + "_Child" + AlarmNameCounter.ToString();
                            OStree.SelectedNode.Nodes.Add(NameForm);
                            AlarmNameCounter++;
                            // Allocate space for task's struct
                            if (AlarmCounter >= (int)15)
                            {
                                MessageBox.Show("Exceeeded max number of alarms");
                            }
                            AlarmList[AlarmCounter] = new Alarm();
                            AlarmList[AlarmCounter++].SetAlarmName(NameForm);

                        }
                        if ("COUNTER" == OStree.SelectedNode.Text)
                        {
                            string NameForm = OStree.SelectedNode.Text + "_Child" + CounterNameCount.ToString();
                            OStree.SelectedNode.Nodes.Add(NameForm);
                            CounterNameCount++;
                            // Allocate space for task's struct
                            if (CounterCount >= (int)15)
                            {
                                MessageBox.Show("Exceeded max number of counters");
                            }
                            CounterList[CounterCount] = new Counter();
                            CounterList[CounterCount++].SetCounterName(NameForm);
                            //COUNTER_SELECTOR.Items.Insert(CounterCombox++,NameForm);

                        }

                    }
                    else
                    {
                        MessageBox.Show("Unkown context menu item for first deptch!");
                    }
                }
                else if(
                    (null != OStree.SelectedNode.Parent)&&
                    (null != OStree.SelectedNode.Parent.Parent)&&
                    ("OSEK_CONF" == OStree.SelectedNode.Parent.Parent.Text)
                    )
                {
                    if("Delete" == item)
                    {
                        int i;
                        if("TASK"  == OStree.SelectedNode.Parent.Text)
                        {

                            try
                            {

                                for(i = OStree.SelectedNode.Index; (i < 15 && (null != TaskList[i+1])); i++)
                                {
                                    TaskList[i] = TaskList[i+1];
                                }
                                 TaskList[i] = null;
                                OStree.SelectedNode.Nodes.Remove(OStree.SelectedNode);

                                if(0 < TaskCounter)
                                {
                                    TaskCounter--;
                                }
                                ManageTaskProperty(false);

                            }
                            catch
                            {
                                MessageBox.Show("Failed remove a child node");
                            }
                        }
                        if ("COUNTER" == OStree.SelectedNode.Parent.Text)
                        {
                            if (0 < CounterCount)
                            {
                                CounterCount--;
                            }

                            try
                            {

                                for (i = OStree.SelectedNode.Index; (i < 15 && (null != CounterList[i + 1])); i++)
                                {
                                    CounterList[i] = CounterList[i + 1];
                                }
                                CounterList[i] = null;
                                OStree.SelectedNode.Nodes.Remove(OStree.SelectedNode);
                                if (0 < AlarmCounter)
                                {
                                    CounterCount--;
                                }
                                ManageCounterProperty(false);
                                //COUNTER_SELECTOR.Items.Remove(OStree.SelectedNode.Index);
                                //CounterCombox--;
                            }
                            catch
                            {
                                MessageBox.Show("Failed remove a child node");
                            }
                        }
                        if ("ALARM" == OStree.SelectedNode.Parent.Text)
                        {
                            if (0 < AlarmCounter)
                            {
                                AlarmCounter--;
                            }

                            try
                            {

                                for (i = OStree.SelectedNode.Index; (i < 15 && (null != AlarmList[i + 1])); i++)
                                {
                                    AlarmList[i] = AlarmList[i + 1];
                                }
                                AlarmList[i] = null;
                                OStree.SelectedNode.Nodes.Remove(OStree.SelectedNode);
                                if (0 < AlarmCounter)
                                {
                                    AlarmCounter--;
                                }
                                ManageAlarmProperty(false);
                            }
                            catch
                            {
                                MessageBox.Show("Failed remove a child node");
                            }
                        }

                        FormContextMenu();
                        GC.Collect();
                        GC.WaitForPendingFinalizers();
                    }
                    else if("Edit" == item)
                    {
                        if(!OStree.SelectedNode.IsEditing)
                        {

                            OStree.SelectedNode.BeginEdit();
                        }

                    }
                    else
                    {
                        MessageBox.Show("Unkown context menu item for second depth!");
                    }
                }
            }
            OStree.ExpandAll();
            EnableTaskEvents();
            EnableAlarmEvents();
            EnableCounterEvents();
        }
Esempio n. 3
0
        private void OpenFileButton_Click(object sender, System.EventArgs e)
        {
            Stream myStream = null;

            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            //openFileDialog1.InitialDirectory = "c:\\" ;
            openFileDialog1.Filter = "OSEK Implementation Language (*.oil)|*.OIL" ;
            openFileDialog1.FilterIndex = 2 ;
            openFileDialog1.RestoreDirectory = true ;

            if(openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = openFileDialog1.OpenFile()) != null)
                    {
                        using (myStream)
                        {
                            // Insert code to read the stream here.

                            string file = openFileDialog1.FileName;
                            int j=0;
                            int counter;
                            try
                            {

                                string text = File.ReadAllText(file);
                                string[] uCconf = text.Split(new string[] { "uC " }, StringSplitOptions.RemoveEmptyEntries);
                                string ucSelected = GetValueFromString(uCconf[0], "MICROCONTROLLER");
                                MicroSelection.SelectedIndex = Convert.ToInt32(ucSelected);
                                //MICROCONTROLLER- > ToolBar BE COMPLETED
                                // OS_CONF  ----------------------------------------------\
                                string[] osconf = text.Split(new string[] { "OS " }, StringSplitOptions.RemoveEmptyEntries);
                                string temp = GetValueFromString(osconf[1], "STACKCHECK");
                                if ("TRUE" == temp)
                                {
                                    STACK_CHECK_ENABLED.Checked = true;
                                }
                                else
                                {
                                    STACK_CHECK_ENABLED.Checked = false;
                                }
                                osconf[1] = osconf[1].Remove(0, (osconf[1].IndexOf('{') + 1));
                                osconf[1] = osconf[1].Remove(0, (osconf[1].IndexOf(';') + 1));
                                temp = GetValueFromString(osconf[1], "ERRORHOOK");
                                if ("TRUE" == temp)
                                {
                                    ERROR_CHECKING_EXTENDEDK_ENABLED.Checked = true;
                                }
                                else
                                {
                                    ERROR_CHECKING_EXTENDEDK_ENABLED.Checked = false;
                                }
                                osconf[1] = osconf[1].Remove(0, (osconf[1].IndexOf(';') + 1));
                                temp = GetValueFromString(osconf[1], "STARTUPHOOK");

                                if ("TRUE" == temp)
                                {
                                    STARTUP_HOOK_ENABLED.Checked = true;
                                }
                                else
                                {
                                    STARTUP_HOOK_ENABLED.Checked = false;
                                }
                                osconf[1] = osconf[1].Remove(0, (osconf[1].IndexOf(';') + 1));
                                temp = GetValueFromString(osconf[1], "SHUTDOWNHOOK");
                                if ("TRUE" == temp)
                                {
                                    SHUTDOWN_HOOK_ENABLED.Checked = true;
                                }
                                else
                                {
                                    SHUTDOWN_HOOK_ENABLED.Checked = false;
                                }
                                osconf[1] = osconf[1].Remove(0, (osconf[1].IndexOf(';') + 1));
                                temp = GetValueFromString(osconf[1], "PRETASKHOOK");
                                if ("TRUE" == temp)
                                {
                                    PRETASK_HOOK_ENABLED.Checked = true;
                                }
                                else
                                {
                                    PRETASK_HOOK_ENABLED.Checked = false;
                                }
                                osconf[1] = osconf[1].Remove(0, (osconf[1].IndexOf(';') + 1));
                                temp = GetValueFromString(osconf[1], "POSTTASKHOOK");
                                if ("TRUE" == temp)
                                {
                                    POSTTASK_HOOK_ENABLED.Checked = true;
                                }
                                else
                                {
                                    POSTTASK_HOOK_ENABLED.Checked = false;
                                }
                                osconf[1] = osconf[1].Remove(0, (osconf[1].IndexOf(';') + 1));
                                temp = GetValueFromString(osconf[1], "PREISRHOOK");
                                if ("TRUE" == temp)
                                {
                                    PREISR_HOOK_ENABLED.Checked = true;
                                }
                                else
                                {
                                    PREISR_HOOK_ENABLED.Checked = false;
                                }
                                osconf[1] = osconf[1].Remove(0, (osconf[1].IndexOf(';') + 1));
                                temp = GetValueFromString(osconf[1], "POSTISRHOOK");
                                if ("TRUE" == temp)
                                {
                                    POSTISR_HOOK_ENABLED.Checked = true;
                                }
                                else
                                {
                                    POSTISR_HOOK_ENABLED.Checked = false;
                                }
                                osconf[1] = osconf[1].Remove(0, (osconf[1].IndexOf(';') + 1));
                                temp = GetValueFromString(osconf[1], "INTERRUPTNESTING");
                                if ("TRUE" == temp)
                                {
                                    Enabled_ISR_Nesting.Checked = true;
                                }
                                else
                                {
                                    Enabled_ISR_Nesting.Checked = false;
                                }
                                osconf[1] = osconf[1].Remove(0, (osconf[1].IndexOf(';') + 1));
                                // COUNTERS ----------------------------------------------\
                                string[] cnt = text.Split(new string[] { "COUNTER " }, StringSplitOptions.RemoveEmptyEntries);
                                CounterCount = cnt.Length;
                                // remove the fake rows
                                for (int i = 0; i < CounterCount; i++)
                                {
                                    if (cnt[i].Contains("TIMER ="))
                                    {
                                        if (CounterList[j] == null)
                                        {
                                            CounterList[j] = new Counter();
                                        }
                                        CounterList[j].SetCounterName(GetNameOfObject(cnt[i]));
                                        cnt[i] = cnt[i].Remove(0, (cnt[i].IndexOf('{') + 1));
                                        CounterList[j].SetTimerName(GetValueFromString(cnt[i], "TIMER"));
                                        cnt[i] = cnt[i].Remove(0, (cnt[i].IndexOf(';') + 1));
                                        CounterList[j].SetMinCycle(GetValueFromString(cnt[i], "MINCYCLE"));
                                        cnt[i] = cnt[i].Remove(0, (cnt[i].IndexOf(';') + 1));
                                        CounterList[j].SetMaxAllowedValue(GetValueFromString(cnt[i], "MAXALLOWEDVALUE"));
                                        cnt[i] = cnt[i].Remove(0, (cnt[i].IndexOf(';') + 1));
                                        CounterList[j].SetTickPerBase(GetValueFromString(cnt[i], "TICKPERBASE"));
                                        cnt[i] = cnt[i].Remove(0, (cnt[i].IndexOf(';') + 1));
                                        CounterList[j].SetTimeInNS(GetValueFromString(cnt[i], "TIME_IN_NS"));
                                        cnt[i] = cnt[i].Remove(0, (cnt[i].IndexOf(';') + 1));
                                        j++;
                                    }
                                }
                                CounterCount = j;
                                this.OStree.SelectedNode = this.OStree.Nodes[0].Nodes[3];
                                if (this.OStree.SelectedNode.Nodes != null)
                                {
                                    this.OStree.SelectedNode.Nodes.Clear();
                                }
                                counter = 0;
                                while (CounterList[counter] != null)
                                {
                                    this.OStree.SelectedNode.Nodes.Add(CounterList[counter].GetCounterName());
                                    counter++;
                                }
                                COUNTER_SELECTOR.Items.Clear();
                                for (int i = 0; i < CounterCount; i++)
                                {
                                    COUNTER_SELECTOR.Items.Add(CounterList[i].GetCounterName());
                                }
                                // ALARMS---------------------------------------------------
                                string[] res = text.Split(new string[] { "ALARM " }, StringSplitOptions.None);
                                AlarmCounter = res.Length - 1;
                                for (int i = 0; i < AlarmCounter; i++)
                                {
                                    if (AlarmList[i] == null)
                                    {
                                        AlarmList[i] = new Alarm();
                                    }
                                    AlarmList[i].SetAlarmName(GetNameOfObject(res[i + 1]));

                                    AlarmList[i].SetAlarmCounter(GetValueFromString(res[i + 1], "COUNTER"));
                                    res[i + 1] = res[i + 1].Remove(0, (res[i + 1].IndexOf(';') + 1));
                                    string AlarmAction = GetValueFromString(res[i + 1], "ACTION");
                                    AlarmList[i].SetACTION_TYPE(AlarmAction);
                                    res[i + 1] = res[i + 1].Remove(0, (res[i + 1].IndexOf('{') + 1));
                                    if ("ACTIVATETASK" == AlarmAction)
                                    {
                                        AlarmList[i].SetTASK_NAME(GetValueFromString(res[i + 1], "TASK"));
                                    }
                                    else if ("SETEVENT" == AlarmAction)
                                    {
                                        AlarmList[i].SetEVENT_NAME(GetValueFromString(res[i + 1], "EVENT"));
                                    }
                                    else if ("ALARMCALLBACK" == AlarmAction)
                                    {
                                        AlarmList[i].SetALARMCALLBACK(GetValueFromString(res[i + 1], "CALLBACK"));
                                    }
                                    else
                                    {
                                        MessageBox.Show(NameOfSystem, "Not correct OIL File!");
                                    }
                                    res[i + 1] = res[i + 1].Remove(0, (res[i + 1].IndexOf('}') + 1));
                                    res[i + 1] = res[i + 1].Remove(0, (res[i + 1].IndexOf(';') + 1));
                                    AlarmList[i].SetAlarmAutostartEn(GetValueFromString(res[i + 1], "AUTOSTART"));
                                    res[i + 1] = res[i + 1].Remove(0, (res[i + 1].IndexOf('{') + 1));
                                    AlarmList[i].SetAutostart_Alarmtime(GetValueFromString(res[i + 1], "ALARMTIME"));
                                    res[i + 1] = res[i + 1].Remove(0, (res[i + 1].IndexOf(';') + 1));
                                    AlarmList[i].SetAutostart_cycletime(GetValueFromString(res[i + 1], "CYCLETIME"));

                                }
                                this.OStree.SelectedNode = this.OStree.Nodes[0].Nodes[5];
                                if (this.OStree.SelectedNode.Nodes != null)
                                {
                                    this.OStree.SelectedNode.Nodes.Clear();
                                }
                                counter = 0;
                                while (AlarmList[counter] != null)
                                {
                                    this.OStree.SelectedNode.Nodes.Add(AlarmList[counter].GetAlarmName());
                                    counter++;
                                }
                                // TASKS --------------------------------------------------------------------
                                j = 0;
                                string[] tsk = text.Split(new string[] { "TASK " }, StringSplitOptions.None);
                                TaskCounter = tsk.Length - 1;
                                for (int i = 0; i < TaskCounter; i++)
                                {
                                    if (tsk[i].Contains("PRIORITY ="))
                                    {
                                        if (TaskList[j] == null)
                                        {
                                            TaskList[j] = new Task();
                                        }
                                        TaskList[j].SetTaskName(GetNameOfObject(tsk[i]));
                                        tsk[i] = tsk[i].Remove(0, (tsk[i].IndexOf('{') + 1));
                                        TaskList[j].SetTaskType(GetValueFromString(tsk[i], "TYPE"));
                                        tsk[i] = tsk[i].Remove(0, (tsk[i].IndexOf(';') + 1));
                                        TaskList[j].SetTaskPrio(GetValueFromString(tsk[i], "PRIORITY"));
                                        tsk[i] = tsk[i].Remove(0, (tsk[i].IndexOf(';') + 1));
                                        TaskList[j].SetTaskActivation(GetValueFromString(tsk[i], "ACTIVATION"));
                                        tsk[i] = tsk[i].Remove(0, (tsk[i].IndexOf(';') + 1));
                                        TaskList[j].SetTaskScheduler(GetValueFromString(tsk[i], "SCHEDULE"));
                                        tsk[i] = tsk[i].Remove(0, (tsk[i].IndexOf(';') + 1));
                                        TaskList[j].SetTaskCallScheduler(GetValueFromString(tsk[i], "CALLSCHEDULER"));
                                        tsk[i] = tsk[i].Remove(0, (tsk[i].IndexOf(';') + 1));
                                        TaskList[j].SetTaskStackSize(GetValueFromString(tsk[i], "STACKSIZE"));
                                        tsk[i] = tsk[i].Remove(0, (tsk[i].IndexOf(';') + 1));
                                        TaskList[j].SetTaskEvent(GetValueFromString(tsk[i], "EVENT"));
                                        tsk[i] = tsk[i].Remove(0, (tsk[i].IndexOf(';') + 1));
                                        TaskList[j].SetTaskResource(GetValueFromString(tsk[i], "RESOURCE"));
                                        tsk[i] = tsk[i].Remove(0, (tsk[i].IndexOf(';') + 1));
                                        TaskList[j].SetAutoStartTask(GetValueFromString(tsk[i], "AUTOSTART").Contains("TRUE"));
                                        tsk[i] = tsk[i].Remove(0, (tsk[i].IndexOf(';') + 1));
                                        j++;
                                    }
                                }
                                TaskCounter = j;
                                this.OStree.SelectedNode = this.OStree.Nodes[0].Nodes[1];
                                if (this.OStree.SelectedNode.Nodes != null)
                                {
                                    this.OStree.SelectedNode.Nodes.Clear();
                                }
                                counter = 0;
                                while (TaskList[counter] != null)
                                {
                                    this.OStree.SelectedNode.Nodes.Add(TaskList[counter].GetTaskName());
                                    counter++;
                                }

                                OStree.Enabled = true;
                                OStree.Visible = true;
                                SaveButton.Enabled = true;
                                tabControl.Visible = true;
                                tabControl.Enabled = true;
                                ValidateIt.Enabled = true;
                                GenerateButton.Enabled = true;
                            }
                            catch (IOException)
                            {
                            }

                        }
                    }

                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
            StatisticsButton.Enabled = true;
        }
Esempio n. 4
0
        //==============================================================================
        // DESCRIPTION :
        //
        // PARAMETERS (Type,Name,Min,Max) :
        //
        // RETURN VALUE :
        //
        // DESIGN INFORMATION :
        //==============================================================================
        private void OnMiceClick(object sender, EventArgs e)
        {
            DisableEvents();
            MenuItem miClicked = (MenuItem)sender;
            string item = miClicked.Text;
            string t = MyContext.ToString();
            if("OSEK_CONF" == OStree.SelectedNode.Text)
            {
                return;
            }
            else
            {
                if( (null != OStree.SelectedNode.Parent)&&
                    ("OSEK_CONF" == OStree.SelectedNode.Parent.Text)
                    )
                {
                    if("New" == item)
                    {
                        OStree.SelectedNode.Nodes.Add("OSEK Properties");

                        try
                        {
                            // OS should have only one set of property
                            MyContext.MenuItems.Clear();

                        }
                        catch
                        {
                            MessageBox.Show("Problem in the clear context menu");
                        }
                    }
                    else if("Add" == item)
                    {
                        string NameForm = OStree.SelectedNode.Text + "_Child" + (TaskCounter + (int)1).ToString();
                        OStree.SelectedNode.Nodes.Add(NameForm);
                        if("TASK" == OStree.SelectedNode.Text)
                        {
                            // Allocate space for task's struct
                            TaskList[TaskCounter++] = new Task();
                            if(TaskCounter >= (int)16)
                            {
                                MessageBox.Show("Exceeeded max number of tasks");
                            }

                        }

                    }
                    else
                    {
                        MessageBox.Show("Unkown context menu item for first deptch!");
                    }
                }
                else if(
                    (null != OStree.SelectedNode.Parent)&&
                    (null != OStree.SelectedNode.Parent.Parent)&&
                    ("OSEK_CONF" == OStree.SelectedNode.Parent.Parent.Text)
                    )
                {
                    if("Delete" == item)
                    {
                        int i;
                        if("TASK"  == OStree.SelectedNode.Parent.Text)
                        {
                            if(0 < TaskCounter)
                            {
                                TaskCounter--;
                            }

                            try
                            {
                                TaskList[OStree.SelectedNode.Index].SetTaskCallScheduler("");
                                TaskList[OStree.SelectedNode.Index].SetTaskEvent("");
                                TaskList[OStree.SelectedNode.Index].SetTaskName("");
                                TaskList[OStree.SelectedNode.Index].SetTaskPrio("");
                                TaskList[OStree.SelectedNode.Index].SetTaskResource("");
                                TaskList[OStree.SelectedNode.Index].SetTaskResource("");
                                TaskList[OStree.SelectedNode.Index].SetTaskScheduler("");
                                TaskList[OStree.SelectedNode.Index].SetTaskStackSize("");
                                TaskList[OStree.SelectedNode.Index].SetTaskActivation("");
                                TaskList[OStree.SelectedNode.Index].SetTaskType("");

                                for(i = OStree.SelectedNode.Index; (i < 16 && (null != TaskList[i+1])); i++)
                                {
                                    TaskList[i] = TaskList[i+1];
                                }
                                TaskList[i] = null;
                                OStree.SelectedNode.Nodes.Remove(OStree.SelectedNode);
                                if(0 < TaskCounter)
                                {
                                    TaskCounter--;
                                }

                            }
                            catch
                            {
                                MessageBox.Show("Failed remove a child node");
                            }
                        }

                        FormContextMenu();
                    }
                    else if("Edit" == item)
                    {
                        if(!OStree.SelectedNode.IsEditing)
                        {

                            OStree.SelectedNode.BeginEdit();
                        }

                    }
                    else
                    {
                        MessageBox.Show("Unkown context menu item for second deptch!");
                    }
                }
            }
            OStree.ExpandAll();
            EnableEvents();
        }