1. Do not share user accounts! Any account that is shared by another person will be blocked and closed. This means: we will close not only the account that is shared, but also the main account of the user who uses another person's account. We have the ability to detect account sharing, so please do not try to cheat the system. This action will take place on 04/18/2023. Read all forum rules.
    Dismiss Notice
  2. 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 Now a Download Plan!
  3. 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
  4. 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. Do not follow these rules can lead to permanent exclusion from this website: Read the forum rules.
    Are you a company? Read our company 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 = 127.0.0.1
- 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
Try
'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
Telemetry_Thread.Start()
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()
Try
'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
Else
'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.
Stop_Telemity_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.
Threading.Thread.Sleep(100)
'Close Client.
Telemetry_Sender.Close()
End IfEnd Sub

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

Source Code:
https://www.xsimulator.net/community/attachments/telemetryoutputexample-zip.45557/
Category:
SimTools Settings, Tips and Tricks
Published:
Oct 26, 2017
Page Views:
10307