예제 #1
0
        public void Main(string argument, UpdateType updateSource)
        {
            wicoControl.ResetUpdates();
            ModulePreMain(argument, updateSource);
            if (tmGridCheckElapsedMs >= 0)
            {
                tmGridCheckElapsedMs += Runtime.TimeSinceLastRun.TotalMilliseconds;
            }
            if (!WicoLocalInit())
            {
                Echo("Init");
            }
            else
            {
                if (wicoControl.IamMain())
                {
                    Echo("MAIN MODULE");
                }
                else
                {
                    Echo("SUB MODULE");
                }
                // only do this on update, not triggers
                if ((updateSource & utUpdates) > 0)
                {
                    //                    Echo("Init and update. Elapsed:" +tmGridCheckElapsedMs.ToString("0.00"));
                    //                    Echo("Local:" + wicoBlockMaster.localBlocksCount.ToString() + " blocks");
                    if (tmGridCheckElapsedMs > tmGridCheckWaitMs || tmGridCheckElapsedMs < 0) // it is time to scan..
                    {
                        //                      Echo("time to check");
                        tmGridCheckElapsedMs = 0;
                        if (wicoBlockMaster.CalcLocalGridChange())
                        {
                            //                            mesurface0.WriteText("GRID check!");
                            //                            Echo("GRID CHANGED!");
                            //                            mesurface0.WriteText("GRID CHANGED!", true);
                            bInitDone                = false;
                            tmGridCheckElapsedMs     = -1;
                            Runtime.UpdateFrequency |= UpdateFrequency.Once; // cause ourselves to run again to continue initialization
                            return;
                        }
                        //                        else Echo("No Grid Change");
                    }
                    //else Echo("Not Timeto check");
                }
                //                else Echo("Init and NOTE update");
            }
//            Echo(updateSource.ToString());
            if ((updateSource & UpdateType.IGC) > 0)
            {
                //                Echo("IGC");
                wicoIGC.ProcessIGCMessages();
                if (wicoControl.IamMain())
                {
                    mesurface1.WriteText("Master Module");
                }
                else
                {
                    mesurface1.WriteText("Sub Module");
                }
            }
            if ((updateSource & (utTriggers)) > 0)
            {
                Echo("Triggers:" + argument);
                MyCommandLine useCommandLine = null;
                if (myCommandLine.TryParse(argument))
                {
                    useCommandLine = myCommandLine;
                }
                bool bProcessed = false;
                if (myCommandLine.ArgumentCount > 1)
                {
                    if (myCommandLine.Argument(0) == "setmode")
                    {
                        int  toMode = 0;
                        bool bOK    = int.TryParse(myCommandLine.Argument(1), out toMode);
                        if (bOK)
                        {
                            wicoControl.SetMode(toMode);
                            bProcessed = true;
                        }
                    }
                }
                if (!bProcessed)
                {
                    foreach (var handler in UpdateTriggerHandlers)
                    {
                        handler(argument, useCommandLine, updateSource);
                    }
                }
            }
            if ((updateSource & (utUpdates)) > 0)
            {
                //                Echo("Update");
                foreach (var handler in UpdateUpdateHandlers)
                {
                    handler(updateSource);
                }
            }

            /*
             * Echo("I Am Main=" + wicoControl.IamMain().ToString());
             * Echo(wicoThrusters.ThrusterCount() + " Thrusters Found");
             *
             * if (wicoGyros.gyroControl == null)
             *  wicoGyros.SetController();
             * Echo(wicoGyros.NumberAllGyros() + " Total Gyros Found");
             * Echo(wicoGyros.NumberUsedGyros() + " Used Gyros");
             *
             * var shipController= wicoBlockMaster.GetMainController();
             * if (shipController != null)
             *  Echo("Controller = " + shipController.CustomName);
             */
            Echo("Mode=" + wicoControl.IMode.ToString() + " State=" + wicoControl.IState.ToString());

            Echo("Reporting:\n" + sMasterReporting);

            ModulePostMain();
            Runtime.UpdateFrequency = wicoControl.GenerateUpdate()
                                      | UpdateFrequency.Update100
            ;
        }
