OutSim and OutGauge

pyinsim makes it easy to deal with Out* packets by requiring very little code. While InSim uses TCP to handle its connection, OutSim and OutGauge instead use UDP. This means that they are stateless and you must define a timeout period. The timeout is the number of seconds that pyinsim will wait after a packet has been received before timing out.

Before you can use OutSim or OutGauge you must initialize their respective systems within LFS. The various settings can be set in the LFS\cfg.txt file, where you will see sections resembling the following:

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

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

An important note to remember is that both OutSim and OutGauge only work if you are using cockpit view in the game. When viewing a car from an external view no packets are sent.

OutSim Example


In the example we initialize OutSim and use Pythons build-in vars() function to dump the content of each packet to the standard output.

import pyinsim

# Function to handle OutInSim packets
def outsim_handler(outsim, packet):
    print vars(packet)

# Initialize OutSim. Set timeout to 30 seconds.
pyinsim.outsim('127.0.0.1', 30000, outinsim_handler, 30.0)

pyinsim.run()

OutGauge Example


Using OutGauge is almost identical.

import pyinsim

# Function to handle OutGauge packet
def outgauge_handler(outgauge, packet):
    print vars(packet)

# Initialize OutGauge. Set timeout to 30 seconds.
pyinsim.outgauge('127.0.0.1', 30000, outgauge_handler, 30.0)

pyinsim.run()

Using OutSim and OutGauge with InSim.


It is possible to receive OutSim and OutGauge packets while using InSim by specifying a separate UDP port when initializing the InSim connection. This example shows you how to enable OutGauge packets by sending a SMALL_SSG packet to InSim.

import pyinsim

def outgauge_handler(insim, og):
    print vars(og)
    
# Initialize InSim with UDP port of 30000
insim = pyinsim.insim('127.0.0.1', 29999, UDPPort=30000, Admin='password')

# Bind OutGauge event.
insim.bind(pyinsim.EVT_OUTGAUGE, outgauge_handler)

# Request OutGauge packets to be sent with a delay of 100 milliseconds between updates (10 per second)
insim.send(pyinsim.ISP_SMALL, ReqI=255, SubT=pyinsim.SMALL_SSG, UVal=100)

pyinsim.run()

Last edited Jul 16, 2011 at 2:17 PM by AlexMcBride, version 7

Comments

No comments yet.