Exemple #1
0
        void AddVesselToMasterStatusDisplay(Vessel vessel)
        {
            MasterStatusItem masterStatusItem = new MasterStatusItem();

            masterStatusItem.vesselID       = vessel.id;
            masterStatusItem.vesselName     = vessel.GetName();
            masterStatusItem.allPartsStatus = new List <PartStatus>();
            masterStatus.Add(vessel.id, masterStatusItem);

            var parts = vessel.Parts;

            for (var j = 0; j < parts.Count; j++)
            {
                var partCores = parts[j].gameObject.GetComponents <TestFlightCore>();
                foreach (var core in partCores)
                {
                    if (!core.TestFlightEnabled)
                    {
                        continue;
                    }

                    PartStatus partStatus = new PartStatus();
                    partStatus.lastSeen   = currentUTC;
                    partStatus.flightCore = core;
                    partStatus.partName   = core.Title;
                    partStatus.partID     = vessel.parts[j].flightID;
                    partStatus.partStatus = core.GetPartStatus();
                    // get any failures
                    partStatus.failures   = core.GetActiveFailures();
                    partStatus.flightData = core.GetFlightData();
                    double failureRate = core.GetBaseFailureRate();
                    MomentaryFailureRate momentaryFailureRate = core.GetWorstMomentaryFailureRate();
                    if (momentaryFailureRate.valid && momentaryFailureRate.failureRate > failureRate)
                    {
                        failureRate = momentaryFailureRate.failureRate;
                    }
                    partStatus.momentaryFailureRate = failureRate;
                    partStatus.acknowledged         = false;
                    partStatus.mtbfString           = core.FailureRateToMTBFString(failureRate, TestFlightUtil.MTBFUnits.SECONDS, 999);
                    partStatus.runningTime          = TestFlightUtil.FormatTime(core.GetBurnTime(), TestFlightUtil.TIMEFORMAT.SHORT_IDENTIFIER, false);
                    masterStatus[vessel.id].allPartsStatus.Add(partStatus);
                }
            }
        }
        internal override void Update()
        {
            if (!isReady)
            {
                return;
            }

            if (!tfScenario.SettingsEnabled)
            {
                return;
            }

            if (masterStatus == null)
            {
                masterStatus = new Dictionary <Guid, MasterStatusItem>();
            }

            currentUTC = Planetarium.GetUniversalTime();
            // ensure out vessel list is up to date
            Profiler.BeginSample("CacheVessels");
            CacheVessels();
            Profiler.EndSample();
            if (currentUTC >= lastMasterStatusUpdate + tfScenario.userSettings.masterStatusUpdateFrequency)
            {
                lastMasterStatusUpdate = currentUTC;
                Profiler.BeginSample("VerifyMasterStatus");
                VerifyMasterStatus();
                Profiler.EndSample();
            }
            // process vessels
            Profiler.BeginSample("ProcessVessels");
            knownVesselsEnumerator = knownVessels.GetEnumerator();
            while (knownVesselsEnumerator.MoveNext())
            {
                KeyValuePair <Guid, double> entry = knownVesselsEnumerator.Current;
                Vessel vessel = null;
                Profiler.BeginSample("FindVessel");
                for (int i = 0; i < FlightGlobals.Vessels.Count; i++)
                {
                    if (FlightGlobals.Vessels[i].id == entry.Key)
                    {
                        vessel = FlightGlobals.Vessels[i];
                    }
                }
                Profiler.EndSample();
                if (vessel == null)
                {
                    continue;
                }

                if (vessel.loaded)
                {
                    Profiler.BeginSample("ProcessParts");
                    List <Part> parts = vessel.Parts;
                    for (int j = 0; j < parts.Count; j++)
                    {
                        // Each KSP part can be composed of N virtual parts
                        Profiler.BeginSample("Reset Core List");
                        cores.Clear();
                        Profiler.EndSample();
                        Profiler.BeginSample("Get Cores");
                        for (int k = 0; k < parts[j].Modules.Count; k++)
                        {
                            ITestFlightCore core = parts[j].Modules[k] as ITestFlightCore;
                            if (core != null && core.TestFlightEnabled)
                            {
                                cores.Add(core.Alias);
                            }
                        }
                        Profiler.EndSample();
                        //cores = TestFlightInterface.GetActiveCores(vessel.parts[j]);
                        if (cores == null || cores.Count <= 0)
                        {
                            continue;
                        }
                        Profiler.BeginSample("ProcessCores");
                        for (int k = 0; k < cores.Count; k++)
                        {
                            ITestFlightCore core = TestFlightUtil.GetCore(vessel.parts[j], cores[k]);
                            if (core == null)
                            {
                                continue;
                            }
                            // Poll for flight data and part status
                            if (!(currentUTC >= lastDataPoll + tfScenario.userSettings.masterStatusUpdateFrequency))
                            {
                                continue;
                            }
                            // Update or Add part status in Master Status
                            if (masterStatus.ContainsKey(vessel.id))
                            {
                                Profiler.BeginSample("MasterStatus Existing Vessel");
                                // Vessel is already in the Master Status, so check if part is in there as well
                                int existingPartIndex = -1;
                                Profiler.BeginSample("Find Part");
                                for (int msIndex = 0; msIndex < masterStatus[vessel.id].allPartsStatus.Count; msIndex++)
                                {
                                    if (masterStatus[vessel.id].allPartsStatus[msIndex].partID !=
                                        vessel.parts[j].flightID)
                                    {
                                        continue;
                                    }
                                    existingPartIndex = msIndex;
                                    break;
                                }
                                Profiler.EndSample();
                                if (existingPartIndex > -1)
                                {
                                    Profiler.BeginSample("Existing Part");
                                    //PartStatus partStatus = masterStatus[vessel.id].allPartsStatus[existingPartIndex];
                                    PartStatus partStatus = new PartStatus();
                                    partStatus.lastSeen   = currentUTC;
                                    partStatus.flightCore = core;
                                    partStatus.partName   = core.Title;
                                    partStatus.partID     = vessel.parts[j].flightID;
                                    Profiler.BeginSample("Part - GetPartStatus");
                                    partStatus.partStatus = core.GetPartStatus();
                                    Profiler.EndSample();
                                    // get any failures
                                    Profiler.BeginSample("Part - GetActiveFailures");
                                    partStatus.failures = core.GetActiveFailures();
                                    Profiler.EndSample();
                                    Profiler.BeginSample("Part - GetFlightData");
                                    partStatus.flightData = core.GetFlightData();
                                    Profiler.EndSample();
                                    Profiler.BeginSample("Part - GetBaseFailureRate");
                                    double failureRate = core.GetBaseFailureRate();
                                    Profiler.EndSample();
                                    Profiler.BeginSample("Part - GetWorstMomentaryFailureRate");
                                    MomentaryFailureRate momentaryFailureRate = core.GetWorstMomentaryFailureRate();
                                    if (momentaryFailureRate.valid && momentaryFailureRate.failureRate > failureRate)
                                    {
                                        failureRate = momentaryFailureRate.failureRate;
                                    }
                                    Profiler.EndSample();
                                    partStatus.momentaryFailureRate = failureRate;
                                    partStatus.acknowledged         = false;
                                    Profiler.BeginSample("Part - FailureRateToMTBFString");
                                    core.FailureRateToMTBFString(failureRate, TestFlightUtil.MTBFUnits.SECONDS, false, 999,
                                                                 out partStatus.mtbfString);
                                    //partStatus.mtbfString = core.FailureRateToMTBFString(failureRate, TestFlightUtil.MTBFUnits.SECONDS, 999);
                                    Profiler.EndSample();
                                    masterStatus[vessel.id].allPartsStatus[existingPartIndex] = partStatus;
                                    Profiler.EndSample();
                                }
                                else
                                {
                                    Profiler.BeginSample("New Part");
                                    PartStatus partStatus = new PartStatus();
                                    partStatus.lastSeen   = currentUTC;
                                    partStatus.flightCore = core;
                                    partStatus.partName   = core.Title;
                                    partStatus.partID     = vessel.parts[j].flightID;
                                    partStatus.partStatus = core.GetPartStatus();
                                    // get any failures
                                    partStatus.failures   = core.GetActiveFailures();
                                    partStatus.flightData = core.GetFlightData();
                                    double failureRate = core.GetBaseFailureRate();
                                    MomentaryFailureRate momentaryFailureRate = core.GetWorstMomentaryFailureRate();
                                    if (momentaryFailureRate.valid && momentaryFailureRate.failureRate > failureRate)
                                    {
                                        failureRate = momentaryFailureRate.failureRate;
                                    }
                                    partStatus.momentaryFailureRate = failureRate;
                                    partStatus.acknowledged         = false;
                                    core.FailureRateToMTBFString(failureRate, TestFlightUtil.MTBFUnits.SECONDS, false, 999,
                                                                 out partStatus.mtbfString);
                                    masterStatus[vessel.id].allPartsStatus.Add(partStatus);
                                    Profiler.EndSample();
                                }
                                Profiler.EndSample();
                            }
                            else
                            {
                                Profiler.BeginSample("MasterStatus New Vessel");
                                // Vessel is not in the Master Status so create a new entry for it and add this part
                                PartStatus partStatus = new PartStatus();
                                partStatus.lastSeen   = currentUTC;
                                partStatus.flightCore = core;
                                partStatus.partName   = core.Title;
                                partStatus.partID     = vessel.parts[j].flightID;
                                partStatus.partStatus = core.GetPartStatus();
                                // get any failures
                                partStatus.failures   = core.GetActiveFailures();
                                partStatus.flightData = core.GetFlightData();
                                double failureRate = core.GetBaseFailureRate();
                                MomentaryFailureRate momentaryFailureRate = core.GetWorstMomentaryFailureRate();
                                if (momentaryFailureRate.valid && momentaryFailureRate.failureRate > failureRate)
                                {
                                    failureRate = momentaryFailureRate.failureRate;
                                }
                                partStatus.momentaryFailureRate = failureRate;
                                partStatus.acknowledged         = false;
                                partStatus.mtbfString           = core.FailureRateToMTBFString(failureRate, TestFlightUtil.MTBFUnits.SECONDS, 999);
                                MasterStatusItem masterStatusItem = new MasterStatusItem();
                                masterStatusItem.vesselID       = vessel.id;
                                masterStatusItem.vesselName     = vessel.GetName();
                                masterStatusItem.allPartsStatus = new List <PartStatus>();
                                masterStatusItem.allPartsStatus.Add(partStatus);
                                masterStatus.Add(vessel.id, masterStatusItem);
                                Profiler.EndSample();
                            }
                        }
                        Profiler.EndSample();
                    }
                }
                Profiler.EndSample();
                if (currentUTC >= lastDataPoll + tfScenario.userSettings.minTimeBetweenDataPoll)
                {
                    lastDataPoll = currentUTC;
                }
                if (currentUTC >= lastFailurePoll + tfScenario.userSettings.minTimeBetweenFailurePoll)
                {
                    lastFailurePoll = currentUTC;
                }
            }
            Profiler.EndSample();
        }