예제 #2
0
        public void Main(string argument, UpdateType updateSource)
        {
            //            _wicoControl.ResetUpdates();
            Echo(moduleList.Trim());
            ModulePreMain(argument, updateSource);
            if (tmGridCheckElapsedMs >= 0)
            {
                tmGridCheckElapsedMs += Runtime.TimeSinceLastRun.TotalMilliseconds;
            }
            if (!WicoLocalInit())
            {
                // we did not complete an init.
                Echo("Init Failed.  Trying again");

                // try again
                Runtime.UpdateFrequency = UpdateFrequency.Once;
            }
            else
            {
                _wicoControl.AnnounceState();
                // only do this on update, not triggers
                if ((updateSource & utUpdates) > 0)
                {
                    //                    Echo("Init and update. Elapsed:" +tmGridCheckElapsedMs.ToString("0.00"));
                    //                    Echo("Local:" + wicoBlockMaster.localBlocksCount.ToString() + " blocks");
                    if (tmGridCheckElapsedMs > tmGridCheckWaitMs || tmGridCheckElapsedMs < 0) // it is time to scan..
                    {
                        //                      Echo("time to check");
                        tmGridCheckElapsedMs = 0;
                        if (wicoBlockMaster.CalcLocalGridChange())
                        {
                            //                            mesurface0.WriteText("GRID check!");
                            //                            Echo("GRID CHANGED!");
                            //                            mesurface0.WriteText("GRID CHANGED!", true);
                            bInitDone                = false;
                            tmGridCheckElapsedMs     = -1;
                            Runtime.UpdateFrequency |= UpdateFrequency.Once; // cause ourselves to run again to continue initialization
                            return;
                        }
                        //                        else Echo("No Grid Change");
                    }
                    //else Echo("Not Timeto check");
                }
                //                else Echo("Init and NOTE update");
            }
            //            Echo(updateSource.ToString());
//            Echo("A:UF=" + _wicoControl.GenerateUpdate());
            if ((updateSource & UpdateType.IGC) > 0)
            {
//                Echo("IGC");
                wicoIGC.ProcessIGCMessages();
            }
//            Echo("B:UF=" + _wicoControl.GenerateUpdate());
            if ((updateSource & (utTriggers)) > 0)
            {
//                Echo("Triggers:"+argument);
                MyCommandLine useCommandLine = null;
                if (myCommandLine.TryParse(argument))
                {
                    useCommandLine = myCommandLine;
                }
                bool bProcessed = false;

//                if(myCommandLine.ArgumentCount>1)
                {
                    if (argument == "save")
//                        if (myCommandLine.Argument(0) == "save")
                    {
                        Save();
                        ErrorLog("After Save storage=");
                        ErrorLog(Storage);
                        bProcessed = true;
                    }
                }
                if (!bProcessed)
                {
                    foreach (var handler in UpdateTriggerHandlers)
                    {
                        handler(argument, useCommandLine, updateSource);
                    }
                }
            }
//            Echo("C:UF=" + _wicoControl.GenerateUpdate());
            if ((updateSource & (utUpdates)) > 0)
            {
                _wicoControl.ResetUpdates();
                Echo("Update");
                foreach (var handler in UpdateUpdateHandlers)
                {
                    handler(updateSource);
                }
            }
//            Echo("D:UF=" + _wicoControl.GenerateUpdate());

//            Echo("Mode=" + _wicoControl.IMode.ToString() + " State=" + _wicoControl.IState.ToString());

            if (sMasterReporting != "")
            {
                Echo("Reporting:\n" + sMasterReporting);
            }
            if (sMasterReporting.Length > 1024 * 2)
            {
                sMasterReporting = "";
            }
//            Echo("Length=" + wicoBlockMaster.LengthInMeters().ToString());

            ModulePostMain();
            wicoElapsedTime.CheckTimers();
            if (bCustomDataNeedsSave)
            {
                bCustomDataNeedsSave = false;
                Me.CustomData        = _CustomDataIni.ToString();
            }

            Runtime.UpdateFrequency = _wicoControl.GenerateUpdate();

//            Echo("UF=" + Runtime.UpdateFrequency.ToString());
        }