TelemetryPC3

Responsive image
Yesterday in this blog post I anticipated this new project, but what is it? what is it for?
This is a really simple telemetry software that display the telemetry data captured by RST_UDP.

Before to go into the details, I want you to know that you can get the source code on GitHub:
https://github.com/CodeSailer/TelemetryPC3

What is does?

It load the data from the text file created by RST_UDP, and display a graph that show the telemetry.
To create the graph I used OxyPlot, which is very simple to use.

How to use it

Before use it you need a telemetry file, to make that open RST_UDP and start Project CARS 3(or 2) then do some laps(any mode).
Now you’ll find a file called telemetry_[n].txt inside the RST_UDP directory.
Open it with this software.
On the left you have the graph.
On the right you have the Settings that allow you to change which lap to analyze, you can write all to show all the datas without filter them by lap.
Then you have the times of the Sector 1, Sector 2, Sector 3 and the lap time.
Last, you have the min and max values of the g-forces.

The code

Now you know how to use this software, so let me explain the code a bit.
The first thing I did was create all the data series and the the plot model for OxyPlot, then I created 3 list for the g-forces(you’ll see later why):

 1PlotModel myModel = new PlotModel { };
 2
 3LineSeries speedSeries = new LineSeries() { Title = "speed"};
 4LineSeries tFLSeries = new LineSeries() { Title = "t° FL" };
 5LineSeries tFRSeries = new LineSeries() { Title = "t° FR" };
 6LineSeries tRLSeries = new LineSeries() { Title = "t° RL" };
 7LineSeries tRRSeries = new LineSeries() { Title = "t° RR" };
 8LineSeries throttleSeries = new LineSeries() { Title = "throttle" };
 9LineSeries brakeSeries = new LineSeries() { Title = "brake" };
10LineSeries steeringSeries = new LineSeries() { Title = "steering" };
11string telemetryFileName;
12
13List<float> gforce_x = new List<float>();
14List<float> gforce_y = new List<float>();
15List<float> gforce_z = new List<float>();

I added the string telemetryFile inside the function Form1() to be able to open multiple window without the necessity to reload each time the telemetry file, then I just set the color of each series:

 1public Form1( string telemetryFile = null)
 2    {
 3        if(telemetryFile != null)
 4        {
 5            telemetryFileName = telemetryFile;
 6        }
 7        InitializeComponent();
 8        
 9        speedSeries.Color = OxyColors.Blue;
10        tFLSeries.Color = OxyColors.Orange;
11        tFRSeries.Color = OxyColors.DarkOrange;
12        tRLSeries.Color = OxyColors.Purple;
13        tRRSeries.Color = OxyColors.DarkViolet;
14        throttleSeries.Color = OxyColors.Green;
15        brakeSeries.Color = OxyColors.Red;
16        steeringSeries.Color = OxyColors.Black;
17    }

When you click Open in the menu it clear the plot and it load the new selected file.
To clear the plot I did:

 1public void ClearPlot()
 2    {
 3        // reset plot
 4        myModel.InvalidatePlot(true);
 5        myModel.Series.Clear();
 6        //reset series data
 7        speedSeries.Points.Clear();
 8        tFLSeries.Points.Clear();
 9        tFRSeries.Points.Clear();
10        tRLSeries.Points.Clear();
11        tRRSeries.Points.Clear();
12        throttleSeries.Points.Clear();
13        brakeSeries.Points.Clear();
14        steeringSeries.Points.Clear();
15    }

