Exemple #1
0
        public static TelemetryState ToTelemetryState(this Sim instance, DGConfig config, TelemetryState oldState)
        {
            var tState = new TelemetryState()
            {
                IsConnected          = instance.Sdk.IsConnected,
                IsRunning            = instance.Sdk.IsRunning,
                DriverMarker         = instance.Sdk.GetTelemetryValue <bool>("DriverMarker").Value,
                OnPitRoad            = instance.Sdk.GetTelemetryValue <bool>("OnPitRoad").Value,
                PlayerCarTowTime     = instance.Sdk.GetTelemetryValue <float>("PlayerCarTowTime").Value,
                PlayerCarInPitStall  = instance.Sdk.GetTelemetryValue <bool>("PlayerCarInPitStall").Value,
                LapsCompleted        = instance.Sdk.GetTelemetryValue <int>("LapCompleted").Value,
                CurrentDriver        = instance.Driver?.Name,
                TeamName             = instance.Driver?.TeamName,
                CurrentSessionNumber = instance.CurrentSessionNumber,
                SubsessionId         = instance.SessionData.SubsessionId
            };

            tState.UpdateEvent = GetUpdateType(tState, oldState);

            foreach (KeyValuePair <string, ConfFormField> field in config.FormMapping)
            {
                object value;

                switch (field.Key)
                {
                case "UpdateEvent":
                    value = tState.UpdateEvent;
                    break;

                case "CurrentDriver":
                    value = instance.Driver?.Name;
                    break;

                case "TeamName":
                    value = instance.Driver?.TeamName;
                    break;

                case "CurrentSessionNumber":
                    value = instance.CurrentSessionNumber;
                    break;

                case "SubsessionId":
                    value = instance.SessionData.SubsessionId;
                    break;

                default:
                    value = instance.Sdk.GetTelemetryValue <object>(field.Key)?.Value;
                    break;
                }
                tState.Fields.Add(field.Key, new TelemetryFormField()
                {
                    Name   = field.Key,
                    FormId = field.Value.FormId,
                    SendOn = field.Value.SendOn,
                    Value  = value
                });
            }

            return(tState);
        }
        public IRacingMonitor(DGConfig config)
        {
            this.config = config;

            Sim.Instance.TelemetryUpdated += TelemetryUpdate;

            this.httpClient = new HttpClient();
            this.state      = new TelemetryState();
        }