1. For downloading SimTools plugins you need a Download Package. Get it with virtual coins that you receive for forum activity or Buy Download Package - We have a zero Spam tolerance so read our forum rules first.

    Buy Download Package Now!
  2. Do not try to cheat our system and do not post an unnecessary amount of useless posts only to earn credits here. We have a zero spam tolerance policy and this will cause a ban of your user account. Otherwise we wish you a pleasant stay here! Read the forum rules
  3. We have a few rules which you need to read and accept before posting anything here! Following these rules will keep the forum clean and your stay pleasant here. Do not following these rules will lead to permanent exclusion from this website: Read the forum rules.

Devs - how to add Telemetry output into a game + Unity and UE4 code

If you are using either Unity or Unreal Engine 4 then @Claudio Silva has done the hard work for you in creating function code for SimTools integration, including a UDP server, see the original post here: https://www.xsimulator.net/community/threads/generic-unity-plugin.7804/page-2#post-146168

And the GitHub QuplaySimTools repository where you can grab the code: https://github.com/ddkclaudio/QuplaySimTools

The SimTools dev @yobuddy gives this example guide to adding telemetry to your game: https://www.xsimulator.net/communit...ow-to-add-telemetry-output-into-a-game.11080/

First, let’s make the game a settings file to hold the Telemetry settings for the game.
I’m suggesting a ‘Telemetry.cfg’ file that holds the motion configuration for the game.

You may already have a configuration file for the game that you want to put these settings in, this is just an example. (This also gives SimTools a file to patch for motion, and allows the telemetry outputting to be on or off as needed.)

The Telemetry.cfg file holds these 4 settings:
- Enable_Telemitry = False
- IpAddress =
- Port = 4123
- MS_OutputRate = 10

I wrote the following example code in VB.net, as its dead simple to read and see what I’m doing.
Basically thou, I’m creating a looping background thread that builds and sends the needed output with UDP.
Once you have ‘something like’ this code in the game, all you have to do is:
Call ‘Start_Telemetry_Output()’ when the game starts up.
And ‘Stop_Telemety_Output()’ when the game shuts down.

Ok, now some code:
Private Telemetry_Sender As New UdpClient
Private Telemetry_Loop_ms As Integer
Private Telemetry_Running As Boolean = False
Private Telemetry_Thread As Threading.Thread

'Starts up the Telemetry Sender.
Private Sub Start_Telemetry_Output()
'only startup if not already started.
If Telemetry_Running = False Then
'read from Telemtry cfg file.
Dim Telemitry_Enabled AsString = "Get Enabled_Telemetry value from the Telemetry.cfg file"
Dim IpAddress AsString = "Get IpAddress value from the Telemetry.cfg file"
Dim Port AsString = "Get Port value from the Telemetry.cfg file"
Dim MS_OutputRate AsString = "Get MS_OutputRate value from the Telemetry.cfg file"

If CBool(Telemitry_Enabled) = True Then
'startup a new client.
Telemetry_Sender = New UdpClient
Telemetry_Sender.Connect(IpAddress, CInt(Port))

'set loop speed & start sending data.
Telemetry_Loop_ms = CInt(MS_OutputRate)
Telemetry_Running = True
Telemetry_Thread = New Threading.Thread(AddressOf Telemetry_Loop)
Telemetry_Thread.IsBackground = True
Catch ex As Exception
'Could not create the UDP sender, no need to do anything.
End TryEnd IfEnd IfEnd Sub

'Send Telemetry
Public Sub SendTelemetry()
'Collect the data.
Dim Roll As String = ""
Dim Pitch As String = ""
Dim Yaw As String = ""
Dim RollSpeed As String = ""
Dim PitchSpeed As String = ""
Dim YawSpeed As String = ""
Dim Vertical As String = ""
Dim Lateral As String = ""
Dim Longitudinal As String = ""
'add anything else you want to add, its easy now!
'Dim Rpm As String = ""
'Dim Speed As String = ""

'check the status to see if the game is being played (In Game, In Menus, Paused).
Dim Game_Is_Playing As Boolean = 'Get if the game is being played)

'game is actually being played check.
If Game_Is_Playing = True Then

'If game is actually being played (not in menus or paused).
Roll = "Get value from your game" 'in degrees - (-180 to 180)
Pitch = "Get value from your game" 'in degrees - (-180 to 180)
Yaw = "Get value from your game" 'in degrees - (-180 to 180)
RollSpeed = "Get value from your game" 'in (rad/sec)
PitchSpeed = "Get value from your game" 'in (rad/sec)
YawSpeed = "Get value from your game" 'in (rad/sec)
Vertical = "Get value from your game" 'in g's acceleration
Lateral = "Get value from your game" 'in g's acceleration
Longitudinal = "Get value from your game" 'in g's acceleration
'If the game is paused or in the menus. (not actually being played)
Roll = "0" 'in degrees - (-180 to 180)
Pitch = "0" 'in degrees - (-180 to 180)
Yaw = "0" 'in degrees - (-180 to 180)
RollSpeed = "0" 'in (rad/sec)
PitchSpeed = "0" 'in (rad/sec)
YawSpeed = "0" 'in (rad/sec)
Vertical = "0" 'in g's acceleration
Lateral = "0" 'in g's acceleration
Longitudinal = "0" 'in g's acceleration
End If

'Build the output string. (The 'S~' and the '~E' is so the user can see if they have a complete string of inputs)
Dim WhatToSend As String = "S~Roll:" & Roll & "Pitch:" & Pitch & ":Yaw:" & Yaw & "RollSpeed:" & RollSpeed & "PitchSpeed:" & PitchSpeed & ":YawSpeed:" & YawSpeed & "Vertical:" & Vertical & ":Lateral:" & Lateral & ":Longitudinal:" & Longitudinal & "~E"

'Send the string
Dim bytCommand As Byte() = NewByte() {}
bytCommand = Encoding.ASCII.GetBytes(WhatToSend)
Telemetry_Sender.Send(bytCommand, bytCommand.Length)Catch ex As Exception
'something went wrong, turn off telemetry output.
End TryEnd Sub

'Stop Telemetry Output
Public Sub Stop_Telemetry_Output()
'only shutdown if already started.
If Telemetry_Running = True Then
'turn output off.
Telemetry_Running = False
'let it finish what its doing.
'Close Client.
End IfEnd Sub

'Send Telemetry Loop
Private Sub Telemetry_Loop()
'Send Telemetry.
'pause till next packet is needed.
'loop again if needed.
If Telemetry_Running = True Then
Telemetry_Thread = New Threading.Thread(AddressOf Telemetry_Loop)
Telemetry_Thread.IsBackground = True
End IfEnd Sub

Source Code:
SimTools Settings, Tips and Tricks
Oct 26, 2017
Page Views: