added prep to read forza data
This commit is contained in:
parent
e55927dbe2
commit
5d676828d4
4 changed files with 23 additions and 5 deletions
1
GAME_METHODS/FORZA_METHODS.py
Normal file
1
GAME_METHODS/FORZA_METHODS.py
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
FROZA_DATA_FORMAT = '<iIfffffffffffffffffffffffffffffffffffffffffffffffffffiiiiifffffffffffffffffHBBBBBBbbb'
|
||||||
|
|
@ -1 +1 @@
|
||||||
__all__= ["BEAMNG_METHODS"]
|
__all__= ["BEAMNG_METHODS","FORZA_METHODS"]
|
||||||
|
|
@ -7,18 +7,35 @@ from GAME_METHODS import *
|
||||||
|
|
||||||
COM_PORT = 'COM5'
|
COM_PORT = 'COM5'
|
||||||
UDP_IP = "127.0.0.1"
|
UDP_IP = "127.0.0.1"
|
||||||
UDP_PORT = 4444
|
BEAMNG_UDP_PORT = 4444
|
||||||
|
FORZA_UDP_PORT= 4843
|
||||||
|
|
||||||
connectedArduino = False
|
connectedArduino = False
|
||||||
connectedWebSocket = False
|
connectedWebSocket = False
|
||||||
|
gameSelected = False
|
||||||
|
portToConnect= 0
|
||||||
|
dataFormat = ""
|
||||||
|
|
||||||
|
while gameSelected == False:
|
||||||
|
gameNo = input("1:BEAMNG\n2:FORZA")
|
||||||
|
if gameNo == 1:
|
||||||
|
portToConnect = BEAMNG_UDP_PORT
|
||||||
|
dataFormat =BEAMNG_METHODS.BEAMNG_DATA_FORMAT
|
||||||
|
gameSelected = True
|
||||||
|
elif gameNo ==2:
|
||||||
|
portToConnect = FORZA_UDP_PORT
|
||||||
|
dataFormat = FORZA_METHODS.FROZA_DATA_FORMAT
|
||||||
|
else:
|
||||||
|
print("please select a number from the list")
|
||||||
|
|
||||||
|
|
||||||
while connectedWebSocket == False:
|
while connectedWebSocket == False:
|
||||||
try:
|
try:
|
||||||
sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
|
sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
|
||||||
sock.bind((UDP_IP,UDP_PORT))
|
sock.bind((UDP_IP,portToConnect))
|
||||||
connectedWebSocket = True
|
connectedWebSocket = True
|
||||||
except:
|
except:
|
||||||
print("please check you are able to open the socket on this system")
|
print("please check you are able to open the socket on this system\ntired to open port: "+portToConnect)
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
while connectedArduino == False:
|
while connectedArduino == False:
|
||||||
|
|
@ -34,7 +51,7 @@ print("ready:\n")
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
data, addr = sock.recvfrom(1024)
|
data, addr = sock.recvfrom(1024)
|
||||||
unpackedData = struct.unpack(BEAMNG_METHODS.BEAMNG_DATA_FORMAT,data)
|
unpackedData = struct.unpack(dataFormat,data)
|
||||||
carData = BEAMNG_METHODS.unpackData(unpackedData)
|
carData = BEAMNG_METHODS.unpackData(unpackedData)
|
||||||
kmh=carData["speed"]*3.6
|
kmh=carData["speed"]*3.6
|
||||||
toPi.write(str(kmh).encode()+":".encode())
|
toPi.write(str(kmh).encode()+":".encode())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue