Esempio n. 1
0
        public Step11(string s_name)
        {
            this.Index = COUNT_STEPS++;
            this.Name  = s_name;

            //initializing the time condition
            this.time_cond = new TimeCondition(this.index, this.name);
            this.IsUsedInTimeConditions = false;
        }
Esempio n. 2
0
        public Step11(XmlNode XmlStepNode)
        {
            this.Index = COUNT_STEPS++;
            this.Name  = XmlStepNode.Attributes[0].Value;
            //MessageBox.Show("new Step = " + this.Name);
            this.Negated       = bool.Parse(XmlStepNode.Attributes[5].Value);
            this.isInitialStep = bool.Parse(XmlStepNode.Attributes[4].Value);
            this.LocalId       = Int32.Parse(XmlStepNode.Attributes[3].Value);
            this.RefLocalId    = XmlStepNode.LastChild.HasChildNodes == true?Int32.Parse(XmlStepNode.LastChild.ChildNodes[0].Attributes[0].Value) : 0;

            //initializing the time condition
            this.time_cond = new TimeCondition(this.index, this.name);
            this.IsUsedInTimeConditions = false;
        }
Esempio n. 3
0
        //Arduino code generation
        /// <summary>
        /// Arduino preparation of code generation : Modify transition conditions to create this.arduino_condition
        /// </summary>
        public void arduino_code_generation_prepare_clearing_condition()
        {
            this.arduino_R_condition = this.Condition;

            //Transform Timing variables
            int    cond_index_begin;
            int    cond_index_end;;
            string stringCondition;

            int min_cond_lenght = "[S5.t>2m]".Length;
            int range;

            do //loops two times in order to takle cases where [S0.x] occurs before [S0.t>4s]; for example: [S0.x] * [S0.t>4s]
               //Transform Timing condition
            {
                do
                {
                    cond_index_begin = this.arduino_R_condition.IndexOf('[');
                    cond_index_end   = this.arduino_R_condition.IndexOf(']');
                    range            = cond_index_end - cond_index_begin + 1;

                    if (range >= min_cond_lenght && this.arduino_R_condition.Contains(">"))
                    {
                        stringCondition = this.arduino_R_condition.Substring(cond_index_begin, range);
                        int    point_index = stringCondition.IndexOf('.');
                        string stepName    = stringCondition.Substring(1, point_index - 1);
                        string st_duration = stringCondition.Substring(point_index + 3, stringCondition.Length - (5 + stepName.Length));
                        int    duration_ms = TimeCondition.getDurationInMilliseconds(st_duration);
                        //Update arduino_condition. "TIMES_UNIT" will be replaced by "*frequency_timer" after the replacement of * by &&
                        //string new_stringCondition = "(" + stepName + "_duration > " + (duration_ms / GrafcetClass.g7_TIME_UNIT_TimingConstraints) + "TIMES_UNIT)";
                        string new_stringCondition = "(" + stepName + "_duration > " + (duration_ms / GrafcetClass.g7_Board_TimeUnit_TimerStepActivity) + ")";
                        this.arduino_R_condition = this.arduino_R_condition.Replace(stringCondition, new_stringCondition);//duration_ms / 1000

                        //MessageBox.Show("Transition: this.arduino_condition = " + this.arduino_condition);
                    }

                    cond_index_begin = this.arduino_R_condition.IndexOf('[');
                    cond_index_end   = this.arduino_R_condition.IndexOf(']');
                    range            = cond_index_end - cond_index_begin + 1;
                } while (range >= min_cond_lenght && this.arduino_R_condition.Contains(">"));

                //MessageBox.Show("Arduino Condition After Condition Time parse : " + this.arduino_condition);

                //Now Time conditions have finished. If there are [ symbols, it is because of step variable
                //Transform Step variable in transition receptivity
                do
                {
                    cond_index_begin = this.arduino_R_condition.IndexOf('[');
                    cond_index_end   = this.arduino_R_condition.IndexOf(']');
                    range            = cond_index_end - cond_index_begin + 1;
                    if (this.arduino_R_condition.Contains(".X]"))
                    {
                        stringCondition = this.arduino_R_condition.Substring(cond_index_begin, range);
                        int    point_index = stringCondition.IndexOf('.');
                        string stepName    = stringCondition.Substring(1, point_index - 1);
                        this.arduino_R_condition = this.arduino_R_condition.Replace(stringCondition, stepName + "_X");
                        //MessageBox.Show("Arduino step variable : " + stepName + "_X \t 1-Arduino Condition : " + this.arduino_condition);
                    }
                } while (this.arduino_R_condition.Contains("[") && this.arduino_R_condition.Contains(".X"));

                //It is necessary to parse this condition to build a tree and to generate the appropriate condition for Arduino
                //Lets consider only Simple Rising Edge
                while (this.arduino_R_condition.Contains('^'))
                {
                    int index_begin = this.arduino_R_condition.IndexOf("^") + 1;
                    int index_end   = index_begin;
                    while ((index_end < this.arduino_R_condition.Length) && (this.arduino_R_condition.ElementAt(index_end) != '+') && (this.arduino_R_condition.ElementAt(index_end) != '*') && (this.arduino_R_condition.ElementAt(index_end) != ')'))
                    {
                        index_end++;
                    }
                    index_end--;
                    int    var_range = index_end - index_begin + 1;
                    string varName   = this.arduino_R_condition.Substring(index_begin, var_range);

                    string str_condition = "(!" + varName + "_Old && " + varName + ")";
                    this.arduino_R_condition = this.arduino_R_condition.Replace("^" + varName, str_condition);

                    //MessageBox.Show(this.Condition + "\nvarName: " + varName + "\n str_condition: " + str_condition);
                }
                //MessageBox.Show("Arduino Condition After Rising Edge parse : \n" + this.arduino_condition);
            } while (this.arduino_R_condition.Contains("["));

            this.arduino_R_condition = this.arduino_R_condition.Replace("+", " || ");
            this.arduino_R_condition = this.arduino_R_condition.Replace("*", " && ");
            //this.arduino_condition = this.arduino_condition.Replace("TIMES_UNIT", "*frequency_timer");
            //MessageBox.Show("Arduino Condition After Step Variable parse : " + this.arduino_condition);
        }