protected virtual async Task <ISessionData> ParseTelemetrySession(byte[] telemetryBytes, IbtParseOptions options) { var s = await Task.Run(() => { var session = new SessionData(); var idx = 0; var fieldDefinitions = ParseFieldDescriptions(telemetryBytes, ref idx); session.Fields = fieldDefinitions; var sessionInfo = ParseSessionInfo(telemetryBytes, options, ref idx); session.SessionInfo = sessionInfo; if (options.HasFlag(IbtParseOptions.CarSetup)) { session.SetupInfo = new SetupInfo(session.SessionInfo.CarSetupYaml); } if (options.HasFlag(IbtParseOptions.TelemetryData)) { var sessionFrames = ParseFrames(telemetryBytes, session.Fields, ref idx); session.Frames = sessionFrames; } var sessionLaps = ParseLaps(session); session.Laps = sessionLaps; return(session); }); return(s); }
public SessionDictionaries(string yamlSessionData, IbtParseOptions options) { var yamlReader = new StringReader(yamlSessionData); var deserializer = new Deserializer(); var sessionData = deserializer.Deserialize(yamlReader); root = (IDictionary <object, object>)sessionData; // required weekendInfo = (IDictionary <object, object>)root["WeekendInfo"]; if (options.HasFlag(IbtParseOptions.DriverInfo)) { driverInfo = (IDictionary <object, object>)root["DriverInfo"]; driverCarIdx = Convert.ToInt32(driverInfo["DriverCarIdx"]); drivers = (IList <object>)driverInfo["Drivers"]; driverCar = (IDictionary <object, object>)drivers[driverCarIdx]; } if (options.HasFlag(IbtParseOptions.WeekendOptions)) { weekendOptions = (IDictionary <object, object>)weekendInfo["WeekendOptions"]; } if (options.HasFlag(IbtParseOptions.SessionInfo)) { sessionInfo = (IDictionary <object, object>)root["SessionInfo"]; } if (options.HasFlag(IbtParseOptions.CameraInfo)) { cameraInfo = (IDictionary <object, object>)root["CameraInfo"]; } if (options.HasFlag(IbtParseOptions.RadioInfo)) { radioInfo = (IDictionary <object, object>)root["RadioInfo"]; } if (options.HasFlag(IbtParseOptions.SplitTimeInfo)) { splitTimeInfo = (IDictionary <object, object>)root["SplitTimeInfo"]; } }
protected virtual ISessionDictionaries ParseSessionInfo(byte[] telemetryBytes, IbtParseOptions options, ref int idx) { idx += 3; // skip the three '-' characters that denote the start of the YAML section. int yamlStartIdx = idx; // find the three '.' characters that denote the end of the YAML section. while (true) { idx++; if (telemetryBytes[idx] == 46) { if ((telemetryBytes[idx + 1] == 46) && (telemetryBytes[idx + 2] == 46)) { idx += 3; break; } } } var yamlLength = idx - yamlStartIdx - 3; // exclude the three '.' characters on the end. //_sessionData.Yaml = GetTextFromBytes(telemetryBytes, yamlStartIdx, yamlLength); var telemetryYaml = _ascii.GetString(telemetryBytes, yamlStartIdx, yamlLength).TrimEnd('\0'); var sessionInfo = new SessionDictionaries(telemetryYaml, options); if (options.HasFlag(IbtParseOptions.CarSetup)) { var beginSetupIdx = telemetryYaml.IndexOf("CarSetup:"); if (beginSetupIdx > 0) { sessionInfo.CarSetupYaml = telemetryYaml.Substring(beginSetupIdx); } } return(sessionInfo); }