Exemplo n.º 1
0
        /// <summary>
        /// Create a new FullStrategy object from file
        /// Filename : contains path to file to load
        /// PatternFilename : contains path to pattern file to load
        /// </summary>
        public FullStrategy(string Filename, string PatternFilename)
        {
            if ((Filename == null) || (PatternFilename == null))
            {
                throw(new Exception("Invalid Filename/PatternFilename"));
            }

            // Read files
            StructuredFile StrategyFile = new StructuredFile(Filename);

            StrategyFile.Parse(PatternFilename);

            // Store data into private data
            // Store PATTERN_STRATEGY_NAME
            _StrategyName = StrategyFile.GetValue("PATTERN_STRATEGY_NAME", "Undefined");
            _DefaultSpeed = StrategyFile.GetValue("PATTERN_DEFAULT_SPEED", "50");

            // Store initial cmd (setpos)
            EnumCmd          CurrentCmd     = Command.GetCmdFromString(StrategyFile.GetValue("PATTERN_INIT_CMD", "App_SetNewPos"));
            EnumCmdType      CurrentCmdType = Command.GetCmdTypeFromString(StrategyFile.GetValue("PATTERN_INIT_CMD_TYPE", "NonBlocking"));
            String           ParamX         = StrategyFile.GetValue("PATTERN_INIT_POS_X", "0");
            String           ParamY         = StrategyFile.GetValue("PATTERN_INIT_POS_Y", "0");
            String           ParamAngle     = StrategyFile.GetValue("PATTERN_INIT_POS_ANGLE", "0.0");
            EnumStrategyFlag ActiveSensors  = Command.GetSensorsFlagFromString(StrategyFile.GetValue("PATTERN_INIT_ACTIVE_SENSORS", "APP_PARAM_APPFLAG_NONE"));

            _InitialCmd = new Command(CurrentCmd, CurrentCmdType, null, ParamX, ParamY, ParamAngle, ActiveSensors);

            // Read other items (Loops)
            // Try to read all loops
            for (int iLoop = 0; iLoop <= StrategyFile.GetMaxLoopID(); iLoop++)
            {
                for (int iCount = 0; iCount <= StrategyFile.GetMaxGID(iLoop); iCount++)
                {
                    // Read ActionID and NextActionID
                    int ActionID     = StrategyFile.GetActionID(iLoop, iCount);
                    int NextActionID = StrategyFile.GetNextActionID(iLoop, iCount);
                    int TimeoutID    = StrategyFile.GetTimeoutID(iLoop, iCount);

                    // If current action is valid
                    if (ActionID >= 0)
                    {
                        // Read command data from StratgeyFile
                        Command ReadCommand = StrategyFile.GetCommand(iLoop, iCount);

                        // If current command is valid, we store it
                        if (ReadCommand != null)
                        {
                            // If current list is empty, we create it
                            if (_Strategy == null)
                            {
                                _Strategy = new List <StrategyItem>();
                            }

                            // Create new entry
                            _Strategy.Add(new StrategyItem(ReadCommand, ActionID, NextActionID, TimeoutID));
                        }
                    }
                }
            }
        }