Exemple #3
0
        internal override void Update()
        {
            if (!isReady)
                return;

            if (!tfScenario.SettingsEnabled)
                return;

            if (masterStatus == null)
                masterStatus = new Dictionary<Guid, MasterStatusItem>();

            currentUTC = Planetarium.GetUniversalTime();
            // ensure out vessel list is up to date
            Profiler.BeginSample("CacheVessels");
            CacheVessels();
            Profiler.EndSample();
            if (currentUTC >= lastMasterStatusUpdate + tfScenario.userSettings.masterStatusUpdateFrequency)
            {
                lastMasterStatusUpdate = currentUTC;
                Profiler.BeginSample("VerifyMasterStatus");
                VerifyMasterStatus();
                Profiler.EndSample();
            }
            // process vessels
            Profiler.BeginSample("ProcessVessels");
            knownVesselsEnumerator = knownVessels.GetEnumerator();
            while (knownVesselsEnumerator.MoveNext())
            {
                KeyValuePair<Guid, double> entry = knownVesselsEnumerator.Current;
                Vessel vessel = null;
                Profiler.BeginSample("FindVessel");
                for (int i = 0; i < FlightGlobals.Vessels.Count; i++)
                {
                    if (FlightGlobals.Vessels[i].id == entry.Key)
                        vessel = FlightGlobals.Vessels[i];
                }
                Profiler.EndSample();
                if (vessel == null)
                    continue;

                if (vessel.loaded)
                {
                    Profiler.BeginSample("ProcessParts");
                    List<Part> parts = vessel.Parts;
                    for (int j = 0; j < parts.Count; j++)
                    {
                        // Each KSP part can be composed of N virtual parts
                        Profiler.BeginSample("Reset Core List");
                        cores.Clear();
                        Profiler.EndSample();
                        Profiler.BeginSample("Get Cores");
                        for (int k = 0; k < parts[j].Modules.Count; k++)
                        {
                            ITestFlightCore core = parts[j].Modules[k] as ITestFlightCore;
                            if (core != null && core.TestFlightEnabled)
                                cores.Add(core.Alias);
                        }
                        Profiler.EndSample();
                        //cores = TestFlightInterface.GetActiveCores(vessel.parts[j]);
                        if (cores == null || cores.Count <= 0)
                            continue;
                        Profiler.BeginSample("ProcessCores");
                        for (int k = 0; k < cores.Count; k++)
                        {
                            ITestFlightCore core = TestFlightUtil.GetCore(vessel.parts[j], cores[k]);
                            if (core == null) continue;
                            // Poll for flight data and part status
                            if (!(currentUTC >= lastDataPoll + tfScenario.userSettings.masterStatusUpdateFrequency))
                                continue;
                            // Update or Add part status in Master Status
                            if (masterStatus.ContainsKey(vessel.id))
                            {
                                Profiler.BeginSample("MasterStatus Existing Vessel");
                                // Vessel is already in the Master Status, so check if part is in there as well
                                int existingPartIndex = -1;
                                Profiler.BeginSample("Find Part");
                                for (int msIndex = 0; msIndex < masterStatus[vessel.id].allPartsStatus.Count; msIndex++)
                                {
                                    if (masterStatus[vessel.id].allPartsStatus[msIndex].partID !=
                                        vessel.parts[j].flightID) continue;
                                    existingPartIndex = msIndex;
                                    break;
                                }
                                Profiler.EndSample();
                                if (existingPartIndex > -1)
                                {
                                    Profiler.BeginSample("Existing Part");
                                    //PartStatus partStatus = masterStatus[vessel.id].allPartsStatus[existingPartIndex];
                                    PartStatus partStatus = new PartStatus();
                                    partStatus.lastSeen = currentUTC;
                                    partStatus.flightCore = core;
                                    partStatus.partName = core.Title;
                                    partStatus.partID = vessel.parts[j].flightID;
                                    Profiler.BeginSample("Part - GetPartStatus");
                                    partStatus.partStatus = core.GetPartStatus();
                                    Profiler.EndSample();
                                    // get any failures
                                    Profiler.BeginSample("Part - GetActiveFailures");
                                    partStatus.failures = core.GetActiveFailures();
                                    Profiler.EndSample();
                                    Profiler.BeginSample("Part - GetFlightData");
                                    partStatus.flightData = core.GetFlightData();
                                    Profiler.EndSample();
                                    Profiler.BeginSample("Part - GetBaseFailureRate");
                                    double failureRate = core.GetBaseFailureRate();
                                    Profiler.EndSample();
                                    Profiler.BeginSample("Part - GetWorstMomentaryFailureRate");
                                    MomentaryFailureRate momentaryFailureRate = core.GetWorstMomentaryFailureRate();
                                    if (momentaryFailureRate.valid && momentaryFailureRate.failureRate > failureRate)
                                        failureRate = momentaryFailureRate.failureRate;
                                    Profiler.EndSample();
                                    partStatus.momentaryFailureRate = failureRate;
                                    partStatus.acknowledged = false;
                                    Profiler.BeginSample("Part - FailureRateToMTBFString");
                                    core.FailureRateToMTBFString(failureRate, TestFlightUtil.MTBFUnits.SECONDS, false, 999,
                                        out partStatus.mtbfString);
                                    //partStatus.mtbfString = core.FailureRateToMTBFString(failureRate, TestFlightUtil.MTBFUnits.SECONDS, 999);
                                    Profiler.EndSample();
                                    masterStatus[vessel.id].allPartsStatus[existingPartIndex] = partStatus;
                                    Profiler.EndSample();
                                }
                                else
                                {
                                    Profiler.BeginSample("New Part");
                                    PartStatus partStatus = new PartStatus();
                                    partStatus.lastSeen = currentUTC;
                                    partStatus.flightCore = core;
                                    partStatus.partName = core.Title;
                                    partStatus.partID = vessel.parts[j].flightID;
                                    partStatus.partStatus = core.GetPartStatus();
                                    // get any failures
                                    partStatus.failures = core.GetActiveFailures();
                                    partStatus.flightData = core.GetFlightData();
                                    double failureRate = core.GetBaseFailureRate();
                                    MomentaryFailureRate momentaryFailureRate = core.GetWorstMomentaryFailureRate();
                                    if (momentaryFailureRate.valid && momentaryFailureRate.failureRate > failureRate)
                                        failureRate = momentaryFailureRate.failureRate;
                                    partStatus.momentaryFailureRate = failureRate;
                                    partStatus.acknowledged = false;
                                    core.FailureRateToMTBFString(failureRate, TestFlightUtil.MTBFUnits.SECONDS, false, 999,
                                        out partStatus.mtbfString);
                                    masterStatus[vessel.id].allPartsStatus.Add(partStatus);
                                    Profiler.EndSample();
                                }
                                Profiler.EndSample();
                            }
                            else
                            {
                                Profiler.BeginSample("MasterStatus New Vessel");
                                // Vessel is not in the Master Status so create a new entry for it and add this part
                                PartStatus partStatus = new PartStatus();
                                partStatus.lastSeen = currentUTC;
                                partStatus.flightCore = core;
                                partStatus.partName = core.Title;
                                partStatus.partID = vessel.parts[j].flightID;
                                partStatus.partStatus = core.GetPartStatus();
                                // get any failures
                                partStatus.failures = core.GetActiveFailures();
                                partStatus.flightData = core.GetFlightData();
                                double failureRate = core.GetBaseFailureRate();
                                MomentaryFailureRate momentaryFailureRate = core.GetWorstMomentaryFailureRate();
                                if (momentaryFailureRate.valid && momentaryFailureRate.failureRate > failureRate)
                                    failureRate = momentaryFailureRate.failureRate;
                                partStatus.momentaryFailureRate = failureRate;
                                partStatus.acknowledged = false;
                                partStatus.mtbfString = core.FailureRateToMTBFString(failureRate, TestFlightUtil.MTBFUnits.SECONDS, 999);
                                MasterStatusItem masterStatusItem = new MasterStatusItem();
                                masterStatusItem.vesselID = vessel.id;
                                masterStatusItem.vesselName = vessel.GetName();
                                masterStatusItem.allPartsStatus = new List<PartStatus>();
                                masterStatusItem.allPartsStatus.Add(partStatus);
                                masterStatus.Add(vessel.id, masterStatusItem);
                                Profiler.EndSample();
                            }
                        }
                        Profiler.EndSample();
                    }
                }
                Profiler.EndSample();
                if (currentUTC >= lastDataPoll + tfScenario.userSettings.minTimeBetweenDataPoll)
                {
                    lastDataPoll = currentUTC;
                }
                if (currentUTC >= lastFailurePoll + tfScenario.userSettings.minTimeBetweenFailurePoll)
                {
                    lastFailurePoll = currentUTC;
                }
            }
            Profiler.EndSample();
        }