To load the telemetry file I did:

 1public void openTelemetryFile(string fileName, string lapNumber)
 2    {
 3        List<string> tmp = File.ReadAllLines(fileName).ToList();
 4        for (int i = 0; i < tmp.Count; i++)
 5        {
 6            string[] line_part = tmp[i].Split(' ');
 7            if (lapNumber != "all")
 8            {
 9                if (line_part[0] == lapNumber)
10                {
11                    speedSeries.Points.Add(new DataPoint(i, double.Parse(line_part[1]) * 3.6));
12                    s1time.Text = line_part[2];
13                    s2time.Text = line_part[3];
14                    s3time.Text = line_part[4];
15                    laptime.Text = line_part[5];
16                    tFLSeries.Points.Add(new DataPoint(i, double.Parse(line_part[6])+(-273.15)));
17                    tFRSeries.Points.Add(new DataPoint(i, double.Parse(line_part[7]) + (-273.15)));
18                    tRLSeries.Points.Add(new DataPoint(i, double.Parse(line_part[8]) + (-273.15)));
19                    tRRSeries.Points.Add(new DataPoint(i, double.Parse(line_part[9]) + (-273.15)));
20
21                    throttleSeries.Points.Add(new DataPoint(i, double.Parse(line_part[10])/255*100));
22                    brakeSeries.Points.Add(new DataPoint(i, double.Parse(line_part[11])/255*100));
23                    steeringSeries.Points.Add(new DataPoint(i, double.Parse(line_part[12])));
24                    gforce_x.Add(float.Parse(line_part[13]) / 10);
25                    gforce_y.Add(float.Parse(line_part[14]) / 10);
26                    gforce_z.Add(float.Parse(line_part[15]) / 10);
27                }
28            }
29            else
30            {
31                speedSeries.Points.Add(new DataPoint(i, double.Parse(line_part[1]) * 3.6));
32                s1time.Text = line_part[2];
33                s2time.Text = line_part[3];
34                s3time.Text = line_part[4];
35                laptime.Text = line_part[5];
36                tFLSeries.Points.Add(new DataPoint(i, double.Parse(line_part[6]) + (-273.15)));
37                tFRSeries.Points.Add(new DataPoint(i, double.Parse(line_part[7]) + (-273.15)));
38                tRLSeries.Points.Add(new DataPoint(i, double.Parse(line_part[8]) + (-273.15)));
39                tRRSeries.Points.Add(new DataPoint(i, double.Parse(line_part[9]) + (-273.15)));
40
41                throttleSeries.Points.Add(new DataPoint(i, double.Parse(line_part[10]) / 255 * 100));
42                brakeSeries.Points.Add(new DataPoint(i, double.Parse(line_part[11])/255*100));
43                steeringSeries.Points.Add(new DataPoint(i, double.Parse(line_part[12])));
44                gforce_x.Add(float.Parse(line_part[13]) / 10);
45                gforce_y.Add(float.Parse(line_part[14]) / 10);
46                gforce_z.Add(float.Parse(line_part[15]) / 10);
47            }
48
49        }
50        myModel.Series.Add(speedSeries);
51        myModel.Series.Add(tFLSeries);
52        myModel.Series.Add(tFRSeries);
53        myModel.Series.Add(tRLSeries);
54        myModel.Series.Add(tRRSeries);
55        myModel.Series.Add(throttleSeries);
56        myModel.Series.Add(brakeSeries);
57        myModel.Series.Add(steeringSeries);
58        if (gforce_x.Count() != 0)
59        {
60            gforce_x_min.Text = gforce_x.Min().ToString("0.0");
61            gforce_x_max.Text = gforce_x.Max().ToString("0.0");
62            gforce_y_min.Text = gforce_y.Min().ToString("0.0");
63            gforce_y_max.Text = gforce_y.Max().ToString("0.0");
64            gforce_z_min.Text = gforce_z.Min().ToString("0.0");
65            gforce_z_max.Text = gforce_z.Max().ToString("0.0");
66        }
67        this.plotView1.Model = myModel;
68    }

Let me explain a bit more.

1List<string> tmp = File.ReadAllLines(fileName).ToList();
2for (int i = 0; i < tmp.Count; i++)
3{
4    string[] line_part = tmp[i].Split(' ');
5    //...
6}

This load the telemetry file, and through the for loop it read it line by line.
The first thing that it does is split each line by spaces, it does like this because the telemetry file is written like this:

1lap speed s1->s3 laptime t°Fl->RR throttle brake g-forceXYZ
20     1    2->4     5       6->9     10      11      12->14

The first part of the line is the lap number(line_part[0]), then the speed(line_part[1]), and so on.
Then it filter the data by lap number and it will display only the data that match the lap number setted in the textbox. After that it add the data to the series:

 1speedSeries.Points.Add(new DataPoint(i, double.Parse(line_part[1]) * 3.6));
 2s1time.Text = line_part[2];
 3s2time.Text = line_part[3];
 4s3time.Text = line_part[4];
 5laptime.Text = line_part[5];
 6tFLSeries.Points.Add(new DataPoint(i, double.Parse(line_part[6]) + (-273.15)));
 7tFRSeries.Points.Add(new DataPoint(i, double.Parse(line_part[7]) + (-273.15)));
 8tRLSeries.Points.Add(new DataPoint(i, double.Parse(line_part[8]) + (-273.15)));
 9tRRSeries.Points.Add(new DataPoint(i, double.Parse(line_part[9]) + (-273.15)));
10
11throttleSeries.Points.Add(new DataPoint(i, double.Parse(line_part[10]) / 255 * 100));
12brakeSeries.Points.Add(new DataPoint(i, double.Parse(line_part[11])/255*100));
13steeringSeries.Points.Add(new DataPoint(i, double.Parse(line_part[12])));
14gforce_x.Add(float.Parse(line_part[13]) / 10);
15gforce_y.Add(float.Parse(line_part[14]) / 10);
16gforce_z.Add(float.Parse(line_part[15]) / 10);

Now it add the series to the plot model:

1myModel.Series.Add(speedSeries);
2myModel.Series.Add(tFLSeries);
3myModel.Series.Add(tFRSeries);
4myModel.Series.Add(tRLSeries);
5myModel.Series.Add(tRRSeries);
6myModel.Series.Add(throttleSeries);
7myModel.Series.Add(brakeSeries);
8myModel.Series.Add(steeringSeries);

Then it update the textbox of the g-forces:

1if (gforce_x.Count() != 0)
2{
3    gforce_x_min.Text = gforce_x.Min().ToString("0.0");
4    gforce_x_max.Text = gforce_x.Max().ToString("0.0");
5    gforce_y_min.Text = gforce_y.Min().ToString("0.0");
6    gforce_y_max.Text = gforce_y.Max().ToString("0.0");
7    gforce_z_min.Text = gforce_z.Min().ToString("0.0");
8    gforce_z_max.Text = gforce_z.Max().ToString("0.0");
9}

I’ve used a list for store the g-forces so I was able to call the Min() and the Max() functions to show their values.

The las thing that it does is set the plotmodel to the plotview:

1this.plotView1.Model = myModel;

Conclusion

I hope you found useful or, at least, interesting.
You can find all the source on GitHub on the link above, with the very permissive MIT license.
You can contact me on Twitter: @CodeSailer