public void SendUdp(string text) { Support.WriteLog($"{Globals.projectName} - Sending UDP Packet: {text} to {dataLogger.receiverIp}"); byte[] sendBuffer = Encoding.ASCII.GetBytes(text); dataLogger.udpClient.Send(sendBuffer, sendBuffer.Length); }
public void GetAllChildrenComponents(GameObject g_object) { Component[] components = g_object.GetComponentsInChildren <Component>(true); foreach (Component comp in components) { Support.WriteLog(comp.ToString()); } Debug.Log(""); }
public void ResetLogger() { runlogger = false; udpClient.Close(); Support.WriteLog("Scene end detected. Stopping telemetry"); Start(); }
IEnumerator WaitForMap() { while (SceneManager.GetActiveScene().buildIndex != 7 || SceneManager.GetActiveScene().buildIndex == 12) { //Pausing this method till the loader scene is unloaded yield return(null); } Support.WriteLog("Done waiting map load"); yield return(new WaitForSeconds(5)); runlogger = true; }
public static Dictionary <string, string> getVehicleLights(GameObject vehicle) { Dictionary <string, string> lights = new Dictionary <string, string>(); //this is BAD //Light landingLights = vehicle.transform.Find("LandingLight").GetComponent<Light>(); try { bool landinglight = false; bool navlight = false; bool strobelight = false; foreach (Light light in vehicle.GetComponentsInChildren <Light>()) { if (light.gameObject.name == "LandingLight") { landinglight = true; } if (light.gameObject.name.ToString().Contains("StrobeLight")) { strobelight = true; } Support.WriteLog(light.ToString()); } foreach (SpriteRenderer spriteish in vehicle.GetComponentsInChildren <SpriteRenderer>()) { if (spriteish.ToString().Contains("Nav")) { navlight = true; } } lights.Add("LandingLights", landinglight.ToString()); lights.Add("NavLights", navlight.ToString()); lights.Add("StrobeLights", strobelight.ToString()); return(lights); } catch (Exception ex) { Support.WriteErrorLog("Error getting lights " + ex.ToString()); return(lights); } }
public void Start() { HarmonyInstance harmony = HarmonyInstance.Create("vtolvrTelemetry.logger.logger"); harmony.PatchAll(Assembly.GetExecutingAssembly()); udpClient = new UdpClient(); udpClient.Connect(receiverIp, receiverPort); Support.WriteLog("Running Startup and Waiting for map load"); vtolmod_api = VTOLAPI.instance; StartCoroutine(WaitForMap()); System.IO.Directory.CreateDirectory("TelemtryDataLogs"); System.IO.Directory.CreateDirectory("TelemtryDataLogs\\" + DateTime.UtcNow.ToString("yyyy-MM-dd HHmm")); DataLogFolder = "TelemtryDataLogs\\" + DateTime.UtcNow.ToString("yyyy-MM-dd HHmm") + "\\"; csv_path = @DataLogFolder + "datalog.csv"; json_path = @DataLogFolder + "datalog.json"; dataGetter = new DataGetters(this); }
public void GetData() { LogData f_info = new LogData(); try { if (dataLogger.printOutput) { Support.WriteLog("Collecting Data..."); } Actor playeractor = FlightSceneManager.instance.playerActor; GameObject currentVehicle = VTOLAPI.instance.GetPlayersVehicleGameObject(); f_info.unixTimestamp = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds; f_info.Physics.XAccel = Math.Round(playeractor.flightInfo.acceleration.x, 2).ToString(); f_info.Physics.YAccel = Math.Round(playeractor.flightInfo.acceleration.y, 2).ToString(); f_info.Physics.ZAccel = Math.Round(playeractor.flightInfo.acceleration.z, 2).ToString(); f_info.Physics.PlayerGs = Math.Round(playeractor.flightInfo.playerGs, 2).ToString(); f_info.Vehicle.VehicleName = currentVehicle.name; f_info.Vehicle.Heading = Math.Round(playeractor.flightInfo.heading, 2).ToString(); f_info.Vehicle.Pitch = Math.Round(playeractor.flightInfo.pitch, 2).ToString(); f_info.Vehicle.Roll = Math.Round(playeractor.flightInfo.roll, 2).ToString(); f_info.Vehicle.AoA = Math.Round(playeractor.flightInfo.aoa, 2).ToString(); f_info.Vehicle.Airspeed = Math.Round(playeractor.flightInfo.airspeed, 2).ToString(); f_info.Vehicle.VerticalSpeed = Math.Round(playeractor.flightInfo.verticalSpeed, 2).ToString(); f_info.Vehicle.AltitudeASL = Math.Round(playeractor.flightInfo.altitudeASL, 2).ToString(); Health health = Traverse.Create(playeractor).Field("h").GetValue() as Health; f_info.Vehicle.Health = health.currentHealth.ToString(); f_info.Vehicle.Drag = Math.Round(playeractor.flightInfo.rb.drag, 2).ToString(); f_info.Vehicle.Mass = Math.Round(playeractor.flightInfo.rb.mass, 2).ToString(); f_info.Vehicle.IsLanded = playeractor.flightInfo.isLanded.ToString(); f_info.Vehicle.Fuel.FuelDensity = DataGetters.getFuelDensity(currentVehicle); f_info.Vehicle.Fuel.FuelBurnRate = DataGetters.getFuelBurnRate(currentVehicle); f_info.Vehicle.Fuel.FuelLevel = DataGetters.getFuelLevel(currentVehicle); f_info.Vehicle.BatteryLevel = DataGetters.GetBattery(currentVehicle); f_info.Vehicle.Engines = DataGetters.GetEngineStats(currentVehicle); f_info.Vehicle.RadarCrossSection = DataGetters.getRadarCrossSection(currentVehicle); f_info.Vehicle.TailHook = DataGetters.GetHook(currentVehicle); f_info.Vehicle.Lights = DataGetters.getVehicleLights(currentVehicle); f_info.Vehicle.Flaps = DataGetters.getFlaps(currentVehicle); f_info.Vehicle.Brakes = DataGetters.getBrakes(currentVehicle); f_info.Vehicle.EjectionState = DataGetters.getEjectionState(currentVehicle); f_info.Vehicle.Avionics.RadarState = DataGetters.getRadarState(currentVehicle); f_info.Vehicle.Avionics.RWRContacts = DataGetters.getRWRContacts(currentVehicle); f_info.Vehicle.Avionics.MissileDetected = DataGetters.getMissileDetected(currentVehicle); f_info.Vehicle.Avionics.StallDetector = DataGetters.GetStall(currentVehicle); f_info.Vehicle.Avionics.masterArm = DataGetters.getMasterArm(currentVehicle); // Dumps all components in the vehicle. Will freeze game, but useful to see what we get. //GetAllVehicleComponents(currentVehicle); if (dataLogger.printOutput) { Support.WriteLog(f_info.ToCSV()); } } catch (Exception ex) { Support.WriteErrorLog($"{Globals.projectName} - Error getting telemetry data " + ex.ToString()); } if (dataLogger.csvEnabled == true) { if (dataLogger.printOutput) { Support.WriteLog("Saving CSV"); } if (!File.Exists(dataLogger.csv_path)) { using (StreamWriter sw = File.AppendText(dataLogger.csv_path)) { sw.WriteLine(f_info.CSVHeaders()); } } using (StreamWriter sw = File.AppendText(dataLogger.csv_path)) { sw.WriteLine(f_info.ToCSV()); } } if (dataLogger.jsonEnabled == true) { if (dataLogger.printOutput) { Support.WriteLog("Saving JSON..."); } using (StreamWriter sw = File.AppendText(dataLogger.json_path)) { sw.WriteLine(JsonConvert.SerializeObject(f_info) + "\n"); } } if (dataLogger.udpEnabled == true) { if (dataLogger.printOutput) { Support.WriteLog("Sending UDP Packet..."); } try { SendUdp(JsonConvert.SerializeObject(f_info)); } catch (Exception ex) { Debug.LogError($"{Globals.projectName} - Error sending UDP " + ex.ToString()); } } }