protected override void ScanVessel(Vessel vessel) { sensors.Clear(); if (vessel == null || vessel.Parts == null) { return; } foreach (Part part in vessel.Parts) { if (part.packed) { part.Unpack(); } if (part.name != null) { if (part.name.Equals("sensorThermometer") || part.name.Equals("sensorGravimeter")) { foreach (PartModule m in part.Modules) { if (m is ModuleEnviroSensor) { ModuleEnviroSensor sensor = m as ModuleEnviroSensor; sensors.Add(sensor); } } } } } }
public static PartValue Construct(global::Part part, SharedObjects shared) { foreach (PartModule module in part.Modules) { ModuleEngines mEng = module as ModuleEngines; if (mEng != null) { return(new EngineValue(part, new ModuleEngineAdapter(mEng), shared)); } ModuleEnginesFX mEngFX = module as ModuleEnginesFX; if (mEngFX != null) { return(new EngineValue(part, new ModuleEngineAdapter(mEngFX), shared)); } ModuleDockingNode mDock = module as ModuleDockingNode; if (mDock != null) { return(new DockingPortValue(mDock, shared)); } ModuleEnviroSensor mSense = module as ModuleEnviroSensor; if (mSense != null) { return(new SensorValue(part, mSense, shared)); } var gimbalModule = module as ModuleGimbal; if (gimbalModule != null) { return(new GimbalValue(gimbalModule, shared)); } } // Fallback if none of the above: then just a normal part: return(new PartValue(part, shared)); }
internal Sensor(Part part) { Part = part; sensor = part.InternalPart.Module <ModuleEnviroSensor> (); if (sensor == null) { throw new ArgumentException("Part is not a sensor"); } }
internal Sensor(Part part) { this.part = part; sensor = part.InternalPart.Module <ModuleEnviroSensor> (); if (sensor == null) { throw new ArgumentException("Part does not have a ModuleEnviroSensor PartModule"); } }
public override void fetchData() { float currentReading = 0; ModuleEnviroSensor sensor = part.Modules.OfType <ModuleEnviroSensor>().First(); string cleanedValue = Regex.Replace(sensor.readoutInfo, @"([0-9]+\.?[0-9]*).*", "$1"); float.TryParse(cleanedValue, out currentReading); data.AddLast(currentReading); }
private void InspectSensor(ModuleEnviroSensor sensor) { if (sensor == null || sensor.sensorType == null) { return; } if (sensor.sensorType == "TEMP") { String readout = sensor.readoutInfo; if (readout != null) { String temp = Regex.Replace(readout, "[^-.0-9]", ""); if (temp.Length > 0) { try { temperature += double.Parse(temp); sensorTempEnabled = true; sensorTempCount++; } catch { if (Log.IsLogable(Log.LEVEL.DETAIL)) { Log.Detail("invalid temp sensor value"); } } } } } else if (sensor.sensorType == "GRAV") { String readout = sensor.readoutInfo; if (readout != null && readout.Length > 5) { String grav = readout.Substring(0, readout.Length - 5); try { gravity += double.Parse(grav); sensorGravEnabled = true; sensorGravCount++; } catch { if (Log.IsLogable(Log.LEVEL.DETAIL)) { Log.Detail("invalid temp sensor value"); } } } } }
private void InspectSensor(ModuleEnviroSensor sensor) { if (IsOff(sensor)) { return; } if (!sensor.isEnabled) { return; } String readout = sensor.readoutInfo; if (readout == null || readout == "") { return; } if (sensor.sensorType == ModuleEnviroSensor.SensorType.TEMP) { temperature += ParseReadout(readout); sensorTempEnabled = true; sensorTempCount++; } else if (sensor.sensorType == ModuleEnviroSensor.SensorType.GRAV) { gravity += ParseReadout(readout); sensorGravEnabled = true; sensorGravCount++; } else if (sensor.sensorType == ModuleEnviroSensor.SensorType.PRES) { pressure += ParseReadout(readout); sensorPressureEnabled = true; sensorPressureCnt++; } else if (sensor.sensorType == ModuleEnviroSensor.SensorType.ACC) { seismic += ParseReadout(readout); sensorSeismicEnabled = true; sensorSeismicCnt++; } }
private kList GetSensorList(SharedObjects shared) { kList list = new kList(); list.AddColumn("Part Name", 37, ColumnAlignment.Left); list.AddColumn("Sensor Type", 11, ColumnAlignment.Left); foreach (Part part in shared.Vessel.Parts) { foreach (PartModule module in part.Modules) { ModuleEnviroSensor sensor = module as ModuleEnviroSensor; if (sensor != null) { list.AddItem(part.partInfo.title, sensor.sensorType); } } } return(list); }
private void ScanPart(Part part) { if (part.name != null) { //if (part.name.StartsWith("sensor") ) { foreach (PartModule m in part.Modules) { if (m is ModuleEnviroSensor) { ModuleEnviroSensor sensor = m as ModuleEnviroSensor; if (!sensors.Contains(sensor)) { sensors.Add(sensor); if (Log.IsLogable(Log.LEVEL.TRACE)) { Log.Trace("Added sensor module of type " + sensor.sensorType); } } } } } } }
public SensorValue(global::Part part, ModuleEnviroSensor sensor, SharedObjects sharedObj) : base(part, sharedObj) { this.sensor = sensor; SensorInitializeSuffixes(); }
private bool IsOff(ModuleEnviroSensor sensor) { return(sensor.readoutInfo == Constants.STRING_OFF); }
private void ConstructPart(global::Part part, PartValue parent, DecouplerValue decoupler) { if (part.State == PartStates.DEAD || part.transform == null) { return; } // Modules can be in any order, so to enforce some sort of priority for parts which are multiple types, // gather all potential modules and then select from those valid. IEngineStatus engine = null; ModuleRCS rcs = null; PartValue separator = null; ModuleEnviroSensor sensor = null; foreach (var module in part.Modules) { if (module is IEngineStatus) { engine = module as IEngineStatus; } else if (module is ModuleRCS) { rcs = module as ModuleRCS; } else if (module is IStageSeparator) { var dock = module as ModuleDockingNode; if (dock != null) { var port = new DockingPortValue(Shared, part, parent, decoupler, dock); separator = port; dockingPorts.Add(port); if (!module.StagingEnabled()) { continue; } decoupler = port; decouplers.Add(decoupler); } // ignore anything with staging disabled and continue the search // this can e.g. be heat shield or some sensor with integrated decoupler else { if (!module.StagingEnabled()) { continue; } if (module is LaunchClamp) { separator = decoupler = new LaunchClampValue(Shared, part, parent, decoupler); } else if (module is ModuleDecouple || module is ModuleAnchoredDecoupler) { separator = decoupler = new DecouplerValue(Shared, part, parent, decoupler); } else // ModuleServiceModule ? { continue; // rather continue the search } decouplers.Add(decoupler); } // ignore leftover decouplers if (decoupler == null || decoupler.Part.inverseStage >= StageManager.CurrentStage) { continue; } // check if we just created closer decoupler (see StageValues.CreatePartSet) if (nextDecoupler == null || decoupler.Part.inverseStage > nextDecoupler.Part.inverseStage) { nextDecoupler = decoupler; } } else if (module is ModuleEnviroSensor) { sensor = module as ModuleEnviroSensor; } } // Select part value in priority order PartValue self; if (engine != null) { self = new EngineValue(Shared, part, parent, decoupler); } else if (rcs != null) { self = new RCSValue(Shared, part, parent, decoupler, rcs); } else if (separator != null) { self = separator; } else if (sensor != null) { self = new SensorValue(Shared, part, parent, decoupler, sensor); } else { self = new PartValue(Shared, part, parent, decoupler); } if (rootPart == null) { rootPart = self; } partCache[part] = self; allParts.Add(self); foreach (var child in part.children) { ConstructPart(child, self, decoupler); } self.Children.IsReadOnly = true; }
public SensorValue(global::Part part, ModuleEnviroSensor sensor, SharedObjects sharedObj) : base(part,sharedObj) { this.sensor = sensor; SensorInitializeSuffixes(); }
/// <summary> /// Do not call! VesselTarget.ConstructPart uses this, would use `friend VesselTarget` if this was C++! /// </summary> internal SensorValue(SharedObjects shared, global::Part part, PartValue parent, DecouplerValue decoupler, ModuleEnviroSensor sensor) : base(shared, part, parent, decoupler) { this.sensor = sensor; RegisterInitializer(SensorInitializeSuffixes); }
public override void Evaluate() { switch (RegexMatch.Groups[1].Value.ToUpper()) { case "BODIES": StdOut(""); StdOut("Name Distance"); StdOut("-------------------------------------"); foreach (var body in FlightGlobals.fetch.bodies) { StdOut(body.bodyName.PadLeft(14) + " " + Vector3d.Distance(body.position, Vessel.GetWorldPos3D())); } StdOut(""); break; case "TARGETS": StdOut(""); StdOut("Vessel Name Distance"); StdOut("-------------------------------------"); double commRange = VesselUtils.GetCommRange(Vessel); foreach (Vessel vessel in FlightGlobals.Vessels) { if (vessel != Vessel) { var vT = new VesselTarget(vessel, this); if (vT.IsInRange(commRange)) { StdOut(vT.target.vesselName.PadRight(24) + " " + vT.GetDistance().ToString("0.0").PadLeft(8)); } } } StdOut(""); break; case "RESOURCES": StdOut(""); StdOut("Stage Resource Name Amount"); StdOut("------------------------------------------------"); foreach (Part part in Vessel.Parts) { String stageStr = part.inverseStage.ToString(); foreach (PartResource resource in part.Resources) { StdOut(part.inverseStage.ToString() + " " + resource.resourceName.PadRight(20) + " " + resource.amount.ToString("0.00").PadLeft(8)); } } break; case "PARTS": StdOut("------------------------------------------------"); foreach (Part part in Vessel.Parts) { StdOut(part.ConstructID + " " + part.partInfo.name); } break; case "ENGINES": StdOut("------------------------------------------------"); foreach (Part part in VesselUtils.GetListOfActivatedEngines(Vessel)) { foreach (PartModule module in part.Modules) { if (module is ModuleEngines) { var engineMod = (ModuleEngines)module; StdOut(part.uid + " " + part.inverseStage.ToString() + " " + engineMod.moduleName); } } } break; case "SENSORS": StdOut(""); StdOut("Part Name Sensor Type"); StdOut("------------------------------------------------"); foreach (Part part in Vessel.Parts) { foreach (PartModule module in part.Modules) { ModuleEnviroSensor sensor = module as ModuleEnviroSensor; if (sensor != null) { if (part.partInfo.name.Length > 37) { StdOut(part.partInfo.title.PadRight(34) + "... " + sensor.sensorType); } else { StdOut(part.partInfo.title.PadRight(37) + " " + sensor.sensorType); } } } } break; } State = ExecutionState.DONE; }
public SensorValue(global::Part part, ModuleEnviroSensor sensor) : base(part) { this.sensor = sensor; }
public SensorValue(global::Part part, ModuleEnviroSensor sensor, SharedObjects sharedObj) : base(part, sharedObj) { this.sensor = sensor; }
public SensorValue(global::Part part, ModuleEnviroSensor sensor) : base(part) { this.sensor = sensor; }
public SensorValue(global::Part part, ModuleEnviroSensor sensor, SharedObjects sharedObj) : base(part,sharedObj) { this.sensor = sensor; }