Exemple #4
0
        internal override void Update()
        {
            if (!isReady)
            {
                return;
            }

            if (masterStatus == null)
            {
                masterStatus = new Dictionary <Guid, MasterStatusItem>();
            }

            currentUTC = Planetarium.GetUniversalTime();
            // ensure out vessel list is up to date
            CacheVessels();
            if (currentUTC >= lastMasterStatusUpdate + tfScenario.userSettings.masterStatusUpdateFrequency)
            {
                lastMasterStatusUpdate = currentUTC;
                VerifyMasterStatus();
            }
            // process vessels
            foreach (var entry in knownVessels)
            {
                Vessel vessel = FlightGlobals.Vessels.Find(v => v.id == entry.Key);
                if (vessel.loaded)
                {
                    foreach (Part part in vessel.parts)
                    {
                        ITestFlightCore core = TestFlightUtil.GetCore(part);
                        if (core != null)
                        {
                            // Poll for flight data and part status
                            if (currentUTC >= lastDataPoll + tfScenario.userSettings.masterStatusUpdateFrequency)
                            {
                                TestFlightData currentFlightData = new TestFlightData();
                                currentFlightData.scope      = core.GetScope();
                                currentFlightData.flightData = core.GetFlightData();
                                currentFlightData.flightTime = core.GetFlightTime();

                                PartStatus partStatus = new PartStatus();
                                partStatus.flightCore   = core;
                                partStatus.partName     = TestFlightUtil.GetPartTitle(part);
                                partStatus.partID       = part.flightID;
                                partStatus.flightData   = currentFlightData.flightData;
                                partStatus.flightTime   = currentFlightData.flightTime;
                                partStatus.partStatus   = core.GetPartStatus();
                                partStatus.timeToRepair = core.GetRepairTime();
                                double failureRate = core.GetBaseFailureRate();
                                MomentaryFailureRate momentaryFailureRate = core.GetWorstMomentaryFailureRate();
                                if (momentaryFailureRate.valid && momentaryFailureRate.failureRate > failureRate)
                                {
                                    failureRate = momentaryFailureRate.failureRate;
                                }
                                partStatus.momentaryFailureRate = failureRate;
                                partStatus.repairRequirements   = core.GetRequirementsTooltip();
                                partStatus.acknowledged         = core.IsFailureAcknowledged();
                                partStatus.activeFailure        = core.GetFailureModule();
                                partStatus.mtbfString           = core.FailureRateToMTBFString(failureRate, TestFlightUtil.MTBFUnits.SECONDS, 999);

                                // Update or Add part status in Master Status
                                if (masterStatus.ContainsKey(vessel.id))
                                {
                                    // Vessel is already in the Master Status, so check if part is in there as well
                                    int numItems = masterStatus[vessel.id].allPartsStatus.Count(p => p.partID == part.flightID);
                                    int existingPartIndex;
                                    if (numItems == 1)
                                    {
                                        existingPartIndex = masterStatus[vessel.id].allPartsStatus.FindIndex(p => p.partID == part.flightID);
                                        masterStatus[vessel.id].allPartsStatus[existingPartIndex] = partStatus;
                                    }
                                    else if (numItems == 0)
                                    {
                                        masterStatus[vessel.id].allPartsStatus.Add(partStatus);
                                    }
                                    else
                                    {
                                        existingPartIndex = masterStatus[vessel.id].allPartsStatus.FindIndex(p => p.partID == part.flightID);
                                        masterStatus[vessel.id].allPartsStatus[existingPartIndex] = partStatus;
                                        Log("[ERROR] TestFlightManager: Found " + numItems + " matching parts in Master Status Display!");
                                    }
                                }
                                else
                                {
                                    // Vessel is not in the Master Status so create a new entry for it and add this part
                                    MasterStatusItem masterStatusItem = new MasterStatusItem();
                                    masterStatusItem.vesselID       = vessel.id;
                                    masterStatusItem.vesselName     = vessel.GetName();
                                    masterStatusItem.allPartsStatus = new List <PartStatus>();
                                    masterStatusItem.allPartsStatus.Add(partStatus);
                                    masterStatus.Add(vessel.id, masterStatusItem);
                                }

                                PartFlightData data = tfScenario.GetFlightDataForPartName(TestFlightUtil.GetFullPartName(part));
                                if (data != null)
                                {
                                    data.AddFlightData(part.name, currentFlightData);
                                }
                                else
                                {
                                    data = new PartFlightData();
                                    data.AddFlightData(TestFlightUtil.GetFullPartName(part), currentFlightData);
                                    tfScenario.SetFlightDataForPartName(TestFlightUtil.GetFullPartName(part), data);
                                }
                            }
                        }
                    }
                }
                if (currentUTC >= lastDataPoll + tfScenario.userSettings.minTimeBetweenDataPoll)
                {
                    lastDataPoll = currentUTC;
                }
                if (currentUTC >= lastFailurePoll + tfScenario.userSettings.minTimeBetweenFailurePoll)
                {
                    lastFailurePoll = currentUTC;
                }
            }
        }
