Beispiel #1
0
        //================================================================================================//
        // process subterm
        //================================================================================================//
        private static int ProcessSubTerm(SignalHead head, List <SignalScripts.SCRScripts.SCRStatTerm> statementTerms, int sublevel, int[] localFloats)
        {
            int tempValue = 0;
            int termValue;

            foreach (SignalScripts.SCRScripts.SCRStatTerm term in statementTerms)
            {
                if (term.Function == SignalScripts.SCRExternalFunctions.RETURN)
                {
                    break;
                }

                SignalScripts.SCRTermOperator thisOperator = term.TermOperator;
                if (term.TermLevel == sublevel)
                {
                    termValue = ProcessAssignTerm(head, statementTerms, term, localFloats);
                    if (term.Negated)
                    {
                        termValue = termValue == 0 ? 1 : 0;
                    }

                    switch (thisOperator)
                    {
                    case (SignalScripts.SCRTermOperator.MULTIPLY):
                        tempValue *= termValue;
                        break;

                    case (SignalScripts.SCRTermOperator.PLUS):
                        tempValue += termValue;
                        break;

                    case (SignalScripts.SCRTermOperator.MINUS):
                        tempValue -= termValue;
                        break;

                    case (SignalScripts.SCRTermOperator.DIVIDE):
                        if (termValue == 0)
                        {
                            tempValue = 0;
                        }
                        else
                        {
                            tempValue /= termValue;
                        }
                        break;

                    case (SignalScripts.SCRTermOperator.MODULO):
                        tempValue %= termValue;
                        break;

                    default:
                        tempValue = termValue;
                        break;
                    }
                }
            }
            return(tempValue);
        }
Beispiel #2
0
 //================================================================================================//
 // process script
 //================================================================================================//
 private static void ProcessScript(SignalHead head, SignalScripts.SCRScripts signalScript)
 {
     int[] localFloats = new int[signalScript.TotalLocalFloats];
     // process script
     if (!ProcessStatementBlock(head, signalScript.Statements, localFloats))
     {
         return;
     }
 }
Beispiel #3
0
        //================================================================================================//
        //
        // update_basic : update signal without script
        //
        //================================================================================================//

        public void SH_update_basic(SignalHead thisHead)
        {
            if (thisHead.mainSignal.block_state() == MstsBlockState.CLEAR)
            {
                thisHead.SetLeastRestrictiveAspect();
            }
            else
            {
                thisHead.SetMostRestrictiveAspect();
            }
        }
Beispiel #4
0
 //================================================================================================//
 // update_basic : update signal without script
 //================================================================================================//
 private static void UpdateBasic(SignalHead head)
 {
     if (head.MainSignal.BlockState() == SignalBlockState.Clear)
     {
         head.SetLeastRestrictiveAspect();
     }
     else
     {
         head.SetMostRestrictiveAspect();
     }
 }
