Пример #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));
                        }
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Function to export current strategy into extern file
        /// </summary>
        /// <param name="Filename">File to write</param>
        /// <param name="PatternFilename">Pattern to use for writting the file</param>
        /// <returns></returns>
        public bool WriteFile(string Filename, string PatternFilename)
        {
            bool Ret = false;
            List<StructuredFileKey> ExportFile = new List<StructuredFileKey>();
            StructuredFile OutputStructuredFile = null;

            // First, we have to create the StrucuredFileKey in order to create a Strucutred File
            // Create items that are not included into Loop
            ExportFile.Add(new StructuredFileKey(-1, 0, "PATTERN_STRATEGY_NAME", _StrategyName));
            ExportFile.Add(new StructuredFileKey(-1, 0, "PATTERN_DEFAULT_SPEED", _DefaultSpeed));

            // Store initial cmd (setpos)
            ExportFile.Add(new StructuredFileKey(-1, 1, "PATTERN_INIT_CMD", Command.GetCmdToString(_InitialCmd.Cmd)));
            ExportFile.Add(new StructuredFileKey(-1, 1, "PATTERN_INIT_CMD_TYPE", Command.GetCmdTypeToString(_InitialCmd.CmdType)));
            ExportFile.Add(new StructuredFileKey(-1, 1, "PATTERN_INIT_POS_X", _InitialCmd.Param2));
            ExportFile.Add(new StructuredFileKey(-1, 1, "PATTERN_INIT_POS_Y", _InitialCmd.Param3));
            ExportFile.Add(new StructuredFileKey(-1, 1, "PATTERN_INIT_POS_ANGLE", _InitialCmd.Param4));
            ExportFile.Add(new StructuredFileKey(-1, 1, "PATTERN_INIT_ACTIVE_SENSORS", Command.GetSensorsFlagToString(_InitialCmd.ActiveSensors)));

            if (_Strategy != null)
            {
                // Create Loops
                foreach (StrategyItem Item in _Strategy)
                {
                    ExportFile.Add(new StructuredFileKey(Item.LoopID, Item.GID, "PATTERN_CMD", Command.GetCmdToString(Item.Cmd.Cmd)));
                    ExportFile.Add(new StructuredFileKey(Item.LoopID, Item.GID, "PATTERN_CMD_TYPE", Command.GetCmdTypeToString(Item.Cmd.CmdType)));
                    ExportFile.Add(new StructuredFileKey(Item.LoopID, Item.GID, "PATTERN_ACTIVE_SENSORS_FLAG", Command.GetSensorsFlagToString(Item.Cmd.ActiveSensors)));
                    ExportFile.Add(new StructuredFileKey(Item.LoopID, Item.GID, "PATTERN_PARAMS", Item.Cmd.ExportParamsIntoString()));
                    ExportFile.Add(new StructuredFileKey(Item.LoopID, Item.GID, "PATTERN_NEXT_ACTION_ID", Item.NextActionID.ToString()));
                    ExportFile.Add(new StructuredFileKey(Item.LoopID, Item.GID, "PATTERN_TIMEOUT_ID", Item.TimeoutID.ToString()));
                }
            }
            OutputStructuredFile = new StructuredFile(ExportFile);
            OutputStructuredFile.WriteFile(Filename, PatternFilename);

            return Ret;
        }