Snippets
Created by
Lennon R. Bisolo
last modified
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | class EpicRollerCoasters_Telemetry
{
// Launch Options: -telemetry network
// Launch Options: -telemetry network -port 7701
// Launch Options: -telemetry network -ip 127.0.0.1 -port 7701
// Default port: 7701
private static int port = 7701;
private static UdpClient client;
private static IPEndPoint anyIP;
public static string lastReceivedUDPPacket = "";
static void Main(string[] args)
{
anyIP = new IPEndPoint(IPAddress.Any, 0);
client = new UdpClient(port);
Thread receiveThread = new Thread(new ThreadStart(ReceiveData));
receiveThread.IsBackground = true;
receiveThread.Start();
// Holds the MainThread while looking for data
receiveThread.Join();
}
private static void ReceiveData()
{
while (true)
{
try
{
byte[] data = client.Receive(ref anyIP);
string text = Encoding.UTF8.GetString(data);
// Latest UDPPacket
lastReceivedUDPPacket = text;
//Console.WriteLine(">> " + lastReceivedUDPPacket);
// UDPPacket output example:
// S[005.001]V[023.729]F[008.801]Y[173.541]P[000.049]R[000.052]H[000.000]W[000.004]U[005.001]A[000.119]I[-000.001]O[000.000]N[00]C[00]G[00]
// S[026.953]V[044.193]F[016.940]Y[159.710]P[001.965]R[-003.653]H[000.182]W[000.170]U[026.952]A[000.480]I[000.541]O[-000.098]N[11]C[19]G[05]
float speed = GetNumber("S", lastReceivedUDPPacket);
float vibrationIntensity = GetNumber("V", lastReceivedUDPPacket);
float vibrationFrequency = GetNumber("F", lastReceivedUDPPacket);
float yaw = GetNumber("Y", lastReceivedUDPPacket);
float pitch = GetNumber("P", lastReceivedUDPPacket);
float roll = GetNumber("R", lastReceivedUDPPacket);
float heave = GetNumber("H", lastReceivedUDPPacket);
float sway = GetNumber("W", lastReceivedUDPPacket);
float surge = GetNumber("U", lastReceivedUDPPacket);
float yawVel = GetNumber("A", lastReceivedUDPPacket);
float pitchVel = GetNumber("I", lastReceivedUDPPacket);
float rollVel = GetNumber("O", lastReceivedUDPPacket);
float rideIndex = GetInt("N", lastReceivedUDPPacket);
float carIndex = GetInt("C", lastReceivedUDPPacket);
float gunIndex = GetInt("G", lastReceivedUDPPacket);
string rideName = ((RideType)rideIndex).ToString();
string carName = ((CartType)carIndex).ToString();
string gunName = ((GunType)gunIndex).ToString();
Console.WriteLine(">> Speed: {0}, Yaw: {1}, Pitch: {2}, Roll: {3}, Heave: {4}, Sway: {5}, Surge: {6}, YawVelocity: {7}, PitchVelocity: {8}, RollVelocity: {9}, RideName: {10}, CarName: {11}, GunName: {12}, VibrationIntensity: {13}, VibrationFrequency: {14}",
speed, yaw, pitch, roll, heave, sway, surge, yawVel, pitchVel, rollVel, rideName, carName, gunName, vibrationIntensity, vibrationFrequency);
}
catch (Exception err)
{
Console.WriteLine("[UDPReceive] Error: " + err.ToString());
}
}
}
// Parse the packats
private float GetNumber(string prefix, string data)
{
string numberRx = @"\-*\d{3}\.\d{3}";
string dataBlockRx = @"\[" + numberRx + @"\]";
string value = new Regex(prefix + dataBlockRx).Match(data).Value;
float number = float.Parse(new Regex(numberRx).Match(value).Value, CultureInfo.InvariantCulture);
return number;
}
private int GetInt(string prefix, string data)
{
string intRx = @"\-*\d{2}";
string dataBlockRx = @"\[" + intRx + @"\]";
string value = new Regex(prefix + dataBlockRx).Match(data).Value;
int number = int.Parse(new Regex(intRx).Match(value).Value, CultureInfo.InvariantCulture);
return number;
}
// Enums
public enum RideType
{
NONE = 0,
ROCK_FALLS = 1,
TREX_KINGDOM = 2,
WYVERN_SIEGE = 3,
SNOW_LAND = 4,
NEON_RIDER = 5,
HALLOWEEN = 6,
ARMAGEDDON = 7,
LOST_FOREST = 8,
DREAD_BLOOD = 9,
TUWHENA_VOLCANO = 10,
TROPICAL_ISLAND = 11,
NORTH_POLE = 12,
TWILIGHT = 13,
HAUNTED_CASTLE = 14,
OASIS = 15,
GREAT_CANYON = 16,
SPACE_STATION = 17,
SECRET_CAVE = 18,
TUTORIAL = 19,
LOBBY = 20
}
public enum CartType
{
RockFalls = 0,
TRexKingdom = 1,
WyvernSiege = 2,
Snowland = 3,
NeonRider = 4,
Halloween = 5,
Armageddon = 6,
LostForest = 7,
DreadBlood = 8,
TuwhenaVolcano = 9,
None = 10,
TropicalIsland = 11,
NorthPole = 12,
Twilight = 13,
HauntedCastle = 14,
Oasis = 15,
GreatCanyon = 16,
SpaceStation = 17,
SecretCave = 18,
Skate = 19
}
public enum GunType
{
NONE = 0,
SLINGSHOT = 1,
DART = 2,
CROSSBOW = 3,
SNOW_GUN = 4,
LASER_GUN = 5,
TOILET_GUN = 6,
CAL50 = 7,
WAND = 8,
SHOTGUN = 9,
TUWHENA_VOLCANO = 10,
TROPICAL_ISLAND = 11,
NORTH_POLE = 12,
TWILIGHT = 13,
HAUNTED_CASTLE = 14,
OASIS = 15,
GREAT_CANYON = 16,
SPACE_STATION = 17,
SECRET_CAVE = 18,
CAL50_SUPRESSED = 19,
}
}
|
Comments (3)
You can clone a snippet to your computer for local editing. Learn more.
Hi Lennon, I have a question. What is the range of each value? maximum and minimum
Hi Abel, we can’t know for sure because it varies from each ride and game mode, but you can measure by yourself. Sim Racing Studio do that for racing games for example, so you can calibrate the chair tilt angle based on each cart and track.
Here are some informations that may help you:
All the best,
Thanks!