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()); } } }