Exemple #5
0
        internal override void Update()
        {
            if (!isReady)
                return;

            if (masterStatus == null)
                masterStatus = new Dictionary<Guid, MasterStatusItem>();

            currentUTC = (float)Planetarium.GetUniversalTime();
            // ensure out vessel list is up to date
            CacheVessels();
            if (currentUTC >= lastMasterStatusUpdate + tfScenario.userSettings.masterStatusUpdateFrequency)
            {
                lastMasterStatusUpdate = currentUTC;
                VerifyMasterStatus();
            }
            // process vessels
            foreach (var entry in knownVessels)
            {
                Vessel vessel = FlightGlobals.Vessels.Find(v => v.id == entry.Key);
                if (vessel.loaded)
                {
                    foreach(Part part in vessel.parts)
                    {
                        ITestFlightCore core = TestFlightUtil.GetCore(part);
                        if (core != null)
                        {
                            // Poll for flight data and part status
                            if (currentUTC >= lastDataPoll + tfScenario.userSettings.masterStatusUpdateFrequency)
                            {

                                // Old data structure deprecated v1.3
                                PartStatus partStatus = new PartStatus();
                                partStatus.lastSeen = currentUTC;
                                partStatus.flightCore = core;
                                partStatus.partName = TestFlightUtil.GetPartTitle(part);
                                partStatus.partID = part.flightID;
                                partStatus.partStatus = core.GetPartStatus();
                                partStatus.timeToRepair = core.GetRepairTime();
                                partStatus.flightData = core.GetFlightData();
                                float failureRate = core.GetBaseFailureRate();
                                MomentaryFailureRate momentaryFailureRate = core.GetWorstMomentaryFailureRate();
                                if (momentaryFailureRate.valid && momentaryFailureRate.failureRate > failureRate)
                                    failureRate = momentaryFailureRate.failureRate;
                                partStatus.momentaryFailureRate = failureRate;
                                partStatus.repairRequirements = core.GetRequirementsTooltip();
                                partStatus.acknowledged = core.IsFailureAcknowledged();
                                partStatus.activeFailure = core.GetFailureModule();
                                partStatus.mtbfString = core.FailureRateToMTBFString(failureRate, TestFlightUtil.MTBFUnits.SECONDS, 999);

                                // Update or Add part status in Master Status
                                if (masterStatus.ContainsKey(vessel.id))
                                {
                                    // Vessel is already in the Master Status, so check if part is in there as well
                                    int numItems = masterStatus[vessel.id].allPartsStatus.Count(p => p.partID == part.flightID);
                                    int existingPartIndex;
                                    if (numItems == 1)
                                    {
                                        existingPartIndex = masterStatus[vessel.id].allPartsStatus.FindIndex(p => p.partID == part.flightID);
                                        masterStatus[vessel.id].allPartsStatus[existingPartIndex] = partStatus;
                                    }
                                    else if (numItems == 0)
                                    {
                                        masterStatus[vessel.id].allPartsStatus.Add(partStatus);
                                    }
                                    else
                                    {
                                        existingPartIndex = masterStatus[vessel.id].allPartsStatus.FindIndex(p => p.partID == part.flightID);
                                        masterStatus[vessel.id].allPartsStatus[existingPartIndex] = partStatus;
                                        Log("[ERROR] TestFlightManager: Found " + numItems + " matching parts in Master Status Display!");
                                    }
                                }
                                else
                                {
                                    // Vessel is not in the Master Status so create a new entry for it and add this part
                                    MasterStatusItem masterStatusItem = new MasterStatusItem();
                                    masterStatusItem.vesselID = vessel.id;
                                    masterStatusItem.vesselName = vessel.GetName();
                                    masterStatusItem.allPartsStatus = new List<PartStatus>();
                                    masterStatusItem.allPartsStatus.Add(partStatus);
                                    masterStatus.Add(vessel.id, masterStatusItem);
                                }
                                string partName = TestFlightUtil.GetFullPartName(part);
                                tfScenario.SetFlightDataForPartName(partName, partStatus.flightData);
                            }
                        }
                    }
                }
                if (currentUTC >= lastDataPoll + tfScenario.userSettings.minTimeBetweenDataPoll)
                {
                    lastDataPoll = currentUTC;
                }
                if (currentUTC >= lastFailurePoll + tfScenario.userSettings.minTimeBetweenFailurePoll)
                {
                    lastFailurePoll = currentUTC;
                }
            }
        }
