OutSim and OutGauge
Note: this is a work in progress.OutSim and OutGauge allow the use of LFS data in motion simulators and dashboards, respectively. OutSim and OutGauge connections are UDP only, which means that an additional timeout may be specified that dictates how long to wait for a packet to be received before closing the connection. Alternatively if no timeout value is specified an infinite timeout is assumed. Before receiving OutSim or OutGauge packets you must first enable their broadcast in the LFS
cfg.txt file.
Note: that OutSim and OutGauge packets are only sent when using an internal cockpit view in the game.
OutSim
To enable OutSim packets in LFS you must edit this section of the game's CFG.txt file.
OutSim Mode 0 :0-off 1-driving 2-driving+replay
OutSim Delay 1 :minimum delay between packets (100ths of a sec)
OutSim IP 0.0.0.0 :IP address to send the UDP packet
OutSim Port 0 :IP port
OutSim ID 0 :if not zero, adds an identifier to the packet
In the following examples we will presume that you have specified an IP of
127.0.0.1 and a port number of
30000. Here is a simple example that shows receiving OutSim packets from LFS.
using System;
using InSimDotNet.Out;
class Program {
static void Main() {
// Create OutSim object.
using (OutSim outsim = new OutSim()) {
// Attach event handler to packet-received event.
outsim.PacketReceived += outsim_PacketReceived;
// Start listening for packets from LFS.
outsim.Connect("127.0.0.1", 30000);
// Stop program from exiting while listening.
Console.ReadLine();
}
}
static void outsim_PacketReceived(object sender, OutSimEventArgs e) {
// Handle packet.
Console.WriteLine(e.Heading);
}
}
As you see receiving packets is simple, we attach an event-handler to the OutSim.PacketReceived event and call
OutSim.Connect(string, port), specifiying the host and port to listen on.
In this example we have not specified a timeout, so the connection will never timeout and will need to be closed manually by a call to
OutSim.Close(), or by exiting the program.
Setting a timeout is simple however!
using System;
using InSimDotNet.Out;
class Program {
static void Main() {
// Create timeout interval.
TimeSpan timeout = TimeSpan.FromSeconds(60);
// Create OutSim object with the specified timeout.
using (OutSim outsim = new OutSim(timeout)) {
// Attach event handlers to packet-received and timedout events.
outsim.PacketReceived += outsim_PacketReceived;
outsim.TimedOut += outsim_TimedOut;
// Start listening for packets from LFS.
outsim.Connect("127.0.0.1", 30000);
// Stop program from exiting while listening.
Console.ReadLine();
}
}
static void outsim_TimedOut(object sender, EventArgs e) {
Console.WriteLine("OutSim timed out!");
}
static void outsim_PacketReceived(object sender, OutSimEventArgs e) {
// Handle packet.
Console.WriteLine(e.Heading);
}
}
We pass the timeout value of sixty seconds into the
OutSim class constructor and then attach an event-handler to the
OutSim.TimedOut event. Now if sixty seconds elapse without a packet being recieved, the OutSim object will close the connection automatically and raise a
OutSim.TimedOut event.
OutGauge
OutGauge works exactly the same as OutSim, except that you use an
OutGauge object to create the connection. Again you must enable OutGauge packets by editing the following section of the LFS
cfg.txt file
OutGauge Mode 0 :0-off 1-driving 2-driving+replay
OutGauge Delay 1 :minimum delay between packets (100ths of a sec)
OutGauge IP 0.0.0.0 :IP address to send the UDP packet
OutGauge Port 0 :IP port
OutGauge ID 0 :if not zero, adds an identifier to the packet
As you can see from the example below there is very little difference between OutSim and OutGauge.
using System;
using InSimDotNet.Out;
class Program {
static void Main() {
// Create timeout interval.
TimeSpan timeout = TimeSpan.FromSeconds(10);
// Create OutGauge object with the specified timeout.
using (OutGauge outgauge = new OutGauge(timeout)) {
// Attach event handler to packet-received event.
outgauge.PacketReceived += outgauge_PacketReceived;
outgauge.TimedOut += outgauge_TimedOut;
// Start listening for packets from LFS.
outgauge.Connect("127.0.0.1", 30000);
// Stop program from exiting while listening.
Console.ReadLine();
}
}
static void outgauge_TimedOut(object sender, EventArgs e) {
Console.WriteLine("OutGauge timed out!");
}
static void outgauge_PacketReceived(object sender, OutGaugeEventArgs e) {
// Handle packet.
Console.WriteLine(e.RPM);
}
}
Using OutGauge or OutSim with InSim
TODO: Write this!