Beispiel #5
0
        //================================================================================================//
        // check IF conditions
        //================================================================================================//
        private static bool ProcessIfCondition(SignalHead head, SignalScripts.SCRScripts.SCRConditionBlock condition, int[] localFloats)
        {
            bool performed = false;

            // check condition

            // if set : execute IF block
            if (ProcessConditionStatement(head, condition.Conditions, localFloats))
            {
                if (!ProcessStatementBlock(head, condition.IfBlock.Statements, localFloats))
                {
                    return(false);
                }
                performed = true;
            }

            // not set : check through ELSEIF
            if (!performed)
            {
                int totalElseIf = condition.ElseIfBlock == null ? 0 : condition.ElseIfBlock.Count;

                for (int ielseif = 0; ielseif < totalElseIf && !performed; ielseif++)
                {
                    // first (and only ) entry in ELSEIF block must be IF condition - extract condition
                    object elseifStat = condition.ElseIfBlock[ielseif].Statements[0];
                    if (elseifStat is SignalScripts.SCRScripts.SCRConditionBlock elseifCond)
                    {
                        if (ProcessConditionStatement(head, elseifCond.Conditions, localFloats))
                        {
                            if (!ProcessStatementBlock(head, elseifCond.IfBlock.Statements, localFloats))
                            {
                                return(false);
                            }
                            performed = true;
                        }
                    }
                }
            }

            // ELSE block
            if (!performed && condition.ElseBlock != null)
            {
                if (!ProcessStatementBlock(head, condition.ElseBlock.Statements, localFloats))
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #6
0
 //================================================================================================//
 //
 // processing routines
 //
 //================================================================================================//
 // main update routine
 //================================================================================================//
 internal static void SignalHeadUpdate(SignalHead head, SignalScripts.SCRScripts signalScript)
 {
     if (head.SignalType == null)
     {
         return;
     }
     if (signalScript != null)
     {
         ProcessScript(head, signalScript);
     }
     else
     {
         UpdateBasic(head);
     }
 }
Beispiel #7
0
        //================================================================================================//
        //
        // process assign statement
        //
        //================================================================================================//

        public void SH_processAssignStatement(SignalHead thisHead, SignalScripts.SCRScripts.SCRStatement thisStat,
                                              int[] localFloats, SIGSCRfile sigscr)
        {
            // get term value

            int tempvalue = 0;

            tempvalue = SH_processSubTerm(thisHead, thisStat.StatementTerms, 0, localFloats, sigscr);

            // assign value

            switch (thisStat.AssignType)
            {
            // assign value to external float
            // Possible floats :
            //                        STATE
            //                        DRAW_STATE
            //                        ENABLED     (not allowed for write)
            //                        BLOCK_STATE (not allowed for write)

            case (SignalScripts.SCRTermType.ExternalFloat):
                SignalScripts.SCRExternalFloats FloatType = (SignalScripts.SCRExternalFloats)thisStat.AssignParameter;

                switch (FloatType)
                {
                case SignalScripts.SCRExternalFloats.STATE:
                    thisHead.state = (MstsSignalAspect)tempvalue;
                    break;

                case SignalScripts.SCRExternalFloats.DRAW_STATE:
                    thisHead.draw_state = tempvalue;
                    break;

                default:
                    break;
                }
                break;

            // Local float

            case (SignalScripts.SCRTermType.LocalFloat):
                localFloats[thisStat.AssignParameter] = tempvalue;
                break;

            default:
                break;
            }
        }
Beispiel #8
0
        //================================================================================================//
        //
        // processing routines
        //
        //================================================================================================//
        //
        // main update routine
        //
        //================================================================================================//

        public static void SH_update(SignalHead thisHead, SIGSCRfile sigscr)
        {
            SignalScripts.SCRScripts signalScript;
            if (thisHead.signalType == null)
            {
                return;
            }
            if (sigscr.SignalScripts.Scripts.TryGetValue(thisHead.signalType, out signalScript))
            {
                sigscr.SH_process_script(thisHead, signalScript, sigscr);
            }
            else
            {
                sigscr.SH_update_basic(thisHead);
            }
        }
Beispiel #9
0
        //================================================================================================//
        //
        // process script
        //
        //================================================================================================//

        public void SH_process_script(SignalHead thisHead, SignalScripts.SCRScripts signalScript, SIGSCRfile sigscr)
        {
            int[] localFloats = new int[signalScript.totalLocalFloats];

            // process script

#if DEBUG_PRINT_ENABLED
            if (thisHead.mainSignal.enabledTrain != null)
            {
                File.AppendAllText(dpe_fileLoc + @"printproc.txt", "\n\nSIGNAL : " + thisHead.TDBIndex.ToString() + "\n");
                File.AppendAllText(dpe_fileLoc + @"printproc.txt", "OBJECT : " + thisHead.mainSignal.thisRef.ToString() + "\n");
                File.AppendAllText(dpe_fileLoc + @"printproc.txt", "type   : " + signalScript.scriptname + "\n");
            }
#endif
#if DEBUG_PRINT_PROCESS
            if (TDB_debug_ref.Contains(thisHead.TDBIndex))
            {
                File.AppendAllText(dpr_fileLoc + @"printproc.txt", "\n\nSIGNAL : " + thisHead.TDBIndex.ToString() + "\n");
                File.AppendAllText(dpr_fileLoc + @"printproc.txt", "OBJECT : " + thisHead.mainSignal.thisRef.ToString() + "\n");
                File.AppendAllText(dpr_fileLoc + @"printproc.txt", "type   : " + signalScript.scriptname + "\n");
            }
#endif

            if (!SH_process_StatementBlock(thisHead, signalScript.Statements, localFloats, sigscr))
            {
                return;
            }


#if DEBUG_PRINT_ENABLED
            if (thisHead.mainSignal.enabledTrain != null)
            {
                File.AppendAllText(dpe_fileLoc + @"printproc.txt", "\n ------- \n");
            }
#endif
#if DEBUG_PRINT_PROCESS
            if (TDB_debug_ref.Contains(thisHead.TDBIndex))
            {
                File.AppendAllText(dpr_fileLoc + @"printproc.txt", "\n ------- \n");
            }
#endif
        }
Beispiel #10
0
        //================================================================================================//
        // get value of single term
        //================================================================================================//
        private static int ProcessAssignTerm(SignalHead head, List <SignalScripts.SCRScripts.SCRStatTerm> statementTerms, SignalScripts.SCRScripts.SCRStatTerm term, int[] localFloats)
        {
            int termvalue = 0;

            if (term.Function != SignalScripts.SCRExternalFunctions.NONE)
            {
                termvalue = FunctionValue(head, term, localFloats);
            }
            else if (term.PartParameter != null)
            {
                // for non-function terms only first entry is valid
                SignalScripts.SCRScripts.SCRParameterType parameter = term.PartParameter[0];
                termvalue = TermValue(head, parameter, localFloats);
            }
            else if (term.TermNumber > 0)
            {
                termvalue = ProcessSubTerm(head, statementTerms, term.TermNumber, localFloats);
            }
            return(termvalue);
        }
Beispiel #11
0
        //================================================================================================//
        // process assign statement
        //================================================================================================//
        private static void ProcessAssignStatement(SignalHead head, SignalScripts.SCRScripts.SCRStatement statement, int[] localFloats)
        {
            // get term value
            int tempvalue = ProcessSubTerm(head, statement.StatementTerms, 0, localFloats);

            // assign value
            switch (statement.AssignType)
            {
            // assign value to external float
            // Possible floats :
            //                        STATE
            //                        DRAW_STATE
            //                        ENABLED     (not allowed for write)
            //                        BLOCK_STATE (not allowed for write)
            case (SignalScripts.SCRTermType.ExternalFloat):
                SignalScripts.SCRExternalFloats floatType = (SignalScripts.SCRExternalFloats)statement.AssignParameter;

                switch (floatType)
                {
                case SignalScripts.SCRExternalFloats.STATE:
                    head.SignalIndicationState = (SignalAspectState)tempvalue;
                    break;

                case SignalScripts.SCRExternalFloats.DRAW_STATE:
                    head.DrawState = tempvalue;
                    break;

                default:
                    break;
                }
                break;

            // Local float
            case (SignalScripts.SCRTermType.LocalFloat):
                localFloats[statement.AssignParameter] = tempvalue;
                break;

            default:
                break;
            }
        }
Beispiel #12
0
 //================================================================================================//
 // process statement block
 // called for full script as well as for IF and ELSE blocks
 // if returns false : abort further processing
 //================================================================================================//
 private static bool ProcessStatementBlock(SignalHead head, ArrayList statements, int[] localFloats)
 {
     // loop through all lines
     foreach (object scriptstat in statements)
     {
         // process statement lines
         if (scriptstat is SignalScripts.SCRScripts.SCRStatement statement)
         {
             if (statement.StatementTerms[0].Function == SignalScripts.SCRExternalFunctions.RETURN)
             {
                 return(false);
             }
             ProcessAssignStatement(head, statement, localFloats);
         }
         else if (scriptstat is SignalScripts.SCRScripts.SCRConditionBlock conditionalBlock)
         {
             if (!ProcessIfCondition(head, conditionalBlock, localFloats))
             {
                 return(false);
             }
         }
     }
     return(true);
 }
Beispiel #13
0
        //================================================================================================//
        //
        // get value of single term
        //
        //================================================================================================//

        public int SH_processAssignTerm(SignalHead thisHead, List <SignalScripts.SCRScripts.SCRStatTerm> StatementTerms,
                                        SignalScripts.SCRScripts.SCRStatTerm thisTerm, int sublevel,
                                        int[] localFloats, SIGSCRfile sigscr)
        {
            int termvalue = 0;

            if (thisTerm.Function != SignalScripts.SCRExternalFunctions.NONE)
            {
                termvalue = SH_function_value(thisHead, thisTerm, localFloats, sigscr);
            }
            else if (thisTerm.PartParameter != null)
            {
                // for non-function terms only first entry is valid

                SignalScripts.SCRScripts.SCRParameterType thisParameter = thisTerm.PartParameter[0];
                termvalue = SH_termvalue(thisHead, thisParameter, localFloats, sigscr);
            }
            else if (thisTerm.sublevel > 0)
            {
                termvalue = SH_processSubTerm(thisHead, StatementTerms, thisTerm.sublevel, localFloats, sigscr);
            }

            return(termvalue);
        }
Beispiel #14
0
        //================================================================================================//
        //
        // check IF conditions
        //
        //================================================================================================//

        public bool SH_processIfCondition(SignalHead thisHead, SignalScripts.SCRScripts.SCRConditionBlock thisCond,
                                          int[] localFloats, SIGSCRfile sigscr)
        {
            //                                SCRScripts.SCRConditionBlock thisCond = (SCRScripts.SCRConditionBlock) scriptstat;
            //                                SH_processIfCondition(thisHead, thisCond, localFloats, sigscr);
            //                                public ArrayList       Conditions;
            //                                public SCRBlock        IfBlock;
            //                                public List <SCRBlock> ElseIfBlock;
            //                                public SCRBlock        ElseBlock;

            bool condition = true;
            bool performed = false;

            // check condition

            condition = SH_processConditionStatement(thisHead, thisCond.Conditions, localFloats, sigscr);

            // if set : execute IF block

            if (condition)
            {
                if (!SH_process_StatementBlock(thisHead, thisCond.IfBlock.Statements, localFloats, sigscr))
                {
                    return(false);
                }
                performed = true;
            }

            // not set : check through ELSEIF

            if (!performed)
            {
                int totalElseIf;
                if (thisCond.ElseIfBlock == null)
                {
                    totalElseIf = 0;
                }
                else
                {
                    totalElseIf = thisCond.ElseIfBlock.Count;
                }

                for (int ielseif = 0; ielseif < totalElseIf && !performed; ielseif++)
                {
                    // first (and only ) entry in ELSEIF block must be IF condition - extract condition

                    object elseifStat = thisCond.ElseIfBlock[ielseif].Statements[0];
                    if (elseifStat is SignalScripts.SCRScripts.SCRConditionBlock)
                    {
                        SignalScripts.SCRScripts.SCRConditionBlock elseifCond =
                            (SignalScripts.SCRScripts.SCRConditionBlock)elseifStat;

                        condition = SH_processConditionStatement(thisHead, elseifCond.Conditions,
                                                                 localFloats, sigscr);

                        if (condition)
                        {
                            if (!SH_process_StatementBlock(thisHead, elseifCond.IfBlock.Statements,
                                                           localFloats, sigscr))
                            {
                                return(false);
                            }
                            performed = true;
                        }
                    }
                }
            }

            // ELSE block

            if (!performed && thisCond.ElseBlock != null)
            {
                if (!SH_process_StatementBlock(thisHead, thisCond.ElseBlock.Statements, localFloats, sigscr))
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #15
0
        //================================================================================================//
        //
        // return function value
        // Possible functions :
        //                        BLOCK_STATE
        //                        ROUTE_SET
        //                        NEXT_SIG_LR
        //                        NEXT_SIG_MR
        //                        THIS_SIG_LR
        //                        THIS_SIG_MR
        //                        OPP_SIG_LR
        //                        OPP_SIG_MR
        //                        DIST_MULTI_SIG_MR
        //                        SIG_FEATURE
        //                        DEF_DRAW_STATE
        //                        HASHEAD
        //                        DEBUG_HEADER   (does not return a value)
        //                        DEBUG_OUT      (does not return a value)
        //
        //================================================================================================//

        public int SH_function_value(SignalHead thisHead, SignalScripts.SCRScripts.SCRStatTerm thisTerm,
                                     int[] localFloats, SIGSCRfile sigscr)
        {
            int return_value     = 0;
            int parameter1_value = 0;
            int parameter2_value = 0;

            // extract parameters (max. 2)

            if (thisTerm.PartParameter != null)
            {
                if (thisTerm.PartParameter.Length >= 1)
                {
                    SignalScripts.SCRScripts.SCRParameterType thisParameter = thisTerm.PartParameter[0];
                    parameter1_value = SH_termvalue(thisHead, thisParameter,
                                                    localFloats, sigscr);
                }

                if (thisTerm.PartParameter.Length >= 2)
                {
                    SignalScripts.SCRScripts.SCRParameterType thisParameter = thisTerm.PartParameter[1];
                    parameter2_value = SH_termvalue(thisHead, thisParameter,
                                                    localFloats, sigscr);
                }
            }

            // switch on function

            SignalScripts.SCRExternalFunctions thisFunction = thisTerm.Function;
            String dumpfile = String.Empty;

            switch (thisFunction)
            {
            // BlockState

            case (SignalScripts.SCRExternalFunctions.BLOCK_STATE):
                return_value = (int)thisHead.mainSignal.block_state();
                break;

            // Route set

            case (SignalScripts.SCRExternalFunctions.ROUTE_SET):
                return_value = (int)thisHead.route_set();
                break;

            // next_sig_lr

            case (SignalScripts.SCRExternalFunctions.NEXT_SIG_LR):
                return_value = (int)thisHead.next_sig_lr((MstsSignalFunction)parameter1_value);
#if DEBUG_PRINT_ENABLED
                if (thisHead.mainSignal.enabledTrain != null)
                {
                    File.AppendAllText(dpe_fileLoc + @"printproc.txt",
                                       " NEXT_SIG_LR : Located signal : " +
                                       thisHead.mainSignal.sigfound[parameter1_value].ToString() + "\n");
                }
#endif
#if DEBUG_PRINT_PROCESS
                if (TDB_debug_ref.Contains(thisHead.TDBIndex))
                {
                    var sob = new StringBuilder();
                    sob.AppendFormat(" NEXT_SIG_LR : Located signal : {0}", thisHead.mainSignal.sigfound[parameter1_value].ToString());

                    if (thisHead.mainSignal.sigfound[parameter1_value] > 0)
                    {
                        SignalObject otherSignal = thisHead.mainSignal.signalRef.SignalObjects[thisHead.mainSignal.sigfound[parameter1_value]];
                        sob.AppendFormat(" (");

                        foreach (SignalHead otherHead in otherSignal.SignalHeads)
                        {
                            sob.AppendFormat(" {0} ", otherHead.TDBIndex);
                        }

                        sob.AppendFormat(") ");
                    }
                    sob.AppendFormat("\n");

                    File.AppendAllText(dpr_fileLoc + @"printproc.txt", sob.ToString());
                }
#endif

                break;

            // next_sig_mr

            case (SignalScripts.SCRExternalFunctions.NEXT_SIG_MR):
                return_value = (int)thisHead.next_sig_mr((MstsSignalFunction)parameter1_value);
#if DEBUG_PRINT_ENABLED
                if (thisHead.mainSignal.enabledTrain != null)
                {
                    File.AppendAllText(dpe_fileLoc + @"printproc.txt",
                                       " NEXT_SIG_LR : Located signal : " +
                                       thisHead.mainSignal.sigfound[parameter1_value].ToString() + "\n");
                }
#endif
#if DEBUG_PRINT_PROCESS
                if (TDB_debug_ref.Contains(thisHead.TDBIndex))
                {
                    File.AppendAllText(dpr_fileLoc + @"printproc.txt",
                                       " NEXT_SIG_LR : Located signal : " +
                                       thisHead.mainSignal.sigfound[parameter1_value].ToString() + "\n");
                }
#endif
                break;

            // this_sig_lr

            case (SignalScripts.SCRExternalFunctions.THIS_SIG_LR):
                bool             sigfound_lr    = false;
                MstsSignalAspect returnState_lr = thisHead.this_sig_lr((MstsSignalFunction)parameter1_value, ref sigfound_lr);
                return_value = sigfound_lr ? (int)returnState_lr : -1;
                break;

            // this_sig_mr

            case (SignalScripts.SCRExternalFunctions.THIS_SIG_MR):
                bool             sigfound_mr    = false;
                MstsSignalAspect returnState_mr = thisHead.this_sig_mr((MstsSignalFunction)parameter1_value, ref sigfound_mr);
                return_value = sigfound_mr ? (int)returnState_mr : -1;
                break;

            // opp_sig_lr

            case (SignalScripts.SCRExternalFunctions.OPP_SIG_LR):
                return_value = (int)thisHead.opp_sig_lr((MstsSignalFunction)parameter1_value);
#if DEBUG_PRINT_ENABLED
                if (thisHead.mainSignal.enabledTrain != null)
                {
                    SignalObject foundSignal = null;
                    int          dummy       = (int)thisHead.opp_sig_lr((MstsSignalFunction)parameter1_value, ref foundSignal);
                    int          foundRef    = foundSignal != null ? foundSignal.thisRef : -1;
                    File.AppendAllText(dpe_fileLoc + @"printproc.txt",
                                       " OPP_SIG_LR : Located signal : " + foundRef.ToString() + "\n");
                }
#endif
#if DEBUG_PRINT_PROCESS
                if (TDB_debug_ref.Contains(thisHead.TDBIndex))
                {
                    SignalObject foundSignal = null;
                    int          dummy       = (int)thisHead.opp_sig_lr((MstsSignalFunction)parameter1_value, ref foundSignal);
                    int          foundRef    = foundSignal != null ? foundSignal.thisRef : -1;
                    File.AppendAllText(dpr_fileLoc + @"printproc.txt",
                                       " OPP_SIG_LR : Located signal : " + foundRef.ToString() + "\n");
                }
#endif
                break;

            // opp_sig_mr

            case (SignalScripts.SCRExternalFunctions.OPP_SIG_MR):
                return_value = (int)thisHead.opp_sig_mr((MstsSignalFunction)parameter1_value);
                break;

            // next_nsig_lr

            case (SignalScripts.SCRExternalFunctions.NEXT_NSIG_LR):
                dumpfile = String.Empty;

#if DEBUG_PRINT_ENABLED
                if (thisHead.mainSignal.enabledTrain != null)
                {
                    dumpfile = String.Concat(dpe_fileLoc, "printproc.txt");
                }
#endif

#if DEBUG_PRINT_PROCESS
                if (TDB_debug_ref.Contains(thisHead.TDBIndex))
                {
                    dumpfile = String.Concat(dpr_fileLoc, "printproc.txt");
                }
#endif
                return_value = (int)thisHead.next_nsig_lr((MstsSignalFunction)parameter1_value, parameter2_value, dumpfile);
                break;

            // dist_multi_sig_mr

            case (SignalScripts.SCRExternalFunctions.DIST_MULTI_SIG_MR):

                dumpfile = String.Empty;

#if DEBUG_PRINT_ENABLED
                if (thisHead.mainSignal.enabledTrain != null)
                {
                    dumpfile = String.Concat(dpe_fileLoc, "printproc.txt");
                }
#endif

#if DEBUG_PRINT_PROCESS
                if (TDB_debug_ref.Contains(thisHead.TDBIndex))
                {
                    dumpfile = String.Concat(dpr_fileLoc, "printproc.txt");
                }
#endif

                return_value = (int)thisHead.dist_multi_sig_mr(
                    (MstsSignalFunction)parameter1_value,
                    (MstsSignalFunction)parameter2_value,
                    dumpfile);

                break;

            // sig_feature

            case (SignalScripts.SCRExternalFunctions.SIG_FEATURE):
                bool temp_value;
                temp_value   = thisHead.sig_feature(parameter1_value);
                return_value = Convert.ToInt32(temp_value);
                break;

            // approach control position

            case (SignalScripts.SCRExternalFunctions.APPROACH_CONTROL_POSITION):
                dumpfile = String.Empty;

#if DEBUG_PRINT_ENABLED
                if (thisHead.mainSignal.enabledTrain != null)
                {
                    dumpfile = String.Concat(dpe_fileLoc, "printproc.txt");
                }
#endif

#if DEBUG_PRINT_PROCESS
                if (TDB_debug_ref.Contains(thisHead.TDBIndex))
                {
                    dumpfile = String.Concat(dpr_fileLoc, "printproc.txt");
                }
#endif
                temp_value   = thisHead.mainSignal.ApproachControlPosition(parameter1_value, dumpfile);
                return_value = Convert.ToInt32(temp_value);
                break;

            // approach control speed

            case (SignalScripts.SCRExternalFunctions.APPROACH_CONTROL_SPEED):
                dumpfile = String.Empty;

#if DEBUG_PRINT_ENABLED
                if (thisHead.mainSignal.enabledTrain != null)
                {
                    dumpfile = String.Concat(dpe_fileLoc, "printproc.txt");
                }
#endif

#if DEBUG_PRINT_PROCESS
                if (TDB_debug_ref.Contains(thisHead.TDBIndex))
                {
                    dumpfile = String.Concat(dpr_fileLoc, "printproc.txt");
                }
#endif
                temp_value   = thisHead.mainSignal.ApproachControlSpeed(parameter1_value, parameter2_value, dumpfile);
                return_value = Convert.ToInt32(temp_value);
                break;

            // Check for CallOn

            case (SignalScripts.SCRExternalFunctions.TRAINHASCALLON):
                dumpfile = String.Empty;

#if DEBUG_PRINT_ENABLED
                if (thisHead.mainSignal.enabledTrain != null)
                {
                    dumpfile = String.Concat(dpe_fileLoc, "printproc.txt");
                }
#endif

#if DEBUG_PRINT_PROCESS
                if (TDB_debug_ref.Contains(thisHead.TDBIndex))
                {
                    dumpfile = String.Concat(dpr_fileLoc, "printproc.txt");
                }
#endif
                temp_value   = thisHead.mainSignal.TrainHasCallOn(true, dumpfile);
                return_value = Convert.ToInt32(temp_value);
                break;

            // Check for CallOn

            case (SignalScripts.SCRExternalFunctions.TRAINHASCALLON_RESTRICTED):
                dumpfile = String.Empty;

#if DEBUG_PRINT_ENABLED
                if (thisHead.mainSignal.enabledTrain != null)
                {
                    dumpfile = String.Concat(dpe_fileLoc, "printproc.txt");
                }
#endif

#if DEBUG_PRINT_PROCESS
                if (TDB_debug_ref.Contains(thisHead.TDBIndex))
                {
                    dumpfile = String.Concat(dpr_fileLoc, "printproc.txt");
                }
#endif
                temp_value   = thisHead.mainSignal.TrainHasCallOn(false, dumpfile);
                return_value = Convert.ToInt32(temp_value);
                break;

            case (SignalScripts.SCRExternalFunctions.HASHEAD):
                return_value = thisHead.mainSignal.HasHead(parameter1_value);
#if DEBUG_PRINT_ENABLED
                if (thisHead.mainSignal.enabledTrain != null)
                {
                    File.AppendAllText(dpe_fileLoc + @"printproc.txt",
                                       " HASHEAD : required head : " + parameter1_value + " ; state :  " + return_value + "\n");
                }
#endif
#if DEBUG_PRINT_PROCESS
                if (TDB_debug_ref.Contains(thisHead.TDBIndex))
                {
                    File.AppendAllText(dpr_fileLoc + @"printproc.txt",
                                       " HASHEAD : required head : " + parameter1_value + " ; state :  " + return_value + "\n");
                }
#endif
                break;

            // def_draw_state

            case (SignalScripts.SCRExternalFunctions.DEF_DRAW_STATE):
                return_value = thisHead.def_draw_state((MstsSignalAspect)parameter1_value);
                break;

            // DEBUG routine : to be implemented later

            default:
                break;
            }

#if DEBUG_PRINT_ENABLED
            if (thisHead.mainSignal.enabledTrain != null)
            {
                File.AppendAllText(dpe_fileLoc + @"printproc.txt",
                                   "Function Result : " + thisFunction.ToString() + "(" + parameter1_value.ToString() + ") = " +
                                   return_value.ToString() + "\n");
            }
#endif
#if DEBUG_PRINT_PROCESS
            if (TDB_debug_ref.Contains(thisHead.TDBIndex))
            {
                File.AppendAllText(dpr_fileLoc + @"printproc.txt",
                                   "Function Result : " + thisFunction.ToString() + "(" + parameter1_value.ToString() + ") = " +
                                   return_value.ToString() + "\n");
            }
#endif

            // check sign

            if (thisTerm.TermOperator == SignalScripts.SCRTermOperator.MINUS)
            {
                return_value = -(return_value);
            }

            return(return_value);
        }
Beispiel #16
0
        //================================================================================================//
        //
        // get parameter term value
        //
        //================================================================================================//

        public static int SH_termvalue(SignalHead thisHead, SignalScripts.SCRScripts.SCRParameterType thisParameter,
                                       int[] localFloats, SIGSCRfile sigscr)
        {
            int return_value = 0;

            // for non-function terms only first entry is valid

            switch (thisParameter.PartType)
            {
            // assign value to external float
            // Possible floats :
            //                        STATE
            //                        DRAW_STATE
            //                        ENABLED
            //                        BLOCK_STATE

            case (SignalScripts.SCRTermType.ExternalFloat):
                SignalScripts.SCRExternalFloats FloatType = (SignalScripts.SCRExternalFloats)thisParameter.PartParameter;

                switch (FloatType)
                {
                case SignalScripts.SCRExternalFloats.STATE:
                    return_value = (int)thisHead.state;
                    break;

                case SignalScripts.SCRExternalFloats.DRAW_STATE:
                    return_value = thisHead.draw_state;
                    break;

                case SignalScripts.SCRExternalFloats.ENABLED:
                    return_value = Convert.ToInt32(thisHead.mainSignal.enabled);
                    break;

                case SignalScripts.SCRExternalFloats.BLOCK_STATE:
                    return_value = (int)thisHead.mainSignal.block_state();
                    break;

                case SignalScripts.SCRExternalFloats.APPROACH_CONTROL_REQ_POSITION:
                    return_value = thisHead.ApproachControlLimitPositionM.HasValue ? Convert.ToInt32(thisHead.ApproachControlLimitPositionM.Value) : -1;
                    break;

                case SignalScripts.SCRExternalFloats.APPROACH_CONTROL_REQ_SPEED:
                    return_value = thisHead.ApproachControlLimitSpeedMpS.HasValue ? Convert.ToInt32(thisHead.ApproachControlLimitSpeedMpS.Value) : -1;
                    break;

                default:
                    break;
                }
                break;

            // Local float

            case (SignalScripts.SCRTermType.LocalFloat):
                return_value = localFloats[thisParameter.PartParameter];
                break;

            // all others : constants

            default:
                return_value = thisParameter.PartParameter;
                break;
            }

            return(return_value);
        }
Beispiel #17
0
        //================================================================================================//
        //
        // process subterm
        //
        //================================================================================================//

        public int SH_processSubTerm(SignalHead thisHead, List <SignalScripts.SCRScripts.SCRStatTerm> StatementTerms,
                                     int sublevel, int[] localFloats, SIGSCRfile sigscr)
        {
            int tempvalue = 0;
            int termvalue = 0;

            foreach (SignalScripts.SCRScripts.SCRStatTerm thisTerm in StatementTerms)
            {
                if (thisTerm.Function == SignalScripts.SCRExternalFunctions.RETURN)
                {
                    break;
                }

                SignalScripts.SCRTermOperator thisOperator = thisTerm.TermOperator;
                if (thisTerm.issublevel == sublevel)
                {
                    termvalue =
                        SH_processAssignTerm(thisHead, StatementTerms, thisTerm, sublevel, localFloats, sigscr);
                    if (thisTerm.negate)
                    {
                        termvalue = termvalue == 0 ? 1 : 0;
                    }

                    switch (thisOperator)
                    {
                    case (SignalScripts.SCRTermOperator.MULTIPLY):
                        tempvalue *= termvalue;
                        break;

                    case (SignalScripts.SCRTermOperator.PLUS):
                        tempvalue += termvalue;
                        break;

                    case (SignalScripts.SCRTermOperator.MINUS):
                        tempvalue -= termvalue;
                        break;

                    case (SignalScripts.SCRTermOperator.DIVIDE):
                        if (termvalue == 0)
                        {
                            tempvalue = 0;
                        }
                        else
                        {
                            tempvalue /= termvalue;
                        }
                        break;

                    case (SignalScripts.SCRTermOperator.MODULO):
                        tempvalue %= termvalue;
                        break;

                    default:
                        tempvalue = termvalue;
                        break;
                    }
                }
            }

            return(tempvalue);
        }
Beispiel #18
0
        //================================================================================================//
        // get parameter term value
        //================================================================================================//
        private static int TermValue(SignalHead head, SignalScripts.SCRScripts.SCRParameterType parameter, int[] localFloats)
        {
            int result = 0;

            // for non-function terms only first entry is valid
            switch (parameter.PartType)
            {
            // assign value to external float
            // Possible floats :
            //                        STATE
            //                        DRAW_STATE
            //                        ENABLED
            //                        BLOCK_STATE

            case (SignalScripts.SCRTermType.ExternalFloat):
                SignalScripts.SCRExternalFloats floatType = (SignalScripts.SCRExternalFloats)parameter.PartParameter;

                switch (floatType)
                {
                case SignalScripts.SCRExternalFloats.STATE:
                    result = (int)head.SignalIndicationState;
                    break;

                case SignalScripts.SCRExternalFloats.DRAW_STATE:
                    result = head.DrawState;
                    break;

                case SignalScripts.SCRExternalFloats.ENABLED:
                    result = Convert.ToInt32(head.MainSignal.Enabled);
                    break;

                case SignalScripts.SCRExternalFloats.BLOCK_STATE:
                    result = (int)head.MainSignal.BlockState();
                    break;

                case SignalScripts.SCRExternalFloats.APPROACH_CONTROL_REQ_POSITION:
                    result = head.ApproachControlLimitPositionM.HasValue ? Convert.ToInt32(head.ApproachControlLimitPositionM.Value) : -1;
                    break;

                case SignalScripts.SCRExternalFloats.APPROACH_CONTROL_REQ_SPEED:
                    result = head.ApproachControlLimitSpeedMpS.HasValue ? Convert.ToInt32(head.ApproachControlLimitSpeedMpS.Value) : -1;
                    break;

                default:
                    break;
                }
                break;

            // Local float
            case (SignalScripts.SCRTermType.LocalFloat):
                result = localFloats[parameter.PartParameter];
                break;

            // all others : constants
            default:
                result = parameter.PartParameter;
                break;
            }

            return(result);
        }
Beispiel #19
0
        //================================================================================================//
        //
        // process statement block
        // called for full script as well as for IF and ELSE blocks
        // if returns false : abort further processing
        //
        //================================================================================================//

        public bool SH_process_StatementBlock(SignalHead thisHead, ArrayList Statements,
                                              int[] localFloats, SIGSCRfile sigscr)
        {
            // loop through all lines

            foreach (object scriptstat in Statements)
            {
                // process statement lines

                if (scriptstat is SignalScripts.SCRScripts.SCRStatement)
                {
                    SignalScripts.SCRScripts.SCRStatement ThisStat = (SignalScripts.SCRScripts.SCRStatement)scriptstat;

                    if (ThisStat.StatementTerms[0].Function == SignalScripts.SCRExternalFunctions.RETURN)
                    {
                        return(false);
                    }

                    SH_processAssignStatement(thisHead, ThisStat, localFloats, sigscr);

#if DEBUG_PRINT_ENABLED
                    if (thisHead.mainSignal.enabledTrain != null)
                    {
                        File.AppendAllText(dpe_fileLoc + @"printproc.txt", "Statement : \n");
                        foreach (string statstring in ThisStat.StatementParts)
                        {
                            File.AppendAllText(dpe_fileLoc + @"printproc.txt", "   " + statstring + "\n");
                        }
                        foreach (int lfloat in localFloats)
                        {
                            File.AppendAllText(dpe_fileLoc + @"printproc.txt", " local : " + lfloat.ToString() + "\n");
                        }
                        File.AppendAllText(dpe_fileLoc + @"printproc.txt", "Externals : \n");
                        File.AppendAllText(dpe_fileLoc + @"printproc.txt", " state      : " + thisHead.state.ToString() + "\n");
                        File.AppendAllText(dpe_fileLoc + @"printproc.txt", " draw_state : " + thisHead.draw_state.ToString() + "\n");
                        File.AppendAllText(dpe_fileLoc + @"printproc.txt", " enabled    : " + thisHead.mainSignal.enabled.ToString() + "\n");
                        File.AppendAllText(dpe_fileLoc + @"printproc.txt", " blockstate : " + thisHead.mainSignal.blockState.ToString() + "\n");
                        File.AppendAllText(dpe_fileLoc + @"printproc.txt", "\n");
                    }
#endif

#if DEBUG_PRINT_PROCESS
                    if (TDB_debug_ref.Contains(thisHead.TDBIndex))
                    {
                        File.AppendAllText(dpr_fileLoc + @"printproc.txt", "Statement : \n");
                        foreach (string statstring in ThisStat.StatementParts)
                        {
                            File.AppendAllText(dpr_fileLoc + @"printproc.txt", "   " + statstring + "\n");
                        }
                        foreach (int lfloat in localFloats)
                        {
                            File.AppendAllText(dpr_fileLoc + @"printproc.txt", " local : " + lfloat.ToString() + "\n");
                        }
                        File.AppendAllText(dpr_fileLoc + @"printproc.txt", "Externals : \n");
                        File.AppendAllText(dpr_fileLoc + @"printproc.txt", " state      : " + thisHead.state.ToString() + "\n");
                        File.AppendAllText(dpr_fileLoc + @"printproc.txt", " draw_state : " + thisHead.draw_state.ToString() + "\n");
                        File.AppendAllText(dpr_fileLoc + @"printproc.txt", " enabled    : " + thisHead.mainSignal.enabled.ToString() + "\n");
                        File.AppendAllText(dpr_fileLoc + @"printproc.txt", " blockstate : " + thisHead.mainSignal.blockState.ToString() + "\n");
                        File.AppendAllText(dpr_fileLoc + @"printproc.txt", "\n");
                    }
#endif
                }

                if (scriptstat is SignalScripts.SCRScripts.SCRConditionBlock)
                {
                    SignalScripts.SCRScripts.SCRConditionBlock thisCond = (SignalScripts.SCRScripts.SCRConditionBlock)scriptstat;
                    if (!SH_processIfCondition(thisHead, thisCond, localFloats, sigscr))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Beispiel #20
0
        //================================================================================================//
        // return function value
        // Possible functions : see enum SCRExternalFunctions
        //================================================================================================//
        private static int FunctionValue(SignalHead head, SignalScripts.SCRScripts.SCRStatTerm term, int[] localFloats)
        {
            int result     = 0;
            int parameter1 = 0;
            int parameter2 = 0;

            // extract parameters (max. 2)

            if (term.PartParameter != null)
            {
                if (term.PartParameter.Length >= 1)
                {
                    SignalScripts.SCRScripts.SCRParameterType parameter = term.PartParameter[0];
                    parameter1 = TermValue(head, parameter, localFloats);
                }

                if (term.PartParameter.Length >= 2)
                {
                    SignalScripts.SCRScripts.SCRParameterType parameter = term.PartParameter[1];
                    parameter2 = TermValue(head, parameter, localFloats);
                }
            }

            // switch on function
            switch (term.Function)
            {
            // BlockState
            case SignalScripts.SCRExternalFunctions.BLOCK_STATE:
                result = (int)head.MainSignal.BlockState();
                break;

            // Route set
            case SignalScripts.SCRExternalFunctions.ROUTE_SET:
                result = head.VerifyRouteSet();
                break;

            // next_sig_lr
            case SignalScripts.SCRExternalFunctions.NEXT_SIG_LR:
                result = (int)head.NextSignalLR(parameter1);
                break;

            // next_sig_mr
            case SignalScripts.SCRExternalFunctions.NEXT_SIG_MR:
                result = (int)head.NextSignalMR(parameter1);
                break;

            // this_sig_lr
            case SignalScripts.SCRExternalFunctions.THIS_SIG_LR:
                SignalAspectState returnState_lr = head.ThisSignalLR(parameter1);
                result = returnState_lr != SignalAspectState.Unknown ? (int)returnState_lr : -1;
                break;

            // this_sig_mr
            case SignalScripts.SCRExternalFunctions.THIS_SIG_MR:
                SignalAspectState returnState_mr = head.ThisSignalMR(parameter1);
                result = returnState_mr != SignalAspectState.Unknown ? (int)returnState_mr : -1;
                break;

            // opp_sig_lr
            case SignalScripts.SCRExternalFunctions.OPP_SIG_LR:
                result = (int)head.OppositeSignalLR(parameter1);
                break;

            // opp_sig_mr
            case SignalScripts.SCRExternalFunctions.OPP_SIG_MR:
                result = (int)head.OppositeSignalMR(parameter1);
                break;

            // next_nsig_lr
            case SignalScripts.SCRExternalFunctions.NEXT_NSIG_LR:
                result = (int)head.NextNthSignalLR(parameter1, parameter2);
                break;

            // dist_multi_sig_mr
            case SignalScripts.SCRExternalFunctions.DIST_MULTI_SIG_MR:
                result = (int)head.MRSignalMultiOnRoute(parameter1, parameter2);
                break;

            // dist_multi_sig_mr_of_lr
            case SignalScripts.SCRExternalFunctions.DIST_MULTI_SIG_MR_OF_LR:
                result = (int)head.LRSignalMultiOnRoute(parameter1, parameter2);
                break;

            // next_sig_id
            case SignalScripts.SCRExternalFunctions.NEXT_SIG_ID:
                result = head.NextSignalId(parameter1);
                break;

            // next_nsig_id
            case SignalScripts.SCRExternalFunctions.NEXT_NSIG_ID:
                result = head.NextNthSignalId(parameter1, parameter2);
                break;

            // opp_sig_id
            case SignalScripts.SCRExternalFunctions.OPP_SIG_ID:
                result = head.OppositeSignalId(parameter1);
                break;

            // id_sig_enabled
            case SignalScripts.SCRExternalFunctions.ID_SIG_ENABLED:
                result = head.SignalEnabledById(parameter1);
                break;

            // id_sig_lr
            case SignalScripts.SCRExternalFunctions.ID_SIG_LR:
                result = (int)head.SignalLRById(parameter1, parameter2);
                break;

            // sig_feature
            case SignalScripts.SCRExternalFunctions.SIG_FEATURE:
                result = Convert.ToInt32(head.VerifySignalFeature(parameter1));
                break;

            // allow to clear to partial route
            case SignalScripts.SCRExternalFunctions.ALLOW_CLEAR_TO_PARTIAL_ROUTE:
                head.MainSignal.AllowClearPartialRoute(parameter1);
                break;

            // approach control position
            case SignalScripts.SCRExternalFunctions.APPROACH_CONTROL_POSITION:
                result = Convert.ToInt32(head.MainSignal.ApproachControlPosition(parameter1, false));
                break;

            // approach control position forced
            case SignalScripts.SCRExternalFunctions.APPROACH_CONTROL_POSITION_FORCED:
                result = Convert.ToInt32(head.MainSignal.ApproachControlPosition(parameter1, true));
                break;

            // approach control speed
            case (SignalScripts.SCRExternalFunctions.APPROACH_CONTROL_SPEED):
                result = Convert.ToInt32(head.MainSignal.ApproachControlSpeed(parameter1, parameter2));
                break;

            // approach control next stop
            case SignalScripts.SCRExternalFunctions.APPROACH_CONTROL_NEXT_STOP:
                result = Convert.ToInt32(head.MainSignal.ApproachControlNextStop(parameter1, parameter2));
                break;

            // Lock claim for approach control
            case SignalScripts.SCRExternalFunctions.APPROACH_CONTROL_LOCK_CLAIM:
                head.MainSignal.LockClaim();
                break;

            // Activate timing trigger
            case (SignalScripts.SCRExternalFunctions.ACTIVATE_TIMING_TRIGGER):
                head.MainSignal.ActivateTimingTrigger();
                break;

            // Check timing trigger
            case SignalScripts.SCRExternalFunctions.CHECK_TIMING_TRIGGER:
                result = Convert.ToInt32(head.MainSignal.CheckTimingTrigger(parameter1));
                break;

            // Check for CallOn
            case SignalScripts.SCRExternalFunctions.TRAINHASCALLON:
                head.MainSignal.CallOnEnabled = true;
                result = Convert.ToInt32(head.MainSignal.TrainHasCallOn(true, false));
                break;

            // Check for CallOn Restricted
            case SignalScripts.SCRExternalFunctions.TRAINHASCALLON_RESTRICTED:
                head.MainSignal.CallOnEnabled = true;
                result = Convert.ToInt32(head.MainSignal.TrainHasCallOn(false, false));
                break;

            // Check for CallOn
            case SignalScripts.SCRExternalFunctions.TRAINHASCALLON_ADVANCED:
                head.MainSignal.CallOnEnabled = true;
                result = Convert.ToInt32(head.MainSignal.TrainHasCallOn(true, true));
                break;

            // Check for CallOn Restricted
            case SignalScripts.SCRExternalFunctions.TRAINHASCALLON_RESTRICTED_ADVANCED:
                head.MainSignal.CallOnEnabled = true;
                result = Convert.ToInt32(head.MainSignal.TrainHasCallOn(false, true));
                break;

            // check if train needs next signal
            case SignalScripts.SCRExternalFunctions.TRAIN_REQUIRES_NEXT_SIGNAL:
                result = Convert.ToInt32(head.MainSignal.RequiresNextSignal(parameter1, parameter2));
                break;

            case SignalScripts.SCRExternalFunctions.FIND_REQ_NORMAL_SIGNAL:
                result = head.MainSignal.FindRequiredNormalSignal(parameter1);
                break;

            // check if route upto required signal is fully cleared
            case SignalScripts.SCRExternalFunctions.ROUTE_CLEARED_TO_SIGNAL:
                result = (int)head.MainSignal.RouteClearedToSignal(parameter1, false);
                break;

            // check if route upto required signal is fully cleared, but allow callon
            case SignalScripts.SCRExternalFunctions.ROUTE_CLEARED_TO_SIGNAL_CALLON:
                result = (int)head.MainSignal.RouteClearedToSignal(parameter1, true);
                break;

            // check if specified head enabled
            case SignalScripts.SCRExternalFunctions.HASHEAD:
                result = head.MainSignal.HasHead(parameter1);
                break;

            // increase active value of SignalNumClearAhead
            case SignalScripts.SCRExternalFunctions.INCREASE_SIGNALNUMCLEARAHEAD:
                head.MainSignal.IncreaseSignalNumClearAhead(parameter1);
                break;

            // decrease active value of SignalNumClearAhead
            case SignalScripts.SCRExternalFunctions.DECREASE_SIGNALNUMCLEARAHEAD:
                head.MainSignal.DecreaseSignalNumClearAhead(parameter1);
                break;

            // set active value of SignalNumClearAhead
            case SignalScripts.SCRExternalFunctions.SET_SIGNALNUMCLEARAHEAD:
                head.MainSignal.SetSignalNumClearAhead(parameter1);
                break;

            // reset active value of SignalNumClearAhead to default
            case SignalScripts.SCRExternalFunctions.RESET_SIGNALNUMCLEARAHEAD:
                head.MainSignal.ResetSignalNumClearAhead();
                break;

            // store_lvar
            case SignalScripts.SCRExternalFunctions.STORE_LVAR:
                head.StoreLocalVariable(parameter1, parameter2);
                break;

            // this_sig_lvar
            case SignalScripts.SCRExternalFunctions.THIS_SIG_LVAR:
                result = head.ThisSignalLocalVariable(parameter1);
                break;

            // next_sig_lvar
            case SignalScripts.SCRExternalFunctions.NEXT_SIG_LVAR:
                result = head.NextSignalLocalVariable(parameter1, parameter2);
                break;

            // id_sig_lvar
            case SignalScripts.SCRExternalFunctions.ID_SIG_LVAR:
                result = head.LocalVariableBySignalId(parameter1, parameter2);
                break;

            // this_sig_noupdate
            case SignalScripts.SCRExternalFunctions.THIS_SIG_NOUPDATE:
                head.MainSignal.Static = true;
                break;

            // this_sig_hasnormalsubtype
            case SignalScripts.SCRExternalFunctions.THIS_SIG_HASNORMALSUBTYPE:
                result = head.SignalHasNormalSubtype(parameter1);
                break;

            // next_sig_hasnormalsubtype
            case SignalScripts.SCRExternalFunctions.NEXT_SIG_HASNORMALSUBTYPE:
                result = head.NextSignalHasNormalSubtype(parameter1);
                break;

            // next_sig_hasnormalsubtype
            case SignalScripts.SCRExternalFunctions.ID_SIG_HASNORMALSUBTYPE:
                result = head.SignalHasNormalSubtypeById(parameter1, parameter2);
                break;

            // switchstand
            case SignalScripts.SCRExternalFunctions.SWITCHSTAND:
                result = head.Switchstand(parameter1, parameter2);
                break;

            // def_draw_state
            case SignalScripts.SCRExternalFunctions.DEF_DRAW_STATE:
                result = head.DefaultDrawState((SignalAspectState)parameter1);
                break;

            // DEBUG routine : to be implemented later
            default:
                break;
            }
            // check sign
            if (term.TermOperator == SignalScripts.SCRTermOperator.MINUS)
            {
                result = -result;
            }

            return(result);
        }
Beispiel #21
0
        //================================================================================================//
        // process condition statement
        //================================================================================================//
        private static bool ProcessConditionStatement(SignalHead head, ArrayList conditionals, int[] localFloats)
        {
            // loop through all conditions
            bool result = true;
            bool negate = false;

            SignalScripts.SCRAndOr condstring = SignalScripts.SCRAndOr.NONE;

            foreach (object condition in conditionals)
            {
                bool newcondition;
                // single condition : process

                if (condition is SignalScripts.SCRNegate)
                {
                    negate = true;
                }

                else if (condition is SignalScripts.SCRScripts.SCRConditions singleCondition)
                {
                    newcondition = ProcessSingleCondition(head, singleCondition, localFloats);

                    if (negate)
                    {
                        negate       = false;
                        newcondition = !newcondition;
                    }

                    switch (condstring)
                    {
                    case (SignalScripts.SCRAndOr.AND):
                        result &= newcondition;
                        break;

                    case (SignalScripts.SCRAndOr.OR):
                        result |= newcondition;
                        break;

                    default:
                        result = newcondition;
                        break;
                    }
                }
                // AND or OR indication (to link previous and next part)
                else if (condition is SignalScripts.SCRAndOr or)
                {
                    condstring = or;
                }
                // subcondition
                else
                {
                    ArrayList subCond = (ArrayList)condition;
                    newcondition = ProcessConditionStatement(head, subCond, localFloats);

                    if (negate)
                    {
                        negate       = false;
                        newcondition = !newcondition;
                    }

                    switch (condstring)
                    {
                    case (SignalScripts.SCRAndOr.AND):
                        result &= newcondition;
                        break;

                    case (SignalScripts.SCRAndOr.OR):
                        result |= newcondition;
                        break;

                    default:
                        result = newcondition;
                        break;
                    }
                }
            }

            return(result);
        }
Beispiel #22
0
        //================================================================================================//
        // process single condition
        //================================================================================================//
        private static bool ProcessSingleCondition(SignalHead head, SignalScripts.SCRScripts.SCRConditions condition, int[] localFloats)
        {
            int  term1value = 0;
            int  term2value = 0;
            bool result     = true;

            // get value of first term
            if (condition.Term1.Function != SignalScripts.SCRExternalFunctions.NONE)
            {
                term1value = FunctionValue(head, condition.Term1, localFloats);
            }
            else if (condition.Term1.PartParameter != null)
            {
                SignalScripts.SCRScripts.SCRParameterType parameter = condition.Term1.PartParameter[0];

                term1value = TermValue(head, parameter, localFloats);
                if (condition.Term1.TermOperator == SignalScripts.SCRTermOperator.MINUS)
                {
                    term1value = -term1value;
                }
            }

            // get value of second term
            if (condition.Term2 == null) // if only one value : check for NOT
            {
                if (condition.Term1.Negated)
                {
                    result = !(Convert.ToBoolean(term1value));
                }
                else
                {
                    result = Convert.ToBoolean(term1value);
                }
            }
            // process second term
            else
            {
                if (condition.Term2.Function != SignalScripts.SCRExternalFunctions.NONE)
                {
                    term2value = FunctionValue(head, condition.Term2, localFloats);
                }
                else if (condition.Term2.PartParameter != null)
                {
                    SignalScripts.SCRScripts.SCRParameterType parameter = condition.Term2.PartParameter[0];
                    term2value = TermValue(head, parameter, localFloats);
                    if (condition.Term2.TermOperator == SignalScripts.SCRTermOperator.MINUS)
                    {
                        term2value = -term2value;
                    }
                }

                // check on required condition
                switch (condition.Condition)
                {
                // GT
                case SignalScripts.SCRTermCondition.GT:
                    result = term1value > term2value;
                    break;

                // GE
                case SignalScripts.SCRTermCondition.GE:
                    result = term1value >= term2value;
                    break;

                // LT
                case SignalScripts.SCRTermCondition.LT:
                    result = term1value < term2value;
                    break;

                // LE
                case SignalScripts.SCRTermCondition.LE:
                    result = term1value <= term2value;
                    break;

                // EQ
                case SignalScripts.SCRTermCondition.EQ:
                    result = term1value == term2value;
                    break;

                // NE
                case SignalScripts.SCRTermCondition.NE:
                    result = term1value != term2value;
                    break;
                }
            }
            return(result);
        }
Beispiel #23
0
        //================================================================================================//
        //
        // process condition statement
        //
        //================================================================================================//

        public bool SH_processConditionStatement(SignalHead thisHead, ArrayList thisCStatList,
                                                 int[] localFloats, SIGSCRfile sigscr)
        {
            // loop through all conditions

            bool condition    = true;
            bool newcondition = true;
            bool termnegate   = false;

            SignalScripts.SCRAndOr condstring = SignalScripts.SCRAndOr.NONE;

            foreach (object thisCond in thisCStatList)
            {
                // single condition : process

                if (thisCond is SignalScripts.SCRNegate)
                {
                    termnegate = true;
                }

                else if (thisCond is SignalScripts.SCRScripts.SCRConditions)
                {
                    SignalScripts.SCRScripts.SCRConditions thisSingleCond = (SignalScripts.SCRScripts.SCRConditions)thisCond;
                    newcondition = SH_processSingleCondition(thisHead, thisSingleCond, localFloats, sigscr);

                    if (termnegate)
                    {
                        termnegate   = false;
                        newcondition = newcondition ? false : true;
                    }

                    switch (condstring)
                    {
                    case (SignalScripts.SCRAndOr.AND):
                        condition &= newcondition;
                        break;

                    case (SignalScripts.SCRAndOr.OR):
                        condition |= newcondition;
                        break;

                    default:
                        condition = newcondition;
                        break;
                    }
                }

                // AND or OR indication (to link previous and next part)

                else if (thisCond is SignalScripts.SCRAndOr)
                {
                    condstring = (SignalScripts.SCRAndOr)thisCond;
                }

                // subcondition

                else
                {
                    ArrayList subCond = (ArrayList)thisCond;
                    newcondition = SH_processConditionStatement(thisHead, subCond, localFloats, sigscr);

                    if (termnegate)
                    {
                        termnegate   = false;
                        newcondition = newcondition ? false : true;
                    }

                    switch (condstring)
                    {
                    case (SignalScripts.SCRAndOr.AND):
                        condition &= newcondition;
                        break;

                    case (SignalScripts.SCRAndOr.OR):
                        condition |= newcondition;
                        break;

                    default:
                        condition = newcondition;
                        break;
                    }
                }
            }

            return(condition);
        }
Beispiel #24
0
        //================================================================================================//
        //
        // process single condition
        //
        //================================================================================================//

        public bool SH_processSingleCondition(SignalHead thisHead, SignalScripts.SCRScripts.SCRConditions thisCond,
                                              int[] localFloats, SIGSCRfile sigscr)
        {
            int  term1value = 0;
            int  term2value = 0;
            bool condition  = true;

            // get value of first term


#if DEBUG_PRINT_ENABLED
            if (thisHead.mainSignal.enabledTrain != null)
            {
                File.AppendAllText(dpe_fileLoc + @"printproc.txt", "IF Condition statement (1) : \n");
            }
#endif
#if DEBUG_PRINT_PROCESS
            if (TDB_debug_ref.Contains(thisHead.TDBIndex))
            {
                File.AppendAllText(dpr_fileLoc + @"printproc.txt", "IF Condition statement (1) : \n");
            }
#endif

            if (thisCond.Term1.Function != SignalScripts.SCRExternalFunctions.NONE)
            {
                term1value = SH_function_value(thisHead, thisCond.Term1, localFloats, sigscr);
            }
            else if (thisCond.Term1.PartParameter != null)
            {
                SignalScripts.SCRScripts.SCRParameterType thisParameter = thisCond.Term1.PartParameter[0];

#if DEBUG_PRINT_ENABLED
                if (thisHead.mainSignal.enabledTrain != null)
                {
                    File.AppendAllText(dpe_fileLoc + @"printproc.txt", "Parameter : " + thisParameter.PartType.ToString() + " : " +
                                       thisParameter.PartParameter.ToString() + "\n");
                }
#endif
#if DEBUG_PRINT_PROCESS
                if (TDB_debug_ref.Contains(thisHead.TDBIndex))
                {
                    File.AppendAllText(dpr_fileLoc + @"printproc.txt", "Parameter : " + thisParameter.PartType.ToString() + " : " +
                                       thisParameter.PartParameter.ToString() + "\n");
                }
#endif

                SignalScripts.SCRTermOperator thisOperator = thisCond.Term1.TermOperator;
                term1value = SH_termvalue(thisHead, thisParameter,
                                          localFloats, sigscr);
                if (thisOperator == SignalScripts.SCRTermOperator.MINUS)
                {
                    term1value = -term1value;
                }
            }

            // get value of second term

            if (thisCond.Term2 == null)

            // if only one value : check for NOT
            {
                if (thisCond.negate1)
                {
                    condition = !(Convert.ToBoolean(term1value));
                }
                else
                {
                    condition = Convert.ToBoolean(term1value);
                }

#if DEBUG_PRINT_ENABLED
                if (thisHead.mainSignal.enabledTrain != null)
                {
                    File.AppendAllText(dpe_fileLoc + @"printproc.txt", "Result of single condition : " +
                                       " : " + condition.ToString() + " (NOT : " + thisCond.negate1.ToString() + ")\n\n");
                }
#endif
#if DEBUG_PRINT_PROCESS
                if (TDB_debug_ref.Contains(thisHead.TDBIndex))
                {
                    File.AppendAllText(dpr_fileLoc + @"printproc.txt", "Result of single condition : " +
                                       " : " + condition.ToString() + " (NOT : " + thisCond.negate1.ToString() + ")\n\n");
                }
#endif
            }

            // process second term

            else
            {
#if DEBUG_PRINT_ENABLED
                if (thisHead.mainSignal.enabledTrain != null)
                {
                    File.AppendAllText(dpe_fileLoc + @"printproc.txt", "IF Condition statement (2) : \n");
                }
#endif
#if DEBUG_PRINT_PROCESS
                if (TDB_debug_ref.Contains(thisHead.TDBIndex))
                {
                    File.AppendAllText(dpr_fileLoc + @"printproc.txt", "IF Condition statement (2) : \n");
                }
#endif

                if (thisCond.Term2.Function != SignalScripts.SCRExternalFunctions.NONE)
                {
                    term2value = SH_function_value(thisHead, thisCond.Term2, localFloats, sigscr);
                }
                else if (thisCond.Term2.PartParameter != null)
                {
                    SignalScripts.SCRScripts.SCRParameterType thisParameter = thisCond.Term2.PartParameter[0];

#if DEBUG_PRINT_ENABLED
                    if (thisHead.mainSignal.enabledTrain != null)
                    {
                        File.AppendAllText(dpe_fileLoc + @"printproc.txt",
                                           "Parameter : " + thisParameter.PartType.ToString() + " : " +
                                           thisParameter.PartParameter.ToString() + "\n");
                    }
#endif
#if DEBUG_PRINT_PROCESS
                    if (TDB_debug_ref.Contains(thisHead.TDBIndex))
                    {
                        File.AppendAllText(dpr_fileLoc + @"printproc.txt",
                                           "Parameter : " + thisParameter.PartType.ToString() + " : " +
                                           thisParameter.PartParameter.ToString() + "\n");
                    }
#endif

                    SignalScripts.SCRTermOperator thisOperator = thisCond.Term2.TermOperator;
                    term2value = SH_termvalue(thisHead, thisParameter,
                                              localFloats, sigscr);
                    if (thisOperator == SignalScripts.SCRTermOperator.MINUS)
                    {
                        term2value = -term2value;
                    }
                }

                // check on required condition

                switch (thisCond.Condition)
                {
                // GT

                case (SignalScripts.SCRTermCondition.GT):
                    condition = (term1value > term2value);
                    break;

                // GE

                case (SignalScripts.SCRTermCondition.GE):
                    condition = (term1value >= term2value);
                    break;

                // LT

                case (SignalScripts.SCRTermCondition.LT):
                    condition = (term1value < term2value);
                    break;

                // LE

                case (SignalScripts.SCRTermCondition.LE):
                    condition = (term1value <= term2value);
                    break;

                // EQ

                case (SignalScripts.SCRTermCondition.EQ):
                    condition = (term1value == term2value);
                    break;

                // NE

                case (SignalScripts.SCRTermCondition.NE):
                    condition = (term1value != term2value);
                    break;
                }

#if DEBUG_PRINT_ENABLED
                if (thisHead.mainSignal.enabledTrain != null)
                {
                    File.AppendAllText(dpe_fileLoc + @"printproc.txt", "Result of operation : " +
                                       thisCond.Condition.ToString() + " : " + condition.ToString() + "\n\n");
                }
#endif
#if DEBUG_PRINT_PROCESS
                if (TDB_debug_ref.Contains(thisHead.TDBIndex))
                {
                    File.AppendAllText(dpr_fileLoc + @"printproc.txt", "Result of operation : " +
                                       thisCond.Condition.ToString() + " : " + condition.ToString() + "\n\n");
                }
#endif
            }


            return(condition);
        }