Exemple #6
0
        internal override void Update()
        {
            if (!isReady)
            {
                return;
            }

            if (masterStatus == null)
            {
                masterStatus = new Dictionary <Guid, MasterStatusItem>();
            }

            currentUTC = Planetarium.GetUniversalTime();
            // ensure out vessel list is up to date
            CacheVessels();
            if (currentUTC >= lastMasterStatusUpdate + tfScenario.userSettings.masterStatusUpdateFrequency)
            {
                lastMasterStatusUpdate = currentUTC;
                VerifyMasterStatus();
            }
            // process vessels
            foreach (var entry in knownVessels)
            {
                Vessel vessel = FlightGlobals.Vessels.Find(v => v.id == entry.Key);
                if (vessel.loaded)
                {
                    foreach (Part part in vessel.parts)
                    {
                        // Each KSP part can be composed of N virtual parts
                        List <string> cores = TestFlightInterface.GetActiveCores(part);
                        if (cores == null || cores.Count <= 0)
                        {
                            continue;
                        }
                        foreach (string activeCore in cores)
                        {
                            ITestFlightCore core = TestFlightUtil.GetCore(part, activeCore);
                            if (core != null)
                            {
                                // Poll for flight data and part status
                                if (currentUTC >= lastDataPoll + tfScenario.userSettings.masterStatusUpdateFrequency)
                                {
                                    // Old data structure deprecated v1.3
                                    PartStatus partStatus = new PartStatus();
                                    partStatus.lastSeen   = currentUTC;
                                    partStatus.flightCore = core;
                                    partStatus.partName   = core.Title;
                                    partStatus.partID     = part.flightID;
                                    partStatus.partStatus = core.GetPartStatus();
                                    // get any failures
                                    partStatus.failures   = core.GetActiveFailures();
                                    partStatus.flightData = core.GetFlightData();
                                    double failureRate = core.GetBaseFailureRate();
                                    MomentaryFailureRate momentaryFailureRate = core.GetWorstMomentaryFailureRate();
                                    if (momentaryFailureRate.valid && momentaryFailureRate.failureRate > failureRate)
                                    {
                                        failureRate = momentaryFailureRate.failureRate;
                                    }
                                    partStatus.momentaryFailureRate = failureRate;
                                    partStatus.acknowledged         = false;
                                    partStatus.mtbfString           = core.FailureRateToMTBFString(failureRate, TestFlightUtil.MTBFUnits.SECONDS, 999);

                                    // Update or Add part status in Master Status
                                    if (masterStatus.ContainsKey(vessel.id))
                                    {
                                        // Vessel is already in the Master Status, so check if part is in there as well
                                        int numItems = masterStatus[vessel.id].allPartsStatus.Count(p => p.partID == part.flightID);
                                        int existingPartIndex;
                                        if (numItems == 1)
                                        {
                                            existingPartIndex = masterStatus[vessel.id].allPartsStatus.FindIndex(p => p.partID == part.flightID);
                                            masterStatus[vessel.id].allPartsStatus[existingPartIndex] = partStatus;
                                        }
                                        else if (numItems == 0)
                                        {
                                            masterStatus[vessel.id].allPartsStatus.Add(partStatus);
                                        }
                                        else
                                        {
                                            existingPartIndex = masterStatus[vessel.id].allPartsStatus.FindIndex(p => p.partID == part.flightID);
                                            masterStatus[vessel.id].allPartsStatus[existingPartIndex] = partStatus;
                                            Log("[ERROR] TestFlightManager: Found " + numItems + " matching parts in Master Status Display!");
                                        }
                                    }
                                    else
                                    {
                                        // Vessel is not in the Master Status so create a new entry for it and add this part
                                        MasterStatusItem masterStatusItem = new MasterStatusItem();
                                        masterStatusItem.vesselID       = vessel.id;
                                        masterStatusItem.vesselName     = vessel.GetName();
                                        masterStatusItem.allPartsStatus = new List <PartStatus>();
                                        masterStatusItem.allPartsStatus.Add(partStatus);
                                        masterStatus.Add(vessel.id, masterStatusItem);
                                    }
                                }
                            }
                        }
                    }
                }
                if (currentUTC >= lastDataPoll + tfScenario.userSettings.minTimeBetweenDataPoll)
                {
                    lastDataPoll = currentUTC;
                }
                if (currentUTC >= lastFailurePoll + tfScenario.userSettings.minTimeBetweenFailurePoll)
                {
                    lastFailurePoll = currentUTC;
                }
            }
        }